Created
February 28, 2014 00:09
-
-
Save foobit/9262501 to your computer and use it in GitHub Desktop.
Copy Elision and the RVO: http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/
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
std::vector<std::string> | |
sorted(std::vector<std::string> names) | |
{ | |
std::sort(names); | |
return names; | |
} | |
// names is an lvalue; a copy is required so we don't modify names | |
std::vector<std::string> sorted_names1 = sorted( names ); | |
// get_names() is an rvalue expression; we can omit the copy! | |
std::vector<std::string> sorted_names2 = sorted( get_names() ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment