#include <iostream>

struct A {};

struct B {
    static int bar() { std::cout << "B::bar()" << std::endl; return 0; }
};

struct C {
    void bar(int) { std::cout << "C::bar(int)" << std::endl; }
};

template <typename T>
class X {
public:
    static void foo() {
        foo_impl(static_cast<T*>(nullptr));
    }
private:
    template <typename U>
    static auto foo_impl(U*) -> decltype(U::bar(), void()) {
        U::bar();
    }
    static void foo_impl(...) {}
};

int main() {
    X<A>::foo();
    X<B>::foo();
    X<C>::foo();
}
