As soon as an instance of the template is created, its own beast. If you have a structure like
struct RGBA(T) { }
you cannot directly check whether a particular instance of this structure is the opinion of this structure. You can test something like is(RGBA!int == RGBA!int) or (RGBA! T == RGBA! Int) `(if you have T), but there is no way to ask if the generic type is an instance of RGBA.
The reason for this is because RGBA is not a type. This is a template for a type. There is no type until you create an instance of the template, and no creation of the template has anything to do with any other template. RGBA! Int is not affiliated with RGBA! Float. Due to template limitations and template specializations and the like, the two types can be completely different. eg.
struct RGBA(T : int) { float a; double b; bool[] c; } struct RGBA(T : float) { @property int w() const pure nothrow { return 2; } }
Now there are games that you can play if you want to limit yourself a little. The trick is that you need a way to get T, which will be used to create RGBA. So something like this will work:
import std.traits; struct RGBA(T) { } struct BMPFile(DataT, T) if(is(DataT == RGBA!T) && IsIntegral!T) { }
Now this has the limitation that T is an integral type, which may or may not be what you want. isFloatingPoint!() will work, like is(T == bool) , and a number of functions in std.traits and hell in __traits . So, if you have an idea of ββwhat T will be, you can add the appropriate restrictions for checking type T.
Now, if you did something like
struct BMPFile(DataT, T) if(is(DataT == RGBA!T))
and then always give the type a second time, which would also work: BMPFile(RGBA!int, int) (although I assume you really don't want this).
Another option: if you know that there is an RGBA function that returns T or accepts T , you can check if this function is present in the DataT, and use traits to get the type. eg.
import std.traits; struct RGBA(T) { T func() { return T.init;} } struct BMPFile(DataT, T = ReturnType!(DataT.func)) if(is(DataT == RGBA!T)) { }
However, the error messages for this can be pretty ugly when you pass it something that does not have the func function, and if the type other than the instance created by RGBA matches the pattern, it will try and create an instance of it that can work or not work, but it's probably not what you want anyway.
So what is happening is that there is currently no way to do what you are trying to do directly, but if you play some games, you can get something that will work. Essentially, it comes down to finding a way to define a template so that you have access to the arguments that were used to instantiate the first template ( RGBA in this case) so that you can check if the type ( DataT ) given to the second template ( BMPFile ), is an instance of this type ( RGBA!T ). If you can get T , then you can check if is(DataT == RGBA!T) .