Reputation:
With new C++11 standard, we have type list (in variadic template) and some compile-time methods checking whether class A is base class of B.
Now, is there any way, how to get list of base classes of a class?
Example:
class A {};
class B {};
class C {};
class AB : public A, public B {};
class Test : public AB, public C {};
template<typename ...BaseTypes>
class BaseTypeList
{
public:
static const int size = sizeof...(BaseTypes);
// ...
};
std::cout << "Size: " << BaseTypeList<GET_BASE_TYPES(Test)>::size
<< std::endl;
Output: Size: 2
(AB
and C
).
(In this example, what I'm asking for is implementation of GET_BASE_TYPES(...)
.)
Notes:
Test
) or base classes of all direct base classes (A
, B
).Upvotes: 0
Views: 152