Comment #0 by snarwin+bugzilla — 2021-03-18T21:59:02Z
This feature was requested on the D forums [1].
It is possible to compute the type index in user code, but the implementation is a bit verbose, and easy to get wrong:
```d
size_t typeIndex(Val)(Val val)
if (isSumType!Val)
{
alias QualifiedTypes = CopyTypeQualifiers!(Val, Val.Types);
return val.match!(v => staticIndexOf!(typeof(v), QualifiedTypes));
}
```
For both convenience and correctness, it would be better if this functionality were included in the `sumtype` module.
[1] https://forum.dlang.org/post/[email protected]
Comment #1 by dlang-bot — 2021-03-19T01:29:41Z
@pbackus created dlang/phobos pull request #7886 "Fix Issue 21731 - SumType should provide convenient access to the typ…" fixing this issue:
- Fix Issue 21731 - SumType should provide convenient access to the type index
https://github.com/dlang/phobos/pull/7886
Comment #2 by dlang-bot — 2021-03-20T14:11:04Z
dlang/phobos pull request #7886 "Fix Issue 21731 - SumType should provide convenient access to the typ…" was merged into master:
- 50c7945236e4fd8e1dfa5992c54bde67ac35c7fb by Paul Backus:
Fix Issue 21731 - SumType should provide convenient access to the type index
https://github.com/dlang/phobos/pull/7886
Comment #3 by dlang-bot — 2021-03-26T21:01:29Z
dlang/phobos pull request #7922 "Revert "Fix Issue 21731 - SumType should provide convenient access to the typ…"" was merged into master:
- 9ec6cba13499d7d7950ee447556d351547282f45 by Atila Neves:
Revert "Fix Issue 21731 - SumType should provide convenient access to the typ…"
https://github.com/dlang/phobos/pull/7922
Comment #4 by robert.schadek — 2024-12-01T16:38:32Z