From 44c7d4dcb3ad4f4fd31461d886d815052b7d3187 Mon Sep 17 00:00:00 2001 From: wyy Date: Sun, 3 Nov 2013 21:51:29 -0800 Subject: [PATCH] add Limonp/std_outbound.hpp --- src/Limonp/std_outbound.hpp | 101 ++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/Limonp/std_outbound.hpp diff --git a/src/Limonp/std_outbound.hpp b/src/Limonp/std_outbound.hpp new file mode 100644 index 0000000..ab3e5c3 --- /dev/null +++ b/src/Limonp/std_outbound.hpp @@ -0,0 +1,101 @@ +#ifndef LIMONP_STD_OUTBOUND_H +#define LIMONP_STD_OUTBOUND_H + +#include +#include +#include + +namespace std +{ + template + ostream& operator << (ostream& os, const vector& vec) + { + if(vec.empty()) + { + return os << "[]"; + } + os<<"[\""< + ostream& operator << (ostream& os, const pair& pr) + { + os << pr.first << ":" << pr.second ; + return os; + } + + + template + string& operator << (string& str, const T& obj) + { + stringstream ss; + ss << obj; // call ostream& operator << (ostream& os, + return str = ss.str(); + } + + template + ostream& operator << (ostream& os, const map& mp) + { + if(mp.empty()) + { + os<<"{}"; + return os; + } + os<<'{'; + typename map::const_iterator it = mp.begin(); + os<<*it; + it++; + while(it != mp.end()) + { + os<<", "<<*it; + it++; + } + os<<'}'; + return os; + } + template + ostream& operator << (ostream& os, const std::tr1::unordered_map& mp) + { + if(mp.empty()) + { + return os << "{}"; + } + os<<'{'; + typename std::tr1::unordered_map::const_iterator it = mp.begin(); + os<<*it; + it++; + while(it != mp.end()) + { + os<<", "<<*it++; + } + return os<<'}'; + } + + template + ostream& operator << (ostream& os, const set& st) + { + if(st.empty()) + { + os << "{}"; + return os; + } + os<<'{'; + typename set::const_iterator it = st.begin(); + os<<*it; + it++; + while(it != st.end()) + { + os<<", "<<*it; + it++; + } + os<<'}'; + return os; + } +} + +#endif