Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-07-13 12:27:27


Martin Wille wrote:

> Usage example:
>
> // udt.hpp
> struct udt { };
> std::ostream &operator<<(std::ostream &, udt const &);
> std::istream &operator>>(std::istream &, udt const &);
>
> // someclass.hpp
> #include "udt.hpp"
> #include <boost/serialization.hpp>
>
> struct someclass
> {
> template<typename Archive>
> void serialize(Archive &ar, const unsigned int version)
> {
> ar & boost::serialization::lexical_cast<std::string>(my_udt);
> }
>
> private:
> udt my_udt;
> };

This puts the serialization support for udt at the wrong level. If you have
twelve classes that have four udt members each, you'll have to repeat
"boost::serialization::lexical_cast<std::string>()" 48 times. And
vector<udt> will still not work.

It's better to define load+save for udt.

If you do that, you'll see that the proposed wrapper adds almost no value.
The 'almost' part comes from track_never, which enables you to sidestep the
usual problem of serializing temporaries. :-)

> - Do you see a use case for using an "external" type other than
> std::string with this wrapper, e.g
> ar & boost::serialization::lexical_cast<int>(my_udt); // ?

I'm not sure I do.

> - Assuming there are some positive responses about the usefulness
> of the lexical_cast wrapper, would this addition be suitable for
> a fast-track review (it is very tiny)?

Fast-track components need to already be in use as an implementation detail
of an existing Boost library, I believe.


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