#include <iostream>
#include <functional>
#include <memory>
template <typename T, typename V>
int mao(T&& t, V&& v, decltype( (t.*v)(0), (int)0 ))
{//オブジェクトとメンバーポインタの組み合わせ
return 0;
}
template <typename T, typename V>
int mao(T&& t, V&& v, decltype( (*t.*v)(0), (char)0) )
{//ポインタ(生ポ/スマポ)とメンバーポインタの組み合わせ
return 1;
}
template <typename T, typename V>
int mao(T&& t, V&& v, ...)
{//それ以外
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,0) << std::endl;
std::cout << mao(&a, &test::get,0) << std::endl;
std::cout << mao(p, &test::get,0) << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPG1lbW9yeT4KCnRlbXBsYXRlIDx0eXBlbmFtZSBULCB0eXBlbmFtZSBWPgppbnQgbWFvKFQmJiB0LCBWJiYgdiwgZGVjbHR5cGUoICh0Lip2KSgwKSwgKGludCkwICkpCnsvL+OCquODluOCuOOCp+OCr+ODiOOBqOODoeODs+ODkOODvOODneOCpOODs+OCv+OBrue1hOOBv+WQiOOCj+OBmwoJcmV0dXJuIDA7Cn0KdGVtcGxhdGUgPHR5cGVuYW1lIFQsIHR5cGVuYW1lIFY+CmludCBtYW8oVCYmIHQsIFYmJiB2LCBkZWNsdHlwZSggKCp0Lip2KSgwKSwgKGNoYXIpMCkgKQp7Ly/jg53jgqTjg7Pjgr/vvIjnlJ/jg53vvI/jgrnjg57jg53vvInjgajjg6Hjg7Pjg5Djg7zjg53jgqTjg7Pjgr/jga7ntYTjgb/lkIjjgo/jgZsKCXJldHVybiAxOwp9CnRlbXBsYXRlIDx0eXBlbmFtZSBULCB0eXBlbmFtZSBWPgppbnQgbWFvKFQmJiB0LCBWJiYgdiwgLi4uKQp7Ly/jgZ3jgozku6XlpJYKCXJldHVybiAtMTs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