Assocative array lookup for object
Salih Dincer
salihdb at hotmail.com
Wed Apr 12 11:35:18 UTC 2023
On Wednesday, 12 April 2023 at 04:57:58 UTC, Salih Dincer wrote:
> I think you want to do an encapsulation like below.
>
> ```d
> auto opIndex(string key)
> => *(key in data);
> ```
I made a little mistake and I'll fix it before someone rub nose
in it :)
```d
auto opIndex(string key) {
if(auto ret = key in data)
{
return *ret;
}
return null;
}
assert(handler["D Lang"] == &foo);
assert(handler["null"] is null);
```
SDB at 79
More information about the Digitalmars-d-learn
mailing list