deep copy or shallow copy?
RenatoL
rexlen at gmail.com
Thu Dec 8 12:50:14 PST 2011
snippet 1)
auto arr1 = [1,2,3];
auto arr2 = arr1;
arr1[1] = 22;
arr2[2] = 33;
foreach (i; 0..arr1.length) write(arr1[i], " ");
writeln();
foreach (i; 0..arr2.length) write(arr2[i], " ");
output:
1 22 33
1 22 33
OK
snippet 2)
int[3] arr1 = [1,2,3];
int[3] arr2 = arr1;
arr1[1] = 22;
arr2[2] = 33;
foreach (i; 0..arr1.length) write(arr1[i], " ");
writeln();
foreach (i; 0..arr2.length) write(arr2[i], " ");
output:
1 22 3
1 2 33
that's unclear to me... i "agree" with the behaviour of the
dynamic array... but if we have a static array we have a deep copy?
More information about the Digitalmars-d-learn
mailing list