Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-09-29 01:25:16


Jonathan Turkanis wrote:

>> 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.

Yes, a bit. OTOH, it would be possible to use the same serialize method to
build, once, and member name -> offset map, which can be then used. For a
name case you can do:

   template<class>
   figure_out_name_offset
   {
 figure_out_name_offset operator&(nvp& p)
        {
             if (p.name() == "name")
             {
                 m_address = &p.value()
             }
        }
        std::string* m_address;
   };
   Person p;
   figure_out_name_offset f;
   p.serialize(f);
   unsigned offset = (int)f.m_address - (int)&p;

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

I'd rather not see several different options when one is good enough. Many
options will confuse users.

- Volodya


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