On 7/17/17 9:23 AM, Petar Kirov [ZombineDev] wrote:
On Monday, 17 July 2017 at 12:38:27 UTC, Steven Schveighoffer wrote:
On 7/16/17 1:04 PM, Andrei Alexandrescu wrote:
On 7/16/17 9:10 AM, Mike Parker wrote:
Congratulations to Timon Gehr. Not only was his "Static foreach" DIP accepted, it picked up a good deal of praise from Walter & Andrei.

Indeed. Kudos to Timon (and thanks Mike for driving the process). This is a well done DIP that many others could draw inspiration from. -- Andrei

What is the resolution of how break statements affect static foreach/foreach?

i.e. this section:

"As some consider this to be potentially confusing, it has been suggested that break and continue directly inside static foreach should instead be compiler errors and require explicit labels. This DIP leaves this decision to the language authors, but recommends the above semantics."

I think the only reliable way is to not use jumps (goto, break, continue) at all.
E.g. if you want to unroll the following loop:

foreach (x; someRange)
     if (x.isSpecial)


You would need to guard every statement/declaration:

static foreach (x; someRange)
     static if (!x.isSpecial)

My concern is that the proposal asked for break to apply to the runtime construct that surrounds the loop. So for instance, break would apply to the switch statement outside the static foreach.

This differs from current static looping (i.e. foreach over a tuple), where break applies to the foreach.

I'm not concerned with breaking out of the loop. I agree that the proposed behavior is the best choice. However, it's confusing given existing behavior that doesn't do that.


Reply via email to