Bug 16520 – static foreach should be more explicit
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-09-21T19:33:59Z
Last change time
2017-11-23T09:57:23Z
Assigned to
No Owner
Creator
Mathias Lang
Comments
Comment #0 by mathias.lang — 2016-09-21T19:33:59Z
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.
Comment #1 by razvan.nitu1305 — 2017-11-23T09:57:23Z
Static foreach has been added to the language. I'll close this as fixed.