is_readable_iterator.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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/detail/iterator.hpp>
  8. #include <boost/type_traits/detail/bool_trait_def.hpp>
  9. #include <boost/iterator/detail/any_conversion_eater.hpp>
  10. // should be the last #include
  11. #include <boost/iterator/detail/config_def.hpp>
  12. #ifndef BOOST_NO_IS_CONVERTIBLE
  13. namespace boost {
  14. namespace detail
  15. {
  16. // Guts of is_readable_iterator. Value is the iterator's value_type
  17. // and the result is computed in the nested rebind template.
  18. template <class Value>
  19. struct is_readable_iterator_impl
  20. {
  21. static char tester(Value&, int);
  22. static char (& tester(any_conversion_eater, ...) )[2];
  23. template <class It>
  24. struct rebind
  25. {
  26. static It& x;
  27. BOOST_STATIC_CONSTANT(
  28. bool
  29. , value = (
  30. sizeof(
  31. is_readable_iterator_impl<Value>::tester(*x, 1)
  32. ) == 1
  33. )
  34. );
  35. };
  36. };
  37. #undef BOOST_READABLE_PRESERVER
  38. //
  39. // void specializations to handle std input and output iterators
  40. //
  41. template <>
  42. struct is_readable_iterator_impl<void>
  43. {
  44. template <class It>
  45. struct rebind : boost::mpl::false_
  46. {};
  47. };
  48. #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
  49. template <>
  50. struct is_readable_iterator_impl<const void>
  51. {
  52. template <class It>
  53. struct rebind : boost::mpl::false_
  54. {};
  55. };
  56. template <>
  57. struct is_readable_iterator_impl<volatile void>
  58. {
  59. template <class It>
  60. struct rebind : boost::mpl::false_
  61. {};
  62. };
  63. template <>
  64. struct is_readable_iterator_impl<const volatile void>
  65. {
  66. template <class It>
  67. struct rebind : boost::mpl::false_
  68. {};
  69. };
  70. #endif
  71. //
  72. // This level of dispatching is required for Borland. We might save
  73. // an instantiation by removing it for others.
  74. //
  75. template <class It>
  76. struct is_readable_iterator_impl2
  77. : is_readable_iterator_impl<
  78. BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<It>::value_type const
  79. >::template rebind<It>
  80. {};
  81. } // namespace detail
  82. // Define the trait with full mpl lambda capability and various broken
  83. // compiler workarounds
  84. BOOST_TT_AUX_BOOL_TRAIT_DEF1(
  85. is_readable_iterator,T,::boost::detail::is_readable_iterator_impl2<T>::value)
  86. } // namespace boost
  87. #endif
  88. #include <boost/iterator/detail/config_undef.hpp>
  89. #endif // IS_READABLE_ITERATOR_DWA2003112_HPP