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