Feature to get or add value to an associative array.

Giles Bathgate giles.bathgate at gmail.com
Tue Apr 17 07:40:23 UTC 2018


On Tuesday, 17 April 2018 at 00:04:32 UTC, Cym13 wrote:
> "in" returns a pointer to the object, there'es not double 
> lookup necessary:
>
>     // if we don't know .get(key, default) exists
>     auto ptr   = key in aa;
>     auto value = ptr ? *ptr : default;

This doesn't work. `in` returns null when the key doesn't exist. 
So you are de-referencing null: 
https://github.com/dlang/druntime/blob/master/src/rt/aaA.d#L417

> is a new flag/method really that necessary? In my experience if 
> you have trouble naming it you haven't found its true purpose 
> yet.

My personal reason for not liking it is because the same name is 
used by Microsoft: 
https://msdn.microsoft.com/en-us/library/ee378676(v=vs.110).aspx

I think I have clearly explained its purpose.




More information about the Digitalmars-d mailing list