has_range_iterator.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2010. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see http://www.boost.org/libs/range/
  9. //
  10. // Acknowledgments:
  11. // Ticket #8341: Arno Schoedl - improved handling of has_range_iterator upon
  12. // use-cases where T was const.
  13. #ifndef BOOST_RANGE_HAS_ITERATOR_HPP_INCLUDED
  14. #define BOOST_RANGE_HAS_ITERATOR_HPP_INCLUDED
  15. #include <boost/mpl/bool.hpp>
  16. #include <boost/mpl/eval_if.hpp>
  17. #include <boost/mpl/has_xxx.hpp>
  18. #include <boost/range/iterator.hpp>
  19. #include <boost/type_traits/remove_reference.hpp>
  20. #include <boost/utility/enable_if.hpp>
  21. namespace boost
  22. {
  23. namespace range_detail
  24. {
  25. BOOST_MPL_HAS_XXX_TRAIT_DEF(type)
  26. template<class T, class Enabler = void>
  27. struct has_range_iterator_impl
  28. : boost::mpl::false_
  29. {
  30. };
  31. template<class T>
  32. struct has_range_iterator_impl<
  33. T,
  34. BOOST_DEDUCED_TYPENAME ::boost::enable_if<
  35. BOOST_DEDUCED_TYPENAME mpl::eval_if<is_const<T>,
  36. has_type<boost::range_const_iterator<
  37. BOOST_DEDUCED_TYPENAME remove_const<T>::type> >,
  38. has_type<boost::range_mutable_iterator<T> >
  39. >::type
  40. >::type
  41. >
  42. : boost::mpl::true_
  43. {
  44. };
  45. template<class T, class Enabler = void>
  46. struct has_range_const_iterator_impl
  47. : boost::mpl::false_
  48. {
  49. };
  50. template<class T>
  51. struct has_range_const_iterator_impl<
  52. T,
  53. BOOST_DEDUCED_TYPENAME ::boost::enable_if<
  54. has_type<boost::range_const_iterator<T> >
  55. >::type
  56. >
  57. : boost::mpl::true_
  58. {
  59. };
  60. } // namespace range_detail
  61. template<class T>
  62. struct has_range_iterator
  63. : range_detail::has_range_iterator_impl<
  64. BOOST_DEDUCED_TYPENAME remove_reference<T>::type>
  65. {};
  66. template<class T>
  67. struct has_range_const_iterator
  68. : range_detail::has_range_const_iterator_impl<
  69. BOOST_DEDUCED_TYPENAME remove_reference<T>::type>
  70. {};
  71. } // namespace boost
  72. #endif // include guard