template<typename T, typename M, M Method>
class ProxyObject
{
public:
template<typename... Args>
void Invoke (T& Object, _In_ Args&&... A)
{
(void)(Object.*Method)(std::forward<Args>(A)...);
}
};
class Object
{
public:
int MyMethod (int Val)
{
wcout << L"Hello!" << endl;
return Val;
}
};
int wmain ()
{
Object myObj;
ProxyObject<Object, decltype(&Object::MyMethod), &Object::MyMethod> obj;
obj.Invoke(myObj, 10);
return 0;
}
The decltype(&Object::MyMethod) seems redundant in the definition of obj. Is there any way to make the ProxyObject automatically infer the type of the pointer-to-member-function being passed, so that I can define obj as follows:
ProxyObject<Object, &Object::MyMethod> obj;