constructing labels for static foreach inside switch inside foreach

Steven Schveighoffer schveiguy at gmail.com
Wed Jul 8 13:48:59 UTC 2020


On 7/8/20 9:38 AM, ag0aep6g wrote:
> On 08.07.20 14:24, Steven Schveighoffer wrote:
>> 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.
> 
> FWIW, you can write the extra function like this:
> 
>      static foreach (T; Types)
>      () {
>          innerloop: while (haveMoreData)
>          {
>              ...
>              break innerloop;
>              ...
>          }
>      } ();


Ooh, that's a good idea. That avoids having to declare a template 
function before the loop (I can't declare it inside because, then 
multiple functions of the same name would exist lol).

Works like a charm, thanks!

-Steve


More information about the Digitalmars-d-learn mailing list