is_readable_iterator.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright David Abrahams 2003. Use, modification and distribution is
  2. // subject to the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef IS_READABLE_ITERATOR_DWA2003112_HPP
  5. # define IS_READABLE_ITERATOR_DWA2003112_HPP
  6. #include <boost/mpl/bool.hpp>
  7. #include <boost/mpl/aux_/lambda_support.hpp>
  8. #include <boost/type_traits/add_lvalue_reference.hpp>
  9. #include <boost/iterator/detail/any_conversion_eater.hpp>
  10. #include <iterator>
  11. // should be the last #include
  12. #include <boost/type_traits/integral_constant.hpp>
  13. #include <boost/iterator/detail/config_def.hpp>
  14. #ifndef BOOST_NO_IS_CONVERTIBLE
  15. namespace boost {
  16. namespace iterators {
  17. namespace detail
  18. {
  19. // Guts of is_readable_iterator. Value is the iterator's value_type
  20. // and the result is computed in the nested rebind template.
  21. template <class Value>
  22. struct is_readable_iterator_impl
  23. {
  24. static char tester(typename add_lvalue_reference<Value>::type, int);
  25. static char (& tester(any_conversion_eater, ...) )[2];
  26. template <class It>
  27. struct rebind
  28. {
  29. static It& x;
  30. BOOST_STATIC_CONSTANT(
  31. bool
  32. , value = (
  33. sizeof(
  34. is_readable_iterator_impl<Value>::tester(*x, 1)
  35. ) == 1
  36. )
  37. );
  38. };
  39. };
  40. #undef BOOST_READABLE_PRESERVER
  41. //
  42. // void specializations to handle std input and output iterators
  43. //
  44. template <>
  45. struct is_readable_iterator_impl<void>
  46. {
  47. template <class It>
  48. struct rebind : boost::mpl::false_
  49. {};
  50. };
  51. #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
  52. template <>
  53. struct is_readable_iterator_impl<const void>
  54. {
  55. template <class It>
  56. struct rebind : boost::mpl::false_
  57. {};
  58. };
  59. template <>
  60. struct is_readable_iterator_impl<volatile void>
  61. {
  62. template <class It>
  63. struct rebind : boost::mpl::false_
  64. {};
  65. };
  66. template <>
  67. struct is_readable_iterator_impl<const volatile void>
  68. {
  69. template <class It>
  70. struct rebind : boost::mpl::false_
  71. {};
  72. };
  73. #endif
  74. //
  75. // This level of dispatching is required for Borland. We might save
  76. // an instantiation by removing it for others.
  77. //
  78. template <class It>
  79. struct is_readable_iterator_impl2
  80. : is_readable_iterator_impl<
  81. BOOST_DEDUCED_TYPENAME std::iterator_traits<It>::value_type const
  82. >::template rebind<It>
  83. {};
  84. } // namespace detail
  85. template< typename T > struct is_readable_iterator
  86. : public ::boost::integral_constant<bool,::boost::iterators::detail::is_readable_iterator_impl2<T>::value>
  87. {
  88. public:
  89. BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_readable_iterator,(T))
  90. };
  91. } // namespace iterators
  92. using iterators::is_readable_iterator;
  93. } // namespace boost
  94. #endif
  95. #include <boost/iterator/detail/config_undef.hpp>
  96. #endif // IS_READABLE_ITERATOR_DWA2003112_HPP