
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(); } Usual const-propagation should be enough to optimize those booleans out when possible. It's true however the current system is really much simpler since there is no such work required for the compiler (and maybe it can be optimized just as well?)