Associative array .get with .init as default second argument

bearophile bearophileHUGS at lycos.com
Mon Oct 18 13:02:02 PDT 2010


Torarin:

> This is what STL map's operator [] does, and I think it's handy. It
> only requires the addition of this overload:
> 
>     Value get(Key key)
>     {
>         auto p = key in *cast(Value[Key]*)(&p);
>         return p ? *p : Value.init;
>     }

In what cases is this useful? Are you able to show me an example of situation where it is useful?

Bye,
bearophile


More information about the Digitalmars-d mailing list