using std::mutex;
using lock = std::unique_lock<std::mutex>;
+#include <stdexcept>
+using std::runtime_error;
+
#include <sstream>
using std::ostringstream;
using std::istringstream;
template <class A, typename I=void> struct is_const_iterable : false_type {};
template<class A> struct is_const_iterable<A,
- decltype(declval<A&>().cbegin(), declval<A&>().cend(), void())
+ decltype(declval<A &>().cbegin(), declval<A &>().cend(), void())
> : true_type {};
template <class A, typename I=void> struct supports_emplace_back : false_type {};
template<class A> struct supports_emplace_back<A,
- decltype(declval<A&>().emplace_back(declval<typename A::value_type>()), void())
+ decltype(declval<A &>().emplace_back(declval<typename A::value_type>()), void())
> : true_type {};
template<typename E>
// string manipulation
+template <class A, class B>
+ostream & operator<<(ostream & o, const pair<A,B> & d) {
+ return o << "<" << d.first << "," << d.second << ">";
+}
+
template <class C>
inline typename enable_if<is_const_iterable<C>::value, string>::type
implode(const C & v, string delim=" ") {
return oss.str();
}
-inline vector<string> explode(const string &s, string delim=" ") {
+inline vector<string> explode(const string & s, string delim=" ") {
vector<string> out;
size_t start = 0, end = 0;
while ((end = s.find(delim, start)) != string::npos) {
return out;
}
+template <class A>
+typename enable_if<is_const_iterable<A>::value && !is_same<A,string>::value, ostream>::type &
+operator<<(ostream & o, const A & a) {
+ return o << "[" << implode(a, ", ") << "]";
+}
+
#include "verify.h"
#include "threaded_log.h"
// 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_, <=) \
// 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 <typename... Args> inline pass(Args&&...) {} };
+struct pass { template <typename... Args> inline pass(Args && ...) {} };
#include "endian.h"