$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] [explore] Library Proposal: Container Streaming
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-12-01 12:14:58
Jeffrey Bosboom wrote:
> Robert Ramey wrote:
>> Jeffrey Bosboom wrote:
>>> I've written simple versions of streaming operators (both output and
>>> input) for the standard containers as a simple, low-barrier-to-entry
>>> form of serialization. Do you plan to provide the input operators
>>> too? (I understand this would involve some restrictions on the
>>> streamed forms of the container elements to prevent parsing
>>> ambiguity.)
>>
>> how would this be different than just writing a special archive
>> class and using boost seriallization?
>>
>> 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;
// lets do some containers in containers
std::vector<std::vector<int> > vvi;
vvi.push_back(vi);
vvi.push_back(vi);
output_log << vvi; // prints [[1, 2, 3], [1, 2, 3]]
// associative containers
std::map<std::string, int> si_map;
si_map["hello"] = 1;
si_map["world"] = 2;
output_log << si_map; // prints [hello:1, world:2]
#if 0
// containers of complex types
std::list<date> dl; // date from boost::gregorian
dl.push_back(date(2007, Jan, 1));
dl.push_back(date(2007, Jan, 3));
output_log << dl; // prints [2007-Jan-1, 2007-Jan-3]
#endif
// how about some boost container types:
boost::array<std::string, 2> sa2;
sa2[0] = "one";
sa2[1] = "two";
output_log << sa2; // prints [one, two]
}
I excluded data/time because I didn't have it compiled on my machine.
I don't see it as being any more difficult to use/learn than the library
you propose.
If I were to do this, I would likely make a special "human readable"
text archive. This would be a tiny fraction of the effort already
expended and produce a result with much more features.
>Also, in the
> specific case I needed this for, I was running code on a cluster where
> Boost was not available, so it was lighter-weight (although obviously
> far less featureful).
I don't see how one is going to run boost libraries in an
environment were boost is not available.
Sorry, I'm just not getting this.
Robert Ramey