On 08/22/2016 12:06 AM, Engine Machine wrote:
T!()'s "data" is specified in the class just like all the other
derivations. I don't want to have to specify an external base class as
in your InstaniateOrBase. Why? Because!!! (There should be no need to,
and if one goes this route of creating classes, it should be all or
nothing, else there is no real benefit)

You make it sound like I came up with the external base class, but I just took that from your code.

[...]
It seems that when one uses `class T(A...) : X`, one can't, for some X,
not have inheritance. The compiler expects X to be something inheritable
from no matter what.

I didn't know it, but your code shows that X can also be an empty compile time list (Seq). I have no idea if this is in the spec, or if it just happens to work with dmd.

If it's valid D, you just need a template that goes from T and A to T!(A[0 .. $ - 1]), or if A is already empty, to the empty Seq.

Like so:

----
template InstantiateOrEmptySeq(alias tmpl, args...)
{
    alias Seq(T...)=T;
    static if (args.length > 0)
        alias InstantiateOrEmptySeq = tmpl!(args[0 .. $ - 1]);
    else
        alias InstantiateOrEmptySeq = Seq!();
}

class T(A...) : InstantiateOrEmptySeq!(T, A)
{
    ...
}
----


Reply via email to