basics.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Copyright David Abrahams, Daniel Wallin 2003.
  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. #include <boost/parameter.hpp>
  7. #include <boost/bind.hpp>
  8. #include "basics.hpp"
  9. namespace test {
  10. // A separate function for getting the "value" key, so we can deduce F
  11. // and use lazy_binding on it.
  12. template <typename Params, typename F>
  13. typename boost::parameter::lazy_binding<Params,tag::value,F>::type
  14. extract_value(Params const& p, F const& f)
  15. {
  16. typename boost::parameter::lazy_binding<
  17. Params,test::tag::value,F
  18. >::type v = p[test::_value || f];
  19. return v;
  20. }
  21. template <typename Params>
  22. int f_impl(Params const& p)
  23. {
  24. typename boost::parameter::binding<Params,test::tag::name>::type
  25. n = p[test::_name];
  26. typename boost::parameter::binding<
  27. Params,test::tag::value,double
  28. >::type v = test::extract_value(p, boost::bind(&test::value_default));
  29. typename boost::parameter::binding<Params,test::tag::index,int>::type
  30. i = p[test::_index | 999];
  31. p[test::_tester](n, v, i);
  32. return 1;
  33. }
  34. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  35. template <typename ...Args>
  36. int f(Args const&... args)
  37. {
  38. return test::f_impl(test::f_parameters()(args...));
  39. }
  40. #else
  41. template <typename A0, typename A1, typename A2, typename A3>
  42. int f(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3)
  43. {
  44. return test::f_impl(test::f_parameters()(a0, a1, a2, a3));
  45. }
  46. template <typename A0, typename A1, typename A2>
  47. int f(A0 const& a0, A1 const& a1, A2 const& a2)
  48. {
  49. return test::f_impl(test::f_parameters()(a0, a1, a2));
  50. }
  51. template <typename A0, typename A1>
  52. int f(A0 const& a0, A1 const& a1)
  53. {
  54. return test::f_impl(test::f_parameters()(a0, a1));
  55. }
  56. #endif // BOOST_PARAMETER_HAS_PERFECT_FORWARDING
  57. template <typename Params>
  58. int f_list(Params const& params)
  59. {
  60. return test::f_impl(params);
  61. }
  62. }
  63. #include <boost/core/ref.hpp>
  64. #include <boost/config/workaround.hpp>
  65. #include <string>
  66. int main()
  67. {
  68. test::f(
  69. test::values(
  70. std::string("foo")
  71. , std::string("bar")
  72. , std::string("baz")
  73. )
  74. , std::string("foo")
  75. , std::string("bar")
  76. , std::string("baz")
  77. );
  78. int x = 56;
  79. test::f(
  80. test::values(std::string("foo"), 666.222, 56)
  81. , test::_index = boost::ref(x)
  82. , test::_name = std::string("foo")
  83. );
  84. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  85. x = 56;
  86. test::f_list((
  87. test::_tester = test::values(std::string("foo"), 666.222, 56)
  88. , test::_index = boost::ref(x)
  89. , test::_name = std::string("foo")
  90. ));
  91. #endif // No comma operator available on Borland.
  92. #if defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE)
  93. test::f(test::_index = 56, test::_name = 55); // won't compile
  94. #endif
  95. return boost::report_errors();
  96. }