What does double ampersand return type mean?
I came across a syntax like this:
int&& move(int&& x)
{
return x;
}
which supposedly implements the function std::move
, but I don't quite understand what the return type (& &) means.
I've googled and couldn't answer, can someone please explain this to me?
EDIT:
Most of my confusion comes from the fact that the function return already has an r value, so I don't understand that && can change there .. not sure if I make sense or not.
source to share
From: http://www.stroustrup.com/C++11FAQ.html#rval
&&
indicates an "rvalue reference". An rvalue reference can bind to rvalues (but not lvalues):
X a;
X f();
X& r1 = a; // bind r1 to a (an lvalue)
X& r2 = f(); // error: f() is an rvalue; can't bind
X&& rr1 = f(); // fine: bind rr1 to temporary
X&& rr2 = a; // error: bind a is an lvalue
source to share
In this case, the move function uses what is called rvalue references
a relatively new C ++ function. This is explained well in this article .
source to share