If handler has a non-void return value, its return value gets forwarded to the caller.
1 union U { 2 int i; 3 string s; 4 } 5 alias TA = TaggedAlgebraic!U; 6 7 assert(TA(12).apply!((v) { 8 static if (is(typeof(v) == int)) { 9 assert(v == 12); 10 return 1; 11 } else { 12 return 0; 13 } 14 }) == 1); 15 16 assert(TA("foo").apply!((v) { 17 static if (is(typeof(v) == string)) { 18 assert(v == "foo"); 19 return 2; 20 } else { 21 return 0; 22 } 23 }) == 2); 24 25 "baz".apply!((v) { 26 assert(v == "baz"); 27 });
Calls a the given callback with the static type of the contained value.
The handler callback must be a lambda or a single-argument template function that accepts all possible types that the given TaggedAlgebraic can hold.