Philippe Sigaud:

Keep in mind all these structures (AA and dynamic arrays) are
reference types.

There are bug-prone things you have to keep in mind.

Not exactly a reference type, this is by D specs:


import std.stdio;
import std.array: popFront;
void main() {
     auto d = [1:[2, 3]];
     auto l = d[1];
     auto l2 = l[0];
     l.popFront();
     writeln(d, "  ", l, "  ", l2);
}


Even AAs (I don't know if this is an implementation bug or if this is by D specs, opinions welcome):

void test(int[int] arraya, int x) {
     arraya[x] = x;
}
void main() {
     int[int] d;
     test(d, 0);
     int[int] d0;
     assert(d == d0); // d is empty, 0:0 is lost
     d[1] = 1;
     test(d, 2);
     assert(d == [1: 1, 2: 2]); // now 2:2 is not lost
}

Bye,
bearophile

Reply via email to