Creating rapid function overloads in C++
- by DeadMG
template<typename Functor, typename Return, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6,
typename Arg7, typename Arg8, typename Arg9, typename Arg10> class LambdaCall : public Instruction {
public:
LambdaCall(Functor func
,unsigned char constructorarg1
,unsigned char constructorarg2
,unsigned char constructorarg3
,unsigned char constructorarg4
,unsigned char constructorarg5
,unsigned char constructorarg6
,unsigned char constructorarg7
,unsigned char constructorarg8
,unsigned char constructorarg9
,unsigned char constructorarg10)
: arg1(constructorarg1)
, arg2(constructorarg2)
, arg3(constructorarg3)
, arg4(constructorarg4)
, arg5(constructorarg5)
, arg6(constructorarg6)
, arg7(constructorarg7)
, arg8(constructorarg8)
, arg9(constructorarg9)
, arg10(constructorarg10)
, function(func) {}
void Call(State& state) {
state.Push<Return>(func(*state.GetRegisterValue<Arg1>(arg1)
,*state.GetRegisterValue<Arg1>(arg1)
,*state.GetRegisterValue<Arg2>(arg2)
,*state.GetRegisterValue<Arg3>(arg3)
,*state.GetRegisterValue<Arg4>(arg4)
,*state.GetRegisterValue<Arg5>(arg5)
,*state.GetRegisterValue<Arg6>(arg6)
,*state.GetRegisterValue<Arg7>(arg7)
,*state.GetRegisterValue<Arg8>(arg8)
,*state.GetRegisterValue<Arg9>(arg9)
,*state.GetRegisterValue<Arg10>(arg10)
));
}
Functor function;
unsigned char arg1;
unsigned char arg2;
unsigned char arg3;
unsigned char arg4;
unsigned char arg5;
unsigned char arg6;
unsigned char arg7;
unsigned char arg8;
unsigned char arg9;
unsigned char arg10;
};
Then again for every possible number of arguments I want to support, and again for void returns.
Any way to do this faster?