1
2 // Copyright 2015 Peter Dimov.
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 //
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
8
9
10 #include <boost/mp11/utility.hpp>
11 #include <boost/mp11/detail/config.hpp>
12 #include <boost/core/lightweight_test_trait.hpp>
13
14 template<class T> struct Xi
15 {
16 };
17
18 template<> struct Xi<void>
19 {
20 using type = void;
21 };
22
23 template<class T> using X = typename Xi<T>::type;
24
25 template<class T> using add_pointer = T*;
26 template<class T> using add_reference = T&;
27 template<class T> using add_extents = T[];
28
29 using boost::mp11::mp_quote;
30
31 using QX = mp_quote<X>;
32 using Q_add_pointer = mp_quote<add_pointer>;
33
main()34 int main()
35 {
36 using boost::mp11::mp_valid;
37 using boost::mp11::mp_valid_q;
38 using boost::mp11::mp_identity;
39
40 BOOST_TEST_TRAIT_FALSE((mp_valid<mp_identity>));
41 BOOST_TEST_TRAIT_TRUE((mp_valid<mp_identity, void>));
42 BOOST_TEST_TRAIT_FALSE((mp_valid<mp_identity, void, void>));
43
44 BOOST_TEST_TRAIT_FALSE((mp_valid<X>));
45 BOOST_TEST_TRAIT_TRUE((mp_valid<X, void>));
46 BOOST_TEST_TRAIT_FALSE((mp_valid<X, int>));
47 BOOST_TEST_TRAIT_FALSE((mp_valid<X, void, void>));
48
49 BOOST_TEST_TRAIT_FALSE((mp_valid<QX::fn>));
50 BOOST_TEST_TRAIT_TRUE((mp_valid<QX::fn, void>));
51 BOOST_TEST_TRAIT_FALSE((mp_valid<QX::fn, int>));
52 BOOST_TEST_TRAIT_FALSE((mp_valid<QX::fn, void, void>));
53
54 BOOST_TEST_TRAIT_FALSE((mp_valid_q<QX>));
55 BOOST_TEST_TRAIT_TRUE((mp_valid_q<QX, void>));
56 BOOST_TEST_TRAIT_FALSE((mp_valid_q<QX, int>));
57 BOOST_TEST_TRAIT_FALSE((mp_valid_q<QX, void, void>));
58
59 BOOST_TEST_TRAIT_FALSE((mp_valid<add_pointer>));
60 BOOST_TEST_TRAIT_TRUE((mp_valid<add_pointer, void>));
61 BOOST_TEST_TRAIT_TRUE((mp_valid<add_pointer, int>));
62 #if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, <= 1800 )
63 // msvc-12.0 can form pointer to reference
64 BOOST_TEST_TRAIT_FALSE((mp_valid<add_pointer, int&>));
65 #endif
66 BOOST_TEST_TRAIT_FALSE((mp_valid<add_pointer, void, void>));
67
68 BOOST_TEST_TRAIT_FALSE((mp_valid<Q_add_pointer::fn>));
69 BOOST_TEST_TRAIT_TRUE((mp_valid<Q_add_pointer::fn, void>));
70 BOOST_TEST_TRAIT_TRUE((mp_valid<Q_add_pointer::fn, int>));
71 BOOST_TEST_TRAIT_FALSE((mp_valid<Q_add_pointer::fn, void, void>));
72
73 BOOST_TEST_TRAIT_FALSE((mp_valid_q<Q_add_pointer>));
74 BOOST_TEST_TRAIT_TRUE((mp_valid_q<Q_add_pointer, void>));
75 BOOST_TEST_TRAIT_TRUE((mp_valid_q<Q_add_pointer, int>));
76 BOOST_TEST_TRAIT_FALSE((mp_valid_q<Q_add_pointer, void, void>));
77
78 #if !BOOST_MP11_WORKAROUND( BOOST_MP11_GCC, < 70000 )
79 // g++ up to at least 6.3 doesn't like add_reference for some reason or other
80 BOOST_TEST_TRAIT_FALSE((mp_valid<add_reference>));
81 #if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, <= 1800 )
82 // msvc-12.0 gives an internal error here
83 BOOST_TEST_TRAIT_FALSE((mp_valid<add_reference, void>));
84 #endif
85 BOOST_TEST_TRAIT_TRUE((mp_valid<add_reference, int>));
86 BOOST_TEST_TRAIT_FALSE((mp_valid<add_reference, int, int>));
87 #endif
88
89 BOOST_TEST_TRAIT_FALSE((mp_valid<add_extents>));
90 BOOST_TEST_TRAIT_TRUE((mp_valid<add_extents, int>));
91 #if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, <= 1800 )
92 // msvc-12.0 can form arrays to void or int&
93 BOOST_TEST_TRAIT_FALSE((mp_valid<add_extents, void>));
94 BOOST_TEST_TRAIT_FALSE((mp_valid<add_extents, int&>));
95 #endif
96 BOOST_TEST_TRAIT_FALSE((mp_valid<add_extents, int, int>));
97
98 return boost::report_errors();
99 }
100