Return value elision

suggest change

If 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents