tryVisit

The same as visit, except that failure to handle types is checked at runtime.

Instead of failing to compile, tryVisit will throw an Exception if none of the handlers is able to handle the value contained in tu.

  1. auto tryVisit(TU tu)
    template tryVisit(VISITORS...)
    tryVisit
    (
    TU
    )
    (
    auto ref TU tu
    )
    if (
    isInstanceOf!(TaggedUnion, TU)
    )
    if (
    VISITORS.length > 0
    )
  2. auto tryVisit(TaggedAlgebraic!U ta)

Members

Functions

tryVisit
auto tryVisit(TU tu)
Undocumented in source. Be warned that the author may not have intended to support it.
tryVisit
auto tryVisit(TaggedAlgebraic!U ta)
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

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); }));

Meta