21 Metaprogramming library [meta]

21.4 Reflection [meta.reflection]

21.4.9 Access control context [meta.reflection.access.context]

The class access_context represents a namespace, class, or function from which queries pertaining to access rules may be performed, as well as the designating class ([class.access.base]), if any.
An access_context has an associated scope and designating class.
namespace std::meta { struct access_context { access_context() = delete; consteval info scope() const; consteval info designating_class() const; static consteval access_context current() noexcept; static consteval access_context unprivileged() noexcept; static consteval access_context unchecked() noexcept; consteval access_context via(info cls) const; }; }
The type access_context is a structural, consteval-only, non-aggregate type.
Two values ac1 and ac2 of type access_context are template-argument-equivalent ([temp.type]) if ac1.scope() and ac2.scope() are template-argument-equivalent and ac1.designating_class() and ac2.designating_class() are template-argument-equivalent.
consteval info scope() const; consteval info designating_class() const;
Returns: The access_context's associated scope and designating class, respectively.
static consteval access_context current() noexcept;
Returns: An access_context whose designating class is the null reflection and whose scope is CURRENT-SCOPE(P), where P is the point at which the invocation of current lexically appears.
Remarks: current is not an addressable function ([namespace.std]).
An invocation of current that appears at a program point P is value-dependent ([temp.dep.constexpr]) if eval-point(P) is enclosed by a scope corresponding to a templated entity.
[Example 1: struct A { int a = 0; consteval A(int p) : a(p) {} }; struct B : A { using A::A; consteval B(int p, int q) : A(p * q) {} info s = access_context::current().scope(); }; struct C : B { using B::B; }; struct Agg { consteval bool eq(info rhs = access_context::current().scope()) { return s == rhs; } info s = access_context::current().scope(); }; namespace NS { static_assert(Agg{}.s == access_context::current().scope()); // OK static_assert(Agg{}.eq()); // OK static_assert(B(1).s == ^^B); // OK static_assert(is_constructor(B{1, 2}.s) && parent_of(B{1, 2}.s) == ^^B); // OK static_assert(is_constructor(C{1, 2}.s) && parent_of(C{1, 2}.s) == ^^B); // OK auto fn() -> [:is_namespace(access_context::current().scope()) ? ^^int : ^^bool:]; static_assert(type_of(^^fn) == ^^auto()->int); // OK template<auto R> struct TCls { consteval bool fn() requires (is_type(access_context::current().scope())) { return true; // OK, scope is TCls<R>. } }; static_assert(TCls<0>{}.fn()); // OK } — end example]
static consteval access_context unprivileged() noexcept;
Returns: An access_context whose designating class is the null reflection and whose scope is the global namespace.
static consteval access_context unchecked() noexcept;
Returns: An access_context whose designating class and scope are both the null reflection.
consteval access_context via(info cls) const;
Returns: An access_context whose scope is this->scope() and whose designating class is cls.
Throws: meta​::​exception unless cls is either the null reflection or a reflection of a complete class type.