tryMatch

Attempts to call a type-appropriate function with the value held in a SumType, and throws on failure.

Matches are chosen using the same rules as match, but are not required to be exhaustive—in other words, a type is allowed to have no matching handler. If a type without a handler is encountered at runtime, a MatchException is thrown.

Not available when compiled with -betterC.

template tryMatch(handlers...)
version(D_Exceptions)
tryMatch
(
Self
)
(
auto ref Self self
)
if (
is(Self : SumType!TypeArgs,
TypeArgs...
)
)

Members

Functions

tryMatch
auto tryMatch(Self self)

The actual tryMatch function.

Return Value

The value returned from the handler that matches the currently-held type, if a handler was given for that type.

Throws

MatchException, if the currently-held type has no matching handler.

See Also

std.variant.tryVisit

Meta