1#ifndef RIVET_RivetSTL_HH
2#define RIVET_RivetSTL_HH
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;
51 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;
153 template <
typename T>
154 inline void operator += (std::vector<T>& v,
const T& x) { v.push_back(x); }
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);
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);
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);
178 template <
typename T>
179 inline std::set<T>
operator + (
const std::set<T>& s1,
const std::set<T>& s2) {
192 template<
typename T,
typename... U>
194 typedef T(fnType)(U...);
195 fnType ** fnPointer = f.template target<fnType*>();
196 return (fnPointer !=
nullptr) ?
reinterpret_cast<uintptr_t
>(*fnPointer) : 0;
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
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