tryGetMember

Behaves as getMember but doesn't enforce at compile time that all types can be handled by the member visitor.

alias tryGetMember(string member) = visitImpl!(getMemberHandler!member, Exhaustive.exception, false)

Throws

Exception if member can't be accessed with provided arguments

Examples

static struct S { int bar(int a) { return a; }}
static struct C { alias Bar = (double a) => a * 2; }

alias V = Variant!(S, C);

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

static assert(is(typeof(x.tryGetMember!"bar"(2)) == int));
static assert(is(typeof(y.tryGetMember!"Bar"(2)) == double));
assert(x.tryGetMember!"bar"(2) == 2);
assert(y.tryGetMember!"Bar"(2) == 4.0);
alias Number = Variant!(int, double);

Number x = Number(23);
Number y = Number(1.0);

assert(x.visit!((int v) => true, (float v) => false));
assert(y.visit!((int v) => false, (float v) => true));

Meta