From 7835ed019cb587164e5d038443b27b1c1d9e4f47 Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Wed, 30 Mar 2016 12:08:46 -0400 Subject: [PATCH 1/7] Updated configuration to support clang targeting VC++ --- include/boost/preprocessor/config/config.hpp | 8 +- test/Jamfile.v2 | 98 ++++++++++---------- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/include/boost/preprocessor/config/config.hpp b/include/boost/preprocessor/config/config.hpp index 8be0e47..f593c90 100644 --- a/include/boost/preprocessor/config/config.hpp +++ b/include/boost/preprocessor/config/config.hpp @@ -32,7 +32,7 @@ # elif defined(__MWERKS__) && __MWERKS__ >= 0x3200 # define BOOST_PP_CONFIG_FLAGS() (BOOST_PP_CONFIG_STRICT()) # elif defined(__EDG__) || defined(__EDG_VERSION__) -# if defined(_MSC_VER) && (defined(__INTELLISENSE__) || __EDG_VERSION__ >= 308) +# if defined(_MSC_VER) && (defined(__clang__) || defined(__INTELLISENSE__) || __EDG_VERSION__ >= 308) # define BOOST_PP_CONFIG_FLAGS() (BOOST_PP_CONFIG_MSVC()) # else # define BOOST_PP_CONFIG_FLAGS() (BOOST_PP_CONFIG_EDG() | BOOST_PP_CONFIG_STRICT()) @@ -45,7 +45,7 @@ # define BOOST_PP_CONFIG_FLAGS() (BOOST_PP_CONFIG_STRICT()) # elif defined(__BORLANDC__) || defined(__IBMC__) || defined(__IBMCPP__) || defined(__SUNPRO_CC) # define BOOST_PP_CONFIG_FLAGS() (BOOST_PP_CONFIG_BCC()) -# elif defined(_MSC_VER) && !defined(__clang__) +# elif defined(_MSC_VER) # define BOOST_PP_CONFIG_FLAGS() (BOOST_PP_CONFIG_MSVC()) # else # define BOOST_PP_CONFIG_FLAGS() (BOOST_PP_CONFIG_STRICT()) @@ -76,7 +76,7 @@ # if defined __GCCXML__ || defined __CUDACC__ || defined __PATHSCALE__ || defined __DMC__ || defined __CODEGEARC__ || defined __BORLANDC__ || defined __MWERKS__ || ( defined __SUNPRO_CC && __SUNPRO_CC < 0x5120 ) || defined __HP_aCC && !defined __EDG__ || defined __MRC__ || defined __SC__ || defined __IBMCPP__ || defined __PGI # define BOOST_PP_VARIADICS 0 # /* VC++ (C/C++) */ -# elif defined _MSC_VER && _MSC_VER >= 1400 && (!defined __EDG__ || defined(__INTELLISENSE__)) && !defined __clang__ +# elif defined _MSC_VER && _MSC_VER >= 1400 && (!defined __EDG__ || defined(__INTELLISENSE__)) # define BOOST_PP_VARIADICS 1 # undef BOOST_PP_VARIADICS_MSVC # define BOOST_PP_VARIADICS_MSVC 1 @@ -92,7 +92,7 @@ # elif !BOOST_PP_VARIADICS + 1 < 2 # undef BOOST_PP_VARIADICS # define BOOST_PP_VARIADICS 1 -# if defined _MSC_VER && _MSC_VER >= 1400 && (defined(__INTELLISENSE__) || !(defined __EDG__ || defined __GCCXML__ || defined __CUDACC__ || defined __PATHSCALE__ || defined __clang__ || defined __DMC__ || defined __CODEGEARC__ || defined __BORLANDC__ || defined __MWERKS__ || defined __SUNPRO_CC || defined __HP_aCC || defined __MRC__ || defined __SC__ || defined __IBMCPP__ || defined __PGI)) +# if defined _MSC_VER && _MSC_VER >= 1400 && (defined(__INTELLISENSE__) || !(defined __EDG__ || defined __GCCXML__ || defined __CUDACC__ || defined __PATHSCALE__ || defined __DMC__ || defined __CODEGEARC__ || defined __BORLANDC__ || defined __MWERKS__ || defined __SUNPRO_CC || defined __HP_aCC || defined __MRC__ || defined __SC__ || defined __IBMCPP__ || defined __PGI)) # undef BOOST_PP_VARIADICS_MSVC # define BOOST_PP_VARIADICS_MSVC 1 # endif diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 100df3b..772ad58 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -19,22 +19,22 @@ project preprocessor_tests : requirements on test-suite preprocessor : - [ compile arithmetic.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile array.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile comparison.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile control.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile debug.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile facilities.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile iteration.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile list.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile logical.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile punctuation.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile repetition.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile selection.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile seq.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile slot.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile tuple.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile variadic.cpp : gcc:-std=c++0x clang:-std=c++0x ] + [ compile arithmetic.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile array.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile comparison.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile control.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile debug.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile facilities.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile iteration.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile list.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile logical.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile punctuation.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile repetition.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile selection.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile seq.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile slot.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile tuple.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile variadic.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] ; test-suite preprocessor_nvm @@ -58,59 +58,59 @@ test-suite preprocessor_nvm test-suite preprocessor_c : [ compile arithmetic.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : arithmetic_c ] [ compile array.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : array_c ] [ compile comparison.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : comparison_c ] [ compile control.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : control_c ] [ compile debug.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : debug_c ] [ compile facilities.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : facilities_c ] [ compile list.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : list_c ] [ compile logical.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : logical_c ] [ compile punctuation.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : punctuation_c ] [ compile selection.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : selection_c ] [ compile seq.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : seq_c ] [ compile slot.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : slot_c ] [ compile tuple.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : tuple_c ] [ compile variadic.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : variadic_c ] ; @@ -119,71 +119,71 @@ test-suite preprocessor_c_nvm : [ compile arithmetic.c : BOOST_PP_VARIADICS=0 - gcc:-std=c99 clang:-std=c99 + gcc:-std=c99 clang-linux:-std=c99 : arithmetic_c_nvm ] [ compile array.c : BOOST_PP_VARIADICS=0 - gcc:-std=c99 clang:-std=c99 + gcc:-std=c99 clang-linux:-std=c99 : array_c_nvm ] [ compile comparison.c : BOOST_PP_VARIADICS=0 - gcc:-std=c99 clang:-std=c99 + gcc:-std=c99 clang-linux:-std=c99 : comparison_c_nvm ] [ compile control.c : BOOST_PP_VARIADICS=0 - gcc:-std=c99 clang:-std=c99 + gcc:-std=c99 clang-linux:-std=c99 : control_c_nvm ] [ compile debug.c : BOOST_PP_VARIADICS=0 - gcc:-std=c99 clang:-std=c99 + gcc:-std=c99 clang-linux:-std=c99 : debug_c_nvm ] [ compile facilities.c : BOOST_PP_VARIADICS=0 - gcc:-std=c99 clang:-std=c99 + gcc:-std=c99 clang-linux:-std=c99 : facilities_c_nvm ] [ compile list.c : BOOST_PP_VARIADICS=0 - gcc:-std=c99 clang:-std=c99 + gcc:-std=c99 clang-linux:-std=c99 : list_c_nvm ] [ compile logical.c : BOOST_PP_VARIADICS=0 - gcc:-std=c99 clang:-std=c99 + gcc:-std=c99 clang-linux:-std=c99 : logical_c_nvm ] [ compile selection.c : BOOST_PP_VARIADICS=0 - gcc:-std=c99 clang:-std=c99 + gcc:-std=c99 clang-linux:-std=c99 : selection_c_nvm ] [ compile seq.c : BOOST_PP_VARIADICS=0 - gcc:-std=c99 clang:-std=c99 + gcc:-std=c99 clang-linux:-std=c99 : seq_c_nvm ] [ compile slot.c : BOOST_PP_VARIADICS=0 - gcc:-std=c99 clang:-std=c99 + gcc:-std=c99 clang-linux:-std=c99 : slot_c_nvm ] [ compile tuple.c : BOOST_PP_VARIADICS=0 - gcc:-std=c99 clang:-std=c99 + gcc:-std=c99 clang-linux:-std=c99 : tuple_c_nvm ] ; test-suite preprocessor_isempty : - [ compile isempty.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile-fail isempty_variadic_standard_failure.cpp : gcc:-std=c++0x clang:-std=c++0x ] - [ compile-fail isempty_variadic_standard_failure2.cpp : gcc:-std=c++0x clang:-std=c++0x ] + [ compile isempty.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile-fail isempty_variadic_standard_failure.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] + [ compile-fail isempty_variadic_standard_failure2.cpp : gcc:-std=c++0x clang-linux:-std=c++0x ] ; test-suite preprocessor_isempty_nvm @@ -194,15 +194,15 @@ test-suite preprocessor_isempty_nvm test-suite preprocessor_isempty_c : [ compile isempty.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : isempty_c ] [ compile-fail isempty_variadic_standard_failure.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : isempty_variadic_standard_failure_c ] [ compile-fail isempty_variadic_standard_failure2.c - : gcc:-std=c99 clang:-std=c99 + : gcc:-std=c99 clang-linux:-std=c99 : isempty_variadic_standard_failure2_c ] ; @@ -211,7 +211,7 @@ test-suite preprocessor_isempty_c_nvm : [ compile isempty.c : BOOST_PP_VARIADICS=0 - gcc:-std=c99 clang:-std=c99 + gcc:-std=c99 clang-linux:-std=c99 : isempty_c_nvm ] ; From ee73989a2160c886ad41b31ee3e56a58f882a1f4 Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Wed, 30 Mar 2016 13:52:02 -0400 Subject: [PATCH 2/7] Further change to ensure that clang targeting VC++ behaves as the VC++ preprocessor --- include/boost/preprocessor/config/config.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/preprocessor/config/config.hpp b/include/boost/preprocessor/config/config.hpp index f593c90..a243f54 100644 --- a/include/boost/preprocessor/config/config.hpp +++ b/include/boost/preprocessor/config/config.hpp @@ -76,7 +76,7 @@ # if defined __GCCXML__ || defined __CUDACC__ || defined __PATHSCALE__ || defined __DMC__ || defined __CODEGEARC__ || defined __BORLANDC__ || defined __MWERKS__ || ( defined __SUNPRO_CC && __SUNPRO_CC < 0x5120 ) || defined __HP_aCC && !defined __EDG__ || defined __MRC__ || defined __SC__ || defined __IBMCPP__ || defined __PGI # define BOOST_PP_VARIADICS 0 # /* VC++ (C/C++) */ -# elif defined _MSC_VER && _MSC_VER >= 1400 && (!defined __EDG__ || defined(__INTELLISENSE__)) +# elif defined _MSC_VER && _MSC_VER >= 1400 && (defined(__clang__) || !defined __EDG__ || defined(__INTELLISENSE__)) # define BOOST_PP_VARIADICS 1 # undef BOOST_PP_VARIADICS_MSVC # define BOOST_PP_VARIADICS_MSVC 1 @@ -92,7 +92,7 @@ # elif !BOOST_PP_VARIADICS + 1 < 2 # undef BOOST_PP_VARIADICS # define BOOST_PP_VARIADICS 1 -# if defined _MSC_VER && _MSC_VER >= 1400 && (defined(__INTELLISENSE__) || !(defined __EDG__ || defined __GCCXML__ || defined __CUDACC__ || defined __PATHSCALE__ || defined __DMC__ || defined __CODEGEARC__ || defined __BORLANDC__ || defined __MWERKS__ || defined __SUNPRO_CC || defined __HP_aCC || defined __MRC__ || defined __SC__ || defined __IBMCPP__ || defined __PGI)) +# if defined _MSC_VER && _MSC_VER >= 1400 && (defined(__clang__) || defined(__INTELLISENSE__) || !(defined __EDG__ || defined __GCCXML__ || defined __CUDACC__ || defined __PATHSCALE__ || defined __DMC__ || defined __CODEGEARC__ || defined __BORLANDC__ || defined __MWERKS__ || defined __SUNPRO_CC || defined __HP_aCC || defined __MRC__ || defined __SC__ || defined __IBMCPP__ || defined __PGI)) # undef BOOST_PP_VARIADICS_MSVC # define BOOST_PP_VARIADICS_MSVC 1 # endif From e70abe7b4984119214682caf2a4d21e88a37ab90 Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Mon, 11 Apr 2016 14:24:38 -0400 Subject: [PATCH 3/7] Updated for VC++ quirks and overload code example. --- doc/ref/overload.html | 88 ++++++++++++++++------------- doc/topics/variadic_macros.html | 98 +++++++++++++++++---------------- 2 files changed, 102 insertions(+), 84 deletions(-) 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 + +

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 From e1e3a2e21e1a5473aefe5826e988266542fd44e6 Mon Sep 17 00:00:00 2001 From: Sergiu Deitsch Date: Sun, 23 Oct 2016 19:27:17 +0200 Subject: [PATCH 4/7] added Intel C++ compiler 17.0 workaround --- include/boost/preprocessor/cat.hpp | 2 +- include/boost/preprocessor/config/config.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/boost/preprocessor/cat.hpp b/include/boost/preprocessor/cat.hpp index 5e52850..52a3892 100644 --- a/include/boost/preprocessor/cat.hpp +++ b/include/boost/preprocessor/cat.hpp @@ -25,7 +25,7 @@ # define BOOST_PP_CAT_OO(par) BOOST_PP_CAT_I ## par # endif # -# if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_MSVC() +# if (~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_MSVC()) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1700) # define BOOST_PP_CAT_I(a, b) a ## b # else # define BOOST_PP_CAT_I(a, b) BOOST_PP_CAT_II(~, a ## b) diff --git a/include/boost/preprocessor/config/config.hpp b/include/boost/preprocessor/config/config.hpp index a243f54..2e59b18 100644 --- a/include/boost/preprocessor/config/config.hpp +++ b/include/boost/preprocessor/config/config.hpp @@ -75,8 +75,8 @@ # /* variadic support explicitly disabled for all untested compilers */ # if defined __GCCXML__ || defined __CUDACC__ || defined __PATHSCALE__ || defined __DMC__ || defined __CODEGEARC__ || defined __BORLANDC__ || defined __MWERKS__ || ( defined __SUNPRO_CC && __SUNPRO_CC < 0x5120 ) || defined __HP_aCC && !defined __EDG__ || defined __MRC__ || defined __SC__ || defined __IBMCPP__ || defined __PGI # define BOOST_PP_VARIADICS 0 -# /* VC++ (C/C++) */ -# elif defined _MSC_VER && _MSC_VER >= 1400 && (defined(__clang__) || !defined __EDG__ || defined(__INTELLISENSE__)) +# /* VC++ (C/C++) and Intel C++ Compiler >= 17.0 with MSVC */ +# elif defined _MSC_VER && _MSC_VER >= 1400 && (defined(__clang__) || !defined __EDG__ || defined(__INTELLISENSE__) || defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1700) # define BOOST_PP_VARIADICS 1 # undef BOOST_PP_VARIADICS_MSVC # define BOOST_PP_VARIADICS_MSVC 1 From eb143c10f8c9a8ceeaa9f94d355da13d114aed06 Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Mon, 14 Nov 2016 00:25:46 -0500 Subject: [PATCH 5/7] Added configuration info test. --- test/Jamfile.v2 | 5 +++ test/config_info.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 test/config_info.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 772ad58..7ac4ad9 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -215,3 +215,8 @@ test-suite preprocessor_isempty_c_nvm : isempty_c_nvm ] ; + +test-suite preprocessor_config + : + [ run config_info.cpp ] + ; diff --git a/test/config_info.cpp b/test/config_info.cpp new file mode 100644 index 0000000..ce92887 --- /dev/null +++ b/test/config_info.cpp @@ -0,0 +1,93 @@ +#include +#include +#include +#include + +static unsigned int indent = 4; +static unsigned int width = 40; + +using std::cout; +using std::istream; + +void print_separator() +{ + std::cout << +"\n\n*********************************************************************\n\n"; +} + +void print_macro(const char* name, const char* value) +{ + // if name == value+1 then then macro is not defined, + // in which case we don't print anything: + if(0 != strcmp(name, value+1)) + { + for(unsigned i = 0; i < indent; ++i) std::cout.put(' '); + std::cout << std::setw(width); + cout.setf(istream::left, istream::adjustfield); + std::cout << name; + if(value[1]) + { + // macro has a value: + std::cout << value << "\n"; + } + else + { + // macro is defined but has no value: + std::cout << " [no value]\n"; + } + } +} + +#define PRINT_MACRO(X) print_macro(#X, BOOST_PP_STRINGIZE(=X)) + +void print_macros() +{ + + print_separator(); + + PRINT_MACRO(__GCCXML__); + PRINT_MACRO(__WAVE__); + PRINT_MACRO(__MWERKS__); + PRINT_MACRO(__EDG__); + PRINT_MACRO(_MSC_VER); + PRINT_MACRO(__clang__); + PRINT_MACRO(__DMC__); + PRINT_MACRO(__BORLANDC__); + PRINT_MACRO(__IBMC__); + PRINT_MACRO(__IBMCPP__); + PRINT_MACRO(__SUNPRO_CC); + PRINT_MACRO(__CUDACC__); + PRINT_MACRO(__PATHSCALE__); + PRINT_MACRO(__CODEGEARC__); + PRINT_MACRO(__HP_aCC); + PRINT_MACRO(__SC__); + PRINT_MACRO(__MRC__); + PRINT_MACRO(__PGI); + PRINT_MACRO(__INTEL_COMPILER); + PRINT_MACRO(__GNUC__); + PRINT_MACRO(__GXX_EXPERIMENTAL_CXX0X__); + + print_separator(); + + PRINT_MACRO(__cplusplus); + PRINT_MACRO(__STDC_VERSION__); + PRINT_MACRO(__EDG_VERSION__); + PRINT_MACRO(__INTELLISENSE__); + PRINT_MACRO(__WAVE_HAS_VARIADICS__); + + print_separator(); + + PRINT_MACRO(BOOST_PP_CONFIG_ERRORS); + PRINT_MACRO(BOOST_PP_CONFIG_EXTENDED_LINE_INFO); + PRINT_MACRO(BOOST_PP_CONFIG_FLAGS()); + PRINT_MACRO(BOOST_PP_VARIADICS); + PRINT_MACRO(BOOST_PP_VARIADICS_MSVC); +} + +int main() +{ + + print_macros(); + + return 0; +} From d922d757be825e8a8b9d31f2db39698952e6f945 Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Wed, 16 Nov 2016 00:15:57 -0500 Subject: [PATCH 6/7] Fix for VC++ and VC++ emuolations ot the SEQ_TO_LIST macro --- .../seq/detail/binary_transform.hpp | 11 ++-- .../preprocessor/seq/detail/to_list_msvc.hpp | 55 +++++++++++++++++++ include/boost/preprocessor/seq/to_list.hpp | 12 ++++ 3 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 include/boost/preprocessor/seq/detail/to_list_msvc.hpp diff --git a/include/boost/preprocessor/seq/detail/binary_transform.hpp b/include/boost/preprocessor/seq/detail/binary_transform.hpp index 70897b0..08b5f9d 100644 --- a/include/boost/preprocessor/seq/detail/binary_transform.hpp +++ b/include/boost/preprocessor/seq/detail/binary_transform.hpp @@ -30,14 +30,13 @@ # endif # if BOOST_PP_VARIADICS # if BOOST_PP_VARIADICS_MSVC -# define BOOST_PP_SEQ_BINARY_TRANSFORM_GET_REM(...) \ - BOOST_PP_VARIADIC_IS_SINGLE_RETURN(BOOST_PP_REM_CAT,BOOST_PP_REM,__VA_ARGS__) \ - /**/ +# define BOOST_PP_SEQ_BINARY_TRANSFORM_REM(data) data +# define BOOST_PP_SEQ_BINARY_TRANSFORM_A(...) (BOOST_PP_SEQ_BINARY_TRANSFORM_REM, __VA_ARGS__)() BOOST_PP_SEQ_BINARY_TRANSFORM_B +# define BOOST_PP_SEQ_BINARY_TRANSFORM_B(...) (BOOST_PP_SEQ_BINARY_TRANSFORM_REM, __VA_ARGS__)() BOOST_PP_SEQ_BINARY_TRANSFORM_A # else -# define BOOST_PP_SEQ_BINARY_TRANSFORM_GET_REM(...) BOOST_PP_REM +# define BOOST_PP_SEQ_BINARY_TRANSFORM_A(...) (BOOST_PP_REM, __VA_ARGS__)() BOOST_PP_SEQ_BINARY_TRANSFORM_B +# define BOOST_PP_SEQ_BINARY_TRANSFORM_B(...) (BOOST_PP_REM, __VA_ARGS__)() BOOST_PP_SEQ_BINARY_TRANSFORM_A # endif -# define BOOST_PP_SEQ_BINARY_TRANSFORM_A(...) (BOOST_PP_SEQ_BINARY_TRANSFORM_GET_REM(__VA_ARGS__), __VA_ARGS__)() BOOST_PP_SEQ_BINARY_TRANSFORM_B -# define BOOST_PP_SEQ_BINARY_TRANSFORM_B(...) (BOOST_PP_SEQ_BINARY_TRANSFORM_GET_REM(__VA_ARGS__), __VA_ARGS__)() BOOST_PP_SEQ_BINARY_TRANSFORM_A # else # define BOOST_PP_SEQ_BINARY_TRANSFORM_A(e) (BOOST_PP_REM, e)() BOOST_PP_SEQ_BINARY_TRANSFORM_B # define BOOST_PP_SEQ_BINARY_TRANSFORM_B(e) (BOOST_PP_REM, e)() BOOST_PP_SEQ_BINARY_TRANSFORM_A diff --git a/include/boost/preprocessor/seq/detail/to_list_msvc.hpp b/include/boost/preprocessor/seq/detail/to_list_msvc.hpp new file mode 100644 index 0000000..2599c00 --- /dev/null +++ b/include/boost/preprocessor/seq/detail/to_list_msvc.hpp @@ -0,0 +1,55 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Edward Diener 2016. * +# * Distributed under the Boost Software License, Version 1.0. (See * +# * accompanying file LICENSE_1_0.txt or copy at * +# * http://www.boost.org/LICENSE_1_0.txt) * +# * * +# ************************************************************************** */ +# +# /* See http://www.boost.org for most recent version. */ +# +# ifndef BOOST_PREPROCESSOR_SEQ_DETAIL_TO_LIST_MSVC_HPP +# define BOOST_PREPROCESSOR_SEQ_DETAIL_TO_LIST_MSVC_HPP +# +# include +# +# if BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_MSVC() +# +# include +# include +# include +# include +# +# define BOOST_PP_SEQ_DETAIL_TO_LIST_MSVC_STATE_RESULT(state) \ + BOOST_PP_TUPLE_ELEM(2, 0, state) \ +/**/ +# define BOOST_PP_SEQ_DETAIL_TO_LIST_MSVC_STATE_SIZE(state) \ + BOOST_PP_TUPLE_ELEM(2, 1, state) \ +/**/ +# define BOOST_PP_SEQ_DETAIL_TO_LIST_MSVC_PRED(d,state) \ + BOOST_PP_SEQ_DETAIL_TO_LIST_MSVC_STATE_SIZE(state) \ +/**/ +# define BOOST_PP_SEQ_DETAIL_TO_LIST_MSVC_OP(d,state) \ + ( \ + BOOST_PP_CAT(BOOST_PP_SEQ_DETAIL_TO_LIST_MSVC_STATE_RESULT(state),), \ + BOOST_PP_DEC(BOOST_PP_SEQ_DETAIL_TO_LIST_MSVC_STATE_SIZE(state)) \ + ) \ +/**/ +# +# /* BOOST_PP_SEQ_DETAIL_TO_LIST_MSVC */ +# +# define BOOST_PP_SEQ_DETAIL_TO_LIST_MSVC(result,seqsize) \ + BOOST_PP_SEQ_DETAIL_TO_LIST_MSVC_STATE_RESULT \ + ( \ + BOOST_PP_WHILE \ + ( \ + BOOST_PP_SEQ_DETAIL_TO_LIST_MSVC_PRED, \ + BOOST_PP_SEQ_DETAIL_TO_LIST_MSVC_OP, \ + (result,seqsize) \ + ) \ + ) \ +/**/ +# endif // BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_MSVC() +# +# endif // BOOST_PREPROCESSOR_SEQ_DETAIL_TO_LIST_MSVC_HPP diff --git a/include/boost/preprocessor/seq/to_list.hpp b/include/boost/preprocessor/seq/to_list.hpp index fa0421b..ed8948d 100644 --- a/include/boost/preprocessor/seq/to_list.hpp +++ b/include/boost/preprocessor/seq/to_list.hpp @@ -19,7 +19,19 @@ # # /* BOOST_PP_SEQ_TO_LIST */ # +# if BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_MSVC() +# include +# include +# define BOOST_PP_SEQ_TO_LIST(seq) \ + BOOST_PP_SEQ_DETAIL_TO_LIST_MSVC \ + ( \ + BOOST_PP_SEQ_TO_LIST_I(BOOST_PP_SEQ_BINARY_TRANSFORM(seq)), \ + BOOST_PP_SEQ_SIZE(seq) \ + ) \ +/**/ +# else # define BOOST_PP_SEQ_TO_LIST(seq) BOOST_PP_SEQ_TO_LIST_I(BOOST_PP_SEQ_BINARY_TRANSFORM(seq)) +# endif # define BOOST_PP_SEQ_TO_LIST_I(bseq) BOOST_PP_SEQ_TO_LIST_A bseq BOOST_PP_NIL BOOST_PP_SEQ_TO_LIST_B bseq # define BOOST_PP_SEQ_TO_LIST_A(m, e) m(BOOST_PP_LPAREN() e BOOST_PP_COMMA() BOOST_PP_SEQ_TO_LIST_A_ID) # define BOOST_PP_SEQ_TO_LIST_A_ID() BOOST_PP_SEQ_TO_LIST_A From dc41624abadf7f204eab78ede76fc9601ff3137f Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Wed, 16 Nov 2016 13:01:51 -0500 Subject: [PATCH 7/7] Added Travis CI file. Updated config.hpp for Intel 17 on Windows. --- .travis.yml | 39 ++++++++++++++++++++ include/boost/preprocessor/config/config.hpp | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..7df0277 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,39 @@ +# Copyright 2016 Edward Diener +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) + +language: cpp + +sudo: false + +python: "2.7" + +os: + - linux + - osx + +branches: + only: + - master + - develop + +install: + - cd .. + - git clone -b $TRAVIS_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root + - cd boost-root + - git submodule update --init --depth 1 tools/build + - git submodule update --init --depth 1 libs/config + - git submodule update --init --depth 1 tools/boostdep + - cp -r $TRAVIS_BUILD_DIR/* libs/preprocessor + - python tools/boostdep/depinst/depinst.py preprocessor + - ./bootstrap.sh + - ./b2 headers + +script: + - TOOLSET=gcc,clang + - if [ $TRAVIS_OS_NAME == osx ]; then TOOLSET=clang; fi + - ./b2 libs/preprocessor/test toolset=$TOOLSET + +notifications: + email: + on_success: always diff --git a/include/boost/preprocessor/config/config.hpp b/include/boost/preprocessor/config/config.hpp index 2e59b18..4801903 100644 --- a/include/boost/preprocessor/config/config.hpp +++ b/include/boost/preprocessor/config/config.hpp @@ -92,7 +92,7 @@ # elif !BOOST_PP_VARIADICS + 1 < 2 # undef BOOST_PP_VARIADICS # define BOOST_PP_VARIADICS 1 -# if defined _MSC_VER && _MSC_VER >= 1400 && (defined(__clang__) || defined(__INTELLISENSE__) || !(defined __EDG__ || defined __GCCXML__ || defined __CUDACC__ || defined __PATHSCALE__ || defined __DMC__ || defined __CODEGEARC__ || defined __BORLANDC__ || defined __MWERKS__ || defined __SUNPRO_CC || defined __HP_aCC || defined __MRC__ || defined __SC__ || defined __IBMCPP__ || defined __PGI)) +# if defined _MSC_VER && _MSC_VER >= 1400 && (defined(__clang__) || defined(__INTELLISENSE__) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1700) || !(defined __EDG__ || defined __GCCXML__ || defined __CUDACC__ || defined __PATHSCALE__ || defined __DMC__ || defined __CODEGEARC__ || defined __BORLANDC__ || defined __MWERKS__ || defined __SUNPRO_CC || defined __HP_aCC || defined __MRC__ || defined __SC__ || defined __IBMCPP__ || defined __PGI)) # undef BOOST_PP_VARIADICS_MSVC # define BOOST_PP_VARIADICS_MSVC 1 # endif