vstring.h

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

Generated on Tue Apr 21 13:13:38 2009 for libstdc++ by  doxygen 1.5.8