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