mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-29 06:15:24 +00:00
Generic operator<< for std::vector, std::pair and custom types providing "streamify()"
This commit is contained in:
parent
50620f4988
commit
cfdf2a93f2
54
src/common/ostream_operators.h
Normal file
54
src/common/ostream_operators.h
Normal file
@ -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 <moritz@bunkus.org>.
|
||||
*/
|
||||
|
||||
#ifndef MTX_COMMON_OSTREAM_OPERATORS_H
|
||||
#define MTX_COMMON_OSTREAM_OPERATORS_H
|
||||
|
||||
namespace std {
|
||||
|
||||
template<typename CharT, typename TraitsT, typename ContT>
|
||||
std::basic_ostream<CharT, TraitsT> &
|
||||
operator <<(std::basic_ostream<CharT, TraitsT> &out,
|
||||
std::vector<ContT> const &vec) {
|
||||
out << "<";
|
||||
bool first = true;
|
||||
for (auto element : vec) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
out << ",";
|
||||
out << element;
|
||||
}
|
||||
out << ">";
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
template<typename CharT, typename TraitsT, typename PairT1, typename PairT2>
|
||||
std::basic_ostream<CharT, TraitsT> &
|
||||
operator <<(std::basic_ostream<CharT, TraitsT> &out,
|
||||
std::pair<PairT1, PairT2> const &p) {
|
||||
out << "(" << p.first << "/" << p.second << ")";
|
||||
return out;
|
||||
}
|
||||
|
||||
template<typename CharT, typename TraitsT, typename ElementT>
|
||||
std::basic_ostream<CharT, TraitsT> &
|
||||
operator <<(std::basic_ostream<CharT, TraitsT> &out,
|
||||
ElementT const &e) {
|
||||
return e.streamify(out);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // MTX_COMMON_OSTREAM_OPERATORS_H
|
Loading…
Reference in New Issue
Block a user