Possible Duplicate:
C++11 rvalues and move semantics confusion
What I think is correct is
std::string GetLine()
{
std::string str;
std::getline(std::cin, str);
return std::move(str);
}
But at this link http://www.cprogramming.com/c++11/rvalue-references-and-move-semantics-in-c++11.html ( check the header part Returning an explicit rvalue-reference from a function)
which is #1 google search hit for move semantics shows a similar function signature as
int&& GetInt()
{
int x = 0;
// code here
return std::move(x);
}
From what I read at other places && means rvalue reference so in this case its returning a reference to an object that doesn't exist.
So which is it?
(Yes I know moving an int has no real benifit but the question is whether to use the return type of std::string or std::string&& in the first function. And if that is how it should be done for all types.)