Question about the new AA behavior in 0.19
Sean Kelly
sean at f4.ca
Thu Aug 10 21:25:52 PDT 2006
Anton V Staaf wrote:
> I've just started working with D. I'm very pleased with what I see.
> I have noticed something that might be a bug though. I'm not sure the
> correct protocol for reporting potential bugs, so I figured I'd send my
> thoughts here first.
>
> The following code apparently worked in earlier versions of D (I
> haven't tested this, but have seen similar code in other threads):
>
> import std.stdio;
>
> void main ()
> {
> int[int][int] array;
>
> array[12][15]++;
> }
>
> I compiled this with:
>
> gdc test.d -o test
>
> And when run it results in an ArrayBoundsError exception being
> thrown. After reading the message boards I came across a change in 0.19
> that I think is responsible. Apparently associative arrays would add
> entries just by being referenced. 0.19 removed this behavior and they
> now throw ArrayBoundsError exceptions. This makes perfect sense to me
> and is the right behavior (at least it seems to be to me).
Personally, I'd prefer if use of AAs as an lvalue inserted the element
if it didn't exist and then returned a reference to this element, while
use of AAs as an rvalue simply returned the init value of the contained
type and didn't modify the AA. 'in' could still be used for testing
whether the AA contained the value or not. But I suppose that's water
under the bridge at this point ;-)
Sean
More information about the Digitalmars-d
mailing list