Question about template argument matching with alias this

Alex sascha.orlov at gmail.com
Sun Jul 29 20:51:45 UTC 2018


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(){}
´´´


More information about the Digitalmars-d-learn mailing list