[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

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

Returns: A vector containing reflections of all members Mof the entity Q represented by dealias(r) for which

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.