Work around name lookup issue on DMD < 2.081.0.

This commit is contained in:
Sönke Ludwig 2019-02-23 17:47:24 +01:00
parent 56d50fd56c
commit 7145693748

View file

@ -434,23 +434,27 @@ template visit(VISITORS...)
///
unittest {
union U {
int number;
string text;
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);
}
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);
}
unittest {
@ -480,14 +484,6 @@ unittest {
}
// workaround for "template to is not defined" error in the unit test above
// happens on DMD 2.080 and below
private U to(U, T)(T val) {
static import std.conv;
return std.conv.to!U(val);
}
/** 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