Boost logo

Boost :

Subject: Re: [boost] Query of interest for a container output library
From: Tal Zion (talzion12_at_[hidden])
Date: 2013-01-30 23:26:16

You might be right.
I too thought overloading operator<< might be problematic but I haven't
encountered any problems yet.
I think that
std::cout << std::vector<int> {1,2,3} << '\n';
is simpler than the alternative, but I see why people would be alarmed.
I think simplicity is worth the extra work and I will look into the subject.
For now I added a str method under boost::stringize and I put the global

Ideas regarding how to define a safe global operator<< would be much
As has been said, currently I use Boost.EnableIf to enable/disable the
I use Boost.TypeTraits and Boost.MPL to introspect the type of the object
and disable if has_left_shift is already defined and enable only for types
that have a const_iterator typedef or are fusion sequences.
Currently the overloads are in the global namespace.

Regarding the str method, for efficiency's sake it returns a detail::feeder
object which simply holds a reference to the input and defines operator<<
and operator std::string() as well as some other operators.
Returning a string from boost::stringize::str would be inefficient if the
user wants to just stream the object.

Tal Zion

View this message in context:
Sent from the Boost - Dev mailing list archive at

Boost list run by bdawes at, gregod at, cpdaniel at, john at