Template type reduction

Engine Machine via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 15 12:31:14 PDT 2016


Suppose I have a templated type like

struct S(T) { int x; static if (T is Y) int y; }

I would like to be able to create a reference to S(T) for any T,

struct Q
{
   S!* s; // Can hold any type of S.
}

and be able to access s.x, since it is common to all S.

Can D do anything like this? It is sort of like runtime 
inheritance, but at the compile time level.

I do not want to have to cast to S!T every time just to access x, 
e.g.,

struct Q
{
    Object s;
}

which is too general as s can be things that are not of type S!*.


Is this possible?



More information about the Digitalmars-d-learn mailing list