0

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Max Frai
  • 61,946
  • 78
  • 197
  • 306
  • 1
    Why do you need this at all? Why not just use the templated function directly, without macros? –  Jun 20 '10 at 22:08
  • @doublep because calling is a lot bigger and takes more place. I've simplied it here. – Max Frai Jun 20 '10 at 22:20

1 Answers1

2

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

Necrolis
  • 25,836
  • 3
  • 63
  • 101
  • I wouldn't worry about VC6: it doesn't support C++. – Mike Seymour Jun 20 '10 at 22:29
  • it supports C++ alright (I use it for legacy development), you just can't get too carried away with templates and macros, plus you need so use a better STL, VC6's one (as a friend describes it) is AIDS – Necrolis Jun 20 '10 at 22:44