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