e6b58950cf0828031596ad077d4842245d9220b3
[invirt/third/libt4.git] / types.h
1 #ifndef types_h
2 #define types_h
3
4 #include <algorithm>
5 using std::copy;
6 using std::move;
7 using std::max;
8 using std::min;
9 using std::min_element;
10 using std::find;
11 using std::count_if;
12
13 #include <chrono>
14 using std::chrono::seconds;
15 using std::chrono::milliseconds;
16 using std::chrono::microseconds;
17 using std::chrono::nanoseconds;
18 using std::chrono::steady_clock;
19 using std::chrono::system_clock;
20 using std::chrono::duration_cast;
21 using std::chrono::time_point_cast;
22 using std::chrono::time_point;
23
24 #include <exception>
25 using std::exception;
26
27 #include <fstream>
28 using std::ofstream;
29 using std::ifstream;
30
31 #ifndef LIBT4_NO_FUNCTIONAL
32 #include <functional>
33 using std::function;
34 using std::bind;
35 using std::placeholders::_1;
36 #endif
37
38 #include <iomanip>
39 #include <iostream>
40 using std::cout;
41 using std::cerr;
42 using std::endl;
43 using std::dec;
44 using std::hex;
45 using std::left;
46 using std::setw;
47 using std::setfill;
48 using std::setprecision;
49 using std::ostream;
50 using std::istream;
51 using std::ostream_iterator;
52 using std::istream_iterator;
53
54 #include <limits>
55 using std::numeric_limits;
56
57 #include <list>
58 using std::list;
59
60 #include <map>
61 using std::map;
62
63 #include <mutex>
64 using std::mutex;
65 using lock = std::unique_lock<std::mutex>;
66 using cond = std::condition_variable;
67 using std::cv_status;
68
69 #include <sstream>
70 using std::ostringstream;
71 using std::istringstream;
72
73 #include <string>
74 using std::string;
75 using std::to_string;
76 using std::stoi;
77
78 #include <thread>
79 using std::thread;
80
81 #include <tuple>
82 using std::tuple;
83 using std::get;
84 using std::tie;
85
86 #include <type_traits>
87 using std::decay;
88 using std::true_type;
89 using std::false_type;
90 using std::is_enum;
91 using std::is_member_function_pointer;
92 using std::is_same;
93 using std::underlying_type;
94 using std::enable_if;
95
96 #include <utility>
97 using std::pair;
98 using std::declval;
99
100 #include <vector>
101 using std::vector;
102
103
104 template <class A, typename I=void> struct is_iterable : false_type {};
105
106 template<class A> struct is_iterable<A,
107     decltype(declval<A&>().cbegin(), declval<A&>().cend(), void())
108 > : true_type {};
109
110 template <class C>
111 inline typename enable_if<is_iterable<C>::value, string>::type
112 implode(const C & v, string delim=" ") {
113     if (v.begin() == v.end())
114         return string();
115     ostringstream oss;
116     auto last = prev(v.end());
117     copy(v.begin(), last, ostream_iterator<typename C::value_type>(oss, delim.c_str()));
118     oss << *last;
119     return oss.str();
120 }
121
122 inline vector<string> explode(const string &s, string delim=" ") {
123     vector<string> out;
124     size_t start = 0, end = 0;
125     while ((end = s.find(delim, start)) != string::npos) {
126         out.push_back(s.substr(start, end - start));
127         start = end + 1;
128     }
129     out.push_back(s.substr(start));
130     return out;
131 }
132
133 #include "lang/verify.h"
134 #include "threaded_log.h"
135
136 #define MEMBERS(...) \
137 inline auto _tuple_() -> decltype(tie(__VA_ARGS__)) { return tie(__VA_ARGS__); } \
138 inline auto _tuple_() const -> decltype(tie(__VA_ARGS__)) { return tie(__VA_ARGS__); }
139
140 #define LEXICOGRAPHIC_OPERATOR(_c_, _op_) \
141 inline bool operator _op_(const _c_ &b) const { return _tuple_() _op_ b._tuple_(); }
142
143 #define LEXICOGRAPHIC_COMPARISON(_c_) \
144 LEXICOGRAPHIC_OPERATOR(_c_, <) LEXICOGRAPHIC_OPERATOR(_c_, <=) \
145 LEXICOGRAPHIC_OPERATOR(_c_, >) LEXICOGRAPHIC_OPERATOR(_c_, >=) \
146 LEXICOGRAPHIC_OPERATOR(_c_, ==) LEXICOGRAPHIC_OPERATOR(_c_, !=)
147
148 #endif