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