Home | History | Annotate | Download | only in ext
      1 // Versatile string -*- C++ -*-
      2 
      3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
      4 // Free Software Foundation, Inc.
      5 //
      6 // This file is part of the GNU ISO C++ Library.  This library is free
      7 // software; you can redistribute it and/or modify it under the
      8 // terms of the GNU General Public License as published by the
      9 // Free Software Foundation; either version 3, or (at your option)
     10 // any later version.
     11 
     12 // This library is distributed in the hope that it will be useful,
     13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 // GNU General Public License for more details.
     16 
     17 // Under Section 7 of GPL version 3, you are granted additional
     18 // permissions described in the GCC Runtime Library Exception, version
     19 // 3.1, as published by the Free Software Foundation.
     20 
     21 // You should have received a copy of the GNU General Public License and
     22 // a copy of the GCC Runtime Library Exception along with this program;
     23 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     24 // <http://www.gnu.org/licenses/>.
     25 
     26 /** @file ext/vstring.h
     27  *  This file is a GNU extension to the Standard C++ Library.
     28  */
     29 
     30 #ifndef _VSTRING_H
     31 #define _VSTRING_H 1
     32 
     33 #pragma GCC system_header
     34 
     35 #ifdef __GXX_EXPERIMENTAL_CXX0X__
     36 #include <initializer_list>
     37 #endif
     38 
     39 #include <ext/vstring_util.h>
     40 #include <ext/rc_string_base.h>
     41 #include <ext/sso_string_base.h>
     42 
     43 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
     44 {
     45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
     46 
     47   /**
     48    *  @class __versa_string vstring.h
     49    *  @brief  Template class __versa_string.
     50    *  @ingroup extensions
     51    *
     52    *  Data structure managing sequences of characters and
     53    *  character-like objects.
     54    */
     55   template<typename _CharT, typename _Traits, typename _Alloc,
     56 	   template <typename, typename, typename> class _Base>
     57     class __versa_string
     58     : private _Base<_CharT, _Traits, _Alloc>
     59     {
     60       typedef _Base<_CharT, _Traits, _Alloc>                __vstring_base;
     61       typedef typename __vstring_base::_CharT_alloc_type    _CharT_alloc_type;
     62 
     63       // Types:
     64     public:
     65       typedef _Traits					    traits_type;
     66       typedef typename _Traits::char_type		    value_type;
     67       typedef _Alloc					    allocator_type;
     68       typedef typename _CharT_alloc_type::size_type	    size_type;
     69       typedef typename _CharT_alloc_type::difference_type   difference_type;
     70       typedef value_type&               	            reference;
     71       typedef const value_type&                             const_reference;
     72       typedef typename _CharT_alloc_type::pointer	    pointer;
     73       typedef typename _CharT_alloc_type::const_pointer	    const_pointer;
     74       typedef __gnu_cxx::__normal_iterator<pointer, __versa_string>  iterator;
     75       typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
     76                                                             const_iterator;
     77       typedef std::reverse_iterator<const_iterator>	const_reverse_iterator;
     78       typedef std::reverse_iterator<iterator>		    reverse_iterator;
     79 
     80       // Data Member (public):
     81       ///  Value returned by various member functions when they fail.
     82       static const size_type	npos = static_cast<size_type>(-1);
     83 
     84     private:
     85       size_type
     86       _M_check(size_type __pos, const char* __s) const
     87       {
     88 	if (__pos > this->size())
     89 	  std::__throw_out_of_range(__N(__s));
     90 	return __pos;
     91       }
     92 
     93       void
     94       _M_check_length(size_type __n1, size_type __n2, const char* __s) const
     95       {
     96 	if (this->max_size() - (this->size() - __n1) < __n2)
     97 	  std::__throw_length_error(__N(__s));
     98       }
     99 
    100       // NB: _M_limit doesn't check for a bad __pos value.
    101       size_type
    102       _M_limit(size_type __pos, size_type __off) const
    103       {
    104 	const bool __testoff =  __off < this->size() - __pos;
    105 	return __testoff ? __off : this->size() - __pos;
    106       }
    107 
    108       // True if _Rep and source do not overlap.
    109       bool
    110       _M_disjunct(const _CharT* __s) const
    111       {
    112 	return (std::less<const _CharT*>()(__s, this->_M_data())
    113 		|| std::less<const _CharT*>()(this->_M_data()
    114 					      + this->size(), __s));
    115       }
    116 
    117       // For the internal use we have functions similar to `begin'/`end'
    118       // but they do not call _M_leak.
    119       iterator
    120       _M_ibegin() const
    121       { return iterator(this->_M_data()); }
    122 
    123       iterator
    124       _M_iend() const
    125       { return iterator(this->_M_data() + this->_M_length()); }
    126 
    127     public:
    128       // Construct/copy/destroy:
    129       // NB: We overload ctors in some cases instead of using default
    130       // arguments, per 17.4.4.4 para. 2 item 2.
    131 
    132       /**
    133        *  @brief  Default constructor creates an empty string.
    134        */
    135       __versa_string()
    136       : __vstring_base() { }
    137 
    138       /**
    139        *  @brief  Construct an empty string using allocator @a a.
    140        */
    141       explicit
    142       __versa_string(const _Alloc& __a)
    143       : __vstring_base(__a) { }
    144 
    145       // NB: per LWG issue 42, semantics different from IS:
    146       /**
    147        *  @brief  Construct string with copy of value of @a __str.
    148        *  @param  __str  Source string.
    149        */
    150       __versa_string(const __versa_string& __str)
    151       : __vstring_base(__str) { }
    152 
    153 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    154       /**
    155        *  @brief  String move constructor.
    156        *  @param  __str  Source string.
    157        *
    158        *  The newly-constructed %string contains the exact contents of
    159        *  @a __str.  The contents of @a __str are a valid, but unspecified
    160        *  string.
    161        */
    162       __versa_string(__versa_string&& __str) noexcept
    163       : __vstring_base(std::move(__str)) { }
    164 
    165       /**
    166        *  @brief  Construct string from an initializer list.
    167        *  @param  __l  std::initializer_list of characters.
    168        *  @param  __a  Allocator to use (default is default allocator).
    169        */
    170       __versa_string(std::initializer_list<_CharT> __l,
    171 		     const _Alloc& __a = _Alloc())
    172       : __vstring_base(__l.begin(), __l.end(), __a) { }
    173 #endif
    174 
    175       /**
    176        *  @brief  Construct string as copy of a substring.
    177        *  @param  __str  Source string.
    178        *  @param  __pos  Index of first character to copy from.
    179        *  @param  __n  Number of characters to copy (default remainder).
    180        */
    181       __versa_string(const __versa_string& __str, size_type __pos,
    182 		     size_type __n = npos)
    183       : __vstring_base(__str._M_data()
    184 		       + __str._M_check(__pos,
    185 					"__versa_string::__versa_string"),
    186 		       __str._M_data() + __str._M_limit(__pos, __n)
    187 		       + __pos, _Alloc()) { }
    188 
    189       /**
    190        *  @brief  Construct string as copy of a substring.
    191        *  @param  __str  Source string.
    192        *  @param  __pos  Index of first character to copy from.
    193        *  @param  __n  Number of characters to copy.
    194        *  @param  __a  Allocator to use.
    195        */
    196       __versa_string(const __versa_string& __str, size_type __pos,
    197 		     size_type __n, const _Alloc& __a)
    198       : __vstring_base(__str._M_data()
    199 		       + __str._M_check(__pos,
    200 					"__versa_string::__versa_string"),
    201 		       __str._M_data() + __str._M_limit(__pos, __n)
    202 		       + __pos, __a) { }
    203 
    204       /**
    205        *  @brief  Construct string initialized by a character array.
    206        *  @param  __s  Source character array.
    207        *  @param  __n  Number of characters to copy.
    208        *  @param  __a  Allocator to use (default is default allocator).
    209        *
    210        *  NB: @a __s must have at least @a __n characters, '\\0' has no special
    211        *  meaning.
    212        */
    213       __versa_string(const _CharT* __s, size_type __n,
    214 		     const _Alloc& __a = _Alloc())
    215       : __vstring_base(__s, __s + __n, __a) { }
    216 
    217       /**
    218        *  @brief  Construct string as copy of a C string.
    219        *  @param  __s  Source C string.
    220        *  @param  __a  Allocator to use (default is default allocator).
    221        */
    222       __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc())
    223       : __vstring_base(__s, __s ? __s + traits_type::length(__s) :
    224 		       __s + npos, __a) { }
    225 
    226       /**
    227        *  @brief  Construct string as multiple characters.
    228        *  @param  __n  Number of characters.
    229        *  @param  __c  Character to use.
    230        *  @param  __a  Allocator to use (default is default allocator).
    231        */
    232       __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
    233       : __vstring_base(__n, __c, __a) { }
    234 
    235       /**
    236        *  @brief  Construct string as copy of a range.
    237        *  @param  __beg  Start of range.
    238        *  @param  __end  End of range.
    239        *  @param  __a  Allocator to use (default is default allocator).
    240        */
    241       template<class _InputIterator>
    242         __versa_string(_InputIterator __beg, _InputIterator __end,
    243 		       const _Alloc& __a = _Alloc())
    244 	: __vstring_base(__beg, __end, __a) { }
    245 
    246       /**
    247        *  @brief  Destroy the string instance.
    248        */
    249       ~__versa_string() _GLIBCXX_NOEXCEPT { }
    250 
    251       /**
    252        *  @brief  Assign the value of @a str to this string.
    253        *  @param  __str  Source string.
    254        */
    255       __versa_string&
    256       operator=(const __versa_string& __str)
    257       { return this->assign(__str); }
    258 
    259 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    260       /**
    261        *  @brief  String move assignment operator.
    262        *  @param  __str  Source string.
    263        *
    264        *  The contents of @a __str are moved into this string (without
    265        *  copying).  @a __str is a valid, but unspecified string.
    266        */
    267       __versa_string&
    268       operator=(__versa_string&& __str)
    269       {
    270 	// NB: DR 1204.
    271 	this->swap(__str);
    272 	return *this;
    273       }
    274 
    275       /**
    276        *  @brief  Set value to string constructed from initializer list.
    277        *  @param  __l  std::initializer_list.
    278        */
    279       __versa_string&
    280       operator=(std::initializer_list<_CharT> __l)
    281       {
    282 	this->assign(__l.begin(), __l.end());
    283 	return *this;
    284       }
    285 #endif
    286 
    287       /**
    288        *  @brief  Copy contents of @a __s into this string.
    289        *  @param  __s  Source null-terminated string.
    290        */
    291       __versa_string&
    292       operator=(const _CharT* __s)
    293       { return this->assign(__s); }
    294 
    295       /**
    296        *  @brief  Set value to string of length 1.
    297        *  @param  __c  Source character.
    298        *
    299        *  Assigning to a character makes this string length 1 and
    300        *  (*this)[0] == @a __c.
    301        */
    302       __versa_string&
    303       operator=(_CharT __c)
    304       {
    305 	this->assign(1, __c);
    306 	return *this;
    307       }
    308 
    309       // Iterators:
    310       /**
    311        *  Returns a read/write iterator that points to the first character in
    312        *  the %string.  Unshares the string.
    313        */
    314       iterator
    315       begin() _GLIBCXX_NOEXCEPT
    316       {
    317 	this->_M_leak();
    318 	return iterator(this->_M_data());
    319       }
    320 
    321       /**
    322        *  Returns a read-only (constant) iterator that points to the first
    323        *  character in the %string.
    324        */
    325       const_iterator
    326       begin() const _GLIBCXX_NOEXCEPT
    327       { return const_iterator(this->_M_data()); }
    328 
    329       /**
    330        *  Returns a read/write iterator that points one past the last
    331        *  character in the %string.  Unshares the string.
    332        */
    333       iterator
    334       end() _GLIBCXX_NOEXCEPT
    335       {
    336 	this->_M_leak();
    337 	return iterator(this->_M_data() + this->size());
    338       }
    339 
    340       /**
    341        *  Returns a read-only (constant) iterator that points one past the
    342        *  last character in the %string.
    343        */
    344       const_iterator
    345       end() const _GLIBCXX_NOEXCEPT
    346       { return const_iterator(this->_M_data() + this->size()); }
    347 
    348       /**
    349        *  Returns a read/write reverse iterator that points to the last
    350        *  character in the %string.  Iteration is done in reverse element
    351        *  order.  Unshares the string.
    352        */
    353       reverse_iterator
    354       rbegin() _GLIBCXX_NOEXCEPT
    355       { return reverse_iterator(this->end()); }
    356 
    357       /**
    358        *  Returns a read-only (constant) reverse iterator that points
    359        *  to the last character in the %string.  Iteration is done in
    360        *  reverse element order.
    361        */
    362       const_reverse_iterator
    363       rbegin() const _GLIBCXX_NOEXCEPT
    364       { return const_reverse_iterator(this->end()); }
    365 
    366       /**
    367        *  Returns a read/write reverse iterator that points to one before the
    368        *  first character in the %string.  Iteration is done in reverse
    369        *  element order.  Unshares the string.
    370        */
    371       reverse_iterator
    372       rend() _GLIBCXX_NOEXCEPT
    373       { return reverse_iterator(this->begin()); }
    374 
    375       /**
    376        *  Returns a read-only (constant) reverse iterator that points
    377        *  to one before the first character in the %string.  Iteration
    378        *  is done in reverse element order.
    379        */
    380       const_reverse_iterator
    381       rend() const _GLIBCXX_NOEXCEPT
    382       { return const_reverse_iterator(this->begin()); }
    383 
    384 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    385       /**
    386        *  Returns a read-only (constant) iterator that points to the first
    387        *  character in the %string.
    388        */
    389       const_iterator
    390       cbegin() const noexcept
    391       { return const_iterator(this->_M_data()); }
    392 
    393       /**
    394        *  Returns a read-only (constant) iterator that points one past the
    395        *  last character in the %string.
    396        */
    397       const_iterator
    398       cend() const noexcept
    399       { return const_iterator(this->_M_data() + this->size()); }
    400 
    401       /**
    402        *  Returns a read-only (constant) reverse iterator that points
    403        *  to the last character in the %string.  Iteration is done in
    404        *  reverse element order.
    405        */
    406       const_reverse_iterator
    407       crbegin() const noexcept
    408       { return const_reverse_iterator(this->end()); }
    409 
    410       /**
    411        *  Returns a read-only (constant) reverse iterator that points
    412        *  to one before the first character in the %string.  Iteration
    413        *  is done in reverse element order.
    414        */
    415       const_reverse_iterator
    416       crend() const noexcept
    417       { return const_reverse_iterator(this->begin()); }
    418 #endif
    419 
    420     public:
    421       // Capacity:
    422       ///  Returns the number of characters in the string, not including any
    423       ///  null-termination.
    424       size_type
    425       size() const _GLIBCXX_NOEXCEPT
    426       { return this->_M_length(); }
    427 
    428       ///  Returns the number of characters in the string, not including any
    429       ///  null-termination.
    430       size_type
    431       length() const _GLIBCXX_NOEXCEPT
    432       { return this->_M_length(); }
    433 
    434       /// Returns the size() of the largest possible %string.
    435       size_type
    436       max_size() const _GLIBCXX_NOEXCEPT
    437       { return this->_M_max_size(); }
    438 
    439       /**
    440        *  @brief  Resizes the %string to the specified number of characters.
    441        *  @param  __n  Number of characters the %string should contain.
    442        *  @param  __c  Character to fill any new elements.
    443        *
    444        *  This function will %resize the %string to the specified
    445        *  number of characters.  If the number is smaller than the
    446        *  %string's current size the %string is truncated, otherwise
    447        *  the %string is extended and new elements are set to @a __c.
    448        */
    449       void
    450       resize(size_type __n, _CharT __c);
    451 
    452       /**
    453        *  @brief  Resizes the %string to the specified number of characters.
    454        *  @param  __n  Number of characters the %string should contain.
    455        *
    456        *  This function will resize the %string to the specified
    457        *  length.  If the new size is smaller than the %string's
    458        *  current size the %string is truncated, otherwise the %string
    459        *  is extended and new characters are default-constructed.  For
    460        *  basic types such as char, this means setting them to 0.
    461        */
    462       void
    463       resize(size_type __n)
    464       { this->resize(__n, _CharT()); }
    465 
    466 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    467       /// A non-binding request to reduce capacity() to size().
    468       void
    469       shrink_to_fit()
    470       {
    471 	if (capacity() > size())
    472 	  {
    473 	    __try
    474 	      { this->reserve(0); }
    475 	    __catch(...)
    476 	      { }
    477 	  }
    478       }
    479 #endif
    480 
    481       /**
    482        *  Returns the total number of characters that the %string can
    483        *  hold before needing to allocate more memory.
    484        */
    485       size_type
    486       capacity() const _GLIBCXX_NOEXCEPT
    487       { return this->_M_capacity(); }
    488 
    489       /**
    490        *  @brief  Attempt to preallocate enough memory for specified number of
    491        *          characters.
    492        *  @param  __res_arg  Number of characters required.
    493        *  @throw  std::length_error  If @a __res_arg exceeds @c max_size().
    494        *
    495        *  This function attempts to reserve enough memory for the
    496        *  %string to hold the specified number of characters.  If the
    497        *  number requested is more than max_size(), length_error is
    498        *  thrown.
    499        *
    500        *  The advantage of this function is that if optimal code is a
    501        *  necessity and the user can determine the string length that
    502        *  will be required, the user can reserve the memory in
    503        *  %advance, and thus prevent a possible reallocation of memory
    504        *  and copying of %string data.
    505        */
    506       void
    507       reserve(size_type __res_arg = 0)
    508       { this->_M_reserve(__res_arg); }
    509 
    510       /**
    511        *  Erases the string, making it empty.
    512        */
    513       void
    514       clear() _GLIBCXX_NOEXCEPT
    515       { this->_M_clear(); }
    516 
    517       /**
    518        *  Returns true if the %string is empty.  Equivalent to
    519        *  <code>*this == ""</code>.
    520        */
    521       bool
    522       empty() const _GLIBCXX_NOEXCEPT
    523       { return this->size() == 0; }
    524 
    525       // Element access:
    526       /**
    527        *  @brief  Subscript access to the data contained in the %string.
    528        *  @param  __pos  The index of the character to access.
    529        *  @return  Read-only (constant) reference to the character.
    530        *
    531        *  This operator allows for easy, array-style, data access.
    532        *  Note that data access with this operator is unchecked and
    533        *  out_of_range lookups are not defined. (For checked lookups
    534        *  see at().)
    535        */
    536       const_reference
    537       operator[] (size_type __pos) const
    538       {
    539 	_GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
    540 	return this->_M_data()[__pos];
    541       }
    542 
    543       /**
    544        *  @brief  Subscript access to the data contained in the %string.
    545        *  @param  __pos  The index of the character to access.
    546        *  @return  Read/write reference to the character.
    547        *
    548        *  This operator allows for easy, array-style, data access.
    549        *  Note that data access with this operator is unchecked and
    550        *  out_of_range lookups are not defined. (For checked lookups
    551        *  see at().)  Unshares the string.
    552        */
    553       reference
    554       operator[](size_type __pos)
    555       {
    556         // allow pos == size() as v3 extension:
    557 	_GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
    558         // but be strict in pedantic mode:
    559 	_GLIBCXX_DEBUG_PEDASSERT(__pos < this->size());
    560 	this->_M_leak();
    561 	return this->_M_data()[__pos];
    562       }
    563 
    564       /**
    565        *  @brief  Provides access to the data contained in the %string.
    566        *  @param __n The index of the character to access.
    567        *  @return  Read-only (const) reference to the character.
    568        *  @throw  std::out_of_range  If @a __n is an invalid index.
    569        *
    570        *  This function provides for safer data access.  The parameter
    571        *  is first checked that it is in the range of the string.  The
    572        *  function throws out_of_range if the check fails.
    573        */
    574       const_reference
    575       at(size_type __n) const
    576       {
    577 	if (__n >= this->size())
    578 	  std::__throw_out_of_range(__N("__versa_string::at"));
    579 	return this->_M_data()[__n];
    580       }
    581 
    582       /**
    583        *  @brief  Provides access to the data contained in the %string.
    584        *  @param __n The index of the character to access.
    585        *  @return  Read/write reference to the character.
    586        *  @throw  std::out_of_range  If @a __n is an invalid index.
    587        *
    588        *  This function provides for safer data access.  The parameter
    589        *  is first checked that it is in the range of the string.  The
    590        *  function throws out_of_range if the check fails.  Success
    591        *  results in unsharing the string.
    592        */
    593       reference
    594       at(size_type __n)
    595       {
    596 	if (__n >= this->size())
    597 	  std::__throw_out_of_range(__N("__versa_string::at"));
    598 	this->_M_leak();
    599 	return this->_M_data()[__n];
    600       }
    601 
    602 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    603       /**
    604        *  Returns a read/write reference to the data at the first
    605        *  element of the %string.
    606        */
    607       reference
    608       front()
    609       { return operator[](0); }
    610 
    611       /**
    612        *  Returns a read-only (constant) reference to the data at the first
    613        *  element of the %string.
    614        */
    615       const_reference
    616       front() const
    617       { return operator[](0); }
    618 
    619       /**
    620        *  Returns a read/write reference to the data at the last
    621        *  element of the %string.
    622        */
    623       reference
    624       back()
    625       { return operator[](this->size() - 1); }
    626 
    627       /**
    628        *  Returns a read-only (constant) reference to the data at the
    629        *  last element of the %string.
    630        */
    631       const_reference
    632       back() const
    633       { return operator[](this->size() - 1); }
    634 #endif
    635 
    636       // Modifiers:
    637       /**
    638        *  @brief  Append a string to this string.
    639        *  @param __str  The string to append.
    640        *  @return  Reference to this string.
    641        */
    642       __versa_string&
    643       operator+=(const __versa_string& __str)
    644       { return this->append(__str); }
    645 
    646       /**
    647        *  @brief  Append a C string.
    648        *  @param __s  The C string to append.
    649        *  @return  Reference to this string.
    650        */
    651       __versa_string&
    652       operator+=(const _CharT* __s)
    653       { return this->append(__s); }
    654 
    655       /**
    656        *  @brief  Append a character.
    657        *  @param __c  The character to append.
    658        *  @return  Reference to this string.
    659        */
    660       __versa_string&
    661       operator+=(_CharT __c)
    662       {
    663 	this->push_back(__c);
    664 	return *this;
    665       }
    666 
    667 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    668       /**
    669        *  @brief  Append an initializer_list of characters.
    670        *  @param __l  The initializer_list of characters to be appended.
    671        *  @return  Reference to this string.
    672        */
    673       __versa_string&
    674       operator+=(std::initializer_list<_CharT> __l)
    675       { return this->append(__l.begin(), __l.end()); }
    676 #endif // __GXX_EXPERIMENTAL_CXX0X__
    677 
    678       /**
    679        *  @brief  Append a string to this string.
    680        *  @param __str  The string to append.
    681        *  @return  Reference to this string.
    682        */
    683       __versa_string&
    684       append(const __versa_string& __str)
    685       { return _M_append(__str._M_data(), __str.size()); }
    686 
    687       /**
    688        *  @brief  Append a substring.
    689        *  @param __str  The string to append.
    690        *  @param __pos  Index of the first character of str to append.
    691        *  @param __n  The number of characters to append.
    692        *  @return  Reference to this string.
    693        *  @throw  std::out_of_range if @a pos is not a valid index.
    694        *
    695        *  This function appends @a __n characters from @a __str
    696        *  starting at @a __pos to this string.  If @a __n is is larger
    697        *  than the number of available characters in @a __str, the
    698        *  remainder of @a __str is appended.
    699        */
    700       __versa_string&
    701       append(const __versa_string& __str, size_type __pos, size_type __n)
    702       { return _M_append(__str._M_data()
    703 			 + __str._M_check(__pos, "__versa_string::append"),
    704 			 __str._M_limit(__pos, __n)); }
    705 
    706       /**
    707        *  @brief  Append a C substring.
    708        *  @param __s  The C string to append.
    709        *  @param __n  The number of characters to append.
    710        *  @return  Reference to this string.
    711        */
    712       __versa_string&
    713       append(const _CharT* __s, size_type __n)
    714       {
    715 	__glibcxx_requires_string_len(__s, __n);
    716 	_M_check_length(size_type(0), __n, "__versa_string::append");
    717 	return _M_append(__s, __n);
    718       }
    719 
    720       /**
    721        *  @brief  Append a C string.
    722        *  @param __s  The C string to append.
    723        *  @return  Reference to this string.
    724        */
    725       __versa_string&
    726       append(const _CharT* __s)
    727       {
    728 	__glibcxx_requires_string(__s);
    729 	const size_type __n = traits_type::length(__s);
    730 	_M_check_length(size_type(0), __n, "__versa_string::append");
    731 	return _M_append(__s, __n);
    732       }
    733 
    734       /**
    735        *  @brief  Append multiple characters.
    736        *  @param __n  The number of characters to append.
    737        *  @param __c  The character to use.
    738        *  @return  Reference to this string.
    739        *
    740        *  Appends n copies of c to this string.
    741        */
    742       __versa_string&
    743       append(size_type __n, _CharT __c)
    744       { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
    745 
    746 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    747       /**
    748        *  @brief  Append an initializer_list of characters.
    749        *  @param __l  The initializer_list of characters to append.
    750        *  @return  Reference to this string.
    751        */
    752       __versa_string&
    753       append(std::initializer_list<_CharT> __l)
    754       { return this->append(__l.begin(), __l.end()); }
    755 #endif // __GXX_EXPERIMENTAL_CXX0X__
    756 
    757       /**
    758        *  @brief  Append a range of characters.
    759        *  @param __first  Iterator referencing the first character to append.
    760        *  @param __last  Iterator marking the end of the range.
    761        *  @return  Reference to this string.
    762        *
    763        *  Appends characters in the range [first,last) to this string.
    764        */
    765       template<class _InputIterator>
    766         __versa_string&
    767         append(_InputIterator __first, _InputIterator __last)
    768         { return this->replace(_M_iend(), _M_iend(), __first, __last); }
    769 
    770       /**
    771        *  @brief  Append a single character.
    772        *  @param __c  Character to append.
    773        */
    774       void
    775       push_back(_CharT __c)
    776       {
    777 	const size_type __size = this->size();
    778 	if (__size + 1 > this->capacity() || this->_M_is_shared())
    779 	  this->_M_mutate(__size, size_type(0), 0, size_type(1));
    780 	traits_type::assign(this->_M_data()[__size], __c);
    781 	this->_M_set_length(__size + 1);
    782       }
    783 
    784       /**
    785        *  @brief  Set value to contents of another string.
    786        *  @param  __str  Source string to use.
    787        *  @return  Reference to this string.
    788        */
    789       __versa_string&
    790       assign(const __versa_string& __str)
    791       {
    792 	this->_M_assign(__str);
    793 	return *this;
    794       }
    795 
    796 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    797       /**
    798        *  @brief  Set value to contents of another string.
    799        *  @param  __str  Source string to use.
    800        *  @return  Reference to this string.
    801        *
    802        *  This function sets this string to the exact contents of @a __str.
    803        *  @a __str is a valid, but unspecified string.
    804        */
    805       __versa_string&
    806       assign(__versa_string&& __str)
    807       {
    808 	this->swap(__str);
    809 	return *this;
    810       }
    811 #endif // __GXX_EXPERIMENTAL_CXX0X__
    812 
    813       /**
    814        *  @brief  Set value to a substring of a string.
    815        *  @param __str  The string to use.
    816        *  @param __pos  Index of the first character of str.
    817        *  @param __n  Number of characters to use.
    818        *  @return  Reference to this string.
    819        *  @throw  std::out_of_range if @a __pos is not a valid index.
    820        *
    821        *  This function sets this string to the substring of @a __str
    822        *  consisting of @a __n characters at @a __pos.  If @a __n is
    823        *  is larger than the number of available characters in @a
    824        *  __str, the remainder of @a __str is used.
    825        */
    826       __versa_string&
    827       assign(const __versa_string& __str, size_type __pos, size_type __n)
    828       { return _M_replace(size_type(0), this->size(), __str._M_data()
    829 			  + __str._M_check(__pos, "__versa_string::assign"),
    830 			  __str._M_limit(__pos, __n)); }
    831 
    832       /**
    833        *  @brief  Set value to a C substring.
    834        *  @param __s  The C string to use.
    835        *  @param __n  Number of characters to use.
    836        *  @return  Reference to this string.
    837        *
    838        *  This function sets the value of this string to the first @a
    839        *  __n characters of @a __s.  If @a __n is is larger than the
    840        *  number of available characters in @a __s, the remainder of
    841        *  @a __s is used.
    842        */
    843       __versa_string&
    844       assign(const _CharT* __s, size_type __n)
    845       {
    846 	__glibcxx_requires_string_len(__s, __n);
    847 	return _M_replace(size_type(0), this->size(), __s, __n);
    848       }
    849 
    850       /**
    851        *  @brief  Set value to contents of a C string.
    852        *  @param __s  The C string to use.
    853        *  @return  Reference to this string.
    854        *
    855        *  This function sets the value of this string to the value of
    856        *  @a __s.  The data is copied, so there is no dependence on @a
    857        *  __s once the function returns.
    858        */
    859       __versa_string&
    860       assign(const _CharT* __s)
    861       {
    862 	__glibcxx_requires_string(__s);
    863 	return _M_replace(size_type(0), this->size(), __s,
    864 			  traits_type::length(__s));
    865       }
    866 
    867       /**
    868        *  @brief  Set value to multiple characters.
    869        *  @param __n  Length of the resulting string.
    870        *  @param __c  The character to use.
    871        *  @return  Reference to this string.
    872        *
    873        *  This function sets the value of this string to @a __n copies of
    874        *  character @a __c.
    875        */
    876       __versa_string&
    877       assign(size_type __n, _CharT __c)
    878       { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
    879 
    880       /**
    881        *  @brief  Set value to a range of characters.
    882        *  @param __first  Iterator referencing the first character to append.
    883        *  @param __last  Iterator marking the end of the range.
    884        *  @return  Reference to this string.
    885        *
    886        *  Sets value of string to characters in the range
    887        *  [first,last).
    888       */
    889       template<class _InputIterator>
    890         __versa_string&
    891         assign(_InputIterator __first, _InputIterator __last)
    892         { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
    893 
    894 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    895       /**
    896        *  @brief  Set value to an initializer_list of characters.
    897        *  @param __l  The initializer_list of characters to assign.
    898        *  @return  Reference to this string.
    899        */
    900       __versa_string&
    901       assign(std::initializer_list<_CharT> __l)
    902       { return this->assign(__l.begin(), __l.end()); }
    903 #endif // __GXX_EXPERIMENTAL_CXX0X__
    904 
    905       /**
    906        *  @brief  Insert multiple characters.
    907        *  @param __p  Iterator referencing location in string to insert at.
    908        *  @param __n  Number of characters to insert
    909        *  @param __c  The character to insert.
    910        *  @throw  std::length_error  If new length exceeds @c max_size().
    911        *
    912        *  Inserts @a __n copies of character @a __c starting at the
    913        *  position referenced by iterator @a __p.  If adding
    914        *  characters causes the length to exceed max_size(),
    915        *  length_error is thrown.  The value of the string doesn't
    916        *  change if an error is thrown.
    917       */
    918       void
    919       insert(iterator __p, size_type __n, _CharT __c)
    920       {	this->replace(__p, __p, __n, __c);  }
    921 
    922       /**
    923        *  @brief  Insert a range of characters.
    924        *  @param __p  Iterator referencing location in string to insert at.
    925        *  @param __beg  Start of range.
    926        *  @param __end  End of range.
    927        *  @throw  std::length_error  If new length exceeds @c max_size().
    928        *
    929        *  Inserts characters in range [beg,end).  If adding characters
    930        *  causes the length to exceed max_size(), length_error is
    931        *  thrown.  The value of the string doesn't change if an error
    932        *  is thrown.
    933       */
    934       template<class _InputIterator>
    935         void
    936         insert(iterator __p, _InputIterator __beg, _InputIterator __end)
    937         { this->replace(__p, __p, __beg, __end); }
    938 
    939 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    940       /**
    941        *  @brief  Insert an initializer_list of characters.
    942        *  @param __p  Iterator referencing location in string to insert at.
    943        *  @param __l  The initializer_list of characters to insert.
    944        *  @throw  std::length_error  If new length exceeds @c max_size().
    945        */
    946       void
    947       insert(iterator __p, std::initializer_list<_CharT> __l)
    948       { this->insert(__p, __l.begin(), __l.end()); }
    949 #endif // __GXX_EXPERIMENTAL_CXX0X__
    950 
    951       /**
    952        *  @brief  Insert value of a string.
    953        *  @param __pos1  Iterator referencing location in string to insert at.
    954        *  @param __str  The string to insert.
    955        *  @return  Reference to this string.
    956        *  @throw  std::length_error  If new length exceeds @c max_size().
    957        *
    958        *  Inserts value of @a __str starting at @a __pos1.  If adding
    959        *  characters causes the length to exceed max_size(),
    960        *  length_error is thrown.  The value of the string doesn't
    961        *  change if an error is thrown.
    962       */
    963       __versa_string&
    964       insert(size_type __pos1, const __versa_string& __str)
    965       { return this->replace(__pos1, size_type(0),
    966 			     __str._M_data(), __str.size()); }
    967 
    968       /**
    969        *  @brief  Insert a substring.
    970        *  @param __pos1  Iterator referencing location in string to insert at.
    971        *  @param __str  The string to insert.
    972        *  @param __pos2  Start of characters in str to insert.
    973        *  @param __n  Number of characters to insert.
    974        *  @return  Reference to this string.
    975        *  @throw  std::length_error  If new length exceeds @c max_size().
    976        *  @throw  std::out_of_range  If @a __pos1 > size() or
    977        *  @a __pos2 > @a __str.size().
    978        *
    979        *  Starting at @a __pos1, insert @a __n character of @a __str
    980        *  beginning with @a __pos2.  If adding characters causes the
    981        *  length to exceed max_size(), length_error is thrown.  If @a
    982        *  __pos1 is beyond the end of this string or @a __pos2 is
    983        *  beyond the end of @a __str, out_of_range is thrown.  The
    984        *  value of the string doesn't change if an error is thrown.
    985       */
    986       __versa_string&
    987       insert(size_type __pos1, const __versa_string& __str,
    988 	     size_type __pos2, size_type __n)
    989       { return this->replace(__pos1, size_type(0), __str._M_data()
    990 			     + __str._M_check(__pos2, "__versa_string::insert"),
    991 			     __str._M_limit(__pos2, __n)); }
    992 
    993       /**
    994        *  @brief  Insert a C substring.
    995        *  @param __pos  Iterator referencing location in string to insert at.
    996        *  @param __s  The C string to insert.
    997        *  @param __n  The number of characters to insert.
    998        *  @return  Reference to this string.
    999        *  @throw  std::length_error  If new length exceeds @c max_size().
   1000        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
   1001        *  string.
   1002        *
   1003        *  Inserts the first @a __n characters of @a __s starting at @a
   1004        *  __pos.  If adding characters causes the length to exceed
   1005        *  max_size(), length_error is thrown.  If @a __pos is beyond
   1006        *  end(), out_of_range is thrown.  The value of the string
   1007        *  doesn't change if an error is thrown.
   1008       */
   1009       __versa_string&
   1010       insert(size_type __pos, const _CharT* __s, size_type __n)
   1011       { return this->replace(__pos, size_type(0), __s, __n); }
   1012 
   1013       /**
   1014        *  @brief  Insert a C string.
   1015        *  @param __pos  Iterator referencing location in string to insert at.
   1016        *  @param __s  The C string to insert.
   1017        *  @return  Reference to this string.
   1018        *  @throw  std::length_error  If new length exceeds @c max_size().
   1019        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
   1020        *  string.
   1021        *
   1022        *  Inserts the first @a __n characters of @a __s starting at @a
   1023        *  __pos.  If adding characters causes the length to exceed
   1024        *  max_size(), length_error is thrown.  If @a __pos is beyond
   1025        *  end(), out_of_range is thrown.  The value of the string
   1026        *  doesn't change if an error is thrown.
   1027       */
   1028       __versa_string&
   1029       insert(size_type __pos, const _CharT* __s)
   1030       {
   1031 	__glibcxx_requires_string(__s);
   1032 	return this->replace(__pos, size_type(0), __s,
   1033 			     traits_type::length(__s));
   1034       }
   1035 
   1036       /**
   1037        *  @brief  Insert multiple characters.
   1038        *  @param __pos  Index in string to insert at.
   1039        *  @param __n  Number of characters to insert
   1040        *  @param __c  The character to insert.
   1041        *  @return  Reference to this string.
   1042        *  @throw  std::length_error  If new length exceeds @c max_size().
   1043        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
   1044        *  string.
   1045        *
   1046        *  Inserts @a __n copies of character @a __c starting at index
   1047        *  @a __pos.  If adding characters causes the length to exceed
   1048        *  max_size(), length_error is thrown.  If @a __pos > length(),
   1049        *  out_of_range is thrown.  The value of the string doesn't
   1050        *  change if an error is thrown.
   1051       */
   1052       __versa_string&
   1053       insert(size_type __pos, size_type __n, _CharT __c)
   1054       { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
   1055 			      size_type(0), __n, __c); }
   1056 
   1057       /**
   1058        *  @brief  Insert one character.
   1059        *  @param __p  Iterator referencing position in string to insert at.
   1060        *  @param __c  The character to insert.
   1061        *  @return  Iterator referencing newly inserted char.
   1062        *  @throw  std::length_error  If new length exceeds @c max_size().
   1063        *
   1064        *  Inserts character @a __c at position referenced by @a __p.
   1065        *  If adding character causes the length to exceed max_size(),
   1066        *  length_error is thrown.  If @a __p is beyond end of string,
   1067        *  out_of_range is thrown.  The value of the string doesn't
   1068        *  change if an error is thrown.
   1069       */
   1070       iterator
   1071       insert(iterator __p, _CharT __c)
   1072       {
   1073 	_GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
   1074 	const size_type __pos = __p - _M_ibegin();
   1075 	_M_replace_aux(__pos, size_type(0), size_type(1), __c);
   1076 	this->_M_set_leaked();
   1077 	return iterator(this->_M_data() + __pos);
   1078       }
   1079 
   1080       /**
   1081        *  @brief  Remove characters.
   1082        *  @param __pos  Index of first character to remove (default 0).
   1083        *  @param __n  Number of characters to remove (default remainder).
   1084        *  @return  Reference to this string.
   1085        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
   1086        *  string.
   1087        *
   1088        *  Removes @a __n characters from this string starting at @a
   1089        *  __pos.  The length of the string is reduced by @a __n.  If
   1090        *  there are < @a __n characters to remove, the remainder of
   1091        *  the string is truncated.  If @a __p is beyond end of string,
   1092        *  out_of_range is thrown.  The value of the string doesn't
   1093        *  change if an error is thrown.
   1094       */
   1095       __versa_string&
   1096       erase(size_type __pos = 0, size_type __n = npos)
   1097       {
   1098 	this->_M_erase(_M_check(__pos, "__versa_string::erase"),
   1099 		       _M_limit(__pos, __n));
   1100 	return *this;
   1101       }
   1102 
   1103       /**
   1104        *  @brief  Remove one character.
   1105        *  @param __position  Iterator referencing the character to remove.
   1106        *  @return  iterator referencing same location after removal.
   1107        *
   1108        *  Removes the character at @a __position from this string. The
   1109        *  value of the string doesn't change if an error is thrown.
   1110       */
   1111       iterator
   1112       erase(iterator __position)
   1113       {
   1114 	_GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
   1115 				 && __position < _M_iend());
   1116 	const size_type __pos = __position - _M_ibegin();
   1117 	this->_M_erase(__pos, size_type(1));
   1118 	this->_M_set_leaked();
   1119 	return iterator(this->_M_data() + __pos);
   1120       }
   1121 
   1122       /**
   1123        *  @brief  Remove a range of characters.
   1124        *  @param __first  Iterator referencing the first character to remove.
   1125        *  @param __last  Iterator referencing the end of the range.
   1126        *  @return  Iterator referencing location of first after removal.
   1127        *
   1128        *  Removes the characters in the range [first,last) from this
   1129        *  string.  The value of the string doesn't change if an error
   1130        *  is thrown.
   1131       */
   1132       iterator
   1133       erase(iterator __first, iterator __last)
   1134       {
   1135 	_GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
   1136 				 && __last <= _M_iend());
   1137         const size_type __pos = __first - _M_ibegin();
   1138 	this->_M_erase(__pos, __last - __first);
   1139 	this->_M_set_leaked();
   1140 	return iterator(this->_M_data() + __pos);
   1141       }
   1142 
   1143 #ifdef __GXX_EXPERIMENTAL_CXX0X__
   1144       /**
   1145        *  @brief  Remove the last character.
   1146        *
   1147        *  The string must be non-empty.
   1148        */
   1149       void
   1150       pop_back()
   1151       { this->_M_erase(size()-1, 1); }
   1152 #endif // __GXX_EXPERIMENTAL_CXX0X__
   1153 
   1154       /**
   1155        *  @brief  Replace characters with value from another string.
   1156        *  @param __pos  Index of first character to replace.
   1157        *  @param __n  Number of characters to be replaced.
   1158        *  @param __str  String to insert.
   1159        *  @return  Reference to this string.
   1160        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
   1161        *  string.
   1162        *  @throw  std::length_error  If new length exceeds @c max_size().
   1163        *
   1164        *  Removes the characters in the range [pos,pos+n) from this
   1165        *  string.  In place, the value of @a __str is inserted.  If @a
   1166        *  __pos is beyond end of string, out_of_range is thrown.  If
   1167        *  the length of the result exceeds max_size(), length_error is
   1168        *  thrown.  The value of the string doesn't change if an error
   1169        *  is thrown.
   1170       */
   1171       __versa_string&
   1172       replace(size_type __pos, size_type __n, const __versa_string& __str)
   1173       { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
   1174 
   1175       /**
   1176        *  @brief  Replace characters with value from another string.
   1177        *  @param __pos1  Index of first character to replace.
   1178        *  @param __n1  Number of characters to be replaced.
   1179        *  @param __str  String to insert.
   1180        *  @param __pos2  Index of first character of str to use.
   1181        *  @param __n2  Number of characters from str to use.
   1182        *  @return  Reference to this string.
   1183        *  @throw  std::out_of_range  If @a __pos1 > size() or @a __pos2 >
   1184        *  str.size().
   1185        *  @throw  std::length_error  If new length exceeds @c max_size().
   1186        *
   1187        *  Removes the characters in the range [pos1,pos1 + n) from
   1188        *  this string.  In place, the value of @a __str is inserted.
   1189        *  If @a __pos is beyond end of string, out_of_range is thrown.
   1190        *  If the length of the result exceeds max_size(), length_error
   1191        *  is thrown.  The value of the string doesn't change if an
   1192        *  error is thrown.
   1193       */
   1194       __versa_string&
   1195       replace(size_type __pos1, size_type __n1, const __versa_string& __str,
   1196 	      size_type __pos2, size_type __n2)
   1197       {
   1198 	return this->replace(__pos1, __n1, __str._M_data()
   1199 			     + __str._M_check(__pos2,
   1200 					      "__versa_string::replace"),
   1201 			     __str._M_limit(__pos2, __n2));
   1202       }
   1203 
   1204       /**
   1205        *  @brief  Replace characters with value of a C substring.
   1206        *  @param __pos  Index of first character to replace.
   1207        *  @param __n1  Number of characters to be replaced.
   1208        *  @param __s  C string to insert.
   1209        *  @param __n2  Number of characters from @a __s to use.
   1210        *  @return  Reference to this string.
   1211        *  @throw  std::out_of_range  If @a __pos1 > size().
   1212        *  @throw  std::length_error  If new length exceeds @c max_size().
   1213        *
   1214        *  Removes the characters in the range [pos,pos + n1) from this
   1215        *  string.  In place, the first @a __n2 characters of @a __s
   1216        *  are inserted, or all of @a __s if @a __n2 is too large.  If
   1217        *  @a __pos is beyond end of string, out_of_range is thrown.
   1218        *  If the length of result exceeds max_size(), length_error is
   1219        *  thrown.  The value of the string doesn't change if an error
   1220        *  is thrown.
   1221       */
   1222       __versa_string&
   1223       replace(size_type __pos, size_type __n1, const _CharT* __s,
   1224 	      size_type __n2)
   1225       {
   1226 	__glibcxx_requires_string_len(__s, __n2);
   1227 	return _M_replace(_M_check(__pos, "__versa_string::replace"),
   1228 			  _M_limit(__pos, __n1), __s, __n2);
   1229       }
   1230 
   1231       /**
   1232        *  @brief  Replace characters with value of a C string.
   1233        *  @param __pos  Index of first character to replace.
   1234        *  @param __n1  Number of characters to be replaced.
   1235        *  @param __s  C string to insert.
   1236        *  @return  Reference to this string.
   1237        *  @throw  std::out_of_range  If @a __pos > size().
   1238        *  @throw  std::length_error  If new length exceeds @c max_size().
   1239        *
   1240        *  Removes the characters in the range [pos,pos + n1) from this
   1241        *  string.  In place, the characters of @a __s are inserted.  If
   1242        *  @a pos is beyond end of string, out_of_range is thrown.  If
   1243        *  the length of result exceeds max_size(), length_error is thrown.
   1244        *  The value of the string doesn't change if an error is thrown.
   1245       */
   1246       __versa_string&
   1247       replace(size_type __pos, size_type __n1, const _CharT* __s)
   1248       {
   1249 	__glibcxx_requires_string(__s);
   1250 	return this->replace(__pos, __n1, __s, traits_type::length(__s));
   1251       }
   1252 
   1253       /**
   1254        *  @brief  Replace characters with multiple characters.
   1255        *  @param __pos  Index of first character to replace.
   1256        *  @param __n1  Number of characters to be replaced.
   1257        *  @param __n2  Number of characters to insert.
   1258        *  @param __c  Character to insert.
   1259        *  @return  Reference to this string.
   1260        *  @throw  std::out_of_range  If @a __pos > size().
   1261        *  @throw  std::length_error  If new length exceeds @c max_size().
   1262        *
   1263        *  Removes the characters in the range [pos,pos + n1) from this
   1264        *  string.  In place, @a __n2 copies of @a __c are inserted.
   1265        *  If @a __pos is beyond end of string, out_of_range is thrown.
   1266        *  If the length of result exceeds max_size(), length_error is
   1267        *  thrown.  The value of the string doesn't change if an error
   1268        *  is thrown.
   1269       */
   1270       __versa_string&
   1271       replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
   1272       { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
   1273 			      _M_limit(__pos, __n1), __n2, __c); }
   1274 
   1275       /**
   1276        *  @brief  Replace range of characters with string.
   1277        *  @param __i1  Iterator referencing start of range to replace.
   1278        *  @param __i2  Iterator referencing end of range to replace.
   1279        *  @param __str  String value to insert.
   1280        *  @return  Reference to this string.
   1281        *  @throw  std::length_error  If new length exceeds @c max_size().
   1282        *
   1283        *  Removes the characters in the range [i1,i2).  In place, the
   1284        *  value of @a __str is inserted.  If the length of result
   1285        *  exceeds max_size(), length_error is thrown.  The value of
   1286        *  the string doesn't change if an error is thrown.
   1287       */
   1288       __versa_string&
   1289       replace(iterator __i1, iterator __i2, const __versa_string& __str)
   1290       { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
   1291 
   1292       /**
   1293        *  @brief  Replace range of characters with C substring.
   1294        *  @param __i1  Iterator referencing start of range to replace.
   1295        *  @param __i2  Iterator referencing end of range to replace.
   1296        *  @param __s  C string value to insert.
   1297        *  @param __n  Number of characters from s to insert.
   1298        *  @return  Reference to this string.
   1299        *  @throw  std::length_error  If new length exceeds @c max_size().
   1300        *
   1301        *  Removes the characters in the range [i1,i2).  In place, the
   1302        *  first @a n characters of @a __s are inserted.  If the length
   1303        *  of result exceeds max_size(), length_error is thrown.  The
   1304        *  value of the string doesn't change if an error is thrown.
   1305       */
   1306       __versa_string&
   1307       replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
   1308       {
   1309 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
   1310 				 && __i2 <= _M_iend());
   1311 	return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
   1312       }
   1313 
   1314       /**
   1315        *  @brief  Replace range of characters with C string.
   1316        *  @param __i1  Iterator referencing start of range to replace.
   1317        *  @param __i2  Iterator referencing end of range to replace.
   1318        *  @param __s  C string value to insert.
   1319        *  @return  Reference to this string.
   1320        *  @throw  std::length_error  If new length exceeds @c max_size().
   1321        *
   1322        *  Removes the characters in the range [i1,i2).  In place, the
   1323        *  characters of @a __s are inserted.  If the length of result
   1324        *  exceeds max_size(), length_error is thrown.  The value of
   1325        *  the string doesn't change if an error is thrown.
   1326       */
   1327       __versa_string&
   1328       replace(iterator __i1, iterator __i2, const _CharT* __s)
   1329       {
   1330 	__glibcxx_requires_string(__s);
   1331 	return this->replace(__i1, __i2, __s, traits_type::length(__s));
   1332       }
   1333 
   1334       /**
   1335        *  @brief  Replace range of characters with multiple characters
   1336        *  @param __i1  Iterator referencing start of range to replace.
   1337        *  @param __i2  Iterator referencing end of range to replace.
   1338        *  @param __n  Number of characters to insert.
   1339        *  @param __c  Character to insert.
   1340        *  @return  Reference to this string.
   1341        *  @throw  std::length_error  If new length exceeds @c max_size().
   1342        *
   1343        *  Removes the characters in the range [i1,i2).  In place, @a
   1344        *  __n copies of @a __c are inserted.  If the length of result
   1345        *  exceeds max_size(), length_error is thrown.  The value of
   1346        *  the string doesn't change if an error is thrown.
   1347       */
   1348       __versa_string&
   1349       replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
   1350       {
   1351 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
   1352 				 && __i2 <= _M_iend());
   1353 	return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
   1354       }
   1355 
   1356       /**
   1357        *  @brief  Replace range of characters with range.
   1358        *  @param __i1  Iterator referencing start of range to replace.
   1359        *  @param __i2  Iterator referencing end of range to replace.
   1360        *  @param __k1  Iterator referencing start of range to insert.
   1361        *  @param __k2  Iterator referencing end of range to insert.
   1362        *  @return  Reference to this string.
   1363        *  @throw  std::length_error  If new length exceeds @c max_size().
   1364        *
   1365        *  Removes the characters in the range [i1,i2).  In place,
   1366        *  characters in the range [k1,k2) are inserted.  If the length
   1367        *  of result exceeds max_size(), length_error is thrown.  The
   1368        *  value of the string doesn't change if an error is thrown.
   1369       */
   1370       template<class _InputIterator>
   1371         __versa_string&
   1372         replace(iterator __i1, iterator __i2,
   1373 		_InputIterator __k1, _InputIterator __k2)
   1374         {
   1375 	  _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
   1376 				   && __i2 <= _M_iend());
   1377 	  __glibcxx_requires_valid_range(__k1, __k2);
   1378 	  typedef typename std::__is_integer<_InputIterator>::__type _Integral;
   1379 	  return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
   1380 	}
   1381 
   1382       // Specializations for the common case of pointer and iterator:
   1383       // useful to avoid the overhead of temporary buffering in _M_replace.
   1384       __versa_string&
   1385       replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
   1386       {
   1387 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
   1388 				 && __i2 <= _M_iend());
   1389 	__glibcxx_requires_valid_range(__k1, __k2);
   1390 	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
   1391 			     __k1, __k2 - __k1);
   1392       }
   1393 
   1394       __versa_string&
   1395       replace(iterator __i1, iterator __i2,
   1396 	      const _CharT* __k1, const _CharT* __k2)
   1397       {
   1398 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
   1399 				 && __i2 <= _M_iend());
   1400 	__glibcxx_requires_valid_range(__k1, __k2);
   1401 	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
   1402 			     __k1, __k2 - __k1);
   1403       }
   1404 
   1405       __versa_string&
   1406       replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
   1407       {
   1408 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
   1409 				 && __i2 <= _M_iend());
   1410 	__glibcxx_requires_valid_range(__k1, __k2);
   1411 	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
   1412 			     __k1.base(), __k2 - __k1);
   1413       }
   1414 
   1415       __versa_string&
   1416       replace(iterator __i1, iterator __i2,
   1417 	      const_iterator __k1, const_iterator __k2)
   1418       {
   1419 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
   1420 				 && __i2 <= _M_iend());
   1421 	__glibcxx_requires_valid_range(__k1, __k2);
   1422 	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
   1423 			     __k1.base(), __k2 - __k1);
   1424       }
   1425 
   1426 #ifdef __GXX_EXPERIMENTAL_CXX0X__
   1427       /**
   1428        *  @brief  Replace range of characters with initializer_list.
   1429        *  @param __i1  Iterator referencing start of range to replace.
   1430        *  @param __i2  Iterator referencing end of range to replace.
   1431        *  @param __l  The initializer_list of characters to insert.
   1432        *  @return  Reference to this string.
   1433        *  @throw  std::length_error  If new length exceeds @c max_size().
   1434        *
   1435        *  Removes the characters in the range [i1,i2).  In place,
   1436        *  characters in the range [k1,k2) are inserted.  If the length
   1437        *  of result exceeds max_size(), length_error is thrown.  The
   1438        *  value of the string doesn't change if an error is thrown.
   1439       */
   1440       __versa_string& replace(iterator __i1, iterator __i2,
   1441 			      std::initializer_list<_CharT> __l)
   1442       { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
   1443 #endif // __GXX_EXPERIMENTAL_CXX0X__
   1444 
   1445     private:
   1446       template<class _Integer>
   1447 	__versa_string&
   1448 	_M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
   1449 			    _Integer __val, std::__true_type)
   1450         { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
   1451 
   1452       template<class _InputIterator>
   1453 	__versa_string&
   1454 	_M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
   1455 			    _InputIterator __k2, std::__false_type);
   1456 
   1457       __versa_string&
   1458       _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
   1459 		     _CharT __c);
   1460 
   1461       __versa_string&
   1462       _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
   1463 		 const size_type __len2);
   1464 
   1465       __versa_string&
   1466       _M_append(const _CharT* __s, size_type __n);
   1467 
   1468     public:
   1469 
   1470       /**
   1471        *  @brief  Copy substring into C string.
   1472        *  @param __s  C string to copy value into.
   1473        *  @param __n  Number of characters to copy.
   1474        *  @param __pos  Index of first character to copy.
   1475        *  @return  Number of characters actually copied
   1476        *  @throw  std::out_of_range  If pos > size().
   1477        *
   1478        *  Copies up to @a __n characters starting at @a __pos into the
   1479        *  C string @a s.  If @a __pos is greater than size(),
   1480        *  out_of_range is thrown.
   1481       */
   1482       size_type
   1483       copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
   1484 
   1485       /**
   1486        *  @brief  Swap contents with another string.
   1487        *  @param __s  String to swap with.
   1488        *
   1489        *  Exchanges the contents of this string with that of @a __s in
   1490        *  constant time.
   1491       */
   1492       void
   1493       swap(__versa_string& __s)
   1494       { this->_M_swap(__s); }
   1495 
   1496       // String operations:
   1497       /**
   1498        *  @brief  Return const pointer to null-terminated contents.
   1499        *
   1500        *  This is a handle to internal data.  Do not modify or dire things may
   1501        *  happen.
   1502       */
   1503       const _CharT*
   1504       c_str() const _GLIBCXX_NOEXCEPT
   1505       { return this->_M_data(); }
   1506 
   1507       /**
   1508        *  @brief  Return const pointer to contents.
   1509        *
   1510        *  This is a handle to internal data.  Do not modify or dire things may
   1511        *  happen.
   1512       */
   1513       const _CharT*
   1514       data() const _GLIBCXX_NOEXCEPT
   1515       { return this->_M_data(); }
   1516 
   1517       /**
   1518        *  @brief  Return copy of allocator used to construct this string.
   1519       */
   1520       allocator_type
   1521       get_allocator() const _GLIBCXX_NOEXCEPT
   1522       { return allocator_type(this->_M_get_allocator()); }
   1523 
   1524       /**
   1525        *  @brief  Find position of a C substring.
   1526        *  @param __s  C string to locate.
   1527        *  @param __pos  Index of character to search from.
   1528        *  @param __n  Number of characters from @a __s to search for.
   1529        *  @return  Index of start of first occurrence.
   1530        *
   1531        *  Starting from @a __pos, searches forward for the first @a
   1532        *  __n characters in @a __s within this string.  If found,
   1533        *  returns the index where it begins.  If not found, returns
   1534        *  npos.
   1535       */
   1536       size_type
   1537       find(const _CharT* __s, size_type __pos, size_type __n) const;
   1538 
   1539       /**
   1540        *  @brief  Find position of a string.
   1541        *  @param __str  String to locate.
   1542        *  @param __pos  Index of character to search from (default 0).
   1543        *  @return  Index of start of first occurrence.
   1544        *
   1545        *  Starting from @a __pos, searches forward for value of @a
   1546        *  __str within this string.  If found, returns the index where
   1547        *  it begins.  If not found, returns npos.
   1548       */
   1549       size_type
   1550       find(const __versa_string& __str, size_type __pos = 0) const
   1551 	_GLIBCXX_NOEXCEPT
   1552       { return this->find(__str.data(), __pos, __str.size()); }
   1553 
   1554       /**
   1555        *  @brief  Find position of a C string.
   1556        *  @param __s  C string to locate.
   1557        *  @param __pos  Index of character to search from (default 0).
   1558        *  @return  Index of start of first occurrence.
   1559        *
   1560        *  Starting from @a __pos, searches forward for the value of @a
   1561        *  __s within this string.  If found, returns the index where
   1562        *  it begins.  If not found, returns npos.
   1563       */
   1564       size_type
   1565       find(const _CharT* __s, size_type __pos = 0) const
   1566       {
   1567 	__glibcxx_requires_string(__s);
   1568 	return this->find(__s, __pos, traits_type::length(__s));
   1569       }
   1570 
   1571       /**
   1572        *  @brief  Find position of a character.
   1573        *  @param __c  Character to locate.
   1574        *  @param __pos  Index of character to search from (default 0).
   1575        *  @return  Index of first occurrence.
   1576        *
   1577        *  Starting from @a __pos, searches forward for @a __c within
   1578        *  this string.  If found, returns the index where it was
   1579        *  found.  If not found, returns npos.
   1580       */
   1581       size_type
   1582       find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
   1583 
   1584       /**
   1585        *  @brief  Find last position of a string.
   1586        *  @param __str  String to locate.
   1587        *  @param __pos  Index of character to search back from (default end).
   1588        *  @return  Index of start of last occurrence.
   1589        *
   1590        *  Starting from @a __pos, searches backward for value of @a
   1591        *  __str within this string.  If found, returns the index where
   1592        *  it begins.  If not found, returns npos.
   1593       */
   1594       size_type
   1595       rfind(const __versa_string& __str, size_type __pos = npos) const
   1596 	_GLIBCXX_NOEXCEPT
   1597       { return this->rfind(__str.data(), __pos, __str.size()); }
   1598 
   1599       /**
   1600        *  @brief  Find last position of a C substring.
   1601        *  @param __s  C string to locate.
   1602        *  @param __pos  Index of character to search back from.
   1603        *  @param __n  Number of characters from s to search for.
   1604        *  @return  Index of start of last occurrence.
   1605        *
   1606        *  Starting from @a __pos, searches backward for the first @a
   1607        *  __n characters in @a __s within this string.  If found,
   1608        *  returns the index where it begins.  If not found, returns
   1609        *  npos.
   1610       */
   1611       size_type
   1612       rfind(const _CharT* __s, size_type __pos, size_type __n) const;
   1613 
   1614       /**
   1615        *  @brief  Find last position of a C string.
   1616        *  @param __s  C string to locate.
   1617        *  @param __pos  Index of character to start search at (default end).
   1618        *  @return  Index of start of  last occurrence.
   1619        *
   1620        *  Starting from @a __pos, searches backward for the value of
   1621        *  @a __s within this string.  If found, returns the index
   1622        *  where it begins.  If not found, returns npos.
   1623       */
   1624       size_type
   1625       rfind(const _CharT* __s, size_type __pos = npos) const
   1626       {
   1627 	__glibcxx_requires_string(__s);
   1628 	return this->rfind(__s, __pos, traits_type::length(__s));
   1629       }
   1630 
   1631       /**
   1632        *  @brief  Find last position of a character.
   1633        *  @param __c  Character to locate.
   1634        *  @param __pos  Index of character to search back from (default end).
   1635        *  @return  Index of last occurrence.
   1636        *
   1637        *  Starting from @a __pos, searches backward for @a __c within
   1638        *  this string.  If found, returns the index where it was
   1639        *  found.  If not found, returns npos.
   1640       */
   1641       size_type
   1642       rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
   1643 
   1644       /**
   1645        *  @brief  Find position of a character of string.
   1646        *  @param __str  String containing characters to locate.
   1647        *  @param __pos  Index of character to search from (default 0).
   1648        *  @return  Index of first occurrence.
   1649        *
   1650        *  Starting from @a __pos, searches forward for one of the characters of
   1651        *  @a __str within this string.  If found, returns the index where it was
   1652        *  found.  If not found, returns npos.
   1653       */
   1654       size_type
   1655       find_first_of(const __versa_string& __str, size_type __pos = 0) const
   1656 	_GLIBCXX_NOEXCEPT
   1657       { return this->find_first_of(__str.data(), __pos, __str.size()); }
   1658 
   1659       /**
   1660        *  @brief  Find position of a character of C substring.
   1661        *  @param __s  String containing characters to locate.
   1662        *  @param __pos  Index of character to search from.
   1663        *  @param __n  Number of characters from s to search for.
   1664        *  @return  Index of first occurrence.
   1665        *
   1666        *  Starting from @a __pos, searches forward for one of the
   1667        *  first @a __n characters of @a __s within this string.  If
   1668        *  found, returns the index where it was found.  If not found,
   1669        *  returns npos.
   1670       */
   1671       size_type
   1672       find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
   1673 
   1674       /**
   1675        *  @brief  Find position of a character of C string.
   1676        *  @param __s  String containing characters to locate.
   1677        *  @param __pos  Index of character to search from (default 0).
   1678        *  @return  Index of first occurrence.
   1679        *
   1680        *  Starting from @a __pos, searches forward for one of the
   1681        *  characters of @a __s within this string.  If found, returns
   1682        *  the index where it was found.  If not found, returns npos.
   1683       */
   1684       size_type
   1685       find_first_of(const _CharT* __s, size_type __pos = 0) const
   1686       {
   1687 	__glibcxx_requires_string(__s);
   1688 	return this->find_first_of(__s, __pos, traits_type::length(__s));
   1689       }
   1690 
   1691       /**
   1692        *  @brief  Find position of a character.
   1693        *  @param __c  Character to locate.
   1694        *  @param __pos  Index of character to search from (default 0).
   1695        *  @return  Index of first occurrence.
   1696        *
   1697        *  Starting from @a __pos, searches forward for the character
   1698        *  @a __c within this string.  If found, returns the index
   1699        *  where it was found.  If not found, returns npos.
   1700        *
   1701        *  Note: equivalent to find(c, pos).
   1702       */
   1703       size_type
   1704       find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
   1705       { return this->find(__c, __pos); }
   1706 
   1707       /**
   1708        *  @brief  Find last position of a character of string.
   1709        *  @param __str  String containing characters to locate.
   1710        *  @param __pos  Index of character to search back from (default end).
   1711        *  @return  Index of last occurrence.
   1712        *
   1713        *  Starting from @a __pos, searches backward for one of the
   1714        *  characters of @a __str within this string.  If found,
   1715        *  returns the index where it was found.  If not found, returns
   1716        *  npos.
   1717       */
   1718       size_type
   1719       find_last_of(const __versa_string& __str, size_type __pos = npos) const
   1720 	_GLIBCXX_NOEXCEPT
   1721       { return this->find_last_of(__str.data(), __pos, __str.size()); }
   1722 
   1723       /**
   1724        *  @brief  Find last position of a character of C substring.
   1725        *  @param __s  C string containing characters to locate.
   1726        *  @param __pos  Index of character to search back from.
   1727        *  @param __n  Number of characters from s to search for.
   1728        *  @return  Index of last occurrence.
   1729        *
   1730        *  Starting from @a __pos, searches backward for one of the
   1731        *  first @a __n characters of @a __s within this string.  If
   1732        *  found, returns the index where it was found.  If not found,
   1733        *  returns npos.
   1734       */
   1735       size_type
   1736       find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
   1737 
   1738       /**
   1739        *  @brief  Find last position of a character of C string.
   1740        *  @param __s  C string containing characters to locate.
   1741        *  @param __pos  Index of character to search back from (default end).
   1742        *  @return  Index of last occurrence.
   1743        *
   1744        *  Starting from @a __pos, searches backward for one of the
   1745        *  characters of @a __s within this string.  If found, returns
   1746        *  the index where it was found.  If not found, returns npos.
   1747       */
   1748       size_type
   1749       find_last_of(const _CharT* __s, size_type __pos = npos) const
   1750       {
   1751 	__glibcxx_requires_string(__s);
   1752 	return this->find_last_of(__s, __pos, traits_type::length(__s));
   1753       }
   1754 
   1755       /**
   1756        *  @brief  Find last position of a character.
   1757        *  @param __c  Character to locate.
   1758        *  @param __pos  Index of character to search back from (default end).
   1759        *  @return  Index of last occurrence.
   1760        *
   1761        *  Starting from @a __pos, searches backward for @a __c within
   1762        *  this string.  If found, returns the index where it was
   1763        *  found.  If not found, returns npos.
   1764        *
   1765        *  Note: equivalent to rfind(c, pos).
   1766       */
   1767       size_type
   1768       find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
   1769       { return this->rfind(__c, __pos); }
   1770 
   1771       /**
   1772        *  @brief  Find position of a character not in string.
   1773        *  @param __str  String containing characters to avoid.
   1774        *  @param __pos  Index of character to search from (default 0).
   1775        *  @return  Index of first occurrence.
   1776        *
   1777        *  Starting from @a __pos, searches forward for a character not
   1778        *  contained in @a __str within this string.  If found, returns
   1779        *  the index where it was found.  If not found, returns npos.
   1780       */
   1781       size_type
   1782       find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
   1783 	_GLIBCXX_NOEXCEPT
   1784       { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
   1785 
   1786       /**
   1787        *  @brief  Find position of a character not in C substring.
   1788        *  @param __s  C string containing characters to avoid.
   1789        *  @param __pos  Index of character to search from.
   1790        *  @param __n  Number of characters from s to consider.
   1791        *  @return  Index of first occurrence.
   1792        *
   1793        *  Starting from @a __pos, searches forward for a character not
   1794        *  contained in the first @a __n characters of @a __s within
   1795        *  this string.  If found, returns the index where it was
   1796        *  found.  If not found, returns npos.
   1797       */
   1798       size_type
   1799       find_first_not_of(const _CharT* __s, size_type __pos,
   1800 			size_type __n) const;
   1801 
   1802       /**
   1803        *  @brief  Find position of a character not in C string.
   1804        *  @param __s  C string containing characters to avoid.
   1805        *  @param __pos  Index of character to search from (default 0).
   1806        *  @return  Index of first occurrence.
   1807        *
   1808        *  Starting from @a __pos, searches forward for a character not
   1809        *  contained in @a __s within this string.  If found, returns
   1810        *  the index where it was found.  If not found, returns npos.
   1811       */
   1812       size_type
   1813       find_first_not_of(const _CharT* __s, size_type __pos = 0) const
   1814       {
   1815 	__glibcxx_requires_string(__s);
   1816 	return this->find_first_not_of(__s, __pos, traits_type::length(__s));
   1817       }
   1818 
   1819       /**
   1820        *  @brief  Find position of a different character.
   1821        *  @param __c  Character to avoid.
   1822        *  @param __pos  Index of character to search from (default 0).
   1823        *  @return  Index of first occurrence.
   1824        *
   1825        *  Starting from @a __pos, searches forward for a character
   1826        *  other than @a __c within this string.  If found, returns the
   1827        *  index where it was found.  If not found, returns npos.
   1828       */
   1829       size_type
   1830       find_first_not_of(_CharT __c, size_type __pos = 0) const
   1831 	_GLIBCXX_NOEXCEPT;
   1832 
   1833       /**
   1834        *  @brief  Find last position of a character not in string.
   1835        *  @param __str  String containing characters to avoid.
   1836        *  @param __pos  Index of character to search back from (default end).
   1837        *  @return  Index of last occurrence.
   1838        *
   1839        *  Starting from @a __pos, searches backward for a character
   1840        *  not contained in @a __str within this string.  If found,
   1841        *  returns the index where it was found.  If not found, returns
   1842        *  npos.
   1843       */
   1844       size_type
   1845       find_last_not_of(const __versa_string& __str,
   1846 		       size_type __pos = npos) const _GLIBCXX_NOEXCEPT
   1847       { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
   1848 
   1849       /**
   1850        *  @brief  Find last position of a character not in C substring.
   1851        *  @param __s  C string containing characters to avoid.
   1852        *  @param __pos  Index of character to search back from.
   1853        *  @param __n  Number of characters from s to consider.
   1854        *  @return  Index of last occurrence.
   1855        *
   1856        *  Starting from @a __pos, searches backward for a character
   1857        *  not contained in the first @a __n characters of @a __s
   1858        *  within this string.  If found, returns the index where it
   1859        *  was found.  If not found, returns npos.
   1860       */
   1861       size_type
   1862       find_last_not_of(const _CharT* __s, size_type __pos,
   1863 		       size_type __n) const;
   1864       /**
   1865        *  @brief  Find last position of a character not in C string.
   1866        *  @param __s  C string containing characters to avoid.
   1867        *  @param __pos  Index of character to search back from (default end).
   1868        *  @return  Index of last occurrence.
   1869        *
   1870        *  Starting from @a __pos, searches backward for a character
   1871        *  not contained in @a __s within this string.  If found,
   1872        *  returns the index where it was found.  If not found, returns
   1873        *  npos.
   1874       */
   1875       size_type
   1876       find_last_not_of(const _CharT* __s, size_type __pos = npos) const
   1877       {
   1878 	__glibcxx_requires_string(__s);
   1879 	return this->find_last_not_of(__s, __pos, traits_type::length(__s));
   1880       }
   1881 
   1882       /**
   1883        *  @brief  Find last position of a different character.
   1884        *  @param __c  Character to avoid.
   1885        *  @param __pos  Index of character to search back from (default end).
   1886        *  @return  Index of last occurrence.
   1887        *
   1888        *  Starting from @a __pos, searches backward for a character
   1889        *  other than @a __c within this string.  If found, returns the
   1890        *  index where it was found.  If not found, returns npos.
   1891       */
   1892       size_type
   1893       find_last_not_of(_CharT __c, size_type __pos = npos) const
   1894 	_GLIBCXX_NOEXCEPT;
   1895 
   1896       /**
   1897        *  @brief  Get a substring.
   1898        *  @param __pos  Index of first character (default 0).
   1899        *  @param __n  Number of characters in substring (default remainder).
   1900        *  @return  The new string.
   1901        *  @throw  std::out_of_range  If pos > size().
   1902        *
   1903        *  Construct and return a new string using the @a __n
   1904        *  characters starting at @a __pos.  If the string is too
   1905        *  short, use the remainder of the characters.  If @a __pos is
   1906        *  beyond the end of the string, out_of_range is thrown.
   1907       */
   1908       __versa_string
   1909       substr(size_type __pos = 0, size_type __n = npos) const
   1910       {
   1911 	return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
   1912 			      __n);
   1913       }
   1914 
   1915       /**
   1916        *  @brief  Compare to a string.
   1917        *  @param __str  String to compare against.
   1918        *  @return  Integer < 0, 0, or > 0.
   1919        *
   1920        *  Returns an integer < 0 if this string is ordered before @a
   1921        *  __str, 0 if their values are equivalent, or > 0 if this
   1922        *  string is ordered after @a __str.  Determines the effective
   1923        *  length rlen of the strings to compare as the smallest of
   1924        *  size() and str.size().  The function then compares the two
   1925        *  strings by calling traits::compare(data(), str.data(),rlen).
   1926        *  If the result of the comparison is nonzero returns it,
   1927        *  otherwise the shorter one is ordered first.
   1928       */
   1929       int
   1930       compare(const __versa_string& __str) const
   1931       {
   1932 	if (this->_M_compare(__str))
   1933 	  return 0;
   1934 
   1935 	const size_type __size = this->size();
   1936 	const size_type __osize = __str.size();
   1937 	const size_type __len = std::min(__size, __osize);
   1938 
   1939 	int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
   1940 	if (!__r)
   1941 	  __r = this->_S_compare(__size, __osize);
   1942 	return __r;
   1943       }
   1944 
   1945       /**
   1946        *  @brief  Compare substring to a string.
   1947        *  @param __pos  Index of first character of substring.
   1948        *  @param __n  Number of characters in substring.
   1949        *  @param __str  String to compare against.
   1950        *  @return  Integer < 0, 0, or > 0.
   1951        *
   1952        *  Form the substring of this string from the @a __n characters
   1953        *  starting at @a __pos.  Returns an integer < 0 if the
   1954        *  substring is ordered before @a __str, 0 if their values are
   1955        *  equivalent, or > 0 if the substring is ordered after @a
   1956        *  __str.  Determines the effective length rlen of the strings
   1957        *  to compare as the smallest of the length of the substring
   1958        *  and @a __str.size().  The function then compares the two
   1959        *  strings by calling
   1960        *  traits::compare(substring.data(),str.data(),rlen).  If the
   1961        *  result of the comparison is nonzero returns it, otherwise
   1962        *  the shorter one is ordered first.
   1963       */
   1964       int
   1965       compare(size_type __pos, size_type __n,
   1966 	      const __versa_string& __str) const;
   1967 
   1968       /**
   1969        *  @brief  Compare substring to a substring.
   1970        *  @param __pos1  Index of first character of substring.
   1971        *  @param __n1  Number of characters in substring.
   1972        *  @param __str  String to compare against.
   1973        *  @param __pos2  Index of first character of substring of str.
   1974        *  @param __n2  Number of characters in substring of str.
   1975        *  @return  Integer < 0, 0, or > 0.
   1976        *
   1977        *  Form the substring of this string from the @a __n1
   1978        *  characters starting at @a __pos1.  Form the substring of @a
   1979        *  __str from the @a __n2 characters starting at @a __pos2.
   1980        *  Returns an integer < 0 if this substring is ordered before
   1981        *  the substring of @a __str, 0 if their values are equivalent,
   1982        *  or > 0 if this substring is ordered after the substring of
   1983        *  @a __str.  Determines the effective length rlen of the
   1984        *  strings to compare as the smallest of the lengths of the
   1985        *  substrings.  The function then compares the two strings by
   1986        *  calling
   1987        *  traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
   1988        *  If the result of the comparison is nonzero returns it,
   1989        *  otherwise the shorter one is ordered first.
   1990       */
   1991       int
   1992       compare(size_type __pos1, size_type __n1, const __versa_string& __str,
   1993 	      size_type __pos2, size_type __n2) const;
   1994 
   1995       /**
   1996        *  @brief  Compare to a C string.
   1997        *  @param __s  C string to compare against.
   1998        *  @return  Integer < 0, 0, or > 0.
   1999        *
   2000        *  Returns an integer < 0 if this string is ordered before @a
   2001        *  __s, 0 if their values are equivalent, or > 0 if this string
   2002        *  is ordered after @a __s.  Determines the effective length
   2003        *  rlen of the strings to compare as the smallest of size() and
   2004        *  the length of a string constructed from @a __s.  The
   2005        *  function then compares the two strings by calling
   2006        *  traits::compare(data(),s,rlen).  If the result of the
   2007        *  comparison is nonzero returns it, otherwise the shorter one
   2008        *  is ordered first.
   2009       */
   2010       int
   2011       compare(const _CharT* __s) const;
   2012 
   2013       // _GLIBCXX_RESOLVE_LIB_DEFECTS
   2014       // 5 String::compare specification questionable
   2015       /**
   2016        *  @brief  Compare substring to a C string.
   2017        *  @param __pos  Index of first character of substring.
   2018        *  @param __n1  Number of characters in substring.
   2019        *  @param __s  C string to compare against.
   2020        *  @return  Integer < 0, 0, or > 0.
   2021        *
   2022        *  Form the substring of this string from the @a __n1
   2023        *  characters starting at @a __pos.  Returns an integer < 0 if
   2024        *  the substring is ordered before @a __s, 0 if their values
   2025        *  are equivalent, or > 0 if the substring is ordered after @a
   2026        *  __s.  Determines the effective length rlen of the strings to
   2027        *  compare as the smallest of the length of the substring and
   2028        *  the length of a string constructed from @a __s.  The
   2029        *  function then compares the two string by calling
   2030        *  traits::compare(substring.data(),s,rlen).  If the result of
   2031        *  the comparison is nonzero returns it, otherwise the shorter
   2032        *  one is ordered first.
   2033       */
   2034       int
   2035       compare(size_type __pos, size_type __n1, const _CharT* __s) const;
   2036 
   2037       /**
   2038        *  @brief  Compare substring against a character array.
   2039        *  @param __pos  Index of first character of substring.
   2040        *  @param __n1  Number of characters in substring.
   2041        *  @param __s  character array to compare against.
   2042        *  @param __n2  Number of characters of s.
   2043        *  @return  Integer < 0, 0, or > 0.
   2044        *
   2045        *  Form the substring of this string from the @a __n1
   2046        *  characters starting at @a __pos.  Form a string from the
   2047        *  first @a __n2 characters of @a __s.  Returns an integer < 0
   2048        *  if this substring is ordered before the string from @a __s,
   2049        *  0 if their values are equivalent, or > 0 if this substring
   2050        *  is ordered after the string from @a __s.  Determines the
   2051        *  effective length rlen of the strings to compare as the
   2052        *  smallest of the length of the substring and @a __n2.  The
   2053        *  function then compares the two strings by calling
   2054        *  traits::compare(substring.data(),__s,rlen).  If the result of
   2055        *  the comparison is nonzero returns it, otherwise the shorter
   2056        *  one is ordered first.
   2057        *
   2058        *  NB: __s must have at least n2 characters, <em>\\0</em> has no special
   2059        *  meaning.
   2060       */
   2061       int
   2062       compare(size_type __pos, size_type __n1, const _CharT* __s,
   2063 	      size_type __n2) const;
   2064     };
   2065 
   2066   // operator+
   2067   /**
   2068    *  @brief  Concatenate two strings.
   2069    *  @param __lhs  First string.
   2070    *  @param __rhs  Last string.
   2071    *  @return  New string with value of @a __lhs followed by @a __rhs.
   2072    */
   2073   template<typename _CharT, typename _Traits, typename _Alloc,
   2074 	   template <typename, typename, typename> class _Base>
   2075     __versa_string<_CharT, _Traits, _Alloc, _Base>
   2076     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2077 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
   2078 
   2079   /**
   2080    *  @brief  Concatenate C string and string.
   2081    *  @param __lhs  First string.
   2082    *  @param __rhs  Last string.
   2083    *  @return  New string with value of @a __lhs followed by @a __rhs.
   2084    */
   2085   template<typename _CharT, typename _Traits, typename _Alloc,
   2086 	   template <typename, typename, typename> class _Base>
   2087     __versa_string<_CharT, _Traits, _Alloc, _Base>
   2088     operator+(const _CharT* __lhs,
   2089 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
   2090 
   2091   /**
   2092    *  @brief  Concatenate character and string.
   2093    *  @param __lhs  First string.
   2094    *  @param __rhs  Last string.
   2095    *  @return  New string with @a __lhs followed by @a __rhs.
   2096    */
   2097   template<typename _CharT, typename _Traits, typename _Alloc,
   2098 	   template <typename, typename, typename> class _Base>
   2099     __versa_string<_CharT, _Traits, _Alloc, _Base>
   2100     operator+(_CharT __lhs,
   2101 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
   2102 
   2103   /**
   2104    *  @brief  Concatenate string and C string.
   2105    *  @param __lhs  First string.
   2106    *  @param __rhs  Last string.
   2107    *  @return  New string with @a __lhs followed by @a __rhs.
   2108    */
   2109   template<typename _CharT, typename _Traits, typename _Alloc,
   2110 	   template <typename, typename, typename> class _Base>
   2111     __versa_string<_CharT, _Traits, _Alloc, _Base>
   2112     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2113 	      const _CharT* __rhs);
   2114 
   2115   /**
   2116    *  @brief  Concatenate string and character.
   2117    *  @param __lhs  First string.
   2118    *  @param __rhs  Last string.
   2119    *  @return  New string with @a __lhs followed by @a __rhs.
   2120    */
   2121   template<typename _CharT, typename _Traits, typename _Alloc,
   2122 	   template <typename, typename, typename> class _Base>
   2123     __versa_string<_CharT, _Traits, _Alloc, _Base>
   2124     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2125 	      _CharT __rhs);
   2126 
   2127 #ifdef __GXX_EXPERIMENTAL_CXX0X__
   2128   template<typename _CharT, typename _Traits, typename _Alloc,
   2129 	   template <typename, typename, typename> class _Base>
   2130     inline __versa_string<_CharT, _Traits, _Alloc, _Base>
   2131     operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
   2132 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
   2133     { return std::move(__lhs.append(__rhs)); }
   2134 
   2135   template<typename _CharT, typename _Traits, typename _Alloc,
   2136 	   template <typename, typename, typename> class _Base>
   2137     inline __versa_string<_CharT, _Traits, _Alloc, _Base>
   2138     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2139 	      __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
   2140     { return std::move(__rhs.insert(0, __lhs)); }
   2141 
   2142   template<typename _CharT, typename _Traits, typename _Alloc,
   2143 	   template <typename, typename, typename> class _Base>
   2144     inline __versa_string<_CharT, _Traits, _Alloc, _Base>
   2145     operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
   2146 	      __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
   2147     {
   2148       const auto __size = __lhs.size() + __rhs.size();
   2149       const bool __cond = (__size > __lhs.capacity()
   2150 			   && __size <= __rhs.capacity());
   2151       return __cond ? std::move(__rhs.insert(0, __lhs))
   2152 	            : std::move(__lhs.append(__rhs));
   2153     }
   2154 
   2155   template<typename _CharT, typename _Traits, typename _Alloc,
   2156 	   template <typename, typename, typename> class _Base>
   2157     inline __versa_string<_CharT, _Traits, _Alloc, _Base>
   2158     operator+(const _CharT* __lhs,
   2159 	      __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
   2160     { return std::move(__rhs.insert(0, __lhs)); }
   2161 
   2162   template<typename _CharT, typename _Traits, typename _Alloc,
   2163 	   template <typename, typename, typename> class _Base>
   2164     inline __versa_string<_CharT, _Traits, _Alloc, _Base>
   2165     operator+(_CharT __lhs,
   2166 	      __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
   2167     { return std::move(__rhs.insert(0, 1, __lhs)); }
   2168 
   2169   template<typename _CharT, typename _Traits, typename _Alloc,
   2170 	   template <typename, typename, typename> class _Base>
   2171     inline __versa_string<_CharT, _Traits, _Alloc, _Base>
   2172     operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
   2173 	      const _CharT* __rhs)
   2174     { return std::move(__lhs.append(__rhs)); }
   2175 
   2176   template<typename _CharT, typename _Traits, typename _Alloc,
   2177 	   template <typename, typename, typename> class _Base>
   2178     inline __versa_string<_CharT, _Traits, _Alloc, _Base>
   2179     operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
   2180 	      _CharT __rhs)
   2181     { return std::move(__lhs.append(1, __rhs)); }
   2182 #endif
   2183 
   2184   // operator ==
   2185   /**
   2186    *  @brief  Test equivalence of two strings.
   2187    *  @param __lhs  First string.
   2188    *  @param __rhs  Second string.
   2189    *  @return  True if @a __lhs.compare(@a __rhs) == 0.  False otherwise.
   2190    */
   2191   template<typename _CharT, typename _Traits, typename _Alloc,
   2192 	   template <typename, typename, typename> class _Base>
   2193     inline bool
   2194     operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2195 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
   2196     { return __lhs.compare(__rhs) == 0; }
   2197 
   2198   template<typename _CharT,
   2199 	   template <typename, typename, typename> class _Base>
   2200     inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type
   2201     operator==(const __versa_string<_CharT, std::char_traits<_CharT>,
   2202 	       std::allocator<_CharT>, _Base>& __lhs,
   2203 	       const __versa_string<_CharT, std::char_traits<_CharT>,
   2204 	       std::allocator<_CharT>, _Base>& __rhs)
   2205     { return (__lhs.size() == __rhs.size()
   2206 	      && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
   2207 						    __lhs.size())); }
   2208 
   2209   /**
   2210    *  @brief  Test equivalence of C string and string.
   2211    *  @param __lhs  C string.
   2212    *  @param __rhs  String.
   2213    *  @return  True if @a __rhs.compare(@a __lhs) == 0.  False otherwise.
   2214    */
   2215   template<typename _CharT, typename _Traits, typename _Alloc,
   2216 	   template <typename, typename, typename> class _Base>
   2217     inline bool
   2218     operator==(const _CharT* __lhs,
   2219 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
   2220     { return __rhs.compare(__lhs) == 0; }
   2221 
   2222   /**
   2223    *  @brief  Test equivalence of string and C string.
   2224    *  @param __lhs  String.
   2225    *  @param __rhs  C string.
   2226    *  @return  True if @a __lhs.compare(@a __rhs) == 0.  False otherwise.
   2227    */
   2228   template<typename _CharT, typename _Traits, typename _Alloc,
   2229 	   template <typename, typename, typename> class _Base>
   2230     inline bool
   2231     operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2232 	       const _CharT* __rhs)
   2233     { return __lhs.compare(__rhs) == 0; }
   2234 
   2235   // operator !=
   2236   /**
   2237    *  @brief  Test difference of two strings.
   2238    *  @param __lhs  First string.
   2239    *  @param __rhs  Second string.
   2240    *  @return  True if @a __lhs.compare(@a __rhs) != 0.  False otherwise.
   2241    */
   2242   template<typename _CharT, typename _Traits, typename _Alloc,
   2243 	   template <typename, typename, typename> class _Base>
   2244     inline bool
   2245     operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2246 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
   2247     { return !(__lhs == __rhs); }
   2248 
   2249   /**
   2250    *  @brief  Test difference of C string and string.
   2251    *  @param __lhs  C string.
   2252    *  @param __rhs  String.
   2253    *  @return  True if @a __rhs.compare(@a __lhs) != 0.  False otherwise.
   2254    */
   2255   template<typename _CharT, typename _Traits, typename _Alloc,
   2256 	   template <typename, typename, typename> class _Base>
   2257     inline bool
   2258     operator!=(const _CharT* __lhs,
   2259 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
   2260     { return !(__lhs == __rhs); }
   2261 
   2262   /**
   2263    *  @brief  Test difference of string and C string.
   2264    *  @param __lhs  String.
   2265    *  @param __rhs  C string.
   2266    *  @return  True if @a __lhs.compare(@a __rhs) != 0.  False otherwise.
   2267    */
   2268   template<typename _CharT, typename _Traits, typename _Alloc,
   2269 	   template <typename, typename, typename> class _Base>
   2270     inline bool
   2271     operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2272 	       const _CharT* __rhs)
   2273     { return !(__lhs == __rhs); }
   2274 
   2275   // operator <
   2276   /**
   2277    *  @brief  Test if string precedes string.
   2278    *  @param __lhs  First string.
   2279    *  @param __rhs  Second string.
   2280    *  @return  True if @a __lhs precedes @a __rhs.  False otherwise.
   2281    */
   2282   template<typename _CharT, typename _Traits, typename _Alloc,
   2283 	   template <typename, typename, typename> class _Base>
   2284     inline bool
   2285     operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2286 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
   2287     { return __lhs.compare(__rhs) < 0; }
   2288 
   2289   /**
   2290    *  @brief  Test if string precedes C string.
   2291    *  @param __lhs  String.
   2292    *  @param __rhs  C string.
   2293    *  @return  True if @a __lhs precedes @a __rhs.  False otherwise.
   2294    */
   2295   template<typename _CharT, typename _Traits, typename _Alloc,
   2296 	   template <typename, typename, typename> class _Base>
   2297     inline bool
   2298     operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2299 	      const _CharT* __rhs)
   2300     { return __lhs.compare(__rhs) < 0; }
   2301 
   2302   /**
   2303    *  @brief  Test if C string precedes string.
   2304    *  @param __lhs  C string.
   2305    *  @param __rhs  String.
   2306    *  @return  True if @a __lhs precedes @a __rhs.  False otherwise.
   2307    */
   2308   template<typename _CharT, typename _Traits, typename _Alloc,
   2309 	   template <typename, typename, typename> class _Base>
   2310     inline bool
   2311     operator<(const _CharT* __lhs,
   2312 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
   2313     { return __rhs.compare(__lhs) > 0; }
   2314 
   2315   // operator >
   2316   /**
   2317    *  @brief  Test if string follows string.
   2318    *  @param __lhs  First string.
   2319    *  @param __rhs  Second string.
   2320    *  @return  True if @a __lhs follows @a __rhs.  False otherwise.
   2321    */
   2322   template<typename _CharT, typename _Traits, typename _Alloc,
   2323 	   template <typename, typename, typename> class _Base>
   2324     inline bool
   2325     operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2326 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
   2327     { return __lhs.compare(__rhs) > 0; }
   2328 
   2329   /**
   2330    *  @brief  Test if string follows C string.
   2331    *  @param __lhs  String.
   2332    *  @param __rhs  C string.
   2333    *  @return  True if @a __lhs follows @a __rhs.  False otherwise.
   2334    */
   2335   template<typename _CharT, typename _Traits, typename _Alloc,
   2336 	   template <typename, typename, typename> class _Base>
   2337     inline bool
   2338     operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2339 	      const _CharT* __rhs)
   2340     { return __lhs.compare(__rhs) > 0; }
   2341 
   2342   /**
   2343    *  @brief  Test if C string follows string.
   2344    *  @param __lhs  C string.
   2345    *  @param __rhs  String.
   2346    *  @return  True if @a __lhs follows @a __rhs.  False otherwise.
   2347    */
   2348   template<typename _CharT, typename _Traits, typename _Alloc,
   2349 	   template <typename, typename, typename> class _Base>
   2350     inline bool
   2351     operator>(const _CharT* __lhs,
   2352 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
   2353     { return __rhs.compare(__lhs) < 0; }
   2354 
   2355   // operator <=
   2356   /**
   2357    *  @brief  Test if string doesn't follow string.
   2358    *  @param __lhs  First string.
   2359    *  @param __rhs  Second string.
   2360    *  @return  True if @a __lhs doesn't follow @a __rhs.  False otherwise.
   2361    */
   2362   template<typename _CharT, typename _Traits, typename _Alloc,
   2363 	   template <typename, typename, typename> class _Base>
   2364     inline bool
   2365     operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2366 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
   2367     { return __lhs.compare(__rhs) <= 0; }
   2368 
   2369   /**
   2370    *  @brief  Test if string doesn't follow C string.
   2371    *  @param __lhs  String.
   2372    *  @param __rhs  C string.
   2373    *  @return  True if @a __lhs doesn't follow @a __rhs.  False otherwise.
   2374    */
   2375   template<typename _CharT, typename _Traits, typename _Alloc,
   2376 	   template <typename, typename, typename> class _Base>
   2377     inline bool
   2378     operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2379 	       const _CharT* __rhs)
   2380     { return __lhs.compare(__rhs) <= 0; }
   2381 
   2382   /**
   2383    *  @brief  Test if C string doesn't follow string.
   2384    *  @param __lhs  C string.
   2385    *  @param __rhs  String.
   2386    *  @return  True if @a __lhs doesn't follow @a __rhs.  False otherwise.
   2387    */
   2388   template<typename _CharT, typename _Traits, typename _Alloc,
   2389 	   template <typename, typename, typename> class _Base>
   2390     inline bool
   2391     operator<=(const _CharT* __lhs,
   2392 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
   2393     { return __rhs.compare(__lhs) >= 0; }
   2394 
   2395   // operator >=
   2396   /**
   2397    *  @brief  Test if string doesn't precede string.
   2398    *  @param __lhs  First string.
   2399    *  @param __rhs  Second string.
   2400    *  @return  True if @a __lhs doesn't precede @a __rhs.  False otherwise.
   2401    */
   2402   template<typename _CharT, typename _Traits, typename _Alloc,
   2403 	   template <typename, typename, typename> class _Base>
   2404     inline bool
   2405     operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2406 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
   2407     { return __lhs.compare(__rhs) >= 0; }
   2408 
   2409   /**
   2410    *  @brief  Test if string doesn't precede C string.
   2411    *  @param __lhs  String.
   2412    *  @param __rhs  C string.
   2413    *  @return  True if @a __lhs doesn't precede @a __rhs.  False otherwise.
   2414    */
   2415   template<typename _CharT, typename _Traits, typename _Alloc,
   2416 	   template <typename, typename, typename> class _Base>
   2417     inline bool
   2418     operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2419 	       const _CharT* __rhs)
   2420     { return __lhs.compare(__rhs) >= 0; }
   2421 
   2422   /**
   2423    *  @brief  Test if C string doesn't precede string.
   2424    *  @param __lhs  C string.
   2425    *  @param __rhs  String.
   2426    *  @return  True if @a __lhs doesn't precede @a __rhs.  False otherwise.
   2427    */
   2428   template<typename _CharT, typename _Traits, typename _Alloc,
   2429 	   template <typename, typename, typename> class _Base>
   2430     inline bool
   2431     operator>=(const _CharT* __lhs,
   2432 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
   2433     { return __rhs.compare(__lhs) <= 0; }
   2434 
   2435   /**
   2436    *  @brief  Swap contents of two strings.
   2437    *  @param __lhs  First string.
   2438    *  @param __rhs  Second string.
   2439    *
   2440    *  Exchanges the contents of @a __lhs and @a __rhs in constant time.
   2441    */
   2442   template<typename _CharT, typename _Traits, typename _Alloc,
   2443 	   template <typename, typename, typename> class _Base>
   2444     inline void
   2445     swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
   2446 	 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
   2447     { __lhs.swap(__rhs); }
   2448 
   2449 _GLIBCXX_END_NAMESPACE_VERSION
   2450 } // namespace
   2451 
   2452 namespace std _GLIBCXX_VISIBILITY(default)
   2453 {
   2454 _GLIBCXX_BEGIN_NAMESPACE_VERSION
   2455 
   2456   /**
   2457    *  @brief  Read stream into a string.
   2458    *  @param __is  Input stream.
   2459    *  @param __str  Buffer to store into.
   2460    *  @return  Reference to the input stream.
   2461    *
   2462    *  Stores characters from @a __is into @a __str until whitespace is
   2463    *  found, the end of the stream is encountered, or str.max_size()
   2464    *  is reached.  If is.width() is non-zero, that is the limit on the
   2465    *  number of characters stored into @a __str.  Any previous
   2466    *  contents of @a __str are erased.
   2467    */
   2468   template<typename _CharT, typename _Traits, typename _Alloc,
   2469            template <typename, typename, typename> class _Base>
   2470     basic_istream<_CharT, _Traits>&
   2471     operator>>(basic_istream<_CharT, _Traits>& __is,
   2472 	       __gnu_cxx::__versa_string<_CharT, _Traits,
   2473 	                                 _Alloc, _Base>& __str);
   2474 
   2475   /**
   2476    *  @brief  Write string to a stream.
   2477    *  @param __os  Output stream.
   2478    *  @param __str  String to write out.
   2479    *  @return  Reference to the output stream.
   2480    *
   2481    *  Output characters of @a __str into os following the same rules as for
   2482    *  writing a C string.
   2483    */
   2484   template<typename _CharT, typename _Traits, typename _Alloc,
   2485 	   template <typename, typename, typename> class _Base>
   2486     inline basic_ostream<_CharT, _Traits>&
   2487     operator<<(basic_ostream<_CharT, _Traits>& __os,
   2488 	       const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc,
   2489 	       _Base>& __str)
   2490     {
   2491       // _GLIBCXX_RESOLVE_LIB_DEFECTS
   2492       // 586. string inserter not a formatted function
   2493       return __ostream_insert(__os, __str.data(), __str.size());
   2494     }
   2495 
   2496   /**
   2497    *  @brief  Read a line from stream into a string.
   2498    *  @param __is  Input stream.
   2499    *  @param __str  Buffer to store into.
   2500    *  @param __delim  Character marking end of line.
   2501    *  @return  Reference to the input stream.
   2502    *
   2503    *  Stores characters from @a __is into @a __str until @a __delim is
   2504    *  found, the end of the stream is encountered, or str.max_size()
   2505    *  is reached.  If is.width() is non-zero, that is the limit on the
   2506    *  number of characters stored into @a __str.  Any previous
   2507    *  contents of @a __str are erased.  If @a delim was encountered,
   2508    *  it is extracted but not stored into @a __str.
   2509    */
   2510   template<typename _CharT, typename _Traits, typename _Alloc,
   2511            template <typename, typename, typename> class _Base>
   2512     basic_istream<_CharT, _Traits>&
   2513     getline(basic_istream<_CharT, _Traits>& __is,
   2514 	    __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
   2515 	    _CharT __delim);
   2516 
   2517   /**
   2518    *  @brief  Read a line from stream into a string.
   2519    *  @param __is  Input stream.
   2520    *  @param __str  Buffer to store into.
   2521    *  @return  Reference to the input stream.
   2522    *
   2523    *  Stores characters from is into @a __str until &apos;\n&apos; is
   2524    *  found, the end of the stream is encountered, or str.max_size()
   2525    *  is reached.  If is.width() is non-zero, that is the limit on the
   2526    *  number of characters stored into @a __str.  Any previous
   2527    *  contents of @a __str are erased.  If end of line was
   2528    *  encountered, it is extracted but not stored into @a __str.
   2529    */
   2530   template<typename _CharT, typename _Traits, typename _Alloc,
   2531            template <typename, typename, typename> class _Base>
   2532     inline basic_istream<_CharT, _Traits>&
   2533     getline(basic_istream<_CharT, _Traits>& __is,
   2534 	    __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
   2535     { return getline(__is, __str, __is.widen('\n')); }
   2536 
   2537 _GLIBCXX_END_NAMESPACE_VERSION
   2538 } // namespace
   2539 
   2540 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99))
   2541 
   2542 #include <ext/string_conversions.h>
   2543 
   2544 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
   2545 {
   2546 _GLIBCXX_BEGIN_NAMESPACE_VERSION
   2547 
   2548   // 21.4 Numeric Conversions [string.conversions].
   2549   inline int
   2550   stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
   2551   { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
   2552 					__idx, __base); }
   2553 
   2554   inline long
   2555   stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
   2556   { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
   2557 			     __idx, __base); }
   2558 
   2559   inline unsigned long
   2560   stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
   2561   { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
   2562 			     __idx, __base); }
   2563 
   2564   inline long long
   2565   stoll(const __vstring& __str, std::size_t* __idx = 0,	int __base = 10)
   2566   { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
   2567 			     __idx, __base); }
   2568 
   2569   inline unsigned long long
   2570   stoull(const __vstring& __str, std::size_t* __idx, int __base = 10)
   2571   { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
   2572 			     __idx, __base); }
   2573 
   2574   // NB: strtof vs strtod.
   2575   inline float
   2576   stof(const __vstring& __str, std::size_t* __idx = 0)
   2577   { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
   2578 
   2579   inline double
   2580   stod(const __vstring& __str, std::size_t* __idx = 0)
   2581   { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
   2582 
   2583   inline long double
   2584   stold(const __vstring& __str, std::size_t* __idx = 0)
   2585   { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
   2586 
   2587   // NB: (v)snprintf vs sprintf.
   2588 
   2589   // DR 1261.
   2590   inline __vstring
   2591   to_string(int __val)
   2592   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
   2593 					      "%d", __val); }
   2594 
   2595   inline __vstring
   2596   to_string(unsigned __val)
   2597   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
   2598 					      4 * sizeof(unsigned),
   2599 					      "%u", __val); }
   2600 
   2601   inline __vstring
   2602   to_string(long __val)
   2603   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
   2604 					      4 * sizeof(long),
   2605 					      "%ld", __val); }
   2606 
   2607   inline __vstring
   2608   to_string(unsigned long __val)
   2609   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
   2610 					      4 * sizeof(unsigned long),
   2611 					      "%lu", __val); }
   2612 
   2613 
   2614   inline __vstring
   2615   to_string(long long __val)
   2616   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
   2617 					      4 * sizeof(long long),
   2618 					      "%lld", __val); }
   2619 
   2620   inline __vstring
   2621   to_string(unsigned long long __val)
   2622   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
   2623 					      4 * sizeof(unsigned long long),
   2624 					      "%llu", __val); }
   2625 
   2626   inline __vstring
   2627   to_string(float __val)
   2628   {
   2629     const int __n = __numeric_traits<float>::__max_exponent10 + 20;
   2630     return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
   2631 					      "%f", __val);
   2632   }
   2633 
   2634   inline __vstring
   2635   to_string(double __val)
   2636   {
   2637     const int __n = __numeric_traits<double>::__max_exponent10 + 20;
   2638     return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
   2639 					      "%f", __val);
   2640   }
   2641 
   2642   inline __vstring
   2643   to_string(long double __val)
   2644   {
   2645     const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
   2646     return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
   2647 					      "%Lf", __val);
   2648   }
   2649 
   2650 #ifdef _GLIBCXX_USE_WCHAR_T
   2651   inline int
   2652   stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
   2653   { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
   2654 					__idx, __base); }
   2655 
   2656   inline long
   2657   stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
   2658   { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
   2659 			     __idx, __base); }
   2660 
   2661   inline unsigned long
   2662   stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
   2663   { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
   2664 			     __idx, __base); }
   2665 
   2666   inline long long
   2667   stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
   2668   { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
   2669 			     __idx, __base); }
   2670 
   2671   inline unsigned long long
   2672   stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
   2673   { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
   2674 			     __idx, __base); }
   2675 
   2676   // NB: wcstof vs wcstod.
   2677   inline float
   2678   stof(const __wvstring& __str, std::size_t* __idx = 0)
   2679   { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
   2680 
   2681   inline double
   2682   stod(const __wvstring& __str, std::size_t* __idx = 0)
   2683   { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
   2684 
   2685   inline long double
   2686   stold(const __wvstring& __str, std::size_t* __idx = 0)
   2687   { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
   2688 
   2689 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
   2690   // DR 1261.
   2691   inline __wvstring
   2692   to_wstring(int __val)
   2693   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
   2694 					       4 * sizeof(int),
   2695 					       L"%d", __val); }
   2696 
   2697   inline __wvstring
   2698   to_wstring(unsigned __val)
   2699   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
   2700 					       4 * sizeof(unsigned),
   2701 					       L"%u", __val); }
   2702 
   2703   inline __wvstring
   2704   to_wstring(long __val)
   2705   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
   2706 					       4 * sizeof(long),
   2707 					       L"%ld", __val); }
   2708 
   2709   inline __wvstring
   2710   to_wstring(unsigned long __val)
   2711   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
   2712 					       4 * sizeof(unsigned long),
   2713 					       L"%lu", __val); }
   2714 
   2715   inline __wvstring
   2716   to_wstring(long long __val)
   2717   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
   2718 					       4 * sizeof(long long),
   2719 					       L"%lld", __val); }
   2720 
   2721   inline __wvstring
   2722   to_wstring(unsigned long long __val)
   2723   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
   2724 					       4 * sizeof(unsigned long long),
   2725 					       L"%llu", __val); }
   2726 
   2727   inline __wvstring
   2728   to_wstring(float __val)
   2729   {
   2730     const int __n = __numeric_traits<float>::__max_exponent10 + 20;
   2731     return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
   2732 					       L"%f", __val);
   2733   }
   2734 
   2735   inline __wvstring
   2736   to_wstring(double __val)
   2737   {
   2738     const int __n = __numeric_traits<double>::__max_exponent10 + 20;
   2739     return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
   2740 					       L"%f", __val);
   2741   }
   2742 
   2743   inline __wvstring
   2744   to_wstring(long double __val)
   2745   {
   2746     const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
   2747     return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
   2748 					       L"%Lf", __val);
   2749   }
   2750 #endif
   2751 #endif
   2752 
   2753 _GLIBCXX_END_NAMESPACE_VERSION
   2754 } // namespace
   2755 
   2756 #endif
   2757 
   2758 #ifdef __GXX_EXPERIMENTAL_CXX0X__
   2759 
   2760 #include <bits/functional_hash.h>
   2761 
   2762 namespace std _GLIBCXX_VISIBILITY(default)
   2763 {
   2764 _GLIBCXX_BEGIN_NAMESPACE_VERSION
   2765 
   2766   /// std::hash specialization for __vstring.
   2767   template<>
   2768     struct hash<__gnu_cxx::__vstring>
   2769     : public __hash_base<size_t, __gnu_cxx::__vstring>
   2770     {
   2771       size_t
   2772       operator()(const __gnu_cxx::__vstring& __s) const noexcept
   2773       { return std::_Hash_impl::hash(__s.data(), __s.length()); }
   2774     };
   2775 
   2776 #ifdef _GLIBCXX_USE_WCHAR_T
   2777   /// std::hash specialization for __wvstring.
   2778   template<>
   2779     struct hash<__gnu_cxx::__wvstring>
   2780     : public __hash_base<size_t, __gnu_cxx::__wvstring>
   2781     {
   2782       size_t
   2783       operator()(const __gnu_cxx::__wvstring& __s) const noexcept
   2784       { return std::_Hash_impl::hash(__s.data(),
   2785                                      __s.length() * sizeof(wchar_t)); }
   2786     };
   2787 #endif
   2788 
   2789 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
   2790   /// std::hash specialization for __u16vstring.
   2791   template<>
   2792     struct hash<__gnu_cxx::__u16vstring>
   2793     : public __hash_base<size_t, __gnu_cxx::__u16vstring>
   2794     {
   2795       size_t
   2796       operator()(const __gnu_cxx::__u16vstring& __s) const noexcept
   2797       { return std::_Hash_impl::hash(__s.data(),
   2798                                      __s.length() * sizeof(char16_t)); }
   2799     };
   2800 
   2801   /// std::hash specialization for __u32vstring.
   2802   template<>
   2803     struct hash<__gnu_cxx::__u32vstring>
   2804     : public __hash_base<size_t, __gnu_cxx::__u32vstring>
   2805     {
   2806       size_t
   2807       operator()(const __gnu_cxx::__u32vstring& __s) const noexcept
   2808       { return std::_Hash_impl::hash(__s.data(),
   2809                                      __s.length() * sizeof(char32_t)); }
   2810     };
   2811 #endif
   2812 
   2813 _GLIBCXX_END_NAMESPACE_VERSION
   2814 } // namespace
   2815 
   2816 #endif /* __GXX_EXPERIMENTAL_CXX0X__ */
   2817 
   2818 #include "vstring.tcc"
   2819 
   2820 #endif /* _VSTRING_H */
   2821