Stats

Contributors: 1
2016-07-30
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook

Return value elision

Download c++ eBook

Example

If you return a prvalue expression from a function, and the prvalue expression has the same type as the function's return type, then the copy from the prvalue temporary can be elided:

std::string func()
{
  return std::string("foo");
}

Pretty much all compilers will elide the temporary construction in this case.