xxxxxxxxxx
import std.traits : EnumMembers;
import std.format : format;
enum Foo
{
A = 10, B = 20, C = 30,
XA= 11, XB= 21, XC= 31,
}
Foo bar(Foo foo)
{
Foo abc;
outer: switch(foo)
{
static foreach(f; EnumMembers!Foo[0 .. 3])
{
mixin(format("case Foo.%s: abc = Foo.X%s; break outer;", f, f));
}
default:
abc = foo;
break;
}
/* do more stuff */
assert(abc == Foo.XA);
return foo;
}
void main(){
auto res = bar(Foo.A);
import std.stdio;
writeln(res);
}