How can I test at compile time whether T is an instance of an interface ?

wjoe invalid at example.com
Wed Sep 23 18:37:45 UTC 2020


I have some similar functions:

void register(C: IFoo)()
{
   _insert!C();
}

void register(C)() if (behavesLikeFoo!C)
{
   _insert!C();
}

There are more overloads with parameters so I want to merge them

void register(C, ARGS...)(ARGS args) if (behavesLikeFoo!C || 
isInstanceOf!(C, IFoo))
{
   _insert!C(args);
}

I found a lot of information on how to do this at runtime but not 
at compile time.
std.traits: isInstanceOf doesn't work. Neither did anything I 
tried with typeid etc.

The behavesLikeFoo constraint works as expected but it accepts 
any class no matter whether or not it implements the interface.


More information about the Digitalmars-d-learn mailing list