Search code examples
c++macrosargumentsc-preprocessorvariadic-macros

Number of arguments in macro definition


I have some templated function which has different number of arguments due to the template-type. This function is wrapped with macro definition.

#define SomeTemplate(TemplateType, Arguments) someFunc<TemplateType>(Arguments);

Everything is okay when I'm using only one argument for function calling, but I need in more. I looked at boost it does such things through definition of different macros, like this:

#define TEMP_1(Arg1) someFunc<Template>(Arg1);
#define TEMP_2(Arg1, Arg2) someFunc<Template>(Arg1, Arg2);
#define TEMP_3(Arg1, Arg2, Arg3) someFunc<Template>(Arg1, Arg2, Arg3);

But this code marked as portable for compilers. There is way to use some defines with any number of arguments. How can I do that?


Solution

  • the only way to do that us using __VA__ARGS__ in the macro definations, however, its not as portable, beacuse older compilers like VC6 doesn't support var arg'ed macros, see: MSVC GCC