string_iterator.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #ifndef BOOST_METAPARSE_V1_IMPL_STRING_ITERATOR_HPP
  2. #define BOOST_METAPARSE_V1_IMPL_STRING_ITERATOR_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2013.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <boost/metaparse/v1/impl/string_iterator_tag.hpp>
  8. #include <boost/metaparse/v1/impl/at_c.hpp>
  9. #include <boost/mpl/iterator_tags.hpp>
  10. #include <boost/mpl/int.hpp>
  11. #include <boost/mpl/bool.hpp>
  12. #include <boost/type_traits/is_same.hpp>
  13. namespace boost
  14. {
  15. namespace metaparse
  16. {
  17. namespace v1
  18. {
  19. namespace impl
  20. {
  21. // string_iterator
  22. template <class S, int N>
  23. struct string_iterator
  24. {
  25. typedef string_iterator type;
  26. typedef string_iterator_tag tag;
  27. typedef boost::mpl::random_access_iterator_tag category;
  28. };
  29. // advance_c
  30. template <class S, int N>
  31. struct advance_c;
  32. template <class S, int N, int P>
  33. struct advance_c<string_iterator<S, N>, P> :
  34. string_iterator<S, N + P>
  35. {};
  36. // distance
  37. template <class A, class B>
  38. struct distance;
  39. template <class S, int A, int B>
  40. struct distance<string_iterator<S, A>, string_iterator<S, B> > :
  41. boost::mpl::int_<B - A>
  42. {};
  43. }
  44. }
  45. }
  46. }
  47. namespace boost
  48. {
  49. namespace mpl
  50. {
  51. // advance
  52. template <class S>
  53. struct advance_impl;
  54. template <>
  55. struct advance_impl<boost::metaparse::v1::impl::string_iterator_tag>
  56. {
  57. typedef advance_impl type;
  58. template <class S, class N>
  59. struct apply :
  60. boost::metaparse::v1::impl::advance_c<
  61. typename S::type, N::type::value
  62. >
  63. {};
  64. };
  65. // distance
  66. template <class S>
  67. struct distance_impl;
  68. template <>
  69. struct distance_impl<boost::metaparse::v1::impl::string_iterator_tag>
  70. {
  71. typedef distance_impl type;
  72. template <class A, class B>
  73. struct apply :
  74. boost::metaparse::v1::impl::distance<
  75. typename A::type,
  76. typename B::type
  77. >
  78. {};
  79. };
  80. // next
  81. template <class S>
  82. struct next;
  83. template <class S, int N>
  84. struct next<boost::metaparse::v1::impl::string_iterator<S, N> > :
  85. boost::metaparse::v1::impl::string_iterator<S, N + 1>
  86. {};
  87. // prior
  88. template <class S>
  89. struct prior;
  90. template <class S, int N>
  91. struct prior<boost::metaparse::v1::impl::string_iterator<S, N> > :
  92. boost::metaparse::v1::impl::string_iterator<S, N - 1>
  93. {};
  94. // deref
  95. template <class S>
  96. struct deref;
  97. template <class S, int N>
  98. struct deref<boost::metaparse::v1::impl::string_iterator<S, N> > :
  99. boost::metaparse::v1::impl::at_c<S, N>
  100. {};
  101. // equal_to
  102. template <class A, class B>
  103. struct equal_to_impl;
  104. template <>
  105. struct equal_to_impl<
  106. boost::metaparse::v1::impl::string_iterator_tag,
  107. boost::metaparse::v1::impl::string_iterator_tag
  108. >
  109. {
  110. typedef equal_to_impl type;
  111. template <class A, class B>
  112. struct apply : is_same<typename A::type, typename B::type> {};
  113. };
  114. template <class T>
  115. struct equal_to_impl<boost::metaparse::v1::impl::string_iterator_tag, T>
  116. {
  117. typedef equal_to_impl type;
  118. template <class, class>
  119. struct apply : false_ {};
  120. };
  121. template <class T>
  122. struct equal_to_impl<T, boost::metaparse::v1::impl::string_iterator_tag> :
  123. equal_to_impl<boost::metaparse::v1::impl::string_iterator_tag, T>
  124. {};
  125. }
  126. }
  127. #endif