Is it possible to check if a type is an instance of a template?

bearophile via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 5 17:01:07 PDT 2014


Andrej Mitrovic:

> I can do this:
>
> struct Foo(T) { }
> template bar(T : Foo!int) { }
>
> I can check if T is a specific instantiation of Foo. But I want 
> to
> check whether T is *any* instantiation of Foo. Is this possible 
> to do?

There is now std.traits.isInstanceOf that could do what you need.

Its implementation:

enum bool isInstanceOf(alias S, T) = is(T == S!Args, Args...);

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list