Subject: Re: [boost] [smart ptr] Any interest in copy-on-write pointer for C++11?
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2013-02-09 21:04:06
Le 08/02/13 16:16, Ralph Tandetzky a écrit :
> is there any interest in a copy-on-write pointer implementation? I
> wrote a cow_ptr<T> template class for C++11 which has the following
> use cases:
As others I would prefer another name for the class. Could you compare
how you class relates to value_ptr as defined here
> 3. You can add cloning to a class hierarchy from the outside. With
> cow_ptr<Base> a( new Derived1 );
> cow_ptr<Base> b( new Derived2 );
> cow_ptr<Base> c;
> c = a; // performs a shallow copy.
> c->doSomething(); // makes a deep copy of a as a Derived1
> // There is no slicing involved.
> you copy Base objects polymorphically. The class Base can even be
> abstract here. It is only required that Derived1 and Derived2 be
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 limitation
Base* ba = new Derived1;
cow_ptr<Base> a( ba );
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.
The conversion to bool should be explicit.
*explicit* operator bool() const noexcept;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk