There are quite many threads about rvalue (reference).
But I haven't found the answer to my following question:
According to http://en.cppreference.com/w/cpp/utility/move, std::move() takes a rvalue reference as the parameter.
According to the graph in C++11 Standard http://i.stack.imgur.com/YKlod.png, a lvalue won't be rvalue.
Common usage of std::move():
Foo f;
std::deque<Foo> fq;
fq.push_back(std::move(f));
f is a lvalue because it is an object according to C++11 standard:
An lvalue (so-called, historically, because lvalues could appear on the left-hand side of an assignment expression) designates a function or an object. [Example: If E is an expression of pointer type, then *E is an lvalue expression referring to the object or function to which E points. As another example, the result of calling a function whose return type is an lvalue reference is an lvalue.]
Then, in theory, std::move(f) should give me an compile error, but it doesn't. I am sure that I miss something...
Any input is welcome.
std::move
does not take an rvalue-reference, but a forwarding-reference (aka universal reference), which means it can be either an lvalue and and rvalue reference. – DeduplicatorT
is deduced, like the prototype of thestd::move
-template. In that case, if you really want to restrict to rvalue-references, use SFINAE orstatic_assert
and type-traits. – Deduplicator