From 3760284e1c040c93604ec9a86f11a9300617ad4b Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 28 Nov 2017 15:00:32 +0100 Subject: Move-append for vector. --- libdevcore/CommonData.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index e76a0949..b85abe95 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -183,6 +183,12 @@ template std::vector& operator+=(std::vector& _a, U con _a.push_back(i); return _a; } +/// Concatenate the contents of a container onto a vector, move variant. +template std::vector& operator+=(std::vector& _a, U&& _b) +{ + std::move(_b.begin(), _b.end(), std::back_inserter(_a)); + return _a; +} /// Concatenate the contents of a container onto a set template std::set& operator+=(std::set& _a, U const& _b) { @@ -197,6 +203,17 @@ inline std::vector operator+(std::vector const& _a, std::vector const& ret += _b; return ret; } +/// Concatenate two vectors of elements, moving them. +template +inline std::vector operator+(std::vector&& _a, std::vector&& _b) +{ + std::vector ret(std::move(_a)); + if (&_a == &_b) + ret += ret; + else + ret += std::move(_b); + return ret; +} template bool contains(T const& _t, V const& _v) -- cgit