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