@FredOverflow mentioned in the C++ chatroom that this
is a rare case of rvalues that have names. The C++0x FDIS mentions under 5.1.1 [expr.prim.general] p4
:
Otherwise, if a member-declarator declares a non-static data member (9.2) of a class X, the expression
this
is a prvalue of type “pointer to X” within the optional brace-or-equal-initializer. It shall not appear elsewhere in the member-declarator. (emphasis mine)
What others are there, if any?
An lvalue (locator value) represents an object that occupies some identifiable location in memory (i.e. has an address). rvalues are defined by exclusion. Every expression is either an lvalue or an rvalue, so, an rvalue is an expression that does not represent an object occupying some identifiable location in memory.
The term rvalue is a logical counterpart for an expression that can be used only on the righthand side of an assignment. For example: #define rvalue 42 int lvalue; lvalue = rvalue; In C++, these simple rules are no longer true, but the names remain because they are close to the truth.
“l-value” refers to a memory location that identifies an object. “r-value” refers to the data value that is stored at some address in memory. References in C++ are nothing but the alternative to the already existing variable.
Rvalue references is a small technical extension to the C++ language. Rvalue references allow programmers to avoid logically unnecessary copying and to provide perfect forwarding functions. They are primarily meant to aid in the design of higer performance and more robust libraries.
One prominent case are enumerators
enum arity { one, two };
The expressions one
and two
are rvalues (more specifically, prvalues in C++0x). Another are template non-type parameters
template<int *P> struct A { };
The expression P
is an rvalue too (more specifically again, a prvalue in C++0x).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With