Not sure if iterative replacement is standard, or just supported by the
compiler I'm using, but this last line gets transformed to
int s = sum(a,b,c);
Doing this for *any* number of parameters with a single set of macros is
unlikely, because you'd have to use a recursive macro, which cannot be
propertly terminated.
Yes, it really looks like doing it for any number of parameters is
impossible.
I tried the following:
#define FUNC2(x) func(dummy FUNC2_END_A(x)
#define FUNC2_END_A(x) ,x FUNC2_END_B
#define FUNC2_END_B(x) ,x FUNC2_END_A
which does:
FUNC2(a)(b)(c) --> func(dummy ,a ,b ,c FUNC2_END_B
FUNC2(a)(b) --> func(dummy ,a ,b FUNC2_END_A
FUNC2(a) --> func(dummy ,a FUNC2_END_B
unfortunately there is no way to transform subsequentely... FUNC2_END_A and
FUNC2_END_B into )
The solution I am now considering is doing:
enum FUNC6_END { FUNC6_END_A, FUNC6_END_B };
#define FUNC6(x) func* FUNC6_END_A(x)
#define FUNC6_END_A(x) (x)*(#x)*FUNC6_END_B
#define FUNC6_END_B(x) (x)*(#x)*FUNC6_END_A
which does:
FUNC6(a)(b)(c) --> func*(a)*(#a)*(b)*(#b)*(c)*(#c)*FUNC6_END_A
FUNC6(a)(b) --> func*(a)*(#a)*(b)*(#b)*FUNC6_END_B
FUNC6(a) --> func*(a)*(#a)*FUNC6_END_A
As you can see, my aim is to get the text and values of all the "arguments"
of the macro FUNC6, and that is why I can't just use overload operator().
This solution requires slightly more complicated code, possibly slighlty
slower, and there may be a problem with the precedence of operators. But it
looks its the closest solution.
SerGioGio