Added the BOOST_PP_CHECK_EMPTY macro and documentation.

This commit is contained in:
Edward Diener
2019-10-06 22:06:38 -04:00
parent af70b2872e
commit 88a0365f4d
6 changed files with 190 additions and 0 deletions

View File

@ -0,0 +1,29 @@
<html>
<head>
<title>facilities/check_empty.hpp</title>
<link rel="stylesheet" type="text/css" href="../../styles.css">
</head>
<body>
<div style="margin-left: 0px;">
The <b>facilities/check_empty.hpp</b> header defines a variadic macro for the C++20 level that checks if its data is empty or not.
</div>
<h4>Usage</h4>
<div class="code">
#include <b>&lt;boost/preprocessor/facilities/check_empty.hpp&gt;</b>
</div>
<h4>Contents</h4>
<ul>
<li><a href="../../ref/check_empty.html">BOOST_PP_CHECK_EMPTY</a></li>
</ul>
<hr size="1">
<div style="margin-left: 0px;">
<i></i><i><EFBFBD> Copyright Edward Diener 2019</i>
</div>
<div style="margin-left: 0px;">
<p><small>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
copy at <a href=
"http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
</div>
</body>
</html>

68
doc/ref/check_empty.html Normal file
View File

@ -0,0 +1,68 @@
<html>
<head>
<title>BOOST_PP_CHECK_EMPTY</title>
<link rel="stylesheet" type="text/css" href="../styles.css">
</head>
<body>
<div style="margin-left: 0px;"> The <b>BOOST_PP_CHECK_EMPTY</b> 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.</div>
<h4>Usage</h4>
<div class="code"> <b>BOOST_PP_CHECK_EMPTY</b>(<i>...</i>) <a href="../topics/variadic_macros.html#VNotation" target="_self"><sup>(v)</sup></a><br>
</div>
<h4>Arguments</h4>
<dl>
<dt>...<br>
</dt>
<dd> The <i>variadic data</i> to be checked for emptiness. </dd>
</dl>
<h4>Remarks</h4>
<div>
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.<br>
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.
</div>
<h4>See Also</h4>
<ul>
<li><a href="variadic_opt.html">BOOST_PP_VARIADIC_OPT</a></li>
</ul>
<h4>Requirements</h4>
<div> <b>Header:</b> &nbsp;<a href="../headers/facilities/check_empty.html">&lt;boost/preprocessor/facilities/check_empty.hpp&gt;</a>
</div>
<h4>Sample Code</h4>
<div>
<pre>
#include &lt;<a href="../headers/facilities/check_empty.html">boost/preprocessor/facilities/check_empty.hpp</a>&gt;
# if <a href="variadic_opt.html">BOOST_PP_VARIADIC_OPT</a>()
#define DATA
#define OBJECT OBJECT2
#define OBJECT2
#define FUNC(x) FUNC2(x)
#define FUNC2(x)
#define FUNC_GEN(x,y) (1,2,3)
<a href="check_empty.html">BOOST_PP_CHECK_EMPTY</a>(DATA) // expands to 1
<a href="check_empty.html">BOOST_PP_CHECK_EMPTY</a>(OBJECT) // expands to 1
<a href="check_empty.html">BOOST_PP_CHECK_EMPTY</a>(FUNC(1)) // expands to 1
<a href="check_empty.html">BOOST_PP_CHECK_EMPTY</a>(FUNC) // expands to 0
<a href="check_empty.html">BOOST_PP_CHECK_EMPTY</a>(FUNC_GEN) // expands to 0
#endif
</pre>
</div>
<hr size="1">
<div style="margin-left: 0px;"> <i></i><i><EFBFBD> Copyright Edward Diener 2019</i> </div>
<div style="margin-left: 0px;">
<p><small>Distributed under the Boost Software License, Version 1.0.
(See accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
</div>
</body>
</html>

View File

@ -14,6 +14,7 @@
# define BOOST_PREPROCESSOR_FACILITIES_HPP
#
# include <boost/preprocessor/facilities/apply.hpp>
# include <boost/preprocessor/facilities/check_empty.hpp>
# include <boost/preprocessor/facilities/empty.hpp>
# include <boost/preprocessor/facilities/expand.hpp>
# include <boost/preprocessor/facilities/identity.hpp>

View File

@ -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 <boost/preprocessor/variadic/opt.hpp>
# if BOOST_PP_VARIADIC_OPT()
# include <boost/preprocessor/facilities/is_empty_variadic.hpp>
# define BOOST_PP_CHECK_EMPTY(...) BOOST_PP_IS_EMPTY_OPT(__VA_ARGS__)
# endif /* BOOST_PP_VARIADIC_OPT() */
# endif /* BOOST_PREPROCESSOR_FACILITIES_CHECK_EMPTY_HPP */

12
test/checkempty.cpp Normal file
View File

@ -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 <libs/preprocessor/test/checkempty.cxx>

61
test/checkempty.cxx Normal file
View File

@ -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 <libs/preprocessor/test/test.h>
# include <boost/preprocessor/facilities/check_empty.hpp>
# if BOOST_PP_VARIADIC_OPT()
# include <boost/preprocessor/facilities/empty.hpp>
#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