From a5a0ad3634c512afb1686a2ec8940843e7f0eb63 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 10 Apr 2023 13:20:49 +0100 Subject: operator* collection helper reserves target space when possible --- lib/collections.hpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') 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 typename C, typename... T> operator*(const C & in, auto && f) { C 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; -- cgit v1.2.3