X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/24bebc0ecf83446c7371eff69042322aab34976a..c9be386a30dc7145ac757fae66c255b21da26d5d:/types.h diff --git a/types.h b/types.h index e6b5895..cdb629a 100644 --- a/types.h +++ b/types.h @@ -50,6 +50,7 @@ using std::ostream; using std::istream; using std::ostream_iterator; using std::istream_iterator; +using std::ios; #include using std::numeric_limits; @@ -77,6 +78,11 @@ using std::stoi; #include using std::thread; +using std::call_once; +using std::once_flag; +namespace this_thread { + using namespace std::this_thread; +} #include using std::tuple; @@ -92,23 +98,40 @@ using std::is_member_function_pointer; using std::is_same; using std::underlying_type; using std::enable_if; +using std::remove_reference; +using std::add_const; #include using std::pair; using std::declval; +using std::forward; #include using std::vector; +// type traits and manipulators -template struct is_iterable : false_type {}; +template struct is_const_iterable : false_type {}; -template struct is_iterable struct is_const_iterable().cbegin(), declval().cend(), void()) > : true_type {}; +template struct supports_emplace_back : false_type {}; + +template struct supports_emplace_back().emplace_back(declval()), void()) +> : true_type {}; + +template +using enum_type_t = typename enable_if::value, typename underlying_type::type>::type; +template constexpr inline enum_type_t from_enum(E e) noexcept { return (enum_type_t)e; } +template constexpr inline E to_enum(enum_type_t value) noexcept { return (E)value; } + +// string manipulation + template -inline typename enable_if::value, string>::type +inline typename enable_if::value, string>::type implode(const C & v, string delim=" ") { if (v.begin() == v.end()) return string(); @@ -133,10 +156,25 @@ inline vector explode(const string &s, string delim=" ") { #include "lang/verify.h" #include "threaded_log.h" +// struct tuple adapter, useful for marshalling +// used like +// struct foo { +// int a, b; +// MEMBERS(a, b) +// }; + #define MEMBERS(...) \ inline auto _tuple_() -> decltype(tie(__VA_ARGS__)) { return tie(__VA_ARGS__); } \ inline auto _tuple_() const -> decltype(tie(__VA_ARGS__)) { return tie(__VA_ARGS__); } +// struct ordering and comparison +// used like +// struct foo { +// int a, b; +// MEMBERS(a, b) +// }; +// LEXICOGRAPHIC_COMPARISON(foo) + #define LEXICOGRAPHIC_OPERATOR(_c_, _op_) \ inline bool operator _op_(const _c_ &b) const { return _tuple_() _op_ b._tuple_(); } @@ -145,4 +183,28 @@ LEXICOGRAPHIC_OPERATOR(_c_, <) LEXICOGRAPHIC_OPERATOR(_c_, <=) \ LEXICOGRAPHIC_OPERATOR(_c_, >) LEXICOGRAPHIC_OPERATOR(_c_, >=) \ LEXICOGRAPHIC_OPERATOR(_c_, ==) LEXICOGRAPHIC_OPERATOR(_c_, !=) +// crucial tool for tuple indexing in variadic templates +// +// This implementation of tuple_indices is redistributed under the MIT +// License as an insubstantial portion of the LLVM compiler infrastructure. + +template struct tuple_indices {}; +template struct make_indices_imp; +template struct make_indices_imp, E> { + typedef typename make_indices_imp, E>::type type; +}; +template struct make_indices_imp, E> { + typedef tuple_indices type; +}; +template struct make_tuple_indices { + typedef typename make_indices_imp, E>::type type; +}; + +// Template parameter pack expansion is not allowed in certain contexts, but +// brace initializers (for instance, calls to constructors of empty structs) +// are fair game. +struct pass { template inline pass(Args&&...) {} }; + +#include "endian.h" + #endif