deduced.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Copyright Daniel Wallin 2006.
  2. // Copyright Cromwell D. Enage 2017.
  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. #ifndef BOOST_DEDUCED_060920_HPP
  7. #define BOOST_DEDUCED_060920_HPP
  8. #include <boost/parameter/config.hpp>
  9. #include "basics.hpp"
  10. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  11. #include <boost/mp11/map.hpp>
  12. #include <boost/mp11/algorithm.hpp>
  13. #else
  14. #include <boost/mpl/bool.hpp>
  15. #include <boost/mpl/if.hpp>
  16. #include <boost/mpl/for_each.hpp>
  17. #include <boost/mpl/assert.hpp>
  18. #include <boost/type_traits/is_same.hpp>
  19. #endif
  20. namespace test {
  21. struct not_present_tag
  22. {
  23. };
  24. not_present_tag not_present;
  25. template <typename E, typename ArgPack>
  26. class assert_expected
  27. {
  28. E const& _expected;
  29. ArgPack const& _args;
  30. public:
  31. assert_expected(E const& e, ArgPack const& args_)
  32. : _expected(e), _args(args_)
  33. {
  34. }
  35. template <typename T>
  36. static bool check_not_present(T const&)
  37. {
  38. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  39. static_assert(
  40. std::is_same<T,test::not_present_tag>::value
  41. , "T == test::not_present_tag"
  42. );
  43. #else
  44. BOOST_MPL_ASSERT((
  45. typename boost::mpl::if_<
  46. boost::is_same<T,test::not_present_tag>
  47. , boost::mpl::true_
  48. , boost::mpl::false_
  49. >::type
  50. ));
  51. #endif
  52. return true;
  53. }
  54. template <typename K>
  55. bool check1(K const& k, test::not_present_tag const& t, long) const
  56. {
  57. return assert_expected<E,ArgPack>::check_not_present(
  58. this->_args[k | t]
  59. );
  60. }
  61. template <typename K, typename Expected>
  62. bool check1(K const& k, Expected const& e, int) const
  63. {
  64. return test::equal(this->_args[k], e);
  65. }
  66. template <typename K>
  67. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  68. void operator()(K&&) const
  69. #else
  70. void operator()(K) const
  71. #endif
  72. {
  73. boost::parameter::keyword<K> const&
  74. k = boost::parameter::keyword<K>::instance;
  75. BOOST_TEST(this->check1(k, this->_expected[k], 0L));
  76. }
  77. };
  78. template <typename E, typename A>
  79. void check0(E const& e, A const& args)
  80. {
  81. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  82. boost::mp11::mp_for_each<boost::mp11::mp_map_keys<E> >(
  83. test::assert_expected<E,A>(e, args)
  84. );
  85. #else
  86. boost::mpl::for_each<E>(test::assert_expected<E,A>(e, args));
  87. #endif
  88. }
  89. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  90. template <typename P, typename E, typename ...Args>
  91. void check(E const& e, Args const&... args)
  92. {
  93. test::check0(e, P()(args...));
  94. }
  95. #else
  96. template <typename P, typename E, typename A0>
  97. void check(E const& e, A0 const& a0)
  98. {
  99. test::check0(e, P()(a0));
  100. }
  101. template <typename P, typename E, typename A0, typename A1>
  102. void check(E const& e, A0 const& a0, A1 const& a1)
  103. {
  104. test::check0(e, P()(a0, a1));
  105. }
  106. template <typename P, typename E, typename A0, typename A1, typename A2>
  107. void check(E const& e, A0 const& a0, A1 const& a1, A2 const& a2)
  108. {
  109. test::check0(e, P()(a0, a1, a2));
  110. }
  111. #endif // BOOST_PARAMETER_HAS_PERFECT_FORWARDING
  112. } // namespace test
  113. #endif // include guard