1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | #ifndef _STL_ITERATOR_H |
61 | #define _STL_ITERATOR_H 1 |
62 | |
63 | #include <bits/cpp_type_traits.h> |
64 | #include <ext/type_traits.h> |
65 | #include <bits/move.h> |
66 | #include <bits/ptr_traits.h> |
67 | |
68 | #if __cplusplus > 201402L |
69 | # define __cpp_lib_array_constexpr 201603 |
70 | #endif |
71 | |
72 | namespace std _GLIBCXX_VISIBILITY(default) |
73 | { |
74 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
75 | |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | |
90 | |
91 | |
92 | |
93 | |
94 | |
95 | |
96 | |
97 | |
98 | |
99 | |
100 | template<typename _Iterator> |
101 | class reverse_iterator |
102 | : public iterator<typename iterator_traits<_Iterator>::iterator_category, |
103 | typename iterator_traits<_Iterator>::value_type, |
104 | typename iterator_traits<_Iterator>::difference_type, |
105 | typename iterator_traits<_Iterator>::pointer, |
106 | typename iterator_traits<_Iterator>::reference> |
107 | { |
108 | protected: |
109 | _Iterator current; |
110 | |
111 | typedef iterator_traits<_Iterator> __traits_type; |
112 | |
113 | public: |
114 | typedef _Iterator iterator_type; |
115 | typedef typename __traits_type::difference_type difference_type; |
116 | typedef typename __traits_type::pointer pointer; |
117 | typedef typename __traits_type::reference reference; |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | _GLIBCXX17_CONSTEXPR |
127 | reverse_iterator() : current() { } |
128 | |
129 | |
130 | |
131 | |
132 | explicit _GLIBCXX17_CONSTEXPR |
133 | reverse_iterator(iterator_type __x) : current(__x) { } |
134 | |
135 | |
136 | |
137 | |
138 | _GLIBCXX17_CONSTEXPR |
139 | reverse_iterator(const reverse_iterator& __x) |
140 | : current(__x.current) { } |
141 | |
142 | |
143 | |
144 | |
145 | |
146 | template<typename _Iter> |
147 | _GLIBCXX17_CONSTEXPR |
148 | reverse_iterator(const reverse_iterator<_Iter>& __x) |
149 | : current(__x.base()) { } |
150 | |
151 | |
152 | |
153 | |
154 | _GLIBCXX17_CONSTEXPR iterator_type |
155 | base() const |
156 | { return current; } |
157 | |
158 | |
159 | |
160 | |
161 | |
162 | |
163 | |
164 | |
165 | |
166 | |
167 | |
168 | _GLIBCXX17_CONSTEXPR reference |
169 | operator*() const |
170 | { |
171 | _Iterator __tmp = current; |
172 | return *--__tmp; |
173 | } |
174 | |
175 | |
176 | |
177 | |
178 | |
179 | |
180 | |
181 | |
182 | _GLIBCXX17_CONSTEXPR pointer |
183 | operator->() const |
184 | { return std::__addressof(operator*()); } |
185 | |
186 | |
187 | |
188 | |
189 | |
190 | |
191 | _GLIBCXX17_CONSTEXPR reverse_iterator& |
192 | operator++() |
193 | { |
194 | --current; |
195 | return *this; |
196 | } |
197 | |
198 | |
199 | |
200 | |
201 | |
202 | |
203 | _GLIBCXX17_CONSTEXPR reverse_iterator |
204 | operator++(int) |
205 | { |
206 | reverse_iterator __tmp = *this; |
207 | --current; |
208 | return __tmp; |
209 | } |
210 | |
211 | |
212 | |
213 | |
214 | |
215 | |
216 | _GLIBCXX17_CONSTEXPR reverse_iterator& |
217 | operator--() |
218 | { |
219 | ++current; |
220 | return *this; |
221 | } |
222 | |
223 | |
224 | |
225 | |
226 | |
227 | |
228 | _GLIBCXX17_CONSTEXPR reverse_iterator |
229 | operator--(int) |
230 | { |
231 | reverse_iterator __tmp = *this; |
232 | ++current; |
233 | return __tmp; |
234 | } |
235 | |
236 | |
237 | |
238 | |
239 | |
240 | |
241 | _GLIBCXX17_CONSTEXPR reverse_iterator |
242 | operator+(difference_type __n) const |
243 | { return reverse_iterator(current - __n); } |
244 | |
245 | |
246 | |
247 | |
248 | |
249 | |
250 | |
251 | _GLIBCXX17_CONSTEXPR reverse_iterator& |
252 | operator+=(difference_type __n) |
253 | { |
254 | current -= __n; |
255 | return *this; |
256 | } |
257 | |
258 | |
259 | |
260 | |
261 | |
262 | |
263 | _GLIBCXX17_CONSTEXPR reverse_iterator |
264 | operator-(difference_type __n) const |
265 | { return reverse_iterator(current + __n); } |
266 | |
267 | |
268 | |
269 | |
270 | |
271 | |
272 | |
273 | _GLIBCXX17_CONSTEXPR reverse_iterator& |
274 | operator-=(difference_type __n) |
275 | { |
276 | current += __n; |
277 | return *this; |
278 | } |
279 | |
280 | |
281 | |
282 | |
283 | |
284 | |
285 | _GLIBCXX17_CONSTEXPR reference |
286 | operator[](difference_type __n) const |
287 | { return *(*this + __n); } |
288 | }; |
289 | |
290 | |
291 | |
292 | |
293 | |
294 | |
295 | |
296 | |
297 | |
298 | |
299 | |
300 | template<typename _Iterator> |
301 | inline _GLIBCXX17_CONSTEXPR bool |
302 | operator==(const reverse_iterator<_Iterator>& __x, |
303 | const reverse_iterator<_Iterator>& __y) |
304 | { return __x.base() == __y.base(); } |
305 | |
306 | template<typename _Iterator> |
307 | inline _GLIBCXX17_CONSTEXPR bool |
308 | operator<(const reverse_iterator<_Iterator>& __x, |
309 | const reverse_iterator<_Iterator>& __y) |
310 | { return __y.base() < __x.base(); } |
311 | |
312 | template<typename _Iterator> |
313 | inline _GLIBCXX17_CONSTEXPR bool |
314 | operator!=(const reverse_iterator<_Iterator>& __x, |
315 | const reverse_iterator<_Iterator>& __y) |
316 | { return !(__x == __y); } |
317 | |
318 | template<typename _Iterator> |
319 | inline _GLIBCXX17_CONSTEXPR bool |
320 | operator>(const reverse_iterator<_Iterator>& __x, |
321 | const reverse_iterator<_Iterator>& __y) |
322 | { return __y < __x; } |
323 | |
324 | template<typename _Iterator> |
325 | inline _GLIBCXX17_CONSTEXPR bool |
326 | operator<=(const reverse_iterator<_Iterator>& __x, |
327 | const reverse_iterator<_Iterator>& __y) |
328 | { return !(__y < __x); } |
329 | |
330 | template<typename _Iterator> |
331 | inline _GLIBCXX17_CONSTEXPR bool |
332 | operator>=(const reverse_iterator<_Iterator>& __x, |
333 | const reverse_iterator<_Iterator>& __y) |
334 | { return !(__x < __y); } |
335 | |
336 | |
337 | |
338 | template<typename _IteratorL, typename _IteratorR> |
339 | inline _GLIBCXX17_CONSTEXPR bool |
340 | operator==(const reverse_iterator<_IteratorL>& __x, |
341 | const reverse_iterator<_IteratorR>& __y) |
342 | { return __x.base() == __y.base(); } |
343 | |
344 | template<typename _IteratorL, typename _IteratorR> |
345 | inline _GLIBCXX17_CONSTEXPR bool |
346 | operator<(const reverse_iterator<_IteratorL>& __x, |
347 | const reverse_iterator<_IteratorR>& __y) |
348 | { return __y.base() < __x.base(); } |
349 | |
350 | template<typename _IteratorL, typename _IteratorR> |
351 | inline _GLIBCXX17_CONSTEXPR bool |
352 | operator!=(const reverse_iterator<_IteratorL>& __x, |
353 | const reverse_iterator<_IteratorR>& __y) |
354 | { return !(__x == __y); } |
355 | |
356 | template<typename _IteratorL, typename _IteratorR> |
357 | inline _GLIBCXX17_CONSTEXPR bool |
358 | operator>(const reverse_iterator<_IteratorL>& __x, |
359 | const reverse_iterator<_IteratorR>& __y) |
360 | { return __y < __x; } |
361 | |
362 | template<typename _IteratorL, typename _IteratorR> |
363 | inline _GLIBCXX17_CONSTEXPR bool |
364 | operator<=(const reverse_iterator<_IteratorL>& __x, |
365 | const reverse_iterator<_IteratorR>& __y) |
366 | { return !(__y < __x); } |
367 | |
368 | template<typename _IteratorL, typename _IteratorR> |
369 | inline _GLIBCXX17_CONSTEXPR bool |
370 | operator>=(const reverse_iterator<_IteratorL>& __x, |
371 | const reverse_iterator<_IteratorR>& __y) |
372 | { return !(__x < __y); } |
373 | |
374 | |
375 | #if __cplusplus < 201103L |
376 | template<typename _Iterator> |
377 | inline typename reverse_iterator<_Iterator>::difference_type |
378 | operator-(const reverse_iterator<_Iterator>& __x, |
379 | const reverse_iterator<_Iterator>& __y) |
380 | { return __y.base() - __x.base(); } |
381 | |
382 | template<typename _IteratorL, typename _IteratorR> |
383 | inline typename reverse_iterator<_IteratorL>::difference_type |
384 | operator-(const reverse_iterator<_IteratorL>& __x, |
385 | const reverse_iterator<_IteratorR>& __y) |
386 | { return __y.base() - __x.base(); } |
387 | #else |
388 | |
389 | |
390 | template<typename _IteratorL, typename _IteratorR> |
391 | inline _GLIBCXX17_CONSTEXPR auto |
392 | operator-(const reverse_iterator<_IteratorL>& __x, |
393 | const reverse_iterator<_IteratorR>& __y) |
394 | -> decltype(__y.base() - __x.base()) |
395 | { return __y.base() - __x.base(); } |
396 | #endif |
397 | |
398 | template<typename _Iterator> |
399 | inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator> |
400 | operator+(typename reverse_iterator<_Iterator>::difference_type __n, |
401 | const reverse_iterator<_Iterator>& __x) |
402 | { return reverse_iterator<_Iterator>(__x.base() - __n); } |
403 | |
404 | #if __cplusplus >= 201103L |
405 | |
406 | template<typename _Iterator> |
407 | inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator> |
408 | __make_reverse_iterator(_Iterator __i) |
409 | { return reverse_iterator<_Iterator>(__i); } |
410 | |
411 | # if __cplusplus > 201103L |
412 | # define __cpp_lib_make_reverse_iterator 201402 |
413 | |
414 | |
415 | |
416 | |
417 | template<typename _Iterator> |
418 | inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator> |
419 | make_reverse_iterator(_Iterator __i) |
420 | { return reverse_iterator<_Iterator>(__i); } |
421 | # endif |
422 | #endif |
423 | |
424 | #if __cplusplus >= 201103L |
425 | template<typename _Iterator> |
426 | auto |
427 | __niter_base(reverse_iterator<_Iterator> __it) |
428 | -> decltype(__make_reverse_iterator(__niter_base(__it.base()))) |
429 | { return __make_reverse_iterator(__niter_base(__it.base())); } |
430 | |
431 | template<typename _Iterator> |
432 | struct __is_move_iterator<reverse_iterator<_Iterator> > |
433 | : __is_move_iterator<_Iterator> |
434 | { }; |
435 | |
436 | template<typename _Iterator> |
437 | auto |
438 | __miter_base(reverse_iterator<_Iterator> __it) |
439 | -> decltype(__make_reverse_iterator(__miter_base(__it.base()))) |
440 | { return __make_reverse_iterator(__miter_base(__it.base())); } |
441 | #endif |
442 | |
443 | |
444 | |
445 | |
446 | |
447 | |
448 | |
449 | |
450 | |
451 | |
452 | |
453 | |
454 | template<typename _Container> |
455 | class back_insert_iterator |
456 | : public iterator<output_iterator_tag, void, void, void, void> |
457 | { |
458 | protected: |
459 | _Container* container; |
460 | |
461 | public: |
462 | |
463 | typedef _Container container_type; |
464 | |
465 | |
466 | explicit |
467 | back_insert_iterator(_Container& __x) |
468 | : container(std::__addressof(__x)) { } |
469 | |
470 | |
471 | |
472 | |
473 | |
474 | |
475 | |
476 | |
477 | |
478 | |
479 | |
480 | |
481 | #if __cplusplus < 201103L |
482 | back_insert_iterator& |
483 | operator=(typename _Container::const_reference __value) |
484 | { |
485 | container->push_back(__value); |
486 | return *this; |
487 | } |
488 | #else |
489 | back_insert_iterator& |
490 | operator=(const typename _Container::value_type& __value) |
491 | { |
492 | container->push_back(__value); |
493 | return *this; |
494 | } |
495 | |
496 | back_insert_iterator& |
497 | operator=(typename _Container::value_type&& __value) |
498 | { |
499 | container->push_back(std::move(__value)); |
500 | return *this; |
501 | } |
502 | #endif |
503 | |
504 | |
505 | back_insert_iterator& |
506 | operator*() |
507 | { return *this; } |
508 | |
509 | |
510 | back_insert_iterator& |
511 | operator++() |
512 | { return *this; } |
513 | |
514 | |
515 | back_insert_iterator |
516 | operator++(int) |
517 | { return *this; } |
518 | }; |
519 | |
520 | |
521 | |
522 | |
523 | |
524 | |
525 | |
526 | |
527 | |
528 | |
529 | |
530 | |
531 | template<typename _Container> |
532 | inline back_insert_iterator<_Container> |
533 | back_inserter(_Container& __x) |
534 | { return back_insert_iterator<_Container>(__x); } |
535 | |
536 | |
537 | |
538 | |
539 | |
540 | |
541 | |
542 | |
543 | |
544 | |
545 | |
546 | template<typename _Container> |
547 | class front_insert_iterator |
548 | : public iterator<output_iterator_tag, void, void, void, void> |
549 | { |
550 | protected: |
551 | _Container* container; |
552 | |
553 | public: |
554 | |
555 | typedef _Container container_type; |
556 | |
557 | |
558 | explicit front_insert_iterator(_Container& __x) |
559 | : container(std::__addressof(__x)) { } |
560 | |
561 | |
562 | |
563 | |
564 | |
565 | |
566 | |
567 | |
568 | |
569 | |
570 | |
571 | |
572 | #if __cplusplus < 201103L |
573 | front_insert_iterator& |
574 | operator=(typename _Container::const_reference __value) |
575 | { |
576 | container->push_front(__value); |
577 | return *this; |
578 | } |
579 | #else |
580 | front_insert_iterator& |
581 | operator=(const typename _Container::value_type& __value) |
582 | { |
583 | container->push_front(__value); |
584 | return *this; |
585 | } |
586 | |
587 | front_insert_iterator& |
588 | operator=(typename _Container::value_type&& __value) |
589 | { |
590 | container->push_front(std::move(__value)); |
591 | return *this; |
592 | } |
593 | #endif |
594 | |
595 | |
596 | front_insert_iterator& |
597 | operator*() |
598 | { return *this; } |
599 | |
600 | |
601 | front_insert_iterator& |
602 | operator++() |
603 | { return *this; } |
604 | |
605 | |
606 | front_insert_iterator |
607 | operator++(int) |
608 | { return *this; } |
609 | }; |
610 | |
611 | |
612 | |
613 | |
614 | |
615 | |
616 | |
617 | |
618 | |
619 | |
620 | |
621 | |
622 | template<typename _Container> |
623 | inline front_insert_iterator<_Container> |
624 | front_inserter(_Container& __x) |
625 | { return front_insert_iterator<_Container>(__x); } |
626 | |
627 | |
628 | |
629 | |
630 | |
631 | |
632 | |
633 | |
634 | |
635 | |
636 | |
637 | |
638 | |
639 | |
640 | |
641 | template<typename _Container> |
642 | class insert_iterator |
643 | : public iterator<output_iterator_tag, void, void, void, void> |
644 | { |
645 | protected: |
646 | _Container* container; |
647 | typename _Container::iterator iter; |
648 | |
649 | public: |
650 | |
651 | typedef _Container container_type; |
652 | |
653 | |
654 | |
655 | |
656 | |
657 | insert_iterator(_Container& __x, typename _Container::iterator __i) |
658 | : container(std::__addressof(__x)), iter(__i) {} |
659 | |
660 | |
661 | |
662 | |
663 | |
664 | |
665 | |
666 | |
667 | |
668 | |
669 | |
670 | |
671 | |
672 | |
673 | |
674 | |
675 | |
676 | |
677 | |
678 | |
679 | |
680 | |
681 | |
682 | |
683 | #if __cplusplus < 201103L |
684 | insert_iterator& |
685 | operator=(typename _Container::const_reference __value) |
686 | { |
687 | iter = container->insert(iter, __value); |
688 | ++iter; |
689 | return *this; |
690 | } |
691 | #else |
692 | insert_iterator& |
693 | operator=(const typename _Container::value_type& __value) |
694 | { |
695 | iter = container->insert(iter, __value); |
696 | ++iter; |
697 | return *this; |
698 | } |
699 | |
700 | insert_iterator& |
701 | operator=(typename _Container::value_type&& __value) |
702 | { |
703 | iter = container->insert(iter, std::move(__value)); |
704 | ++iter; |
705 | return *this; |
706 | } |
707 | #endif |
708 | |
709 | |
710 | insert_iterator& |
711 | operator*() |
712 | { return *this; } |
713 | |
714 | |
715 | insert_iterator& |
716 | operator++() |
717 | { return *this; } |
718 | |
719 | |
720 | insert_iterator& |
721 | operator++(int) |
722 | { return *this; } |
723 | }; |
724 | |
725 | |
726 | |
727 | |
728 | |
729 | |
730 | |
731 | |
732 | |
733 | |
734 | |
735 | |
736 | template<typename _Container, typename _Iterator> |
737 | inline insert_iterator<_Container> |
738 | inserter(_Container& __x, _Iterator __i) |
739 | { |
740 | return insert_iterator<_Container>(__x, |
741 | typename _Container::iterator(__i)); |
742 | } |
743 | |
744 | |
745 | |
746 | _GLIBCXX_END_NAMESPACE_VERSION |
747 | } |
748 | |
749 | namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) |
750 | { |
751 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
752 | |
753 | |
754 | |
755 | |
756 | |
757 | |
758 | |
759 | |
760 | using std::iterator_traits; |
761 | using std::iterator; |
762 | template<typename _Iterator, typename _Container> |
763 | class __normal_iterator |
764 | { |
765 | protected: |
766 | _Iterator _M_current; |
767 | |
768 | typedef iterator_traits<_Iterator> __traits_type; |
769 | |
770 | public: |
771 | typedef _Iterator iterator_type; |
772 | typedef typename __traits_type::iterator_category iterator_category; |
773 | typedef typename __traits_type::value_type value_type; |
774 | typedef typename __traits_type::difference_type difference_type; |
775 | typedef typename __traits_type::reference reference; |
776 | typedef typename __traits_type::pointer pointer; |
777 | |
778 | _GLIBCXX_CONSTEXPR __normal_iterator() _GLIBCXX_NOEXCEPT |
779 | : _M_current(_Iterator()) { } |
780 | |
781 | explicit |
782 | __normal_iterator(const _Iterator& __i) _GLIBCXX_NOEXCEPT |
783 | : _M_current(__i) { } |
784 | |
785 | |
786 | template<typename _Iter> |
787 | __normal_iterator(const __normal_iterator<_Iter, |
788 | typename __enable_if< |
789 | (std::__are_same<_Iter, typename _Container::pointer>::__value), |
790 | _Container>::__type>& __i) _GLIBCXX_NOEXCEPT |
791 | : _M_current(__i.base()) { } |
792 | |
793 | |
794 | reference |
795 | operator*() const _GLIBCXX_NOEXCEPT |
796 | { return *_M_current; } |
797 | |
798 | pointer |
799 | operator->() const _GLIBCXX_NOEXCEPT |
800 | { return _M_current; } |
801 | |
802 | __normal_iterator& |
803 | operator++() _GLIBCXX_NOEXCEPT |
804 | { |
805 | ++_M_current; |
806 | return *this; |
807 | } |
808 | |
809 | __normal_iterator |
810 | operator++(int) _GLIBCXX_NOEXCEPT |
811 | { return __normal_iterator(_M_current++); } |
812 | |
813 | |
814 | __normal_iterator& |
815 | operator--() _GLIBCXX_NOEXCEPT |
816 | { |
817 | --_M_current; |
818 | return *this; |
819 | } |
820 | |
821 | __normal_iterator |
822 | operator--(int) _GLIBCXX_NOEXCEPT |
823 | { return __normal_iterator(_M_current--); } |
824 | |
825 | |
826 | reference |
827 | operator[](difference_type __n) const _GLIBCXX_NOEXCEPT |
828 | { return _M_current[__n]; } |
829 | |
830 | __normal_iterator& |
831 | operator+=(difference_type __n) _GLIBCXX_NOEXCEPT |
832 | { _M_current += __n; return *this; } |
833 | |
834 | __normal_iterator |
835 | operator+(difference_type __n) const _GLIBCXX_NOEXCEPT |
836 | { return __normal_iterator(_M_current + __n); } |
837 | |
838 | __normal_iterator& |
839 | operator-=(difference_type __n) _GLIBCXX_NOEXCEPT |
840 | { _M_current -= __n; return *this; } |
841 | |
842 | __normal_iterator |
843 | operator-(difference_type __n) const _GLIBCXX_NOEXCEPT |
844 | { return __normal_iterator(_M_current - __n); } |
845 | |
846 | const _Iterator& |
847 | base() const _GLIBCXX_NOEXCEPT |
848 | { return _M_current; } |
849 | }; |
850 | |
851 | |
852 | |
853 | |
854 | |
855 | |
856 | |
857 | |
858 | |
859 | |
860 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
861 | inline bool |
862 | operator==(const __normal_iterator<_IteratorL, _Container>& __lhs, |
863 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
864 | _GLIBCXX_NOEXCEPT |
865 | { return __lhs.base() == __rhs.base(); } |
866 | |
867 | template<typename _Iterator, typename _Container> |
868 | inline bool |
869 | operator==(const __normal_iterator<_Iterator, _Container>& __lhs, |
870 | const __normal_iterator<_Iterator, _Container>& __rhs) |
871 | _GLIBCXX_NOEXCEPT |
872 | { return __lhs.base() == __rhs.base(); } |
873 | |
874 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
875 | inline bool |
876 | operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs, |
877 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
878 | _GLIBCXX_NOEXCEPT |
879 | { return __lhs.base() != __rhs.base(); } |
880 | |
881 | template<typename _Iterator, typename _Container> |
882 | inline bool |
883 | operator!=(const __normal_iterator<_Iterator, _Container>& __lhs, |
884 | const __normal_iterator<_Iterator, _Container>& __rhs) |
885 | _GLIBCXX_NOEXCEPT |
886 | { return __lhs.base() != __rhs.base(); } |
887 | |
888 | |
889 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
890 | inline bool |
891 | operator<(const __normal_iterator<_IteratorL, _Container>& __lhs, |
892 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
893 | _GLIBCXX_NOEXCEPT |
894 | { return __lhs.base() < __rhs.base(); } |
895 | |
896 | template<typename _Iterator, typename _Container> |
897 | inline bool |
898 | operator<(const __normal_iterator<_Iterator, _Container>& __lhs, |
899 | const __normal_iterator<_Iterator, _Container>& __rhs) |
900 | _GLIBCXX_NOEXCEPT |
901 | { return __lhs.base() < __rhs.base(); } |
902 | |
903 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
904 | inline bool |
905 | operator>(const __normal_iterator<_IteratorL, _Container>& __lhs, |
906 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
907 | _GLIBCXX_NOEXCEPT |
908 | { return __lhs.base() > __rhs.base(); } |
909 | |
910 | template<typename _Iterator, typename _Container> |
911 | inline bool |
912 | operator>(const __normal_iterator<_Iterator, _Container>& __lhs, |
913 | const __normal_iterator<_Iterator, _Container>& __rhs) |
914 | _GLIBCXX_NOEXCEPT |
915 | { return __lhs.base() > __rhs.base(); } |
916 | |
917 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
918 | inline bool |
919 | operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs, |
920 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
921 | _GLIBCXX_NOEXCEPT |
922 | { return __lhs.base() <= __rhs.base(); } |
923 | |
924 | template<typename _Iterator, typename _Container> |
925 | inline bool |
926 | operator<=(const __normal_iterator<_Iterator, _Container>& __lhs, |
927 | const __normal_iterator<_Iterator, _Container>& __rhs) |
928 | _GLIBCXX_NOEXCEPT |
929 | { return __lhs.base() <= __rhs.base(); } |
930 | |
931 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
932 | inline bool |
933 | operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs, |
934 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
935 | _GLIBCXX_NOEXCEPT |
936 | { return __lhs.base() >= __rhs.base(); } |
937 | |
938 | template<typename _Iterator, typename _Container> |
939 | inline bool |
940 | operator>=(const __normal_iterator<_Iterator, _Container>& __lhs, |
941 | const __normal_iterator<_Iterator, _Container>& __rhs) |
942 | _GLIBCXX_NOEXCEPT |
943 | { return __lhs.base() >= __rhs.base(); } |
944 | |
945 | |
946 | |
947 | |
948 | |
949 | template<typename _IteratorL, typename _IteratorR, typename _Container> |
950 | #if __cplusplus >= 201103L |
951 | |
952 | inline auto |
953 | operator-(const __normal_iterator<_IteratorL, _Container>& __lhs, |
954 | const __normal_iterator<_IteratorR, _Container>& __rhs) noexcept |
955 | -> decltype(__lhs.base() - __rhs.base()) |
956 | #else |
957 | inline typename __normal_iterator<_IteratorL, _Container>::difference_type |
958 | operator-(const __normal_iterator<_IteratorL, _Container>& __lhs, |
959 | const __normal_iterator<_IteratorR, _Container>& __rhs) |
960 | #endif |
961 | { return __lhs.base() - __rhs.base(); } |
962 | |
963 | template<typename _Iterator, typename _Container> |
964 | inline typename __normal_iterator<_Iterator, _Container>::difference_type |
965 | operator-(const __normal_iterator<_Iterator, _Container>& __lhs, |
966 | const __normal_iterator<_Iterator, _Container>& __rhs) |
967 | _GLIBCXX_NOEXCEPT |
968 | { return __lhs.base() - __rhs.base(); } |
969 | |
970 | template<typename _Iterator, typename _Container> |
971 | inline __normal_iterator<_Iterator, _Container> |
972 | operator+(typename __normal_iterator<_Iterator, _Container>::difference_type |
973 | __n, const __normal_iterator<_Iterator, _Container>& __i) |
974 | _GLIBCXX_NOEXCEPT |
975 | { return __normal_iterator<_Iterator, _Container>(__i.base() + __n); } |
976 | |
977 | _GLIBCXX_END_NAMESPACE_VERSION |
978 | } |
979 | |
980 | namespace std _GLIBCXX_VISIBILITY(default) |
981 | { |
982 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
983 | |
984 | template<typename _Iterator, typename _Container> |
985 | _Iterator |
986 | __niter_base(__gnu_cxx::__normal_iterator<_Iterator, _Container> __it) |
987 | { return __it.base(); } |
988 | |
989 | _GLIBCXX_END_NAMESPACE_VERSION |
990 | } |
991 | |
992 | #if __cplusplus >= 201103L |
993 | |
994 | namespace std _GLIBCXX_VISIBILITY(default) |
995 | { |
996 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
997 | |
998 | |
999 | |
1000 | |
1001 | |
1002 | |
1003 | |
1004 | |
1005 | |
1006 | |
1007 | |
1008 | |
1009 | |
1010 | |
1011 | |
1012 | template<typename _Iterator> |
1013 | class move_iterator |
1014 | { |
1015 | protected: |
1016 | _Iterator _M_current; |
1017 | |
1018 | typedef iterator_traits<_Iterator> __traits_type; |
1019 | typedef typename __traits_type::reference __base_ref; |
1020 | |
1021 | public: |
1022 | typedef _Iterator iterator_type; |
1023 | typedef typename __traits_type::iterator_category iterator_category; |
1024 | typedef typename __traits_type::value_type value_type; |
1025 | typedef typename __traits_type::difference_type difference_type; |
1026 | |
1027 | typedef _Iterator pointer; |
1028 | |
1029 | |
1030 | typedef typename conditional<is_reference<__base_ref>::value, |
1031 | typename remove_reference<__base_ref>::type&&, |
1032 | __base_ref>::type reference; |
1033 | |
1034 | _GLIBCXX17_CONSTEXPR |
1035 | move_iterator() |
1036 | : _M_current() { } |
1037 | |
1038 | explicit _GLIBCXX17_CONSTEXPR |
1039 | move_iterator(iterator_type __i) |
1040 | : _M_current(__i) { } |
1041 | |
1042 | template<typename _Iter> |
1043 | _GLIBCXX17_CONSTEXPR |
1044 | move_iterator(const move_iterator<_Iter>& __i) |
1045 | : _M_current(__i.base()) { } |
1046 | |
1047 | _GLIBCXX17_CONSTEXPR iterator_type |
1048 | base() const |
1049 | { return _M_current; } |
1050 | |
1051 | _GLIBCXX17_CONSTEXPR reference |
1052 | operator*() const |
1053 | { return static_cast<reference>(*_M_current); } |
1054 | |
1055 | _GLIBCXX17_CONSTEXPR pointer |
1056 | operator->() const |
1057 | { return _M_current; } |
1058 | |
1059 | _GLIBCXX17_CONSTEXPR move_iterator& |
1060 | operator++() |
1061 | { |
1062 | ++_M_current; |
1063 | return *this; |
1064 | } |
1065 | |
1066 | _GLIBCXX17_CONSTEXPR move_iterator |
1067 | operator++(int) |
1068 | { |
1069 | move_iterator __tmp = *this; |
1070 | ++_M_current; |
1071 | return __tmp; |
1072 | } |
1073 | |
1074 | _GLIBCXX17_CONSTEXPR move_iterator& |
1075 | operator--() |
1076 | { |
1077 | --_M_current; |
1078 | return *this; |
1079 | } |
1080 | |
1081 | _GLIBCXX17_CONSTEXPR move_iterator |
1082 | operator--(int) |
1083 | { |
1084 | move_iterator __tmp = *this; |
1085 | --_M_current; |
1086 | return __tmp; |
1087 | } |
1088 | |
1089 | _GLIBCXX17_CONSTEXPR move_iterator |
1090 | operator+(difference_type __n) const |
1091 | { return move_iterator(_M_current + __n); } |
1092 | |
1093 | _GLIBCXX17_CONSTEXPR move_iterator& |
1094 | operator+=(difference_type __n) |
1095 | { |
1096 | _M_current += __n; |
1097 | return *this; |
1098 | } |
1099 | |
1100 | _GLIBCXX17_CONSTEXPR move_iterator |
1101 | operator-(difference_type __n) const |
1102 | { return move_iterator(_M_current - __n); } |
1103 | |
1104 | _GLIBCXX17_CONSTEXPR move_iterator& |
1105 | operator-=(difference_type __n) |
1106 | { |
1107 | _M_current -= __n; |
1108 | return *this; |
1109 | } |
1110 | |
1111 | _GLIBCXX17_CONSTEXPR reference |
1112 | operator[](difference_type __n) const |
1113 | { return std::move(_M_current[__n]); } |
1114 | }; |
1115 | |
1116 | |
1117 | |
1118 | |
1119 | template<typename _IteratorL, typename _IteratorR> |
1120 | inline _GLIBCXX17_CONSTEXPR bool |
1121 | operator==(const move_iterator<_IteratorL>& __x, |
1122 | const move_iterator<_IteratorR>& __y) |
1123 | { return __x.base() == __y.base(); } |
1124 | |
1125 | template<typename _Iterator> |
1126 | inline _GLIBCXX17_CONSTEXPR bool |
1127 | operator==(const move_iterator<_Iterator>& __x, |
1128 | const move_iterator<_Iterator>& __y) |
1129 | { return __x.base() == __y.base(); } |
1130 | |
1131 | template<typename _IteratorL, typename _IteratorR> |
1132 | inline _GLIBCXX17_CONSTEXPR bool |
1133 | operator!=(const move_iterator<_IteratorL>& __x, |
1134 | const move_iterator<_IteratorR>& __y) |
1135 | { return !(__x == __y); } |
1136 | |
1137 | template<typename _Iterator> |
1138 | inline _GLIBCXX17_CONSTEXPR bool |
1139 | operator!=(const move_iterator<_Iterator>& __x, |
1140 | const move_iterator<_Iterator>& __y) |
1141 | { return !(__x == __y); } |
1142 | |
1143 | template<typename _IteratorL, typename _IteratorR> |
1144 | inline _GLIBCXX17_CONSTEXPR bool |
1145 | operator<(const move_iterator<_IteratorL>& __x, |
1146 | const move_iterator<_IteratorR>& __y) |
1147 | { return __x.base() < __y.base(); } |
1148 | |
1149 | template<typename _Iterator> |
1150 | inline _GLIBCXX17_CONSTEXPR bool |
1151 | operator<(const move_iterator<_Iterator>& __x, |
1152 | const move_iterator<_Iterator>& __y) |
1153 | { return __x.base() < __y.base(); } |
1154 | |
1155 | template<typename _IteratorL, typename _IteratorR> |
1156 | inline _GLIBCXX17_CONSTEXPR bool |
1157 | operator<=(const move_iterator<_IteratorL>& __x, |
1158 | const move_iterator<_IteratorR>& __y) |
1159 | { return !(__y < __x); } |
1160 | |
1161 | template<typename _Iterator> |
1162 | inline _GLIBCXX17_CONSTEXPR bool |
1163 | operator<=(const move_iterator<_Iterator>& __x, |
1164 | const move_iterator<_Iterator>& __y) |
1165 | { return !(__y < __x); } |
1166 | |
1167 | template<typename _IteratorL, typename _IteratorR> |
1168 | inline _GLIBCXX17_CONSTEXPR bool |
1169 | operator>(const move_iterator<_IteratorL>& __x, |
1170 | const move_iterator<_IteratorR>& __y) |
1171 | { return __y < __x; } |
1172 | |
1173 | template<typename _Iterator> |
1174 | inline _GLIBCXX17_CONSTEXPR bool |
1175 | operator>(const move_iterator<_Iterator>& __x, |
1176 | const move_iterator<_Iterator>& __y) |
1177 | { return __y < __x; } |
1178 | |
1179 | template<typename _IteratorL, typename _IteratorR> |
1180 | inline _GLIBCXX17_CONSTEXPR bool |
1181 | operator>=(const move_iterator<_IteratorL>& __x, |
1182 | const move_iterator<_IteratorR>& __y) |
1183 | { return !(__x < __y); } |
1184 | |
1185 | template<typename _Iterator> |
1186 | inline _GLIBCXX17_CONSTEXPR bool |
1187 | operator>=(const move_iterator<_Iterator>& __x, |
1188 | const move_iterator<_Iterator>& __y) |
1189 | { return !(__x < __y); } |
1190 | |
1191 | |
1192 | template<typename _IteratorL, typename _IteratorR> |
1193 | inline _GLIBCXX17_CONSTEXPR auto |
1194 | operator-(const move_iterator<_IteratorL>& __x, |
1195 | const move_iterator<_IteratorR>& __y) |
1196 | -> decltype(__x.base() - __y.base()) |
1197 | { return __x.base() - __y.base(); } |
1198 | |
1199 | template<typename _Iterator> |
1200 | inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator> |
1201 | operator+(typename move_iterator<_Iterator>::difference_type __n, |
1202 | const move_iterator<_Iterator>& __x) |
1203 | { return __x + __n; } |
1204 | |
1205 | template<typename _Iterator> |
1206 | inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator> |
1207 | make_move_iterator(_Iterator __i) |
1208 | { return move_iterator<_Iterator>(__i); } |
1209 | |
1210 | template<typename _Iterator, typename _ReturnType |
1211 | = typename conditional<__move_if_noexcept_cond |
1212 | <typename iterator_traits<_Iterator>::value_type>::value, |
1213 | _Iterator, move_iterator<_Iterator>>::type> |
1214 | inline _GLIBCXX17_CONSTEXPR _ReturnType |
1215 | __make_move_if_noexcept_iterator(_Iterator __i) |
1216 | { return _ReturnType(__i); } |
1217 | |
1218 | |
1219 | |
1220 | template<typename _Tp, typename _ReturnType |
1221 | = typename conditional<__move_if_noexcept_cond<_Tp>::value, |
1222 | const _Tp*, move_iterator<_Tp*>>::type> |
1223 | inline _GLIBCXX17_CONSTEXPR _ReturnType |
1224 | __make_move_if_noexcept_iterator(_Tp* __i) |
1225 | { return _ReturnType(__i); } |
1226 | |
1227 | |
1228 | |
1229 | template<typename _Iterator> |
1230 | auto |
1231 | __niter_base(move_iterator<_Iterator> __it) |
1232 | -> decltype(make_move_iterator(__niter_base(__it.base()))) |
1233 | { return make_move_iterator(__niter_base(__it.base())); } |
1234 | |
1235 | template<typename _Iterator> |
1236 | struct __is_move_iterator<move_iterator<_Iterator> > |
1237 | { |
1238 | enum { __value = 1 }; |
1239 | typedef __true_type __type; |
1240 | }; |
1241 | |
1242 | template<typename _Iterator> |
1243 | auto |
1244 | __miter_base(move_iterator<_Iterator> __it) |
1245 | -> decltype(__miter_base(__it.base())) |
1246 | { return __miter_base(__it.base()); } |
1247 | |
1248 | _GLIBCXX_END_NAMESPACE_VERSION |
1249 | } |
1250 | |
1251 | #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) std::make_move_iterator(_Iter) |
1252 | #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) \ |
1253 | std::__make_move_if_noexcept_iterator(_Iter) |
1254 | #else |
1255 | #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) (_Iter) |
1256 | #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) (_Iter) |
1257 | #endif |
1258 | |
1259 | #ifdef _GLIBCXX_DEBUG |
1260 | # include <debug/stl_iterator.h> |
1261 | #endif |
1262 | |
1263 | #endif |
1264 | |