1 | // Copyright David Abrahams, Daniel Wallin 2003. Use, modification and |
---|
2 | // distribution is subject to 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 | |
---|
6 | #include <boost/parameter.hpp> |
---|
7 | #include <cassert> |
---|
8 | #include <string.h> |
---|
9 | #include <boost/bind.hpp> |
---|
10 | #include <boost/ref.hpp> |
---|
11 | |
---|
12 | #include "basics.hpp" |
---|
13 | |
---|
14 | |
---|
15 | namespace test |
---|
16 | { |
---|
17 | // A separate function for getting the "value" key, so we can deduce |
---|
18 | // F and use lazy_binding on it. |
---|
19 | template <class Params, class F> |
---|
20 | typename boost::parameter::lazy_binding<Params,tag::value,F>::type |
---|
21 | extract_value(Params const& p, F const& f) |
---|
22 | { |
---|
23 | typename boost::parameter::lazy_binding< |
---|
24 | Params, tag::value, F |
---|
25 | >::type v = p[value || f ]; |
---|
26 | return v; |
---|
27 | } |
---|
28 | |
---|
29 | template<class Params> |
---|
30 | int f_impl(Params const& p) |
---|
31 | { |
---|
32 | typename boost::parameter::binding<Params, tag::name>::type |
---|
33 | n = p[name]; |
---|
34 | |
---|
35 | typename boost::parameter::binding< |
---|
36 | Params, tag::value, double |
---|
37 | >::type v = extract_value(p, boost::bind(&value_default)); |
---|
38 | |
---|
39 | typename boost::parameter::binding< |
---|
40 | Params, tag::index, int |
---|
41 | >::type i = |
---|
42 | #if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042)) |
---|
43 | p[test::index | 999]; |
---|
44 | #else |
---|
45 | p[index | 999]; |
---|
46 | #endif |
---|
47 | |
---|
48 | p[tester](n,v,i); |
---|
49 | |
---|
50 | return 1; |
---|
51 | } |
---|
52 | |
---|
53 | template<class Tester, class Name, class Value, class Index> |
---|
54 | int f(Tester const& t, const Name& name_, |
---|
55 | const Value& value_, const Index& index_) |
---|
56 | { |
---|
57 | return f_impl(f_parameters()(t, name_, value_, index_)); |
---|
58 | } |
---|
59 | |
---|
60 | template<class Tester, class Name, class Value> |
---|
61 | int f(Tester const& t, const Name& name_, const Value& value_) |
---|
62 | { |
---|
63 | return f_impl(f_parameters()(t, name_, value_)); |
---|
64 | } |
---|
65 | |
---|
66 | template<class Tester, class Name> |
---|
67 | int f(Tester const& t, const Name& name_) |
---|
68 | { |
---|
69 | return f_impl(f_parameters()(t, name_)); |
---|
70 | } |
---|
71 | |
---|
72 | template<class Params> |
---|
73 | int f_list(Params const& params) |
---|
74 | { |
---|
75 | return f_impl(params); |
---|
76 | } |
---|
77 | |
---|
78 | } |
---|
79 | |
---|
80 | int main() |
---|
81 | { |
---|
82 | using test::f; |
---|
83 | using test::f_list; |
---|
84 | using test::name; |
---|
85 | using test::value; |
---|
86 | using test::index; |
---|
87 | using test::tester; |
---|
88 | |
---|
89 | f( |
---|
90 | test::values(S("foo"), S("bar"), S("baz")) |
---|
91 | , S("foo"), S("bar"), S("baz") |
---|
92 | ); |
---|
93 | |
---|
94 | int x = 56; |
---|
95 | f( |
---|
96 | test::values("foo", 666.222, 56) |
---|
97 | , index = boost::ref(x), name = "foo" |
---|
98 | ); |
---|
99 | |
---|
100 | #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) |
---|
101 | // No comma operator available on Borland |
---|
102 | f_list(( |
---|
103 | tester = test::values("foo", 666.222, 56) |
---|
104 | , index = boost::ref(x) |
---|
105 | , name = "foo" |
---|
106 | )); |
---|
107 | #endif |
---|
108 | |
---|
109 | //f(index = 56, name = 55); // won't compile |
---|
110 | return 0; |
---|
111 | } |
---|
112 | |
---|