Skip to content

Commit

Permalink
Merge pull request ethereum#3290 from ethereum/moveAppend
Browse files Browse the repository at this point in the history
Move-append for vector.
  • Loading branch information
chriseth authored Dec 12, 2017
2 parents 40e8716 + 3760284 commit 45d0992
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions libdevcore/CommonData.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ template <class T, class U> std::vector<T>& operator+=(std::vector<T>& _a, U con
_a.push_back(i);
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
template <class T, class U> std::set<T>& operator+=(std::set<T>& _a, U const& _b)
{
Expand All @@ -197,6 +203,17 @@ inline std::vector<T> operator+(std::vector<T> const& _a, std::vector<T> const&
ret += _b;
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>
bool contains(T const& _t, V const& _v)
Expand Down

0 comments on commit 45d0992

Please sign in to comment.