The OpenD Programming Language

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 (or combination of types) 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)
ref
tryMatch
(
SumTypes...
)
(
auto ref SumTypes args
)
if (
allSatisfy!(isSumType, SumTypes) &&
args.length > 0
)

Members

Functions

tryMatch
auto ref tryMatch(SumTypes args)

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

Meta