Created
April 19, 2009 04:46
-
-
Save naoyat/97924 to your computer and use it in GitHub Desktop.
TopCoderでデバッグ用に使ってる簡易cout拡張
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <list> | |
#include <queue> | |
#include <deque> | |
#include <stack> | |
#include <map> | |
#include <set> | |
using namespace std; | |
ostream& operator<<(ostream &s, vector<string> v) | |
{ | |
int cnt = v.size(); | |
s << "[ "; | |
for (int i=0; i<cnt; i++) { | |
if (i > 0) s << ", "; | |
s << '"' << v[i] << '"'; | |
} | |
return s << " ] // " << cnt << " item" << (cnt >= 2 ? "s" : ""); | |
} | |
template <typename T> ostream& operator<<(ostream &s, vector<T> v) | |
{ | |
int cnt = v.size(); | |
s << "[ "; | |
for (int i=0; i<cnt; i++) { | |
if (i > 0) s << ", "; | |
s << v[i]; | |
} | |
return s << " ] // " << cnt << " item" << (cnt >= 2 ? "s" : ""); | |
} | |
template <typename T> ostream& operator<<(ostream &s, list<T> ls) | |
{ | |
int cnt = 0; | |
s << "( "; | |
for (typeof(ls.begin()) it=ls.begin(); it!=ls.end(); it++) { | |
if (it != ls.begin()) s << ", "; | |
s << *it; | |
cnt++; | |
} | |
return s << " ) // " << cnt << " item" << (cnt >= 2 ? "s" : ""); | |
} | |
template <typename T> ostream& operator<<(ostream &s, deque<T> st) | |
{ | |
int cnt = st.size(); | |
s << "[ "; | |
for (typeof(st.begin()) it=st.begin(); it!=st.end(); it++) { | |
if (it != st.begin()) s << ", "; | |
s << *it; | |
} | |
return s << " ] // " << cnt << " item" << (cnt >= 2 ? "s" : ""); | |
} | |
template <typename T1, typename T2> ostream& operator<<(ostream &s, map<T1,T2> m) | |
{ | |
int cnt = m.size(); | |
s << "{ "; | |
for (typeof(m.begin()) it=m.begin(); it!=m.end(); it++) { | |
if (it != m.begin()) s << ", "; | |
s << it->first << " => " << it->second; | |
} | |
return s << " } // " << cnt << " item" << (cnt >= 2 ? "s" : ""); | |
} | |
template <typename T> ostream& operator<<(ostream &s, set<T> st) | |
{ | |
int cnt = st.size(); | |
s << "[ "; | |
for (typeof(st.begin()) it=st.begin(); it!=st.end(); it++) { | |
if (it != st.begin()) s << ", "; | |
s << *it; | |
} | |
return s << " ] // " << cnt << " item" << (cnt >= 2 ? "s" : ""); | |
} | |
template <typename T1, typename T2> ostream& operator<<(ostream &s, pair<T1,T2> p) | |
{ | |
return s << "(" << p.first << "," << p.second << ")"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment