Boost logo

Boost :

From: Dave Harris (brangdon_at_[hidden])
Date: 2003-10-15 14:34:00


In-Reply-To: <01C3917F.DDE396E0_at_[hidden]>
ramey_at_[hidden] (Robert Ramey) wrote (abridged):
> > std::auto_ptr<T> pt;
> > ar >> pt; // Uses pointer load.
>
> The current one looks like:
> [...]
> T t;
> for (--size; size != 0; --size) {
> ar >> t;
>
> which essentially the same but it doesn't use the heap.
>
> Both of the above fail to address the point that I'm concerned about -
> the requirement that for non-default constructors overloads have to be
> written in two places and have to be kept in sync.

My version does address that, because it loads a pointer. Perhaps it would
be clearer without the auto_ptr?

     T *pt;
     ar >> pt;
     c.push_back( *pt );

This should go through the pointer version of load:

   template<class Archive ar, class T>
   void load(Archive & ar, T * &t, unsigned int file_version);

If the user writes an overload for load, my container code will use it. So
they only have to write one overload.

> construct(ar, tptr);
> ar >> *tptr;

I would bundle the construction with the loading, to help in cases where
the construction is all that's required (or permitted)

Also, David's vision is somewhat different to mine and I don't understand
it in detail. I think he is saying that uninitialized_load() is the only
load the user should need to write, and initialised_load() should be
written in terms of it. Presumably using a second object and assignment
(or swap?), or else destructing the original object and constructing a new
object at that same location. If I have this right, it sounds less
efficient in the common case, so I've probably misunderstood. And I'd want
to understand before making any final decisions :-)

> So, as I said before, I am happy to concede you point as gracefull as I
> am able to do..

OK, thanks.

-- Dave Harris, Nottingham, UK


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