Inserting to associative array do not return a lvalue.

Yang Bo pop.atry at gmail.com
Tue Oct 16 01:43:18 PDT 2007


Sorry. I thought I have a mistake. Holding a pointer to the value of an
associative array is very dangerious.Yang Bo 写道:
> I tend to write code like this:
> 
> int[int] a;
> int* r = &(a[1] = 2); // error
> (*r)++;
> 
> The problem is, `a[1] = 2` does not return a lvalue. I must write:
> 
> int[int] a;
> a[1] = 2;
> int* r = a[1];
> (*r)++;
> 
> I have to look up the associative array twice, this is unwanted cost.



More information about the Digitalmars-d mailing list