| Start |
|---|
| Value Category Meanings Expressions in C++ are assigned a particular value category, based on the result of those expressions. Value categories for expressions can affect C++ function overload resolution. Value categories determines two important-but-separate properties about an expression. One property is whether the expression has identity. An expression has identity if it refers to an object that has a variable name. The variable name may not be involved in the expression, but the object can still have one. The other property is whether it is legal to implicitly move from the expression's value. Or more specifically, whether the expression, when used as a function parameter, will bind to r-value parameter types or not. C++ defines 3 value categories which represent the useful combination of these properties: lvalue (expressions with identity but not movable from), xvalue (expressions with identity that are moveable from), and prvalue (expressions without identity that are moveable from). C++ does not have expressions which have no identity and cannot be moved from. C++ defines two other value categories, each based solely on one of these properties: glvalue (expressions with identity) and rvalue (expressions that can be moved from). These act as useful groupings of the prior categories. This graph serves as an illustration: |
| rvalue An rvalue expression is any expression which can be implicitly moved from, regardless of whether it has identity. More precisely, rvalue expressions may be used as the argument to a function that takes a parameter of type The category of rvalue expressions includes all xvalue and prvalue expressions, and only those expressions. The standard library function Consider the following:
Line 3 changes things. The return value of Line 4 passes a temporary to the assignment operator of Line 5 creates a named rvalue reference called See, while To move it, we would have to employ |
| xvalue An xvalue (eXpiring value) expression is an expression which has identity and represents an object which can be implicitly moved from. The general idea with xvalue expressions is that the object they represent is going to be destroyed soon (hence the "eXpiring" part), and therefore implicitly moving from them is fine. Given: |
| prvalue A prvalue (pure-rvalue) expression is an expression which lacks identity, whose evaluation is typically used to initialize an object, and which can be implicitly moved from. These include, but are not limited to:
The built-in addressof operator ( |
| lvalue An lvalue expression is an expression which has identity, but cannot be implicitly moved from. Among these are expressions that consist of a variable name, function name, expressions that are built-in dereference operator uses and expressions that refer to lvalue references. The typical lvalue is simply a name, but lvalues can come in other flavors as well: Additionally, while most literals (e.g. |
| glvalue A glvalue (a "generalized lvalue") expression is any expression which has identity, regardless of whether it can be moved from or not. This category includes lvalues (expressions that have identity but can't be moved from) and xvalues (expressions that have identity, and can be moved from), but excludes prvalues (expressions without identity). If an expression has a name, it's a glvalue: |
Read Article
https://develop.horje.com/learn/1434/reference