iterator_category.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 <type_traits>
  22. namespace boost{
  23. namespace detail{
  24. template <class I>
  25. struct is_random_imp
  26. {
  27. private:
  28. typedef typename std::iterator_traits<I>::iterator_category cat;
  29. public:
  30. static const bool value = (std::is_convertible<cat*, std::random_access_iterator_tag*>::value);
  31. };
  32. template <class I>
  33. struct is_random_pointer_imp
  34. {
  35. static const bool value = true;
  36. };
  37. template <bool is_pointer_type>
  38. struct is_random_imp_selector
  39. {
  40. template <class I>
  41. struct rebind
  42. {
  43. typedef is_random_imp<I> type;
  44. };
  45. };
  46. template <>
  47. struct is_random_imp_selector<true>
  48. {
  49. template <class I>
  50. struct rebind
  51. {
  52. typedef is_random_pointer_imp<I> type;
  53. };
  54. };
  55. }
  56. template <class I>
  57. struct is_random_access_iterator
  58. {
  59. private:
  60. typedef detail::is_random_imp_selector< std::is_pointer<I>::value> selector;
  61. typedef typename selector::template rebind<I> bound_type;
  62. typedef typename bound_type::type answer;
  63. public:
  64. static const bool value = answer::value;
  65. };
  66. template <class I>
  67. const bool is_random_access_iterator<I>::value;
  68. }
  69. #endif