From e7d946aadebfdf49cc96e6a518c1af1ef7f5c71c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 10 Apr 2023 14:34:56 +0100 Subject: Add operator* helper specialised for std::span --- lib/collections.hpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib') 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 & in, auto && f) return out; } +template +[[nodiscard]] constexpr auto +operator*(const std::span in, auto && f) +{ + std::array())), N> out; + + std::transform(in.begin(), in.end(), out.begin(), f); + return out; +} + +template +[[nodiscard]] constexpr auto +operator*(const std::span in, auto && f) +{ + std::vector()))> out; + + out.reserve(in.size()); + std::transform(in.begin(), in.end(), std::inserter(out, out.end()), f); + return out; +} + template constexpr auto & operator+=(std::vector & in, std::vector && src) -- cgit v1.2.3