]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/iterator/test/filter_iterator_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / iterator / test / filter_iterator_test.cpp
1 // Copyright David Abrahams 2003, Jeremy Siek 2004.
2
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 #include <boost/iterator/filter_iterator.hpp>
8 #include <boost/iterator/reverse_iterator.hpp>
9 #include <boost/iterator/new_iterator_tests.hpp>
10 #include <boost/type_traits/is_convertible.hpp>
11 #include <boost/concept_check.hpp>
12 #include <boost/concept_archetype.hpp>
13 #include <boost/iterator/iterator_concepts.hpp>
14 #include <boost/iterator/iterator_archetypes.hpp>
15 #include <boost/cstdlib.hpp>
16
17 #include <deque>
18 #include <iostream>
19
20 using boost::dummyT;
21
22 struct one_or_four
23 {
24 bool operator()(dummyT x) const
25 {
26 return x.foo() == 1 || x.foo() == 4;
27 }
28 };
29
30 template <class T> struct undefined;
31
32 template <class T> struct see_type;
33
34 // Test filter iterator
35 int main()
36 {
37 // Concept checks
38 // Adapting old-style iterators
39 {
40 typedef boost::filter_iterator<one_or_four, boost::input_iterator_archetype<dummyT> > Iter;
41 boost::function_requires< boost::InputIteratorConcept<Iter> >();
42 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
43 boost::function_requires< boost_concepts::SinglePassIteratorConcept<Iter> >();
44 }
45 {
46 typedef boost::filter_iterator<one_or_four, boost::input_output_iterator_archetype<dummyT> > Iter;
47 boost::function_requires< boost::InputIteratorConcept<Iter> >();
48 boost::function_requires< boost::OutputIteratorConcept<Iter, dummyT> >();
49 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
50 boost::function_requires< boost_concepts::WritableIteratorConcept<Iter> >();
51 boost::function_requires< boost_concepts::SinglePassIteratorConcept<Iter> >();
52 }
53 {
54 typedef boost::filter_iterator<one_or_four, boost::forward_iterator_archetype<dummyT> > Iter;
55 boost::function_requires< boost::ForwardIteratorConcept<Iter> >();
56 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
57 boost::function_requires< boost_concepts::ForwardTraversalConcept<Iter> >();
58 }
59 {
60 typedef boost::filter_iterator<one_or_four, boost::mutable_forward_iterator_archetype<dummyT> > Iter;
61 boost::function_requires< boost::Mutable_ForwardIteratorConcept<Iter> >();
62 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
63 boost::function_requires< boost_concepts::WritableIteratorConcept<Iter> >();
64 boost::function_requires< boost_concepts::ForwardTraversalConcept<Iter> >();
65 }
66 {
67 typedef boost::filter_iterator<one_or_four, boost::bidirectional_iterator_archetype<dummyT> > Iter;
68 boost::function_requires< boost::BidirectionalIteratorConcept<Iter> >();
69 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
70 boost::function_requires< boost_concepts::BidirectionalTraversalConcept<Iter> >();
71 }
72 {
73 typedef boost::filter_iterator<one_or_four, boost::mutable_bidirectional_iterator_archetype<dummyT> > Iter;
74 boost::function_requires< boost::Mutable_BidirectionalIteratorConcept<Iter> >();
75 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
76 boost::function_requires< boost_concepts::WritableIteratorConcept<Iter> >();
77 boost::function_requires< boost_concepts::BidirectionalTraversalConcept<Iter> >();
78 }
79 {
80 typedef boost::filter_iterator<one_or_four, boost::random_access_iterator_archetype<dummyT> > Iter;
81 boost::function_requires< boost::BidirectionalIteratorConcept<Iter> >();
82 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
83 boost::function_requires< boost_concepts::BidirectionalTraversalConcept<Iter> >();
84 }
85 {
86 typedef boost::filter_iterator<one_or_four, boost::mutable_random_access_iterator_archetype<dummyT> > Iter;
87 boost::function_requires< boost::Mutable_BidirectionalIteratorConcept<Iter> >();
88 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
89 boost::function_requires< boost_concepts::WritableIteratorConcept<Iter> >();
90 boost::function_requires< boost_concepts::BidirectionalTraversalConcept<Iter> >();
91 }
92 // Adapting new-style iterators
93 {
94 typedef boost::iterator_archetype<
95 const dummyT
96 , boost::iterator_archetypes::readable_iterator_t
97 , boost::single_pass_traversal_tag
98 > BaseIter;
99 typedef boost::filter_iterator<one_or_four, BaseIter> Iter;
100 boost::function_requires< boost::InputIteratorConcept<Iter> >();
101 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
102 boost::function_requires< boost_concepts::SinglePassIteratorConcept<Iter> >();
103 }
104 #if !BOOST_WORKAROUND(BOOST_MSVC, == 1200) // Causes Internal Error in linker.
105 {
106 typedef boost::iterator_archetype<
107 dummyT
108 , boost::iterator_archetypes::readable_writable_iterator_t
109 , boost::single_pass_traversal_tag
110 > BaseIter;
111 typedef boost::filter_iterator<one_or_four, BaseIter> Iter;
112
113 boost::function_requires< boost::InputIteratorConcept<Iter> >();
114 boost::function_requires< boost::OutputIteratorConcept<Iter, dummyT> >();
115 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
116 boost::function_requires< boost_concepts::WritableIteratorConcept<Iter> >();
117 boost::function_requires< boost_concepts::SinglePassIteratorConcept<Iter> >();
118 }
119 #endif
120 {
121 typedef boost::iterator_archetype<
122 const dummyT
123 , boost::iterator_archetypes::readable_iterator_t
124 , boost::forward_traversal_tag
125 > BaseIter;
126 typedef boost::filter_iterator<one_or_four, BaseIter> Iter;
127 boost::function_requires< boost::InputIteratorConcept<Iter> >();
128 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
129 boost::function_requires< boost_concepts::ForwardTraversalConcept<Iter> >();
130 }
131
132 #if !BOOST_WORKAROUND(BOOST_MSVC, == 1200) // Causes Internal Error in linker.
133 {
134 typedef boost::iterator_archetype<
135 dummyT
136 , boost::iterator_archetypes::readable_writable_iterator_t
137 , boost::forward_traversal_tag
138 > BaseIter;
139 typedef boost::filter_iterator<one_or_four, BaseIter> Iter;
140 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
141 boost::function_requires< boost_concepts::WritableIteratorConcept<Iter> >();
142 boost::function_requires< boost_concepts::ForwardTraversalConcept<Iter> >();
143 }
144 {
145 typedef boost::iterator_archetype<
146 const dummyT
147 , boost::iterator_archetypes::readable_lvalue_iterator_t
148 , boost::forward_traversal_tag
149 > BaseIter;
150 typedef boost::filter_iterator<one_or_four, BaseIter> Iter;
151 boost::function_requires< boost::ForwardIteratorConcept<Iter> >();
152 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
153 boost::function_requires< boost_concepts::LvalueIteratorConcept<Iter> >();
154 boost::function_requires< boost_concepts::ForwardTraversalConcept<Iter> >();
155 }
156 {
157 typedef boost::iterator_archetype<
158 dummyT
159 , boost::iterator_archetypes::writable_lvalue_iterator_t
160 , boost::forward_traversal_tag
161 > BaseIter;
162 typedef boost::filter_iterator<one_or_four, BaseIter> Iter;
163 boost::function_requires< boost::Mutable_ForwardIteratorConcept<Iter> >();
164 boost::function_requires< boost_concepts::WritableIteratorConcept<Iter> >();
165 boost::function_requires< boost_concepts::LvalueIteratorConcept<Iter> >();
166 boost::function_requires< boost_concepts::ForwardTraversalConcept<Iter> >();
167 }
168 #endif
169
170 {
171 typedef boost::iterator_archetype<
172 const dummyT
173 , boost::iterator_archetypes::readable_iterator_t
174 , boost::random_access_traversal_tag
175 > BaseIter;
176 typedef boost::filter_iterator<one_or_four, BaseIter> Iter;
177 boost::function_requires< boost::InputIteratorConcept<Iter> >();
178 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
179 boost::function_requires< boost_concepts::BidirectionalTraversalConcept<Iter> >();
180 }
181
182 #if !BOOST_WORKAROUND(BOOST_MSVC, == 1200) // Causes Internal Error in linker.
183 {
184 typedef boost::iterator_archetype<
185 dummyT
186 , boost::iterator_archetypes::readable_writable_iterator_t
187 , boost::random_access_traversal_tag
188 > BaseIter;
189 typedef boost::filter_iterator<one_or_four, BaseIter> Iter;
190 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
191 boost::function_requires< boost_concepts::WritableIteratorConcept<Iter> >();
192 boost::function_requires< boost_concepts::BidirectionalTraversalConcept<Iter> >();
193 }
194 {
195 typedef boost::iterator_archetype<
196 const dummyT
197 , boost::iterator_archetypes::readable_lvalue_iterator_t
198 , boost::random_access_traversal_tag
199 > BaseIter;
200 typedef boost::filter_iterator<one_or_four, BaseIter> Iter;
201 boost::function_requires< boost::BidirectionalIteratorConcept<Iter> >();
202 boost::function_requires< boost_concepts::ReadableIteratorConcept<Iter> >();
203 boost::function_requires< boost_concepts::LvalueIteratorConcept<Iter> >();
204 boost::function_requires< boost_concepts::BidirectionalTraversalConcept<Iter> >();
205 }
206 {
207 typedef boost::iterator_archetype<
208 dummyT
209 , boost::iterator_archetypes::writable_lvalue_iterator_t
210 , boost::random_access_traversal_tag
211 > BaseIter;
212 typedef boost::filter_iterator<one_or_four, BaseIter> Iter;
213 boost::function_requires< boost::Mutable_BidirectionalIteratorConcept<Iter> >();
214 boost::function_requires< boost_concepts::WritableIteratorConcept<Iter> >();
215 boost::function_requires< boost_concepts::LvalueIteratorConcept<Iter> >();
216 boost::function_requires< boost_concepts::BidirectionalTraversalConcept<Iter> >();
217 }
218 #endif
219
220 // Run-time tests
221
222 dummyT array[] = { dummyT(0), dummyT(1), dummyT(2),
223 dummyT(3), dummyT(4), dummyT(5) };
224 const int N = sizeof(array)/sizeof(dummyT);
225
226 typedef boost::filter_iterator<one_or_four, dummyT*> filter_iter;
227
228 boost::bidirectional_readable_iterator_test(
229 filter_iter(one_or_four(), array, array+N)
230 , dummyT(1), dummyT(4));
231
232 BOOST_STATIC_ASSERT(
233 (!boost::is_convertible<
234 boost::iterator_traversal<filter_iter>::type
235 , boost::random_access_traversal_tag
236 >::value
237 ));
238
239 //# endif
240
241 // On compilers not supporting partial specialization, we can do more type
242 // deduction with deque iterators than with pointers... unless the library
243 // is broken ;-(
244 std::deque<dummyT> array2;
245 std::copy(array+0, array+N, std::back_inserter(array2));
246 boost::bidirectional_readable_iterator_test(
247 boost::make_filter_iterator(one_or_four(), array2.begin(), array2.end()),
248 dummyT(1), dummyT(4));
249
250 boost::bidirectional_readable_iterator_test(
251 boost::make_filter_iterator(one_or_four(), array2.begin(), array2.end()),
252 dummyT(1), dummyT(4));
253
254 boost::bidirectional_readable_iterator_test(
255 boost::make_filter_iterator(
256 one_or_four()
257 , boost::make_reverse_iterator(array2.end())
258 , boost::make_reverse_iterator(array2.begin())
259 ),
260 dummyT(4), dummyT(1));
261
262 boost::bidirectional_readable_iterator_test(
263 filter_iter(array+0, array+N),
264 dummyT(1), dummyT(4));
265
266 boost::bidirectional_readable_iterator_test(
267 filter_iter(one_or_four(), array, array + N),
268 dummyT(1), dummyT(4));
269
270
271 return boost::report_errors();
272 }