How do I expand a macro containing commas inside a BOOST_PP_IF

二次信任 提交于 2019-12-01 22:13:22

You can delay invoking your macro by first selecting it and then invoking it:

#define TEST(...)\
    BOOST_PP_REPEAT( \
        BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), \
        MACRO, \
        BOOST_PP_VARIADIC_TO_TUPLE(__VA_ARGS__))

#define MACRO(z, n, data) BOOST_PP_IF(1,MACRO_CONTAINING_COMMA,MACRO_CONTAINING_COMMA)(n, n)

#define MACRO_CONTAINING_COMMA(_NAME, _NAME2) _NAME EATEN_COMMA _NAME2

#define EATEN_COMMA BOOST_PP_IF(1,BOOST_PP_COMMA,BOOST_PP_TUPLE_EAT())()

See it work

The IF invocation expands to either your macro without an invocation or something that discard arguments when invoked. After one is chosen, the last parentheses invoke it with the desired arguments without the commas getting in the way.

Apart from that, I changed z to n and TIBRA_EATEN_COMMA() to EATEN_COMMA. As some parts are redundant, you can find a simpler version here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!