visit

Dispatches the value contained on a TaggedUnion or TaggedAlgebraic to a set of visitors.

A visitor can have one of three forms:

  • function or delegate taking a single typed parameter
  • function or delegate taking no parameters
  • function or delegate template taking any single parameter

....

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

Members

Functions

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

Examples

static if (__VERSION__ >= 2081) {
	import std.conv : to;

	union U {
		int number;
		string text;
	}
	alias TU = TaggedUnion!U;

	auto tu = TU.number(42);
	tu.visit!(
		(int n) { assert(n == 42); },
		(string s) { assert(false); }
	);

	assert(tu.visit!((v) => to!int(v)) == 42);

	tu.setText("43");

	assert(tu.visit!((v) => to!int(v)) == 43);
}

Meta