With std::is_base_of<A,B>::value
one can check if a class A
is a base class of
class B
. Is it also possible to query the compiler for all base classes of a class
B
, e.g., something like base_classes_of<B>
returning a std::tuple containing all base classes of B
?
Is there evtl. a non-standard extension in g++ that can accomplish this ?
If this is not possible at all, does anyone know why? It sounds like a rather fundamental piece of information the compiler easily should have available?
Example:
#include <type_traits>
#include <tuple>
struct A {};
struct B : A {};
static_assert(std::is_base_of<A, B>::value, "A is base of B");
static_assert(! std::is_base_of<B, A>::value, "but B is not base of A");
// now I am looking for something like
// typedef base_classes_of<B>::type B_bases;
// static_assert(std::is_same<B_bases, std::tuple<A>>::value, "all bases of B are: A");
int main() {}