More magical AA semantics

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Jan 12 13:56:13 PST 2013


On 1/12/13 7:40 AM, Jonathan M Davis wrote:
> On Saturday, January 12, 2013 13:30:47 monarch_dodra wrote:
>> What about "++a[0]" when there is no a[0]? Is this something that
>> will throw or not?
>
> Personally, I think that it should, but there's probably a good chance that it
> won't, because it's an lvalue. I don't know what will happen with that though.
> There are a lot of bugs right now related elements being inserted into AAs
> when they shouldn't be, so I really don't know how much relation the current
> behavior will have with the behavior that AAs will ultimately have.

++a[0] should work.

>> As well, what about
>> //----
>> immutable(int)[int] aa;
>> aa[0] = 5;
>> //----
>> This should work, right?
>
> That should definitely work. That's how you add elements to AA. My gripe with
> something like ++a[0] working when there's no a[0] is that you'd be adding to
> an element that doesn't exist yet.

Shouldn't work.

Andrei




More information about the Digitalmars-d mailing list