check if _argument[0] is a descendant of a specific class.

Adam D. Ruppe destructionator at gmail.com
Sat Jun 8 21:24:53 UTC 2019


On Saturday, 8 June 2019 at 21:16:14 UTC, realhet wrote:
> void foo(...){

Do you have to use the variadic thing?

It is easy to do with template variadic or with just regular 
arrays of interfaces/base classes.

> I just wanna check if a compile_time _argument[0] is a 
> descendant of a class or not.

_arguments is a compile time construct, it is a run time thing.

I kinda suspect what you really want to write is

foo(T...)(T args) { }

and then you can do `static if(is(arg[0] : A))` to catch both A 
and B.

Your approach for the typeinfo thing at runtime was close though, 
just it isn't `next` (that's used for like immutable(A), where 
next is A), but `base`.

http://dpldocs.info/experimental-docs/object.TypeInfo_Class.html

but with the compile time list foo(T...)(T args), there's no need 
to do typeid/typeinfo at all.


More information about the Digitalmars-d-learn mailing list