On 20.08.2016 21:20, Engine Machine wrote:
That is
It would be nice to have something like
alias Type = Type!();
class Type(T...): TypeParent!T if(T.length==1){
int x;
static if (T is Dog)
int y;
}
I don't understand how this is related.
The only difference is the alias Type = Type!(); Again, D can't do this
but the point is that it would be nice to have the alias. One can't do
everything as a "library" solution.
...
I see what you are after (but this was not part of the original
requirements :) ). I don't think there's a way to make a symbol act as
both a type and a template.
Trying to expand your code results in some odd behavior:
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;
}
b and c are of type P!, not Type!
It seems that this is a compiler bug. Is the problem just with getting a
string representation of the type?