#include <iostream>
#include <type_traits>
template<typename T>
struct has_size_method
{
private:
typedef std::true_type yes;
typedef std::false_type no;
template<typename U, int (U::*f)() const> struct SFINAE{};
template<typename U, std::size_t (U::*f)() const> struct SFINAE<U,f>{};
template<class C> static yes test(SFINAE<C,&C::size>*);
template<class C> static no test(...);
public:
static constexpr bool value = std::is_same<yes,decltype(test<T>(nullptr))>::value;
};
struct x
{
int size() const { return 42; }
};
struct y : x {};
int main()
{
std::cout << has_size_method<x>::value << std::endl;
std::cout << has_size_method<y>::value << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZV90cmFpdHM+Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBUPgpzdHJ1Y3QgaGFzX3NpemVfbWV0aG9kCnsKcHJpdmF0ZToKCXR5cGVkZWYgc3RkOjp0cnVlX3R5cGUgeWVzOwoJdHlwZWRlZiBzdGQ6OmZhbHNlX3R5cGUgbm87CgoJdGVtcGxhdGU8dHlwZW5hbWUgVSwgaW50IChVOjoqZikoKSBjb25zdD4gc3RydWN0IFNGSU5BRXt9OwoJdGVtcGxhdGU8dHlwZW5hbWUgVSwgc3RkOjpzaXplX3QgKFU6OipmKSgpIGNvbnN0PiBzdHJ1Y3QgU0ZJTkFFPFUsZj57fTsKCgoJdGVtcGxhdGU8Y2xhc3MgQz4gc3RhdGljIHllcyB0ZXN0KFNGSU5BRTxDLCZDOjpzaXplPiopOwoJdGVtcGxhdGU8Y2xhc3MgQz4gc3RhdGljIG5vIHRlc3QoLi4uKTsKCnB1YmxpYzoKCXN0YXRpYyBjb25zdGV4cHIgYm9vbCB2YWx1ZSA9IHN0ZDo6aXNfc2FtZTx5ZXMsZGVjbHR5cGUodGVzdDxUPihudWxscHRyKSk+Ojp2YWx1ZTsKfTsKCnN0cnVjdCB4CnsKCWludCBzaXplKCkgY29uc3QgeyByZXR1cm4gNDI7IH0KfTsKCnN0cnVjdCB5IDogeCB7fTsKCmludCBtYWluKCkKewoJc3RkOjpjb3V0IDw8IGhhc19zaXplX21ldGhvZDx4Pjo6dmFsdWUgPDwgc3RkOjplbmRsOwoJc3RkOjpjb3V0IDw8IGhhc19zaXplX21ldGhvZDx5Pjo6dmFsdWUgPDwgc3RkOjplbmRsOwp9Cg==