From 2c7cf9410ac858dcffdc9943fa0cff781c654624 Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Mon, 28 Apr 2014 22:12:08 -0400 Subject: [PATCH] Added variadic version of BOOST_PP_EMPTY and added new is_empty tests. --- .../boost/preprocessor/facilities/empty.hpp | 7 ++++ .../facilities/is_empty_variadic.hpp | 6 +-- test/isempty.cxx | 40 ++++++++++++++++--- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/include/boost/preprocessor/facilities/empty.hpp b/include/boost/preprocessor/facilities/empty.hpp index 46db190..99e1daa 100644 --- a/include/boost/preprocessor/facilities/empty.hpp +++ b/include/boost/preprocessor/facilities/empty.hpp @@ -8,14 +8,21 @@ # */ # # /* Revised by Paul Mensonides (2002) */ +# /* Revised by Edward Diener (2014) */ # # /* See http://www.boost.org for most recent version. */ # # ifndef BOOST_PREPROCESSOR_FACILITIES_EMPTY_HPP # define BOOST_PREPROCESSOR_FACILITIES_EMPTY_HPP # +# include +# # /* BOOST_PP_EMPTY */ # +# if BOOST_PP_VARIADICS +# define BOOST_PP_EMPTY(...) +# else # define BOOST_PP_EMPTY() +# endif # # endif diff --git a/include/boost/preprocessor/facilities/is_empty_variadic.hpp b/include/boost/preprocessor/facilities/is_empty_variadic.hpp index 27b4ec0..c2700fe 100644 --- a/include/boost/preprocessor/facilities/is_empty_variadic.hpp +++ b/include/boost/preprocessor/facilities/is_empty_variadic.hpp @@ -16,10 +16,10 @@ # # if BOOST_PP_VARIADICS # +# include # include # include # -#define BOOST_PP_IS_EMPTY_GEN_ZERO(...) 0 #if BOOST_PP_VARIADICS_MSVC && _MSC_VER <= 1400 # #define BOOST_PP_IS_EMPTY(param) \ @@ -31,7 +31,7 @@ ) \ ) \ ( \ - BOOST_PP_IS_EMPTY_GEN_ZERO, \ + 0 BOOST_PP_EMPTY, \ BOOST_PP_DETAIL_IS_EMPTY_PROCESS \ ) \ (param) \ @@ -46,7 +46,7 @@ ) \ ) \ ( \ - BOOST_PP_IS_EMPTY_GEN_ZERO, \ + 0 BOOST_PP_EMPTY, \ BOOST_PP_DETAIL_IS_EMPTY_PROCESS \ ) \ (__VA_ARGS__) \ diff --git a/test/isempty.cxx b/test/isempty.cxx index f2d7bc2..94be43a 100644 --- a/test/isempty.cxx +++ b/test/isempty.cxx @@ -22,13 +22,43 @@ #define OBJECT2 #define FUNC(x) FUNC2(x) #define FUNC2(x) -#define FUNC_GEN3() anything -#define FUNC_GEN4(x) anything - +#define FUNC_GEN() () +#define FUNC_GEN2(x) () +#define FUNC_GEN3() (&) +#define FUNC_GEN4(x) (y) +#define FUNC_GEN5() (y,z) +#define FUNC_GEN6() anything +#define FUNC_GEN7(x) anything + #if defined(BOOST_PP_VARIADICS_MSVC) +#define FUNC_GEN8(x,y) (1,2,3) +#define FUNC_GEN9(x,y,z) anything + +/* These next five produce the wrong result in VC++ */ + +BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN) == 1 END +BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN2) == 1 END +BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN3) == 1 END +BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN4) == 1 END +BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN5) == 1 END + +/* This next should produce a compiler error but does not, and produces the incorrect result */ + +BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN8) == 1 END + +/* This next should produce a compiler error but does not */ + +BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN9) == 0 END + #else +BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN) == 0 END +BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN2) == 0 END +BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN3) == 0 END +BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN4) == 0 END +BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN5) == 0 END + #endif BEGIN BOOST_PP_IS_EMPTY(BOOST_PP_EMPTY()) == 1 END @@ -36,7 +66,7 @@ BEGIN BOOST_PP_IS_EMPTY(DATA BOOST_PP_EMPTY()) == 1 END BEGIN BOOST_PP_IS_EMPTY(x BOOST_PP_EMPTY()) == 0 END BEGIN BOOST_PP_IS_EMPTY(OBJECT BOOST_PP_EMPTY()) == 1 END BEGIN BOOST_PP_IS_EMPTY(FUNC(z) BOOST_PP_EMPTY()) == 1 END -BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN3) == 0 END -BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN4) == 0 END +BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN6) == 0 END +BEGIN BOOST_PP_IS_EMPTY(FUNC_GEN7) == 0 END #endif