I have a function which modifies std::string& lvalue references in-place, returning a reference to the input parameter:
std::string& tra
This leads me to believe a copy would happen from the std::string& return value of the lvalue reference version of transform(...) into the std::string return value.
Is that correct?
The return reference version will not let std::string copy happened, but the return value version will have copy, if the compiler does not do RVO. However, RVO has its limitation, so C++11 add r-value reference and move constructor / assignment / std::move to help handle this situation. Yes, RVO is more efficient than move semantic, move is cheaper than copy but more expensive than RVO.
Is it better to keep my std::string&& transform(...) version?
This is somehow interesting and strange. As Potatoswatter answered,
std::string transform(std::string&& input)
{
return transform(input); // calls the lvalue reference version
}
You should call std::move manually.
However, you can click this developerworks link: RVO V.S. std::move to see more detail, which explain your problem clearly.