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.

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

Members

Functions

tryMatch
auto tryMatch(auto ref 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