197403Sobrien// Components for manipulating sequences of characters -*- C++ -*-
297403Sobrien
3169691Skan// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4169691Skan// 2006, 2007
597403Sobrien// Free Software Foundation, Inc.
697403Sobrien//
797403Sobrien// This file is part of the GNU ISO C++ Library.  This library is free
897403Sobrien// software; you can redistribute it and/or modify it under the
997403Sobrien// terms of the GNU General Public License as published by the
1097403Sobrien// Free Software Foundation; either version 2, or (at your option)
1197403Sobrien// any later version.
1297403Sobrien
1397403Sobrien// This library is distributed in the hope that it will be useful,
1497403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of
1597403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1697403Sobrien// GNU General Public License for more details.
1797403Sobrien
1897403Sobrien// You should have received a copy of the GNU General Public License along
1997403Sobrien// with this library; see the file COPYING.  If not, write to the Free
20169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
2197403Sobrien// USA.
2297403Sobrien
2397403Sobrien// As a special exception, you may use this file as part of a free software
2497403Sobrien// library without restriction.  Specifically, if other files instantiate
2597403Sobrien// templates or use macros or inline functions from this file, or you compile
2697403Sobrien// this file and link it with other files to produce an executable, this
2797403Sobrien// file does not by itself cause the resulting executable to be covered by
2897403Sobrien// the GNU General Public License.  This exception does not however
2997403Sobrien// invalidate any other reasons why the executable file might be covered by
3097403Sobrien// the GNU General Public License.
3197403Sobrien
3297403Sobrien/** @file basic_string.h
3397403Sobrien *  This is an internal header file, included by other library headers.
3497403Sobrien *  You should not attempt to use it directly.
3597403Sobrien */
3697403Sobrien
37169691Skan//
38169691Skan// ISO C++ 14882: 21 Strings library
39169691Skan//
40169691Skan
41132720Skan#ifndef _BASIC_STRING_H
42132720Skan#define _BASIC_STRING_H 1
4397403Sobrien
4497403Sobrien#pragma GCC system_header
4597403Sobrien
46169691Skan#include <ext/atomicity.h>
47132720Skan#include <debug/debug.h>
4897403Sobrien
49169691Skan_GLIBCXX_BEGIN_NAMESPACE(std)
50169691Skan
51117397Skan  /**
52117397Skan   *  @class basic_string basic_string.h <string>
53117397Skan   *  @brief  Managing sequences of characters and character-like objects.
54117397Skan   *
55117397Skan   *  @ingroup Containers
56117397Skan   *  @ingroup Sequences
57117397Skan   *
58117397Skan   *  Meets the requirements of a <a href="tables.html#65">container</a>, a
59117397Skan   *  <a href="tables.html#66">reversible container</a>, and a
60117397Skan   *  <a href="tables.html#67">sequence</a>.  Of the
61117397Skan   *  <a href="tables.html#68">optional sequence requirements</a>, only
62117397Skan   *  @c push_back, @c at, and array access are supported.
63117397Skan   *
64117397Skan   *  @doctodo
65117397Skan   *
66117397Skan   *
67117397Skan   *  @if maint
68117397Skan   *  Documentation?  What's that?
69117397Skan   *  Nathan Myers <ncm@cantrip.org>.
70117397Skan   *
71117397Skan   *  A string looks like this:
72117397Skan   *
73117397Skan   *  @code
74117397Skan   *                                        [_Rep]
75117397Skan   *                                        _M_length
76117397Skan   *   [basic_string<char_type>]            _M_capacity
77132720Skan   *   _M_dataplus                          _M_refcount
78117397Skan   *   _M_p ---------------->               unnamed array of char_type
79117397Skan   *  @endcode
80117397Skan   *
81117397Skan   *  Where the _M_p points to the first character in the string, and
82117397Skan   *  you cast it to a pointer-to-_Rep and subtract 1 to get a
83117397Skan   *  pointer to the header.
84117397Skan   *
85117397Skan   *  This approach has the enormous advantage that a string object
86117397Skan   *  requires only one allocation.  All the ugliness is confined
87117397Skan   *  within a single pair of inline functions, which each compile to
88117397Skan   *  a single "add" instruction: _Rep::_M_data(), and
89117397Skan   *  string::_M_rep(); and the allocation function which gets a
90117397Skan   *  block of raw bytes and with room enough and constructs a _Rep
91117397Skan   *  object at the front.
92117397Skan   *
93117397Skan   *  The reason you want _M_data pointing to the character array and
94117397Skan   *  not the _Rep is so that the debugger can see the string
95117397Skan   *  contents. (Probably we should add a non-inline member to get
96117397Skan   *  the _Rep for the debugger to use, so users can check the actual
97117397Skan   *  string length.)
98117397Skan   *
99117397Skan   *  Note that the _Rep object is a POD so that you can have a
100117397Skan   *  static "empty string" _Rep object already "constructed" before
101117397Skan   *  static constructors have run.  The reference-count encoding is
102117397Skan   *  chosen so that a 0 indicates one reference, so you never try to
103117397Skan   *  destroy the empty-string _Rep object.
104117397Skan   *
105117397Skan   *  All but the last paragraph is considered pretty conventional
106117397Skan   *  for a C++ string implementation.
107117397Skan   *  @endif
108117397Skan  */
10997403Sobrien  // 21.3  Template class basic_string
11097403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
11197403Sobrien    class basic_string
11297403Sobrien    {
113169691Skan      typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type;
114169691Skan
11597403Sobrien      // Types:
11697403Sobrien    public:
117132720Skan      typedef _Traits					    traits_type;
118132720Skan      typedef typename _Traits::char_type		    value_type;
119132720Skan      typedef _Alloc					    allocator_type;
120169691Skan      typedef typename _CharT_alloc_type::size_type	    size_type;
121169691Skan      typedef typename _CharT_alloc_type::difference_type   difference_type;
122169691Skan      typedef typename _CharT_alloc_type::reference	    reference;
123169691Skan      typedef typename _CharT_alloc_type::const_reference   const_reference;
124169691Skan      typedef typename _CharT_alloc_type::pointer	    pointer;
125169691Skan      typedef typename _CharT_alloc_type::const_pointer	    const_pointer;
12697403Sobrien      typedef __gnu_cxx::__normal_iterator<pointer, basic_string>  iterator;
12797403Sobrien      typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
12897403Sobrien                                                            const_iterator;
129132720Skan      typedef std::reverse_iterator<const_iterator>	const_reverse_iterator;
130132720Skan      typedef std::reverse_iterator<iterator>		    reverse_iterator;
131117397Skan
13297403Sobrien    private:
13397403Sobrien      // _Rep: string representation
13497403Sobrien      //   Invariants:
135132720Skan      //   1. String really contains _M_length + 1 characters: due to 21.3.4
136132720Skan      //      must be kept null-terminated.
13797403Sobrien      //   2. _M_capacity >= _M_length
138132720Skan      //      Allocated memory is always (_M_capacity + 1) * sizeof(_CharT).
139132720Skan      //   3. _M_refcount has three states:
14097403Sobrien      //      -1: leaked, one reference, no ref-copies allowed, non-const.
14197403Sobrien      //       0: one reference, non-const.
14297403Sobrien      //     n>0: n + 1 references, operations require a lock, const.
14397403Sobrien      //   4. All fields==0 is an empty string, given the extra storage
14497403Sobrien      //      beyond-the-end for a null terminator; thus, the shared
14597403Sobrien      //      empty string representation needs no constructor.
146132720Skan
147132720Skan      struct _Rep_base
14897403Sobrien      {
149132720Skan	size_type		_M_length;
150132720Skan	size_type		_M_capacity;
151132720Skan	_Atomic_word		_M_refcount;
152132720Skan      };
153132720Skan
154132720Skan      struct _Rep : _Rep_base
155132720Skan      {
15697403Sobrien	// Types:
15797403Sobrien	typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc;
15897403Sobrien
159117397Skan	// (Public) Data members:
16097403Sobrien
16197403Sobrien	// The maximum number of individual char_type elements of an
16297403Sobrien	// individual string is determined by _S_max_size. This is the
16397403Sobrien	// value that will be returned by max_size().  (Whereas npos
16497403Sobrien	// is the maximum number of bytes the allocator can allocate.)
16597403Sobrien	// If one was to divvy up the theoretical largest size string,
16697403Sobrien	// with a terminating character and m _CharT elements, it'd
167117397Skan	// look like this:
16897403Sobrien	// npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
16997403Sobrien	// Solving for m:
170117397Skan	// m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
171132720Skan	// In addition, this implementation quarters this amount.
172132720Skan	static const size_type	_S_max_size;
173132720Skan	static const _CharT	_S_terminal;
17497403Sobrien
175132720Skan	// The following storage is init'd to 0 by the linker, resulting
176132720Skan        // (carefully) in an empty string with one reference.
177132720Skan        static size_type _S_empty_rep_storage[];
178117397Skan
179132720Skan        static _Rep&
180132720Skan        _S_empty_rep()
181169691Skan        {
182169691Skan	  // NB: Mild hack to avoid strict-aliasing warnings.  Note that
183169691Skan	  // _S_empty_rep_storage is never modified and the punning should
184169691Skan	  // be reasonably safe in this case.
185169691Skan	  void* __p = reinterpret_cast<void*>(&_S_empty_rep_storage);
186169691Skan	  return *reinterpret_cast<_Rep*>(__p);
187169691Skan	}
188132720Skan
18997403Sobrien        bool
19097403Sobrien	_M_is_leaked() const
191132720Skan        { return this->_M_refcount < 0; }
19297403Sobrien
19397403Sobrien        bool
19497403Sobrien	_M_is_shared() const
195132720Skan        { return this->_M_refcount > 0; }
19697403Sobrien
19797403Sobrien        void
198117397Skan	_M_set_leaked()
199132720Skan        { this->_M_refcount = -1; }
20097403Sobrien
20197403Sobrien        void
202117397Skan	_M_set_sharable()
203132720Skan        { this->_M_refcount = 0; }
20497403Sobrien
205169691Skan	void
206169691Skan	_M_set_length_and_sharable(size_type __n)
207169691Skan	{
208169691Skan	  this->_M_set_sharable();  // One reference.
209169691Skan	  this->_M_length = __n;
210169691Skan	  traits_type::assign(this->_M_refdata()[__n], _S_terminal);
211169691Skan	  // grrr. (per 21.3.4)
212169691Skan	  // You cannot leave those LWG people alone for a second.
213169691Skan	}
214169691Skan
215117397Skan	_CharT*
21697403Sobrien	_M_refdata() throw()
21797403Sobrien	{ return reinterpret_cast<_CharT*>(this + 1); }
21897403Sobrien
219117397Skan	_CharT*
22097403Sobrien	_M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2)
221117397Skan	{
222117397Skan	  return (!_M_is_leaked() && __alloc1 == __alloc2)
223117397Skan	          ? _M_refcopy() : _M_clone(__alloc1);
22497403Sobrien	}
22597403Sobrien
22697403Sobrien	// Create & Destroy
227117397Skan	static _Rep*
228132720Skan	_S_create(size_type, size_type, const _Alloc&);
22997403Sobrien
230117397Skan	void
23197403Sobrien	_M_dispose(const _Alloc& __a)
232117397Skan	{
233146897Skan#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
234132720Skan	  if (__builtin_expect(this != &_S_empty_rep(), false))
235146897Skan#endif
236169691Skan	    if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
237169691Skan						       -1) <= 0)
238132720Skan	      _M_destroy(__a);
23997403Sobrien	}  // XXX MT
24097403Sobrien
241117397Skan	void
24297403Sobrien	_M_destroy(const _Alloc&) throw();
24397403Sobrien
244117397Skan	_CharT*
24597403Sobrien	_M_refcopy() throw()
246117397Skan	{
247146897Skan#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
248132720Skan	  if (__builtin_expect(this != &_S_empty_rep(), false))
249146897Skan#endif
250169691Skan            __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
251117397Skan	  return _M_refdata();
25297403Sobrien	}  // XXX MT
25397403Sobrien
254117397Skan	_CharT*
25597403Sobrien	_M_clone(const _Alloc&, size_type __res = 0);
25697403Sobrien      };
25797403Sobrien
25897403Sobrien      // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
25997403Sobrien      struct _Alloc_hider : _Alloc
26097403Sobrien      {
26197403Sobrien	_Alloc_hider(_CharT* __dat, const _Alloc& __a)
26297403Sobrien	: _Alloc(__a), _M_p(__dat) { }
26397403Sobrien
26497403Sobrien	_CharT* _M_p; // The actual data.
26597403Sobrien      };
26697403Sobrien
26797403Sobrien    public:
26897403Sobrien      // Data Members (public):
26997403Sobrien      // NB: This is an unsigned type, and thus represents the maximum
27097403Sobrien      // size that the allocator can hold.
271169691Skan      ///  Value returned by various member functions when they fail.
272132720Skan      static const size_type	npos = static_cast<size_type>(-1);
27397403Sobrien
27497403Sobrien    private:
27597403Sobrien      // Data Members (private):
276132720Skan      mutable _Alloc_hider	_M_dataplus;
27797403Sobrien
278117397Skan      _CharT*
279117397Skan      _M_data() const
28097403Sobrien      { return  _M_dataplus._M_p; }
28197403Sobrien
282117397Skan      _CharT*
283117397Skan      _M_data(_CharT* __p)
28497403Sobrien      { return (_M_dataplus._M_p = __p); }
28597403Sobrien
286117397Skan      _Rep*
28797403Sobrien      _M_rep() const
28897403Sobrien      { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }
28997403Sobrien
29097403Sobrien      // For the internal use we have functions similar to `begin'/`end'
29197403Sobrien      // but they do not call _M_leak.
292117397Skan      iterator
293169691Skan      _M_ibegin() const
294169691Skan      { return iterator(_M_data()); }
29597403Sobrien
296117397Skan      iterator
297169691Skan      _M_iend() const
298169691Skan      { return iterator(_M_data() + this->size()); }
29997403Sobrien
300117397Skan      void
30197403Sobrien      _M_leak()    // for use in begin() & non-const op[]
302117397Skan      {
303117397Skan	if (!_M_rep()->_M_is_leaked())
304117397Skan	  _M_leak_hard();
30597403Sobrien      }
30697403Sobrien
307132720Skan      size_type
308132720Skan      _M_check(size_type __pos, const char* __s) const
309117397Skan      {
31097403Sobrien	if (__pos > this->size())
311132720Skan	  __throw_out_of_range(__N(__s));
312132720Skan	return __pos;
31397403Sobrien      }
31497403Sobrien
315169691Skan      void
316169691Skan      _M_check_length(size_type __n1, size_type __n2, const char* __s) const
317169691Skan      {
318169691Skan	if (this->max_size() - (this->size() - __n1) < __n2)
319169691Skan	  __throw_length_error(__N(__s));
320169691Skan      }
321169691Skan
322132720Skan      // NB: _M_limit doesn't check for a bad __pos value.
323132720Skan      size_type
324132720Skan      _M_limit(size_type __pos, size_type __off) const
325117397Skan      {
326132720Skan	const bool __testoff =  __off < this->size() - __pos;
327132720Skan	return __testoff ? __off : this->size() - __pos;
32897403Sobrien      }
32997403Sobrien
330169691Skan      // True if _Rep and source do not overlap.
331169691Skan      bool
332169691Skan      _M_disjunct(const _CharT* __s) const
333169691Skan      {
334169691Skan	return (less<const _CharT*>()(__s, _M_data())
335169691Skan		|| less<const _CharT*>()(_M_data() + this->size(), __s));
336169691Skan      }
337169691Skan
338169691Skan      // When __n = 1 way faster than the general multichar
339169691Skan      // traits_type::copy/move/assign.
340169691Skan      static void
341169691Skan      _M_copy(_CharT* __d, const _CharT* __s, size_type __n)
342169691Skan      {
343169691Skan	if (__n == 1)
344169691Skan	  traits_type::assign(*__d, *__s);
345169691Skan	else
346169691Skan	  traits_type::copy(__d, __s, __n);
347169691Skan      }
348169691Skan
349169691Skan      static void
350169691Skan      _M_move(_CharT* __d, const _CharT* __s, size_type __n)
351169691Skan      {
352169691Skan	if (__n == 1)
353169691Skan	  traits_type::assign(*__d, *__s);
354169691Skan	else
355169691Skan	  traits_type::move(__d, __s, __n);
356169691Skan      }
357169691Skan
358169691Skan      static void
359169691Skan      _M_assign(_CharT* __d, size_type __n, _CharT __c)
360169691Skan      {
361169691Skan	if (__n == 1)
362169691Skan	  traits_type::assign(*__d, __c);
363169691Skan	else
364169691Skan	  traits_type::assign(__d, __n, __c);
365169691Skan      }
366169691Skan
36797403Sobrien      // _S_copy_chars is a separate template to permit specialization
36897403Sobrien      // to optimize for the common case of pointers as iterators.
36997403Sobrien      template<class _Iterator>
37097403Sobrien        static void
37197403Sobrien        _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
372117397Skan        {
373117397Skan	  for (; __k1 != __k2; ++__k1, ++__p)
37497403Sobrien	    traits_type::assign(*__p, *__k1); // These types are off.
37597403Sobrien	}
37697403Sobrien
37797403Sobrien      static void
37897403Sobrien      _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2)
37997403Sobrien      { _S_copy_chars(__p, __k1.base(), __k2.base()); }
38097403Sobrien
38197403Sobrien      static void
38297403Sobrien      _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
38397403Sobrien      { _S_copy_chars(__p, __k1.base(), __k2.base()); }
384117397Skan
38597403Sobrien      static void
38697403Sobrien      _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2)
387169691Skan      { _M_copy(__p, __k1, __k2 - __k1); }
38897403Sobrien
38997403Sobrien      static void
39097403Sobrien      _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
391169691Skan      { _M_copy(__p, __k1, __k2 - __k1); }
39297403Sobrien
393117397Skan      void
39497403Sobrien      _M_mutate(size_type __pos, size_type __len1, size_type __len2);
39597403Sobrien
396117397Skan      void
39797403Sobrien      _M_leak_hard();
39897403Sobrien
399117397Skan      static _Rep&
40097403Sobrien      _S_empty_rep()
401132720Skan      { return _Rep::_S_empty_rep(); }
40297403Sobrien
40397403Sobrien    public:
40497403Sobrien      // Construct/copy/destroy:
40597403Sobrien      // NB: We overload ctors in some cases instead of using default
40697403Sobrien      // arguments, per 17.4.4.4 para. 2 item 2.
40797403Sobrien
408132720Skan      /**
409132720Skan       *  @brief  Default constructor creates an empty string.
410132720Skan       */
411117397Skan      inline
41297403Sobrien      basic_string();
41397403Sobrien
414132720Skan      /**
415169691Skan       *  @brief  Construct an empty string using allocator @a a.
416132720Skan       */
417117397Skan      explicit
41897403Sobrien      basic_string(const _Alloc& __a);
41997403Sobrien
42097403Sobrien      // NB: per LWG issue 42, semantics different from IS:
421132720Skan      /**
422132720Skan       *  @brief  Construct string with copy of value of @a str.
423132720Skan       *  @param  str  Source string.
424132720Skan       */
42597403Sobrien      basic_string(const basic_string& __str);
426132720Skan      /**
427132720Skan       *  @brief  Construct string as copy of a substring.
428132720Skan       *  @param  str  Source string.
429132720Skan       *  @param  pos  Index of first character to copy from.
430132720Skan       *  @param  n  Number of characters to copy (default remainder).
431132720Skan       */
43297403Sobrien      basic_string(const basic_string& __str, size_type __pos,
43397403Sobrien		   size_type __n = npos);
434132720Skan      /**
435132720Skan       *  @brief  Construct string as copy of a substring.
436132720Skan       *  @param  str  Source string.
437132720Skan       *  @param  pos  Index of first character to copy from.
438132720Skan       *  @param  n  Number of characters to copy.
439132720Skan       *  @param  a  Allocator to use.
440132720Skan       */
44197403Sobrien      basic_string(const basic_string& __str, size_type __pos,
44297403Sobrien		   size_type __n, const _Alloc& __a);
44397403Sobrien
444132720Skan      /**
445132720Skan       *  @brief  Construct string initialized by a character array.
446132720Skan       *  @param  s  Source character array.
447132720Skan       *  @param  n  Number of characters to copy.
448132720Skan       *  @param  a  Allocator to use (default is default allocator).
449132720Skan       *
450169691Skan       *  NB: @a s must have at least @a n characters, '\0' has no special
451132720Skan       *  meaning.
452132720Skan       */
45397403Sobrien      basic_string(const _CharT* __s, size_type __n,
45497403Sobrien		   const _Alloc& __a = _Alloc());
455132720Skan      /**
456132720Skan       *  @brief  Construct string as copy of a C string.
457132720Skan       *  @param  s  Source C string.
458132720Skan       *  @param  a  Allocator to use (default is default allocator).
459132720Skan       */
46097403Sobrien      basic_string(const _CharT* __s, const _Alloc& __a = _Alloc());
461132720Skan      /**
462132720Skan       *  @brief  Construct string as multiple characters.
463132720Skan       *  @param  n  Number of characters.
464132720Skan       *  @param  c  Character to use.
465132720Skan       *  @param  a  Allocator to use (default is default allocator).
466132720Skan       */
46797403Sobrien      basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
46897403Sobrien
469132720Skan      /**
470132720Skan       *  @brief  Construct string as copy of a range.
471132720Skan       *  @param  beg  Start of range.
472132720Skan       *  @param  end  End of range.
473132720Skan       *  @param  a  Allocator to use (default is default allocator).
474132720Skan       */
47597403Sobrien      template<class _InputIterator>
47697403Sobrien        basic_string(_InputIterator __beg, _InputIterator __end,
47797403Sobrien		     const _Alloc& __a = _Alloc());
47897403Sobrien
479132720Skan      /**
480132720Skan       *  @brief  Destroy the string instance.
481132720Skan       */
482117397Skan      ~basic_string()
48397403Sobrien      { _M_rep()->_M_dispose(this->get_allocator()); }
48497403Sobrien
485132720Skan      /**
486132720Skan       *  @brief  Assign the value of @a str to this string.
487132720Skan       *  @param  str  Source string.
488132720Skan       */
489117397Skan      basic_string&
490132720Skan      operator=(const basic_string& __str)
491169691Skan      { return this->assign(__str); }
49297403Sobrien
493132720Skan      /**
494132720Skan       *  @brief  Copy contents of @a s into this string.
495132720Skan       *  @param  s  Source null-terminated string.
496132720Skan       */
497117397Skan      basic_string&
498132720Skan      operator=(const _CharT* __s)
499169691Skan      { return this->assign(__s); }
50097403Sobrien
501132720Skan      /**
502132720Skan       *  @brief  Set value to string of length 1.
503132720Skan       *  @param  c  Source character.
504132720Skan       *
505132720Skan       *  Assigning to a character makes this string length 1 and
506132720Skan       *  (*this)[0] == @a c.
507132720Skan       */
508117397Skan      basic_string&
509132720Skan      operator=(_CharT __c)
510132720Skan      {
511132720Skan	this->assign(1, __c);
512132720Skan	return *this;
513132720Skan      }
51497403Sobrien
51597403Sobrien      // Iterators:
516132720Skan      /**
517132720Skan       *  Returns a read/write iterator that points to the first character in
518132720Skan       *  the %string.  Unshares the string.
519132720Skan       */
520117397Skan      iterator
521117397Skan      begin()
522117397Skan      {
523117397Skan	_M_leak();
52497403Sobrien	return iterator(_M_data());
52597403Sobrien      }
52697403Sobrien
527132720Skan      /**
528132720Skan       *  Returns a read-only (constant) iterator that points to the first
529132720Skan       *  character in the %string.
530132720Skan       */
531117397Skan      const_iterator
532117397Skan      begin() const
53397403Sobrien      { return const_iterator(_M_data()); }
53497403Sobrien
535132720Skan      /**
536132720Skan       *  Returns a read/write iterator that points one past the last
537132720Skan       *  character in the %string.  Unshares the string.
538132720Skan       */
539117397Skan      iterator
54097403Sobrien      end()
54197403Sobrien      {
542132720Skan	_M_leak();
543132720Skan	return iterator(_M_data() + this->size());
54497403Sobrien      }
54597403Sobrien
546132720Skan      /**
547132720Skan       *  Returns a read-only (constant) iterator that points one past the
548132720Skan       *  last character in the %string.
549132720Skan       */
550117397Skan      const_iterator
55197403Sobrien      end() const
55297403Sobrien      { return const_iterator(_M_data() + this->size()); }
55397403Sobrien
554132720Skan      /**
555132720Skan       *  Returns a read/write reverse iterator that points to the last
556132720Skan       *  character in the %string.  Iteration is done in reverse element
557132720Skan       *  order.  Unshares the string.
558132720Skan       */
559117397Skan      reverse_iterator
560117397Skan      rbegin()
56197403Sobrien      { return reverse_iterator(this->end()); }
56297403Sobrien
563132720Skan      /**
564132720Skan       *  Returns a read-only (constant) reverse iterator that points
565132720Skan       *  to the last character in the %string.  Iteration is done in
566132720Skan       *  reverse element order.
567132720Skan       */
568117397Skan      const_reverse_iterator
569117397Skan      rbegin() const
57097403Sobrien      { return const_reverse_iterator(this->end()); }
57197403Sobrien
572132720Skan      /**
573132720Skan       *  Returns a read/write reverse iterator that points to one before the
574132720Skan       *  first character in the %string.  Iteration is done in reverse
575132720Skan       *  element order.  Unshares the string.
576132720Skan       */
577117397Skan      reverse_iterator
578117397Skan      rend()
57997403Sobrien      { return reverse_iterator(this->begin()); }
58097403Sobrien
581132720Skan      /**
582132720Skan       *  Returns a read-only (constant) reverse iterator that points
583132720Skan       *  to one before the first character in the %string.  Iteration
584132720Skan       *  is done in reverse element order.
585132720Skan       */
586117397Skan      const_reverse_iterator
587117397Skan      rend() const
58897403Sobrien      { return const_reverse_iterator(this->begin()); }
58997403Sobrien
59097403Sobrien    public:
59197403Sobrien      // Capacity:
592132720Skan      ///  Returns the number of characters in the string, not including any
593132720Skan      ///  null-termination.
594117397Skan      size_type
595169691Skan      size() const
596169691Skan      { return _M_rep()->_M_length; }
59797403Sobrien
598132720Skan      ///  Returns the number of characters in the string, not including any
599132720Skan      ///  null-termination.
600117397Skan      size_type
601169691Skan      length() const
602169691Skan      { return _M_rep()->_M_length; }
60397403Sobrien
604132720Skan      /// Returns the size() of the largest possible %string.
605117397Skan      size_type
606169691Skan      max_size() const
607169691Skan      { return _Rep::_S_max_size; }
60897403Sobrien
609132720Skan      /**
610132720Skan       *  @brief  Resizes the %string to the specified number of characters.
611132720Skan       *  @param  n  Number of characters the %string should contain.
612132720Skan       *  @param  c  Character to fill any new elements.
613132720Skan       *
614132720Skan       *  This function will %resize the %string to the specified
615132720Skan       *  number of characters.  If the number is smaller than the
616132720Skan       *  %string's current size the %string is truncated, otherwise
617132720Skan       *  the %string is extended and new elements are set to @a c.
618132720Skan       */
619117397Skan      void
62097403Sobrien      resize(size_type __n, _CharT __c);
62197403Sobrien
622132720Skan      /**
623132720Skan       *  @brief  Resizes the %string to the specified number of characters.
624132720Skan       *  @param  n  Number of characters the %string should contain.
625132720Skan       *
626132720Skan       *  This function will resize the %string to the specified length.  If
627132720Skan       *  the new size is smaller than the %string's current size the %string
628132720Skan       *  is truncated, otherwise the %string is extended and new characters
629132720Skan       *  are default-constructed.  For basic types such as char, this means
630132720Skan       *  setting them to 0.
631132720Skan       */
632117397Skan      void
633169691Skan      resize(size_type __n)
634169691Skan      { this->resize(__n, _CharT()); }
63597403Sobrien
636132720Skan      /**
637132720Skan       *  Returns the total number of characters that the %string can hold
638132720Skan       *  before needing to allocate more memory.
639132720Skan       */
640117397Skan      size_type
641169691Skan      capacity() const
642169691Skan      { return _M_rep()->_M_capacity; }
64397403Sobrien
644132720Skan      /**
645132720Skan       *  @brief  Attempt to preallocate enough memory for specified number of
646132720Skan       *          characters.
647169691Skan       *  @param  res_arg  Number of characters required.
648169691Skan       *  @throw  std::length_error  If @a res_arg exceeds @c max_size().
649132720Skan       *
650132720Skan       *  This function attempts to reserve enough memory for the
651132720Skan       *  %string to hold the specified number of characters.  If the
652132720Skan       *  number requested is more than max_size(), length_error is
653132720Skan       *  thrown.
654132720Skan       *
655132720Skan       *  The advantage of this function is that if optimal code is a
656132720Skan       *  necessity and the user can determine the string length that will be
657132720Skan       *  required, the user can reserve the memory in %advance, and thus
658132720Skan       *  prevent a possible reallocation of memory and copying of %string
659132720Skan       *  data.
660132720Skan       */
661117397Skan      void
66297403Sobrien      reserve(size_type __res_arg = 0);
66397403Sobrien
664132720Skan      /**
665132720Skan       *  Erases the string, making it empty.
666132720Skan       */
667117397Skan      void
668169691Skan      clear()
669169691Skan      { _M_mutate(0, this->size(), 0); }
67097403Sobrien
671132720Skan      /**
672132720Skan       *  Returns true if the %string is empty.  Equivalent to *this == "".
673132720Skan       */
674117397Skan      bool
675169691Skan      empty() const
676169691Skan      { return this->size() == 0; }
67797403Sobrien
67897403Sobrien      // Element access:
679132720Skan      /**
680132720Skan       *  @brief  Subscript access to the data contained in the %string.
681169691Skan       *  @param  pos  The index of the character to access.
682132720Skan       *  @return  Read-only (constant) reference to the character.
683132720Skan       *
684132720Skan       *  This operator allows for easy, array-style, data access.
685132720Skan       *  Note that data access with this operator is unchecked and
686132720Skan       *  out_of_range lookups are not defined. (For checked lookups
687132720Skan       *  see at().)
688132720Skan       */
689117397Skan      const_reference
690117397Skan      operator[] (size_type __pos) const
691132720Skan      {
692132720Skan	_GLIBCXX_DEBUG_ASSERT(__pos <= size());
693132720Skan	return _M_data()[__pos];
694132720Skan      }
69597403Sobrien
696132720Skan      /**
697132720Skan       *  @brief  Subscript access to the data contained in the %string.
698169691Skan       *  @param  pos  The index of the character to access.
699132720Skan       *  @return  Read/write reference to the character.
700132720Skan       *
701132720Skan       *  This operator allows for easy, array-style, data access.
702132720Skan       *  Note that data access with this operator is unchecked and
703132720Skan       *  out_of_range lookups are not defined. (For checked lookups
704132720Skan       *  see at().)  Unshares the string.
705132720Skan       */
706117397Skan      reference
707117397Skan      operator[](size_type __pos)
708117397Skan      {
709169691Skan        // allow pos == size() as v3 extension:
710169691Skan	_GLIBCXX_DEBUG_ASSERT(__pos <= size());
711169691Skan        // but be strict in pedantic mode:
712169691Skan	_GLIBCXX_DEBUG_PEDASSERT(__pos < size());
713117397Skan	_M_leak();
714117397Skan	return _M_data()[__pos];
71597403Sobrien      }
71697403Sobrien
717132720Skan      /**
718132720Skan       *  @brief  Provides access to the data contained in the %string.
719132720Skan       *  @param n The index of the character to access.
720132720Skan       *  @return  Read-only (const) reference to the character.
721132720Skan       *  @throw  std::out_of_range  If @a n is an invalid index.
722132720Skan       *
723132720Skan       *  This function provides for safer data access.  The parameter is
724132720Skan       *  first checked that it is in the range of the string.  The function
725132720Skan       *  throws out_of_range if the check fails.
726132720Skan       */
727117397Skan      const_reference
72897403Sobrien      at(size_type __n) const
72997403Sobrien      {
73097403Sobrien	if (__n >= this->size())
731132720Skan	  __throw_out_of_range(__N("basic_string::at"));
732117397Skan	return _M_data()[__n];
73397403Sobrien      }
73497403Sobrien
735132720Skan      /**
736132720Skan       *  @brief  Provides access to the data contained in the %string.
737132720Skan       *  @param n The index of the character to access.
738132720Skan       *  @return  Read/write reference to the character.
739132720Skan       *  @throw  std::out_of_range  If @a n is an invalid index.
740132720Skan       *
741132720Skan       *  This function provides for safer data access.  The parameter is
742132720Skan       *  first checked that it is in the range of the string.  The function
743132720Skan       *  throws out_of_range if the check fails.  Success results in
744132720Skan       *  unsharing the string.
745132720Skan       */
746117397Skan      reference
74797403Sobrien      at(size_type __n)
74897403Sobrien      {
74997403Sobrien	if (__n >= size())
750132720Skan	  __throw_out_of_range(__N("basic_string::at"));
751117397Skan	_M_leak();
752117397Skan	return _M_data()[__n];
75397403Sobrien      }
75497403Sobrien
75597403Sobrien      // Modifiers:
756132720Skan      /**
757132720Skan       *  @brief  Append a string to this string.
758132720Skan       *  @param str  The string to append.
759132720Skan       *  @return  Reference to this string.
760132720Skan       */
761117397Skan      basic_string&
762169691Skan      operator+=(const basic_string& __str)
763169691Skan      { return this->append(__str); }
76497403Sobrien
765132720Skan      /**
766132720Skan       *  @brief  Append a C string.
767132720Skan       *  @param s  The C string to append.
768132720Skan       *  @return  Reference to this string.
769132720Skan       */
770117397Skan      basic_string&
771169691Skan      operator+=(const _CharT* __s)
772169691Skan      { return this->append(__s); }
77397403Sobrien
774132720Skan      /**
775132720Skan       *  @brief  Append a character.
776169691Skan       *  @param c  The character to append.
777132720Skan       *  @return  Reference to this string.
778132720Skan       */
779117397Skan      basic_string&
780169691Skan      operator+=(_CharT __c)
781169691Skan      {
782169691Skan	this->push_back(__c);
783169691Skan	return *this;
784169691Skan      }
78597403Sobrien
786132720Skan      /**
787132720Skan       *  @brief  Append a string to this string.
788132720Skan       *  @param str  The string to append.
789132720Skan       *  @return  Reference to this string.
790132720Skan       */
791117397Skan      basic_string&
79297403Sobrien      append(const basic_string& __str);
79397403Sobrien
794132720Skan      /**
795132720Skan       *  @brief  Append a substring.
796132720Skan       *  @param str  The string to append.
797132720Skan       *  @param pos  Index of the first character of str to append.
798132720Skan       *  @param n  The number of characters to append.
799132720Skan       *  @return  Reference to this string.
800132720Skan       *  @throw  std::out_of_range if @a pos is not a valid index.
801132720Skan       *
802132720Skan       *  This function appends @a n characters from @a str starting at @a pos
803132720Skan       *  to this string.  If @a n is is larger than the number of available
804132720Skan       *  characters in @a str, the remainder of @a str is appended.
805132720Skan       */
806117397Skan      basic_string&
80797403Sobrien      append(const basic_string& __str, size_type __pos, size_type __n);
80897403Sobrien
809132720Skan      /**
810132720Skan       *  @brief  Append a C substring.
811132720Skan       *  @param s  The C string to append.
812132720Skan       *  @param n  The number of characters to append.
813132720Skan       *  @return  Reference to this string.
814132720Skan       */
815117397Skan      basic_string&
81697403Sobrien      append(const _CharT* __s, size_type __n);
81797403Sobrien
818132720Skan      /**
819132720Skan       *  @brief  Append a C string.
820132720Skan       *  @param s  The C string to append.
821132720Skan       *  @return  Reference to this string.
822132720Skan       */
823117397Skan      basic_string&
82497403Sobrien      append(const _CharT* __s)
825132720Skan      {
826132720Skan	__glibcxx_requires_string(__s);
827132720Skan	return this->append(__s, traits_type::length(__s));
828132720Skan      }
82997403Sobrien
830132720Skan      /**
831132720Skan       *  @brief  Append multiple characters.
832132720Skan       *  @param n  The number of characters to append.
833132720Skan       *  @param c  The character to use.
834132720Skan       *  @return  Reference to this string.
835132720Skan       *
836132720Skan       *  Appends n copies of c to this string.
837132720Skan       */
838117397Skan      basic_string&
839169691Skan      append(size_type __n, _CharT __c);
84097403Sobrien
841132720Skan      /**
842132720Skan       *  @brief  Append a range of characters.
843132720Skan       *  @param first  Iterator referencing the first character to append.
844132720Skan       *  @param last  Iterator marking the end of the range.
845132720Skan       *  @return  Reference to this string.
846132720Skan       *
847132720Skan       *  Appends characters in the range [first,last) to this string.
848132720Skan       */
84997403Sobrien      template<class _InputIterator>
850117397Skan        basic_string&
85197403Sobrien        append(_InputIterator __first, _InputIterator __last)
85297403Sobrien        { return this->replace(_M_iend(), _M_iend(), __first, __last); }
85397403Sobrien
854132720Skan      /**
855132720Skan       *  @brief  Append a single character.
856132720Skan       *  @param c  Character to append.
857132720Skan       */
858117397Skan      void
85997403Sobrien      push_back(_CharT __c)
860169691Skan      {
861169691Skan	const size_type __len = 1 + this->size();
862169691Skan	if (__len > this->capacity() || _M_rep()->_M_is_shared())
863169691Skan	  this->reserve(__len);
864169691Skan	traits_type::assign(_M_data()[this->size()], __c);
865169691Skan	_M_rep()->_M_set_length_and_sharable(__len);
866169691Skan      }
86797403Sobrien
868132720Skan      /**
869132720Skan       *  @brief  Set value to contents of another string.
870132720Skan       *  @param  str  Source string to use.
871132720Skan       *  @return  Reference to this string.
872132720Skan       */
873117397Skan      basic_string&
87497403Sobrien      assign(const basic_string& __str);
87597403Sobrien
876132720Skan      /**
877132720Skan       *  @brief  Set value to a substring of a string.
878132720Skan       *  @param str  The string to use.
879132720Skan       *  @param pos  Index of the first character of str.
880132720Skan       *  @param n  Number of characters to use.
881132720Skan       *  @return  Reference to this string.
882132720Skan       *  @throw  std::out_of_range if @a pos is not a valid index.
883132720Skan       *
884132720Skan       *  This function sets this string to the substring of @a str consisting
885132720Skan       *  of @a n characters at @a pos.  If @a n is is larger than the number
886132720Skan       *  of available characters in @a str, the remainder of @a str is used.
887132720Skan       */
888117397Skan      basic_string&
889132720Skan      assign(const basic_string& __str, size_type __pos, size_type __n)
890132720Skan      { return this->assign(__str._M_data()
891132720Skan			    + __str._M_check(__pos, "basic_string::assign"),
892132720Skan			    __str._M_limit(__pos, __n)); }
89397403Sobrien
894132720Skan      /**
895132720Skan       *  @brief  Set value to a C substring.
896132720Skan       *  @param s  The C string to use.
897132720Skan       *  @param n  Number of characters to use.
898132720Skan       *  @return  Reference to this string.
899132720Skan       *
900132720Skan       *  This function sets the value of this string to the first @a n
901132720Skan       *  characters of @a s.  If @a n is is larger than the number of
902132720Skan       *  available characters in @a s, the remainder of @a s is used.
903132720Skan       */
904117397Skan      basic_string&
905117397Skan      assign(const _CharT* __s, size_type __n);
90697403Sobrien
907132720Skan      /**
908132720Skan       *  @brief  Set value to contents of a C string.
909132720Skan       *  @param s  The C string to use.
910132720Skan       *  @return  Reference to this string.
911132720Skan       *
912132720Skan       *  This function sets the value of this string to the value of @a s.
913132720Skan       *  The data is copied, so there is no dependence on @a s once the
914132720Skan       *  function returns.
915132720Skan       */
916117397Skan      basic_string&
91797403Sobrien      assign(const _CharT* __s)
918132720Skan      {
919132720Skan	__glibcxx_requires_string(__s);
920132720Skan	return this->assign(__s, traits_type::length(__s));
921132720Skan      }
92297403Sobrien
923132720Skan      /**
924132720Skan       *  @brief  Set value to multiple characters.
925132720Skan       *  @param n  Length of the resulting string.
926132720Skan       *  @param c  The character to use.
927132720Skan       *  @return  Reference to this string.
928132720Skan       *
929132720Skan       *  This function sets the value of this string to @a n copies of
930132720Skan       *  character @a c.
931132720Skan       */
932117397Skan      basic_string&
93397403Sobrien      assign(size_type __n, _CharT __c)
934132720Skan      { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
93597403Sobrien
936132720Skan      /**
937132720Skan       *  @brief  Set value to a range of characters.
938132720Skan       *  @param first  Iterator referencing the first character to append.
939132720Skan       *  @param last  Iterator marking the end of the range.
940132720Skan       *  @return  Reference to this string.
941132720Skan       *
942132720Skan       *  Sets value of string to characters in the range [first,last).
943132720Skan      */
94497403Sobrien      template<class _InputIterator>
945117397Skan        basic_string&
94697403Sobrien        assign(_InputIterator __first, _InputIterator __last)
94797403Sobrien        { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
94897403Sobrien
949132720Skan      /**
950132720Skan       *  @brief  Insert multiple characters.
951132720Skan       *  @param p  Iterator referencing location in string to insert at.
952132720Skan       *  @param n  Number of characters to insert
953132720Skan       *  @param c  The character to insert.
954132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
955132720Skan       *
956132720Skan       *  Inserts @a n copies of character @a c starting at the position
957132720Skan       *  referenced by iterator @a p.  If adding characters causes the length
958132720Skan       *  to exceed max_size(), length_error is thrown.  The value of the
959132720Skan       *  string doesn't change if an error is thrown.
960132720Skan      */
961117397Skan      void
96297403Sobrien      insert(iterator __p, size_type __n, _CharT __c)
96397403Sobrien      {	this->replace(__p, __p, __n, __c);  }
96497403Sobrien
965132720Skan      /**
966132720Skan       *  @brief  Insert a range of characters.
967132720Skan       *  @param p  Iterator referencing location in string to insert at.
968132720Skan       *  @param beg  Start of range.
969132720Skan       *  @param end  End of range.
970132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
971132720Skan       *
972132720Skan       *  Inserts characters in range [beg,end).  If adding characters causes
973132720Skan       *  the length to exceed max_size(), length_error is thrown.  The value
974132720Skan       *  of the string doesn't change if an error is thrown.
975132720Skan      */
97697403Sobrien      template<class _InputIterator>
977169691Skan        void
978169691Skan        insert(iterator __p, _InputIterator __beg, _InputIterator __end)
97997403Sobrien        { this->replace(__p, __p, __beg, __end); }
98097403Sobrien
981132720Skan      /**
982132720Skan       *  @brief  Insert value of a string.
983132720Skan       *  @param pos1  Iterator referencing location in string to insert at.
984132720Skan       *  @param str  The string to insert.
985132720Skan       *  @return  Reference to this string.
986132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
987132720Skan       *
988132720Skan       *  Inserts value of @a str starting at @a pos1.  If adding characters
989132720Skan       *  causes the length to exceed max_size(), length_error is thrown.  The
990132720Skan       *  value of the string doesn't change if an error is thrown.
991132720Skan      */
992117397Skan      basic_string&
99397403Sobrien      insert(size_type __pos1, const basic_string& __str)
994132720Skan      { return this->insert(__pos1, __str, size_type(0), __str.size()); }
99597403Sobrien
996132720Skan      /**
997132720Skan       *  @brief  Insert a substring.
998132720Skan       *  @param pos1  Iterator referencing location in string to insert at.
999132720Skan       *  @param str  The string to insert.
1000132720Skan       *  @param pos2  Start of characters in str to insert.
1001132720Skan       *  @param n  Number of characters to insert.
1002132720Skan       *  @return  Reference to this string.
1003132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1004132720Skan       *  @throw  std::out_of_range  If @a pos1 > size() or
1005132720Skan       *  @a pos2 > @a str.size().
1006132720Skan       *
1007132720Skan       *  Starting at @a pos1, insert @a n character of @a str beginning with
1008132720Skan       *  @a pos2.  If adding characters causes the length to exceed
1009132720Skan       *  max_size(), length_error is thrown.  If @a pos1 is beyond the end of
1010132720Skan       *  this string or @a pos2 is beyond the end of @a str, out_of_range is
1011132720Skan       *  thrown.  The value of the string doesn't change if an error is
1012132720Skan       *  thrown.
1013132720Skan      */
1014117397Skan      basic_string&
101597403Sobrien      insert(size_type __pos1, const basic_string& __str,
1016132720Skan	     size_type __pos2, size_type __n)
1017132720Skan      { return this->insert(__pos1, __str._M_data()
1018132720Skan			    + __str._M_check(__pos2, "basic_string::insert"),
1019132720Skan			    __str._M_limit(__pos2, __n)); }
102097403Sobrien
1021132720Skan      /**
1022132720Skan       *  @brief  Insert a C substring.
1023132720Skan       *  @param pos  Iterator referencing location in string to insert at.
1024132720Skan       *  @param s  The C string to insert.
1025132720Skan       *  @param n  The number of characters to insert.
1026132720Skan       *  @return  Reference to this string.
1027132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1028132720Skan       *  @throw  std::out_of_range  If @a pos is beyond the end of this
1029132720Skan       *  string.
1030132720Skan       *
1031132720Skan       *  Inserts the first @a n characters of @a s starting at @a pos.  If
1032132720Skan       *  adding characters causes the length to exceed max_size(),
1033132720Skan       *  length_error is thrown.  If @a pos is beyond end(), out_of_range is
1034132720Skan       *  thrown.  The value of the string doesn't change if an error is
1035132720Skan       *  thrown.
1036132720Skan      */
1037117397Skan      basic_string&
1038117397Skan      insert(size_type __pos, const _CharT* __s, size_type __n);
103997403Sobrien
1040132720Skan      /**
1041132720Skan       *  @brief  Insert a C string.
1042132720Skan       *  @param pos  Iterator referencing location in string to insert at.
1043132720Skan       *  @param s  The C string to insert.
1044132720Skan       *  @return  Reference to this string.
1045132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1046132720Skan       *  @throw  std::out_of_range  If @a pos is beyond the end of this
1047132720Skan       *  string.
1048132720Skan       *
1049132720Skan       *  Inserts the first @a n characters of @a s starting at @a pos.  If
1050132720Skan       *  adding characters causes the length to exceed max_size(),
1051132720Skan       *  length_error is thrown.  If @a pos is beyond end(), out_of_range is
1052132720Skan       *  thrown.  The value of the string doesn't change if an error is
1053132720Skan       *  thrown.
1054132720Skan      */
1055117397Skan      basic_string&
105697403Sobrien      insert(size_type __pos, const _CharT* __s)
1057132720Skan      {
1058132720Skan	__glibcxx_requires_string(__s);
1059132720Skan	return this->insert(__pos, __s, traits_type::length(__s));
1060132720Skan      }
106197403Sobrien
1062132720Skan      /**
1063132720Skan       *  @brief  Insert multiple characters.
1064132720Skan       *  @param pos  Index in string to insert at.
1065132720Skan       *  @param n  Number of characters to insert
1066132720Skan       *  @param c  The character to insert.
1067132720Skan       *  @return  Reference to this string.
1068132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1069132720Skan       *  @throw  std::out_of_range  If @a pos is beyond the end of this
1070132720Skan       *  string.
1071132720Skan       *
1072132720Skan       *  Inserts @a n copies of character @a c starting at index @a pos.  If
1073132720Skan       *  adding characters causes the length to exceed max_size(),
1074132720Skan       *  length_error is thrown.  If @a pos > length(), out_of_range is
1075132720Skan       *  thrown.  The value of the string doesn't change if an error is
1076132720Skan       *  thrown.
1077132720Skan      */
1078117397Skan      basic_string&
107997403Sobrien      insert(size_type __pos, size_type __n, _CharT __c)
1080132720Skan      { return _M_replace_aux(_M_check(__pos, "basic_string::insert"),
1081132720Skan			      size_type(0), __n, __c); }
108297403Sobrien
1083132720Skan      /**
1084132720Skan       *  @brief  Insert one character.
1085132720Skan       *  @param p  Iterator referencing position in string to insert at.
1086132720Skan       *  @param c  The character to insert.
1087132720Skan       *  @return  Iterator referencing newly inserted char.
1088132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1089132720Skan       *
1090132720Skan       *  Inserts character @a c at position referenced by @a p.  If adding
1091132720Skan       *  character causes the length to exceed max_size(), length_error is
1092132720Skan       *  thrown.  If @a p is beyond end of string, out_of_range is thrown.
1093132720Skan       *  The value of the string doesn't change if an error is thrown.
1094132720Skan      */
1095117397Skan      iterator
1096132720Skan      insert(iterator __p, _CharT __c)
109797403Sobrien      {
1098132720Skan	_GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1099132720Skan	const size_type __pos = __p - _M_ibegin();
1100132720Skan	_M_replace_aux(__pos, size_type(0), size_type(1), __c);
1101117397Skan	_M_rep()->_M_set_leaked();
1102169691Skan	return iterator(_M_data() + __pos);
110397403Sobrien      }
110497403Sobrien
1105132720Skan      /**
1106132720Skan       *  @brief  Remove characters.
1107132720Skan       *  @param pos  Index of first character to remove (default 0).
1108132720Skan       *  @param n  Number of characters to remove (default remainder).
1109132720Skan       *  @return  Reference to this string.
1110132720Skan       *  @throw  std::out_of_range  If @a pos is beyond the end of this
1111132720Skan       *  string.
1112132720Skan       *
1113132720Skan       *  Removes @a n characters from this string starting at @a pos.  The
1114132720Skan       *  length of the string is reduced by @a n.  If there are < @a n
1115132720Skan       *  characters to remove, the remainder of the string is truncated.  If
1116132720Skan       *  @a p is beyond end of string, out_of_range is thrown.  The value of
1117132720Skan       *  the string doesn't change if an error is thrown.
1118132720Skan      */
1119117397Skan      basic_string&
112097403Sobrien      erase(size_type __pos = 0, size_type __n = npos)
1121169691Skan      {
1122169691Skan	_M_mutate(_M_check(__pos, "basic_string::erase"),
1123169691Skan		  _M_limit(__pos, __n), size_type(0));
1124169691Skan	return *this;
1125169691Skan      }
112697403Sobrien
1127132720Skan      /**
1128132720Skan       *  @brief  Remove one character.
1129132720Skan       *  @param position  Iterator referencing the character to remove.
1130132720Skan       *  @return  iterator referencing same location after removal.
1131132720Skan       *
1132132720Skan       *  Removes the character at @a position from this string. The value
1133132720Skan       *  of the string doesn't change if an error is thrown.
1134132720Skan      */
1135117397Skan      iterator
113697403Sobrien      erase(iterator __position)
113797403Sobrien      {
1138132720Skan	_GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1139132720Skan				 && __position < _M_iend());
1140132720Skan	const size_type __pos = __position - _M_ibegin();
1141169691Skan	_M_mutate(__pos, size_type(1), size_type(0));
1142117397Skan	_M_rep()->_M_set_leaked();
1143169691Skan	return iterator(_M_data() + __pos);
114497403Sobrien      }
114597403Sobrien
1146132720Skan      /**
1147132720Skan       *  @brief  Remove a range of characters.
1148132720Skan       *  @param first  Iterator referencing the first character to remove.
1149132720Skan       *  @param last  Iterator referencing the end of the range.
1150132720Skan       *  @return  Iterator referencing location of first after removal.
1151132720Skan       *
1152132720Skan       *  Removes the characters in the range [first,last) from this string.
1153132720Skan       *  The value of the string doesn't change if an error is thrown.
1154132720Skan      */
1155117397Skan      iterator
115697403Sobrien      erase(iterator __first, iterator __last)
115797403Sobrien      {
1158132720Skan	_GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1159132720Skan				 && __last <= _M_iend());
1160132720Skan        const size_type __pos = __first - _M_ibegin();
1161169691Skan	_M_mutate(__pos, __last - __first, size_type(0));
116297403Sobrien	_M_rep()->_M_set_leaked();
1163169691Skan	return iterator(_M_data() + __pos);
116497403Sobrien      }
116597403Sobrien
1166132720Skan      /**
1167132720Skan       *  @brief  Replace characters with value from another string.
1168132720Skan       *  @param pos  Index of first character to replace.
1169132720Skan       *  @param n  Number of characters to be replaced.
1170132720Skan       *  @param str  String to insert.
1171132720Skan       *  @return  Reference to this string.
1172132720Skan       *  @throw  std::out_of_range  If @a pos is beyond the end of this
1173132720Skan       *  string.
1174132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1175132720Skan       *
1176132720Skan       *  Removes the characters in the range [pos,pos+n) from this string.
1177132720Skan       *  In place, the value of @a str is inserted.  If @a pos is beyond end
1178132720Skan       *  of string, out_of_range is thrown.  If the length of the result
1179132720Skan       *  exceeds max_size(), length_error is thrown.  The value of the string
1180132720Skan       *  doesn't change if an error is thrown.
1181132720Skan      */
1182117397Skan      basic_string&
118397403Sobrien      replace(size_type __pos, size_type __n, const basic_string& __str)
118497403Sobrien      { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
118597403Sobrien
1186132720Skan      /**
1187132720Skan       *  @brief  Replace characters with value from another string.
1188132720Skan       *  @param pos1  Index of first character to replace.
1189132720Skan       *  @param n1  Number of characters to be replaced.
1190132720Skan       *  @param str  String to insert.
1191132720Skan       *  @param pos2  Index of first character of str to use.
1192132720Skan       *  @param n2  Number of characters from str to use.
1193132720Skan       *  @return  Reference to this string.
1194132720Skan       *  @throw  std::out_of_range  If @a pos1 > size() or @a pos2 >
1195132720Skan       *  str.size().
1196132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1197132720Skan       *
1198132720Skan       *  Removes the characters in the range [pos1,pos1 + n) from this
1199132720Skan       *  string.  In place, the value of @a str is inserted.  If @a pos is
1200132720Skan       *  beyond end of string, out_of_range is thrown.  If the length of the
1201132720Skan       *  result exceeds max_size(), length_error is thrown.  The value of the
1202132720Skan       *  string doesn't change if an error is thrown.
1203132720Skan      */
1204117397Skan      basic_string&
120597403Sobrien      replace(size_type __pos1, size_type __n1, const basic_string& __str,
1206132720Skan	      size_type __pos2, size_type __n2)
1207132720Skan      { return this->replace(__pos1, __n1, __str._M_data()
1208132720Skan			     + __str._M_check(__pos2, "basic_string::replace"),
1209132720Skan			     __str._M_limit(__pos2, __n2)); }
121097403Sobrien
1211132720Skan      /**
1212132720Skan       *  @brief  Replace characters with value of a C substring.
1213132720Skan       *  @param pos  Index of first character to replace.
1214132720Skan       *  @param n1  Number of characters to be replaced.
1215169691Skan       *  @param s  C string to insert.
1216169691Skan       *  @param n2  Number of characters from @a s to use.
1217132720Skan       *  @return  Reference to this string.
1218132720Skan       *  @throw  std::out_of_range  If @a pos1 > size().
1219132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1220132720Skan       *
1221132720Skan       *  Removes the characters in the range [pos,pos + n1) from this string.
1222169691Skan       *  In place, the first @a n2 characters of @a s are inserted, or all
1223169691Skan       *  of @a s if @a n2 is too large.  If @a pos is beyond end of string,
1224132720Skan       *  out_of_range is thrown.  If the length of result exceeds max_size(),
1225132720Skan       *  length_error is thrown.  The value of the string doesn't change if
1226132720Skan       *  an error is thrown.
1227132720Skan      */
1228117397Skan      basic_string&
122997403Sobrien      replace(size_type __pos, size_type __n1, const _CharT* __s,
1230117397Skan	      size_type __n2);
123197403Sobrien
1232132720Skan      /**
1233132720Skan       *  @brief  Replace characters with value of a C string.
1234132720Skan       *  @param pos  Index of first character to replace.
1235132720Skan       *  @param n1  Number of characters to be replaced.
1236169691Skan       *  @param s  C string to insert.
1237132720Skan       *  @return  Reference to this string.
1238132720Skan       *  @throw  std::out_of_range  If @a pos > size().
1239132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1240132720Skan       *
1241132720Skan       *  Removes the characters in the range [pos,pos + n1) from this string.
1242169691Skan       *  In place, the first @a n characters of @a s are inserted.  If @a
1243132720Skan       *  pos is beyond end of string, out_of_range is thrown.  If the length
1244132720Skan       *  of result exceeds max_size(), length_error is thrown.  The value of
1245132720Skan       *  the string doesn't change if an error is thrown.
1246132720Skan      */
1247117397Skan      basic_string&
124897403Sobrien      replace(size_type __pos, size_type __n1, const _CharT* __s)
1249132720Skan      {
1250132720Skan	__glibcxx_requires_string(__s);
1251132720Skan	return this->replace(__pos, __n1, __s, traits_type::length(__s));
1252132720Skan      }
125397403Sobrien
1254132720Skan      /**
1255132720Skan       *  @brief  Replace characters with multiple characters.
1256132720Skan       *  @param pos  Index of first character to replace.
1257132720Skan       *  @param n1  Number of characters to be replaced.
1258132720Skan       *  @param n2  Number of characters to insert.
1259132720Skan       *  @param c  Character to insert.
1260132720Skan       *  @return  Reference to this string.
1261132720Skan       *  @throw  std::out_of_range  If @a pos > size().
1262132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1263132720Skan       *
1264132720Skan       *  Removes the characters in the range [pos,pos + n1) from this string.
1265132720Skan       *  In place, @a n2 copies of @a c are inserted.  If @a pos is beyond
1266132720Skan       *  end of string, out_of_range is thrown.  If the length of result
1267132720Skan       *  exceeds max_size(), length_error is thrown.  The value of the string
1268132720Skan       *  doesn't change if an error is thrown.
1269132720Skan      */
1270117397Skan      basic_string&
127197403Sobrien      replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1272132720Skan      { return _M_replace_aux(_M_check(__pos, "basic_string::replace"),
1273132720Skan			      _M_limit(__pos, __n1), __n2, __c); }
127497403Sobrien
1275132720Skan      /**
1276132720Skan       *  @brief  Replace range of characters with string.
1277132720Skan       *  @param i1  Iterator referencing start of range to replace.
1278132720Skan       *  @param i2  Iterator referencing end of range to replace.
1279132720Skan       *  @param str  String value to insert.
1280132720Skan       *  @return  Reference to this string.
1281132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1282132720Skan       *
1283132720Skan       *  Removes the characters in the range [i1,i2).  In place, the value of
1284132720Skan       *  @a str is inserted.  If the length of result exceeds max_size(),
1285132720Skan       *  length_error is thrown.  The value of the string doesn't change if
1286132720Skan       *  an error is thrown.
1287132720Skan      */
1288117397Skan      basic_string&
128997403Sobrien      replace(iterator __i1, iterator __i2, const basic_string& __str)
129097403Sobrien      { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
129197403Sobrien
1292132720Skan      /**
1293132720Skan       *  @brief  Replace range of characters with C substring.
1294132720Skan       *  @param i1  Iterator referencing start of range to replace.
1295132720Skan       *  @param i2  Iterator referencing end of range to replace.
1296132720Skan       *  @param s  C string value to insert.
1297132720Skan       *  @param n  Number of characters from s to insert.
1298132720Skan       *  @return  Reference to this string.
1299132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1300132720Skan       *
1301132720Skan       *  Removes the characters in the range [i1,i2).  In place, the first @a
1302132720Skan       *  n characters of @a s are inserted.  If the length of result exceeds
1303132720Skan       *  max_size(), length_error is thrown.  The value of the string doesn't
1304132720Skan       *  change if an error is thrown.
1305132720Skan      */
1306117397Skan      basic_string&
1307132720Skan      replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1308132720Skan      {
1309132720Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1310132720Skan				 && __i2 <= _M_iend());
1311132720Skan	return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1312132720Skan      }
131397403Sobrien
1314132720Skan      /**
1315132720Skan       *  @brief  Replace range of characters with C string.
1316132720Skan       *  @param i1  Iterator referencing start of range to replace.
1317132720Skan       *  @param i2  Iterator referencing end of range to replace.
1318132720Skan       *  @param s  C string value to insert.
1319132720Skan       *  @return  Reference to this string.
1320132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1321132720Skan       *
1322132720Skan       *  Removes the characters in the range [i1,i2).  In place, the
1323132720Skan       *  characters of @a s are inserted.  If the length of result exceeds
1324132720Skan       *  max_size(), length_error is thrown.  The value of the string doesn't
1325132720Skan       *  change if an error is thrown.
1326132720Skan      */
1327117397Skan      basic_string&
132897403Sobrien      replace(iterator __i1, iterator __i2, const _CharT* __s)
1329132720Skan      {
1330132720Skan	__glibcxx_requires_string(__s);
1331132720Skan	return this->replace(__i1, __i2, __s, traits_type::length(__s));
1332132720Skan      }
133397403Sobrien
1334132720Skan      /**
1335132720Skan       *  @brief  Replace range of characters with multiple characters
1336132720Skan       *  @param i1  Iterator referencing start of range to replace.
1337132720Skan       *  @param i2  Iterator referencing end of range to replace.
1338132720Skan       *  @param n  Number of characters to insert.
1339132720Skan       *  @param c  Character to insert.
1340132720Skan       *  @return  Reference to this string.
1341132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1342132720Skan       *
1343132720Skan       *  Removes the characters in the range [i1,i2).  In place, @a n copies
1344132720Skan       *  of @a c are inserted.  If the length of result exceeds max_size(),
1345132720Skan       *  length_error is thrown.  The value of the string doesn't change if
1346132720Skan       *  an error is thrown.
1347132720Skan      */
1348117397Skan      basic_string&
1349132720Skan      replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1350132720Skan      {
1351132720Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1352132720Skan				 && __i2 <= _M_iend());
1353132720Skan	return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1354132720Skan      }
135597403Sobrien
1356132720Skan      /**
1357132720Skan       *  @brief  Replace range of characters with range.
1358132720Skan       *  @param i1  Iterator referencing start of range to replace.
1359132720Skan       *  @param i2  Iterator referencing end of range to replace.
1360132720Skan       *  @param k1  Iterator referencing start of range to insert.
1361132720Skan       *  @param k2  Iterator referencing end of range to insert.
1362132720Skan       *  @return  Reference to this string.
1363132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1364132720Skan       *
1365132720Skan       *  Removes the characters in the range [i1,i2).  In place, characters
1366132720Skan       *  in the range [k1,k2) are inserted.  If the length of result exceeds
1367132720Skan       *  max_size(), length_error is thrown.  The value of the string doesn't
1368132720Skan       *  change if an error is thrown.
1369132720Skan      */
137097403Sobrien      template<class _InputIterator>
1371117397Skan        basic_string&
137297403Sobrien        replace(iterator __i1, iterator __i2,
137397403Sobrien		_InputIterator __k1, _InputIterator __k2)
1374132720Skan        {
1375132720Skan	  _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1376132720Skan				   && __i2 <= _M_iend());
1377132720Skan	  __glibcxx_requires_valid_range(__k1, __k2);
1378169691Skan	  typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1379132720Skan	  return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1380132720Skan	}
138197403Sobrien
1382102782Skan      // Specializations for the common case of pointer and iterator:
1383102782Skan      // useful to avoid the overhead of temporary buffering in _M_replace.
1384117397Skan      basic_string&
1385169691Skan      replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1386169691Skan      {
1387169691Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1388169691Skan				 && __i2 <= _M_iend());
1389169691Skan	__glibcxx_requires_valid_range(__k1, __k2);
1390169691Skan	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1391169691Skan			     __k1, __k2 - __k1);
1392169691Skan      }
1393102782Skan
1394117397Skan      basic_string&
1395169691Skan      replace(iterator __i1, iterator __i2,
1396169691Skan	      const _CharT* __k1, const _CharT* __k2)
1397169691Skan      {
1398169691Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1399169691Skan				 && __i2 <= _M_iend());
1400169691Skan	__glibcxx_requires_valid_range(__k1, __k2);
1401169691Skan	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1402169691Skan			     __k1, __k2 - __k1);
1403169691Skan      }
1404102782Skan
1405117397Skan      basic_string&
1406169691Skan      replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1407169691Skan      {
1408169691Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1409169691Skan				 && __i2 <= _M_iend());
1410169691Skan	__glibcxx_requires_valid_range(__k1, __k2);
1411169691Skan	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1412169691Skan			     __k1.base(), __k2 - __k1);
1413169691Skan      }
1414102782Skan
1415117397Skan      basic_string&
1416169691Skan      replace(iterator __i1, iterator __i2,
1417169691Skan	      const_iterator __k1, const_iterator __k2)
1418169691Skan      {
1419169691Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1420169691Skan				 && __i2 <= _M_iend());
1421169691Skan	__glibcxx_requires_valid_range(__k1, __k2);
1422169691Skan	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1423169691Skan			     __k1.base(), __k2 - __k1);
1424169691Skan      }
1425169691Skan
142697403Sobrien    private:
1427132720Skan      template<class _Integer>
1428132720Skan	basic_string&
1429132720Skan	_M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1430132720Skan			    _Integer __val, __true_type)
1431132720Skan        { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1432132720Skan
143397403Sobrien      template<class _InputIterator>
1434132720Skan	basic_string&
1435132720Skan	_M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1436132720Skan			    _InputIterator __k2, __false_type);
143797403Sobrien
1438132720Skan      basic_string&
1439132720Skan      _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1440169691Skan		     _CharT __c);
144197403Sobrien
1442132720Skan      basic_string&
1443132720Skan      _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s,
1444169691Skan		      size_type __n2);
1445132720Skan
144697403Sobrien      // _S_construct_aux is used to implement the 21.3.1 para 15 which
144797403Sobrien      // requires special behaviour if _InIter is an integral type
1448132720Skan      template<class _InIterator>
144997403Sobrien        static _CharT*
1450132720Skan        _S_construct_aux(_InIterator __beg, _InIterator __end,
1451132720Skan			 const _Alloc& __a, __false_type)
145297403Sobrien	{
1453132720Skan          typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
145497403Sobrien          return _S_construct(__beg, __end, __a, _Tag());
145597403Sobrien	}
1456117397Skan
1457132720Skan      template<class _InIterator>
145897403Sobrien        static _CharT*
1459132720Skan        _S_construct_aux(_InIterator __beg, _InIterator __end,
1460132720Skan			 const _Alloc& __a, __true_type)
1461132720Skan	{ return _S_construct(static_cast<size_type>(__beg),
1462132720Skan			      static_cast<value_type>(__end), __a); }
1463117397Skan
1464132720Skan      template<class _InIterator>
146597403Sobrien        static _CharT*
1466132720Skan        _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a)
146797403Sobrien	{
1468169691Skan	  typedef typename std::__is_integer<_InIterator>::__type _Integral;
146997403Sobrien	  return _S_construct_aux(__beg, __end, __a, _Integral());
147097403Sobrien        }
147197403Sobrien
147297403Sobrien      // For Input Iterators, used in istreambuf_iterators, etc.
1473132720Skan      template<class _InIterator>
147497403Sobrien        static _CharT*
1475132720Skan         _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
147697403Sobrien		      input_iterator_tag);
1477117397Skan
147897403Sobrien      // For forward_iterators up to random_access_iterators, used for
147997403Sobrien      // string::iterator, _CharT*, etc.
1480132720Skan      template<class _FwdIterator>
148197403Sobrien        static _CharT*
1482132720Skan        _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a,
148397403Sobrien		     forward_iterator_tag);
148497403Sobrien
1485117397Skan      static _CharT*
148697403Sobrien      _S_construct(size_type __req, _CharT __c, const _Alloc& __a);
148797403Sobrien
148897403Sobrien    public:
148997403Sobrien
1490132720Skan      /**
1491132720Skan       *  @brief  Copy substring into C string.
1492132720Skan       *  @param s  C string to copy value into.
1493132720Skan       *  @param n  Number of characters to copy.
1494132720Skan       *  @param pos  Index of first character to copy.
1495132720Skan       *  @return  Number of characters actually copied
1496132720Skan       *  @throw  std::out_of_range  If pos > size().
1497132720Skan       *
1498132720Skan       *  Copies up to @a n characters starting at @a pos into the C string @a
1499132720Skan       *  s.  If @a pos is greater than size(), out_of_range is thrown.
1500132720Skan      */
1501117397Skan      size_type
150297403Sobrien      copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
150397403Sobrien
1504132720Skan      /**
1505132720Skan       *  @brief  Swap contents with another string.
1506132720Skan       *  @param s  String to swap with.
1507132720Skan       *
1508132720Skan       *  Exchanges the contents of this string with that of @a s in constant
1509132720Skan       *  time.
1510132720Skan      */
1511117397Skan      void
1512132720Skan      swap(basic_string& __s);
151397403Sobrien
151497403Sobrien      // String operations:
1515132720Skan      /**
1516132720Skan       *  @brief  Return const pointer to null-terminated contents.
1517132720Skan       *
1518132720Skan       *  This is a handle to internal data.  Do not modify or dire things may
1519132720Skan       *  happen.
1520132720Skan      */
1521117397Skan      const _CharT*
1522169691Skan      c_str() const
1523169691Skan      { return _M_data(); }
152497403Sobrien
1525132720Skan      /**
1526132720Skan       *  @brief  Return const pointer to contents.
1527132720Skan       *
1528132720Skan       *  This is a handle to internal data.  Do not modify or dire things may
1529132720Skan       *  happen.
1530132720Skan      */
1531117397Skan      const _CharT*
1532169691Skan      data() const
1533169691Skan      { return _M_data(); }
153497403Sobrien
1535132720Skan      /**
1536132720Skan       *  @brief  Return copy of allocator used to construct this string.
1537132720Skan      */
1538117397Skan      allocator_type
1539169691Skan      get_allocator() const
1540169691Skan      { return _M_dataplus; }
154197403Sobrien
1542132720Skan      /**
1543132720Skan       *  @brief  Find position of a C substring.
1544132720Skan       *  @param s  C string to locate.
1545132720Skan       *  @param pos  Index of character to search from.
1546132720Skan       *  @param n  Number of characters from @a s to search for.
1547132720Skan       *  @return  Index of start of first occurrence.
1548132720Skan       *
1549132720Skan       *  Starting from @a pos, searches forward for the first @a n characters
1550132720Skan       *  in @a s within this string.  If found, returns the index where it
1551132720Skan       *  begins.  If not found, returns npos.
1552132720Skan      */
1553117397Skan      size_type
155497403Sobrien      find(const _CharT* __s, size_type __pos, size_type __n) const;
155597403Sobrien
1556132720Skan      /**
1557132720Skan       *  @brief  Find position of a string.
1558132720Skan       *  @param str  String to locate.
1559132720Skan       *  @param pos  Index of character to search from (default 0).
1560132720Skan       *  @return  Index of start of first occurrence.
1561132720Skan       *
1562132720Skan       *  Starting from @a pos, searches forward for value of @a str within
1563132720Skan       *  this string.  If found, returns the index where it begins.  If not
1564132720Skan       *  found, returns npos.
1565132720Skan      */
1566117397Skan      size_type
156797403Sobrien      find(const basic_string& __str, size_type __pos = 0) const
156897403Sobrien      { return this->find(__str.data(), __pos, __str.size()); }
156997403Sobrien
1570132720Skan      /**
1571132720Skan       *  @brief  Find position of a C string.
1572132720Skan       *  @param s  C string to locate.
1573132720Skan       *  @param pos  Index of character to search from (default 0).
1574132720Skan       *  @return  Index of start of first occurrence.
1575132720Skan       *
1576132720Skan       *  Starting from @a pos, searches forward for the value of @a s within
1577132720Skan       *  this string.  If found, returns the index where it begins.  If not
1578132720Skan       *  found, returns npos.
1579132720Skan      */
1580117397Skan      size_type
158197403Sobrien      find(const _CharT* __s, size_type __pos = 0) const
1582132720Skan      {
1583132720Skan	__glibcxx_requires_string(__s);
1584132720Skan	return this->find(__s, __pos, traits_type::length(__s));
1585132720Skan      }
158697403Sobrien
1587132720Skan      /**
1588132720Skan       *  @brief  Find position of a character.
1589132720Skan       *  @param c  Character to locate.
1590132720Skan       *  @param pos  Index of character to search from (default 0).
1591132720Skan       *  @return  Index of first occurrence.
1592132720Skan       *
1593132720Skan       *  Starting from @a pos, searches forward for @a c within this string.
1594132720Skan       *  If found, returns the index where it was found.  If not found,
1595132720Skan       *  returns npos.
1596132720Skan      */
1597117397Skan      size_type
159897403Sobrien      find(_CharT __c, size_type __pos = 0) const;
159997403Sobrien
1600132720Skan      /**
1601132720Skan       *  @brief  Find last position of a string.
1602132720Skan       *  @param str  String to locate.
1603132720Skan       *  @param pos  Index of character to search back from (default end).
1604132720Skan       *  @return  Index of start of last occurrence.
1605132720Skan       *
1606132720Skan       *  Starting from @a pos, searches backward for value of @a str within
1607132720Skan       *  this string.  If found, returns the index where it begins.  If not
1608132720Skan       *  found, returns npos.
1609132720Skan      */
1610117397Skan      size_type
161197403Sobrien      rfind(const basic_string& __str, size_type __pos = npos) const
161297403Sobrien      { return this->rfind(__str.data(), __pos, __str.size()); }
161397403Sobrien
1614132720Skan      /**
1615132720Skan       *  @brief  Find last position of a C substring.
1616132720Skan       *  @param s  C string to locate.
1617132720Skan       *  @param pos  Index of character to search back from.
1618132720Skan       *  @param n  Number of characters from s to search for.
1619132720Skan       *  @return  Index of start of last occurrence.
1620132720Skan       *
1621132720Skan       *  Starting from @a pos, searches backward for the first @a n
1622132720Skan       *  characters in @a s within this string.  If found, returns the index
1623132720Skan       *  where it begins.  If not found, returns npos.
1624132720Skan      */
1625117397Skan      size_type
162697403Sobrien      rfind(const _CharT* __s, size_type __pos, size_type __n) const;
162797403Sobrien
1628132720Skan      /**
1629132720Skan       *  @brief  Find last position of a C string.
1630132720Skan       *  @param s  C string to locate.
1631169691Skan       *  @param pos  Index of character to start search at (default end).
1632132720Skan       *  @return  Index of start of  last occurrence.
1633132720Skan       *
1634132720Skan       *  Starting from @a pos, searches backward for the value of @a s within
1635132720Skan       *  this string.  If found, returns the index where it begins.  If not
1636132720Skan       *  found, returns npos.
1637132720Skan      */
1638117397Skan      size_type
163997403Sobrien      rfind(const _CharT* __s, size_type __pos = npos) const
1640132720Skan      {
1641132720Skan	__glibcxx_requires_string(__s);
1642132720Skan	return this->rfind(__s, __pos, traits_type::length(__s));
1643132720Skan      }
164497403Sobrien
1645132720Skan      /**
1646132720Skan       *  @brief  Find last position of a character.
1647132720Skan       *  @param c  Character to locate.
1648169691Skan       *  @param pos  Index of character to search back from (default end).
1649132720Skan       *  @return  Index of last occurrence.
1650132720Skan       *
1651132720Skan       *  Starting from @a pos, searches backward for @a c within this string.
1652132720Skan       *  If found, returns the index where it was found.  If not found,
1653132720Skan       *  returns npos.
1654132720Skan      */
1655117397Skan      size_type
165697403Sobrien      rfind(_CharT __c, size_type __pos = npos) const;
165797403Sobrien
1658132720Skan      /**
1659132720Skan       *  @brief  Find position of a character of string.
1660132720Skan       *  @param str  String containing characters to locate.
1661132720Skan       *  @param pos  Index of character to search from (default 0).
1662132720Skan       *  @return  Index of first occurrence.
1663132720Skan       *
1664132720Skan       *  Starting from @a pos, searches forward for one of the characters of
1665132720Skan       *  @a str within this string.  If found, returns the index where it was
1666132720Skan       *  found.  If not found, returns npos.
1667132720Skan      */
1668117397Skan      size_type
166997403Sobrien      find_first_of(const basic_string& __str, size_type __pos = 0) const
167097403Sobrien      { return this->find_first_of(__str.data(), __pos, __str.size()); }
167197403Sobrien
1672132720Skan      /**
1673132720Skan       *  @brief  Find position of a character of C substring.
1674132720Skan       *  @param s  String containing characters to locate.
1675228780Spfg       *  @param pos  Index of character to search from.
1676132720Skan       *  @param n  Number of characters from s to search for.
1677132720Skan       *  @return  Index of first occurrence.
1678132720Skan       *
1679132720Skan       *  Starting from @a pos, searches forward for one of the first @a n
1680132720Skan       *  characters of @a s within this string.  If found, returns the index
1681132720Skan       *  where it was found.  If not found, returns npos.
1682132720Skan      */
1683117397Skan      size_type
168497403Sobrien      find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
168597403Sobrien
1686132720Skan      /**
1687132720Skan       *  @brief  Find position of a character of C string.
1688132720Skan       *  @param s  String containing characters to locate.
1689132720Skan       *  @param pos  Index of character to search from (default 0).
1690132720Skan       *  @return  Index of first occurrence.
1691132720Skan       *
1692132720Skan       *  Starting from @a pos, searches forward for one of the characters of
1693132720Skan       *  @a s within this string.  If found, returns the index where it was
1694132720Skan       *  found.  If not found, returns npos.
1695132720Skan      */
1696117397Skan      size_type
169797403Sobrien      find_first_of(const _CharT* __s, size_type __pos = 0) const
1698132720Skan      {
1699132720Skan	__glibcxx_requires_string(__s);
1700132720Skan	return this->find_first_of(__s, __pos, traits_type::length(__s));
1701132720Skan      }
170297403Sobrien
1703132720Skan      /**
1704132720Skan       *  @brief  Find position of a character.
1705132720Skan       *  @param c  Character to locate.
1706132720Skan       *  @param pos  Index of character to search from (default 0).
1707132720Skan       *  @return  Index of first occurrence.
1708132720Skan       *
1709132720Skan       *  Starting from @a pos, searches forward for the character @a c within
1710132720Skan       *  this string.  If found, returns the index where it was found.  If
1711132720Skan       *  not found, returns npos.
1712132720Skan       *
1713132720Skan       *  Note: equivalent to find(c, pos).
1714132720Skan      */
1715117397Skan      size_type
171697403Sobrien      find_first_of(_CharT __c, size_type __pos = 0) const
171797403Sobrien      { return this->find(__c, __pos); }
171897403Sobrien
1719132720Skan      /**
1720132720Skan       *  @brief  Find last position of a character of string.
1721132720Skan       *  @param str  String containing characters to locate.
1722132720Skan       *  @param pos  Index of character to search back from (default end).
1723132720Skan       *  @return  Index of last occurrence.
1724132720Skan       *
1725132720Skan       *  Starting from @a pos, searches backward for one of the characters of
1726132720Skan       *  @a str within this string.  If found, returns the index where it was
1727132720Skan       *  found.  If not found, returns npos.
1728132720Skan      */
1729117397Skan      size_type
173097403Sobrien      find_last_of(const basic_string& __str, size_type __pos = npos) const
173197403Sobrien      { return this->find_last_of(__str.data(), __pos, __str.size()); }
173297403Sobrien
1733132720Skan      /**
1734132720Skan       *  @brief  Find last position of a character of C substring.
1735132720Skan       *  @param s  C string containing characters to locate.
1736228780Spfg       *  @param pos  Index of character to search back from.
1737132720Skan       *  @param n  Number of characters from s to search for.
1738132720Skan       *  @return  Index of last occurrence.
1739132720Skan       *
1740132720Skan       *  Starting from @a pos, searches backward for one of the first @a n
1741132720Skan       *  characters of @a s within this string.  If found, returns the index
1742132720Skan       *  where it was found.  If not found, returns npos.
1743132720Skan      */
1744117397Skan      size_type
174597403Sobrien      find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
174697403Sobrien
1747132720Skan      /**
1748132720Skan       *  @brief  Find last position of a character of C string.
1749132720Skan       *  @param s  C string containing characters to locate.
1750132720Skan       *  @param pos  Index of character to search back from (default end).
1751132720Skan       *  @return  Index of last occurrence.
1752132720Skan       *
1753132720Skan       *  Starting from @a pos, searches backward for one of the characters of
1754132720Skan       *  @a s within this string.  If found, returns the index where it was
1755132720Skan       *  found.  If not found, returns npos.
1756132720Skan      */
1757117397Skan      size_type
175897403Sobrien      find_last_of(const _CharT* __s, size_type __pos = npos) const
1759132720Skan      {
1760132720Skan	__glibcxx_requires_string(__s);
1761132720Skan	return this->find_last_of(__s, __pos, traits_type::length(__s));
1762132720Skan      }
176397403Sobrien
1764132720Skan      /**
1765132720Skan       *  @brief  Find last position of a character.
1766132720Skan       *  @param c  Character to locate.
1767228780Spfg       *  @param pos  Index of character to search back from (default end).
1768132720Skan       *  @return  Index of last occurrence.
1769132720Skan       *
1770132720Skan       *  Starting from @a pos, searches backward for @a c within this string.
1771132720Skan       *  If found, returns the index where it was found.  If not found,
1772132720Skan       *  returns npos.
1773132720Skan       *
1774132720Skan       *  Note: equivalent to rfind(c, pos).
1775132720Skan      */
1776117397Skan      size_type
177797403Sobrien      find_last_of(_CharT __c, size_type __pos = npos) const
177897403Sobrien      { return this->rfind(__c, __pos); }
177997403Sobrien
1780132720Skan      /**
1781132720Skan       *  @brief  Find position of a character not in string.
1782132720Skan       *  @param str  String containing characters to avoid.
1783132720Skan       *  @param pos  Index of character to search from (default 0).
1784132720Skan       *  @return  Index of first occurrence.
1785132720Skan       *
1786132720Skan       *  Starting from @a pos, searches forward for a character not contained
1787132720Skan       *  in @a str within this string.  If found, returns the index where it
1788132720Skan       *  was found.  If not found, returns npos.
1789132720Skan      */
1790117397Skan      size_type
179197403Sobrien      find_first_not_of(const basic_string& __str, size_type __pos = 0) const
179297403Sobrien      { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
179397403Sobrien
1794132720Skan      /**
1795132720Skan       *  @brief  Find position of a character not in C substring.
1796132720Skan       *  @param s  C string containing characters to avoid.
1797228780Spfg       *  @param pos  Index of character to search from.
1798132720Skan       *  @param n  Number of characters from s to consider.
1799132720Skan       *  @return  Index of first occurrence.
1800132720Skan       *
1801132720Skan       *  Starting from @a pos, searches forward for a character not contained
1802132720Skan       *  in the first @a n characters of @a s within this string.  If found,
1803132720Skan       *  returns the index where it was found.  If not found, returns npos.
1804132720Skan      */
1805117397Skan      size_type
1806117397Skan      find_first_not_of(const _CharT* __s, size_type __pos,
180797403Sobrien			size_type __n) const;
180897403Sobrien
1809132720Skan      /**
1810132720Skan       *  @brief  Find position of a character not in C string.
1811132720Skan       *  @param s  C string containing characters to avoid.
1812132720Skan       *  @param pos  Index of character to search from (default 0).
1813132720Skan       *  @return  Index of first occurrence.
1814132720Skan       *
1815132720Skan       *  Starting from @a pos, searches forward for a character not contained
1816132720Skan       *  in @a s within this string.  If found, returns the index where it
1817132720Skan       *  was found.  If not found, returns npos.
1818132720Skan      */
1819117397Skan      size_type
182097403Sobrien      find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1821132720Skan      {
1822132720Skan	__glibcxx_requires_string(__s);
1823132720Skan	return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1824132720Skan      }
182597403Sobrien
1826132720Skan      /**
1827132720Skan       *  @brief  Find position of a different character.
1828132720Skan       *  @param c  Character to avoid.
1829132720Skan       *  @param pos  Index of character to search from (default 0).
1830132720Skan       *  @return  Index of first occurrence.
1831132720Skan       *
1832132720Skan       *  Starting from @a pos, searches forward for a character other than @a c
1833132720Skan       *  within this string.  If found, returns the index where it was found.
1834132720Skan       *  If not found, returns npos.
1835132720Skan      */
1836117397Skan      size_type
183797403Sobrien      find_first_not_of(_CharT __c, size_type __pos = 0) const;
183897403Sobrien
1839132720Skan      /**
1840132720Skan       *  @brief  Find last position of a character not in string.
1841132720Skan       *  @param str  String containing characters to avoid.
1842228780Spfg       *  @param pos  Index of character to search back from (default end).
1843228780Spfg       *  @return  Index of last occurrence.
1844132720Skan       *
1845132720Skan       *  Starting from @a pos, searches backward for a character not
1846132720Skan       *  contained in @a str within this string.  If found, returns the index
1847132720Skan       *  where it was found.  If not found, returns npos.
1848132720Skan      */
1849117397Skan      size_type
185097403Sobrien      find_last_not_of(const basic_string& __str, size_type __pos = npos) const
185197403Sobrien      { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
185297403Sobrien
1853132720Skan      /**
1854132720Skan       *  @brief  Find last position of a character not in C substring.
1855132720Skan       *  @param s  C string containing characters to avoid.
1856228780Spfg       *  @param pos  Index of character to search back from.
1857132720Skan       *  @param n  Number of characters from s to consider.
1858228780Spfg       *  @return  Index of last occurrence.
1859132720Skan       *
1860132720Skan       *  Starting from @a pos, searches backward for a character not
1861132720Skan       *  contained in the first @a n characters of @a s within this string.
1862132720Skan       *  If found, returns the index where it was found.  If not found,
1863132720Skan       *  returns npos.
1864132720Skan      */
1865117397Skan      size_type
1866117397Skan      find_last_not_of(const _CharT* __s, size_type __pos,
186797403Sobrien		       size_type __n) const;
1868132720Skan      /**
1869228780Spfg       *  @brief  Find last position of a character not in C string.
1870132720Skan       *  @param s  C string containing characters to avoid.
1871228780Spfg       *  @param pos  Index of character to search back from (default end).
1872228780Spfg       *  @return  Index of last occurrence.
1873132720Skan       *
1874132720Skan       *  Starting from @a pos, searches backward for a character not
1875132720Skan       *  contained in @a s within this string.  If found, returns the index
1876132720Skan       *  where it was found.  If not found, returns npos.
1877132720Skan      */
1878117397Skan      size_type
187997403Sobrien      find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1880132720Skan      {
1881132720Skan	__glibcxx_requires_string(__s);
1882132720Skan	return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1883132720Skan      }
188497403Sobrien
1885132720Skan      /**
1886132720Skan       *  @brief  Find last position of a different character.
1887132720Skan       *  @param c  Character to avoid.
1888228780Spfg       *  @param pos  Index of character to search back from (default end).
1889228780Spfg       *  @return  Index of last occurrence.
1890132720Skan       *
1891132720Skan       *  Starting from @a pos, searches backward for a character other than
1892132720Skan       *  @a c within this string.  If found, returns the index where it was
1893132720Skan       *  found.  If not found, returns npos.
1894132720Skan      */
1895117397Skan      size_type
189697403Sobrien      find_last_not_of(_CharT __c, size_type __pos = npos) const;
189797403Sobrien
1898132720Skan      /**
1899132720Skan       *  @brief  Get a substring.
1900132720Skan       *  @param pos  Index of first character (default 0).
1901132720Skan       *  @param n  Number of characters in substring (default remainder).
1902132720Skan       *  @return  The new string.
1903132720Skan       *  @throw  std::out_of_range  If pos > size().
1904132720Skan       *
1905132720Skan       *  Construct and return a new string using the @a n characters starting
1906132720Skan       *  at @a pos.  If the string is too short, use the remainder of the
1907132720Skan       *  characters.  If @a pos is beyond the end of the string, out_of_range
1908132720Skan       *  is thrown.
1909132720Skan      */
1910117397Skan      basic_string
191197403Sobrien      substr(size_type __pos = 0, size_type __n = npos) const
1912132720Skan      { return basic_string(*this,
1913132720Skan			    _M_check(__pos, "basic_string::substr"), __n); }
191497403Sobrien
1915132720Skan      /**
1916132720Skan       *  @brief  Compare to a string.
1917132720Skan       *  @param str  String to compare against.
1918132720Skan       *  @return  Integer < 0, 0, or > 0.
1919132720Skan       *
1920132720Skan       *  Returns an integer < 0 if this string is ordered before @a str, 0 if
1921132720Skan       *  their values are equivalent, or > 0 if this string is ordered after
1922146897Skan       *  @a str.  Determines the effective length rlen of the strings to
1923146897Skan       *  compare as the smallest of size() and str.size().  The function
1924146897Skan       *  then compares the two strings by calling traits::compare(data(),
1925146897Skan       *  str.data(),rlen).  If the result of the comparison is nonzero returns
1926146897Skan       *  it, otherwise the shorter one is ordered first.
1927132720Skan      */
1928117397Skan      int
192997403Sobrien      compare(const basic_string& __str) const
193097403Sobrien      {
1931132720Skan	const size_type __size = this->size();
1932132720Skan	const size_type __osize = __str.size();
1933132720Skan	const size_type __len = std::min(__size, __osize);
1934117397Skan
193597403Sobrien	int __r = traits_type::compare(_M_data(), __str.data(), __len);
193697403Sobrien	if (!__r)
193797403Sobrien	  __r =  __size - __osize;
193897403Sobrien	return __r;
193997403Sobrien      }
194097403Sobrien
1941132720Skan      /**
1942132720Skan       *  @brief  Compare substring to a string.
1943132720Skan       *  @param pos  Index of first character of substring.
1944132720Skan       *  @param n  Number of characters in substring.
1945132720Skan       *  @param str  String to compare against.
1946132720Skan       *  @return  Integer < 0, 0, or > 0.
1947132720Skan       *
1948132720Skan       *  Form the substring of this string from the @a n characters starting
1949132720Skan       *  at @a pos.  Returns an integer < 0 if the substring is ordered
1950132720Skan       *  before @a str, 0 if their values are equivalent, or > 0 if the
1951146897Skan       *  substring is ordered after @a str.  Determines the effective length
1952146897Skan       *  rlen of the strings to compare as the smallest of the length of the
1953146897Skan       *  substring and @a str.size().  The function then compares the two
1954146897Skan       *  strings by calling traits::compare(substring.data(),str.data(),rlen).
1955146897Skan       *  If the result of the comparison is nonzero returns it, otherwise the
1956146897Skan       *  shorter one is ordered first.
1957132720Skan      */
1958117397Skan      int
195997403Sobrien      compare(size_type __pos, size_type __n, const basic_string& __str) const;
196097403Sobrien
1961132720Skan      /**
1962132720Skan       *  @brief  Compare substring to a substring.
1963132720Skan       *  @param pos1  Index of first character of substring.
1964132720Skan       *  @param n1  Number of characters in substring.
1965132720Skan       *  @param str  String to compare against.
1966132720Skan       *  @param pos2  Index of first character of substring of str.
1967132720Skan       *  @param n2  Number of characters in substring of str.
1968132720Skan       *  @return  Integer < 0, 0, or > 0.
1969132720Skan       *
1970132720Skan       *  Form the substring of this string from the @a n1 characters starting
1971132720Skan       *  at @a pos1.  Form the substring of @a str from the @a n2 characters
1972132720Skan       *  starting at @a pos2.  Returns an integer < 0 if this substring is
1973132720Skan       *  ordered before the substring of @a str, 0 if their values are
1974132720Skan       *  equivalent, or > 0 if this substring is ordered after the substring
1975146897Skan       *  of @a str.  Determines the effective length rlen of the strings
1976146897Skan       *  to compare as the smallest of the lengths of the substrings.  The
1977146897Skan       *  function then compares the two strings by calling
1978146897Skan       *  traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
1979146897Skan       *  If the result of the comparison is nonzero returns it, otherwise the
1980146897Skan       *  shorter one is ordered first.
1981132720Skan      */
1982117397Skan      int
198397403Sobrien      compare(size_type __pos1, size_type __n1, const basic_string& __str,
198497403Sobrien	      size_type __pos2, size_type __n2) const;
198597403Sobrien
1986132720Skan      /**
1987132720Skan       *  @brief  Compare to a C string.
1988132720Skan       *  @param s  C string to compare against.
1989132720Skan       *  @return  Integer < 0, 0, or > 0.
1990132720Skan       *
1991132720Skan       *  Returns an integer < 0 if this string is ordered before @a s, 0 if
1992132720Skan       *  their values are equivalent, or > 0 if this string is ordered after
1993146897Skan       *  @a s.  Determines the effective length rlen of the strings to
1994146897Skan       *  compare as the smallest of size() and the length of a string
1995146897Skan       *  constructed from @a s.  The function then compares the two strings
1996146897Skan       *  by calling traits::compare(data(),s,rlen).  If the result of the
1997146897Skan       *  comparison is nonzero returns it, otherwise the shorter one is
1998146897Skan       *  ordered first.
1999132720Skan      */
2000117397Skan      int
200197403Sobrien      compare(const _CharT* __s) const;
200297403Sobrien
2003132720Skan      // _GLIBCXX_RESOLVE_LIB_DEFECTS
2004117397Skan      // 5 String::compare specification questionable
2005132720Skan      /**
2006132720Skan       *  @brief  Compare substring to a C string.
2007132720Skan       *  @param pos  Index of first character of substring.
2008132720Skan       *  @param n1  Number of characters in substring.
2009132720Skan       *  @param s  C string to compare against.
2010132720Skan       *  @return  Integer < 0, 0, or > 0.
2011132720Skan       *
2012132720Skan       *  Form the substring of this string from the @a n1 characters starting
2013132720Skan       *  at @a pos.  Returns an integer < 0 if the substring is ordered
2014132720Skan       *  before @a s, 0 if their values are equivalent, or > 0 if the
2015146897Skan       *  substring is ordered after @a s.  Determines the effective length
2016146897Skan       *  rlen of the strings to compare as the smallest of the length of the
2017146897Skan       *  substring and the length of a string constructed from @a s.  The
2018146897Skan       *  function then compares the two string by calling
2019146897Skan       *  traits::compare(substring.data(),s,rlen).  If the result of the
2020146897Skan       *  comparison is nonzero returns it, otherwise the shorter one is
2021146897Skan       *  ordered first.
2022132720Skan      */
2023117397Skan      int
202497403Sobrien      compare(size_type __pos, size_type __n1, const _CharT* __s) const;
202597403Sobrien
2026132720Skan      /**
2027132720Skan       *  @brief  Compare substring against a character array.
2028132720Skan       *  @param pos1  Index of first character of substring.
2029132720Skan       *  @param n1  Number of characters in substring.
2030132720Skan       *  @param s  character array to compare against.
2031132720Skan       *  @param n2  Number of characters of s.
2032132720Skan       *  @return  Integer < 0, 0, or > 0.
2033132720Skan       *
2034132720Skan       *  Form the substring of this string from the @a n1 characters starting
2035132720Skan       *  at @a pos1.  Form a string from the first @a n2 characters of @a s.
2036132720Skan       *  Returns an integer < 0 if this substring is ordered before the string
2037132720Skan       *  from @a s, 0 if their values are equivalent, or > 0 if this substring
2038146897Skan       *  is ordered after the string from @a s.   Determines the effective
2039146897Skan       *  length rlen of the strings to compare as the smallest of the length
2040146897Skan       *  of the substring and @a n2.  The function then compares the two
2041146897Skan       *  strings by calling traits::compare(substring.data(),s,rlen).  If the
2042146897Skan       *  result of the comparison is nonzero returns it, otherwise the shorter
2043146897Skan       *  one is ordered first.
2044132720Skan       *
2045132720Skan       *  NB: s must have at least n2 characters, '\0' has no special
2046132720Skan       *  meaning.
2047132720Skan      */
2048117397Skan      int
2049117397Skan      compare(size_type __pos, size_type __n1, const _CharT* __s,
205097403Sobrien	      size_type __n2) const;
205197403Sobrien  };
205297403Sobrien
205397403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
205497403Sobrien    inline basic_string<_CharT, _Traits, _Alloc>::
205597403Sobrien    basic_string()
2056146897Skan#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
2057132720Skan    : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
2058146897Skan#else
2059146897Skan    : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()) { }
2060146897Skan#endif
206197403Sobrien
206297403Sobrien  // operator+
2063132720Skan  /**
2064132720Skan   *  @brief  Concatenate two strings.
2065132720Skan   *  @param lhs  First string.
2066132720Skan   *  @param rhs  Last string.
2067132720Skan   *  @return  New string with value of @a lhs followed by @a rhs.
2068132720Skan   */
206997403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
207097403Sobrien    basic_string<_CharT, _Traits, _Alloc>
207197403Sobrien    operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
207297403Sobrien	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
207397403Sobrien    {
207497403Sobrien      basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
207597403Sobrien      __str.append(__rhs);
207697403Sobrien      return __str;
207797403Sobrien    }
207897403Sobrien
2079132720Skan  /**
2080132720Skan   *  @brief  Concatenate C string and string.
2081132720Skan   *  @param lhs  First string.
2082132720Skan   *  @param rhs  Last string.
2083132720Skan   *  @return  New string with value of @a lhs followed by @a rhs.
2084132720Skan   */
208597403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
208697403Sobrien    basic_string<_CharT,_Traits,_Alloc>
208797403Sobrien    operator+(const _CharT* __lhs,
208897403Sobrien	      const basic_string<_CharT,_Traits,_Alloc>& __rhs);
208997403Sobrien
2090132720Skan  /**
2091132720Skan   *  @brief  Concatenate character and string.
2092132720Skan   *  @param lhs  First string.
2093132720Skan   *  @param rhs  Last string.
2094132720Skan   *  @return  New string with @a lhs followed by @a rhs.
2095132720Skan   */
209697403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
209797403Sobrien    basic_string<_CharT,_Traits,_Alloc>
209897403Sobrien    operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs);
209997403Sobrien
2100132720Skan  /**
2101132720Skan   *  @brief  Concatenate string and C string.
2102132720Skan   *  @param lhs  First string.
2103132720Skan   *  @param rhs  Last string.
2104132720Skan   *  @return  New string with @a lhs followed by @a rhs.
2105132720Skan   */
210697403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
210797403Sobrien    inline basic_string<_CharT, _Traits, _Alloc>
210897403Sobrien    operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
210997403Sobrien	     const _CharT* __rhs)
211097403Sobrien    {
211197403Sobrien      basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
211297403Sobrien      __str.append(__rhs);
211397403Sobrien      return __str;
211497403Sobrien    }
211597403Sobrien
2116132720Skan  /**
2117132720Skan   *  @brief  Concatenate string and character.
2118132720Skan   *  @param lhs  First string.
2119132720Skan   *  @param rhs  Last string.
2120132720Skan   *  @return  New string with @a lhs followed by @a rhs.
2121132720Skan   */
212297403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
212397403Sobrien    inline basic_string<_CharT, _Traits, _Alloc>
212497403Sobrien    operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
212597403Sobrien    {
2126132720Skan      typedef basic_string<_CharT, _Traits, _Alloc>	__string_type;
212797403Sobrien      typedef typename __string_type::size_type		__size_type;
212897403Sobrien      __string_type __str(__lhs);
212997403Sobrien      __str.append(__size_type(1), __rhs);
213097403Sobrien      return __str;
213197403Sobrien    }
213297403Sobrien
213397403Sobrien  // operator ==
2134132720Skan  /**
2135132720Skan   *  @brief  Test equivalence of two strings.
2136132720Skan   *  @param lhs  First string.
2137132720Skan   *  @param rhs  Second string.
2138132720Skan   *  @return  True if @a lhs.compare(@a rhs) == 0.  False otherwise.
2139132720Skan   */
214097403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
214197403Sobrien    inline bool
214297403Sobrien    operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
214397403Sobrien	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
214497403Sobrien    { return __lhs.compare(__rhs) == 0; }
214597403Sobrien
2146132720Skan  /**
2147132720Skan   *  @brief  Test equivalence of C string and string.
2148132720Skan   *  @param lhs  C string.
2149132720Skan   *  @param rhs  String.
2150132720Skan   *  @return  True if @a rhs.compare(@a lhs) == 0.  False otherwise.
2151132720Skan   */
215297403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
215397403Sobrien    inline bool
215497403Sobrien    operator==(const _CharT* __lhs,
215597403Sobrien	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
215697403Sobrien    { return __rhs.compare(__lhs) == 0; }
215797403Sobrien
2158132720Skan  /**
2159132720Skan   *  @brief  Test equivalence of string and C string.
2160132720Skan   *  @param lhs  String.
2161132720Skan   *  @param rhs  C string.
2162132720Skan   *  @return  True if @a lhs.compare(@a rhs) == 0.  False otherwise.
2163132720Skan   */
216497403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
216597403Sobrien    inline bool
216697403Sobrien    operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
216797403Sobrien	       const _CharT* __rhs)
216897403Sobrien    { return __lhs.compare(__rhs) == 0; }
216997403Sobrien
217097403Sobrien  // operator !=
2171132720Skan  /**
2172132720Skan   *  @brief  Test difference of two strings.
2173132720Skan   *  @param lhs  First string.
2174132720Skan   *  @param rhs  Second string.
2175132720Skan   *  @return  True if @a lhs.compare(@a rhs) != 0.  False otherwise.
2176132720Skan   */
217797403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
217897403Sobrien    inline bool
217997403Sobrien    operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
218097403Sobrien	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
218197403Sobrien    { return __rhs.compare(__lhs) != 0; }
218297403Sobrien
2183132720Skan  /**
2184132720Skan   *  @brief  Test difference of C string and string.
2185132720Skan   *  @param lhs  C string.
2186132720Skan   *  @param rhs  String.
2187132720Skan   *  @return  True if @a rhs.compare(@a lhs) != 0.  False otherwise.
2188132720Skan   */
218997403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
219097403Sobrien    inline bool
219197403Sobrien    operator!=(const _CharT* __lhs,
219297403Sobrien	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
219397403Sobrien    { return __rhs.compare(__lhs) != 0; }
219497403Sobrien
2195132720Skan  /**
2196132720Skan   *  @brief  Test difference of string and C string.
2197132720Skan   *  @param lhs  String.
2198132720Skan   *  @param rhs  C string.
2199132720Skan   *  @return  True if @a lhs.compare(@a rhs) != 0.  False otherwise.
2200132720Skan   */
220197403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
220297403Sobrien    inline bool
220397403Sobrien    operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
220497403Sobrien	       const _CharT* __rhs)
220597403Sobrien    { return __lhs.compare(__rhs) != 0; }
220697403Sobrien
220797403Sobrien  // operator <
2208132720Skan  /**
2209132720Skan   *  @brief  Test if string precedes string.
2210132720Skan   *  @param lhs  First string.
2211132720Skan   *  @param rhs  Second string.
2212132720Skan   *  @return  True if @a lhs precedes @a rhs.  False otherwise.
2213132720Skan   */
221497403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
221597403Sobrien    inline bool
221697403Sobrien    operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
221797403Sobrien	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
221897403Sobrien    { return __lhs.compare(__rhs) < 0; }
221997403Sobrien
2220132720Skan  /**
2221132720Skan   *  @brief  Test if string precedes C string.
2222132720Skan   *  @param lhs  String.
2223132720Skan   *  @param rhs  C string.
2224132720Skan   *  @return  True if @a lhs precedes @a rhs.  False otherwise.
2225132720Skan   */
222697403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
222797403Sobrien    inline bool
222897403Sobrien    operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
222997403Sobrien	      const _CharT* __rhs)
223097403Sobrien    { return __lhs.compare(__rhs) < 0; }
223197403Sobrien
2232132720Skan  /**
2233132720Skan   *  @brief  Test if C string precedes string.
2234132720Skan   *  @param lhs  C string.
2235132720Skan   *  @param rhs  String.
2236132720Skan   *  @return  True if @a lhs precedes @a rhs.  False otherwise.
2237132720Skan   */
223897403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
223997403Sobrien    inline bool
224097403Sobrien    operator<(const _CharT* __lhs,
224197403Sobrien	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
224297403Sobrien    { return __rhs.compare(__lhs) > 0; }
224397403Sobrien
224497403Sobrien  // operator >
2245132720Skan  /**
2246132720Skan   *  @brief  Test if string follows string.
2247132720Skan   *  @param lhs  First string.
2248132720Skan   *  @param rhs  Second string.
2249132720Skan   *  @return  True if @a lhs follows @a rhs.  False otherwise.
2250132720Skan   */
225197403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
225297403Sobrien    inline bool
225397403Sobrien    operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
225497403Sobrien	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
225597403Sobrien    { return __lhs.compare(__rhs) > 0; }
225697403Sobrien
2257132720Skan  /**
2258132720Skan   *  @brief  Test if string follows C string.
2259132720Skan   *  @param lhs  String.
2260132720Skan   *  @param rhs  C string.
2261132720Skan   *  @return  True if @a lhs follows @a rhs.  False otherwise.
2262132720Skan   */
226397403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
226497403Sobrien    inline bool
226597403Sobrien    operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
226697403Sobrien	      const _CharT* __rhs)
226797403Sobrien    { return __lhs.compare(__rhs) > 0; }
226897403Sobrien
2269132720Skan  /**
2270132720Skan   *  @brief  Test if C string follows string.
2271132720Skan   *  @param lhs  C string.
2272132720Skan   *  @param rhs  String.
2273132720Skan   *  @return  True if @a lhs follows @a rhs.  False otherwise.
2274132720Skan   */
227597403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
227697403Sobrien    inline bool
227797403Sobrien    operator>(const _CharT* __lhs,
227897403Sobrien	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
227997403Sobrien    { return __rhs.compare(__lhs) < 0; }
228097403Sobrien
228197403Sobrien  // operator <=
2282132720Skan  /**
2283132720Skan   *  @brief  Test if string doesn't follow string.
2284132720Skan   *  @param lhs  First string.
2285132720Skan   *  @param rhs  Second string.
2286132720Skan   *  @return  True if @a lhs doesn't follow @a rhs.  False otherwise.
2287132720Skan   */
228897403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
228997403Sobrien    inline bool
229097403Sobrien    operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
229197403Sobrien	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
229297403Sobrien    { return __lhs.compare(__rhs) <= 0; }
229397403Sobrien
2294132720Skan  /**
2295132720Skan   *  @brief  Test if string doesn't follow C string.
2296132720Skan   *  @param lhs  String.
2297132720Skan   *  @param rhs  C string.
2298132720Skan   *  @return  True if @a lhs doesn't follow @a rhs.  False otherwise.
2299132720Skan   */
230097403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
230197403Sobrien    inline bool
230297403Sobrien    operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
230397403Sobrien	       const _CharT* __rhs)
230497403Sobrien    { return __lhs.compare(__rhs) <= 0; }
230597403Sobrien
2306132720Skan  /**
2307132720Skan   *  @brief  Test if C string doesn't follow string.
2308132720Skan   *  @param lhs  C string.
2309132720Skan   *  @param rhs  String.
2310132720Skan   *  @return  True if @a lhs doesn't follow @a rhs.  False otherwise.
2311132720Skan   */
231297403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
231397403Sobrien    inline bool
231497403Sobrien    operator<=(const _CharT* __lhs,
231597403Sobrien	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2316169691Skan    { return __rhs.compare(__lhs) >= 0; }
231797403Sobrien
231897403Sobrien  // operator >=
2319132720Skan  /**
2320132720Skan   *  @brief  Test if string doesn't precede string.
2321132720Skan   *  @param lhs  First string.
2322132720Skan   *  @param rhs  Second string.
2323132720Skan   *  @return  True if @a lhs doesn't precede @a rhs.  False otherwise.
2324132720Skan   */
232597403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
232697403Sobrien    inline bool
232797403Sobrien    operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
232897403Sobrien	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
232997403Sobrien    { return __lhs.compare(__rhs) >= 0; }
233097403Sobrien
2331132720Skan  /**
2332132720Skan   *  @brief  Test if string doesn't precede C string.
2333132720Skan   *  @param lhs  String.
2334132720Skan   *  @param rhs  C string.
2335132720Skan   *  @return  True if @a lhs doesn't precede @a rhs.  False otherwise.
2336132720Skan   */
233797403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
233897403Sobrien    inline bool
233997403Sobrien    operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
234097403Sobrien	       const _CharT* __rhs)
234197403Sobrien    { return __lhs.compare(__rhs) >= 0; }
234297403Sobrien
2343132720Skan  /**
2344132720Skan   *  @brief  Test if C string doesn't precede string.
2345132720Skan   *  @param lhs  C string.
2346132720Skan   *  @param rhs  String.
2347132720Skan   *  @return  True if @a lhs doesn't precede @a rhs.  False otherwise.
2348132720Skan   */
234997403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
235097403Sobrien    inline bool
235197403Sobrien    operator>=(const _CharT* __lhs,
235297403Sobrien	     const basic_string<_CharT, _Traits, _Alloc>& __rhs)
235397403Sobrien    { return __rhs.compare(__lhs) <= 0; }
235497403Sobrien
2355132720Skan  /**
2356132720Skan   *  @brief  Swap contents of two strings.
2357132720Skan   *  @param lhs  First string.
2358132720Skan   *  @param rhs  Second string.
2359132720Skan   *
2360132720Skan   *  Exchanges the contents of @a lhs and @a rhs in constant time.
2361132720Skan   */
236297403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
236397403Sobrien    inline void
236497403Sobrien    swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
236597403Sobrien	 basic_string<_CharT, _Traits, _Alloc>& __rhs)
236697403Sobrien    { __lhs.swap(__rhs); }
236797403Sobrien
2368132720Skan  /**
2369132720Skan   *  @brief  Read stream into a string.
2370132720Skan   *  @param is  Input stream.
2371132720Skan   *  @param str  Buffer to store into.
2372132720Skan   *  @return  Reference to the input stream.
2373132720Skan   *
2374132720Skan   *  Stores characters from @a is into @a str until whitespace is found, the
2375132720Skan   *  end of the stream is encountered, or str.max_size() is reached.  If
2376132720Skan   *  is.width() is non-zero, that is the limit on the number of characters
2377132720Skan   *  stored into @a str.  Any previous contents of @a str are erased.
2378132720Skan   */
237997403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
238097403Sobrien    basic_istream<_CharT, _Traits>&
238197403Sobrien    operator>>(basic_istream<_CharT, _Traits>& __is,
238297403Sobrien	       basic_string<_CharT, _Traits, _Alloc>& __str);
238397403Sobrien
2384169691Skan  template<>
2385169691Skan    basic_istream<char>&
2386169691Skan    operator>>(basic_istream<char>& __is, basic_string<char>& __str);
2387169691Skan
2388132720Skan  /**
2389132720Skan   *  @brief  Write string to a stream.
2390132720Skan   *  @param os  Output stream.
2391132720Skan   *  @param str  String to write out.
2392132720Skan   *  @return  Reference to the output stream.
2393132720Skan   *
2394132720Skan   *  Output characters of @a str into os following the same rules as for
2395132720Skan   *  writing a C string.
2396132720Skan   */
239797403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
2398169691Skan    inline basic_ostream<_CharT, _Traits>&
239997403Sobrien    operator<<(basic_ostream<_CharT, _Traits>& __os,
2400169691Skan	       const basic_string<_CharT, _Traits, _Alloc>& __str)
2401169691Skan    {
2402169691Skan      // _GLIBCXX_RESOLVE_LIB_DEFECTS
2403169691Skan      // 586. string inserter not a formatted function
2404169691Skan      return __ostream_insert(__os, __str.data(), __str.size());
2405169691Skan    }
240697403Sobrien
2407132720Skan  /**
2408132720Skan   *  @brief  Read a line from stream into a string.
2409132720Skan   *  @param is  Input stream.
2410132720Skan   *  @param str  Buffer to store into.
2411132720Skan   *  @param delim  Character marking end of line.
2412132720Skan   *  @return  Reference to the input stream.
2413132720Skan   *
2414132720Skan   *  Stores characters from @a is into @a str until @a delim is found, the
2415132720Skan   *  end of the stream is encountered, or str.max_size() is reached.  If
2416132720Skan   *  is.width() is non-zero, that is the limit on the number of characters
2417132720Skan   *  stored into @a str.  Any previous contents of @a str are erased.  If @a
2418132720Skan   *  delim was encountered, it is extracted but not stored into @a str.
2419132720Skan   */
242097403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
2421169691Skan    basic_istream<_CharT, _Traits>&
242297403Sobrien    getline(basic_istream<_CharT, _Traits>& __is,
242397403Sobrien	    basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
242497403Sobrien
2425132720Skan  /**
2426132720Skan   *  @brief  Read a line from stream into a string.
2427132720Skan   *  @param is  Input stream.
2428132720Skan   *  @param str  Buffer to store into.
2429132720Skan   *  @return  Reference to the input stream.
2430132720Skan   *
2431132720Skan   *  Stores characters from is into @a str until '\n' is found, the end of
2432132720Skan   *  the stream is encountered, or str.max_size() is reached.  If is.width()
2433132720Skan   *  is non-zero, that is the limit on the number of characters stored into
2434132720Skan   *  @a str.  Any previous contents of @a str are erased.  If end of line was
2435132720Skan   *  encountered, it is extracted but not stored into @a str.
2436132720Skan   */
243797403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
2438169691Skan    inline basic_istream<_CharT, _Traits>&
243997403Sobrien    getline(basic_istream<_CharT, _Traits>& __is,
2440169691Skan	    basic_string<_CharT, _Traits, _Alloc>& __str)
2441169691Skan    { return getline(__is, __str, __is.widen('\n')); }
244297403Sobrien
2443169691Skan  template<>
2444169691Skan    basic_istream<char>&
2445169691Skan    getline(basic_istream<char>& __in, basic_string<char>& __str,
2446169691Skan	    char __delim);
2447169691Skan
2448169691Skan#ifdef _GLIBCXX_USE_WCHAR_T
2449169691Skan  template<>
2450169691Skan    basic_istream<wchar_t>&
2451169691Skan    getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
2452169691Skan	    wchar_t __delim);
2453169691Skan#endif
2454169691Skan
2455169691Skan_GLIBCXX_END_NAMESPACE
2456169691Skan
2457132720Skan#endif /* _BASIC_STRING_H */
2458