Skip to content

Provide convenient access to the type index #56

@pbackus

Description

@pbackus

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions