11 using std::min_element;
16 using std::chrono::seconds;
17 using std::chrono::milliseconds;
18 using std::chrono::microseconds;
19 using std::chrono::nanoseconds;
20 using std::chrono::steady_clock;
21 using std::chrono::system_clock;
22 using std::chrono::duration_cast;
23 using std::chrono::time_point_cast;
24 using std::chrono::time_point;
33 #ifndef LIBT4_NO_FUNCTIONAL
37 using std::placeholders::_1;
50 using std::setprecision;
56 using std::numeric_limits;
65 using std::enable_shared_from_this;
66 using std::make_shared;
67 using std::shared_ptr;
68 using std::unique_ptr;
72 using lock = std::unique_lock<std::mutex>;
73 using cond = std::condition_variable;
77 using std::ostringstream;
78 using std::istringstream;
89 namespace this_thread {
90 using namespace std::this_thread;
98 #include <type_traits>
100 using std::true_type;
101 using std::false_type;
103 using std::is_member_function_pointer;
105 using std::underlying_type;
106 using std::enable_if;
107 using std::remove_reference;
108 using std::add_const;
118 // type traits and manipulators
120 template <class A, typename I=void> struct is_const_iterable : false_type {};
122 template<class A> struct is_const_iterable<A,
123 decltype(declval<A&>().cbegin(), declval<A&>().cend(), void())
126 template <class A, typename I=void> struct supports_emplace_back : false_type {};
128 template<class A> struct supports_emplace_back<A,
129 decltype(declval<A&>().emplace_back(declval<typename A::value_type>()), void())
133 using enum_type_t = typename enable_if<is_enum<E>::value, typename underlying_type<E>::type>::type;
134 template<typename E> constexpr inline enum_type_t<E> from_enum(E e) noexcept { return (enum_type_t<E>)e; }
135 template<typename E> constexpr inline E to_enum(enum_type_t<E> value) noexcept { return (E)value; }
137 // string manipulation
140 inline typename enable_if<is_const_iterable<C>::value, string>::type
141 implode(const C & v, string delim=" ") {
142 auto i=v.cbegin(), end=v.cend();
148 oss << delim << *i++;
152 inline vector<string> explode(const string &s, string delim=" ") {
154 size_t start = 0, end = 0;
155 while ((end = s.find(delim, start)) != string::npos) {
156 out.push_back(s.substr(start, end - start));
157 start = end + delim.size();
159 out.push_back(s.substr(start));
163 #include "lang/verify.h"
164 #include "threaded_log.h"
166 // struct tuple adapter, useful for marshalling
173 #define MEMBERS(...) \
174 inline auto _tuple_() -> decltype(tie(__VA_ARGS__)) { return tie(__VA_ARGS__); } \
175 inline auto _tuple_() const -> decltype(tie(__VA_ARGS__)) { return tie(__VA_ARGS__); }
177 // struct ordering and comparison
183 // LEXICOGRAPHIC_COMPARISON(foo)
185 #define LEXICOGRAPHIC_OPERATOR(_c_, _op_) \
186 inline bool operator _op_(const _c_ &b) const { return _tuple_() _op_ b._tuple_(); }
188 #define LEXICOGRAPHIC_COMPARISON(_c_) \
189 LEXICOGRAPHIC_OPERATOR(_c_, <) LEXICOGRAPHIC_OPERATOR(_c_, <=) \
190 LEXICOGRAPHIC_OPERATOR(_c_, >) LEXICOGRAPHIC_OPERATOR(_c_, >=) \
191 LEXICOGRAPHIC_OPERATOR(_c_, ==) LEXICOGRAPHIC_OPERATOR(_c_, !=)
193 // crucial tool for tuple indexing in variadic templates
195 // This implementation of tuple_indices is redistributed under the MIT
196 // License as an insubstantial portion of the LLVM compiler infrastructure.
198 template <size_t...> struct tuple_indices {};
199 template <size_t S, class IntTuple, size_t E> struct make_indices_imp;
200 template <size_t S, size_t... Indices, size_t E> struct make_indices_imp<S, tuple_indices<Indices...>, E> {
201 typedef typename make_indices_imp<S+1, tuple_indices<Indices..., S>, E>::type type;
203 template <size_t E, size_t... Indices> struct make_indices_imp<E, tuple_indices<Indices...>, E> {
204 typedef tuple_indices<Indices...> type;
206 template <size_t E, size_t S=0> struct make_tuple_indices {
207 typedef typename make_indices_imp<S, tuple_indices<>, E>::type type;
210 // Template parameter pack expansion is not allowed in certain contexts, but
211 // brace initializers (for instance, calls to constructors of empty structs)
213 struct pass { template <typename... Args> inline pass(Args&&...) {} };