]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/parameter/test/sfinae.cpp
1 // Copyright David Abrahams, Daniel Wallin 2003.
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>
8 #if (BOOST_PARAMETER_MAX_ARITY < 2)
9 #error Define BOOST_PARAMETER_MAX_ARITY as 2 or greater.
11 #if !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
12 #if (BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY < 3)
13 #error Define BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY \
18 #include <boost/parameter/name.hpp>
22 BOOST_PARAMETER_NAME((name
, keywords
) in(name
))
23 BOOST_PARAMETER_NAME((value
, keywords
) in(value
))
26 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
27 #include <type_traits>
29 #include <boost/mpl/bool.hpp>
30 #include <boost/mpl/if.hpp>
31 #include <boost/type_traits/is_convertible.hpp>
36 template <typename To
>
39 template <typename From
, typename Args
>
40 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
41 using fn
= std::is_convertible
<From
,To
>;
45 boost::is_convertible
<From
,To
>
55 #include <boost/parameter/parameters.hpp>
56 #include <boost/parameter/optional.hpp>
62 : boost::parameter::parameters
<
63 boost::parameter::optional
<
65 , test::f_predicate
<std::string
>
67 , boost::parameter::optional
<
69 , test::f_predicate
<float>
76 #include <boost/core/lightweight_test.hpp>
80 // The use of assert_equal_string is just a nasty workaround for a
82 void assert_equal_string(std::string x
, std::string y
)
88 void f_impl(P
const& p
)
90 float v
= p
[test::value
| 3.f
];
91 BOOST_TEST_EQ(v
, 3.f
);
92 test::assert_equal_string(p
[test::name
| "bar"], "foo");
97 test::f_impl(f_parameters()());
101 #include <boost/parameter/match.hpp>
105 template <typename A0
>
109 , BOOST_PARAMETER_MATCH(f_parameters
, (A0
), args
)
112 test::f_impl(args(a0
));
115 template <typename A0
, typename A1
>
120 , BOOST_PARAMETER_MATCH(f_parameters
, (A0
)(A1
), args
)
123 test::f_impl(args(a0
, a1
));
127 #if !defined(BOOST_NO_SFINAE) && \
128 !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
129 #include <boost/core/enable_if.hpp>
131 #if !defined(BOOST_PARAMETER_CAN_USE_MP11)
132 #include <boost/type_traits/is_same.hpp>
137 // On compilers that actually support SFINAE, add another overload that is
138 // an equally good match and can only be in the overload set when the
139 // others are not. This tests that the SFINAE is actually working. On
140 // all other compilers we're just checking that everything about
141 // SFINAE-enabled code will work, except of course the SFINAE.
142 template <typename A0
, typename A1
>
143 typename
boost::enable_if
<
144 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
147 typename
boost::mpl::if_
<
148 boost::is_same
<int,A0
>
155 f(A0
const& a0
, A1
const& a1
)
161 #endif // SFINAE enabled, no Borland workarounds needed.
167 test::f(test::value
= 3.f
, test::name
= "foo");
168 #if !defined(BOOST_NO_SFINAE) && \
169 !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
170 BOOST_TEST_EQ(0, test::f(3, 4));
172 return boost::report_errors();