On Saturday, 20 August 2016 at 09:42:08 UTC, Jack Applegame wrote:
On Saturday, 20 August 2016 at 00:46:15 UTC, Engine Machine wrote:
Any ideas?
Something like this?

mixin template TypeData(string type: "Animal") {
    int y;
}
mixin template TypeData(string type: "Dog") {
    int z;
}
mixin template TypeData(string type: "Pug") {
    int s;
}

template Type(string type, ARGS...) {
    static if(ARGS.length == 0) {
        class Type {
            mixin TypeData!type;
        }
    } else {
        class Type : Type!ARGS {
            mixin TypeData!type;
        }
    }
}

void main() {
    auto a = new Type!("Pug", "Dog", "Animal")();
    Type!("Dog", "Animal") b = a;   
    Type!("Animal") c = b;    
        
    a.s = 1;
    b.z = 2;
    c.y = 3;

    pragma(msg, typeof(a));
    pragma(msg, typeof(b));
    pragma(msg, typeof(c));
}

See result - https://dpaste.dzfl.pl/1a76490aaf55

No, this is just standard inheritance that has been complexified. The point is to have a single class that encapsulates it's own derived types. You have a type constructor. It also doesn't solve the original problem.



Reply via email to