]>
Commit | Line | Data |
---|---|---|
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/config.hpp> | |
7 | ||
8 | #if (BOOST_PARAMETER_MAX_ARITY < 2) | |
9 | #error Define BOOST_PARAMETER_MAX_ARITY as 2 or greater. | |
10 | #endif | |
11 | #if !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) && \ | |
12 | (BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY < 3) | |
13 | #error Define BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY \ | |
14 | as 3 or greater. | |
15 | #endif | |
16 | ||
17 | namespace test { | |
18 | ||
19 | struct count_instances | |
20 | { | |
21 | count_instances() | |
22 | { | |
23 | ++count_instances::count; | |
24 | } | |
25 | ||
26 | count_instances(count_instances const&) | |
27 | { | |
28 | ++count_instances::count; | |
29 | } | |
30 | ||
31 | template <typename T> | |
32 | count_instances(T const&) | |
33 | { | |
34 | ++count_instances::count; | |
35 | } | |
36 | ||
37 | ~count_instances() | |
38 | { | |
39 | --count_instances::count; | |
40 | } | |
41 | ||
42 | static std::size_t count; | |
43 | ||
44 | void noop() const | |
45 | { | |
46 | } | |
47 | }; | |
48 | ||
49 | std::size_t count_instances::count = 0; | |
50 | } // namespace test | |
51 | ||
52 | #include <boost/parameter/name.hpp> | |
53 | ||
54 | namespace test { | |
55 | ||
56 | BOOST_PARAMETER_NAME(x) | |
57 | BOOST_PARAMETER_NAME(y) | |
58 | } // namespace test | |
59 | ||
60 | #include <boost/parameter/preprocessor.hpp> | |
61 | ||
62 | #if defined(BOOST_PARAMETER_CAN_USE_MP11) | |
63 | #include <type_traits> | |
64 | #else | |
65 | #include <boost/mpl/bool.hpp> | |
66 | #include <boost/mpl/if.hpp> | |
67 | #include <boost/mpl/assert.hpp> | |
68 | #include <boost/type_traits/is_convertible.hpp> | |
69 | #endif | |
70 | ||
71 | namespace test { | |
72 | ||
73 | BOOST_PARAMETER_FUNCTION((int), f, tag, | |
74 | (required | |
75 | (x, (long)) | |
76 | ) | |
77 | (optional | |
78 | (y, (long), 2L) | |
79 | ) | |
80 | ) | |
81 | { | |
82 | #if defined(BOOST_PARAMETER_CAN_USE_MP11) | |
83 | static_assert( | |
84 | std::is_convertible<x_type,long>::value | |
85 | , "is_convertible<x_type,long>" | |
86 | ); | |
87 | static_assert( | |
88 | std::is_convertible<y_type,long>::value | |
89 | , "is_convertible<y_type,long>" | |
90 | ); | |
91 | #else | |
92 | BOOST_MPL_ASSERT(( | |
93 | typename boost::mpl::if_< | |
94 | boost::is_convertible<x_type,long> | |
95 | , boost::mpl::true_ | |
96 | , boost::mpl::false_ | |
97 | >::type | |
98 | )); | |
99 | BOOST_MPL_ASSERT(( | |
100 | typename boost::mpl::if_< | |
101 | boost::is_convertible<y_type,long> | |
102 | , boost::mpl::true_ | |
103 | , boost::mpl::false_ | |
104 | >::type | |
105 | )); | |
106 | #endif // BOOST_PARAMETER_CAN_USE_MP11 | |
107 | return 0; | |
108 | } | |
109 | } // namespace test | |
110 | ||
111 | #include <boost/core/lightweight_test.hpp> | |
112 | ||
113 | namespace test { | |
114 | ||
115 | BOOST_PARAMETER_FUNCTION((int), g, tag, | |
116 | (required | |
117 | (x, (test::count_instances)) | |
118 | ) | |
119 | ) | |
120 | { | |
121 | #if defined(BOOST_PARAMETER_CAN_USE_MP11) | |
122 | static_assert( | |
123 | std::is_convertible<x_type,test::count_instances>::value | |
124 | , "is_convertible<x_type,test::count_instances>" | |
125 | ); | |
126 | #else | |
127 | BOOST_MPL_ASSERT(( | |
128 | typename boost::mpl::if_< | |
129 | boost::is_convertible<x_type,test::count_instances> | |
130 | , boost::mpl::true_ | |
131 | , boost::mpl::false_ | |
132 | >::type | |
133 | )); | |
134 | #endif | |
135 | x.noop(); | |
136 | #if !BOOST_WORKAROUND(BOOST_GCC, < 40000) | |
137 | BOOST_TEST_LT(0, test::count_instances::count); | |
138 | #endif | |
139 | return 0; | |
140 | } | |
141 | ||
142 | BOOST_PARAMETER_FUNCTION((int), h, tag, | |
143 | (required | |
144 | (x, (test::count_instances const&)) | |
145 | ) | |
146 | ) | |
147 | { | |
148 | #if defined(BOOST_PARAMETER_CAN_USE_MP11) | |
149 | static_assert( | |
150 | std::is_convertible<x_type,test::count_instances const>::value | |
151 | , "is_convertible<x_type,test::count_instances const>" | |
152 | ); | |
153 | #else | |
154 | BOOST_MPL_ASSERT(( | |
155 | typename boost::mpl::if_< | |
156 | boost::is_convertible<x_type,test::count_instances const> | |
157 | , boost::mpl::true_ | |
158 | , boost::mpl::false_ | |
159 | >::type | |
160 | )); | |
161 | #endif | |
162 | x.noop(); | |
163 | #if !BOOST_WORKAROUND(BOOST_GCC, < 40000) | |
164 | BOOST_TEST_EQ(1, test::count_instances::count); | |
165 | #endif | |
166 | return 0; | |
167 | } | |
168 | } // namespace test | |
169 | ||
170 | int main() | |
171 | { | |
172 | test::f(1, 2); | |
173 | test::f(1., 2.f); | |
174 | test::f(1U); | |
175 | test::g(0); | |
176 | test::h(0); | |
177 | return boost::report_errors(); | |
178 | } | |
179 |