#include <iostream>
#include <type_traits>

using namespace std;

struct FooNo {};
struct FooYes { int x; };

struct FooDerivedYes : public FooYes {};
struct FooDerivedNo : public FooNo {};
struct FooDerivedTwiceYes final : public FooYes { int x; };

template <typename T, typename = void>
struct HasX : false_type { };

template <typename T>
struct HasX <T, decltype((void) T::x)> : true_type { };

int main() {
    cout << HasX<FooYes>::value << endl;
    cout << HasX<FooNo>::value << endl;
    cout << HasX<FooDerivedYes>::value << endl;
    cout << HasX<FooDerivedNo>::value << endl;
    cout << HasX<FooDerivedTwiceYes>::value << endl;
}