Say we have an utility function:
std::string GetDescription() { return \"The description.\"; }
Is it OK to return the string literal? Is th
std::string GetDescription() { return "XYZ"; }
is equivalent to this:
std::string GetDescription() { return std::string("XYZ"); }
which in turn is equivalent to this:
std::string GetDescription() { return std::move(std::string("XYZ")); }
Means when you return std::string("XYZ") which is a temporary object, then std::move is unnecessary, because the object will be moved anyway (implicitly).
Likewise, when you return "XYZ", then the explicit construction std::string("XYZ") is unnecessary, because the construction will happen anyway (implicitly).
So the answer to this question:
Is the implicitly created std::string object copied?
is NO. The implicitly created object is after all a temporary object which is moved (implicitly). But then the move can be elided by the compiler!
So the bottomline is this : you can write this code and be happy:
std::string GetDescription() { return "XYZ"; }
And in some corner-cases, return tempObj is more efficient (and thus better) than return std::move(tempObj).