9 using std::min_element;
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;
31 #ifndef LIBT4_NO_FUNCTIONAL
35 using std::placeholders::_1;
48 using std::setprecision;
51 using std::ostream_iterator;
52 using std::istream_iterator;
56 using std::numeric_limits;
66 using lock = std::unique_lock<std::mutex>;
67 using cond = std::condition_variable;
71 using std::ostringstream;
72 using std::istringstream;
83 namespace this_thread {
84 using namespace std::this_thread;
92 #include <type_traits>
95 using std::false_type;
97 using std::is_member_function_pointer;
99 using std::underlying_type;
100 using std::enable_if;
101 using std::remove_reference;
102 using std::add_const;
112 // type traits and manipulators
114 template <class A, typename I=void> struct is_const_iterable : false_type {};
116 template<class A> struct is_const_iterable<A,
117 decltype(declval<A&>().cbegin(), declval<A&>().cend(), void())
120 template <class A, typename I=void> struct supports_emplace_back : false_type {};
122 template<class A> struct supports_emplace_back<A,
123 decltype(declval<A&>().emplace_back(declval<typename A::value_type>()), void())
127 using enum_type_t = typename enable_if<is_enum<E>::value, typename underlying_type<E>::type>::type;
128 template<typename E> constexpr inline enum_type_t<E> from_enum(E e) noexcept { return (enum_type_t<E>)e; }
129 template<typename E> constexpr inline E to_enum(enum_type_t<E> value) noexcept { return (E)value; }
131 // string manipulation
134 inline typename enable_if<is_const_iterable<C>::value, string>::type
135 implode(const C & v, string delim=" ") {
136 if (v.begin() == v.end())
139 auto last = prev(v.end());
140 copy(v.begin(), last, ostream_iterator<typename C::value_type>(oss, delim.c_str()));
145 inline vector<string> explode(const string &s, string delim=" ") {
147 size_t start = 0, end = 0;
148 while ((end = s.find(delim, start)) != string::npos) {
149 out.push_back(s.substr(start, end - start));
152 out.push_back(s.substr(start));
156 #include "lang/verify.h"
157 #include "threaded_log.h"
159 // struct tuple adapter, useful for marshalling
166 #define MEMBERS(...) \
167 inline auto _tuple_() -> decltype(tie(__VA_ARGS__)) { return tie(__VA_ARGS__); } \
168 inline auto _tuple_() const -> decltype(tie(__VA_ARGS__)) { return tie(__VA_ARGS__); }
170 // struct ordering and comparison
176 // LEXICOGRAPHIC_COMPARISON(foo)
178 #define LEXICOGRAPHIC_OPERATOR(_c_, _op_) \
179 inline bool operator _op_(const _c_ &b) const { return _tuple_() _op_ b._tuple_(); }
181 #define LEXICOGRAPHIC_COMPARISON(_c_) \
182 LEXICOGRAPHIC_OPERATOR(_c_, <) LEXICOGRAPHIC_OPERATOR(_c_, <=) \
183 LEXICOGRAPHIC_OPERATOR(_c_, >) LEXICOGRAPHIC_OPERATOR(_c_, >=) \
184 LEXICOGRAPHIC_OPERATOR(_c_, ==) LEXICOGRAPHIC_OPERATOR(_c_, !=)
186 // crucial tool for tuple indexing in variadic templates
188 // This implementation of tuple_indices is redistributed under the MIT
189 // License as an insubstantial portion of the LLVM compiler infrastructure.
191 template <size_t...> struct tuple_indices {};
192 template <size_t S, class IntTuple, size_t E> struct make_indices_imp;
193 template <size_t S, size_t... Indices, size_t E> struct make_indices_imp<S, tuple_indices<Indices...>, E> {
194 typedef typename make_indices_imp<S+1, tuple_indices<Indices..., S>, E>::type type;
196 template <size_t E, size_t... Indices> struct make_indices_imp<E, tuple_indices<Indices...>, E> {
197 typedef tuple_indices<Indices...> type;
199 template <size_t E, size_t S=0> struct make_tuple_indices {
200 typedef typename make_indices_imp<S, tuple_indices<>, E>::type type;
203 // Template parameter pack expansion is not allowed in certain contexts, but
204 // brace initializers (for instance, calls to constructors of empty structs)
206 struct pass { template <typename... Args> inline pass(Args&&...) {} };