key membership in multi-dimensional assoc. array

Paul phshaffer at gmail.com
Thu Jun 15 05:53:07 UTC 2023


On Thursday, 15 June 2023 at 02:21:16 UTC, Steven Schveighoffer 
wrote:
>
> Not in as short code. You could write a helper though:
>
> ```d
> auto deepIn(V, K, Keys...)(V[K] aa, Keys keys) if (Keys.length
> > 0)
> {
>    auto v = keys[0] in aa;
>    static if(keys.length == 1)
>      return v;
>    else
>      return v ? deepIn(*v, keys[1 .. $]) : null;
> }
>
> if(auto v = cubelist.deepIn(xKey, yKey, zKey)) { // v now 
> points at the value
> }
> ```
>
> -Steve
Thanks Steve.



More information about the Digitalmars-d-learn mailing list