Search for, o/w create element for AA

Q. Schroll via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 19 10:07:34 PDT 2017


On Monday, 19 June 2017 at 16:54:46 UTC, Ali Çehreli wrote:
> On 06/19/2017 08:19 AM, Q. Schroll wrote:
>
>> Can't I tell the AA to set a value for a given key if it 
>> doesn't already
>> have one
>>  (1) with only one lookup, and
>>  (2) in a safe way?
>
> aa.get(key, defaultValue)
>
>   https://dlang.org/spec/hash-map.html#properties
>
> Ali

aa.get returns the defaultValue if the key is not in the AA, but 
does not add the key-value pair (x, defaultValue) to the AA. I'd 
find it rather surprising if it did.


More information about the Digitalmars-d-learn mailing list