AA default value?

Sean Kelly sean at f4.ca
Fri Jan 25 10:22:25 PST 2008


Oskar Linde wrote:
> Jarrett Billingsley wrote:
>> "Janice Caron" <caron800 at googlemail.com> wrote in message
>> news:mailman.24.1201263099.5260.digitalmars-d at puremagic.com...
>>
>>> Wouldn't
>>> it be nicer if, instead, it simply returned
>>>
>>> typeof(aa[key]).init
>>>
>>> if the key was not present in the array?
>>
>> What's funny is that a while ago ((long) before 1.0), if you looked up
>> a key in an AA and the key didn't exist, it'd be added with a value of
>> typeof(aa[key]).init.  So
>>
>> int[int] aa;
>> writefln(aa[5]);
>>
>> would give "0" as the output.
>>
>> This was to mirror the behavior of C++'s std::map but many people
>> opposed it, so now we have what we have now..
> 
> I believe the implemented solution to the old problem overshoot the best
> solution, which would have been to make a rvalue expression aa[5] return
> 0, but *without* inserting 5 into the aa.

Agreed.  And I think this was brought up at the time, but it wasn't
implemented for some reason.


Sean



More information about the Digitalmars-d mailing list