phobos
phobos copied to clipboard
SumType should provide convenient access to the type index
snarwin+bugzilla (@pbackus) reported this on 2021-03-18T21:59:02Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=21731
Description
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]
dlang-bot commented on 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
dlang-bot commented on 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
dlang-bot commented on 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
#10650 didn't implement this, but other useful methods for procedural code.
This was implemented in #7886 and subsequently reverted in #7922. I am not opposed to adding it again, but it will be up to either Atila Neves or Adam Wilson (not sure who's currently in charge of Phobos v2) whether it gets merged.