Static typing loop

bearophile bearophileHUGS at lycos.com
Tue Dec 25 18:06:29 PST 2007


Sometimes the static typing gives me problems still. I am creating a recursive data structure, I'd like to create a class template like Foo1, but with that the DMD compiler V.1.024 goes into loop eating more and more memory during the compilation. Foo2 too shares the same problem.
The only way to solve the problem I have found so far is Foo3 (that uses a std.gc.malloc to allocate memory to be used an array of pointers, that need a cast every time), but if possible I'd like to use the nicer dynamic arrays as in Foo1. Do you have some suggestions?

class Foo1(T, int n=10) {
    Foo1!(T[], 20) f;
}

class Foo2(T, int n=10) {
    Foo2!(T*, 20) f;
}

class Foo3(T, int n=10) {
    Foo3!(void*, 20) f;
}

void main() {
    //auto f1 = new Foo1!(int);
    //auto f2 = new Foo2!(int);
    auto f3 = new Foo3!(int);
}

Bye and thank you,
bearophile


More information about the Digitalmars-d-learn mailing list