#include <iostream>
#include <utility>
#include <memory>
#include <cstdint>
template <typename V, typename T>
std::int8_t test(V&& v, T&& t, decltype((t.*v)((int)0))* = 0) {
return 0;
}
template <typename V, typename T>
std::int16_t test(V&& v, T&& t, decltype((t->*v)((int)0))* = 0) {
return 0;
}
template <typename V, typename T>
std::int32_t test(V&& v, T&& t, decltype((t.operator->()->*v)((int)0))* = 0) {
return 0;
}
std::int64_t test(...) {
return 0;
}
struct ichikawa {
int fun(int a) const {
return 2 * a;
}
};
int main() {
ichikawa ic;
std::unique_ptr<ichikawa> sp(new ichikawa);
int (ichikawa::*pF)(int)const = &ichikawa::fun;
std::cout << (*sp.*pF)(7) << std::endl; //14
auto result1 = test(pF, ic);
auto result2 = test(pF, &ic);
auto result3 = test(pF, sp);
auto result4 = test(2014, 01/02);
std::cout << sizeof(result1) << std::endl;
std::cout << sizeof(result2) << std::endl;
std::cout << sizeof(result3) << std::endl;
std::cout << sizeof(result4) << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dXRpbGl0eT4KI2luY2x1ZGUgPG1lbW9yeT4KI2luY2x1ZGUgPGNzdGRpbnQ+Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgViwgdHlwZW5hbWUgVD4Kc3RkOjppbnQ4X3QgdGVzdChWJiYgdiwgVCYmIHQsIGRlY2x0eXBlKCh0Lip2KSgoaW50KTApKSogPSAwKSB7CiAgICByZXR1cm4gMDsKfQoKdGVtcGxhdGUgPHR5cGVuYW1lIFYsIHR5cGVuYW1lIFQ+CnN0ZDo6aW50MTZfdCB0ZXN0KFYmJiB2LCBUJiYgdCwgZGVjbHR5cGUoKHQtPip2KSgoaW50KTApKSogPSAwKSB7CiAgICByZXR1cm4gMDsKfQoKdGVtcGxhdGUgPHR5cGVuYW1lIFYsIHR5cGVuYW1lIFQ+CnN0ZDo6aW50MzJfdCB0ZXN0KFYmJiB2LCBUJiYgdCwgZGVjbHR5cGUoKHQub3BlcmF0b3ItP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