Created
November 29, 2021 00:02
-
-
Save LucianoPAlmeida/cfcb3916b3ce0ab328325a49a3a99d41 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> all_strings; | |
for(int i = 0; i < aLenght; ++i) { | |
std::string result = aCallThatProducesAStr(i); | |
// Note that push_back result will copy the contents of | |
// result to an new object that will be stored in the vector. | |
// all_strings.emplace_back(result); | |
// Since is the last use of result string object, move | |
// which is more efficient. | |
all_strings.emplace_back(std::move(result)); | |
// Any use of result variable after the move is undefined behavior. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment