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