I would like to define lots of functions dispatchers. Based on a flag, I will call one or the other. Flag checking is always the same, and namings also.
This is an example code:
int myfunction(int a,int b)
{
if (flag)
return myfunction_flag1(a, b);
else
return myfunction_flag0(a, b);
}
Since this code will repeat for each my functions (actual usecase uses more lines than just this if else but it was simplified for the question purpose), I would like to write it as a MACRO.
#define DISPATCHER(function_type, function_name, ...) \
function_type function_name(__VA_ARGS__) \
{ \
if (flag) \
return function_name ## flag1(__VA_ARGS__); \
else \
return function_name ## flag0(__VA_ARGS__); \
} \
And then have a lot of :
DISPATCHER(int, myfunction, int a, int b)
DISPATCHER(int, myfunction2, int a, int b, int c)
DISPATCHER(int, myfunction3, int a)
...
However, I can't call function_name ## flag1(\__VA_ARGS__)
as \__VA_ARGS__
contains the arguments types.
Is there a way to do this another way ?