test_is_empty.cxx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #include <boost/vmd/is_empty.hpp>
  6. #include <boost/preprocessor/facilities/empty.hpp>
  7. #include <boost/preprocessor/variadic/has_opt.hpp>
  8. #include <boost/detail/lightweight_test.hpp>
  9. int main()
  10. {
  11. #if BOOST_PP_VARIADICS
  12. #define DATA
  13. #define OBJECT OBJECT2
  14. #define OBJECT2
  15. #define FUNC(x) FUNC2(x)
  16. #define FUNC2(x)
  17. BOOST_TEST(BOOST_VMD_IS_EMPTY(BOOST_PP_EMPTY()));
  18. BOOST_TEST(BOOST_VMD_IS_EMPTY(DATA BOOST_PP_EMPTY()));
  19. BOOST_TEST(!BOOST_VMD_IS_EMPTY(x BOOST_PP_EMPTY()));
  20. BOOST_TEST(BOOST_VMD_IS_EMPTY(OBJECT BOOST_PP_EMPTY()));
  21. BOOST_TEST(BOOST_VMD_IS_EMPTY(FUNC(z) BOOST_PP_EMPTY()));
  22. #define FUNC_GEN() ()
  23. #define FUNC_GEN2(x) ()
  24. #define FUNC_GEN3() anything
  25. #define FUNC_GEN4(x) anything
  26. #if BOOST_PP_VARIADIC_HAS_OPT()
  27. #define FUNC_GEN5(x,y) ()
  28. #define FUNC_GEN6(x,y) anything
  29. #define FUNC_GEN7() (y,z)
  30. #define FUNC_GEN5A() (&)
  31. #define FUNC_GEN6A(x) (y)
  32. #define FUNC_GEN7A() (y,z)
  33. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN));
  34. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN2));
  35. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN5));
  36. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN6));
  37. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN7));
  38. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN5A));
  39. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN6A));
  40. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN7A));
  41. #elif BOOST_VMD_MSVC
  42. #define FUNC_GEN5(x,y) ()
  43. #define FUNC_GEN6(x,y) anything
  44. /* This shows that VC++ does not work correctly in these cases. */
  45. BOOST_TEST(BOOST_VMD_IS_EMPTY(FUNC_GEN)); /* This produces the wrong result */
  46. BOOST_TEST(BOOST_VMD_IS_EMPTY(FUNC_GEN2)); /* This produces the wrong result */
  47. BOOST_TEST(BOOST_VMD_IS_EMPTY(FUNC_GEN5)); /* This should produce a compiler error but does not and produces the incorrect result */
  48. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN6)); /* This should produce a compiler error but does not */
  49. #else
  50. #define FUNC_GEN5() (&)
  51. #define FUNC_GEN6(x) (y)
  52. #define FUNC_GEN7() (y,z)
  53. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN));
  54. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN2));
  55. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN5));
  56. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN6));
  57. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN7));
  58. #endif /* BOOST_VMD_MSVC */
  59. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN3));
  60. BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN4));
  61. #else
  62. BOOST_ERROR("No variadic macro support");
  63. #endif /* BOOST_PP_VARIADICS */
  64. return boost::report_errors();
  65. }