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

Timon Gehr timon.gehr at gmx.ch
Thu Sep 15 13:43:54 PDT 2011


On 09/15/2011 10:24 PM, Andrej Mitrovic wrote:
> 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?
>
> Otherwise I'm currently having to hardcode via:
>
> template bar(T) if (isOneOf!(T, Foo!int, Foo!double)) { }
>
> But having to list all possible instantiations doesn't really scale too well.

template bar(T : Foo!S,S){ }

S will be bound to the type that was used to instantiate Foo.

It won't work if Foo takes a variable number of parameters though. 
Probably a bug.


More information about the Digitalmars-d-learn mailing list