What are lvalues ,rvalues, xvalues, glvalues, and prvalues in cpp?

1 Like

The traditional dichotomy between lvalues and rvalues is subdivided into five overlapping categories.

The result of binding an rvalue reference to an object is called an “xvalue” (inspired by the fact that the canonical use of an rvalue reference is to move the resources of a value that is “eXpiring,” i.e., at the end of its lifetime).

Traditional lvalues retain that name. Together, xvalues and lvalues are called “glvalues” (“generalized” lvalues).

Rvalues, as currently known in the core language clauses, are renamed to “prvalues” (“pure” rvalues). Together, prvalues
and xvalues are called “rvalues,”

reflecting the use of that term in the library clauses and the intended uses in reference binding, overload resolution, and template argument deduction.

This taxonomy provides the means to refer collectively to expressions that designate objects in memory or functions (“glvalues”) and to expressions that can be used to initialize rvalue references (the new “rvalues”), as well as to designate the specific kinds of values when that is necessary. • Xvalues are created by three kinds

. expression
glvalue rvalue
| |
----------------- ---------------------
| | | |
lvalue xvalue prvalue

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 which E points. As another example, the result of calling a function whose return type is an lvalue reference is an lvalue.

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 . [Example: The result of calling a function whose return type is an rvalue reference is an xvalue. — end example]

A glvalue (“generalized” lvalue) is an lvalue or an xvalue.

An rvalue (so-called, historically, because rvalues could appear on the right-hand side of an assignment expression) is an xvalue, a temporary object or subobject thereof, or a value that is not associated with an object.

A 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 , or true, is also a prvalue. —end example]