indirect_reference.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef BOOST_INDIRECT_REFERENCE_DWA200415_HPP
  2. #define BOOST_INDIRECT_REFERENCE_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 indirect_reference<P>::type provides the type of *p.
  9. //
  10. // http://www.boost.org/libs/iterator/doc/pointee.html
  11. //
  12. #include <type_traits>
  13. #include <boost/detail/is_incrementable.hpp>
  14. #include <boost/iterator/iterator_traits.hpp>
  15. #include <boost/pointee.hpp>
  16. namespace boost {
  17. namespace detail {
  18. template< typename P >
  19. struct smart_ptr_reference
  20. {
  21. using type = boost::pointee_t< P >&;
  22. };
  23. } // namespace detail
  24. template< typename P >
  25. struct indirect_reference :
  26. std::conditional<
  27. detail::is_incrementable< P >::value,
  28. iterator_reference< P >,
  29. detail::smart_ptr_reference< P >
  30. >::type
  31. {
  32. };
  33. template< typename P >
  34. using indirect_reference_t = typename indirect_reference< P >::type;
  35. } // namespace boost
  36. #endif // BOOST_INDIRECT_REFERENCE_DWA200415_HPP