constructing labels for static foreach inside switch inside foreach

Steven Schveighoffer schveiguy at gmail.com
Wed Jul 8 12:24:37 UTC 2020


On 7/8/20 6:13 AM, Stanislav Blinov wrote:
> On Wednesday, 8 July 2020 at 02:06:01 UTC, Steven Schveighoffer wrote:
> 
>> 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?
> 
> Can't you put a single label after your outer foreach and goto it?

There is potentially code after the while loop that needs to run, but I 
could move that code somewhere else. However it still won't work, 
because static foreach requires a label for break. So if I fix the loop 
problem, I will still have a label problem, because I need to label the 
switch and use labeled breaks on that.

This is really an issue with:

a) static foreach-ing case clauses requires a labeled break.
b) static foreach (or foreach on a tuple) unrolls all the code inside, 
including labels
c) labels have to be unique within the function.

I solved it for now by extrapolating the inner code into a local 
template function. But this is definitely an awkward situation for 
static foreach.

I was hoping I could use mixins or something to make new label names, 
but it appears I cannot (without mixing in the entire loop contents).

-Steve


More information about the Digitalmars-d-learn mailing list