#include <iostream>
#include <functional>
#include <memory>
template <typename T, typename V>
int mao(T&& t, V&& v, decltype( (t.*v)(0), (int)0 ) = 0)
{//オブジェクトとメンバーポインタの組み合わせ
return 0;
}
template <typename T, typename V>
int mao(T&& t, V&& v, decltype( (*t.*v)(0), (char)0 ) = 0)
{//ポインタ(生ポ/スマポ)とメンバーポインタの組み合わせ
return 1;
}
int mao(...)
{//それ以外
return -1;
}
struct test {
int a;
test(int b) : a(b) { }
int get(int b) const { return a+b; }
};
int main()
{
test a(7);
std::unique_ptr<test> p(new test(8));
std::cout << mao(a, &test::get) << std::endl;
std::cout << mao(&a, &test::get) << std::endl;
std::cout << mao(p, &test::get) << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPG1lbW9yeT4KCnRlbXBsYXRlIDx0eXBlbmFtZSBULCB0eXBlbmFtZSBWPgppbnQgbWFvKFQmJiB0LCBWJiYgdiwgZGVjbHR5cGUoICh0Lip2KSgwKSwgKGludCkwICkgPSAwKQp7Ly/jgqrjg5bjgrjjgqfjgq/jg4jjgajjg6Hjg7Pjg5Djg7zjg53jgqTjg7Pjgr/jga7ntYTjgb/lkIjjgo/jgZsKCXJldHVybiAwOwp9CnRlbXBsYXRlIDx0eXBlbmFtZSBULCB0eXBlbmFtZSBWPgppbnQgbWFvKFQmJiB0LCBWJiYgdiwgZGVjbHR5cGUoICgqdC4qdikoMCksIChjaGFyKTAgKSA9IDApCnsvL+ODneOCpOODs+OCv++8iOeUn+ODne+8j+OCueODnuODne+8ieOBqOODoeODs+ODkOODvOODneOCpOODs+OCv+OBrue1hOOBv+WQiOOCj+OBmwoJcmV0dXJuIDE7Cn0KaW50IG1hbyguLi4pCnsvL+OBneOCjOS7peWklgoJcmV0dXJuIC0xOwp9CgpzdHJ1Y3QgdGVzdAl7CglpbnQgYTsKCXRlc3QoaW50IGIpIDogYShiKSB7IH0KCWludCBnZXQoaW50IG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