Boost logo

Boost :

Subject: Re: [boost] [serialization] problems implementing free-standingfunctions
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-03-04 12:47:05

> Why do I need to store the object locally first?

Of course the easy answer is that the make_nvp takes a reference
and the compiler flags an error the conversion of an temporary
item on the stack as an error. But of course you knew that.

The real question is, "Why does make_nvp (and other wrappers)
take only references rather than copying real values". Here a couple of

a) All parameters in the serialization library are passed by reference.
This is necessary to support tracking for those situations which
require it. It would be confusing if support of tracking were
a hidden side effect of how an argument has been passed.

b) make_nvp is a wrapper. The concept of a wrapper is to
add some extra "sauce" (in this case, the external name of the
data item") while leaving original operations the same. This
is the case with all wrappers. That is, a wrapper doesn't
change things, it just adds something. This permits one
to keep in his brain what is really going on. Also it permits
one to nest wrappers to any resonable depth.

c) passing by reference is going to be more efficient for
larger structures.

d) not all structures have copy constructors

FWIW, Lately, I've had occasion to consider this question in more
depth and can see how elaborating this issue might make the
serialization library useful in new domains. However this is
outside of the scope of this discussion.

Robert Ramey

Thorsten Ottosen wrote:
> Thorsten Ottosen skrev:
>> From: Thorsten Ottosen [mailto:thorsten.ottosen_at_[hidden]]
>>> Is it not posssible to turn this feature into a debugging aid,
>>> rather than
>>> something that is enabled by default? I'm thinking that the cost of
>>> the current strategy very much out-weights its benefits :-( .
>> *** that was my intention when I changed it from ERROR to WARNING.
> Here's my error:
> d:\boost\trunk\boost/utility/serialize_auto_buffer.hpp(62) : error
> C2664: 'boost
>>> serialization::make_nvp' : cannot convert parameter 2 from 'unsigned
> int' to '
> unsigned int &'
> Produced by this line:
> ar << boost::serialization::make_nvp( "count",
> c.capacity() );
> Why do I need to store the object locally first?
> I'm using visual C++ 9 SP1.
> -Thorsten
> _______________________________________________
> Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at