Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Using variadic macros

Variadic macros, as specified by C++11, is a feature taken from the C99 specification. They are macros which take a final parameter denoted as '...' which represents one or more final arguments to the macro as a series of comma-separated tokens. In the macro expansion a special keyword of '__VA_ARGS__' represents the comma-separated tokens. This information when passed to a variadic macro I call 'variadic macro data', which gives its name to this library. The more general term 'variadic data' is used in this documentation to specify data passed to a macro which can contain any number of macro tokens as a single macro parameter, such as is found in Boost PP data types.

Boost support

The Boost PP library has support for variadic macros and uses its own criteria to determine if a particular compiler has that support. Boost PP defines or uses the macro BOOST_PP_VARIADICS to denote whether the compiler being used supports variadic macros. When BOOST_PP_VARIADICS is set to 1 the compiler supports variadic macros, otherwise when BOOST_PP_VARIADICS is set to 0 the compiler does not support variadic macros. If a user of Boost PP sets this value, Boost PP uses the value the end-user sets, otherwise Boost PP defines the value of BOOST_PP_VARIADICS based on its own analysis of the compiler being used. This macro can also be checked to determine if a compiler has support for variadic macros.

Determining variadic macro support

The VMD library automatically determines whether variadic macro support is enabled for a particular compiler by also using the same BOOST_PP_VARIADICS macro from Boost PP. The end-user of VMD can also manually set the macro BOOST_PP_VARIADICS to turn on or off compiler support for variadic macros in the VMD library. When BOOST_PP_VARIADICS is set to 0 variadic macros are not supported in the VMD library, otherwise when BOOST_PP_VARIADICS is set to non-zero they are supported in the VMD library. This same macro can be used to determine if VMD supports variadic macros for a particular compiler.

Since this library depends on variadic macro support, if BOOST_PP_VARIADICS is set to 0, using any of the macros in VMD will lead to a compiler error since the macro will not be defined. However just including any of the header files in VMD, even with no variadic macro support for the compiler, will not lead to any compiler errors.


PrevUpHomeNext