What's the trick to create a variadic macro FOO(a1, a2, a3,..., an)
such that it expands to FOOn(a1, a2, a3,..., an)
for values of n
in whatever preselected bounded range you choose? That is, FOO(a)
should expand to FOO1(a)
, FOO(a, b, c)
to FOO3(a, b, c)
, etc. I know there's a standard trick but I can't seem to find it.
Please feel free to mark this question as a duplicate and close it if there's another question with the answer. I suspect there is but I couldn't find it.
The invocations are replaced by:
Improving upon James answer to add some flexibility:
Output:
This post Variadic macro to count number of arguments has what you're looking for I believe. Look at the first and second responses.