The following codes make VC2010 fail :
//code1
std::string& test1(std::string&& x){
return x;
}
std::string str("xxx");
test1(str); //#1 You cannot bind an lvalue to an rvalue reference
//code2
std::string&& test1(std::string&& x){
return x; //#2 You cannot bind an lvalue to an rvalue reference
}
There are some articles to explain #1, but I don't understand why #2 also fails.
let's see how std::move implements
template<class _Ty> inline
typename tr1::_Remove_reference<_Ty>::_Type&&
move(_Ty&& _Arg)
{ // forward _Arg as movable
return ((typename tr1::_Remove_reference<_Ty>::_Type&&)_Arg);
}
- The argument of move is still a rvalue reference,but move(str) is ok!
- move also returns rvalue.
What's the magic of std:move?
Thanks