
Le 10/02/13 03:04, Vicente J. Botet Escriba a écrit :
Le 08/02/13 16:16, Ralph Tandetzky a écrit :
Hi,
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 (file://localhost/Users/viboes/Downloads/n3339-1.pdf)?
I meant " N3339: A Preliminary Proposal for a Deep-Copying Smart Pointer" http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3339.pdf
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 class. // 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 CopyConstructible.
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 ); 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. I don't see any relational operators. Is this intentional? It is worth adding interactions with nullptr_t? What about a T* release() member function? What about a reset(U*) member function ? Best, Vicente