]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/parameter/test/preprocessor_deduced.cpp
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)
6 #include <boost/parameter/config.hpp>
7 #include <boost/parameter/preprocessor.hpp>
8 #include <boost/parameter/name.hpp>
9 #include <boost/tuple/tuple.hpp>
14 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
15 #include <boost/parameter/value_type.hpp>
16 #include <boost/mp11/map.hpp>
17 #include <boost/core/enable_if.hpp>
18 #include <type_traits>
20 #include <boost/mpl/bool.hpp>
21 #include <boost/mpl/if.hpp>
22 #include <boost/type_traits/is_convertible.hpp>
23 #if !defined(BOOST_NO_SFINAE)
24 #include <boost/parameter/value_type.hpp>
25 #include <boost/mpl/has_key.hpp>
26 #include <boost/core/enable_if.hpp>
27 #include <boost/type_traits/is_same.hpp>
33 BOOST_PARAMETER_NAME(expected
)
34 BOOST_PARAMETER_NAME(x
)
35 BOOST_PARAMETER_NAME(y
)
36 BOOST_PARAMETER_NAME(z
)
38 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
39 template <typename To
>
42 template <typename From
, typename Args
>
43 using fn
= std::is_convertible
<From
,To
>;
46 BOOST_PARAMETER_FUNCTION((int), f
, test::tag
,
52 (x
, *(test::predicate
<int>))
53 (y
, *(test::predicate
<std::string
>))
57 #else // !defined(BOOST_PARAMETER_CAN_USE_MP11)
60 template <typename From
, typename Args
>
63 boost::is_convertible
<From
,int>
71 struct predicate_string
73 template <typename From
, typename Args
>
76 boost::is_convertible
<From
,std::string
>
84 BOOST_PARAMETER_FUNCTION((int), f
, test::tag
,
90 (x
, *(test::predicate_int
))
91 (y
, *(test::predicate_string
))
95 #endif // BOOST_PARAMETER_CAN_USE_MP11
97 BOOST_TEST(test::equal(x
, boost::tuples::get
<0>(expected
)));
98 BOOST_TEST(test::equal(y
, boost::tuples::get
<1>(expected
)));
104 X(int x_
= -1) : x(x_
)
108 bool operator==(X
const& other
) const
110 return this->x
== other
.x
;
116 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
117 BOOST_PARAMETER_FUNCTION((int), g
, test::tag
,
123 (x
, *(test::predicate
<int>))
124 (y
, *(test::predicate
<std::string
>))
127 (z
, *(test::predicate
<test::X
>), test::X())
131 #else // !defined(BOOST_PARAMETER_CAN_USE_MP11)
134 template <typename From
, typename Args
>
137 boost::is_convertible
<From
,test::X
>
145 BOOST_PARAMETER_FUNCTION((int), g
, tag
,
151 (x
, *(test::predicate_int
))
152 (y
, *(test::predicate_string
))
155 (z
, *(test::predicate_X
), test::X())
159 #endif // BOOST_PARAMETER_CAN_USE_MP11
161 BOOST_TEST(test::equal(x
, boost::tuples::get
<0>(expected
)));
162 BOOST_TEST(test::equal(y
, boost::tuples::get
<1>(expected
)));
163 BOOST_TEST(test::equal(z
, boost::tuples::get
<2>(expected
)));
167 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
168 BOOST_PARAMETER_FUNCTION((int), sfinae
, test::tag
,
171 (x
, *(test::predicate
<std::string
>))
176 BOOST_PARAMETER_FUNCTION((int), sfinae
, test::tag
,
179 (x
, *(test::predicate_string
))
188 #if !defined(BOOST_NO_SFINAE)
189 // On compilers that actually support SFINAE, add another overload
190 // that is an equally good match and can only be in the overload set
191 // when the others are not. This tests that the SFINAE is actually
192 // working. On all other compilers we're just checking that everything
193 // about SFINAE-enabled code will work, except of course the SFINAE.
194 template <typename A0
>
195 typename
boost::enable_if
<
196 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
199 typename
boost::mpl::if_
<
200 boost::is_same
<int,A0
>
212 #if defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE_VENDOR_SPECIFIC) || \
213 !BOOST_WORKAROUND(BOOST_MSVC, < 1800)
214 // Test support for two different Boost.Parameter-enabled
215 // function call operator overloads.
222 template <typename Args
>
223 explicit char_read_base(Args
const& args
)
224 : index(args
[test::_y
]), key(args
[test::_z
])
228 BOOST_PARAMETER_FUNCTION_CALL_OPERATOR((void), test::tag
,
241 BOOST_PARAMETER_CONST_FUNCTION_CALL_OPERATOR((char), test::tag
,
245 (z
, (std::map
<char const*,std::string
>))
251 (z
.find(this->key
)->second
)[this->index
]
252 ) : this->key
[this->index
];
256 struct char_reader
: public char_read_base
258 BOOST_PARAMETER_CONSTRUCTOR(char_reader
, (char_read_base
), test::tag
,
269 // Test Boost.Parameter-enabled functions
270 // with parameter-dependent return types.
271 #if !defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE)
272 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
273 BOOST_PARAMETER_FUNCTION(
275 boost::lazy_enable_if
<
276 boost::mp11::mp_map_contains
<Args
,test::tag::y
>
277 , boost::parameter::value_type
<Args
,test::tag::y
>
279 ), return_y
, test::tag
,
282 (x
, (std::map
<char const*,std::string
>))
290 #else // !defined(BOOST_PARAMETER_CAN_USE_MP11)
291 BOOST_PARAMETER_FUNCTION(
293 boost::lazy_enable_if
<
294 typename
boost::mpl::has_key
<Args
,test::tag::y
>::type
295 , boost::parameter::value_type
<Args
,test::tag::y
>
297 ), return_y
, test::tag
,
300 (x
, (std::map
<char const*,std::string
>))
308 #endif // BOOST_PARAMETER_CAN_USE_MP11
312 #endif // LIBS_PARAMETER_TEST_COMPILE_FAILURE
313 #endif // BOOST_NO_SFINAE
315 #if defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE)
316 BOOST_PARAMETER_FUNCTION(
317 (typename
boost::parameter::value_type
<Args
,test::tag::y
>::type
),
321 (x
, (std::map
<char const*,std::string
>))
332 #endif // defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE)
335 #include <boost/core/lightweight_test.hpp>
340 boost::make_tuple(0, std::string("foo"))
342 , test::_y
= std::string("foo")
345 boost::make_tuple(0, std::string("foo"))
350 boost::make_tuple(0, std::string("foo"))
355 boost::make_tuple(0, std::string("foo"))
356 , test::_y
= std::string("foo")
360 boost::make_tuple(0, std::string("foo"))
365 boost::make_tuple(0, std::string("foo"))
367 , test::_y
= std::string("foo")
370 boost::make_tuple(0, std::string("foo"), test::X())
372 , test::_y
= std::string("foo")
375 boost::make_tuple(0, std::string("foo"), test::X())
380 boost::make_tuple(0, std::string("foo"), test::X())
385 boost::make_tuple(0, std::string("foo"), test::X())
386 , test::_y
= std::string("foo")
390 boost::make_tuple(0, std::string("foo"), test::X())
395 boost::make_tuple(0, std::string("foo"), test::X())
397 , test::_y
= std::string("foo")
400 boost::make_tuple(0, std::string("foo"), test::X(1))
402 , test::_y
= std::string("foo")
406 boost::make_tuple(0, std::string("foo"), test::X(1))
409 , test::_y
= std::string("foo")
412 std::map
<char const*,std::string
> k2s
;
413 #if !defined(BOOST_NO_SFINAE)
414 char const* keys
[] = {"foo", "bar", "baz"};
415 BOOST_TEST_EQ(1, test::sfinae(keys
[0]));
416 BOOST_TEST_EQ(0, test::sfinae(0));
417 #if defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE_VENDOR_SPECIFIC) || \
418 !BOOST_WORKAROUND(BOOST_MSVC, < 1800)
419 k2s
[keys
[0]] = std::string("qux");
420 k2s
[keys
[1]] = std::string("wmb");
421 k2s
[keys
[2]] = std::string("zxc");
422 test::char_reader
r(keys
[0], 0);
423 BOOST_TEST_EQ('q', (r(k2s
, true)));
424 BOOST_TEST_EQ('f', (r(k2s
, false)));
426 BOOST_TEST_EQ('m', (r(k2s
, true)));
427 BOOST_TEST_EQ('a', (r(k2s
, false)));
429 BOOST_TEST_EQ('c', (r(k2s
, true)));
430 BOOST_TEST_EQ('z', (r(k2s
, false)));
432 #if !defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE)
433 BOOST_TEST_EQ(keys
[1], test::return_y(2, k2s
, keys
[1]));
435 #endif // BOOST_NO_SFINAE
437 #if defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE)
438 BOOST_TEST_EQ(keys
[1], test::return_y(2, k2s
, keys
[1]));
441 return boost::report_errors();