earwicker.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright David Abrahams, Daniel Wallin 2005.
  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 < 4)
  7. #error Define BOOST_PARAMETER_MAX_ARITY as 4 or greater.
  8. #endif
  9. #if !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) && \
  10. (BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY < 5)
  11. #error Define BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY \
  12. as 5 or greater.
  13. #endif
  14. #include <boost/parameter/name.hpp>
  15. namespace test {
  16. BOOST_PARAMETER_NAME(w)
  17. BOOST_PARAMETER_NAME(x)
  18. BOOST_PARAMETER_NAME(y)
  19. BOOST_PARAMETER_NAME(z)
  20. } // namespace test
  21. #if !defined(BOOST_PARAMETER_CAN_USE_MP11)
  22. #include <boost/mpl/bool.hpp>
  23. #include <boost/mpl/if.hpp>
  24. #include <boost/type_traits/is_convertible.hpp>
  25. namespace test {
  26. struct f_predicate
  27. {
  28. template <typename T, typename Args>
  29. struct apply
  30. : boost::mpl::if_<
  31. boost::is_convertible<T,int>
  32. , boost::mpl::true_
  33. , boost::mpl::false_
  34. >
  35. {
  36. };
  37. };
  38. } // namespace test
  39. #endif // BOOST_PARAMETER_CAN_USE_MP11
  40. #include <boost/parameter/parameters.hpp>
  41. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  42. #include <boost/mp11/bind.hpp>
  43. #include <type_traits>
  44. #endif
  45. namespace test {
  46. struct f_parameters // vc6 is happier with inheritance than with a typedef
  47. : boost::parameter::parameters<
  48. boost::parameter::required<test::tag::w>
  49. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  50. , boost::parameter::optional<
  51. test::tag::x
  52. , boost::mp11::mp_bind<std::is_convertible,boost::mp11::_1,int>
  53. >
  54. , boost::parameter::optional<
  55. test::tag::y
  56. , boost::mp11::mp_bind<std::is_convertible,boost::mp11::_1,int>
  57. >
  58. , boost::parameter::optional<
  59. test::tag::z
  60. , boost::mp11::mp_bind<std::is_convertible,boost::mp11::_1,int>
  61. >
  62. #else
  63. , boost::parameter::optional<test::tag::x,test::f_predicate>
  64. , boost::parameter::optional<test::tag::y,test::f_predicate>
  65. , boost::parameter::optional<test::tag::z,test::f_predicate>
  66. #endif // BOOST_PARAMETER_CAN_USE_MP11
  67. >
  68. {
  69. };
  70. } // namespace test
  71. #include <boost/parameter/macros.hpp>
  72. #include <boost/core/lightweight_test.hpp>
  73. namespace test {
  74. #if defined(BOOST_NO_VOID_RETURNS)
  75. BOOST_PARAMETER_FUN(int, f, 1, 4, f_parameters)
  76. #else
  77. BOOST_PARAMETER_FUN(void, f, 1, 4, f_parameters)
  78. #endif
  79. {
  80. BOOST_TEST_EQ(p[test::_w][0], p[test::_x | -1]);
  81. BOOST_TEST_EQ(p[test::_w][1], p[test::_y | -2]);
  82. BOOST_TEST_EQ(p[test::_w][2], p[test::_z | -3]);
  83. #if defined(BOOST_NO_VOID_RETURNS)
  84. return 0;
  85. #endif
  86. }
  87. } // namespace test
  88. int main()
  89. {
  90. int a[3];
  91. a[0] = 1;
  92. a[1] = 2;
  93. a[2] = 3;
  94. test::f(test::_x = 1, test::_y = 2, test::_z = 3, test::_w = a);
  95. a[1] = -2;
  96. a[2] = -3;
  97. test::f(test::_x = 1, test::_w = a);
  98. a[0] = -1;
  99. a[1] = 2;
  100. test::f(test::_y = 2, test::_w = a);
  101. a[1] = -2;
  102. a[2] = 3;
  103. test::f(test::_z = 3, test::_w = a);
  104. a[0] = 1;
  105. test::f(test::_z = 3, test::_x = 1, test::_w = a);
  106. return boost::report_errors();
  107. }