Updated Value Categories
C++ 17 introduces some updated value categories. This part helps familiarize with them. Read below to find out more!
We'll cover the following
In C++98/03, we had two basic categories of expressions:
lvalue
- an expression that can appear on the left-hand side of an assignmentrvalue
- an expression that can appear only on the right-hand side of an assignment
C++11 extended this taxonomy (due to the move semantics), with three more categories:
xvalue
- an eXpiringlvalue
prvalue
- a purervalue
, anxvalue
, a temporary object or subobject, or a value that is not associated with an object.glvalue
- a generalisedlvalue
, which is anlvalue
or anxvalue
Examples:
std::string str;
str; // lvalue
42; // prvalue
str + "10" // prvalue
std::move(str); // xvalue
Let’s look at the Diagram
The tree chart below gives a better overview of the categories:
Get hands-on with 1400+ tech skills courses.