deepdup

Undocumented in source. Be warned that the author may not have intended to support it.

Examples

auto x = [1, 2, 3];
assert(x == x.dup);
auto y = x;
assert(&x[0] == &y[0]);
assert(&x[0] != &x.dup[0]);
auto x = [[1], [2], [3]];
auto y = x.dup;
x[0][0] = 11;
assert(x[0][0] == 11);
assert(y[0][0] == 11);
auto x = [[1], [2], [3]];
auto y = x.deepdup;
x[0][0] = 11;
assert(x[0][0] == 11);
assert(y[0][0] == 1);
auto x = [[1], [2], [3]];
auto y = x.deepdup;
x[0][0] = 11;
assert(x[0][0] == 11);
assert(y[0][0] == 1);
auto x = [[[1]], [[2]], [[3]]];
auto y = x.deepdup;
x[0][0][0] = 11;
assert(x[0][0][0] == 11);
assert(y[0][0][0] == 1);

dup of static array

int[3] x = [1, 2, 3];
auto y = x.dup;
x[0] = 11;
assert(x[0] == 11);
assert(y[0] == 1);

dup of static array of dynamic arrays

int[][3] x = [[1], [2], [3]];
auto y = x.dup;
x[0][0] = 11;
assert(x[0][0] == 11);
assert(y[0][0] == 11);

deepdup of static array of dynamic arrays

int[][3] x = [[1], [2], [3]];
auto y = x.deepdup;
x[0][0] = 11;
assert(x[0][0] == 11);
assert(y[0][0] == 1);

Meta