How do I make a template function that only accepts instances of a specific class?
Adam D. Ruppe
destructionator at gmail.com
Mon Jan 18 19:02:10 UTC 2021
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.
isInstanceOf is for checking instances of templates rather than
classes.
More information about the Digitalmars-d-learn
mailing list