I'm missing something about the way associative arrays are allocated. In the example below, case 1 and case 2 seem to be the same, a type indexed by a long.
Case 2 fails with a Range violation.

Can someone explain the difference?
I found a work around (or the correct way) in case 3.

struct Project
{
        string  date;
        string  name;
}

                // case 1
                string[long] a1;
                a1[10] = "testing a1";

                foreach (f; a1)
                        writeln ("name ", f);

                // case 2
                Project[long] a2;
                a2[10].name = "testing a2";

                foreach (f; a2)
                        writeln ("name ", f.name);

                // case 3
                Project*[long] a3;
                a3[10] = new Project;
                a3[10].name = "testing a3";

                foreach (f; a3)
                        writeln ("name ", f.name);

Reply via email to