From cfdf2a93f27c93004d4ee4a7dfbd20b12b4ea06f Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 17 Apr 2012 22:14:46 +0200 Subject: [PATCH] Generic operator<< for std::vector, std::pair and custom types providing "streamify()" --- src/common/ostream_operators.h | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/common/ostream_operators.h diff --git a/src/common/ostream_operators.h b/src/common/ostream_operators.h new file mode 100644 index 000000000..fb1ec9e95 --- /dev/null +++ b/src/common/ostream_operators.h @@ -0,0 +1,54 @@ +/* + mkvmerge -- utility for splicing together matroska files + from component media subtypes + + Distributed under the GPL + see the file COPYING for details + or visit http://www.gnu.org/copyleft/gpl.html + + generic "operator <<()" for standard types + + Written by Moritz Bunkus . +*/ + +#ifndef MTX_COMMON_OSTREAM_OPERATORS_H +#define MTX_COMMON_OSTREAM_OPERATORS_H + +namespace std { + +template +std::basic_ostream & +operator <<(std::basic_ostream &out, + std::vector const &vec) { + out << "<"; + bool first = true; + for (auto element : vec) { + if (first) + first = false; + else + out << ","; + out << element; + } + out << ">"; + + return out; +} + +template +std::basic_ostream & +operator <<(std::basic_ostream &out, + std::pair const &p) { + out << "(" << p.first << "/" << p.second << ")"; + return out; +} + +template +std::basic_ostream & +operator <<(std::basic_ostream &out, + ElementT const &e) { + return e.streamify(out); +} + +} + +#endif // MTX_COMMON_OSTREAM_OPERATORS_H