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


- 静态初始化顺序失败 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- C++ 协变模板 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07