Boost logo

Boost :

Subject: Re: [boost] [smart ptr] Any interest in copy-on-write pointerforC++11?
From: Dave Abrahams (dave_at_[hidden])
Date: 2013-02-11 18:21:33


on Mon Feb 11 2013, "Peter Dimov" <lists-AT-pdimov.com> wrote:

> Jeffrey Lee Hellrung, Jr. wrote:
> On Mon, Feb 11, 2013 at 12:01 PM, Ralph Tandetzky <
> ralph.tandetzky_at_[hidden]> wrote:
>
>> > Nice idea though. write_ptr<T> would behave like value_ptr<T>
>>
>> Not as I understand it; write_ptr would behave similar to
>> unique_ptr, i.e.,
>> it would be move-only.
>
> You could, in principle, make it do a deep copy, but the point of the
> exercise is to avoid inadvertent expensive copies, so a move-only
> pointer makes a bit more sense, I think. An explicit copy() could
> perform the deep copy, if needed.

Nit: there is no such thing as "deep copy." :-)

> On the other hand, making it do a deep copy is slightly more flexible
> because you could then use it as a value_ptr if you don't care for the
> whole CoW business. I could go either way on that.

Random thoughts:

I don't know where this discussion stands on the issue, but it just
occurred to me that I wouldn't want copying a ptr to automatically do
anything to the ptee (pointee).

I could imagine something like shared_ptr taking an optional cloner (as
well as a deleter) and having

     shared_ptr<T const> x(new T);
     shared_ptr<T> y = x.clone_ptee();

I like the way const qualification integrates with that. I wonder if
everyone who wants to implement CoW also wants the cost of shared_xxx,
though.

-- 
Dave Abrahams

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk