More dependency check-ups
[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 using std::ios;
54
55 #include <limits>
56 using std::numeric_limits;
57
58 #include <list>
59 using std::list;
60
61 #include <map>
62 using std::map;
63
64 #include <mutex>
65 using std::mutex;
66 using lock = std::unique_lock<std::mutex>;
67 using cond = std::condition_variable;
68 using std::cv_status;
69
70 #include <sstream>
71 using std::ostringstream;
72 using std::istringstream;
73
74 #include <string>
75 using std::string;
76 using std::to_string;
77 using std::stoi;
78
79 #include <thread>
80 using std::thread;
81 using std::call_once;
82 using std::once_flag;
83 namespace this_thread {
84     using namespace std::this_thread;
85 }
86
87 #include <tuple>
88 using std::tuple;
89 using std::get;
90 using std::tie;
91
92 #include <type_traits>
93 using std::decay;
94 using std::true_type;
95 using std::false_type;
96 using std::is_enum;
97 using std::is_member_function_pointer;
98 using std::is_same;
99 using std::underlying_type;
100 using std::enable_if;
101 using std::remove_reference;
102
103 #include <utility>
104 using std::pair;
105 using std::declval;
106 using std::forward;
107
108 #include <vector>
109 using std::vector;
110
111
112 template <class A, typename I=void> struct is_iterable : false_type {};
113
114 template<class A> struct is_iterable<A,
115     decltype(declval<A&>().cbegin(), declval<A&>().cend(), void())
116 > : true_type {};
117
118 template <class C>
119 inline typename enable_if<is_iterable<C>::value, string>::type
120 implode(const C & v, string delim=" ") {
121     if (v.begin() == v.end())
122         return string();
123     ostringstream oss;
124     auto last = prev(v.end());
125     copy(v.begin(), last, ostream_iterator<typename C::value_type>(oss, delim.c_str()));
126     oss << *last;
127     return oss.str();
128 }
129
130 inline vector<string> explode(const string &s, string delim=" ") {
131     vector<string> out;
132     size_t start = 0, end = 0;
133     while ((end = s.find(delim, start)) != string::npos) {
134         out.push_back(s.substr(start, end - start));
135         start = end + 1;
136     }
137     out.push_back(s.substr(start));
138     return out;
139 }
140
141 #include "lang/verify.h"
142 #include "threaded_log.h"
143
144 #define MEMBERS(...) \
145 inline auto _tuple_() -> decltype(tie(__VA_ARGS__)) { return tie(__VA_ARGS__); } \
146 inline auto _tuple_() const -> decltype(tie(__VA_ARGS__)) { return tie(__VA_ARGS__); }
147
148 #define LEXICOGRAPHIC_OPERATOR(_c_, _op_) \
149 inline bool operator _op_(const _c_ &b) const { return _tuple_() _op_ b._tuple_(); }
150
151 #define LEXICOGRAPHIC_COMPARISON(_c_) \
152 LEXICOGRAPHIC_OPERATOR(_c_, <) LEXICOGRAPHIC_OPERATOR(_c_, <=) \
153 LEXICOGRAPHIC_OPERATOR(_c_, >) LEXICOGRAPHIC_OPERATOR(_c_, >=) \
154 LEXICOGRAPHIC_OPERATOR(_c_, ==) LEXICOGRAPHIC_OPERATOR(_c_, !=)
155
156 // The following implementation of tuple_indices is redistributed under the MIT
157 // License as an insubstantial portion of the LLVM compiler infrastructure.
158
159 template <size_t...> struct tuple_indices {};
160 template <size_t S, class IntTuple, size_t E> struct make_indices_imp;
161 template <size_t S, size_t... Indices, size_t E> struct make_indices_imp<S, tuple_indices<Indices...>, E> {
162     typedef typename make_indices_imp<S+1, tuple_indices<Indices..., S>, E>::type type;
163 };
164 template <size_t E, size_t... Indices> struct make_indices_imp<E, tuple_indices<Indices...>, E> {
165     typedef tuple_indices<Indices...> type;
166 };
167 template <size_t E, size_t S=0> struct make_tuple_indices {
168     typedef typename make_indices_imp<S, tuple_indices<>, E>::type type;
169 };
170
171 #include "endian.h"
172
173 #endif