Assocative array lookup for object

Ali Çehreli acehreli at yahoo.com
Wed Apr 12 13:09:07 UTC 2023


On 4/12/23 04:35, Salih Dincer wrote:

 > I made a little mistake and I'll fix it before someone rub nose in it :)

You asked for it! :)

 >    auto opIndex(string key) {
 >      if(auto ret = key in data)
 >      {
 >        return *ret;
 >      }
 >      return null;
 >    }

Not every type is null'able but nullable. ;) So, a design may use the 
following:

   https://dlang.org/library/std/typecons/nullable.html

Ali



More information about the Digitalmars-d-learn mailing list