I am trying to write a class that "manages" delegates in c++. I already have the delegate class implemented for me. I want this delegate manager class to have two functions:
One would take a pointer to instance of a delegate of a certain type with a given input-argument/return type, and cache it.
The other function would take a member function of the right type in order to bind the cached delegate instance to it.
Currently, I have:
template<typename... Args>
struct FunctionParamsPack { };
This is the container for the types of the parameters this function takes. ie for foo(int i, double d)
that would be int
and double
. I am following the advice from here.
then I have the DelegateInfoPack
class:
template<typename FuncRetType,typename... FuncParams>
struct DelegateInfoPack{
//for look-up by components in the program
typedef typename DelegateClass<FuncRetType, FuncParams...> _Delegate;
//for the delegate manager
typedef typename FuncRetType _FuncRetType;
typedef typename FunctionParamsPack<FuncParams...> _FuncParams;
};
This struct is included by that the components in the program and it typedefs three typenames, two of which are to be used in the DelegateManger class:
template<typename DelegateInfoPack>
class DelegateManager
{
typedef typename DelegateInfoPack::_Delegate _Delegate;
typedef typename DelegateInfoPack::_FuncRetType _FuncRetType;
typedef typename DelegateInfoPack::_FuncParams _FuncParams;
void CacheDelegate(_Delegate* del,...) {}
template<typename UserClass>
void BindDelegate(..., _FuncRetType(UserClass::*fp)( _FuncParams())) {} //Doesn't work!
}
My problem is with the BindDelegate()
function. I am not able to create the correct signature for the member function of the type with a given return type and input parameter types.
basically, I need to know the way to have the right function pointer type with a given return type and argument type so my BindDelegate takes it as an argument.