1 // Copyright Cromwell D. Enage 2017.
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 ( \
9         !defined(__MINGW32__) && \
10         defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) \
11     ) || defined(BOOST_MSVC)
12 #if (BOOST_PARAMETER_MAX_ARITY < 8)
13 #error Define BOOST_PARAMETER_MAX_ARITY as 8 or greater.
14 #endif
15 #else   // mingw, or no perfect forwarding support and not msvc
16 #if (BOOST_PARAMETER_COMPOSE_MAX_ARITY < 8)
17 #error Define BOOST_PARAMETER_COMPOSE_MAX_ARITY as 8 or greater.
18 #endif
19 #endif  // msvc, or perfect forwarding support and not mingw
20 
21 #include <boost/parameter/name.hpp>
22 
23 namespace test {
24 
25     BOOST_PARAMETER_NAME((_lrc0, kw) in(lrc0))
26     BOOST_PARAMETER_NAME((_lr0, kw) in_out(lr0))
27     BOOST_PARAMETER_NAME((_rrc0, kw) in(rrc0))
28 #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
29     BOOST_PARAMETER_NAME((_rr0, kw) consume(rr0))
30 #else
31     BOOST_PARAMETER_NAME((_rr0, kw) rr0)
32 #endif
33     BOOST_PARAMETER_NAME((_lrc1, kw) in(lrc1))
34     BOOST_PARAMETER_NAME((_lr1, kw) out(lr1))
35     BOOST_PARAMETER_NAME((_rrc1, kw) in(rrc1))
36     BOOST_PARAMETER_NAME((_rr1, kw) rr1)
37 } // namespace test
38 
39 #include <boost/mpl/bool.hpp>
40 #include <boost/mpl/placeholders.hpp>
41 #include <boost/mpl/if.hpp>
42 #include <boost/core/lightweight_test.hpp>
43 #include <boost/type_traits/is_convertible.hpp>
44 #include "evaluate_category.hpp"
45 
46 #if !defined(__MINGW32__) && defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
47 #include <boost/parameter/preprocessor.hpp>
48 #include <utility>
49 #elif defined(BOOST_MSVC)
50 #include <boost/parameter/preprocessor.hpp>
51 #else
52 #include <boost/parameter/preprocessor_no_spec.hpp>
53 #endif
54 
55 namespace test {
56 
57     struct C
58     {
59 #if ( \
60         !defined(__MINGW32__) && \
61         defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) \
62     ) || defined(BOOST_MSVC)
63         typedef boost::mpl::if_<
64             boost::is_convertible<boost::mpl::_,std::bitset<1> >
65           , boost::mpl::true_
66           , boost::mpl::false_
67         > bs0_pred;
68         typedef boost::mpl::if_<
69             boost::is_convertible<boost::mpl::_,std::bitset<2> >
70           , boost::mpl::true_
71           , boost::mpl::false_
72         > bs1_pred;
73         typedef boost::mpl::if_<
74             boost::is_convertible<boost::mpl::_,std::bitset<3> >
75           , boost::mpl::true_
76           , boost::mpl::false_
77         > bs2_pred;
78         typedef boost::mpl::if_<
79             boost::is_convertible<boost::mpl::_,std::bitset<4> >
80           , boost::mpl::true_
81           , boost::mpl::false_
82         > bs3_pred;
83         typedef boost::mpl::if_<
84             boost::is_convertible<boost::mpl::_,std::bitset<5> >
85           , boost::mpl::true_
86           , boost::mpl::false_
87         > bs4_pred;
88         typedef boost::mpl::if_<
89             boost::is_convertible<boost::mpl::_,std::bitset<6> >
90           , boost::mpl::true_
91           , boost::mpl::false_
92         > bs5_pred;
93         typedef boost::mpl::if_<
94             boost::is_convertible<boost::mpl::_,std::bitset<7> >
95           , boost::mpl::true_
96           , boost::mpl::false_
97         > bs6_pred;
98         typedef boost::mpl::if_<
99             boost::is_convertible<boost::mpl::_,std::bitset<8> >
100           , boost::mpl::true_
101           , boost::mpl::false_
102         > bs7_pred;
103 
104         BOOST_PARAMETER_CONST_FUNCTION_CALL_OPERATOR((bool), kw,
105             (deduced
106                 (required
107                     (lrc0, *(bs0_pred))
108                     (lr0, *(bs1_pred))
109                     (rrc0, *(bs2_pred))
110                     (rr0, *(bs3_pred))
111                     (lrc1, *(bs4_pred))
112                 )
113                 (optional
114                     (lr1, *(bs5_pred), test::lvalue_bitset<5>())
115                     (rrc1, *(bs6_pred), test::rvalue_const_bitset<6>())
116                     (rr1, *(bs7_pred), test::rvalue_bitset<7>())
117                 )
118             )
119         )
120 #else
121         BOOST_PARAMETER_NO_SPEC_CONST_FUNCTION_CALL_OPERATOR((bool))
122 #endif  // msvc, or perfect forwarding support and not mingw
123         {
124 #if ( \
125         !defined(__MINGW32__) && \
126         defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) \
127     ) || defined(BOOST_MSVC)
128             BOOST_TEST_EQ(
129                 test::passed_by_lvalue_reference_to_const
130               , test::U::evaluate_category<0>(lrc0)
131             );
132             BOOST_TEST_EQ(
133                 test::passed_by_lvalue_reference
134               , test::U::evaluate_category<1>(lr0)
135             );
136             BOOST_TEST_EQ(
137                 test::passed_by_lvalue_reference_to_const
138               , test::U::evaluate_category<4>(lrc1)
139             );
140             BOOST_TEST_EQ(
141                 test::passed_by_lvalue_reference
142               , test::U::evaluate_category<5>(lr1)
143             );
144 #else   // mingw, or no perfect forwarding support and not msvc
145             BOOST_TEST_EQ(
146                 test::passed_by_lvalue_reference_to_const
147               , test::U::evaluate_category<0>(args[test::_lrc0])
148             );
149             BOOST_TEST_EQ(
150                 test::passed_by_lvalue_reference
151               , test::U::evaluate_category<1>(args[test::_lr0])
152             );
153             BOOST_TEST_EQ(
154                 test::passed_by_lvalue_reference_to_const
155               , test::U::evaluate_category<4>(args[test::_lrc1])
156             );
157             BOOST_TEST_EQ(
158                 test::passed_by_lvalue_reference
159               , test::U::evaluate_category<5>(
160                     args[test::_lr1 | test::lvalue_bitset<5>()]
161                 )
162             );
163 #endif  // msvc, or perfect forwarding support and not mingw
164 #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
165 #if defined(__MINGW32__)
166             BOOST_TEST_EQ(
167                 test::passed_by_rvalue_reference_to_const
168               , test::U::evaluate_category<2>(args[test::_rrc0])
169             );
170             BOOST_TEST_EQ(
171                 test::passed_by_rvalue_reference
172               , test::U::evaluate_category<3>(args[test::_rr0])
173             );
174             BOOST_TEST_EQ(
175                 test::passed_by_rvalue_reference_to_const
176               , test::U::evaluate_category<6>(
177                     args[test::_rrc1 | test::rvalue_const_bitset<6>()]
178                 )
179             );
180             BOOST_TEST_EQ(
181                 test::passed_by_rvalue_reference
182               , test::U::evaluate_category<7>(
183                     args[test::_rr1 | test::rvalue_bitset<7>()]
184                 )
185             );
186 #else   // !defined(__MINGW32__)
187             BOOST_TEST_EQ(
188                 test::passed_by_rvalue_reference_to_const
189               , test::U::evaluate_category<2>(std::forward<rrc0_type>(rrc0))
190             );
191             BOOST_TEST_EQ(
192                 test::passed_by_rvalue_reference
193               , test::U::evaluate_category<3>(std::forward<rr0_type>(rr0))
194             );
195             BOOST_TEST_EQ(
196                 test::passed_by_rvalue_reference_to_const
197               , test::U::evaluate_category<6>(std::forward<rrc1_type>(rrc1))
198             );
199             BOOST_TEST_EQ(
200                 test::passed_by_rvalue_reference
201               , test::U::evaluate_category<7>(std::forward<rr1_type>(rr1))
202             );
203 #endif  // __MINGW32__
204 #else   // !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
205 #if defined(BOOST_MSVC)
206             BOOST_TEST_EQ(
207                 test::passed_by_lvalue_reference_to_const
208               , test::U::evaluate_category<2>(rrc0)
209             );
210             BOOST_TEST_EQ(
211                 test::passed_by_lvalue_reference_to_const
212               , test::U::evaluate_category<3>(rr0)
213             );
214             BOOST_TEST_EQ(
215                 test::passed_by_lvalue_reference_to_const
216               , test::U::evaluate_category<6>(rrc1)
217             );
218             BOOST_TEST_EQ(
219                 test::passed_by_lvalue_reference_to_const
220               , test::U::evaluate_category<7>(rr1)
221             );
222 #else   // !defined(BOOST_MSVC)
223             BOOST_TEST_EQ(
224                 test::passed_by_lvalue_reference_to_const
225               , test::U::evaluate_category<2>(args[test::_rrc0])
226             );
227             BOOST_TEST_EQ(
228                 test::passed_by_lvalue_reference_to_const
229               , test::U::evaluate_category<3>(args[test::_rr0])
230             );
231             BOOST_TEST_EQ(
232                 test::passed_by_lvalue_reference_to_const
233               , test::U::evaluate_category<6>(
234                     args[test::_rrc1 | test::rvalue_const_bitset<6>()]
235                 )
236             );
237             BOOST_TEST_EQ(
238                 test::passed_by_lvalue_reference_to_const
239               , test::U::evaluate_category<7>(
240                     args[test::_rr1 | test::rvalue_bitset<7>()]
241                 )
242             );
243 #endif  // BOOST_MSVC
244 #endif  // BOOST_PARAMETER_HAS_PERFECT_FORWARDING
245 
246             return true;
247         }
248     };
249 } // namespace test
250 
main()251 int main()
252 {
253     test::C cp0;
254     test::C cp1;
255 
256 #if ( \
257         !defined(__MINGW32__) && \
258         defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) \
259     ) || defined(BOOST_MSVC)
260     cp0(
261         test::lvalue_const_bitset<4>()
262       , test::lvalue_const_bitset<0>()
263       , test::lvalue_bitset<1>()
264       , test::rvalue_const_bitset<2>()
265       , test::rvalue_bitset<3>()
266     );
267     cp0(
268         test::lvalue_const_bitset<4>()
269       , test::lvalue_const_bitset<0>()
270       , test::rvalue_const_bitset<6>()
271       , test::lvalue_bitset<1>()
272       , test::rvalue_const_bitset<2>()
273       , test::rvalue_bitset<3>()
274     );
275     cp1(
276         test::lvalue_bitset<1>()
277       , test::rvalue_const_bitset<2>()
278       , test::rvalue_bitset<3>()
279       , test::lvalue_const_bitset<4>()
280       , test::lvalue_bitset<5>()
281       , test::rvalue_const_bitset<6>()
282       , test::rvalue_bitset<7>()
283       , test::lvalue_const_bitset<0>()
284     );
285 #else   // mingw, or no perfect forwarding support and not msvc
286     cp0(
287         test::_lrc1 = test::lvalue_const_bitset<4>()
288       , test::_lrc0 = test::lvalue_const_bitset<0>()
289       , test::_lr0 = test::lvalue_bitset<1>()
290       , test::_rrc0 = test::rvalue_const_bitset<2>()
291       , test::_rr0 = test::rvalue_bitset<3>()
292     );
293     cp0(
294         test::_lrc1 = test::lvalue_const_bitset<4>()
295       , test::_lrc0 = test::lvalue_const_bitset<0>()
296       , test::_rrc1 = test::rvalue_const_bitset<6>()
297       , test::_lr0 = test::lvalue_bitset<1>()
298       , test::_rrc0 = test::rvalue_const_bitset<2>()
299       , test::_rr0 = test::rvalue_bitset<3>()
300     );
301     cp1(
302         test::_lr0 = test::lvalue_bitset<1>()
303       , test::_rrc0 = test::rvalue_const_bitset<2>()
304       , test::_rr0 = test::rvalue_bitset<3>()
305       , test::_lrc1 = test::lvalue_const_bitset<4>()
306       , test::_lr1 = test::lvalue_bitset<5>()
307       , test::_rrc1 = test::rvalue_const_bitset<6>()
308       , test::_rr1 = test::rvalue_bitset<7>()
309       , test::_lrc0 = test::lvalue_const_bitset<0>()
310     );
311 #endif  // msvc, or perfect forwarding support and not mingw
312     return boost::report_errors();
313 }
314 
315