
3 May
2010
3 May
'10
8:47 p.m.
Chad Nelson:
If that's the case, and GCC is doing that as it should, why would adding move semantics to the library provide any speed increase at all?
Consider something like X f(); g( X ); int main() { f( g() ); // #1 f( -g() ); // #2 } In #1, the compiler can eliminate all copies, if f is written in a RVO-friendly way. (It won't be able to in general if there's more than one return statement, or the return value is a ternary ?: expression.) But in #2, there's going to be one allocation for the result of the unary op-. Even if operator- takes its parameter by value and directly flips its sign and returns it, I don't think that the compiler is allowed to allocate the return value and the parameter at the same address.