Boost logo

Boost :

Subject: Re: [boost] [explore] Library Proposal: Container Streaming
From: David Bergman (David.Bergman_at_[hidden])
Date: 2009-12-01 13:09:28

On Dec 1, 2009, at 12:43 PM, Robert Ramey wrote:

> Vladimir Prus wrote:
>> Robert Ramey wrote:
>>>>> Robert Ramey
>>>> It didn't require learning to use Boost.Serialization.
>>> Here is what you're example looks like with boost serialization
>>> #include <iostream>
>>> #include <boost/serialization/vector.hpp>
>>> #include <boost/serialization/map.hpp>
>>> #include <boost/serialization/list.hpp>
>>> #include <boost/serialization/string.hpp>
>>> //#include <boost/date_time.hpp>
>>> #include <boost/archive/text_oarchive.hpp>
>>> int main(int argc, char * argv[]){
>>> boost::archive::text_oarchive output_log(std::cout);
>>> // simple vector example
>>> std::vector<int> vi;
>>> vi.push_back(1);
>>> vi.push_back(2);
>>> vi.push_back(3);
>>> output_log << vi;
>> While this is possible, with a custom archive class, I hope you'll
>> agree that it will be rather heavyweight solution,
> Hmmm - I realize that the serialization library has a lot of template
> code. But to me the issue is conceptual "heaviness".

The only line that might look heavy to anyone is

        boost::archive::text_oarchive output_log(std::cout);

So, perhaps Vladimir should create an alias

        typedef boost::archive::text_oarchive arch;

and then:

        arch(std::cout) << v; // v is a standard vector

for a simple one-shot archive...

I cannot see anything heavy at all, but that might be a disease related to having spent 23 years with C++ and having implemented CFront alternatives in the old days :-(

Perhaps even using a simple wrapper function would make Vladimir less stressed?

        template<typename Cont>
        std::ostream& output(Cont const& cont, std::ostream & stream = std::cout) {
                boost::archive::text_oarchive(stream) << cont;
                return stream;

and then use



        output(v, std::cerr);

> In both libraries, the idea is to wrap extra information about types
> so that they can easily be displayed on a stream. In either library
> you just write
> #include ...
> ...
> output_stream << data
> I just don't see the value in re-inventing of a whole new wheel.

Vladimir's claim is that his solution is lighter in two aspects (I think):

1. Easier to use

2. Not dependent on Boost

I hope we all realize that, no, #1 is not the case, and if so, one can create a simple wrapper as the one above to make it easier. So, what about #2? Well, as a proposed Boost library, it is no longer that important.

> By the time such a library would pass the
> boost review process, I'm sure it would be just as heavy
> weight (or more) than boost serialization.
> One would have a whole new interface to to something that
> is less capable.
> Already the serialization library has an xml_archive as well
> as text archive.
>> while a simple
>> output of output of std::vector can be implement in a 3-line template
>> function.
> I didn't have to write even one line to template code to
> implement the example.

This is a point of confusion for Vladimir, and I will comment on it in a more recent post.


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