is_empty.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // (C) Copyright Edward Diener 2011-2015,2019
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt).
  5. #if !defined(BOOST_VMD_IS_EMPTY_HPP)
  6. #define BOOST_VMD_IS_EMPTY_HPP
  7. #include <boost/vmd/detail/setup.hpp>
  8. #if BOOST_PP_VARIADICS
  9. #include <boost/preprocessor/punctuation/is_begin_parens.hpp>
  10. #include <boost/vmd/detail/is_empty.hpp>
  11. /*
  12. The succeeding comments in this file are in doxygen format.
  13. */
  14. /** \file
  15. */
  16. /** \def BOOST_VMD_IS_EMPTY(...)
  17. \brief Tests whether its input is empty or not.
  18. The macro checks to see if the input is empty or not.
  19. It returns 1 if the input is empty, else returns 0.
  20. The macro is a variadic macro taking any input.
  21. For the VC++8 compiler (VS2005) the macro takes a single parameter of input to check.
  22. For all levels of C++ prior to C++20 the macro is not perfect,
  23. and can not be so. The problem area is if the input to be
  24. checked is a function-like macro name, in which case either
  25. a compiler error can result or a false result can occur.
  26. For C++20, with its support for the new __VA_OPT__ preprocessor
  27. construct, the macro will always work correctly no matter what
  28. the variadic input, and is therefore 100% reliable.
  29. This macro is a replacement, using variadic macro support,
  30. for the undocumented macro BOOST_PP_IS_EMPTY in the Boost
  31. PP library. The code is taken from a posting by Paul Mensonides
  32. of a variadic version for BOOST_PP_IS_EMPTY, and changed
  33. in order to also support VC++. The code for the C++20
  34. implementation of the macro, using the __VA_OPT__ preprocessor
  35. construct, is the author's own and reuses code added to the
  36. Boost preprocessor library by this author.
  37. ... = variadic input, for VC++8 this must be a single parameter
  38. returns = 1 if the input is empty, 0 if it is not
  39. It is recommended to append BOOST_PP_EMPTY() to whatever input
  40. is being tested in order to avoid possible warning messages
  41. from some compilers about no parameters being passed to the macro
  42. when the input is truly empty.
  43. */
  44. #if BOOST_VMD_MSVC_V8
  45. #define BOOST_VMD_IS_EMPTY(sequence) \
  46. BOOST_VMD_DETAIL_IS_EMPTY_IIF \
  47. ( \
  48. BOOST_PP_IS_BEGIN_PARENS \
  49. ( \
  50. sequence \
  51. ) \
  52. ) \
  53. ( \
  54. BOOST_VMD_DETAIL_IS_EMPTY_GEN_ZERO, \
  55. BOOST_VMD_DETAIL_IS_EMPTY_PROCESS \
  56. ) \
  57. (sequence) \
  58. /**/
  59. #else
  60. # if defined(__cplusplus) && __cplusplus > 201703L
  61. #include <boost/preprocessor/variadic/has_opt.hpp>
  62. #include <boost/preprocessor/facilities/is_empty.hpp>
  63. #define BOOST_VMD_IS_EMPTY(...) \
  64. BOOST_VMD_DETAIL_IS_EMPTY_IIF \
  65. ( \
  66. BOOST_PP_VARIADIC_HAS_OPT() \
  67. ) \
  68. ( \
  69. BOOST_PP_IS_EMPTY_OPT, \
  70. BOOST_VMD_IS_EMPTY_NO_OPT \
  71. ) \
  72. (__VA_ARGS__) \
  73. /**/
  74. # else
  75. #define BOOST_VMD_IS_EMPTY(...) \
  76. BOOST_VMD_IS_EMPTY_NO_OPT(__VA_ARGS__) \
  77. /**/
  78. # endif
  79. #define BOOST_VMD_IS_EMPTY_NO_OPT(...) \
  80. BOOST_VMD_DETAIL_IS_EMPTY_IIF \
  81. ( \
  82. BOOST_PP_IS_BEGIN_PARENS \
  83. ( \
  84. __VA_ARGS__ \
  85. ) \
  86. ) \
  87. ( \
  88. BOOST_VMD_DETAIL_IS_EMPTY_GEN_ZERO, \
  89. BOOST_VMD_DETAIL_IS_EMPTY_PROCESS \
  90. ) \
  91. (__VA_ARGS__) \
  92. /**/
  93. #endif /* BOOST_VMD_MSVC_V8 */
  94. #endif /* BOOST_PP_VARIADICS */
  95. #endif /* BOOST_VMD_IS_EMPTY_HPP */