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