
on Fri Dec 05 2008, Mathias Gaunard <mathias.gaunard-AT-ens-lyon.org> wrote:
David Abrahams wrote:
on Wed Dec 03 2008, Mathias Gaunard <mathias.gaunard-AT-ens-lyon.org> wrote:
David Abrahams wrote:
I don't think it's unfortunate. Destructive move semantics is nearly impossible to use correctly in many conditions. Would you mind giving examples?
void f() { X a; if (something) g(move(a)); // ... // a.~X() ? }
Indeed, in the general case, the compiler (this certainly shouldn't be the job of the programmer) would have to transform the code to something like that:
void f() { X a; bool destruct_a = true;
if (something) { g(move(a)); destruct_a = false; } // ...
if (destruct_a) a.~X(); }
In general the compiler can't know. void f(X& a) { if (something) g(move(a)); } void h() { X a; f(a); } Separate translation units if you must. Challenge your own idea a little bit; you'll see where this leads. Destruction without static knowledge thereof is the ultimate violation of invariants. -- Dave Abrahams BoostPro Computing http://www.boostpro.com