How to test if preprocessor symbol is #define'd but has no value?

前端 未结 9 1370
渐次进展
渐次进展 2020-11-30 06:08

Using C++ preprocessor directives, is it possible to test if a preprocessor symbol has been defined but has no value? Something like that:

#define MYVARIABLE         


        
9条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 06:49

    You can use the BOOST_PP_IS_EMPTY macro like so:

    #include 
    
    #define MYVARIABLE
    #if !defined(MYVARIABLE) || !BOOST_PP_IS_EMPTY(MYVARIABLE)
        // ... blablabla ...
    #endif
    

    That did the trick for me. I shall add this macro is undocumented, so use it with caution.

    Source: preprocessor-missing-IS-EMPTY-documentation

提交回复
热议问题