rivet is hosted by Hepforge, IPPP Durham
Rivet  2.7.0
RivetSTL.hh
1 #ifndef RIVET_RivetSTL_HH
2 #define RIVET_RivetSTL_HH
3 
4 #include <string>
5 #include <array>
6 #include <vector>
7 #include <set>
8 #include <list>
9 #include <map>
10 #include <utility>
11 #include <tuple>
12 #include <algorithm>
13 #include <type_traits>
14 #include <stdexcept>
15 #include <cassert>
16 #include <memory>
17 #include <typeinfo>
18 #include <sstream>
19 #include <fstream>
20 #include <iostream>
21 #include <iomanip>
22 #include <cmath>
23 #include <limits>
24 #include <functional>
25 
26 
27 #ifndef foreach
28 #define foreach(value, container) for (value : container)
30 #endif
31 
32 
33 namespace Rivet {
34 
35 
37  using namespace std;
38 
39 
43 
44 
46  template<typename T>
47  inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
48  os << "[ ";
49  for (size_t i=0; i<vec.size(); ++i) {
50  os << vec[i] << " ";
51  }
52  os << "]";
53  return os;
54  }
55 
57  template<typename T>
58  inline std::ostream& operator<<(std::ostream& os, const std::list<T>& vec) {
59  os << "[ ";
60  for (size_t i=0; i<vec.size(); ++i) {
61  os << vec[i] << " ";
62  }
63  os << "]";
64  return os;
65  }
66 
68 
69 
71 
72 
74 
76  inline bool contains(const std::string& s, const std::string& sub) {
77  return s.find(sub) != string::npos;
78  }
79 
81  template <typename T>
82  inline bool contains(const std::initializer_list<T>& il, const T& x) {
83  return find(begin(il), end(il), x) != end(il);
84  }
85 
87  template <typename T>
88  inline bool contains(const std::vector<T>& v, const T& x) {
89  return find(begin(v), end(v), x) != end(v);
90  }
91 
93  template <typename T>
94  inline bool contains(const std::list<T>& l, const T& x) {
95  return find(begin(l), end(l), x) != end(l);
96  }
97 
99  template <typename T>
100  inline bool contains(const std::set<T>& s, const T& x) {
101  return find(begin(s), end(s), x) != end(s);
102  }
103 
105  template <typename K, typename T>
106  inline bool has_key(const std::map<K, T>& m, const K& key) {
107  return m.find(key) != end(m);
108  }
109 
111  template <typename K, typename T>
112  inline bool has_value(const std::map<K, T>& m, const T& val) {
113  for (typename std::map<K,T>::const_iterator it = begin(m); it != end(m); ++it) {
114  if (it->second == val) return true;
115  }
116  return false;
117  }
118 
120 
121 
122 }
123 
124 namespace std {
125 
126 
128 
129 
131  template <typename T>
132  inline void operator+=(std::vector<T>& v, const T& x) { v.push_back(x); }
133 
135  template <typename T>
136  inline void operator+=(std::vector<T>& v1, const std::vector<T>& v2) {
137  for (const auto& x : v2) v1.push_back(x);
138  }
139 
141  template <typename T>
142  inline std::vector<T> operator+(const std::vector<T>& v1, const std::vector<T>& v2) {
143  std::vector<T> rtn(v1);
144  rtn += v2;
145  return rtn;
146  }
147 
148 
150  template <typename T>
151  inline void operator+=(std::set<T>& s1, const std::set<T>& s2) {
152  for (const auto& x : s2) s1.insert(x);
153  }
154 
156  template <typename T>
157  inline std::set<T> operator+(const std::set<T>& s1, const std::set<T>& s2) {
158  std::set<T> rtn(s1);
159  rtn += s2;
160  return rtn;
161  }
162 
164 
165 
167 
168 
170  template<typename T, typename... U>
171  inline size_t get_address(std::function<T(U...)> f) {
172  typedef T(fnType)(U...);
173  fnType ** fnPointer = f.template target<fnType*>();
174  return (fnPointer != nullptr) ? reinterpret_cast<size_t>(*fnPointer) : 0;
175  }
176 
178 
179 
180 }
181 
182 #endif
Definition: ALICE_2010_I880049.cc:13
bool has_value(const std::map< K, T > &m, const T &val)
Does the map m contain the value val?
Definition: RivetSTL.hh:112
bool has_key(const std::map< K, T > &m, const K &key)
Does the map m contain the key key?
Definition: RivetSTL.hh:106
STL namespace.
bool contains(const std::string &s, const std::string &sub)
Does s contain sub as a substring?
Definition: RivetSTL.hh:76