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