Created
April 3, 2018 19:56
-
-
Save robobenklein/db130c269afda7fcb15de6b55fd0e84c to your computer and use it in GitHub Desktop.
C++ debugging ostreams
This file contains 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
// for cerr debugging, overloads for vector, list, set | |
template <class T> | |
std::ostream& operator<< (std::ostream& out, const std::vector<T>& v) { | |
if ( !v.empty() ) { | |
out << "vector["; | |
for (T item : v) { | |
out << item; | |
out << ", "; | |
} | |
out << "\b\b]"; | |
} | |
return out; | |
} | |
template <class T> | |
std::ostream& operator<< (std::ostream& out, const std::list<T>& v) { | |
if ( !v.empty() ) { | |
out << "list["; | |
for (T item : v) { | |
out << item; | |
out << ", "; | |
} | |
out << "\b\b]"; | |
} | |
return out; | |
} | |
template <class T> | |
std::ostream& operator<< (std::ostream& out, const std::set<T>& v) { | |
if ( !v.empty() ) { | |
out << "set["; | |
for (T item : v) { | |
out << item; | |
out << ", "; | |
} | |
out << "\b\b]"; | |
} | |
return out; | |
} | |
template <typename T1, typename T2> | |
std::ostream& operator<< (std::ostream& out, const std::pair<T1, T2>& v) { | |
out << "pair("; | |
out << v.first; | |
out << ", "; | |
out << v.second; | |
out << ")"; | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment