Evaluation order of index expressions
kinke via Digitalmars-d
digitalmars-d at puremagic.com
Sun May 24 12:30:52 PDT 2015
<code>
import core.stdc.stdio;
static int[] _array = [ 0, 1, 2, 3 ];
int[] array() @property { printf("array()\n"); return _array; }
int start() @property { printf("start()\n"); return 0; }
int end() @property { printf("end()\n"); return 1; }
void main()
{
array[start..end] = 666;
printf("---\n");
array[start] = end;
}
</code>
<stdout>
array()
start()
end()
---
start()
array()
end()
</stdout>
So for the 2nd assignment's left-hand-side, the index is
evaluated before evaluating the container! Please don't tell me
that's by design. :>
[origin:
https://github.com/D-Programming-Language/phobos/pull/3311]
More information about the Digitalmars-d
mailing list