C++ Logo

sg7

Advanced search

[SG7] Incomplete types

From: Cleiton Santoia <cleitonsantoia_at_[hidden]>
Date: Mon, 2 Nov 2020 03:33:07 -0300
Can I use reflection in incomplete types ?

struct X {
  int a;
  bool b;
  char c;

  constexpr variant < typename( members_of( reflexpr(X),
meta::is_nonstatic_data_member) ) >
  get_by_name(std::string s) {
   constexpr auto members = members_of( reflexpr(X),
meta::is_nonstatic_data_member);
   for constexpr (meta::info member : members) {
       if ( name_of( member ) == s ) {
           auto m = typename(member);
           return (this->*m);
       }
   }
  }
} x ;

  This is a "get_by_name" sample where we can use dynamically
x.get_by_name("a") as same as x.a;

Received on 2020-11-02 00:33:21