deduced.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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/parameters.hpp>
  6. #include <boost/parameter/name.hpp>
  7. #include <boost/parameter/binding.hpp>
  8. #include <boost/parameter/config.hpp>
  9. #include "deduced.hpp"
  10. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  11. #include <type_traits>
  12. #else
  13. #include <boost/mpl/bool.hpp>
  14. #include <boost/mpl/if.hpp>
  15. #include <boost/type_traits/is_convertible.hpp>
  16. #endif
  17. #if defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE)
  18. #include <boost/parameter/aux_/preprocessor/nullptr.hpp>
  19. #endif
  20. namespace test {
  21. BOOST_PARAMETER_NAME(x)
  22. BOOST_PARAMETER_NAME(y)
  23. BOOST_PARAMETER_NAME(z)
  24. template <typename To>
  25. struct predicate
  26. {
  27. template <typename From, typename Args>
  28. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  29. using fn = std::is_convertible<From,To>;
  30. #else
  31. struct apply
  32. : boost::mpl::if_<
  33. boost::is_convertible<From,To>
  34. , boost::mpl::true_
  35. , boost::mpl::false_
  36. >
  37. {
  38. };
  39. #endif
  40. };
  41. } // namespace test
  42. #include <boost/core/lightweight_test.hpp>
  43. #include <string>
  44. int main()
  45. {
  46. test::check<
  47. boost::parameter::parameters<test::tag::x,test::tag::y>
  48. >((test::_x = 0, test::_y = 1), 0, 1);
  49. test::check<
  50. boost::parameter::parameters<
  51. test::tag::x
  52. , boost::parameter::required<
  53. boost::parameter::deduced<test::tag::y>
  54. , test::predicate<int>
  55. >
  56. , boost::parameter::optional<
  57. boost::parameter::deduced<test::tag::z>
  58. , test::predicate<std::string>
  59. >
  60. >
  61. >(
  62. (
  63. test::_x = 0
  64. , test::_y = test::not_present
  65. , test::_z = std::string("foo")
  66. )
  67. , test::_x = 0
  68. , std::string("foo")
  69. );
  70. test::check<
  71. boost::parameter::parameters<
  72. test::tag::x
  73. , boost::parameter::required<
  74. boost::parameter::deduced<test::tag::y>
  75. , test::predicate<int>
  76. >
  77. , boost::parameter::optional<
  78. boost::parameter::deduced<test::tag::z>
  79. , test::predicate<std::string>
  80. >
  81. >
  82. >(
  83. (test::_x = 0, test::_y = 1, test::_z = std::string("foo"))
  84. , 0
  85. , std::string("foo")
  86. , 1
  87. );
  88. test::check<
  89. boost::parameter::parameters<
  90. test::tag::x
  91. , boost::parameter::required<
  92. boost::parameter::deduced<test::tag::y>
  93. , test::predicate<int>
  94. >
  95. , boost::parameter::optional<
  96. boost::parameter::deduced<test::tag::z>
  97. , test::predicate<std::string>
  98. >
  99. >
  100. >(
  101. (test::_x = 0, test::_y = 1, test::_z = std::string("foo"))
  102. , 0
  103. , 1
  104. , std::string("foo")
  105. );
  106. test::check<
  107. boost::parameter::parameters<
  108. test::tag::x
  109. , boost::parameter::required<
  110. boost::parameter::deduced<test::tag::y>
  111. , test::predicate<int>
  112. >
  113. , boost::parameter::optional<
  114. boost::parameter::deduced<test::tag::z>
  115. , test::predicate<std::string>
  116. >
  117. >
  118. >(
  119. (test::_x = 0, test::_y = 1, test::_z = std::string("foo"))
  120. , 0
  121. , test::_y = 1
  122. , std::string("foo")
  123. );
  124. test::check<
  125. boost::parameter::parameters<
  126. test::tag::x
  127. , boost::parameter::required<
  128. boost::parameter::deduced<test::tag::y>
  129. , test::predicate<int>
  130. >
  131. , boost::parameter::optional<
  132. boost::parameter::deduced<test::tag::z>
  133. , test::predicate<std::string>
  134. >
  135. >
  136. >(
  137. (test::_x = 0, test::_y = 1, test::_z = std::string("foo"))
  138. , test::_z = std::string("foo")
  139. , test::_x = 0
  140. , 1
  141. );
  142. #if defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE)
  143. // Fails because boost::parameter::aux::make_arg_list<> evaluates
  144. // boost::parameter::aux::is_named_argument<> to boost::mpl::false_
  145. // for static_cast<long*>(BOOST_PARAMETER_AUX_PP_NULLPTR).
  146. test::check<
  147. boost::parameter::parameters<
  148. test::tag::x
  149. , boost::parameter::required<
  150. boost::parameter::deduced<test::tag::y>
  151. , test::predicate<int>
  152. >
  153. , boost::parameter::optional<
  154. boost::parameter::deduced<test::tag::z>
  155. , test::predicate<std::string>
  156. >
  157. >
  158. >(
  159. (test::_x = 0, test::_y = 1, test::_z = std::string("foo"))
  160. , test::_x = 0
  161. , static_cast<long*>(BOOST_PARAMETER_AUX_PP_NULLPTR)
  162. , 1
  163. );
  164. #endif
  165. return boost::report_errors();
  166. }