summaryrefslogtreecommitdiff
path: root/lib/collections.hpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-14 18:03:34 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-14 18:03:34 +0100
commit5776a36b454fac04617313da011d7aa2b0e834d3 (patch)
tree1eb96d07e9a17a51e5763f397fc003f762cd2e75 /lib/collections.hpp
parentMerge branch 'model-factory-textures' (diff)
parentAdd an asset template and use it to define all the foliage assets in the plan... (diff)
downloadilt-5776a36b454fac04617313da011d7aa2b0e834d3.tar.bz2
ilt-5776a36b454fac04617313da011d7aa2b0e834d3.tar.xz
ilt-5776a36b454fac04617313da011d7aa2b0e834d3.zip
Merge branch 'assimp'
Diffstat (limited to 'lib/collections.hpp')
-rw-r--r--lib/collections.hpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/collections.hpp b/lib/collections.hpp
index 59cec6f..8f5a43d 100644
--- a/lib/collections.hpp
+++ b/lib/collections.hpp
@@ -65,11 +65,36 @@ operator*=(IterableCollection auto & in, auto && f)
}
template<template<typename...> typename C, typename... T>
+ requires IterableCollection<C<T...>>
[[nodiscard]] constexpr auto
operator*(const C<T...> & in, auto && f)
{
- C<decltype(f(in[0]))> out;
+ C<decltype(f(*in.begin()))> out;
+ if constexpr (requires { out.reserve(in.size()); }) {
+ out.reserve(in.size());
+ }
+
+ std::transform(in.begin(), in.end(), std::inserter(out, out.end()), f);
+ return out;
+}
+
+template<typename T, std::size_t N>
+[[nodiscard]] constexpr auto
+operator*(const std::span<T, N> in, auto && f)
+{
+ std::array<decltype(f(std::declval<T>())), N> out;
+
+ std::transform(in.begin(), in.end(), out.begin(), f);
+ return out;
+}
+
+template<typename T>
+[[nodiscard]] constexpr auto
+operator*(const std::span<T, std::dynamic_extent> in, auto && f)
+{
+ std::vector<decltype(f(std::declval<T>()))> out;
+ out.reserve(in.size());
std::transform(in.begin(), in.end(), std::inserter(out, out.end()), f);
return out;
}