Consider the function
const std::string f()
{
return "hello";
}
And the call
std::string x = f();
Regardless of whether value return types should be const or not, does the fact the return value is const, prevent a compiler from performing return value optimization?
My understanding of RVO is that the returned object is constructed directly into the variable outside the function. However, if the return type is const T
, this isn't the same as a T
, so will RVO be prevented?
来源:https://stackoverflow.com/questions/25360617/does-returning-by-const-value-affect-return-value-optimization