On 08.06.2017 14:06, Steven Schveighoffer wrote:
The issue here is that arrays are special. Arrays allow foreach(i, v;
arr) and foreach(v; arr). Ranges in general do not. So there is no way
to forward this capability via the range interface. Not only that, but
foreach(i, v; arr) is much different than iterating even a range that
returns a tuple in that the index is *specific to the loop* and doesn't
involve the array at all. It's more similar to opApply.
opApply can help, but still is different than how arrays work (foreach
with array is handled directly by the compiler). But ranges are not
going to be forwarding this feature just for arrays.
Arguably, foreach over ranges and foreach over arrays are badly
designed. Automatic tuple expansion only works with ranges, and indexed
iteration only works with arrays, and they are mutually incompatible.
Therefore, there is no good way to fix the problem.