summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-10 14:34:56 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-10 14:34:56 +0100
commite7d946aadebfdf49cc96e6a518c1af1ef7f5c71c (patch)
tree5077b9db0ea285f665d2225347dbddd0512ce658
parentAdd the plant/foliage game item concepts (diff)
downloadilt-e7d946aadebfdf49cc96e6a518c1af1ef7f5c71c.tar.bz2
ilt-e7d946aadebfdf49cc96e6a518c1af1ef7f5c71c.tar.xz
ilt-e7d946aadebfdf49cc96e6a518c1af1ef7f5c71c.zip
Add operator* helper specialised for std::span
-rw-r--r--lib/collections.hpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/collections.hpp b/lib/collections.hpp
index b51d18e..8f5a43d 100644
--- a/lib/collections.hpp
+++ b/lib/collections.hpp
@@ -78,6 +78,27 @@ operator*(const C<T...> & in, auto && 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;
+}
+
template<typename... T>
constexpr auto &
operator+=(std::vector<T...> & in, std::vector<T...> && src)