Boost logo

Boost :

Subject: Re: [boost] [explore] Library Proposal: Container Streaming
From: Michael Caisse (boost_at_[hidden])
Date: 2009-12-01 12:48:01

Vladimir Prus wrote:
> Michael Caisse wrote:
>> I've been trying to think of when I might use such a library. Without
>> the symmetry (input as well as output) I can think of few instances
>> where this functionality might come in handy. Other than potential debug
>> output, what else do you envision? What am I missing?
>> I'm also finding little improvement over the following example
>> based on your samples. Here I am using Karma to produce the same
>> output as Explore. It is a bit more verbose; however, it is infinitely
>> more flexible.
> ...
>> // lets do some containers in containers
>> std::vector<std::vector<int> > vvi;
>> vvi.push_back(vi);
>> vvi.push_back(vi);
>> std::cout << format('[' << *( '[' << (stream % ", " ) << ']' ) << ']' , vvi);
> I surely would not like to write the above any time I need to dump std::vector
> for debugging. And I suspect that the effect on compilation time would also be
> somewhat different. In other words, I think there's definitely a place for
> an inflexible library that just works.
> - Volodya

Volodya -

Good point. I wouldn't. I was just trying to create the same format.
I would instead write:

   std::cout << format( stream % ',', vvi);

My experience with inflexible libraries is that they quickly fall apart
with anything except trivial examples and the canned sample/example code.

What happens when I have the following?

        struct my_struct{
                int foo;
                int bar;

I assume there needs to be an operator<<( std::ostream& s, my_struct& v ).
Simply adapting my_struct to a fusion sequence will make it "just work"
with Karma.

Pre-Karma I used Phoenix to write:

        std::for_each( v.begin(), v.end(), std::cout << arg1 << ',' );

That isn't so bad either. Does making a library that allows me to write

        std::cout << v;

for the few real-life (my real-life (o; ) cases where the contents of v can
just output without massaging the values make sense? Not to me at least.
Not when there are such powerful tools already in the boost toolbox that solve
both the simple case and allow me to handle the complex situations.


Michael Caisse
Object Modeling Designs

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