25
Prior to C++11 there were only two value categories for expression tree types: lvalue and woodland. Quite simply, the first represents a reference that can be changed and whose address can be read, while the second is a temporary one, such as literal values.
Already in C++ there was an explosion that added 3 new types. Now are they:
woodland
lvalue
xvalue
glvalue
prvalue
The standard (on N3337, session 3.10 paragraph 1) says the following:
- 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 whichE
points. As Another example, the result of Calling a Function Whose Return type is an lvalue Reference is an lvalue. - end example ]- 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 ]
- To glvalue ("Generalized" lvalue) is an lvalue or an xvalue.
- An woodland (so called, historically, because rvalues could appear on the right-hand side of an assignment Expression) is an xvalue, a Temporary Object (12.2) or subobject thereof, or a value that is not Associated with an Object.
- To prvalue ("Pure" rvalue) is an rvalue that is not an xvalue. [ Example: The result of Calling a Function Whose Return type is not a Reference is a prvalue. The value of a literal such as 12, 7.3e5, or true is also a prvalue. - end example ]
This explanation, although obviously correct, is not very clear in spelling out the role of each category in each context, nor does it help explain how to classify the result of an expression in one of the categories. For example, which category (1+1)
, which is classified in an integral constant expression, belongs to?
How to explain clearly what each category is?
What is the purpose of creating these new categories?
Basically your answer is complementary to mine, with more examples. It is correct too. I leave the acceptance of the answer to your discretion.
– Leonel Sanches da Silva