CT Inheritence structures
Engine Machine via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Aug 19 17:46:15 PDT 2016
I am trying to get Timon Gehr's code working, with some
modifications:
public template TypeParent(P)
{
import std.traits;
alias T = TemplateArgsOf!P;
alias Seq(T...) = T;
static if (T.length == 0 || is(typeof(T[0]) == typeof(null)))
{
alias TypeParent = Seq!();
}
else
{
alias TypeParent = Seq!(P!(T[0..T.length-1]));
}
}
class Type(T...) : TypeParent!(Type!T)
{
int x;
static if (T.length >= 1 && T[0] is "Animal")
{
int y;
static if (T.length >= 2 && T[1] is "Dog")
{
int z;
static if (T.length >= 3&& T[2] is "Pug")
{
int s;
}
}
}
}
void main()
{
import std.traits;
auto a = new Type!("Animal", "Dog", "Pug")();
Type!("Animal", "Dog") b = a;
Type!("Animal") c = b;
a.s = 1;
b.z = 2;
c.y = 3;
}
The problem is that b and c are of type P!
Type!("Animal", "Dog", "Pug")
P!("Animal", "Dog")
P!"Animal"
Of course, P should be Type and b.z and c.y should change a's
variables.
I don't know why
alias TypeParent = Seq!(P!(T[0..T.length-1]));
is returning P but I guess I'm doing it wrong. What I want is for
it to return Type!(T[0],...,T[n-1]);
Any ideas?
More information about the Digitalmars-d-learn
mailing list