From 88a0365f4de3d0bf894c7841b8293f7ff07ad8cf Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Sun, 6 Oct 2019 22:06:38 -0400 Subject: [PATCH] Added the BOOST_PP_CHECK_EMPTY macro and documentation. --- doc/headers/facilities/check_empty.html | 29 ++++++++ doc/ref/check_empty.html | 68 +++++++++++++++++++ include/boost/preprocessor/facilities.hpp | 1 + .../preprocessor/facilities/check_empty.hpp | 19 ++++++ test/checkempty.cpp | 12 ++++ test/checkempty.cxx | 61 +++++++++++++++++ 6 files changed, 190 insertions(+) create mode 100644 doc/headers/facilities/check_empty.html create mode 100644 doc/ref/check_empty.html create mode 100644 include/boost/preprocessor/facilities/check_empty.hpp create mode 100644 test/checkempty.cpp create mode 100644 test/checkempty.cxx diff --git a/doc/headers/facilities/check_empty.html b/doc/headers/facilities/check_empty.html new file mode 100644 index 0000000..81cdf8d --- /dev/null +++ b/doc/headers/facilities/check_empty.html @@ -0,0 +1,29 @@ + + + facilities/check_empty.hpp + + + +
+ The facilities/check_empty.hpp header defines a variadic macro for the C++20 level that checks if its data is empty or not. +
+

Usage

+
+ #include <boost/preprocessor/facilities/check_empty.hpp> +
+

Contents

+ +
+
+ © Copyright Edward Diener 2019 +
+
+

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/ref/check_empty.html b/doc/ref/check_empty.html new file mode 100644 index 0000000..76cef8b --- /dev/null +++ b/doc/ref/check_empty.html @@ -0,0 +1,68 @@ + + + BOOST_PP_CHECK_EMPTY + + + +
The BOOST_PP_CHECK_EMPTY variadic macro +checks to see if its variadic input is empty or not. It expands to 1 if its input +is empty and expands to 0 if its input is not empty. The macro only exists when +the compilation is at the C++20 level and the __VA_OPT__ construct is supported.
+

Usage

+
BOOST_PP_CHECK_EMPTY(...) (v)
+
+

Arguments

+
+
...
+
+
The variadic data to be checked for emptiness.
+
+

Remarks

+
+When the macro invocation BOOST_PP_VARIADIC_OPT() expands to 1, then this +macro exists and can be invoked, otherwise this macro does not exist +and attempting to invoke it will lead to a preprocessor error that the macro +can not be found. Because of this condition the header file for including +this macro includes the header file for the BOOST_PP_VARIADIC_OPT macro.
+It is possible to pass data to this macro which expands to nothing, in which +case this macro will expand to 1 just as if nothing has been passed. +
+

See Also

+ +

Requirements

+
Header:  <boost/preprocessor/facilities/check_empty.hpp> +
+

Sample Code

+
+
+#include <boost/preprocessor/facilities/check_empty.hpp>
+
+# if BOOST_PP_VARIADIC_OPT()
+
+#define DATA
+#define OBJECT OBJECT2
+#define OBJECT2
+#define FUNC(x) FUNC2(x)
+#define FUNC2(x)
+#define FUNC_GEN(x,y) (1,2,3)
+
+BOOST_PP_CHECK_EMPTY(DATA)     // expands to 1
+BOOST_PP_CHECK_EMPTY(OBJECT)   // expands to 1
+BOOST_PP_CHECK_EMPTY(FUNC(1))  // expands to 1
+BOOST_PP_CHECK_EMPTY(FUNC)     // expands to 0
+BOOST_PP_CHECK_EMPTY(FUNC_GEN) // expands to 0
+
+#endif
+
+
+
+
© Copyright Edward Diener 2019
+
+

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/include/boost/preprocessor/facilities.hpp b/include/boost/preprocessor/facilities.hpp index c20547c..291b78e 100644 --- a/include/boost/preprocessor/facilities.hpp +++ b/include/boost/preprocessor/facilities.hpp @@ -14,6 +14,7 @@ # define BOOST_PREPROCESSOR_FACILITIES_HPP # # include +# include # include # include # include diff --git a/include/boost/preprocessor/facilities/check_empty.hpp b/include/boost/preprocessor/facilities/check_empty.hpp new file mode 100644 index 0000000..4ffe169 --- /dev/null +++ b/include/boost/preprocessor/facilities/check_empty.hpp @@ -0,0 +1,19 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Edward Diener 2019. +# * 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_FACILITIES_CHECK_EMPTY_HPP +# define BOOST_PREPROCESSOR_FACILITIES_CHECK_EMPTY_HPP +# include +# if BOOST_PP_VARIADIC_OPT() +# include +# define BOOST_PP_CHECK_EMPTY(...) BOOST_PP_IS_EMPTY_OPT(__VA_ARGS__) +# endif /* BOOST_PP_VARIADIC_OPT() */ +# endif /* BOOST_PREPROCESSOR_FACILITIES_CHECK_EMPTY_HPP */ diff --git a/test/checkempty.cpp b/test/checkempty.cpp new file mode 100644 index 0000000..6306708 --- /dev/null +++ b/test/checkempty.cpp @@ -0,0 +1,12 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Edward Diener 2019. +# * 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. */ +# +# include diff --git a/test/checkempty.cxx b/test/checkempty.cxx new file mode 100644 index 0000000..04ce245 --- /dev/null +++ b/test/checkempty.cxx @@ -0,0 +1,61 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Edward Diener 2019. +# * 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. */ +# +# include +# include + +# if BOOST_PP_VARIADIC_OPT() + +# include + +#define DATA +#define OBJECT OBJECT2 +#define OBJECT2 +#define FUNC(x) FUNC2(x) +#define FUNC2(x) +#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 +#define FUNC_GEN8(x,y) (1,2,3) +#define FUNC_GEN9(x,y,z) anything +#define FUNC_GEN10(x) (y) data +#define NAME &name +#define ATUPLE (atuple) +#define ATUPLE_PLUS (atuple) data + +BEGIN BOOST_PP_CHECK_EMPTY(FUNC_GEN) == 0 END +BEGIN BOOST_PP_CHECK_EMPTY(FUNC_GEN2) == 0 END +BEGIN BOOST_PP_CHECK_EMPTY(FUNC_GEN3) == 0 END +BEGIN BOOST_PP_CHECK_EMPTY(FUNC_GEN4) == 0 END +BEGIN BOOST_PP_CHECK_EMPTY(FUNC_GEN5) == 0 END +BEGIN BOOST_PP_CHECK_EMPTY(FUNC_GEN8) == 0 END +BEGIN BOOST_PP_CHECK_EMPTY(FUNC_GEN9) == 0 END +BEGIN BOOST_PP_CHECK_EMPTY(FUNC_GEN10) == 0 END +BEGIN BOOST_PP_CHECK_EMPTY(BOOST_PP_EMPTY()) == 1 END +BEGIN BOOST_PP_CHECK_EMPTY(DATA BOOST_PP_EMPTY()) == 1 END +BEGIN BOOST_PP_CHECK_EMPTY(x BOOST_PP_EMPTY()) == 0 END +BEGIN BOOST_PP_CHECK_EMPTY(OBJECT BOOST_PP_EMPTY()) == 1 END +BEGIN BOOST_PP_CHECK_EMPTY(FUNC(z) BOOST_PP_EMPTY()) == 1 END +BEGIN BOOST_PP_CHECK_EMPTY(FUNC_GEN6) == 0 END +BEGIN BOOST_PP_CHECK_EMPTY(FUNC_GEN7) == 0 END +BEGIN BOOST_PP_CHECK_EMPTY(NAME) == 0 END +BEGIN BOOST_PP_CHECK_EMPTY(ATUPLE) == 0 END +BEGIN BOOST_PP_CHECK_EMPTY(ATUPLE_PLUS) == 0 END + +# else + +BEGIN 1 == 1 END + +# endif