Namespaces
Variants

std::meta::is_accessible

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Reflection queries
Reflection layout queries
Type properties
Type property queries
 
Defined in header <meta>
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_CLS be the class that contains the declaration of what r represents or the derived class in the direct base relationship;
  • DESIGNATING_CLS be ctx.designating_class() if it's not the null reflection, or PARENT_CLS otherwise.

The result is determined as follows:

  • If DESIGNATING_CLS is not the same as or derived from PARENT_CLS, then returns false.
  • Otherwise, if ctx.scope() is the null reflection, then returns true.
  • Otherwise, if r represents a direct base class relationship where the base class is B, returns true if the base class B of DESIGNATING_CLS is accessible within ctx.scope(); otherwise returns false.
  • Otherwise, r represents a member M. returns true if M as a member of DESIGNATING_CLS would be accessible within ctx.scope() if the effect of any using declaration were ignored; otherwise returns false.

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() {}

See also

represents a context for access checking
(class) [edit]