tags:

views:

233

answers:

3

How are arrays manipulated in "D"?

+4  A: 

Here you can find a complete reference of array manipulations in D.

CMS
+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
+3  A: 

FYI. You can also copy with:

int[7] a;
int[] b;
b = a[5..7].dup;