Some time ago I was told, that the usual pattern to implement two-ary operators needs a final move in the return.
Matrix operator+(const Matrix &a, Matrix &&b) {
b += a;
return std::move(b);
}
But now there is the special rule that in a return the compiler may treat the return value as a temporary, and then this would not be necessary — a simple return b would suffice.
But then again, b has a name in this function, therefore, its an LValue — which hinders the compiler to m consider it being a temp, and the move is required.
Is this still the case in the most recent version of the C++0x Standard? We need the move to implement the above pattern?
You need the explicit
std::movein this example becausebis not the name of a non-volatile automatic object. Reference 12.8 [class.copy] /p31/b1: