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:

innerloop:
while(haveMoreData)
   switchstmt:
   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?

-Steve

Reply via email to