Detect existence of private member

There is indeed a way for non-final non-union class types:

namespace detail {
    struct P {typedef int member;};
    template <typename U>
    struct test_for_member : U, P
    {
        template <typename T=test_for_member, typename = typename T::member>
        static std::false_type test(int);
        static std::true_type test(float);
    };
}
template <typename T>
using test_for_member =
  std::integral_constant<bool, decltype(detail::test_for_member<T>::test(0)){}>;

Demo. The trick is to check whether lookup into different base classes will yield an ambiguity. [class.member.lookup]/2:

Member name lookup determines the meaning of a name (id-expression)
in a class scope (3.3.7). Name lookup can result in an ambiguity, in
which case the program is ill-formed. […] Name lookup takes place
before access control (3.4, Clause 11).

Note that GCCs lookup is broken insofar as it ignores non-type names for lookup in typename-specifiers.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)