Boost logo

Boost :

From: Rainer Deyke (rainerd_at_[hidden])
Date: 2003-10-09 00:46:51


E. Gladyshev wrote:
> Wait a second the CPU does it all the time, you know L1 cache and
> stuff. :) Seriously in practice you don't want to do it often because
> another operation may indirectly reference the moved object.
> In this particular case it is not a problem because
> it is an assignment operator that assumes that the current rhs
> content is destroyed anyway before anything else can happen.

I can think of at least one degenerate case where your trick fails.

class A;

A* the_A = 0;

class A {
  A() { the_A = this; }
  ~A() { the_A = 0; }
};

class B {
  B() { if (the_A) do_something_with(the_A); }
};

variant<A, B> v(A());
v = B();

-- 
Rainer Deyke - rainerd_at_[hidden] - http://eldwood.com

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