|
Boost : |
Subject: Re: [boost] Composing non copyable and movable classes
From: Vicente Botet (vicente.botet_at_[hidden])
Date: 2008-12-07 07:40:30
----- Original Message -----
From: "Mathias Gaunard" <mathias.gaunard_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Saturday, December 06, 2008 11:00 PM
Subject: Re: [boost] Composing non copyable and movable classes
>
> 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.
Right, std::unique_ptr is enough.
>> 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.
If both classes were available, will you use the class Ci in contexts where nonmovable_Ci is more performant?
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk