PrevUpHomeNext

01. c++ lvalue, rvalue, xvalue, prvalue, glvalue (understanding)


c++ lvalue, rvalue, xvalue, prvalue, glvalue

Created on Oct 24, 2024

cpp lvalue, rvalue, xvalue, prvalue, glvalue

c++ lvalue, rvalue, xvalue, prvalue, glvalue: c++ value categories

Categories

lvalue

Examples:

rvalue

Examples:

prvalue

xvalue

glvalue

silice

Q: Is an xvalue an rvalue ?

A: Yes, an xvalue is an rvalue, but it is not a pure rvalue, a pure rvalue is called prvalue.

Q: Which value the resource of can be reused?

A: Just the resource of lvalue can not be reused, the resource of all other values can be reused.

cppreference xvalue:

https://en.cppreference.com/w/cpp/language/value_category#xvalue

silice

Q: How to quickly understand all value categories?

A: An lvalue is a value that has an address that can be accessed by the program, its resource can not be reused. An rvalue is a value that is not lvalue, its resource can be reused. Most cases, when we talk about rvalue, we are actually talking about pure rvalue, which is called prvalue. There is a value category that is rvalue but not pure rvalue, it is xvalue. If the subspace expression of an rvalue expression contains an implicit named value, that is likely an xvalue, x here means expiring. Xvalue is rvalue, but it is not pure rvalue (prvalue). We put xvalue and lvalue to one category: glvalue (generalized lvalue).

See Also

cppreference c++ value categories

Microsoft c++ value categories

cpp/c++

c++ std::exception:

std::cout.write(err.data(), err.size());

std::cout << std::endl;

caught:

  ==================================================
  #        The c++ programming language.           #
  #                                                #
  #        Home: cppfx.xyz                         #
  #        E                                       #
  #        Deck                                    #
  ==================================================

PrevUpHomeNext