• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.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
extract_value(Params const & p,F const & f)17         extract_value(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>
f_impl(Params const & p)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(&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>
f(Args const &...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>
f(A0 const & a0,A1 const & a1,A2 const & a2,A3 const & 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>
f(A0 const & a0,A1 const & a1,A2 const & 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>
f(A0 const & a0,A1 const & 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>
f_list(Params const & 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 
main()80 int main()
81 {
82     test::f(
83         test::values(
84             std::string("foo")
85           , std::string("bar")
86           , std::string("baz")
87         )
88       , std::string("foo")
89       , std::string("bar")
90       , std::string("baz")
91     );
92 
93     int x = 56;
94     test::f(
95         test::values(std::string("foo"), 666.222, 56)
96       , test::_index = boost::ref(x)
97       , test::_name = std::string("foo")
98     );
99 
100 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
101     x = 56;
102     test::f_list((
103         test::_tester = test::values(std::string("foo"), 666.222, 56)
104       , test::_index = boost::ref(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