#include <iostream>
#include <utility>
using namespace std;
// fix for gcc:
// see http://stackoverflow.com/a/25833474/3087952
//template< class ... > using void_t = void;
template< class ... >
struct make_void {
typedef void type;
};
template< class ... T >
using void_t = typename make_void< T... >::type;
template< class , class = void >
struct has_member : false_type
{ };
// specialized as has_member< T , void > or discarded (sfinae)
template< class T >
struct has_member< T , void_t< decltype( T::member ) > > : true_type
{ };
class A {
public:
int member;
};
class B {
};
int main() {
cout << "A has 'member' = " << boolalpha << has_member< A >::value << endl;
cout << "B has 'member' = " << boolalpha << has_member< B >::value << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dXRpbGl0eT4KCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKLy8gZml4IGZvciBnY2M6Ci8vIHNlZSBodHRwOi8vc3RhY2tvdmVyZmxvdy5jb20vYS8yNTgzMzQ3NC8zMDg3OTUyCgovL3RlbXBsYXRlPCBjbGFzcyAuLi4gPiB1c2luZyB2b2lkX3QgPSB2b2lkOwoKdGVtcGxhdGU8IGNsYXNzIC4uLiA+CnN0cnVjdCBtYWtlX3ZvaWQgewoJdHlwZWRlZiB2b2lkIHR5cGU7Cn07Cgp0ZW1wbGF0ZTwgY2xhc3MgLi4uIFQgPgp1c2luZyB2b2lkX3QgPSB0eXBlbmFtZSBtYWtlX3ZvaWQ8IFQuLi4gPjo6dHlwZTsKCnRlbXBsYXRlPCBjbGFzcyAsIGNsYXNzID0gdm9pZCA+CnN0cnVjdCBoYXNfbWVtYmVyIDogZmFsc2VfdHlwZQp7IH07CgovLyBzcGVjaWFsaXplZCBhcyBoYXNfbWVtYmVyPCBUICwgdm9pZCA+IG9yIGRpc2NhcmRlZCAoc2ZpbmFlKQp0ZW1wbGF0ZTwgY2xhc3MgVCA+CnN0cnVjdCBoYXNfbWVtYmVyPCBUICwgdm9pZF90PCBkZWNsdHlwZSggVDo6bWVtYmVyICkgPiA+IDogdHJ1ZV90eXBlCnsgfTsKCmNsYXNzIE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