Understanding the code for std::move()

Viewed 2523

I really want to understand the intrinsic details of the std::move() function.

The code for std::move() as stated here: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2027.html#Move_Semantics.

template <class T>
typename remove_reference<T>::type&&
move(T&& a)
{
    return a;
}

Why does this code return a rvalue reference? The parameter is a type T rvalue reference. Does a evaluate to the object pointed to by the rvalue reference, such that a rvalue reference is returned to the object? Also, why is the remove_reference<T> part required?

The tutorial also writes

This move() gives its target the value of its argument, but is not obliged to preserve the value of its source. So, for a vector, move() could reasonably be expected to leave its argument as a zero-capacity vector to avoid having to copy all the elements. In other words, move is a potentially destructive read.

but then it is said that

The move function really does very little work. All move does is accept either an lvalue or rvalue argument, and return it as an rvalue without triggering a copy construction.

Should this be understood as, the std::move() could first "empty" the object (in this case a std::vector) and thereafter return the object as an rvalue (according to the C++ specification)? But, that the official std::move() does exactly as specified in the latter quote?

And why is it said that std::move() returns a rvalue, when it returns a rvalue reference?

3 Answers
Related