std::meta::access_context::via
From cppreference.com
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
Run this code
#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
| returns the associated scope and designating class, respectively (public member function) |