1 #ifndef RIVET_RivetSTL_HH 2 #define RIVET_RivetSTL_HH 13 #include <type_traits> 28 #define foreach(value, container) for (value : container) 47 inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
49 for (
size_t i=0; i<vec.size(); ++i) {
58 inline std::ostream& operator<<(std::ostream& os, const std::list<T>& vec) {
60 for (
size_t i=0; i<vec.size(); ++i) {
76 inline bool contains(
const std::string& s,
const std::string& sub) {
77 return s.find(sub) != string::npos;
82 inline bool contains(
const std::initializer_list<T>& il,
const T& x) {
83 return find(begin(il), end(il), x) != end(il);
88 inline bool contains(
const std::vector<T>& v,
const T& x) {
89 return find(begin(v), end(v), x) != end(v);
94 inline bool contains(
const std::list<T>& l,
const T& x) {
95 return find(begin(l), end(l), x) != end(l);
100 inline bool contains(
const std::set<T>& s,
const T& x) {
101 return find(begin(s), end(s), x) != end(s);
105 template <
typename K,
typename T>
106 inline bool has_key(
const std::map<K, T>& m,
const K& key) {
107 return m.find(key) != end(m);
111 template <
typename K,
typename T>
112 inline bool has_value(
const std::map<K, T>& m,
const T& val) {
113 for (
typename std::map<K,T>::const_iterator it = begin(m); it != end(m); ++it) {
114 if (it->second == val)
return true;
131 template <
typename T>
132 inline void operator+=(std::vector<T>& v,
const T& x) { v.push_back(x); }
135 template <
typename T>
136 inline void operator+=(std::vector<T>& v1,
const std::vector<T>& v2) {
137 for (
const auto& x : v2) v1.push_back(x);
141 template <
typename T>
142 inline std::vector<T> operator+(
const std::vector<T>& v1,
const std::vector<T>& v2) {
143 std::vector<T> rtn(v1);
150 template <
typename T>
151 inline void operator+=(std::set<T>& s1,
const std::set<T>& s2) {
152 for (
const auto& x : s2) s1.insert(x);
156 template <
typename T>
157 inline std::set<T> operator+(
const std::set<T>& s1,
const std::set<T>& s2) {
170 template<
typename T,
typename... U>
171 inline size_t get_address(std::function<T(U...)> f) {
172 typedef T(fnType)(U...);
173 fnType ** fnPointer = f.template target<fnType*>();
174 return (fnPointer !=
nullptr) ?
reinterpret_cast<size_t>(*fnPointer) : 0;
Definition: ALICE_2010_I880049.cc:13
bool has_value(const std::map< K, T > &m, const T &val)
Does the map m contain the value val?
Definition: RivetSTL.hh:112
bool has_key(const std::map< K, T > &m, const K &key)
Does the map m contain the key key?
Definition: RivetSTL.hh:106
bool contains(const std::string &s, const std::string &sub)
Does s contain sub as a substring?
Definition: RivetSTL.hh:76