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 );
可以为所欲为.
这篇关于如何用宏删除括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何用宏删除括号?


基础教程推荐
- 常量变量在标题中不起作用 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01