Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-02-27 14:21:28


From: "David Abrahams" <david.abrahams_at_[hidden]>
> There are much worse problems with operator>>() than that one, IMO. How do
> you unserialize an object with no default constructor?

Actually I require a default constructor and this hasn't been a problem so
far. In my initial attempt I used operator<<=/>>= for serialization (<< and
>> being reserved for text I/O.) This has the advantage that you can
implement them as members or as free functions and Koenig lookup works on
MSVC.

Operators turned out to not work well, though. You can't add additional
arguments to them. I now use

template<class Reader, class Value> void read(Reader & r, Value & v, int);
// partial ordering hack

template<class Writer, class Value> void write(Writer & w, Value const & v,
int);

template<class Writer, class Value, class Attributes> void write(Writer & w,
Value const & v, Attributes const & a, int);

The Attributes object is typically the name of the Value, i.e. (real code)

template<class W, class T, class A> void write(W & w, math::point2<T> const
& p, A const & a, int)
{
 begin_struct(w, a & type_descriptor(p));
 write(w, p[0], "x", 0);
 write(w, p[1], "y", 0);
 end_struct(w, a & type_descriptor(p));
}


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