Wrong lowering for a[b][c]++

Jesse Phillips jessekphillips+D at gmail.com
Thu Mar 22 07:15:27 PDT 2012


On Wednesday, 21 March 2012 at 20:41:17 UTC, Alvaro wrote:

> I partially disagree. I think items should be added if we try 
> to *write* to them, but not when we *read* them (lvalue vs 
> rvalue). The problem is that it's hard to distinguish those 
> cases in C++ without an intermediate class that makes its use 
> uglier. So:
>
> int[int] a;
> a[3] = 1; // OK, add key 3
> b = a[5]; // error, add nothing
>
> And, compound assignment and increment/decrement are forms of 
> *writing*. So, they should trigger an element creation with the 
> .init value.
>
> a[5]++; // create a[5] = int.init; and then increment

I have used similar before, it is nicer than

if(5 !in a)
     a[5] = 1;
else
     a[5]++;

but after taking a look at reduce.

double[int] a;

What is the result of your code on 'a' now? double.init is NAN.


More information about the Digitalmars-d mailing list