constructing labels for static foreach inside switch inside foreach

Steven Schveighoffer schveiguy at
Wed Jul 8 02:06:01 UTC 2020

OK, so I have a situation where I'm foreaching over a compile-time list 
of types. Inside the loop, I'm using a second loop over a set of input.

Inside that loop, I'm using a switch on the input, and inside the 
switch, I'm foreaching over the type's members, to construct a switch 
that can handle member names (this is for serialization).

If I encounter a certain name, then I want to break out of the inner 
loop (it's a while loop)

So naturally, I have to use break statements with labels like:

    switch(nextDataElement) {
       static foreach(name; __traits(allMembers, T)) {
       case name:
          ... // handle it
          break switchstmt;
       case "STOP":
          break innerloop;

Seems simple enough, except that this inner portion is unrolled, and if 
I have more than one type to run this on, I already have an "innerloop" 
label defined.

Is there a way to define a label using a mixin or something? or do I 
have to wrap this in a function?

Is there another way to approach this?


More information about the Digitalmars-d-learn mailing list