I\'m trying to understand rvalue references and move semantics of C++11.
What is the difference between these examples, and which of them is going to do no vector cop
None of them will copy, but the second will refer to a destroyed vector. Named rvalue references almost never exist in regular code. You write it just how you would have written a copy in C++03.
std::vector return_vector()
{
std::vector tmp {1,2,3,4,5};
return tmp;
}
std::vector rval_ref = return_vector();
Except now, the vector is moved. The user of a class doesn't deal with it's rvalue references in the vast majority of cases.