Guaranteed Copy Elision
This part introduces the concept of Copy Elision and its role in optimization.
We'll cover the following...
Copy Elision is a common optimisation that avoids creating unnecessary temporary objects.
Copy Elision Example
For example:
Press + to interact
#include <iostream>using namespace std;struct Test{Test() { std::cout << "Test::Test\n"; }Test(const Test&) { std::cout << "Test(const Test&)\n"; }Test(Test&&) { std::cout << "Test(Test&&)\n"; }~Test() { std::cout << "~Test\n"; }};Test Create(){return Test();}int main(){auto n = Create();}
In the above call, you might assume a temporary copy is used - to store the ...