Created
September 5, 2012 17:04
-
-
Save AndreLouisCaron/3640062 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
std::vector<int> multiply (std::vector<int> input, int value) | |
{ | |
for (auto& i : input ) | |
i *= value; | |
return input; | |
} | |
int main (int, char**) | |
{ | |
std::vector<int> foo; | |
foo.push_back(1); | |
foo.push_back(2); | |
foo = multiply(foo, 2); | |
// Assuming a (very) aggressive inlining compiler, | |
// the last line could be rewritten as: | |
for (auto& i : foo) | |
i *= 2; | |
// ... no copy or move occurs! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perhaps I'm pushing it, but does is this inlining technically legal, given the standard "explicitly forbids eliding the move in [the case that the function returns its argument]"?