pointee.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef BOOST_POINTEE_DWA200415_HPP
  2. #define BOOST_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 <iterator>
  15. #include <type_traits>
  16. #include <boost/detail/is_incrementable.hpp>
  17. namespace boost {
  18. namespace detail {
  19. template< typename P >
  20. struct smart_ptr_pointee
  21. {
  22. using type = typename P::element_type;
  23. };
  24. template<
  25. typename Iterator,
  26. typename = typename std::remove_reference< decltype(*std::declval< Iterator& >()) >::type
  27. >
  28. struct iterator_pointee
  29. {
  30. using type = typename std::iterator_traits< Iterator >::value_type;
  31. };
  32. template< typename Iterator, typename Reference >
  33. struct iterator_pointee< Iterator, const Reference >
  34. {
  35. using type = typename std::add_const< typename std::iterator_traits< Iterator >::value_type >::type;
  36. };
  37. } // namespace detail
  38. template< typename P >
  39. struct pointee :
  40. public std::conditional<
  41. detail::is_incrementable< P >::value,
  42. detail::iterator_pointee< P >,
  43. detail::smart_ptr_pointee< P >
  44. >::type
  45. {
  46. };
  47. template< typename P >
  48. using pointee_t = typename pointee< P >::type;
  49. } // namespace boost
  50. #endif // BOOST_POINTEE_DWA200415_HPP