In C++ there is no way to get information about the member variables of a class. This makes features like auto-serialization cumbersome to implement. It seems like this feature would be simple to add to the language. After all typeid
and std::typeinfo
makes it possible to get a unique identifier for a type. To illustrate how such a feature might work, see below:
// An integer constant corresponding to the number of members in the struct
type_members(A)::count
// An array of type_info corresponding to the members in the struct
type_members(A)::typeids
// An array of null terminated char* corresponding to the names of the members
type_members(A)::names
// Ann array of T A::* corresponding to the memory offsets of the members
// Where T is the type of the member at that index
type_members(A)::members
Has there been any discussion of adding a feature similar to this to the C++ standard? And if such a feature has been considered and rejected, why?