diff --git a/doc/ref/overload.html b/doc/ref/overload.html index 860b1e2..c744c55 100644 --- a/doc/ref/overload.html +++ b/doc/ref/overload.html @@ -1,17 +1,19 @@ + - + BOOST_PP_OVERLOAD - + -
The BOOST_PP_OVERLOAD variadic - macro expands to the name of a non-variadic macro having a given number of - parameters.
+
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)
+
BOOST_PP_OVERLOAD(prefix,...) (v)

Arguments

@@ -20,39 +22,43 @@
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 +
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. + 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> +
Header:  <boost/preprocessor/facilities/overload.hpp>

Sample Code

-
#include <boost/preprocessor/facilities/overload.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/facilities/empty.hpp>
#include <boost/preprocessor/arithmetic/add.hpp>

#define MACRO_1(number) MACRO_2(number,10)
#define MACRO_2(number1,number2) BOOST_PP_ADD(number1,number2)

#if !BOOST_PP_VARIADICS_MSVC

#define MACRO_ADD_NUMBERS(...) BOOST_PP_OVERLOAD(MACRO_,__VA_ARGS__)(__VA_ARGS__)

#else

// or for Visual C++

#define MACRO_ADD_NUMBERS(...) \
BOOST_PP_CAT(BOOST_PP_OVERLOAD(MACRO_,__VA_ARGS__)(__VA_ARGS__),BOOST_PP_EMPTY())

#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)

-
- - \ No newline at end of file +
#include <boost/preprocessor/facilities/overload.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/facilities/empty.hpp>
#include <boost/preprocessor/arithmetic/add.hpp>

#define MACRO_1(number) MACRO_2(number,10)
#define MACRO_2(number1,number2) BOOST_PP_ADD(number1,number2)

#if !BOOST_PP_VARIADICS_MSVC

#define MACRO_ADD_NUMBERS(...) BOOST_PP_OVERLOAD(MACRO_,__VA_ARGS__)(__VA_ARGS__)

#else

// or for Visual C++

#define MACRO_ADD_NUMBERS(...) \
BOOST_PP_CAT(BOOST_PP_OVERLOAD(MACRO_,__VA_ARGS__)(__VA_ARGS__),BOOST_PP_EMPTY())

#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)

+
+ + diff --git a/doc/topics/variadic_macros.html b/doc/topics/variadic_macros.html index 8d4bdde..7554055 100644 --- a/doc/topics/variadic_macros.html +++ b/doc/topics/variadic_macros.html @@ -1,4 +1,4 @@ - + In the C++20 specification there is a new construct which can be used in the expansion of a variadic macro, called __VA_OPT__. This construct when used in the expansion of a variadic macro is - followed by an opening paranthesis ('('), preprocessor data, and a - closing parenthesis ('}'). When the variadic data passed by the + followed by an opening paranthesis '(', preprocessor data, and a + closing parenthesis ')'. When the variadic data passed by the invocation of a variadic macro is empty, this new construct expands to nothing. When the variadic data passed by the invocation of a variadic macro is not empty, this new construct @@ -159,21 +159,23 @@ it returns 0.

When the __VA_OPT__ construct is supported in C++20 mode the - variadic data passed to the variadic macros can be empty, - otherwise when not in this mode variadic data passed to the - variadic macros should never be empty. In this C+++20 mode - invoking BOOST_PP_VARIADIC_SIZE with empty data expands to 0, - invoking BOOST_PP_VARIADIC_TO_ARRAY with empty data expands to the - empty array '(0,())', and invoking BOOST_PP_VARIADIC_TO_LIST with - empty data expands to the empty list 'BOOST_PP_NIL'. Similarly in - this C++20 mode passing an empty array '(0,())' to - BOOST_PP_ARRAY_ENUM expands to empty variadic data and passing an - empty list 'BOOST_PP_NIL' to BOOST_PP_LIST_ENUM also expands to - empty variadic data. Neither a seq or a tuple can be empty so - passing empty variadic data to either BOOST_PP_VARIADIC_TO_SEQ or + variadic data passed to the variadic macros and to + BOOST_PP_OVERLOAD can be empty, otherwise when not in this mode + variadic data passed to the variadic macros should never be empty. + In this C+++20 mode invoking BOOST_PP_VARIADIC_SIZE with empty + data expands to 0, invoking BOOST_PP_VARIADIC_TO_ARRAY with empty + data expands to the empty array '(0,())', invoking + BOOST_PP_VARIADIC_TO_LIST with empty data expands to the empty + list 'BOOST_PP_NIL', and invoking BOOST_PP_OVERLOAD with empty + data creates an overload name with 0 appended. Similarly in this + C++20 mode passing an empty array '(0,())' to BOOST_PP_ARRAY_ENUM + expands to empty variadic data and passing an empty list + 'BOOST_PP_NIL' to BOOST_PP_LIST_ENUM also expands to empty + variadic data. Neither a seq or a tuple can be empty so passing + empty variadic data to either BOOST_PP_VARIADIC_TO_SEQ or BOOST_PP_VARIADIC_TO_TUPLE is erroneous. Likewise passing empty data to BOOST_PP_VARIADIC_ELEM is always erroneous since there are - no tokens of variadic data to access.
+ no tokens of variadic data to access.
Using a Tuple Instead of an Array