#include <iostream>
using namespace std;

struct Action
{
	template <typename T>
	static bool func_real(T a){return func(a, special_());}
	
private:

    struct general_ {};
    struct special_ : general_ {};
    template<typename> struct bool_ { typedef bool type; };

    template<typename S, typename bool_<decltype(std::declval<S>().Y())>::type = 0>
    static bool func(S a, special_) {
    	cout<<"Y() exists"<<endl;
    	if(a.X()){
    		return a.Y();
    	}
  		return false;
    }

    template<typename S>
    static bool func(S a, general_) {
        cout<<"Y() does not exist"<<endl;
        return false;
    }
};


struct Has{
	bool X(){return true;}
	bool Y(){return true;}
};

struct Has2{
	bool X(){return true;}
	bool Y(){return false;}
};

struct HasNo{
	bool X(){return false;}
};

int main() {
	Has has;
	Has2 has2;
	HasNo no;
	cout<< Action::func_real<Has>(has) <<endl;
	cout<< Action::func_real<Has2>(has2) <<endl;
	cout<< Action::func_real<HasNo>(no) <<endl;
	return 0;
}