• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 // Copyright 2015-2017 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/integral.hpp>
12 #include <boost/mp11/detail/config.hpp>
13 #include <boost/core/lightweight_test_trait.hpp>
14 #include <type_traits>
15 
16 using boost::mp11::mp_identity;
17 using boost::mp11::mp_true;
18 using boost::mp11::mp_false;
19 
20 template<class T> struct has_type
21 {
22     template<class U> static mp_true f( mp_identity<typename U::type>* );
23     template<class U> static mp_false f( ... );
24 
25     using type = decltype( f<T>(0) );
26 
27     static const bool value = type::value;
28 };
29 
30 using boost::mp11::mp_defer;
31 
32 template<class T> using add_pointer = T*;
33 template<class... T> using add_pointer_impl = mp_defer<add_pointer, T...>;
34 
35 using boost::mp11::mp_quote;
36 
37 using Q_add_pointer = mp_quote<add_pointer>;
38 template<class... T> using Q_add_pointer_impl = mp_defer<Q_add_pointer::fn, T...>;
39 
main()40 int main()
41 {
42     BOOST_TEST_TRAIT_TRUE((has_type<add_pointer_impl<void>>));
43     BOOST_TEST_TRAIT_TRUE((std::is_same<add_pointer_impl<void>::type, void*>));
44 
45     BOOST_TEST_TRAIT_TRUE((has_type<add_pointer_impl<int>>));
46     BOOST_TEST_TRAIT_TRUE((std::is_same<add_pointer_impl<int>::type, int*>));
47 
48     BOOST_TEST_TRAIT_FALSE((has_type<add_pointer_impl<>>));
49     BOOST_TEST_TRAIT_FALSE((has_type<add_pointer_impl<void, void>>));
50 
51 #if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, <= 1800 )
52     BOOST_TEST_TRAIT_TRUE((has_type<Q_add_pointer_impl<void>>));
53 #endif
54     BOOST_TEST_TRAIT_TRUE((std::is_same<Q_add_pointer_impl<void>::type, void*>));
55 
56 #if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, <= 1800 )
57     BOOST_TEST_TRAIT_TRUE((has_type<Q_add_pointer_impl<int>>));
58 #endif
59     BOOST_TEST_TRAIT_TRUE((std::is_same<Q_add_pointer_impl<int>::type, int*>));
60 
61     BOOST_TEST_TRAIT_FALSE((has_type<Q_add_pointer_impl<>>));
62     BOOST_TEST_TRAIT_FALSE((has_type<Q_add_pointer_impl<void, void>>));
63 
64     return boost::report_errors();
65 }
66