Back to Arangodb

BOOST_PP_OVERLOAD

3rdParty/boost/1.78.0/libs/preprocessor/doc/ref/overload.html

3.12.9.12.4 KB
Original Source

The BOOST_PP_OVERLOAD variadic macro expands to the name of a non-variadic macro having a given number of parameters.

Usage

BOOST_PP_OVERLOAD (prefix,...) (v)

Arguments

prefix
The prefix of the non-variadic macro name. ...
Variadic data. The number of variadic data elements, as determined by BOOST_PP_VARIADIC_SIZE, is appended to the prefix to form the output non-variadic macro name.

Remarks

This macro creates a macro name which depends on the number of elements of variadic data. It should be used in the form of
BOOST_PP_OVERLOAD(MACRO_NAME_,__VA_ARGS__)(__VA_ARGS__) in order to call a non-variadic macro taking a given number of variadic data elements as non-variadic arguments. In this way one can invoke a variadic macro with a variable number of parameters which calls one of a series of non-variadic macros doing very similar things.

In C++ 20 mode the variadic data can be empty and the given number of parameters will be 0.

Requirements Header: <boost/preprocessor/facilities/overload.hpp>

Sample Code

#include <[boost/preprocessor/facilities/overload.hpp](../headers/facilities/overload.html)>
#include <[boost/preprocessor/cat.hpp](../headers/cat.html)>
#include <[boost/preprocessor/facilities/empty.hpp](../headers/facilities/empty.html)>
#include <[boost/preprocessor/arithmetic/add.hpp](../headers/arithmetic/add.html)>

#define MACRO_1(number) MACRO_2(number,10)
#define MACRO_2(number1,number2)[BOOST\_PP\_ADD](add.html)(number1,number2)

#if !BOOST_PP_VARIADICS_MSVC

#define MACRO_ADD_NUMBERS(...)[BOOST\_PP\_OVERLOAD](overload.html)(MACRO_, __VA_ARGS__ )( __VA_ARGS__ )

#else

// or for Visual C++'s default preprocessor

#define MACRO_ADD_NUMBERS(...) \
[BOOST\_PP\_CAT](cat.html)([BOOST\_PP\_OVERLOAD](overload.html)(MACRO_, __VA_ARGS__ )( __VA_ARGS__ ),[BOOST\_PP\_EMPTY](empty.html)())

#endif

MACRO_ADD_NUMBERS(5) // output is 15
MACRO_ADD_NUMBERS(3,6) // output is 9

Copyright Edward Diener 2011,2013,2016

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)