Files
cppdraft_translate/cppdraft/meta/reflection/member/queries.md
2025-10-25 03:02:53 +03:00

8.9 KiB
Raw Blame History

[meta.reflection.member.queries]

21 Metaprogramming library [meta]

21.4 Reflection [meta.reflection]

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

🔗

consteval vector<info> members_of(info r, access_context ctx);

1

#

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.

2

#

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 Q are Q-members-of-eligible.

3

#

A member M of a class or namespace Q isQ-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 namespace, 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]

4

#

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: // TU1export module M;namespace NS {export int m; static int l;}static_assert(members_of(^^NS, access_context::current()).size() == 2);

// TU2import 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 basestatic_assert( // all of the above, members_of(^^S, access_context::unchecked()).size() == 8); // as well as a reflection// representing S::I — end example]

5

#

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.

🔗

consteval vector<info> bases_of(info type, access_context ctx);

6

#

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.

7

#

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);

8

#

Returns: A vector containing each element e of members_of(type, ctx) such that is_variable(e) is true, preserving their order.

9

#

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);

10

#

Returns: A vector containing each element e of members_of(type, ctx) such that is_nonstatic_data_member(e) is true, preserving their order.

11

#

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);

12

#

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.

13

#

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);

14

#

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.

15

#

Throws: meta::exception unlessdealias(type_enum) represents an enumeration type, and is_enumerable_type(type_enum) is true.