basics.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright David Abrahams, Daniel Wallin 2005.
  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 BASICS_050424_HPP
  7. #define BASICS_050424_HPP
  8. #include <boost/parameter.hpp>
  9. #if (BOOST_PARAMETER_MAX_ARITY < 4)
  10. #error Define BOOST_PARAMETER_MAX_ARITY as 4 or greater.
  11. #endif
  12. #if !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) && \
  13. (BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY < 5)
  14. #error Define BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY \
  15. as 5 or greater.
  16. #endif
  17. #if !defined(BOOST_PARAMETER_CAN_USE_MP11)
  18. #include <boost/mpl/bool.hpp>
  19. #include <boost/mpl/if.hpp>
  20. #include <boost/mpl/assert.hpp>
  21. #include <boost/type_traits/is_same.hpp>
  22. #endif
  23. #include <boost/core/lightweight_test.hpp>
  24. namespace test {
  25. BOOST_PARAMETER_NAME(name)
  26. BOOST_PARAMETER_NAME(value)
  27. BOOST_PARAMETER_NAME(index)
  28. BOOST_PARAMETER_NAME(tester)
  29. struct f_parameters // vc6 is happier with inheritance than with a typedef
  30. : boost::parameter::parameters<
  31. test::tag::tester
  32. , test::tag::name
  33. , test::tag::value
  34. , test::tag::index
  35. >
  36. {
  37. };
  38. inline double value_default()
  39. {
  40. return 666.222;
  41. }
  42. template <typename T>
  43. inline bool equal(T const& x, T const& y)
  44. {
  45. return x == y;
  46. }
  47. template <typename Name, typename Value, typename Index>
  48. struct values_t
  49. {
  50. values_t(Name const& n_, Value const& v_, Index const& i_)
  51. : n(n_), v(v_), i(i_)
  52. {
  53. }
  54. template <typename Name_, typename Value_, typename Index_>
  55. void
  56. operator()(
  57. Name_ const& n_
  58. , Value_ const& v_
  59. , Index_ const& i_
  60. ) const
  61. {
  62. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  63. static_assert(
  64. std::is_same<Index,Index_>::value
  65. , "Index == Index_"
  66. );
  67. static_assert(
  68. std::is_same<Value,Value_>::value
  69. , "Value == Value_"
  70. );
  71. static_assert(
  72. std::is_same<Name,Name_>::value
  73. , "Name == Name_"
  74. );
  75. #else // !defined(BOOST_PARAMETER_CAN_USE_MP11)
  76. BOOST_MPL_ASSERT((
  77. typename boost::mpl::if_<
  78. boost::is_same<Index,Index_>
  79. , boost::mpl::true_
  80. , boost::mpl::false_
  81. >::type
  82. ));
  83. BOOST_MPL_ASSERT((
  84. typename boost::mpl::if_<
  85. boost::is_same<Value,Value_>
  86. , boost::mpl::true_
  87. , boost::mpl::false_
  88. >::type
  89. ));
  90. BOOST_MPL_ASSERT((
  91. typename boost::mpl::if_<
  92. boost::is_same<Name,Name_>
  93. , boost::mpl::true_
  94. , boost::mpl::false_
  95. >::type
  96. ));
  97. #endif // BOOST_PARAMETER_CAN_USE_MP11
  98. BOOST_TEST(test::equal(n, n_));
  99. BOOST_TEST(test::equal(v, v_));
  100. BOOST_TEST(test::equal(i, i_));
  101. }
  102. Name const& n;
  103. Value const& v;
  104. Index const& i;
  105. };
  106. template <typename Name, typename Value, typename Index>
  107. inline test::values_t<Name,Value,Index>
  108. values(Name const& n, Value const& v, Index const& i)
  109. {
  110. return test::values_t<Name,Value,Index>(n, v, i);
  111. }
  112. } // namespace test
  113. #endif // include guard