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 #ifndef _BASIC_STRING_H
00037 #define _BASIC_STRING_H 1
00038
00039 #pragma GCC system_header
00040
00041 #include <ext/atomicity.h>
00042 #include <debug/debug.h>
00043 #include <initializer_list>
00044
00045 _GLIBCXX_BEGIN_NAMESPACE(std)
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 template<typename _CharT, typename _Traits, typename _Alloc>
00104 class basic_string
00105 {
00106 typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type;
00107
00108
00109 public:
00110 typedef _Traits traits_type;
00111 typedef typename _Traits::char_type value_type;
00112 typedef _Alloc allocator_type;
00113 typedef typename _CharT_alloc_type::size_type size_type;
00114 typedef typename _CharT_alloc_type::difference_type difference_type;
00115 typedef typename _CharT_alloc_type::reference reference;
00116 typedef typename _CharT_alloc_type::const_reference const_reference;
00117 typedef typename _CharT_alloc_type::pointer pointer;
00118 typedef typename _CharT_alloc_type::const_pointer const_pointer;
00119 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
00120 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
00121 const_iterator;
00122 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
00123 typedef std::reverse_iterator<iterator> reverse_iterator;
00124
00125 private:
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 struct _Rep_base
00141 {
00142 size_type _M_length;
00143 size_type _M_capacity;
00144 _Atomic_word _M_refcount;
00145 };
00146
00147 struct _Rep : _Rep_base
00148 {
00149
00150 typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc;
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 static const size_type _S_max_size;
00166 static const _CharT _S_terminal;
00167
00168
00169
00170 static size_type _S_empty_rep_storage[];
00171
00172 static _Rep&
00173 _S_empty_rep()
00174 {
00175
00176
00177
00178 void* __p = reinterpret_cast<void*>(&_S_empty_rep_storage);
00179 return *reinterpret_cast<_Rep*>(__p);
00180 }
00181
00182 bool
00183 _M_is_leaked() const
00184 { return this->_M_refcount < 0; }
00185
00186 bool
00187 _M_is_shared() const
00188 { return this->_M_refcount > 0; }
00189
00190 void
00191 _M_set_leaked()
00192 { this->_M_refcount = -1; }
00193
00194 void
00195 _M_set_sharable()
00196 { this->_M_refcount = 0; }
00197
00198 void
00199 _M_set_length_and_sharable(size_type __n)
00200 {
00201 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
00202 if (__builtin_expect(this != &_S_empty_rep(), false))
00203 #endif
00204 {
00205 this->_M_set_sharable();
00206 this->_M_length = __n;
00207 traits_type::assign(this->_M_refdata()[__n], _S_terminal);
00208
00209
00210 }
00211 }
00212
00213 _CharT*
00214 _M_refdata() throw()
00215 { return reinterpret_cast<_CharT*>(this + 1); }
00216
00217 _CharT*
00218 _M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2)
00219 {
00220 return (!_M_is_leaked() && __alloc1 == __alloc2)
00221 ? _M_refcopy() : _M_clone(__alloc1);
00222 }
00223
00224
00225 static _Rep*
00226 _S_create(size_type, size_type, const _Alloc&);
00227
00228 void
00229 _M_dispose(const _Alloc& __a)
00230 {
00231 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
00232 if (__builtin_expect(this != &_S_empty_rep(), false))
00233 #endif
00234 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
00235 -1) <= 0)
00236 _M_destroy(__a);
00237 }
00238
00239 void
00240 _M_destroy(const _Alloc&) throw();
00241
00242 _CharT*
00243 _M_refcopy() throw()
00244 {
00245 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
00246 if (__builtin_expect(this != &_S_empty_rep(), false))
00247 #endif
00248 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
00249 return _M_refdata();
00250 }
00251
00252 _CharT*
00253 _M_clone(const _Alloc&, size_type __res = 0);
00254 };
00255
00256
00257 struct _Alloc_hider : _Alloc
00258 {
00259 _Alloc_hider(_CharT* __dat, const _Alloc& __a)
00260 : _Alloc(__a), _M_p(__dat) { }
00261
00262 _CharT* _M_p;
00263 };
00264
00265 public:
00266
00267
00268
00269
00270 static const size_type npos = static_cast<size_type>(-1);
00271
00272 private:
00273
00274 mutable _Alloc_hider _M_dataplus;
00275
00276 _CharT*
00277 _M_data() const
00278 { return _M_dataplus._M_p; }
00279
00280 _CharT*
00281 _M_data(_CharT* __p)
00282 { return (_M_dataplus._M_p = __p); }
00283
00284 _Rep*
00285 _M_rep() const
00286 { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }
00287
00288
00289
00290 iterator
00291 _M_ibegin() const
00292 { return iterator(_M_data()); }
00293
00294 iterator
00295 _M_iend() const
00296 { return iterator(_M_data() + this->size()); }
00297
00298 void
00299 _M_leak()
00300 {
00301 if (!_M_rep()->_M_is_leaked())
00302 _M_leak_hard();
00303 }
00304
00305 size_type
00306 _M_check(size_type __pos, const char* __s) const
00307 {
00308 if (__pos > this->size())
00309 __throw_out_of_range(__N(__s));
00310 return __pos;
00311 }
00312
00313 void
00314 _M_check_length(size_type __n1, size_type __n2, const char* __s) const
00315 {
00316 if (this->max_size() - (this->size() - __n1) < __n2)
00317 __throw_length_error(__N(__s));
00318 }
00319
00320
00321 size_type
00322 _M_limit(size_type __pos, size_type __off) const
00323 {
00324 const bool __testoff = __off < this->size() - __pos;
00325 return __testoff ? __off : this->size() - __pos;
00326 }
00327
00328
00329 bool
00330 _M_disjunct(const _CharT* __s) const
00331 {
00332 return (less<const _CharT*>()(__s, _M_data())
00333 || less<const _CharT*>()(_M_data() + this->size(), __s));
00334 }
00335
00336
00337
00338 static void
00339 _M_copy(_CharT* __d, const _CharT* __s, size_type __n)
00340 {
00341 if (__n == 1)
00342 traits_type::assign(*__d, *__s);
00343 else
00344 traits_type::copy(__d, __s, __n);
00345 }
00346
00347 static void
00348 _M_move(_CharT* __d, const _CharT* __s, size_type __n)
00349 {
00350 if (__n == 1)
00351 traits_type::assign(*__d, *__s);
00352 else
00353 traits_type::move(__d, __s, __n);
00354 }
00355
00356 static void
00357 _M_assign(_CharT* __d, size_type __n, _CharT __c)
00358 {
00359 if (__n == 1)
00360 traits_type::assign(*__d, __c);
00361 else
00362 traits_type::assign(__d, __n, __c);
00363 }
00364
00365
00366
00367 template<class _Iterator>
00368 static void
00369 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
00370 {
00371 for (; __k1 != __k2; ++__k1, ++__p)
00372 traits_type::assign(*__p, *__k1);
00373 }
00374
00375 static void
00376 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2)
00377 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
00378
00379 static void
00380 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
00381 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
00382
00383 static void
00384 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2)
00385 { _M_copy(__p, __k1, __k2 - __k1); }
00386
00387 static void
00388 _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
00389 { _M_copy(__p, __k1, __k2 - __k1); }
00390
00391 static int
00392 _S_compare(size_type __n1, size_type __n2)
00393 {
00394 const difference_type __d = difference_type(__n1 - __n2);
00395
00396 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
00397 return __gnu_cxx::__numeric_traits<int>::__max;
00398 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
00399 return __gnu_cxx::__numeric_traits<int>::__min;
00400 else
00401 return int(__d);
00402 }
00403
00404 void
00405 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
00406
00407 void
00408 _M_leak_hard();
00409
00410 static _Rep&
00411 _S_empty_rep()
00412 { return _Rep::_S_empty_rep(); }
00413
00414 public:
00415
00416
00417
00418
00419
00420
00421
00422 basic_string()
00423 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
00424 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
00425 #else
00426 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()){ }
00427 #endif
00428
00429
00430
00431
00432 explicit
00433 basic_string(const _Alloc& __a);
00434
00435
00436
00437
00438
00439
00440 basic_string(const basic_string& __str);
00441
00442
00443
00444
00445
00446
00447 basic_string(const basic_string& __str, size_type __pos,
00448 size_type __n = npos);
00449
00450
00451
00452
00453
00454
00455
00456 basic_string(const basic_string& __str, size_type __pos,
00457 size_type __n, const _Alloc& __a);
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468 basic_string(const _CharT* __s, size_type __n,
00469 const _Alloc& __a = _Alloc());
00470
00471
00472
00473
00474
00475 basic_string(const _CharT* __s, const _Alloc& __a = _Alloc());
00476
00477
00478
00479
00480
00481
00482 basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
00483
00484 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00485
00486
00487
00488
00489
00490
00491
00492 basic_string(basic_string&& __str)
00493 : _M_dataplus(__str._M_dataplus)
00494 {
00495 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
00496 __str._M_data(_S_empty_rep()._M_refdata());
00497 #else
00498 __str._M_data(_S_construct(size_type(), _CharT(), get_allocator()));
00499 #endif
00500 }
00501
00502
00503
00504
00505
00506
00507 basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc());
00508 #endif // __GXX_EXPERIMENTAL_CXX0X__
00509
00510
00511
00512
00513
00514
00515
00516 template<class _InputIterator>
00517 basic_string(_InputIterator __beg, _InputIterator __end,
00518 const _Alloc& __a = _Alloc());
00519
00520
00521
00522
00523 ~basic_string()
00524 { _M_rep()->_M_dispose(this->get_allocator()); }
00525
00526
00527
00528
00529
00530 basic_string&
00531 operator=(const basic_string& __str)
00532 { return this->assign(__str); }
00533
00534
00535
00536
00537
00538 basic_string&
00539 operator=(const _CharT* __s)
00540 { return this->assign(__s); }
00541
00542
00543
00544
00545
00546
00547
00548
00549 basic_string&
00550 operator=(_CharT __c)
00551 {
00552 this->assign(1, __c);
00553 return *this;
00554 }
00555
00556 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00557
00558
00559
00560
00561
00562
00563
00564 basic_string&
00565 operator=(basic_string&& __str)
00566 {
00567
00568 this->swap(__str);
00569 return *this;
00570 }
00571
00572
00573
00574
00575
00576 basic_string&
00577 operator=(initializer_list<_CharT> __l)
00578 {
00579 this->assign(__l.begin(), __l.size());
00580 return *this;
00581 }
00582 #endif // __GXX_EXPERIMENTAL_CXX0X__
00583
00584
00585
00586
00587
00588
00589 iterator
00590 begin()
00591 {
00592 _M_leak();
00593 return iterator(_M_data());
00594 }
00595
00596
00597
00598
00599
00600 const_iterator
00601 begin() const
00602 { return const_iterator(_M_data()); }
00603
00604
00605
00606
00607
00608 iterator
00609 end()
00610 {
00611 _M_leak();
00612 return iterator(_M_data() + this->size());
00613 }
00614
00615
00616
00617
00618
00619 const_iterator
00620 end() const
00621 { return const_iterator(_M_data() + this->size()); }
00622
00623
00624
00625
00626
00627
00628 reverse_iterator
00629 rbegin()
00630 { return reverse_iterator(this->end()); }
00631
00632
00633
00634
00635
00636
00637 const_reverse_iterator
00638 rbegin() const
00639 { return const_reverse_iterator(this->end()); }
00640
00641
00642
00643
00644
00645
00646 reverse_iterator
00647 rend()
00648 { return reverse_iterator(this->begin()); }
00649
00650
00651
00652
00653
00654
00655 const_reverse_iterator
00656 rend() const
00657 { return const_reverse_iterator(this->begin()); }
00658
00659 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00660
00661
00662
00663
00664 const_iterator
00665 cbegin() const
00666 { return const_iterator(this->_M_data()); }
00667
00668
00669
00670
00671
00672 const_iterator
00673 cend() const
00674 { return const_iterator(this->_M_data() + this->size()); }
00675
00676
00677
00678
00679
00680
00681 const_reverse_iterator
00682 crbegin() const
00683 { return const_reverse_iterator(this->end()); }
00684
00685
00686
00687
00688
00689
00690 const_reverse_iterator
00691 crend() const
00692 { return const_reverse_iterator(this->begin()); }
00693 #endif
00694
00695 public:
00696
00697
00698
00699 size_type
00700 size() const
00701 { return _M_rep()->_M_length; }
00702
00703
00704
00705 size_type
00706 length() const
00707 { return _M_rep()->_M_length; }
00708
00709
00710 size_type
00711 max_size() const
00712 { return _Rep::_S_max_size; }
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724 void
00725 resize(size_type __n, _CharT __c);
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737 void
00738 resize(size_type __n)
00739 { this->resize(__n, _CharT()); }
00740
00741 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00742
00743 void
00744 shrink_to_fit()
00745 {
00746 __try
00747 { reserve(0); }
00748 __catch(...)
00749 { }
00750 }
00751 #endif
00752
00753
00754
00755
00756
00757 size_type
00758 capacity() const
00759 { return _M_rep()->_M_capacity; }
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778 void
00779 reserve(size_type __res_arg = 0);
00780
00781
00782
00783
00784 void
00785 clear()
00786 { _M_mutate(0, this->size(), 0); }
00787
00788
00789
00790
00791
00792 bool
00793 empty() const
00794 { return this->size() == 0; }
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807 const_reference
00808 operator[] (size_type __pos) const
00809 {
00810 _GLIBCXX_DEBUG_ASSERT(__pos <= size());
00811 return _M_data()[__pos];
00812 }
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824 reference
00825 operator[](size_type __pos)
00826 {
00827
00828 _GLIBCXX_DEBUG_ASSERT(__pos <= size());
00829
00830 _GLIBCXX_DEBUG_PEDASSERT(__pos < size());
00831 _M_leak();
00832 return _M_data()[__pos];
00833 }
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845 const_reference
00846 at(size_type __n) const
00847 {
00848 if (__n >= this->size())
00849 __throw_out_of_range(__N("basic_string::at"));
00850 return _M_data()[__n];
00851 }
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864 reference
00865 at(size_type __n)
00866 {
00867 if (__n >= size())
00868 __throw_out_of_range(__N("basic_string::at"));
00869 _M_leak();
00870 return _M_data()[__n];
00871 }
00872
00873
00874
00875
00876
00877
00878
00879 basic_string&
00880 operator+=(const basic_string& __str)
00881 { return this->append(__str); }
00882
00883
00884
00885
00886
00887
00888 basic_string&
00889 operator+=(const _CharT* __s)
00890 { return this->append(__s); }
00891
00892
00893
00894
00895
00896
00897 basic_string&
00898 operator+=(_CharT __c)
00899 {
00900 this->push_back(__c);
00901 return *this;
00902 }
00903
00904 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00905
00906
00907
00908
00909
00910 basic_string&
00911 operator+=(initializer_list<_CharT> __l)
00912 { return this->append(__l.begin(), __l.size()); }
00913 #endif // __GXX_EXPERIMENTAL_CXX0X__
00914
00915
00916
00917
00918
00919
00920 basic_string&
00921 append(const basic_string& __str);
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935 basic_string&
00936 append(const basic_string& __str, size_type __pos, size_type __n);
00937
00938
00939
00940
00941
00942
00943
00944 basic_string&
00945 append(const _CharT* __s, size_type __n);
00946
00947
00948
00949
00950
00951
00952 basic_string&
00953 append(const _CharT* __s)
00954 {
00955 __glibcxx_requires_string(__s);
00956 return this->append(__s, traits_type::length(__s));
00957 }
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967 basic_string&
00968 append(size_type __n, _CharT __c);
00969
00970 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00971
00972
00973
00974
00975
00976 basic_string&
00977 append(initializer_list<_CharT> __l)
00978 { return this->append(__l.begin(), __l.size()); }
00979 #endif // __GXX_EXPERIMENTAL_CXX0X__
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989 template<class _InputIterator>
00990 basic_string&
00991 append(_InputIterator __first, _InputIterator __last)
00992 { return this->replace(_M_iend(), _M_iend(), __first, __last); }
00993
00994
00995
00996
00997
00998 void
00999 push_back(_CharT __c)
01000 {
01001 const size_type __len = 1 + this->size();
01002 if (__len > this->capacity() || _M_rep()->_M_is_shared())
01003 this->reserve(__len);
01004 traits_type::assign(_M_data()[this->size()], __c);
01005 _M_rep()->_M_set_length_and_sharable(__len);
01006 }
01007
01008
01009
01010
01011
01012
01013 basic_string&
01014 assign(const basic_string& __str);
01015
01016 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01017
01018
01019
01020
01021
01022
01023
01024
01025 basic_string&
01026 assign(basic_string&& __str)
01027 {
01028 this->swap(__str);
01029 return *this;
01030 }
01031 #endif // __GXX_EXPERIMENTAL_CXX0X__
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045 basic_string&
01046 assign(const basic_string& __str, size_type __pos, size_type __n)
01047 { return this->assign(__str._M_data()
01048 + __str._M_check(__pos, "basic_string::assign"),
01049 __str._M_limit(__pos, __n)); }
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061 basic_string&
01062 assign(const _CharT* __s, size_type __n);
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073 basic_string&
01074 assign(const _CharT* __s)
01075 {
01076 __glibcxx_requires_string(__s);
01077 return this->assign(__s, traits_type::length(__s));
01078 }
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089 basic_string&
01090 assign(size_type __n, _CharT __c)
01091 { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101 template<class _InputIterator>
01102 basic_string&
01103 assign(_InputIterator __first, _InputIterator __last)
01104 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
01105
01106 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01107
01108
01109
01110
01111
01112 basic_string&
01113 assign(initializer_list<_CharT> __l)
01114 { return this->assign(__l.begin(), __l.size()); }
01115 #endif // __GXX_EXPERIMENTAL_CXX0X__
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129 void
01130 insert(iterator __p, size_type __n, _CharT __c)
01131 { this->replace(__p, __p, __n, __c); }
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144 template<class _InputIterator>
01145 void
01146 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
01147 { this->replace(__p, __p, __beg, __end); }
01148
01149 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01150
01151
01152
01153
01154
01155
01156 void
01157 insert(iterator __p, initializer_list<_CharT> __l)
01158 {
01159 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
01160 this->insert(__p - _M_ibegin(), __l.begin(), __l.size());
01161 }
01162 #endif // __GXX_EXPERIMENTAL_CXX0X__
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175 basic_string&
01176 insert(size_type __pos1, const basic_string& __str)
01177 { return this->insert(__pos1, __str, size_type(0), __str.size()); }
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197 basic_string&
01198 insert(size_type __pos1, const basic_string& __str,
01199 size_type __pos2, size_type __n)
01200 { return this->insert(__pos1, __str._M_data()
01201 + __str._M_check(__pos2, "basic_string::insert"),
01202 __str._M_limit(__pos2, __n)); }
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220 basic_string&
01221 insert(size_type __pos, const _CharT* __s, size_type __n);
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238 basic_string&
01239 insert(size_type __pos, const _CharT* __s)
01240 {
01241 __glibcxx_requires_string(__s);
01242 return this->insert(__pos, __s, traits_type::length(__s));
01243 }
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261 basic_string&
01262 insert(size_type __pos, size_type __n, _CharT __c)
01263 { return _M_replace_aux(_M_check(__pos, "basic_string::insert"),
01264 size_type(0), __n, __c); }
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278 iterator
01279 insert(iterator __p, _CharT __c)
01280 {
01281 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
01282 const size_type __pos = __p - _M_ibegin();
01283 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
01284 _M_rep()->_M_set_leaked();
01285 return iterator(_M_data() + __pos);
01286 }
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302 basic_string&
01303 erase(size_type __pos = 0, size_type __n = npos)
01304 {
01305 _M_mutate(_M_check(__pos, "basic_string::erase"),
01306 _M_limit(__pos, __n), size_type(0));
01307 return *this;
01308 }
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318 iterator
01319 erase(iterator __position)
01320 {
01321 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
01322 && __position < _M_iend());
01323 const size_type __pos = __position - _M_ibegin();
01324 _M_mutate(__pos, size_type(1), size_type(0));
01325 _M_rep()->_M_set_leaked();
01326 return iterator(_M_data() + __pos);
01327 }
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338 iterator
01339 erase(iterator __first, iterator __last);
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357 basic_string&
01358 replace(size_type __pos, size_type __n, const basic_string& __str)
01359 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379 basic_string&
01380 replace(size_type __pos1, size_type __n1, const basic_string& __str,
01381 size_type __pos2, size_type __n2)
01382 { return this->replace(__pos1, __n1, __str._M_data()
01383 + __str._M_check(__pos2, "basic_string::replace"),
01384 __str._M_limit(__pos2, __n2)); }
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403 basic_string&
01404 replace(size_type __pos, size_type __n1, const _CharT* __s,
01405 size_type __n2);
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422 basic_string&
01423 replace(size_type __pos, size_type __n1, const _CharT* __s)
01424 {
01425 __glibcxx_requires_string(__s);
01426 return this->replace(__pos, __n1, __s, traits_type::length(__s));
01427 }
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445 basic_string&
01446 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
01447 { return _M_replace_aux(_M_check(__pos, "basic_string::replace"),
01448 _M_limit(__pos, __n1), __n2, __c); }
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463 basic_string&
01464 replace(iterator __i1, iterator __i2, const basic_string& __str)
01465 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481 basic_string&
01482 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
01483 {
01484 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
01485 && __i2 <= _M_iend());
01486 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
01487 }
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502 basic_string&
01503 replace(iterator __i1, iterator __i2, const _CharT* __s)
01504 {
01505 __glibcxx_requires_string(__s);
01506 return this->replace(__i1, __i2, __s, traits_type::length(__s));
01507 }
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523 basic_string&
01524 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
01525 {
01526 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
01527 && __i2 <= _M_iend());
01528 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
01529 }
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545 template<class _InputIterator>
01546 basic_string&
01547 replace(iterator __i1, iterator __i2,
01548 _InputIterator __k1, _InputIterator __k2)
01549 {
01550 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
01551 && __i2 <= _M_iend());
01552 __glibcxx_requires_valid_range(__k1, __k2);
01553 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
01554 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
01555 }
01556
01557
01558
01559 basic_string&
01560 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
01561 {
01562 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
01563 && __i2 <= _M_iend());
01564 __glibcxx_requires_valid_range(__k1, __k2);
01565 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
01566 __k1, __k2 - __k1);
01567 }
01568
01569 basic_string&
01570 replace(iterator __i1, iterator __i2,
01571 const _CharT* __k1, const _CharT* __k2)
01572 {
01573 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
01574 && __i2 <= _M_iend());
01575 __glibcxx_requires_valid_range(__k1, __k2);
01576 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
01577 __k1, __k2 - __k1);
01578 }
01579
01580 basic_string&
01581 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
01582 {
01583 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
01584 && __i2 <= _M_iend());
01585 __glibcxx_requires_valid_range(__k1, __k2);
01586 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
01587 __k1.base(), __k2 - __k1);
01588 }
01589
01590 basic_string&
01591 replace(iterator __i1, iterator __i2,
01592 const_iterator __k1, const_iterator __k2)
01593 {
01594 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
01595 && __i2 <= _M_iend());
01596 __glibcxx_requires_valid_range(__k1, __k2);
01597 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
01598 __k1.base(), __k2 - __k1);
01599 }
01600
01601 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615 basic_string& replace(iterator __i1, iterator __i2,
01616 initializer_list<_CharT> __l)
01617 { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
01618 #endif // __GXX_EXPERIMENTAL_CXX0X__
01619
01620 private:
01621 template<class _Integer>
01622 basic_string&
01623 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
01624 _Integer __val, __true_type)
01625 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
01626
01627 template<class _InputIterator>
01628 basic_string&
01629 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
01630 _InputIterator __k2, __false_type);
01631
01632 basic_string&
01633 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
01634 _CharT __c);
01635
01636 basic_string&
01637 _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s,
01638 size_type __n2);
01639
01640
01641
01642 template<class _InIterator>
01643 static _CharT*
01644 _S_construct_aux(_InIterator __beg, _InIterator __end,
01645 const _Alloc& __a, __false_type)
01646 {
01647 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
01648 return _S_construct(__beg, __end, __a, _Tag());
01649 }
01650
01651
01652
01653 template<class _Integer>
01654 static _CharT*
01655 _S_construct_aux(_Integer __beg, _Integer __end,
01656 const _Alloc& __a, __true_type)
01657 { return _S_construct_aux_2(static_cast<size_type>(__beg),
01658 __end, __a); }
01659
01660 static _CharT*
01661 _S_construct_aux_2(size_type __req, _CharT __c, const _Alloc& __a)
01662 { return _S_construct(__req, __c, __a); }
01663
01664 template<class _InIterator>
01665 static _CharT*
01666 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a)
01667 {
01668 typedef typename std::__is_integer<_InIterator>::__type _Integral;
01669 return _S_construct_aux(__beg, __end, __a, _Integral());
01670 }
01671
01672
01673 template<class _InIterator>
01674 static _CharT*
01675 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
01676 input_iterator_tag);
01677
01678
01679
01680 template<class _FwdIterator>
01681 static _CharT*
01682 _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a,
01683 forward_iterator_tag);
01684
01685 static _CharT*
01686 _S_construct(size_type __req, _CharT __c, const _Alloc& __a);
01687
01688 public:
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701 size_type
01702 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
01703
01704
01705
01706
01707
01708
01709
01710
01711 void
01712 swap(basic_string& __s);
01713
01714
01715
01716
01717
01718
01719
01720
01721 const _CharT*
01722 c_str() const
01723 { return _M_data(); }
01724
01725
01726
01727
01728
01729
01730
01731 const _CharT*
01732 data() const
01733 { return _M_data(); }
01734
01735
01736
01737
01738 allocator_type
01739 get_allocator() const
01740 { return _M_dataplus; }
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752
01753 size_type
01754 find(const _CharT* __s, size_type __pos, size_type __n) const;
01755
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766 size_type
01767 find(const basic_string& __str, size_type __pos = 0) const
01768 { return this->find(__str.data(), __pos, __str.size()); }
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780 size_type
01781 find(const _CharT* __s, size_type __pos = 0) const
01782 {
01783 __glibcxx_requires_string(__s);
01784 return this->find(__s, __pos, traits_type::length(__s));
01785 }
01786
01787
01788
01789
01790
01791
01792
01793
01794
01795
01796
01797 size_type
01798 find(_CharT __c, size_type __pos = 0) const;
01799
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810 size_type
01811 rfind(const basic_string& __str, size_type __pos = npos) const
01812 { return this->rfind(__str.data(), __pos, __str.size()); }
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825 size_type
01826 rfind(const _CharT* __s, size_type __pos, size_type __n) const;
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838 size_type
01839 rfind(const _CharT* __s, size_type __pos = npos) const
01840 {
01841 __glibcxx_requires_string(__s);
01842 return this->rfind(__s, __pos, traits_type::length(__s));
01843 }
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855 size_type
01856 rfind(_CharT __c, size_type __pos = npos) const;
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868 size_type
01869 find_first_of(const basic_string& __str, size_type __pos = 0) const
01870 { return this->find_first_of(__str.data(), __pos, __str.size()); }
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883 size_type
01884 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
01885
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896 size_type
01897 find_first_of(const _CharT* __s, size_type __pos = 0) const
01898 {
01899 __glibcxx_requires_string(__s);
01900 return this->find_first_of(__s, __pos, traits_type::length(__s));
01901 }
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913
01914
01915 size_type
01916 find_first_of(_CharT __c, size_type __pos = 0) const
01917 { return this->find(__c, __pos); }
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929 size_type
01930 find_last_of(const basic_string& __str, size_type __pos = npos) const
01931 { return this->find_last_of(__str.data(), __pos, __str.size()); }
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944 size_type
01945 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957 size_type
01958 find_last_of(const _CharT* __s, size_type __pos = npos) const
01959 {
01960 __glibcxx_requires_string(__s);
01961 return this->find_last_of(__s, __pos, traits_type::length(__s));
01962 }
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975
01976 size_type
01977 find_last_of(_CharT __c, size_type __pos = npos) const
01978 { return this->rfind(__c, __pos); }
01979
01980
01981
01982
01983
01984
01985
01986
01987
01988
01989
01990 size_type
01991 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
01992 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
01993
01994
01995
01996
01997
01998
01999
02000
02001
02002
02003
02004
02005 size_type
02006 find_first_not_of(const _CharT* __s, size_type __pos,
02007 size_type __n) const;
02008
02009
02010
02011
02012
02013
02014
02015
02016
02017
02018
02019 size_type
02020 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
02021 {
02022 __glibcxx_requires_string(__s);
02023 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
02024 }
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035
02036 size_type
02037 find_first_not_of(_CharT __c, size_type __pos = 0) const;
02038
02039
02040
02041
02042
02043
02044
02045
02046
02047
02048
02049 size_type
02050 find_last_not_of(const basic_string& __str, size_type __pos = npos) const
02051 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065 size_type
02066 find_last_not_of(const _CharT* __s, size_type __pos,
02067 size_type __n) const;
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078 size_type
02079 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
02080 {
02081 __glibcxx_requires_string(__s);
02082 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
02083 }
02084
02085
02086
02087
02088
02089
02090
02091
02092
02093
02094
02095 size_type
02096 find_last_not_of(_CharT __c, size_type __pos = npos) const;
02097
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109
02110 basic_string
02111 substr(size_type __pos = 0, size_type __n = npos) const
02112 { return basic_string(*this,
02113 _M_check(__pos, "basic_string::substr"), __n); }
02114
02115
02116
02117
02118
02119
02120
02121
02122
02123
02124
02125
02126
02127
02128 int
02129 compare(const basic_string& __str) const
02130 {
02131 const size_type __size = this->size();
02132 const size_type __osize = __str.size();
02133 const size_type __len = std::min(__size, __osize);
02134
02135 int __r = traits_type::compare(_M_data(), __str.data(), __len);
02136 if (!__r)
02137 __r = _S_compare(__size, __osize);
02138 return __r;
02139 }
02140
02141
02142
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158 int
02159 compare(size_type __pos, size_type __n, const basic_string& __str) const;
02160
02161
02162
02163
02164
02165
02166
02167
02168
02169
02170
02171
02172
02173
02174
02175
02176
02177
02178
02179
02180
02181
02182 int
02183 compare(size_type __pos1, size_type __n1, const basic_string& __str,
02184 size_type __pos2, size_type __n2) const;
02185
02186
02187
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200 int
02201 compare(const _CharT* __s) const;
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212
02213
02214
02215
02216
02217
02218
02219
02220
02221
02222
02223 int
02224 compare(size_type __pos, size_type __n1, const _CharT* __s) const;
02225
02226
02227
02228
02229
02230
02231
02232
02233
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248 int
02249 compare(size_type __pos, size_type __n1, const _CharT* __s,
02250 size_type __n2) const;
02251 };
02252
02253
02254
02255
02256
02257
02258
02259
02260 template<typename _CharT, typename _Traits, typename _Alloc>
02261 basic_string<_CharT, _Traits, _Alloc>
02262 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
02263 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
02264 {
02265 basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
02266 __str.append(__rhs);
02267 return __str;
02268 }
02269
02270
02271
02272
02273
02274
02275
02276 template<typename _CharT, typename _Traits, typename _Alloc>
02277 basic_string<_CharT,_Traits,_Alloc>
02278 operator+(const _CharT* __lhs,
02279 const basic_string<_CharT,_Traits,_Alloc>& __rhs);
02280
02281
02282
02283
02284
02285
02286
02287 template<typename _CharT, typename _Traits, typename _Alloc>
02288 basic_string<_CharT,_Traits,_Alloc>
02289 operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs);
02290
02291
02292
02293
02294
02295
02296
02297 template<typename _CharT, typename _Traits, typename _Alloc>
02298 inline basic_string<_CharT, _Traits, _Alloc>
02299 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
02300 const _CharT* __rhs)
02301 {
02302 basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
02303 __str.append(__rhs);
02304 return __str;
02305 }
02306
02307
02308
02309
02310
02311
02312
02313 template<typename _CharT, typename _Traits, typename _Alloc>
02314 inline basic_string<_CharT, _Traits, _Alloc>
02315 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
02316 {
02317 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
02318 typedef typename __string_type::size_type __size_type;
02319 __string_type __str(__lhs);
02320 __str.append(__size_type(1), __rhs);
02321 return __str;
02322 }
02323
02324
02325
02326
02327
02328
02329
02330
02331 template<typename _CharT, typename _Traits, typename _Alloc>
02332 inline bool
02333 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
02334 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
02335 { return __lhs.compare(__rhs) == 0; }
02336
02337 template<typename _CharT>
02338 inline
02339 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, bool>::__type
02340 operator==(const basic_string<_CharT>& __lhs,
02341 const basic_string<_CharT>& __rhs)
02342 { return (__lhs.size() == __rhs.size()
02343 && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
02344 __lhs.size())); }
02345
02346
02347
02348
02349
02350
02351
02352 template<typename _CharT, typename _Traits, typename _Alloc>
02353 inline bool
02354 operator==(const _CharT* __lhs,
02355 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
02356 { return __rhs.compare(__lhs) == 0; }
02357
02358
02359
02360
02361
02362
02363
02364 template<typename _CharT, typename _Traits, typename _Alloc>
02365 inline bool
02366 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
02367 const _CharT* __rhs)
02368 { return __lhs.compare(__rhs) == 0; }
02369
02370
02371
02372
02373
02374
02375
02376
02377 template<typename _CharT, typename _Traits, typename _Alloc>
02378 inline bool
02379 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
02380 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
02381 { return !(__lhs == __rhs); }
02382
02383
02384
02385
02386
02387
02388
02389 template<typename _CharT, typename _Traits, typename _Alloc>
02390 inline bool
02391 operator!=(const _CharT* __lhs,
02392 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
02393 { return !(__lhs == __rhs); }
02394
02395
02396
02397
02398
02399
02400
02401 template<typename _CharT, typename _Traits, typename _Alloc>
02402 inline bool
02403 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
02404 const _CharT* __rhs)
02405 { return !(__lhs == __rhs); }
02406
02407
02408
02409
02410
02411
02412
02413
02414 template<typename _CharT, typename _Traits, typename _Alloc>
02415 inline bool
02416 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
02417 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
02418 { return __lhs.compare(__rhs) < 0; }
02419
02420
02421
02422
02423
02424
02425
02426 template<typename _CharT, typename _Traits, typename _Alloc>
02427 inline bool
02428 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
02429 const _CharT* __rhs)
02430 { return __lhs.compare(__rhs) < 0; }
02431
02432
02433
02434
02435
02436
02437
02438 template<typename _CharT, typename _Traits, typename _Alloc>
02439 inline bool
02440 operator<(const _CharT* __lhs,
02441 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
02442 { return __rhs.compare(__lhs) > 0; }
02443
02444
02445
02446
02447
02448
02449
02450
02451 template<typename _CharT, typename _Traits, typename _Alloc>
02452 inline bool
02453 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
02454 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
02455 { return __lhs.compare(__rhs) > 0; }
02456
02457
02458
02459
02460
02461
02462
02463 template<typename _CharT, typename _Traits, typename _Alloc>
02464 inline bool
02465 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
02466 const _CharT* __rhs)
02467 { return __lhs.compare(__rhs) > 0; }
02468
02469
02470
02471
02472
02473
02474
02475 template<typename _CharT, typename _Traits, typename _Alloc>
02476 inline bool
02477 operator>(const _CharT* __lhs,
02478 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
02479 { return __rhs.compare(__lhs) < 0; }
02480
02481
02482
02483
02484
02485
02486
02487
02488 template<typename _CharT, typename _Traits, typename _Alloc>
02489 inline bool
02490 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
02491 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
02492 { return __lhs.compare(__rhs) <= 0; }
02493
02494
02495
02496
02497
02498
02499
02500 template<typename _CharT, typename _Traits, typename _Alloc>
02501 inline bool
02502 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
02503 const _CharT* __rhs)
02504 { return __lhs.compare(__rhs) <= 0; }
02505
02506
02507
02508
02509
02510
02511
02512 template<typename _CharT, typename _Traits, typename _Alloc>
02513 inline bool
02514 operator<=(const _CharT* __lhs,
02515 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
02516 { return __rhs.compare(__lhs) >= 0; }
02517
02518
02519
02520
02521
02522
02523
02524
02525 template<typename _CharT, typename _Traits, typename _Alloc>
02526 inline bool
02527 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
02528 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
02529 { return __lhs.compare(__rhs) >= 0; }
02530
02531
02532
02533
02534
02535
02536
02537 template<typename _CharT, typename _Traits, typename _Alloc>
02538 inline bool
02539 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
02540 const _CharT* __rhs)
02541 { return __lhs.compare(__rhs) >= 0; }
02542
02543
02544
02545
02546
02547
02548
02549 template<typename _CharT, typename _Traits, typename _Alloc>
02550 inline bool
02551 operator>=(const _CharT* __lhs,
02552 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
02553 { return __rhs.compare(__lhs) <= 0; }
02554
02555
02556
02557
02558
02559
02560
02561
02562 template<typename _CharT, typename _Traits, typename _Alloc>
02563 inline void
02564 swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
02565 basic_string<_CharT, _Traits, _Alloc>& __rhs)
02566 { __lhs.swap(__rhs); }
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579 template<typename _CharT, typename _Traits, typename _Alloc>
02580 basic_istream<_CharT, _Traits>&
02581 operator>>(basic_istream<_CharT, _Traits>& __is,
02582 basic_string<_CharT, _Traits, _Alloc>& __str);
02583
02584 template<>
02585 basic_istream<char>&
02586 operator>>(basic_istream<char>& __is, basic_string<char>& __str);
02587
02588
02589
02590
02591
02592
02593
02594
02595
02596
02597 template<typename _CharT, typename _Traits, typename _Alloc>
02598 inline basic_ostream<_CharT, _Traits>&
02599 operator<<(basic_ostream<_CharT, _Traits>& __os,
02600 const basic_string<_CharT, _Traits, _Alloc>& __str)
02601 {
02602
02603
02604 return __ostream_insert(__os, __str.data(), __str.size());
02605 }
02606
02607
02608
02609
02610
02611
02612
02613
02614
02615
02616
02617
02618
02619
02620 template<typename _CharT, typename _Traits, typename _Alloc>
02621 basic_istream<_CharT, _Traits>&
02622 getline(basic_istream<_CharT, _Traits>& __is,
02623 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
02624
02625
02626
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638 template<typename _CharT, typename _Traits, typename _Alloc>
02639 inline basic_istream<_CharT, _Traits>&
02640 getline(basic_istream<_CharT, _Traits>& __is,
02641 basic_string<_CharT, _Traits, _Alloc>& __str)
02642 { return getline(__is, __str, __is.widen('\n')); }
02643
02644 template<>
02645 basic_istream<char>&
02646 getline(basic_istream<char>& __in, basic_string<char>& __str,
02647 char __delim);
02648
02649 #ifdef _GLIBCXX_USE_WCHAR_T
02650 template<>
02651 basic_istream<wchar_t>&
02652 getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
02653 wchar_t __delim);
02654 #endif
02655
02656 _GLIBCXX_END_NAMESPACE
02657
02658 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99) \
02659 && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
02660
02661 #include <ext/string_conversions.h>
02662
02663 _GLIBCXX_BEGIN_NAMESPACE(std)
02664
02665
02666 inline int
02667 stoi(const string& __str, size_t* __idx = 0, int __base = 10)
02668 { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
02669 __idx, __base); }
02670
02671 inline long
02672 stol(const string& __str, size_t* __idx = 0, int __base = 10)
02673 { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
02674 __idx, __base); }
02675
02676 inline unsigned long
02677 stoul(const string& __str, size_t* __idx = 0, int __base = 10)
02678 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
02679 __idx, __base); }
02680
02681 inline long long
02682 stoll(const string& __str, size_t* __idx = 0, int __base = 10)
02683 { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
02684 __idx, __base); }
02685
02686 inline unsigned long long
02687 stoull(const string& __str, size_t* __idx = 0, int __base = 10)
02688 { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
02689 __idx, __base); }
02690
02691
02692 inline float
02693 stof(const string& __str, size_t* __idx = 0)
02694 { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
02695
02696 inline double
02697 stod(const string& __str, size_t* __idx = 0)
02698 { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
02699
02700 inline long double
02701 stold(const string& __str, size_t* __idx = 0)
02702 { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
02703
02704
02705
02706
02707 inline string
02708 to_string(int __val)
02709 { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(int),
02710 "%d", __val); }
02711
02712 inline string
02713 to_string(unsigned __val)
02714 { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
02715 4 * sizeof(unsigned),
02716 "%u", __val); }
02717
02718 inline string
02719 to_string(long __val)
02720 { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(long),
02721 "%ld", __val); }
02722
02723 inline string
02724 to_string(unsigned long __val)
02725 { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
02726 4 * sizeof(unsigned long),
02727 "%lu", __val); }
02728
02729 inline string
02730 to_string(long long __val)
02731 { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
02732 4 * sizeof(long long),
02733 "%lld", __val); }
02734
02735 inline string
02736 to_string(unsigned long long __val)
02737 { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
02738 4 * sizeof(unsigned long long),
02739 "%llu", __val); }
02740
02741 inline string
02742 to_string(float __val)
02743 {
02744 const int __n =
02745 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
02746 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
02747 "%f", __val);
02748 }
02749
02750 inline string
02751 to_string(double __val)
02752 {
02753 const int __n =
02754 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
02755 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
02756 "%f", __val);
02757 }
02758
02759 inline string
02760 to_string(long double __val)
02761 {
02762 const int __n =
02763 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
02764 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
02765 "%Lf", __val);
02766 }
02767
02768 #ifdef _GLIBCXX_USE_WCHAR_T
02769 inline int
02770 stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
02771 { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
02772 __idx, __base); }
02773
02774 inline long
02775 stol(const wstring& __str, size_t* __idx = 0, int __base = 10)
02776 { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
02777 __idx, __base); }
02778
02779 inline unsigned long
02780 stoul(const wstring& __str, size_t* __idx = 0, int __base = 10)
02781 { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
02782 __idx, __base); }
02783
02784 inline long long
02785 stoll(const wstring& __str, size_t* __idx = 0, int __base = 10)
02786 { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
02787 __idx, __base); }
02788
02789 inline unsigned long long
02790 stoull(const wstring& __str, size_t* __idx = 0, int __base = 10)
02791 { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
02792 __idx, __base); }
02793
02794
02795 inline float
02796 stof(const wstring& __str, size_t* __idx = 0)
02797 { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
02798
02799 inline double
02800 stod(const wstring& __str, size_t* __idx = 0)
02801 { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
02802
02803 inline long double
02804 stold(const wstring& __str, size_t* __idx = 0)
02805 { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
02806
02807
02808 inline wstring
02809 to_wstring(int __val)
02810 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(int),
02811 L"%d", __val); }
02812
02813 inline wstring
02814 to_wstring(unsigned __val)
02815 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
02816 4 * sizeof(unsigned),
02817 L"%u", __val); }
02818
02819 inline wstring
02820 to_wstring(long __val)
02821 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(long),
02822 L"%ld", __val); }
02823
02824 inline wstring
02825 to_wstring(unsigned long __val)
02826 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
02827 4 * sizeof(unsigned long),
02828 L"%lu", __val); }
02829
02830 inline wstring
02831 to_wstring(long long __val)
02832 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
02833 4 * sizeof(long long),
02834 L"%lld", __val); }
02835
02836 inline wstring
02837 to_wstring(unsigned long long __val)
02838 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
02839 4 * sizeof(unsigned long long),
02840 L"%llu", __val); }
02841
02842 inline wstring
02843 to_wstring(float __val)
02844 {
02845 const int __n =
02846 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
02847 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
02848 L"%f", __val);
02849 }
02850
02851 inline wstring
02852 to_wstring(double __val)
02853 {
02854 const int __n =
02855 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
02856 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
02857 L"%f", __val);
02858 }
02859
02860 inline wstring
02861 to_wstring(long double __val)
02862 {
02863 const int __n =
02864 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
02865 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
02866 L"%Lf", __val);
02867 }
02868 #endif
02869
02870 _GLIBCXX_END_NAMESPACE
02871
02872 #endif
02873
02874 #ifdef __GXX_EXPERIMENTAL_CXX0X__
02875
02876 #include <bits/functional_hash.h>
02877
02878 _GLIBCXX_BEGIN_NAMESPACE(std)
02879
02880
02881
02882 #ifndef _GLIBCXX_COMPATIBILITY_CXX0X
02883
02884 template<>
02885 struct hash<string>
02886 : public std::unary_function<string, size_t>
02887 {
02888 size_t
02889 operator()(const string& __s) const
02890 { return std::_Fnv_hash::hash(__s.data(), __s.length()); }
02891 };
02892
02893 #ifdef _GLIBCXX_USE_WCHAR_T
02894
02895 template<>
02896 struct hash<wstring>
02897 : public std::unary_function<wstring, size_t>
02898 {
02899 size_t
02900 operator()(const wstring& __s) const
02901 { return std::_Fnv_hash::hash(__s.data(),
02902 __s.length() * sizeof(wchar_t)); }
02903 };
02904 #endif
02905 #endif
02906
02907 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
02908
02909 template<>
02910 struct hash<u16string>
02911 : public std::unary_function<u16string, size_t>
02912 {
02913 size_t
02914 operator()(const u16string& __s) const
02915 { return std::_Fnv_hash::hash(__s.data(),
02916 __s.length() * sizeof(char16_t)); }
02917 };
02918
02919
02920 template<>
02921 struct hash<u32string>
02922 : public std::unary_function<u32string, size_t>
02923 {
02924 size_t
02925 operator()(const u32string& __s) const
02926 { return std::_Fnv_hash::hash(__s.data(),
02927 __s.length() * sizeof(char32_t)); }
02928 };
02929 #endif
02930
02931 _GLIBCXX_END_NAMESPACE
02932
02933 #endif
02934
02935 #endif