On 5/03/11 4:39 AM, Jonathan M Davis wrote:
On Friday 04 March 2011 20:31:38 Walter Bright wrote:
uri wrote:
Explain why (a*b) is lvalue in bearophile's second example.

Because the expression evaluates to a temporary, which is an lvalue.

This is one of the weird things in D. The language is too complex. It
takes years to find out about the corner cases.

It's not a weird corner case at all. Temporaries can be used as lvalues (in
C++ too).

Really? I thought that a temporary was pretty much _the_ classic example of an
rvalue. If you can assign to temporaries, you can assign to most anything then,
other than literals. Why on earth would assigning to temporaries be permitted?
That just seems unnecessary and bug-prone.

- Jonathan M Davis

How do you think array assignments in C++ work?

a[i] = x;

a[i] is just *(a + i), i.e. the evaluation of an expression that yields a temporary, which in this case is an lvalue. Same applies to all other operator[] overloads.

Reply via email to