In my code I have a function that constructs a string from a piece of data and then returns it. This string isn't used anywhere else, so it's safe for the receiving side to use move-assignment or move-initialization on it.
std::string ReadString(...) {
...
return std::string(...)
}
This is basically what I have. Is there any point in making the function return type std::string&&, since the value being returned is an rvalue?
std::string&& ReadString(...) {
...
return std::string(...)
}
My concern is that there might be an excess copy being made when we return our string, and that it can be alleviated by making the return type an rvalue reference.
I suspect that the compiler may also be capable of optimizing for these scenarios, however, I am not sure.
So the question is - is there any point in making the return type an rvalue reference in this case and why? Also, if there isn't, then what are possible applications for functions returning rvalue references?
Thanks.