The BOOST_PP_VARIADIC_HAS_OPT macro determines whether or not the C++20 __VA_OPT__ construct is supported for the compiler's preprocessor being used. Expands to 1 if the __VA_OPT__ construct is supported, otherwise expands to 0.

Usage

BOOST_PP_VARIADIC_HAS_OPT()

Arguments

None

Remarks

This macro only returns 1 if the compiler is compiling at its own C++20 level and __VA_OPT__ is supported. It is possible for a compiler to support the __VA_OPT__ construct when not compiling at its own C++20 level, but this macro will return 0 in that case even if __VA_OPT__ is normally supported for that level. The reason for this is that such a compiler may have a compiler switch, enforcing a strict adherence to a particular C++ standard level, which gives a warning or an error if __VA_OPT__ is specified below the C++20 level, and the preprocessor library wants to avoid that happening. Therefore the macro will only test to see whether or not __VA_OPT__ is supported at the C++20 level, while otherwise always returning 0 for all lesser C++ standard levels.

Requirements

Header:  <boost/preprocessor/variadic/has_opt.hpp>

Sample Code

#include <boost/preprocessor/variadic/has_opt.hpp>
#if BOOST_PP_VARIADIC_HAS_OPT() // Preprocessor code which uses __VA_OPT__ #else // Preprocessor code which does not use __VA_OPT__ #endif

or within a macro definition

#include <boost/preprocessor/control/iif.hpp>
#include <boost/preprocessor/variadic/has_opt.hpp>
#define USE_OPT(...) BOOST_PP_IIF(BOOST_PP_VARIADIC_HAS_OPT(),MACRO_USING_OPT,MACRO_NOT_USING_OPT)(__VA_ARGS__) #define MACRO_USING_OPT(...) __VA_OPT__( preprocessor tokens ) anything #define MACRO_NOT_USING_OPT(...) anything

© Copyright Edward Diener 2019

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at www.boost.org/LICENSE_1_0.txt)