What is Return Value Optimization (RVO) and Copy Elision?
Last updated
Copy elision is a compiler optimization that builds an object directly in its final location, skipping copy/move constructions. RVO (Return Value Optimization) is the case of a returned object built straight into the caller's storage.
Since C++17, returning a prvalue temporary is guaranteed elided (works even with deleted copy/move constructors). NRVO (eliding a named local) is allowed but not guaranteed.
Don't write
return std::move(local): it disables NRVO and forces a move.