How are arrays manipulated in "D"?
+3
A:
To slice arrays, it's a simple matter of using
int[7] a;
int[] b;
b = a[5..7];
which sets b[0] to a[5] and b[1] to a[6]. But remember that this is a reference to the elements in a, not another copy of them. If you change b[0], this also affects a[5].
If you want to copy, you have to do:
int[7] a;
int[2] b;
b[0..1] = a[5..7];
This is because b is a static array; in the first code block, it was dynamic (effectively a pointer to somewhere within another array).
paxdiablo
2008-10-13 05:45:48