3 ms·
> The rule of thumb is don't use std::move on a return value unless you are returning a move-only type (which forces you to do so). RVO will be automatically a
by frankzinger 10y ago
> The rule of thumb is don't use std::move on a return value unless you are returning a move-only type (which forces you to do so).
RVO will be automatically applied if the returned variable is local to a function and of the same type as the function's return type. That's all that the standard allows.
RVO is not applied to function arguments, regardless of whether or not they're rvalue references.
So your rule of thumb breaks for cases such as these (X is a movable and copyable type):
X f(X&& x) {
return x; // x is copied, not moved
}
In order to get x moved into the return location, you would need to do move it explicitly.
Source: Effective Modern C++ by Meyers.