可变参数宏技巧 [英] Variadic macro trick
问题描述
创建可变参数宏FOO(a1, a2, a3,..., an)
以使其在您选择的任何预选有界范围内将n
的值扩展到FOOn(a1, a2, a3,..., an)
的窍门是什么?也就是说,FOO(a)
应该扩展到FOO1(a)
,FOO(a, b, c)
扩展到FOO3(a, b, c)
,依此类推.我知道有一个标准的技巧,但是我似乎找不到它.
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.
推荐答案
This post Variadic macro to count number of arguments has what you're looking for I believe. Look at the first and second responses.
这篇关于可变参数宏技巧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!