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

后端 未结 4 2171
自闭症患者
自闭症患者 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:20

    This should perhaps ideally be a comment, but SO doesn't support code in comments, so, you can do

    #include 
    
    #define T_ARGS( ... ) < __VA_ARGS__ >
    
    #define FOO( a )  a x;
    
    auto main() -> int
    {
        FOO( std::map T_ARGS( int, int ) );
        (void) x;
    }
    

    or you can define a macro that resolves to comma, or you can use just about any scheme that's specific to some particular use case (e.g., passing template name separately).

提交回复
热议问题