|
|
|
|
|
by biotronic
2335 days ago
|
|
Both your convenience function and the quotes in the type name can be removed via the use of static opDispatch: struct FlagImpl(string name) {
bool value;
alias value this;
} struct Flag {
alias opDispatch(string name) = FlagImpl!name;
} struct Yes {
static auto opDispatch(string name)() { return FlagImpl!name(true); }
} struct No {
static auto opDispatch(string name)() { return FlagImpl!name(false); }
} void fun(Flag.foo a) {} // Look ma, no quotes! unittest {
fun(Yes.foo);
fun(Flag.foo(true));
} |
|