Boost logo

Boost :

Subject: Re: [boost] [smart ptr] Any interest in copy-on-writepointerforC++11?
From: Peter Dimov (lists_at_[hidden])
Date: 2013-02-11 23:33:33


Jeffrey Lee Hellrung, Jr. wrote:
> On Mon, Feb 11, 2013 at 1:47 PM, Peter Dimov <lists_at_[hidden]> wrote:
>
> > read_ptr<T> pr;
> >>
> >> if( write_ptr<T> pw = pr.write() )
> >> {
> >> pw->mutate();
> >> pr = std::move( pw );
> >> }
...
> > In fact, now that I think of it, .write should be a move, too.
>
> In the case that pr has a use_count of 1, definitely. I thought that's
> what
> you had been proposing all along :)

Yes. I meant syntactically, as well, to match the semantics.

...

> > The advantage here is that (1) in
> >
> > read_ptr<T> get_value();
> > write_ptr<T> p = get_value();
> >
> > you don't need a write() call,
>
> I would expect most of the time you're not going to be immediately
> modifying a read_ptr rvalue like above.

Well, you have to return _something_ from get_value. It's going to be either
read_ptr or write_ptr. It can't be both. You don't know what the caller
needs to do. So if you choose read_ptr for some reason, and the caller needs
a write_ptr, all is well (and vice versa - they both move into each other).


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