Is there a way in C++ to check if a class has one or more base classes?
I am looking for a type trait that would return true
for:
struct X
{
int a;
int b;
};
but return false
for
struct Y : X
{
int c;
int d;
};
There doesn't seem to be any type trait for that in the standard library.
I need it to determine aggregate classes that can be decomposed in structured binding to the same number of arguments as they are initialized with in brace-initialization:
// class X is ok:
X x = {{}, {}}; // 2 arguments
auto [m1, m2] = x; // 2 arguments
// class Y is bad:
Y y = {{}, {}, {}}; // 3 arguments, because Y has base
auto [m1, m2] = y; // 2 arguments
For thus filtered types I could determine how many members they can be decomposed into in structured binding by looking at how many numbers they can be maximally brace-initialized with. The latter can be determined with SFINAE tricks; the former cannot.
This in turn can be useful in a library like this one: https://apolukhin.github.io/magic_get/index.html