static foreach considered
Idan Arye via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jun 8 17:01:06 PDT 2015
On Monday, 8 June 2015 at 22:15:32 UTC, rsw0x wrote:
> On Monday, 8 June 2015 at 20:02:11 UTC, Andrei Alexandrescu
> wrote:
>> I'm trying to collect together motivating examples and to
>> figure out the semantics of the feature.
>
> maybe not completely related, but I made a blog post on using
> CTFE to unroll foreach at compiletime
>
> https://rsw0x.github.io/post/switch-unrolling/
>
> I find myself often writing recursive templates for
> compile-time generation of constructs that could be done
> cleaner with static foreach.
I also use this method alot, and sometimes encounter this "bug":
http://dpaste.dzfl.pl/16af3c5dad73
The break inside the `foreach` is breaking from the `foreach`,
not from the `switch`, so it continues to execute the `default`
clause.
This is not really a bug - `foreach` unrolling is more of a loop
unrolling optimization that we hijack, so it makes sense `break`
inside it will act like it's inside a regular `foreach`. With
`static foreach`, we might want `break`(and `continue`) to
operate on the containing, runtime control structure.
More information about the Digitalmars-d
mailing list