]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | // Copyright (C) 2019 T. Zachary Laine |
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 | #include <boost/stl_interfaces/iterator_interface.hpp> | |
7 | ||
8 | #include "ill_formed.hpp" | |
9 | ||
10 | #include <boost/core/lightweight_test.hpp> | |
11 | ||
12 | #include <algorithm> | |
13 | #include <array> | |
1e59de90 | 14 | #include <functional> |
20effc67 TL |
15 | #include <numeric> |
16 | #include <list> | |
17 | #include <type_traits> | |
18 | ||
19 | ||
20 | struct basic_bidirectional_iter : boost::stl_interfaces::iterator_interface< | |
21 | basic_bidirectional_iter, | |
22 | std::bidirectional_iterator_tag, | |
23 | int> | |
24 | { | |
25 | basic_bidirectional_iter() : it_(nullptr) {} | |
26 | basic_bidirectional_iter(int * it) : it_(it) {} | |
27 | ||
28 | int & operator*() const { return *it_; } | |
29 | basic_bidirectional_iter & operator++() | |
30 | { | |
31 | ++it_; | |
32 | return *this; | |
33 | } | |
34 | basic_bidirectional_iter & operator--() | |
35 | { | |
36 | --it_; | |
37 | return *this; | |
38 | } | |
39 | friend bool operator==( | |
40 | basic_bidirectional_iter lhs, basic_bidirectional_iter rhs) noexcept | |
41 | { | |
42 | return lhs.it_ == rhs.it_; | |
43 | } | |
44 | ||
45 | using base_type = boost::stl_interfaces::iterator_interface< | |
46 | basic_bidirectional_iter, | |
47 | std::bidirectional_iterator_tag, | |
48 | int>; | |
49 | using base_type::operator++; | |
50 | using base_type::operator--; | |
51 | ||
52 | private: | |
53 | int * it_; | |
54 | }; | |
55 | ||
56 | BOOST_STL_INTERFACES_STATIC_ASSERT_CONCEPT( | |
57 | basic_bidirectional_iter, std::bidirectional_iterator) | |
58 | BOOST_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS( | |
59 | basic_bidirectional_iter, | |
60 | std::bidirectional_iterator_tag, | |
61 | std::bidirectional_iterator_tag, | |
62 | int, | |
63 | int &, | |
64 | int *, | |
65 | std::ptrdiff_t) | |
66 | ||
67 | static_assert( | |
68 | !boost::stl_interfaces::v1::v1_dtl:: | |
69 | plus_eq<basic_bidirectional_iter, std::ptrdiff_t>::value, | |
70 | ""); | |
71 | ||
72 | struct basic_adapted_bidirectional_ptr_iter | |
73 | : boost::stl_interfaces::iterator_interface< | |
74 | basic_adapted_bidirectional_ptr_iter, | |
75 | std::bidirectional_iterator_tag, | |
76 | int> | |
77 | { | |
78 | basic_adapted_bidirectional_ptr_iter() : it_(nullptr) {} | |
79 | basic_adapted_bidirectional_ptr_iter(int * it) : it_(it) {} | |
80 | ||
81 | private: | |
82 | friend boost::stl_interfaces::access; | |
83 | int *& base_reference() noexcept { return it_; } | |
84 | int * base_reference() const noexcept { return it_; } | |
85 | ||
86 | int * it_; | |
87 | }; | |
88 | ||
89 | BOOST_STL_INTERFACES_STATIC_ASSERT_CONCEPT( | |
90 | basic_adapted_bidirectional_ptr_iter, std::bidirectional_iterator) | |
91 | BOOST_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS( | |
92 | basic_adapted_bidirectional_ptr_iter, | |
93 | std::bidirectional_iterator_tag, | |
94 | std::bidirectional_iterator_tag, | |
95 | int, | |
96 | int &, | |
97 | int *, | |
98 | std::ptrdiff_t) | |
99 | ||
100 | struct basic_adapted_bidirectional_list_iter | |
101 | : boost::stl_interfaces::iterator_interface< | |
102 | basic_adapted_bidirectional_list_iter, | |
103 | std::bidirectional_iterator_tag, | |
104 | int> | |
105 | { | |
106 | basic_adapted_bidirectional_list_iter() : it_() {} | |
107 | basic_adapted_bidirectional_list_iter(std::list<int>::iterator it) : it_(it) | |
108 | {} | |
109 | ||
110 | private: | |
111 | friend boost::stl_interfaces::access; | |
112 | std::list<int>::iterator & base_reference() noexcept { return it_; } | |
113 | std::list<int>::iterator base_reference() const noexcept { return it_; } | |
114 | ||
115 | std::list<int>::iterator it_; | |
116 | }; | |
117 | ||
118 | BOOST_STL_INTERFACES_STATIC_ASSERT_CONCEPT( | |
119 | basic_adapted_bidirectional_list_iter, std::bidirectional_iterator) | |
120 | BOOST_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS( | |
121 | basic_adapted_bidirectional_list_iter, | |
122 | std::bidirectional_iterator_tag, | |
123 | std::bidirectional_iterator_tag, | |
124 | int, | |
125 | int &, | |
126 | int *, | |
127 | std::ptrdiff_t) | |
128 | ||
129 | template<typename ValueType> | |
130 | struct adapted_bidirectional_ptr_iter | |
131 | : boost::stl_interfaces::iterator_interface< | |
132 | adapted_bidirectional_ptr_iter<ValueType>, | |
133 | std::bidirectional_iterator_tag, | |
134 | ValueType> | |
135 | { | |
136 | adapted_bidirectional_ptr_iter() : it_(nullptr) {} | |
137 | adapted_bidirectional_ptr_iter(ValueType * it) : it_(it) {} | |
138 | ||
139 | template<typename ValueType2> | |
140 | adapted_bidirectional_ptr_iter( | |
141 | adapted_bidirectional_ptr_iter<ValueType2> other) : | |
142 | it_(other.it_) | |
143 | {} | |
144 | ||
145 | template<typename ValueType2> | |
146 | friend struct adapted_bidirectional_ptr_iter; | |
147 | ||
148 | private: | |
149 | friend boost::stl_interfaces::access; | |
150 | ValueType *& base_reference() noexcept { return it_; } | |
151 | ValueType * base_reference() const noexcept { return it_; } | |
152 | ||
153 | ValueType * it_; | |
154 | }; | |
155 | ||
156 | static_assert( | |
1e59de90 | 157 | !boost::stl_interfaces::v1::v1_dtl::ra_iter< |
20effc67 TL |
158 | adapted_bidirectional_ptr_iter<int>>::value, |
159 | ""); | |
160 | static_assert( | |
1e59de90 | 161 | !boost::stl_interfaces::v1::v1_dtl::ra_iter< |
20effc67 TL |
162 | adapted_bidirectional_ptr_iter<int const>>::value, |
163 | ""); | |
164 | ||
165 | BOOST_STL_INTERFACES_STATIC_ASSERT_CONCEPT( | |
166 | adapted_bidirectional_ptr_iter<int>, std::bidirectional_iterator) | |
167 | BOOST_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS( | |
168 | adapted_bidirectional_ptr_iter<int>, | |
169 | std::bidirectional_iterator_tag, | |
170 | std::bidirectional_iterator_tag, | |
171 | int, | |
172 | int &, | |
173 | int *, | |
174 | std::ptrdiff_t) | |
175 | BOOST_STL_INTERFACES_STATIC_ASSERT_CONCEPT( | |
176 | adapted_bidirectional_ptr_iter<int const>, std::bidirectional_iterator) | |
177 | BOOST_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS( | |
178 | adapted_bidirectional_ptr_iter<int const>, | |
179 | std::bidirectional_iterator_tag, | |
180 | std::bidirectional_iterator_tag, | |
181 | int, | |
182 | int const &, | |
183 | int const *, | |
184 | std::ptrdiff_t) | |
185 | ||
186 | template<typename ValueType> | |
187 | struct bidirectional_iter : boost::stl_interfaces::iterator_interface< | |
188 | bidirectional_iter<ValueType>, | |
189 | std::bidirectional_iterator_tag, | |
190 | ValueType> | |
191 | { | |
192 | bidirectional_iter() : it_(nullptr) {} | |
193 | bidirectional_iter(ValueType * it) : it_(it) {} | |
194 | template< | |
195 | typename ValueType2, | |
196 | typename E = std::enable_if_t< | |
197 | std::is_convertible<ValueType2 *, ValueType *>::value>> | |
198 | bidirectional_iter(bidirectional_iter<ValueType2> it) : it_(it.it_) | |
199 | {} | |
200 | ||
201 | ValueType & operator*() const { return *it_; } | |
202 | bidirectional_iter & operator++() | |
203 | { | |
204 | ++it_; | |
205 | return *this; | |
206 | } | |
207 | bidirectional_iter & operator--() | |
208 | { | |
209 | --it_; | |
210 | return *this; | |
211 | } | |
212 | friend bool | |
213 | operator==(bidirectional_iter lhs, bidirectional_iter rhs) noexcept | |
214 | { | |
215 | return lhs.it_ == rhs.it_; | |
216 | } | |
217 | ||
218 | using base_type = boost::stl_interfaces::iterator_interface< | |
219 | bidirectional_iter<ValueType>, | |
220 | std::bidirectional_iterator_tag, | |
221 | ValueType>; | |
222 | using base_type::operator++; | |
223 | using base_type::operator--; | |
224 | ||
225 | private: | |
226 | ValueType * it_; | |
227 | ||
228 | template<typename ValueType2> | |
229 | friend struct bidirectional_iter; | |
230 | }; | |
231 | ||
232 | using bidirectional = bidirectional_iter<int>; | |
233 | using const_bidirectional = bidirectional_iter<int const>; | |
234 | ||
235 | BOOST_STL_INTERFACES_STATIC_ASSERT_CONCEPT( | |
236 | bidirectional, std::bidirectional_iterator) | |
237 | BOOST_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS( | |
238 | bidirectional, | |
239 | std::bidirectional_iterator_tag, | |
240 | std::bidirectional_iterator_tag, | |
241 | int, | |
242 | int &, | |
243 | int *, | |
244 | std::ptrdiff_t) | |
245 | ||
246 | BOOST_STL_INTERFACES_STATIC_ASSERT_CONCEPT( | |
247 | const_bidirectional, std::bidirectional_iterator) | |
248 | BOOST_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS( | |
249 | const_bidirectional, | |
250 | std::bidirectional_iterator_tag, | |
251 | std::bidirectional_iterator_tag, | |
252 | int, | |
253 | int const &, | |
254 | int const *, | |
255 | std::ptrdiff_t) | |
256 | ||
257 | ||
258 | std::array<int, 10> ints = {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}}; | |
259 | ||
260 | ||
261 | //////////////////// | |
262 | // view_interface // | |
263 | //////////////////// | |
264 | #include "view_tests.hpp" | |
265 | ||
266 | template<typename T> | |
267 | using data_t = decltype(std::declval<T>().data()); | |
268 | ||
269 | static_assert( | |
270 | ill_formed< | |
271 | data_t, | |
272 | subrange< | |
273 | basic_bidirectional_iter, | |
274 | basic_bidirectional_iter, | |
1e59de90 | 275 | boost::stl_interfaces::element_layout::discontiguous>>::value, |
20effc67 TL |
276 | ""); |
277 | static_assert( | |
278 | ill_formed< | |
279 | data_t, | |
280 | subrange< | |
281 | basic_bidirectional_iter, | |
282 | basic_bidirectional_iter, | |
1e59de90 | 283 | boost::stl_interfaces::element_layout::discontiguous> const>:: |
20effc67 TL |
284 | value, |
285 | ""); | |
286 | ||
287 | template<typename T> | |
288 | using size_t_ = decltype(std::declval<T>().size()); | |
289 | ||
290 | static_assert( | |
291 | ill_formed< | |
292 | size_t_, | |
293 | subrange< | |
294 | basic_bidirectional_iter, | |
295 | basic_bidirectional_iter, | |
1e59de90 | 296 | boost::stl_interfaces::element_layout::discontiguous>>::value, |
20effc67 TL |
297 | ""); |
298 | static_assert( | |
299 | ill_formed< | |
300 | size_t_, | |
301 | subrange< | |
302 | basic_bidirectional_iter, | |
303 | basic_bidirectional_iter, | |
1e59de90 | 304 | boost::stl_interfaces::element_layout::discontiguous> const>:: |
20effc67 TL |
305 | value, |
306 | ""); | |
307 | ||
308 | template<typename T> | |
309 | using index_operator_t = decltype(std::declval<T>()[0]); | |
310 | ||
311 | static_assert( | |
312 | ill_formed< | |
313 | index_operator_t, | |
314 | subrange< | |
315 | basic_bidirectional_iter, | |
316 | basic_bidirectional_iter, | |
1e59de90 | 317 | boost::stl_interfaces::element_layout::discontiguous>>::value, |
20effc67 TL |
318 | ""); |
319 | static_assert( | |
320 | ill_formed< | |
321 | index_operator_t, | |
322 | subrange< | |
323 | basic_bidirectional_iter, | |
324 | basic_bidirectional_iter, | |
1e59de90 | 325 | boost::stl_interfaces::element_layout::discontiguous> const>:: |
20effc67 TL |
326 | value, |
327 | ""); | |
328 | ||
329 | ||
330 | int main() | |
331 | { | |
332 | ||
333 | { | |
334 | basic_bidirectional_iter first(ints.data()); | |
335 | basic_bidirectional_iter last(ints.data() + ints.size()); | |
336 | ||
337 | { | |
338 | std::array<int, 10> ints_copy; | |
339 | std::copy(first, last, ints_copy.begin()); | |
340 | BOOST_TEST(ints_copy == ints); | |
341 | } | |
342 | ||
343 | { | |
344 | std::array<int, 10> ints_copy; | |
345 | std::copy( | |
346 | std::make_reverse_iterator(last), | |
347 | std::make_reverse_iterator(first), | |
348 | ints_copy.begin()); | |
349 | std::reverse(ints_copy.begin(), ints_copy.end()); | |
350 | BOOST_TEST(ints_copy == ints); | |
351 | } | |
352 | ||
353 | { | |
354 | std::array<int, 10> iota_ints; | |
355 | basic_bidirectional_iter first(iota_ints.data()); | |
356 | basic_bidirectional_iter last(iota_ints.data() + iota_ints.size()); | |
357 | std::iota(first, last, 0); | |
358 | BOOST_TEST(iota_ints == ints); | |
359 | } | |
360 | ||
361 | { | |
362 | std::array<int, 10> iota_ints; | |
363 | basic_bidirectional_iter first(iota_ints.data()); | |
364 | basic_bidirectional_iter last(iota_ints.data() + iota_ints.size()); | |
365 | std::iota( | |
366 | std::make_reverse_iterator(last), | |
367 | std::make_reverse_iterator(first), | |
368 | 0); | |
369 | std::reverse(iota_ints.begin(), iota_ints.end()); | |
370 | BOOST_TEST(iota_ints == ints); | |
371 | } | |
372 | } | |
373 | ||
374 | ||
375 | { | |
376 | basic_adapted_bidirectional_ptr_iter first(ints.data()); | |
377 | basic_adapted_bidirectional_ptr_iter last(ints.data() + ints.size()); | |
378 | ||
379 | { | |
380 | std::array<int, 10> ints_copy; | |
381 | std::copy(first, last, ints_copy.begin()); | |
382 | BOOST_TEST(ints_copy == ints); | |
383 | } | |
384 | ||
385 | { | |
386 | std::array<int, 10> ints_copy; | |
387 | std::copy( | |
388 | std::make_reverse_iterator(last), | |
389 | std::make_reverse_iterator(first), | |
390 | ints_copy.begin()); | |
391 | std::reverse(ints_copy.begin(), ints_copy.end()); | |
392 | BOOST_TEST(ints_copy == ints); | |
393 | } | |
394 | ||
395 | { | |
396 | std::array<int, 10> iota_ints; | |
397 | basic_adapted_bidirectional_ptr_iter first(iota_ints.data()); | |
398 | basic_adapted_bidirectional_ptr_iter last( | |
399 | iota_ints.data() + iota_ints.size()); | |
400 | std::iota(first, last, 0); | |
401 | BOOST_TEST(iota_ints == ints); | |
402 | } | |
403 | ||
404 | { | |
405 | std::array<int, 10> iota_ints; | |
406 | basic_adapted_bidirectional_ptr_iter first(iota_ints.data()); | |
407 | basic_adapted_bidirectional_ptr_iter last( | |
408 | iota_ints.data() + iota_ints.size()); | |
409 | std::iota( | |
410 | std::make_reverse_iterator(last), | |
411 | std::make_reverse_iterator(first), | |
412 | 0); | |
413 | std::reverse(iota_ints.begin(), iota_ints.end()); | |
414 | BOOST_TEST(iota_ints == ints); | |
415 | } | |
416 | } | |
417 | ||
418 | ||
419 | { | |
420 | std::list<int> ints = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | |
421 | ||
422 | basic_adapted_bidirectional_list_iter first(ints.begin()); | |
423 | basic_adapted_bidirectional_list_iter last(ints.end()); | |
424 | ||
425 | { | |
426 | std::list<int> ints_copy; | |
427 | std::copy(first, last, std::back_inserter(ints_copy)); | |
428 | BOOST_TEST(ints_copy == ints); | |
429 | } | |
430 | ||
431 | { | |
432 | std::list<int> ints_copy; | |
433 | std::copy( | |
434 | std::make_reverse_iterator(last), | |
435 | std::make_reverse_iterator(first), | |
436 | std::back_inserter(ints_copy)); | |
437 | std::reverse(ints_copy.begin(), ints_copy.end()); | |
438 | BOOST_TEST(ints_copy == ints); | |
439 | } | |
440 | } | |
441 | ||
442 | ||
443 | { | |
444 | { | |
445 | bidirectional first(ints.data()); | |
446 | bidirectional last(ints.data() + ints.size()); | |
447 | const_bidirectional first_copy(first); | |
448 | const_bidirectional last_copy(last); | |
449 | std::equal(first, last, first_copy, last_copy); | |
450 | } | |
451 | ||
452 | { | |
453 | adapted_bidirectional_ptr_iter<int> first(ints.data()); | |
454 | adapted_bidirectional_ptr_iter<int> last(ints.data() + ints.size()); | |
455 | adapted_bidirectional_ptr_iter<int const> first_copy( | |
456 | (int const *)ints.data()); | |
457 | adapted_bidirectional_ptr_iter<int const> last_copy( | |
458 | (int const *)ints.data() + ints.size()); | |
459 | std::equal(first, last, first_copy, last_copy); | |
460 | } | |
461 | } | |
462 | ||
463 | ||
464 | { | |
465 | { | |
466 | bidirectional first(ints.data()); | |
467 | bidirectional last(ints.data() + ints.size()); | |
468 | const_bidirectional first_const(first); | |
469 | const_bidirectional last_const(last); | |
470 | ||
471 | BOOST_TEST(first == first_const); | |
472 | BOOST_TEST(first_const == first); | |
473 | BOOST_TEST(first != last_const); | |
474 | BOOST_TEST(last_const != first); | |
475 | } | |
476 | ||
477 | { | |
478 | adapted_bidirectional_ptr_iter<int> first(ints.data()); | |
479 | adapted_bidirectional_ptr_iter<int> last(ints.data() + ints.size()); | |
480 | adapted_bidirectional_ptr_iter<int const> first_const( | |
481 | (int const *)ints.data()); | |
482 | adapted_bidirectional_ptr_iter<int const> last_const( | |
483 | (int const *)ints.data() + ints.size()); | |
484 | ||
485 | static_assert( | |
1e59de90 | 486 | !boost::stl_interfaces::v1::v1_dtl::ra_iter< |
20effc67 TL |
487 | adapted_bidirectional_ptr_iter<int>>::value, |
488 | ""); | |
489 | ||
490 | BOOST_TEST(first == first_const); | |
491 | BOOST_TEST(first_const == first); | |
492 | BOOST_TEST(first != last_const); | |
493 | BOOST_TEST(last_const != first); | |
494 | } | |
495 | } | |
496 | ||
497 | ||
498 | { | |
499 | { | |
500 | bidirectional first(ints.data()); | |
501 | bidirectional last(ints.data() + ints.size()); | |
502 | while (first != last && !(first == last)) | |
503 | first++; | |
504 | } | |
505 | ||
506 | { | |
507 | bidirectional first(ints.data()); | |
508 | bidirectional last(ints.data() + ints.size()); | |
509 | while (first != last && !(first == last)) | |
510 | last--; | |
511 | } | |
512 | ||
513 | { | |
514 | basic_bidirectional_iter first(ints.data()); | |
515 | basic_bidirectional_iter last(ints.data() + ints.size()); | |
516 | while (first != last && !(first == last)) | |
517 | first++; | |
518 | } | |
519 | ||
520 | { | |
521 | basic_bidirectional_iter first(ints.data()); | |
522 | basic_bidirectional_iter last(ints.data() + ints.size()); | |
523 | while (first != last && !(first == last)) | |
524 | last--; | |
525 | } | |
526 | ||
527 | { | |
528 | basic_adapted_bidirectional_ptr_iter first(ints.data()); | |
529 | basic_adapted_bidirectional_ptr_iter last(ints.data() + ints.size()); | |
530 | while (first != last && !(first == last)) | |
531 | first++; | |
532 | } | |
533 | ||
534 | { | |
535 | basic_adapted_bidirectional_ptr_iter first(ints.data()); | |
536 | basic_adapted_bidirectional_ptr_iter last(ints.data() + ints.size()); | |
537 | while (first != last && !(first == last)) | |
538 | last--; | |
539 | } | |
540 | ||
541 | { | |
542 | std::list<int> ints = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | |
543 | basic_adapted_bidirectional_list_iter first(ints.begin()); | |
544 | basic_adapted_bidirectional_list_iter last(ints.end()); | |
545 | while (first != last && !(first == last)) | |
546 | first++; | |
547 | } | |
548 | ||
549 | { | |
550 | std::list<int> ints = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | |
551 | basic_adapted_bidirectional_list_iter first(ints.begin()); | |
552 | basic_adapted_bidirectional_list_iter last(ints.end()); | |
553 | while (first != last && !(first == last)) | |
554 | last--; | |
555 | } | |
556 | } | |
557 | ||
558 | ||
559 | { | |
560 | bidirectional first(ints.data()); | |
561 | bidirectional last(ints.data() + ints.size()); | |
562 | ||
563 | { | |
564 | std::array<int, 10> ints_copy; | |
565 | std::copy(first, last, ints_copy.begin()); | |
566 | BOOST_TEST(ints_copy == ints); | |
567 | } | |
568 | ||
569 | { | |
570 | std::array<int, 10> ints_copy; | |
571 | std::copy( | |
572 | std::make_reverse_iterator(last), | |
573 | std::make_reverse_iterator(first), | |
574 | ints_copy.begin()); | |
575 | std::reverse(ints_copy.begin(), ints_copy.end()); | |
576 | BOOST_TEST(ints_copy == ints); | |
577 | } | |
578 | ||
579 | { | |
580 | std::array<int, 10> iota_ints; | |
581 | bidirectional first(iota_ints.data()); | |
582 | bidirectional last(iota_ints.data() + iota_ints.size()); | |
583 | std::iota(first, last, 0); | |
584 | BOOST_TEST(iota_ints == ints); | |
585 | } | |
586 | ||
587 | { | |
588 | std::array<int, 10> iota_ints; | |
589 | bidirectional first(iota_ints.data()); | |
590 | bidirectional last(iota_ints.data() + iota_ints.size()); | |
591 | std::iota( | |
592 | std::make_reverse_iterator(last), | |
593 | std::make_reverse_iterator(first), | |
594 | 0); | |
595 | std::reverse(iota_ints.begin(), iota_ints.end()); | |
596 | BOOST_TEST(iota_ints == ints); | |
597 | } | |
598 | } | |
599 | ||
600 | ||
601 | { | |
602 | const_bidirectional first(ints.data()); | |
603 | const_bidirectional last(ints.data() + ints.size()); | |
604 | ||
605 | { | |
606 | std::array<int, 10> ints_copy; | |
607 | std::copy(first, last, ints_copy.begin()); | |
608 | BOOST_TEST(ints_copy == ints); | |
609 | } | |
610 | ||
611 | { | |
612 | BOOST_TEST(std::binary_search(first, last, 3)); | |
613 | BOOST_TEST(std::binary_search( | |
614 | std::make_reverse_iterator(last), | |
615 | std::make_reverse_iterator(first), | |
616 | 3, | |
617 | std::greater<>{})); | |
618 | } | |
619 | } | |
620 | ||
621 | { | |
622 | basic_bidirectional_iter first(ints.data()); | |
623 | basic_bidirectional_iter last(ints.data() + ints.size()); | |
624 | ||
1e59de90 | 625 | auto r = range<boost::stl_interfaces::element_layout::discontiguous>( |
20effc67 TL |
626 | first, last); |
627 | auto empty = | |
1e59de90 | 628 | range<boost::stl_interfaces::element_layout::discontiguous>( |
20effc67 TL |
629 | first, first); |
630 | ||
631 | // range begin/end | |
632 | { | |
633 | std::array<int, 10> ints_copy; | |
634 | std::copy(r.begin(), r.end(), ints_copy.begin()); | |
635 | BOOST_TEST(ints_copy == ints); | |
636 | ||
637 | BOOST_TEST(empty.begin() == empty.end()); | |
638 | } | |
639 | ||
640 | // empty/op bool | |
641 | { | |
642 | BOOST_TEST(!r.empty()); | |
643 | BOOST_TEST(r); | |
644 | ||
645 | BOOST_TEST(empty.empty()); | |
646 | BOOST_TEST(!empty); | |
647 | ||
648 | auto const cr = r; | |
649 | BOOST_TEST(!cr.empty()); | |
650 | BOOST_TEST(cr); | |
651 | ||
652 | auto const cempty = empty; | |
653 | BOOST_TEST(cempty.empty()); | |
654 | BOOST_TEST(!cempty); | |
655 | } | |
656 | ||
657 | // front/back | |
658 | { | |
659 | BOOST_TEST(r.front() == 0); | |
660 | BOOST_TEST(r.back() == 9); | |
661 | ||
662 | auto const cr = r; | |
663 | BOOST_TEST(cr.front() == 0); | |
664 | BOOST_TEST(cr.back() == 9); | |
665 | } | |
666 | } | |
667 | ||
668 | return boost::report_errors(); | |
669 | } |