29#include <unordered_set>
35 template <
class T1,
class T2>
36 std::ostream&
operator<<( std::ostream& s,
const std::pair<T1, T2>& p );
39 template <
typename... Args>
40 std::ostream&
operator<<( std::ostream& s,
const std::tuple<Args...>& tuple );
43 template <
class T,
class ALLOC>
44 std::ostream&
operator<<( std::ostream& s,
const std::vector<T, ALLOC>& v );
47 template <
class T, std::
size_t N>
48 std::ostream&
operator<<( std::ostream& s,
const std::array<T, N>& v );
51 template <
class T,
class ALLOC>
52 std::ostream&
operator<<( std::ostream& s,
const std::list<T, ALLOC>& l );
55 template <
class T,
class ALLOC>
56 std::ostream&
operator<<( std::ostream& s,
const std::set<T, ALLOC>& l );
59 template <
class T,
class ALLOC>
60 std::ostream&
operator<<( std::ostream& s,
const std::unordered_set<T, ALLOC>& l );
63 template <
class T1,
class T2,
class COMP,
class ALLOC>
64 std::ostream&
operator<<( std::ostream& s,
const std::map<T1, T2, COMP, ALLOC>& m );
70 std::ostream&
operator()( std::ostream& os, T&& t )
const {
71 return os << std::forward<T>( t );
75 template <
typename Stream,
typename Iterator,
typename Separator,
typename OutputElement = IdentityOutputter>
77 OutputElement output = OutputElement{} ) {
78 if ( first != last ) output( os, *first++ );
79 while ( first != last ) output( os << sep, *first++ );
83 template <
typename Stream,
typename Container,
typename Separator,
typename OutputElement = IdentityOutputter>
84 Stream&
ostream_joiner( Stream& os,
const Container& c, Separator sep, OutputElement output = OutputElement{} ) {
85 using std::begin, std::end;
90 template <
class T1,
class T2>
91 std::ostream&
operator<<( std::ostream& s,
const std::pair<T1, T2>& p ) {
92 return s <<
'(' << p.first <<
", " << p.second <<
')';
95 template <
typename... Args>
96 std::ostream&
operator<<( std::ostream& s,
const std::tuple<Args...>& tup ) {
98 [&s](
const auto&... a ) ->
decltype(
auto ) {
99 unsigned n =
sizeof...( a );
102 ( ( s <<
" " << a << ( --n == 0 ?
"" :
"," ) ), ... );
108 template <
class T,
class ALLOC>
109 std::ostream&
operator<<( std::ostream& s,
const std::vector<T, ALLOC>& v ) {
113 template <
class T, std::
size_t N>
114 std::ostream&
operator<<( std::ostream& s,
const std::array<T, N>& v ) {
118 template <
class T,
class ALLOC>
119 std::ostream&
operator<<( std::ostream& s,
const std::list<T, ALLOC>& l ) {
123 template <
class T,
class ALLOC>
124 std::ostream&
operator<<( std::ostream& s,
const std::set<T, ALLOC>& l ) {
128 template <
class T,
class ALLOC>
129 std::ostream&
operator<<( std::ostream& s,
const std::unordered_set<T, ALLOC>& l ) {
130 auto ordered = std::set( l.begin(), l.end() );
135 template <
class T1,
class T2,
class COMP,
class ALLOC>
136 std::ostream&
operator<<( std::ostream& s,
const std::map<T1, T2, COMP, ALLOC>& m ) {
138 []( std::ostream& os,
const std::pair<const T1, T2>& p ) -> std::ostream& {
139 return os << p.first <<
": " << p.second;
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
std::ostream & operator<<(std::ostream &s, const std::pair< T1, T2 > &p)
Serialize an std::pair in a python like format. E.g. "(1, 2)".
std::ostream & operator()(std::ostream &os, T &&t) const