mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Move CommonData operator functions to the global namespace
This commit is contained in:
parent
c7824932a4
commit
15a5b2bf65
@ -34,6 +34,47 @@
|
||||
#include <set>
|
||||
#include <functional>
|
||||
|
||||
/// Operators need to stay in the global namespace.
|
||||
|
||||
/// Concatenate the contents of a container onto a vector
|
||||
template <class T, class U> std::vector<T>& operator+=(std::vector<T>& _a, U const& _b)
|
||||
{
|
||||
for (auto const& i: _b)
|
||||
_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)
|
||||
{
|
||||
_a.insert(_b.begin(), _b.end());
|
||||
return _a;
|
||||
}
|
||||
/// Concatenate two vectors of elements.
|
||||
template <class T>
|
||||
inline std::vector<T> operator+(std::vector<T> const& _a, std::vector<T> const& _b)
|
||||
{
|
||||
std::vector<T> ret(_a);
|
||||
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;
|
||||
}
|
||||
|
||||
namespace dev
|
||||
{
|
||||
|
||||
@ -190,52 +231,12 @@ inline unsigned bytesRequired(T _i)
|
||||
for (; _i != 0; ++i, _i >>= 8) {}
|
||||
return i;
|
||||
}
|
||||
/// Concatenate the contents of a container onto a vector
|
||||
template <class T, class U> std::vector<T>& operator+=(std::vector<T>& _a, U const& _b)
|
||||
{
|
||||
for (auto const& i: _b)
|
||||
_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)
|
||||
{
|
||||
_a.insert(_b.begin(), _b.end());
|
||||
return _a;
|
||||
}
|
||||
/// Concatenate two vectors of elements.
|
||||
template <class T>
|
||||
inline std::vector<T> operator+(std::vector<T> const& _a, std::vector<T> const& _b)
|
||||
{
|
||||
std::vector<T> ret(_a);
|
||||
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)
|
||||
{
|
||||
return std::end(_t) != std::find(std::begin(_t), std::end(_t), _v);
|
||||
}
|
||||
|
||||
|
||||
/// Function that iterates over a vector, calling a function on each of its
|
||||
/// elements. If that function returns a vector, the element is replaced by
|
||||
/// the returned vector. During the iteration, the original vector is only valid
|
||||
|
Loading…
Reference in New Issue
Block a user