[Issue 21731] New: SumType should provide convenient access to the type index
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Mar 18 21:59:02 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=21731
Issue ID: 21731
Summary: SumType should provide convenient access to the type
index
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: snarwin+bugzilla at gmail.com
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/ouqgmoxzlcyrfqxsrtnm@forum.dlang.org
--
More information about the Digitalmars-d-bugs
mailing list