std::meta::is_accessible - cppreference.com
From cppreference.com
consteval bool is_accessible( std::meta::info r, std::meta::access_context ctx ); |
(since C++26) | |
Determines whether the member or base class represented by r is accessible in the context of ctx.
If r does not represent a class member or direct base class relationship, returns true. Otherwise, let:
PARENT_CLSbe the class that contains the declaration of whatrrepresents or the derived class in the direct base relationship;DESIGNATING_CLSbectx.designating_class()if it's not the null reflection, orPARENT_CLSotherwise.
The result is determined as follows:
- If
DESIGNATING_CLSis not the same as or derived fromPARENT_CLS, then returnsfalse. - Otherwise, if
ctx.scope()is the null reflection, then returnstrue. - Otherwise, if
rrepresents a direct base class relationship where the base class isB, returnstrueif the base classBofDESIGNATING_CLSis accessible withinctx.scope(); otherwise returnsfalse. - Otherwise,
rrepresents a member M. returnstrueif M as a member ofDESIGNATING_CLSwould be accessible withinctx.scope()if the effect of any using declaration were ignored; otherwise returnsfalse.
This function treats an unnamed bit-field as a non-static data member with the same access.
Parameters
| r | - | a reflection value |
| ctx | - | an access context |
Return value
true if what r represents is accessible in the context ctx, otherwise false
Exceptions
Throws std::meta::exception if r represents a member of a class currently being defined.
Example
#include <meta> consteval std::meta::access_context fn() { return std::meta::access_context::current(); } class C { [[maybe_unused]] int moo; friend consteval std::meta::access_context fn(); public: static constexpr auto r{^^moo}; }; static_assert(is_accessible(C::r, fn()) == true); static_assert(is_accessible(C::r, std::meta::access_context::current()) == false); static_assert(is_accessible(C::r, std::meta::access_context::unchecked()) == true); int main() {}