How to remove the enclosing parentheses with macro?(如何用宏删除括号?)
问题描述
宏参数中不允许使用逗号,因为它将被视为多个参数,并且预处理将是错误的.但是,我们可以将参数括起来,让预处理器将其视为一个参数.是否有可以删除括号的宏或其他技术?
No comma is allowed in a macro argument because it will be treated as more than one arguments and the preprocessing will be wrong. However, we can parenthesize the argument to let preprocessor treat it as one argument. Is there a macro or other techniques which can remove the enclosing parentheses?
例如,如果我定义一个宏
For example, if I define a macro like
#define MY_MACRO(a, b) ...
并像使用它
MY_MACRO( A<int, double>, text );
会错的.像这样使用它
MY_MACRO( (A<int, double>), text)
使用宏或技术来删除括号就可以了.Boost 提供了 BOOST_IDENTITY_TYPE
宏,只适用于类型而不是一般情况
with a macro or technique to remove the parentheses will be fine. Boost provides BOOST_IDENTITY_TYPE
macro for only types but not general cases
推荐答案
#define ESC(...) __VA_ARGS__
然后
MY_MACRO( ESC(A<int, double>), text );
可以为所欲为.
这篇关于如何用宏删除括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何用宏删除括号?


基础教程推荐
- 从 std::cin 读取密码 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01