static struct S { auto bar(int a) { return a; } enum boolean = true; } static struct C { alias bar = (double a) => a * 2; enum boolean = false; } alias V = Variant!(S, C); V x = S(); V y = C(); static assert(is(typeof(x.getMember!"bar"(2)) == Variant!(int, double))); assert(x.getMember!"bar"(2) == 2); assert(y.getMember!"bar"(2) != 4); assert(y.getMember!"bar"(2) == 4.0); // direct implementation assert(x.bar(2) == 2); assert(y.bar(2) != 4); assert(y.bar(2) == 4.0); assert(x.boolean); assert(!y.boolean);
Applies a member handler to the given Variant depending on the held type, ensuring that all types are handled by the visiting handler.