Boost logo

Boost :

Subject: Re: [boost] Composing non copyable and movable classes
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2008-12-06 17:00:24


vicente.botet wrote:

> The question is how to make X movable efficiently. The first way is to move each one of the movable objects one by one. This could be expensive if the number of members is high. In addition X can have also member that are not movable.
>
> The second approach is to use the same technique, store a pointer to the data on a shared_pointer, and move on one operation all the members via the pointer.

Why shared_ptr? There is no sharing of ownership required.
Just use std::unique_ptr.

> I think that this separation is in line with the C++ principle "you don't pay for what you don't use". Any thoughts?

You're just stating the advantages and disadvantages between storing the
data in the object itself and storing it in a separate object that is
referenced.

It's simply a tradeoff between {locality, compactness, allocation speed}
and moving speed.


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