Re: Changing elements during foreach

2013-10-21 Thread Krzysztof Ciebiera
On Monday, 21 October 2013 at 14:59:54 UTC, Alexandr Druzhinin wrote: If you switch instruction order you create local copy and then set x[0] in local copy so original is unchanged. But local copy creating depends on several thing and happens not every appending in general. Your way is not D-is

Re: Changing elements during foreach

2013-10-21 Thread Krzysztof Ciebiera
On Monday, 21 October 2013 at 10:41:38 UTC, Alexandr Druzhinin wrote: 21.10.2013 17:31, Krzysztof Ciebiera пишет: void main() { int a[][] = [[1,2,3]]; foreach(x; a) { x[0] = 0; x ~= 4; } writeln(a); } ... &) or [0,2,3,4] (python, C++ ref). But [0,2,3]? It

Changing elements during foreach

2013-10-21 Thread Krzysztof Ciebiera
Is the following compiler behavior consistent with language specification? import std.stdio; void main() { int a[][] = [[1,2,3]]; foreach(x; a) { x[0] = 0; x ~= 4; } writeln(a); } I understand why thw program could output [1,2,3] (like in C++ without &) or