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