Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/container/detail/iterators.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 ////////////////////////////////////////////////////////////////////////////// | |
2 // | |
3 // (C) Copyright Ion Gaztanaga 2005-2012. | |
4 // (C) Copyright Gennaro Prota 2003 - 2004. | |
5 // | |
6 // Distributed under the Boost Software License, Version 1.0. | |
7 // (See accompanying file LICENSE_1_0.txt or copy at | |
8 // http://www.boost.org/LICENSE_1_0.txt) | |
9 // | |
10 // See http://www.boost.org/libs/container for documentation. | |
11 // | |
12 ////////////////////////////////////////////////////////////////////////////// | |
13 | |
14 #ifndef BOOST_CONTAINER_DETAIL_ITERATORS_HPP | |
15 #define BOOST_CONTAINER_DETAIL_ITERATORS_HPP | |
16 | |
17 #if defined(_MSC_VER) | |
18 # pragma once | |
19 #endif | |
20 | |
21 #include "config_begin.hpp" | |
22 #include <boost/container/detail/workaround.hpp> | |
23 #include <boost/move/utility.hpp> | |
24 #include <boost/container/allocator_traits.hpp> | |
25 #include <boost/container/detail/type_traits.hpp> | |
26 #include <boost/static_assert.hpp> | |
27 | |
28 #ifdef BOOST_CONTAINER_PERFECT_FORWARDING | |
29 #include <boost/container/detail/variadic_templates_tools.hpp> | |
30 #else | |
31 #include <boost/container/detail/preprocessor.hpp> | |
32 #endif | |
33 | |
34 #include <iterator> | |
35 | |
36 namespace boost { | |
37 namespace container { | |
38 | |
39 template <class T, class Difference = std::ptrdiff_t> | |
40 class constant_iterator | |
41 : public std::iterator | |
42 <std::random_access_iterator_tag, T, Difference, const T*, const T &> | |
43 { | |
44 typedef constant_iterator<T, Difference> this_type; | |
45 | |
46 public: | |
47 explicit constant_iterator(const T &ref, Difference range_size) | |
48 : m_ptr(&ref), m_num(range_size){} | |
49 | |
50 //Constructors | |
51 constant_iterator() | |
52 : m_ptr(0), m_num(0){} | |
53 | |
54 constant_iterator& operator++() | |
55 { increment(); return *this; } | |
56 | |
57 constant_iterator operator++(int) | |
58 { | |
59 constant_iterator result (*this); | |
60 increment(); | |
61 return result; | |
62 } | |
63 | |
64 constant_iterator& operator--() | |
65 { decrement(); return *this; } | |
66 | |
67 constant_iterator operator--(int) | |
68 { | |
69 constant_iterator result (*this); | |
70 decrement(); | |
71 return result; | |
72 } | |
73 | |
74 friend bool operator== (const constant_iterator& i, const constant_iterator& i2) | |
75 { return i.equal(i2); } | |
76 | |
77 friend bool operator!= (const constant_iterator& i, const constant_iterator& i2) | |
78 { return !(i == i2); } | |
79 | |
80 friend bool operator< (const constant_iterator& i, const constant_iterator& i2) | |
81 { return i.less(i2); } | |
82 | |
83 friend bool operator> (const constant_iterator& i, const constant_iterator& i2) | |
84 { return i2 < i; } | |
85 | |
86 friend bool operator<= (const constant_iterator& i, const constant_iterator& i2) | |
87 { return !(i > i2); } | |
88 | |
89 friend bool operator>= (const constant_iterator& i, const constant_iterator& i2) | |
90 { return !(i < i2); } | |
91 | |
92 friend Difference operator- (const constant_iterator& i, const constant_iterator& i2) | |
93 { return i2.distance_to(i); } | |
94 | |
95 //Arithmetic | |
96 constant_iterator& operator+=(Difference off) | |
97 { this->advance(off); return *this; } | |
98 | |
99 constant_iterator operator+(Difference off) const | |
100 { | |
101 constant_iterator other(*this); | |
102 other.advance(off); | |
103 return other; | |
104 } | |
105 | |
106 friend constant_iterator operator+(Difference off, const constant_iterator& right) | |
107 { return right + off; } | |
108 | |
109 constant_iterator& operator-=(Difference off) | |
110 { this->advance(-off); return *this; } | |
111 | |
112 constant_iterator operator-(Difference off) const | |
113 { return *this + (-off); } | |
114 | |
115 const T& operator*() const | |
116 { return dereference(); } | |
117 | |
118 const T& operator[] (Difference ) const | |
119 { return dereference(); } | |
120 | |
121 const T* operator->() const | |
122 { return &(dereference()); } | |
123 | |
124 private: | |
125 const T * m_ptr; | |
126 Difference m_num; | |
127 | |
128 void increment() | |
129 { --m_num; } | |
130 | |
131 void decrement() | |
132 { ++m_num; } | |
133 | |
134 bool equal(const this_type &other) const | |
135 { return m_num == other.m_num; } | |
136 | |
137 bool less(const this_type &other) const | |
138 { return other.m_num < m_num; } | |
139 | |
140 const T & dereference() const | |
141 { return *m_ptr; } | |
142 | |
143 void advance(Difference n) | |
144 { m_num -= n; } | |
145 | |
146 Difference distance_to(const this_type &other)const | |
147 { return m_num - other.m_num; } | |
148 }; | |
149 | |
150 template <class T, class Difference = std::ptrdiff_t> | |
151 class value_init_construct_iterator | |
152 : public std::iterator | |
153 <std::random_access_iterator_tag, T, Difference, const T*, const T &> | |
154 { | |
155 typedef value_init_construct_iterator<T, Difference> this_type; | |
156 | |
157 public: | |
158 explicit value_init_construct_iterator(Difference range_size) | |
159 : m_num(range_size){} | |
160 | |
161 //Constructors | |
162 value_init_construct_iterator() | |
163 : m_num(0){} | |
164 | |
165 value_init_construct_iterator& operator++() | |
166 { increment(); return *this; } | |
167 | |
168 value_init_construct_iterator operator++(int) | |
169 { | |
170 value_init_construct_iterator result (*this); | |
171 increment(); | |
172 return result; | |
173 } | |
174 | |
175 value_init_construct_iterator& operator--() | |
176 { decrement(); return *this; } | |
177 | |
178 value_init_construct_iterator operator--(int) | |
179 { | |
180 value_init_construct_iterator result (*this); | |
181 decrement(); | |
182 return result; | |
183 } | |
184 | |
185 friend bool operator== (const value_init_construct_iterator& i, const value_init_construct_iterator& i2) | |
186 { return i.equal(i2); } | |
187 | |
188 friend bool operator!= (const value_init_construct_iterator& i, const value_init_construct_iterator& i2) | |
189 { return !(i == i2); } | |
190 | |
191 friend bool operator< (const value_init_construct_iterator& i, const value_init_construct_iterator& i2) | |
192 { return i.less(i2); } | |
193 | |
194 friend bool operator> (const value_init_construct_iterator& i, const value_init_construct_iterator& i2) | |
195 { return i2 < i; } | |
196 | |
197 friend bool operator<= (const value_init_construct_iterator& i, const value_init_construct_iterator& i2) | |
198 { return !(i > i2); } | |
199 | |
200 friend bool operator>= (const value_init_construct_iterator& i, const value_init_construct_iterator& i2) | |
201 { return !(i < i2); } | |
202 | |
203 friend Difference operator- (const value_init_construct_iterator& i, const value_init_construct_iterator& i2) | |
204 { return i2.distance_to(i); } | |
205 | |
206 //Arithmetic | |
207 value_init_construct_iterator& operator+=(Difference off) | |
208 { this->advance(off); return *this; } | |
209 | |
210 value_init_construct_iterator operator+(Difference off) const | |
211 { | |
212 value_init_construct_iterator other(*this); | |
213 other.advance(off); | |
214 return other; | |
215 } | |
216 | |
217 friend value_init_construct_iterator operator+(Difference off, const value_init_construct_iterator& right) | |
218 { return right + off; } | |
219 | |
220 value_init_construct_iterator& operator-=(Difference off) | |
221 { this->advance(-off); return *this; } | |
222 | |
223 value_init_construct_iterator operator-(Difference off) const | |
224 { return *this + (-off); } | |
225 | |
226 //This pseudo-iterator's dereference operations have no sense since value is not | |
227 //constructed until ::boost::container::construct_in_place is called. | |
228 //So comment them to catch bad uses | |
229 //const T& operator*() const; | |
230 //const T& operator[](difference_type) const; | |
231 //const T* operator->() const; | |
232 | |
233 private: | |
234 Difference m_num; | |
235 | |
236 void increment() | |
237 { --m_num; } | |
238 | |
239 void decrement() | |
240 { ++m_num; } | |
241 | |
242 bool equal(const this_type &other) const | |
243 { return m_num == other.m_num; } | |
244 | |
245 bool less(const this_type &other) const | |
246 { return other.m_num < m_num; } | |
247 | |
248 const T & dereference() const | |
249 { | |
250 static T dummy; | |
251 return dummy; | |
252 } | |
253 | |
254 void advance(Difference n) | |
255 { m_num -= n; } | |
256 | |
257 Difference distance_to(const this_type &other)const | |
258 { return m_num - other.m_num; } | |
259 }; | |
260 | |
261 template <class T, class Difference = std::ptrdiff_t> | |
262 class default_init_construct_iterator | |
263 : public std::iterator | |
264 <std::random_access_iterator_tag, T, Difference, const T*, const T &> | |
265 { | |
266 typedef default_init_construct_iterator<T, Difference> this_type; | |
267 | |
268 public: | |
269 explicit default_init_construct_iterator(Difference range_size) | |
270 : m_num(range_size){} | |
271 | |
272 //Constructors | |
273 default_init_construct_iterator() | |
274 : m_num(0){} | |
275 | |
276 default_init_construct_iterator& operator++() | |
277 { increment(); return *this; } | |
278 | |
279 default_init_construct_iterator operator++(int) | |
280 { | |
281 default_init_construct_iterator result (*this); | |
282 increment(); | |
283 return result; | |
284 } | |
285 | |
286 default_init_construct_iterator& operator--() | |
287 { decrement(); return *this; } | |
288 | |
289 default_init_construct_iterator operator--(int) | |
290 { | |
291 default_init_construct_iterator result (*this); | |
292 decrement(); | |
293 return result; | |
294 } | |
295 | |
296 friend bool operator== (const default_init_construct_iterator& i, const default_init_construct_iterator& i2) | |
297 { return i.equal(i2); } | |
298 | |
299 friend bool operator!= (const default_init_construct_iterator& i, const default_init_construct_iterator& i2) | |
300 { return !(i == i2); } | |
301 | |
302 friend bool operator< (const default_init_construct_iterator& i, const default_init_construct_iterator& i2) | |
303 { return i.less(i2); } | |
304 | |
305 friend bool operator> (const default_init_construct_iterator& i, const default_init_construct_iterator& i2) | |
306 { return i2 < i; } | |
307 | |
308 friend bool operator<= (const default_init_construct_iterator& i, const default_init_construct_iterator& i2) | |
309 { return !(i > i2); } | |
310 | |
311 friend bool operator>= (const default_init_construct_iterator& i, const default_init_construct_iterator& i2) | |
312 { return !(i < i2); } | |
313 | |
314 friend Difference operator- (const default_init_construct_iterator& i, const default_init_construct_iterator& i2) | |
315 { return i2.distance_to(i); } | |
316 | |
317 //Arithmetic | |
318 default_init_construct_iterator& operator+=(Difference off) | |
319 { this->advance(off); return *this; } | |
320 | |
321 default_init_construct_iterator operator+(Difference off) const | |
322 { | |
323 default_init_construct_iterator other(*this); | |
324 other.advance(off); | |
325 return other; | |
326 } | |
327 | |
328 friend default_init_construct_iterator operator+(Difference off, const default_init_construct_iterator& right) | |
329 { return right + off; } | |
330 | |
331 default_init_construct_iterator& operator-=(Difference off) | |
332 { this->advance(-off); return *this; } | |
333 | |
334 default_init_construct_iterator operator-(Difference off) const | |
335 { return *this + (-off); } | |
336 | |
337 //This pseudo-iterator's dereference operations have no sense since value is not | |
338 //constructed until ::boost::container::construct_in_place is called. | |
339 //So comment them to catch bad uses | |
340 //const T& operator*() const; | |
341 //const T& operator[](difference_type) const; | |
342 //const T* operator->() const; | |
343 | |
344 private: | |
345 Difference m_num; | |
346 | |
347 void increment() | |
348 { --m_num; } | |
349 | |
350 void decrement() | |
351 { ++m_num; } | |
352 | |
353 bool equal(const this_type &other) const | |
354 { return m_num == other.m_num; } | |
355 | |
356 bool less(const this_type &other) const | |
357 { return other.m_num < m_num; } | |
358 | |
359 const T & dereference() const | |
360 { | |
361 static T dummy; | |
362 return dummy; | |
363 } | |
364 | |
365 void advance(Difference n) | |
366 { m_num -= n; } | |
367 | |
368 Difference distance_to(const this_type &other)const | |
369 { return m_num - other.m_num; } | |
370 }; | |
371 | |
372 | |
373 template <class T, class Difference = std::ptrdiff_t> | |
374 class repeat_iterator | |
375 : public std::iterator | |
376 <std::random_access_iterator_tag, T, Difference> | |
377 { | |
378 typedef repeat_iterator<T, Difference> this_type; | |
379 public: | |
380 explicit repeat_iterator(T &ref, Difference range_size) | |
381 : m_ptr(&ref), m_num(range_size){} | |
382 | |
383 //Constructors | |
384 repeat_iterator() | |
385 : m_ptr(0), m_num(0){} | |
386 | |
387 this_type& operator++() | |
388 { increment(); return *this; } | |
389 | |
390 this_type operator++(int) | |
391 { | |
392 this_type result (*this); | |
393 increment(); | |
394 return result; | |
395 } | |
396 | |
397 this_type& operator--() | |
398 { increment(); return *this; } | |
399 | |
400 this_type operator--(int) | |
401 { | |
402 this_type result (*this); | |
403 increment(); | |
404 return result; | |
405 } | |
406 | |
407 friend bool operator== (const this_type& i, const this_type& i2) | |
408 { return i.equal(i2); } | |
409 | |
410 friend bool operator!= (const this_type& i, const this_type& i2) | |
411 { return !(i == i2); } | |
412 | |
413 friend bool operator< (const this_type& i, const this_type& i2) | |
414 { return i.less(i2); } | |
415 | |
416 friend bool operator> (const this_type& i, const this_type& i2) | |
417 { return i2 < i; } | |
418 | |
419 friend bool operator<= (const this_type& i, const this_type& i2) | |
420 { return !(i > i2); } | |
421 | |
422 friend bool operator>= (const this_type& i, const this_type& i2) | |
423 { return !(i < i2); } | |
424 | |
425 friend Difference operator- (const this_type& i, const this_type& i2) | |
426 { return i2.distance_to(i); } | |
427 | |
428 //Arithmetic | |
429 this_type& operator+=(Difference off) | |
430 { this->advance(off); return *this; } | |
431 | |
432 this_type operator+(Difference off) const | |
433 { | |
434 this_type other(*this); | |
435 other.advance(off); | |
436 return other; | |
437 } | |
438 | |
439 friend this_type operator+(Difference off, const this_type& right) | |
440 { return right + off; } | |
441 | |
442 this_type& operator-=(Difference off) | |
443 { this->advance(-off); return *this; } | |
444 | |
445 this_type operator-(Difference off) const | |
446 { return *this + (-off); } | |
447 | |
448 T& operator*() const | |
449 { return dereference(); } | |
450 | |
451 T& operator[] (Difference ) const | |
452 { return dereference(); } | |
453 | |
454 T *operator->() const | |
455 { return &(dereference()); } | |
456 | |
457 private: | |
458 T * m_ptr; | |
459 Difference m_num; | |
460 | |
461 void increment() | |
462 { --m_num; } | |
463 | |
464 void decrement() | |
465 { ++m_num; } | |
466 | |
467 bool equal(const this_type &other) const | |
468 { return m_num == other.m_num; } | |
469 | |
470 bool less(const this_type &other) const | |
471 { return other.m_num < m_num; } | |
472 | |
473 T & dereference() const | |
474 { return *m_ptr; } | |
475 | |
476 void advance(Difference n) | |
477 { m_num -= n; } | |
478 | |
479 Difference distance_to(const this_type &other)const | |
480 { return m_num - other.m_num; } | |
481 }; | |
482 | |
483 template <class T, class EmplaceFunctor, class Difference /*= std::ptrdiff_t*/> | |
484 class emplace_iterator | |
485 : public std::iterator | |
486 <std::random_access_iterator_tag, T, Difference, const T*, const T &> | |
487 { | |
488 typedef emplace_iterator this_type; | |
489 | |
490 public: | |
491 typedef Difference difference_type; | |
492 explicit emplace_iterator(EmplaceFunctor&e) | |
493 : m_num(1), m_pe(&e){} | |
494 | |
495 emplace_iterator() | |
496 : m_num(0), m_pe(0){} | |
497 | |
498 this_type& operator++() | |
499 { increment(); return *this; } | |
500 | |
501 this_type operator++(int) | |
502 { | |
503 this_type result (*this); | |
504 increment(); | |
505 return result; | |
506 } | |
507 | |
508 this_type& operator--() | |
509 { decrement(); return *this; } | |
510 | |
511 this_type operator--(int) | |
512 { | |
513 this_type result (*this); | |
514 decrement(); | |
515 return result; | |
516 } | |
517 | |
518 friend bool operator== (const this_type& i, const this_type& i2) | |
519 { return i.equal(i2); } | |
520 | |
521 friend bool operator!= (const this_type& i, const this_type& i2) | |
522 { return !(i == i2); } | |
523 | |
524 friend bool operator< (const this_type& i, const this_type& i2) | |
525 { return i.less(i2); } | |
526 | |
527 friend bool operator> (const this_type& i, const this_type& i2) | |
528 { return i2 < i; } | |
529 | |
530 friend bool operator<= (const this_type& i, const this_type& i2) | |
531 { return !(i > i2); } | |
532 | |
533 friend bool operator>= (const this_type& i, const this_type& i2) | |
534 { return !(i < i2); } | |
535 | |
536 friend difference_type operator- (const this_type& i, const this_type& i2) | |
537 { return i2.distance_to(i); } | |
538 | |
539 //Arithmetic | |
540 this_type& operator+=(difference_type off) | |
541 { this->advance(off); return *this; } | |
542 | |
543 this_type operator+(difference_type off) const | |
544 { | |
545 this_type other(*this); | |
546 other.advance(off); | |
547 return other; | |
548 } | |
549 | |
550 friend this_type operator+(difference_type off, const this_type& right) | |
551 { return right + off; } | |
552 | |
553 this_type& operator-=(difference_type off) | |
554 { this->advance(-off); return *this; } | |
555 | |
556 this_type operator-(difference_type off) const | |
557 { return *this + (-off); } | |
558 | |
559 //This pseudo-iterator's dereference operations have no sense since value is not | |
560 //constructed until ::boost::container::construct_in_place is called. | |
561 //So comment them to catch bad uses | |
562 //const T& operator*() const; | |
563 //const T& operator[](difference_type) const; | |
564 //const T* operator->() const; | |
565 | |
566 template<class A> | |
567 void construct_in_place(A &a, T* ptr) | |
568 { (*m_pe)(a, ptr); } | |
569 | |
570 private: | |
571 difference_type m_num; | |
572 EmplaceFunctor * m_pe; | |
573 | |
574 void increment() | |
575 { --m_num; } | |
576 | |
577 void decrement() | |
578 { ++m_num; } | |
579 | |
580 bool equal(const this_type &other) const | |
581 { return m_num == other.m_num; } | |
582 | |
583 bool less(const this_type &other) const | |
584 { return other.m_num < m_num; } | |
585 | |
586 const T & dereference() const | |
587 { | |
588 static T dummy; | |
589 return dummy; | |
590 } | |
591 | |
592 void advance(difference_type n) | |
593 { m_num -= n; } | |
594 | |
595 difference_type distance_to(const this_type &other)const | |
596 { return difference_type(m_num - other.m_num); } | |
597 }; | |
598 | |
599 #ifdef BOOST_CONTAINER_PERFECT_FORWARDING | |
600 | |
601 template<class ...Args> | |
602 struct emplace_functor | |
603 { | |
604 typedef typename container_detail::build_number_seq<sizeof...(Args)>::type index_tuple_t; | |
605 | |
606 emplace_functor(Args&&... args) | |
607 : args_(args...) | |
608 {} | |
609 | |
610 template<class A, class T> | |
611 void operator()(A &a, T *ptr) | |
612 { emplace_functor::inplace_impl(a, ptr, index_tuple_t()); } | |
613 | |
614 template<class A, class T, int ...IdxPack> | |
615 void inplace_impl(A &a, T* ptr, const container_detail::index_tuple<IdxPack...>&) | |
616 { | |
617 allocator_traits<A>::construct | |
618 (a, ptr, ::boost::forward<Args>(container_detail::get<IdxPack>(args_))...); | |
619 } | |
620 | |
621 container_detail::tuple<Args&...> args_; | |
622 }; | |
623 | |
624 #else //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING | |
625 | |
626 #define BOOST_PP_LOCAL_MACRO(n) \ | |
627 BOOST_PP_EXPR_IF(n, template <) \ | |
628 BOOST_PP_ENUM_PARAMS(n, class P) \ | |
629 BOOST_PP_EXPR_IF(n, >) \ | |
630 struct BOOST_PP_CAT(BOOST_PP_CAT(emplace_functor, n), arg) \ | |
631 { \ | |
632 BOOST_PP_CAT(BOOST_PP_CAT(emplace_functor, n), arg) \ | |
633 ( BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _) ) \ | |
634 BOOST_PP_EXPR_IF(n, :) BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_INIT, _){} \ | |
635 \ | |
636 template<class A, class T> \ | |
637 void operator()(A &a, T *ptr) \ | |
638 { \ | |
639 allocator_traits<A>::construct \ | |
640 (a, ptr BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_MEMBER_FORWARD, _) ); \ | |
641 } \ | |
642 BOOST_PP_REPEAT(n, BOOST_CONTAINER_PP_PARAM_DEFINE, _) \ | |
643 }; \ | |
644 //! | |
645 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS) | |
646 #include BOOST_PP_LOCAL_ITERATE() | |
647 | |
648 #endif | |
649 | |
650 namespace container_detail { | |
651 | |
652 template<class T> | |
653 struct has_iterator_category | |
654 { | |
655 template <typename X> | |
656 static char test(int, typename X::iterator_category*); | |
657 | |
658 template <typename X> | |
659 static int test(int, ...); | |
660 | |
661 static const bool value = (1 == sizeof(test<T>(0, 0))); | |
662 }; | |
663 | |
664 | |
665 template<class T, bool = has_iterator_category<T>::value > | |
666 struct is_input_iterator | |
667 { | |
668 static const bool value = is_same<typename T::iterator_category, std::input_iterator_tag>::value; | |
669 }; | |
670 | |
671 template<class T> | |
672 struct is_input_iterator<T, false> | |
673 { | |
674 static const bool value = false; | |
675 }; | |
676 | |
677 template<class T, bool = has_iterator_category<T>::value > | |
678 struct is_forward_iterator | |
679 { | |
680 static const bool value = is_same<typename T::iterator_category, std::forward_iterator_tag>::value; | |
681 }; | |
682 | |
683 template<class T> | |
684 struct is_forward_iterator<T, false> | |
685 { | |
686 static const bool value = false; | |
687 }; | |
688 | |
689 template<class T, bool = has_iterator_category<T>::value > | |
690 struct is_bidirectional_iterator | |
691 { | |
692 static const bool value = is_same<typename T::iterator_category, std::bidirectional_iterator_tag>::value; | |
693 }; | |
694 | |
695 template<class T> | |
696 struct is_bidirectional_iterator<T, false> | |
697 { | |
698 static const bool value = false; | |
699 }; | |
700 | |
701 template<class IIterator> | |
702 struct iiterator_types | |
703 { | |
704 typedef typename IIterator::value_type it_value_type; | |
705 typedef typename it_value_type::value_type value_type; | |
706 typedef typename std::iterator_traits<IIterator>::pointer it_pointer; | |
707 typedef typename std::iterator_traits<IIterator>::difference_type difference_type; | |
708 typedef typename ::boost::intrusive::pointer_traits<it_pointer>:: | |
709 template rebind_pointer<value_type>::type pointer; | |
710 typedef typename ::boost::intrusive::pointer_traits<it_pointer>:: | |
711 template rebind_pointer<const value_type>::type const_pointer; | |
712 typedef typename ::boost::intrusive:: | |
713 pointer_traits<pointer>::reference reference; | |
714 typedef typename ::boost::intrusive:: | |
715 pointer_traits<const_pointer>::reference const_reference; | |
716 typedef typename IIterator::iterator_category iterator_category; | |
717 }; | |
718 | |
719 template<class IIterator, bool IsConst> | |
720 struct std_iterator | |
721 { | |
722 typedef typename std::iterator | |
723 < typename iiterator_types<IIterator>::iterator_category | |
724 , typename iiterator_types<IIterator>::value_type | |
725 , typename iiterator_types<IIterator>::difference_type | |
726 , typename iiterator_types<IIterator>::const_pointer | |
727 , typename iiterator_types<IIterator>::const_reference> type; | |
728 }; | |
729 | |
730 template<class IIterator> | |
731 struct std_iterator<IIterator, false> | |
732 { | |
733 typedef typename std::iterator | |
734 < typename iiterator_types<IIterator>::iterator_category | |
735 , typename iiterator_types<IIterator>::value_type | |
736 , typename iiterator_types<IIterator>::difference_type | |
737 , typename iiterator_types<IIterator>::pointer | |
738 , typename iiterator_types<IIterator>::reference> type; | |
739 }; | |
740 | |
741 template<class IIterator, bool IsConst> | |
742 class iterator | |
743 : public std_iterator<IIterator, IsConst>::type | |
744 { | |
745 typedef typename std_iterator<IIterator, IsConst>::type types_t; | |
746 | |
747 public: | |
748 typedef typename types_t::value_type value_type; | |
749 typedef typename types_t::pointer pointer; | |
750 typedef typename types_t::reference reference; | |
751 | |
752 iterator() | |
753 {} | |
754 | |
755 explicit iterator(IIterator iit) BOOST_CONTAINER_NOEXCEPT | |
756 : m_iit(iit) | |
757 {} | |
758 | |
759 iterator(iterator<IIterator, false> const& other) BOOST_CONTAINER_NOEXCEPT | |
760 : m_iit(other.get()) | |
761 {} | |
762 | |
763 iterator& operator++() BOOST_CONTAINER_NOEXCEPT | |
764 { ++this->m_iit; return *this; } | |
765 | |
766 iterator operator++(int) BOOST_CONTAINER_NOEXCEPT | |
767 { | |
768 iterator result (*this); | |
769 ++this->m_iit; | |
770 return result; | |
771 } | |
772 | |
773 iterator& operator--() BOOST_CONTAINER_NOEXCEPT | |
774 { | |
775 //If the iterator is not a bidirectional iterator, operator-- should not exist | |
776 BOOST_STATIC_ASSERT((is_bidirectional_iterator<iterator>::value)); | |
777 --this->m_iit; return *this; | |
778 } | |
779 | |
780 iterator operator--(int) BOOST_CONTAINER_NOEXCEPT | |
781 { | |
782 iterator result (*this); | |
783 --this->m_iit; | |
784 return result; | |
785 } | |
786 | |
787 friend bool operator== (const iterator& l, const iterator& r) BOOST_CONTAINER_NOEXCEPT | |
788 { return l.m_iit == r.m_iit; } | |
789 | |
790 friend bool operator!= (const iterator& l, const iterator& r) BOOST_CONTAINER_NOEXCEPT | |
791 { return !(l == r); } | |
792 | |
793 reference operator*() const BOOST_CONTAINER_NOEXCEPT | |
794 { return (*this->m_iit).get_data(); } | |
795 | |
796 pointer operator->() const BOOST_CONTAINER_NOEXCEPT | |
797 { return ::boost::intrusive::pointer_traits<pointer>::pointer_to(this->operator*()); } | |
798 | |
799 const IIterator &get() const BOOST_CONTAINER_NOEXCEPT | |
800 { return this->m_iit; } | |
801 | |
802 private: | |
803 IIterator m_iit; | |
804 }; | |
805 | |
806 } //namespace container_detail { | |
807 } //namespace container { | |
808 } //namespace boost { | |
809 | |
810 #include <boost/container/detail/config_end.hpp> | |
811 | |
812 #endif //#ifndef BOOST_CONTAINER_DETAIL_ITERATORS_HPP |