How can we ensure the compiler performs RVO?
Show answer and explanation
Return a prvalue directly when possible to obtain guaranteed C++17 elision, or return the same named local from all relevant paths to make NRVO possible. Do not write std::move(local) in the return, because it usually prevents NRVO.
Return a prvalue directly when possible to obtain guaranteed C++17 elision, or return the same named local from all relevant paths to make NRVO possible. Do not write std::move(local) in the return, because it usually prevents NRVO.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.