Files
2025-10-25 03:02:53 +03:00

5.8 KiB
Raw Permalink Blame History

[meta.reflection.access.queries]

21 Metaprogramming library [meta]

21.4 Reflection [meta.reflection]

21.4.9 Member accessibility queries [meta.reflection.access.queries]

🔗

consteval bool is_accessible(info r, access_context ctx);

1

#

Let PARENT-CLS(r) be:

  • (1.1)

    If parent_of(r) represents a class C, then C.

  • (1.2)

    Otherwise, PARENT-CLS(parent_of(r)).

2

#

Let DESIGNATING-CLS(r, ctx) be:

  • (2.1)

    If ctx.designating_class() represents a class C, then C.

  • (2.2)

    Otherwise, PARENT-CLS(r).

3

#

Returns:

  • (3.1)

    If r represents an unnamed bit-field F, then is_accessible(rH, ctx), where rH represents a hypothetical non-static data member of the class represented by PARENT-CLS(r) with the same access as F. [Note 1: Unnamed bit-fields are treated as class members for the purpose of is_accessible. — end note]

  • (3.2)

    Otherwise, if r does not represent a class member or a direct base class relationship, then true.

  • (3.3)

    Otherwise, if r represents

a class member that is not a (possibly indirect or variant) member of DESIGNATING-CLS(r, ctx) or

a direct base class relationship such that parent_of(r) does not represent DESIGNATING-CLS(r, ctx) or a (direct or indirect) base class thereof,

then false.

  • (3.4)

    Otherwise, if ctx.scope() is the null reflection, then true.

  • (3.5)

    Otherwise, letting P be a program point whose immediate scope is the function parameter scope, class scope, or namespace scope corresponding to the function, class, or namespace represented by ctx.scope():

[Note 2:

The definitions of when a class member or base class is accessible from a point P do not consider whether a declaration of that entity is reachable from P.

— end note]

[Example 1: consteval access_context fn() {return access_context::current();}class Cls {int mem; friend consteval access_context fn();public:static constexpr auto r = ^^mem;};

static_assert(is_accessible(Cls::r, fn())); // OKstatic_assert(!is_accessible(Cls::r, access_context::current())); // OKstatic_assert(is_accessible(Cls::r, access_context::unchecked())); // OK — end example]

4

#

Throws: meta::exception if

r represents a class member for which PARENT-CLS(r) is an incomplete class or

r represents a direct base class relationship (D,B) for which D is incomplete.

🔗

consteval bool has_inaccessible_nonstatic_data_members(info r, access_context ctx);

5

#

Returns: true if is_accessible(R, ctx) is false for any R in nonstatic_data_members_of(r, access_context::unchecked()).

Otherwise, false.

6

#

Throws: meta::exception unless

nonstatic_data_members_of(r, access_context::unchecked()) is a constant subexpression and

r does not represent a closure type.

🔗

consteval bool has_inaccessible_bases(info r, access_context ctx);

7

#

Returns: true if is_accessible(R, ctx) is false for any R in bases_of(r, access_context::unchecked()).

Otherwise, false.

8

#

Throws: meta::exception unlessbases_of(r, access_context::unchecked()) is a constant subexpression.

🔗

consteval bool has_inaccessible_subobjects(info r, access_context ctx);

9

#

Effects: Equivalent to:return has_inaccessible_bases(r, ctx) || has_inaccessible_nonstatic_data_members(r, ctx);