Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-09-28 12:13:39


"Vladimir Prus" <ghost_at_[hidden]> wrote in message
news:200409281058.35304.ghost_at_cs.msu.su...
> Hi Jonathan,
>
> > > > II. A system for allowing user-defined type to advertise their
> > > > internal
> > > >
> > > > structure, ......
>
> > > Isn't this close to using 'serialize' for extracting members, that I
> > > advocate?
> >
> > Could you repeat how this would work? I considered allowing user defined
> > types to provide a function (member or non-member) which returns a list of
> > members for use in serialization; unfortunately this was very wastefull in
> > the (common) case that you don;t need to use all the information
>
> I though the system will just work by providing an object with overloaded
> operator&:
>
> class outputter {
> public:
> template<class T>
> outputter& operator&(const boost::nvp<T>& nvp)
> {
> cout << nvp.name() << ":" << nvp.value() << "\n";
> }
> };
>
> class my {
> template<.....>
> void serialize(Archive& ar......) { ar & BOOST_SERIALIZATION_NVP(i); }
> int i;
> };
>
> Why do you think it's common to don't need all the information? Yes, you
> probably don't need names for many formatters, but then the operator& will be
> inline and compiler can optimize passing of the name.

I can imagine wanting to generate a report in xml which involves enumerating the
employees working on a project. The employees may be represented by complex
objects containing extraneous information such as work history, and only the
employee name may be needed. In that case, using a serialize method would be
wasteful.

I don't see why a framework can't provide several options.

Jonathan


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