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
operator<< under #ifdef BOOST_STRINGIZE_GLOBAL_LEFT_SHIFT_OPERATOR.

Ideas regarding how to define a safe global operator<< would be much
appreciated.
As has been said, currently I use Boost.EnableIf to enable/disable the
overloads.
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.

P.S.
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: http://boost.2283326.n4.nabble.com/Query-of-interest-for-a-container-output-library-tp4641997p4642051.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk