1 #ifndef POINTEE_DWA200415_HPP 2 # define POINTEE_DWA200415_HPP 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 <boost/detail/is_incrementable.hpp> 17 # include <boost/iterator/iterator_traits.hpp> 18 # include <boost/type_traits/add_const.hpp> 19 # include <boost/type_traits/remove_cv.hpp> 20 # include <boost/mpl/if.hpp> 21 # include <boost/mpl/eval_if.hpp> 22 23 #include <iterator> 24 25 namespace boost { 26 27 namespace detail 28 { 29 template <class P> 30 struct smart_ptr_pointee 31 { 32 typedef typename P::element_type type; 33 }; 34 35 template <class Iterator> 36 struct iterator_pointee 37 { 38 typedef typename std::iterator_traits<Iterator>::value_type value_type; 39 40 struct impl 41 { 42 template <class T> 43 static char test(T const&); 44 45 static char (& test(value_type&) )[2]; 46 47 static Iterator& x; 48 }; 49 50 BOOST_STATIC_CONSTANT(bool, is_constant = sizeof(impl::test(*impl::x)) == 1); 51 52 typedef typename mpl::if_c< 53 # if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x551)) 54 ::boost::detail::iterator_pointee<Iterator>::is_constant 55 # else 56 is_constant 57 # endif 58 , typename add_const<value_type>::type 59 , value_type 60 >::type type; 61 }; 62 } 63 64 template <class P> 65 struct pointee 66 : mpl::eval_if< 67 detail::is_incrementable<P> 68 , detail::iterator_pointee<P> 69 , detail::smart_ptr_pointee<P> 70 > 71 { 72 }; 73 74 } // namespace boost 75 76 #endif // POINTEE_DWA200415_HPP 77