On 10/10/2019 5:17 AM, Edward Diener via Boost wrote:
The C++20 preprocessor construct __VA_OPT__ has the additional affect of providing the ability to write a general purpose macro for testing emptiness, ie. no preprocessor tokens, in C++ macro programming that is 100% reliable for any preprocessor data passed to it. Previously such a macro testing for emptiness always had some corner cases where the test might fail with a preprocessor error, but in C++20 mode at least the test can now be completely reliable in all cases.
So I have added two macros along with documentation, as well as a topic discussing emptiness, to the Boost PP library. The first macro is called BOOST_PP_VARIADIC_OPT, invoked with no parameters as BOOST_PP_VARIADIC_OPT(), which expands to 1 if the compiler is in C++20 mode, supports variadic macros, and supports the C++ 20 __VA_OPT__ construct, and otherwise expands to 0. The second macro, which only exists if BOOST_PP_VARIADIC_OPT() expands to 1, is called BOOST_PP_CHECK_EMPTY. This second macro is a variadic macro which takes a single parameter of variadic data, and expands to 1 if the data is empty or expands to being empty, while otherwise expanding to 0 if the data is not empty.
I have changed the name of the first macro from BOOST_PP_VARIADIC_OPT to BOOST_PP_VARIADIC_HAS_OPT on the 'develop' branch and will update the change in the 'master' branch once 'develop' tests recycle. The new name is more descriptive. Also since I am working on a macro called BOOST_PP_VA_OPT, which will be a Boost PP alternative to the C++20 __VA_OPT__ construct, I did not want to cause confusion in the macro names.
Furthermore in the Boost VMD library I have updated the BOOST_VMD_IS_EMPTY macro to essentially invoke the BOOST_PP_CHECK_EMPTY macro when BOOST_PP_VARIADIC_OPT() expands to 1, while retaining the current processing when that is not the case. As well I have updated the VMD discussion of emptiness in the documentation of Boost VMD to include information about the ability to provide a 100% reliable test for emptiness in C++20.
Neither change in Boost PP or Boost VMD should affect any end-user or Boost library in any way. There are tests for all these changes and all tests have passed. I will update the release notes for Boost PP and Boost VMD for the next release of Boost with this information.
As always any comments, questions, or criticism of these changes are always welcome.