Does the new variable implement return value optimization?

We all know that

Foo returnAFoo()
{
    return Foo();
}

will be compiled with optimization of the return value, so a copy of the value will not be accepted, even if the copy constructor Foohas side effects. But there will be

Foo returnAFoo()
{
    Foo f = Foo();
    return f;
}

also? The second design may be useful when debugging. But can I discard important optimization? Perhaps I need to write an explicit move constructor?

+4
source share
1 answer

. elision . NRVO ( ). , ; copy elision ++ 98/03, .

, , : (NRVO), (RVO).

NRVO RVO , .


, NRVO.

+7

All Articles