How to execute a request for all base classes of a class at compile time?

You std::is_base_of<A,B>::valuecan check with C whether the class is a Abase class B. Is it possible to request a compiler for all the base classes of a class B , for example, something like base_classes_of<B>returning std :: tuple containing all the base classes B?

Is there evtl. non-standard extension in g ++ that can do this?

If this is not possible at all, does anyone know why? Does this sound quite fundamentally a piece of information that the compiler should easily have?

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() {}
+3
source share
3 answers

bases direct_bases N2965.
, , .
, . , , bases , N2965.
, , ++ , , , GCC Clang-++, , ...

+2

, ++, , , ( ).

hth.,

+1

++ - ++ -.... -, ( ) ( ) - std::is_base_of , , . - , , , , . : , ++?

+1

All Articles