vstring.h

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

Generated on 11 Jan 2010 for libstdc++ by  doxygen 1.6.1