/home/ntakagi/work/STLport-5.1.5/stlport/stl/_string_workaround.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004
00003  * Francois Dumont
00004  *
00005  * This material is provided "as is", with absolutely no warranty expressed
00006  * or implied. Any use is at your own risk.
00007  *
00008  * Permission to use or copy this software for any purpose is hereby granted
00009  * without fee, provided the above notices are retained on all copies.
00010  * Permission to modify the code and to distribute modified code is granted,
00011  * provided the above notices are retained, and a notice that the code was
00012  * modified is included with the above copyright notice.
00013  *
00014  */
00015 
00016 //Included from _string.h, no need for macro guarding.
00017 
00018 _STLP_BEGIN_NAMESPACE
00019 
00020 #if defined (_STLP_DEBUG)
00021 #  define basic_string _STLP_NON_DBG_NAME(str)
00022 _STLP_MOVE_TO_PRIV_NAMESPACE
00023 #endif
00024 
00025 #define _STLP_NO_MEM_T_STRING_BASE _STLP_PRIV _STLP_NO_MEM_T_NAME(str)<_CharT, _Traits, _Alloc>
00026 
00027 template <class _CharT, class _Traits, class _Alloc>
00028 class basic_string : public _STLP_NO_MEM_T_STRING_BASE
00029 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && \
00030     !defined (basic_string)
00031                    , public __stlport_class<basic_string<_CharT, _Traits, _Alloc> >
00032 #endif
00033 {
00034 protected:                        // Protected members inherited from base.
00035   typedef basic_string<_CharT, _Traits, _Alloc> _Self;
00036   typedef _STLP_NO_MEM_T_STRING_BASE _Base;
00037   typedef typename _Base::_Char_Is_POD _Char_Is_POD;
00038 
00039 public:
00040 
00041   __IMPORT_WITH_REVERSE_ITERATORS(_Base)
00042 
00043   typedef typename _Base::_Iterator_category _Iterator_category;
00044   typedef typename _Base::traits_type traits_type;
00045   typedef typename _Base::_Reserve_t _Reserve_t;
00046 
00047 public:                         // Constructor, destructor, assignment.
00048   explicit basic_string(const allocator_type& __a = allocator_type())
00049     : _STLP_NO_MEM_T_STRING_BASE(__a) {}
00050 
00051   basic_string(_Reserve_t __r, size_t __n,
00052                const allocator_type& __a = allocator_type())
00053     : _STLP_NO_MEM_T_STRING_BASE(__r, __n, __a) {}
00054 
00055   basic_string(const _Self& __s)
00056     : _STLP_NO_MEM_T_STRING_BASE(__s) {}
00057 
00058   basic_string(const _Self& __s, size_type __pos, size_type __n = npos,
00059                const allocator_type& __a = allocator_type())
00060     : _STLP_NO_MEM_T_STRING_BASE(__s, __pos, __n, __a) {}
00061 
00062   basic_string(const _CharT* __s, size_type __n,
00063                const allocator_type& __a = allocator_type())
00064     : _STLP_NO_MEM_T_STRING_BASE(__s, __n, __a) {}
00065 
00066   basic_string(const _CharT* __s,
00067                const allocator_type& __a = allocator_type())
00068     : _STLP_NO_MEM_T_STRING_BASE(__s, __a) {}
00069 
00070   basic_string(size_type __n, _CharT __c,
00071                const allocator_type& __a = allocator_type())
00072     : _STLP_NO_MEM_T_STRING_BASE(__n, __c, __a) {}
00073 
00074   basic_string(__move_source<_Self> src)
00075     : _STLP_NO_MEM_T_STRING_BASE(__move_source<_Base>(src.get())) {}
00076 
00077   // Check to see if _InputIterator is an integer type.  If so, then
00078   // it can't be an iterator.
00079 #if !(defined(__MRC__) || (defined(__SC__) && !defined(__DMC__))) //*ty 04/30/2001 - mpw compilers choke on this ctor
00080   template <class _InputIterator>
00081   basic_string(_InputIterator __f, _InputIterator __l,
00082                const allocator_type & __a _STLP_ALLOCATOR_TYPE_DFL)
00083     : _STLP_NO_MEM_T_STRING_BASE(_Base::_CalledFromWorkaround_t(), __a) {
00084     typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
00085     _M_initialize_dispatch(__f, __l, _Integral());
00086   }
00087 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
00088   template <class _InputIterator>
00089   basic_string(_InputIterator __f, _InputIterator __l)
00090     : _STLP_NO_MEM_T_STRING_BASE(_Base::_CalledFromWorkaround_t(), allocator_type()) {
00091     typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
00092     _M_initialize_dispatch(__f, __l, _Integral());
00093   }
00094 #  endif
00095 #endif /* !__MRC__ || (__SC__ && !__DMC__) */
00096 
00097   _Self& operator=(const _Self& __s) {
00098     _Base::operator=(__s);
00099     return *this;
00100   }
00101 
00102   _Self& operator=(const _CharT* __s) {
00103     _Base::operator=(__s);
00104     return *this;
00105   }
00106 
00107   _Self& operator=(_CharT __c) {
00108     _Base::operator=(__c);
00109     return *this;
00110   }
00111 
00112 private:
00113   template <class _InputIter>
00114   void _M_range_initialize(_InputIter __f, _InputIter __l,
00115                            const input_iterator_tag &__tag) {
00116     this->_M_allocate_block();
00117     this->_M_construct_null(this->_M_Finish());
00118     _STLP_TRY {
00119       _M_appendT(__f, __l, __tag);
00120     }
00121     _STLP_UNWIND(this->_M_destroy_range())
00122   }
00123 
00124   template <class _ForwardIter>
00125   void _M_range_initialize(_ForwardIter __f, _ForwardIter __l,
00126                            const forward_iterator_tag &) {
00127     difference_type __n = distance(__f, __l);
00128     this->_M_allocate_block(__n + 1);
00129 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00130     if (this->_M_using_static_buf()) {
00131       _M_copyT(__f, __l, this->_M_Start());
00132       this->_M_finish = this->_M_Start() + __n;
00133     }
00134     else
00135 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00136     this->_M_finish = uninitialized_copy(__f, __l, this->_M_Start());
00137     this->_M_terminate_string();
00138   }
00139 
00140   template <class _InputIter>
00141   void _M_range_initializeT(_InputIter __f, _InputIter __l) {
00142     _M_range_initialize(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
00143   }
00144 
00145   template <class _Integer>
00146   void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type& /*_Integral*/) {
00147     this->_M_allocate_block(__n + 1);
00148 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00149     if (this->_M_using_static_buf()) {
00150       _Traits::assign(this->_M_Start(), __n, __x);
00151       this->_M_finish = this->_M_Start() + __n;
00152     }
00153     else
00154 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00155     this->_M_finish = uninitialized_fill_n(this->_M_Start(), __n, __x);
00156     this->_M_terminate_string();
00157   }
00158 
00159   template <class _InputIter>
00160   void _M_initialize_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*_Integral*/) {
00161     _M_range_initializeT(__f, __l);
00162   }
00163 
00164 public:                         // Append, operator+=, push_back.
00165   _Self& operator+=(const _Self& __s) {
00166     _Base::operator+=(__s);
00167     return *this;
00168   }
00169   _Self& operator+=(const _CharT* __s) {
00170     _STLP_FIX_LITERAL_BUG(__s)
00171     _Base::operator+=(__s);
00172     return *this;
00173   }
00174   _Self& operator+=(_CharT __c) {
00175     _Base::operator+=(__c);
00176     return *this;
00177   }
00178 
00179   _Self& append(const _Self& __s) {
00180     _Base::append(__s);
00181     return *this;
00182   }
00183 
00184   _Self& append(const _Self& __s,
00185                 size_type __pos, size_type __n) {
00186     _Base::append(__s, __pos, __n);
00187     return *this;
00188   }
00189 
00190   _Self& append(const _CharT* __s, size_type __n) {
00191     _STLP_FIX_LITERAL_BUG(__s)
00192     _Base::append(__s, __n);
00193     return *this;
00194   }
00195   _Self& append(const _CharT* __s) {
00196     _STLP_FIX_LITERAL_BUG(__s)
00197     _Base::append(__s);
00198     return *this;
00199   }
00200   _Self& append(size_type __n, _CharT __c) {
00201     _Base::append(__n, __c);
00202     return *this;
00203   }
00204 
00205   // Check to see if _InputIterator is an integer type.  If so, then
00206   // it can't be an iterator.
00207   template <class _InputIter>
00208   _Self& append(_InputIter __first, _InputIter __last) {
00209     typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
00210     return _M_append_dispatch(__first, __last, _Integral());
00211   }
00212 
00213 #if !defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)
00214   //See equivalent assign method remark.
00215   _Self& append(const _CharT* __f, const _CharT* __l) {
00216     _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)
00217     _Base::append(__f, __l);
00218     return *this;
00219   }
00220 #endif
00221 
00222 private:                        // Helper functions for append.
00223 
00224   template <class _InputIter>
00225   _Self& _M_appendT(_InputIter __first, _InputIter __last,
00226                    const input_iterator_tag &) {
00227     for ( ; __first != __last ; ++__first)
00228       _Base::push_back(*__first);
00229     return *this;
00230   }
00231 
00232   template <class _ForwardIter>
00233   _Self& _M_appendT(_ForwardIter __first, _ForwardIter __last,
00234                     const forward_iterator_tag &)  {
00235     if (__first != __last) {
00236       const size_type __old_size = this->size();
00237       difference_type __n = distance(__first, __last);
00238       if (__STATIC_CAST(size_type,__n) > max_size() || __old_size > max_size() - __STATIC_CAST(size_type,__n))
00239         this->_M_throw_length_error();
00240       if (__old_size + __n > capacity()) {
00241         const size_type __len = __old_size +
00242           (max)(__old_size, __STATIC_CAST(size_type,__n)) + 1;
00243         pointer __new_start = this->_M_end_of_storage.allocate(__len);
00244         pointer __new_finish = __new_start;
00245         _STLP_TRY {
00246           __new_finish = uninitialized_copy(this->_M_Start(), this->_M_Finish(), __new_start);
00247           __new_finish = uninitialized_copy(__first, __last, __new_finish);
00248           _M_construct_null(__new_finish);
00249         }
00250         _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
00251           this->_M_end_of_storage.deallocate(__new_start,__len)))
00252           this->_M_destroy_range();
00253         this->_M_deallocate_block();
00254         this->_M_reset(__new_start, __new_finish, __new_start + __len);
00255       }
00256       else {
00257         _ForwardIter __f1 = __first;
00258         ++__f1;
00259 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00260         if (this->_M_using_static_buf())
00261           _M_copyT(__f1, __last, this->_M_Finish() + 1);
00262         else
00263 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00264           uninitialized_copy(__f1, __last, this->_M_Finish() + 1);
00265         _STLP_TRY {
00266           this->_M_construct_null(this->_M_Finish() + __n);
00267         }
00268         _STLP_UNWIND(this->_M_destroy_ptr_range(this->_M_Finish() + 1, this->_M_Finish() + __n))
00269         _Traits::assign(*this->_M_finish, *__first);
00270         this->_M_finish += __n;
00271       }
00272     }
00273     return *this;
00274   }
00275 
00276   template <class _Integer>
00277   _Self& _M_append_dispatch(_Integer __n, _Integer __x, const __true_type& /*Integral*/) {
00278     return append((size_type) __n, (_CharT) __x);
00279   }
00280 
00281   template <class _InputIter>
00282   _Self& _M_append_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*Integral*/) {
00283     return _M_appendT(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
00284   }
00285 
00286 public:                         // Assign
00287 
00288   _Self& assign(const _Self& __s) {
00289     _Base::assign(__s);
00290     return *this;
00291   }
00292 
00293   _Self& assign(const _Self& __s,
00294                 size_type __pos, size_type __n) {
00295     _Base::assign(__s, __pos, __n);
00296     return *this;
00297   }
00298 
00299   _Self& assign(const _CharT* __s, size_type __n) {
00300     _STLP_FIX_LITERAL_BUG(__s)
00301     _Base::assign(__s, __n);
00302     return *this;
00303   }
00304 
00305   _Self& assign(const _CharT* __s) {
00306     _STLP_FIX_LITERAL_BUG(__s)
00307     _Base::assign(__s);
00308     return *this;
00309   }
00310 
00311   _Self& assign(size_type __n, _CharT __c) {
00312     _Base::assign(__n, __c);
00313     return *this;
00314   }
00315 
00316 private:                        // Helper functions for assign.
00317 
00318   template <class _Integer>
00319   _Self& _M_assign_dispatch(_Integer __n, _Integer __x, const __true_type& /*_Integral*/) {
00320     return assign((size_type) __n, (_CharT) __x);
00321   }
00322 
00323   template <class _InputIter>
00324   _Self& _M_assign_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*_Integral*/)  {
00325     pointer __cur = this->_M_Start();
00326     while (__f != __l && __cur != this->_M_Finish()) {
00327       _Traits::assign(*__cur, *__f);
00328       ++__f;
00329       ++__cur;
00330     }
00331     if (__f == __l)
00332       _Base::erase(__cur, this->_M_Finish());
00333     else
00334       _M_appendT(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
00335     return *this;
00336   }
00337 
00338 public:
00339   // Check to see if _InputIterator is an integer type.  If so, then
00340   // it can't be an iterator.
00341   template <class _InputIter>
00342   _Self& assign(_InputIter __first, _InputIter __last) {
00343     typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
00344     return _M_assign_dispatch(__first, __last, _Integral());
00345   }
00346 
00347 #if !defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)
00348   /* This method is not part of the standard and is a specialization of the
00349    * template method assign. It is only granted for convenience to call assign
00350    * with mixed parameters iterator and const_iterator.
00351    */
00352   _Self& assign(const _CharT* __f, const _CharT* __l) {
00353     _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)
00354     _Base::assign(__f, __l);
00355     return *this;
00356   }
00357 #endif
00358 
00359 public:                         // Insert
00360 
00361   _Self& insert(size_type __pos, const _Self& __s) {
00362     _Base::insert(__pos, __s);
00363     return *this;
00364   }
00365 
00366   _Self& insert(size_type __pos, const _Self& __s,
00367                 size_type __beg, size_type __n) {
00368     _Base::insert(__pos, __s, __beg, __n);
00369     return *this;
00370   }
00371   _Self& insert(size_type __pos, const _CharT* __s, size_type __n) {
00372     _STLP_FIX_LITERAL_BUG(__s)
00373     _Base::insert(__pos, __s, __n);
00374     return *this;
00375   }
00376 
00377   _Self& insert(size_type __pos, const _CharT* __s) {
00378     _STLP_FIX_LITERAL_BUG(__s)
00379     _Base::insert(__pos, __s);
00380     return *this;
00381   }
00382 
00383   _Self& insert(size_type __pos, size_type __n, _CharT __c) {
00384     _Base::insert(__pos, __n, __c);
00385     return *this;
00386   }
00387 
00388   iterator insert(iterator __p, _CharT __c) {
00389     return _Base::insert(__p, __c);
00390   }
00391 
00392   void insert(iterator __p, size_t __n, _CharT __c) {
00393     _Base::insert(__p, __n, __c);
00394   }
00395 
00396   // Check to see if _InputIterator is an integer type.  If so, then
00397   // it can't be an iterator.
00398   template <class _InputIter>
00399   void insert(iterator __p, _InputIter __first, _InputIter __last) {
00400     typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
00401     _M_insert_dispatch(__p, __first, __last, _Integral());
00402   }
00403 
00404 private:  // Helper functions for insert.
00405 
00406   void _M_insert(iterator __p, const _CharT* __f, const _CharT* __l, bool __self_ref) {
00407     _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)
00408     _Base::_M_insert(__p, __f, __l, __self_ref);
00409   }
00410 
00411   template <class _ForwardIter>
00412   void _M_insert_overflow(iterator __position, _ForwardIter __first, _ForwardIter __last,
00413                           difference_type __n) {
00414     const size_type __old_size = this->size();
00415     const size_type __len = __old_size + (max)(__old_size, __STATIC_CAST(size_type,__n)) + 1;
00416     pointer __new_start = this->_M_end_of_storage.allocate(__len);
00417     pointer __new_finish = __new_start;
00418     _STLP_TRY {
00419       __new_finish = uninitialized_copy(this->_M_Start(), __position, __new_start);
00420       __new_finish = uninitialized_copy(__first, __last, __new_finish);
00421       __new_finish = uninitialized_copy(__position, this->_M_Finish(), __new_finish);
00422       this->_M_construct_null(__new_finish);
00423     }
00424     _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
00425                   this->_M_end_of_storage.deallocate(__new_start,__len)))
00426     this->_M_destroy_range();
00427     this->_M_deallocate_block();
00428     this->_M_reset(__new_start, __new_finish, __new_start + __len);
00429   }
00430 
00431   template <class _InputIter>
00432   void _M_insertT(iterator __p, _InputIter __first, _InputIter __last,
00433                   const input_iterator_tag &) {
00434     for ( ; __first != __last; ++__first) {
00435       __p = insert(__p, *__first);
00436       ++__p;
00437     }
00438   }
00439 
00440   template <class _ForwardIter>
00441   void _M_insertT(iterator __position, _ForwardIter __first, _ForwardIter __last,
00442                   const forward_iterator_tag &) {
00443     if (__first != __last) {
00444       difference_type __n = distance(__first, __last);
00445       if (this->_M_end_of_storage._M_data - this->_M_finish >= __n + 1) {
00446         const difference_type __elems_after = this->_M_finish - __position;
00447         if (__elems_after >= __n) {
00448 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00449           if (this->_M_using_static_buf())
00450             _Base::_M_copy((this->_M_Finish() - __n) + 1, this->_M_Finish() + 1, this->_M_Finish() + 1);
00451           else
00452 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00453           uninitialized_copy((this->_M_Finish() - __n) + 1, this->_M_Finish() + 1, this->_M_Finish() + 1);
00454           this->_M_finish += __n;
00455           _Traits::move(__position + __n, __position, (__elems_after - __n) + 1);
00456           _M_copyT(__first, __last, __position);
00457         }
00458         else {
00459           pointer __old_finish = this->_M_Finish();
00460           _ForwardIter __mid = __first;
00461           advance(__mid, __elems_after + 1);
00462 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00463           if (this->_M_using_static_buf())
00464             _M_copyT(__mid, __last, this->_M_Finish() + 1);
00465           else
00466 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00467           uninitialized_copy(__mid, __last, this->_M_Finish() + 1);
00468           this->_M_finish += __n - __elems_after;
00469           _STLP_TRY {
00470 #if defined (_STLP_USE_SHORT_STRING_OPTIM)
00471             if (this->_M_using_static_buf())
00472               _Base::_M_copy(__position, __old_finish + 1, this->_M_Finish());
00473             else
00474 #endif /* _STLP_USE_SHORT_STRING_OPTIM */
00475             uninitialized_copy(__position, __old_finish + 1, this->_M_Finish());
00476             this->_M_finish += __elems_after;
00477           }
00478           _STLP_UNWIND((this->_M_destroy_ptr_range(__old_finish + 1, this->_M_Finish()),
00479                         this->_M_finish = __old_finish))
00480           _M_copyT(__first, __mid, __position);
00481         }
00482       }
00483       else {
00484         _M_insert_overflow(__position, __first, __last, __n);
00485       }
00486     }
00487   }
00488 
00489   template <class _Integer>
00490   void _M_insert_dispatch(iterator __p, _Integer __n, _Integer __x,
00491                           const __true_type& /*Integral*/) {
00492     insert(__p, (size_type) __n, (_CharT) __x);
00493   }
00494 
00495   template <class _InputIter>
00496   void _M_insert_dispatch(iterator __p, _InputIter __first, _InputIter __last,
00497                           const __false_type& /*Integral*/) {
00498     _STLP_FIX_LITERAL_BUG(__p)
00499     /*
00500      * Within the basic_string implementation we are only going to check for
00501      * self referencing if iterators are string iterators or _CharT pointers.
00502      * A user could encapsulate those iterator within their own iterator interface
00503      * and in this case lead to a bad behavior, this is a known limitation.
00504      */
00505     typedef typename _AreSameUnCVTypes<_InputIter, iterator>::_Ret _IsIterator;
00506     typedef typename _AreSameUnCVTypes<_InputIter, const_iterator>::_Ret _IsConstIterator;
00507     typedef typename _Lor2<_IsIterator, _IsConstIterator>::_Ret _CheckInside;
00508     _M_insert_aux(__p, __first, __last, _CheckInside());
00509   }
00510 
00511   template <class _RandomIter>
00512   void _M_insert_aux (iterator __p, _RandomIter __first, _RandomIter __last,
00513                       const __true_type& /*_CheckInside*/) {
00514     _STLP_FIX_LITERAL_BUG(__p)
00515     _M_insert(__p, &(*__first), &(*__last), _Base::_M_inside(&(*__first)));
00516   }
00517 
00518   template<class _InputIter>
00519   void _M_insert_aux (iterator __p, _InputIter __first, _InputIter __last,
00520                       const __false_type& /*_CheckInside*/) {
00521     _STLP_FIX_LITERAL_BUG(__p)
00522     _M_insertT(__p, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
00523   }
00524 
00525   template <class _InputIterator>
00526   void _M_copyT(_InputIterator __first, _InputIterator __last, pointer __result) {
00527     _STLP_FIX_LITERAL_BUG(__p)
00528     for ( ; __first != __last; ++__first, ++__result)
00529       _Traits::assign(*__result, *__first);
00530   }
00531 
00532 #if !defined (_STLP_NO_METHOD_SPECIALIZATION)
00533   void _M_copyT(const _CharT* __f, const _CharT* __l, _CharT* __res) {
00534     _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l) _STLP_FIX_LITERAL_BUG(__res)
00535     _Base::_M_copy(__f, __l, __res);
00536   }
00537 #endif
00538 
00539 public:                         // Erase.
00540 
00541   _Self& erase(size_type __pos = 0, size_type __n = npos) {
00542     _Base::erase(__pos, __n);
00543     return *this;
00544   }
00545 
00546   iterator erase(iterator __pos) {
00547     _STLP_FIX_LITERAL_BUG(__pos)
00548     return _Base::erase(__pos);
00549   }
00550 
00551   iterator erase(iterator __first, iterator __last) {
00552     _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
00553     return _Base::erase(__first, __last);
00554   }
00555 
00556 public:                         // Replace.  (Conceptually equivalent
00557                                 // to erase followed by insert.)
00558   _Self& replace(size_type __pos, size_type __n, const _Self& __s) {
00559     _Base::replace(__pos, __n, __s);
00560     return *this;
00561   }
00562 
00563   _Self& replace(size_type __pos1, size_type __n1, const _Self& __s,
00564                  size_type __pos2, size_type __n2) {
00565     _Base::replace(__pos1, __n1, __s, __pos2, __n2);
00566     return *this;
00567   }
00568 
00569   _Self& replace(size_type __pos, size_type __n1,
00570                  const _CharT* __s, size_type __n2) {
00571     _STLP_FIX_LITERAL_BUG(__s)
00572     _Base::replace(__pos, __n1, __s, __n2);
00573     return *this;
00574   }
00575 
00576   _Self& replace(size_type __pos, size_type __n1, const _CharT* __s) {
00577     _STLP_FIX_LITERAL_BUG(__s)
00578     _Base::replace(__pos, __n1, __s);
00579     return *this;
00580   }
00581 
00582   _Self& replace(size_type __pos, size_type __n1,
00583                  size_type __n2, _CharT __c) {
00584     _Base::replace(__pos, __n1, __n2, __c);
00585     return *this;
00586   }
00587 
00588   _Self& replace(iterator __first, iterator __last, const _Self& __s) {
00589     _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
00590     _Base::replace(__first, __last, __s);
00591     return *this;
00592   }
00593 
00594   _Self& replace(iterator __first, iterator __last,
00595                  const _CharT* __s, size_type __n) {
00596     _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
00597     _STLP_FIX_LITERAL_BUG(__s)
00598     _Base::replace(__first, __last, __s, __n);
00599     return *this;
00600   }
00601 
00602   _Self& replace(iterator __first, iterator __last,
00603                  const _CharT* __s) {
00604     _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
00605     _STLP_FIX_LITERAL_BUG(__s)
00606     _Base::replace(__first, __last, __s);
00607     return *this;
00608   }
00609 
00610   _Self& replace(iterator __first, iterator __last,
00611                  size_type __n, _CharT __c) {
00612     _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
00613     _Base::replace(__first, __last, __n, __c);
00614     return *this;
00615   }
00616 
00617   // Check to see if _InputIter is an integer type.  If so, then
00618   // it can't be an iterator.
00619   template <class _InputIter>
00620   _Self& replace(iterator __first, iterator __last,
00621                  _InputIter __f, _InputIter __l) {
00622     _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last)
00623     typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
00624     return _M_replace_dispatch(__first, __last, __f, __l,  _Integral());
00625   }
00626 
00627 #if !defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)
00628   _Self& replace(iterator __first, iterator __last,
00629                  const _CharT* __f, const _CharT* __l) {
00630     _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
00631     _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
00632     _Base::replace(__first, __last, __f, __l);
00633     return *this;
00634   }
00635 #endif
00636 
00637 protected:                        // Helper functions for replace.
00638   _Self& _M_replace(iterator __first, iterator __last,
00639                     const _CharT* __f, const _CharT* __l, bool __self_ref) {
00640     _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
00641     _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
00642     _Base::_M_replace(__first, __last, __f, __l, __self_ref);
00643     return *this;
00644   }
00645 
00646   template <class _Integer>
00647   _Self& _M_replace_dispatch(iterator __first, iterator __last,
00648                              _Integer __n, _Integer __x, const __true_type& /*IsIntegral*/) {
00649     _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
00650     return replace(__first, __last, (size_type) __n, (_CharT) __x);
00651   }
00652 
00653   template <class _InputIter>
00654   _Self& _M_replace_dispatch(iterator __first, iterator __last,
00655                              _InputIter __f, _InputIter __l, const __false_type& /*IsIntegral*/) {
00656     _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
00657     typedef typename _AreSameUnCVTypes<_InputIter, iterator>::_Ret _IsIterator;
00658     typedef typename _AreSameUnCVTypes<_InputIter, const_iterator>::_Ret _IsConstIterator;
00659     typedef typename _Lor2<_IsIterator, _IsConstIterator>::_Ret _CheckInside;
00660     return _M_replace_aux(__first, __last, __f, __l, _CheckInside());
00661   }
00662 
00663   template <class _RandomIter>
00664   _Self& _M_replace_aux(iterator __first, iterator __last,
00665                         _RandomIter __f, _RandomIter __l, __true_type const& /*_CheckInside*/) {
00666     _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
00667     return _M_replace(__first, __last, &(*__f), &(*__l), _Base::_M_inside(&(*__f)));
00668   }
00669 
00670   template <class _InputIter>
00671   _Self& _M_replace_aux(iterator __first, iterator __last,
00672                      _InputIter __f, _InputIter __l, __false_type const& /*_CheckInside*/) {
00673     _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
00674     return _M_replaceT(__first, __last, __f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
00675   }
00676 
00677   template <class _InputIter>
00678   _Self& _M_replaceT(iterator __first, iterator __last,
00679                      _InputIter __f, _InputIter __l, const input_iterator_tag&__ite_tag) {
00680     _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
00681     for ( ; __first != __last && __f != __l; ++__first, ++__f)
00682       _Traits::assign(*__first, *__f);
00683     if (__f == __l)
00684       _Base::erase(__first, __last);
00685     else
00686       _M_insertT(__last, __f, __l, __ite_tag);
00687     return *this;
00688   }
00689 
00690   template <class _ForwardIter>
00691   _Self& _M_replaceT(iterator __first, iterator __last,
00692                      _ForwardIter __f, _ForwardIter __l, const forward_iterator_tag &__ite_tag) {
00693     _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
00694     difference_type __n = distance(__f, __l);
00695     const difference_type __len = __last - __first;
00696     if (__len >= __n) {
00697       _M_copyT(__f, __l, __first);
00698       _Base::erase(__first + __n, __last);
00699     }
00700     else {
00701       _ForwardIter __m = __f;
00702       advance(__m, __len);
00703       _M_copyT(__f, __m, __first);
00704       _M_insertT(__last, __m, __l, __ite_tag);
00705     }
00706     return *this;
00707   }
00708 
00709 public:                         // Other modifier member functions.
00710 
00711   void swap(_Self& __s)
00712   { _Base::swap(__s); }
00713 
00714 public:                         // Substring.
00715 
00716   _Self substr(size_type __pos = 0, size_type __n = npos) const
00717   { return _Self(*this, __pos, __n, get_allocator()); }
00718 
00719 #if defined (_STLP_USE_TEMPLATE_EXPRESSION) && !defined (_STLP_DEBUG)
00720 #  define _STLP_STRING_SUM_BASE _STLP_NO_MEM_T_STRING_BASE
00721 #  include <stl/_string_sum_methods.h>
00722 #  undef _STLP_STRING_SUM_BASE
00723 #endif
00724 };
00725 
00726 #undef _STLP_NO_MEM_T_STRING_BASE
00727 
00728 #if defined (basic_string)
00729 _STLP_MOVE_TO_STD_NAMESPACE
00730 #  undef basic_string
00731 #endif
00732 
00733 _STLP_END_NAMESPACE



Generated on Mon Mar 10 15:32:41 2008 by  doxygen 1.5.1