21 Metaprogramming library [meta]

21.4 Reflection [meta.reflection]

21.4.9 Reflection member queries [meta.reflection.member.queries]

consteval vector<info> members_of(info r, access_context ctx);
Constant When: dealias(r) is a reflection representing either a class type that is complete from some point in the evaluation context or a namespace.
A declaration D members-of-precedes a point P if D precedes either P or the point immediately following the class-specifier of the outermost class for which P is in a complete-class context.
A declaration D of a member M of a class or namespace Q is Q-members-of-eligible if
It is implementation-defined whether declarations of other members of a closure type Q are Q-members-of-eligible.
A member M of a class or namespace Q is Q-members-of-representable from a point P if a Q-members-of-eligible declaration of M members-of-precedes P, and M is
  • a class or enumeration type
  • a type alias
  • a class template, function template, variable template, alias template, or concept,
  • a variable or reference V for which the type of V does not contain an undeduced placeholder type,
  • a function F for which
    • the type of F does not contain an undeduced placeholder type,
    • the constraints (if any) of F are satisfied, and
    • if F is a prospective destructor, F is the selected destructor ([class.dtor]),
  • a non-static data member,
  • a namesapce, or
  • a namespace alias.
[Note 1: 
Examples of direct members that are not Q-members-of-representable for any entity Q include: unscoped enumerators ([enum]), partial specializations of templates ([temp.spec.partial]), and closure types ([expr.prim.lambda.closure]).
— end note]
Returns: A vector containing reflections of all members M of the entity Q represented by dealias(r) for which
  • M is Q-members-of-representable from some point in the evaluation context and
  • is_accessible(^^M, ctx) is true.
If dealias(r) represents a class C, then the vector also contains reflections representing all unnamed bit-fields B whose declarations inhabit the class scope corresponding to C for which is_accessible(^^B, ctx) is true.
Reflections of class members and unnamed bit-fields that are declared appear in the order in which they are declared.
[Note 2: 
Base classes are not members.
Implicitly-declared special members appear after any user-declared members ([special]).
— end note]
[Example 1: // TU1 export module M; namespace NS { export int m; static int l; } static_assert(members_of(^^NS, access_context::current()).size() == 2); // TU2 import M; static_assert( // NS​::​l does not precede members_of(^^NS, access_context::current()).size() == 1); // the constant-expression ([basic.lookup]) class B {}; struct S : B { private: class I; public: int m; }; static_assert( // 6 special members, members_of(^^S, access_context::current()).size() == 7); // 1 public member, // does not include base static_assert( // all of the above, members_of(^^S, access_context::unchecked()).size() == 8); // as well as a reflection // representing S​::​I — end example]
consteval vector<info> bases_of(info type, access_context ctx);
Constant When: dealias(type) represents a class type that is complete from some point in the evaluation context.
Returns: Let C be the class represented by dealias(type).
A vector containing the reflections of all the direct base class relationships of B, if any, of C such that is_accessible(^^B, txt) is true.
The direct base class relationships appear in the order in which the corresponding base classes appear in the base-specifier-list of C.
consteval vector<info> static_data_members_of(info type, access_context ctx);
Constant When: dealias(type) represents a class type that is complete from some point in the evaluation context.
Returns: A vector containing each element e of members_of(type, ctx) such that is_variable(e) is true, preserving their order.
consteval vector<info> nonstatic_data_members_of(info type, access_context ctx);
Constant When: dealias(type) represents a class type that is complete from some point in the evaluation context.
Returns: A vector containing each element e of members_of(type, ctx) such that is_nonstatic_data_members_of(e) is true, preserving their order.
consteval vector<info> subobjects_of(info type, access_context ctx);
Constant When: dealias(type) represents a class type that is complete from some point in the evaluation context.
Returns: A vector containing each element of bases_of(type, ctx) followed by each element of nonstatic_data_members_of(​type,​ ctx), preserving their order.
consteval vector<info> enumerators_of(info type_enum);
Constant When: dealias(type_enum) represents an enumeration type, and is_enumerable_type(​type_enum) is true.
Returns: A vector containing the reflections of each enumerator of the enumeration represented by dealias(type_enum), in the order in which they are declared.