On Sunday, 29 July 2018 at 16:43:08 UTC, Johannes Loher wrote:
I have a question about template argument matching in combination with implicit conversion and alias this. Consider the following code:


interface SomeInterface
{
}

class SomeClass : SomeInterface
{
}

struct SomeStruct
{
    SomeClass someClass;
    alias someClass this;
}

template isSuperType(T, S : T)
{
    enum isSuperType = is(SomeStruct : SomeInterface);
}

void main()
{
    static assert(is(SomeStruct : SomeInterface));
static assert(isSuperType!(SomeInterface, SomeStruct)); // why does the template not match?
}


The question is, why does the template declaration not match? Thanks for your help!

Do you mean something like this?

´´´
interface SomeInterface {}

class SomeClass : SomeInterface {}

struct SomeStruct
{
    SomeClass someClass;
    alias someClass this;
}

template isSuperType(T, S) if(is(S : T))
{
    enum isSuperType = is(S : T);
}

static assert(is(SomeStruct : SomeInterface));
static assert(isSuperType!(SomeInterface, SomeStruct));
void main(){}
´´´

Reply via email to