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
393259705Spfg      static int
394259705Spfg      _S_compare(size_type __x, size_type __y)
395259705Spfg      {
396259705Spfg         if (__x > __y)
397259705Spfg            return 1;
398259705Spfg         if (__x < __y)
399259705Spfg            return -1;
400259705Spfg         return 0;
401259705Spfg      }
402259705Spfg
403117397Skan      void
40497403Sobrien      _M_mutate(size_type __pos, size_type __len1, size_type __len2);
40597403Sobrien
406117397Skan      void
40797403Sobrien      _M_leak_hard();
40897403Sobrien
409117397Skan      static _Rep&
41097403Sobrien      _S_empty_rep()
411132720Skan      { return _Rep::_S_empty_rep(); }
41297403Sobrien
41397403Sobrien    public:
41497403Sobrien      // Construct/copy/destroy:
41597403Sobrien      // NB: We overload ctors in some cases instead of using default
41697403Sobrien      // arguments, per 17.4.4.4 para. 2 item 2.
41797403Sobrien
418132720Skan      /**
419132720Skan       *  @brief  Default constructor creates an empty string.
420132720Skan       */
421117397Skan      inline
42297403Sobrien      basic_string();
42397403Sobrien
424132720Skan      /**
425169691Skan       *  @brief  Construct an empty string using allocator @a a.
426132720Skan       */
427117397Skan      explicit
42897403Sobrien      basic_string(const _Alloc& __a);
42997403Sobrien
43097403Sobrien      // NB: per LWG issue 42, semantics different from IS:
431132720Skan      /**
432132720Skan       *  @brief  Construct string with copy of value of @a str.
433132720Skan       *  @param  str  Source string.
434132720Skan       */
43597403Sobrien      basic_string(const basic_string& __str);
436132720Skan      /**
437132720Skan       *  @brief  Construct string as copy of a substring.
438132720Skan       *  @param  str  Source string.
439132720Skan       *  @param  pos  Index of first character to copy from.
440132720Skan       *  @param  n  Number of characters to copy (default remainder).
441132720Skan       */
44297403Sobrien      basic_string(const basic_string& __str, size_type __pos,
44397403Sobrien		   size_type __n = npos);
444132720Skan      /**
445132720Skan       *  @brief  Construct string as copy of a substring.
446132720Skan       *  @param  str  Source string.
447132720Skan       *  @param  pos  Index of first character to copy from.
448132720Skan       *  @param  n  Number of characters to copy.
449132720Skan       *  @param  a  Allocator to use.
450132720Skan       */
45197403Sobrien      basic_string(const basic_string& __str, size_type __pos,
45297403Sobrien		   size_type __n, const _Alloc& __a);
45397403Sobrien
454132720Skan      /**
455132720Skan       *  @brief  Construct string initialized by a character array.
456132720Skan       *  @param  s  Source character array.
457132720Skan       *  @param  n  Number of characters to copy.
458132720Skan       *  @param  a  Allocator to use (default is default allocator).
459132720Skan       *
460169691Skan       *  NB: @a s must have at least @a n characters, '\0' has no special
461132720Skan       *  meaning.
462132720Skan       */
46397403Sobrien      basic_string(const _CharT* __s, size_type __n,
46497403Sobrien		   const _Alloc& __a = _Alloc());
465132720Skan      /**
466132720Skan       *  @brief  Construct string as copy of a C string.
467132720Skan       *  @param  s  Source C string.
468132720Skan       *  @param  a  Allocator to use (default is default allocator).
469132720Skan       */
47097403Sobrien      basic_string(const _CharT* __s, const _Alloc& __a = _Alloc());
471132720Skan      /**
472132720Skan       *  @brief  Construct string as multiple characters.
473132720Skan       *  @param  n  Number of characters.
474132720Skan       *  @param  c  Character to use.
475132720Skan       *  @param  a  Allocator to use (default is default allocator).
476132720Skan       */
47797403Sobrien      basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
47897403Sobrien
479132720Skan      /**
480132720Skan       *  @brief  Construct string as copy of a range.
481132720Skan       *  @param  beg  Start of range.
482132720Skan       *  @param  end  End of range.
483132720Skan       *  @param  a  Allocator to use (default is default allocator).
484132720Skan       */
48597403Sobrien      template<class _InputIterator>
48697403Sobrien        basic_string(_InputIterator __beg, _InputIterator __end,
48797403Sobrien		     const _Alloc& __a = _Alloc());
48897403Sobrien
489132720Skan      /**
490132720Skan       *  @brief  Destroy the string instance.
491132720Skan       */
492117397Skan      ~basic_string()
49397403Sobrien      { _M_rep()->_M_dispose(this->get_allocator()); }
49497403Sobrien
495132720Skan      /**
496132720Skan       *  @brief  Assign the value of @a str to this string.
497132720Skan       *  @param  str  Source string.
498132720Skan       */
499117397Skan      basic_string&
500132720Skan      operator=(const basic_string& __str)
501169691Skan      { return this->assign(__str); }
50297403Sobrien
503132720Skan      /**
504132720Skan       *  @brief  Copy contents of @a s into this string.
505132720Skan       *  @param  s  Source null-terminated string.
506132720Skan       */
507117397Skan      basic_string&
508132720Skan      operator=(const _CharT* __s)
509169691Skan      { return this->assign(__s); }
51097403Sobrien
511132720Skan      /**
512132720Skan       *  @brief  Set value to string of length 1.
513132720Skan       *  @param  c  Source character.
514132720Skan       *
515132720Skan       *  Assigning to a character makes this string length 1 and
516132720Skan       *  (*this)[0] == @a c.
517132720Skan       */
518117397Skan      basic_string&
519132720Skan      operator=(_CharT __c)
520132720Skan      {
521132720Skan	this->assign(1, __c);
522132720Skan	return *this;
523132720Skan      }
52497403Sobrien
52597403Sobrien      // Iterators:
526132720Skan      /**
527132720Skan       *  Returns a read/write iterator that points to the first character in
528132720Skan       *  the %string.  Unshares the string.
529132720Skan       */
530117397Skan      iterator
531117397Skan      begin()
532117397Skan      {
533117397Skan	_M_leak();
53497403Sobrien	return iterator(_M_data());
53597403Sobrien      }
53697403Sobrien
537132720Skan      /**
538132720Skan       *  Returns a read-only (constant) iterator that points to the first
539132720Skan       *  character in the %string.
540132720Skan       */
541117397Skan      const_iterator
542117397Skan      begin() const
54397403Sobrien      { return const_iterator(_M_data()); }
54497403Sobrien
545132720Skan      /**
546132720Skan       *  Returns a read/write iterator that points one past the last
547132720Skan       *  character in the %string.  Unshares the string.
548132720Skan       */
549117397Skan      iterator
55097403Sobrien      end()
55197403Sobrien      {
552132720Skan	_M_leak();
553132720Skan	return iterator(_M_data() + this->size());
55497403Sobrien      }
55597403Sobrien
556132720Skan      /**
557132720Skan       *  Returns a read-only (constant) iterator that points one past the
558132720Skan       *  last character in the %string.
559132720Skan       */
560117397Skan      const_iterator
56197403Sobrien      end() const
56297403Sobrien      { return const_iterator(_M_data() + this->size()); }
56397403Sobrien
564132720Skan      /**
565132720Skan       *  Returns a read/write reverse iterator that points to the last
566132720Skan       *  character in the %string.  Iteration is done in reverse element
567132720Skan       *  order.  Unshares the string.
568132720Skan       */
569117397Skan      reverse_iterator
570117397Skan      rbegin()
57197403Sobrien      { return reverse_iterator(this->end()); }
57297403Sobrien
573132720Skan      /**
574132720Skan       *  Returns a read-only (constant) reverse iterator that points
575132720Skan       *  to the last character in the %string.  Iteration is done in
576132720Skan       *  reverse element order.
577132720Skan       */
578117397Skan      const_reverse_iterator
579117397Skan      rbegin() const
58097403Sobrien      { return const_reverse_iterator(this->end()); }
58197403Sobrien
582132720Skan      /**
583132720Skan       *  Returns a read/write reverse iterator that points to one before the
584132720Skan       *  first character in the %string.  Iteration is done in reverse
585132720Skan       *  element order.  Unshares the string.
586132720Skan       */
587117397Skan      reverse_iterator
588117397Skan      rend()
58997403Sobrien      { return reverse_iterator(this->begin()); }
59097403Sobrien
591132720Skan      /**
592132720Skan       *  Returns a read-only (constant) reverse iterator that points
593132720Skan       *  to one before the first character in the %string.  Iteration
594132720Skan       *  is done in reverse element order.
595132720Skan       */
596117397Skan      const_reverse_iterator
597117397Skan      rend() const
59897403Sobrien      { return const_reverse_iterator(this->begin()); }
59997403Sobrien
60097403Sobrien    public:
60197403Sobrien      // Capacity:
602132720Skan      ///  Returns the number of characters in the string, not including any
603132720Skan      ///  null-termination.
604117397Skan      size_type
605169691Skan      size() const
606169691Skan      { return _M_rep()->_M_length; }
60797403Sobrien
608132720Skan      ///  Returns the number of characters in the string, not including any
609132720Skan      ///  null-termination.
610117397Skan      size_type
611169691Skan      length() const
612169691Skan      { return _M_rep()->_M_length; }
61397403Sobrien
614132720Skan      /// Returns the size() of the largest possible %string.
615117397Skan      size_type
616169691Skan      max_size() const
617169691Skan      { return _Rep::_S_max_size; }
61897403Sobrien
619132720Skan      /**
620132720Skan       *  @brief  Resizes the %string to the specified number of characters.
621132720Skan       *  @param  n  Number of characters the %string should contain.
622132720Skan       *  @param  c  Character to fill any new elements.
623132720Skan       *
624132720Skan       *  This function will %resize the %string to the specified
625132720Skan       *  number of characters.  If the number is smaller than the
626132720Skan       *  %string's current size the %string is truncated, otherwise
627132720Skan       *  the %string is extended and new elements are set to @a c.
628132720Skan       */
629117397Skan      void
63097403Sobrien      resize(size_type __n, _CharT __c);
63197403Sobrien
632132720Skan      /**
633132720Skan       *  @brief  Resizes the %string to the specified number of characters.
634132720Skan       *  @param  n  Number of characters the %string should contain.
635132720Skan       *
636132720Skan       *  This function will resize the %string to the specified length.  If
637132720Skan       *  the new size is smaller than the %string's current size the %string
638132720Skan       *  is truncated, otherwise the %string is extended and new characters
639132720Skan       *  are default-constructed.  For basic types such as char, this means
640132720Skan       *  setting them to 0.
641132720Skan       */
642117397Skan      void
643169691Skan      resize(size_type __n)
644169691Skan      { this->resize(__n, _CharT()); }
64597403Sobrien
646132720Skan      /**
647132720Skan       *  Returns the total number of characters that the %string can hold
648132720Skan       *  before needing to allocate more memory.
649132720Skan       */
650117397Skan      size_type
651169691Skan      capacity() const
652169691Skan      { return _M_rep()->_M_capacity; }
65397403Sobrien
654132720Skan      /**
655132720Skan       *  @brief  Attempt to preallocate enough memory for specified number of
656132720Skan       *          characters.
657169691Skan       *  @param  res_arg  Number of characters required.
658169691Skan       *  @throw  std::length_error  If @a res_arg exceeds @c max_size().
659132720Skan       *
660132720Skan       *  This function attempts to reserve enough memory for the
661132720Skan       *  %string to hold the specified number of characters.  If the
662132720Skan       *  number requested is more than max_size(), length_error is
663132720Skan       *  thrown.
664132720Skan       *
665132720Skan       *  The advantage of this function is that if optimal code is a
666132720Skan       *  necessity and the user can determine the string length that will be
667132720Skan       *  required, the user can reserve the memory in %advance, and thus
668132720Skan       *  prevent a possible reallocation of memory and copying of %string
669132720Skan       *  data.
670132720Skan       */
671117397Skan      void
67297403Sobrien      reserve(size_type __res_arg = 0);
67397403Sobrien
674132720Skan      /**
675132720Skan       *  Erases the string, making it empty.
676132720Skan       */
677117397Skan      void
678169691Skan      clear()
679169691Skan      { _M_mutate(0, this->size(), 0); }
68097403Sobrien
681132720Skan      /**
682132720Skan       *  Returns true if the %string is empty.  Equivalent to *this == "".
683132720Skan       */
684117397Skan      bool
685169691Skan      empty() const
686169691Skan      { return this->size() == 0; }
68797403Sobrien
68897403Sobrien      // Element access:
689132720Skan      /**
690132720Skan       *  @brief  Subscript access to the data contained in the %string.
691169691Skan       *  @param  pos  The index of the character to access.
692132720Skan       *  @return  Read-only (constant) reference to the character.
693132720Skan       *
694132720Skan       *  This operator allows for easy, array-style, data access.
695132720Skan       *  Note that data access with this operator is unchecked and
696132720Skan       *  out_of_range lookups are not defined. (For checked lookups
697132720Skan       *  see at().)
698132720Skan       */
699117397Skan      const_reference
700117397Skan      operator[] (size_type __pos) const
701132720Skan      {
702132720Skan	_GLIBCXX_DEBUG_ASSERT(__pos <= size());
703132720Skan	return _M_data()[__pos];
704132720Skan      }
70597403Sobrien
706132720Skan      /**
707132720Skan       *  @brief  Subscript access to the data contained in the %string.
708169691Skan       *  @param  pos  The index of the character to access.
709132720Skan       *  @return  Read/write reference to the character.
710132720Skan       *
711132720Skan       *  This operator allows for easy, array-style, data access.
712132720Skan       *  Note that data access with this operator is unchecked and
713132720Skan       *  out_of_range lookups are not defined. (For checked lookups
714132720Skan       *  see at().)  Unshares the string.
715132720Skan       */
716117397Skan      reference
717117397Skan      operator[](size_type __pos)
718117397Skan      {
719169691Skan        // allow pos == size() as v3 extension:
720169691Skan	_GLIBCXX_DEBUG_ASSERT(__pos <= size());
721169691Skan        // but be strict in pedantic mode:
722169691Skan	_GLIBCXX_DEBUG_PEDASSERT(__pos < size());
723117397Skan	_M_leak();
724117397Skan	return _M_data()[__pos];
72597403Sobrien      }
72697403Sobrien
727132720Skan      /**
728132720Skan       *  @brief  Provides access to the data contained in the %string.
729132720Skan       *  @param n The index of the character to access.
730132720Skan       *  @return  Read-only (const) reference to the character.
731132720Skan       *  @throw  std::out_of_range  If @a n is an invalid index.
732132720Skan       *
733132720Skan       *  This function provides for safer data access.  The parameter is
734132720Skan       *  first checked that it is in the range of the string.  The function
735132720Skan       *  throws out_of_range if the check fails.
736132720Skan       */
737117397Skan      const_reference
73897403Sobrien      at(size_type __n) const
73997403Sobrien      {
74097403Sobrien	if (__n >= this->size())
741132720Skan	  __throw_out_of_range(__N("basic_string::at"));
742117397Skan	return _M_data()[__n];
74397403Sobrien      }
74497403Sobrien
745132720Skan      /**
746132720Skan       *  @brief  Provides access to the data contained in the %string.
747132720Skan       *  @param n The index of the character to access.
748132720Skan       *  @return  Read/write reference to the character.
749132720Skan       *  @throw  std::out_of_range  If @a n is an invalid index.
750132720Skan       *
751132720Skan       *  This function provides for safer data access.  The parameter is
752132720Skan       *  first checked that it is in the range of the string.  The function
753132720Skan       *  throws out_of_range if the check fails.  Success results in
754132720Skan       *  unsharing the string.
755132720Skan       */
756117397Skan      reference
75797403Sobrien      at(size_type __n)
75897403Sobrien      {
75997403Sobrien	if (__n >= size())
760132720Skan	  __throw_out_of_range(__N("basic_string::at"));
761117397Skan	_M_leak();
762117397Skan	return _M_data()[__n];
76397403Sobrien      }
76497403Sobrien
76597403Sobrien      // Modifiers:
766132720Skan      /**
767132720Skan       *  @brief  Append a string to this string.
768132720Skan       *  @param str  The string to append.
769132720Skan       *  @return  Reference to this string.
770132720Skan       */
771117397Skan      basic_string&
772169691Skan      operator+=(const basic_string& __str)
773169691Skan      { return this->append(__str); }
77497403Sobrien
775132720Skan      /**
776132720Skan       *  @brief  Append a C string.
777132720Skan       *  @param s  The C string to append.
778132720Skan       *  @return  Reference to this string.
779132720Skan       */
780117397Skan      basic_string&
781169691Skan      operator+=(const _CharT* __s)
782169691Skan      { return this->append(__s); }
78397403Sobrien
784132720Skan      /**
785132720Skan       *  @brief  Append a character.
786169691Skan       *  @param c  The character to append.
787132720Skan       *  @return  Reference to this string.
788132720Skan       */
789117397Skan      basic_string&
790169691Skan      operator+=(_CharT __c)
791169691Skan      {
792169691Skan	this->push_back(__c);
793169691Skan	return *this;
794169691Skan      }
79597403Sobrien
796132720Skan      /**
797132720Skan       *  @brief  Append a string to this string.
798132720Skan       *  @param str  The string to append.
799132720Skan       *  @return  Reference to this string.
800132720Skan       */
801117397Skan      basic_string&
80297403Sobrien      append(const basic_string& __str);
80397403Sobrien
804132720Skan      /**
805132720Skan       *  @brief  Append a substring.
806132720Skan       *  @param str  The string to append.
807132720Skan       *  @param pos  Index of the first character of str to append.
808132720Skan       *  @param n  The number of characters to append.
809132720Skan       *  @return  Reference to this string.
810132720Skan       *  @throw  std::out_of_range if @a pos is not a valid index.
811132720Skan       *
812132720Skan       *  This function appends @a n characters from @a str starting at @a pos
813132720Skan       *  to this string.  If @a n is is larger than the number of available
814132720Skan       *  characters in @a str, the remainder of @a str is appended.
815132720Skan       */
816117397Skan      basic_string&
81797403Sobrien      append(const basic_string& __str, size_type __pos, size_type __n);
81897403Sobrien
819132720Skan      /**
820132720Skan       *  @brief  Append a C substring.
821132720Skan       *  @param s  The C string to append.
822132720Skan       *  @param n  The number of characters to append.
823132720Skan       *  @return  Reference to this string.
824132720Skan       */
825117397Skan      basic_string&
82697403Sobrien      append(const _CharT* __s, size_type __n);
82797403Sobrien
828132720Skan      /**
829132720Skan       *  @brief  Append a C string.
830132720Skan       *  @param s  The C string to append.
831132720Skan       *  @return  Reference to this string.
832132720Skan       */
833117397Skan      basic_string&
83497403Sobrien      append(const _CharT* __s)
835132720Skan      {
836132720Skan	__glibcxx_requires_string(__s);
837132720Skan	return this->append(__s, traits_type::length(__s));
838132720Skan      }
83997403Sobrien
840132720Skan      /**
841132720Skan       *  @brief  Append multiple characters.
842132720Skan       *  @param n  The number of characters to append.
843132720Skan       *  @param c  The character to use.
844132720Skan       *  @return  Reference to this string.
845132720Skan       *
846132720Skan       *  Appends n copies of c to this string.
847132720Skan       */
848117397Skan      basic_string&
849169691Skan      append(size_type __n, _CharT __c);
85097403Sobrien
851132720Skan      /**
852132720Skan       *  @brief  Append a range of characters.
853132720Skan       *  @param first  Iterator referencing the first character to append.
854132720Skan       *  @param last  Iterator marking the end of the range.
855132720Skan       *  @return  Reference to this string.
856132720Skan       *
857132720Skan       *  Appends characters in the range [first,last) to this string.
858132720Skan       */
85997403Sobrien      template<class _InputIterator>
860117397Skan        basic_string&
86197403Sobrien        append(_InputIterator __first, _InputIterator __last)
86297403Sobrien        { return this->replace(_M_iend(), _M_iend(), __first, __last); }
86397403Sobrien
864132720Skan      /**
865132720Skan       *  @brief  Append a single character.
866132720Skan       *  @param c  Character to append.
867132720Skan       */
868117397Skan      void
86997403Sobrien      push_back(_CharT __c)
870169691Skan      {
871169691Skan	const size_type __len = 1 + this->size();
872169691Skan	if (__len > this->capacity() || _M_rep()->_M_is_shared())
873169691Skan	  this->reserve(__len);
874169691Skan	traits_type::assign(_M_data()[this->size()], __c);
875169691Skan	_M_rep()->_M_set_length_and_sharable(__len);
876169691Skan      }
87797403Sobrien
878132720Skan      /**
879132720Skan       *  @brief  Set value to contents of another string.
880132720Skan       *  @param  str  Source string to use.
881132720Skan       *  @return  Reference to this string.
882132720Skan       */
883117397Skan      basic_string&
88497403Sobrien      assign(const basic_string& __str);
88597403Sobrien
886132720Skan      /**
887132720Skan       *  @brief  Set value to a substring of a string.
888132720Skan       *  @param str  The string to use.
889132720Skan       *  @param pos  Index of the first character of str.
890132720Skan       *  @param n  Number of characters to use.
891132720Skan       *  @return  Reference to this string.
892132720Skan       *  @throw  std::out_of_range if @a pos is not a valid index.
893132720Skan       *
894132720Skan       *  This function sets this string to the substring of @a str consisting
895132720Skan       *  of @a n characters at @a pos.  If @a n is is larger than the number
896132720Skan       *  of available characters in @a str, the remainder of @a str is used.
897132720Skan       */
898117397Skan      basic_string&
899132720Skan      assign(const basic_string& __str, size_type __pos, size_type __n)
900132720Skan      { return this->assign(__str._M_data()
901132720Skan			    + __str._M_check(__pos, "basic_string::assign"),
902132720Skan			    __str._M_limit(__pos, __n)); }
90397403Sobrien
904132720Skan      /**
905132720Skan       *  @brief  Set value to a C substring.
906132720Skan       *  @param s  The C string to use.
907132720Skan       *  @param n  Number of characters to use.
908132720Skan       *  @return  Reference to this string.
909132720Skan       *
910132720Skan       *  This function sets the value of this string to the first @a n
911132720Skan       *  characters of @a s.  If @a n is is larger than the number of
912132720Skan       *  available characters in @a s, the remainder of @a s is used.
913132720Skan       */
914117397Skan      basic_string&
915117397Skan      assign(const _CharT* __s, size_type __n);
91697403Sobrien
917132720Skan      /**
918132720Skan       *  @brief  Set value to contents of a C string.
919132720Skan       *  @param s  The C string to use.
920132720Skan       *  @return  Reference to this string.
921132720Skan       *
922132720Skan       *  This function sets the value of this string to the value of @a s.
923132720Skan       *  The data is copied, so there is no dependence on @a s once the
924132720Skan       *  function returns.
925132720Skan       */
926117397Skan      basic_string&
92797403Sobrien      assign(const _CharT* __s)
928132720Skan      {
929132720Skan	__glibcxx_requires_string(__s);
930132720Skan	return this->assign(__s, traits_type::length(__s));
931132720Skan      }
93297403Sobrien
933132720Skan      /**
934132720Skan       *  @brief  Set value to multiple characters.
935132720Skan       *  @param n  Length of the resulting string.
936132720Skan       *  @param c  The character to use.
937132720Skan       *  @return  Reference to this string.
938132720Skan       *
939132720Skan       *  This function sets the value of this string to @a n copies of
940132720Skan       *  character @a c.
941132720Skan       */
942117397Skan      basic_string&
94397403Sobrien      assign(size_type __n, _CharT __c)
944132720Skan      { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
94597403Sobrien
946132720Skan      /**
947132720Skan       *  @brief  Set value to a range of characters.
948132720Skan       *  @param first  Iterator referencing the first character to append.
949132720Skan       *  @param last  Iterator marking the end of the range.
950132720Skan       *  @return  Reference to this string.
951132720Skan       *
952132720Skan       *  Sets value of string to characters in the range [first,last).
953132720Skan      */
95497403Sobrien      template<class _InputIterator>
955117397Skan        basic_string&
95697403Sobrien        assign(_InputIterator __first, _InputIterator __last)
95797403Sobrien        { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
95897403Sobrien
959132720Skan      /**
960132720Skan       *  @brief  Insert multiple characters.
961132720Skan       *  @param p  Iterator referencing location in string to insert at.
962132720Skan       *  @param n  Number of characters to insert
963132720Skan       *  @param c  The character to insert.
964132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
965132720Skan       *
966132720Skan       *  Inserts @a n copies of character @a c starting at the position
967132720Skan       *  referenced by iterator @a p.  If adding characters causes the length
968132720Skan       *  to exceed max_size(), length_error is thrown.  The value of the
969132720Skan       *  string doesn't change if an error is thrown.
970132720Skan      */
971117397Skan      void
97297403Sobrien      insert(iterator __p, size_type __n, _CharT __c)
97397403Sobrien      {	this->replace(__p, __p, __n, __c);  }
97497403Sobrien
975132720Skan      /**
976132720Skan       *  @brief  Insert a range of characters.
977132720Skan       *  @param p  Iterator referencing location in string to insert at.
978132720Skan       *  @param beg  Start of range.
979132720Skan       *  @param end  End of range.
980132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
981132720Skan       *
982132720Skan       *  Inserts characters in range [beg,end).  If adding characters causes
983132720Skan       *  the length to exceed max_size(), length_error is thrown.  The value
984132720Skan       *  of the string doesn't change if an error is thrown.
985132720Skan      */
98697403Sobrien      template<class _InputIterator>
987169691Skan        void
988169691Skan        insert(iterator __p, _InputIterator __beg, _InputIterator __end)
98997403Sobrien        { this->replace(__p, __p, __beg, __end); }
99097403Sobrien
991132720Skan      /**
992132720Skan       *  @brief  Insert value of a string.
993132720Skan       *  @param pos1  Iterator referencing location in string to insert at.
994132720Skan       *  @param str  The string to insert.
995132720Skan       *  @return  Reference to this string.
996132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
997132720Skan       *
998132720Skan       *  Inserts value of @a str starting at @a pos1.  If adding characters
999132720Skan       *  causes the length to exceed max_size(), length_error is thrown.  The
1000132720Skan       *  value of the string doesn't change if an error is thrown.
1001132720Skan      */
1002117397Skan      basic_string&
100397403Sobrien      insert(size_type __pos1, const basic_string& __str)
1004132720Skan      { return this->insert(__pos1, __str, size_type(0), __str.size()); }
100597403Sobrien
1006132720Skan      /**
1007132720Skan       *  @brief  Insert a substring.
1008132720Skan       *  @param pos1  Iterator referencing location in string to insert at.
1009132720Skan       *  @param str  The string to insert.
1010132720Skan       *  @param pos2  Start of characters in str to insert.
1011132720Skan       *  @param n  Number of characters to insert.
1012132720Skan       *  @return  Reference to this string.
1013132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1014132720Skan       *  @throw  std::out_of_range  If @a pos1 > size() or
1015132720Skan       *  @a pos2 > @a str.size().
1016132720Skan       *
1017132720Skan       *  Starting at @a pos1, insert @a n character of @a str beginning with
1018132720Skan       *  @a pos2.  If adding characters causes the length to exceed
1019132720Skan       *  max_size(), length_error is thrown.  If @a pos1 is beyond the end of
1020132720Skan       *  this string or @a pos2 is beyond the end of @a str, out_of_range is
1021132720Skan       *  thrown.  The value of the string doesn't change if an error is
1022132720Skan       *  thrown.
1023132720Skan      */
1024117397Skan      basic_string&
102597403Sobrien      insert(size_type __pos1, const basic_string& __str,
1026132720Skan	     size_type __pos2, size_type __n)
1027132720Skan      { return this->insert(__pos1, __str._M_data()
1028132720Skan			    + __str._M_check(__pos2, "basic_string::insert"),
1029132720Skan			    __str._M_limit(__pos2, __n)); }
103097403Sobrien
1031132720Skan      /**
1032132720Skan       *  @brief  Insert a C substring.
1033132720Skan       *  @param pos  Iterator referencing location in string to insert at.
1034132720Skan       *  @param s  The C string to insert.
1035132720Skan       *  @param n  The number of characters to insert.
1036132720Skan       *  @return  Reference to this string.
1037132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1038132720Skan       *  @throw  std::out_of_range  If @a pos is beyond the end of this
1039132720Skan       *  string.
1040132720Skan       *
1041132720Skan       *  Inserts the first @a n characters of @a s starting at @a pos.  If
1042132720Skan       *  adding characters causes the length to exceed max_size(),
1043132720Skan       *  length_error is thrown.  If @a pos is beyond end(), out_of_range is
1044132720Skan       *  thrown.  The value of the string doesn't change if an error is
1045132720Skan       *  thrown.
1046132720Skan      */
1047117397Skan      basic_string&
1048117397Skan      insert(size_type __pos, const _CharT* __s, size_type __n);
104997403Sobrien
1050132720Skan      /**
1051132720Skan       *  @brief  Insert a C string.
1052132720Skan       *  @param pos  Iterator referencing location in string to insert at.
1053132720Skan       *  @param s  The C string to insert.
1054132720Skan       *  @return  Reference to this string.
1055132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1056132720Skan       *  @throw  std::out_of_range  If @a pos is beyond the end of this
1057132720Skan       *  string.
1058132720Skan       *
1059132720Skan       *  Inserts the first @a n characters of @a s starting at @a pos.  If
1060132720Skan       *  adding characters causes the length to exceed max_size(),
1061132720Skan       *  length_error is thrown.  If @a pos is beyond end(), out_of_range is
1062132720Skan       *  thrown.  The value of the string doesn't change if an error is
1063132720Skan       *  thrown.
1064132720Skan      */
1065117397Skan      basic_string&
106697403Sobrien      insert(size_type __pos, const _CharT* __s)
1067132720Skan      {
1068132720Skan	__glibcxx_requires_string(__s);
1069132720Skan	return this->insert(__pos, __s, traits_type::length(__s));
1070132720Skan      }
107197403Sobrien
1072132720Skan      /**
1073132720Skan       *  @brief  Insert multiple characters.
1074132720Skan       *  @param pos  Index in string to insert at.
1075132720Skan       *  @param n  Number of characters to insert
1076132720Skan       *  @param c  The character to insert.
1077132720Skan       *  @return  Reference to this string.
1078132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1079132720Skan       *  @throw  std::out_of_range  If @a pos is beyond the end of this
1080132720Skan       *  string.
1081132720Skan       *
1082132720Skan       *  Inserts @a n copies of character @a c starting at index @a pos.  If
1083132720Skan       *  adding characters causes the length to exceed max_size(),
1084132720Skan       *  length_error is thrown.  If @a pos > length(), out_of_range is
1085132720Skan       *  thrown.  The value of the string doesn't change if an error is
1086132720Skan       *  thrown.
1087132720Skan      */
1088117397Skan      basic_string&
108997403Sobrien      insert(size_type __pos, size_type __n, _CharT __c)
1090132720Skan      { return _M_replace_aux(_M_check(__pos, "basic_string::insert"),
1091132720Skan			      size_type(0), __n, __c); }
109297403Sobrien
1093132720Skan      /**
1094132720Skan       *  @brief  Insert one character.
1095132720Skan       *  @param p  Iterator referencing position in string to insert at.
1096132720Skan       *  @param c  The character to insert.
1097132720Skan       *  @return  Iterator referencing newly inserted char.
1098132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1099132720Skan       *
1100132720Skan       *  Inserts character @a c at position referenced by @a p.  If adding
1101132720Skan       *  character causes the length to exceed max_size(), length_error is
1102132720Skan       *  thrown.  If @a p is beyond end of string, out_of_range is thrown.
1103132720Skan       *  The value of the string doesn't change if an error is thrown.
1104132720Skan      */
1105117397Skan      iterator
1106132720Skan      insert(iterator __p, _CharT __c)
110797403Sobrien      {
1108132720Skan	_GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1109132720Skan	const size_type __pos = __p - _M_ibegin();
1110132720Skan	_M_replace_aux(__pos, size_type(0), size_type(1), __c);
1111117397Skan	_M_rep()->_M_set_leaked();
1112169691Skan	return iterator(_M_data() + __pos);
111397403Sobrien      }
111497403Sobrien
1115132720Skan      /**
1116132720Skan       *  @brief  Remove characters.
1117132720Skan       *  @param pos  Index of first character to remove (default 0).
1118132720Skan       *  @param n  Number of characters to remove (default remainder).
1119132720Skan       *  @return  Reference to this string.
1120132720Skan       *  @throw  std::out_of_range  If @a pos is beyond the end of this
1121132720Skan       *  string.
1122132720Skan       *
1123132720Skan       *  Removes @a n characters from this string starting at @a pos.  The
1124132720Skan       *  length of the string is reduced by @a n.  If there are < @a n
1125132720Skan       *  characters to remove, the remainder of the string is truncated.  If
1126132720Skan       *  @a p is beyond end of string, out_of_range is thrown.  The value of
1127132720Skan       *  the string doesn't change if an error is thrown.
1128132720Skan      */
1129117397Skan      basic_string&
113097403Sobrien      erase(size_type __pos = 0, size_type __n = npos)
1131169691Skan      {
1132169691Skan	_M_mutate(_M_check(__pos, "basic_string::erase"),
1133169691Skan		  _M_limit(__pos, __n), size_type(0));
1134169691Skan	return *this;
1135169691Skan      }
113697403Sobrien
1137132720Skan      /**
1138132720Skan       *  @brief  Remove one character.
1139132720Skan       *  @param position  Iterator referencing the character to remove.
1140132720Skan       *  @return  iterator referencing same location after removal.
1141132720Skan       *
1142132720Skan       *  Removes the character at @a position from this string. The value
1143132720Skan       *  of the string doesn't change if an error is thrown.
1144132720Skan      */
1145117397Skan      iterator
114697403Sobrien      erase(iterator __position)
114797403Sobrien      {
1148132720Skan	_GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1149132720Skan				 && __position < _M_iend());
1150132720Skan	const size_type __pos = __position - _M_ibegin();
1151169691Skan	_M_mutate(__pos, size_type(1), size_type(0));
1152117397Skan	_M_rep()->_M_set_leaked();
1153169691Skan	return iterator(_M_data() + __pos);
115497403Sobrien      }
115597403Sobrien
1156132720Skan      /**
1157132720Skan       *  @brief  Remove a range of characters.
1158132720Skan       *  @param first  Iterator referencing the first character to remove.
1159132720Skan       *  @param last  Iterator referencing the end of the range.
1160132720Skan       *  @return  Iterator referencing location of first after removal.
1161132720Skan       *
1162132720Skan       *  Removes the characters in the range [first,last) from this string.
1163132720Skan       *  The value of the string doesn't change if an error is thrown.
1164132720Skan      */
1165117397Skan      iterator
116697403Sobrien      erase(iterator __first, iterator __last)
116797403Sobrien      {
1168132720Skan	_GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1169132720Skan				 && __last <= _M_iend());
1170132720Skan        const size_type __pos = __first - _M_ibegin();
1171169691Skan	_M_mutate(__pos, __last - __first, size_type(0));
117297403Sobrien	_M_rep()->_M_set_leaked();
1173169691Skan	return iterator(_M_data() + __pos);
117497403Sobrien      }
117597403Sobrien
1176132720Skan      /**
1177132720Skan       *  @brief  Replace characters with value from another string.
1178132720Skan       *  @param pos  Index of first character to replace.
1179132720Skan       *  @param n  Number of characters to be replaced.
1180132720Skan       *  @param str  String to insert.
1181132720Skan       *  @return  Reference to this string.
1182132720Skan       *  @throw  std::out_of_range  If @a pos is beyond the end of this
1183132720Skan       *  string.
1184132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1185132720Skan       *
1186132720Skan       *  Removes the characters in the range [pos,pos+n) from this string.
1187132720Skan       *  In place, the value of @a str is inserted.  If @a pos is beyond end
1188132720Skan       *  of string, out_of_range is thrown.  If the length of the result
1189132720Skan       *  exceeds max_size(), length_error is thrown.  The value of the string
1190132720Skan       *  doesn't change if an error is thrown.
1191132720Skan      */
1192117397Skan      basic_string&
119397403Sobrien      replace(size_type __pos, size_type __n, const basic_string& __str)
119497403Sobrien      { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
119597403Sobrien
1196132720Skan      /**
1197132720Skan       *  @brief  Replace characters with value from another string.
1198132720Skan       *  @param pos1  Index of first character to replace.
1199132720Skan       *  @param n1  Number of characters to be replaced.
1200132720Skan       *  @param str  String to insert.
1201132720Skan       *  @param pos2  Index of first character of str to use.
1202132720Skan       *  @param n2  Number of characters from str to use.
1203132720Skan       *  @return  Reference to this string.
1204132720Skan       *  @throw  std::out_of_range  If @a pos1 > size() or @a pos2 >
1205132720Skan       *  str.size().
1206132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1207132720Skan       *
1208132720Skan       *  Removes the characters in the range [pos1,pos1 + n) from this
1209132720Skan       *  string.  In place, the value of @a str is inserted.  If @a pos is
1210132720Skan       *  beyond end of string, out_of_range is thrown.  If the length of the
1211132720Skan       *  result exceeds max_size(), length_error is thrown.  The value of the
1212132720Skan       *  string doesn't change if an error is thrown.
1213132720Skan      */
1214117397Skan      basic_string&
121597403Sobrien      replace(size_type __pos1, size_type __n1, const basic_string& __str,
1216132720Skan	      size_type __pos2, size_type __n2)
1217132720Skan      { return this->replace(__pos1, __n1, __str._M_data()
1218132720Skan			     + __str._M_check(__pos2, "basic_string::replace"),
1219132720Skan			     __str._M_limit(__pos2, __n2)); }
122097403Sobrien
1221132720Skan      /**
1222132720Skan       *  @brief  Replace characters with value of a C substring.
1223132720Skan       *  @param pos  Index of first character to replace.
1224132720Skan       *  @param n1  Number of characters to be replaced.
1225169691Skan       *  @param s  C string to insert.
1226169691Skan       *  @param n2  Number of characters from @a s to use.
1227132720Skan       *  @return  Reference to this string.
1228132720Skan       *  @throw  std::out_of_range  If @a pos1 > size().
1229132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1230132720Skan       *
1231132720Skan       *  Removes the characters in the range [pos,pos + n1) from this string.
1232169691Skan       *  In place, the first @a n2 characters of @a s are inserted, or all
1233169691Skan       *  of @a s if @a n2 is too large.  If @a pos is beyond end of string,
1234132720Skan       *  out_of_range is thrown.  If the length of result exceeds max_size(),
1235132720Skan       *  length_error is thrown.  The value of the string doesn't change if
1236132720Skan       *  an error is thrown.
1237132720Skan      */
1238117397Skan      basic_string&
123997403Sobrien      replace(size_type __pos, size_type __n1, const _CharT* __s,
1240117397Skan	      size_type __n2);
124197403Sobrien
1242132720Skan      /**
1243132720Skan       *  @brief  Replace characters with value of a C string.
1244132720Skan       *  @param pos  Index of first character to replace.
1245132720Skan       *  @param n1  Number of characters to be replaced.
1246169691Skan       *  @param s  C string to insert.
1247132720Skan       *  @return  Reference to this string.
1248132720Skan       *  @throw  std::out_of_range  If @a pos > size().
1249132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1250132720Skan       *
1251132720Skan       *  Removes the characters in the range [pos,pos + n1) from this string.
1252169691Skan       *  In place, the first @a n characters of @a s are inserted.  If @a
1253132720Skan       *  pos is beyond end of string, out_of_range is thrown.  If the length
1254132720Skan       *  of result exceeds max_size(), length_error is thrown.  The value of
1255132720Skan       *  the string doesn't change if an error is thrown.
1256132720Skan      */
1257117397Skan      basic_string&
125897403Sobrien      replace(size_type __pos, size_type __n1, const _CharT* __s)
1259132720Skan      {
1260132720Skan	__glibcxx_requires_string(__s);
1261132720Skan	return this->replace(__pos, __n1, __s, traits_type::length(__s));
1262132720Skan      }
126397403Sobrien
1264132720Skan      /**
1265132720Skan       *  @brief  Replace characters with multiple characters.
1266132720Skan       *  @param pos  Index of first character to replace.
1267132720Skan       *  @param n1  Number of characters to be replaced.
1268132720Skan       *  @param n2  Number of characters to insert.
1269132720Skan       *  @param c  Character to insert.
1270132720Skan       *  @return  Reference to this string.
1271132720Skan       *  @throw  std::out_of_range  If @a pos > size().
1272132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1273132720Skan       *
1274132720Skan       *  Removes the characters in the range [pos,pos + n1) from this string.
1275132720Skan       *  In place, @a n2 copies of @a c are inserted.  If @a pos is beyond
1276132720Skan       *  end of string, out_of_range is thrown.  If the length of result
1277132720Skan       *  exceeds max_size(), length_error is thrown.  The value of the string
1278132720Skan       *  doesn't change if an error is thrown.
1279132720Skan      */
1280117397Skan      basic_string&
128197403Sobrien      replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1282132720Skan      { return _M_replace_aux(_M_check(__pos, "basic_string::replace"),
1283132720Skan			      _M_limit(__pos, __n1), __n2, __c); }
128497403Sobrien
1285132720Skan      /**
1286132720Skan       *  @brief  Replace range of characters with string.
1287132720Skan       *  @param i1  Iterator referencing start of range to replace.
1288132720Skan       *  @param i2  Iterator referencing end of range to replace.
1289132720Skan       *  @param str  String value to insert.
1290132720Skan       *  @return  Reference to this string.
1291132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1292132720Skan       *
1293132720Skan       *  Removes the characters in the range [i1,i2).  In place, the value of
1294132720Skan       *  @a str is inserted.  If the length of result exceeds max_size(),
1295132720Skan       *  length_error is thrown.  The value of the string doesn't change if
1296132720Skan       *  an error is thrown.
1297132720Skan      */
1298117397Skan      basic_string&
129997403Sobrien      replace(iterator __i1, iterator __i2, const basic_string& __str)
130097403Sobrien      { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
130197403Sobrien
1302132720Skan      /**
1303132720Skan       *  @brief  Replace range of characters with C substring.
1304132720Skan       *  @param i1  Iterator referencing start of range to replace.
1305132720Skan       *  @param i2  Iterator referencing end of range to replace.
1306132720Skan       *  @param s  C string value to insert.
1307132720Skan       *  @param n  Number of characters from s to insert.
1308132720Skan       *  @return  Reference to this string.
1309132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1310132720Skan       *
1311132720Skan       *  Removes the characters in the range [i1,i2).  In place, the first @a
1312132720Skan       *  n characters of @a s are inserted.  If the length of result exceeds
1313132720Skan       *  max_size(), length_error is thrown.  The value of the string doesn't
1314132720Skan       *  change if an error is thrown.
1315132720Skan      */
1316117397Skan      basic_string&
1317132720Skan      replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1318132720Skan      {
1319132720Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1320132720Skan				 && __i2 <= _M_iend());
1321132720Skan	return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1322132720Skan      }
132397403Sobrien
1324132720Skan      /**
1325132720Skan       *  @brief  Replace range of characters with C string.
1326132720Skan       *  @param i1  Iterator referencing start of range to replace.
1327132720Skan       *  @param i2  Iterator referencing end of range to replace.
1328132720Skan       *  @param s  C string value to insert.
1329132720Skan       *  @return  Reference to this string.
1330132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1331132720Skan       *
1332132720Skan       *  Removes the characters in the range [i1,i2).  In place, the
1333132720Skan       *  characters of @a s are inserted.  If the length of result exceeds
1334132720Skan       *  max_size(), length_error is thrown.  The value of the string doesn't
1335132720Skan       *  change if an error is thrown.
1336132720Skan      */
1337117397Skan      basic_string&
133897403Sobrien      replace(iterator __i1, iterator __i2, const _CharT* __s)
1339132720Skan      {
1340132720Skan	__glibcxx_requires_string(__s);
1341132720Skan	return this->replace(__i1, __i2, __s, traits_type::length(__s));
1342132720Skan      }
134397403Sobrien
1344132720Skan      /**
1345132720Skan       *  @brief  Replace range of characters with multiple characters
1346132720Skan       *  @param i1  Iterator referencing start of range to replace.
1347132720Skan       *  @param i2  Iterator referencing end of range to replace.
1348132720Skan       *  @param n  Number of characters to insert.
1349132720Skan       *  @param c  Character to insert.
1350132720Skan       *  @return  Reference to this string.
1351132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1352132720Skan       *
1353132720Skan       *  Removes the characters in the range [i1,i2).  In place, @a n copies
1354132720Skan       *  of @a c are inserted.  If the length of result exceeds max_size(),
1355132720Skan       *  length_error is thrown.  The value of the string doesn't change if
1356132720Skan       *  an error is thrown.
1357132720Skan      */
1358117397Skan      basic_string&
1359132720Skan      replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1360132720Skan      {
1361132720Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1362132720Skan				 && __i2 <= _M_iend());
1363132720Skan	return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1364132720Skan      }
136597403Sobrien
1366132720Skan      /**
1367132720Skan       *  @brief  Replace range of characters with range.
1368132720Skan       *  @param i1  Iterator referencing start of range to replace.
1369132720Skan       *  @param i2  Iterator referencing end of range to replace.
1370132720Skan       *  @param k1  Iterator referencing start of range to insert.
1371132720Skan       *  @param k2  Iterator referencing end of range to insert.
1372132720Skan       *  @return  Reference to this string.
1373132720Skan       *  @throw  std::length_error  If new length exceeds @c max_size().
1374132720Skan       *
1375132720Skan       *  Removes the characters in the range [i1,i2).  In place, characters
1376132720Skan       *  in the range [k1,k2) are inserted.  If the length of result exceeds
1377132720Skan       *  max_size(), length_error is thrown.  The value of the string doesn't
1378132720Skan       *  change if an error is thrown.
1379132720Skan      */
138097403Sobrien      template<class _InputIterator>
1381117397Skan        basic_string&
138297403Sobrien        replace(iterator __i1, iterator __i2,
138397403Sobrien		_InputIterator __k1, _InputIterator __k2)
1384132720Skan        {
1385132720Skan	  _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1386132720Skan				   && __i2 <= _M_iend());
1387132720Skan	  __glibcxx_requires_valid_range(__k1, __k2);
1388169691Skan	  typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1389132720Skan	  return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1390132720Skan	}
139197403Sobrien
1392102782Skan      // Specializations for the common case of pointer and iterator:
1393102782Skan      // useful to avoid the overhead of temporary buffering in _M_replace.
1394117397Skan      basic_string&
1395169691Skan      replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1396169691Skan      {
1397169691Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1398169691Skan				 && __i2 <= _M_iend());
1399169691Skan	__glibcxx_requires_valid_range(__k1, __k2);
1400169691Skan	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1401169691Skan			     __k1, __k2 - __k1);
1402169691Skan      }
1403102782Skan
1404117397Skan      basic_string&
1405169691Skan      replace(iterator __i1, iterator __i2,
1406169691Skan	      const _CharT* __k1, const _CharT* __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, __k2 - __k1);
1413169691Skan      }
1414102782Skan
1415117397Skan      basic_string&
1416169691Skan      replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1417169691Skan      {
1418169691Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1419169691Skan				 && __i2 <= _M_iend());
1420169691Skan	__glibcxx_requires_valid_range(__k1, __k2);
1421169691Skan	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1422169691Skan			     __k1.base(), __k2 - __k1);
1423169691Skan      }
1424102782Skan
1425117397Skan      basic_string&
1426169691Skan      replace(iterator __i1, iterator __i2,
1427169691Skan	      const_iterator __k1, const_iterator __k2)
1428169691Skan      {
1429169691Skan	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1430169691Skan				 && __i2 <= _M_iend());
1431169691Skan	__glibcxx_requires_valid_range(__k1, __k2);
1432169691Skan	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1433169691Skan			     __k1.base(), __k2 - __k1);
1434169691Skan      }
1435169691Skan
143697403Sobrien    private:
1437132720Skan      template<class _Integer>
1438132720Skan	basic_string&
1439132720Skan	_M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1440132720Skan			    _Integer __val, __true_type)
1441132720Skan        { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1442132720Skan
144397403Sobrien      template<class _InputIterator>
1444132720Skan	basic_string&
1445132720Skan	_M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1446132720Skan			    _InputIterator __k2, __false_type);
144797403Sobrien
1448132720Skan      basic_string&
1449132720Skan      _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1450169691Skan		     _CharT __c);
145197403Sobrien
1452132720Skan      basic_string&
1453132720Skan      _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s,
1454169691Skan		      size_type __n2);
1455132720Skan
145697403Sobrien      // _S_construct_aux is used to implement the 21.3.1 para 15 which
145797403Sobrien      // requires special behaviour if _InIter is an integral type
1458132720Skan      template<class _InIterator>
145997403Sobrien        static _CharT*
1460132720Skan        _S_construct_aux(_InIterator __beg, _InIterator __end,
1461132720Skan			 const _Alloc& __a, __false_type)
146297403Sobrien	{
1463132720Skan          typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
146497403Sobrien          return _S_construct(__beg, __end, __a, _Tag());
146597403Sobrien	}
1466117397Skan
1467132720Skan      template<class _InIterator>
146897403Sobrien        static _CharT*
1469132720Skan        _S_construct_aux(_InIterator __beg, _InIterator __end,
1470132720Skan			 const _Alloc& __a, __true_type)
1471132720Skan	{ return _S_construct(static_cast<size_type>(__beg),
1472132720Skan			      static_cast<value_type>(__end), __a); }
1473117397Skan
1474132720Skan      template<class _InIterator>
147597403Sobrien        static _CharT*
1476132720Skan        _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a)
147797403Sobrien	{
1478169691Skan	  typedef typename std::__is_integer<_InIterator>::__type _Integral;
147997403Sobrien	  return _S_construct_aux(__beg, __end, __a, _Integral());
148097403Sobrien        }
148197403Sobrien
148297403Sobrien      // For Input Iterators, used in istreambuf_iterators, etc.
1483132720Skan      template<class _InIterator>
148497403Sobrien        static _CharT*
1485132720Skan         _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
148697403Sobrien		      input_iterator_tag);
1487117397Skan
148897403Sobrien      // For forward_iterators up to random_access_iterators, used for
148997403Sobrien      // string::iterator, _CharT*, etc.
1490132720Skan      template<class _FwdIterator>
149197403Sobrien        static _CharT*
1492132720Skan        _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a,
149397403Sobrien		     forward_iterator_tag);
149497403Sobrien
1495117397Skan      static _CharT*
149697403Sobrien      _S_construct(size_type __req, _CharT __c, const _Alloc& __a);
149797403Sobrien
149897403Sobrien    public:
149997403Sobrien
1500132720Skan      /**
1501132720Skan       *  @brief  Copy substring into C string.
1502132720Skan       *  @param s  C string to copy value into.
1503132720Skan       *  @param n  Number of characters to copy.
1504132720Skan       *  @param pos  Index of first character to copy.
1505132720Skan       *  @return  Number of characters actually copied
1506132720Skan       *  @throw  std::out_of_range  If pos > size().
1507132720Skan       *
1508132720Skan       *  Copies up to @a n characters starting at @a pos into the C string @a
1509132720Skan       *  s.  If @a pos is greater than size(), out_of_range is thrown.
1510132720Skan      */
1511117397Skan      size_type
151297403Sobrien      copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
151397403Sobrien
1514132720Skan      /**
1515132720Skan       *  @brief  Swap contents with another string.
1516132720Skan       *  @param s  String to swap with.
1517132720Skan       *
1518132720Skan       *  Exchanges the contents of this string with that of @a s in constant
1519132720Skan       *  time.
1520132720Skan      */
1521117397Skan      void
1522132720Skan      swap(basic_string& __s);
152397403Sobrien
152497403Sobrien      // String operations:
1525132720Skan      /**
1526132720Skan       *  @brief  Return const pointer to null-terminated contents.
1527132720Skan       *
1528132720Skan       *  This is a handle to internal data.  Do not modify or dire things may
1529132720Skan       *  happen.
1530132720Skan      */
1531117397Skan      const _CharT*
1532169691Skan      c_str() const
1533169691Skan      { return _M_data(); }
153497403Sobrien
1535132720Skan      /**
1536132720Skan       *  @brief  Return const pointer to contents.
1537132720Skan       *
1538132720Skan       *  This is a handle to internal data.  Do not modify or dire things may
1539132720Skan       *  happen.
1540132720Skan      */
1541117397Skan      const _CharT*
1542169691Skan      data() const
1543169691Skan      { return _M_data(); }
154497403Sobrien
1545132720Skan      /**
1546132720Skan       *  @brief  Return copy of allocator used to construct this string.
1547132720Skan      */
1548117397Skan      allocator_type
1549169691Skan      get_allocator() const
1550169691Skan      { return _M_dataplus; }
155197403Sobrien
1552132720Skan      /**
1553132720Skan       *  @brief  Find position of a C substring.
1554132720Skan       *  @param s  C string to locate.
1555132720Skan       *  @param pos  Index of character to search from.
1556132720Skan       *  @param n  Number of characters from @a s to search for.
1557132720Skan       *  @return  Index of start of first occurrence.
1558132720Skan       *
1559132720Skan       *  Starting from @a pos, searches forward for the first @a n characters
1560132720Skan       *  in @a s within this string.  If found, returns the index where it
1561132720Skan       *  begins.  If not found, returns npos.
1562132720Skan      */
1563117397Skan      size_type
156497403Sobrien      find(const _CharT* __s, size_type __pos, size_type __n) const;
156597403Sobrien
1566132720Skan      /**
1567132720Skan       *  @brief  Find position of a string.
1568132720Skan       *  @param str  String to locate.
1569132720Skan       *  @param pos  Index of character to search from (default 0).
1570132720Skan       *  @return  Index of start of first occurrence.
1571132720Skan       *
1572132720Skan       *  Starting from @a pos, searches forward for value of @a str within
1573132720Skan       *  this string.  If found, returns the index where it begins.  If not
1574132720Skan       *  found, returns npos.
1575132720Skan      */
1576117397Skan      size_type
157797403Sobrien      find(const basic_string& __str, size_type __pos = 0) const
157897403Sobrien      { return this->find(__str.data(), __pos, __str.size()); }
157997403Sobrien
1580132720Skan      /**
1581132720Skan       *  @brief  Find position of a C string.
1582132720Skan       *  @param s  C string to locate.
1583132720Skan       *  @param pos  Index of character to search from (default 0).
1584132720Skan       *  @return  Index of start of first occurrence.
1585132720Skan       *
1586132720Skan       *  Starting from @a pos, searches forward for the value of @a s within
1587132720Skan       *  this string.  If found, returns the index where it begins.  If not
1588132720Skan       *  found, returns npos.
1589132720Skan      */
1590117397Skan      size_type
159197403Sobrien      find(const _CharT* __s, size_type __pos = 0) const
1592132720Skan      {
1593132720Skan	__glibcxx_requires_string(__s);
1594132720Skan	return this->find(__s, __pos, traits_type::length(__s));
1595132720Skan      }
159697403Sobrien
1597132720Skan      /**
1598132720Skan       *  @brief  Find position of a character.
1599132720Skan       *  @param c  Character to locate.
1600132720Skan       *  @param pos  Index of character to search from (default 0).
1601132720Skan       *  @return  Index of first occurrence.
1602132720Skan       *
1603132720Skan       *  Starting from @a pos, searches forward for @a c within this string.
1604132720Skan       *  If found, returns the index where it was found.  If not found,
1605132720Skan       *  returns npos.
1606132720Skan      */
1607117397Skan      size_type
160897403Sobrien      find(_CharT __c, size_type __pos = 0) const;
160997403Sobrien
1610132720Skan      /**
1611132720Skan       *  @brief  Find last position of a string.
1612132720Skan       *  @param str  String to locate.
1613132720Skan       *  @param pos  Index of character to search back from (default end).
1614132720Skan       *  @return  Index of start of last occurrence.
1615132720Skan       *
1616132720Skan       *  Starting from @a pos, searches backward for value of @a str within
1617132720Skan       *  this string.  If found, returns the index where it begins.  If not
1618132720Skan       *  found, returns npos.
1619132720Skan      */
1620117397Skan      size_type
162197403Sobrien      rfind(const basic_string& __str, size_type __pos = npos) const
162297403Sobrien      { return this->rfind(__str.data(), __pos, __str.size()); }
162397403Sobrien
1624132720Skan      /**
1625132720Skan       *  @brief  Find last position of a C substring.
1626132720Skan       *  @param s  C string to locate.
1627132720Skan       *  @param pos  Index of character to search back from.
1628132720Skan       *  @param n  Number of characters from s to search for.
1629132720Skan       *  @return  Index of start of last occurrence.
1630132720Skan       *
1631132720Skan       *  Starting from @a pos, searches backward for the first @a n
1632132720Skan       *  characters in @a s within this string.  If found, returns the index
1633132720Skan       *  where it begins.  If not found, returns npos.
1634132720Skan      */
1635117397Skan      size_type
163697403Sobrien      rfind(const _CharT* __s, size_type __pos, size_type __n) const;
163797403Sobrien
1638132720Skan      /**
1639132720Skan       *  @brief  Find last position of a C string.
1640132720Skan       *  @param s  C string to locate.
1641169691Skan       *  @param pos  Index of character to start search at (default end).
1642132720Skan       *  @return  Index of start of  last occurrence.
1643132720Skan       *
1644132720Skan       *  Starting from @a pos, searches backward for the value of @a s within
1645132720Skan       *  this string.  If found, returns the index where it begins.  If not
1646132720Skan       *  found, returns npos.
1647132720Skan      */
1648117397Skan      size_type
164997403Sobrien      rfind(const _CharT* __s, size_type __pos = npos) const
1650132720Skan      {
1651132720Skan	__glibcxx_requires_string(__s);
1652132720Skan	return this->rfind(__s, __pos, traits_type::length(__s));
1653132720Skan      }
165497403Sobrien
1655132720Skan      /**
1656132720Skan       *  @brief  Find last position of a character.
1657132720Skan       *  @param c  Character to locate.
1658169691Skan       *  @param pos  Index of character to search back from (default end).
1659132720Skan       *  @return  Index of last occurrence.
1660132720Skan       *
1661132720Skan       *  Starting from @a pos, searches backward for @a c within this string.
1662132720Skan       *  If found, returns the index where it was found.  If not found,
1663132720Skan       *  returns npos.
1664132720Skan      */
1665117397Skan      size_type
166697403Sobrien      rfind(_CharT __c, size_type __pos = npos) const;
166797403Sobrien
1668132720Skan      /**
1669132720Skan       *  @brief  Find position of a character of string.
1670132720Skan       *  @param str  String containing characters to locate.
1671132720Skan       *  @param pos  Index of character to search from (default 0).
1672132720Skan       *  @return  Index of first occurrence.
1673132720Skan       *
1674132720Skan       *  Starting from @a pos, searches forward for one of the characters of
1675132720Skan       *  @a str within this string.  If found, returns the index where it was
1676132720Skan       *  found.  If not found, returns npos.
1677132720Skan      */
1678117397Skan      size_type
167997403Sobrien      find_first_of(const basic_string& __str, size_type __pos = 0) const
168097403Sobrien      { return this->find_first_of(__str.data(), __pos, __str.size()); }
168197403Sobrien
1682132720Skan      /**
1683132720Skan       *  @brief  Find position of a character of C substring.
1684132720Skan       *  @param s  String containing characters to locate.
1685229551Spfg       *  @param pos  Index of character to search from.
1686132720Skan       *  @param n  Number of characters from s to search for.
1687132720Skan       *  @return  Index of first occurrence.
1688132720Skan       *
1689132720Skan       *  Starting from @a pos, searches forward for one of the first @a n
1690132720Skan       *  characters of @a s within this string.  If found, returns the index
1691132720Skan       *  where it was found.  If not found, returns npos.
1692132720Skan      */
1693117397Skan      size_type
169497403Sobrien      find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
169597403Sobrien
1696132720Skan      /**
1697132720Skan       *  @brief  Find position of a character of C string.
1698132720Skan       *  @param s  String containing characters to locate.
1699132720Skan       *  @param pos  Index of character to search from (default 0).
1700132720Skan       *  @return  Index of first occurrence.
1701132720Skan       *
1702132720Skan       *  Starting from @a pos, searches forward for one of the characters of
1703132720Skan       *  @a s within this string.  If found, returns the index where it was
1704132720Skan       *  found.  If not found, returns npos.
1705132720Skan      */
1706117397Skan      size_type
170797403Sobrien      find_first_of(const _CharT* __s, size_type __pos = 0) const
1708132720Skan      {
1709132720Skan	__glibcxx_requires_string(__s);
1710132720Skan	return this->find_first_of(__s, __pos, traits_type::length(__s));
1711132720Skan      }
171297403Sobrien
1713132720Skan      /**
1714132720Skan       *  @brief  Find position of a character.
1715132720Skan       *  @param c  Character to locate.
1716132720Skan       *  @param pos  Index of character to search from (default 0).
1717132720Skan       *  @return  Index of first occurrence.
1718132720Skan       *
1719132720Skan       *  Starting from @a pos, searches forward for the character @a c within
1720132720Skan       *  this string.  If found, returns the index where it was found.  If
1721132720Skan       *  not found, returns npos.
1722132720Skan       *
1723132720Skan       *  Note: equivalent to find(c, pos).
1724132720Skan      */
1725117397Skan      size_type
172697403Sobrien      find_first_of(_CharT __c, size_type __pos = 0) const
172797403Sobrien      { return this->find(__c, __pos); }
172897403Sobrien
1729132720Skan      /**
1730132720Skan       *  @brief  Find last position of a character of string.
1731132720Skan       *  @param str  String containing characters to locate.
1732132720Skan       *  @param pos  Index of character to search back from (default end).
1733132720Skan       *  @return  Index of last occurrence.
1734132720Skan       *
1735132720Skan       *  Starting from @a pos, searches backward for one of the characters of
1736132720Skan       *  @a str within this string.  If found, returns the index where it was
1737132720Skan       *  found.  If not found, returns npos.
1738132720Skan      */
1739117397Skan      size_type
174097403Sobrien      find_last_of(const basic_string& __str, size_type __pos = npos) const
174197403Sobrien      { return this->find_last_of(__str.data(), __pos, __str.size()); }
174297403Sobrien
1743132720Skan      /**
1744132720Skan       *  @brief  Find last position of a character of C substring.
1745132720Skan       *  @param s  C string containing characters to locate.
1746229551Spfg       *  @param pos  Index of character to search back from.
1747132720Skan       *  @param n  Number of characters from s to search for.
1748132720Skan       *  @return  Index of last occurrence.
1749132720Skan       *
1750132720Skan       *  Starting from @a pos, searches backward for one of the first @a n
1751132720Skan       *  characters of @a s within this string.  If found, returns the index
1752132720Skan       *  where it was found.  If not found, returns npos.
1753132720Skan      */
1754117397Skan      size_type
175597403Sobrien      find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
175697403Sobrien
1757132720Skan      /**
1758132720Skan       *  @brief  Find last position of a character of C string.
1759132720Skan       *  @param s  C string containing characters to locate.
1760132720Skan       *  @param pos  Index of character to search back from (default end).
1761132720Skan       *  @return  Index of last occurrence.
1762132720Skan       *
1763132720Skan       *  Starting from @a pos, searches backward for one of the characters of
1764132720Skan       *  @a s within this string.  If found, returns the index where it was
1765132720Skan       *  found.  If not found, returns npos.
1766132720Skan      */
1767117397Skan      size_type
176897403Sobrien      find_last_of(const _CharT* __s, size_type __pos = npos) const
1769132720Skan      {
1770132720Skan	__glibcxx_requires_string(__s);
1771132720Skan	return this->find_last_of(__s, __pos, traits_type::length(__s));
1772132720Skan      }
177397403Sobrien
1774132720Skan      /**
1775132720Skan       *  @brief  Find last position of a character.
1776132720Skan       *  @param c  Character to locate.
1777229551Spfg       *  @param pos  Index of character to search back from (default end).
1778132720Skan       *  @return  Index of last occurrence.
1779132720Skan       *
1780132720Skan       *  Starting from @a pos, searches backward for @a c within this string.
1781132720Skan       *  If found, returns the index where it was found.  If not found,
1782132720Skan       *  returns npos.
1783132720Skan       *
1784132720Skan       *  Note: equivalent to rfind(c, pos).
1785132720Skan      */
1786117397Skan      size_type
178797403Sobrien      find_last_of(_CharT __c, size_type __pos = npos) const
178897403Sobrien      { return this->rfind(__c, __pos); }
178997403Sobrien
1790132720Skan      /**
1791132720Skan       *  @brief  Find position of a character not in string.
1792132720Skan       *  @param str  String containing characters to avoid.
1793132720Skan       *  @param pos  Index of character to search from (default 0).
1794132720Skan       *  @return  Index of first occurrence.
1795132720Skan       *
1796132720Skan       *  Starting from @a pos, searches forward for a character not contained
1797132720Skan       *  in @a str within this string.  If found, returns the index where it
1798132720Skan       *  was found.  If not found, returns npos.
1799132720Skan      */
1800117397Skan      size_type
180197403Sobrien      find_first_not_of(const basic_string& __str, size_type __pos = 0) const
180297403Sobrien      { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
180397403Sobrien
1804132720Skan      /**
1805132720Skan       *  @brief  Find position of a character not in C substring.
1806132720Skan       *  @param s  C string containing characters to avoid.
1807229551Spfg       *  @param pos  Index of character to search from.
1808132720Skan       *  @param n  Number of characters from s to consider.
1809132720Skan       *  @return  Index of first occurrence.
1810132720Skan       *
1811132720Skan       *  Starting from @a pos, searches forward for a character not contained
1812132720Skan       *  in the first @a n characters of @a s within this string.  If found,
1813132720Skan       *  returns the index where it was found.  If not found, returns npos.
1814132720Skan      */
1815117397Skan      size_type
1816117397Skan      find_first_not_of(const _CharT* __s, size_type __pos,
181797403Sobrien			size_type __n) const;
181897403Sobrien
1819132720Skan      /**
1820132720Skan       *  @brief  Find position of a character not in C string.
1821132720Skan       *  @param s  C string containing characters to avoid.
1822132720Skan       *  @param pos  Index of character to search from (default 0).
1823132720Skan       *  @return  Index of first occurrence.
1824132720Skan       *
1825132720Skan       *  Starting from @a pos, searches forward for a character not contained
1826132720Skan       *  in @a s within this string.  If found, returns the index where it
1827132720Skan       *  was found.  If not found, returns npos.
1828132720Skan      */
1829117397Skan      size_type
183097403Sobrien      find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1831132720Skan      {
1832132720Skan	__glibcxx_requires_string(__s);
1833132720Skan	return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1834132720Skan      }
183597403Sobrien
1836132720Skan      /**
1837132720Skan       *  @brief  Find position of a different character.
1838132720Skan       *  @param c  Character to avoid.
1839132720Skan       *  @param pos  Index of character to search from (default 0).
1840132720Skan       *  @return  Index of first occurrence.
1841132720Skan       *
1842132720Skan       *  Starting from @a pos, searches forward for a character other than @a c
1843132720Skan       *  within this string.  If found, returns the index where it was found.
1844132720Skan       *  If not found, returns npos.
1845132720Skan      */
1846117397Skan      size_type
184797403Sobrien      find_first_not_of(_CharT __c, size_type __pos = 0) const;
184897403Sobrien
1849132720Skan      /**
1850132720Skan       *  @brief  Find last position of a character not in string.
1851132720Skan       *  @param str  String containing characters to avoid.
1852229551Spfg       *  @param pos  Index of character to search back from (default end).
1853229551Spfg       *  @return  Index of last occurrence.
1854132720Skan       *
1855132720Skan       *  Starting from @a pos, searches backward for a character not
1856132720Skan       *  contained in @a str within this string.  If found, returns the index
1857132720Skan       *  where it was found.  If not found, returns npos.
1858132720Skan      */
1859117397Skan      size_type
186097403Sobrien      find_last_not_of(const basic_string& __str, size_type __pos = npos) const
186197403Sobrien      { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
186297403Sobrien
1863132720Skan      /**
1864132720Skan       *  @brief  Find last position of a character not in C substring.
1865132720Skan       *  @param s  C string containing characters to avoid.
1866229551Spfg       *  @param pos  Index of character to search back from.
1867132720Skan       *  @param n  Number of characters from s to consider.
1868229551Spfg       *  @return  Index of last occurrence.
1869132720Skan       *
1870132720Skan       *  Starting from @a pos, searches backward for a character not
1871132720Skan       *  contained in the first @a n characters of @a s within this string.
1872132720Skan       *  If found, returns the index where it was found.  If not found,
1873132720Skan       *  returns npos.
1874132720Skan      */
1875117397Skan      size_type
1876117397Skan      find_last_not_of(const _CharT* __s, size_type __pos,
187797403Sobrien		       size_type __n) const;
1878132720Skan      /**
1879229551Spfg       *  @brief  Find last position of a character not in C string.
1880132720Skan       *  @param s  C string containing characters to avoid.
1881229551Spfg       *  @param pos  Index of character to search back from (default end).
1882229551Spfg       *  @return  Index of last occurrence.
1883132720Skan       *
1884132720Skan       *  Starting from @a pos, searches backward for a character not
1885132720Skan       *  contained in @a s within this string.  If found, returns the index
1886132720Skan       *  where it was found.  If not found, returns npos.
1887132720Skan      */
1888117397Skan      size_type
188997403Sobrien      find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1890132720Skan      {
1891132720Skan	__glibcxx_requires_string(__s);
1892132720Skan	return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1893132720Skan      }
189497403Sobrien
1895132720Skan      /**
1896132720Skan       *  @brief  Find last position of a different character.
1897132720Skan       *  @param c  Character to avoid.
1898229551Spfg       *  @param pos  Index of character to search back from (default end).
1899229551Spfg       *  @return  Index of last occurrence.
1900132720Skan       *
1901132720Skan       *  Starting from @a pos, searches backward for a character other than
1902132720Skan       *  @a c within this string.  If found, returns the index where it was
1903132720Skan       *  found.  If not found, returns npos.
1904132720Skan      */
1905117397Skan      size_type
190697403Sobrien      find_last_not_of(_CharT __c, size_type __pos = npos) const;
190797403Sobrien
1908132720Skan      /**
1909132720Skan       *  @brief  Get a substring.
1910132720Skan       *  @param pos  Index of first character (default 0).
1911132720Skan       *  @param n  Number of characters in substring (default remainder).
1912132720Skan       *  @return  The new string.
1913132720Skan       *  @throw  std::out_of_range  If pos > size().
1914132720Skan       *
1915132720Skan       *  Construct and return a new string using the @a n characters starting
1916132720Skan       *  at @a pos.  If the string is too short, use the remainder of the
1917132720Skan       *  characters.  If @a pos is beyond the end of the string, out_of_range
1918132720Skan       *  is thrown.
1919132720Skan      */
1920117397Skan      basic_string
192197403Sobrien      substr(size_type __pos = 0, size_type __n = npos) const
1922132720Skan      { return basic_string(*this,
1923132720Skan			    _M_check(__pos, "basic_string::substr"), __n); }
192497403Sobrien
1925132720Skan      /**
1926132720Skan       *  @brief  Compare to a string.
1927132720Skan       *  @param str  String to compare against.
1928132720Skan       *  @return  Integer < 0, 0, or > 0.
1929132720Skan       *
1930132720Skan       *  Returns an integer < 0 if this string is ordered before @a str, 0 if
1931132720Skan       *  their values are equivalent, or > 0 if this string is ordered after
1932146897Skan       *  @a str.  Determines the effective length rlen of the strings to
1933146897Skan       *  compare as the smallest of size() and str.size().  The function
1934146897Skan       *  then compares the two strings by calling traits::compare(data(),
1935146897Skan       *  str.data(),rlen).  If the result of the comparison is nonzero returns
1936146897Skan       *  it, otherwise the shorter one is ordered first.
1937132720Skan      */
1938117397Skan      int
193997403Sobrien      compare(const basic_string& __str) const
194097403Sobrien      {
1941132720Skan	const size_type __size = this->size();
1942132720Skan	const size_type __osize = __str.size();
1943132720Skan	const size_type __len = std::min(__size, __osize);
1944117397Skan
194597403Sobrien	int __r = traits_type::compare(_M_data(), __str.data(), __len);
194697403Sobrien	if (!__r)
1947259705Spfg	  __r =  _S_compare(__size, __osize);
194897403Sobrien	return __r;
194997403Sobrien      }
195097403Sobrien
1951132720Skan      /**
1952132720Skan       *  @brief  Compare substring to a string.
1953132720Skan       *  @param pos  Index of first character of substring.
1954132720Skan       *  @param n  Number of characters in substring.
1955132720Skan       *  @param str  String to compare against.
1956132720Skan       *  @return  Integer < 0, 0, or > 0.
1957132720Skan       *
1958132720Skan       *  Form the substring of this string from the @a n characters starting
1959132720Skan       *  at @a pos.  Returns an integer < 0 if the substring is ordered
1960132720Skan       *  before @a str, 0 if their values are equivalent, or > 0 if the
1961146897Skan       *  substring is ordered after @a str.  Determines the effective length
1962146897Skan       *  rlen of the strings to compare as the smallest of the length of the
1963146897Skan       *  substring and @a str.size().  The function then compares the two
1964146897Skan       *  strings by calling traits::compare(substring.data(),str.data(),rlen).
1965146897Skan       *  If the result of the comparison is nonzero returns it, otherwise the
1966146897Skan       *  shorter one is ordered first.
1967132720Skan      */
1968117397Skan      int
196997403Sobrien      compare(size_type __pos, size_type __n, const basic_string& __str) const;
197097403Sobrien
1971132720Skan      /**
1972132720Skan       *  @brief  Compare substring to a substring.
1973132720Skan       *  @param pos1  Index of first character of substring.
1974132720Skan       *  @param n1  Number of characters in substring.
1975132720Skan       *  @param str  String to compare against.
1976132720Skan       *  @param pos2  Index of first character of substring of str.
1977132720Skan       *  @param n2  Number of characters in substring of str.
1978132720Skan       *  @return  Integer < 0, 0, or > 0.
1979132720Skan       *
1980132720Skan       *  Form the substring of this string from the @a n1 characters starting
1981132720Skan       *  at @a pos1.  Form the substring of @a str from the @a n2 characters
1982132720Skan       *  starting at @a pos2.  Returns an integer < 0 if this substring is
1983132720Skan       *  ordered before the substring of @a str, 0 if their values are
1984132720Skan       *  equivalent, or > 0 if this substring is ordered after the substring
1985146897Skan       *  of @a str.  Determines the effective length rlen of the strings
1986146897Skan       *  to compare as the smallest of the lengths of the substrings.  The
1987146897Skan       *  function then compares the two strings by calling
1988146897Skan       *  traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
1989146897Skan       *  If the result of the comparison is nonzero returns it, otherwise the
1990146897Skan       *  shorter one is ordered first.
1991132720Skan      */
1992117397Skan      int
199397403Sobrien      compare(size_type __pos1, size_type __n1, const basic_string& __str,
199497403Sobrien	      size_type __pos2, size_type __n2) const;
199597403Sobrien
1996132720Skan      /**
1997132720Skan       *  @brief  Compare to a C string.
1998132720Skan       *  @param s  C string to compare against.
1999132720Skan       *  @return  Integer < 0, 0, or > 0.
2000132720Skan       *
2001132720Skan       *  Returns an integer < 0 if this string is ordered before @a s, 0 if
2002132720Skan       *  their values are equivalent, or > 0 if this string is ordered after
2003146897Skan       *  @a s.  Determines the effective length rlen of the strings to
2004146897Skan       *  compare as the smallest of size() and the length of a string
2005146897Skan       *  constructed from @a s.  The function then compares the two strings
2006146897Skan       *  by calling traits::compare(data(),s,rlen).  If the result of the
2007146897Skan       *  comparison is nonzero returns it, otherwise the shorter one is
2008146897Skan       *  ordered first.
2009132720Skan      */
2010117397Skan      int
201197403Sobrien      compare(const _CharT* __s) const;
201297403Sobrien
2013132720Skan      // _GLIBCXX_RESOLVE_LIB_DEFECTS
2014117397Skan      // 5 String::compare specification questionable
2015132720Skan      /**
2016132720Skan       *  @brief  Compare substring to a C string.
2017132720Skan       *  @param pos  Index of first character of substring.
2018132720Skan       *  @param n1  Number of characters in substring.
2019132720Skan       *  @param s  C string to compare against.
2020132720Skan       *  @return  Integer < 0, 0, or > 0.
2021132720Skan       *
2022132720Skan       *  Form the substring of this string from the @a n1 characters starting
2023132720Skan       *  at @a pos.  Returns an integer < 0 if the substring is ordered
2024132720Skan       *  before @a s, 0 if their values are equivalent, or > 0 if the
2025146897Skan       *  substring is ordered after @a s.  Determines the effective length
2026146897Skan       *  rlen of the strings to compare as the smallest of the length of the
2027146897Skan       *  substring and the length of a string constructed from @a s.  The
2028146897Skan       *  function then compares the two string by calling
2029146897Skan       *  traits::compare(substring.data(),s,rlen).  If the result of the
2030146897Skan       *  comparison is nonzero returns it, otherwise the shorter one is
2031146897Skan       *  ordered first.
2032132720Skan      */
2033117397Skan      int
203497403Sobrien      compare(size_type __pos, size_type __n1, const _CharT* __s) const;
203597403Sobrien
2036132720Skan      /**
2037132720Skan       *  @brief  Compare substring against a character array.
2038132720Skan       *  @param pos1  Index of first character of substring.
2039132720Skan       *  @param n1  Number of characters in substring.
2040132720Skan       *  @param s  character array to compare against.
2041132720Skan       *  @param n2  Number of characters of s.
2042132720Skan       *  @return  Integer < 0, 0, or > 0.
2043132720Skan       *
2044132720Skan       *  Form the substring of this string from the @a n1 characters starting
2045132720Skan       *  at @a pos1.  Form a string from the first @a n2 characters of @a s.
2046132720Skan       *  Returns an integer < 0 if this substring is ordered before the string
2047132720Skan       *  from @a s, 0 if their values are equivalent, or > 0 if this substring
2048146897Skan       *  is ordered after the string from @a s.   Determines the effective
2049146897Skan       *  length rlen of the strings to compare as the smallest of the length
2050146897Skan       *  of the substring and @a n2.  The function then compares the two
2051146897Skan       *  strings by calling traits::compare(substring.data(),s,rlen).  If the
2052146897Skan       *  result of the comparison is nonzero returns it, otherwise the shorter
2053146897Skan       *  one is ordered first.
2054132720Skan       *
2055132720Skan       *  NB: s must have at least n2 characters, '\0' has no special
2056132720Skan       *  meaning.
2057132720Skan      */
2058117397Skan      int
2059117397Skan      compare(size_type __pos, size_type __n1, const _CharT* __s,
206097403Sobrien	      size_type __n2) const;
206197403Sobrien  };
206297403Sobrien
206397403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
206497403Sobrien    inline basic_string<_CharT, _Traits, _Alloc>::
206597403Sobrien    basic_string()
2066146897Skan#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
2067132720Skan    : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
2068146897Skan#else
2069146897Skan    : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()) { }
2070146897Skan#endif
207197403Sobrien
207297403Sobrien  // operator+
2073132720Skan  /**
2074132720Skan   *  @brief  Concatenate two strings.
2075132720Skan   *  @param lhs  First string.
2076132720Skan   *  @param rhs  Last string.
2077132720Skan   *  @return  New string with value of @a lhs followed by @a rhs.
2078132720Skan   */
207997403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
208097403Sobrien    basic_string<_CharT, _Traits, _Alloc>
208197403Sobrien    operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
208297403Sobrien	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
208397403Sobrien    {
208497403Sobrien      basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
208597403Sobrien      __str.append(__rhs);
208697403Sobrien      return __str;
208797403Sobrien    }
208897403Sobrien
2089132720Skan  /**
2090132720Skan   *  @brief  Concatenate C string and string.
2091132720Skan   *  @param lhs  First string.
2092132720Skan   *  @param rhs  Last string.
2093132720Skan   *  @return  New string with value of @a lhs followed by @a rhs.
2094132720Skan   */
209597403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
209697403Sobrien    basic_string<_CharT,_Traits,_Alloc>
209797403Sobrien    operator+(const _CharT* __lhs,
209897403Sobrien	      const basic_string<_CharT,_Traits,_Alloc>& __rhs);
209997403Sobrien
2100132720Skan  /**
2101132720Skan   *  @brief  Concatenate character and 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    basic_string<_CharT,_Traits,_Alloc>
210897403Sobrien    operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs);
210997403Sobrien
2110132720Skan  /**
2111132720Skan   *  @brief  Concatenate string and C string.
2112132720Skan   *  @param lhs  First string.
2113132720Skan   *  @param rhs  Last string.
2114132720Skan   *  @return  New string with @a lhs followed by @a rhs.
2115132720Skan   */
211697403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
211797403Sobrien    inline basic_string<_CharT, _Traits, _Alloc>
211897403Sobrien    operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
211997403Sobrien	     const _CharT* __rhs)
212097403Sobrien    {
212197403Sobrien      basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
212297403Sobrien      __str.append(__rhs);
212397403Sobrien      return __str;
212497403Sobrien    }
212597403Sobrien
2126132720Skan  /**
2127132720Skan   *  @brief  Concatenate string and character.
2128132720Skan   *  @param lhs  First string.
2129132720Skan   *  @param rhs  Last string.
2130132720Skan   *  @return  New string with @a lhs followed by @a rhs.
2131132720Skan   */
213297403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
213397403Sobrien    inline basic_string<_CharT, _Traits, _Alloc>
213497403Sobrien    operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
213597403Sobrien    {
2136132720Skan      typedef basic_string<_CharT, _Traits, _Alloc>	__string_type;
213797403Sobrien      typedef typename __string_type::size_type		__size_type;
213897403Sobrien      __string_type __str(__lhs);
213997403Sobrien      __str.append(__size_type(1), __rhs);
214097403Sobrien      return __str;
214197403Sobrien    }
214297403Sobrien
214397403Sobrien  // operator ==
2144132720Skan  /**
2145132720Skan   *  @brief  Test equivalence of two strings.
2146132720Skan   *  @param lhs  First string.
2147132720Skan   *  @param rhs  Second string.
2148132720Skan   *  @return  True if @a lhs.compare(@a rhs) == 0.  False otherwise.
2149132720Skan   */
215097403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
215197403Sobrien    inline bool
215297403Sobrien    operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
215397403Sobrien	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
215497403Sobrien    { return __lhs.compare(__rhs) == 0; }
215597403Sobrien
2156132720Skan  /**
2157132720Skan   *  @brief  Test equivalence of C string and string.
2158132720Skan   *  @param lhs  C string.
2159132720Skan   *  @param rhs  String.
2160132720Skan   *  @return  True if @a rhs.compare(@a lhs) == 0.  False otherwise.
2161132720Skan   */
216297403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
216397403Sobrien    inline bool
216497403Sobrien    operator==(const _CharT* __lhs,
216597403Sobrien	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
216697403Sobrien    { return __rhs.compare(__lhs) == 0; }
216797403Sobrien
2168132720Skan  /**
2169132720Skan   *  @brief  Test equivalence of string and C string.
2170132720Skan   *  @param lhs  String.
2171132720Skan   *  @param rhs  C string.
2172132720Skan   *  @return  True if @a lhs.compare(@a rhs) == 0.  False otherwise.
2173132720Skan   */
217497403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
217597403Sobrien    inline bool
217697403Sobrien    operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
217797403Sobrien	       const _CharT* __rhs)
217897403Sobrien    { return __lhs.compare(__rhs) == 0; }
217997403Sobrien
218097403Sobrien  // operator !=
2181132720Skan  /**
2182132720Skan   *  @brief  Test difference of two strings.
2183132720Skan   *  @param lhs  First string.
2184132720Skan   *  @param rhs  Second string.
2185132720Skan   *  @return  True if @a lhs.compare(@a rhs) != 0.  False otherwise.
2186132720Skan   */
218797403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
218897403Sobrien    inline bool
218997403Sobrien    operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
219097403Sobrien	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
219197403Sobrien    { return __rhs.compare(__lhs) != 0; }
219297403Sobrien
2193132720Skan  /**
2194132720Skan   *  @brief  Test difference of C string and string.
2195132720Skan   *  @param lhs  C string.
2196132720Skan   *  @param rhs  String.
2197132720Skan   *  @return  True if @a rhs.compare(@a lhs) != 0.  False otherwise.
2198132720Skan   */
219997403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
220097403Sobrien    inline bool
220197403Sobrien    operator!=(const _CharT* __lhs,
220297403Sobrien	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
220397403Sobrien    { return __rhs.compare(__lhs) != 0; }
220497403Sobrien
2205132720Skan  /**
2206132720Skan   *  @brief  Test difference of string and C string.
2207132720Skan   *  @param lhs  String.
2208132720Skan   *  @param rhs  C string.
2209132720Skan   *  @return  True if @a lhs.compare(@a rhs) != 0.  False otherwise.
2210132720Skan   */
221197403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
221297403Sobrien    inline bool
221397403Sobrien    operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
221497403Sobrien	       const _CharT* __rhs)
221597403Sobrien    { return __lhs.compare(__rhs) != 0; }
221697403Sobrien
221797403Sobrien  // operator <
2218132720Skan  /**
2219132720Skan   *  @brief  Test if string precedes string.
2220132720Skan   *  @param lhs  First string.
2221132720Skan   *  @param rhs  Second string.
2222132720Skan   *  @return  True if @a lhs precedes @a rhs.  False otherwise.
2223132720Skan   */
222497403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
222597403Sobrien    inline bool
222697403Sobrien    operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
222797403Sobrien	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
222897403Sobrien    { return __lhs.compare(__rhs) < 0; }
222997403Sobrien
2230132720Skan  /**
2231132720Skan   *  @brief  Test if string precedes C string.
2232132720Skan   *  @param lhs  String.
2233132720Skan   *  @param rhs  C string.
2234132720Skan   *  @return  True if @a lhs precedes @a rhs.  False otherwise.
2235132720Skan   */
223697403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
223797403Sobrien    inline bool
223897403Sobrien    operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
223997403Sobrien	      const _CharT* __rhs)
224097403Sobrien    { return __lhs.compare(__rhs) < 0; }
224197403Sobrien
2242132720Skan  /**
2243132720Skan   *  @brief  Test if C string precedes string.
2244132720Skan   *  @param lhs  C string.
2245132720Skan   *  @param rhs  String.
2246132720Skan   *  @return  True if @a lhs precedes @a rhs.  False otherwise.
2247132720Skan   */
224897403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
224997403Sobrien    inline bool
225097403Sobrien    operator<(const _CharT* __lhs,
225197403Sobrien	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
225297403Sobrien    { return __rhs.compare(__lhs) > 0; }
225397403Sobrien
225497403Sobrien  // operator >
2255132720Skan  /**
2256132720Skan   *  @brief  Test if string follows string.
2257132720Skan   *  @param lhs  First string.
2258132720Skan   *  @param rhs  Second string.
2259132720Skan   *  @return  True if @a lhs follows @a rhs.  False otherwise.
2260132720Skan   */
226197403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
226297403Sobrien    inline bool
226397403Sobrien    operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
226497403Sobrien	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
226597403Sobrien    { return __lhs.compare(__rhs) > 0; }
226697403Sobrien
2267132720Skan  /**
2268132720Skan   *  @brief  Test if string follows C string.
2269132720Skan   *  @param lhs  String.
2270132720Skan   *  @param rhs  C string.
2271132720Skan   *  @return  True if @a lhs follows @a rhs.  False otherwise.
2272132720Skan   */
227397403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
227497403Sobrien    inline bool
227597403Sobrien    operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
227697403Sobrien	      const _CharT* __rhs)
227797403Sobrien    { return __lhs.compare(__rhs) > 0; }
227897403Sobrien
2279132720Skan  /**
2280132720Skan   *  @brief  Test if C string follows string.
2281132720Skan   *  @param lhs  C string.
2282132720Skan   *  @param rhs  String.
2283132720Skan   *  @return  True if @a lhs follows @a rhs.  False otherwise.
2284132720Skan   */
228597403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
228697403Sobrien    inline bool
228797403Sobrien    operator>(const _CharT* __lhs,
228897403Sobrien	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
228997403Sobrien    { return __rhs.compare(__lhs) < 0; }
229097403Sobrien
229197403Sobrien  // operator <=
2292132720Skan  /**
2293132720Skan   *  @brief  Test if string doesn't follow string.
2294132720Skan   *  @param lhs  First string.
2295132720Skan   *  @param rhs  Second string.
2296132720Skan   *  @return  True if @a lhs doesn't follow @a rhs.  False otherwise.
2297132720Skan   */
229897403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
229997403Sobrien    inline bool
230097403Sobrien    operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
230197403Sobrien	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
230297403Sobrien    { return __lhs.compare(__rhs) <= 0; }
230397403Sobrien
2304132720Skan  /**
2305132720Skan   *  @brief  Test if string doesn't follow C string.
2306132720Skan   *  @param lhs  String.
2307132720Skan   *  @param rhs  C string.
2308132720Skan   *  @return  True if @a lhs doesn't follow @a rhs.  False otherwise.
2309132720Skan   */
231097403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
231197403Sobrien    inline bool
231297403Sobrien    operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
231397403Sobrien	       const _CharT* __rhs)
231497403Sobrien    { return __lhs.compare(__rhs) <= 0; }
231597403Sobrien
2316132720Skan  /**
2317132720Skan   *  @brief  Test if C string doesn't follow string.
2318132720Skan   *  @param lhs  C string.
2319132720Skan   *  @param rhs  String.
2320132720Skan   *  @return  True if @a lhs doesn't follow @a rhs.  False otherwise.
2321132720Skan   */
232297403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
232397403Sobrien    inline bool
232497403Sobrien    operator<=(const _CharT* __lhs,
232597403Sobrien	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2326169691Skan    { return __rhs.compare(__lhs) >= 0; }
232797403Sobrien
232897403Sobrien  // operator >=
2329132720Skan  /**
2330132720Skan   *  @brief  Test if string doesn't precede string.
2331132720Skan   *  @param lhs  First string.
2332132720Skan   *  @param rhs  Second string.
2333132720Skan   *  @return  True if @a lhs doesn't precede @a rhs.  False otherwise.
2334132720Skan   */
233597403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
233697403Sobrien    inline bool
233797403Sobrien    operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
233897403Sobrien	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
233997403Sobrien    { return __lhs.compare(__rhs) >= 0; }
234097403Sobrien
2341132720Skan  /**
2342132720Skan   *  @brief  Test if string doesn't precede C string.
2343132720Skan   *  @param lhs  String.
2344132720Skan   *  @param rhs  C string.
2345132720Skan   *  @return  True if @a lhs doesn't precede @a rhs.  False otherwise.
2346132720Skan   */
234797403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
234897403Sobrien    inline bool
234997403Sobrien    operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
235097403Sobrien	       const _CharT* __rhs)
235197403Sobrien    { return __lhs.compare(__rhs) >= 0; }
235297403Sobrien
2353132720Skan  /**
2354132720Skan   *  @brief  Test if C string doesn't precede string.
2355132720Skan   *  @param lhs  C string.
2356132720Skan   *  @param rhs  String.
2357132720Skan   *  @return  True if @a lhs doesn't precede @a rhs.  False otherwise.
2358132720Skan   */
235997403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
236097403Sobrien    inline bool
236197403Sobrien    operator>=(const _CharT* __lhs,
236297403Sobrien	     const basic_string<_CharT, _Traits, _Alloc>& __rhs)
236397403Sobrien    { return __rhs.compare(__lhs) <= 0; }
236497403Sobrien
2365132720Skan  /**
2366132720Skan   *  @brief  Swap contents of two strings.
2367132720Skan   *  @param lhs  First string.
2368132720Skan   *  @param rhs  Second string.
2369132720Skan   *
2370132720Skan   *  Exchanges the contents of @a lhs and @a rhs in constant time.
2371132720Skan   */
237297403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
237397403Sobrien    inline void
237497403Sobrien    swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
237597403Sobrien	 basic_string<_CharT, _Traits, _Alloc>& __rhs)
237697403Sobrien    { __lhs.swap(__rhs); }
237797403Sobrien
2378132720Skan  /**
2379132720Skan   *  @brief  Read stream into a string.
2380132720Skan   *  @param is  Input stream.
2381132720Skan   *  @param str  Buffer to store into.
2382132720Skan   *  @return  Reference to the input stream.
2383132720Skan   *
2384132720Skan   *  Stores characters from @a is into @a str until whitespace is found, the
2385132720Skan   *  end of the stream is encountered, or str.max_size() is reached.  If
2386132720Skan   *  is.width() is non-zero, that is the limit on the number of characters
2387132720Skan   *  stored into @a str.  Any previous contents of @a str are erased.
2388132720Skan   */
238997403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
239097403Sobrien    basic_istream<_CharT, _Traits>&
239197403Sobrien    operator>>(basic_istream<_CharT, _Traits>& __is,
239297403Sobrien	       basic_string<_CharT, _Traits, _Alloc>& __str);
239397403Sobrien
2394169691Skan  template<>
2395169691Skan    basic_istream<char>&
2396169691Skan    operator>>(basic_istream<char>& __is, basic_string<char>& __str);
2397169691Skan
2398132720Skan  /**
2399132720Skan   *  @brief  Write string to a stream.
2400132720Skan   *  @param os  Output stream.
2401132720Skan   *  @param str  String to write out.
2402132720Skan   *  @return  Reference to the output stream.
2403132720Skan   *
2404132720Skan   *  Output characters of @a str into os following the same rules as for
2405132720Skan   *  writing a C string.
2406132720Skan   */
240797403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
2408169691Skan    inline basic_ostream<_CharT, _Traits>&
240997403Sobrien    operator<<(basic_ostream<_CharT, _Traits>& __os,
2410169691Skan	       const basic_string<_CharT, _Traits, _Alloc>& __str)
2411169691Skan    {
2412169691Skan      // _GLIBCXX_RESOLVE_LIB_DEFECTS
2413169691Skan      // 586. string inserter not a formatted function
2414169691Skan      return __ostream_insert(__os, __str.data(), __str.size());
2415169691Skan    }
241697403Sobrien
2417132720Skan  /**
2418132720Skan   *  @brief  Read a line from stream into a string.
2419132720Skan   *  @param is  Input stream.
2420132720Skan   *  @param str  Buffer to store into.
2421132720Skan   *  @param delim  Character marking end of line.
2422132720Skan   *  @return  Reference to the input stream.
2423132720Skan   *
2424132720Skan   *  Stores characters from @a is into @a str until @a delim is found, the
2425132720Skan   *  end of the stream is encountered, or str.max_size() is reached.  If
2426132720Skan   *  is.width() is non-zero, that is the limit on the number of characters
2427132720Skan   *  stored into @a str.  Any previous contents of @a str are erased.  If @a
2428132720Skan   *  delim was encountered, it is extracted but not stored into @a str.
2429132720Skan   */
243097403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
2431169691Skan    basic_istream<_CharT, _Traits>&
243297403Sobrien    getline(basic_istream<_CharT, _Traits>& __is,
243397403Sobrien	    basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
243497403Sobrien
2435132720Skan  /**
2436132720Skan   *  @brief  Read a line from stream into a string.
2437132720Skan   *  @param is  Input stream.
2438132720Skan   *  @param str  Buffer to store into.
2439132720Skan   *  @return  Reference to the input stream.
2440132720Skan   *
2441132720Skan   *  Stores characters from is into @a str until '\n' is found, the end of
2442132720Skan   *  the stream is encountered, or str.max_size() is reached.  If is.width()
2443132720Skan   *  is non-zero, that is the limit on the number of characters stored into
2444132720Skan   *  @a str.  Any previous contents of @a str are erased.  If end of line was
2445132720Skan   *  encountered, it is extracted but not stored into @a str.
2446132720Skan   */
244797403Sobrien  template<typename _CharT, typename _Traits, typename _Alloc>
2448169691Skan    inline basic_istream<_CharT, _Traits>&
244997403Sobrien    getline(basic_istream<_CharT, _Traits>& __is,
2450169691Skan	    basic_string<_CharT, _Traits, _Alloc>& __str)
2451169691Skan    { return getline(__is, __str, __is.widen('\n')); }
245297403Sobrien
2453169691Skan  template<>
2454169691Skan    basic_istream<char>&
2455169691Skan    getline(basic_istream<char>& __in, basic_string<char>& __str,
2456169691Skan	    char __delim);
2457169691Skan
2458169691Skan#ifdef _GLIBCXX_USE_WCHAR_T
2459169691Skan  template<>
2460169691Skan    basic_istream<wchar_t>&
2461169691Skan    getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
2462169691Skan	    wchar_t __delim);
2463169691Skan#endif
2464169691Skan
2465169691Skan_GLIBCXX_END_NAMESPACE
2466169691Skan
2467132720Skan#endif /* _BASIC_STRING_H */
2468