The OpenD Programming Language

getMember

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

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

Examples

static struct S { auto bar(int a) { return a; } enum boolean = true; }
static struct C2 { alias bar = (double a) => a * 2; enum boolean = false; }

alias V = Variant!(S, C2);

V x = S();
V y = C2();

static assert(is(typeof(x.getMember!"bar"(2)) == Variant!(int, double)));
assert(x.getMember!"bar"(2) == 2);
assert(y.getMember!"bar"(2) != 4);
assert(y.getMember!"bar"(2) == 4.0);

// direct implementation
assert(x.bar(2) == 2);
assert(y.bar(2) != 4);
assert(y.bar(2) == 4.0);
assert(x.boolean);
assert(!y.boolean);

Meta