C++ Copy Elision Return value elision

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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.



Got any C++ Question?