From 4688fc7d0dcd182e74ea102bfcd80d6b69516e4d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 28 Dec 2022 14:17:36 +0000 Subject: Add two new array helpers * create a new array from an old one and a mutation * mutate all the members of an existing array --- lib/collections.hpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib/collections.hpp') diff --git a/lib/collections.hpp b/lib/collections.hpp index ad4d947..5f4be68 100644 --- a/lib/collections.hpp +++ b/lib/collections.hpp @@ -12,3 +12,24 @@ operator+(const std::array & a, const std::array & b) std::copy(b.begin(), b.end(), out); return r; } + +template +auto +operator*(const std::array & in, auto && f) +{ + std::array out; + + for (auto outitr = out.begin(); const auto & v : in) { + *outitr++ = f(v); + } + return out; +} + +template +auto & +operator*=(std::array & in, auto && f) +{ + for (const auto & v : in) { + f(v); + } +} -- cgit v1.2.3