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 #include "../meta/is_integral.h"
00044
00045 namespace lass
00046 {
00047 namespace stde
00048 {
00049
00050 namespace impl
00051 {
00052
00053
00054
00055 struct slist_traits
00056 {
00057 template <typename Container, typename T>
00058 static void push(Container& container, const T& value)
00059 {
00060 container.push_front(value);
00061 }
00062 template <typename Container>
00063 static void temp_to_output(Container& temp, Container& output)
00064 {
00065 temp.swap(output);
00066 }
00067 };
00068
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 template <typename T, class Alloc>
00082 slist<T, Alloc>::slist(const Alloc& allocator):
00083 Alloc(allocator)
00084 {
00085 head_.next = 0;
00086 }
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 template <typename T, class Alloc>
00100 slist<T, Alloc>::slist(size_type n, const T& value, const Alloc& allocator):
00101 Alloc(allocator)
00102 {
00103 head_.next = 0;
00104 insert_after(before_begin(), n, value);
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 template <typename T, class Alloc>
00119 template <typename InputIterator>
00120 slist<T, Alloc>::slist(InputIterator first, InputIterator last, const Alloc& allocator):
00121 Alloc(allocator)
00122 {
00123 head_.next = 0;
00124 insert_after(before_begin(), first, last);
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 template <typename T, class Alloc>
00136 slist<T, Alloc>::slist(const slist<T, Alloc>& other):
00137 Alloc(other.get_allocator())
00138 {
00139 head_.next = 0;
00140 insert_after(before_begin(), other.begin(), other.end());
00141 }
00142
00143
00144
00145
00146
00147
00148
00149 template <typename T, class Alloc>
00150 slist<T, Alloc>::~slist()
00151 {
00152 while (head_.next)
00153 {
00154 unlink_and_destroy_after(&head_);
00155 }
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 template <typename T, class Alloc>
00167 slist<T, Alloc>& slist<T, Alloc>::operator=(slist<T, Alloc> other)
00168 {
00169 swap(other);
00170 return *this;
00171 }
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 template <typename T, class Alloc>
00185 template <typename ForwardIterator>
00186 void slist<T, Alloc>::assign(ForwardIterator first, ForwardIterator last)
00187 {
00188 slist<T, Alloc> temp(first, last, get_allocator());
00189 swap(temp);
00190 }
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 template <typename T, class Alloc>
00202 void slist<T, Alloc>::assign(size_type n, const T& value)
00203 {
00204 slist<T, Alloc> temp(n, value, get_allocator());
00205 swap(temp);
00206 }
00207
00208
00209
00210
00211
00212
00213
00214 template <typename T, class Alloc>
00215 typename slist<T, Alloc>::allocator_type
00216 slist<T, Alloc>::get_allocator() const
00217 {
00218 return *static_cast<const allocator_type*>(this);
00219 }
00220
00221
00222
00223
00224
00225
00226
00227 template <typename T, class Alloc>
00228 typename slist<T, Alloc>::iterator
00229 slist<T, Alloc>::begin()
00230 {
00231 return iterator(head_.next);
00232 }
00233
00234
00235
00236
00237
00238
00239
00240 template <typename T, class Alloc>
00241 typename slist<T, Alloc>::const_iterator
00242 slist<T, Alloc>::begin() const
00243 {
00244 return const_iterator(head_.next);
00245 }
00246
00247
00248
00249
00250
00251
00252
00253 template <typename T, class Alloc>
00254 typename slist<T, Alloc>::iterator
00255 slist<T, Alloc>::end()
00256 {
00257 return iterator(0);
00258 }
00259
00260
00261
00262
00263
00264
00265
00266 template <typename T, class Alloc>
00267 typename slist<T, Alloc>::const_iterator
00268 slist<T, Alloc>::end() const
00269 {
00270 return const_iterator(0);
00271 }
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 template <typename T, class Alloc>
00284 typename slist<T, Alloc>::iterator
00285 slist<T, Alloc>::before_begin()
00286 {
00287 return iterator(&head_);
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 template <typename T, class Alloc>
00301 typename slist<T, Alloc>::const_iterator
00302 slist<T, Alloc>::before_begin() const
00303 {
00304 return const_iterator(&head_);
00305 }
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 template <typename T, class Alloc>
00317 typename slist<T, Alloc>::iterator
00318 slist<T, Alloc>::prior(iterator position) const
00319 {
00320 return prior(position, const_cast<slist<T, Alloc>*>(this)->before_begin());
00321 }
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 template <typename T, class Alloc>
00333 typename slist<T, Alloc>::const_iterator
00334 slist<T, Alloc>::prior(const_iterator position) const
00335 {
00336 return prior(position, before_begin());
00337 }
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351 template <typename T, class Alloc>
00352 typename slist<T, Alloc>::iterator
00353 slist<T, Alloc>::prior(iterator position, iterator start) const
00354 {
00355 iterator result = start;
00356 while (result.node_->next != position.node_)
00357 {
00358 LASS_ASSERT(result.node_->next);
00359 ++result;
00360 }
00361 return result;
00362 }
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376 template <typename T, class Alloc>
00377 typename slist<T, Alloc>::const_iterator
00378 slist<T, Alloc>::prior(const_iterator position, const_iterator start) const
00379 {
00380 const_iterator result = start;
00381 while (result.node_->next != position.node_)
00382 {
00383 LASS_ASSERT(result.node_->next);
00384 ++result;
00385 }
00386 return result;
00387 }
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397 template <typename T, class Alloc>
00398 bool slist<T, Alloc>::empty() const
00399 {
00400 return head_.next == 0;
00401 }
00402
00403
00404
00405
00406
00407
00408
00409 template <typename T, class Alloc>
00410 typename slist<T, Alloc>::size_type
00411 slist<T, Alloc>::size() const
00412 {
00413 size_type n = 0;
00414 for (node_base_t* i = head_.next; i != 0; i = i->next)
00415 {
00416 ++n;
00417 }
00418 return n;
00419 }
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430 template <typename T, class Alloc>
00431 typename slist<T, Alloc>::size_type
00432 slist<T, Alloc>::max_size() const
00433 {
00434
00435
00436 return size_type(-1);
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449 template <typename T, class Alloc>
00450 void slist<T, Alloc>::resize(size_type n, const T& value)
00451 {
00452 node_base_t* i = &head_;
00453 while (i->next && n)
00454 {
00455 --n;
00456 i = i->next;
00457 }
00458 if (n)
00459 {
00460 insert_after(iterator(i), n, value);
00461 }
00462 else
00463 {
00464 while (i->next)
00465 {
00466 unlink_and_destroy_after(i);
00467 }
00468 }
00469 }
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480 template <typename T, class Alloc>
00481 typename slist<T, Alloc>::reference
00482 slist<T, Alloc>::front()
00483 {
00484 return static_cast<node_t*>(head_.next)->value;
00485 }
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496 template <typename T, class Alloc>
00497 typename slist<T, Alloc>::const_reference
00498 slist<T, Alloc>::front() const
00499 {
00500 return static_cast<node_t*>(head_.next)->value;
00501 }
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514 template <typename T, class Alloc>
00515 void slist<T, Alloc>::push_front(const T& value)
00516 {
00517 node_base_t* node = make_node(value);
00518 node->next = head_.next;
00519 head_.next = node;
00520 }
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531 template <typename T, class Alloc>
00532 void slist<T, Alloc>::pop_front()
00533 {
00534 unlink_and_destroy_after(&head_);
00535 }
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551 template <typename T, class Alloc>
00552 typename slist<T, Alloc>::iterator
00553 slist<T, Alloc>::insert(iterator position, const T& value)
00554 {
00555 const iterator before_position = prior(position);
00556 return insert_after(before_position, value);
00557 }
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575 template <typename T, class Alloc>
00576 void slist<T, Alloc>::insert(iterator position, size_type n, const T& value)
00577 {
00578 const iterator before_position = prior(position);
00579 insert_after(before_position, n, value);
00580 }
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599 template <typename T, class Alloc>
00600 template <typename InputIterator>
00601 void slist<T, Alloc>::insert(iterator position, InputIterator first, InputIterator last)
00602 {
00603 const iterator before_position = prior(position);
00604 insert_after(before_position, first, last);
00605 }
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618 template <typename T, class Alloc>
00619 typename slist<T, Alloc>::iterator
00620 slist<T, Alloc>::insert_after(iterator position, const T& value)
00621 {
00622 node_base_t* new_node = make_node(value);
00623 link_after(position.node_, new_node);
00624 return iterator(new_node);
00625 }
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639 template <typename T, class Alloc>
00640 void slist<T, Alloc>::insert_after(iterator position, size_type n, const T& value)
00641 {
00642 node_base_t* node = position.node_;
00643 for (size_type i = 0; i < n; ++i)
00644 {
00645 node_t* new_node = make_node(value);
00646 link_after(node, new_node);
00647 node = new_node;
00648 }
00649 }
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664 template <typename T, class Alloc>
00665 template <typename InputIterator>
00666 void slist<T, Alloc>::insert_after(iterator position, InputIterator first, InputIterator last)
00667 {
00668 insert_after(position, first, last, meta::Wrap<typename meta::IsIntegral<InputIterator>::Type>());
00669 }
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685 template <typename T, class Alloc>
00686 typename slist<T, Alloc>::iterator
00687 slist<T, Alloc>::erase(iterator position)
00688 {
00689 iterator before_position = prior(position);
00690 erase_after(before_position);
00691 return ++before_position;
00692 }
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711 template <typename T, class Alloc>
00712 typename slist<T, Alloc>::iterator
00713 slist<T, Alloc>::erase(iterator position, iterator last)
00714 {
00715 iterator before_position = prior(position);
00716 erase_after(before_position, last);
00717 return ++before_position;
00718 }
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731 template <typename T, class Alloc>
00732 void slist<T, Alloc>::erase_after(iterator position)
00733 {
00734 LASS_ASSERT(position.node_ && position.node_->next);
00735 unlink_and_destroy_after(position.node_);
00736 }
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751 template <typename T, class Alloc>
00752 void slist<T, Alloc>::erase_after(iterator position, iterator last)
00753 {
00754 LASS_ASSERT(position.node_);
00755 while (position.node_->next != last.node_)
00756 {
00757 erase_after(position);
00758 }
00759 }
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769 template <typename T, class Alloc>
00770 void slist<T, Alloc>::swap(slist<T, Alloc>& other)
00771 {
00772 LASS_ASSERT(get_allocator() == other.get_allocator());
00773 std::swap(head_.next, other.head_.next);
00774 }
00775
00776
00777
00778
00779
00780
00781
00782 template <typename T, class Alloc>
00783 void slist<T, Alloc>::clear()
00784 {
00785 slist<T, Alloc> temp(get_allocator());
00786 swap(temp);
00787 }
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805 template <typename T, class Alloc>
00806 void slist<T, Alloc>::splice(iterator position, slist<T, Alloc>& other)
00807 {
00808 const iterator before_position = prior(position);
00809 splice_after(before_position, other);
00810 }
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828 template <typename T, class Alloc>
00829 void slist<T, Alloc>::splice(iterator position, slist<T, Alloc>& other, iterator x)
00830 {
00831 const iterator before_position = prior(position);
00832 const iterator before_x = other.prior(x);
00833 splice_after(before_position, other, before_x);
00834 }
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854 template <typename T, class Alloc>
00855 void slist<T, Alloc>::splice(iterator position, slist<T, Alloc>& other, iterator first, iterator last)
00856 {
00857 const iterator before_position = prior(position);
00858 const iterator before_first = other.prior(first);
00859 const iterator before_last = other.prior(last, before_first);
00860 splice_after(before_position, other, before_first, before_last);
00861 }
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875 template <typename T, class Alloc>
00876 void slist<T, Alloc>::splice_after(iterator position, slist<T, Alloc>& other)
00877 {
00878 node_base_t* other_before_last = &other.head_;
00879 while (other_before_last->next)
00880 {
00881 other_before_last = other_before_last->next;
00882 }
00883
00884 splice_after(position.node_, &other.head_, other_before_last);
00885 }
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899 template <typename T, class Alloc>
00900 void slist<T, Alloc>::splice_after(iterator position, slist<T, Alloc>& , iterator before_x)
00901 {
00902 splice_after(position.node_, before_x.node_, before_x.node_->next);
00903 }
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919 template <typename T, class Alloc>
00920 void slist<T, Alloc>::splice_after(iterator position, slist<T, Alloc>& , iterator before_first,
00921 iterator before_last)
00922 {
00923 splice_after(position.node_, before_first.node_, before_last.node_);
00924 }
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934 template <typename T, class Alloc>
00935 void slist<T, Alloc>::remove(const T& value)
00936 {
00937 node_base_t* node = &head_;
00938 while (node->next)
00939 {
00940 if (static_cast<node_t*>(node->next)->value == value)
00941 {
00942 unlink_and_destroy_after(node);
00943 }
00944 else
00945 {
00946 node = node->next;
00947 }
00948 }
00949 }
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959 template <typename T, class Alloc>
00960 template <class UnaryPredicate>
00961 void slist<T, Alloc>::remove_if(UnaryPredicate predicate)
00962 {
00963 node_base_t* node = &head_;
00964 while (node->next)
00965 {
00966 if (predicate(static_cast<node_t*>(node->next)->value))
00967 {
00968 unlink_and_destroy_after(node);
00969 }
00970 else
00971 {
00972 node = node->next;
00973 }
00974 }
00975 }
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986 template <typename T, class Alloc>
00987 void slist<T, Alloc>::unique()
00988 {
00989 node_base_t* node = head_.next;
00990 if (!node)
00991 {
00992 return;
00993 }
00994 while (node->next)
00995 {
00996 if (static_cast<node_t*>(node)->value == static_cast<node_t*>(node->next)->value)
00997 {
00998 unlink_and_destroy_after(node);
00999 }
01000 else
01001 {
01002 node = node->next;
01003 }
01004 }
01005 }
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019 template <typename T, class Alloc>
01020 template <class BinaryPredicate>
01021 void slist<T, Alloc>::unique(BinaryPredicate predicate)
01022 {
01023 node_base_t* node = head_.next;
01024 if (!node)
01025 {
01026 return;
01027 }
01028 while (node->next)
01029 {
01030 if (predicate(static_cast<node_t*>(node)->value, static_cast<node_t*>(node->next)->value))
01031 {
01032 unlink_and_destroy_after(node);
01033 }
01034 else
01035 {
01036 node = node->next;
01037 }
01038 }
01039 }
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055 template <typename T, class Alloc>
01056 void slist<T, Alloc>::merge(slist<T, Alloc>& other)
01057 {
01058 merge(other, std::less<value_type>());
01059 }
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077 template <typename T, class Alloc>
01078 template <class BinaryPredicate>
01079 void slist<T, Alloc>::merge(slist<T, Alloc>& other, BinaryPredicate compare)
01080 {
01081 node_base_t* node = &head_;
01082 while (node->next && other.head_.next)
01083 {
01084 if (compare(static_cast<node_t*>(other.head_.next)->value,
01085 static_cast<node_t*>(node->next)->value))
01086 {
01087 splice_after(node, &other.head_, other.head_.next);
01088 }
01089 node = node->next;
01090 }
01091 if (other.head_.next)
01092 {
01093 node->next = other.head_.next;
01094 other.head_.next = 0;
01095 }
01096 }
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107 template <typename T, class Alloc>
01108 void slist<T, Alloc>::sort()
01109 {
01110 sort(std::less<value_type>());
01111 }
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129 template <typename T, class Alloc>
01130 template <class BinaryPredicate>
01131 void slist<T, Alloc>::sort(BinaryPredicate compare)
01132 {
01133 if (head_.next && head_.next->next)
01134 {
01135 slist<T, Alloc> carry;
01136 slist<T, Alloc> counter[64];
01137 size_type fill = 0;
01138 while (!empty())
01139 {
01140 splice_after(&carry.head_, &head_, head_.next);
01141 size_type i = 0;
01142 while (i < fill && !counter[i].empty())
01143 {
01144 counter[i].merge(carry, compare);
01145 carry.swap(counter[i]);
01146 ++i;
01147 }
01148 carry.swap(counter[i]);
01149 if (i == fill)
01150 {
01151 ++fill;
01152 }
01153 }
01154 for (size_type i = 1; i < fill; ++i)
01155 {
01156 counter[i].merge(counter[i - 1], compare);
01157 }
01158 swap(counter[fill - 1]);
01159 }
01160 }
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170 template <typename T, class Alloc>
01171 void slist<T, Alloc>::reverse()
01172 {
01173 node_base_t* begin = 0;
01174 while (head_.next)
01175 {
01176 node_base_t* node = head_.next;
01177 head_.next = node->next;
01178 node->next = begin;
01179 begin = node;
01180 }
01181 head_.next = begin;
01182 }
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192 template <typename T, class Alloc>
01193 typename slist<T, Alloc>::node_t*
01194 slist<T, Alloc>::make_node(const T& value) const
01195 {
01196 allocator_type allocator = get_allocator();
01197 node_allocator_type node_allocator = node_allocator_type(allocator);
01198
01199 node_t* node = node_allocator.allocate(1);
01200 try
01201 {
01202 allocator.construct(&node->value, value);
01203 }
01204 catch (...)
01205 {
01206 node_allocator.deallocate(node, 1);
01207 throw;
01208 }
01209 node->next = 0;
01210 return node;
01211 }
01212
01213
01214
01215
01216
01217 template <typename T, class Alloc>
01218 void slist<T, Alloc>::unlink_and_destroy_after(node_base_t* before) const
01219 {
01220 allocator_type allocator = get_allocator();
01221 node_allocator_type node_allocator = node_allocator_type(allocator);
01222
01223 LASS_ASSERT(before && before->next);
01224
01225 node_base_t* node = before->next;
01226 before->next = node->next;
01227 allocator.destroy(&static_cast<node_t*>(node)->value);
01228 node_allocator.deallocate(static_cast<node_t*>(node), 1);
01229 }
01230
01231
01232
01233
01234
01235 template <typename T, class Alloc>
01236 void slist<T, Alloc>::link_after(node_base_t* position, node_base_t* node) const
01237 {
01238 LASS_ASSERT(position && node);
01239 node->next = position->next;
01240 position->next = node;
01241 }
01242
01243
01244
01245
01246
01247 template <typename T, class Alloc>
01248 void slist<T, Alloc>::splice_after(node_base_t* position, node_base_t* before_first,
01249 node_base_t* before_last) const
01250 {
01251 LASS_ASSERT(before_first != before_last);
01252 if (position != before_first && position != before_last)
01253 {
01254 node_base_t* const first = before_first->next;
01255 before_first->next = before_last->next;
01256 before_last->next = position->next;
01257 position->next = first;
01258 }
01259 }
01260
01261
01262
01263
01264
01265 template <typename T, class Alloc>
01266 void slist<T, Alloc>::insert_after(iterator position, size_type n, const value_type& value,
01267 meta::Wrap<meta::True>)
01268 {
01269 node_base_t* node = position.node_;
01270 for (size_type i = 0; i < n; ++i)
01271 {
01272 node_t* new_node = make_node(value);
01273 link_after(node, new_node);
01274 node = new_node;
01275 }
01276 }
01277
01278
01279
01280
01281
01282 template <typename T, class Alloc>
01283 template <typename InputIterator>
01284 void slist<T, Alloc>::insert_after(iterator position, InputIterator first, InputIterator last,
01285 meta::Wrap<meta::False>)
01286 {
01287 while (first != last)
01288 {
01289 node_t* new_node = make_node(*first);
01290 link_after(position.node_, new_node);
01291 ++position;
01292 ++first;
01293 }
01294 }
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311 template <typename T, class Alloc>
01312 bool operator==(const slist<T, Alloc>& a, const slist<T, Alloc>& b)
01313 {
01314 typedef typename slist<T, Alloc>::const_iterator const_iterator;
01315 const const_iterator a_end = a.end();
01316 const const_iterator b_end = b.end();
01317 const_iterator i = a.begin();
01318 const_iterator j = b.begin();
01319 while (i != a_end && j != b_end)
01320 {
01321 if (*i != *j)
01322 {
01323 return false;
01324 }
01325 ++i;
01326 ++j;
01327 }
01328 return i == a_end && j == b_end;
01329 }
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343 template <typename T, class Alloc>
01344 bool operator!=(const slist<T, Alloc>& a, const slist<T, Alloc>& b)
01345 {
01346 return !(a == b);
01347 }
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363 template <typename T, class Alloc>
01364 bool operator<(const slist<T, Alloc>& a, const slist<T, Alloc>& b)
01365 {
01366 typedef typename slist<T, Alloc>::const_iterator const_iterator;
01367 const const_iterator a_end = a.end();
01368 const const_iterator b_end = b.end();
01369 const_iterator i = a.begin();
01370 const_iterator j = b.begin();
01371 while (i != a_end && j != b_end)
01372 {
01373 if (!(*i < *j))
01374 {
01375 return false;
01376 }
01377 ++i;
01378 ++j;
01379 }
01380 return j != b_end;
01381 }
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395 template <typename T, class Alloc>
01396 bool operator>(const slist<T, Alloc>& a, const slist<T, Alloc>& b)
01397 {
01398 return b < a;
01399 }
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413 template <typename T, class Alloc>
01414 bool operator<=(const slist<T, Alloc>& a, const slist<T, Alloc>& b)
01415 {
01416 return !(b < a);
01417 }
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431 template <typename T, class Alloc>
01432 bool operator>=(const slist<T, Alloc>& a, const slist<T, Alloc>& b)
01433 {
01434 return !(a < b);
01435 }
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447 template <typename T, class Alloc, typename Char, typename Traits>
01448 std::basic_ostream<Char, Traits>&
01449 operator<<(std::basic_ostream<Char, Traits>& ostream,
01450 const slist<T, Alloc>& container)
01451 {
01452 return impl::print_sequence(
01453 ostream, container.begin(), container.end(), "[", ", ", "]");
01454 }
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466 template <typename T, class Alloc, typename Char, typename Traits>
01467 std::basic_istream<Char, Traits>&
01468 operator>>(std::basic_istream<Char, Traits>& istream,
01469 slist<T, Alloc>& container)
01470 {
01471 std::basic_istream<Char, Traits>& result =
01472 impl::read_container<impl::slist_traits, impl::value_traits, T, Char>(
01473 istream, container, '[', ',', 0, ']');
01474 container.reverse();
01475 return result;
01476 }
01477
01478
01479
01480 }
01481
01482 }
01483
01484