#include <iostream>
using namespace std;
struct Foo
{
void Bar(int a)
{
cout<<"non-const "<<a<<endl;
}
void BarConst(int a) const
{
cout<<"const "<<a<<endl;
}
};
struct CallMe
{
template<class This, class Return, class... Args>
void Invoke(This *obj, Return(This::*MFPTR)(Args...), Args&&... args) const
{
// Do something need the Return, This, Args... types..
(obj->*MFPTR)(std::forward<Args>(args)...);
}
template<class This, class Return, class... Args>
void Invoke(This *obj, Return(This::*MFPTR)(Args...) const, Args&&... args) const
{
(obj->*MFPTR)(std::forward<Args>(args)...);
}
};
int main() {
CallMe call;
Foo f;
call.Invoke(&f, &Foo::Bar, 1);
call.Invoke(&f, &Foo::BarConst, 1);
// your code goes here
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IEZvbwp7Cgl2b2lkIEJhcihpbnQgYSkKCXsKCQljb3V0PDwibm9uLWNvbnN0ICI8PGE8PGVuZGw7Cgl9Cgl2b2lkIEJhckNvbnN0KGludCBhKSBjb25zdAoJewoJCWNvdXQ8PCJjb25zdCAiPDxhPDxlbmRsOwoJfQp9OwpzdHJ1Y3QgQ2FsbE1lCnsKCXRlbXBsYXRlPGNsYXNzIFRoaXMsIGNsYXNzIFJldHVybiwgY2xhc3MuLi4gQXJncz4KCXZvaWQgSW52b2tlKFRoaXMgKm9iaiwgUmV0dXJuKFRoaXM6OipNRlBUUikoQXJncy4uLiksIEFyZ3MmJi4uLiBhcmdzKSBjb25zdAoJewoJCS8vIERvIHNvbWV0aGluZyBuZWVkIHRoZSBSZXR1cm4sIFRoaXMsIEFyZ3MuLi4gdHlwZXMuLgoJCShvYmotPipNRlBUUikoc3RkOjpmb3J3YXJkPEFyZ3M+KGFyZ3MpLi4uKTsKCX0KCQoJdGVtcGxhdGU8Y2xhc3MgVGhpcywgY2xhc3MgUmV0dXJuLCBjbGFzcy4uLiBBcmdzPgoJdm9pZCBJbnZva2UoVGhpcyAqb2JqLCBSZXR1cm4o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