tryVisit

Behaves as visit but doesn't enforce that all types are handled by the visiting functions.

If a parameter-less function is specified it is called when either variant doesn't hold a value or holds a type which isn't handled by the visiting functions.

template tryVisit(Handlers...)
tryVisit
(
VariantType
)
(
VariantType variant
)
if (
isAlgebraic!VariantType
)
if (
Handlers.length > 0
)

Members

Functions

tryVisit
auto tryVisit(VariantType variant)

Return Value

The return type of tryVisit is deduced from the visiting functions and must be the same across all overloads.

Throws

VariantException if variant doesn't hold a value or variant holds a value which isn't handled by the visiting functions, when no parameter-less fallback function is specified.

Examples

Algebraic!(int, string) variant;

variant = 10;
auto which = -1;
variant.tryVisit!((int i) { which = 0; })();
assert(which == 0);

// Error function usage
variant = "test";
variant.tryVisit!((int i) { which = 0; },
                  ()      { which = -100; })();
assert(which == -100);

Meta