Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-04-14 20:04:41


Joe Gottman wrote:

> shared_ptr<int> p(new int(1));
> foo(move(p));
> if (p) { // foo didn't want it, try the next potential consumer
> bar(move(p));
> } else {
> return; // foo consumed our shared_ptr, so we are done.
> }

An interesting pattern, thanks for the example. A bit of a circular logic
here, since for this example to work reliably shared_ptr must clear the
source of the move; therefore, if we don't specify it to clear the source,
this example will not be valid. (It isn't in general; a raw pointer, for
example, is not zeroed when moved from.) But it may well be a pattern that
we decide to support.

This implies an "overspecified" assignment, though; the straightforward swap
doesn't clear the source.


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