According to
https://dlang.org/spec/statement.html#foreach_over_arrays
point 2, "ref" on "index" is not allowed. However,
the following compiles:
import std;
void main() {
foreach(ref i, x; [1,2,3,4,5]) {
writeln(x);
i++;
}
}
and produces:
1
3
5
Comment #1 by dlang-bot — 2024-04-14T17:36:24Z
@ntrel updated dlang/dmd pull request #16381 "[foreach] Deprecate `ref` for array index or range parameter" fixing this issue:
- Fix Bugzilla 24232 - ref for index of foreach for arrays is not allowed by spec but accepted by compiler
https://github.com/dlang/dmd/pull/16381
Comment #2 by robert.schadek — 2024-12-13T19:31:37Z