Skip to content

Instantly share code, notes, and snippets.

@LucianoPAlmeida
Created November 29, 2021 00:02
Show Gist options
  • Save LucianoPAlmeida/cfcb3916b3ce0ab328325a49a3a99d41 to your computer and use it in GitHub Desktop.
Save LucianoPAlmeida/cfcb3916b3ce0ab328325a49a3a99d41 to your computer and use it in GitHub Desktop.
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