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