Given this example:
std::vector<std::string> split(const std::string& str) {
std::vector<std::string> result;
std::string curr;
for (auto c : str) {
if (c == DELIMITER) {
result.push_back(std::move(curr)); // ATTENTION HERE!
} else {
curr.push_back(c);
}
}
result.push_back(std::move(curr));
return result;
}
Can I reuse the curr
std:string? This snippet seems working: after curr
is moved inside
the result
vector, it becomes empty. I want to be sure this is not an undefined behavior in the standard and it isn't working only because of luck.