pointee.hpp 1.8 KB

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