This code works as expected (online here ). At the end, v empty, and w not empty, since it typed the contents of v .
vector<int> v; v.push_back(1); cout << "v.size(): " << v.size() << endl; auto vp = move(v); vector<int> w(vp); cout << "w.size(): " << w.size() << endl; cout << "v.size(): " << v.size() << endl;
But if I replaced auto vp=move(v) with
vector<int> && vp = move (v);
Then he does not move. Instead, it copies and both vectors are not empty at the end. As shown here .
Explanation: In particular, what is a type with automatic vp production? If it is not vector<int> && , then what else could it be? Why do the two examples give different results, even though they are so similar?
Extra . I also tried this and it was still copying instead of moving
std :: remove_reference< vector<int> > :: type && vp = move(v);
source share