tan  0.0.1
container.h
1 #ifndef __TAN_SRC_BASE_CONTAINER_H__
2 #define __TAN_SRC_BASE_CONTAINER_H__
3 
4 #include <unordered_map>
5 #include <unordered_set>
6 #include <vector>
7 #include <stack>
8 #include <string>
9 #include <memory>
10 #include <functional>
11 
12 template <typename T> using vector = std::vector<T>;
13 
14 using str = std::string;
15 using str_view = std::string_view;
16 
17 template <typename Key, typename Value, typename Hash = std::hash<Key>>
18 using umap = std::unordered_map<Key, Value, Hash>;
19 
20 template <typename Key, typename Hash = std::hash<Key>> using uset = std::unordered_set<Key, Hash>;
21 
22 using std::pair;
23 using std::stack;
24 
25 struct PairHash {
26  template <class T1, class T2> std::size_t operator()(const pair<T1, T2> &p) const {
27  // https://stackoverflow.com/questions/5889238/why-is-xor-the-default-way-to-combine-hashes/27952689#27952689
28  size_t lhs = std::hash<T1>{}(p.first);
29  size_t rhs = std::hash<T2>{}(p.second);
30  lhs ^= rhs + 0x9e3779b9 + (lhs << 6) + (lhs >> 2);
31  return lhs;
32  }
33 };
34 
35 inline bool is_string_in(const str &s, const vector<str> &list) {
36  return std::find(list.begin(), list.end(), s) != list.end();
37 }
38 
39 #endif //__TAN_SRC_BASE_CONTAINER_H__