C++Now 2018: Jon Kalb “Copy Elision”

preview_player
Показать описание

Lightning Talk


---

*--*

---
Рекомендации по теме
Комментарии
Автор

Great Visualisation Jon and Great Talk as Usual. Blair.

BlairDavidson
Автор

I am not sure if it was accurate because when no Named Return Value Optimization (NRVO) applied, it means in return statement a copy of 'a' will be created in a return statement and then that copy will be considered as the return value and if copy elision applies since C++17, then that template return value will be created where 'x' and before C++17, it might elide or might not! Not sure if Jon was correctly demonstrated! In fact, he made me more confused!

sky_is_the_limit_
Автор

Great Visualization but I see a problem:
when you exclude the RVO with the compiler option
-fno-elide-constructors you can see that, returning an object by value, the compiler's generated code calls 3 constructors (assume no move semantic implementated for the sake of semplicity):

1) 'normal' constructor that builds the object obj inside the function
2) copy constructor that builds a temporary object tmp_obj (fictitious name) from obj
3) copy constructor that builds the final object final_obj from tmp_obj inside the caller

So, 3 steps versus 2 step by Jon Kalb

Here is a skeleton example:


MyClass func()
{
MyClass obj;
return obj;
}

int main()
{
MyClass final_obj = func();
}



Sorry for my english very very poor and simple.

openyourmind
Автор

I am not sure if it was accurate because when no Named Return Value Optimization (NRVO) applied, it means in return statement a copy of 'a' will be created in a return statement and then that copy will be considered as the return value and if copy elision applies since C++17, then that template return value will be created where 'x' and before C++17, it might elide or might not! Not sure if Jon was correctly demonstrated! In fact, he made me more confused! I think he kind of confused copy elision with NRVO!!!

sky_is_the_limit_
Автор

I appreciate the talk, but isn't named RVO still optional for the compiler in C++17

kalinda