Reputation: 68588
I think I'm missing something basic regarding the lvalue-to-rvalue standard conversion.
From C++11 4.1:
A glvalue of a non-function, non-array type T can be converted to a prvalue
So we declare a variable x
:
int x = 42;
An expression x
in this scope is now an lvalue (so also a glvalue). It satisfies the requirements in 4.1 for an lvalue-to-rvalue conversion.
What is a typical example of a context where the lvalue-to-rvalue conversion is applied to the expression x
?
Upvotes: 3
Views: 2332
Reputation: 45410
A prvalue ("pure" rvalue) is an expression that identifies a temporary object (or a subobject thereof) or is a value not associated with any object.
struct Bar
{
int foo()
{
int x = 42;
return x; // x is converted to prvalue
}
};
the expression bar.foo()
is a prvalue.
OR
Lambda expressions, such as
[](int x){return x*x;}
§ 3.10.1
A prvalue (“pure” rvalue) is an rvalue that is not an xvalue. [ Example: The result of calling a function whose return type is not a reference is a prvalue. The value of a literal such as 12, 7.3e5, or true is also a prvalue. —end example ]
see n3055.
Upvotes: 5