开发者

List of base classes for use with variadic templates

开发者 https://www.devze.com 2023-04-01 05:09 出处:网络
Is there a way to access all base classes of a 开发者_如何学Cclass in C++? Since variadic templates are available I think it would make sense to have e.g. ___BASE which is a variadic list of all types

Is there a way to access all base classes of a 开发者_如何学Cclass in C++? Since variadic templates are available I think it would make sense to have e.g. ___BASE which is a variadic list of all types the current class does derive from. This would also enable a check whether a class or it's base classes are of a certain type. Is this already possible or am I missing something here why this isn't possible!?


There isn't a general mechanism in the language that'll tell you all the base classes, though you're free to add a suitable typedef to all members of your class hierarchy that will make this information available (e.g. typedef a tuple whose argument types are the ancestor plus the ancestor's ancestors) -- you could probably write a little mixin for that.

As for checking whether something is a base of another, that's already part of the standard in the shape of the std::is_base_of type trait.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号