$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
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 :
> 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)?
> 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.
The conversion to bool should be explicit.
*explicit* operator bool() const noexcept;
Best,
Vicente