Passing a template which requires a comma to a single-argument macro

后端 未结 4 2134
自闭症患者
自闭症患者 2021-01-03 00:02

I have some code that essentially condenses down to

#define FOO(a)
FOO(std::map);

But it emits a compile error (too many ac

4条回答
  •  孤街浪徒
    2021-01-03 00:38

    The comma is being treated as a macro argument seperator, it does not do this with commas within parenthesizes.

    If you are using Boost, they provide BOOST_PP_COMMA:

    #include 
    
    #define FOO(a)
    FOO(std::map);
    

    You can also define your own:

    #define COMMA ,
    FOO(std::map);
    

提交回复
热议问题