From 88a0365f4de3d0bf894c7841b8293f7ff07ad8cf Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Sun, 6 Oct 2019 22:06:38 -0400 Subject: [PATCH 1/4] 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 From bda6ad91483096774dfe014eeaa54b11929f8513 Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Sun, 6 Oct 2019 22:20:19 -0400 Subject: [PATCH 2/4] Updated docs --- doc/headers.html | 1 + doc/ref.html | 1 + doc/ref/variadic_opt.html | 13 +++++++++++++ test/Jamfile.v2 | 1 + 4 files changed, 16 insertions(+) diff --git a/doc/headers.html b/doc/headers.html index 7df8cb0..b26fb96 100644 --- a/doc/headers.html +++ b/doc/headers.html @@ -80,6 +80,7 @@
  • facilities.hpp
  • facilities/
  • apply.hpp
  • +
  • check_empty.hpp
  • empty.hpp
  • expand.hpp
  • identity.hpp
  • diff --git a/doc/ref.html b/doc/ref.html index 749e881..e3f78b2 100644 --- a/doc/ref.html +++ b/doc/ref.html @@ -45,6 +45,7 @@
  • BOOL
  • CAT
  • +
  • CHECK_EMPTY
  • COMMA
  • COMMA_IF
  • COMPL
  • diff --git a/doc/ref/variadic_opt.html b/doc/ref/variadic_opt.html index d8c425a..7057cbc 100644 --- a/doc/ref/variadic_opt.html +++ b/doc/ref/variadic_opt.html @@ -16,6 +16,19 @@ Expands to 1 if the __VA_OPT__ construct is supported, otherwise expands to 0.
    None
    +

    Remarks

    +
    + This macro only returns 1 if the compiler is compiling at its own C++20 level and + __VA_OPT__ is supported. It is possible for a compiler to support the __VA_OPT__ + construct when not compiling at its own C++20 level, but this macro will return + 0 in that case even if __VA_OPT__ is normally supported for that level. The reason + for this is that such a compiler may have a compiler switch, enforcing a strict + adherence to a particular C++ standard level, which gives a warning or an error + if __VA_OPT__ is specified below the C++20 level, and the preprocessor library + wants to avoid that happening. Therefore the macro will only test to see whether + or not __VA_OPT__ is supported at the C++20 level, while otherwise always returning + 0 for all lesser C++ standard levels. +

    Requirements

    diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 51b6b1c..811e4e2 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -211,6 +211,7 @@ alias preprocessor_isempty : : alias preprocessor_isempty : [ compile isempty.cpp ] + [ compile checkempty.cpp ] [ compile-fail isempty_variadic_standard_failure.cpp : BOOST_PP_VARIADICS=1 ] [ compile-fail isempty_variadic_standard_failure2.cpp : BOOST_PP_VARIADICS=1 ] ; From ac99242b7169b26bf08ed26011d9758463a2e131 Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Tue, 8 Oct 2019 09:43:18 -0400 Subject: [PATCH 3/4] Add a topic on "emptiness" --- doc/topics.html | 1 + doc/topics/emptiness.html | 97 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 doc/topics/emptiness.html diff --git a/doc/topics.html b/doc/topics.html index 5826a58..cff091a 100644 --- a/doc/topics.html +++ b/doc/topics.html @@ -15,6 +15,7 @@
  • file iteration
  • evaluated slots
  • variadic macros
  • +
  • emptiness