1 | |
2 | #ifndef BOOST_MPL_MAP_AUX_ITERATOR_HPP_INCLUDED |
3 | #define BOOST_MPL_MAP_AUX_ITERATOR_HPP_INCLUDED |
4 | |
5 | // Copyright Aleksey Gurtovoy 2003-2004 |
6 | // Copyright David Abrahams 2003-2004 |
7 | // |
8 | // Distributed under the Boost Software License, Version 1.0. |
9 | // (See accompanying file LICENSE_1_0.txt or copy at |
10 | // http://www.boost.org/LICENSE_1_0.txt) |
11 | // |
12 | // See http://www.boost.org/libs/mpl for documentation. |
13 | |
14 | // $Id$ |
15 | // $Date$ |
16 | // $Revision$ |
17 | |
18 | #include <boost/mpl/map/aux_/map0.hpp> |
19 | #include <boost/mpl/map/aux_/at_impl.hpp> |
20 | #include <boost/mpl/map/aux_/tag.hpp> |
21 | #include <boost/mpl/iterator_tags.hpp> |
22 | #include <boost/mpl/if.hpp> |
23 | #include <boost/mpl/next.hpp> |
24 | #include <boost/mpl/deref.hpp> |
25 | #include <boost/mpl/long.hpp> |
26 | #include <boost/mpl/void.hpp> |
27 | #include <boost/mpl/aux_/nttp_decl.hpp> |
28 | #include <boost/mpl/aux_/config/ctps.hpp> |
29 | |
30 | namespace boost { namespace mpl { |
31 | |
32 | #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) |
33 | |
34 | template< |
35 | typename Map |
36 | , long order |
37 | , long max_order |
38 | > |
39 | struct next_order |
40 | : if_< |
41 | is_void_< typename item_by_order<Map,order>::type > |
42 | , next_order<Map,(order+1),max_order> |
43 | , long_<order> |
44 | >::type |
45 | { |
46 | }; |
47 | |
48 | template< |
49 | typename Map |
50 | , long max_order |
51 | > |
52 | struct next_order<Map,max_order,max_order> |
53 | : long_<max_order> |
54 | { |
55 | }; |
56 | |
57 | |
58 | template< typename Map, long order, long max_order > |
59 | struct m_iter |
60 | { |
61 | typedef forward_iterator_tag category; |
62 | typedef typename item_by_order<Map,order>::type type; |
63 | }; |
64 | |
65 | template< typename Map, long max_order > |
66 | struct m_iter<Map,max_order,max_order> |
67 | { |
68 | typedef forward_iterator_tag category; |
69 | }; |
70 | |
71 | |
72 | template< typename Map, long order, long max_order > |
73 | struct next< m_iter<Map,order,max_order> > |
74 | { |
75 | typedef m_iter< |
76 | Map |
77 | , next_order<Map,order+1,max_order>::value |
78 | , max_order |
79 | > type; |
80 | }; |
81 | |
82 | template< typename Map, long max_order > |
83 | struct next< m_iter<Map,max_order,max_order> > |
84 | { |
85 | }; |
86 | |
87 | #else |
88 | |
89 | template< |
90 | typename Map |
91 | , BOOST_MPL_AUX_NTTP_DECL(long, order) |
92 | , BOOST_MPL_AUX_NTTP_DECL(long, max_order) |
93 | > |
94 | struct next_order; |
95 | |
96 | template< |
97 | typename Map |
98 | , BOOST_MPL_AUX_NTTP_DECL(long, order) |
99 | , BOOST_MPL_AUX_NTTP_DECL(long, max_order) |
100 | > |
101 | struct next_order_impl |
102 | : if_< |
103 | is_void_< typename item_by_order<Map,order>::type > |
104 | , next_order<Map,(order+1),max_order> |
105 | , long_<order> |
106 | >::type |
107 | { |
108 | }; |
109 | |
110 | template< |
111 | typename Map |
112 | , BOOST_MPL_AUX_NTTP_DECL(long, order) |
113 | , BOOST_MPL_AUX_NTTP_DECL(long, max_order) |
114 | > |
115 | struct next_order |
116 | : if_c< |
117 | (order != max_order) |
118 | , next_order_impl<Map,order,max_order> |
119 | , long_<order> |
120 | >::type |
121 | { |
122 | }; |
123 | |
124 | |
125 | template< |
126 | typename Map |
127 | , BOOST_MPL_AUX_NTTP_DECL(long, order) |
128 | , BOOST_MPL_AUX_NTTP_DECL(long, max_order) |
129 | > |
130 | struct m_iter; |
131 | |
132 | struct m_iter_empty_base {}; |
133 | |
134 | template< |
135 | typename Map |
136 | , BOOST_MPL_AUX_NTTP_DECL(long, order) |
137 | , BOOST_MPL_AUX_NTTP_DECL(long, max_order) |
138 | > |
139 | struct m_iter_base |
140 | { |
141 | typedef typename item_by_order<Map,order>::type type; |
142 | |
143 | typedef m_iter< |
144 | Map |
145 | , next_order<Map,order+1,max_order>::value |
146 | , max_order |
147 | > next; |
148 | }; |
149 | |
150 | template< |
151 | typename Map |
152 | , BOOST_MPL_AUX_NTTP_DECL(long, order) |
153 | , BOOST_MPL_AUX_NTTP_DECL(long, max_order) |
154 | > |
155 | struct m_iter |
156 | : if_c< |
157 | (order == max_order) |
158 | , m_iter_empty_base |
159 | , m_iter_base<Map,order,max_order> |
160 | >::type |
161 | { |
162 | typedef forward_iterator_tag category; |
163 | }; |
164 | |
165 | #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
166 | |
167 | }} |
168 | |
169 | #endif // BOOST_MPL_MAP_AUX_ITERATOR_HPP_INCLUDED |
170 | |