|
Boost : |
From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-09-28 01:58:35
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.
- Volodya
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk