diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-10 13:20:49 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-10 13:20:49 +0100 |
commit | a5a0ad3634c512afb1686a2ec8940843e7f0eb63 (patch) | |
tree | 7d476c4bcadaba9f2e8a5a2a0935255e5ad06137 /lib/collections.hpp | |
parent | Constraint operator* collection helper to IterableCollections (diff) | |
download | ilt-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.hpp | 3 |
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; |