#include <iostream>
using namespace std;
template<typename T, typename = int>
struct HasHelloFunction : std::false_type {};
template<typename T>
struct HasHelloFunction<T, decltype((void)T::hello(), 0)> : std::true_type {};
struct Works
{
static int hello() {}
};
struct Works2
{
static void hello() {}
};
struct DoesntWork
{
static int hello; // close but not callable
};
int main() {
cout << "char: " << HasHelloFunction<char>::value << endl;
cout << "Works: " << HasHelloFunction<Works>::value << endl;
cout << "Works2: " << HasHelloFunction<Works2>::value << endl;
cout << "DoesntWork: " << HasHelloFunction<DoesntWork>::value << endl;
cout << "int: " << HasHelloFunction<int>::value << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCnRlbXBsYXRlPHR5cGVuYW1lIFQsIHR5cGVuYW1lID0gaW50PgpzdHJ1Y3QgSGFzSGVsbG9GdW5jdGlvbiA6IHN0ZDo6ZmFsc2VfdHlwZSB7fTsKIAp0ZW1wbGF0ZTx0eXBlbmFtZSBUPgpzdHJ1Y3QgSGFzSGVsbG9GdW5jdGlvbjxULCBkZWNsdHlwZSgodm9pZClUOjpoZWxsbygpLCAwKT4gOiBzdGQ6OnRydWVfdHlwZSB7fTsKIApzdHJ1Y3QgV29ya3MKewoJc3RhdGljIGludCBoZWxsbygpIHt9Cn07CiAKc3RydWN0IFdvcmtzMgp7CglzdGF0aWMgdm9pZCBoZWxsbygpIHt9Cn07CiAKc3RydWN0IERvZXNudFdvcmsKewogICAgc3RhdGljIGludCBoZWxsbzsgLy8gY2xvc2UgYnV0IG5vdCBjYWxsYWJsZQp9OwogCmludCBtYWluKCkgewogCgljb3V0IDw8ICJjaGFyOiAiIDw8IEhhc0hlbGxvRnVuY3Rpb248Y2hhcj46OnZhbHVlIDw8IGVuZGw7Cgljb3V0IDw8ICJXb3JrczogIiA8PCBIYXNIZWxsb0Z1bmN0aW9uPFdvcmtzPjo6dmFsdWUgPDwgZW5kbDsKCWNvdXQgPDwgIldvcmtzMjogIiA8PCBIYXNIZW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