Skip to content

Instantly share code, notes, and snippets.

@longngn
Last active January 18, 2018 11:01
Show Gist options
  • Save longngn/0137c21f50fd0755a4c885ef4f05bd18 to your computer and use it in GitHub Desktop.
Save longngn/0137c21f50fd0755a4c885ef4f05bd18 to your computer and use it in GitHub Desktop.
// 1. Put this file into the folder "bits"
// 2. Put this line into "bits/stdc++.h": #include "cp-debug.cpp"
// 3. Now you can cout << STL !! Modify this code as to suit your style
// Example: https://imgur.com/a/kulaD
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
os << '[';
for (unsigned int i = 0; i < a.size(); i++)
os << a[i] << (i < a.size() - 1? ", " : "");
os << ']';
return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &a) {
os << '{';
for(typename set<T>::iterator it = a.begin(); it != a.end(); it++) {
typename set<T>::iterator jt = it;
os << *it << (++jt != a.end()? ", " : "");
}
os << '}';
return os;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, map<T1, T2> &a) {
os << "{\n";
for(typename map<T1, T2>::iterator it = a.begin(); it != a.end(); it++) {
typename map<T1, T2>::iterator jt = it;
os << " " << it->first << ": " << it->second << (++jt != a.end()? ",\n" : "\n");
}
os << '}';
return os;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment