diff --git a/doc/ref/overload.html b/doc/ref/overload.html index e45f26b..860b1e2 100644 --- a/doc/ref/overload.html +++ b/doc/ref/overload.html @@ -1,46 +1,58 @@ + BOOST_PP_OVERLOAD - + -
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. -
Requirements -
Header:  <boost/preprocessor/facilities/overload.hpp> +
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. +
+ Requirements +
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
-

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)

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

// or for Visual C++

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

MACRO_ADD_NUMBERS(5) // output is 15
MACRO_ADD_NUMBERS(3,6) // output is 9
-
-
-
© Copyright Edward Diener 2011,2013
-
+
+
© 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)

+(See accompanying file LICENSE_1_0.txt +or copy at www.boost.org/LICENSE_1_0.txt)

- - \ No newline at end of file + + \ No newline at end of file diff --git a/doc/topics/variadic_macros.html b/doc/topics/variadic_macros.html index 4427765..985b9eb 100644 --- a/doc/topics/variadic_macros.html +++ b/doc/topics/variadic_macros.html @@ -1,40 +1,37 @@ + variadic_macros.html - +

Variadic Macros

-
Variadic macros are supported by a number of compilers. - They are - macros of the form: -
-
+
Variadic macros are supported by a number of compilers. They are + macros of the form:
+
#define SOME_MACRO(ZeroOrMoreParameters,...) macro expansion possible specifying __VA_ARGS__
-
The '...' in the parameter list represents the variadic - data when the macro is invoked and the __VA_ARGS__ in the expansion - represents the variadic data in the expansion of the macro. Variadic - data is of the form of 1 or more preprocessor tokens separated by - commas.
+
The '...' in the parameter list represents the variadic data when the + macro is invoked and the __VA_ARGS__ in the expansion represents the + variadic data in the expansion of the macro. Variadic data is of the form + of 1 or more preprocessor tokens separated by commas.

- The '...' must be the last parameter in the macro definition and there - may be 0 or more non-variadic parameters preceding it.
+ The '...' must be the last parameter in the macro definition and there may + be 0 or more non-variadic parameters preceding it.

- In the expansion of the macro __VA_ARGS__ may be specified 0 or more - times to represent the variadic data. The variadic data in the - expansion is a comma separated list of preprocessor tokens representing - the variadic data which the invoker of the macro enters as the last - arguments to the macro.
+ In the expansion of the macro __VA_ARGS__ may be specified 0 or more times + to represent the variadic data. The variadic data in the expansion is a + comma separated list of preprocessor tokens representing the variadic data + which the invoker of the macro enters as the last arguments to the macro.

Example - Creating and invoking a variadic macro.

-
+
#define INITIALIZE_INT_ARRAY(array_name,...) \ 
static int array_name[] = { __VA_ARGS__ }; \
/**/

INITIALIZE_INT_ARRAY(myname,45,789,33510,9346,2)
- Preprocessor + Preprocessor Library Support
The library offers support for variadic macros for those @@ -56,7 +53,15 @@ When BOOST_PP_VARIADICS is 1, the library offers some extended functionality by using variadic macros, and also offers extended support for working - with variadic data.
+ with variadic data.

+ Visual C++ has a + few quirks related to variadic macros which require the end-user to code + slightly differently. When BOOST_PP_VARIADICS is 1 and Visual C++ is the + compiler BOOST_PP_VARIADICS_MSVC is 1, else when BOOST_PP_VARIADICS is 1 + and Visual C++ is not the compiler BOOST_PP_VARIADICS_MSVC is 0. When + BOOST_PP_VARIADICS is 0 then BOOST_PP_VARIADICS_MSVC is not defined. + In this way the end-user, when using variadic macros, can test for the + presence of Visual C++ as the compiler and code accordingly.

Support for working with variadic data is largely centered on being able to convert variadic data to @@ -64,7 +69,7 @@ functionality for working with those Boost preprocessor library data types is much greater than that for working with variadic data directly.
- +

Notation For Variadic Macros

In the documentation, headers which have variadic macros, @@ -131,7 +136,7 @@ use this variadic data reliably as arguments to other macros, one needs variadic macro support.
- Using a Tuple Instead of an Array
+ Using a Tuple Instead of an Array
An array as a preprocessor data type is a two-element tuple where the first element is the array size and the second element is a tuple which @@ -144,7 +149,7 @@ type is essentially obsolete for conforming C++ compilers. Only if your compiler does not support variadic macros is the preprocessor array data type still useful.
- Using Variadic Data + Using Variadic Data
Variadic data exists in the form of comma-separated preprocessor tokens. This is the case whether the variadic data comes from the __VA_ARGS__ of a variadic macro, from @@ -169,7 +174,7 @@ variadic data as a whole to variadic macros as the last parameter of the macro. However:

- Attempting to pass + Attempting to pass variadic data as a whole directly into a non-variadic macro is not guaranteed to work and may fail.
@@ -178,7 +183,7 @@ of compilers, currently most notably Visual C++. Even passing variadic data as arguments to a non-variadic macro, when it is not represented in - the form of  __VA_ARGS__, may fail with certain compilers.
+ the form of  __VA_ARGS__, may fail with certain compilers.

What follows are very simple examples, showing how variadic data can be passed to a non-variadic macro.
@@ -188,9 +193,9 @@

Example - Passing variadic data as a whole to a non-variadic macro. DO NOT DO.

-
+
#define MACRO_ARG_2(x,y) BOOST_PP_ADD(x,y)
#define VAR_MACRO(...) __VA_ARGS__

/* The following should not be done and is not guaranteed to work with compilers. */

int xx = MACRO_ARG_2(VAR_MACRO(2,3));
+ style="font-weight: bold;">int xx = MACRO_ARG_2(VAR_MACRO(2,3));
There are two ways to pass variadic data to a non-variadic macro. @@ -203,7 +208,7 @@ style="font-weight: bold;">i a non-variadic macro.
-
+
#define MACRO_ARG_2(x,y) BOOST_PP_ADD(x,y)
#define VAR_MACRO(...) __VA_ARGS__

/* The following will work correctly */

int xx = MACRO_ARG_2
(
BOOST_PP_VARIADIC_ELEM(0,VAR_MACRO(2,3)),
BOOST_PP_VARIADIC_ELEM(1,VAR_MACRO(2,3))
);
The second way is to use a macro in the library called @@ -215,7 +220,7 @@ style="font-weight: bold;">i BOOST_PP_OVERLOAD and on to a non-variadic macro.
-
+
#define MACRO_ARG_2(x,y) BOOST_PP_ADD(x,y)
#define VAR_MACRO(...) __VA_ARGS__

/* The following will work correctly */

int xx = BOOST_PP_OVERLOAD(MACRO_ARG_,VAR_MACRO(2,3))(VAR_MACRO(2,3));

/* For Visual C++ it is necessary to do this */

int xx =
BOOST_PP_CAT(BOOST_PP_OVERLOAD(MACRO_ARG_,VAR_MACRO(2,3))(VAR_MACRO(2,3)),BOOST_PP_EMPTY());

@@ -230,27 +235,28 @@ style="font-weight: bold;">i
See Also
-
-
© Copyright +
+
© Copyright Edward Diener - 2011,2013
-
+ 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)

+ (See accompanying file LICENSE_1_0.txt + or copy at www.boost.org/LICENSE_1_0.txt)

- - + + + \ No newline at end of file