Return value elision
suggest changeIf you return a prvalue expression from a function, and the prvalue expression has the same type as the function’s return type, then through C++14 the copy or move from that temporary may be elided:
std::string func()
{
return std::string("foo");
}
Pretty much all compilers elide that temporary through C++14, but the copy or move constructor must still be accessible. Since C++17, the prvalue initializes the return object directly and that constructor is not required.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents