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;
54 using std::numeric_limits;
64 using lock = std::unique_lock<std::mutex>;
65 using cond = std::condition_variable;
69 using std::ostringstream;
70 using std::istringstream;
81 namespace this_thread {
82 using namespace std::this_thread;
90 #include <type_traits>
93 using std::false_type;
95 using std::is_member_function_pointer;
97 using std::underlying_type;
99 using std::remove_reference;
100 using std::add_const;
110 // type traits and manipulators
112 template <class A, typename I=void> struct is_const_iterable : false_type {};
114 template<class A> struct is_const_iterable<A,
115 decltype(declval<A&>().cbegin(), declval<A&>().cend(), void())
118 template <class A, typename I=void> struct supports_emplace_back : false_type {};
120 template<class A> struct supports_emplace_back<A,
121 decltype(declval<A&>().emplace_back(declval<typename A::value_type>()), void())
125 using enum_type_t = typename enable_if<is_enum<E>::value, typename underlying_type<E>::type>::type;
126 template<typename E> constexpr inline enum_type_t<E> from_enum(E e) noexcept { return (enum_type_t<E>)e; }
127 template<typename E> constexpr inline E to_enum(enum_type_t<E> value) noexcept { return (E)value; }
129 // string manipulation
132 inline typename enable_if<is_const_iterable<C>::value, string>::type
133 implode(const C & v, string delim=" ") {
134 auto i=v.cbegin(), end=v.cend();
140 oss << delim << *i++;
144 inline vector<string> explode(const string &s, string delim=" ") {
146 size_t start = 0, end = 0;
147 while ((end = s.find(delim, start)) != string::npos) {
148 out.push_back(s.substr(start, end - start));
149 start = end + delim.size();
151 out.push_back(s.substr(start));
155 #include "lang/verify.h"
156 #include "threaded_log.h"
158 // struct tuple adapter, useful for marshalling
165 #define MEMBERS(...) \
166 inline auto _tuple_() -> decltype(tie(__VA_ARGS__)) { return tie(__VA_ARGS__); } \
167 inline auto _tuple_() const -> decltype(tie(__VA_ARGS__)) { return tie(__VA_ARGS__); }
169 // struct ordering and comparison
175 // LEXICOGRAPHIC_COMPARISON(foo)
177 #define LEXICOGRAPHIC_OPERATOR(_c_, _op_) \
178 inline bool operator _op_(const _c_ &b) const { return _tuple_() _op_ b._tuple_(); }
180 #define LEXICOGRAPHIC_COMPARISON(_c_) \
181 LEXICOGRAPHIC_OPERATOR(_c_, <) LEXICOGRAPHIC_OPERATOR(_c_, <=) \
182 LEXICOGRAPHIC_OPERATOR(_c_, >) LEXICOGRAPHIC_OPERATOR(_c_, >=) \
183 LEXICOGRAPHIC_OPERATOR(_c_, ==) LEXICOGRAPHIC_OPERATOR(_c_, !=)
185 // crucial tool for tuple indexing in variadic templates
187 // This implementation of tuple_indices is redistributed under the MIT
188 // License as an insubstantial portion of the LLVM compiler infrastructure.
190 template <size_t...> struct tuple_indices {};
191 template <size_t S, class IntTuple, size_t E> struct make_indices_imp;
192 template <size_t S, size_t... Indices, size_t E> struct make_indices_imp<S, tuple_indices<Indices...>, E> {
193 typedef typename make_indices_imp<S+1, tuple_indices<Indices..., S>, E>::type type;
195 template <size_t E, size_t... Indices> struct make_indices_imp<E, tuple_indices<Indices...>, E> {
196 typedef tuple_indices<Indices...> type;
198 template <size_t E, size_t S=0> struct make_tuple_indices {
199 typedef typename make_indices_imp<S, tuple_indices<>, E>::type type;
202 // Template parameter pack expansion is not allowed in certain contexts, but
203 // brace initializers (for instance, calls to constructors of empty structs)
205 struct pass { template <typename... Args> inline pass(Args&&...) {} };