C++ Logo

SG7

Advanced search

Subject: Incomplete types
From: Cleiton Santoia (cleitonsantoia_at_[hidden])
Date: 2020-11-02 00:33:07


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;



SG7 list run by sg7-owner@lists.isocpp.org

Older Archives on Google Groups