#include <iostream>
template <typename Type>
class has_member
{
class yes { char m;};
class no { yes m[2];};
struct BaseMixin
{
void operator()(){}
};
struct Base : public Type, public BaseMixin {};
template <typename T, T t> class Helper{};
template <typename U>
static no deduce(U*, Helper<void (BaseMixin::*)(), &U::operator()>* = 0);
static yes deduce(...);
public:
static const bool result = sizeof(yes) == sizeof(deduce((Base*)(0)));
};
struct A{};
struct B{ void operator()(){} };
struct C{ void operator()(int,int){} };
int main()
{
std::cout << std::boolalpha; //so that true or false will be printed instead of 1 or 0
std::cout << has_member<A>::result << std::endl;
std::cout << has_member<B>::result << std::endl;
std::cout << has_member<C>::result << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdGVtcGxhdGUgPHR5cGVuYW1lIFR5cGU+IApjbGFzcyBoYXNfbWVtYmVyIAp7IAogICBjbGFzcyB5ZXMgeyBjaGFyIG07fTsgCiAgIGNsYXNzIG5vIHsgeWVzIG1bMl07fTsgCiAgIHN0cnVjdCBCYXNlTWl4aW4gCiAgIHsgCiAgICAgdm9pZCBvcGVyYXRvcigpKCl7fSAKICAgfTsgCiAgIHN0cnVjdCBCYXNlIDogcHVibGljIFR5cGUsIHB1YmxpYyBCYXNlTWl4aW4ge307IAogICB0ZW1wbGF0ZSA8dHlwZW5hbWUgVCwgVCB0PiAgY2xhc3MgSGVscGVye307IAogICB0ZW1wbGF0ZSA8dHlwZW5hbWUgVT4gCiAgIHN0YXRpYyBubyBkZWR1Y2UoVSosIEhlbHBlcjx2b2lkIChCYXNlTWl4aW46OiopKCksICZVOjpvcGVyYXRvcigpPiogPSAwKTsgCiAgIHN0YXRpYyB5ZXMgZGVkdWNlKC4uLik7IApwdWJsaWM6IAogICBzdGF0aWMgY29uc3QgYm9vbCByZXN1bHQgPSBzaXplb2YoeWVzKSA9PSBzaXplb2YoZGVkdWNlKChCYXNlKikoMCkpKTsgCn07CgpzdHJ1Y3QgQXt9OwpzdHJ1Y3QgQnsgdm9pZCBvcGVyYXRvcigpKCl7fSB9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