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