optionalVisit

Behaves as visit but doesn't enforce at compile time that all types can be handled by the visiting functions.

alias optionalVisit(visitors...) = visitImpl!(naryFun!visitors, Exhaustive.nullable, false)

Return Value

nullable variant, null value is used if naryFun!visitors can't be called with provided arguments.

Examples

static struct S { int a; }

Variant!(S, double) variant;

alias optionalVisitInst = optionalVisit!((ref value) => value + 0);

// do nothing because of variant isn't initialized
Nullable!double result = optionalVisitInst(variant);
assert(result.isNull);

variant = S(2);
// do nothing because of lambda can't compile
result = optionalVisitInst(variant);
assert(result == null);

variant = 3.0;
result = optionalVisitInst(variant);
assert (result == 3.0);

Meta