Checking template parameter types of class

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 24 20:35:06 PDT 2015


On Monday, May 25, 2015 03:19:29 tcak via Digitalmars-d-learn wrote:
> Is there any syntax for something like that:
>
> class Resource(T) if( is(T: FileResource) ){
> }
>
>
> I tried it as above, but it is not accepted. Maybe I am following
> a wrong syntax.
>
> I tried
>
> class Resource(T: FileResource){
> }
>
> But it is not accepted as well.

What about it isn't accepted? This code compiles just fine


class FileResource
{
}

class SubFileResource : FileResource
{
}

class Resource(T)
    if(is(T : FileResource))
{
}

void main()
{
    Resource!SubFileResource foo;
}

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list