summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-12-28 14:17:36 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-12-28 14:17:36 +0000
commit4688fc7d0dcd182e74ea102bfcd80d6b69516e4d (patch)
tree52886d61eb21b289efc970ba2cba51c81c3a2b29 /lib
parentReduce camera extents to the point they cross the sea floor boundary (diff)
downloadilt-4688fc7d0dcd182e74ea102bfcd80d6b69516e4d.tar.bz2
ilt-4688fc7d0dcd182e74ea102bfcd80d6b69516e4d.tar.xz
ilt-4688fc7d0dcd182e74ea102bfcd80d6b69516e4d.zip
Add two new array helpers
* create a new array from an old one and a mutation * mutate all the members of an existing array
Diffstat (limited to 'lib')
-rw-r--r--lib/collections.hpp21
1 files changed, 21 insertions, 0 deletions
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<T, first> & a, const std::array<T, second> & b)
std::copy(b.begin(), b.end(), out);
return r;
}
+
+template<typename T, std::size_t N>
+auto
+operator*(const std::array<T, N> & in, auto && f)
+{
+ std::array<decltype(f(in[0])), N> out;
+
+ for (auto outitr = out.begin(); const auto & v : in) {
+ *outitr++ = f(v);
+ }
+ return out;
+}
+
+template<typename T, std::size_t N>
+auto &
+operator*=(std::array<T, N> & in, auto && f)
+{
+ for (const auto & v : in) {
+ f(v);
+ }
+}