I want to write a type trait to check if some type has a member member
. If member
were public, there are any number of ways to do this (e.g. void_t
), the most concise of which is probably Yakk's can_apply
(which could eventually be called std::is_detected
):
struct C {
int member;
};
template <typename T>
using member_type = decltype(&T::member);
template <typename T>
using has_member = can_apply<member_type, T>;
static_assert(has_member<C>{}, "!"); // OK
But if the member were private, this trait fails, since the access on member
is ill-formed (we are not friends) and there is no differentiation between ill-formed due to access reasons and ill-formed due to this-thing-doesn't-exist reasons:
class D {
int member;
};
static_assert(has_member<D>{}, "!"); // error
Is there a way to write such a member checker across all access controls?