| 1 | /* |
|---|---|
| 2 | Copyright 2021 Glen Joseph Fernandes |
| 3 | (glenjofe@gmail.com) |
| 4 | |
| 5 | Distributed under the Boost Software License, Version 1.0. |
| 6 | (http://www.boost.org/LICENSE_1_0.txt) |
| 7 | */ |
| 8 | #include <boost/config.hpp> |
| 9 | #if !defined(BOOST_NO_CXX11_DECLTYPE_N3276) |
| 10 | #include <boost/core/pointer_traits.hpp> |
| 11 | #include <boost/core/lightweight_test.hpp> |
| 12 | |
| 13 | template<class T> |
| 14 | class has_pointer_to { |
| 15 | template<class> |
| 16 | struct result { |
| 17 | char x, y; |
| 18 | }; |
| 19 | |
| 20 | template<class O> |
| 21 | static auto check(int) -> result<decltype(O::pointer_to)>; |
| 22 | |
| 23 | template<class O> |
| 24 | static char check(long); |
| 25 | |
| 26 | public: |
| 27 | static const bool value = sizeof(check<T>(0)) > 1; |
| 28 | }; |
| 29 | |
| 30 | struct P1 { }; |
| 31 | |
| 32 | struct P2 { |
| 33 | typedef int element_type; |
| 34 | |
| 35 | static int* pointer_to(int& value) { |
| 36 | return &value; |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | struct P3 { |
| 41 | typedef void element_type; |
| 42 | }; |
| 43 | |
| 44 | struct P4 { |
| 45 | typedef int element_type; |
| 46 | }; |
| 47 | |
| 48 | struct P5 { |
| 49 | typedef int element_type; |
| 50 | |
| 51 | static int* pointer_to() { |
| 52 | return 0; |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | int main() |
| 57 | { |
| 58 | BOOST_TEST((!has_pointer_to<boost::pointer_traits<P1> >::value)); |
| 59 | BOOST_TEST(has_pointer_to<boost::pointer_traits<P2> >::value); |
| 60 | BOOST_TEST(!has_pointer_to<boost::pointer_traits<P3> >::value); |
| 61 | BOOST_TEST(!has_pointer_to<boost::pointer_traits<P4> >::value); |
| 62 | BOOST_TEST(!has_pointer_to<boost::pointer_traits<P5> >::value); |
| 63 | BOOST_TEST(has_pointer_to<boost::pointer_traits<int*> >::value); |
| 64 | BOOST_TEST(!has_pointer_to<boost::pointer_traits<void*> >::value); |
| 65 | return boost::report_errors(); |
| 66 | } |
| 67 | #else |
| 68 | int main() |
| 69 | { |
| 70 | return 0; |
| 71 | } |
| 72 | #endif |
| 73 |
