如何删除宏括起来的括号? [英] How to remove the enclosing parentheses with macro?

查看:113
本文介绍了如何删除宏括起来的括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

宏参数中不允许使用逗号,因为它将被视为多个参数,并且预处理将是错误的.但是,我们可以在参数上加上括号,以使预处理器将其视为一个参数.是否有宏或其他技术可以删除括号?

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 );

可能会做你想做的事.

这篇关于如何删除宏括起来的括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆