|
 |
Rivet 4.0.3
|
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::make_unique;
45 using std::dynamic_pointer_cast;
47 using std::initializer_list;
62 inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
64 for ( size_t i=0; i<vec.size(); ++i) {
73 inline std::ostream& operator<<(std::ostream& os, const std::list<T>& vec) {
75 for ( size_t i=0; i<vec.size(); ++i) {
86 typedef vector<std::string> strings;
87 typedef vector<double> doubles;
88 typedef vector<float> floats;
89 typedef vector<int> ints;
98 inline bool contains( const std::string& s, const std::string& sub) {
99 return s.find(sub) != string::npos;
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);
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);
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);
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);
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);
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;
142 template < typename K, typename T>
143 inline const T& retrieve( const std::map<K, T>& m, const K& key, const T& fallback) {
144 return has_key(m, key) ? m[key] : fallback;
148 template < typename K>
149 inline const std::string& retrieve( const std::map<K, std::string>& m, const K& key, const std::string& fallback) {
150 return has_key(m, key) ? m.find(key)->second : fallback;
154 template < typename T>
155 inline const T& retrieve( const std::map<std::string, T>& m, const std::string& key, const T& fallback) {
156 return has_key(m, key) ? m.find(key)->second : fallback;
160 inline const std::string& retrieve( const std::map<std::string, std::string>& m, const std::string& key, const std::string& fallback) {
161 return has_key(m, key) ? m.find(key)->second : fallback;
177 template < typename T>
178 inline void operator += (std::vector<T>& v, const T& x) { v.push_back(x); }
181 template < typename T>
182 inline void operator += (std::vector<T>& v1, const std::vector<T>& v2) {
183 for ( const auto& x : v2) v1.push_back(x);
187 template < typename T>
188 inline std::vector<T> operator + ( const std::vector<T>& v1, const std::vector<T>& v2) {
189 std::vector<T> rtn(v1);
196 template < typename T>
197 inline void operator += (std::set<T>& s1, const std::set<T>& s2) {
198 for ( const auto& x : s2) s1.insert(x);
202 template < typename T>
203 inline std::set<T> operator + ( const std::set<T>& s1, const std::set<T>& s2) {
216 template< typename T, typename... U>
218 typedef T(fnType)(U...);
219 fnType ** fnPointer = f.template target<fnType*>();
220 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:143
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:362
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
uintptr_t get_address(std::function< T(U...)> f) Get a function pointer / hash integer from an std::function. Definition RivetSTL.hh:217
void operator+=(std::vector< T > &v, const T &x) Append a single item to vector v. Definition RivetSTL.hh:178
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:188
|