I think this might be a problem because every template instance creates separate independent class, as far as I know.

Well, maybe you can use function pointer and create static constructor. More job need to be done, but the resulting class doesn't lose much and even become more flexible, configurable;

final class StaticMyClass {

        static void _myfun() {
                writeln("Hello!");
        }
}

class MyClass(T) {
        uint x, y;

        static void function() myfun;

        static this() {
                MyClass.myfun = &StaticMyClass._myfun;
        }

//still you have additional memory consumed by static constructor function;

        this() {
                this.myfun();
        }
}

void main() {
    auto obj = new MyClass!int();
}

Reply via email to