Rivet  3.1.3
RivetSTL.hh
1 #ifndef RIVET_RivetSTL_HH
2 #define RIVET_RivetSTL_HH
3 
4 #include <string>
5 #include <array>
6 #include <vector>
7 #include <list>
8 #include <set>
9 #include <map>
10 #include <memory>
11 #include <functional>
12 #include <ostream>
13 #include <sstream>
14 // #include <tuple>
15 // #include <utility>
16 // #include <algorithm>
17 // #include <cassert>
18 // #include <typeinfo>
19 // #include <iomanip>
20 // #include <cmath>
21 // #include <limits>
22 
23 namespace Rivet {
24 
25 
27  // using namespace std;
28  using std::string;
29  using std::to_string;
30 
31  using std::array;
32  using std::vector;
33  using std::list;
34  using std::set;
35  using std::multiset;
36  using std::map;
37  using std::multimap;
38  using std::pair;
39  using std::make_pair;
40 
41  using std::unique_ptr;
42  using std::shared_ptr;
43  using std::make_shared;
44  using std::dynamic_pointer_cast;
45 
46  using std::initializer_list;
47 
48  using std::function;
49 
53 
54 
56  template<typename T>
57  inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
58  os << "[ ";
59  for (size_t i=0; i<vec.size(); ++i) {
60  os << vec[i] << " ";
61  }
62  os << "]";
63  return os;
64  }
65 
67  template<typename T>
68  inline std::ostream& operator<<(std::ostream& os, const std::list<T>& vec) {
69  os << "[ ";
70  for (size_t i=0; i<vec.size(); ++i) {
71  os << vec[i] << " ";
72  }
73  os << "]";
74  return os;
75  }
76 
78 
80 
81  typedef vector<std::string> strings;
82  typedef vector<double> doubles;
83  typedef vector<float> floats;
84  typedef vector<int> ints;
86 
88 
89 
91 
93  inline bool contains(const std::string& s, const std::string& sub) {
94  return s.find(sub) != string::npos;
95  }
96 
98  template <typename T>
99  inline bool contains(const std::initializer_list<T>& il, const T& x) {
100  return find(begin(il), end(il), x) != end(il);
101  }
102 
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);
107  }
108 
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);
113  }
114 
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);
119  }
120 
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);
125  }
126 
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;
132  }
133  return false;
134  }
135 
137 
138 
139 }
140 
141 namespace std {
142 
143 
145 
146 
148  template <typename T>
149  inline void operator += (std::vector<T>& v, const T& x) { v.push_back(x); }
150 
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);
155  }
156 
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);
161  rtn += v2;
162  return rtn;
163  }
164 
165 
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);
170  }
171 
173  template <typename T>
174  inline std::set<T> operator + (const std::set<T>& s1, const std::set<T>& s2) {
175  std::set<T> rtn(s1);
176  rtn += s2;
177  return rtn;
178  }
179 
181 
182 
184 
185 
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;
192  }
193 
195 
196 
197 }
198 
199 #endif
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
STL namespace.
bool contains(const std::string &s, const std::string &sub)
Does s contain sub as a substring?
Definition: RivetSTL.hh:93