
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.