summaryrefslogtreecommitdiff
path: root/lib/collections.hpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-10 13:20:49 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-10 13:20:49 +0100
commita5a0ad3634c512afb1686a2ec8940843e7f0eb63 (patch)
tree7d476c4bcadaba9f2e8a5a2a0935255e5ad06137 /lib/collections.hpp
parentConstraint operator* collection helper to IterableCollections (diff)
downloadilt-a5a0ad3634c512afb1686a2ec8940843e7f0eb63.tar.bz2
ilt-a5a0ad3634c512afb1686a2ec8940843e7f0eb63.tar.xz
ilt-a5a0ad3634c512afb1686a2ec8940843e7f0eb63.zip
operator* collection helper reserves target space when possible
Diffstat (limited to 'lib/collections.hpp')
-rw-r--r--lib/collections.hpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/collections.hpp b/lib/collections.hpp
index 4df622e..b51d18e 100644
--- a/lib/collections.hpp
+++ b/lib/collections.hpp
@@ -70,6 +70,9 @@ template<template<typename...> typename C, typename... T>
operator*(const C<T...> & in, auto && f)
{
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;