diff --git a/include/Rivet/Tools/RivetSTL.hh b/include/Rivet/Tools/RivetSTL.hh --- a/include/Rivet/Tools/RivetSTL.hh +++ b/include/Rivet/Tools/RivetSTL.hh @@ -1,196 +1,196 @@ #ifndef RIVET_RivetSTL_HH #define RIVET_RivetSTL_HH #include #include #include #include #include #include #include - +#include // #include // #include // #include // #include // #include // #include // #include // #include #include #include namespace Rivet { /// We implicitly use STL entities in the Rivet namespace // using namespace std; using std::string; using std::to_string; using std::array; using std::vector; using std::list; using std::set; using std::multiset; using std::map; using std::multimap; using std::pair; using std::make_pair; using std::unique_ptr; using std::shared_ptr; using std::make_shared; using std::dynamic_pointer_cast; using std::initializer_list; using std::function; /// @name Streaming containers as string reps /// @todo Make these named toStr rather than operator<< /// @todo Make these generic to any iterable //@{ /// Convenient function for streaming out vectors of any streamable object. template inline std::ostream& operator<<(std::ostream& os, const std::vector& vec) { os << "[ "; for (size_t i=0; i inline std::ostream& operator<<(std::ostream& os, const std::list& vec) { os << "[ "; for (size_t i=0; i inline bool contains(const std::initializer_list& il, const T& x) { return find(begin(il), end(il), x) != end(il); } /// Does the vector @a v contain @a x? template inline bool contains(const std::vector& v, const T& x) { return find(begin(v), end(v), x) != end(v); } /// Does the list @a l contain @a x? template inline bool contains(const std::list& l, const T& x) { return find(begin(l), end(l), x) != end(l); } /// Does the set @a s contain @a x? template inline bool contains(const std::set& s, const T& x) { return find(begin(s), end(s), x) != end(s); } /// Does the map @a m contain the key @a key? template inline bool has_key(const std::map& m, const K& key) { return m.find(key) != end(m); } /// Does the map @a m contain the value @a val? template inline bool has_value(const std::map& m, const T& val) { for (typename std::map::const_iterator it = begin(m); it != end(m); ++it) { if (it->second == val) return true; } return false; } //@} } namespace std { /// @name Container filling and merging //@{ /// Append a single item to vector @a v template inline void operator+=(std::vector& v, const T& x) { v.push_back(x); } /// Append all the items from vector @a v2 to vector @a v1 template inline void operator+=(std::vector& v1, const std::vector& v2) { for (const auto& x : v2) v1.push_back(x); } /// Create a new vector from the concatenated items in vectors @a v1 and @a v2 template inline std::vector operator+(const std::vector& v1, const std::vector& v2) { std::vector rtn(v1); rtn += v2; return rtn; } /// Merge the contents of set @a s2 into @a s1 template inline void operator+=(std::set& s1, const std::set& s2) { for (const auto& x : s2) s1.insert(x); } /// Merge the contents of sets @a s1 and @a s2 template inline std::set operator+(const std::set& s1, const std::set& s2) { std::set rtn(s1); rtn += s2; return rtn; } //@} /// @name Function helpers //@{ /// Get a function pointer / hash integer from an std::function template inline size_t get_address(std::function f) { typedef T(fnType)(U...); fnType ** fnPointer = f.template target(); return (fnPointer != nullptr) ? reinterpret_cast(*fnPointer) : 0; } //@} } #endif