In C++, every expression has a value category. An lvalue is an expression that identifies an object with a persistent identity, such as a named variable, so you can take its address. An rvalue is an expression that is either a temporary (a prvalue) or an object marked as expiring (an xvalue), so its resources can be moved from. Since C++11 this distinction powers move semantics, rvalue references and perfect forwarding.
The old rule "lvalues go on the left of =, rvalues on the right" is only a rough guide. The precise model has five categories, and understanding it explains std::move, T&& and why a named rvalue reference is itself an lvalue.
The standard defines these categories:
| Category | Meaning | Example |
|---|---|---|
| lvalue | Has identity, cannot be moved from implicitly | x, *p, arr[0] |
| prvalue | Pure rvalue, initialises an object | 42, a + b, f() returning by value |
| xvalue | Has identity, resources can be reused | std::move(x), static_cast<T&&>(x) |
| glvalue | lvalue or xvalue | |
| rvalue | prvalue or xvalue |
A quick test: if you can take the address of the expression with &, it is an lvalue. If it is a temporary with no name, it is a prvalue.
In C++, even ++x is an lvalue (it refers to x), while x++ is a prvalue because it returns a copy of the old value.
Rvalues are temporaries you cannot take the address of:
An rvalue reference, written T&&, binds to rvalues. Overloading on const T& and T&& lets a function copy from lvalues and move from temporaries:
std::move does not move anything. It is a cast to an rvalue reference, static_cast<T&&>, which turns an lvalue into an xvalue so that a move constructor or move assignment can be selected. After you move from an object, leave it only for destruction or assignment, since it is in a valid but unspecified state.
A named rvalue reference is an lvalue, because it has a name:
In a template, T&& with a deduced T is a forwarding reference and can bind to both lvalues and rvalues. Use std::forward<T>(arg) to preserve the original category:
Since C++17, a prvalue does not create a temporary that is then copied: it directly initialises the destination object. std::string s = make(); constructs the result in place, even if the type has no copy or move constructor. Avoid writing return std::move(local);, because it blocks this optimisation for named locals and triggers compiler warnings.
No. An lvalue can appear on either side, and a const lvalue cannot be assigned to at all. What matters is that the expression has identity.
Because you can refer to it by name repeatedly, so using it as an rvalue automatically would be unsafe. Use std::move or std::forward when you want to pass it on as an rvalue.
No. It only casts to an rvalue reference. The move happens in the move constructor or move assignment operator that overload resolution then selects.
A prvalue is a pure temporary value without identity. An xvalue is an existing object whose resources may be taken, typically the result of std::move.
In C++, lvalues have identity and a name or address, prvalues are temporaries, and xvalues are expiring objects that can be moved from. Rvalue references and std::move let you move rather than copy, forwarding references with std::forward preserve value category in templates, and C++17 guaranteed copy elision removes many copies entirely.