]>
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) | |
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 < 2) | |
13 | #error Define BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY \ | |
14 | as 2 or greater. | |
15 | #endif | |
7c673cae FG |
16 | |
17 | #include <boost/parameter/preprocessor.hpp> | |
18 | #include <boost/parameter/name.hpp> | |
92f5a8d4 | 19 | #include <boost/parameter/aux_/preprocessor/nullptr.hpp> |
7c673cae | 20 | #include <boost/tuple/tuple.hpp> |
92f5a8d4 | 21 | #include <boost/core/enable_if.hpp> |
7c673cae | 22 | #include <string> |
7c673cae | 23 | |
92f5a8d4 TL |
24 | #if defined(BOOST_PARAMETER_CAN_USE_MP11) |
25 | #include <boost/mp11/utility.hpp> | |
26 | #include <type_traits> | |
7c673cae | 27 | #else |
92f5a8d4 TL |
28 | #include <boost/mpl/bool.hpp> |
29 | #include <boost/mpl/if.hpp> | |
30 | #include <boost/type_traits/is_convertible.hpp> | |
7c673cae FG |
31 | #endif |
32 | ||
92f5a8d4 | 33 | namespace test { |
7c673cae | 34 | |
92f5a8d4 TL |
35 | BOOST_PARAMETER_NAME(x) |
36 | ||
37 | #if defined(BOOST_PARAMETER_CAN_USE_MP11) | |
38 | template <typename T, typename Args> | |
39 | using predicate = std::is_convertible<T,char const*>; | |
40 | ||
41 | BOOST_PARAMETER_FUNCTION((int), sfinae, test::tag, | |
42 | (deduced | |
43 | (optional | |
44 | (x | |
45 | , *(boost::mp11::mp_quote<test::predicate>) | |
46 | , static_cast<char const*>(BOOST_PARAMETER_AUX_PP_NULLPTR) | |
47 | ) | |
48 | ) | |
49 | ) | |
50 | ) | |
51 | #else // !defined(BOOST_PARAMETER_CAN_USE_MP11) | |
52 | struct predicate | |
53 | { | |
54 | template <typename T, typename Args> | |
55 | struct apply | |
56 | : boost::mpl::if_< | |
57 | boost::is_convertible<T,char const*> | |
58 | , boost::mpl::true_ | |
59 | , boost::mpl::false_ | |
60 | > | |
61 | { | |
62 | }; | |
63 | }; | |
64 | ||
65 | BOOST_PARAMETER_FUNCTION((int), sfinae, test::tag, | |
66 | (deduced | |
67 | (optional | |
68 | (x | |
69 | , *(test::predicate) | |
70 | , static_cast<char const*>(BOOST_PARAMETER_AUX_PP_NULLPTR) | |
71 | ) | |
72 | ) | |
73 | ) | |
74 | ) | |
75 | #endif // BOOST_PARAMETER_CAN_USE_MP11 | |
76 | { | |
77 | return 1; | |
78 | } | |
79 | ||
80 | template <typename A0> | |
81 | typename boost::enable_if< | |
82 | #if defined(BOOST_PARAMETER_CAN_USE_MP11) | |
83 | std::is_same<int,A0> | |
84 | #else | |
85 | typename boost::mpl::if_< | |
86 | boost::is_same<int,A0> | |
87 | , boost::mpl::true_ | |
88 | , boost::mpl::false_ | |
89 | >::type | |
90 | #endif | |
91 | , int | |
92 | >::type | |
93 | sfinae(A0 const& a0) | |
94 | { | |
95 | return 0; | |
96 | } | |
7c673cae FG |
97 | } // namespace test |
98 | ||
92f5a8d4 TL |
99 | #include <boost/core/lightweight_test.hpp> |
100 | ||
7c673cae FG |
101 | int main() |
102 | { | |
92f5a8d4 TL |
103 | BOOST_TEST_EQ(1, test::sfinae()); |
104 | BOOST_TEST_EQ(1, test::sfinae("foo")); | |
105 | BOOST_TEST_EQ(0, test::sfinae(1)); | |
106 | return boost::report_errors(); | |
7c673cae FG |
107 | } |
108 |