The OpenD Programming Language

matchMember

Applies a member handler to the given Variant depending on the held type, ensuring that all types are handled by the visiting handler.

Fuses algebraic types on return.

import mir.algebraic;
alias matchMember(string member, TArgs...) = visitImpl!(getMemberHandler!(member, TArgs), Exhaustive.compileTime, true)

Examples

static struct S
{
    Nullable!int m;
}

static struct C1
{
    Variant!(float, double) m;
}

alias V = Variant!(S, C1);

V x = S(2.nullable);
V y = C1(Variant!(float, double)(4.0));

// getMember returns an algebraic of algebraics
static assert(is(typeof(x.getMember!"m") == Variant!(Variant!(float, double), Nullable!int)));
// matchMember returns a fused algebraic
static assert(is(typeof(x.matchMember!"m") == Nullable!(int, float, double)));
assert(x.matchMember!"m" == 2);
assert(y.matchMember!"m" != 4);
assert(y.matchMember!"m" == 4.0);

Meta