X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/4e881433f37417ccbda89c09ffdf936855d462d4..eb3d5c6416c0f0d1cad35e52af3231de7866fea8:/types.h diff --git a/types.h b/types.h index ede859f..0241bd3 100644 --- a/types.h +++ b/types.h @@ -75,6 +75,9 @@ using std::weak_ptr; using std::mutex; using lock = std::unique_lock; +#include +using std::runtime_error; + #include using std::ostringstream; using std::istringstream; @@ -122,13 +125,13 @@ using std::vector; template struct is_const_iterable : false_type {}; template struct is_const_iterable().cbegin(), declval().cend(), void()) + decltype(declval().cbegin(), declval().cend(), void()) > : true_type {}; template struct supports_emplace_back : false_type {}; template struct supports_emplace_back().emplace_back(declval()), void()) + decltype(declval().emplace_back(declval()), void()) > : true_type {}; template @@ -138,6 +141,11 @@ template constexpr inline E to_enum(enum_type_t value) noexcept { // string manipulation +template +ostream & operator<<(ostream & o, const pair & d) { + return o << "<" << d.first << "," << d.second << ">"; +} + template inline typename enable_if::value, string>::type implode(const C & v, string delim=" ") { @@ -151,7 +159,7 @@ implode(const C & v, string delim=" ") { return oss.str(); } -inline vector explode(const string &s, string delim=" ") { +inline vector explode(const string & s, string delim=" ") { vector out; size_t start = 0, end = 0; while ((end = s.find(delim, start)) != string::npos) { @@ -162,6 +170,12 @@ inline vector explode(const string &s, string delim=" ") { return out; } +template +typename enable_if::value && !is_same::value, ostream>::type & +operator<<(ostream & o, const A & a) { + return o << "[" << implode(a, ", ") << "]"; +} + #include "verify.h" #include "threaded_log.h" @@ -185,7 +199,7 @@ inline auto _tuple_() const -> decltype(tie(__VA_ARGS__)) { return tie(__VA_ARGS // LEXICOGRAPHIC_COMPARISON(foo) #define LEXICOGRAPHIC_OPERATOR(_c_, _op_) \ -inline bool operator _op_(const _c_ &b) const { return _tuple_() _op_ b._tuple_(); } +inline bool operator _op_(const _c_ & b) const { return _tuple_() _op_ b._tuple_(); } #define LEXICOGRAPHIC_COMPARISON(_c_) \ LEXICOGRAPHIC_OPERATOR(_c_, <) LEXICOGRAPHIC_OPERATOR(_c_, <=) \ @@ -212,7 +226,7 @@ template struct make_tuple_indices { // 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&&...) {} }; +struct pass { template inline pass(Args && ...) {} }; #include "endian.h"