iterator_category.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. *
  3. * Copyright (c) 2002
  4. * John Maddock
  5. *
  6. * Use, modification and distribution are subject to the
  7. * Boost Software License, Version 1.0. (See accompanying file
  8. * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. *
  10. */
  11. /*
  12. * LOCATION: see http://www.boost.org for most recent version.
  13. * FILE regex_match.hpp
  14. * VERSION see <boost/version.hpp>
  15. * DESCRIPTION: Iterator traits for selecting an iterator type as
  16. * an integral constant expression.
  17. */
  18. #ifndef BOOST_REGEX_ITERATOR_CATEGORY_HPP
  19. #define BOOST_REGEX_ITERATOR_CATEGORY_HPP
  20. #include <iterator>
  21. #include <boost/type_traits/is_convertible.hpp>
  22. #include <boost/type_traits/is_pointer.hpp>
  23. namespace boost{
  24. namespace detail{
  25. template <class I>
  26. struct is_random_imp
  27. {
  28. #ifndef BOOST_NO_STD_ITERATOR_TRAITS
  29. private:
  30. typedef typename std::iterator_traits<I>::iterator_category cat;
  31. public:
  32. BOOST_STATIC_CONSTANT(bool, value = (::boost::is_convertible<cat*, std::random_access_iterator_tag*>::value));
  33. #else
  34. BOOST_STATIC_CONSTANT(bool, value = false);
  35. #endif
  36. };
  37. template <class I>
  38. struct is_random_pointer_imp
  39. {
  40. BOOST_STATIC_CONSTANT(bool, value = true);
  41. };
  42. template <bool is_pointer_type>
  43. struct is_random_imp_selector
  44. {
  45. template <class I>
  46. struct rebind
  47. {
  48. typedef is_random_imp<I> type;
  49. };
  50. };
  51. template <>
  52. struct is_random_imp_selector<true>
  53. {
  54. template <class I>
  55. struct rebind
  56. {
  57. typedef is_random_pointer_imp<I> type;
  58. };
  59. };
  60. }
  61. template <class I>
  62. struct is_random_access_iterator
  63. {
  64. private:
  65. typedef detail::is_random_imp_selector< ::boost::is_pointer<I>::value> selector;
  66. typedef typename selector::template rebind<I> bound_type;
  67. typedef typename bound_type::type answer;
  68. public:
  69. BOOST_STATIC_CONSTANT(bool, value = answer::value);
  70. };
  71. #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
  72. template <class I>
  73. const bool is_random_access_iterator<I>::value;
  74. #endif
  75. }
  76. #endif