std.sumtype?

drug drug2004 at bk.ru
Mon Aug 30 10:50:40 UTC 2021


30.08.2021 13:20, Oleg B пишет:
> 
> ```d
> auto typeIndex(T)(in T val) if (is(T == SumType!Args, Args...))
> {
>    return match!(v => staticIndexOf!(typeof(v), T.Types))(*(cast(T*)&val));
> }
> ```

A little tip: you can use just `cast()` to remove qualifiers:
```D
return match!(v => staticIndexOf!(typeof(v), T.Types))(cast()val));
```


More information about the Digitalmars-d mailing list