[meta.reflection.member.queries]

# 21 Metaprogramming library [[meta]](./#meta)

## 21.4 Reflection [[meta.reflection]](meta.reflection#member.queries)

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

[ð](#lib:members_of)

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

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5407)

A declaration D [*members-of-precedes*](#def:members-of-precedes) a point P if D precedes either P or the point immediately following the [*class-specifier*](class.pre#nt:class-specifier "11.1 Preamble [class.pre]") of the outermost class for which P is in a complete-class context[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5413)

A declaration D of a member M of a class or namespace Q is[*Q-members-of-eligible*](#def:Q-members-of-eligible) if

- [(2.1)](#2.1)

the host scope of D ([[basic.scope.scope]](basic.scope.scope "6.4.1 General"))
 is the class scope or namespace scope associated with Q,

- [(2.2)](#2.2)

D is not a friend declaration,

- [(2.3)](#2.3)

M is not a closure type ([[expr.prim.lambda.closure]](expr.prim.lambda.closure "7.5.6.2 Closure types")),

- [(2.4)](#2.4)

M is not a specialization of a template ([[temp.pre]](temp.pre "13.1 Preamble")),

- [(2.5)](#2.5)

if Q is a class that is not a closure type,
 then M is a direct member of Q ([[class.mem.general]](class.mem.general "11.4.1 General"))
 that is not a variant member of a
 nested anonymous union of Q ([[class.union.anon]](class.union.anon "11.5.2 Anonymous unions")), and

- [(2.6)](#2.6)

if Q is a closure type,
 then M is a function call operator or function call operator template[.](#2.sentence-1)

It is implementation-defined
whether declarations of other members of a closure type Q are Q-members-of-eligible[.](#2.sentence-2)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5440)

A member M of a class or namespace Q is[*Q-members-of-representable*](#def:Q-members-of-representable) from a point P if a Q-members-of-eligible declaration of M members-of-precedes P,
and M is

- [(3.1)](#3.1)

a class or enumeration type

- [(3.2)](#3.2)

a type alias

- [(3.3)](#3.3)

a class template, function template,
 variable template, alias template, or concept,

- [(3.4)](#3.4)

a variable or reference V for which the type of V does not contain an undeduced placeholder type,

- [(3.5)](#3.5)

a function F for which
  * [(3.5.1)](#3.5.1)

the type of F does not contain an undeduced placeholder type,

  * [(3.5.2)](#3.5.2)

the constraints (if any) of F are satisfied, and

  * [(3.5.3)](#3.5.3)

if F is a prospective destructor, F is the selected destructor ([[class.dtor]](class.dtor "11.4.7 Destructors")),

- [(3.6)](#3.6)

a non-static data member,

- [(3.7)](#3.7)

a namespace, or

- [(3.8)](#3.8)

a namespace alias[.](#3.sentence-1)

[*Note [1](#note-1)*:

Examples of direct members that are not Q-members-of-representable
for any entity Q include:
unscoped enumerators ([[enum]](enum "9.8 Enumerations")),
partial specializations of templates ([[temp.spec.partial]](temp.spec.partial "13.7.6 Partial specialization")), and
closure types ([[expr.prim.lambda.closure]](expr.prim.lambda.closure "7.5.6.2 Closure types"))[.](#3.sentence-2)

â *end note*]

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5482)

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

- [(4.1)](#4.1)

M is Q-members-of-representable
 from some point in the evaluation context and

- [(4.2)](#4.2)

is_accessible(^^M, ctx) is true[.](#4.sentence-1)

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[.](#4.sentence-2)

Reflections of class members and unnamed bit-fields that are declared
appear in the order in which they are declared[.](#4.sentence-3)

[*Note [2](#note-2)*:

Base classes are not members[.](#4.sentence-4)

Implicitly-declared special members
appear after any user-declared members ([[special]](special "11.4.4 Special member functions"))[.](#4.sentence-5)

â *end note*]

[*Example [1](#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]](basic.lookup "6.5 Name 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](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5540)

*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[.](#5.sentence-1)

[ð](#lib:bases_of)

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

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5554)

*Returns*: Let C be the class represented by dealias(type)[.](#6.sentence-1)

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[.](#6.sentence-2)

The direct base class relationships appear in the order in which
the corresponding base classes appear in the [*base-specifier-list*](class.derived.general#nt:base-specifier-list "11.7.1 General [class.derived.general]") of C[.](#6.sentence-3)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5563)

*Throws*: meta​::​exception unlessdealias(type) represents a class type
that is complete from some point in the evaluation context[.](#7.sentence-1)

[ð](#lib:static_data_members_of)

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

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5576)

*Returns*: A vector containing each element e of members_of(type, ctx) such that is_variable(e) is true,
preserving their order[.](#8.sentence-1)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5582)

*Throws*: meta​::​exception unlessdealias(type) represents a class type
that is complete from some point in the evaluation context[.](#9.sentence-1)

[ð](#lib:nonstatic_data_members_of)

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

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5596)

*Returns*: A vector containing each element e of members_of(type, ctx) such that is_nonstatic_data_member(e) is true,
preserving their order[.](#10.sentence-1)

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5602)

*Throws*: meta​::​exception unlessdealias(type) represents a class type
that is complete from some point in the evaluation context[.](#11.sentence-1)

[ð](#lib:subobjects_of)

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

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5615)

*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[.](#12.sentence-1)

[13](#13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5621)

*Throws*: meta​::​exception unlessdealias(type) represents a class type
that is complete from some point in the evaluation context[.](#13.sentence-1)

[ð](#lib:enumerators_of)

`consteval vector<info> enumerators_of(info type_enum);
`

[14](#14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5634)

*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[.](#14.sentence-1)

[15](#15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L5640)

*Throws*: meta​::​exception unlessdealias(type_enum) represents an enumeration type,
and is_enumerable_type(​type_enum) is true[.](#15.sentence-1)
