Spec-Zone.ru › C++

std::meta::access_context::via

consteval std::meta::access_context via( std::meta::info cls ) const;

Returns a new access_context whose associated scope is this->scope() and whose designating class is cls.

Parameters

cls - a reflection of a class type or a null reflection

Return value

A access_context as described above.

Exceptions

Throws std::meta::exception unless cls is either the null reflection or a reflection of a complete class type.

Notes

The designating class is the class used to name a member. For example, in C::member, the designating class is C; in obj.member, the designating class is the type of obj.

The same member may have different accessibility when designated in different classes.

Example

#include <meta>

struct Base { static constexpr int mem = 42; };

struct Derived : private Base
{
    static constexpr auto ctx = std::meta::access_context::current();
};

constexpr auto ctx = std::meta::access_context::unprivileged();

int x = Base::mem; // OK, Base::mem is public
static_assert(std::meta::is_accessible(^^Base::mem, ctx));

// int y = Derived::mem; // Error: Base::mem is private in Derived
static_assert(!std::meta::is_accessible(^^Base::mem, ctx.via(^^Derived)));

// The private Derived::mem is accessible in the scope of Derived
static_assert(std::meta::is_accessible(^^Base::mem, Derived::ctx.via(^^Derived)));

int main() {}

See also

scopedesignating_class
returns the associated scope and designating class, respectively
(public member function)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/meta/access_context/via

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API