X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/eb3d5c6416c0f0d1cad35e52af3231de7866fea8..26ade07ab0e62b98b452fbbd18edba0450035e35:/types.h diff --git a/types.h b/types.h index 0241bd3..7de35e9 100644 --- a/types.h +++ b/types.h @@ -4,14 +4,6 @@ #include #include -using std::copy; -using std::count_if; -using std::find; -using std::max; -using std::min; -using std::min_element; -using std::move; -using std::swap; #include using cond = std::condition_variable; @@ -29,31 +21,15 @@ using std::chrono::time_point; using std::chrono::time_point_cast; #include -using std::exception; #include using std::ifstream; using std::ofstream; #include -// std::bind conflicts with BIND(2) -using std::function; -using std::placeholders::_1; #include #include -using std::cout; -using std::cerr; -using std::endl; -using std::dec; -using std::hex; -using std::left; -using std::setw; -using std::setfill; -using std::setprecision; -using std::ostream; -using std::istream; -using std::ios; #include using std::numeric_limits; @@ -79,8 +55,6 @@ using lock = std::unique_lock; using std::runtime_error; #include -using std::ostringstream; -using std::istringstream; #include using std::string; @@ -139,10 +113,17 @@ using enum_type_t = typename enable_if::value, typename underlying_ty 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; } + +template struct is_tuple_convertible : false_type {}; + +template struct is_tuple_convertible()._tuple_(), void()) +> : true_type {}; + // string manipulation template -ostream & operator<<(ostream & o, const pair & d) { +std::ostream & operator<<(std::ostream & o, const pair & d) { return o << "<" << d.first << "," << d.second << ">"; } @@ -152,7 +133,7 @@ implode(const C & v, string delim=" ") { auto i=v.cbegin(), end=v.cend(); if (i == end) return string(); - ostringstream oss; + std::ostringstream oss; oss << *i++; while (i != end) oss << delim << *i++; @@ -171,16 +152,16 @@ inline vector explode(const string & s, string delim=" ") { } template -typename enable_if::value && !is_same::value, ostream>::type & -operator<<(ostream & o, const A & a) { +typename enable_if::value && !is_same::value, std::ostream>::type & +operator<<(std::ostream & o, const A & a) { return o << "[" << implode(a, ", ") << "]"; } #include "verify.h" #include "threaded_log.h" -// struct tuple adapter, useful for marshalling -// used like +// struct tuple adapter, useful for marshalling and endian swapping. usage: +// // struct foo { // int a, b; // MEMBERS(a, b) @@ -190,12 +171,9 @@ operator<<(ostream & o, const A & a) { 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) -// }; +// struct ordering and comparison operations; requires the use of MEMBERS. +// usage: +// // LEXICOGRAPHIC_COMPARISON(foo) #define LEXICOGRAPHIC_OPERATOR(_c_, _op_) \ @@ -223,6 +201,8 @@ template struct make_tuple_indices { typedef typename make_indices_imp, E>::type type; }; +#define TUPLE_INDICES(_ArgPack_) typename make_tuple_indices::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.