Consider the following code:
#include <tuple>
#include <type_traits>
struct foo
{
struct a {};
struct b {};
struct c {};
};
// we use here an hypothetical type trait 'get_struct_list_t'
using T = get_struct_list_t<foo>;
static_assert (std::is_same_v <T, std::tuple<foo::a, foo::b, foo::c>>);
int main () {}
Question: is is possible to design a type trait get_struct_list_t that returns the list of inner struct types of a given struct ?
I don't think it is possible in c++ since it would require to have some reflection feature, so my question is mainly to confirm this point.
The original question didn't make any assumption on the inner structs whose types list has to be retrieved.
If these inner structs only hold type information (ie. no data members), we could use the following trick: instead of naming for instance
struct a {};, we could instead define a member of an anonymous struct, ie.struct {} a;. The good point now is that we have something to get a type information from, in other words we can use somestruct_to_tuplemachinery to obtain what we want. However, this solution is quite akward and misleading for the end user. It's more a matter of fun than for every day usage...Here is the whole example. Note that I use here the following gist for getting a
std::tuplefrom a structure.