Checking template parameter types of class

tcak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 24 20:42:22 PDT 2015


On Monday, 25 May 2015 at 03:35:22 UTC, Jonathan M Davis wrote:
> 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

Well, if I do not check the line number of error, this happens. 
It was giving error on the line of creating a new instance.

Line 243: auto fileResourceList = new shared FileResourceList( 2 
);

main.d(243): Error: class main.FileResourceList(T) if (is(T : 
FileResource)) is used as a type


More information about the Digitalmars-d-learn mailing list