1// Copyright Daniel Wallin 2006.
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
6#include <boost/parameter/parameters.hpp>
7#include <boost/parameter/name.hpp>
8#include <boost/parameter/binding.hpp>
9#include <boost/parameter/config.hpp>
10#include "deduced.hpp"
11
12#if defined(BOOST_PARAMETER_CAN_USE_MP11)
13#include <type_traits>
14#else
15#include <boost/mpl/bool.hpp>
16#include <boost/mpl/if.hpp>
17#include <boost/type_traits/is_convertible.hpp>
18#endif
19
20#if defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE)
21#include <boost/parameter/aux_/preprocessor/nullptr.hpp>
22#endif
23
24namespace test {
25
26 BOOST_PARAMETER_NAME(x)
27 BOOST_PARAMETER_NAME(y)
28 BOOST_PARAMETER_NAME(z)
29
30 template <typename To>
31 struct predicate
32 {
33 template <typename From, typename Args>
34#if defined(BOOST_PARAMETER_CAN_USE_MP11)
35 using fn = std::is_convertible<From,To>;
36#else
37 struct apply
38 : boost::mpl::if_<
39 boost::is_convertible<From,To>
40 , boost::mpl::true_
41 , boost::mpl::false_
42 >
43 {
44 };
45#endif
46 };
47} // namespace test
48
49#include <boost/core/lightweight_test.hpp>
50#include <string>
51
52int main()
53{
54 test::check<
55 boost::parameter::parameters<test::tag::x,test::tag::y>
56 >(e: (test::_x = 0, test::_y = 1), args: 0, args: 1);
57
58 test::check<
59 boost::parameter::parameters<
60 test::tag::x
61 , boost::parameter::required<
62 boost::parameter::deduced<test::tag::y>
63 , test::predicate<int>
64 >
65 , boost::parameter::optional<
66 boost::parameter::deduced<test::tag::z>
67 , test::predicate<std::string>
68 >
69 >
70 >(
71 e: (
72 test::_x = 0
73 , test::_y = test::not_present
74 , test::_z = std::string("foo")
75 )
76 , args: test::_x = 0
77 , args: std::string("foo")
78 );
79
80 test::check<
81 boost::parameter::parameters<
82 test::tag::x
83 , boost::parameter::required<
84 boost::parameter::deduced<test::tag::y>
85 , test::predicate<int>
86 >
87 , boost::parameter::optional<
88 boost::parameter::deduced<test::tag::z>
89 , test::predicate<std::string>
90 >
91 >
92 >(
93 e: (test::_x = 0, test::_y = 1, test::_z = std::string("foo"))
94 , args: 0
95 , args: std::string("foo")
96 , args: 1
97 );
98
99 test::check<
100 boost::parameter::parameters<
101 test::tag::x
102 , boost::parameter::required<
103 boost::parameter::deduced<test::tag::y>
104 , test::predicate<int>
105 >
106 , boost::parameter::optional<
107 boost::parameter::deduced<test::tag::z>
108 , test::predicate<std::string>
109 >
110 >
111 >(
112 e: (test::_x = 0, test::_y = 1, test::_z = std::string("foo"))
113 , args: 0
114 , args: 1
115 , args: std::string("foo")
116 );
117
118 test::check<
119 boost::parameter::parameters<
120 test::tag::x
121 , boost::parameter::required<
122 boost::parameter::deduced<test::tag::y>
123 , test::predicate<int>
124 >
125 , boost::parameter::optional<
126 boost::parameter::deduced<test::tag::z>
127 , test::predicate<std::string>
128 >
129 >
130 >(
131 e: (test::_x = 0, test::_y = 1, test::_z = std::string("foo"))
132 , args: 0
133 , args: test::_y = 1
134 , args: std::string("foo")
135 );
136
137 test::check<
138 boost::parameter::parameters<
139 test::tag::x
140 , boost::parameter::required<
141 boost::parameter::deduced<test::tag::y>
142 , test::predicate<int>
143 >
144 , boost::parameter::optional<
145 boost::parameter::deduced<test::tag::z>
146 , test::predicate<std::string>
147 >
148 >
149 >(
150 e: (test::_x = 0, test::_y = 1, test::_z = std::string("foo"))
151 , args: test::_z = std::string("foo")
152 , args: test::_x = 0
153 , args: 1
154 );
155
156#if defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE)
157 // Fails because boost::parameter::aux::make_arg_list<> evaluates
158 // boost::parameter::aux::is_named_argument<> to boost::mpl::false_
159 // for static_cast<long*>(BOOST_PARAMETER_AUX_PP_NULLPTR).
160 test::check<
161 boost::parameter::parameters<
162 test::tag::x
163 , boost::parameter::required<
164 boost::parameter::deduced<test::tag::y>
165 , test::predicate<int>
166 >
167 , boost::parameter::optional<
168 boost::parameter::deduced<test::tag::z>
169 , test::predicate<std::string>
170 >
171 >
172 >(
173 (test::_x = 0, test::_y = 1, test::_z = std::string("foo"))
174 , test::_x = 0
175 , static_cast<long*>(BOOST_PARAMETER_AUX_PP_NULLPTR)
176 , 1
177 );
178#endif
179
180 return boost::report_errors();
181}
182
183

source code of boost/libs/parameter/test/deduced.cpp