Rivet 3.1.9
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 <fstream>
14#include <sstream>
15// #include <tuple>
16// #include <utility>
17// #include <algorithm>
18// #include <cassert>
19// #include <typeinfo>
20// #include <iomanip>
21// #include <cmath>
22// #include <limits>
23
24namespace Rivet {
25
26
28 // using namespace std;
29 using std::string;
30 using std::to_string;
31
32 using std::ifstream;
33 using std::ofstream;
34
35 using std::array;
36 using std::vector;
37 using std::list;
38 using std::set;
39 using std::multiset;
40 using std::map;
41 using std::multimap;
42 using std::pair;
43 using std::make_pair;
44
45 using std::unique_ptr;
46 using std::shared_ptr;
47 using std::make_shared;
48 using std::make_unique;
49 using std::dynamic_pointer_cast;
50
51 using std::initializer_list;
52
53 using std::function;
54
58
59
61 template<typename T>
62 inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
63 os << "[ ";
64 for (size_t i=0; i<vec.size(); ++i) {
65 os << vec[i] << " ";
66 }
67 os << "]";
68 return os;
69 }
70
72 template<typename T>
73 inline std::ostream& operator<<(std::ostream& os, const std::list<T>& vec) {
74 os << "[ ";
75 for (size_t i=0; i<vec.size(); ++i) {
76 os << vec[i] << " ";
77 }
78 os << "]";
79 return os;
80 }
81
83
85
86 typedef vector<std::string> strings;
87 typedef vector<double> doubles;
88 typedef vector<float> floats;
89 typedef vector<int> ints;
91
93
94
96
98 inline bool contains(const std::string& s, const std::string& sub) {
99 return s.find(sub) != string::npos;
100 }
101
103 template <typename T>
104 inline bool contains(const std::initializer_list<T>& il, const T& x) {
105 return find(begin(il), end(il), x) != end(il);
106 }
107
109 template <typename T>
110 inline bool contains(const std::vector<T>& v, const T& x) {
111 return find(begin(v), end(v), x) != end(v);
112 }
113
115 template <typename T>
116 inline bool contains(const std::list<T>& l, const T& x) {
117 return find(begin(l), end(l), x) != end(l);
118 }
119
121 template <typename T>
122 inline bool contains(const std::set<T>& s, const T& x) {
123 return find(begin(s), end(s), x) != end(s);
124 }
125
127 template <typename K, typename T>
128 inline bool has_key(const std::map<K, T>& m, const K& key) {
129 return m.find(key) != end(m);
130 }
131
133 template <typename K, typename T>
134 inline bool has_value(const std::map<K, T>& m, const T& val) {
135 for (typename std::map<K,T>::const_iterator it = begin(m); it != end(m); ++it) {
136 if (it->second == val) return true;
137 }
138 return false;
139 }
140
142
143
144}
145
146namespace std {
147
148
150
151
153 template <typename T>
154 inline void operator += (std::vector<T>& v, const T& x) { v.push_back(x); }
155
157 template <typename T>
158 inline void operator += (std::vector<T>& v1, const std::vector<T>& v2) {
159 for (const auto& x : v2) v1.push_back(x);
160 }
161
163 template <typename T>
164 inline std::vector<T> operator + (const std::vector<T>& v1, const std::vector<T>& v2) {
165 std::vector<T> rtn(v1);
166 rtn += v2;
167 return rtn;
168 }
169
170
172 template <typename T>
173 inline void operator += (std::set<T>& s1, const std::set<T>& s2) {
174 for (const auto& x : s2) s1.insert(x);
175 }
176
178 template <typename T>
179 inline std::set<T> operator + (const std::set<T>& s1, const std::set<T>& s2) {
180 std::set<T> rtn(s1);
181 rtn += s2;
182 return rtn;
183 }
184
186
187
189
190
192 template<typename T, typename... U>
193 inline uintptr_t get_address(std::function<T(U...)> f) {
194 typedef T(fnType)(U...);
195 fnType ** fnPointer = f.template target<fnType*>();
196 return (fnPointer != nullptr) ? reinterpret_cast<uintptr_t>(*fnPointer) : 0;
197 }
198
200
201
202}
203
204#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:134
std::ostream & operator<<(std::ostream &os, const AnalysisInfo &ai)
Stream an AnalysisInfo as a text description.
Definition AnalysisInfo.hh:368
bool contains(const std::string &s, const std::string &sub)
Does s contain sub as a substring?
Definition RivetSTL.hh:98
bool has_key(const std::map< K, T > &m, const K &key)
Does the map m contain the key key?
Definition RivetSTL.hh:128
STL namespace.
uintptr_t get_address(std::function< T(U...)> f)
Get a function pointer / hash integer from an std::function.
Definition RivetSTL.hh:193
void operator+=(std::vector< T > &v, const T &x)
Append a single item to vector v.
Definition RivetSTL.hh:154
std::vector< T > operator+(const std::vector< T > &v1, const std::vector< T > &v2)
Create a new vector from the concatenated items in vectors v1 and v2.
Definition RivetSTL.hh:164