DIP 57: static foreach

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Tue Nov 3 16:24:00 PST 2015


On 11/3/15 3:12 PM, Shammah Chancellor wrote:
> On Monday, 10 March 2014 at 06:40:49 UTC, Kenji Hara wrote:
>> 2014-03-10 6:31 GMT+09:00 Timon Gehr <timon.gehr at gmx.ch>:
>>
>>> http://wiki.dlang.org/DIP57
>>>
>>> Thoughts?
>>>
>>
>>> From the "Semantics" section:
>>
>>> For static foreach statements, break and continue are supported and
>> treated like for foreach statements over tuples.
>>
>> This is questionable sentence. On the foreach with tuple iteration,
>> break and continue have no effect for the unrolling.
>>
>> void main()
>> {
>>     import std.typetuple, std.stdio;
>>
>>     foreach (i; TypeTuple!(1, 2, 3))
>>     {
>>         static if (i == 2) continue;
>>         else static if (i == 3) break;
>>
>>         pragma(msg, "CT: i = ", i); // prints 1, 2, and 3 in CT
>>         writeln("RT: i = ", i);     // prints only 1 in RT
>>     }
>> }
>>
>> So, I think that static foreach *cannot* support break and continue as
>> same as foreach with tuples.
>>
>> Kenji Hara
>
> Ditto.  This needs `static continue` and `static break`.  Without this
> functionality, the control flow in `static foreach` becomes very unwieldy.

There's no reason technical or otherwise to require "static" with 
continue/break in static foreach. -- Andrei


More information about the Digitalmars-d mailing list