How do I make a template function that only accepts instances of a specific class?

Jack jckj33 at gmail.com
Mon Jan 18 19:34:52 UTC 2021


On Monday, 18 January 2021 at 19:02:10 UTC, Adam D. Ruppe wrote:
> On Monday, 18 January 2021 at 18:40:37 UTC, Jack wrote:
>> isInstanceOf from std.traits seems to not work with class the 
>> way I need to. I'd like to make a template function accepts 
>> only class of a specified class type
>>
>> class A { }
>> class B : A { }
>> class C : A { }
>>
>> int f(T)(in A[int] arr)
>
> Use
>
> if(is(T : A))
>
> the syntax there is similar to the class declaration itself.

is that sytax derived from there?

> isInstanceOf is for checking instances of templates rather than 
> classes.

I see

Thanks!





More information about the Digitalmars-d-learn mailing list