# vstring.h

Go to the documentation of this file.

    00001 // Versatile string -*- C++ -*-
    00002
    00003 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
    00004 // Free Software Foundation, Inc.
    00005 //
    00006 // This file is part of the GNU ISO C++ Library.  This library is free
    00007 // software; you can redistribute it and/or modify it under the
    00008 // terms of the GNU General Public License as published by the
    00009 // Free Software Foundation; either version 3, or (at your option)
    00010 // any later version.
    00011
    00012 // This library is distributed in the hope that it will be useful,
    00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00015 // GNU General Public License for more details.
    00016
    00017 // Under Section 7 of GPL version 3, you are granted additional
    00018 // permissions described in the GCC Runtime Library Exception, version
    00019 // 3.1, as published by the Free Software Foundation.
    00020
    00021 // You should have received a copy of the GNU General Public License and
    00022 // a copy of the GCC Runtime Library Exception along with this program;
    00023 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    00024 // <http://www.gnu.org/licenses/>.
    00025
    00026 /** @file ext/vstring.h
    00027  *  This file is a GNU extension to the Standard C++ Library.
    00028  */
    00029
    00030 #ifndef _VSTRING_H
    00031 #define _VSTRING_H 1
    00032
    00033 #pragma GCC system_header
    00034
    00035 #include <initializer_list>
    00036 #include <ext/vstring_util.h>
    00037 #include <ext/rc_string_base.h>
    00038 #include <ext/sso_string_base.h>
    00039
    00040 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
    00041
    00042   /**
    00043    *  @class __versa_string vstring.h
    00044    *  @brief  Template class __versa_string.
    00045    *  @ingroup extensions
    00046    *
    00047    *  Data structure managing sequences of characters and
    00048    *  character-like objects.
    00049    */
    00050   template<typename _CharT, typename _Traits, typename _Alloc,
    00051        template <typename, typename, typename> class _Base>
    00052     class __versa_string
    00053     : private _Base<_CharT, _Traits, _Alloc>
    00054     {
    00055       typedef _Base<_CharT, _Traits, _Alloc>                __vstring_base;
    00056       typedef typename __vstring_base::_CharT_alloc_type    _CharT_alloc_type;
    00057
    00058       // Types:
    00059     public:
    00060       typedef _Traits                       traits_type;
    00061       typedef typename _Traits::char_type           value_type;
    00062       typedef _Alloc                        allocator_type;
    00063       typedef typename _CharT_alloc_type::size_type     size_type;
    00064       typedef typename _CharT_alloc_type::difference_type   difference_type;
    00065       typedef typename _CharT_alloc_type::reference     reference;
    00066       typedef typename _CharT_alloc_type::const_reference   const_reference;
    00067       typedef typename _CharT_alloc_type::pointer       pointer;
    00068       typedef typename _CharT_alloc_type::const_pointer     const_pointer;
    00069       typedef __gnu_cxx::__normal_iterator<pointer, __versa_string>  iterator;
    00070       typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
    00071                                                             const_iterator;
    00072       typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
    00073       typedef std::reverse_iterator<iterator>           reverse_iterator;
    00074
    00075       // Data Member (public):
    00076       ///  Value returned by various member functions when they fail.
    00077       static const size_type    npos = static_cast<size_type>(-1);
    00078
    00079     private:
    00080       size_type
    00081       _M_check(size_type __pos, const char* __s) const
    00082       {
    00083     if (__pos > this->size())
    00084       std::__throw_out_of_range(__N(__s));
    00085     return __pos;
    00086       }
    00087
    00088       void
    00089       _M_check_length(size_type __n1, size_type __n2, const char* __s) const
    00090       {
    00091     if (this->max_size() - (this->size() - __n1) < __n2)
    00092       std::__throw_length_error(__N(__s));
    00093       }
    00094
    00095       // NB: _M_limit doesn't check for a bad __pos value.
    00096       size_type
    00097       _M_limit(size_type __pos, size_type __off) const
    00098       {
    00099     const bool __testoff =  __off < this->size() - __pos;
    00100     return __testoff ? __off : this->size() - __pos;
    00101       }
    00102
    00103       // True if _Rep and source do not overlap.
    00104       bool
    00105       _M_disjunct(const _CharT* __s) const
    00106       {
    00107     return (std::less<const _CharT*>()(__s, this->_M_data())
    00108         || std::less<const _CharT*>()(this->_M_data()
    00109                           + this->size(), __s));
    00110       }
    00111
    00112       // For the internal use we have functions similar to `begin'/`end'
    00113       // but they do not call _M_leak.
    00114       iterator
    00115       _M_ibegin() const
    00116       { return iterator(this->_M_data()); }
    00117
    00118       iterator
    00119       _M_iend() const
    00120       { return iterator(this->_M_data() + this->_M_length()); }
    00121
    00122     public:
    00123       // Construct/copy/destroy:
    00124       // NB: We overload ctors in some cases instead of using default
    00125       // arguments, per 17.4.4.4 para. 2 item 2.
    00126
    00127       /**
    00128        *  @brief  Default constructor creates an empty string.
    00129        */
    00130       __versa_string()
    00131       : __vstring_base() { }
    00132
    00133       /**
    00134        *  @brief  Construct an empty string using allocator @a a.
    00135        */
    00136       explicit
    00137       __versa_string(const _Alloc& __a)
    00138       : __vstring_base(__a) { }
    00139
    00140       // NB: per LWG issue 42, semantics different from IS:
    00141       /**
    00142        *  @brief  Construct string with copy of value of @a str.
    00143        *  @param  __str  Source string.
    00144        */
    00145       __versa_string(const __versa_string& __str)
    00146       : __vstring_base(__str) { }
    00147
    00148 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00149       /**
    00150        *  @brief  String move constructor.
    00151        *  @param  __str  Source string.
    00152        *
    00153        *  The newly-constructed %string contains the exact contents of
    00154        *  @a str.  The contents of @a str are a valid, but unspecified
    00155        *  string.
    00156        */
    00157       __versa_string(__versa_string&& __str)
    00158       : __vstring_base(std::forward<__vstring_base>(__str)) { }
    00159
    00160       /**
    00161        *  @brief  Construct string from an initializer list.
    00162        *  @param  __l  std::initializer_list of characters.
    00163        *  @param  __a  Allocator to use (default is default allocator).
    00164        */
    00165       __versa_string(std::initializer_list<_CharT> __l,
    00166              const _Alloc& __a = _Alloc())
    00167       : __vstring_base(__l.begin(), __l.end(), __a) { }
    00168 #endif
    00169
    00170       /**
    00171        *  @brief  Construct string as copy of a substring.
    00172        *  @param  __str  Source string.
    00173        *  @param  __pos  Index of first character to copy from.
    00174        *  @param  __n  Number of characters to copy (default remainder).
    00175        */
    00176       __versa_string(const __versa_string& __str, size_type __pos,
    00177              size_type __n = npos)
    00178       : __vstring_base(__str._M_data()
    00179                + __str._M_check(__pos,
    00180                     "__versa_string::__versa_string"),
    00181                __str._M_data() + __str._M_limit(__pos, __n)
    00182                + __pos, _Alloc()) { }
    00183
    00184       /**
    00185        *  @brief  Construct string as copy of a substring.
    00186        *  @param  __str  Source string.
    00187        *  @param  __pos  Index of first character to copy from.
    00188        *  @param  __n  Number of characters to copy.
    00189        *  @param  __a  Allocator to use.
    00190        */
    00191       __versa_string(const __versa_string& __str, size_type __pos,
    00192              size_type __n, const _Alloc& __a)
    00193       : __vstring_base(__str._M_data()
    00194                + __str._M_check(__pos,
    00195                     "__versa_string::__versa_string"),
    00196                __str._M_data() + __str._M_limit(__pos, __n)
    00197                + __pos, __a) { }
    00198
    00199       /**
    00200        *  @brief  Construct string initialized by a character array.
    00201        *  @param  __s  Source character array.
    00202        *  @param  __n  Number of characters to copy.
    00203        *  @param  __a  Allocator to use (default is default allocator).
    00204        *
    00205        *  NB: @a __s must have at least @a __n characters, '\\0' has no special
    00206        *  meaning.
    00207        */
    00208       __versa_string(const _CharT* __s, size_type __n,
    00209              const _Alloc& __a = _Alloc())
    00210       : __vstring_base(__s, __s + __n, __a) { }
    00211
    00212       /**
    00213        *  @brief  Construct string as copy of a C string.
    00214        *  @param  __s  Source C string.
    00215        *  @param  __a  Allocator to use (default is default allocator).
    00216        */
    00217       __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc())
    00218       : __vstring_base(__s, __s ? __s + traits_type::length(__s) :
    00219                __s + npos, __a) { }
    00220
    00221       /**
    00222        *  @brief  Construct string as multiple characters.
    00223        *  @param  __n  Number of characters.
    00224        *  @param  __c  Character to use.
    00225        *  @param  __a  Allocator to use (default is default allocator).
    00226        */
    00227       __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
    00228       : __vstring_base(__n, __c, __a) { }
    00229
    00230       /**
    00231        *  @brief  Construct string as copy of a range.
    00232        *  @param  __beg  Start of range.
    00233        *  @param  __end  End of range.
    00234        *  @param  __a  Allocator to use (default is default allocator).
    00235        */
    00236       template<class _InputIterator>
    00237         __versa_string(_InputIterator __beg, _InputIterator __end,
    00238                const _Alloc& __a = _Alloc())
    00239     : __vstring_base(__beg, __end, __a) { }
    00240
    00241       /**
    00242        *  @brief  Destroy the string instance.
    00243        */
    00244       ~__versa_string() { }
    00245
    00246       /**
    00247        *  @brief  Assign the value of @a str to this string.
    00248        *  @param  __str  Source string.
    00249        */
    00250       __versa_string&
    00251       operator=(const __versa_string& __str)
    00252       { return this->assign(__str); }
    00253
    00254 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00255       /**
    00256        *  @brief  String move assignment operator.
    00257        *  @param  __str  Source string.
    00258        *
    00259        *  The contents of @a __str are moved into this string (without
    00260        *  copying).  @a __str is a valid, but unspecified string.
    00261        */
    00262       __versa_string&
    00263       operator=(__versa_string&& __str)
    00264       {
    00265     // NB: DR 1204.
    00266     this->swap(__str);
    00267     return *this;
    00268       }
    00269
    00270       /**
    00271        *  @brief  Set value to string constructed from initializer list.
    00272        *  @param  __l  std::initializer_list.
    00273        */
    00274       __versa_string&
    00275       operator=(std::initializer_list<_CharT> __l)
    00276       {
    00277     this->assign(__l.begin(), __l.end());
    00278     return *this;
    00279       }
    00280 #endif
    00281
    00282       /**
    00283        *  @brief  Copy contents of @a __s into this string.
    00284        *  @param  __s  Source null-terminated string.
    00285        */
    00286       __versa_string&
    00287       operator=(const _CharT* __s)
    00288       { return this->assign(__s); }
    00289
    00290       /**
    00291        *  @brief  Set value to string of length 1.
    00292        *  @param  __c  Source character.
    00293        *
    00294        *  Assigning to a character makes this string length 1 and
    00295        *  (*this)[0] == @a __c.
    00296        */
    00297       __versa_string&
    00298       operator=(_CharT __c)
    00299       {
    00300     this->assign(1, __c);
    00301     return *this;
    00302       }
    00303
    00304       // Iterators:
    00305       /**
    00306        *  Returns a read/write iterator that points to the first character in
    00307        *  the %string.  Unshares the string.
    00308        */
    00309       iterator
    00310       begin()
    00311       {
    00312     this->_M_leak();
    00313     return iterator(this->_M_data());
    00314       }
    00315
    00316       /**
    00317        *  Returns a read-only (constant) iterator that points to the first
    00318        *  character in the %string.
    00319        */
    00320       const_iterator
    00321       begin() const
    00322       { return const_iterator(this->_M_data()); }
    00323
    00324       /**
    00325        *  Returns a read/write iterator that points one past the last
    00326        *  character in the %string.  Unshares the string.
    00327        */
    00328       iterator
    00329       end()
    00330       {
    00331     this->_M_leak();
    00332     return iterator(this->_M_data() + this->size());
    00333       }
    00334
    00335       /**
    00336        *  Returns a read-only (constant) iterator that points one past the
    00337        *  last character in the %string.
    00338        */
    00339       const_iterator
    00340       end() const
    00341       { return const_iterator(this->_M_data() + this->size()); }
    00342
    00343       /**
    00344        *  Returns a read/write reverse iterator that points to the last
    00345        *  character in the %string.  Iteration is done in reverse element
    00346        *  order.  Unshares the string.
    00347        */
    00348       reverse_iterator
    00349       rbegin()
    00350       { return reverse_iterator(this->end()); }
    00351
    00352       /**
    00353        *  Returns a read-only (constant) reverse iterator that points
    00354        *  to the last character in the %string.  Iteration is done in
    00355        *  reverse element order.
    00356        */
    00357       const_reverse_iterator
    00358       rbegin() const
    00359       { return const_reverse_iterator(this->end()); }
    00360
    00361       /**
    00362        *  Returns a read/write reverse iterator that points to one before the
    00363        *  first character in the %string.  Iteration is done in reverse
    00364        *  element order.  Unshares the string.
    00365        */
    00366       reverse_iterator
    00367       rend()
    00368       { return reverse_iterator(this->begin()); }
    00369
    00370       /**
    00371        *  Returns a read-only (constant) reverse iterator that points
    00372        *  to one before the first character in the %string.  Iteration
    00373        *  is done in reverse element order.
    00374        */
    00375       const_reverse_iterator
    00376       rend() const
    00377       { return const_reverse_iterator(this->begin()); }
    00378
    00379 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00380       /**
    00381        *  Returns a read-only (constant) iterator that points to the first
    00382        *  character in the %string.
    00383        */
    00384       const_iterator
    00385       cbegin() const
    00386       { return const_iterator(this->_M_data()); }
    00387
    00388       /**
    00389        *  Returns a read-only (constant) iterator that points one past the
    00390        *  last character in the %string.
    00391        */
    00392       const_iterator
    00393       cend() const
    00394       { return const_iterator(this->_M_data() + this->size()); }
    00395
    00396       /**
    00397        *  Returns a read-only (constant) reverse iterator that points
    00398        *  to the last character in the %string.  Iteration is done in
    00399        *  reverse element order.
    00400        */
    00401       const_reverse_iterator
    00402       crbegin() const
    00403       { return const_reverse_iterator(this->end()); }
    00404
    00405       /**
    00406        *  Returns a read-only (constant) reverse iterator that points
    00407        *  to one before the first character in the %string.  Iteration
    00408        *  is done in reverse element order.
    00409        */
    00410       const_reverse_iterator
    00411       crend() const
    00412       { return const_reverse_iterator(this->begin()); }
    00413 #endif
    00414
    00415     public:
    00416       // Capacity:
    00417       ///  Returns the number of characters in the string, not including any
    00418       ///  null-termination.
    00419       size_type
    00420       size() const
    00421       { return this->_M_length(); }
    00422
    00423       ///  Returns the number of characters in the string, not including any
    00424       ///  null-termination.
    00425       size_type
    00426       length() const
    00427       { return this->_M_length(); }
    00428
    00429       /// Returns the size() of the largest possible %string.
    00430       size_type
    00431       max_size() const
    00432       { return this->_M_max_size(); }
    00433
    00434       /**
    00435        *  @brief  Resizes the %string to the specified number of characters.
    00436        *  @param  __n  Number of characters the %string should contain.
    00437        *  @param  __c  Character to fill any new elements.
    00438        *
    00439        *  This function will %resize the %string to the specified
    00440        *  number of characters.  If the number is smaller than the
    00441        *  %string's current size the %string is truncated, otherwise
    00442        *  the %string is extended and new elements are set to @a __c.
    00443        */
    00444       void
    00445       resize(size_type __n, _CharT __c);
    00446
    00447       /**
    00448        *  @brief  Resizes the %string to the specified number of characters.
    00449        *  @param  __n  Number of characters the %string should contain.
    00450        *
    00451        *  This function will resize the %string to the specified
    00452        *  length.  If the new size is smaller than the %string's
    00453        *  current size the %string is truncated, otherwise the %string
    00454        *  is extended and new characters are default-constructed.  For
    00455        *  basic types such as char, this means setting them to 0.
    00456        */
    00457       void
    00458       resize(size_type __n)
    00459       { this->resize(__n, _CharT()); }
    00460
    00461 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00462       /// A non-binding request to reduce capacity() to size().
    00463       void
    00464       shrink_to_fit()
    00465       {
    00466     __try
    00467       { this->reserve(0); }
    00468     __catch(...)
    00469       { }
    00470       }
    00471 #endif
    00472
    00473       /**
    00474        *  Returns the total number of characters that the %string can
    00475        *  hold before needing to allocate more memory.
    00476        */
    00477       size_type
    00478       capacity() const
    00479       { return this->_M_capacity(); }
    00480
    00481       /**
    00482        *  @brief  Attempt to preallocate enough memory for specified number of
    00483        *          characters.
    00484        *  @param  __res_arg  Number of characters required.
    00485        *  @throw  std::length_error  If @a __res_arg exceeds @c max_size().
    00486        *
    00487        *  This function attempts to reserve enough memory for the
    00488        *  %string to hold the specified number of characters.  If the
    00489        *  number requested is more than max_size(), length_error is
    00490        *  thrown.
    00491        *
    00492        *  The advantage of this function is that if optimal code is a
    00493        *  necessity and the user can determine the string length that
    00494        *  will be required, the user can reserve the memory in
    00495        *  %advance, and thus prevent a possible reallocation of memory
    00496        *  and copying of %string data.
    00497        */
    00498       void
    00499       reserve(size_type __res_arg = 0)
    00500       { this->_M_reserve(__res_arg); }
    00501
    00502       /**
    00503        *  Erases the string, making it empty.
    00504        */
    00505       void
    00506       clear()
    00507       { this->_M_clear(); }
    00508
    00509       /**
    00510        *  Returns true if the %string is empty.  Equivalent to
    00511        *  <code>*this == ""</code>.
    00512        */
    00513       bool
    00514       empty() const
    00515       { return this->size() == 0; }
    00516
    00517       // Element access:
    00518       /**
    00519        *  @brief  Subscript access to the data contained in the %string.
    00520        *  @param  __pos  The index of the character to access.
    00521        *  @return  Read-only (constant) reference to the character.
    00522        *
    00523        *  This operator allows for easy, array-style, data access.
    00524        *  Note that data access with this operator is unchecked and
    00525        *  out_of_range lookups are not defined. (For checked lookups
    00526        *  see at().)
    00527        */
    00528       const_reference
    00529       operator[] (size_type __pos) const
    00530       {
    00531     _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
    00532     return this->_M_data()[__pos];
    00533       }
    00534
    00535       /**
    00536        *  @brief  Subscript access to the data contained in the %string.
    00537        *  @param  __pos  The index of the character to access.
    00538        *  @return  Read/write reference to the character.
    00539        *
    00540        *  This operator allows for easy, array-style, data access.
    00541        *  Note that data access with this operator is unchecked and
    00542        *  out_of_range lookups are not defined. (For checked lookups
    00543        *  see at().)  Unshares the string.
    00544        */
    00545       reference
    00546       operator[](size_type __pos)
    00547       {
    00548         // allow pos == size() as v3 extension:
    00549     _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
    00550         // but be strict in pedantic mode:
    00551     _GLIBCXX_DEBUG_PEDASSERT(__pos < this->size());
    00552     this->_M_leak();
    00553     return this->_M_data()[__pos];
    00554       }
    00555
    00556       /**
    00557        *  @brief  Provides access to the data contained in the %string.
    00558        *  @param __n The index of the character to access.
    00559        *  @return  Read-only (const) reference to the character.
    00560        *  @throw  std::out_of_range  If @a __n is an invalid index.
    00561        *
    00562        *  This function provides for safer data access.  The parameter
    00563        *  is first checked that it is in the range of the string.  The
    00564        *  function throws out_of_range if the check fails.
    00565        */
    00566       const_reference
    00567       at(size_type __n) const
    00568       {
    00569     if (__n >= this->size())
    00570       std::__throw_out_of_range(__N("__versa_string::at"));
    00571     return this->_M_data()[__n];
    00572       }
    00573
    00574       /**
    00575        *  @brief  Provides access to the data contained in the %string.
    00576        *  @param __n The index of the character to access.
    00577        *  @return  Read/write reference to the character.
    00578        *  @throw  std::out_of_range  If @a __n is an invalid index.
    00579        *
    00580        *  This function provides for safer data access.  The parameter
    00581        *  is first checked that it is in the range of the string.  The
    00582        *  function throws out_of_range if the check fails.  Success
    00583        *  results in unsharing the string.
    00584        */
    00585       reference
    00586       at(size_type __n)
    00587       {
    00588     if (__n >= this->size())
    00589       std::__throw_out_of_range(__N("__versa_string::at"));
    00590     this->_M_leak();
    00591     return this->_M_data()[__n];
    00592       }
    00593
    00594 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00595       /**
    00596        *  Returns a read/write reference to the data at the first
    00597        *  element of the %string.
    00598        */
    00599       reference
    00600       front()
    00601       { return *begin(); }
    00602
    00603       /**
    00604        *  Returns a read-only (constant) reference to the data at the first
    00605        *  element of the %string.
    00606        */
    00607       const_reference
    00608       front() const
    00609       { return *begin(); }
    00610
    00611       /**
    00612        *  Returns a read/write reference to the data at the last
    00613        *  element of the %string.
    00614        */
    00615       reference
    00616       back()
    00617       { return *(end() - 1); }
    00618
    00619       /**
    00620        *  Returns a read-only (constant) reference to the data at the
    00621        *  last element of the %string.
    00622        */
    00623       const_reference
    00624       back() const
    00625       { return *(end() - 1); }
    00626 #endif
    00627
    00628       // Modifiers:
    00629       /**
    00630        *  @brief  Append a string to this string.
    00631        *  @param __str  The string to append.
    00632        *  @return  Reference to this string.
    00633        */
    00634       __versa_string&
    00635       operator+=(const __versa_string& __str)
    00636       { return this->append(__str); }
    00637
    00638       /**
    00639        *  @brief  Append a C string.
    00640        *  @param __s  The C string to append.
    00641        *  @return  Reference to this string.
    00642        */
    00643       __versa_string&
    00644       operator+=(const _CharT* __s)
    00645       { return this->append(__s); }
    00646
    00647       /**
    00648        *  @brief  Append a character.
    00649        *  @param __c  The character to append.
    00650        *  @return  Reference to this string.
    00651        */
    00652       __versa_string&
    00653       operator+=(_CharT __c)
    00654       {
    00655     this->push_back(__c);
    00656     return *this;
    00657       }
    00658
    00659 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00660       /**
    00661        *  @brief  Append an initializer_list of characters.
    00662        *  @param __l  The initializer_list of characters to be appended.
    00663        *  @return  Reference to this string.
    00664        */
    00665       __versa_string&
    00666       operator+=(std::initializer_list<_CharT> __l)
    00667       { return this->append(__l.begin(), __l.end()); }
    00668 #endif // __GXX_EXPERIMENTAL_CXX0X__
    00669
    00670       /**
    00671        *  @brief  Append a string to this string.
    00672        *  @param __str  The string to append.
    00673        *  @return  Reference to this string.
    00674        */
    00675       __versa_string&
    00676       append(const __versa_string& __str)
    00677       { return _M_append(__str._M_data(), __str.size()); }
    00678
    00679       /**
    00680        *  @brief  Append a substring.
    00681        *  @param __str  The string to append.
    00682        *  @param __pos  Index of the first character of str to append.
    00683        *  @param __n  The number of characters to append.
    00684        *  @return  Reference to this string.
    00685        *  @throw  std::out_of_range if @a pos is not a valid index.
    00686        *
    00687        *  This function appends @a __n characters from @a __str
    00688        *  starting at @a __pos to this string.  If @a __n is is larger
    00689        *  than the number of available characters in @a __str, the
    00690        *  remainder of @a __str is appended.
    00691        */
    00692       __versa_string&
    00693       append(const __versa_string& __str, size_type __pos, size_type __n)
    00694       { return _M_append(__str._M_data()
    00695              + __str._M_check(__pos, "__versa_string::append"),
    00696              __str._M_limit(__pos, __n)); }
    00697
    00698       /**
    00699        *  @brief  Append a C substring.
    00700        *  @param __s  The C string to append.
    00701        *  @param __n  The number of characters to append.
    00702        *  @return  Reference to this string.
    00703        */
    00704       __versa_string&
    00705       append(const _CharT* __s, size_type __n)
    00706       {
    00707     __glibcxx_requires_string_len(__s, __n);
    00708     _M_check_length(size_type(0), __n, "__versa_string::append");
    00709     return _M_append(__s, __n);
    00710       }
    00711
    00712       /**
    00713        *  @brief  Append a C string.
    00714        *  @param __s  The C string to append.
    00715        *  @return  Reference to this string.
    00716        */
    00717       __versa_string&
    00718       append(const _CharT* __s)
    00719       {
    00720     __glibcxx_requires_string(__s);
    00721     const size_type __n = traits_type::length(__s);
    00722     _M_check_length(size_type(0), __n, "__versa_string::append");
    00723     return _M_append(__s, __n);
    00724       }
    00725
    00726       /**
    00727        *  @brief  Append multiple characters.
    00728        *  @param __n  The number of characters to append.
    00729        *  @param __c  The character to use.
    00730        *  @return  Reference to this string.
    00731        *
    00732        *  Appends n copies of c to this string.
    00733        */
    00734       __versa_string&
    00735       append(size_type __n, _CharT __c)
    00736       { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
    00737
    00738 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00739       /**
    00740        *  @brief  Append an initializer_list of characters.
    00741        *  @param __l  The initializer_list of characters to append.
    00742        *  @return  Reference to this string.
    00743        */
    00744       __versa_string&
    00745       append(std::initializer_list<_CharT> __l)
    00746       { return this->append(__l.begin(), __l.end()); }
    00747 #endif // __GXX_EXPERIMENTAL_CXX0X__
    00748
    00749       /**
    00750        *  @brief  Append a range of characters.
    00751        *  @param __first  Iterator referencing the first character to append.
    00752        *  @param __last  Iterator marking the end of the range.
    00753        *  @return  Reference to this string.
    00754        *
    00755        *  Appends characters in the range [first,last) to this string.
    00756        */
    00757       template<class _InputIterator>
    00758         __versa_string&
    00759         append(_InputIterator __first, _InputIterator __last)
    00760         { return this->replace(_M_iend(), _M_iend(), __first, __last); }
    00761
    00762       /**
    00763        *  @brief  Append a single character.
    00764        *  @param __c  Character to append.
    00765        */
    00766       void
    00767       push_back(_CharT __c)
    00768       {
    00769     const size_type __size = this->size();
    00770     if (__size + 1 > this->capacity() || this->_M_is_shared())
    00771       this->_M_mutate(__size, size_type(0), 0, size_type(1));
    00772     traits_type::assign(this->_M_data()[__size], __c);
    00773     this->_M_set_length(__size + 1);
    00774       }
    00775
    00776       /**
    00777        *  @brief  Set value to contents of another string.
    00778        *  @param  __str  Source string to use.
    00779        *  @return  Reference to this string.
    00780        */
    00781       __versa_string&
    00782       assign(const __versa_string& __str)
    00783       {
    00784     this->_M_assign(__str);
    00785     return *this;
    00786       }
    00787
    00788 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00789       /**
    00790        *  @brief  Set value to contents of another string.
    00791        *  @param  __str  Source string to use.
    00792        *  @return  Reference to this string.
    00793        *
    00794        *  This function sets this string to the exact contents of @a __str.
    00795        *  @a __str is a valid, but unspecified string.
    00796        */
    00797       __versa_string&
    00798       assign(__versa_string&& __str)
    00799       {
    00800     this->swap(__str);
    00801     return *this;
    00802       }
    00803 #endif // __GXX_EXPERIMENTAL_CXX0X__
    00804
    00805       /**
    00806        *  @brief  Set value to a substring of a string.
    00807        *  @param __str  The string to use.
    00808        *  @param __pos  Index of the first character of str.
    00809        *  @param __n  Number of characters to use.
    00810        *  @return  Reference to this string.
    00811        *  @throw  std::out_of_range if @a __pos is not a valid index.
    00812        *
    00813        *  This function sets this string to the substring of @a __str
    00814        *  consisting of @a __n characters at @a __pos.  If @a __n is
    00815        *  is larger than the number of available characters in @a
    00816        *  __str, the remainder of @a __str is used.
    00817        */
    00818       __versa_string&
    00819       assign(const __versa_string& __str, size_type __pos, size_type __n)
    00820       { return _M_replace(size_type(0), this->size(), __str._M_data()
    00821               + __str._M_check(__pos, "__versa_string::assign"),
    00822               __str._M_limit(__pos, __n)); }
    00823
    00824       /**
    00825        *  @brief  Set value to a C substring.
    00826        *  @param __s  The C string to use.
    00827        *  @param __n  Number of characters to use.
    00828        *  @return  Reference to this string.
    00829        *
    00830        *  This function sets the value of this string to the first @a
    00831        *  __n characters of @a __s.  If @a __n is is larger than the
    00832        *  number of available characters in @a __s, the remainder of
    00833        *  @a __s is used.
    00834        */
    00835       __versa_string&
    00836       assign(const _CharT* __s, size_type __n)
    00837       {
    00838     __glibcxx_requires_string_len(__s, __n);
    00839     return _M_replace(size_type(0), this->size(), __s, __n);
    00840       }
    00841
    00842       /**
    00843        *  @brief  Set value to contents of a C string.
    00844        *  @param __s  The C string to use.
    00845        *  @return  Reference to this string.
    00846        *
    00847        *  This function sets the value of this string to the value of
    00848        *  @a __s.  The data is copied, so there is no dependence on @a
    00849        *  __s once the function returns.
    00850        */
    00851       __versa_string&
    00852       assign(const _CharT* __s)
    00853       {
    00854     __glibcxx_requires_string(__s);
    00855     return _M_replace(size_type(0), this->size(), __s,
    00856               traits_type::length(__s));
    00857       }
    00858
    00859       /**
    00860        *  @brief  Set value to multiple characters.
    00861        *  @param __n  Length of the resulting string.
    00862        *  @param __c  The character to use.
    00863        *  @return  Reference to this string.
    00864        *
    00865        *  This function sets the value of this string to @a __n copies of
    00866        *  character @a __c.
    00867        */
    00868       __versa_string&
    00869       assign(size_type __n, _CharT __c)
    00870       { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
    00871
    00872       /**
    00873        *  @brief  Set value to a range of characters.
    00874        *  @param __first  Iterator referencing the first character to append.
    00875        *  @param __last  Iterator marking the end of the range.
    00876        *  @return  Reference to this string.
    00877        *
    00878        *  Sets value of string to characters in the range
    00879        *  [first,last).
    00880       */
    00881       template<class _InputIterator>
    00882         __versa_string&
    00883         assign(_InputIterator __first, _InputIterator __last)
    00884         { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
    00885
    00886 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00887       /**
    00888        *  @brief  Set value to an initializer_list of characters.
    00889        *  @param __l  The initializer_list of characters to assign.
    00890        *  @return  Reference to this string.
    00891        */
    00892       __versa_string&
    00893       assign(std::initializer_list<_CharT> __l)
    00894       { return this->assign(__l.begin(), __l.end()); }
    00895 #endif // __GXX_EXPERIMENTAL_CXX0X__
    00896
    00897       /**
    00898        *  @brief  Insert multiple characters.
    00899        *  @param __p  Iterator referencing location in string to insert at.
    00900        *  @param __n  Number of characters to insert
    00901        *  @param __c  The character to insert.
    00902        *  @throw  std::length_error  If new length exceeds @c max_size().
    00903        *
    00904        *  Inserts @a __n copies of character @a __c starting at the
    00905        *  position referenced by iterator @a __p.  If adding
    00906        *  characters causes the length to exceed max_size(),
    00907        *  length_error is thrown.  The value of the string doesn't
    00908        *  change if an error is thrown.
    00909       */
    00910       void
    00911       insert(iterator __p, size_type __n, _CharT __c)
    00912       { this->replace(__p, __p, __n, __c);  }
    00913
    00914       /**
    00915        *  @brief  Insert a range of characters.
    00916        *  @param __p  Iterator referencing location in string to insert at.
    00917        *  @param __beg  Start of range.
    00918        *  @param __end  End of range.
    00919        *  @throw  std::length_error  If new length exceeds @c max_size().
    00920        *
    00921        *  Inserts characters in range [beg,end).  If adding characters
    00922        *  causes the length to exceed max_size(), length_error is
    00923        *  thrown.  The value of the string doesn't change if an error
    00924        *  is thrown.
    00925       */
    00926       template<class _InputIterator>
    00927         void
    00928         insert(iterator __p, _InputIterator __beg, _InputIterator __end)
    00929         { this->replace(__p, __p, __beg, __end); }
    00930
    00931 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00932       /**
    00933        *  @brief  Insert an initializer_list of characters.
    00934        *  @param __p  Iterator referencing location in string to insert at.
    00935        *  @param __l  The initializer_list of characters to insert.
    00936        *  @throw  std::length_error  If new length exceeds @c max_size().
    00937        */
    00938       void
    00939       insert(iterator __p, std::initializer_list<_CharT> __l)
    00940       { this->insert(__p, __l.begin(), __l.end()); }
    00941 #endif // __GXX_EXPERIMENTAL_CXX0X__
    00942
    00943       /**
    00944        *  @brief  Insert value of a string.
    00945        *  @param __pos1  Iterator referencing location in string to insert at.
    00946        *  @param __str  The string to insert.
    00947        *  @return  Reference to this string.
    00948        *  @throw  std::length_error  If new length exceeds @c max_size().
    00949        *
    00950        *  Inserts value of @a __str starting at @a __pos1.  If adding
    00951        *  characters causes the length to exceed max_size(),
    00952        *  length_error is thrown.  The value of the string doesn't
    00953        *  change if an error is thrown.
    00954       */
    00955       __versa_string&
    00956       insert(size_type __pos1, const __versa_string& __str)
    00957       { return this->replace(__pos1, size_type(0),
    00958                  __str._M_data(), __str.size()); }
    00959
    00960       /**
    00961        *  @brief  Insert a substring.
    00962        *  @param __pos1  Iterator referencing location in string to insert at.
    00963        *  @param __str  The string to insert.
    00964        *  @param __pos2  Start of characters in str to insert.
    00965        *  @param __n  Number of characters to insert.
    00966        *  @return  Reference to this string.
    00967        *  @throw  std::length_error  If new length exceeds @c max_size().
    00968        *  @throw  std::out_of_range  If @a __pos1 > size() or
    00969        *  @a __pos2 > @a __str.size().
    00970        *
    00971        *  Starting at @a __pos1, insert @a __n character of @a __str
    00972        *  beginning with @a __pos2.  If adding characters causes the
    00973        *  length to exceed max_size(), length_error is thrown.  If @a
    00974        *  __pos1 is beyond the end of this string or @a __pos2 is
    00975        *  beyond the end of @a __str, out_of_range is thrown.  The
    00976        *  value of the string doesn't change if an error is thrown.
    00977       */
    00978       __versa_string&
    00979       insert(size_type __pos1, const __versa_string& __str,
    00980          size_type __pos2, size_type __n)
    00981       { return this->replace(__pos1, size_type(0), __str._M_data()
    00982                  + __str._M_check(__pos2, "__versa_string::insert"),
    00983                  __str._M_limit(__pos2, __n)); }
    00984
    00985       /**
    00986        *  @brief  Insert a C substring.
    00987        *  @param __pos  Iterator referencing location in string to insert at.
    00988        *  @param __s  The C string to insert.
    00989        *  @param __n  The number of characters to insert.
    00990        *  @return  Reference to this string.
    00991        *  @throw  std::length_error  If new length exceeds @c max_size().
    00992        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
    00993        *  string.
    00994        *
    00995        *  Inserts the first @a __n characters of @a __s starting at @a
    00996        *  __pos.  If adding characters causes the length to exceed
    00997        *  max_size(), length_error is thrown.  If @a __pos is beyond
    00998        *  end(), out_of_range is thrown.  The value of the string
    00999        *  doesn't change if an error is thrown.
    01000       */
    01001       __versa_string&
    01002       insert(size_type __pos, const _CharT* __s, size_type __n)
    01003       { return this->replace(__pos, size_type(0), __s, __n); }
    01004
    01005       /**
    01006        *  @brief  Insert a C string.
    01007        *  @param __pos  Iterator referencing location in string to insert at.
    01008        *  @param __s  The C string to insert.
    01009        *  @return  Reference to this string.
    01010        *  @throw  std::length_error  If new length exceeds @c max_size().
    01011        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
    01012        *  string.
    01013        *
    01014        *  Inserts the first @a __n characters of @a __s starting at @a
    01015        *  __pos.  If adding characters causes the length to exceed
    01016        *  max_size(), length_error is thrown.  If @a __pos is beyond
    01017        *  end(), out_of_range is thrown.  The value of the string
    01018        *  doesn't change if an error is thrown.
    01019       */
    01020       __versa_string&
    01021       insert(size_type __pos, const _CharT* __s)
    01022       {
    01023     __glibcxx_requires_string(__s);
    01024     return this->replace(__pos, size_type(0), __s,
    01025                  traits_type::length(__s));
    01026       }
    01027
    01028       /**
    01029        *  @brief  Insert multiple characters.
    01030        *  @param __pos  Index in string to insert at.
    01031        *  @param __n  Number of characters to insert
    01032        *  @param __c  The character to insert.
    01033        *  @return  Reference to this string.
    01034        *  @throw  std::length_error  If new length exceeds @c max_size().
    01035        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
    01036        *  string.
    01037        *
    01038        *  Inserts @a __n copies of character @a __c starting at index
    01039        *  @a __pos.  If adding characters causes the length to exceed
    01040        *  max_size(), length_error is thrown.  If @a __pos > length(),
    01041        *  out_of_range is thrown.  The value of the string doesn't
    01042        *  change if an error is thrown.
    01043       */
    01044       __versa_string&
    01045       insert(size_type __pos, size_type __n, _CharT __c)
    01046       { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
    01047                   size_type(0), __n, __c); }
    01048
    01049       /**
    01050        *  @brief  Insert one character.
    01051        *  @param __p  Iterator referencing position in string to insert at.
    01052        *  @param __c  The character to insert.
    01053        *  @return  Iterator referencing newly inserted char.
    01054        *  @throw  std::length_error  If new length exceeds @c max_size().
    01055        *
    01056        *  Inserts character @a __c at position referenced by @a __p.
    01057        *  If adding character causes the length to exceed max_size(),
    01058        *  length_error is thrown.  If @a __p is beyond end of string,
    01059        *  out_of_range is thrown.  The value of the string doesn't
    01060        *  change if an error is thrown.
    01061       */
    01062       iterator
    01063       insert(iterator __p, _CharT __c)
    01064       {
    01065     _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
    01066     const size_type __pos = __p - _M_ibegin();
    01067     _M_replace_aux(__pos, size_type(0), size_type(1), __c);
    01068     this->_M_set_leaked();
    01069     return iterator(this->_M_data() + __pos);
    01070       }
    01071
    01072       /**
    01073        *  @brief  Remove characters.
    01074        *  @param __pos  Index of first character to remove (default 0).
    01075        *  @param __n  Number of characters to remove (default remainder).
    01076        *  @return  Reference to this string.
    01077        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
    01078        *  string.
    01079        *
    01080        *  Removes @a __n characters from this string starting at @a
    01081        *  __pos.  The length of the string is reduced by @a __n.  If
    01082        *  there are < @a __n characters to remove, the remainder of
    01083        *  the string is truncated.  If @a __p is beyond end of string,
    01084        *  out_of_range is thrown.  The value of the string doesn't
    01085        *  change if an error is thrown.
    01086       */
    01087       __versa_string&
    01088       erase(size_type __pos = 0, size_type __n = npos)
    01089       {
    01090     this->_M_erase(_M_check(__pos, "__versa_string::erase"),
    01091                _M_limit(__pos, __n));
    01092     return *this;
    01093       }
    01094
    01095       /**
    01096        *  @brief  Remove one character.
    01097        *  @param __position  Iterator referencing the character to remove.
    01098        *  @return  iterator referencing same location after removal.
    01099        *
    01100        *  Removes the character at @a __position from this string. The
    01101        *  value of the string doesn't change if an error is thrown.
    01102       */
    01103       iterator
    01104       erase(iterator __position)
    01105       {
    01106     _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
    01107                  && __position < _M_iend());
    01108     const size_type __pos = __position - _M_ibegin();
    01109     this->_M_erase(__pos, size_type(1));
    01110     this->_M_set_leaked();
    01111     return iterator(this->_M_data() + __pos);
    01112       }
    01113
    01114       /**
    01115        *  @brief  Remove a range of characters.
    01116        *  @param __first  Iterator referencing the first character to remove.
    01117        *  @param __last  Iterator referencing the end of the range.
    01118        *  @return  Iterator referencing location of first after removal.
    01119        *
    01120        *  Removes the characters in the range [first,last) from this
    01121        *  string.  The value of the string doesn't change if an error
    01122        *  is thrown.
    01123       */
    01124       iterator
    01125       erase(iterator __first, iterator __last)
    01126       {
    01127     _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
    01128                  && __last <= _M_iend());
    01129         const size_type __pos = __first - _M_ibegin();
    01130     this->_M_erase(__pos, __last - __first);
    01131     this->_M_set_leaked();
    01132     return iterator(this->_M_data() + __pos);
    01133       }
    01134
    01135       /**
    01136        *  @brief  Replace characters with value from another string.
    01137        *  @param __pos  Index of first character to replace.
    01138        *  @param __n  Number of characters to be replaced.
    01139        *  @param __str  String to insert.
    01140        *  @return  Reference to this string.
    01141        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
    01142        *  string.
    01143        *  @throw  std::length_error  If new length exceeds @c max_size().
    01144        *
    01145        *  Removes the characters in the range [pos,pos+n) from this
    01146        *  string.  In place, the value of @a __str is inserted.  If @a
    01147        *  __pos is beyond end of string, out_of_range is thrown.  If
    01148        *  the length of the result exceeds max_size(), length_error is
    01149        *  thrown.  The value of the string doesn't change if an error
    01150        *  is thrown.
    01151       */
    01152       __versa_string&
    01153       replace(size_type __pos, size_type __n, const __versa_string& __str)
    01154       { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
    01155
    01156       /**
    01157        *  @brief  Replace characters with value from another string.
    01158        *  @param __pos1  Index of first character to replace.
    01159        *  @param __n1  Number of characters to be replaced.
    01160        *  @param __str  String to insert.
    01161        *  @param __pos2  Index of first character of str to use.
    01162        *  @param __n2  Number of characters from str to use.
    01163        *  @return  Reference to this string.
    01164        *  @throw  std::out_of_range  If @a __pos1 > size() or @a __pos2 >
    01165        *  str.size().
    01166        *  @throw  std::length_error  If new length exceeds @c max_size().
    01167        *
    01168        *  Removes the characters in the range [pos1,pos1 + n) from
    01169        *  this string.  In place, the value of @a __str is inserted.
    01170        *  If @a __pos is beyond end of string, out_of_range is thrown.
    01171        *  If the length of the result exceeds max_size(), length_error
    01172        *  is thrown.  The value of the string doesn't change if an
    01173        *  error is thrown.
    01174       */
    01175       __versa_string&
    01176       replace(size_type __pos1, size_type __n1, const __versa_string& __str,
    01177           size_type __pos2, size_type __n2)
    01178       {
    01179     return this->replace(__pos1, __n1, __str._M_data()
    01180                  + __str._M_check(__pos2,
    01181                           "__versa_string::replace"),
    01182                  __str._M_limit(__pos2, __n2));
    01183       }
    01184
    01185       /**
    01186        *  @brief  Replace characters with value of a C substring.
    01187        *  @param __pos  Index of first character to replace.
    01188        *  @param __n1  Number of characters to be replaced.
    01189        *  @param __s  C string to insert.
    01190        *  @param __n2  Number of characters from @a __s to use.
    01191        *  @return  Reference to this string.
    01192        *  @throw  std::out_of_range  If @a __pos1 > size().
    01193        *  @throw  std::length_error  If new length exceeds @c max_size().
    01194        *
    01195        *  Removes the characters in the range [pos,pos + n1) from this
    01196        *  string.  In place, the first @a __n2 characters of @a __s
    01197        *  are inserted, or all of @a __s if @a __n2 is too large.  If
    01198        *  @a __pos is beyond end of string, out_of_range is thrown.
    01199        *  If the length of result exceeds max_size(), length_error is
    01200        *  thrown.  The value of the string doesn't change if an error
    01201        *  is thrown.
    01202       */
    01203       __versa_string&
    01204       replace(size_type __pos, size_type __n1, const _CharT* __s,
    01205           size_type __n2)
    01206       {
    01207     __glibcxx_requires_string_len(__s, __n2);
    01208     return _M_replace(_M_check(__pos, "__versa_string::replace"),
    01209               _M_limit(__pos, __n1), __s, __n2);
    01210       }
    01211
    01212       /**
    01213        *  @brief  Replace characters with value of a C string.
    01214        *  @param __pos  Index of first character to replace.
    01215        *  @param __n1  Number of characters to be replaced.
    01216        *  @param __s  C string to insert.
    01217        *  @return  Reference to this string.
    01218        *  @throw  std::out_of_range  If @a __pos > size().
    01219        *  @throw  std::length_error  If new length exceeds @c max_size().
    01220        *
    01221        *  Removes the characters in the range [pos,pos + n1) from this
    01222        *  string.  In place, the characters of @a __s are inserted.  If
    01223        *  @a pos is beyond end of string, out_of_range is thrown.  If
    01224        *  the length of result exceeds max_size(), length_error is thrown.
    01225        *  The value of the string doesn't change if an error is thrown.
    01226       */
    01227       __versa_string&
    01228       replace(size_type __pos, size_type __n1, const _CharT* __s)
    01229       {
    01230     __glibcxx_requires_string(__s);
    01231     return this->replace(__pos, __n1, __s, traits_type::length(__s));
    01232       }
    01233
    01234       /**
    01235        *  @brief  Replace characters with multiple characters.
    01236        *  @param __pos  Index of first character to replace.
    01237        *  @param __n1  Number of characters to be replaced.
    01238        *  @param __n2  Number of characters to insert.
    01239        *  @param __c  Character to insert.
    01240        *  @return  Reference to this string.
    01241        *  @throw  std::out_of_range  If @a __pos > size().
    01242        *  @throw  std::length_error  If new length exceeds @c max_size().
    01243        *
    01244        *  Removes the characters in the range [pos,pos + n1) from this
    01245        *  string.  In place, @a __n2 copies of @a __c are inserted.
    01246        *  If @a __pos is beyond end of string, out_of_range is thrown.
    01247        *  If the length of result exceeds max_size(), length_error is
    01248        *  thrown.  The value of the string doesn't change if an error
    01249        *  is thrown.
    01250       */
    01251       __versa_string&
    01252       replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
    01253       { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
    01254                   _M_limit(__pos, __n1), __n2, __c); }
    01255
    01256       /**
    01257        *  @brief  Replace range of characters with string.
    01258        *  @param __i1  Iterator referencing start of range to replace.
    01259        *  @param __i2  Iterator referencing end of range to replace.
    01260        *  @param __str  String value to insert.
    01261        *  @return  Reference to this string.
    01262        *  @throw  std::length_error  If new length exceeds @c max_size().
    01263        *
    01264        *  Removes the characters in the range [i1,i2).  In place, the
    01265        *  value of @a __str is inserted.  If the length of result
    01266        *  exceeds max_size(), length_error is thrown.  The value of
    01267        *  the string doesn't change if an error is thrown.
    01268       */
    01269       __versa_string&
    01270       replace(iterator __i1, iterator __i2, const __versa_string& __str)
    01271       { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
    01272
    01273       /**
    01274        *  @brief  Replace range of characters with C substring.
    01275        *  @param __i1  Iterator referencing start of range to replace.
    01276        *  @param __i2  Iterator referencing end of range to replace.
    01277        *  @param __s  C string value to insert.
    01278        *  @param __n  Number of characters from s to insert.
    01279        *  @return  Reference to this string.
    01280        *  @throw  std::length_error  If new length exceeds @c max_size().
    01281        *
    01282        *  Removes the characters in the range [i1,i2).  In place, the
    01283        *  first @a n characters of @a __s are inserted.  If the length
    01284        *  of result exceeds max_size(), length_error is thrown.  The
    01285        *  value of the string doesn't change if an error is thrown.
    01286       */
    01287       __versa_string&
    01288       replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
    01289       {
    01290     _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
    01291                  && __i2 <= _M_iend());
    01292     return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
    01293       }
    01294
    01295       /**
    01296        *  @brief  Replace range of characters with C string.
    01297        *  @param __i1  Iterator referencing start of range to replace.
    01298        *  @param __i2  Iterator referencing end of range to replace.
    01299        *  @param __s  C string value to insert.
    01300        *  @return  Reference to this string.
    01301        *  @throw  std::length_error  If new length exceeds @c max_size().
    01302        *
    01303        *  Removes the characters in the range [i1,i2).  In place, the
    01304        *  characters of @a __s are inserted.  If the length of result
    01305        *  exceeds max_size(), length_error is thrown.  The value of
    01306        *  the string doesn't change if an error is thrown.
    01307       */
    01308       __versa_string&
    01309       replace(iterator __i1, iterator __i2, const _CharT* __s)
    01310       {
    01311     __glibcxx_requires_string(__s);
    01312     return this->replace(__i1, __i2, __s, traits_type::length(__s));
    01313       }
    01314
    01315       /**
    01316        *  @brief  Replace range of characters with multiple characters
    01317        *  @param __i1  Iterator referencing start of range to replace.
    01318        *  @param __i2  Iterator referencing end of range to replace.
    01319        *  @param __n  Number of characters to insert.
    01320        *  @param __c  Character to insert.
    01321        *  @return  Reference to this string.
    01322        *  @throw  std::length_error  If new length exceeds @c max_size().
    01323        *
    01324        *  Removes the characters in the range [i1,i2).  In place, @a
    01325        *  __n copies of @a __c are inserted.  If the length of result
    01326        *  exceeds max_size(), length_error is thrown.  The value of
    01327        *  the string doesn't change if an error is thrown.
    01328       */
    01329       __versa_string&
    01330       replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
    01331       {
    01332     _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
    01333                  && __i2 <= _M_iend());
    01334     return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
    01335       }
    01336
    01337       /**
    01338        *  @brief  Replace range of characters with range.
    01339        *  @param __i1  Iterator referencing start of range to replace.
    01340        *  @param __i2  Iterator referencing end of range to replace.
    01341        *  @param __k1  Iterator referencing start of range to insert.
    01342        *  @param __k2  Iterator referencing end of range to insert.
    01343        *  @return  Reference to this string.
    01344        *  @throw  std::length_error  If new length exceeds @c max_size().
    01345        *
    01346        *  Removes the characters in the range [i1,i2).  In place,
    01347        *  characters in the range [k1,k2) are inserted.  If the length
    01348        *  of result exceeds max_size(), length_error is thrown.  The
    01349        *  value of the string doesn't change if an error is thrown.
    01350       */
    01351       template<class _InputIterator>
    01352         __versa_string&
    01353         replace(iterator __i1, iterator __i2,
    01354         _InputIterator __k1, _InputIterator __k2)
    01355         {
    01356       _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
    01357                    && __i2 <= _M_iend());
    01358       __glibcxx_requires_valid_range(__k1, __k2);
    01359       typedef typename std::__is_integer<_InputIterator>::__type _Integral;
    01360       return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
    01361     }
    01362
    01363       // Specializations for the common case of pointer and iterator:
    01364       // useful to avoid the overhead of temporary buffering in _M_replace.
    01365       __versa_string&
    01366       replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
    01367       {
    01368     _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
    01369                  && __i2 <= _M_iend());
    01370     __glibcxx_requires_valid_range(__k1, __k2);
    01371     return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
    01372                  __k1, __k2 - __k1);
    01373       }
    01374
    01375       __versa_string&
    01376       replace(iterator __i1, iterator __i2,
    01377           const _CharT* __k1, const _CharT* __k2)
    01378       {
    01379     _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
    01380                  && __i2 <= _M_iend());
    01381     __glibcxx_requires_valid_range(__k1, __k2);
    01382     return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
    01383                  __k1, __k2 - __k1);
    01384       }
    01385
    01386       __versa_string&
    01387       replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
    01388       {
    01389     _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
    01390                  && __i2 <= _M_iend());
    01391     __glibcxx_requires_valid_range(__k1, __k2);
    01392     return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
    01393                  __k1.base(), __k2 - __k1);
    01394       }
    01395
    01396       __versa_string&
    01397       replace(iterator __i1, iterator __i2,
    01398           const_iterator __k1, const_iterator __k2)
    01399       {
    01400     _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
    01401                  && __i2 <= _M_iend());
    01402     __glibcxx_requires_valid_range(__k1, __k2);
    01403     return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
    01404                  __k1.base(), __k2 - __k1);
    01405       }
    01406
    01407 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    01408       /**
    01409        *  @brief  Replace range of characters with initializer_list.
    01410        *  @param __i1  Iterator referencing start of range to replace.
    01411        *  @param __i2  Iterator referencing end of range to replace.
    01412        *  @param __l  The initializer_list of characters to insert.
    01413        *  @return  Reference to this string.
    01414        *  @throw  std::length_error  If new length exceeds @c max_size().
    01415        *
    01416        *  Removes the characters in the range [i1,i2).  In place,
    01417        *  characters in the range [k1,k2) are inserted.  If the length
    01418        *  of result exceeds max_size(), length_error is thrown.  The
    01419        *  value of the string doesn't change if an error is thrown.
    01420       */
    01421       __versa_string& replace(iterator __i1, iterator __i2,
    01422                   std::initializer_list<_CharT> __l)
    01423       { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
    01424 #endif // __GXX_EXPERIMENTAL_CXX0X__
    01425
    01426     private:
    01427       template<class _Integer>
    01428     __versa_string&
    01429     _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
    01430                 _Integer __val, std::__true_type)
    01431         { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
    01432
    01433       template<class _InputIterator>
    01434     __versa_string&
    01435     _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
    01436                 _InputIterator __k2, std::__false_type);
    01437
    01438       __versa_string&
    01439       _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
    01440              _CharT __c);
    01441
    01442       __versa_string&
    01443       _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
    01444          const size_type __len2);
    01445
    01446       __versa_string&
    01447       _M_append(const _CharT* __s, size_type __n);
    01448
    01449     public:
    01450
    01451       /**
    01452        *  @brief  Copy substring into C string.
    01453        *  @param __s  C string to copy value into.
    01454        *  @param __n  Number of characters to copy.
    01455        *  @param __pos  Index of first character to copy.
    01456        *  @return  Number of characters actually copied
    01457        *  @throw  std::out_of_range  If pos > size().
    01458        *
    01459        *  Copies up to @a __n characters starting at @a __pos into the
    01460        *  C string @a s.  If @a __pos is greater than size(),
    01461        *  out_of_range is thrown.
    01462       */
    01463       size_type
    01464       copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
    01465
    01466       /**
    01467        *  @brief  Swap contents with another string.
    01468        *  @param __s  String to swap with.
    01469        *
    01470        *  Exchanges the contents of this string with that of @a __s in
    01471        *  constant time.
    01472       */
    01473       void
    01474       swap(__versa_string& __s)
    01475       { this->_M_swap(__s); }
    01476
    01477       // String operations:
    01478       /**
    01479        *  @brief  Return const pointer to null-terminated contents.
    01480        *
    01481        *  This is a handle to internal data.  Do not modify or dire things may
    01482        *  happen.
    01483       */
    01484       const _CharT*
    01485       c_str() const
    01486       { return this->_M_data(); }
    01487
    01488       /**
    01489        *  @brief  Return const pointer to contents.
    01490        *
    01491        *  This is a handle to internal data.  Do not modify or dire things may
    01492        *  happen.
    01493       */
    01494       const _CharT*
    01495       data() const
    01496       { return this->_M_data(); }
    01497
    01498       /**
    01499        *  @brief  Return copy of allocator used to construct this string.
    01500       */
    01501       allocator_type
    01502       get_allocator() const
    01503       { return allocator_type(this->_M_get_allocator()); }
    01504
    01505       /**
    01506        *  @brief  Find position of a C substring.
    01507        *  @param __s  C string to locate.
    01508        *  @param __pos  Index of character to search from.
    01509        *  @param __n  Number of characters from @a __s to search for.
    01510        *  @return  Index of start of first occurrence.
    01511        *
    01512        *  Starting from @a __pos, searches forward for the first @a
    01513        *  __n characters in @a __s within this string.  If found,
    01514        *  returns the index where it begins.  If not found, returns
    01515        *  npos.
    01516       */
    01517       size_type
    01518       find(const _CharT* __s, size_type __pos, size_type __n) const;
    01519
    01520       /**
    01521        *  @brief  Find position of a string.
    01522        *  @param __str  String to locate.
    01523        *  @param __pos  Index of character to search from (default 0).
    01524        *  @return  Index of start of first occurrence.
    01525        *
    01526        *  Starting from @a __pos, searches forward for value of @a
    01527        *  __str within this string.  If found, returns the index where
    01528        *  it begins.  If not found, returns npos.
    01529       */
    01530       size_type
    01531       find(const __versa_string& __str, size_type __pos = 0) const
    01532       { return this->find(__str.data(), __pos, __str.size()); }
    01533
    01534       /**
    01535        *  @brief  Find position of a C string.
    01536        *  @param __s  C string to locate.
    01537        *  @param __pos  Index of character to search from (default 0).
    01538        *  @return  Index of start of first occurrence.
    01539        *
    01540        *  Starting from @a __pos, searches forward for the value of @a
    01541        *  __s within this string.  If found, returns the index where
    01542        *  it begins.  If not found, returns npos.
    01543       */
    01544       size_type
    01545       find(const _CharT* __s, size_type __pos = 0) const
    01546       {
    01547     __glibcxx_requires_string(__s);
    01548     return this->find(__s, __pos, traits_type::length(__s));
    01549       }
    01550
    01551       /**
    01552        *  @brief  Find position of a character.
    01553        *  @param __c  Character to locate.
    01554        *  @param __pos  Index of character to search from (default 0).
    01555        *  @return  Index of first occurrence.
    01556        *
    01557        *  Starting from @a __pos, searches forward for @a __c within
    01558        *  this string.  If found, returns the index where it was
    01559        *  found.  If not found, returns npos.
    01560       */
    01561       size_type
    01562       find(_CharT __c, size_type __pos = 0) const;
    01563
    01564       /**
    01565        *  @brief  Find last position of a string.
    01566        *  @param __str  String to locate.
    01567        *  @param __pos  Index of character to search back from (default end).
    01568        *  @return  Index of start of last occurrence.
    01569        *
    01570        *  Starting from @a __pos, searches backward for value of @a
    01571        *  __str within this string.  If found, returns the index where
    01572        *  it begins.  If not found, returns npos.
    01573       */
    01574       size_type
    01575       rfind(const __versa_string& __str, size_type __pos = npos) const
    01576       { return this->rfind(__str.data(), __pos, __str.size()); }
    01577
    01578       /**
    01579        *  @brief  Find last position of a C substring.
    01580        *  @param __s  C string to locate.
    01581        *  @param __pos  Index of character to search back from.
    01582        *  @param __n  Number of characters from s to search for.
    01583        *  @return  Index of start of last occurrence.
    01584        *
    01585        *  Starting from @a __pos, searches backward for the first @a
    01586        *  __n characters in @a __s within this string.  If found,
    01587        *  returns the index where it begins.  If not found, returns
    01588        *  npos.
    01589       */
    01590       size_type
    01591       rfind(const _CharT* __s, size_type __pos, size_type __n) const;
    01592
    01593       /**
    01594        *  @brief  Find last position of a C string.
    01595        *  @param __s  C string to locate.
    01596        *  @param __pos  Index of character to start search at (default end).
    01597        *  @return  Index of start of  last occurrence.
    01598        *
    01599        *  Starting from @a __pos, searches backward for the value of
    01600        *  @a __s within this string.  If found, returns the index
    01601        *  where it begins.  If not found, returns npos.
    01602       */
    01603       size_type
    01604       rfind(const _CharT* __s, size_type __pos = npos) const
    01605       {
    01606     __glibcxx_requires_string(__s);
    01607     return this->rfind(__s, __pos, traits_type::length(__s));
    01608       }
    01609
    01610       /**
    01611        *  @brief  Find last position of a character.
    01612        *  @param __c  Character to locate.
    01613        *  @param __pos  Index of character to search back from (default end).
    01614        *  @return  Index of last occurrence.
    01615        *
    01616        *  Starting from @a __pos, searches backward for @a __c within
    01617        *  this string.  If found, returns the index where it was
    01618        *  found.  If not found, returns npos.
    01619       */
    01620       size_type
    01621       rfind(_CharT __c, size_type __pos = npos) const;
    01622
    01623       /**
    01624        *  @brief  Find position of a character of string.
    01625        *  @param __str  String containing characters to locate.
    01626        *  @param __pos  Index of character to search from (default 0).
    01627        *  @return  Index of first occurrence.
    01628        *
    01629        *  Starting from @a __pos, searches forward for one of the characters of
    01630        *  @a __str within this string.  If found, returns the index where it was
    01631        *  found.  If not found, returns npos.
    01632       */
    01633       size_type
    01634       find_first_of(const __versa_string& __str, size_type __pos = 0) const
    01635       { return this->find_first_of(__str.data(), __pos, __str.size()); }
    01636
    01637       /**
    01638        *  @brief  Find position of a character of C substring.
    01639        *  @param __s  String containing characters to locate.
    01640        *  @param __pos  Index of character to search from.
    01641        *  @param __n  Number of characters from s to search for.
    01642        *  @return  Index of first occurrence.
    01643        *
    01644        *  Starting from @a __pos, searches forward for one of the
    01645        *  first @a __n characters of @a __s within this string.  If
    01646        *  found, returns the index where it was found.  If not found,
    01647        *  returns npos.
    01648       */
    01649       size_type
    01650       find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
    01651
    01652       /**
    01653        *  @brief  Find position of a character of C string.
    01654        *  @param __s  String containing characters to locate.
    01655        *  @param __pos  Index of character to search from (default 0).
    01656        *  @return  Index of first occurrence.
    01657        *
    01658        *  Starting from @a __pos, searches forward for one of the
    01659        *  characters of @a __s within this string.  If found, returns
    01660        *  the index where it was found.  If not found, returns npos.
    01661       */
    01662       size_type
    01663       find_first_of(const _CharT* __s, size_type __pos = 0) const
    01664       {
    01665     __glibcxx_requires_string(__s);
    01666     return this->find_first_of(__s, __pos, traits_type::length(__s));
    01667       }
    01668
    01669       /**
    01670        *  @brief  Find position of a character.
    01671        *  @param __c  Character to locate.
    01672        *  @param __pos  Index of character to search from (default 0).
    01673        *  @return  Index of first occurrence.
    01674        *
    01675        *  Starting from @a __pos, searches forward for the character
    01676        *  @a __c within this string.  If found, returns the index
    01677        *  where it was found.  If not found, returns npos.
    01678        *
    01679        *  Note: equivalent to find(c, pos).
    01680       */
    01681       size_type
    01682       find_first_of(_CharT __c, size_type __pos = 0) const
    01683       { return this->find(__c, __pos); }
    01684
    01685       /**
    01686        *  @brief  Find last position of a character of string.
    01687        *  @param __str  String containing characters to locate.
    01688        *  @param __pos  Index of character to search back from (default end).
    01689        *  @return  Index of last occurrence.
    01690        *
    01691        *  Starting from @a __pos, searches backward for one of the
    01692        *  characters of @a __str within this string.  If found,
    01693        *  returns the index where it was found.  If not found, returns
    01694        *  npos.
    01695       */
    01696       size_type
    01697       find_last_of(const __versa_string& __str, size_type __pos = npos) const
    01698       { return this->find_last_of(__str.data(), __pos, __str.size()); }
    01699
    01700       /**
    01701        *  @brief  Find last position of a character of C substring.
    01702        *  @param __s  C string containing characters to locate.
    01703        *  @param __pos  Index of character to search back from.
    01704        *  @param __n  Number of characters from s to search for.
    01705        *  @return  Index of last occurrence.
    01706        *
    01707        *  Starting from @a __pos, searches backward for one of the
    01708        *  first @a __n characters of @a __s within this string.  If
    01709        *  found, returns the index where it was found.  If not found,
    01710        *  returns npos.
    01711       */
    01712       size_type
    01713       find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
    01714
    01715       /**
    01716        *  @brief  Find last position of a character of C string.
    01717        *  @param __s  C string containing characters to locate.
    01718        *  @param __pos  Index of character to search back from (default end).
    01719        *  @return  Index of last occurrence.
    01720        *
    01721        *  Starting from @a __pos, searches backward for one of the
    01722        *  characters of @a __s within this string.  If found, returns
    01723        *  the index where it was found.  If not found, returns npos.
    01724       */
    01725       size_type
    01726       find_last_of(const _CharT* __s, size_type __pos = npos) const
    01727       {
    01728     __glibcxx_requires_string(__s);
    01729     return this->find_last_of(__s, __pos, traits_type::length(__s));
    01730       }
    01731
    01732       /**
    01733        *  @brief  Find last position of a character.
    01734        *  @param __c  Character to locate.
    01735        *  @param __pos  Index of character to search back from (default end).
    01736        *  @return  Index of last occurrence.
    01737        *
    01738        *  Starting from @a __pos, searches backward for @a __c within
    01739        *  this string.  If found, returns the index where it was
    01740        *  found.  If not found, returns npos.
    01741        *
    01742        *  Note: equivalent to rfind(c, pos).
    01743       */
    01744       size_type
    01745       find_last_of(_CharT __c, size_type __pos = npos) const
    01746       { return this->rfind(__c, __pos); }
    01747
    01748       /**
    01749        *  @brief  Find position of a character not in string.
    01750        *  @param __str  String containing characters to avoid.
    01751        *  @param __pos  Index of character to search from (default 0).
    01752        *  @return  Index of first occurrence.
    01753        *
    01754        *  Starting from @a __pos, searches forward for a character not
    01755        *  contained in @a __str within this string.  If found, returns
    01756        *  the index where it was found.  If not found, returns npos.
    01757       */
    01758       size_type
    01759       find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
    01760       { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
    01761
    01762       /**
    01763        *  @brief  Find position of a character not in C substring.
    01764        *  @param __s  C string containing characters to avoid.
    01765        *  @param __pos  Index of character to search from.
    01766        *  @param __n  Number of characters from s to consider.
    01767        *  @return  Index of first occurrence.
    01768        *
    01769        *  Starting from @a __pos, searches forward for a character not
    01770        *  contained in the first @a __n characters of @a __s within
    01771        *  this string.  If found, returns the index where it was
    01772        *  found.  If not found, returns npos.
    01773       */
    01774       size_type
    01775       find_first_not_of(const _CharT* __s, size_type __pos,
    01776             size_type __n) const;
    01777
    01778       /**
    01779        *  @brief  Find position of a character not in C string.
    01780        *  @param __s  C string containing characters to avoid.
    01781        *  @param __pos  Index of character to search from (default 0).
    01782        *  @return  Index of first occurrence.
    01783        *
    01784        *  Starting from @a __pos, searches forward for a character not
    01785        *  contained in @a __s within this string.  If found, returns
    01786        *  the index where it was found.  If not found, returns npos.
    01787       */
    01788       size_type
    01789       find_first_not_of(const _CharT* __s, size_type __pos = 0) const
    01790       {
    01791     __glibcxx_requires_string(__s);
    01792     return this->find_first_not_of(__s, __pos, traits_type::length(__s));
    01793       }
    01794
    01795       /**
    01796        *  @brief  Find position of a different character.
    01797        *  @param __c  Character to avoid.
    01798        *  @param __pos  Index of character to search from (default 0).
    01799        *  @return  Index of first occurrence.
    01800        *
    01801        *  Starting from @a __pos, searches forward for a character
    01802        *  other than @a __c within this string.  If found, returns the
    01803        *  index where it was found.  If not found, returns npos.
    01804       */
    01805       size_type
    01806       find_first_not_of(_CharT __c, size_type __pos = 0) const;
    01807
    01808       /**
    01809        *  @brief  Find last position of a character not in string.
    01810        *  @param __str  String containing characters to avoid.
    01811        *  @param __pos  Index of character to search back from (default end).
    01812        *  @return  Index of last occurrence.
    01813        *
    01814        *  Starting from @a __pos, searches backward for a character
    01815        *  not contained in @a __str within this string.  If found,
    01816        *  returns the index where it was found.  If not found, returns
    01817        *  npos.
    01818       */
    01819       size_type
    01820       find_last_not_of(const __versa_string& __str,
    01821                size_type __pos = npos) const
    01822       { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
    01823
    01824       /**
    01825        *  @brief  Find last position of a character not in C substring.
    01826        *  @param __s  C string containing characters to avoid.
    01827        *  @param __pos  Index of character to search back from.
    01828        *  @param __n  Number of characters from s to consider.
    01829        *  @return  Index of last occurrence.
    01830        *
    01831        *  Starting from @a __pos, searches backward for a character
    01832        *  not contained in the first @a __n characters of @a __s
    01833        *  within this string.  If found, returns the index where it
    01834        *  was found.  If not found, returns npos.
    01835       */
    01836       size_type
    01837       find_last_not_of(const _CharT* __s, size_type __pos,
    01838                size_type __n) const;
    01839       /**
    01840        *  @brief  Find last position of a character not in C string.
    01841        *  @param __s  C string containing characters to avoid.
    01842        *  @param __pos  Index of character to search back from (default end).
    01843        *  @return  Index of last occurrence.
    01844        *
    01845        *  Starting from @a __pos, searches backward for a character
    01846        *  not contained in @a __s within this string.  If found,
    01847        *  returns the index where it was found.  If not found, returns
    01848        *  npos.
    01849       */
    01850       size_type
    01851       find_last_not_of(const _CharT* __s, size_type __pos = npos) const
    01852       {
    01853     __glibcxx_requires_string(__s);
    01854     return this->find_last_not_of(__s, __pos, traits_type::length(__s));
    01855       }
    01856
    01857       /**
    01858        *  @brief  Find last position of a different character.
    01859        *  @param __c  Character to avoid.
    01860        *  @param __pos  Index of character to search back from (default end).
    01861        *  @return  Index of last occurrence.
    01862        *
    01863        *  Starting from @a __pos, searches backward for a character
    01864        *  other than @a __c within this string.  If found, returns the
    01865        *  index where it was found.  If not found, returns npos.
    01866       */
    01867       size_type
    01868       find_last_not_of(_CharT __c, size_type __pos = npos) const;
    01869
    01870       /**
    01871        *  @brief  Get a substring.
    01872        *  @param __pos  Index of first character (default 0).
    01873        *  @param __n  Number of characters in substring (default remainder).
    01874        *  @return  The new string.
    01875        *  @throw  std::out_of_range  If pos > size().
    01876        *
    01877        *  Construct and return a new string using the @a __n
    01878        *  characters starting at @a __pos.  If the string is too
    01879        *  short, use the remainder of the characters.  If @a __pos is
    01880        *  beyond the end of the string, out_of_range is thrown.
    01881       */
    01882       __versa_string
    01883       substr(size_type __pos = 0, size_type __n = npos) const
    01884       {
    01885     return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
    01886                   __n);
    01887       }
    01888
    01889       /**
    01890        *  @brief  Compare to a string.
    01891        *  @param __str  String to compare against.
    01892        *  @return  Integer < 0, 0, or > 0.
    01893        *
    01894        *  Returns an integer < 0 if this string is ordered before @a
    01895        *  __str, 0 if their values are equivalent, or > 0 if this
    01896        *  string is ordered after @a __str.  Determines the effective
    01897        *  length rlen of the strings to compare as the smallest of
    01898        *  size() and str.size().  The function then compares the two
    01899        *  strings by calling traits::compare(data(), str.data(),rlen).
    01900        *  If the result of the comparison is nonzero returns it,
    01901        *  otherwise the shorter one is ordered first.
    01902       */
    01903       int
    01904       compare(const __versa_string& __str) const
    01905       {
    01906     if (this->_M_compare(__str))
    01907       return 0;
    01908
    01909     const size_type __size = this->size();
    01910     const size_type __osize = __str.size();
    01911     const size_type __len = std::min(__size, __osize);
    01912
    01913     int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
    01914     if (!__r)
    01915       __r = _S_compare(__size, __osize);
    01916     return __r;
    01917       }
    01918
    01919       /**
    01920        *  @brief  Compare substring to a string.
    01921        *  @param __pos  Index of first character of substring.
    01922        *  @param __n  Number of characters in substring.
    01923        *  @param __str  String to compare against.
    01924        *  @return  Integer < 0, 0, or > 0.
    01925        *
    01926        *  Form the substring of this string from the @a __n characters
    01927        *  starting at @a __pos.  Returns an integer < 0 if the
    01928        *  substring is ordered before @a __str, 0 if their values are
    01929        *  equivalent, or > 0 if the substring is ordered after @a
    01930        *  __str.  Determines the effective length rlen of the strings
    01931        *  to compare as the smallest of the length of the substring
    01932        *  and @a __str.size().  The function then compares the two
    01933        *  strings by calling
    01934        *  traits::compare(substring.data(),str.data(),rlen).  If the
    01935        *  result of the comparison is nonzero returns it, otherwise
    01936        *  the shorter one is ordered first.
    01937       */
    01938       int
    01939       compare(size_type __pos, size_type __n,
    01940           const __versa_string& __str) const;
    01941
    01942       /**
    01943        *  @brief  Compare substring to a substring.
    01944        *  @param __pos1  Index of first character of substring.
    01945        *  @param __n1  Number of characters in substring.
    01946        *  @param __str  String to compare against.
    01947        *  @param __pos2  Index of first character of substring of str.
    01948        *  @param __n2  Number of characters in substring of str.
    01949        *  @return  Integer < 0, 0, or > 0.
    01950        *
    01951        *  Form the substring of this string from the @a __n1
    01952        *  characters starting at @a __pos1.  Form the substring of @a
    01953        *  __str from the @a __n2 characters starting at @a __pos2.
    01954        *  Returns an integer < 0 if this substring is ordered before
    01955        *  the substring of @a __str, 0 if their values are equivalent,
    01956        *  or > 0 if this substring is ordered after the substring of
    01957        *  @a __str.  Determines the effective length rlen of the
    01958        *  strings to compare as the smallest of the lengths of the
    01959        *  substrings.  The function then compares the two strings by
    01960        *  calling
    01961        *  traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
    01962        *  If the result of the comparison is nonzero returns it,
    01963        *  otherwise the shorter one is ordered first.
    01964       */
    01965       int
    01966       compare(size_type __pos1, size_type __n1, const __versa_string& __str,
    01967           size_type __pos2, size_type __n2) const;
    01968
    01969       /**
    01970        *  @brief  Compare to a C string.
    01971        *  @param __s  C string to compare against.
    01972        *  @return  Integer < 0, 0, or > 0.
    01973        *
    01974        *  Returns an integer < 0 if this string is ordered before @a
    01975        *  __s, 0 if their values are equivalent, or > 0 if this string
    01976        *  is ordered after @a __s.  Determines the effective length
    01977        *  rlen of the strings to compare as the smallest of size() and
    01978        *  the length of a string constructed from @a __s.  The
    01979        *  function then compares the two strings by calling
    01980        *  traits::compare(data(),s,rlen).  If the result of the
    01981        *  comparison is nonzero returns it, otherwise the shorter one
    01982        *  is ordered first.
    01983       */
    01984       int
    01985       compare(const _CharT* __s) const;
    01986
    01987       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    01988       // 5 String::compare specification questionable
    01989       /**
    01990        *  @brief  Compare substring to a C string.
    01991        *  @param __pos  Index of first character of substring.
    01992        *  @param __n1  Number of characters in substring.
    01993        *  @param __s  C string to compare against.
    01994        *  @return  Integer < 0, 0, or > 0.
    01995        *
    01996        *  Form the substring of this string from the @a __n1
    01997        *  characters starting at @a __pos.  Returns an integer < 0 if
    01998        *  the substring is ordered before @a __s, 0 if their values
    01999        *  are equivalent, or > 0 if the substring is ordered after @a
    02000        *  __s.  Determines the effective length rlen of the strings to
    02001        *  compare as the smallest of the length of the substring and
    02002        *  the length of a string constructed from @a __s.  The
    02003        *  function then compares the two string by calling
    02004        *  traits::compare(substring.data(),s,rlen).  If the result of
    02005        *  the comparison is nonzero returns it, otherwise the shorter
    02006        *  one is ordered first.
    02007       */
    02008       int
    02009       compare(size_type __pos, size_type __n1, const _CharT* __s) const;
    02010
    02011       /**
    02012        *  @brief  Compare substring against a character array.
    02013        *  @param __pos1  Index of first character of substring.
    02014        *  @param __n1  Number of characters in substring.
    02015        *  @param __s  character array to compare against.
    02016        *  @param __n2  Number of characters of s.
    02017        *  @return  Integer < 0, 0, or > 0.
    02018        *
    02019        *  Form the substring of this string from the @a __n1
    02020        *  characters starting at @a __pos1.  Form a string from the
    02021        *  first @a __n2 characters of @a __s.  Returns an integer < 0
    02022        *  if this substring is ordered before the string from @a __s,
    02023        *  0 if their values are equivalent, or > 0 if this substring
    02024        *  is ordered after the string from @a __s.  Determines the
    02025        *  effective length rlen of the strings to compare as the
    02026        *  smallest of the length of the substring and @a __n2.  The
    02027        *  function then compares the two strings by calling
    02028        *  traits::compare(substring.data(),s,rlen).  If the result of
    02029        *  the comparison is nonzero returns it, otherwise the shorter
    02030        *  one is ordered first.
    02031        *
    02032        *  NB: s must have at least n2 characters, <em>\\0</em> has no special
    02033        *  meaning.
    02034       */
    02035       int
    02036       compare(size_type __pos, size_type __n1, const _CharT* __s,
    02037           size_type __n2) const;
    02038     };
    02039
    02040   // operator+
    02041   /**
    02042    *  @brief  Concatenate two strings.
    02043    *  @param __lhs  First string.
    02044    *  @param __rhs  Last string.
    02045    *  @return  New string with value of @a __lhs followed by @a __rhs.
    02046    */
    02047   template<typename _CharT, typename _Traits, typename _Alloc,
    02048        template <typename, typename, typename> class _Base>
    02049     __versa_string<_CharT, _Traits, _Alloc, _Base>
    02050     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02051           const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
    02052
    02053   /**
    02054    *  @brief  Concatenate C string and string.
    02055    *  @param __lhs  First string.
    02056    *  @param __rhs  Last string.
    02057    *  @return  New string with value of @a __lhs followed by @a __rhs.
    02058    */
    02059   template<typename _CharT, typename _Traits, typename _Alloc,
    02060        template <typename, typename, typename> class _Base>
    02061     __versa_string<_CharT, _Traits, _Alloc, _Base>
    02062     operator+(const _CharT* __lhs,
    02063           const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
    02064
    02065   /**
    02066    *  @brief  Concatenate character and string.
    02067    *  @param __lhs  First string.
    02068    *  @param __rhs  Last string.
    02069    *  @return  New string with @a __lhs followed by @a __rhs.
    02070    */
    02071   template<typename _CharT, typename _Traits, typename _Alloc,
    02072        template <typename, typename, typename> class _Base>
    02073     __versa_string<_CharT, _Traits, _Alloc, _Base>
    02074     operator+(_CharT __lhs,
    02075           const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
    02076
    02077   /**
    02078    *  @brief  Concatenate string and C string.
    02079    *  @param __lhs  First string.
    02080    *  @param __rhs  Last string.
    02081    *  @return  New string with @a __lhs followed by @a __rhs.
    02082    */
    02083   template<typename _CharT, typename _Traits, typename _Alloc,
    02084        template <typename, typename, typename> class _Base>
    02085     __versa_string<_CharT, _Traits, _Alloc, _Base>
    02086     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02087           const _CharT* __rhs);
    02088
    02089   /**
    02090    *  @brief  Concatenate string and character.
    02091    *  @param __lhs  First string.
    02092    *  @param __rhs  Last string.
    02093    *  @return  New string with @a __lhs followed by @a __rhs.
    02094    */
    02095   template<typename _CharT, typename _Traits, typename _Alloc,
    02096        template <typename, typename, typename> class _Base>
    02097     __versa_string<_CharT, _Traits, _Alloc, _Base>
    02098     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02099           _CharT __rhs);
    02100
    02101   // operator ==
    02102   /**
    02103    *  @brief  Test equivalence of two strings.
    02104    *  @param __lhs  First string.
    02105    *  @param __rhs  Second string.
    02106    *  @return  True if @a __lhs.compare(@a __rhs) == 0.  False otherwise.
    02107    */
    02108   template<typename _CharT, typename _Traits, typename _Alloc,
    02109        template <typename, typename, typename> class _Base>
    02110     inline bool
    02111     operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02112            const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    02113     { return __lhs.compare(__rhs) == 0; }
    02114
    02115   template<typename _CharT,
    02116        template <typename, typename, typename> class _Base>
    02117     inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type
    02118     operator==(const __versa_string<_CharT, std::char_traits<_CharT>,
    02119            std::allocator<_CharT>, _Base>& __lhs,
    02120            const __versa_string<_CharT, std::char_traits<_CharT>,
    02121            std::allocator<_CharT>, _Base>& __rhs)
    02122     { return (__lhs.size() == __rhs.size()
    02123           && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
    02124                             __lhs.size())); }
    02125
    02126   /**
    02127    *  @brief  Test equivalence of C string and string.
    02128    *  @param __lhs  C string.
    02129    *  @param __rhs  String.
    02130    *  @return  True if @a __rhs.compare(@a __lhs) == 0.  False otherwise.
    02131    */
    02132   template<typename _CharT, typename _Traits, typename _Alloc,
    02133        template <typename, typename, typename> class _Base>
    02134     inline bool
    02135     operator==(const _CharT* __lhs,
    02136            const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    02137     { return __rhs.compare(__lhs) == 0; }
    02138
    02139   /**
    02140    *  @brief  Test equivalence of string and C string.
    02141    *  @param __lhs  String.
    02142    *  @param __rhs  C string.
    02143    *  @return  True if @a __lhs.compare(@a __rhs) == 0.  False otherwise.
    02144    */
    02145   template<typename _CharT, typename _Traits, typename _Alloc,
    02146        template <typename, typename, typename> class _Base>
    02147     inline bool
    02148     operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02149            const _CharT* __rhs)
    02150     { return __lhs.compare(__rhs) == 0; }
    02151
    02152   // operator !=
    02153   /**
    02154    *  @brief  Test difference of two strings.
    02155    *  @param __lhs  First string.
    02156    *  @param __rhs  Second string.
    02157    *  @return  True if @a __lhs.compare(@a __rhs) != 0.  False otherwise.
    02158    */
    02159   template<typename _CharT, typename _Traits, typename _Alloc,
    02160        template <typename, typename, typename> class _Base>
    02161     inline bool
    02162     operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02163            const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    02164     { return !(__lhs == __rhs); }
    02165
    02166   /**
    02167    *  @brief  Test difference of C string and string.
    02168    *  @param __lhs  C string.
    02169    *  @param __rhs  String.
    02170    *  @return  True if @a __rhs.compare(@a __lhs) != 0.  False otherwise.
    02171    */
    02172   template<typename _CharT, typename _Traits, typename _Alloc,
    02173        template <typename, typename, typename> class _Base>
    02174     inline bool
    02175     operator!=(const _CharT* __lhs,
    02176            const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    02177     { return !(__lhs == __rhs); }
    02178
    02179   /**
    02180    *  @brief  Test difference of string and C string.
    02181    *  @param __lhs  String.
    02182    *  @param __rhs  C string.
    02183    *  @return  True if @a __lhs.compare(@a __rhs) != 0.  False otherwise.
    02184    */
    02185   template<typename _CharT, typename _Traits, typename _Alloc,
    02186        template <typename, typename, typename> class _Base>
    02187     inline bool
    02188     operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02189            const _CharT* __rhs)
    02190     { return !(__lhs == __rhs); }
    02191
    02192   // operator <
    02193   /**
    02194    *  @brief  Test if string precedes string.
    02195    *  @param __lhs  First string.
    02196    *  @param __rhs  Second string.
    02197    *  @return  True if @a __lhs precedes @a __rhs.  False otherwise.
    02198    */
    02199   template<typename _CharT, typename _Traits, typename _Alloc,
    02200        template <typename, typename, typename> class _Base>
    02201     inline bool
    02202     operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02203           const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    02204     { return __lhs.compare(__rhs) < 0; }
    02205
    02206   /**
    02207    *  @brief  Test if string precedes C string.
    02208    *  @param __lhs  String.
    02209    *  @param __rhs  C string.
    02210    *  @return  True if @a __lhs precedes @a __rhs.  False otherwise.
    02211    */
    02212   template<typename _CharT, typename _Traits, typename _Alloc,
    02213        template <typename, typename, typename> class _Base>
    02214     inline bool
    02215     operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02216           const _CharT* __rhs)
    02217     { return __lhs.compare(__rhs) < 0; }
    02218
    02219   /**
    02220    *  @brief  Test if C string precedes string.
    02221    *  @param __lhs  C string.
    02222    *  @param __rhs  String.
    02223    *  @return  True if @a __lhs precedes @a __rhs.  False otherwise.
    02224    */
    02225   template<typename _CharT, typename _Traits, typename _Alloc,
    02226        template <typename, typename, typename> class _Base>
    02227     inline bool
    02228     operator<(const _CharT* __lhs,
    02229           const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    02230     { return __rhs.compare(__lhs) > 0; }
    02231
    02232   // operator >
    02233   /**
    02234    *  @brief  Test if string follows string.
    02235    *  @param __lhs  First string.
    02236    *  @param __rhs  Second string.
    02237    *  @return  True if @a __lhs follows @a __rhs.  False otherwise.
    02238    */
    02239   template<typename _CharT, typename _Traits, typename _Alloc,
    02240        template <typename, typename, typename> class _Base>
    02241     inline bool
    02242     operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02243           const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    02244     { return __lhs.compare(__rhs) > 0; }
    02245
    02246   /**
    02247    *  @brief  Test if string follows C string.
    02248    *  @param __lhs  String.
    02249    *  @param __rhs  C string.
    02250    *  @return  True if @a __lhs follows @a __rhs.  False otherwise.
    02251    */
    02252   template<typename _CharT, typename _Traits, typename _Alloc,
    02253        template <typename, typename, typename> class _Base>
    02254     inline bool
    02255     operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02256           const _CharT* __rhs)
    02257     { return __lhs.compare(__rhs) > 0; }
    02258
    02259   /**
    02260    *  @brief  Test if C string follows string.
    02261    *  @param __lhs  C string.
    02262    *  @param __rhs  String.
    02263    *  @return  True if @a __lhs follows @a __rhs.  False otherwise.
    02264    */
    02265   template<typename _CharT, typename _Traits, typename _Alloc,
    02266        template <typename, typename, typename> class _Base>
    02267     inline bool
    02268     operator>(const _CharT* __lhs,
    02269           const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    02270     { return __rhs.compare(__lhs) < 0; }
    02271
    02272   // operator <=
    02273   /**
    02274    *  @brief  Test if string doesn't follow string.
    02275    *  @param __lhs  First string.
    02276    *  @param __rhs  Second string.
    02277    *  @return  True if @a __lhs doesn't follow @a __rhs.  False otherwise.
    02278    */
    02279   template<typename _CharT, typename _Traits, typename _Alloc,
    02280        template <typename, typename, typename> class _Base>
    02281     inline bool
    02282     operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02283            const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    02284     { return __lhs.compare(__rhs) <= 0; }
    02285
    02286   /**
    02287    *  @brief  Test if string doesn't follow C string.
    02288    *  @param __lhs  String.
    02289    *  @param __rhs  C string.
    02290    *  @return  True if @a __lhs doesn't follow @a __rhs.  False otherwise.
    02291    */
    02292   template<typename _CharT, typename _Traits, typename _Alloc,
    02293        template <typename, typename, typename> class _Base>
    02294     inline bool
    02295     operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02296            const _CharT* __rhs)
    02297     { return __lhs.compare(__rhs) <= 0; }
    02298
    02299   /**
    02300    *  @brief  Test if C string doesn't follow string.
    02301    *  @param __lhs  C string.
    02302    *  @param __rhs  String.
    02303    *  @return  True if @a __lhs doesn't follow @a __rhs.  False otherwise.
    02304    */
    02305   template<typename _CharT, typename _Traits, typename _Alloc,
    02306        template <typename, typename, typename> class _Base>
    02307     inline bool
    02308     operator<=(const _CharT* __lhs,
    02309            const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    02310     { return __rhs.compare(__lhs) >= 0; }
    02311
    02312   // operator >=
    02313   /**
    02314    *  @brief  Test if string doesn't precede string.
    02315    *  @param __lhs  First string.
    02316    *  @param __rhs  Second string.
    02317    *  @return  True if @a __lhs doesn't precede @a __rhs.  False otherwise.
    02318    */
    02319   template<typename _CharT, typename _Traits, typename _Alloc,
    02320        template <typename, typename, typename> class _Base>
    02321     inline bool
    02322     operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02323            const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    02324     { return __lhs.compare(__rhs) >= 0; }
    02325
    02326   /**
    02327    *  @brief  Test if string doesn't precede C string.
    02328    *  @param __lhs  String.
    02329    *  @param __rhs  C string.
    02330    *  @return  True if @a __lhs doesn't precede @a __rhs.  False otherwise.
    02331    */
    02332   template<typename _CharT, typename _Traits, typename _Alloc,
    02333        template <typename, typename, typename> class _Base>
    02334     inline bool
    02335     operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02336            const _CharT* __rhs)
    02337     { return __lhs.compare(__rhs) >= 0; }
    02338
    02339   /**
    02340    *  @brief  Test if C string doesn't precede string.
    02341    *  @param __lhs  C string.
    02342    *  @param __rhs  String.
    02343    *  @return  True if @a __lhs doesn't precede @a __rhs.  False otherwise.
    02344    */
    02345   template<typename _CharT, typename _Traits, typename _Alloc,
    02346        template <typename, typename, typename> class _Base>
    02347     inline bool
    02348     operator>=(const _CharT* __lhs,
    02349            const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    02350     { return __rhs.compare(__lhs) <= 0; }
    02351
    02352   /**
    02353    *  @brief  Swap contents of two strings.
    02354    *  @param __lhs  First string.
    02355    *  @param __rhs  Second string.
    02356    *
    02357    *  Exchanges the contents of @a __lhs and @a __rhs in constant time.
    02358    */
    02359   template<typename _CharT, typename _Traits, typename _Alloc,
    02360        template <typename, typename, typename> class _Base>
    02361     inline void
    02362     swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    02363      __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    02364     { __lhs.swap(__rhs); }
    02365
    02366 _GLIBCXX_END_NAMESPACE
    02367
    02368 _GLIBCXX_BEGIN_NAMESPACE(std)
    02369
    02370   /**
    02371    *  @brief  Read stream into a string.
    02372    *  @param __is  Input stream.
    02373    *  @param __str  Buffer to store into.
    02374    *  @return  Reference to the input stream.
    02375    *
    02376    *  Stores characters from @a __is into @a __str until whitespace is
    02377    *  found, the end of the stream is encountered, or str.max_size()
    02378    *  is reached.  If is.width() is non-zero, that is the limit on the
    02379    *  number of characters stored into @a __str.  Any previous
    02380    *  contents of @a __str are erased.
    02381    */
    02382   template<typename _CharT, typename _Traits, typename _Alloc,
    02383            template <typename, typename, typename> class _Base>
    02384     basic_istream<_CharT, _Traits>&
    02385     operator>>(basic_istream<_CharT, _Traits>& __is,
    02386            __gnu_cxx::__versa_string<_CharT, _Traits,
    02387                                      _Alloc, _Base>& __str);
    02388
    02389   /**
    02390    *  @brief  Write string to a stream.
    02391    *  @param __os  Output stream.
    02392    *  @param __str  String to write out.
    02393    *  @return  Reference to the output stream.
    02394    *
    02395    *  Output characters of @a __str into os following the same rules as for
    02396    *  writing a C string.
    02397    */
    02398   template<typename _CharT, typename _Traits, typename _Alloc,
    02399        template <typename, typename, typename> class _Base>
    02400     inline basic_ostream<_CharT, _Traits>&
    02401     operator<<(basic_ostream<_CharT, _Traits>& __os,
    02402            const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc,
    02403            _Base>& __str)
    02404     {
    02405       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    02406       // 586. string inserter not a formatted function
    02407       return __ostream_insert(__os, __str.data(), __str.size());
    02408     }
    02409
    02410   /**
    02411    *  @brief  Read a line from stream into a string.
    02412    *  @param __is  Input stream.
    02413    *  @param __str  Buffer to store into.
    02414    *  @param __delim  Character marking end of line.
    02415    *  @return  Reference to the input stream.
    02416    *
    02417    *  Stores characters from @a __is into @a __str until @a __delim is
    02418    *  found, the end of the stream is encountered, or str.max_size()
    02419    *  is reached.  If is.width() is non-zero, that is the limit on the
    02420    *  number of characters stored into @a __str.  Any previous
    02421    *  contents of @a __str are erased.  If @a delim was encountered,
    02422    *  it is extracted but not stored into @a __str.
    02423    */
    02424   template<typename _CharT, typename _Traits, typename _Alloc,
    02425            template <typename, typename, typename> class _Base>
    02426     basic_istream<_CharT, _Traits>&
    02427     getline(basic_istream<_CharT, _Traits>& __is,
    02428         __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
    02429         _CharT __delim);
    02430
    02431   /**
    02432    *  @brief  Read a line from stream into a string.
    02433    *  @param __is  Input stream.
    02434    *  @param __str  Buffer to store into.
    02435    *  @return  Reference to the input stream.
    02436    *
    02437    *  Stores characters from is into @a __str until &apos;\n&apos; is
    02438    *  found, the end of the stream is encountered, or str.max_size()
    02439    *  is reached.  If is.width() is non-zero, that is the limit on the
    02440    *  number of characters stored into @a __str.  Any previous
    02441    *  contents of @a __str are erased.  If end of line was
    02442    *  encountered, it is extracted but not stored into @a __str.
    02443    */
    02444   template<typename _CharT, typename _Traits, typename _Alloc,
    02445            template <typename, typename, typename> class _Base>
    02446     inline basic_istream<_CharT, _Traits>&
    02447     getline(basic_istream<_CharT, _Traits>& __is,
    02448         __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
    02449     { return getline(__is, __str, __is.widen('\n')); }
    02450
    02451 _GLIBCXX_END_NAMESPACE
    02452
    02453 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99))
    02454
    02455 #include <ext/string_conversions.h>
    02456
    02457 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
    02458
    02459   // 21.4 Numeric Conversions [string.conversions].
    02460   inline int
    02461   stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
    02462   { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
    02463                     __idx, __base); }
    02464
    02465   inline long
    02466   stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
    02467   { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
    02468                  __idx, __base); }
    02469
    02470   inline unsigned long
    02471   stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
    02472   { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
    02473                  __idx, __base); }
    02474
    02475   inline long long
    02476   stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
    02477   { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
    02478                  __idx, __base); }
    02479
    02480   inline unsigned long long
    02481   stoull(const __vstring& __str, std::size_t* __idx, int __base = 10)
    02482   { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
    02483                  __idx, __base); }
    02484
    02485   // NB: strtof vs strtod.
    02486   inline float
    02487   stof(const __vstring& __str, std::size_t* __idx = 0)
    02488   { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
    02489
    02490   inline double
    02491   stod(const __vstring& __str, std::size_t* __idx = 0)
    02492   { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
    02493
    02494   inline long double
    02495   stold(const __vstring& __str, std::size_t* __idx = 0)
    02496   { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
    02497
    02498   // NB: (v)snprintf vs sprintf.
    02499
    02500   // DR 1261.
    02501   inline __vstring
    02502   to_string(int __val)
    02503   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
    02504                           "%d", __val); }
    02505
    02506   inline __vstring
    02507   to_string(unsigned __val)
    02508   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
    02509                           4 * sizeof(unsigned),
    02510                           "%u", __val); }
    02511
    02512   inline __vstring
    02513   to_string(long __val)
    02514   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
    02515                           4 * sizeof(long),
    02516                           "%ld", __val); }
    02517
    02518   inline __vstring
    02519   to_string(unsigned long __val)
    02520   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
    02521                           4 * sizeof(unsigned long),
    02522                           "%lu", __val); }
    02523
    02524
    02525   inline __vstring
    02526   to_string(long long __val)
    02527   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
    02528                           4 * sizeof(long long),
    02529                           "%lld", __val); }
    02530
    02531   inline __vstring
    02532   to_string(unsigned long long __val)
    02533   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
    02534                           4 * sizeof(unsigned long long),
    02535                           "%llu", __val); }
    02536
    02537   inline __vstring
    02538   to_string(float __val)
    02539   {
    02540     const int __n = __numeric_traits<float>::__max_exponent10 + 20;
    02541     return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
    02542                           "%f", __val);
    02543   }
    02544
    02545   inline __vstring
    02546   to_string(double __val)
    02547   {
    02548     const int __n = __numeric_traits<double>::__max_exponent10 + 20;
    02549     return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
    02550                           "%f", __val);
    02551   }
    02552
    02553   inline __vstring
    02554   to_string(long double __val)
    02555   {
    02556     const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
    02557     return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
    02558                           "%Lf", __val);
    02559   }
    02560
    02561 #ifdef _GLIBCXX_USE_WCHAR_T
    02562   inline int
    02563   stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
    02564   { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
    02565                     __idx, __base); }
    02566
    02567   inline long
    02568   stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
    02569   { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
    02570                  __idx, __base); }
    02571
    02572   inline unsigned long
    02573   stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
    02574   { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
    02575                  __idx, __base); }
    02576
    02577   inline long long
    02578   stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
    02579   { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
    02580                  __idx, __base); }
    02581
    02582   inline unsigned long long
    02583   stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
    02584   { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
    02585                  __idx, __base); }
    02586
    02587   // NB: wcstof vs wcstod.
    02588   inline float
    02589   stof(const __wvstring& __str, std::size_t* __idx = 0)
    02590   { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
    02591
    02592   inline double
    02593   stod(const __wvstring& __str, std::size_t* __idx = 0)
    02594   { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
    02595
    02596   inline long double
    02597   stold(const __wvstring& __str, std::size_t* __idx = 0)
    02598   { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
    02599
    02600 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
    02601   // DR 1261.
    02602   inline __wvstring
    02603   to_wstring(int __val)
    02604   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
    02605                            4 * sizeof(int),
    02606                            L"%d", __val); }
    02607
    02608   inline __wvstring
    02609   to_wstring(unsigned __val)
    02610   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
    02611                            4 * sizeof(unsigned),
    02612                            L"%u", __val); }
    02613
    02614   inline __wvstring
    02615   to_wstring(long __val)
    02616   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
    02617                            4 * sizeof(long),
    02618                            L"%ld", __val); }
    02619
    02620   inline __wvstring
    02621   to_wstring(unsigned long __val)
    02622   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
    02623                            4 * sizeof(unsigned long),
    02624                            L"%lu", __val); }
    02625
    02626   inline __wvstring
    02627   to_wstring(long long __val)
    02628   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
    02629                            4 * sizeof(long long),
    02630                            L"%lld", __val); }
    02631
    02632   inline __wvstring
    02633   to_wstring(unsigned long long __val)
    02634   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
    02635                            4 * sizeof(unsigned long long),
    02636                            L"%llu", __val); }
    02637
    02638   inline __wvstring
    02639   to_wstring(float __val)
    02640   {
    02641     const int __n = __numeric_traits<float>::__max_exponent10 + 20;
    02642     return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
    02643                            L"%f", __val);
    02644   }
    02645
    02646   inline __wvstring
    02647   to_wstring(double __val)
    02648   {
    02649     const int __n = __numeric_traits<double>::__max_exponent10 + 20;
    02650     return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
    02651                            L"%f", __val);
    02652   }
    02653
    02654   inline __wvstring
    02655   to_wstring(long double __val)
    02656   {
    02657     const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
    02658     return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
    02659                            L"%Lf", __val);
    02660   }
    02661 #endif
    02662 #endif
    02663
    02664 _GLIBCXX_END_NAMESPACE
    02665
    02666 #endif
    02667
    02668 #ifndef _GLIBCXX_EXPORT_TEMPLATE
    02669 # include "vstring.tcc"
    02670 #endif
    02671
    02672 #endif /* _VSTRING_H */