pointee.hpp 1.8 KB

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