#include <type_traits>
#include <utility>
template<typename T>
class has_foo
{
private:
template<typename U>
static auto check( U v ) -> decltype( v.foo(), std::true_type() );
static auto check( ... ) -> decltype( std::false_type() );
public:
typedef decltype( check( std::declval<T>() ) ) type;
static bool const value = type::value;
};
class klass
{
public:
void foo() const {}
};
#include <iostream>
int main()
{
std::cout
<< has_foo<int>::value << std::endl
<< has_foo<klass>::value << std::endl;
}
I2luY2x1ZGUgPHR5cGVfdHJhaXRzPgojaW5jbHVkZSA8dXRpbGl0eT4KCnRlbXBsYXRlPHR5cGVuYW1lIFQ+CmNsYXNzIGhhc19mb28Kewpwcml2YXRlOgoJdGVtcGxhdGU8dHlwZW5hbWUgVT4KCXN0YXRpYyBhdXRvIGNoZWNrKCBVIHYgKSAtPiBkZWNsdHlwZSggdi5mb28oKSwgc3RkOjp0cnVlX3R5cGUoKSApOwoJc3RhdGljIGF1dG8gY2hlY2soIC4uLiApIC0+IGRlY2x0eXBlKCBzdGQ6OmZhbHNlX3R5cGUoKSApOwoKcHVibGljOgoJdHlwZWRlZiBkZWNsdHlwZSggY2hlY2soIHN0ZDo6ZGVjbHZhbDxUPigpICkgKSB0eXBlOwoJc3RhdGljIGJvb2wgY29uc3QgdmFsdWUgPSB0eXBlOjp2YWx1ZTsKfTsKCgpjbGFzcyBrbGFzcwp7CnB1YmxpYzoKCXZvaWQgZm9vKCkgY29uc3Qge30KfTsKCgojaW5jbHVkZSA8aW9zdHJlYW0+CgppbnQgbWFpbigpCnsKCXN0ZDo6Y291dAoJCTw8IGhhc19mb288aW50Pjo6dmFsdWUgPDwgc3RkOjplbmRsCgkJPDwgaGFzX2ZvbzxrbGFzcz46OnZhbHVlIDw8IHN0ZDo6ZW5kbDsKCn0=