Merge pull request #3290 from ethereum/moveAppend

Move-append for vector.
This commit is contained in:
chriseth 2017-12-12 10:23:19 +01:00 committed by GitHub
commit 45d0992ce8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -183,6 +183,12 @@ template <class T, class U> std::vector<T>& operator+=(std::vector<T>& _a, U con
_a.push_back(i); _a.push_back(i);
return _a; return _a;
} }
/// Concatenate the contents of a container onto a vector, move variant.
template <class T, class U> std::vector<T>& operator+=(std::vector<T>& _a, U&& _b)
{
std::move(_b.begin(), _b.end(), std::back_inserter(_a));
return _a;
}
/// Concatenate the contents of a container onto a set /// Concatenate the contents of a container onto a set
template <class T, class U> std::set<T>& operator+=(std::set<T>& _a, U const& _b) template <class T, class U> std::set<T>& operator+=(std::set<T>& _a, U const& _b)
{ {
@ -197,6 +203,17 @@ inline std::vector<T> operator+(std::vector<T> const& _a, std::vector<T> const&
ret += _b; ret += _b;
return ret; return ret;
} }
/// Concatenate two vectors of elements, moving them.
template <class T>
inline std::vector<T> operator+(std::vector<T>&& _a, std::vector<T>&& _b)
{
std::vector<T> ret(std::move(_a));
if (&_a == &_b)
ret += ret;
else
ret += std::move(_b);
return ret;
}
template <class T, class V> template <class T, class V>
bool contains(T const& _t, V const& _v) bool contains(T const& _t, V const& _v)