00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 #ifndef _ITERATOR_H
00066 #define _ITERATOR_H 1
00067
00068 namespace std
00069 {
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 template<typename _Iterator>
00090 class reverse_iterator
00091 : public iterator<typename iterator_traits<_Iterator>::iterator_category,
00092 typename iterator_traits<_Iterator>::value_type,
00093 typename iterator_traits<_Iterator>::difference_type,
00094 typename iterator_traits<_Iterator>::pointer,
00095 typename iterator_traits<_Iterator>::reference>
00096 {
00097 protected:
00098 _Iterator current;
00099
00100 public:
00101 typedef _Iterator iterator_type;
00102 typedef typename iterator_traits<_Iterator>::difference_type
00103 difference_type;
00104 typedef typename iterator_traits<_Iterator>::reference reference;
00105 typedef typename iterator_traits<_Iterator>::pointer pointer;
00106
00107 public:
00108
00109
00110
00111
00112
00113
00114 reverse_iterator() : current() { }
00115
00116
00117
00118
00119 explicit
00120 reverse_iterator(iterator_type __x) : current(__x) { }
00121
00122
00123
00124
00125 reverse_iterator(const reverse_iterator& __x)
00126 : current(__x.current) { }
00127
00128
00129
00130
00131
00132 template<typename _Iter>
00133 reverse_iterator(const reverse_iterator<_Iter>& __x)
00134 : current(__x.base()) { }
00135
00136
00137
00138
00139 iterator_type
00140 base() const
00141 { return current; }
00142
00143
00144
00145
00146
00147
00148 reference
00149 operator*() const
00150 {
00151 _Iterator __tmp = current;
00152 return *--__tmp;
00153 }
00154
00155
00156
00157
00158
00159
00160 pointer
00161 operator->() const
00162 { return &(operator*()); }
00163
00164
00165
00166
00167
00168
00169 reverse_iterator&
00170 operator++()
00171 {
00172 --current;
00173 return *this;
00174 }
00175
00176
00177
00178
00179
00180
00181 reverse_iterator
00182 operator++(int)
00183 {
00184 reverse_iterator __tmp = *this;
00185 --current;
00186 return __tmp;
00187 }
00188
00189
00190
00191
00192
00193
00194 reverse_iterator&
00195 operator--()
00196 {
00197 ++current;
00198 return *this;
00199 }
00200
00201
00202
00203
00204
00205
00206 reverse_iterator operator--(int)
00207 {
00208 reverse_iterator __tmp = *this;
00209 ++current;
00210 return __tmp;
00211 }
00212
00213
00214
00215
00216
00217
00218 reverse_iterator
00219 operator+(difference_type __n) const
00220 { return reverse_iterator(current - __n); }
00221
00222
00223
00224
00225
00226
00227 reverse_iterator&
00228 operator+=(difference_type __n)
00229 {
00230 current -= __n;
00231 return *this;
00232 }
00233
00234
00235
00236
00237
00238
00239 reverse_iterator
00240 operator-(difference_type __n) const
00241 { return reverse_iterator(current + __n); }
00242
00243
00244
00245
00246
00247
00248 reverse_iterator&
00249 operator-=(difference_type __n)
00250 {
00251 current += __n;
00252 return *this;
00253 }
00254
00255
00256
00257
00258
00259
00260 reference
00261 operator[](difference_type __n) const
00262 { return *(*this + __n); }
00263 };
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 template<typename _Iterator>
00276 inline bool
00277 operator==(const reverse_iterator<_Iterator>& __x,
00278 const reverse_iterator<_Iterator>& __y)
00279 { return __x.base() == __y.base(); }
00280
00281 template<typename _Iterator>
00282 inline bool
00283 operator<(const reverse_iterator<_Iterator>& __x,
00284 const reverse_iterator<_Iterator>& __y)
00285 { return __y.base() < __x.base(); }
00286
00287 template<typename _Iterator>
00288 inline bool
00289 operator!=(const reverse_iterator<_Iterator>& __x,
00290 const reverse_iterator<_Iterator>& __y)
00291 { return !(__x == __y); }
00292
00293 template<typename _Iterator>
00294 inline bool
00295 operator>(const reverse_iterator<_Iterator>& __x,
00296 const reverse_iterator<_Iterator>& __y)
00297 { return __y < __x; }
00298
00299 template<typename _Iterator>
00300 inline bool
00301 operator<=(const reverse_iterator<_Iterator>& __x,
00302 const reverse_iterator<_Iterator>& __y)
00303 { return !(__y < __x); }
00304
00305 template<typename _Iterator>
00306 inline bool
00307 operator>=(const reverse_iterator<_Iterator>& __x,
00308 const reverse_iterator<_Iterator>& __y)
00309 { return !(__x < __y); }
00310
00311 template<typename _Iterator>
00312 inline typename reverse_iterator<_Iterator>::difference_type
00313 operator-(const reverse_iterator<_Iterator>& __x,
00314 const reverse_iterator<_Iterator>& __y)
00315 { return __y.base() - __x.base(); }
00316
00317 template<typename _Iterator>
00318 inline reverse_iterator<_Iterator>
00319 operator+(typename reverse_iterator<_Iterator>::difference_type __n,
00320 const reverse_iterator<_Iterator>& __x)
00321 { return reverse_iterator<_Iterator>(__x.base() - __n); }
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335 template<typename _Container>
00336 class back_insert_iterator
00337 : public iterator<output_iterator_tag, void, void, void, void>
00338 {
00339 protected:
00340 _Container* container;
00341
00342 public:
00343
00344 typedef _Container container_type;
00345
00346
00347 explicit
00348 back_insert_iterator(_Container& __x) : container(&__x) { }
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361 back_insert_iterator&
00362 operator=(typename _Container::const_reference __value)
00363 {
00364 container->push_back(__value);
00365 return *this;
00366 }
00367
00368
00369 back_insert_iterator&
00370 operator*()
00371 { return *this; }
00372
00373
00374 back_insert_iterator&
00375 operator++()
00376 { return *this; }
00377
00378
00379 back_insert_iterator
00380 operator++(int)
00381 { return *this; }
00382 };
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395 template<typename _Container>
00396 inline back_insert_iterator<_Container>
00397 back_inserter(_Container& __x)
00398 { return back_insert_iterator<_Container>(__x); }
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410 template<typename _Container>
00411 class front_insert_iterator
00412 : public iterator<output_iterator_tag, void, void, void, void>
00413 {
00414 protected:
00415 _Container* container;
00416
00417 public:
00418
00419 typedef _Container container_type;
00420
00421
00422 explicit front_insert_iterator(_Container& __x) : container(&__x) { }
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435 front_insert_iterator&
00436 operator=(typename _Container::const_reference __value)
00437 {
00438 container->push_front(__value);
00439 return *this;
00440 }
00441
00442
00443 front_insert_iterator&
00444 operator*()
00445 { return *this; }
00446
00447
00448 front_insert_iterator&
00449 operator++()
00450 { return *this; }
00451
00452
00453 front_insert_iterator
00454 operator++(int)
00455 { return *this; }
00456 };
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469 template<typename _Container>
00470 inline front_insert_iterator<_Container>
00471 front_inserter(_Container& __x)
00472 { return front_insert_iterator<_Container>(__x); }
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488 template<typename _Container>
00489 class insert_iterator
00490 : public iterator<output_iterator_tag, void, void, void, void>
00491 {
00492 protected:
00493 _Container* container;
00494 typename _Container::iterator iter;
00495
00496 public:
00497
00498 typedef _Container container_type;
00499
00500
00501
00502
00503
00504 insert_iterator(_Container& __x, typename _Container::iterator __i)
00505 : container(&__x), iter(__i) {}
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530 insert_iterator&
00531 operator=(const typename _Container::const_reference __value)
00532 {
00533 iter = container->insert(iter, __value);
00534 ++iter;
00535 return *this;
00536 }
00537
00538
00539 insert_iterator&
00540 operator*()
00541 { return *this; }
00542
00543
00544 insert_iterator&
00545 operator++()
00546 { return *this; }
00547
00548
00549 insert_iterator&
00550 operator++(int)
00551 { return *this; }
00552 };
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565 template<typename _Container, typename _Iterator>
00566 inline insert_iterator<_Container>
00567 inserter(_Container& __x, _Iterator __i)
00568 {
00569 return insert_iterator<_Container>(__x,
00570 typename _Container::iterator(__i));
00571 }
00572 }
00573
00574 namespace __gnu_cxx
00575 {
00576
00577
00578
00579
00580
00581
00582
00583 using std::iterator_traits;
00584 using std::iterator;
00585 template<typename _Iterator, typename _Container>
00586 class __normal_iterator
00587 {
00588 protected:
00589 _Iterator _M_current;
00590
00591 public:
00592 typedef typename iterator_traits<_Iterator>::iterator_category
00593 iterator_category;
00594 typedef typename iterator_traits<_Iterator>::value_type value_type;
00595 typedef typename iterator_traits<_Iterator>::difference_type
00596 difference_type;
00597 typedef typename iterator_traits<_Iterator>::reference reference;
00598 typedef typename iterator_traits<_Iterator>::pointer pointer;
00599
00600 __normal_iterator() : _M_current(_Iterator()) { }
00601
00602 explicit
00603 __normal_iterator(const _Iterator& __i) : _M_current(__i) { }
00604
00605
00606 template<typename _Iter>
00607 inline __normal_iterator(const __normal_iterator<_Iter,
00608 _Container>& __i)
00609 : _M_current(__i.base()) { }
00610
00611
00612 reference
00613 operator*() const
00614 { return *_M_current; }
00615
00616 pointer
00617 operator->() const
00618 { return _M_current; }
00619
00620 __normal_iterator&
00621 operator++()
00622 {
00623 ++_M_current;
00624 return *this;
00625 }
00626
00627 __normal_iterator
00628 operator++(int)
00629 { return __normal_iterator(_M_current++); }
00630
00631
00632 __normal_iterator&
00633 operator--()
00634 {
00635 --_M_current;
00636 return *this;
00637 }
00638
00639 __normal_iterator
00640 operator--(int)
00641 { return __normal_iterator(_M_current--); }
00642
00643
00644 reference
00645 operator[](const difference_type& __n) const
00646 { return _M_current[__n]; }
00647
00648 __normal_iterator&
00649 operator+=(const difference_type& __n)
00650 { _M_current += __n; return *this; }
00651
00652 __normal_iterator
00653 operator+(const difference_type& __n) const
00654 { return __normal_iterator(_M_current + __n); }
00655
00656 __normal_iterator&
00657 operator-=(const difference_type& __n)
00658 { _M_current -= __n; return *this; }
00659
00660 __normal_iterator
00661 operator-(const difference_type& __n) const
00662 { return __normal_iterator(_M_current - __n); }
00663
00664 const _Iterator&
00665 base() const
00666 { return _M_current; }
00667 };
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678 template<typename _IteratorL, typename _IteratorR, typename _Container>
00679 inline bool
00680 operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
00681 const __normal_iterator<_IteratorR, _Container>& __rhs)
00682 { return __lhs.base() == __rhs.base(); }
00683
00684 template<typename _Iterator, typename _Container>
00685 inline bool
00686 operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
00687 const __normal_iterator<_Iterator, _Container>& __rhs)
00688 { return __lhs.base() == __rhs.base(); }
00689
00690 template<typename _IteratorL, typename _IteratorR, typename _Container>
00691 inline bool
00692 operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs,
00693 const __normal_iterator<_IteratorR, _Container>& __rhs)
00694 { return __lhs.base() != __rhs.base(); }
00695
00696 template<typename _Iterator, typename _Container>
00697 inline bool
00698 operator!=(const __normal_iterator<_Iterator, _Container>& __lhs,
00699 const __normal_iterator<_Iterator, _Container>& __rhs)
00700 { return __lhs.base() != __rhs.base(); }
00701
00702
00703 template<typename _IteratorL, typename _IteratorR, typename _Container>
00704 inline bool
00705 operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
00706 const __normal_iterator<_IteratorR, _Container>& __rhs)
00707 { return __lhs.base() < __rhs.base(); }
00708
00709 template<typename _Iterator, typename _Container>
00710 inline bool
00711 operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
00712 const __normal_iterator<_Iterator, _Container>& __rhs)
00713 { return __lhs.base() < __rhs.base(); }
00714
00715 template<typename _IteratorL, typename _IteratorR, typename _Container>
00716 inline bool
00717 operator>(const __normal_iterator<_IteratorL, _Container>& __lhs,
00718 const __normal_iterator<_IteratorR, _Container>& __rhs)
00719 { return __lhs.base() > __rhs.base(); }
00720
00721 template<typename _Iterator, typename _Container>
00722 inline bool
00723 operator>(const __normal_iterator<_Iterator, _Container>& __lhs,
00724 const __normal_iterator<_Iterator, _Container>& __rhs)
00725 { return __lhs.base() > __rhs.base(); }
00726
00727 template<typename _IteratorL, typename _IteratorR, typename _Container>
00728 inline bool
00729 operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
00730 const __normal_iterator<_IteratorR, _Container>& __rhs)
00731 { return __lhs.base() <= __rhs.base(); }
00732
00733 template<typename _Iterator, typename _Container>
00734 inline bool
00735 operator<=(const __normal_iterator<_Iterator, _Container>& __lhs,
00736 const __normal_iterator<_Iterator, _Container>& __rhs)
00737 { return __lhs.base() <= __rhs.base(); }
00738
00739 template<typename _IteratorL, typename _IteratorR, typename _Container>
00740 inline bool
00741 operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs,
00742 const __normal_iterator<_IteratorR, _Container>& __rhs)
00743 { return __lhs.base() >= __rhs.base(); }
00744
00745 template<typename _Iterator, typename _Container>
00746 inline bool
00747 operator>=(const __normal_iterator<_Iterator, _Container>& __lhs,
00748 const __normal_iterator<_Iterator, _Container>& __rhs)
00749 { return __lhs.base() >= __rhs.base(); }
00750
00751
00752
00753
00754
00755 template<typename _IteratorL, typename _IteratorR, typename _Container>
00756 inline typename __normal_iterator<_IteratorL, _Container>::difference_type
00757 operator-(const __normal_iterator<_IteratorL, _Container>& __lhs,
00758 const __normal_iterator<_IteratorR, _Container>& __rhs)
00759 { return __lhs.base() - __rhs.base(); }
00760
00761 template<typename _Iterator, typename _Container>
00762 inline __normal_iterator<_Iterator, _Container>
00763 operator+(typename __normal_iterator<_Iterator, _Container>::difference_type
00764 __n, const __normal_iterator<_Iterator, _Container>& __i)
00765 { return __normal_iterator<_Iterator, _Container>(__i.base() + __n); }
00766 }
00767
00768 #endif
00769
00770
00771
00772