diff --git a/libsolutil/CommonData.h b/libsolutil/CommonData.h index b61ba82a2..5fe0c2bfb 100644 --- a/libsolutil/CommonData.h +++ b/libsolutil/CommonData.h @@ -37,7 +37,10 @@ #include #include -/// Operators need to stay in the global namespace. +namespace std +{ + +/// Operator overloads for STL containers should be in std namespace for ADL to work properly. /// Concatenate the contents of a container onto a vector template std::vector& operator+=(std::vector& _a, U& _b) @@ -78,6 +81,7 @@ template std::set& operator+=(std::set& _a, U& _a.insert(std::move(x)); return _a; } + /// Concatenate two vectors of elements. template inline std::vector operator+(std::vector const& _a, std::vector const& _b) @@ -86,6 +90,7 @@ 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) @@ -97,6 +102,7 @@ inline std::vector operator+(std::vector&& _a, std::vector&& _b) ret += std::move(_b); return ret; } + /// Concatenate something to a sets of elements. template inline std::set operator+(std::set const& _a, U&& _b) @@ -105,6 +111,7 @@ inline std::set operator+(std::set const& _a, U&& _b) ret += std::forward(_b); return ret; } + /// Concatenate something to a sets of elements, move variant. template inline std::set operator+(std::set&& _a, U&& _b) @@ -140,6 +147,8 @@ inline std::multiset& operator-=(std::multiset& _a, C const& _b) return _a; } +} // end namespace std + namespace solidity::util {