Consider the following snippet:
std::string foo(std::string x) {
x += "!";
return x;
}
// ...
std::string y = "Hello";
// ...
y = foo(y);
My questions:
- Does the compiler recognize that
ycan be moved when passed tofoo, since it's going to be assigned into right after that. - If not, is it valid for me to add
std::movefor passingytofoo:y = foo(std::move(y))? Does it eliminate all copies?