Subject: Re: [boost] [smart ptr] Any interest in copy-on-write pointer for C++11?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2013-02-10 13:01:52
On 10/02/13 10:27, Vicente J. Botet Escriba wrote:
>> It seems to me that the copy of polymorphic object works only with the
>> help of the user and that the following should be mentioned as a
>> Base* ba = new Derived1;
>> cow_ptr<Base> a( ba );
>> cow_ptr<Base> c;
>> c = a; // performs a shallow copy.
>> c->doSomething(); // couldn't makes a deep copy of a as a
>> Derived1 class as the type has been lost.
>> // There is a slicing involved.
> If this is confirmed, I see it as a show-stopper, and the cloning
> strategy must be redefined.
This is something that I already pointed out elsewhere on the thread.
To me the best approach is to make the class have a "virtual copy
constructor" (a clone virtual member function counts as one), which is
the only way to fix this issue.
I don't quite like the approach in N3339 because it couples allocation
and copy construction.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk