Template tryVisit
The same as visit
, except that failure to handle types is checked at runtime.
template tryVisit(VISITORS...)
;
Instead of failing to compile, tryVisit
will throw an Exception
if none
of the handlers is able to handle the value contained in tu
.
Contained Functions
Name | Description |
---|---|
tryVisit |
Example
import std .exception : assertThrown;
union U {
int number;
string text;
}
alias TU = TaggedUnion!U;
auto tu = TU .number(42);
tu .tryVisit!((int n) { assert(n == 42); });
assertThrown(tu .tryVisit!((string s) { assert(false); }));