Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, there are three categories of expressions<sup>1</sup>:</p> <ol> <li>those that represent objects that have an identity and cannot be moved from;</li> <li>those that represent objects that have an identity and can be moved from;</li> <li>those that represent objects that do not have an identity and can be moved from;</li> </ol> <p>The first ones are called lvalues, the second ones are xvalues, and the third ones are prvalues. If we put lvalues and xvalues together, we have glvalues. Glvalues are all expressions that represent objects with an identity. If we put xvalues and prvalues together we have rvalues. Rvalues are all expressions that represent objects that can be moved.</p> <p>The expression in question, <code>x</code>, is a glvalue: one can write <code>&amp;x</code>, so the object clearly has an identity.</p> <p>Can we move from this expression? Is this object about to expire? No, it is not. It only expires sometime after the current expression. That means it cannot be moved from. That makes it an lvalue.</p> <p>All these names can be a bit confusing because lvalue and rvalue in C++ no longer mean what they meant in their C origins. The C++ meaning is completely unrelated to being on the left or right side of assignment<sup>2</sup>.</p> <p>Personally, I prefer to use the terminology from <a href="http://stroustrup.com/terminology.pdf">this paper</a> by Bjarne: iM-values (instead of lvalues), im-values (instead of xvalues), Im-values (instead of prvalues), i-values (instead of glvalues), and m-values (instead of rvalues). That is not the terminology that the standard uses, unfortunately.</p> <hr> <p><sup>1</sup> Here "have an identity" means "its address can be taken"; "can be moved from" means that it is about to expire, either due to its temporary nature, or because the programmer made that explicit in the type system by calling <code>std::move</code> or something similar.</p> <p><sup>2</sup> You can have rvalues on the left side of assignment: <code>std::vector&lt;int&gt;(17) = std::vector&lt;int&gt;(42)</code> is a valid expression, even if it is useless.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload