I am trying to get the name of the OS and the compiler as a string in C ++. Although there are many questions about this, I did not find a definitive answer. So I tried using Boost.Predef 1.55, which defines macros like BOOST_OS_<OS>and BOOST_OS_<OS>_NAME.
Therefore, you can simply do if(BOOST_OS_<OS>) return BOOST_OS_<OS>_NAME;to support OS support. The same goes for compilers with COMPinstead OS. To avoid repetition, I wanted to use Boost.Preprocessor and put them in a loop.
I came up with the following:
#define MAKE_STMT_I2(PREFIX) if(PREFIX) return PREFIX
#define MAKE_STMT_I(type, curName) MAKE_STMT_I2(BOOST_
#define MAKE_STMT(s, type, curName) MAKE_STMT_I(type, curName)
#define OS_LIST (AIX)(AMIGAOS)(ANDROID)(BEOS)(BSD)(CYGWIN)(HPUX)(IRIX)(LINUX)(MACOS)(OS400)(QNX)(SOLARIS)(UNIX)(SVR4)(VMS)(WINDOWS)(BSDI)(DRAGONFLY)(BSD_FREE)(BSD_NET)(BSD_OPEN)
BOOST_PP_SEQ_FOR_EACH(MAKE_STMT, OS, OS_LIST)
However, I run into problems when the values expand soon. For instance. VMS already defines a macro with a name VMS, which is then replaced by OS_LIST. It #define OS_LIST (##AIX##)(##AMIGAOS##)(...doesn’t even help to do something , as it seems to expand in boost later.
How can I completely avoid the extension in the sequence?
source
share