Following is the code snippet:
int i=0;
int&&k=std::move(i);
In c++ primer the move is
template <typename T>
typename remove_reference<T>::type &&move(T&& t)
{return static_cast<typename remove_reference<T>::type&&>(t);}
As far as i know,this std::move
template will deduct a function like
int&& move(int& t){return static_cast<int&&>(t);}
As a comparison and to elaborate my question,consider an example like this:
int test(int k){k=66;return k;}
int k;
int a=test(k);
The code above will be compiled as:
int temp;//the temporary object
temp=k;
int a=temp;
Similarly,i think the first code snippet will be compiled as:
int&& temp=0;
int&& k=temp;//oop!temp is an lvalue!
which seems wrong because temp
is an lvalue,did i get something wrong?
int &&k = static_cast<int&&>(i);
. – Wulfstd::move
is just a cast. It will cast an lvalue or rvalue to an rvalue. – Hankins