I presume the problem you are having here is that you are getting an error along the lines of cmd0 does not take 5 arguments?
This is because the function created as a result of the DispatchCommand(CMD_TWO, 5, 6, 7, 8, 9) is creating code that expects to call cmd0 (and cmd1) with all 5 arguments, if the cmd == CMD_ZERO. Remember that templates are compile time, not runtime.
If static_if was available, then that might be a solution, instead of the switch conditions. However, I don't believe it is implemented by any compiler and debate still rages (AFAIK) about it's use / support / standardisation.
However, another solution would be with partially specialized template classes (template functions cannot be partially specialized), although this seems like an aweful lot of code for what you are trying to achieve :) ...
template<int>
class Dispatcher
{
public:
template <typename... Args>
static int exec(Args... args) {
return -1;
}
};
template<>
class Dispatcher<CMD_ZERO>
{
public:
template <typename... Args>
static int exec(Args... args) {
cmd0(args...);
return 0;
}
};
template<>
class Dispatcher<CMD_ONE>
{
public:
template <typename... Args>
static int exec(Args... args) {
cmd1(args...);
return 0;
}
};
template <int _Cmd, typename... Args >
int DispatchCommand(Args... args)
{
return Dispatcher<_Cmd>::exec(args...);
}
int main()
{
int stat;
stat = DispatchCommand<CMD_ZERO>(1, 3.141, 4);
stat = DispatchCommand<CMD_ONE>(5, 6, 7);
stat = DispatchCommand<CMD_TWO>(5, 6, 7, 8, 9);
system("pause");
return 0;
}
Of course, this only works if the template parameters to DispatchCommand are compile time constants..... I hope this is of some help ?