Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What rvalues have names?

@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?

like image 699
Xeo Avatar asked May 28 '11 14:05

Xeo


People also ask

What are Lvalues and Rvalues?

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.

What are Rvalues?

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.

Are references Lvalues?

“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.

What is R value reference in C++?

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.


1 Answers

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).

like image 148
Johannes Schaub - litb Avatar answered Oct 24 '22 18:10

Johannes Schaub - litb