https://issues.dlang.org/show_bug.cgi?id=16520

          Issue ID: 16520
           Summary: static foreach should be more explicit
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nob...@puremagic.com
          Reporter: mathias.l...@sociomantic.com

Currently, one can hardly tell when reading a `foreach` statement if it's
executed at CT or not. One should know that the argument passed is actually a
tuple.
Even when it's known, there is a risk that a later change can change this
property.

I propose we implement a `static foreach` construct, which ensures that a
`foreach` is executed at compile time.
The roadmap could look like the following:
- Support for `static foreach`: Old `foreach` over tuple still have the same
effect, but one can use the `static` keyword to ensure this specific behaviour
is used. If not, the compiler produces an error;
- Later on, deprecate `foreach` on tuple without `foreach`.
- Then make it an error
- Later on, we can consider allowing it, but it will mean it gets executed at
runtime

This would not introduce any new feature in `static foreach` - That can be done
later if wanted. But would make this obscure construct a bit less obscure.

--

Reply via email to