singular.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // Copyright Daniel Wallin 2005.
  2. // Copyright Cromwell D. Enage 2019.
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. namespace test {
  7. struct default_src
  8. {
  9. typedef int result_type;
  10. int operator()() const
  11. {
  12. return 0;
  13. }
  14. };
  15. } // namespace test
  16. #include <boost/parameter/name.hpp>
  17. namespace test {
  18. BOOST_PARAMETER_NAME(x)
  19. BOOST_PARAMETER_NAME(y)
  20. BOOST_PARAMETER_NAME(z)
  21. } // namespace test
  22. #include <boost/parameter/is_argument_pack.hpp>
  23. #include <boost/parameter/config.hpp>
  24. #include <boost/mpl/has_key.hpp>
  25. #include <boost/mpl/assert.hpp>
  26. #include <boost/core/lightweight_test.hpp>
  27. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  28. #include <boost/mp11/map.hpp>
  29. #include <type_traits>
  30. #endif
  31. namespace test {
  32. template <typename ArgumentPack, typename K, typename T>
  33. void check0(ArgumentPack const& p, K const& kw, T const& value)
  34. {
  35. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  36. static_assert(
  37. !boost::mp11::mp_map_contains<ArgumentPack,test::tag::z>::value
  38. , "test::tag::z must not be in ArgumentPack"
  39. );
  40. static_assert(
  41. std::is_same<
  42. boost::mp11::mp_map_find<ArgumentPack,test::tag::z>
  43. , void
  44. >::value
  45. , "test::tag::z must not be found in ArgumentPack"
  46. );
  47. #endif // BOOST_PARAMETER_CAN_USE_MP11
  48. BOOST_MPL_ASSERT((boost::parameter::is_argument_pack<ArgumentPack>));
  49. BOOST_MPL_ASSERT_NOT((
  50. boost::mpl::has_key<ArgumentPack,test::tag::z>
  51. ));
  52. BOOST_TEST_EQ(p[kw], value);
  53. }
  54. } // namespace test
  55. #include <boost/mpl/void.hpp>
  56. #include <boost/mpl/bool.hpp>
  57. #include <boost/mpl/int.hpp>
  58. #include <boost/mpl/if.hpp>
  59. #include <boost/mpl/key_type.hpp>
  60. #include <boost/mpl/order.hpp>
  61. #include <boost/mpl/count.hpp>
  62. #include <boost/mpl/equal_to.hpp>
  63. #include <boost/type_traits/is_same.hpp>
  64. namespace test {
  65. template <typename ArgumentPack, typename K, typename T>
  66. void check1(ArgumentPack const& p, K const& kw, T const& value)
  67. {
  68. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  69. static_assert(
  70. boost::mp11::mp_map_contains<ArgumentPack,typename K::tag>::value
  71. , "typename K::tag must be in ArgumentPack"
  72. );
  73. static_assert(
  74. !boost::mp11::mp_map_contains<ArgumentPack,test::tag::z>::value
  75. , "test::tag::z must not be in ArgumentPack"
  76. );
  77. static_assert(
  78. !std::is_same<
  79. boost::mp11::mp_map_find<ArgumentPack,typename K::tag>
  80. , void
  81. >::value
  82. , "typename K::tag must be found in ArgumentPack"
  83. );
  84. static_assert(
  85. std::is_same<
  86. boost::mp11::mp_map_find<ArgumentPack,test::tag::z>
  87. , void
  88. >::value
  89. , "test::tag::z must not be found in ArgumentPack"
  90. );
  91. #endif // BOOST_PARAMETER_CAN_USE_MP11
  92. BOOST_MPL_ASSERT((boost::parameter::is_argument_pack<ArgumentPack>));
  93. BOOST_MPL_ASSERT((boost::mpl::has_key<ArgumentPack,typename K::tag>));
  94. BOOST_MPL_ASSERT_NOT((
  95. boost::mpl::has_key<ArgumentPack,test::tag::z>
  96. ));
  97. BOOST_MPL_ASSERT((
  98. boost::mpl::equal_to<
  99. typename boost::mpl::count<ArgumentPack,typename K::tag>::type
  100. , boost::mpl::int_<1>
  101. >
  102. ));
  103. BOOST_MPL_ASSERT((
  104. typename boost::mpl::if_<
  105. boost::is_same<
  106. typename boost::mpl
  107. ::key_type<ArgumentPack,typename K::tag>::type
  108. , typename K::tag
  109. >
  110. , boost::mpl::true_
  111. , boost::mpl::false_
  112. >::type
  113. ));
  114. BOOST_MPL_ASSERT((
  115. typename boost::mpl::if_<
  116. boost::is_same<
  117. typename boost::mpl
  118. ::order<ArgumentPack,typename K::tag>::type
  119. , boost::mpl::void_
  120. >
  121. , boost::mpl::false_
  122. , boost::mpl::true_
  123. >::type
  124. ));
  125. BOOST_TEST_EQ(p[kw], value);
  126. }
  127. } // namespace test
  128. int main()
  129. {
  130. test::check1(test::_x = 20, test::_x, 20);
  131. test::check1(test::_y = 20, test::_y, 20);
  132. test::check0(test::_x = 20, test::_x | 0, 20);
  133. test::check0(test::_y = 20, test::_y | 0, 20);
  134. test::check0(test::_x = 20, test::_x || test::default_src(), 20);
  135. test::check0(test::_y = 20, test::_y || test::default_src(), 20);
  136. test::check0(test::_y = 20, test::_x | 0, 0);
  137. test::check0(test::_y = 20, test::_x || test::default_src(), 0);
  138. return boost::report_errors();
  139. }