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