normalized_argument_types.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // Copyright Daniel Wallin 2006.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/parameter/config.hpp>
  6. #if (BOOST_PARAMETER_MAX_ARITY < 2)
  7. #error Define BOOST_PARAMETER_MAX_ARITY as 2 or greater.
  8. #endif
  9. #if !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) && \
  10. (BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY < 3)
  11. #error Define BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY \
  12. as 3 or greater.
  13. #endif
  14. namespace test {
  15. struct count_instances
  16. {
  17. count_instances()
  18. {
  19. ++count_instances::count;
  20. }
  21. count_instances(count_instances const&)
  22. {
  23. ++count_instances::count;
  24. }
  25. template <typename T>
  26. count_instances(T const&)
  27. {
  28. ++count_instances::count;
  29. }
  30. ~count_instances()
  31. {
  32. --count_instances::count;
  33. }
  34. static std::size_t count;
  35. void noop() const
  36. {
  37. }
  38. };
  39. std::size_t count_instances::count = 0;
  40. } // namespace test
  41. #include <boost/parameter/name.hpp>
  42. namespace test {
  43. BOOST_PARAMETER_NAME(x)
  44. BOOST_PARAMETER_NAME(y)
  45. } // namespace test
  46. #include <boost/parameter/preprocessor.hpp>
  47. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  48. #include <type_traits>
  49. #else
  50. #include <boost/mpl/bool.hpp>
  51. #include <boost/mpl/if.hpp>
  52. #include <boost/mpl/assert.hpp>
  53. #include <boost/type_traits/is_convertible.hpp>
  54. #endif
  55. namespace test {
  56. BOOST_PARAMETER_FUNCTION((int), f, tag,
  57. (required
  58. (x, (long))
  59. )
  60. (optional
  61. (y, (long), 2L)
  62. )
  63. )
  64. {
  65. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  66. static_assert(
  67. std::is_convertible<x_type,long>::value
  68. , "is_convertible<x_type,long>"
  69. );
  70. static_assert(
  71. std::is_convertible<y_type,long>::value
  72. , "is_convertible<y_type,long>"
  73. );
  74. #else
  75. BOOST_MPL_ASSERT((
  76. typename boost::mpl::if_<
  77. boost::is_convertible<x_type,long>
  78. , boost::mpl::true_
  79. , boost::mpl::false_
  80. >::type
  81. ));
  82. BOOST_MPL_ASSERT((
  83. typename boost::mpl::if_<
  84. boost::is_convertible<y_type,long>
  85. , boost::mpl::true_
  86. , boost::mpl::false_
  87. >::type
  88. ));
  89. #endif // BOOST_PARAMETER_CAN_USE_MP11
  90. return 0;
  91. }
  92. } // namespace test
  93. #include <boost/core/lightweight_test.hpp>
  94. namespace test {
  95. BOOST_PARAMETER_FUNCTION((int), g, tag,
  96. (required
  97. (x, (test::count_instances))
  98. )
  99. )
  100. {
  101. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  102. static_assert(
  103. std::is_convertible<x_type,test::count_instances>::value
  104. , "is_convertible<x_type,test::count_instances>"
  105. );
  106. #else
  107. BOOST_MPL_ASSERT((
  108. typename boost::mpl::if_<
  109. boost::is_convertible<x_type,test::count_instances>
  110. , boost::mpl::true_
  111. , boost::mpl::false_
  112. >::type
  113. ));
  114. #endif
  115. x.noop();
  116. #if !BOOST_WORKAROUND(BOOST_GCC, < 40000)
  117. BOOST_TEST_LT(0, test::count_instances::count);
  118. #endif
  119. return 0;
  120. }
  121. BOOST_PARAMETER_FUNCTION((int), h, tag,
  122. (required
  123. (x, (test::count_instances const&))
  124. )
  125. )
  126. {
  127. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  128. static_assert(
  129. std::is_convertible<x_type,test::count_instances const>::value
  130. , "is_convertible<x_type,test::count_instances const>"
  131. );
  132. #else
  133. BOOST_MPL_ASSERT((
  134. typename boost::mpl::if_<
  135. boost::is_convertible<x_type,test::count_instances const>
  136. , boost::mpl::true_
  137. , boost::mpl::false_
  138. >::type
  139. ));
  140. #endif
  141. x.noop();
  142. #if !BOOST_WORKAROUND(BOOST_GCC, < 40000)
  143. BOOST_TEST_EQ(1, test::count_instances::count);
  144. #endif
  145. return 0;
  146. }
  147. } // namespace test
  148. int main()
  149. {
  150. test::f(1, 2);
  151. test::f(1., 2.f);
  152. test::f(1U);
  153. test::g(0);
  154. test::h(0);
  155. return boost::report_errors();
  156. }