#include <iostream>
#include <vector>
#include <memory>
#include <functional>
using namespace std;
template<class S> class Foo;
template<class Ret, class Arg, class... Args>
class Foo<Ret(Arg*, Args...)>
{
public:
template<class FUNC>
Foo(FUNC func)
{
cout << "func" << endl;
}
Foo(Ret(Arg::*method)(Args...)) { cout << "fptr" << endl; }
};
class EMPTY {};
class Bar
{
public:
Bar() {}
void XD(int a) {}
};
void func1(Bar*, int)
{
}
void func2(int*, int)
{
}
void func3(int, int)
{
}
void func4(EMPTY*, int)
{
}
int main()
{
//Foo<void(int*, int)> fff(bbb); //0. 這到底是為什麼? 他始終會想先走不用推導的版本
Foo<void(Bar*, int)> obj(&Bar::XD); //1. 因為他是pointer to member所以直接走不用推導的版本
Foo<void(Bar*, int)> obj2(func1); //2 因為是非pointer to member所以只能走另一個, 透過推導
Foo<void(EMPTY*, int)> obj3(func4); //3. 原因跟2 一樣
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWVtb3J5PgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdGVtcGxhdGU8Y2xhc3MgUz4gY2xhc3MgRm9vOwoKdGVtcGxhdGU8Y2xhc3MgUmV0LCBjbGFzcyBBcmcsIGNsYXNzLi4uIEFyZ3M+CmNsYXNzIEZvbzxSZXQoQXJnKiwgQXJncy4uLik+IAp7CnB1YmxpYzoKCXRlbXBsYXRlPGNsYXNzIEZVTkM+CglGb28oRlVOQyBmdW5jKQoJewoJCWNvdXQgPDwgImZ1bmMiIDw8IGVuZGw7Cgl9CglGb28oUmV0KEFyZzo6Km1ldGhvZCkoQXJncy4uLikpIHsgY291dCA8PCAiZnB0ciIgPDwgZW5kbDsgfQp9OwpjbGFzcyBFTVBUWSB7fTsKY2xhc3MgQmFyCnsKcHVibGljOgoJQmFyKCkge30KCXZvaWQgWEQoaW50IGEpIHt9Cn07CnZvaWQgZnVuYzEoQmFyK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