Skip to content

Instantly share code, notes, and snippets.

@fortheday
Created January 31, 2018 06:25
Show Gist options
  • Save fortheday/138af1eceabd6907edf0df7070356f9c to your computer and use it in GitHub Desktop.
Save fortheday/138af1eceabd6907edf0df7070356f9c to your computer and use it in GitHub Desktop.
class CTest {
public:
CTest() { puts("ctor"); }
CTest(CTest &&rrRight) { puts("ctor-m"); } // move
CTest & operator=(CTest &&rrRight) noexcept { puts("assign-m"); return *this; } // move
CTest & operator=(CTest &rRight) { puts("assign"); return *this; } // copy (일반적으로 딥카피)
};
auto createTest1 = []() -> CTest
{
CTest test;
return test;
};
auto createTest2 = []() -> CTest
{
return CTest();
};
CTest test1 = createTest1(); // NRVO(/O2)적용시 (1)ctor 미적용시 (1)ctor (2)ctor-m
CTest test2 = createTest2(); // RVO. (1)ctor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment