import std; import std.range; void main() { int[] a = [3, 5, 7]; foreach (i, ref ae; a.enumerate) { writeln(i, " ", ae); ae = 6; } writeln(a); assert(a[].equal([6, 6, 6])); // fails, a is in initial state }
Why does the compiler allow such 'ref ae' loop, if the actual value is not a reference? Or it is a reference to hidden stack variable that was copied by enumerate from a during front()?