Clean-ups and fixes to compile with more warnings enabled and with g++.
[invirt/third/libt4.git] / types.h
diff --git a/types.h b/types.h
index 888cd68..0241bd3 100644 (file)
--- a/types.h
+++ b/types.h
@@ -75,6 +75,9 @@ using std::weak_ptr;
 using std::mutex;
 using lock = std::unique_lock<std::mutex>;
 
+#include <stdexcept>
+using std::runtime_error;
+
 #include <sstream>
 using std::ostringstream;
 using std::istringstream;
@@ -138,6 +141,11 @@ template<typename E> constexpr inline E to_enum(enum_type_t<E> value) noexcept {
 
 // 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=" ") {
@@ -162,6 +170,12 @@ inline vector<string> explode(const string & s, string delim=" ") {
     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"