|
|
Rivet 4.0.0
|
1#ifndef RIVET_RivetSTL_HH
2#define RIVET_RivetSTL_HH
40 using std::unique_ptr;
41 using std::shared_ptr;
42 using std::make_shared;
43 using std::make_unique;
44 using std::dynamic_pointer_cast;
46 using std::initializer_list;
61 inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
63 for ( size_t i=0; i<vec.size(); ++i) {
72 inline std::ostream& operator<<(std::ostream& os, const std::list<T>& vec) {
74 for ( size_t i=0; i<vec.size(); ++i) {
85 typedef vector<std::string> strings;
86 typedef vector<double> doubles;
87 typedef vector<float> floats;
88 typedef vector<int> ints;
97 inline bool contains( const std::string& s, const std::string& sub) {
98 return s.find(sub) != string::npos;
102 template < typename T>
103 inline bool contains( const std::initializer_list<T>& il, const T& x) {
104 return find(begin(il), end(il), x) != end(il);
108 template < typename T>
109 inline bool contains( const std::vector<T>& v, const T& x) {
110 return find(begin(v), end(v), x) != end(v);
114 template < typename T>
115 inline bool contains( const std::list<T>& l, const T& x) {
116 return find(begin(l), end(l), x) != end(l);
120 template < typename T>
121 inline bool contains( const std::set<T>& s, const T& x) {
122 return find(begin(s), end(s), x) != end(s);
126 template < typename K, typename T>
127 inline bool has_key( const std::map<K, T>& m, const K& key) {
128 return m.find(key) != end(m);
132 template < typename K, typename T>
133 inline bool has_value( const std::map<K, T>& m, const T& val) {
134 for ( typename std::map<K,T>::const_iterator it = begin(m); it != end(m); ++it) {
135 if (it->second == val) return true;
141 template < typename K, typename T>
142 inline const T& retrieve( const std::map<K, T>& m, const K& key, const T& fallback) {
143 return has_key(m, key) ? m[key] : fallback;
147 template < typename K>
148 inline const std::string& retrieve( const std::map<K, std::string>& m, const K& key, const std::string& fallback) {
149 return has_key(m, key) ? m.find(key)->second : fallback;
153 template < typename T>
154 inline const T& retrieve( const std::map<std::string, T>& m, const std::string& key, const T& fallback) {
155 return has_key(m, key) ? m.find(key)->second : fallback;
159 inline const std::string& retrieve( const std::map<std::string, std::string>& m, const std::string& key, const std::string& fallback) {
160 return has_key(m, key) ? m.find(key)->second : fallback;
176 template < typename T>
177 inline void operator += (std::vector<T>& v, const T& x) { v.push_back(x); }
180 template < typename T>
181 inline void operator += (std::vector<T>& v1, const std::vector<T>& v2) {
182 for ( const auto& x : v2) v1.push_back(x);
186 template < typename T>
187 inline std::vector<T> operator + ( const std::vector<T>& v1, const std::vector<T>& v2) {
188 std::vector<T> rtn(v1);
195 template < typename T>
196 inline void operator += (std::set<T>& s1, const std::set<T>& s2) {
197 for ( const auto& x : s2) s1.insert(x);
201 template < typename T>
202 inline std::set<T> operator + ( const std::set<T>& s1, const std::set<T>& s2) {
215 template< typename T, typename... U>
217 typedef T(fnType)(U...);
218 fnType ** fnPointer = f.template target<fnType*>();
219 return (fnPointer != nullptr) ? reinterpret_cast<uintptr_t >(*fnPointer) : 0;
Definition MC_CENT_PPB_Projections.hh:10
const T & retrieve(const std::map< K, T > &m, const K &key, const T &fallback) Get the value in map m with key key, or fall back to fallback. Definition RivetSTL.hh:142
bool has_value(const std::map< K, T > &m, const T &val) Does the map m contain the value val? Definition RivetSTL.hh:133
std::ostream & operator<<(std::ostream &os, const AnalysisInfo &ai) Stream an AnalysisInfo as a text description. Definition AnalysisInfo.hh:362
bool contains(const std::string &s, const std::string &sub) Does s contain sub as a substring? Definition RivetSTL.hh:97
bool has_key(const std::map< K, T > &m, const K &key) Does the map m contain the key key? Definition RivetSTL.hh:127
uintptr_t get_address(std::function< T(U...)> f) Get a function pointer / hash integer from an std::function. Definition RivetSTL.hh:216
void operator+=(std::vector< T > &v, const T &x) Append a single item to vector v. Definition RivetSTL.hh:177
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:187
|