On Tuesday, 3 April 2018 at 19:31:50 UTC, Vladimirs Nordholm
wrote:
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
Would labelling help?
https://run.dlang.io/is/vE1KyD