Created
April 27, 2023 08:13
-
-
Save nthery/26b4e87408a3738d6cc7ec9ce57669dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example showing when temporary materialisation and copy elision occurs. | |
struct S { | |
S(); | |
~S(); | |
S(const S&); | |
S& operator=(const S&); | |
S(S&&) noexcept; | |
S& operator=(S&&) noexcept; | |
S& set(int); | |
}; | |
void h(); | |
void f() { | |
// initialisation causes temporary materialisation => copy elision | |
auto s = S(); | |
h(); | |
} | |
void g() { | |
// calling set() causes temporary materialisation => copy not elided | |
auto s = S().set(42); | |
h(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment