refl-cpp
Learn by Example

Print the Name of a Type

printf("Type Name: %s", reflect<T>().name.c_str());

Explaination

  1. reflect<T>() returns a type_descriptor<T> (an empty TrivialType describing T)
  2. type_descriptor<T>::name returns const_string<N> (name is a static member)
  3. const_string<N>::c_str() returns const char*

Print the Members of a Type

type_descriptor<T> td;
for_each(td.members, [](auto member) {
printf("Member Name: %s\n" member.name.c_str());
});

Explaination

  1. type_descriptor<T> is a TrivialType which describes T. Can be also created with reflect<T>();
  2. type_descriptor<T>::members returns type_list<Ts...> (members is a static member of type type_list<Ts...> where each Ts... is either field_descriptor<T, I> or function_descriptor<T, I>)
  3. member_descriptor_base<T, I>::name returns const_string<N> (name is a static member)
  1. const_string<N>::c_str() returns const char*