I’m trying to understand the C++11 concepts.
The standard draft which I have says:
An xvalue (an “eXpiring” value) also refers to an object, usually near the end of its lifetime (so that its
resources may be moved, for example). An xvalue is the result of certain kinds of expressions involving
rvalue references (8.3.2). [ Example: The result of calling a function whose return type is an rvalue
reference is an xvalue. —end example ]
OK, so what exactly are the “certain kinds of expressions” that produce xvalues? This part of the spec does not detail a list of these expressions.
I understand lvalue and prvalue (at least I think, I understand).
There is a helpful non-normative note in the introduction to §5 (C++11 §5[expr]/6):
Searching through the rest of §5, this list appears exhaustive. The list is followed by an example:
There are two common ways to get an xvalue expression:
Use
std::moveto move an object.std::moveperforms astatic_castto an rvalue reference type and returns the rvalue reference.Use
std::forwardto forward an rvalue.std::forwardis typically used in a function template to enable perfect forwarding of a function argument.If the argument provided to the function template was an rvalue, the parameter type will be an rvalue reference, which is an lvalue. In this case,
std::forwardperforms astatic_castto an rvalue reference type and returns the rvalue reference.(Note: If the argument provided to the function template was an lvalue, the parameter type will be an lvalue reference and
std::forwardwill return an lvalue reference.)