mixin break; in switch containing static foreach
Vladimirs Nordholm
v at vladde.net
Tue Apr 3 19:31:50 UTC 2018
My base problem is that I want to mixin `break` into a switch
statement, but the mixin is within a static foreach. Take a look
at the following code:
switch(foo)
{
static foreach(f; EnumMembers!Foo)
{
mixin(format("
case Foo.%s: bar = Bar.%s; break;
", f, f));
}
default: /* do stuff */; break;
}
The above code returns the error "Error: must use labeled `break`
within `static foreach`". For a more complete example, take a
look att this sample code: https://dpaste.dzfl.pl/f3ab6d9679fc
I also attempted this solution, but I got the error that the
label didn't exist. (And it looks pretty ugly)
mixin(format("%s: case Foo.%s: abc = Foo.X%s; break %s;", f,
f, f, f));
Any of you have a solution for this problem?
Best regards,
Vladimirs Nordholm
More information about the Digitalmars-d-learn
mailing list