Jeff Thompson | 2491bd6 | 2013-10-15 17:10:24 -0700 | [diff] [blame] | 1 | #ifndef POINTEE_NDNBOOST_DWA200415_HPP |
| 2 | # define POINTEE_NDNBOOST_DWA200415_HPP |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 3 | |
| 4 | // |
| 5 | // Copyright David Abrahams 2004. Use, modification and distribution is |
| 6 | // subject to the Boost Software License, Version 1.0. (See accompanying |
| 7 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 8 | // |
| 9 | // typename pointee<P>::type provides the pointee type of P. |
| 10 | // |
| 11 | // For example, it is T for T* and X for shared_ptr<X>. |
| 12 | // |
| 13 | // http://www.boost.org/libs/iterator/doc/pointee.html |
| 14 | // |
| 15 | |
| 16 | # include <ndnboost/detail/is_incrementable.hpp> |
| 17 | # include <ndnboost/iterator/iterator_traits.hpp> |
| 18 | # include <ndnboost/type_traits/add_const.hpp> |
| 19 | # include <ndnboost/type_traits/remove_cv.hpp> |
| 20 | # include <ndnboost/mpl/if.hpp> |
| 21 | # include <ndnboost/mpl/eval_if.hpp> |
| 22 | |
| 23 | namespace ndnboost { |
| 24 | |
| 25 | namespace detail |
| 26 | { |
| 27 | template <class P> |
| 28 | struct smart_ptr_pointee |
| 29 | { |
| 30 | typedef typename P::element_type type; |
| 31 | }; |
| 32 | |
| 33 | template <class Iterator> |
| 34 | struct iterator_pointee |
| 35 | { |
| 36 | typedef typename iterator_traits<Iterator>::value_type value_type; |
| 37 | |
| 38 | struct impl |
| 39 | { |
| 40 | template <class T> |
| 41 | static char test(T const&); |
| 42 | |
| 43 | static char (& test(value_type&) )[2]; |
| 44 | |
| 45 | static Iterator& x; |
| 46 | }; |
| 47 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 48 | NDNBOOST_STATIC_CONSTANT(bool, is_constant = sizeof(impl::test(*impl::x)) == 1); |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 49 | |
| 50 | typedef typename mpl::if_c< |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 51 | # if NDNBOOST_WORKAROUND(__BORLANDC__, NDNBOOST_TESTED_AT(0x551)) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 52 | ::ndnboost::detail::iterator_pointee<Iterator>::is_constant |
| 53 | # else |
| 54 | is_constant |
| 55 | # endif |
| 56 | , typename add_const<value_type>::type |
| 57 | , value_type |
| 58 | >::type type; |
| 59 | }; |
| 60 | } |
| 61 | |
| 62 | template <class P> |
| 63 | struct pointee |
| 64 | : mpl::eval_if< |
| 65 | detail::is_incrementable<P> |
| 66 | , detail::iterator_pointee<P> |
| 67 | , detail::smart_ptr_pointee<P> |
| 68 | > |
| 69 | { |
| 70 | }; |
| 71 | |
| 72 | } // namespace ndnboost |
| 73 | |
Jeff Thompson | 2491bd6 | 2013-10-15 17:10:24 -0700 | [diff] [blame] | 74 | #endif // POINTEE_NDNBOOST_DWA200415_HPP |