1 #ifndef RIVET_RivetSTL_HH 2 #define RIVET_RivetSTL_HH 41 using std::unique_ptr;
42 using std::shared_ptr;
43 using std::make_shared;
44 using std::dynamic_pointer_cast;
46 using std::initializer_list;
57 inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
59 for (
size_t i=0; i<vec.size(); ++i) {
68 inline std::ostream& operator<<(std::ostream& os, const std::list<T>& vec) {
70 for (
size_t i=0; i<vec.size(); ++i) {
81 typedef vector<std::string> strings;
82 typedef vector<double> doubles;
83 typedef vector<float> floats;
84 typedef vector<int> ints;
93 inline bool contains(
const std::string& s,
const std::string& sub) {
94 return s.find(sub) != string::npos;
99 inline bool contains(
const std::initializer_list<T>& il,
const T& x) {
100 return find(begin(il), end(il), x) != end(il);
104 template <
typename T>
105 inline bool contains(
const std::vector<T>& v,
const T& x) {
106 return find(begin(v), end(v), x) != end(v);
110 template <
typename T>
111 inline bool contains(
const std::list<T>& l,
const T& x) {
112 return find(begin(l), end(l), x) != end(l);
116 template <
typename T>
117 inline bool contains(
const std::set<T>& s,
const T& x) {
118 return find(begin(s), end(s), x) != end(s);
122 template <
typename K,
typename T>
123 inline bool has_key(
const std::map<K, T>& m,
const K& key) {
124 return m.find(key) != end(m);
128 template <
typename K,
typename T>
129 inline bool has_value(
const std::map<K, T>& m,
const T& val) {
130 for (
typename std::map<K,T>::const_iterator it = begin(m); it != end(m); ++it) {
131 if (it->second == val)
return true;
148 template <
typename T>
149 inline void operator+=(std::vector<T>& v,
const T& x) { v.push_back(x); }
152 template <
typename T>
153 inline void operator+=(std::vector<T>& v1,
const std::vector<T>& v2) {
154 for (
const auto& x : v2) v1.push_back(x);
158 template <
typename T>
159 inline std::vector<T> operator+(
const std::vector<T>& v1,
const std::vector<T>& v2) {
160 std::vector<T> rtn(v1);
167 template <
typename T>
168 inline void operator+=(std::set<T>& s1,
const std::set<T>& s2) {
169 for (
const auto& x : s2) s1.insert(x);
173 template <
typename T>
174 inline std::set<T> operator+(
const std::set<T>& s1,
const std::set<T>& s2) {
187 template<
typename T,
typename... U>
188 inline uintptr_t get_address(std::function<T(U...)> f) {
189 typedef T(fnType)(U...);
190 fnType ** fnPointer = f.template target<fnType*>();
191 return (fnPointer !=
nullptr) ?
reinterpret_cast<uintptr_t
>(*fnPointer) : 0;
Definition: MC_Cent_pPb.hh:10
bool has_value(const std::map< K, T > &m, const T &val)
Does the map m contain the value val?
Definition: RivetSTL.hh:129
bool has_key(const std::map< K, T > &m, const K &key)
Does the map m contain the key key?
Definition: RivetSTL.hh:123
bool contains(const std::string &s, const std::string &sub)
Does s contain sub as a substring?
Definition: RivetSTL.hh:93