可变参数宏技巧
创建可变参数宏 FOO(a1, a2, a3,..., an)
使其扩展为 FOOn(a1, a2, a3,..., an) 的技巧是什么)
对于 n
的值在您选择的任何预选有界范围内?也就是说,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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
调用被替换为:
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.