Boost logo

Boost :

Subject: Re: [boost] [smart ptr] Any interest in copy-on-write pointerforC++11?
From: Peter Dimov (lists_at_[hidden])
Date: 2013-02-11 16:47:32


> read_ptr<T> pr;
>
> if( write_ptr<T> pw = pr.write() )
> {
> pw->mutate();
> pr = std::move( pw );
> }
>
> I don't, however, particularly like the semantics of the case in which pr
> is already unique.

In fact, now that I think of it, .write should be a move, too. In this case,
it's wouldn't be surprising to sometimes find pr holding a NULL after the
move.

    write_ptr<T> pw = std::move( pr );
    pw->mutate();
    pr - std::move( pw );

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, and (2) this avoids the mistake of doing

    pr.write();

without storing the return value and as a result, losing *pr when it's
unique. Just doing

    std::move( pr );

would do nothing, so it's safer.


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