1 // Copyright David Abrahams 2003, Jeremy Siek 2004.
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)
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>
24 bool operator()(dummyT x
) const
26 return x
.foo() == 1 || x
.foo() == 4;
30 template <class T
> struct undefined
;
32 template <class T
> struct see_type
;
34 // Test filter iterator
38 // Adapting old-style iterators
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
> >();
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
> >();
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
> >();
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
> >();
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
> >();
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
> >();
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
> >();
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
> >();
92 // Adapting new-style iterators
94 typedef boost::iterator_archetype
<
96 , boost::iterator_archetypes::readable_iterator_t
97 , boost::single_pass_traversal_tag
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
> >();
104 #if !BOOST_WORKAROUND(BOOST_MSVC, == 1200) // Causes Internal Error in linker.
106 typedef boost::iterator_archetype
<
108 , boost::iterator_archetypes::readable_writable_iterator_t
109 , boost::single_pass_traversal_tag
111 typedef boost::filter_iterator
<one_or_four
, BaseIter
> Iter
;
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
> >();
121 typedef boost::iterator_archetype
<
123 , boost::iterator_archetypes::readable_iterator_t
124 , boost::forward_traversal_tag
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
> >();
132 #if !BOOST_WORKAROUND(BOOST_MSVC, == 1200) // Causes Internal Error in linker.
134 typedef boost::iterator_archetype
<
136 , boost::iterator_archetypes::readable_writable_iterator_t
137 , boost::forward_traversal_tag
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
> >();
145 typedef boost::iterator_archetype
<
147 , boost::iterator_archetypes::readable_lvalue_iterator_t
148 , boost::forward_traversal_tag
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
> >();
157 typedef boost::iterator_archetype
<
159 , boost::iterator_archetypes::writable_lvalue_iterator_t
160 , boost::forward_traversal_tag
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
> >();
171 typedef boost::iterator_archetype
<
173 , boost::iterator_archetypes::readable_iterator_t
174 , boost::random_access_traversal_tag
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
> >();
182 #if !BOOST_WORKAROUND(BOOST_MSVC, == 1200) // Causes Internal Error in linker.
184 typedef boost::iterator_archetype
<
186 , boost::iterator_archetypes::readable_writable_iterator_t
187 , boost::random_access_traversal_tag
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
> >();
195 typedef boost::iterator_archetype
<
197 , boost::iterator_archetypes::readable_lvalue_iterator_t
198 , boost::random_access_traversal_tag
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
> >();
207 typedef boost::iterator_archetype
<
209 , boost::iterator_archetypes::writable_lvalue_iterator_t
210 , boost::random_access_traversal_tag
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
> >();
222 dummyT array
[] = { dummyT(0), dummyT(1), dummyT(2),
223 dummyT(3), dummyT(4), dummyT(5) };
224 const int N
= sizeof(array
)/sizeof(dummyT
);
226 typedef boost::filter_iterator
<one_or_four
, dummyT
*> filter_iter
;
228 boost::bidirectional_readable_iterator_test(
229 filter_iter(one_or_four(), array
, array
+N
)
230 , dummyT(1), dummyT(4));
233 (!boost::is_convertible
<
234 boost::iterator_traversal
<filter_iter
>::type
235 , boost::random_access_traversal_tag
241 // On compilers not supporting partial specialization, we can do more type
242 // deduction with deque iterators than with pointers... unless the library
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));
250 boost::bidirectional_readable_iterator_test(
251 boost::make_filter_iterator(one_or_four(), array2
.begin(), array2
.end()),
252 dummyT(1), dummyT(4));
254 boost::bidirectional_readable_iterator_test(
255 boost::make_filter_iterator(
257 , boost::make_reverse_iterator(array2
.end())
258 , boost::make_reverse_iterator(array2
.begin())
260 dummyT(4), dummyT(1));
262 boost::bidirectional_readable_iterator_test(
263 filter_iter(array
+0, array
+N
),
264 dummyT(1), dummyT(4));
266 boost::bidirectional_readable_iterator_test(
267 filter_iter(one_or_four(), array
, array
+ N
),
268 dummyT(1), dummyT(4));
271 return boost::report_errors();