File indexing completed on 2025-04-19 09:06:54
0001 #ifndef RIVET_RivetSTL_HH
0002 #define RIVET_RivetSTL_HH
0003
0004 #include <string>
0005 #include <array>
0006 #include <vector>
0007 #include <list>
0008 #include <set>
0009 #include <map>
0010 #include <memory>
0011 #include <functional>
0012 #include <ostream>
0013 #include <fstream>
0014 #include <sstream>
0015 #include <cmath>
0016 #include <limits>
0017 #include <complex>
0018
0019 namespace Rivet {
0020
0021
0022
0023
0024 using std::string;
0025 using std::to_string;
0026
0027 using std::ifstream;
0028 using std::ofstream;
0029
0030 using std::array;
0031 using std::vector;
0032 using std::list;
0033 using std::set;
0034 using std::multiset;
0035 using std::map;
0036 using std::multimap;
0037 using std::pair;
0038 using std::make_pair;
0039
0040 using std::unique_ptr;
0041 using std::shared_ptr;
0042 using std::make_shared;
0043 using std::make_unique;
0044 using std::dynamic_pointer_cast;
0045
0046 using std::initializer_list;
0047
0048 using std::function;
0049
0050 using std::isnan;
0051
0052 using std::complex;
0053
0054
0055
0056
0057
0058
0059
0060 template<typename T>
0061 inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
0062 os << "[ ";
0063 for (size_t i=0; i<vec.size(); ++i) {
0064 os << vec[i] << " ";
0065 }
0066 os << "]";
0067 return os;
0068 }
0069
0070
0071 template<typename T>
0072 inline std::ostream& operator<<(std::ostream& os, const std::list<T>& vec) {
0073 os << "[ ";
0074 for (size_t i=0; i<vec.size(); ++i) {
0075 os << vec[i] << " ";
0076 }
0077 os << "]";
0078 return os;
0079 }
0080
0081
0082
0083
0084
0085 typedef vector<std::string> strings;
0086 typedef vector<double> doubles;
0087 typedef vector<float> floats;
0088 typedef vector<int> ints;
0089
0090
0091
0092
0093
0094
0095
0096
0097 inline bool contains(const std::string& s, const std::string& sub) {
0098 return s.find(sub) != string::npos;
0099 }
0100
0101
0102 template <typename T>
0103 inline bool contains(const std::initializer_list<T>& il, const T& x) {
0104 return find(begin(il), end(il), x) != end(il);
0105 }
0106
0107
0108 template <typename T>
0109 inline bool contains(const std::vector<T>& v, const T& x) {
0110 return find(begin(v), end(v), x) != end(v);
0111 }
0112
0113
0114 template <typename T>
0115 inline bool contains(const std::list<T>& l, const T& x) {
0116 return find(begin(l), end(l), x) != end(l);
0117 }
0118
0119
0120 template <typename T>
0121 inline bool contains(const std::set<T>& s, const T& x) {
0122 return find(begin(s), end(s), x) != end(s);
0123 }
0124
0125
0126 template <typename K, typename T>
0127 inline bool has_key(const std::map<K, T>& m, const K& key) {
0128 return m.find(key) != end(m);
0129 }
0130
0131
0132 template <typename K, typename T>
0133 inline bool has_value(const std::map<K, T>& m, const T& val) {
0134 for (typename std::map<K,T>::const_iterator it = begin(m); it != end(m); ++it) {
0135 if (it->second == val) return true;
0136 }
0137 return false;
0138 }
0139
0140
0141 template <typename K, typename T>
0142 inline const T& retrieve(const std::map<K, T>& m, const K& key, const T& fallback) {
0143 return has_key(m, key) ? m[key] : fallback;
0144 }
0145
0146
0147 template <typename K>
0148 inline const std::string& retrieve(const std::map<K, std::string>& m, const K& key, const std::string& fallback) {
0149 return has_key(m, key) ? m.find(key)->second : fallback;
0150 }
0151
0152
0153 template <typename T>
0154 inline const T& retrieve(const std::map<std::string, T>& m, const std::string& key, const T& fallback) {
0155 return has_key(m, key) ? m.find(key)->second : fallback;
0156 }
0157
0158
0159 inline const std::string& retrieve(const std::map<std::string, std::string>& m, const std::string& key, const std::string& fallback) {
0160 return has_key(m, key) ? m.find(key)->second : fallback;
0161 }
0162
0163
0164
0165
0166 }
0167
0168
0169 namespace std {
0170
0171
0172
0173
0174
0175
0176 template <typename T>
0177 inline void operator += (std::vector<T>& v, const T& x) { v.push_back(x); }
0178
0179
0180 template <typename T>
0181 inline void operator += (std::vector<T>& v1, const std::vector<T>& v2) {
0182 for (const auto& x : v2) v1.push_back(x);
0183 }
0184
0185
0186 template <typename T>
0187 inline std::vector<T> operator + (const std::vector<T>& v1, const std::vector<T>& v2) {
0188 std::vector<T> rtn(v1);
0189 rtn += v2;
0190 return rtn;
0191 }
0192
0193
0194
0195 template <typename T>
0196 inline void operator += (std::set<T>& s1, const std::set<T>& s2) {
0197 for (const auto& x : s2) s1.insert(x);
0198 }
0199
0200
0201 template <typename T>
0202 inline std::set<T> operator + (const std::set<T>& s1, const std::set<T>& s2) {
0203 std::set<T> rtn(s1);
0204 rtn += s2;
0205 return rtn;
0206 }
0207
0208
0209
0210
0211
0212
0213
0214
0215 template<typename T, typename... U>
0216 inline uintptr_t get_address(std::function<T(U...)> f) {
0217 typedef T(fnType)(U...);
0218 fnType ** fnPointer = f.template target<fnType*>();
0219 return (fnPointer != nullptr) ? reinterpret_cast<uintptr_t>(*fnPointer) : 0;
0220 }
0221
0222
0223
0224
0225 }
0226
0227 #endif