[meta.reflection.member.queries] (original) (raw)
21 Metaprogramming library [meta]
21.4.10 Reflection member queries [meta.reflection.member.queries]
consteval vector<info> members_of(info r, access_context ctx);
A declaration D members-of-precedes a point Pif D precedes either Por the point immediately following the class-specifierof 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 isQ-members-of-eligible if
- the host scope of D ([basic.scope.scope]) is the class scope or namespace scope associated with Q,
- D is not a friend declaration,
- M is not a closure type ([expr.prim.lambda.closure]),
- M is not a specialization of a template ([temp.pre]),
- if Q is a class that is not a closure type, then M is a direct member of Q ([class.mem.general]) that is not a variant member of a nested anonymous union of Q ([class.union.anon]), and
- if Q is a closure type, then M is a function call operator or function call operator template.
It is implementation-defined whether declarations of other members of a closure type Qare Q-members-of-eligible.
A member M of a class or namespace Q isQ-members-of-representable from a point Pif 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 namespace, or
- a namespace alias.
Returns: A vector containing reflections of all members Mof 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 Bwhose declarations inhabit the class scope corresponding to Cfor 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_]
Throws: meta::exception unlessdealias(r) is a reflection representing either a class type that is complete from some point in the evaluation context or a namespace.
[Example 1: export module M;namespace NS { export int m;static int l;} static_assert(members_of(^^NS, access_context::current()).size() == 2);import M;static_assert( members_of(^^NS, access_context::current()).size() == 1); class B {};struct S : B { private: class I;public: int m;};static_assert( members_of(^^S, access_context::current()).size() == 7); static_assert( members_of(^^S, access_context::unchecked()).size() == 8); — _end example_]
consteval vector<info> bases_of(info type, access_context ctx);
Returns: Let C be the class represented by dealias(type).
A vector containing the reflections of all the direct base class relationships B, if any, of C such that is_accessible(^^B, ctx) 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.
Throws: meta::exception unlessdealias(type) represents a class type that is complete from some point in the evaluation context.
consteval vector<info> static_data_members_of(info type, access_context ctx);
Returns: A vector containing each element e of members_of(type, ctx)such that is_variable(e) is true, preserving their order.
Throws: meta::exception unlessdealias(type) represents a class type that is complete from some point in the evaluation context.
consteval vector<info> nonstatic_data_members_of(info type, access_context ctx);
Returns: A vector containing each element e of members_of(type, ctx)such that is_nonstatic_data_member(e) is true, preserving their order.
Throws: meta::exception unlessdealias(type) represents a class type that is complete from some point in the evaluation context.
consteval vector<info> subobjects_of(info type, access_context ctx);
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.
Throws: meta::exception unlessdealias(type) represents a class type that is complete from some point in the evaluation context.
consteval vector<info> enumerators_of(info type_enum);
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.
Throws: meta::exception unlessdealias(type_enum) represents an enumeration type, and is_enumerable_type(type_enum) is true.