veselink1 / refl-cpp

Static reflection for C++17 (compile-time enumeration, attributes, proxies, overloads, template functions, metaprogramming).
https://veselink1.github.io/refl-cpp/md__introduction.html
MIT License
1.06k stars 77 forks source link

Feature: Support inherited members #27

Closed veselink1 closed 4 years ago

veselink1 commented 4 years ago

Problem

refl-cpp does not automatically enumerate base types when using member_list<T> or type_descriptor<T>::members. This requires derived classes to redeclare members in their REFL_AUTO metadata definition for them to be properly picked up.

Solution

Use attr::base_types<Ts...> built-in attribute to generate a list of own and inherited members and expose that to the user. This will require there to be a distinction between the members declared by the current type and all the members of the type (incl. inherited).

Possible implementations

  1. Replace the current member_list (and type_descriptor::members) with the new combined list of members and expose the list of non-inherited members as declared_member_list and (and type_descriptor::declared_members). This might break compilation of code relying on util::find_one with a member name in case the same member is redeclared in the derived class metadata (as find_one static_asserts a single match). Can be solved by implementing "name shadowing" and hiding the inherited member.
  2. Keep the current contract intact, expose the new lists as ?_member_list (and type_descriptor::?_members). This might require users to remove duplicated members from derived class metadata, but also modify existing utility functions relying on those members to be in member_list.
veselink1 commented 4 years ago

Depends on #28.