xref: /dflybsd-src/contrib/gcc-8.0/libstdc++-v3/include/bits/basic_string.h (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj // Components for manipulating sequences of characters -*- C++ -*-
2*38fd1498Szrj 
3*38fd1498Szrj // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4*38fd1498Szrj //
5*38fd1498Szrj // This file is part of the GNU ISO C++ Library.  This library is free
6*38fd1498Szrj // software; you can redistribute it and/or modify it under the
7*38fd1498Szrj // terms of the GNU General Public License as published by the
8*38fd1498Szrj // Free Software Foundation; either version 3, or (at your option)
9*38fd1498Szrj // any later version.
10*38fd1498Szrj 
11*38fd1498Szrj // This library is distributed in the hope that it will be useful,
12*38fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*38fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*38fd1498Szrj // GNU General Public License for more details.
15*38fd1498Szrj 
16*38fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional
17*38fd1498Szrj // permissions described in the GCC Runtime Library Exception, version
18*38fd1498Szrj // 3.1, as published by the Free Software Foundation.
19*38fd1498Szrj 
20*38fd1498Szrj // You should have received a copy of the GNU General Public License and
21*38fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program;
22*38fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23*38fd1498Szrj // <http://www.gnu.org/licenses/>.
24*38fd1498Szrj 
25*38fd1498Szrj /** @file bits/basic_string.h
26*38fd1498Szrj  *  This is an internal header file, included by other library headers.
27*38fd1498Szrj  *  Do not attempt to use it directly. @headername{string}
28*38fd1498Szrj  */
29*38fd1498Szrj 
30*38fd1498Szrj //
31*38fd1498Szrj // ISO C++ 14882: 21 Strings library
32*38fd1498Szrj //
33*38fd1498Szrj 
34*38fd1498Szrj #ifndef _BASIC_STRING_H
35*38fd1498Szrj #define _BASIC_STRING_H 1
36*38fd1498Szrj 
37*38fd1498Szrj #pragma GCC system_header
38*38fd1498Szrj 
39*38fd1498Szrj #include <ext/atomicity.h>
40*38fd1498Szrj #include <ext/alloc_traits.h>
41*38fd1498Szrj #include <debug/debug.h>
42*38fd1498Szrj 
43*38fd1498Szrj #if __cplusplus >= 201103L
44*38fd1498Szrj #include <initializer_list>
45*38fd1498Szrj #endif
46*38fd1498Szrj 
47*38fd1498Szrj #if __cplusplus > 201402L
48*38fd1498Szrj # include <string_view>
49*38fd1498Szrj #endif
50*38fd1498Szrj 
51*38fd1498Szrj 
52*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default)
53*38fd1498Szrj {
54*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
55*38fd1498Szrj 
56*38fd1498Szrj #if _GLIBCXX_USE_CXX11_ABI
57*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CXX11
58*38fd1498Szrj   /**
59*38fd1498Szrj    *  @class basic_string basic_string.h <string>
60*38fd1498Szrj    *  @brief  Managing sequences of characters and character-like objects.
61*38fd1498Szrj    *
62*38fd1498Szrj    *  @ingroup strings
63*38fd1498Szrj    *  @ingroup sequences
64*38fd1498Szrj    *
65*38fd1498Szrj    *  @tparam _CharT  Type of character
66*38fd1498Szrj    *  @tparam _Traits  Traits for character type, defaults to
67*38fd1498Szrj    *                   char_traits<_CharT>.
68*38fd1498Szrj    *  @tparam _Alloc  Allocator type, defaults to allocator<_CharT>.
69*38fd1498Szrj    *
70*38fd1498Szrj    *  Meets the requirements of a <a href="tables.html#65">container</a>, a
71*38fd1498Szrj    *  <a href="tables.html#66">reversible container</a>, and a
72*38fd1498Szrj    *  <a href="tables.html#67">sequence</a>.  Of the
73*38fd1498Szrj    *  <a href="tables.html#68">optional sequence requirements</a>, only
74*38fd1498Szrj    *  @c push_back, @c at, and @c %array access are supported.
75*38fd1498Szrj    */
76*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
77*38fd1498Szrj     class basic_string
78*38fd1498Szrj     {
79*38fd1498Szrj       typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
80*38fd1498Szrj 	rebind<_CharT>::other _Char_alloc_type;
81*38fd1498Szrj       typedef __gnu_cxx::__alloc_traits<_Char_alloc_type> _Alloc_traits;
82*38fd1498Szrj 
83*38fd1498Szrj       // Types:
84*38fd1498Szrj     public:
85*38fd1498Szrj       typedef _Traits					traits_type;
86*38fd1498Szrj       typedef typename _Traits::char_type		value_type;
87*38fd1498Szrj       typedef _Char_alloc_type				allocator_type;
88*38fd1498Szrj       typedef typename _Alloc_traits::size_type		size_type;
89*38fd1498Szrj       typedef typename _Alloc_traits::difference_type	difference_type;
90*38fd1498Szrj       typedef typename _Alloc_traits::reference		reference;
91*38fd1498Szrj       typedef typename _Alloc_traits::const_reference	const_reference;
92*38fd1498Szrj       typedef typename _Alloc_traits::pointer		pointer;
93*38fd1498Szrj       typedef typename _Alloc_traits::const_pointer	const_pointer;
94*38fd1498Szrj       typedef __gnu_cxx::__normal_iterator<pointer, basic_string>  iterator;
95*38fd1498Szrj       typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
96*38fd1498Szrj 							const_iterator;
97*38fd1498Szrj       typedef std::reverse_iterator<const_iterator>	const_reverse_iterator;
98*38fd1498Szrj       typedef std::reverse_iterator<iterator>		reverse_iterator;
99*38fd1498Szrj 
100*38fd1498Szrj       ///  Value returned by various member functions when they fail.
101*38fd1498Szrj       static const size_type	npos = static_cast<size_type>(-1);
102*38fd1498Szrj 
103*38fd1498Szrj     private:
104*38fd1498Szrj       // type used for positions in insert, erase etc.
105*38fd1498Szrj #if __cplusplus < 201103L
106*38fd1498Szrj       typedef iterator __const_iterator;
107*38fd1498Szrj #else
108*38fd1498Szrj       typedef const_iterator __const_iterator;
109*38fd1498Szrj #endif
110*38fd1498Szrj 
111*38fd1498Szrj #if __cplusplus > 201402L
112*38fd1498Szrj       // A helper type for avoiding boiler-plate.
113*38fd1498Szrj       typedef basic_string_view<_CharT, _Traits> __sv_type;
114*38fd1498Szrj 
115*38fd1498Szrj       template<typename _Tp, typename _Res>
116*38fd1498Szrj 	using _If_sv = enable_if_t<
117*38fd1498Szrj 	  __and_<is_convertible<const _Tp&, __sv_type>,
118*38fd1498Szrj 		 __not_<is_convertible<const _Tp*, const basic_string*>>,
119*38fd1498Szrj 		 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
120*38fd1498Szrj 	  _Res>;
121*38fd1498Szrj 
122*38fd1498Szrj       // Allows an implicit conversion to __sv_type.
123*38fd1498Szrj       static __sv_type
124*38fd1498Szrj       _S_to_string_view(__sv_type __svt) noexcept
125*38fd1498Szrj       { return __svt; }
126*38fd1498Szrj 
127*38fd1498Szrj       // Wraps a string_view by explicit conversion and thus
128*38fd1498Szrj       // allows to add an internal constructor that does not
129*38fd1498Szrj       // participate in overload resolution when a string_view
130*38fd1498Szrj       // is provided.
131*38fd1498Szrj       struct __sv_wrapper
132*38fd1498Szrj       {
133*38fd1498Szrj 	explicit __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
134*38fd1498Szrj 	__sv_type _M_sv;
135*38fd1498Szrj       };
136*38fd1498Szrj #endif
137*38fd1498Szrj 
138*38fd1498Szrj       // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
139*38fd1498Szrj       struct _Alloc_hider : allocator_type // TODO check __is_final
140*38fd1498Szrj       {
141*38fd1498Szrj #if __cplusplus < 201103L
142*38fd1498Szrj 	_Alloc_hider(pointer __dat, const _Alloc& __a = _Alloc())
143*38fd1498Szrj 	: allocator_type(__a), _M_p(__dat) { }
144*38fd1498Szrj #else
145*38fd1498Szrj 	_Alloc_hider(pointer __dat, const _Alloc& __a)
146*38fd1498Szrj 	: allocator_type(__a), _M_p(__dat) { }
147*38fd1498Szrj 
148*38fd1498Szrj 	_Alloc_hider(pointer __dat, _Alloc&& __a = _Alloc())
149*38fd1498Szrj 	: allocator_type(std::move(__a)), _M_p(__dat) { }
150*38fd1498Szrj #endif
151*38fd1498Szrj 
152*38fd1498Szrj 	pointer _M_p; // The actual data.
153*38fd1498Szrj       };
154*38fd1498Szrj 
155*38fd1498Szrj       _Alloc_hider	_M_dataplus;
156*38fd1498Szrj       size_type		_M_string_length;
157*38fd1498Szrj 
158*38fd1498Szrj       enum { _S_local_capacity = 15 / sizeof(_CharT) };
159*38fd1498Szrj 
160*38fd1498Szrj       union
161*38fd1498Szrj       {
162*38fd1498Szrj 	_CharT           _M_local_buf[_S_local_capacity + 1];
163*38fd1498Szrj 	size_type        _M_allocated_capacity;
164*38fd1498Szrj       };
165*38fd1498Szrj 
166*38fd1498Szrj       void
167*38fd1498Szrj       _M_data(pointer __p)
168*38fd1498Szrj       { _M_dataplus._M_p = __p; }
169*38fd1498Szrj 
170*38fd1498Szrj       void
171*38fd1498Szrj       _M_length(size_type __length)
172*38fd1498Szrj       { _M_string_length = __length; }
173*38fd1498Szrj 
174*38fd1498Szrj       pointer
175*38fd1498Szrj       _M_data() const
176*38fd1498Szrj       { return _M_dataplus._M_p; }
177*38fd1498Szrj 
178*38fd1498Szrj       pointer
179*38fd1498Szrj       _M_local_data()
180*38fd1498Szrj       {
181*38fd1498Szrj #if __cplusplus >= 201103L
182*38fd1498Szrj 	return std::pointer_traits<pointer>::pointer_to(*_M_local_buf);
183*38fd1498Szrj #else
184*38fd1498Szrj 	return pointer(_M_local_buf);
185*38fd1498Szrj #endif
186*38fd1498Szrj       }
187*38fd1498Szrj 
188*38fd1498Szrj       const_pointer
189*38fd1498Szrj       _M_local_data() const
190*38fd1498Szrj       {
191*38fd1498Szrj #if __cplusplus >= 201103L
192*38fd1498Szrj 	return std::pointer_traits<const_pointer>::pointer_to(*_M_local_buf);
193*38fd1498Szrj #else
194*38fd1498Szrj 	return const_pointer(_M_local_buf);
195*38fd1498Szrj #endif
196*38fd1498Szrj       }
197*38fd1498Szrj 
198*38fd1498Szrj       void
199*38fd1498Szrj       _M_capacity(size_type __capacity)
200*38fd1498Szrj       { _M_allocated_capacity = __capacity; }
201*38fd1498Szrj 
202*38fd1498Szrj       void
203*38fd1498Szrj       _M_set_length(size_type __n)
204*38fd1498Szrj       {
205*38fd1498Szrj 	_M_length(__n);
206*38fd1498Szrj 	traits_type::assign(_M_data()[__n], _CharT());
207*38fd1498Szrj       }
208*38fd1498Szrj 
209*38fd1498Szrj       bool
210*38fd1498Szrj       _M_is_local() const
211*38fd1498Szrj       { return _M_data() == _M_local_data(); }
212*38fd1498Szrj 
213*38fd1498Szrj       // Create & Destroy
214*38fd1498Szrj       pointer
215*38fd1498Szrj       _M_create(size_type&, size_type);
216*38fd1498Szrj 
217*38fd1498Szrj       void
218*38fd1498Szrj       _M_dispose()
219*38fd1498Szrj       {
220*38fd1498Szrj 	if (!_M_is_local())
221*38fd1498Szrj 	  _M_destroy(_M_allocated_capacity);
222*38fd1498Szrj       }
223*38fd1498Szrj 
224*38fd1498Szrj       void
225*38fd1498Szrj       _M_destroy(size_type __size) throw()
226*38fd1498Szrj       { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); }
227*38fd1498Szrj 
228*38fd1498Szrj       // _M_construct_aux is used to implement the 21.3.1 para 15 which
229*38fd1498Szrj       // requires special behaviour if _InIterator is an integral type
230*38fd1498Szrj       template<typename _InIterator>
231*38fd1498Szrj         void
232*38fd1498Szrj         _M_construct_aux(_InIterator __beg, _InIterator __end,
233*38fd1498Szrj 			 std::__false_type)
234*38fd1498Szrj 	{
235*38fd1498Szrj           typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
236*38fd1498Szrj           _M_construct(__beg, __end, _Tag());
237*38fd1498Szrj 	}
238*38fd1498Szrj 
239*38fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
240*38fd1498Szrj       // 438. Ambiguity in the "do the right thing" clause
241*38fd1498Szrj       template<typename _Integer>
242*38fd1498Szrj         void
243*38fd1498Szrj         _M_construct_aux(_Integer __beg, _Integer __end, std::__true_type)
244*38fd1498Szrj 	{ _M_construct_aux_2(static_cast<size_type>(__beg), __end); }
245*38fd1498Szrj 
246*38fd1498Szrj       void
247*38fd1498Szrj       _M_construct_aux_2(size_type __req, _CharT __c)
248*38fd1498Szrj       { _M_construct(__req, __c); }
249*38fd1498Szrj 
250*38fd1498Szrj       template<typename _InIterator>
251*38fd1498Szrj         void
252*38fd1498Szrj         _M_construct(_InIterator __beg, _InIterator __end)
253*38fd1498Szrj 	{
254*38fd1498Szrj 	  typedef typename std::__is_integer<_InIterator>::__type _Integral;
255*38fd1498Szrj 	  _M_construct_aux(__beg, __end, _Integral());
256*38fd1498Szrj         }
257*38fd1498Szrj 
258*38fd1498Szrj       // For Input Iterators, used in istreambuf_iterators, etc.
259*38fd1498Szrj       template<typename _InIterator>
260*38fd1498Szrj         void
261*38fd1498Szrj         _M_construct(_InIterator __beg, _InIterator __end,
262*38fd1498Szrj 		     std::input_iterator_tag);
263*38fd1498Szrj 
264*38fd1498Szrj       // For forward_iterators up to random_access_iterators, used for
265*38fd1498Szrj       // string::iterator, _CharT*, etc.
266*38fd1498Szrj       template<typename _FwdIterator>
267*38fd1498Szrj         void
268*38fd1498Szrj         _M_construct(_FwdIterator __beg, _FwdIterator __end,
269*38fd1498Szrj 		     std::forward_iterator_tag);
270*38fd1498Szrj 
271*38fd1498Szrj       void
272*38fd1498Szrj       _M_construct(size_type __req, _CharT __c);
273*38fd1498Szrj 
274*38fd1498Szrj       allocator_type&
275*38fd1498Szrj       _M_get_allocator()
276*38fd1498Szrj       { return _M_dataplus; }
277*38fd1498Szrj 
278*38fd1498Szrj       const allocator_type&
279*38fd1498Szrj       _M_get_allocator() const
280*38fd1498Szrj       { return _M_dataplus; }
281*38fd1498Szrj 
282*38fd1498Szrj     private:
283*38fd1498Szrj 
284*38fd1498Szrj #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
285*38fd1498Szrj       // The explicit instantiations in misc-inst.cc require this due to
286*38fd1498Szrj       // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64063
287*38fd1498Szrj       template<typename _Tp, bool _Requires =
288*38fd1498Szrj 	       !__are_same<_Tp, _CharT*>::__value
289*38fd1498Szrj 	       && !__are_same<_Tp, const _CharT*>::__value
290*38fd1498Szrj 	       && !__are_same<_Tp, iterator>::__value
291*38fd1498Szrj 	       && !__are_same<_Tp, const_iterator>::__value>
292*38fd1498Szrj 	struct __enable_if_not_native_iterator
293*38fd1498Szrj 	{ typedef basic_string& __type; };
294*38fd1498Szrj       template<typename _Tp>
295*38fd1498Szrj 	struct __enable_if_not_native_iterator<_Tp, false> { };
296*38fd1498Szrj #endif
297*38fd1498Szrj 
298*38fd1498Szrj       size_type
299*38fd1498Szrj       _M_check(size_type __pos, const char* __s) const
300*38fd1498Szrj       {
301*38fd1498Szrj 	if (__pos > this->size())
302*38fd1498Szrj 	  __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
303*38fd1498Szrj 				       "this->size() (which is %zu)"),
304*38fd1498Szrj 				   __s, __pos, this->size());
305*38fd1498Szrj 	return __pos;
306*38fd1498Szrj       }
307*38fd1498Szrj 
308*38fd1498Szrj       void
309*38fd1498Szrj       _M_check_length(size_type __n1, size_type __n2, const char* __s) const
310*38fd1498Szrj       {
311*38fd1498Szrj 	if (this->max_size() - (this->size() - __n1) < __n2)
312*38fd1498Szrj 	  __throw_length_error(__N(__s));
313*38fd1498Szrj       }
314*38fd1498Szrj 
315*38fd1498Szrj 
316*38fd1498Szrj       // NB: _M_limit doesn't check for a bad __pos value.
317*38fd1498Szrj       size_type
318*38fd1498Szrj       _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT
319*38fd1498Szrj       {
320*38fd1498Szrj 	const bool __testoff =  __off < this->size() - __pos;
321*38fd1498Szrj 	return __testoff ? __off : this->size() - __pos;
322*38fd1498Szrj       }
323*38fd1498Szrj 
324*38fd1498Szrj       // True if _Rep and source do not overlap.
325*38fd1498Szrj       bool
326*38fd1498Szrj       _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT
327*38fd1498Szrj       {
328*38fd1498Szrj 	return (less<const _CharT*>()(__s, _M_data())
329*38fd1498Szrj 		|| less<const _CharT*>()(_M_data() + this->size(), __s));
330*38fd1498Szrj       }
331*38fd1498Szrj 
332*38fd1498Szrj       // When __n = 1 way faster than the general multichar
333*38fd1498Szrj       // traits_type::copy/move/assign.
334*38fd1498Szrj       static void
335*38fd1498Szrj       _S_copy(_CharT* __d, const _CharT* __s, size_type __n)
336*38fd1498Szrj       {
337*38fd1498Szrj 	if (__n == 1)
338*38fd1498Szrj 	  traits_type::assign(*__d, *__s);
339*38fd1498Szrj 	else
340*38fd1498Szrj 	  traits_type::copy(__d, __s, __n);
341*38fd1498Szrj       }
342*38fd1498Szrj 
343*38fd1498Szrj       static void
344*38fd1498Szrj       _S_move(_CharT* __d, const _CharT* __s, size_type __n)
345*38fd1498Szrj       {
346*38fd1498Szrj 	if (__n == 1)
347*38fd1498Szrj 	  traits_type::assign(*__d, *__s);
348*38fd1498Szrj 	else
349*38fd1498Szrj 	  traits_type::move(__d, __s, __n);
350*38fd1498Szrj       }
351*38fd1498Szrj 
352*38fd1498Szrj       static void
353*38fd1498Szrj       _S_assign(_CharT* __d, size_type __n, _CharT __c)
354*38fd1498Szrj       {
355*38fd1498Szrj 	if (__n == 1)
356*38fd1498Szrj 	  traits_type::assign(*__d, __c);
357*38fd1498Szrj 	else
358*38fd1498Szrj 	  traits_type::assign(__d, __n, __c);
359*38fd1498Szrj       }
360*38fd1498Szrj 
361*38fd1498Szrj       // _S_copy_chars is a separate template to permit specialization
362*38fd1498Szrj       // to optimize for the common case of pointers as iterators.
363*38fd1498Szrj       template<class _Iterator>
364*38fd1498Szrj         static void
365*38fd1498Szrj         _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
366*38fd1498Szrj         {
367*38fd1498Szrj 	  for (; __k1 != __k2; ++__k1, (void)++__p)
368*38fd1498Szrj 	    traits_type::assign(*__p, *__k1); // These types are off.
369*38fd1498Szrj 	}
370*38fd1498Szrj 
371*38fd1498Szrj       static void
372*38fd1498Szrj       _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
373*38fd1498Szrj       { _S_copy_chars(__p, __k1.base(), __k2.base()); }
374*38fd1498Szrj 
375*38fd1498Szrj       static void
376*38fd1498Szrj       _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
377*38fd1498Szrj       _GLIBCXX_NOEXCEPT
378*38fd1498Szrj       { _S_copy_chars(__p, __k1.base(), __k2.base()); }
379*38fd1498Szrj 
380*38fd1498Szrj       static void
381*38fd1498Szrj       _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
382*38fd1498Szrj       { _S_copy(__p, __k1, __k2 - __k1); }
383*38fd1498Szrj 
384*38fd1498Szrj       static void
385*38fd1498Szrj       _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
386*38fd1498Szrj       _GLIBCXX_NOEXCEPT
387*38fd1498Szrj       { _S_copy(__p, __k1, __k2 - __k1); }
388*38fd1498Szrj 
389*38fd1498Szrj       static int
390*38fd1498Szrj       _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
391*38fd1498Szrj       {
392*38fd1498Szrj 	const difference_type __d = difference_type(__n1 - __n2);
393*38fd1498Szrj 
394*38fd1498Szrj 	if (__d > __gnu_cxx::__numeric_traits<int>::__max)
395*38fd1498Szrj 	  return __gnu_cxx::__numeric_traits<int>::__max;
396*38fd1498Szrj 	else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
397*38fd1498Szrj 	  return __gnu_cxx::__numeric_traits<int>::__min;
398*38fd1498Szrj 	else
399*38fd1498Szrj 	  return int(__d);
400*38fd1498Szrj       }
401*38fd1498Szrj 
402*38fd1498Szrj       void
403*38fd1498Szrj       _M_assign(const basic_string&);
404*38fd1498Szrj 
405*38fd1498Szrj       void
406*38fd1498Szrj       _M_mutate(size_type __pos, size_type __len1, const _CharT* __s,
407*38fd1498Szrj 		size_type __len2);
408*38fd1498Szrj 
409*38fd1498Szrj       void
410*38fd1498Szrj       _M_erase(size_type __pos, size_type __n);
411*38fd1498Szrj 
412*38fd1498Szrj     public:
413*38fd1498Szrj       // Construct/copy/destroy:
414*38fd1498Szrj       // NB: We overload ctors in some cases instead of using default
415*38fd1498Szrj       // arguments, per 17.4.4.4 para. 2 item 2.
416*38fd1498Szrj 
417*38fd1498Szrj       /**
418*38fd1498Szrj        *  @brief  Default constructor creates an empty string.
419*38fd1498Szrj        */
420*38fd1498Szrj       basic_string()
421*38fd1498Szrj       _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value)
422*38fd1498Szrj       : _M_dataplus(_M_local_data())
423*38fd1498Szrj       { _M_set_length(0); }
424*38fd1498Szrj 
425*38fd1498Szrj       /**
426*38fd1498Szrj        *  @brief  Construct an empty string using allocator @a a.
427*38fd1498Szrj        */
428*38fd1498Szrj       explicit
429*38fd1498Szrj       basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT
430*38fd1498Szrj       : _M_dataplus(_M_local_data(), __a)
431*38fd1498Szrj       { _M_set_length(0); }
432*38fd1498Szrj 
433*38fd1498Szrj       /**
434*38fd1498Szrj        *  @brief  Construct string with copy of value of @a __str.
435*38fd1498Szrj        *  @param  __str  Source string.
436*38fd1498Szrj        */
437*38fd1498Szrj       basic_string(const basic_string& __str)
438*38fd1498Szrj       : _M_dataplus(_M_local_data(),
439*38fd1498Szrj 		    _Alloc_traits::_S_select_on_copy(__str._M_get_allocator()))
440*38fd1498Szrj       { _M_construct(__str._M_data(), __str._M_data() + __str.length()); }
441*38fd1498Szrj 
442*38fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
443*38fd1498Szrj       // 2583. no way to supply an allocator for basic_string(str, pos)
444*38fd1498Szrj       /**
445*38fd1498Szrj        *  @brief  Construct string as copy of a substring.
446*38fd1498Szrj        *  @param  __str  Source string.
447*38fd1498Szrj        *  @param  __pos  Index of first character to copy from.
448*38fd1498Szrj        *  @param  __a  Allocator to use.
449*38fd1498Szrj        */
450*38fd1498Szrj       basic_string(const basic_string& __str, size_type __pos,
451*38fd1498Szrj 		   const _Alloc& __a = _Alloc())
452*38fd1498Szrj       : _M_dataplus(_M_local_data(), __a)
453*38fd1498Szrj       {
454*38fd1498Szrj 	const _CharT* __start = __str._M_data()
455*38fd1498Szrj 	  + __str._M_check(__pos, "basic_string::basic_string");
456*38fd1498Szrj 	_M_construct(__start, __start + __str._M_limit(__pos, npos));
457*38fd1498Szrj       }
458*38fd1498Szrj 
459*38fd1498Szrj       /**
460*38fd1498Szrj        *  @brief  Construct string as copy of a substring.
461*38fd1498Szrj        *  @param  __str  Source string.
462*38fd1498Szrj        *  @param  __pos  Index of first character to copy from.
463*38fd1498Szrj        *  @param  __n  Number of characters to copy.
464*38fd1498Szrj        */
465*38fd1498Szrj       basic_string(const basic_string& __str, size_type __pos,
466*38fd1498Szrj 		   size_type __n)
467*38fd1498Szrj       : _M_dataplus(_M_local_data())
468*38fd1498Szrj       {
469*38fd1498Szrj 	const _CharT* __start = __str._M_data()
470*38fd1498Szrj 	  + __str._M_check(__pos, "basic_string::basic_string");
471*38fd1498Szrj 	_M_construct(__start, __start + __str._M_limit(__pos, __n));
472*38fd1498Szrj       }
473*38fd1498Szrj 
474*38fd1498Szrj       /**
475*38fd1498Szrj        *  @brief  Construct string as copy of a substring.
476*38fd1498Szrj        *  @param  __str  Source string.
477*38fd1498Szrj        *  @param  __pos  Index of first character to copy from.
478*38fd1498Szrj        *  @param  __n  Number of characters to copy.
479*38fd1498Szrj        *  @param  __a  Allocator to use.
480*38fd1498Szrj        */
481*38fd1498Szrj       basic_string(const basic_string& __str, size_type __pos,
482*38fd1498Szrj 		   size_type __n, const _Alloc& __a)
483*38fd1498Szrj       : _M_dataplus(_M_local_data(), __a)
484*38fd1498Szrj       {
485*38fd1498Szrj 	const _CharT* __start
486*38fd1498Szrj 	  = __str._M_data() + __str._M_check(__pos, "string::string");
487*38fd1498Szrj 	_M_construct(__start, __start + __str._M_limit(__pos, __n));
488*38fd1498Szrj       }
489*38fd1498Szrj 
490*38fd1498Szrj       /**
491*38fd1498Szrj        *  @brief  Construct string initialized by a character %array.
492*38fd1498Szrj        *  @param  __s  Source character %array.
493*38fd1498Szrj        *  @param  __n  Number of characters to copy.
494*38fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
495*38fd1498Szrj        *
496*38fd1498Szrj        *  NB: @a __s must have at least @a __n characters, &apos;\\0&apos;
497*38fd1498Szrj        *  has no special meaning.
498*38fd1498Szrj        */
499*38fd1498Szrj       basic_string(const _CharT* __s, size_type __n,
500*38fd1498Szrj 		   const _Alloc& __a = _Alloc())
501*38fd1498Szrj       : _M_dataplus(_M_local_data(), __a)
502*38fd1498Szrj       { _M_construct(__s, __s + __n); }
503*38fd1498Szrj 
504*38fd1498Szrj       /**
505*38fd1498Szrj        *  @brief  Construct string as copy of a C string.
506*38fd1498Szrj        *  @param  __s  Source C string.
507*38fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
508*38fd1498Szrj        */
509*38fd1498Szrj       basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
510*38fd1498Szrj       : _M_dataplus(_M_local_data(), __a)
511*38fd1498Szrj       { _M_construct(__s, __s ? __s + traits_type::length(__s) : __s+npos); }
512*38fd1498Szrj 
513*38fd1498Szrj       /**
514*38fd1498Szrj        *  @brief  Construct string as multiple characters.
515*38fd1498Szrj        *  @param  __n  Number of characters.
516*38fd1498Szrj        *  @param  __c  Character to use.
517*38fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
518*38fd1498Szrj        */
519*38fd1498Szrj       basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
520*38fd1498Szrj       : _M_dataplus(_M_local_data(), __a)
521*38fd1498Szrj       { _M_construct(__n, __c); }
522*38fd1498Szrj 
523*38fd1498Szrj #if __cplusplus >= 201103L
524*38fd1498Szrj       /**
525*38fd1498Szrj        *  @brief  Move construct string.
526*38fd1498Szrj        *  @param  __str  Source string.
527*38fd1498Szrj        *
528*38fd1498Szrj        *  The newly-created string contains the exact contents of @a __str.
529*38fd1498Szrj        *  @a __str is a valid, but unspecified string.
530*38fd1498Szrj        **/
531*38fd1498Szrj       basic_string(basic_string&& __str) noexcept
532*38fd1498Szrj       : _M_dataplus(_M_local_data(), std::move(__str._M_get_allocator()))
533*38fd1498Szrj       {
534*38fd1498Szrj 	if (__str._M_is_local())
535*38fd1498Szrj 	  {
536*38fd1498Szrj 	    traits_type::copy(_M_local_buf, __str._M_local_buf,
537*38fd1498Szrj 			      _S_local_capacity + 1);
538*38fd1498Szrj 	  }
539*38fd1498Szrj 	else
540*38fd1498Szrj 	  {
541*38fd1498Szrj 	    _M_data(__str._M_data());
542*38fd1498Szrj 	    _M_capacity(__str._M_allocated_capacity);
543*38fd1498Szrj 	  }
544*38fd1498Szrj 
545*38fd1498Szrj 	// Must use _M_length() here not _M_set_length() because
546*38fd1498Szrj 	// basic_stringbuf relies on writing into unallocated capacity so
547*38fd1498Szrj 	// we mess up the contents if we put a '\0' in the string.
548*38fd1498Szrj 	_M_length(__str.length());
549*38fd1498Szrj 	__str._M_data(__str._M_local_data());
550*38fd1498Szrj 	__str._M_set_length(0);
551*38fd1498Szrj       }
552*38fd1498Szrj 
553*38fd1498Szrj       /**
554*38fd1498Szrj        *  @brief  Construct string from an initializer %list.
555*38fd1498Szrj        *  @param  __l  std::initializer_list of characters.
556*38fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
557*38fd1498Szrj        */
558*38fd1498Szrj       basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
559*38fd1498Szrj       : _M_dataplus(_M_local_data(), __a)
560*38fd1498Szrj       { _M_construct(__l.begin(), __l.end()); }
561*38fd1498Szrj 
562*38fd1498Szrj       basic_string(const basic_string& __str, const _Alloc& __a)
563*38fd1498Szrj       : _M_dataplus(_M_local_data(), __a)
564*38fd1498Szrj       { _M_construct(__str.begin(), __str.end()); }
565*38fd1498Szrj 
566*38fd1498Szrj       basic_string(basic_string&& __str, const _Alloc& __a)
567*38fd1498Szrj       noexcept(_Alloc_traits::_S_always_equal())
568*38fd1498Szrj       : _M_dataplus(_M_local_data(), __a)
569*38fd1498Szrj       {
570*38fd1498Szrj 	if (__str._M_is_local())
571*38fd1498Szrj 	  {
572*38fd1498Szrj 	    traits_type::copy(_M_local_buf, __str._M_local_buf,
573*38fd1498Szrj 			      _S_local_capacity + 1);
574*38fd1498Szrj 	    _M_length(__str.length());
575*38fd1498Szrj 	    __str._M_set_length(0);
576*38fd1498Szrj 	  }
577*38fd1498Szrj 	else if (_Alloc_traits::_S_always_equal()
578*38fd1498Szrj 	    || __str.get_allocator() == __a)
579*38fd1498Szrj 	  {
580*38fd1498Szrj 	    _M_data(__str._M_data());
581*38fd1498Szrj 	    _M_length(__str.length());
582*38fd1498Szrj 	    _M_capacity(__str._M_allocated_capacity);
583*38fd1498Szrj 	    __str._M_data(__str._M_local_buf);
584*38fd1498Szrj 	    __str._M_set_length(0);
585*38fd1498Szrj 	  }
586*38fd1498Szrj 	else
587*38fd1498Szrj 	  _M_construct(__str.begin(), __str.end());
588*38fd1498Szrj       }
589*38fd1498Szrj 
590*38fd1498Szrj #endif // C++11
591*38fd1498Szrj 
592*38fd1498Szrj       /**
593*38fd1498Szrj        *  @brief  Construct string as copy of a range.
594*38fd1498Szrj        *  @param  __beg  Start of range.
595*38fd1498Szrj        *  @param  __end  End of range.
596*38fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
597*38fd1498Szrj        */
598*38fd1498Szrj #if __cplusplus >= 201103L
599*38fd1498Szrj       template<typename _InputIterator,
600*38fd1498Szrj 	       typename = std::_RequireInputIter<_InputIterator>>
601*38fd1498Szrj #else
602*38fd1498Szrj       template<typename _InputIterator>
603*38fd1498Szrj #endif
604*38fd1498Szrj         basic_string(_InputIterator __beg, _InputIterator __end,
605*38fd1498Szrj 		     const _Alloc& __a = _Alloc())
606*38fd1498Szrj 	: _M_dataplus(_M_local_data(), __a)
607*38fd1498Szrj 	{ _M_construct(__beg, __end); }
608*38fd1498Szrj 
609*38fd1498Szrj #if __cplusplus > 201402L
610*38fd1498Szrj       /**
611*38fd1498Szrj        *  @brief  Construct string from a substring of a string_view.
612*38fd1498Szrj        *  @param  __t   Source object convertible to string view.
613*38fd1498Szrj        *  @param  __pos The index of the first character to copy from __t.
614*38fd1498Szrj        *  @param  __n   The number of characters to copy from __t.
615*38fd1498Szrj        *  @param  __a   Allocator to use.
616*38fd1498Szrj        */
617*38fd1498Szrj       template<typename _Tp, typename = _If_sv<_Tp, void>>
618*38fd1498Szrj 	basic_string(const _Tp& __t, size_type __pos, size_type __n,
619*38fd1498Szrj 		     const _Alloc& __a = _Alloc())
620*38fd1498Szrj 	: basic_string(_S_to_string_view(__t).substr(__pos, __n), __a) { }
621*38fd1498Szrj 
622*38fd1498Szrj       /**
623*38fd1498Szrj        *  @brief  Construct string from a string_view.
624*38fd1498Szrj        *  @param  __t  Source object convertible to string view.
625*38fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
626*38fd1498Szrj        */
627*38fd1498Szrj       template<typename _Tp, typename = _If_sv<_Tp, void>>
628*38fd1498Szrj 	explicit
629*38fd1498Szrj 	basic_string(const _Tp& __t, const _Alloc& __a = _Alloc())
630*38fd1498Szrj 	: basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
631*38fd1498Szrj 
632*38fd1498Szrj       /**
633*38fd1498Szrj        *  @brief  Only internally used: Construct string from a string view
634*38fd1498Szrj        *          wrapper.
635*38fd1498Szrj        *  @param  __svw  string view wrapper.
636*38fd1498Szrj        *  @param  __a  Allocator to use.
637*38fd1498Szrj        */
638*38fd1498Szrj       explicit
639*38fd1498Szrj       basic_string(__sv_wrapper __svw, const _Alloc& __a)
640*38fd1498Szrj       : basic_string(__svw._M_sv.data(), __svw._M_sv.size(), __a) { }
641*38fd1498Szrj #endif // C++17
642*38fd1498Szrj 
643*38fd1498Szrj       /**
644*38fd1498Szrj        *  @brief  Destroy the string instance.
645*38fd1498Szrj        */
646*38fd1498Szrj       ~basic_string()
647*38fd1498Szrj       { _M_dispose(); }
648*38fd1498Szrj 
649*38fd1498Szrj       /**
650*38fd1498Szrj        *  @brief  Assign the value of @a str to this string.
651*38fd1498Szrj        *  @param  __str  Source string.
652*38fd1498Szrj        */
653*38fd1498Szrj       basic_string&
654*38fd1498Szrj       operator=(const basic_string& __str)
655*38fd1498Szrj       {
656*38fd1498Szrj #if __cplusplus >= 201103L
657*38fd1498Szrj 	if (_Alloc_traits::_S_propagate_on_copy_assign())
658*38fd1498Szrj 	  {
659*38fd1498Szrj 	    if (!_Alloc_traits::_S_always_equal() && !_M_is_local()
660*38fd1498Szrj 		&& _M_get_allocator() != __str._M_get_allocator())
661*38fd1498Szrj 	      {
662*38fd1498Szrj 		// Propagating allocator cannot free existing storage so must
663*38fd1498Szrj 		// deallocate it before replacing current allocator.
664*38fd1498Szrj 		if (__str.size() <= _S_local_capacity)
665*38fd1498Szrj 		  {
666*38fd1498Szrj 		    _M_destroy(_M_allocated_capacity);
667*38fd1498Szrj 		    _M_data(_M_local_data());
668*38fd1498Szrj 		    _M_set_length(0);
669*38fd1498Szrj 		  }
670*38fd1498Szrj 		else
671*38fd1498Szrj 		  {
672*38fd1498Szrj 		    const auto __len = __str.size();
673*38fd1498Szrj 		    auto __alloc = __str._M_get_allocator();
674*38fd1498Szrj 		    // If this allocation throws there are no effects:
675*38fd1498Szrj 		    auto __ptr = _Alloc_traits::allocate(__alloc, __len + 1);
676*38fd1498Szrj 		    _M_destroy(_M_allocated_capacity);
677*38fd1498Szrj 		    _M_data(__ptr);
678*38fd1498Szrj 		    _M_capacity(__len);
679*38fd1498Szrj 		    _M_set_length(__len);
680*38fd1498Szrj 		  }
681*38fd1498Szrj 	      }
682*38fd1498Szrj 	    std::__alloc_on_copy(_M_get_allocator(), __str._M_get_allocator());
683*38fd1498Szrj 	  }
684*38fd1498Szrj #endif
685*38fd1498Szrj 	return this->assign(__str);
686*38fd1498Szrj       }
687*38fd1498Szrj 
688*38fd1498Szrj       /**
689*38fd1498Szrj        *  @brief  Copy contents of @a s into this string.
690*38fd1498Szrj        *  @param  __s  Source null-terminated string.
691*38fd1498Szrj        */
692*38fd1498Szrj       basic_string&
693*38fd1498Szrj       operator=(const _CharT* __s)
694*38fd1498Szrj       { return this->assign(__s); }
695*38fd1498Szrj 
696*38fd1498Szrj       /**
697*38fd1498Szrj        *  @brief  Set value to string of length 1.
698*38fd1498Szrj        *  @param  __c  Source character.
699*38fd1498Szrj        *
700*38fd1498Szrj        *  Assigning to a character makes this string length 1 and
701*38fd1498Szrj        *  (*this)[0] == @a c.
702*38fd1498Szrj        */
703*38fd1498Szrj       basic_string&
704*38fd1498Szrj       operator=(_CharT __c)
705*38fd1498Szrj       {
706*38fd1498Szrj 	this->assign(1, __c);
707*38fd1498Szrj 	return *this;
708*38fd1498Szrj       }
709*38fd1498Szrj 
710*38fd1498Szrj #if __cplusplus >= 201103L
711*38fd1498Szrj       /**
712*38fd1498Szrj        *  @brief  Move assign the value of @a str to this string.
713*38fd1498Szrj        *  @param  __str  Source string.
714*38fd1498Szrj        *
715*38fd1498Szrj        *  The contents of @a str are moved into this string (without copying).
716*38fd1498Szrj        *  @a str is a valid, but unspecified string.
717*38fd1498Szrj        **/
718*38fd1498Szrj       // PR 58265, this should be noexcept.
719*38fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
720*38fd1498Szrj       // 2063. Contradictory requirements for string move assignment
721*38fd1498Szrj       basic_string&
722*38fd1498Szrj       operator=(basic_string&& __str)
723*38fd1498Szrj       noexcept(_Alloc_traits::_S_nothrow_move())
724*38fd1498Szrj       {
725*38fd1498Szrj 	if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign()
726*38fd1498Szrj 	    && !_Alloc_traits::_S_always_equal()
727*38fd1498Szrj 	    && _M_get_allocator() != __str._M_get_allocator())
728*38fd1498Szrj 	  {
729*38fd1498Szrj 	    // Destroy existing storage before replacing allocator.
730*38fd1498Szrj 	    _M_destroy(_M_allocated_capacity);
731*38fd1498Szrj 	    _M_data(_M_local_data());
732*38fd1498Szrj 	    _M_set_length(0);
733*38fd1498Szrj 	  }
734*38fd1498Szrj 	// Replace allocator if POCMA is true.
735*38fd1498Szrj 	std::__alloc_on_move(_M_get_allocator(), __str._M_get_allocator());
736*38fd1498Szrj 
737*38fd1498Szrj 	if (!__str._M_is_local()
738*38fd1498Szrj 	    && (_Alloc_traits::_S_propagate_on_move_assign()
739*38fd1498Szrj 	      || _Alloc_traits::_S_always_equal()))
740*38fd1498Szrj 	  {
741*38fd1498Szrj 	    pointer __data = nullptr;
742*38fd1498Szrj 	    size_type __capacity;
743*38fd1498Szrj 	    if (!_M_is_local())
744*38fd1498Szrj 	      {
745*38fd1498Szrj 		if (_Alloc_traits::_S_always_equal())
746*38fd1498Szrj 		  {
747*38fd1498Szrj 		    __data = _M_data();
748*38fd1498Szrj 		    __capacity = _M_allocated_capacity;
749*38fd1498Szrj 		  }
750*38fd1498Szrj 		else
751*38fd1498Szrj 		  _M_destroy(_M_allocated_capacity);
752*38fd1498Szrj 	      }
753*38fd1498Szrj 
754*38fd1498Szrj 	    _M_data(__str._M_data());
755*38fd1498Szrj 	    _M_length(__str.length());
756*38fd1498Szrj 	    _M_capacity(__str._M_allocated_capacity);
757*38fd1498Szrj 	    if (__data)
758*38fd1498Szrj 	      {
759*38fd1498Szrj 		__str._M_data(__data);
760*38fd1498Szrj 		__str._M_capacity(__capacity);
761*38fd1498Szrj 	      }
762*38fd1498Szrj 	    else
763*38fd1498Szrj 	      __str._M_data(__str._M_local_buf);
764*38fd1498Szrj 	  }
765*38fd1498Szrj 	else
766*38fd1498Szrj 	    assign(__str);
767*38fd1498Szrj 	__str.clear();
768*38fd1498Szrj 	return *this;
769*38fd1498Szrj       }
770*38fd1498Szrj 
771*38fd1498Szrj       /**
772*38fd1498Szrj        *  @brief  Set value to string constructed from initializer %list.
773*38fd1498Szrj        *  @param  __l  std::initializer_list.
774*38fd1498Szrj        */
775*38fd1498Szrj       basic_string&
776*38fd1498Szrj       operator=(initializer_list<_CharT> __l)
777*38fd1498Szrj       {
778*38fd1498Szrj 	this->assign(__l.begin(), __l.size());
779*38fd1498Szrj 	return *this;
780*38fd1498Szrj       }
781*38fd1498Szrj #endif // C++11
782*38fd1498Szrj 
783*38fd1498Szrj #if __cplusplus > 201402L
784*38fd1498Szrj       /**
785*38fd1498Szrj        *  @brief  Set value to string constructed from a string_view.
786*38fd1498Szrj        *  @param  __svt  An object convertible to string_view.
787*38fd1498Szrj        */
788*38fd1498Szrj      template<typename _Tp>
789*38fd1498Szrj        _If_sv<_Tp, basic_string&>
790*38fd1498Szrj        operator=(const _Tp& __svt)
791*38fd1498Szrj        { return this->assign(__svt); }
792*38fd1498Szrj 
793*38fd1498Szrj       /**
794*38fd1498Szrj        *  @brief  Convert to a string_view.
795*38fd1498Szrj        *  @return A string_view.
796*38fd1498Szrj        */
797*38fd1498Szrj       operator __sv_type() const noexcept
798*38fd1498Szrj       { return __sv_type(data(), size()); }
799*38fd1498Szrj #endif // C++17
800*38fd1498Szrj 
801*38fd1498Szrj       // Iterators:
802*38fd1498Szrj       /**
803*38fd1498Szrj        *  Returns a read/write iterator that points to the first character in
804*38fd1498Szrj        *  the %string.
805*38fd1498Szrj        */
806*38fd1498Szrj       iterator
807*38fd1498Szrj       begin() _GLIBCXX_NOEXCEPT
808*38fd1498Szrj       { return iterator(_M_data()); }
809*38fd1498Szrj 
810*38fd1498Szrj       /**
811*38fd1498Szrj        *  Returns a read-only (constant) iterator that points to the first
812*38fd1498Szrj        *  character in the %string.
813*38fd1498Szrj        */
814*38fd1498Szrj       const_iterator
815*38fd1498Szrj       begin() const _GLIBCXX_NOEXCEPT
816*38fd1498Szrj       { return const_iterator(_M_data()); }
817*38fd1498Szrj 
818*38fd1498Szrj       /**
819*38fd1498Szrj        *  Returns a read/write iterator that points one past the last
820*38fd1498Szrj        *  character in the %string.
821*38fd1498Szrj        */
822*38fd1498Szrj       iterator
823*38fd1498Szrj       end() _GLIBCXX_NOEXCEPT
824*38fd1498Szrj       { return iterator(_M_data() + this->size()); }
825*38fd1498Szrj 
826*38fd1498Szrj       /**
827*38fd1498Szrj        *  Returns a read-only (constant) iterator that points one past the
828*38fd1498Szrj        *  last character in the %string.
829*38fd1498Szrj        */
830*38fd1498Szrj       const_iterator
831*38fd1498Szrj       end() const _GLIBCXX_NOEXCEPT
832*38fd1498Szrj       { return const_iterator(_M_data() + this->size()); }
833*38fd1498Szrj 
834*38fd1498Szrj       /**
835*38fd1498Szrj        *  Returns a read/write reverse iterator that points to the last
836*38fd1498Szrj        *  character in the %string.  Iteration is done in reverse element
837*38fd1498Szrj        *  order.
838*38fd1498Szrj        */
839*38fd1498Szrj       reverse_iterator
840*38fd1498Szrj       rbegin() _GLIBCXX_NOEXCEPT
841*38fd1498Szrj       { return reverse_iterator(this->end()); }
842*38fd1498Szrj 
843*38fd1498Szrj       /**
844*38fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points
845*38fd1498Szrj        *  to the last character in the %string.  Iteration is done in
846*38fd1498Szrj        *  reverse element order.
847*38fd1498Szrj        */
848*38fd1498Szrj       const_reverse_iterator
849*38fd1498Szrj       rbegin() const _GLIBCXX_NOEXCEPT
850*38fd1498Szrj       { return const_reverse_iterator(this->end()); }
851*38fd1498Szrj 
852*38fd1498Szrj       /**
853*38fd1498Szrj        *  Returns a read/write reverse iterator that points to one before the
854*38fd1498Szrj        *  first character in the %string.  Iteration is done in reverse
855*38fd1498Szrj        *  element order.
856*38fd1498Szrj        */
857*38fd1498Szrj       reverse_iterator
858*38fd1498Szrj       rend() _GLIBCXX_NOEXCEPT
859*38fd1498Szrj       { return reverse_iterator(this->begin()); }
860*38fd1498Szrj 
861*38fd1498Szrj       /**
862*38fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points
863*38fd1498Szrj        *  to one before the first character in the %string.  Iteration
864*38fd1498Szrj        *  is done in reverse element order.
865*38fd1498Szrj        */
866*38fd1498Szrj       const_reverse_iterator
867*38fd1498Szrj       rend() const _GLIBCXX_NOEXCEPT
868*38fd1498Szrj       { return const_reverse_iterator(this->begin()); }
869*38fd1498Szrj 
870*38fd1498Szrj #if __cplusplus >= 201103L
871*38fd1498Szrj       /**
872*38fd1498Szrj        *  Returns a read-only (constant) iterator that points to the first
873*38fd1498Szrj        *  character in the %string.
874*38fd1498Szrj        */
875*38fd1498Szrj       const_iterator
876*38fd1498Szrj       cbegin() const noexcept
877*38fd1498Szrj       { return const_iterator(this->_M_data()); }
878*38fd1498Szrj 
879*38fd1498Szrj       /**
880*38fd1498Szrj        *  Returns a read-only (constant) iterator that points one past the
881*38fd1498Szrj        *  last character in the %string.
882*38fd1498Szrj        */
883*38fd1498Szrj       const_iterator
884*38fd1498Szrj       cend() const noexcept
885*38fd1498Szrj       { return const_iterator(this->_M_data() + this->size()); }
886*38fd1498Szrj 
887*38fd1498Szrj       /**
888*38fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points
889*38fd1498Szrj        *  to the last character in the %string.  Iteration is done in
890*38fd1498Szrj        *  reverse element order.
891*38fd1498Szrj        */
892*38fd1498Szrj       const_reverse_iterator
893*38fd1498Szrj       crbegin() const noexcept
894*38fd1498Szrj       { return const_reverse_iterator(this->end()); }
895*38fd1498Szrj 
896*38fd1498Szrj       /**
897*38fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points
898*38fd1498Szrj        *  to one before the first character in the %string.  Iteration
899*38fd1498Szrj        *  is done in reverse element order.
900*38fd1498Szrj        */
901*38fd1498Szrj       const_reverse_iterator
902*38fd1498Szrj       crend() const noexcept
903*38fd1498Szrj       { return const_reverse_iterator(this->begin()); }
904*38fd1498Szrj #endif
905*38fd1498Szrj 
906*38fd1498Szrj     public:
907*38fd1498Szrj       // Capacity:
908*38fd1498Szrj       ///  Returns the number of characters in the string, not including any
909*38fd1498Szrj       ///  null-termination.
910*38fd1498Szrj       size_type
911*38fd1498Szrj       size() const _GLIBCXX_NOEXCEPT
912*38fd1498Szrj       { return _M_string_length; }
913*38fd1498Szrj 
914*38fd1498Szrj       ///  Returns the number of characters in the string, not including any
915*38fd1498Szrj       ///  null-termination.
916*38fd1498Szrj       size_type
917*38fd1498Szrj       length() const _GLIBCXX_NOEXCEPT
918*38fd1498Szrj       { return _M_string_length; }
919*38fd1498Szrj 
920*38fd1498Szrj       ///  Returns the size() of the largest possible %string.
921*38fd1498Szrj       size_type
922*38fd1498Szrj       max_size() const _GLIBCXX_NOEXCEPT
923*38fd1498Szrj       { return (_Alloc_traits::max_size(_M_get_allocator()) - 1) / 2; }
924*38fd1498Szrj 
925*38fd1498Szrj       /**
926*38fd1498Szrj        *  @brief  Resizes the %string to the specified number of characters.
927*38fd1498Szrj        *  @param  __n  Number of characters the %string should contain.
928*38fd1498Szrj        *  @param  __c  Character to fill any new elements.
929*38fd1498Szrj        *
930*38fd1498Szrj        *  This function will %resize the %string to the specified
931*38fd1498Szrj        *  number of characters.  If the number is smaller than the
932*38fd1498Szrj        *  %string's current size the %string is truncated, otherwise
933*38fd1498Szrj        *  the %string is extended and new elements are %set to @a __c.
934*38fd1498Szrj        */
935*38fd1498Szrj       void
936*38fd1498Szrj       resize(size_type __n, _CharT __c);
937*38fd1498Szrj 
938*38fd1498Szrj       /**
939*38fd1498Szrj        *  @brief  Resizes the %string to the specified number of characters.
940*38fd1498Szrj        *  @param  __n  Number of characters the %string should contain.
941*38fd1498Szrj        *
942*38fd1498Szrj        *  This function will resize the %string to the specified length.  If
943*38fd1498Szrj        *  the new size is smaller than the %string's current size the %string
944*38fd1498Szrj        *  is truncated, otherwise the %string is extended and new characters
945*38fd1498Szrj        *  are default-constructed.  For basic types such as char, this means
946*38fd1498Szrj        *  setting them to 0.
947*38fd1498Szrj        */
948*38fd1498Szrj       void
949*38fd1498Szrj       resize(size_type __n)
950*38fd1498Szrj       { this->resize(__n, _CharT()); }
951*38fd1498Szrj 
952*38fd1498Szrj #if __cplusplus >= 201103L
953*38fd1498Szrj       ///  A non-binding request to reduce capacity() to size().
954*38fd1498Szrj       void
955*38fd1498Szrj       shrink_to_fit() noexcept
956*38fd1498Szrj       {
957*38fd1498Szrj #if __cpp_exceptions
958*38fd1498Szrj 	if (capacity() > size())
959*38fd1498Szrj 	  {
960*38fd1498Szrj 	    try
961*38fd1498Szrj 	      { reserve(0); }
962*38fd1498Szrj 	    catch(...)
963*38fd1498Szrj 	      { }
964*38fd1498Szrj 	  }
965*38fd1498Szrj #endif
966*38fd1498Szrj       }
967*38fd1498Szrj #endif
968*38fd1498Szrj 
969*38fd1498Szrj       /**
970*38fd1498Szrj        *  Returns the total number of characters that the %string can hold
971*38fd1498Szrj        *  before needing to allocate more memory.
972*38fd1498Szrj        */
973*38fd1498Szrj       size_type
974*38fd1498Szrj       capacity() const _GLIBCXX_NOEXCEPT
975*38fd1498Szrj       {
976*38fd1498Szrj 	return _M_is_local() ? size_type(_S_local_capacity)
977*38fd1498Szrj 	                     : _M_allocated_capacity;
978*38fd1498Szrj       }
979*38fd1498Szrj 
980*38fd1498Szrj       /**
981*38fd1498Szrj        *  @brief  Attempt to preallocate enough memory for specified number of
982*38fd1498Szrj        *          characters.
983*38fd1498Szrj        *  @param  __res_arg  Number of characters required.
984*38fd1498Szrj        *  @throw  std::length_error  If @a __res_arg exceeds @c max_size().
985*38fd1498Szrj        *
986*38fd1498Szrj        *  This function attempts to reserve enough memory for the
987*38fd1498Szrj        *  %string to hold the specified number of characters.  If the
988*38fd1498Szrj        *  number requested is more than max_size(), length_error is
989*38fd1498Szrj        *  thrown.
990*38fd1498Szrj        *
991*38fd1498Szrj        *  The advantage of this function is that if optimal code is a
992*38fd1498Szrj        *  necessity and the user can determine the string length that will be
993*38fd1498Szrj        *  required, the user can reserve the memory in %advance, and thus
994*38fd1498Szrj        *  prevent a possible reallocation of memory and copying of %string
995*38fd1498Szrj        *  data.
996*38fd1498Szrj        */
997*38fd1498Szrj       void
998*38fd1498Szrj       reserve(size_type __res_arg = 0);
999*38fd1498Szrj 
1000*38fd1498Szrj       /**
1001*38fd1498Szrj        *  Erases the string, making it empty.
1002*38fd1498Szrj        */
1003*38fd1498Szrj       void
1004*38fd1498Szrj       clear() _GLIBCXX_NOEXCEPT
1005*38fd1498Szrj       { _M_set_length(0); }
1006*38fd1498Szrj 
1007*38fd1498Szrj       /**
1008*38fd1498Szrj        *  Returns true if the %string is empty.  Equivalent to
1009*38fd1498Szrj        *  <code>*this == ""</code>.
1010*38fd1498Szrj        */
1011*38fd1498Szrj       bool
1012*38fd1498Szrj       empty() const _GLIBCXX_NOEXCEPT
1013*38fd1498Szrj       { return this->size() == 0; }
1014*38fd1498Szrj 
1015*38fd1498Szrj       // Element access:
1016*38fd1498Szrj       /**
1017*38fd1498Szrj        *  @brief  Subscript access to the data contained in the %string.
1018*38fd1498Szrj        *  @param  __pos  The index of the character to access.
1019*38fd1498Szrj        *  @return  Read-only (constant) reference to the character.
1020*38fd1498Szrj        *
1021*38fd1498Szrj        *  This operator allows for easy, array-style, data access.
1022*38fd1498Szrj        *  Note that data access with this operator is unchecked and
1023*38fd1498Szrj        *  out_of_range lookups are not defined. (For checked lookups
1024*38fd1498Szrj        *  see at().)
1025*38fd1498Szrj        */
1026*38fd1498Szrj       const_reference
1027*38fd1498Szrj       operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT
1028*38fd1498Szrj       {
1029*38fd1498Szrj 	__glibcxx_assert(__pos <= size());
1030*38fd1498Szrj 	return _M_data()[__pos];
1031*38fd1498Szrj       }
1032*38fd1498Szrj 
1033*38fd1498Szrj       /**
1034*38fd1498Szrj        *  @brief  Subscript access to the data contained in the %string.
1035*38fd1498Szrj        *  @param  __pos  The index of the character to access.
1036*38fd1498Szrj        *  @return  Read/write reference to the character.
1037*38fd1498Szrj        *
1038*38fd1498Szrj        *  This operator allows for easy, array-style, data access.
1039*38fd1498Szrj        *  Note that data access with this operator is unchecked and
1040*38fd1498Szrj        *  out_of_range lookups are not defined. (For checked lookups
1041*38fd1498Szrj        *  see at().)
1042*38fd1498Szrj        */
1043*38fd1498Szrj       reference
1044*38fd1498Szrj       operator[](size_type __pos)
1045*38fd1498Szrj       {
1046*38fd1498Szrj         // Allow pos == size() both in C++98 mode, as v3 extension,
1047*38fd1498Szrj 	// and in C++11 mode.
1048*38fd1498Szrj 	__glibcxx_assert(__pos <= size());
1049*38fd1498Szrj         // In pedantic mode be strict in C++98 mode.
1050*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos < size());
1051*38fd1498Szrj 	return _M_data()[__pos];
1052*38fd1498Szrj       }
1053*38fd1498Szrj 
1054*38fd1498Szrj       /**
1055*38fd1498Szrj        *  @brief  Provides access to the data contained in the %string.
1056*38fd1498Szrj        *  @param __n The index of the character to access.
1057*38fd1498Szrj        *  @return  Read-only (const) reference to the character.
1058*38fd1498Szrj        *  @throw  std::out_of_range  If @a n is an invalid index.
1059*38fd1498Szrj        *
1060*38fd1498Szrj        *  This function provides for safer data access.  The parameter is
1061*38fd1498Szrj        *  first checked that it is in the range of the string.  The function
1062*38fd1498Szrj        *  throws out_of_range if the check fails.
1063*38fd1498Szrj        */
1064*38fd1498Szrj       const_reference
1065*38fd1498Szrj       at(size_type __n) const
1066*38fd1498Szrj       {
1067*38fd1498Szrj 	if (__n >= this->size())
1068*38fd1498Szrj 	  __throw_out_of_range_fmt(__N("basic_string::at: __n "
1069*38fd1498Szrj 				       "(which is %zu) >= this->size() "
1070*38fd1498Szrj 				       "(which is %zu)"),
1071*38fd1498Szrj 				   __n, this->size());
1072*38fd1498Szrj 	return _M_data()[__n];
1073*38fd1498Szrj       }
1074*38fd1498Szrj 
1075*38fd1498Szrj       /**
1076*38fd1498Szrj        *  @brief  Provides access to the data contained in the %string.
1077*38fd1498Szrj        *  @param __n The index of the character to access.
1078*38fd1498Szrj        *  @return  Read/write reference to the character.
1079*38fd1498Szrj        *  @throw  std::out_of_range  If @a n is an invalid index.
1080*38fd1498Szrj        *
1081*38fd1498Szrj        *  This function provides for safer data access.  The parameter is
1082*38fd1498Szrj        *  first checked that it is in the range of the string.  The function
1083*38fd1498Szrj        *  throws out_of_range if the check fails.
1084*38fd1498Szrj        */
1085*38fd1498Szrj       reference
1086*38fd1498Szrj       at(size_type __n)
1087*38fd1498Szrj       {
1088*38fd1498Szrj 	if (__n >= size())
1089*38fd1498Szrj 	  __throw_out_of_range_fmt(__N("basic_string::at: __n "
1090*38fd1498Szrj 				       "(which is %zu) >= this->size() "
1091*38fd1498Szrj 				       "(which is %zu)"),
1092*38fd1498Szrj 				   __n, this->size());
1093*38fd1498Szrj 	return _M_data()[__n];
1094*38fd1498Szrj       }
1095*38fd1498Szrj 
1096*38fd1498Szrj #if __cplusplus >= 201103L
1097*38fd1498Szrj       /**
1098*38fd1498Szrj        *  Returns a read/write reference to the data at the first
1099*38fd1498Szrj        *  element of the %string.
1100*38fd1498Szrj        */
1101*38fd1498Szrj       reference
1102*38fd1498Szrj       front() noexcept
1103*38fd1498Szrj       {
1104*38fd1498Szrj 	__glibcxx_assert(!empty());
1105*38fd1498Szrj 	return operator[](0);
1106*38fd1498Szrj       }
1107*38fd1498Szrj 
1108*38fd1498Szrj       /**
1109*38fd1498Szrj        *  Returns a read-only (constant) reference to the data at the first
1110*38fd1498Szrj        *  element of the %string.
1111*38fd1498Szrj        */
1112*38fd1498Szrj       const_reference
1113*38fd1498Szrj       front() const noexcept
1114*38fd1498Szrj       {
1115*38fd1498Szrj 	__glibcxx_assert(!empty());
1116*38fd1498Szrj 	return operator[](0);
1117*38fd1498Szrj       }
1118*38fd1498Szrj 
1119*38fd1498Szrj       /**
1120*38fd1498Szrj        *  Returns a read/write reference to the data at the last
1121*38fd1498Szrj        *  element of the %string.
1122*38fd1498Szrj        */
1123*38fd1498Szrj       reference
1124*38fd1498Szrj       back() noexcept
1125*38fd1498Szrj       {
1126*38fd1498Szrj 	__glibcxx_assert(!empty());
1127*38fd1498Szrj 	return operator[](this->size() - 1);
1128*38fd1498Szrj       }
1129*38fd1498Szrj 
1130*38fd1498Szrj       /**
1131*38fd1498Szrj        *  Returns a read-only (constant) reference to the data at the
1132*38fd1498Szrj        *  last element of the %string.
1133*38fd1498Szrj        */
1134*38fd1498Szrj       const_reference
1135*38fd1498Szrj       back() const noexcept
1136*38fd1498Szrj       {
1137*38fd1498Szrj 	__glibcxx_assert(!empty());
1138*38fd1498Szrj 	return operator[](this->size() - 1);
1139*38fd1498Szrj       }
1140*38fd1498Szrj #endif
1141*38fd1498Szrj 
1142*38fd1498Szrj       // Modifiers:
1143*38fd1498Szrj       /**
1144*38fd1498Szrj        *  @brief  Append a string to this string.
1145*38fd1498Szrj        *  @param __str  The string to append.
1146*38fd1498Szrj        *  @return  Reference to this string.
1147*38fd1498Szrj        */
1148*38fd1498Szrj       basic_string&
1149*38fd1498Szrj       operator+=(const basic_string& __str)
1150*38fd1498Szrj       { return this->append(__str); }
1151*38fd1498Szrj 
1152*38fd1498Szrj       /**
1153*38fd1498Szrj        *  @brief  Append a C string.
1154*38fd1498Szrj        *  @param __s  The C string to append.
1155*38fd1498Szrj        *  @return  Reference to this string.
1156*38fd1498Szrj        */
1157*38fd1498Szrj       basic_string&
1158*38fd1498Szrj       operator+=(const _CharT* __s)
1159*38fd1498Szrj       { return this->append(__s); }
1160*38fd1498Szrj 
1161*38fd1498Szrj       /**
1162*38fd1498Szrj        *  @brief  Append a character.
1163*38fd1498Szrj        *  @param __c  The character to append.
1164*38fd1498Szrj        *  @return  Reference to this string.
1165*38fd1498Szrj        */
1166*38fd1498Szrj       basic_string&
1167*38fd1498Szrj       operator+=(_CharT __c)
1168*38fd1498Szrj       {
1169*38fd1498Szrj 	this->push_back(__c);
1170*38fd1498Szrj 	return *this;
1171*38fd1498Szrj       }
1172*38fd1498Szrj 
1173*38fd1498Szrj #if __cplusplus >= 201103L
1174*38fd1498Szrj       /**
1175*38fd1498Szrj        *  @brief  Append an initializer_list of characters.
1176*38fd1498Szrj        *  @param __l  The initializer_list of characters to be appended.
1177*38fd1498Szrj        *  @return  Reference to this string.
1178*38fd1498Szrj        */
1179*38fd1498Szrj       basic_string&
1180*38fd1498Szrj       operator+=(initializer_list<_CharT> __l)
1181*38fd1498Szrj       { return this->append(__l.begin(), __l.size()); }
1182*38fd1498Szrj #endif // C++11
1183*38fd1498Szrj 
1184*38fd1498Szrj #if __cplusplus > 201402L
1185*38fd1498Szrj       /**
1186*38fd1498Szrj        *  @brief  Append a string_view.
1187*38fd1498Szrj        *  @param __svt  An object convertible to string_view to be appended.
1188*38fd1498Szrj        *  @return  Reference to this string.
1189*38fd1498Szrj        */
1190*38fd1498Szrj       template<typename _Tp>
1191*38fd1498Szrj 	_If_sv<_Tp, basic_string&>
1192*38fd1498Szrj 	operator+=(const _Tp& __svt)
1193*38fd1498Szrj 	{ return this->append(__svt); }
1194*38fd1498Szrj #endif // C++17
1195*38fd1498Szrj 
1196*38fd1498Szrj       /**
1197*38fd1498Szrj        *  @brief  Append a string to this string.
1198*38fd1498Szrj        *  @param __str  The string to append.
1199*38fd1498Szrj        *  @return  Reference to this string.
1200*38fd1498Szrj        */
1201*38fd1498Szrj       basic_string&
1202*38fd1498Szrj       append(const basic_string& __str)
1203*38fd1498Szrj       { return _M_append(__str._M_data(), __str.size()); }
1204*38fd1498Szrj 
1205*38fd1498Szrj       /**
1206*38fd1498Szrj        *  @brief  Append a substring.
1207*38fd1498Szrj        *  @param __str  The string to append.
1208*38fd1498Szrj        *  @param __pos  Index of the first character of str to append.
1209*38fd1498Szrj        *  @param __n  The number of characters to append.
1210*38fd1498Szrj        *  @return  Reference to this string.
1211*38fd1498Szrj        *  @throw  std::out_of_range if @a __pos is not a valid index.
1212*38fd1498Szrj        *
1213*38fd1498Szrj        *  This function appends @a __n characters from @a __str
1214*38fd1498Szrj        *  starting at @a __pos to this string.  If @a __n is is larger
1215*38fd1498Szrj        *  than the number of available characters in @a __str, the
1216*38fd1498Szrj        *  remainder of @a __str is appended.
1217*38fd1498Szrj        */
1218*38fd1498Szrj       basic_string&
1219*38fd1498Szrj       append(const basic_string& __str, size_type __pos, size_type __n)
1220*38fd1498Szrj       { return _M_append(__str._M_data()
1221*38fd1498Szrj 			 + __str._M_check(__pos, "basic_string::append"),
1222*38fd1498Szrj 			 __str._M_limit(__pos, __n)); }
1223*38fd1498Szrj 
1224*38fd1498Szrj       /**
1225*38fd1498Szrj        *  @brief  Append a C substring.
1226*38fd1498Szrj        *  @param __s  The C string to append.
1227*38fd1498Szrj        *  @param __n  The number of characters to append.
1228*38fd1498Szrj        *  @return  Reference to this string.
1229*38fd1498Szrj        */
1230*38fd1498Szrj       basic_string&
1231*38fd1498Szrj       append(const _CharT* __s, size_type __n)
1232*38fd1498Szrj       {
1233*38fd1498Szrj 	__glibcxx_requires_string_len(__s, __n);
1234*38fd1498Szrj 	_M_check_length(size_type(0), __n, "basic_string::append");
1235*38fd1498Szrj 	return _M_append(__s, __n);
1236*38fd1498Szrj       }
1237*38fd1498Szrj 
1238*38fd1498Szrj       /**
1239*38fd1498Szrj        *  @brief  Append a C string.
1240*38fd1498Szrj        *  @param __s  The C string to append.
1241*38fd1498Szrj        *  @return  Reference to this string.
1242*38fd1498Szrj        */
1243*38fd1498Szrj       basic_string&
1244*38fd1498Szrj       append(const _CharT* __s)
1245*38fd1498Szrj       {
1246*38fd1498Szrj 	__glibcxx_requires_string(__s);
1247*38fd1498Szrj 	const size_type __n = traits_type::length(__s);
1248*38fd1498Szrj 	_M_check_length(size_type(0), __n, "basic_string::append");
1249*38fd1498Szrj 	return _M_append(__s, __n);
1250*38fd1498Szrj       }
1251*38fd1498Szrj 
1252*38fd1498Szrj       /**
1253*38fd1498Szrj        *  @brief  Append multiple characters.
1254*38fd1498Szrj        *  @param __n  The number of characters to append.
1255*38fd1498Szrj        *  @param __c  The character to use.
1256*38fd1498Szrj        *  @return  Reference to this string.
1257*38fd1498Szrj        *
1258*38fd1498Szrj        *  Appends __n copies of __c to this string.
1259*38fd1498Szrj        */
1260*38fd1498Szrj       basic_string&
1261*38fd1498Szrj       append(size_type __n, _CharT __c)
1262*38fd1498Szrj       { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
1263*38fd1498Szrj 
1264*38fd1498Szrj #if __cplusplus >= 201103L
1265*38fd1498Szrj       /**
1266*38fd1498Szrj        *  @brief  Append an initializer_list of characters.
1267*38fd1498Szrj        *  @param __l  The initializer_list of characters to append.
1268*38fd1498Szrj        *  @return  Reference to this string.
1269*38fd1498Szrj        */
1270*38fd1498Szrj       basic_string&
1271*38fd1498Szrj       append(initializer_list<_CharT> __l)
1272*38fd1498Szrj       { return this->append(__l.begin(), __l.size()); }
1273*38fd1498Szrj #endif // C++11
1274*38fd1498Szrj 
1275*38fd1498Szrj       /**
1276*38fd1498Szrj        *  @brief  Append a range of characters.
1277*38fd1498Szrj        *  @param __first  Iterator referencing the first character to append.
1278*38fd1498Szrj        *  @param __last  Iterator marking the end of the range.
1279*38fd1498Szrj        *  @return  Reference to this string.
1280*38fd1498Szrj        *
1281*38fd1498Szrj        *  Appends characters in the range [__first,__last) to this string.
1282*38fd1498Szrj        */
1283*38fd1498Szrj #if __cplusplus >= 201103L
1284*38fd1498Szrj       template<class _InputIterator,
1285*38fd1498Szrj 	       typename = std::_RequireInputIter<_InputIterator>>
1286*38fd1498Szrj #else
1287*38fd1498Szrj       template<class _InputIterator>
1288*38fd1498Szrj #endif
1289*38fd1498Szrj         basic_string&
1290*38fd1498Szrj         append(_InputIterator __first, _InputIterator __last)
1291*38fd1498Szrj         { return this->replace(end(), end(), __first, __last); }
1292*38fd1498Szrj 
1293*38fd1498Szrj #if __cplusplus > 201402L
1294*38fd1498Szrj       /**
1295*38fd1498Szrj        *  @brief  Append a string_view.
1296*38fd1498Szrj        *  @param __svt  An object convertible to string_view to be appended.
1297*38fd1498Szrj        *  @return  Reference to this string.
1298*38fd1498Szrj        */
1299*38fd1498Szrj       template<typename _Tp>
1300*38fd1498Szrj         _If_sv<_Tp, basic_string&>
1301*38fd1498Szrj         append(const _Tp& __svt)
1302*38fd1498Szrj         {
1303*38fd1498Szrj           __sv_type __sv = __svt;
1304*38fd1498Szrj           return this->append(__sv.data(), __sv.size());
1305*38fd1498Szrj         }
1306*38fd1498Szrj 
1307*38fd1498Szrj       /**
1308*38fd1498Szrj        *  @brief  Append a range of characters from a string_view.
1309*38fd1498Szrj        *  @param __svt  An object convertible to string_view to be appended from.
1310*38fd1498Szrj        *  @param __pos The position in the string_view to append from.
1311*38fd1498Szrj        *  @param __n   The number of characters to append from the string_view.
1312*38fd1498Szrj        *  @return  Reference to this string.
1313*38fd1498Szrj        */
1314*38fd1498Szrj       template<typename _Tp>
1315*38fd1498Szrj         _If_sv<_Tp, basic_string&>
1316*38fd1498Szrj 	append(const _Tp& __svt, size_type __pos, size_type __n = npos)
1317*38fd1498Szrj 	{
1318*38fd1498Szrj 	  __sv_type __sv = __svt;
1319*38fd1498Szrj 	  return _M_append(__sv.data()
1320*38fd1498Szrj 			   + __sv._M_check(__pos, "basic_string::append"),
1321*38fd1498Szrj 			   __sv._M_limit(__pos, __n));
1322*38fd1498Szrj 	}
1323*38fd1498Szrj #endif // C++17
1324*38fd1498Szrj 
1325*38fd1498Szrj       /**
1326*38fd1498Szrj        *  @brief  Append a single character.
1327*38fd1498Szrj        *  @param __c  Character to append.
1328*38fd1498Szrj        */
1329*38fd1498Szrj       void
1330*38fd1498Szrj       push_back(_CharT __c)
1331*38fd1498Szrj       {
1332*38fd1498Szrj 	const size_type __size = this->size();
1333*38fd1498Szrj 	if (__size + 1 > this->capacity())
1334*38fd1498Szrj 	  this->_M_mutate(__size, size_type(0), 0, size_type(1));
1335*38fd1498Szrj 	traits_type::assign(this->_M_data()[__size], __c);
1336*38fd1498Szrj 	this->_M_set_length(__size + 1);
1337*38fd1498Szrj       }
1338*38fd1498Szrj 
1339*38fd1498Szrj       /**
1340*38fd1498Szrj        *  @brief  Set value to contents of another string.
1341*38fd1498Szrj        *  @param  __str  Source string to use.
1342*38fd1498Szrj        *  @return  Reference to this string.
1343*38fd1498Szrj        */
1344*38fd1498Szrj       basic_string&
1345*38fd1498Szrj       assign(const basic_string& __str)
1346*38fd1498Szrj       {
1347*38fd1498Szrj 	this->_M_assign(__str);
1348*38fd1498Szrj 	return *this;
1349*38fd1498Szrj       }
1350*38fd1498Szrj 
1351*38fd1498Szrj #if __cplusplus >= 201103L
1352*38fd1498Szrj       /**
1353*38fd1498Szrj        *  @brief  Set value to contents of another string.
1354*38fd1498Szrj        *  @param  __str  Source string to use.
1355*38fd1498Szrj        *  @return  Reference to this string.
1356*38fd1498Szrj        *
1357*38fd1498Szrj        *  This function sets this string to the exact contents of @a __str.
1358*38fd1498Szrj        *  @a __str is a valid, but unspecified string.
1359*38fd1498Szrj        */
1360*38fd1498Szrj       basic_string&
1361*38fd1498Szrj       assign(basic_string&& __str)
1362*38fd1498Szrj       noexcept(_Alloc_traits::_S_nothrow_move())
1363*38fd1498Szrj       {
1364*38fd1498Szrj 	// _GLIBCXX_RESOLVE_LIB_DEFECTS
1365*38fd1498Szrj 	// 2063. Contradictory requirements for string move assignment
1366*38fd1498Szrj 	return *this = std::move(__str);
1367*38fd1498Szrj       }
1368*38fd1498Szrj #endif // C++11
1369*38fd1498Szrj 
1370*38fd1498Szrj       /**
1371*38fd1498Szrj        *  @brief  Set value to a substring of a string.
1372*38fd1498Szrj        *  @param __str  The string to use.
1373*38fd1498Szrj        *  @param __pos  Index of the first character of str.
1374*38fd1498Szrj        *  @param __n  Number of characters to use.
1375*38fd1498Szrj        *  @return  Reference to this string.
1376*38fd1498Szrj        *  @throw  std::out_of_range if @a pos is not a valid index.
1377*38fd1498Szrj        *
1378*38fd1498Szrj        *  This function sets this string to the substring of @a __str
1379*38fd1498Szrj        *  consisting of @a __n characters at @a __pos.  If @a __n is
1380*38fd1498Szrj        *  is larger than the number of available characters in @a
1381*38fd1498Szrj        *  __str, the remainder of @a __str is used.
1382*38fd1498Szrj        */
1383*38fd1498Szrj       basic_string&
1384*38fd1498Szrj       assign(const basic_string& __str, size_type __pos, size_type __n)
1385*38fd1498Szrj       { return _M_replace(size_type(0), this->size(), __str._M_data()
1386*38fd1498Szrj 			  + __str._M_check(__pos, "basic_string::assign"),
1387*38fd1498Szrj 			  __str._M_limit(__pos, __n)); }
1388*38fd1498Szrj 
1389*38fd1498Szrj       /**
1390*38fd1498Szrj        *  @brief  Set value to a C substring.
1391*38fd1498Szrj        *  @param __s  The C string to use.
1392*38fd1498Szrj        *  @param __n  Number of characters to use.
1393*38fd1498Szrj        *  @return  Reference to this string.
1394*38fd1498Szrj        *
1395*38fd1498Szrj        *  This function sets the value of this string to the first @a __n
1396*38fd1498Szrj        *  characters of @a __s.  If @a __n is is larger than the number of
1397*38fd1498Szrj        *  available characters in @a __s, the remainder of @a __s is used.
1398*38fd1498Szrj        */
1399*38fd1498Szrj       basic_string&
1400*38fd1498Szrj       assign(const _CharT* __s, size_type __n)
1401*38fd1498Szrj       {
1402*38fd1498Szrj 	__glibcxx_requires_string_len(__s, __n);
1403*38fd1498Szrj 	return _M_replace(size_type(0), this->size(), __s, __n);
1404*38fd1498Szrj       }
1405*38fd1498Szrj 
1406*38fd1498Szrj       /**
1407*38fd1498Szrj        *  @brief  Set value to contents of a C string.
1408*38fd1498Szrj        *  @param __s  The C string to use.
1409*38fd1498Szrj        *  @return  Reference to this string.
1410*38fd1498Szrj        *
1411*38fd1498Szrj        *  This function sets the value of this string to the value of @a __s.
1412*38fd1498Szrj        *  The data is copied, so there is no dependence on @a __s once the
1413*38fd1498Szrj        *  function returns.
1414*38fd1498Szrj        */
1415*38fd1498Szrj       basic_string&
1416*38fd1498Szrj       assign(const _CharT* __s)
1417*38fd1498Szrj       {
1418*38fd1498Szrj 	__glibcxx_requires_string(__s);
1419*38fd1498Szrj 	return _M_replace(size_type(0), this->size(), __s,
1420*38fd1498Szrj 			  traits_type::length(__s));
1421*38fd1498Szrj       }
1422*38fd1498Szrj 
1423*38fd1498Szrj       /**
1424*38fd1498Szrj        *  @brief  Set value to multiple characters.
1425*38fd1498Szrj        *  @param __n  Length of the resulting string.
1426*38fd1498Szrj        *  @param __c  The character to use.
1427*38fd1498Szrj        *  @return  Reference to this string.
1428*38fd1498Szrj        *
1429*38fd1498Szrj        *  This function sets the value of this string to @a __n copies of
1430*38fd1498Szrj        *  character @a __c.
1431*38fd1498Szrj        */
1432*38fd1498Szrj       basic_string&
1433*38fd1498Szrj       assign(size_type __n, _CharT __c)
1434*38fd1498Szrj       { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
1435*38fd1498Szrj 
1436*38fd1498Szrj       /**
1437*38fd1498Szrj        *  @brief  Set value to a range of characters.
1438*38fd1498Szrj        *  @param __first  Iterator referencing the first character to append.
1439*38fd1498Szrj        *  @param __last  Iterator marking the end of the range.
1440*38fd1498Szrj        *  @return  Reference to this string.
1441*38fd1498Szrj        *
1442*38fd1498Szrj        *  Sets value of string to characters in the range [__first,__last).
1443*38fd1498Szrj       */
1444*38fd1498Szrj #if __cplusplus >= 201103L
1445*38fd1498Szrj       template<class _InputIterator,
1446*38fd1498Szrj 	       typename = std::_RequireInputIter<_InputIterator>>
1447*38fd1498Szrj #else
1448*38fd1498Szrj       template<class _InputIterator>
1449*38fd1498Szrj #endif
1450*38fd1498Szrj         basic_string&
1451*38fd1498Szrj         assign(_InputIterator __first, _InputIterator __last)
1452*38fd1498Szrj         { return this->replace(begin(), end(), __first, __last); }
1453*38fd1498Szrj 
1454*38fd1498Szrj #if __cplusplus >= 201103L
1455*38fd1498Szrj       /**
1456*38fd1498Szrj        *  @brief  Set value to an initializer_list of characters.
1457*38fd1498Szrj        *  @param __l  The initializer_list of characters to assign.
1458*38fd1498Szrj        *  @return  Reference to this string.
1459*38fd1498Szrj        */
1460*38fd1498Szrj       basic_string&
1461*38fd1498Szrj       assign(initializer_list<_CharT> __l)
1462*38fd1498Szrj       { return this->assign(__l.begin(), __l.size()); }
1463*38fd1498Szrj #endif // C++11
1464*38fd1498Szrj 
1465*38fd1498Szrj #if __cplusplus > 201402L
1466*38fd1498Szrj       /**
1467*38fd1498Szrj        *  @brief  Set value from a string_view.
1468*38fd1498Szrj        *  @param __svt  The source object convertible to string_view.
1469*38fd1498Szrj        *  @return  Reference to this string.
1470*38fd1498Szrj        */
1471*38fd1498Szrj       template<typename _Tp>
1472*38fd1498Szrj 	_If_sv<_Tp, basic_string&>
1473*38fd1498Szrj 	assign(const _Tp& __svt)
1474*38fd1498Szrj 	{
1475*38fd1498Szrj 	  __sv_type __sv = __svt;
1476*38fd1498Szrj 	  return this->assign(__sv.data(), __sv.size());
1477*38fd1498Szrj 	}
1478*38fd1498Szrj 
1479*38fd1498Szrj       /**
1480*38fd1498Szrj        *  @brief  Set value from a range of characters in a string_view.
1481*38fd1498Szrj        *  @param __svt  The source object convertible to string_view.
1482*38fd1498Szrj        *  @param __pos  The position in the string_view to assign from.
1483*38fd1498Szrj        *  @param __n  The number of characters to assign.
1484*38fd1498Szrj        *  @return  Reference to this string.
1485*38fd1498Szrj        */
1486*38fd1498Szrj       template<typename _Tp>
1487*38fd1498Szrj 	_If_sv<_Tp, basic_string&>
1488*38fd1498Szrj 	assign(const _Tp& __svt, size_type __pos, size_type __n = npos)
1489*38fd1498Szrj 	{
1490*38fd1498Szrj 	  __sv_type __sv = __svt;
1491*38fd1498Szrj 	  return _M_replace(size_type(0), this->size(), __sv.data()
1492*38fd1498Szrj 			    + __sv._M_check(__pos, "basic_string::assign"),
1493*38fd1498Szrj 			    __sv._M_limit(__pos, __n));
1494*38fd1498Szrj 	}
1495*38fd1498Szrj #endif // C++17
1496*38fd1498Szrj 
1497*38fd1498Szrj #if __cplusplus >= 201103L
1498*38fd1498Szrj       /**
1499*38fd1498Szrj        *  @brief  Insert multiple characters.
1500*38fd1498Szrj        *  @param __p  Const_iterator referencing location in string to
1501*38fd1498Szrj        *              insert at.
1502*38fd1498Szrj        *  @param __n  Number of characters to insert
1503*38fd1498Szrj        *  @param __c  The character to insert.
1504*38fd1498Szrj        *  @return  Iterator referencing the first inserted char.
1505*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1506*38fd1498Szrj        *
1507*38fd1498Szrj        *  Inserts @a __n copies of character @a __c starting at the
1508*38fd1498Szrj        *  position referenced by iterator @a __p.  If adding
1509*38fd1498Szrj        *  characters causes the length to exceed max_size(),
1510*38fd1498Szrj        *  length_error is thrown.  The value of the string doesn't
1511*38fd1498Szrj        *  change if an error is thrown.
1512*38fd1498Szrj       */
1513*38fd1498Szrj       iterator
1514*38fd1498Szrj       insert(const_iterator __p, size_type __n, _CharT __c)
1515*38fd1498Szrj       {
1516*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end());
1517*38fd1498Szrj 	const size_type __pos = __p - begin();
1518*38fd1498Szrj 	this->replace(__p, __p, __n, __c);
1519*38fd1498Szrj 	return iterator(this->_M_data() + __pos);
1520*38fd1498Szrj       }
1521*38fd1498Szrj #else
1522*38fd1498Szrj       /**
1523*38fd1498Szrj        *  @brief  Insert multiple characters.
1524*38fd1498Szrj        *  @param __p  Iterator referencing location in string to insert at.
1525*38fd1498Szrj        *  @param __n  Number of characters to insert
1526*38fd1498Szrj        *  @param __c  The character to insert.
1527*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1528*38fd1498Szrj        *
1529*38fd1498Szrj        *  Inserts @a __n copies of character @a __c starting at the
1530*38fd1498Szrj        *  position referenced by iterator @a __p.  If adding
1531*38fd1498Szrj        *  characters causes the length to exceed max_size(),
1532*38fd1498Szrj        *  length_error is thrown.  The value of the string doesn't
1533*38fd1498Szrj        *  change if an error is thrown.
1534*38fd1498Szrj       */
1535*38fd1498Szrj       void
1536*38fd1498Szrj       insert(iterator __p, size_type __n, _CharT __c)
1537*38fd1498Szrj       {	this->replace(__p, __p, __n, __c);  }
1538*38fd1498Szrj #endif
1539*38fd1498Szrj 
1540*38fd1498Szrj #if __cplusplus >= 201103L
1541*38fd1498Szrj       /**
1542*38fd1498Szrj        *  @brief  Insert a range of characters.
1543*38fd1498Szrj        *  @param __p  Const_iterator referencing location in string to
1544*38fd1498Szrj        *              insert at.
1545*38fd1498Szrj        *  @param __beg  Start of range.
1546*38fd1498Szrj        *  @param __end  End of range.
1547*38fd1498Szrj        *  @return  Iterator referencing the first inserted char.
1548*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1549*38fd1498Szrj        *
1550*38fd1498Szrj        *  Inserts characters in range [beg,end).  If adding characters
1551*38fd1498Szrj        *  causes the length to exceed max_size(), length_error is
1552*38fd1498Szrj        *  thrown.  The value of the string doesn't change if an error
1553*38fd1498Szrj        *  is thrown.
1554*38fd1498Szrj       */
1555*38fd1498Szrj       template<class _InputIterator,
1556*38fd1498Szrj 	       typename = std::_RequireInputIter<_InputIterator>>
1557*38fd1498Szrj 	iterator
1558*38fd1498Szrj         insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
1559*38fd1498Szrj         {
1560*38fd1498Szrj 	  _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end());
1561*38fd1498Szrj 	  const size_type __pos = __p - begin();
1562*38fd1498Szrj 	  this->replace(__p, __p, __beg, __end);
1563*38fd1498Szrj 	  return iterator(this->_M_data() + __pos);
1564*38fd1498Szrj 	}
1565*38fd1498Szrj #else
1566*38fd1498Szrj       /**
1567*38fd1498Szrj        *  @brief  Insert a range of characters.
1568*38fd1498Szrj        *  @param __p  Iterator referencing location in string to insert at.
1569*38fd1498Szrj        *  @param __beg  Start of range.
1570*38fd1498Szrj        *  @param __end  End of range.
1571*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1572*38fd1498Szrj        *
1573*38fd1498Szrj        *  Inserts characters in range [__beg,__end).  If adding
1574*38fd1498Szrj        *  characters causes the length to exceed max_size(),
1575*38fd1498Szrj        *  length_error is thrown.  The value of the string doesn't
1576*38fd1498Szrj        *  change if an error is thrown.
1577*38fd1498Szrj       */
1578*38fd1498Szrj       template<class _InputIterator>
1579*38fd1498Szrj         void
1580*38fd1498Szrj         insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1581*38fd1498Szrj         { this->replace(__p, __p, __beg, __end); }
1582*38fd1498Szrj #endif
1583*38fd1498Szrj 
1584*38fd1498Szrj #if __cplusplus >= 201103L
1585*38fd1498Szrj       /**
1586*38fd1498Szrj        *  @brief  Insert an initializer_list of characters.
1587*38fd1498Szrj        *  @param __p  Iterator referencing location in string to insert at.
1588*38fd1498Szrj        *  @param __l  The initializer_list of characters to insert.
1589*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1590*38fd1498Szrj        */
1591*38fd1498Szrj       void
1592*38fd1498Szrj       insert(iterator __p, initializer_list<_CharT> __l)
1593*38fd1498Szrj       {
1594*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end());
1595*38fd1498Szrj 	this->insert(__p - begin(), __l.begin(), __l.size());
1596*38fd1498Szrj       }
1597*38fd1498Szrj #endif // C++11
1598*38fd1498Szrj 
1599*38fd1498Szrj       /**
1600*38fd1498Szrj        *  @brief  Insert value of a string.
1601*38fd1498Szrj        *  @param __pos1  Iterator referencing location in string to insert at.
1602*38fd1498Szrj        *  @param __str  The string to insert.
1603*38fd1498Szrj        *  @return  Reference to this string.
1604*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1605*38fd1498Szrj        *
1606*38fd1498Szrj        *  Inserts value of @a __str starting at @a __pos1.  If adding
1607*38fd1498Szrj        *  characters causes the length to exceed max_size(),
1608*38fd1498Szrj        *  length_error is thrown.  The value of the string doesn't
1609*38fd1498Szrj        *  change if an error is thrown.
1610*38fd1498Szrj       */
1611*38fd1498Szrj       basic_string&
1612*38fd1498Szrj       insert(size_type __pos1, const basic_string& __str)
1613*38fd1498Szrj       { return this->replace(__pos1, size_type(0),
1614*38fd1498Szrj 			     __str._M_data(), __str.size()); }
1615*38fd1498Szrj 
1616*38fd1498Szrj       /**
1617*38fd1498Szrj        *  @brief  Insert a substring.
1618*38fd1498Szrj        *  @param __pos1  Iterator referencing location in string to insert at.
1619*38fd1498Szrj        *  @param __str  The string to insert.
1620*38fd1498Szrj        *  @param __pos2  Start of characters in str to insert.
1621*38fd1498Szrj        *  @param __n  Number of characters to insert.
1622*38fd1498Szrj        *  @return  Reference to this string.
1623*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1624*38fd1498Szrj        *  @throw  std::out_of_range  If @a pos1 > size() or
1625*38fd1498Szrj        *  @a __pos2 > @a str.size().
1626*38fd1498Szrj        *
1627*38fd1498Szrj        *  Starting at @a pos1, insert @a __n character of @a __str
1628*38fd1498Szrj        *  beginning with @a __pos2.  If adding characters causes the
1629*38fd1498Szrj        *  length to exceed max_size(), length_error is thrown.  If @a
1630*38fd1498Szrj        *  __pos1 is beyond the end of this string or @a __pos2 is
1631*38fd1498Szrj        *  beyond the end of @a __str, out_of_range is thrown.  The
1632*38fd1498Szrj        *  value of the string doesn't change if an error is thrown.
1633*38fd1498Szrj       */
1634*38fd1498Szrj       basic_string&
1635*38fd1498Szrj       insert(size_type __pos1, const basic_string& __str,
1636*38fd1498Szrj 	     size_type __pos2, size_type __n)
1637*38fd1498Szrj       { return this->replace(__pos1, size_type(0), __str._M_data()
1638*38fd1498Szrj 			     + __str._M_check(__pos2, "basic_string::insert"),
1639*38fd1498Szrj 			     __str._M_limit(__pos2, __n)); }
1640*38fd1498Szrj 
1641*38fd1498Szrj       /**
1642*38fd1498Szrj        *  @brief  Insert a C substring.
1643*38fd1498Szrj        *  @param __pos  Iterator referencing location in string to insert at.
1644*38fd1498Szrj        *  @param __s  The C string to insert.
1645*38fd1498Szrj        *  @param __n  The number of characters to insert.
1646*38fd1498Szrj        *  @return  Reference to this string.
1647*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1648*38fd1498Szrj        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
1649*38fd1498Szrj        *  string.
1650*38fd1498Szrj        *
1651*38fd1498Szrj        *  Inserts the first @a __n characters of @a __s starting at @a
1652*38fd1498Szrj        *  __pos.  If adding characters causes the length to exceed
1653*38fd1498Szrj        *  max_size(), length_error is thrown.  If @a __pos is beyond
1654*38fd1498Szrj        *  end(), out_of_range is thrown.  The value of the string
1655*38fd1498Szrj        *  doesn't change if an error is thrown.
1656*38fd1498Szrj       */
1657*38fd1498Szrj       basic_string&
1658*38fd1498Szrj       insert(size_type __pos, const _CharT* __s, size_type __n)
1659*38fd1498Szrj       { return this->replace(__pos, size_type(0), __s, __n); }
1660*38fd1498Szrj 
1661*38fd1498Szrj       /**
1662*38fd1498Szrj        *  @brief  Insert a C string.
1663*38fd1498Szrj        *  @param __pos  Iterator referencing location in string to insert at.
1664*38fd1498Szrj        *  @param __s  The C string to insert.
1665*38fd1498Szrj        *  @return  Reference to this string.
1666*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1667*38fd1498Szrj        *  @throw  std::out_of_range  If @a pos is beyond the end of this
1668*38fd1498Szrj        *  string.
1669*38fd1498Szrj        *
1670*38fd1498Szrj        *  Inserts the first @a n characters of @a __s starting at @a __pos.  If
1671*38fd1498Szrj        *  adding characters causes the length to exceed max_size(),
1672*38fd1498Szrj        *  length_error is thrown.  If @a __pos is beyond end(), out_of_range is
1673*38fd1498Szrj        *  thrown.  The value of the string doesn't change if an error is
1674*38fd1498Szrj        *  thrown.
1675*38fd1498Szrj       */
1676*38fd1498Szrj       basic_string&
1677*38fd1498Szrj       insert(size_type __pos, const _CharT* __s)
1678*38fd1498Szrj       {
1679*38fd1498Szrj 	__glibcxx_requires_string(__s);
1680*38fd1498Szrj 	return this->replace(__pos, size_type(0), __s,
1681*38fd1498Szrj 			     traits_type::length(__s));
1682*38fd1498Szrj       }
1683*38fd1498Szrj 
1684*38fd1498Szrj       /**
1685*38fd1498Szrj        *  @brief  Insert multiple characters.
1686*38fd1498Szrj        *  @param __pos  Index in string to insert at.
1687*38fd1498Szrj        *  @param __n  Number of characters to insert
1688*38fd1498Szrj        *  @param __c  The character to insert.
1689*38fd1498Szrj        *  @return  Reference to this string.
1690*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1691*38fd1498Szrj        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
1692*38fd1498Szrj        *  string.
1693*38fd1498Szrj        *
1694*38fd1498Szrj        *  Inserts @a __n copies of character @a __c starting at index
1695*38fd1498Szrj        *  @a __pos.  If adding characters causes the length to exceed
1696*38fd1498Szrj        *  max_size(), length_error is thrown.  If @a __pos > length(),
1697*38fd1498Szrj        *  out_of_range is thrown.  The value of the string doesn't
1698*38fd1498Szrj        *  change if an error is thrown.
1699*38fd1498Szrj       */
1700*38fd1498Szrj       basic_string&
1701*38fd1498Szrj       insert(size_type __pos, size_type __n, _CharT __c)
1702*38fd1498Szrj       { return _M_replace_aux(_M_check(__pos, "basic_string::insert"),
1703*38fd1498Szrj 			      size_type(0), __n, __c); }
1704*38fd1498Szrj 
1705*38fd1498Szrj       /**
1706*38fd1498Szrj        *  @brief  Insert one character.
1707*38fd1498Szrj        *  @param __p  Iterator referencing position in string to insert at.
1708*38fd1498Szrj        *  @param __c  The character to insert.
1709*38fd1498Szrj        *  @return  Iterator referencing newly inserted char.
1710*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1711*38fd1498Szrj        *
1712*38fd1498Szrj        *  Inserts character @a __c at position referenced by @a __p.
1713*38fd1498Szrj        *  If adding character causes the length to exceed max_size(),
1714*38fd1498Szrj        *  length_error is thrown.  If @a __p is beyond end of string,
1715*38fd1498Szrj        *  out_of_range is thrown.  The value of the string doesn't
1716*38fd1498Szrj        *  change if an error is thrown.
1717*38fd1498Szrj       */
1718*38fd1498Szrj       iterator
1719*38fd1498Szrj       insert(__const_iterator __p, _CharT __c)
1720*38fd1498Szrj       {
1721*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end());
1722*38fd1498Szrj 	const size_type __pos = __p - begin();
1723*38fd1498Szrj 	_M_replace_aux(__pos, size_type(0), size_type(1), __c);
1724*38fd1498Szrj 	return iterator(_M_data() + __pos);
1725*38fd1498Szrj       }
1726*38fd1498Szrj 
1727*38fd1498Szrj #if __cplusplus > 201402L
1728*38fd1498Szrj       /**
1729*38fd1498Szrj        *  @brief  Insert a string_view.
1730*38fd1498Szrj        *  @param __pos  Iterator referencing position in string to insert at.
1731*38fd1498Szrj        *  @param __svt  The object convertible to string_view to insert.
1732*38fd1498Szrj        *  @return  Reference to this string.
1733*38fd1498Szrj       */
1734*38fd1498Szrj       template<typename _Tp>
1735*38fd1498Szrj 	_If_sv<_Tp, basic_string&>
1736*38fd1498Szrj 	insert(size_type __pos, const _Tp& __svt)
1737*38fd1498Szrj 	{
1738*38fd1498Szrj 	  __sv_type __sv = __svt;
1739*38fd1498Szrj 	  return this->insert(__pos, __sv.data(), __sv.size());
1740*38fd1498Szrj 	}
1741*38fd1498Szrj 
1742*38fd1498Szrj       /**
1743*38fd1498Szrj        *  @brief  Insert a string_view.
1744*38fd1498Szrj        *  @param __pos  Iterator referencing position in string to insert at.
1745*38fd1498Szrj        *  @param __svt  The object convertible to string_view to insert from.
1746*38fd1498Szrj        *  @param __pos  Iterator referencing position in string_view to insert
1747*38fd1498Szrj        *  from.
1748*38fd1498Szrj        *  @param __n    The number of characters to insert.
1749*38fd1498Szrj        *  @return  Reference to this string.
1750*38fd1498Szrj       */
1751*38fd1498Szrj       template<typename _Tp>
1752*38fd1498Szrj 	_If_sv<_Tp, basic_string&>
1753*38fd1498Szrj 	insert(size_type __pos1, const _Tp& __svt,
1754*38fd1498Szrj 	       size_type __pos2, size_type __n = npos)
1755*38fd1498Szrj 	{
1756*38fd1498Szrj 	  __sv_type __sv = __svt;
1757*38fd1498Szrj 	  return this->replace(__pos1, size_type(0), __sv.data()
1758*38fd1498Szrj 			       + __sv._M_check(__pos2, "basic_string::insert"),
1759*38fd1498Szrj 			       __sv._M_limit(__pos2, __n));
1760*38fd1498Szrj 	}
1761*38fd1498Szrj #endif // C++17
1762*38fd1498Szrj 
1763*38fd1498Szrj       /**
1764*38fd1498Szrj        *  @brief  Remove characters.
1765*38fd1498Szrj        *  @param __pos  Index of first character to remove (default 0).
1766*38fd1498Szrj        *  @param __n  Number of characters to remove (default remainder).
1767*38fd1498Szrj        *  @return  Reference to this string.
1768*38fd1498Szrj        *  @throw  std::out_of_range  If @a pos is beyond the end of this
1769*38fd1498Szrj        *  string.
1770*38fd1498Szrj        *
1771*38fd1498Szrj        *  Removes @a __n characters from this string starting at @a
1772*38fd1498Szrj        *  __pos.  The length of the string is reduced by @a __n.  If
1773*38fd1498Szrj        *  there are < @a __n characters to remove, the remainder of
1774*38fd1498Szrj        *  the string is truncated.  If @a __p is beyond end of string,
1775*38fd1498Szrj        *  out_of_range is thrown.  The value of the string doesn't
1776*38fd1498Szrj        *  change if an error is thrown.
1777*38fd1498Szrj       */
1778*38fd1498Szrj       basic_string&
1779*38fd1498Szrj       erase(size_type __pos = 0, size_type __n = npos)
1780*38fd1498Szrj       {
1781*38fd1498Szrj 	_M_check(__pos, "basic_string::erase");
1782*38fd1498Szrj 	if (__n == npos)
1783*38fd1498Szrj 	  this->_M_set_length(__pos);
1784*38fd1498Szrj 	else if (__n != 0)
1785*38fd1498Szrj 	  this->_M_erase(__pos, _M_limit(__pos, __n));
1786*38fd1498Szrj 	return *this;
1787*38fd1498Szrj       }
1788*38fd1498Szrj 
1789*38fd1498Szrj       /**
1790*38fd1498Szrj        *  @brief  Remove one character.
1791*38fd1498Szrj        *  @param __position  Iterator referencing the character to remove.
1792*38fd1498Szrj        *  @return  iterator referencing same location after removal.
1793*38fd1498Szrj        *
1794*38fd1498Szrj        *  Removes the character at @a __position from this string. The value
1795*38fd1498Szrj        *  of the string doesn't change if an error is thrown.
1796*38fd1498Szrj       */
1797*38fd1498Szrj       iterator
1798*38fd1498Szrj       erase(__const_iterator __position)
1799*38fd1498Szrj       {
1800*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(__position >= begin()
1801*38fd1498Szrj 				 && __position < end());
1802*38fd1498Szrj 	const size_type __pos = __position - begin();
1803*38fd1498Szrj 	this->_M_erase(__pos, size_type(1));
1804*38fd1498Szrj 	return iterator(_M_data() + __pos);
1805*38fd1498Szrj       }
1806*38fd1498Szrj 
1807*38fd1498Szrj       /**
1808*38fd1498Szrj        *  @brief  Remove a range of characters.
1809*38fd1498Szrj        *  @param __first  Iterator referencing the first character to remove.
1810*38fd1498Szrj        *  @param __last  Iterator referencing the end of the range.
1811*38fd1498Szrj        *  @return  Iterator referencing location of first after removal.
1812*38fd1498Szrj        *
1813*38fd1498Szrj        *  Removes the characters in the range [first,last) from this string.
1814*38fd1498Szrj        *  The value of the string doesn't change if an error is thrown.
1815*38fd1498Szrj       */
1816*38fd1498Szrj       iterator
1817*38fd1498Szrj       erase(__const_iterator __first, __const_iterator __last)
1818*38fd1498Szrj       {
1819*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(__first >= begin() && __first <= __last
1820*38fd1498Szrj 				 && __last <= end());
1821*38fd1498Szrj         const size_type __pos = __first - begin();
1822*38fd1498Szrj 	if (__last == end())
1823*38fd1498Szrj 	  this->_M_set_length(__pos);
1824*38fd1498Szrj 	else
1825*38fd1498Szrj 	  this->_M_erase(__pos, __last - __first);
1826*38fd1498Szrj 	return iterator(this->_M_data() + __pos);
1827*38fd1498Szrj       }
1828*38fd1498Szrj 
1829*38fd1498Szrj #if __cplusplus >= 201103L
1830*38fd1498Szrj       /**
1831*38fd1498Szrj        *  @brief  Remove the last character.
1832*38fd1498Szrj        *
1833*38fd1498Szrj        *  The string must be non-empty.
1834*38fd1498Szrj        */
1835*38fd1498Szrj       void
1836*38fd1498Szrj       pop_back() noexcept
1837*38fd1498Szrj       {
1838*38fd1498Szrj 	__glibcxx_assert(!empty());
1839*38fd1498Szrj 	_M_erase(size() - 1, 1);
1840*38fd1498Szrj       }
1841*38fd1498Szrj #endif // C++11
1842*38fd1498Szrj 
1843*38fd1498Szrj       /**
1844*38fd1498Szrj        *  @brief  Replace characters with value from another string.
1845*38fd1498Szrj        *  @param __pos  Index of first character to replace.
1846*38fd1498Szrj        *  @param __n  Number of characters to be replaced.
1847*38fd1498Szrj        *  @param __str  String to insert.
1848*38fd1498Szrj        *  @return  Reference to this string.
1849*38fd1498Szrj        *  @throw  std::out_of_range  If @a pos is beyond the end of this
1850*38fd1498Szrj        *  string.
1851*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1852*38fd1498Szrj        *
1853*38fd1498Szrj        *  Removes the characters in the range [__pos,__pos+__n) from
1854*38fd1498Szrj        *  this string.  In place, the value of @a __str is inserted.
1855*38fd1498Szrj        *  If @a __pos is beyond end of string, out_of_range is thrown.
1856*38fd1498Szrj        *  If the length of the result exceeds max_size(), length_error
1857*38fd1498Szrj        *  is thrown.  The value of the string doesn't change if an
1858*38fd1498Szrj        *  error is thrown.
1859*38fd1498Szrj       */
1860*38fd1498Szrj       basic_string&
1861*38fd1498Szrj       replace(size_type __pos, size_type __n, const basic_string& __str)
1862*38fd1498Szrj       { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1863*38fd1498Szrj 
1864*38fd1498Szrj       /**
1865*38fd1498Szrj        *  @brief  Replace characters with value from another string.
1866*38fd1498Szrj        *  @param __pos1  Index of first character to replace.
1867*38fd1498Szrj        *  @param __n1  Number of characters to be replaced.
1868*38fd1498Szrj        *  @param __str  String to insert.
1869*38fd1498Szrj        *  @param __pos2  Index of first character of str to use.
1870*38fd1498Szrj        *  @param __n2  Number of characters from str to use.
1871*38fd1498Szrj        *  @return  Reference to this string.
1872*38fd1498Szrj        *  @throw  std::out_of_range  If @a __pos1 > size() or @a __pos2 >
1873*38fd1498Szrj        *  __str.size().
1874*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1875*38fd1498Szrj        *
1876*38fd1498Szrj        *  Removes the characters in the range [__pos1,__pos1 + n) from this
1877*38fd1498Szrj        *  string.  In place, the value of @a __str is inserted.  If @a __pos is
1878*38fd1498Szrj        *  beyond end of string, out_of_range is thrown.  If the length of the
1879*38fd1498Szrj        *  result exceeds max_size(), length_error is thrown.  The value of the
1880*38fd1498Szrj        *  string doesn't change if an error is thrown.
1881*38fd1498Szrj       */
1882*38fd1498Szrj       basic_string&
1883*38fd1498Szrj       replace(size_type __pos1, size_type __n1, const basic_string& __str,
1884*38fd1498Szrj 	      size_type __pos2, size_type __n2)
1885*38fd1498Szrj       { return this->replace(__pos1, __n1, __str._M_data()
1886*38fd1498Szrj 			     + __str._M_check(__pos2, "basic_string::replace"),
1887*38fd1498Szrj 			     __str._M_limit(__pos2, __n2)); }
1888*38fd1498Szrj 
1889*38fd1498Szrj       /**
1890*38fd1498Szrj        *  @brief  Replace characters with value of a C substring.
1891*38fd1498Szrj        *  @param __pos  Index of first character to replace.
1892*38fd1498Szrj        *  @param __n1  Number of characters to be replaced.
1893*38fd1498Szrj        *  @param __s  C string to insert.
1894*38fd1498Szrj        *  @param __n2  Number of characters from @a s to use.
1895*38fd1498Szrj        *  @return  Reference to this string.
1896*38fd1498Szrj        *  @throw  std::out_of_range  If @a pos1 > size().
1897*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1898*38fd1498Szrj        *
1899*38fd1498Szrj        *  Removes the characters in the range [__pos,__pos + __n1)
1900*38fd1498Szrj        *  from this string.  In place, the first @a __n2 characters of
1901*38fd1498Szrj        *  @a __s are inserted, or all of @a __s if @a __n2 is too large.  If
1902*38fd1498Szrj        *  @a __pos is beyond end of string, out_of_range is thrown.  If
1903*38fd1498Szrj        *  the length of result exceeds max_size(), length_error is
1904*38fd1498Szrj        *  thrown.  The value of the string doesn't change if an error
1905*38fd1498Szrj        *  is thrown.
1906*38fd1498Szrj       */
1907*38fd1498Szrj       basic_string&
1908*38fd1498Szrj       replace(size_type __pos, size_type __n1, const _CharT* __s,
1909*38fd1498Szrj 	      size_type __n2)
1910*38fd1498Szrj       {
1911*38fd1498Szrj 	__glibcxx_requires_string_len(__s, __n2);
1912*38fd1498Szrj 	return _M_replace(_M_check(__pos, "basic_string::replace"),
1913*38fd1498Szrj 			  _M_limit(__pos, __n1), __s, __n2);
1914*38fd1498Szrj       }
1915*38fd1498Szrj 
1916*38fd1498Szrj       /**
1917*38fd1498Szrj        *  @brief  Replace characters with value of a C string.
1918*38fd1498Szrj        *  @param __pos  Index of first character to replace.
1919*38fd1498Szrj        *  @param __n1  Number of characters to be replaced.
1920*38fd1498Szrj        *  @param __s  C string to insert.
1921*38fd1498Szrj        *  @return  Reference to this string.
1922*38fd1498Szrj        *  @throw  std::out_of_range  If @a pos > size().
1923*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1924*38fd1498Szrj        *
1925*38fd1498Szrj        *  Removes the characters in the range [__pos,__pos + __n1)
1926*38fd1498Szrj        *  from this string.  In place, the characters of @a __s are
1927*38fd1498Szrj        *  inserted.  If @a __pos is beyond end of string, out_of_range
1928*38fd1498Szrj        *  is thrown.  If the length of result exceeds max_size(),
1929*38fd1498Szrj        *  length_error is thrown.  The value of the string doesn't
1930*38fd1498Szrj        *  change if an error is thrown.
1931*38fd1498Szrj       */
1932*38fd1498Szrj       basic_string&
1933*38fd1498Szrj       replace(size_type __pos, size_type __n1, const _CharT* __s)
1934*38fd1498Szrj       {
1935*38fd1498Szrj 	__glibcxx_requires_string(__s);
1936*38fd1498Szrj 	return this->replace(__pos, __n1, __s, traits_type::length(__s));
1937*38fd1498Szrj       }
1938*38fd1498Szrj 
1939*38fd1498Szrj       /**
1940*38fd1498Szrj        *  @brief  Replace characters with multiple characters.
1941*38fd1498Szrj        *  @param __pos  Index of first character to replace.
1942*38fd1498Szrj        *  @param __n1  Number of characters to be replaced.
1943*38fd1498Szrj        *  @param __n2  Number of characters to insert.
1944*38fd1498Szrj        *  @param __c  Character to insert.
1945*38fd1498Szrj        *  @return  Reference to this string.
1946*38fd1498Szrj        *  @throw  std::out_of_range  If @a __pos > size().
1947*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1948*38fd1498Szrj        *
1949*38fd1498Szrj        *  Removes the characters in the range [pos,pos + n1) from this
1950*38fd1498Szrj        *  string.  In place, @a __n2 copies of @a __c are inserted.
1951*38fd1498Szrj        *  If @a __pos is beyond end of string, out_of_range is thrown.
1952*38fd1498Szrj        *  If the length of result exceeds max_size(), length_error is
1953*38fd1498Szrj        *  thrown.  The value of the string doesn't change if an error
1954*38fd1498Szrj        *  is thrown.
1955*38fd1498Szrj       */
1956*38fd1498Szrj       basic_string&
1957*38fd1498Szrj       replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1958*38fd1498Szrj       { return _M_replace_aux(_M_check(__pos, "basic_string::replace"),
1959*38fd1498Szrj 			      _M_limit(__pos, __n1), __n2, __c); }
1960*38fd1498Szrj 
1961*38fd1498Szrj       /**
1962*38fd1498Szrj        *  @brief  Replace range of characters with string.
1963*38fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
1964*38fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
1965*38fd1498Szrj        *  @param __str  String value to insert.
1966*38fd1498Szrj        *  @return  Reference to this string.
1967*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1968*38fd1498Szrj        *
1969*38fd1498Szrj        *  Removes the characters in the range [__i1,__i2).  In place,
1970*38fd1498Szrj        *  the value of @a __str is inserted.  If the length of result
1971*38fd1498Szrj        *  exceeds max_size(), length_error is thrown.  The value of
1972*38fd1498Szrj        *  the string doesn't change if an error is thrown.
1973*38fd1498Szrj       */
1974*38fd1498Szrj       basic_string&
1975*38fd1498Szrj       replace(__const_iterator __i1, __const_iterator __i2,
1976*38fd1498Szrj 	      const basic_string& __str)
1977*38fd1498Szrj       { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1978*38fd1498Szrj 
1979*38fd1498Szrj       /**
1980*38fd1498Szrj        *  @brief  Replace range of characters with C substring.
1981*38fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
1982*38fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
1983*38fd1498Szrj        *  @param __s  C string value to insert.
1984*38fd1498Szrj        *  @param __n  Number of characters from s to insert.
1985*38fd1498Szrj        *  @return  Reference to this string.
1986*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
1987*38fd1498Szrj        *
1988*38fd1498Szrj        *  Removes the characters in the range [__i1,__i2).  In place,
1989*38fd1498Szrj        *  the first @a __n characters of @a __s are inserted.  If the
1990*38fd1498Szrj        *  length of result exceeds max_size(), length_error is thrown.
1991*38fd1498Szrj        *  The value of the string doesn't change if an error is
1992*38fd1498Szrj        *  thrown.
1993*38fd1498Szrj       */
1994*38fd1498Szrj       basic_string&
1995*38fd1498Szrj       replace(__const_iterator __i1, __const_iterator __i2,
1996*38fd1498Szrj 	      const _CharT* __s, size_type __n)
1997*38fd1498Szrj       {
1998*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
1999*38fd1498Szrj 				 && __i2 <= end());
2000*38fd1498Szrj 	return this->replace(__i1 - begin(), __i2 - __i1, __s, __n);
2001*38fd1498Szrj       }
2002*38fd1498Szrj 
2003*38fd1498Szrj       /**
2004*38fd1498Szrj        *  @brief  Replace range of characters with C string.
2005*38fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
2006*38fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
2007*38fd1498Szrj        *  @param __s  C string value to insert.
2008*38fd1498Szrj        *  @return  Reference to this string.
2009*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
2010*38fd1498Szrj        *
2011*38fd1498Szrj        *  Removes the characters in the range [__i1,__i2).  In place,
2012*38fd1498Szrj        *  the characters of @a __s are inserted.  If the length of
2013*38fd1498Szrj        *  result exceeds max_size(), length_error is thrown.  The
2014*38fd1498Szrj        *  value of the string doesn't change if an error is thrown.
2015*38fd1498Szrj       */
2016*38fd1498Szrj       basic_string&
2017*38fd1498Szrj       replace(__const_iterator __i1, __const_iterator __i2, const _CharT* __s)
2018*38fd1498Szrj       {
2019*38fd1498Szrj 	__glibcxx_requires_string(__s);
2020*38fd1498Szrj 	return this->replace(__i1, __i2, __s, traits_type::length(__s));
2021*38fd1498Szrj       }
2022*38fd1498Szrj 
2023*38fd1498Szrj       /**
2024*38fd1498Szrj        *  @brief  Replace range of characters with multiple characters
2025*38fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
2026*38fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
2027*38fd1498Szrj        *  @param __n  Number of characters to insert.
2028*38fd1498Szrj        *  @param __c  Character to insert.
2029*38fd1498Szrj        *  @return  Reference to this string.
2030*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
2031*38fd1498Szrj        *
2032*38fd1498Szrj        *  Removes the characters in the range [__i1,__i2).  In place,
2033*38fd1498Szrj        *  @a __n copies of @a __c are inserted.  If the length of
2034*38fd1498Szrj        *  result exceeds max_size(), length_error is thrown.  The
2035*38fd1498Szrj        *  value of the string doesn't change if an error is thrown.
2036*38fd1498Szrj       */
2037*38fd1498Szrj       basic_string&
2038*38fd1498Szrj       replace(__const_iterator __i1, __const_iterator __i2, size_type __n,
2039*38fd1498Szrj 	      _CharT __c)
2040*38fd1498Szrj       {
2041*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2042*38fd1498Szrj 				 && __i2 <= end());
2043*38fd1498Szrj 	return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __c);
2044*38fd1498Szrj       }
2045*38fd1498Szrj 
2046*38fd1498Szrj       /**
2047*38fd1498Szrj        *  @brief  Replace range of characters with range.
2048*38fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
2049*38fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
2050*38fd1498Szrj        *  @param __k1  Iterator referencing start of range to insert.
2051*38fd1498Szrj        *  @param __k2  Iterator referencing end of range to insert.
2052*38fd1498Szrj        *  @return  Reference to this string.
2053*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
2054*38fd1498Szrj        *
2055*38fd1498Szrj        *  Removes the characters in the range [__i1,__i2).  In place,
2056*38fd1498Szrj        *  characters in the range [__k1,__k2) are inserted.  If the
2057*38fd1498Szrj        *  length of result exceeds max_size(), length_error is thrown.
2058*38fd1498Szrj        *  The value of the string doesn't change if an error is
2059*38fd1498Szrj        *  thrown.
2060*38fd1498Szrj       */
2061*38fd1498Szrj #if __cplusplus >= 201103L
2062*38fd1498Szrj       template<class _InputIterator,
2063*38fd1498Szrj 	       typename = std::_RequireInputIter<_InputIterator>>
2064*38fd1498Szrj         basic_string&
2065*38fd1498Szrj         replace(const_iterator __i1, const_iterator __i2,
2066*38fd1498Szrj 		_InputIterator __k1, _InputIterator __k2)
2067*38fd1498Szrj         {
2068*38fd1498Szrj 	  _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2069*38fd1498Szrj 				   && __i2 <= end());
2070*38fd1498Szrj 	  __glibcxx_requires_valid_range(__k1, __k2);
2071*38fd1498Szrj 	  return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
2072*38fd1498Szrj 					   std::__false_type());
2073*38fd1498Szrj 	}
2074*38fd1498Szrj #else
2075*38fd1498Szrj       template<class _InputIterator>
2076*38fd1498Szrj #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
2077*38fd1498Szrj         typename __enable_if_not_native_iterator<_InputIterator>::__type
2078*38fd1498Szrj #else
2079*38fd1498Szrj         basic_string&
2080*38fd1498Szrj #endif
2081*38fd1498Szrj         replace(iterator __i1, iterator __i2,
2082*38fd1498Szrj 		_InputIterator __k1, _InputIterator __k2)
2083*38fd1498Szrj         {
2084*38fd1498Szrj 	  _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2085*38fd1498Szrj 				   && __i2 <= end());
2086*38fd1498Szrj 	  __glibcxx_requires_valid_range(__k1, __k2);
2087*38fd1498Szrj 	  typedef typename std::__is_integer<_InputIterator>::__type _Integral;
2088*38fd1498Szrj 	  return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
2089*38fd1498Szrj 	}
2090*38fd1498Szrj #endif
2091*38fd1498Szrj 
2092*38fd1498Szrj       // Specializations for the common case of pointer and iterator:
2093*38fd1498Szrj       // useful to avoid the overhead of temporary buffering in _M_replace.
2094*38fd1498Szrj       basic_string&
2095*38fd1498Szrj       replace(__const_iterator __i1, __const_iterator __i2,
2096*38fd1498Szrj 	      _CharT* __k1, _CharT* __k2)
2097*38fd1498Szrj       {
2098*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2099*38fd1498Szrj 				 && __i2 <= end());
2100*38fd1498Szrj 	__glibcxx_requires_valid_range(__k1, __k2);
2101*38fd1498Szrj 	return this->replace(__i1 - begin(), __i2 - __i1,
2102*38fd1498Szrj 			     __k1, __k2 - __k1);
2103*38fd1498Szrj       }
2104*38fd1498Szrj 
2105*38fd1498Szrj       basic_string&
2106*38fd1498Szrj       replace(__const_iterator __i1, __const_iterator __i2,
2107*38fd1498Szrj 	      const _CharT* __k1, const _CharT* __k2)
2108*38fd1498Szrj       {
2109*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2110*38fd1498Szrj 				 && __i2 <= end());
2111*38fd1498Szrj 	__glibcxx_requires_valid_range(__k1, __k2);
2112*38fd1498Szrj 	return this->replace(__i1 - begin(), __i2 - __i1,
2113*38fd1498Szrj 			     __k1, __k2 - __k1);
2114*38fd1498Szrj       }
2115*38fd1498Szrj 
2116*38fd1498Szrj       basic_string&
2117*38fd1498Szrj       replace(__const_iterator __i1, __const_iterator __i2,
2118*38fd1498Szrj 	      iterator __k1, iterator __k2)
2119*38fd1498Szrj       {
2120*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2121*38fd1498Szrj 				 && __i2 <= end());
2122*38fd1498Szrj 	__glibcxx_requires_valid_range(__k1, __k2);
2123*38fd1498Szrj 	return this->replace(__i1 - begin(), __i2 - __i1,
2124*38fd1498Szrj 			     __k1.base(), __k2 - __k1);
2125*38fd1498Szrj       }
2126*38fd1498Szrj 
2127*38fd1498Szrj       basic_string&
2128*38fd1498Szrj       replace(__const_iterator __i1, __const_iterator __i2,
2129*38fd1498Szrj 	      const_iterator __k1, const_iterator __k2)
2130*38fd1498Szrj       {
2131*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2132*38fd1498Szrj 				 && __i2 <= end());
2133*38fd1498Szrj 	__glibcxx_requires_valid_range(__k1, __k2);
2134*38fd1498Szrj 	return this->replace(__i1 - begin(), __i2 - __i1,
2135*38fd1498Szrj 			     __k1.base(), __k2 - __k1);
2136*38fd1498Szrj       }
2137*38fd1498Szrj 
2138*38fd1498Szrj #if __cplusplus >= 201103L
2139*38fd1498Szrj       /**
2140*38fd1498Szrj        *  @brief  Replace range of characters with initializer_list.
2141*38fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
2142*38fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
2143*38fd1498Szrj        *  @param __l  The initializer_list of characters to insert.
2144*38fd1498Szrj        *  @return  Reference to this string.
2145*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
2146*38fd1498Szrj        *
2147*38fd1498Szrj        *  Removes the characters in the range [__i1,__i2).  In place,
2148*38fd1498Szrj        *  characters in the range [__k1,__k2) are inserted.  If the
2149*38fd1498Szrj        *  length of result exceeds max_size(), length_error is thrown.
2150*38fd1498Szrj        *  The value of the string doesn't change if an error is
2151*38fd1498Szrj        *  thrown.
2152*38fd1498Szrj       */
2153*38fd1498Szrj       basic_string& replace(const_iterator __i1, const_iterator __i2,
2154*38fd1498Szrj 			    initializer_list<_CharT> __l)
2155*38fd1498Szrj       { return this->replace(__i1, __i2, __l.begin(), __l.size()); }
2156*38fd1498Szrj #endif // C++11
2157*38fd1498Szrj 
2158*38fd1498Szrj #if __cplusplus > 201402L
2159*38fd1498Szrj       /**
2160*38fd1498Szrj        *  @brief  Replace range of characters with string_view.
2161*38fd1498Szrj        *  @param __pos  The position to replace at.
2162*38fd1498Szrj        *  @param __n    The number of characters to replace.
2163*38fd1498Szrj        *  @param __svt  The object convertible to string_view to insert.
2164*38fd1498Szrj        *  @return  Reference to this string.
2165*38fd1498Szrj       */
2166*38fd1498Szrj       template<typename _Tp>
2167*38fd1498Szrj 	_If_sv<_Tp, basic_string&>
2168*38fd1498Szrj 	replace(size_type __pos, size_type __n, const _Tp& __svt)
2169*38fd1498Szrj 	{
2170*38fd1498Szrj 	  __sv_type __sv = __svt;
2171*38fd1498Szrj 	  return this->replace(__pos, __n, __sv.data(), __sv.size());
2172*38fd1498Szrj 	}
2173*38fd1498Szrj 
2174*38fd1498Szrj       /**
2175*38fd1498Szrj        *  @brief  Replace range of characters with string_view.
2176*38fd1498Szrj        *  @param __pos1  The position to replace at.
2177*38fd1498Szrj        *  @param __n1    The number of characters to replace.
2178*38fd1498Szrj        *  @param __svt   The object convertible to string_view to insert from.
2179*38fd1498Szrj        *  @param __pos2  The position in the string_view to insert from.
2180*38fd1498Szrj        *  @param __n2    The number of characters to insert.
2181*38fd1498Szrj        *  @return  Reference to this string.
2182*38fd1498Szrj       */
2183*38fd1498Szrj       template<typename _Tp>
2184*38fd1498Szrj 	_If_sv<_Tp, basic_string&>
2185*38fd1498Szrj 	replace(size_type __pos1, size_type __n1, const _Tp& __svt,
2186*38fd1498Szrj 		size_type __pos2, size_type __n2 = npos)
2187*38fd1498Szrj 	{
2188*38fd1498Szrj 	  __sv_type __sv = __svt;
2189*38fd1498Szrj 	  return this->replace(__pos1, __n1, __sv.data()
2190*38fd1498Szrj 			       + __sv._M_check(__pos2, "basic_string::replace"),
2191*38fd1498Szrj 			       __sv._M_limit(__pos2, __n2));
2192*38fd1498Szrj 	}
2193*38fd1498Szrj 
2194*38fd1498Szrj       /**
2195*38fd1498Szrj        *  @brief  Replace range of characters with string_view.
2196*38fd1498Szrj        *  @param __i1    An iterator referencing the start position
2197*38fd1498Szrj           to replace at.
2198*38fd1498Szrj        *  @param __i2    An iterator referencing the end position
2199*38fd1498Szrj           for the replace.
2200*38fd1498Szrj        *  @param __svt   The object convertible to string_view to insert from.
2201*38fd1498Szrj        *  @return  Reference to this string.
2202*38fd1498Szrj       */
2203*38fd1498Szrj       template<typename _Tp>
2204*38fd1498Szrj 	_If_sv<_Tp, basic_string&>
2205*38fd1498Szrj 	replace(const_iterator __i1, const_iterator __i2, const _Tp& __svt)
2206*38fd1498Szrj 	{
2207*38fd1498Szrj 	  __sv_type __sv = __svt;
2208*38fd1498Szrj 	  return this->replace(__i1 - begin(), __i2 - __i1, __sv);
2209*38fd1498Szrj 	}
2210*38fd1498Szrj #endif // C++17
2211*38fd1498Szrj 
2212*38fd1498Szrj     private:
2213*38fd1498Szrj       template<class _Integer>
2214*38fd1498Szrj 	basic_string&
2215*38fd1498Szrj 	_M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2216*38fd1498Szrj 			    _Integer __n, _Integer __val, __true_type)
2217*38fd1498Szrj         { return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __val); }
2218*38fd1498Szrj 
2219*38fd1498Szrj       template<class _InputIterator>
2220*38fd1498Szrj 	basic_string&
2221*38fd1498Szrj 	_M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2222*38fd1498Szrj 			    _InputIterator __k1, _InputIterator __k2,
2223*38fd1498Szrj 			    __false_type);
2224*38fd1498Szrj 
2225*38fd1498Szrj       basic_string&
2226*38fd1498Szrj       _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
2227*38fd1498Szrj 		     _CharT __c);
2228*38fd1498Szrj 
2229*38fd1498Szrj       basic_string&
2230*38fd1498Szrj       _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
2231*38fd1498Szrj 		 const size_type __len2);
2232*38fd1498Szrj 
2233*38fd1498Szrj       basic_string&
2234*38fd1498Szrj       _M_append(const _CharT* __s, size_type __n);
2235*38fd1498Szrj 
2236*38fd1498Szrj     public:
2237*38fd1498Szrj 
2238*38fd1498Szrj       /**
2239*38fd1498Szrj        *  @brief  Copy substring into C string.
2240*38fd1498Szrj        *  @param __s  C string to copy value into.
2241*38fd1498Szrj        *  @param __n  Number of characters to copy.
2242*38fd1498Szrj        *  @param __pos  Index of first character to copy.
2243*38fd1498Szrj        *  @return  Number of characters actually copied
2244*38fd1498Szrj        *  @throw  std::out_of_range  If __pos > size().
2245*38fd1498Szrj        *
2246*38fd1498Szrj        *  Copies up to @a __n characters starting at @a __pos into the
2247*38fd1498Szrj        *  C string @a __s.  If @a __pos is %greater than size(),
2248*38fd1498Szrj        *  out_of_range is thrown.
2249*38fd1498Szrj       */
2250*38fd1498Szrj       size_type
2251*38fd1498Szrj       copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
2252*38fd1498Szrj 
2253*38fd1498Szrj       /**
2254*38fd1498Szrj        *  @brief  Swap contents with another string.
2255*38fd1498Szrj        *  @param __s  String to swap with.
2256*38fd1498Szrj        *
2257*38fd1498Szrj        *  Exchanges the contents of this string with that of @a __s in constant
2258*38fd1498Szrj        *  time.
2259*38fd1498Szrj       */
2260*38fd1498Szrj       void
2261*38fd1498Szrj       swap(basic_string& __s) _GLIBCXX_NOEXCEPT;
2262*38fd1498Szrj 
2263*38fd1498Szrj       // String operations:
2264*38fd1498Szrj       /**
2265*38fd1498Szrj        *  @brief  Return const pointer to null-terminated contents.
2266*38fd1498Szrj        *
2267*38fd1498Szrj        *  This is a handle to internal data.  Do not modify or dire things may
2268*38fd1498Szrj        *  happen.
2269*38fd1498Szrj       */
2270*38fd1498Szrj       const _CharT*
2271*38fd1498Szrj       c_str() const _GLIBCXX_NOEXCEPT
2272*38fd1498Szrj       { return _M_data(); }
2273*38fd1498Szrj 
2274*38fd1498Szrj       /**
2275*38fd1498Szrj        *  @brief  Return const pointer to contents.
2276*38fd1498Szrj        *
2277*38fd1498Szrj        *  This is a pointer to internal data.  It is undefined to modify
2278*38fd1498Szrj        *  the contents through the returned pointer. To get a pointer that
2279*38fd1498Szrj        *  allows modifying the contents use @c &str[0] instead,
2280*38fd1498Szrj        *  (or in C++17 the non-const @c str.data() overload).
2281*38fd1498Szrj       */
2282*38fd1498Szrj       const _CharT*
2283*38fd1498Szrj       data() const _GLIBCXX_NOEXCEPT
2284*38fd1498Szrj       { return _M_data(); }
2285*38fd1498Szrj 
2286*38fd1498Szrj #if __cplusplus > 201402L
2287*38fd1498Szrj       /**
2288*38fd1498Szrj        *  @brief  Return non-const pointer to contents.
2289*38fd1498Szrj        *
2290*38fd1498Szrj        *  This is a pointer to the character sequence held by the string.
2291*38fd1498Szrj        *  Modifying the characters in the sequence is allowed.
2292*38fd1498Szrj       */
2293*38fd1498Szrj       _CharT*
2294*38fd1498Szrj       data() noexcept
2295*38fd1498Szrj       { return _M_data(); }
2296*38fd1498Szrj #endif
2297*38fd1498Szrj 
2298*38fd1498Szrj       /**
2299*38fd1498Szrj        *  @brief  Return copy of allocator used to construct this string.
2300*38fd1498Szrj       */
2301*38fd1498Szrj       allocator_type
2302*38fd1498Szrj       get_allocator() const _GLIBCXX_NOEXCEPT
2303*38fd1498Szrj       { return _M_get_allocator(); }
2304*38fd1498Szrj 
2305*38fd1498Szrj       /**
2306*38fd1498Szrj        *  @brief  Find position of a C substring.
2307*38fd1498Szrj        *  @param __s  C string to locate.
2308*38fd1498Szrj        *  @param __pos  Index of character to search from.
2309*38fd1498Szrj        *  @param __n  Number of characters from @a s to search for.
2310*38fd1498Szrj        *  @return  Index of start of first occurrence.
2311*38fd1498Szrj        *
2312*38fd1498Szrj        *  Starting from @a __pos, searches forward for the first @a
2313*38fd1498Szrj        *  __n characters in @a __s within this string.  If found,
2314*38fd1498Szrj        *  returns the index where it begins.  If not found, returns
2315*38fd1498Szrj        *  npos.
2316*38fd1498Szrj       */
2317*38fd1498Szrj       size_type
2318*38fd1498Szrj       find(const _CharT* __s, size_type __pos, size_type __n) const
2319*38fd1498Szrj       _GLIBCXX_NOEXCEPT;
2320*38fd1498Szrj 
2321*38fd1498Szrj       /**
2322*38fd1498Szrj        *  @brief  Find position of a string.
2323*38fd1498Szrj        *  @param __str  String to locate.
2324*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
2325*38fd1498Szrj        *  @return  Index of start of first occurrence.
2326*38fd1498Szrj        *
2327*38fd1498Szrj        *  Starting from @a __pos, searches forward for value of @a __str within
2328*38fd1498Szrj        *  this string.  If found, returns the index where it begins.  If not
2329*38fd1498Szrj        *  found, returns npos.
2330*38fd1498Szrj       */
2331*38fd1498Szrj       size_type
2332*38fd1498Szrj       find(const basic_string& __str, size_type __pos = 0) const
2333*38fd1498Szrj       _GLIBCXX_NOEXCEPT
2334*38fd1498Szrj       { return this->find(__str.data(), __pos, __str.size()); }
2335*38fd1498Szrj 
2336*38fd1498Szrj #if __cplusplus > 201402L
2337*38fd1498Szrj       /**
2338*38fd1498Szrj        *  @brief  Find position of a string_view.
2339*38fd1498Szrj        *  @param __svt  The object convertible to string_view to locate.
2340*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
2341*38fd1498Szrj        *  @return  Index of start of first occurrence.
2342*38fd1498Szrj       */
2343*38fd1498Szrj       template<typename _Tp>
2344*38fd1498Szrj 	_If_sv<_Tp, size_type>
2345*38fd1498Szrj 	find(const _Tp& __svt, size_type __pos = 0) const
2346*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
2347*38fd1498Szrj 	{
2348*38fd1498Szrj 	  __sv_type __sv = __svt;
2349*38fd1498Szrj 	  return this->find(__sv.data(), __pos, __sv.size());
2350*38fd1498Szrj 	}
2351*38fd1498Szrj #endif // C++17
2352*38fd1498Szrj 
2353*38fd1498Szrj       /**
2354*38fd1498Szrj        *  @brief  Find position of a C string.
2355*38fd1498Szrj        *  @param __s  C string to locate.
2356*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
2357*38fd1498Szrj        *  @return  Index of start of first occurrence.
2358*38fd1498Szrj        *
2359*38fd1498Szrj        *  Starting from @a __pos, searches forward for the value of @a
2360*38fd1498Szrj        *  __s within this string.  If found, returns the index where
2361*38fd1498Szrj        *  it begins.  If not found, returns npos.
2362*38fd1498Szrj       */
2363*38fd1498Szrj       size_type
2364*38fd1498Szrj       find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2365*38fd1498Szrj       {
2366*38fd1498Szrj 	__glibcxx_requires_string(__s);
2367*38fd1498Szrj 	return this->find(__s, __pos, traits_type::length(__s));
2368*38fd1498Szrj       }
2369*38fd1498Szrj 
2370*38fd1498Szrj       /**
2371*38fd1498Szrj        *  @brief  Find position of a character.
2372*38fd1498Szrj        *  @param __c  Character to locate.
2373*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
2374*38fd1498Szrj        *  @return  Index of first occurrence.
2375*38fd1498Szrj        *
2376*38fd1498Szrj        *  Starting from @a __pos, searches forward for @a __c within
2377*38fd1498Szrj        *  this string.  If found, returns the index where it was
2378*38fd1498Szrj        *  found.  If not found, returns npos.
2379*38fd1498Szrj       */
2380*38fd1498Szrj       size_type
2381*38fd1498Szrj       find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
2382*38fd1498Szrj 
2383*38fd1498Szrj       /**
2384*38fd1498Szrj        *  @brief  Find last position of a string.
2385*38fd1498Szrj        *  @param __str  String to locate.
2386*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
2387*38fd1498Szrj        *  @return  Index of start of last occurrence.
2388*38fd1498Szrj        *
2389*38fd1498Szrj        *  Starting from @a __pos, searches backward for value of @a
2390*38fd1498Szrj        *  __str within this string.  If found, returns the index where
2391*38fd1498Szrj        *  it begins.  If not found, returns npos.
2392*38fd1498Szrj       */
2393*38fd1498Szrj       size_type
2394*38fd1498Szrj       rfind(const basic_string& __str, size_type __pos = npos) const
2395*38fd1498Szrj       _GLIBCXX_NOEXCEPT
2396*38fd1498Szrj       { return this->rfind(__str.data(), __pos, __str.size()); }
2397*38fd1498Szrj 
2398*38fd1498Szrj #if __cplusplus > 201402L
2399*38fd1498Szrj       /**
2400*38fd1498Szrj        *  @brief  Find last position of a string_view.
2401*38fd1498Szrj        *  @param __svt  The object convertible to string_view to locate.
2402*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
2403*38fd1498Szrj        *  @return  Index of start of last occurrence.
2404*38fd1498Szrj       */
2405*38fd1498Szrj       template<typename _Tp>
2406*38fd1498Szrj 	_If_sv<_Tp, size_type>
2407*38fd1498Szrj 	rfind(const _Tp& __svt, size_type __pos = npos) const
2408*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
2409*38fd1498Szrj 	{
2410*38fd1498Szrj 	  __sv_type __sv = __svt;
2411*38fd1498Szrj 	  return this->rfind(__sv.data(), __pos, __sv.size());
2412*38fd1498Szrj 	}
2413*38fd1498Szrj #endif // C++17
2414*38fd1498Szrj 
2415*38fd1498Szrj       /**
2416*38fd1498Szrj        *  @brief  Find last position of a C substring.
2417*38fd1498Szrj        *  @param __s  C string to locate.
2418*38fd1498Szrj        *  @param __pos  Index of character to search back from.
2419*38fd1498Szrj        *  @param __n  Number of characters from s to search for.
2420*38fd1498Szrj        *  @return  Index of start of last occurrence.
2421*38fd1498Szrj        *
2422*38fd1498Szrj        *  Starting from @a __pos, searches backward for the first @a
2423*38fd1498Szrj        *  __n characters in @a __s within this string.  If found,
2424*38fd1498Szrj        *  returns the index where it begins.  If not found, returns
2425*38fd1498Szrj        *  npos.
2426*38fd1498Szrj       */
2427*38fd1498Szrj       size_type
2428*38fd1498Szrj       rfind(const _CharT* __s, size_type __pos, size_type __n) const
2429*38fd1498Szrj       _GLIBCXX_NOEXCEPT;
2430*38fd1498Szrj 
2431*38fd1498Szrj       /**
2432*38fd1498Szrj        *  @brief  Find last position of a C string.
2433*38fd1498Szrj        *  @param __s  C string to locate.
2434*38fd1498Szrj        *  @param __pos  Index of character to start search at (default end).
2435*38fd1498Szrj        *  @return  Index of start of  last occurrence.
2436*38fd1498Szrj        *
2437*38fd1498Szrj        *  Starting from @a __pos, searches backward for the value of
2438*38fd1498Szrj        *  @a __s within this string.  If found, returns the index
2439*38fd1498Szrj        *  where it begins.  If not found, returns npos.
2440*38fd1498Szrj       */
2441*38fd1498Szrj       size_type
2442*38fd1498Szrj       rfind(const _CharT* __s, size_type __pos = npos) const
2443*38fd1498Szrj       {
2444*38fd1498Szrj 	__glibcxx_requires_string(__s);
2445*38fd1498Szrj 	return this->rfind(__s, __pos, traits_type::length(__s));
2446*38fd1498Szrj       }
2447*38fd1498Szrj 
2448*38fd1498Szrj       /**
2449*38fd1498Szrj        *  @brief  Find last position of a character.
2450*38fd1498Szrj        *  @param __c  Character to locate.
2451*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
2452*38fd1498Szrj        *  @return  Index of last occurrence.
2453*38fd1498Szrj        *
2454*38fd1498Szrj        *  Starting from @a __pos, searches backward for @a __c within
2455*38fd1498Szrj        *  this string.  If found, returns the index where it was
2456*38fd1498Szrj        *  found.  If not found, returns npos.
2457*38fd1498Szrj       */
2458*38fd1498Szrj       size_type
2459*38fd1498Szrj       rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
2460*38fd1498Szrj 
2461*38fd1498Szrj       /**
2462*38fd1498Szrj        *  @brief  Find position of a character of string.
2463*38fd1498Szrj        *  @param __str  String containing characters to locate.
2464*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
2465*38fd1498Szrj        *  @return  Index of first occurrence.
2466*38fd1498Szrj        *
2467*38fd1498Szrj        *  Starting from @a __pos, searches forward for one of the
2468*38fd1498Szrj        *  characters of @a __str within this string.  If found,
2469*38fd1498Szrj        *  returns the index where it was found.  If not found, returns
2470*38fd1498Szrj        *  npos.
2471*38fd1498Szrj       */
2472*38fd1498Szrj       size_type
2473*38fd1498Szrj       find_first_of(const basic_string& __str, size_type __pos = 0) const
2474*38fd1498Szrj       _GLIBCXX_NOEXCEPT
2475*38fd1498Szrj       { return this->find_first_of(__str.data(), __pos, __str.size()); }
2476*38fd1498Szrj 
2477*38fd1498Szrj #if __cplusplus > 201402L
2478*38fd1498Szrj       /**
2479*38fd1498Szrj        *  @brief  Find position of a character of a string_view.
2480*38fd1498Szrj        *  @param __svt  An object convertible to string_view containing
2481*38fd1498Szrj        *                characters to locate.
2482*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
2483*38fd1498Szrj        *  @return  Index of first occurrence.
2484*38fd1498Szrj       */
2485*38fd1498Szrj       template<typename _Tp>
2486*38fd1498Szrj 	_If_sv<_Tp, size_type>
2487*38fd1498Szrj 	find_first_of(const _Tp& __svt, size_type __pos = 0) const
2488*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
2489*38fd1498Szrj 	{
2490*38fd1498Szrj 	  __sv_type __sv = __svt;
2491*38fd1498Szrj 	  return this->find_first_of(__sv.data(), __pos, __sv.size());
2492*38fd1498Szrj 	}
2493*38fd1498Szrj #endif // C++17
2494*38fd1498Szrj 
2495*38fd1498Szrj       /**
2496*38fd1498Szrj        *  @brief  Find position of a character of C substring.
2497*38fd1498Szrj        *  @param __s  String containing characters to locate.
2498*38fd1498Szrj        *  @param __pos  Index of character to search from.
2499*38fd1498Szrj        *  @param __n  Number of characters from s to search for.
2500*38fd1498Szrj        *  @return  Index of first occurrence.
2501*38fd1498Szrj        *
2502*38fd1498Szrj        *  Starting from @a __pos, searches forward for one of the
2503*38fd1498Szrj        *  first @a __n characters of @a __s within this string.  If
2504*38fd1498Szrj        *  found, returns the index where it was found.  If not found,
2505*38fd1498Szrj        *  returns npos.
2506*38fd1498Szrj       */
2507*38fd1498Szrj       size_type
2508*38fd1498Szrj       find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
2509*38fd1498Szrj       _GLIBCXX_NOEXCEPT;
2510*38fd1498Szrj 
2511*38fd1498Szrj       /**
2512*38fd1498Szrj        *  @brief  Find position of a character of C string.
2513*38fd1498Szrj        *  @param __s  String containing characters to locate.
2514*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
2515*38fd1498Szrj        *  @return  Index of first occurrence.
2516*38fd1498Szrj        *
2517*38fd1498Szrj        *  Starting from @a __pos, searches forward for one of the
2518*38fd1498Szrj        *  characters of @a __s within this string.  If found, returns
2519*38fd1498Szrj        *  the index where it was found.  If not found, returns npos.
2520*38fd1498Szrj       */
2521*38fd1498Szrj       size_type
2522*38fd1498Szrj       find_first_of(const _CharT* __s, size_type __pos = 0) const
2523*38fd1498Szrj       _GLIBCXX_NOEXCEPT
2524*38fd1498Szrj       {
2525*38fd1498Szrj 	__glibcxx_requires_string(__s);
2526*38fd1498Szrj 	return this->find_first_of(__s, __pos, traits_type::length(__s));
2527*38fd1498Szrj       }
2528*38fd1498Szrj 
2529*38fd1498Szrj       /**
2530*38fd1498Szrj        *  @brief  Find position of a character.
2531*38fd1498Szrj        *  @param __c  Character to locate.
2532*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
2533*38fd1498Szrj        *  @return  Index of first occurrence.
2534*38fd1498Szrj        *
2535*38fd1498Szrj        *  Starting from @a __pos, searches forward for the character
2536*38fd1498Szrj        *  @a __c within this string.  If found, returns the index
2537*38fd1498Szrj        *  where it was found.  If not found, returns npos.
2538*38fd1498Szrj        *
2539*38fd1498Szrj        *  Note: equivalent to find(__c, __pos).
2540*38fd1498Szrj       */
2541*38fd1498Szrj       size_type
2542*38fd1498Szrj       find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2543*38fd1498Szrj       { return this->find(__c, __pos); }
2544*38fd1498Szrj 
2545*38fd1498Szrj       /**
2546*38fd1498Szrj        *  @brief  Find last position of a character of string.
2547*38fd1498Szrj        *  @param __str  String containing characters to locate.
2548*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
2549*38fd1498Szrj        *  @return  Index of last occurrence.
2550*38fd1498Szrj        *
2551*38fd1498Szrj        *  Starting from @a __pos, searches backward for one of the
2552*38fd1498Szrj        *  characters of @a __str within this string.  If found,
2553*38fd1498Szrj        *  returns the index where it was found.  If not found, returns
2554*38fd1498Szrj        *  npos.
2555*38fd1498Szrj       */
2556*38fd1498Szrj       size_type
2557*38fd1498Szrj       find_last_of(const basic_string& __str, size_type __pos = npos) const
2558*38fd1498Szrj       _GLIBCXX_NOEXCEPT
2559*38fd1498Szrj       { return this->find_last_of(__str.data(), __pos, __str.size()); }
2560*38fd1498Szrj 
2561*38fd1498Szrj #if __cplusplus > 201402L
2562*38fd1498Szrj       /**
2563*38fd1498Szrj        *  @brief  Find last position of a character of string.
2564*38fd1498Szrj        *  @param __svt  An object convertible to string_view containing
2565*38fd1498Szrj        *                characters to locate.
2566*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
2567*38fd1498Szrj        *  @return  Index of last occurrence.
2568*38fd1498Szrj       */
2569*38fd1498Szrj       template<typename _Tp>
2570*38fd1498Szrj 	_If_sv<_Tp, size_type>
2571*38fd1498Szrj 	find_last_of(const _Tp& __svt, size_type __pos = npos) const
2572*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
2573*38fd1498Szrj 	{
2574*38fd1498Szrj 	  __sv_type __sv = __svt;
2575*38fd1498Szrj 	  return this->find_last_of(__sv.data(), __pos, __sv.size());
2576*38fd1498Szrj 	}
2577*38fd1498Szrj #endif // C++17
2578*38fd1498Szrj 
2579*38fd1498Szrj       /**
2580*38fd1498Szrj        *  @brief  Find last position of a character of C substring.
2581*38fd1498Szrj        *  @param __s  C string containing characters to locate.
2582*38fd1498Szrj        *  @param __pos  Index of character to search back from.
2583*38fd1498Szrj        *  @param __n  Number of characters from s to search for.
2584*38fd1498Szrj        *  @return  Index of last occurrence.
2585*38fd1498Szrj        *
2586*38fd1498Szrj        *  Starting from @a __pos, searches backward for one of the
2587*38fd1498Szrj        *  first @a __n characters of @a __s within this string.  If
2588*38fd1498Szrj        *  found, returns the index where it was found.  If not found,
2589*38fd1498Szrj        *  returns npos.
2590*38fd1498Szrj       */
2591*38fd1498Szrj       size_type
2592*38fd1498Szrj       find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
2593*38fd1498Szrj       _GLIBCXX_NOEXCEPT;
2594*38fd1498Szrj 
2595*38fd1498Szrj       /**
2596*38fd1498Szrj        *  @brief  Find last position of a character of C string.
2597*38fd1498Szrj        *  @param __s  C string containing characters to locate.
2598*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
2599*38fd1498Szrj        *  @return  Index of last occurrence.
2600*38fd1498Szrj        *
2601*38fd1498Szrj        *  Starting from @a __pos, searches backward for one of the
2602*38fd1498Szrj        *  characters of @a __s within this string.  If found, returns
2603*38fd1498Szrj        *  the index where it was found.  If not found, returns npos.
2604*38fd1498Szrj       */
2605*38fd1498Szrj       size_type
2606*38fd1498Szrj       find_last_of(const _CharT* __s, size_type __pos = npos) const
2607*38fd1498Szrj       _GLIBCXX_NOEXCEPT
2608*38fd1498Szrj       {
2609*38fd1498Szrj 	__glibcxx_requires_string(__s);
2610*38fd1498Szrj 	return this->find_last_of(__s, __pos, traits_type::length(__s));
2611*38fd1498Szrj       }
2612*38fd1498Szrj 
2613*38fd1498Szrj       /**
2614*38fd1498Szrj        *  @brief  Find last position of a character.
2615*38fd1498Szrj        *  @param __c  Character to locate.
2616*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
2617*38fd1498Szrj        *  @return  Index of last occurrence.
2618*38fd1498Szrj        *
2619*38fd1498Szrj        *  Starting from @a __pos, searches backward for @a __c within
2620*38fd1498Szrj        *  this string.  If found, returns the index where it was
2621*38fd1498Szrj        *  found.  If not found, returns npos.
2622*38fd1498Szrj        *
2623*38fd1498Szrj        *  Note: equivalent to rfind(__c, __pos).
2624*38fd1498Szrj       */
2625*38fd1498Szrj       size_type
2626*38fd1498Szrj       find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
2627*38fd1498Szrj       { return this->rfind(__c, __pos); }
2628*38fd1498Szrj 
2629*38fd1498Szrj       /**
2630*38fd1498Szrj        *  @brief  Find position of a character not in string.
2631*38fd1498Szrj        *  @param __str  String containing characters to avoid.
2632*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
2633*38fd1498Szrj        *  @return  Index of first occurrence.
2634*38fd1498Szrj        *
2635*38fd1498Szrj        *  Starting from @a __pos, searches forward for a character not contained
2636*38fd1498Szrj        *  in @a __str within this string.  If found, returns the index where it
2637*38fd1498Szrj        *  was found.  If not found, returns npos.
2638*38fd1498Szrj       */
2639*38fd1498Szrj       size_type
2640*38fd1498Szrj       find_first_not_of(const basic_string& __str, size_type __pos = 0) const
2641*38fd1498Szrj       _GLIBCXX_NOEXCEPT
2642*38fd1498Szrj       { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
2643*38fd1498Szrj 
2644*38fd1498Szrj #if __cplusplus > 201402L
2645*38fd1498Szrj       /**
2646*38fd1498Szrj        *  @brief  Find position of a character not in a string_view.
2647*38fd1498Szrj        *  @param __svt  A object convertible to string_view containing
2648*38fd1498Szrj        *                characters to avoid.
2649*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
2650*38fd1498Szrj        *  @return  Index of first occurrence.
2651*38fd1498Szrj        */
2652*38fd1498Szrj       template<typename _Tp>
2653*38fd1498Szrj 	_If_sv<_Tp, size_type>
2654*38fd1498Szrj 	find_first_not_of(const _Tp& __svt, size_type __pos = 0) const
2655*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
2656*38fd1498Szrj 	{
2657*38fd1498Szrj 	  __sv_type __sv = __svt;
2658*38fd1498Szrj 	  return this->find_first_not_of(__sv.data(), __pos, __sv.size());
2659*38fd1498Szrj 	}
2660*38fd1498Szrj #endif // C++17
2661*38fd1498Szrj 
2662*38fd1498Szrj       /**
2663*38fd1498Szrj        *  @brief  Find position of a character not in C substring.
2664*38fd1498Szrj        *  @param __s  C string containing characters to avoid.
2665*38fd1498Szrj        *  @param __pos  Index of character to search from.
2666*38fd1498Szrj        *  @param __n  Number of characters from __s to consider.
2667*38fd1498Szrj        *  @return  Index of first occurrence.
2668*38fd1498Szrj        *
2669*38fd1498Szrj        *  Starting from @a __pos, searches forward for a character not
2670*38fd1498Szrj        *  contained in the first @a __n characters of @a __s within
2671*38fd1498Szrj        *  this string.  If found, returns the index where it was
2672*38fd1498Szrj        *  found.  If not found, returns npos.
2673*38fd1498Szrj       */
2674*38fd1498Szrj       size_type
2675*38fd1498Szrj       find_first_not_of(const _CharT* __s, size_type __pos,
2676*38fd1498Szrj 			size_type __n) const _GLIBCXX_NOEXCEPT;
2677*38fd1498Szrj 
2678*38fd1498Szrj       /**
2679*38fd1498Szrj        *  @brief  Find position of a character not in C string.
2680*38fd1498Szrj        *  @param __s  C string containing characters to avoid.
2681*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
2682*38fd1498Szrj        *  @return  Index of first occurrence.
2683*38fd1498Szrj        *
2684*38fd1498Szrj        *  Starting from @a __pos, searches forward for a character not
2685*38fd1498Szrj        *  contained in @a __s within this string.  If found, returns
2686*38fd1498Szrj        *  the index where it was found.  If not found, returns npos.
2687*38fd1498Szrj       */
2688*38fd1498Szrj       size_type
2689*38fd1498Szrj       find_first_not_of(const _CharT* __s, size_type __pos = 0) const
2690*38fd1498Szrj       _GLIBCXX_NOEXCEPT
2691*38fd1498Szrj       {
2692*38fd1498Szrj 	__glibcxx_requires_string(__s);
2693*38fd1498Szrj 	return this->find_first_not_of(__s, __pos, traits_type::length(__s));
2694*38fd1498Szrj       }
2695*38fd1498Szrj 
2696*38fd1498Szrj       /**
2697*38fd1498Szrj        *  @brief  Find position of a different character.
2698*38fd1498Szrj        *  @param __c  Character to avoid.
2699*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
2700*38fd1498Szrj        *  @return  Index of first occurrence.
2701*38fd1498Szrj        *
2702*38fd1498Szrj        *  Starting from @a __pos, searches forward for a character
2703*38fd1498Szrj        *  other than @a __c within this string.  If found, returns the
2704*38fd1498Szrj        *  index where it was found.  If not found, returns npos.
2705*38fd1498Szrj       */
2706*38fd1498Szrj       size_type
2707*38fd1498Szrj       find_first_not_of(_CharT __c, size_type __pos = 0) const
2708*38fd1498Szrj       _GLIBCXX_NOEXCEPT;
2709*38fd1498Szrj 
2710*38fd1498Szrj       /**
2711*38fd1498Szrj        *  @brief  Find last position of a character not in string.
2712*38fd1498Szrj        *  @param __str  String containing characters to avoid.
2713*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
2714*38fd1498Szrj        *  @return  Index of last occurrence.
2715*38fd1498Szrj        *
2716*38fd1498Szrj        *  Starting from @a __pos, searches backward for a character
2717*38fd1498Szrj        *  not contained in @a __str within this string.  If found,
2718*38fd1498Szrj        *  returns the index where it was found.  If not found, returns
2719*38fd1498Szrj        *  npos.
2720*38fd1498Szrj       */
2721*38fd1498Szrj       size_type
2722*38fd1498Szrj       find_last_not_of(const basic_string& __str, size_type __pos = npos) const
2723*38fd1498Szrj       _GLIBCXX_NOEXCEPT
2724*38fd1498Szrj       { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
2725*38fd1498Szrj 
2726*38fd1498Szrj #if __cplusplus > 201402L
2727*38fd1498Szrj       /**
2728*38fd1498Szrj        *  @brief  Find last position of a character not in a string_view.
2729*38fd1498Szrj        *  @param __svt  An object convertible to string_view containing
2730*38fd1498Szrj        *                characters to avoid.
2731*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
2732*38fd1498Szrj        *  @return  Index of last occurrence.
2733*38fd1498Szrj        */
2734*38fd1498Szrj       template<typename _Tp>
2735*38fd1498Szrj 	_If_sv<_Tp, size_type>
2736*38fd1498Szrj 	find_last_not_of(const _Tp& __svt, size_type __pos = npos) const
2737*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
2738*38fd1498Szrj 	{
2739*38fd1498Szrj 	  __sv_type __sv = __svt;
2740*38fd1498Szrj 	  return this->find_last_not_of(__sv.data(), __pos, __sv.size());
2741*38fd1498Szrj 	}
2742*38fd1498Szrj #endif // C++17
2743*38fd1498Szrj 
2744*38fd1498Szrj       /**
2745*38fd1498Szrj        *  @brief  Find last position of a character not in C substring.
2746*38fd1498Szrj        *  @param __s  C string containing characters to avoid.
2747*38fd1498Szrj        *  @param __pos  Index of character to search back from.
2748*38fd1498Szrj        *  @param __n  Number of characters from s to consider.
2749*38fd1498Szrj        *  @return  Index of last occurrence.
2750*38fd1498Szrj        *
2751*38fd1498Szrj        *  Starting from @a __pos, searches backward for a character not
2752*38fd1498Szrj        *  contained in the first @a __n characters of @a __s within this string.
2753*38fd1498Szrj        *  If found, returns the index where it was found.  If not found,
2754*38fd1498Szrj        *  returns npos.
2755*38fd1498Szrj       */
2756*38fd1498Szrj       size_type
2757*38fd1498Szrj       find_last_not_of(const _CharT* __s, size_type __pos,
2758*38fd1498Szrj 		       size_type __n) const _GLIBCXX_NOEXCEPT;
2759*38fd1498Szrj       /**
2760*38fd1498Szrj        *  @brief  Find last position of a character not in C string.
2761*38fd1498Szrj        *  @param __s  C string containing characters to avoid.
2762*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
2763*38fd1498Szrj        *  @return  Index of last occurrence.
2764*38fd1498Szrj        *
2765*38fd1498Szrj        *  Starting from @a __pos, searches backward for a character
2766*38fd1498Szrj        *  not contained in @a __s within this string.  If found,
2767*38fd1498Szrj        *  returns the index where it was found.  If not found, returns
2768*38fd1498Szrj        *  npos.
2769*38fd1498Szrj       */
2770*38fd1498Szrj       size_type
2771*38fd1498Szrj       find_last_not_of(const _CharT* __s, size_type __pos = npos) const
2772*38fd1498Szrj       _GLIBCXX_NOEXCEPT
2773*38fd1498Szrj       {
2774*38fd1498Szrj 	__glibcxx_requires_string(__s);
2775*38fd1498Szrj 	return this->find_last_not_of(__s, __pos, traits_type::length(__s));
2776*38fd1498Szrj       }
2777*38fd1498Szrj 
2778*38fd1498Szrj       /**
2779*38fd1498Szrj        *  @brief  Find last position of a different character.
2780*38fd1498Szrj        *  @param __c  Character to avoid.
2781*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
2782*38fd1498Szrj        *  @return  Index of last occurrence.
2783*38fd1498Szrj        *
2784*38fd1498Szrj        *  Starting from @a __pos, searches backward for a character other than
2785*38fd1498Szrj        *  @a __c within this string.  If found, returns the index where it was
2786*38fd1498Szrj        *  found.  If not found, returns npos.
2787*38fd1498Szrj       */
2788*38fd1498Szrj       size_type
2789*38fd1498Szrj       find_last_not_of(_CharT __c, size_type __pos = npos) const
2790*38fd1498Szrj       _GLIBCXX_NOEXCEPT;
2791*38fd1498Szrj 
2792*38fd1498Szrj       /**
2793*38fd1498Szrj        *  @brief  Get a substring.
2794*38fd1498Szrj        *  @param __pos  Index of first character (default 0).
2795*38fd1498Szrj        *  @param __n  Number of characters in substring (default remainder).
2796*38fd1498Szrj        *  @return  The new string.
2797*38fd1498Szrj        *  @throw  std::out_of_range  If __pos > size().
2798*38fd1498Szrj        *
2799*38fd1498Szrj        *  Construct and return a new string using the @a __n
2800*38fd1498Szrj        *  characters starting at @a __pos.  If the string is too
2801*38fd1498Szrj        *  short, use the remainder of the characters.  If @a __pos is
2802*38fd1498Szrj        *  beyond the end of the string, out_of_range is thrown.
2803*38fd1498Szrj       */
2804*38fd1498Szrj       basic_string
2805*38fd1498Szrj       substr(size_type __pos = 0, size_type __n = npos) const
2806*38fd1498Szrj       { return basic_string(*this,
2807*38fd1498Szrj 			    _M_check(__pos, "basic_string::substr"), __n); }
2808*38fd1498Szrj 
2809*38fd1498Szrj       /**
2810*38fd1498Szrj        *  @brief  Compare to a string.
2811*38fd1498Szrj        *  @param __str  String to compare against.
2812*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
2813*38fd1498Szrj        *
2814*38fd1498Szrj        *  Returns an integer < 0 if this string is ordered before @a
2815*38fd1498Szrj        *  __str, 0 if their values are equivalent, or > 0 if this
2816*38fd1498Szrj        *  string is ordered after @a __str.  Determines the effective
2817*38fd1498Szrj        *  length rlen of the strings to compare as the smallest of
2818*38fd1498Szrj        *  size() and str.size().  The function then compares the two
2819*38fd1498Szrj        *  strings by calling traits::compare(data(), str.data(),rlen).
2820*38fd1498Szrj        *  If the result of the comparison is nonzero returns it,
2821*38fd1498Szrj        *  otherwise the shorter one is ordered first.
2822*38fd1498Szrj       */
2823*38fd1498Szrj       int
2824*38fd1498Szrj       compare(const basic_string& __str) const
2825*38fd1498Szrj       {
2826*38fd1498Szrj 	const size_type __size = this->size();
2827*38fd1498Szrj 	const size_type __osize = __str.size();
2828*38fd1498Szrj 	const size_type __len = std::min(__size, __osize);
2829*38fd1498Szrj 
2830*38fd1498Szrj 	int __r = traits_type::compare(_M_data(), __str.data(), __len);
2831*38fd1498Szrj 	if (!__r)
2832*38fd1498Szrj 	  __r = _S_compare(__size, __osize);
2833*38fd1498Szrj 	return __r;
2834*38fd1498Szrj       }
2835*38fd1498Szrj 
2836*38fd1498Szrj #if __cplusplus > 201402L
2837*38fd1498Szrj       /**
2838*38fd1498Szrj        *  @brief  Compare to a string_view.
2839*38fd1498Szrj        *  @param __svt An object convertible to string_view to compare against.
2840*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
2841*38fd1498Szrj        */
2842*38fd1498Szrj       template<typename _Tp>
2843*38fd1498Szrj 	_If_sv<_Tp, int>
2844*38fd1498Szrj 	compare(const _Tp& __svt) const
2845*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
2846*38fd1498Szrj 	{
2847*38fd1498Szrj 	  __sv_type __sv = __svt;
2848*38fd1498Szrj 	  const size_type __size = this->size();
2849*38fd1498Szrj 	  const size_type __osize = __sv.size();
2850*38fd1498Szrj 	  const size_type __len = std::min(__size, __osize);
2851*38fd1498Szrj 
2852*38fd1498Szrj 	  int __r = traits_type::compare(_M_data(), __sv.data(), __len);
2853*38fd1498Szrj 	  if (!__r)
2854*38fd1498Szrj 	    __r = _S_compare(__size, __osize);
2855*38fd1498Szrj 	  return __r;
2856*38fd1498Szrj 	}
2857*38fd1498Szrj 
2858*38fd1498Szrj       /**
2859*38fd1498Szrj        *  @brief  Compare to a string_view.
2860*38fd1498Szrj        *  @param __pos  A position in the string to start comparing from.
2861*38fd1498Szrj        *  @param __n  The number of characters to compare.
2862*38fd1498Szrj        *  @param __svt  An object convertible to string_view to compare
2863*38fd1498Szrj        *                against.
2864*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
2865*38fd1498Szrj        */
2866*38fd1498Szrj       template<typename _Tp>
2867*38fd1498Szrj 	_If_sv<_Tp, int>
2868*38fd1498Szrj 	compare(size_type __pos, size_type __n, const _Tp& __svt) const
2869*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
2870*38fd1498Szrj 	{
2871*38fd1498Szrj 	  __sv_type __sv = __svt;
2872*38fd1498Szrj 	  return __sv_type(*this).substr(__pos, __n).compare(__sv);
2873*38fd1498Szrj 	}
2874*38fd1498Szrj 
2875*38fd1498Szrj       /**
2876*38fd1498Szrj        *  @brief  Compare to a string_view.
2877*38fd1498Szrj        *  @param __pos1  A position in the string to start comparing from.
2878*38fd1498Szrj        *  @param __n1  The number of characters to compare.
2879*38fd1498Szrj        *  @param __svt  An object convertible to string_view to compare
2880*38fd1498Szrj        *                against.
2881*38fd1498Szrj        *  @param __pos2  A position in the string_view to start comparing from.
2882*38fd1498Szrj        *  @param __n2  The number of characters to compare.
2883*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
2884*38fd1498Szrj        */
2885*38fd1498Szrj       template<typename _Tp>
2886*38fd1498Szrj 	_If_sv<_Tp, int>
2887*38fd1498Szrj 	compare(size_type __pos1, size_type __n1, const _Tp& __svt,
2888*38fd1498Szrj 		size_type __pos2, size_type __n2 = npos) const
2889*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
2890*38fd1498Szrj 	{
2891*38fd1498Szrj 	  __sv_type __sv = __svt;
2892*38fd1498Szrj 	  return __sv_type(*this)
2893*38fd1498Szrj 	    .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
2894*38fd1498Szrj 	}
2895*38fd1498Szrj #endif // C++17
2896*38fd1498Szrj 
2897*38fd1498Szrj       /**
2898*38fd1498Szrj        *  @brief  Compare substring to a string.
2899*38fd1498Szrj        *  @param __pos  Index of first character of substring.
2900*38fd1498Szrj        *  @param __n  Number of characters in substring.
2901*38fd1498Szrj        *  @param __str  String to compare against.
2902*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
2903*38fd1498Szrj        *
2904*38fd1498Szrj        *  Form the substring of this string from the @a __n characters
2905*38fd1498Szrj        *  starting at @a __pos.  Returns an integer < 0 if the
2906*38fd1498Szrj        *  substring is ordered before @a __str, 0 if their values are
2907*38fd1498Szrj        *  equivalent, or > 0 if the substring is ordered after @a
2908*38fd1498Szrj        *  __str.  Determines the effective length rlen of the strings
2909*38fd1498Szrj        *  to compare as the smallest of the length of the substring
2910*38fd1498Szrj        *  and @a __str.size().  The function then compares the two
2911*38fd1498Szrj        *  strings by calling
2912*38fd1498Szrj        *  traits::compare(substring.data(),str.data(),rlen).  If the
2913*38fd1498Szrj        *  result of the comparison is nonzero returns it, otherwise
2914*38fd1498Szrj        *  the shorter one is ordered first.
2915*38fd1498Szrj       */
2916*38fd1498Szrj       int
2917*38fd1498Szrj       compare(size_type __pos, size_type __n, const basic_string& __str) const;
2918*38fd1498Szrj 
2919*38fd1498Szrj       /**
2920*38fd1498Szrj        *  @brief  Compare substring to a substring.
2921*38fd1498Szrj        *  @param __pos1  Index of first character of substring.
2922*38fd1498Szrj        *  @param __n1  Number of characters in substring.
2923*38fd1498Szrj        *  @param __str  String to compare against.
2924*38fd1498Szrj        *  @param __pos2  Index of first character of substring of str.
2925*38fd1498Szrj        *  @param __n2  Number of characters in substring of str.
2926*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
2927*38fd1498Szrj        *
2928*38fd1498Szrj        *  Form the substring of this string from the @a __n1
2929*38fd1498Szrj        *  characters starting at @a __pos1.  Form the substring of @a
2930*38fd1498Szrj        *  __str from the @a __n2 characters starting at @a __pos2.
2931*38fd1498Szrj        *  Returns an integer < 0 if this substring is ordered before
2932*38fd1498Szrj        *  the substring of @a __str, 0 if their values are equivalent,
2933*38fd1498Szrj        *  or > 0 if this substring is ordered after the substring of
2934*38fd1498Szrj        *  @a __str.  Determines the effective length rlen of the
2935*38fd1498Szrj        *  strings to compare as the smallest of the lengths of the
2936*38fd1498Szrj        *  substrings.  The function then compares the two strings by
2937*38fd1498Szrj        *  calling
2938*38fd1498Szrj        *  traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
2939*38fd1498Szrj        *  If the result of the comparison is nonzero returns it,
2940*38fd1498Szrj        *  otherwise the shorter one is ordered first.
2941*38fd1498Szrj       */
2942*38fd1498Szrj       int
2943*38fd1498Szrj       compare(size_type __pos1, size_type __n1, const basic_string& __str,
2944*38fd1498Szrj 	      size_type __pos2, size_type __n2) const;
2945*38fd1498Szrj 
2946*38fd1498Szrj       /**
2947*38fd1498Szrj        *  @brief  Compare to a C string.
2948*38fd1498Szrj        *  @param __s  C string to compare against.
2949*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
2950*38fd1498Szrj        *
2951*38fd1498Szrj        *  Returns an integer < 0 if this string is ordered before @a __s, 0 if
2952*38fd1498Szrj        *  their values are equivalent, or > 0 if this string is ordered after
2953*38fd1498Szrj        *  @a __s.  Determines the effective length rlen of the strings to
2954*38fd1498Szrj        *  compare as the smallest of size() and the length of a string
2955*38fd1498Szrj        *  constructed from @a __s.  The function then compares the two strings
2956*38fd1498Szrj        *  by calling traits::compare(data(),s,rlen).  If the result of the
2957*38fd1498Szrj        *  comparison is nonzero returns it, otherwise the shorter one is
2958*38fd1498Szrj        *  ordered first.
2959*38fd1498Szrj       */
2960*38fd1498Szrj       int
2961*38fd1498Szrj       compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT;
2962*38fd1498Szrj 
2963*38fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
2964*38fd1498Szrj       // 5 String::compare specification questionable
2965*38fd1498Szrj       /**
2966*38fd1498Szrj        *  @brief  Compare substring to a C string.
2967*38fd1498Szrj        *  @param __pos  Index of first character of substring.
2968*38fd1498Szrj        *  @param __n1  Number of characters in substring.
2969*38fd1498Szrj        *  @param __s  C string to compare against.
2970*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
2971*38fd1498Szrj        *
2972*38fd1498Szrj        *  Form the substring of this string from the @a __n1
2973*38fd1498Szrj        *  characters starting at @a pos.  Returns an integer < 0 if
2974*38fd1498Szrj        *  the substring is ordered before @a __s, 0 if their values
2975*38fd1498Szrj        *  are equivalent, or > 0 if the substring is ordered after @a
2976*38fd1498Szrj        *  __s.  Determines the effective length rlen of the strings to
2977*38fd1498Szrj        *  compare as the smallest of the length of the substring and
2978*38fd1498Szrj        *  the length of a string constructed from @a __s.  The
2979*38fd1498Szrj        *  function then compares the two string by calling
2980*38fd1498Szrj        *  traits::compare(substring.data(),__s,rlen).  If the result of
2981*38fd1498Szrj        *  the comparison is nonzero returns it, otherwise the shorter
2982*38fd1498Szrj        *  one is ordered first.
2983*38fd1498Szrj       */
2984*38fd1498Szrj       int
2985*38fd1498Szrj       compare(size_type __pos, size_type __n1, const _CharT* __s) const;
2986*38fd1498Szrj 
2987*38fd1498Szrj       /**
2988*38fd1498Szrj        *  @brief  Compare substring against a character %array.
2989*38fd1498Szrj        *  @param __pos  Index of first character of substring.
2990*38fd1498Szrj        *  @param __n1  Number of characters in substring.
2991*38fd1498Szrj        *  @param __s  character %array to compare against.
2992*38fd1498Szrj        *  @param __n2  Number of characters of s.
2993*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
2994*38fd1498Szrj        *
2995*38fd1498Szrj        *  Form the substring of this string from the @a __n1
2996*38fd1498Szrj        *  characters starting at @a __pos.  Form a string from the
2997*38fd1498Szrj        *  first @a __n2 characters of @a __s.  Returns an integer < 0
2998*38fd1498Szrj        *  if this substring is ordered before the string from @a __s,
2999*38fd1498Szrj        *  0 if their values are equivalent, or > 0 if this substring
3000*38fd1498Szrj        *  is ordered after the string from @a __s.  Determines the
3001*38fd1498Szrj        *  effective length rlen of the strings to compare as the
3002*38fd1498Szrj        *  smallest of the length of the substring and @a __n2.  The
3003*38fd1498Szrj        *  function then compares the two strings by calling
3004*38fd1498Szrj        *  traits::compare(substring.data(),s,rlen).  If the result of
3005*38fd1498Szrj        *  the comparison is nonzero returns it, otherwise the shorter
3006*38fd1498Szrj        *  one is ordered first.
3007*38fd1498Szrj        *
3008*38fd1498Szrj        *  NB: s must have at least n2 characters, &apos;\\0&apos; has
3009*38fd1498Szrj        *  no special meaning.
3010*38fd1498Szrj       */
3011*38fd1498Szrj       int
3012*38fd1498Szrj       compare(size_type __pos, size_type __n1, const _CharT* __s,
3013*38fd1498Szrj 	      size_type __n2) const;
3014*38fd1498Szrj 
3015*38fd1498Szrj       // Allow basic_stringbuf::__xfer_bufptrs to call _M_length:
3016*38fd1498Szrj       template<typename, typename, typename> friend class basic_stringbuf;
3017*38fd1498Szrj     };
3018*38fd1498Szrj _GLIBCXX_END_NAMESPACE_CXX11
3019*38fd1498Szrj #else  // !_GLIBCXX_USE_CXX11_ABI
3020*38fd1498Szrj   // Reference-counted COW string implentation
3021*38fd1498Szrj 
3022*38fd1498Szrj   /**
3023*38fd1498Szrj    *  @class basic_string basic_string.h <string>
3024*38fd1498Szrj    *  @brief  Managing sequences of characters and character-like objects.
3025*38fd1498Szrj    *
3026*38fd1498Szrj    *  @ingroup strings
3027*38fd1498Szrj    *  @ingroup sequences
3028*38fd1498Szrj    *
3029*38fd1498Szrj    *  @tparam _CharT  Type of character
3030*38fd1498Szrj    *  @tparam _Traits  Traits for character type, defaults to
3031*38fd1498Szrj    *                   char_traits<_CharT>.
3032*38fd1498Szrj    *  @tparam _Alloc  Allocator type, defaults to allocator<_CharT>.
3033*38fd1498Szrj    *
3034*38fd1498Szrj    *  Meets the requirements of a <a href="tables.html#65">container</a>, a
3035*38fd1498Szrj    *  <a href="tables.html#66">reversible container</a>, and a
3036*38fd1498Szrj    *  <a href="tables.html#67">sequence</a>.  Of the
3037*38fd1498Szrj    *  <a href="tables.html#68">optional sequence requirements</a>, only
3038*38fd1498Szrj    *  @c push_back, @c at, and @c %array access are supported.
3039*38fd1498Szrj    *
3040*38fd1498Szrj    *  @doctodo
3041*38fd1498Szrj    *
3042*38fd1498Szrj    *
3043*38fd1498Szrj    *  Documentation?  What's that?
3044*38fd1498Szrj    *  Nathan Myers <ncm@cantrip.org>.
3045*38fd1498Szrj    *
3046*38fd1498Szrj    *  A string looks like this:
3047*38fd1498Szrj    *
3048*38fd1498Szrj    *  @code
3049*38fd1498Szrj    *                                        [_Rep]
3050*38fd1498Szrj    *                                        _M_length
3051*38fd1498Szrj    *   [basic_string<char_type>]            _M_capacity
3052*38fd1498Szrj    *   _M_dataplus                          _M_refcount
3053*38fd1498Szrj    *   _M_p ---------------->               unnamed array of char_type
3054*38fd1498Szrj    *  @endcode
3055*38fd1498Szrj    *
3056*38fd1498Szrj    *  Where the _M_p points to the first character in the string, and
3057*38fd1498Szrj    *  you cast it to a pointer-to-_Rep and subtract 1 to get a
3058*38fd1498Szrj    *  pointer to the header.
3059*38fd1498Szrj    *
3060*38fd1498Szrj    *  This approach has the enormous advantage that a string object
3061*38fd1498Szrj    *  requires only one allocation.  All the ugliness is confined
3062*38fd1498Szrj    *  within a single %pair of inline functions, which each compile to
3063*38fd1498Szrj    *  a single @a add instruction: _Rep::_M_data(), and
3064*38fd1498Szrj    *  string::_M_rep(); and the allocation function which gets a
3065*38fd1498Szrj    *  block of raw bytes and with room enough and constructs a _Rep
3066*38fd1498Szrj    *  object at the front.
3067*38fd1498Szrj    *
3068*38fd1498Szrj    *  The reason you want _M_data pointing to the character %array and
3069*38fd1498Szrj    *  not the _Rep is so that the debugger can see the string
3070*38fd1498Szrj    *  contents. (Probably we should add a non-inline member to get
3071*38fd1498Szrj    *  the _Rep for the debugger to use, so users can check the actual
3072*38fd1498Szrj    *  string length.)
3073*38fd1498Szrj    *
3074*38fd1498Szrj    *  Note that the _Rep object is a POD so that you can have a
3075*38fd1498Szrj    *  static <em>empty string</em> _Rep object already @a constructed before
3076*38fd1498Szrj    *  static constructors have run.  The reference-count encoding is
3077*38fd1498Szrj    *  chosen so that a 0 indicates one reference, so you never try to
3078*38fd1498Szrj    *  destroy the empty-string _Rep object.
3079*38fd1498Szrj    *
3080*38fd1498Szrj    *  All but the last paragraph is considered pretty conventional
3081*38fd1498Szrj    *  for a C++ string implementation.
3082*38fd1498Szrj   */
3083*38fd1498Szrj   // 21.3  Template class basic_string
3084*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
3085*38fd1498Szrj     class basic_string
3086*38fd1498Szrj     {
3087*38fd1498Szrj       typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type;
3088*38fd1498Szrj 
3089*38fd1498Szrj       // Types:
3090*38fd1498Szrj     public:
3091*38fd1498Szrj       typedef _Traits					    traits_type;
3092*38fd1498Szrj       typedef typename _Traits::char_type		    value_type;
3093*38fd1498Szrj       typedef _Alloc					    allocator_type;
3094*38fd1498Szrj       typedef typename _CharT_alloc_type::size_type	    size_type;
3095*38fd1498Szrj       typedef typename _CharT_alloc_type::difference_type   difference_type;
3096*38fd1498Szrj       typedef typename _CharT_alloc_type::reference	    reference;
3097*38fd1498Szrj       typedef typename _CharT_alloc_type::const_reference   const_reference;
3098*38fd1498Szrj       typedef typename _CharT_alloc_type::pointer	    pointer;
3099*38fd1498Szrj       typedef typename _CharT_alloc_type::const_pointer	    const_pointer;
3100*38fd1498Szrj       typedef __gnu_cxx::__normal_iterator<pointer, basic_string>  iterator;
3101*38fd1498Szrj       typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
3102*38fd1498Szrj                                                             const_iterator;
3103*38fd1498Szrj       typedef std::reverse_iterator<const_iterator>	const_reverse_iterator;
3104*38fd1498Szrj       typedef std::reverse_iterator<iterator>		    reverse_iterator;
3105*38fd1498Szrj 
3106*38fd1498Szrj     private:
3107*38fd1498Szrj       // _Rep: string representation
3108*38fd1498Szrj       //   Invariants:
3109*38fd1498Szrj       //   1. String really contains _M_length + 1 characters: due to 21.3.4
3110*38fd1498Szrj       //      must be kept null-terminated.
3111*38fd1498Szrj       //   2. _M_capacity >= _M_length
3112*38fd1498Szrj       //      Allocated memory is always (_M_capacity + 1) * sizeof(_CharT).
3113*38fd1498Szrj       //   3. _M_refcount has three states:
3114*38fd1498Szrj       //      -1: leaked, one reference, no ref-copies allowed, non-const.
3115*38fd1498Szrj       //       0: one reference, non-const.
3116*38fd1498Szrj       //     n>0: n + 1 references, operations require a lock, const.
3117*38fd1498Szrj       //   4. All fields==0 is an empty string, given the extra storage
3118*38fd1498Szrj       //      beyond-the-end for a null terminator; thus, the shared
3119*38fd1498Szrj       //      empty string representation needs no constructor.
3120*38fd1498Szrj 
3121*38fd1498Szrj       struct _Rep_base
3122*38fd1498Szrj       {
3123*38fd1498Szrj 	size_type		_M_length;
3124*38fd1498Szrj 	size_type		_M_capacity;
3125*38fd1498Szrj 	_Atomic_word		_M_refcount;
3126*38fd1498Szrj       };
3127*38fd1498Szrj 
3128*38fd1498Szrj       struct _Rep : _Rep_base
3129*38fd1498Szrj       {
3130*38fd1498Szrj 	// Types:
3131*38fd1498Szrj 	typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc;
3132*38fd1498Szrj 
3133*38fd1498Szrj 	// (Public) Data members:
3134*38fd1498Szrj 
3135*38fd1498Szrj 	// The maximum number of individual char_type elements of an
3136*38fd1498Szrj 	// individual string is determined by _S_max_size. This is the
3137*38fd1498Szrj 	// value that will be returned by max_size().  (Whereas npos
3138*38fd1498Szrj 	// is the maximum number of bytes the allocator can allocate.)
3139*38fd1498Szrj 	// If one was to divvy up the theoretical largest size string,
3140*38fd1498Szrj 	// with a terminating character and m _CharT elements, it'd
3141*38fd1498Szrj 	// look like this:
3142*38fd1498Szrj 	// npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
3143*38fd1498Szrj 	// Solving for m:
3144*38fd1498Szrj 	// m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
3145*38fd1498Szrj 	// In addition, this implementation quarters this amount.
3146*38fd1498Szrj 	static const size_type	_S_max_size;
3147*38fd1498Szrj 	static const _CharT	_S_terminal;
3148*38fd1498Szrj 
3149*38fd1498Szrj 	// The following storage is init'd to 0 by the linker, resulting
3150*38fd1498Szrj         // (carefully) in an empty string with one reference.
3151*38fd1498Szrj         static size_type _S_empty_rep_storage[];
3152*38fd1498Szrj 
3153*38fd1498Szrj         static _Rep&
3154*38fd1498Szrj         _S_empty_rep() _GLIBCXX_NOEXCEPT
3155*38fd1498Szrj         {
3156*38fd1498Szrj 	  // NB: Mild hack to avoid strict-aliasing warnings.  Note that
3157*38fd1498Szrj 	  // _S_empty_rep_storage is never modified and the punning should
3158*38fd1498Szrj 	  // be reasonably safe in this case.
3159*38fd1498Szrj 	  void* __p = reinterpret_cast<void*>(&_S_empty_rep_storage);
3160*38fd1498Szrj 	  return *reinterpret_cast<_Rep*>(__p);
3161*38fd1498Szrj 	}
3162*38fd1498Szrj 
3163*38fd1498Szrj         bool
3164*38fd1498Szrj 	_M_is_leaked() const _GLIBCXX_NOEXCEPT
3165*38fd1498Szrj         {
3166*38fd1498Szrj #if defined(__GTHREADS)
3167*38fd1498Szrj           // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose,
3168*38fd1498Szrj           // so we need to use an atomic load. However, _M_is_leaked
3169*38fd1498Szrj           // predicate does not change concurrently (i.e. the string is either
3170*38fd1498Szrj           // leaked or not), so a relaxed load is enough.
3171*38fd1498Szrj           return __atomic_load_n(&this->_M_refcount, __ATOMIC_RELAXED) < 0;
3172*38fd1498Szrj #else
3173*38fd1498Szrj           return this->_M_refcount < 0;
3174*38fd1498Szrj #endif
3175*38fd1498Szrj         }
3176*38fd1498Szrj 
3177*38fd1498Szrj         bool
3178*38fd1498Szrj 	_M_is_shared() const _GLIBCXX_NOEXCEPT
3179*38fd1498Szrj 	{
3180*38fd1498Szrj #if defined(__GTHREADS)
3181*38fd1498Szrj           // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose,
3182*38fd1498Szrj           // so we need to use an atomic load. Another thread can drop last
3183*38fd1498Szrj           // but one reference concurrently with this check, so we need this
3184*38fd1498Szrj           // load to be acquire to synchronize with release fetch_and_add in
3185*38fd1498Szrj           // _M_dispose.
3186*38fd1498Szrj           return __atomic_load_n(&this->_M_refcount, __ATOMIC_ACQUIRE) > 0;
3187*38fd1498Szrj #else
3188*38fd1498Szrj           return this->_M_refcount > 0;
3189*38fd1498Szrj #endif
3190*38fd1498Szrj         }
3191*38fd1498Szrj 
3192*38fd1498Szrj         void
3193*38fd1498Szrj 	_M_set_leaked() _GLIBCXX_NOEXCEPT
3194*38fd1498Szrj         { this->_M_refcount = -1; }
3195*38fd1498Szrj 
3196*38fd1498Szrj         void
3197*38fd1498Szrj 	_M_set_sharable() _GLIBCXX_NOEXCEPT
3198*38fd1498Szrj         { this->_M_refcount = 0; }
3199*38fd1498Szrj 
3200*38fd1498Szrj 	void
3201*38fd1498Szrj 	_M_set_length_and_sharable(size_type __n) _GLIBCXX_NOEXCEPT
3202*38fd1498Szrj 	{
3203*38fd1498Szrj #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3204*38fd1498Szrj 	  if (__builtin_expect(this != &_S_empty_rep(), false))
3205*38fd1498Szrj #endif
3206*38fd1498Szrj 	    {
3207*38fd1498Szrj 	      this->_M_set_sharable();  // One reference.
3208*38fd1498Szrj 	      this->_M_length = __n;
3209*38fd1498Szrj 	      traits_type::assign(this->_M_refdata()[__n], _S_terminal);
3210*38fd1498Szrj 	      // grrr. (per 21.3.4)
3211*38fd1498Szrj 	      // You cannot leave those LWG people alone for a second.
3212*38fd1498Szrj 	    }
3213*38fd1498Szrj 	}
3214*38fd1498Szrj 
3215*38fd1498Szrj 	_CharT*
3216*38fd1498Szrj 	_M_refdata() throw()
3217*38fd1498Szrj 	{ return reinterpret_cast<_CharT*>(this + 1); }
3218*38fd1498Szrj 
3219*38fd1498Szrj 	_CharT*
3220*38fd1498Szrj 	_M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2)
3221*38fd1498Szrj 	{
3222*38fd1498Szrj 	  return (!_M_is_leaked() && __alloc1 == __alloc2)
3223*38fd1498Szrj 	          ? _M_refcopy() : _M_clone(__alloc1);
3224*38fd1498Szrj 	}
3225*38fd1498Szrj 
3226*38fd1498Szrj 	// Create & Destroy
3227*38fd1498Szrj 	static _Rep*
3228*38fd1498Szrj 	_S_create(size_type, size_type, const _Alloc&);
3229*38fd1498Szrj 
3230*38fd1498Szrj 	void
3231*38fd1498Szrj 	_M_dispose(const _Alloc& __a) _GLIBCXX_NOEXCEPT
3232*38fd1498Szrj 	{
3233*38fd1498Szrj #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3234*38fd1498Szrj 	  if (__builtin_expect(this != &_S_empty_rep(), false))
3235*38fd1498Szrj #endif
3236*38fd1498Szrj 	    {
3237*38fd1498Szrj 	      // Be race-detector-friendly.  For more info see bits/c++config.
3238*38fd1498Szrj 	      _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount);
3239*38fd1498Szrj               // Decrement of _M_refcount is acq_rel, because:
3240*38fd1498Szrj               // - all but last decrements need to release to synchronize with
3241*38fd1498Szrj               //   the last decrement that will delete the object.
3242*38fd1498Szrj               // - the last decrement needs to acquire to synchronize with
3243*38fd1498Szrj               //   all the previous decrements.
3244*38fd1498Szrj               // - last but one decrement needs to release to synchronize with
3245*38fd1498Szrj               //   the acquire load in _M_is_shared that will conclude that
3246*38fd1498Szrj               //   the object is not shared anymore.
3247*38fd1498Szrj 	      if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
3248*38fd1498Szrj 							 -1) <= 0)
3249*38fd1498Szrj 		{
3250*38fd1498Szrj 		  _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount);
3251*38fd1498Szrj 		  _M_destroy(__a);
3252*38fd1498Szrj 		}
3253*38fd1498Szrj 	    }
3254*38fd1498Szrj 	}  // XXX MT
3255*38fd1498Szrj 
3256*38fd1498Szrj 	void
3257*38fd1498Szrj 	_M_destroy(const _Alloc&) throw();
3258*38fd1498Szrj 
3259*38fd1498Szrj 	_CharT*
3260*38fd1498Szrj 	_M_refcopy() throw()
3261*38fd1498Szrj 	{
3262*38fd1498Szrj #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3263*38fd1498Szrj 	  if (__builtin_expect(this != &_S_empty_rep(), false))
3264*38fd1498Szrj #endif
3265*38fd1498Szrj             __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
3266*38fd1498Szrj 	  return _M_refdata();
3267*38fd1498Szrj 	}  // XXX MT
3268*38fd1498Szrj 
3269*38fd1498Szrj 	_CharT*
3270*38fd1498Szrj 	_M_clone(const _Alloc&, size_type __res = 0);
3271*38fd1498Szrj       };
3272*38fd1498Szrj 
3273*38fd1498Szrj       // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
3274*38fd1498Szrj       struct _Alloc_hider : _Alloc
3275*38fd1498Szrj       {
3276*38fd1498Szrj 	_Alloc_hider(_CharT* __dat, const _Alloc& __a) _GLIBCXX_NOEXCEPT
3277*38fd1498Szrj 	: _Alloc(__a), _M_p(__dat) { }
3278*38fd1498Szrj 
3279*38fd1498Szrj 	_CharT* _M_p; // The actual data.
3280*38fd1498Szrj       };
3281*38fd1498Szrj 
3282*38fd1498Szrj     public:
3283*38fd1498Szrj       // Data Members (public):
3284*38fd1498Szrj       // NB: This is an unsigned type, and thus represents the maximum
3285*38fd1498Szrj       // size that the allocator can hold.
3286*38fd1498Szrj       ///  Value returned by various member functions when they fail.
3287*38fd1498Szrj       static const size_type	npos = static_cast<size_type>(-1);
3288*38fd1498Szrj 
3289*38fd1498Szrj     private:
3290*38fd1498Szrj       // Data Members (private):
3291*38fd1498Szrj       mutable _Alloc_hider	_M_dataplus;
3292*38fd1498Szrj 
3293*38fd1498Szrj       _CharT*
3294*38fd1498Szrj       _M_data() const _GLIBCXX_NOEXCEPT
3295*38fd1498Szrj       { return  _M_dataplus._M_p; }
3296*38fd1498Szrj 
3297*38fd1498Szrj       _CharT*
3298*38fd1498Szrj       _M_data(_CharT* __p) _GLIBCXX_NOEXCEPT
3299*38fd1498Szrj       { return (_M_dataplus._M_p = __p); }
3300*38fd1498Szrj 
3301*38fd1498Szrj       _Rep*
3302*38fd1498Szrj       _M_rep() const _GLIBCXX_NOEXCEPT
3303*38fd1498Szrj       { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }
3304*38fd1498Szrj 
3305*38fd1498Szrj       // For the internal use we have functions similar to `begin'/`end'
3306*38fd1498Szrj       // but they do not call _M_leak.
3307*38fd1498Szrj       iterator
3308*38fd1498Szrj       _M_ibegin() const _GLIBCXX_NOEXCEPT
3309*38fd1498Szrj       { return iterator(_M_data()); }
3310*38fd1498Szrj 
3311*38fd1498Szrj       iterator
3312*38fd1498Szrj       _M_iend() const _GLIBCXX_NOEXCEPT
3313*38fd1498Szrj       { return iterator(_M_data() + this->size()); }
3314*38fd1498Szrj 
3315*38fd1498Szrj       void
3316*38fd1498Szrj       _M_leak()    // for use in begin() & non-const op[]
3317*38fd1498Szrj       {
3318*38fd1498Szrj 	if (!_M_rep()->_M_is_leaked())
3319*38fd1498Szrj 	  _M_leak_hard();
3320*38fd1498Szrj       }
3321*38fd1498Szrj 
3322*38fd1498Szrj       size_type
3323*38fd1498Szrj       _M_check(size_type __pos, const char* __s) const
3324*38fd1498Szrj       {
3325*38fd1498Szrj 	if (__pos > this->size())
3326*38fd1498Szrj 	  __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
3327*38fd1498Szrj 				       "this->size() (which is %zu)"),
3328*38fd1498Szrj 				   __s, __pos, this->size());
3329*38fd1498Szrj 	return __pos;
3330*38fd1498Szrj       }
3331*38fd1498Szrj 
3332*38fd1498Szrj       void
3333*38fd1498Szrj       _M_check_length(size_type __n1, size_type __n2, const char* __s) const
3334*38fd1498Szrj       {
3335*38fd1498Szrj 	if (this->max_size() - (this->size() - __n1) < __n2)
3336*38fd1498Szrj 	  __throw_length_error(__N(__s));
3337*38fd1498Szrj       }
3338*38fd1498Szrj 
3339*38fd1498Szrj       // NB: _M_limit doesn't check for a bad __pos value.
3340*38fd1498Szrj       size_type
3341*38fd1498Szrj       _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT
3342*38fd1498Szrj       {
3343*38fd1498Szrj 	const bool __testoff =  __off < this->size() - __pos;
3344*38fd1498Szrj 	return __testoff ? __off : this->size() - __pos;
3345*38fd1498Szrj       }
3346*38fd1498Szrj 
3347*38fd1498Szrj       // True if _Rep and source do not overlap.
3348*38fd1498Szrj       bool
3349*38fd1498Szrj       _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT
3350*38fd1498Szrj       {
3351*38fd1498Szrj 	return (less<const _CharT*>()(__s, _M_data())
3352*38fd1498Szrj 		|| less<const _CharT*>()(_M_data() + this->size(), __s));
3353*38fd1498Szrj       }
3354*38fd1498Szrj 
3355*38fd1498Szrj       // When __n = 1 way faster than the general multichar
3356*38fd1498Szrj       // traits_type::copy/move/assign.
3357*38fd1498Szrj       static void
3358*38fd1498Szrj       _M_copy(_CharT* __d, const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
3359*38fd1498Szrj       {
3360*38fd1498Szrj 	if (__n == 1)
3361*38fd1498Szrj 	  traits_type::assign(*__d, *__s);
3362*38fd1498Szrj 	else
3363*38fd1498Szrj 	  traits_type::copy(__d, __s, __n);
3364*38fd1498Szrj       }
3365*38fd1498Szrj 
3366*38fd1498Szrj       static void
3367*38fd1498Szrj       _M_move(_CharT* __d, const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
3368*38fd1498Szrj       {
3369*38fd1498Szrj 	if (__n == 1)
3370*38fd1498Szrj 	  traits_type::assign(*__d, *__s);
3371*38fd1498Szrj 	else
3372*38fd1498Szrj 	  traits_type::move(__d, __s, __n);
3373*38fd1498Szrj       }
3374*38fd1498Szrj 
3375*38fd1498Szrj       static void
3376*38fd1498Szrj       _M_assign(_CharT* __d, size_type __n, _CharT __c) _GLIBCXX_NOEXCEPT
3377*38fd1498Szrj       {
3378*38fd1498Szrj 	if (__n == 1)
3379*38fd1498Szrj 	  traits_type::assign(*__d, __c);
3380*38fd1498Szrj 	else
3381*38fd1498Szrj 	  traits_type::assign(__d, __n, __c);
3382*38fd1498Szrj       }
3383*38fd1498Szrj 
3384*38fd1498Szrj       // _S_copy_chars is a separate template to permit specialization
3385*38fd1498Szrj       // to optimize for the common case of pointers as iterators.
3386*38fd1498Szrj       template<class _Iterator>
3387*38fd1498Szrj         static void
3388*38fd1498Szrj         _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
3389*38fd1498Szrj         {
3390*38fd1498Szrj 	  for (; __k1 != __k2; ++__k1, (void)++__p)
3391*38fd1498Szrj 	    traits_type::assign(*__p, *__k1); // These types are off.
3392*38fd1498Szrj 	}
3393*38fd1498Szrj 
3394*38fd1498Szrj       static void
3395*38fd1498Szrj       _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
3396*38fd1498Szrj       { _S_copy_chars(__p, __k1.base(), __k2.base()); }
3397*38fd1498Szrj 
3398*38fd1498Szrj       static void
3399*38fd1498Szrj       _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
3400*38fd1498Szrj       _GLIBCXX_NOEXCEPT
3401*38fd1498Szrj       { _S_copy_chars(__p, __k1.base(), __k2.base()); }
3402*38fd1498Szrj 
3403*38fd1498Szrj       static void
3404*38fd1498Szrj       _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
3405*38fd1498Szrj       { _M_copy(__p, __k1, __k2 - __k1); }
3406*38fd1498Szrj 
3407*38fd1498Szrj       static void
3408*38fd1498Szrj       _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
3409*38fd1498Szrj       _GLIBCXX_NOEXCEPT
3410*38fd1498Szrj       { _M_copy(__p, __k1, __k2 - __k1); }
3411*38fd1498Szrj 
3412*38fd1498Szrj       static int
3413*38fd1498Szrj       _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
3414*38fd1498Szrj       {
3415*38fd1498Szrj 	const difference_type __d = difference_type(__n1 - __n2);
3416*38fd1498Szrj 
3417*38fd1498Szrj 	if (__d > __gnu_cxx::__numeric_traits<int>::__max)
3418*38fd1498Szrj 	  return __gnu_cxx::__numeric_traits<int>::__max;
3419*38fd1498Szrj 	else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
3420*38fd1498Szrj 	  return __gnu_cxx::__numeric_traits<int>::__min;
3421*38fd1498Szrj 	else
3422*38fd1498Szrj 	  return int(__d);
3423*38fd1498Szrj       }
3424*38fd1498Szrj 
3425*38fd1498Szrj       void
3426*38fd1498Szrj       _M_mutate(size_type __pos, size_type __len1, size_type __len2);
3427*38fd1498Szrj 
3428*38fd1498Szrj       void
3429*38fd1498Szrj       _M_leak_hard();
3430*38fd1498Szrj 
3431*38fd1498Szrj       static _Rep&
3432*38fd1498Szrj       _S_empty_rep() _GLIBCXX_NOEXCEPT
3433*38fd1498Szrj       { return _Rep::_S_empty_rep(); }
3434*38fd1498Szrj 
3435*38fd1498Szrj #if __cplusplus > 201402L
3436*38fd1498Szrj       // A helper type for avoiding boiler-plate.
3437*38fd1498Szrj       typedef basic_string_view<_CharT, _Traits> __sv_type;
3438*38fd1498Szrj 
3439*38fd1498Szrj       template<typename _Tp, typename _Res>
3440*38fd1498Szrj 	using _If_sv = enable_if_t<
3441*38fd1498Szrj 	  __and_<is_convertible<const _Tp&, __sv_type>,
3442*38fd1498Szrj 		 __not_<is_convertible<const _Tp*, const basic_string*>>,
3443*38fd1498Szrj 		 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
3444*38fd1498Szrj 	  _Res>;
3445*38fd1498Szrj 
3446*38fd1498Szrj       // Allows an implicit conversion to __sv_type.
3447*38fd1498Szrj       static __sv_type
3448*38fd1498Szrj       _S_to_string_view(__sv_type __svt) noexcept
3449*38fd1498Szrj       { return __svt; }
3450*38fd1498Szrj 
3451*38fd1498Szrj       // Wraps a string_view by explicit conversion and thus
3452*38fd1498Szrj       // allows to add an internal constructor that does not
3453*38fd1498Szrj       // participate in overload resolution when a string_view
3454*38fd1498Szrj       // is provided.
3455*38fd1498Szrj       struct __sv_wrapper
3456*38fd1498Szrj       {
3457*38fd1498Szrj 	explicit __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
3458*38fd1498Szrj 	__sv_type _M_sv;
3459*38fd1498Szrj       };
3460*38fd1498Szrj #endif
3461*38fd1498Szrj 
3462*38fd1498Szrj     public:
3463*38fd1498Szrj       // Construct/copy/destroy:
3464*38fd1498Szrj       // NB: We overload ctors in some cases instead of using default
3465*38fd1498Szrj       // arguments, per 17.4.4.4 para. 2 item 2.
3466*38fd1498Szrj 
3467*38fd1498Szrj       /**
3468*38fd1498Szrj        *  @brief  Default constructor creates an empty string.
3469*38fd1498Szrj        */
3470*38fd1498Szrj       basic_string()
3471*38fd1498Szrj #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3472*38fd1498Szrj       : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
3473*38fd1498Szrj #else
3474*38fd1498Szrj       : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()){ }
3475*38fd1498Szrj #endif
3476*38fd1498Szrj 
3477*38fd1498Szrj       /**
3478*38fd1498Szrj        *  @brief  Construct an empty string using allocator @a a.
3479*38fd1498Szrj        */
3480*38fd1498Szrj       explicit
3481*38fd1498Szrj       basic_string(const _Alloc& __a);
3482*38fd1498Szrj 
3483*38fd1498Szrj       // NB: per LWG issue 42, semantics different from IS:
3484*38fd1498Szrj       /**
3485*38fd1498Szrj        *  @brief  Construct string with copy of value of @a str.
3486*38fd1498Szrj        *  @param  __str  Source string.
3487*38fd1498Szrj        */
3488*38fd1498Szrj       basic_string(const basic_string& __str);
3489*38fd1498Szrj 
3490*38fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
3491*38fd1498Szrj       // 2583. no way to supply an allocator for basic_string(str, pos)
3492*38fd1498Szrj       /**
3493*38fd1498Szrj        *  @brief  Construct string as copy of a substring.
3494*38fd1498Szrj        *  @param  __str  Source string.
3495*38fd1498Szrj        *  @param  __pos  Index of first character to copy from.
3496*38fd1498Szrj        *  @param  __a  Allocator to use.
3497*38fd1498Szrj        */
3498*38fd1498Szrj       basic_string(const basic_string& __str, size_type __pos,
3499*38fd1498Szrj 		   const _Alloc& __a = _Alloc());
3500*38fd1498Szrj 
3501*38fd1498Szrj       /**
3502*38fd1498Szrj        *  @brief  Construct string as copy of a substring.
3503*38fd1498Szrj        *  @param  __str  Source string.
3504*38fd1498Szrj        *  @param  __pos  Index of first character to copy from.
3505*38fd1498Szrj        *  @param  __n  Number of characters to copy.
3506*38fd1498Szrj        */
3507*38fd1498Szrj       basic_string(const basic_string& __str, size_type __pos,
3508*38fd1498Szrj 		   size_type __n);
3509*38fd1498Szrj       /**
3510*38fd1498Szrj        *  @brief  Construct string as copy of a substring.
3511*38fd1498Szrj        *  @param  __str  Source string.
3512*38fd1498Szrj        *  @param  __pos  Index of first character to copy from.
3513*38fd1498Szrj        *  @param  __n  Number of characters to copy.
3514*38fd1498Szrj        *  @param  __a  Allocator to use.
3515*38fd1498Szrj        */
3516*38fd1498Szrj       basic_string(const basic_string& __str, size_type __pos,
3517*38fd1498Szrj 		   size_type __n, const _Alloc& __a);
3518*38fd1498Szrj 
3519*38fd1498Szrj       /**
3520*38fd1498Szrj        *  @brief  Construct string initialized by a character %array.
3521*38fd1498Szrj        *  @param  __s  Source character %array.
3522*38fd1498Szrj        *  @param  __n  Number of characters to copy.
3523*38fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
3524*38fd1498Szrj        *
3525*38fd1498Szrj        *  NB: @a __s must have at least @a __n characters, &apos;\\0&apos;
3526*38fd1498Szrj        *  has no special meaning.
3527*38fd1498Szrj        */
3528*38fd1498Szrj       basic_string(const _CharT* __s, size_type __n,
3529*38fd1498Szrj 		   const _Alloc& __a = _Alloc());
3530*38fd1498Szrj       /**
3531*38fd1498Szrj        *  @brief  Construct string as copy of a C string.
3532*38fd1498Szrj        *  @param  __s  Source C string.
3533*38fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
3534*38fd1498Szrj        */
3535*38fd1498Szrj       basic_string(const _CharT* __s, const _Alloc& __a = _Alloc());
3536*38fd1498Szrj       /**
3537*38fd1498Szrj        *  @brief  Construct string as multiple characters.
3538*38fd1498Szrj        *  @param  __n  Number of characters.
3539*38fd1498Szrj        *  @param  __c  Character to use.
3540*38fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
3541*38fd1498Szrj        */
3542*38fd1498Szrj       basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
3543*38fd1498Szrj 
3544*38fd1498Szrj #if __cplusplus >= 201103L
3545*38fd1498Szrj       /**
3546*38fd1498Szrj        *  @brief  Move construct string.
3547*38fd1498Szrj        *  @param  __str  Source string.
3548*38fd1498Szrj        *
3549*38fd1498Szrj        *  The newly-created string contains the exact contents of @a __str.
3550*38fd1498Szrj        *  @a __str is a valid, but unspecified string.
3551*38fd1498Szrj        **/
3552*38fd1498Szrj       basic_string(basic_string&& __str)
3553*38fd1498Szrj #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3554*38fd1498Szrj       noexcept // FIXME C++11: should always be noexcept.
3555*38fd1498Szrj #endif
3556*38fd1498Szrj       : _M_dataplus(__str._M_dataplus)
3557*38fd1498Szrj       {
3558*38fd1498Szrj #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3559*38fd1498Szrj 	__str._M_data(_S_empty_rep()._M_refdata());
3560*38fd1498Szrj #else
3561*38fd1498Szrj 	__str._M_data(_S_construct(size_type(), _CharT(), get_allocator()));
3562*38fd1498Szrj #endif
3563*38fd1498Szrj       }
3564*38fd1498Szrj 
3565*38fd1498Szrj       /**
3566*38fd1498Szrj        *  @brief  Construct string from an initializer %list.
3567*38fd1498Szrj        *  @param  __l  std::initializer_list of characters.
3568*38fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
3569*38fd1498Szrj        */
3570*38fd1498Szrj       basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc());
3571*38fd1498Szrj #endif // C++11
3572*38fd1498Szrj 
3573*38fd1498Szrj       /**
3574*38fd1498Szrj        *  @brief  Construct string as copy of a range.
3575*38fd1498Szrj        *  @param  __beg  Start of range.
3576*38fd1498Szrj        *  @param  __end  End of range.
3577*38fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
3578*38fd1498Szrj        */
3579*38fd1498Szrj       template<class _InputIterator>
3580*38fd1498Szrj         basic_string(_InputIterator __beg, _InputIterator __end,
3581*38fd1498Szrj 		     const _Alloc& __a = _Alloc());
3582*38fd1498Szrj 
3583*38fd1498Szrj #if __cplusplus > 201402L
3584*38fd1498Szrj       /**
3585*38fd1498Szrj        *  @brief  Construct string from a substring of a string_view.
3586*38fd1498Szrj        *  @param  __t   Source object convertible to string view.
3587*38fd1498Szrj        *  @param  __pos The index of the first character to copy from __t.
3588*38fd1498Szrj        *  @param  __n   The number of characters to copy from __t.
3589*38fd1498Szrj        *  @param  __a   Allocator to use.
3590*38fd1498Szrj        */
3591*38fd1498Szrj       template<typename _Tp, typename = _If_sv<_Tp, void>>
3592*38fd1498Szrj 	basic_string(const _Tp& __t, size_type __pos, size_type __n,
3593*38fd1498Szrj 		     const _Alloc& __a = _Alloc())
3594*38fd1498Szrj 	: basic_string(_S_to_string_view(__t).substr(__pos, __n), __a) { }
3595*38fd1498Szrj 
3596*38fd1498Szrj       /**
3597*38fd1498Szrj        *  @brief  Construct string from a string_view.
3598*38fd1498Szrj        *  @param  __t  Source object convertible to string view.
3599*38fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
3600*38fd1498Szrj        */
3601*38fd1498Szrj       template<typename _Tp, typename = _If_sv<_Tp, void>>
3602*38fd1498Szrj 	explicit
3603*38fd1498Szrj 	basic_string(const _Tp& __t, const _Alloc& __a = _Alloc())
3604*38fd1498Szrj 	: basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
3605*38fd1498Szrj 
3606*38fd1498Szrj       /**
3607*38fd1498Szrj        *  @brief  Only internally used: Construct string from a string view
3608*38fd1498Szrj        *          wrapper.
3609*38fd1498Szrj        *  @param  __svw  string view wrapper.
3610*38fd1498Szrj        *  @param  __a  Allocator to use.
3611*38fd1498Szrj        */
3612*38fd1498Szrj       explicit
3613*38fd1498Szrj       basic_string(__sv_wrapper __svw, const _Alloc& __a)
3614*38fd1498Szrj       : basic_string(__svw._M_sv.data(), __svw._M_sv.size(), __a) { }
3615*38fd1498Szrj #endif // C++17
3616*38fd1498Szrj 
3617*38fd1498Szrj       /**
3618*38fd1498Szrj        *  @brief  Destroy the string instance.
3619*38fd1498Szrj        */
3620*38fd1498Szrj       ~basic_string() _GLIBCXX_NOEXCEPT
3621*38fd1498Szrj       { _M_rep()->_M_dispose(this->get_allocator()); }
3622*38fd1498Szrj 
3623*38fd1498Szrj       /**
3624*38fd1498Szrj        *  @brief  Assign the value of @a str to this string.
3625*38fd1498Szrj        *  @param  __str  Source string.
3626*38fd1498Szrj        */
3627*38fd1498Szrj       basic_string&
3628*38fd1498Szrj       operator=(const basic_string& __str)
3629*38fd1498Szrj       { return this->assign(__str); }
3630*38fd1498Szrj 
3631*38fd1498Szrj       /**
3632*38fd1498Szrj        *  @brief  Copy contents of @a s into this string.
3633*38fd1498Szrj        *  @param  __s  Source null-terminated string.
3634*38fd1498Szrj        */
3635*38fd1498Szrj       basic_string&
3636*38fd1498Szrj       operator=(const _CharT* __s)
3637*38fd1498Szrj       { return this->assign(__s); }
3638*38fd1498Szrj 
3639*38fd1498Szrj       /**
3640*38fd1498Szrj        *  @brief  Set value to string of length 1.
3641*38fd1498Szrj        *  @param  __c  Source character.
3642*38fd1498Szrj        *
3643*38fd1498Szrj        *  Assigning to a character makes this string length 1 and
3644*38fd1498Szrj        *  (*this)[0] == @a c.
3645*38fd1498Szrj        */
3646*38fd1498Szrj       basic_string&
3647*38fd1498Szrj       operator=(_CharT __c)
3648*38fd1498Szrj       {
3649*38fd1498Szrj 	this->assign(1, __c);
3650*38fd1498Szrj 	return *this;
3651*38fd1498Szrj       }
3652*38fd1498Szrj 
3653*38fd1498Szrj #if __cplusplus >= 201103L
3654*38fd1498Szrj       /**
3655*38fd1498Szrj        *  @brief  Move assign the value of @a str to this string.
3656*38fd1498Szrj        *  @param  __str  Source string.
3657*38fd1498Szrj        *
3658*38fd1498Szrj        *  The contents of @a str are moved into this string (without copying).
3659*38fd1498Szrj        *  @a str is a valid, but unspecified string.
3660*38fd1498Szrj        **/
3661*38fd1498Szrj       // PR 58265, this should be noexcept.
3662*38fd1498Szrj       basic_string&
3663*38fd1498Szrj       operator=(basic_string&& __str)
3664*38fd1498Szrj       {
3665*38fd1498Szrj 	// NB: DR 1204.
3666*38fd1498Szrj 	this->swap(__str);
3667*38fd1498Szrj 	return *this;
3668*38fd1498Szrj       }
3669*38fd1498Szrj 
3670*38fd1498Szrj       /**
3671*38fd1498Szrj        *  @brief  Set value to string constructed from initializer %list.
3672*38fd1498Szrj        *  @param  __l  std::initializer_list.
3673*38fd1498Szrj        */
3674*38fd1498Szrj       basic_string&
3675*38fd1498Szrj       operator=(initializer_list<_CharT> __l)
3676*38fd1498Szrj       {
3677*38fd1498Szrj 	this->assign(__l.begin(), __l.size());
3678*38fd1498Szrj 	return *this;
3679*38fd1498Szrj       }
3680*38fd1498Szrj #endif // C++11
3681*38fd1498Szrj 
3682*38fd1498Szrj #if __cplusplus > 201402L
3683*38fd1498Szrj       /**
3684*38fd1498Szrj        *  @brief  Set value to string constructed from a string_view.
3685*38fd1498Szrj        *  @param  __svt An object convertible to  string_view.
3686*38fd1498Szrj        */
3687*38fd1498Szrj       template<typename _Tp>
3688*38fd1498Szrj 	_If_sv<_Tp, basic_string&>
3689*38fd1498Szrj 	operator=(const _Tp& __svt)
3690*38fd1498Szrj 	{ return this->assign(__svt); }
3691*38fd1498Szrj 
3692*38fd1498Szrj       /**
3693*38fd1498Szrj        *  @brief  Convert to a string_view.
3694*38fd1498Szrj        *  @return A string_view.
3695*38fd1498Szrj        */
3696*38fd1498Szrj       operator __sv_type() const noexcept
3697*38fd1498Szrj       { return __sv_type(data(), size()); }
3698*38fd1498Szrj #endif // C++17
3699*38fd1498Szrj 
3700*38fd1498Szrj       // Iterators:
3701*38fd1498Szrj       /**
3702*38fd1498Szrj        *  Returns a read/write iterator that points to the first character in
3703*38fd1498Szrj        *  the %string.  Unshares the string.
3704*38fd1498Szrj        */
3705*38fd1498Szrj       iterator
3706*38fd1498Szrj       begin() // FIXME C++11: should be noexcept.
3707*38fd1498Szrj       {
3708*38fd1498Szrj 	_M_leak();
3709*38fd1498Szrj 	return iterator(_M_data());
3710*38fd1498Szrj       }
3711*38fd1498Szrj 
3712*38fd1498Szrj       /**
3713*38fd1498Szrj        *  Returns a read-only (constant) iterator that points to the first
3714*38fd1498Szrj        *  character in the %string.
3715*38fd1498Szrj        */
3716*38fd1498Szrj       const_iterator
3717*38fd1498Szrj       begin() const _GLIBCXX_NOEXCEPT
3718*38fd1498Szrj       { return const_iterator(_M_data()); }
3719*38fd1498Szrj 
3720*38fd1498Szrj       /**
3721*38fd1498Szrj        *  Returns a read/write iterator that points one past the last
3722*38fd1498Szrj        *  character in the %string.  Unshares the string.
3723*38fd1498Szrj        */
3724*38fd1498Szrj       iterator
3725*38fd1498Szrj       end() // FIXME C++11: should be noexcept.
3726*38fd1498Szrj       {
3727*38fd1498Szrj 	_M_leak();
3728*38fd1498Szrj 	return iterator(_M_data() + this->size());
3729*38fd1498Szrj       }
3730*38fd1498Szrj 
3731*38fd1498Szrj       /**
3732*38fd1498Szrj        *  Returns a read-only (constant) iterator that points one past the
3733*38fd1498Szrj        *  last character in the %string.
3734*38fd1498Szrj        */
3735*38fd1498Szrj       const_iterator
3736*38fd1498Szrj       end() const _GLIBCXX_NOEXCEPT
3737*38fd1498Szrj       { return const_iterator(_M_data() + this->size()); }
3738*38fd1498Szrj 
3739*38fd1498Szrj       /**
3740*38fd1498Szrj        *  Returns a read/write reverse iterator that points to the last
3741*38fd1498Szrj        *  character in the %string.  Iteration is done in reverse element
3742*38fd1498Szrj        *  order.  Unshares the string.
3743*38fd1498Szrj        */
3744*38fd1498Szrj       reverse_iterator
3745*38fd1498Szrj       rbegin() // FIXME C++11: should be noexcept.
3746*38fd1498Szrj       { return reverse_iterator(this->end()); }
3747*38fd1498Szrj 
3748*38fd1498Szrj       /**
3749*38fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points
3750*38fd1498Szrj        *  to the last character in the %string.  Iteration is done in
3751*38fd1498Szrj        *  reverse element order.
3752*38fd1498Szrj        */
3753*38fd1498Szrj       const_reverse_iterator
3754*38fd1498Szrj       rbegin() const _GLIBCXX_NOEXCEPT
3755*38fd1498Szrj       { return const_reverse_iterator(this->end()); }
3756*38fd1498Szrj 
3757*38fd1498Szrj       /**
3758*38fd1498Szrj        *  Returns a read/write reverse iterator that points to one before the
3759*38fd1498Szrj        *  first character in the %string.  Iteration is done in reverse
3760*38fd1498Szrj        *  element order.  Unshares the string.
3761*38fd1498Szrj        */
3762*38fd1498Szrj       reverse_iterator
3763*38fd1498Szrj       rend() // FIXME C++11: should be noexcept.
3764*38fd1498Szrj       { return reverse_iterator(this->begin()); }
3765*38fd1498Szrj 
3766*38fd1498Szrj       /**
3767*38fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points
3768*38fd1498Szrj        *  to one before the first character in the %string.  Iteration
3769*38fd1498Szrj        *  is done in reverse element order.
3770*38fd1498Szrj        */
3771*38fd1498Szrj       const_reverse_iterator
3772*38fd1498Szrj       rend() const _GLIBCXX_NOEXCEPT
3773*38fd1498Szrj       { return const_reverse_iterator(this->begin()); }
3774*38fd1498Szrj 
3775*38fd1498Szrj #if __cplusplus >= 201103L
3776*38fd1498Szrj       /**
3777*38fd1498Szrj        *  Returns a read-only (constant) iterator that points to the first
3778*38fd1498Szrj        *  character in the %string.
3779*38fd1498Szrj        */
3780*38fd1498Szrj       const_iterator
3781*38fd1498Szrj       cbegin() const noexcept
3782*38fd1498Szrj       { return const_iterator(this->_M_data()); }
3783*38fd1498Szrj 
3784*38fd1498Szrj       /**
3785*38fd1498Szrj        *  Returns a read-only (constant) iterator that points one past the
3786*38fd1498Szrj        *  last character in the %string.
3787*38fd1498Szrj        */
3788*38fd1498Szrj       const_iterator
3789*38fd1498Szrj       cend() const noexcept
3790*38fd1498Szrj       { return const_iterator(this->_M_data() + this->size()); }
3791*38fd1498Szrj 
3792*38fd1498Szrj       /**
3793*38fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points
3794*38fd1498Szrj        *  to the last character in the %string.  Iteration is done in
3795*38fd1498Szrj        *  reverse element order.
3796*38fd1498Szrj        */
3797*38fd1498Szrj       const_reverse_iterator
3798*38fd1498Szrj       crbegin() const noexcept
3799*38fd1498Szrj       { return const_reverse_iterator(this->end()); }
3800*38fd1498Szrj 
3801*38fd1498Szrj       /**
3802*38fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points
3803*38fd1498Szrj        *  to one before the first character in the %string.  Iteration
3804*38fd1498Szrj        *  is done in reverse element order.
3805*38fd1498Szrj        */
3806*38fd1498Szrj       const_reverse_iterator
3807*38fd1498Szrj       crend() const noexcept
3808*38fd1498Szrj       { return const_reverse_iterator(this->begin()); }
3809*38fd1498Szrj #endif
3810*38fd1498Szrj 
3811*38fd1498Szrj     public:
3812*38fd1498Szrj       // Capacity:
3813*38fd1498Szrj       ///  Returns the number of characters in the string, not including any
3814*38fd1498Szrj       ///  null-termination.
3815*38fd1498Szrj       size_type
3816*38fd1498Szrj       size() const _GLIBCXX_NOEXCEPT
3817*38fd1498Szrj       { return _M_rep()->_M_length; }
3818*38fd1498Szrj 
3819*38fd1498Szrj       ///  Returns the number of characters in the string, not including any
3820*38fd1498Szrj       ///  null-termination.
3821*38fd1498Szrj       size_type
3822*38fd1498Szrj       length() const _GLIBCXX_NOEXCEPT
3823*38fd1498Szrj       { return _M_rep()->_M_length; }
3824*38fd1498Szrj 
3825*38fd1498Szrj       ///  Returns the size() of the largest possible %string.
3826*38fd1498Szrj       size_type
3827*38fd1498Szrj       max_size() const _GLIBCXX_NOEXCEPT
3828*38fd1498Szrj       { return _Rep::_S_max_size; }
3829*38fd1498Szrj 
3830*38fd1498Szrj       /**
3831*38fd1498Szrj        *  @brief  Resizes the %string to the specified number of characters.
3832*38fd1498Szrj        *  @param  __n  Number of characters the %string should contain.
3833*38fd1498Szrj        *  @param  __c  Character to fill any new elements.
3834*38fd1498Szrj        *
3835*38fd1498Szrj        *  This function will %resize the %string to the specified
3836*38fd1498Szrj        *  number of characters.  If the number is smaller than the
3837*38fd1498Szrj        *  %string's current size the %string is truncated, otherwise
3838*38fd1498Szrj        *  the %string is extended and new elements are %set to @a __c.
3839*38fd1498Szrj        */
3840*38fd1498Szrj       void
3841*38fd1498Szrj       resize(size_type __n, _CharT __c);
3842*38fd1498Szrj 
3843*38fd1498Szrj       /**
3844*38fd1498Szrj        *  @brief  Resizes the %string to the specified number of characters.
3845*38fd1498Szrj        *  @param  __n  Number of characters the %string should contain.
3846*38fd1498Szrj        *
3847*38fd1498Szrj        *  This function will resize the %string to the specified length.  If
3848*38fd1498Szrj        *  the new size is smaller than the %string's current size the %string
3849*38fd1498Szrj        *  is truncated, otherwise the %string is extended and new characters
3850*38fd1498Szrj        *  are default-constructed.  For basic types such as char, this means
3851*38fd1498Szrj        *  setting them to 0.
3852*38fd1498Szrj        */
3853*38fd1498Szrj       void
3854*38fd1498Szrj       resize(size_type __n)
3855*38fd1498Szrj       { this->resize(__n, _CharT()); }
3856*38fd1498Szrj 
3857*38fd1498Szrj #if __cplusplus >= 201103L
3858*38fd1498Szrj       ///  A non-binding request to reduce capacity() to size().
3859*38fd1498Szrj       void
3860*38fd1498Szrj       shrink_to_fit() _GLIBCXX_NOEXCEPT
3861*38fd1498Szrj       {
3862*38fd1498Szrj #if __cpp_exceptions
3863*38fd1498Szrj 	if (capacity() > size())
3864*38fd1498Szrj 	  {
3865*38fd1498Szrj 	    try
3866*38fd1498Szrj 	      { reserve(0); }
3867*38fd1498Szrj 	    catch(...)
3868*38fd1498Szrj 	      { }
3869*38fd1498Szrj 	  }
3870*38fd1498Szrj #endif
3871*38fd1498Szrj       }
3872*38fd1498Szrj #endif
3873*38fd1498Szrj 
3874*38fd1498Szrj       /**
3875*38fd1498Szrj        *  Returns the total number of characters that the %string can hold
3876*38fd1498Szrj        *  before needing to allocate more memory.
3877*38fd1498Szrj        */
3878*38fd1498Szrj       size_type
3879*38fd1498Szrj       capacity() const _GLIBCXX_NOEXCEPT
3880*38fd1498Szrj       { return _M_rep()->_M_capacity; }
3881*38fd1498Szrj 
3882*38fd1498Szrj       /**
3883*38fd1498Szrj        *  @brief  Attempt to preallocate enough memory for specified number of
3884*38fd1498Szrj        *          characters.
3885*38fd1498Szrj        *  @param  __res_arg  Number of characters required.
3886*38fd1498Szrj        *  @throw  std::length_error  If @a __res_arg exceeds @c max_size().
3887*38fd1498Szrj        *
3888*38fd1498Szrj        *  This function attempts to reserve enough memory for the
3889*38fd1498Szrj        *  %string to hold the specified number of characters.  If the
3890*38fd1498Szrj        *  number requested is more than max_size(), length_error is
3891*38fd1498Szrj        *  thrown.
3892*38fd1498Szrj        *
3893*38fd1498Szrj        *  The advantage of this function is that if optimal code is a
3894*38fd1498Szrj        *  necessity and the user can determine the string length that will be
3895*38fd1498Szrj        *  required, the user can reserve the memory in %advance, and thus
3896*38fd1498Szrj        *  prevent a possible reallocation of memory and copying of %string
3897*38fd1498Szrj        *  data.
3898*38fd1498Szrj        */
3899*38fd1498Szrj       void
3900*38fd1498Szrj       reserve(size_type __res_arg = 0);
3901*38fd1498Szrj 
3902*38fd1498Szrj       /**
3903*38fd1498Szrj        *  Erases the string, making it empty.
3904*38fd1498Szrj        */
3905*38fd1498Szrj #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3906*38fd1498Szrj       void
3907*38fd1498Szrj       clear() _GLIBCXX_NOEXCEPT
3908*38fd1498Szrj       {
3909*38fd1498Szrj 	if (_M_rep()->_M_is_shared())
3910*38fd1498Szrj 	  {
3911*38fd1498Szrj 	    _M_rep()->_M_dispose(this->get_allocator());
3912*38fd1498Szrj 	    _M_data(_S_empty_rep()._M_refdata());
3913*38fd1498Szrj 	  }
3914*38fd1498Szrj 	else
3915*38fd1498Szrj 	  _M_rep()->_M_set_length_and_sharable(0);
3916*38fd1498Szrj       }
3917*38fd1498Szrj #else
3918*38fd1498Szrj       // PR 56166: this should not throw.
3919*38fd1498Szrj       void
3920*38fd1498Szrj       clear()
3921*38fd1498Szrj       { _M_mutate(0, this->size(), 0); }
3922*38fd1498Szrj #endif
3923*38fd1498Szrj 
3924*38fd1498Szrj       /**
3925*38fd1498Szrj        *  Returns true if the %string is empty.  Equivalent to
3926*38fd1498Szrj        *  <code>*this == ""</code>.
3927*38fd1498Szrj        */
3928*38fd1498Szrj       bool
3929*38fd1498Szrj       empty() const _GLIBCXX_NOEXCEPT
3930*38fd1498Szrj       { return this->size() == 0; }
3931*38fd1498Szrj 
3932*38fd1498Szrj       // Element access:
3933*38fd1498Szrj       /**
3934*38fd1498Szrj        *  @brief  Subscript access to the data contained in the %string.
3935*38fd1498Szrj        *  @param  __pos  The index of the character to access.
3936*38fd1498Szrj        *  @return  Read-only (constant) reference to the character.
3937*38fd1498Szrj        *
3938*38fd1498Szrj        *  This operator allows for easy, array-style, data access.
3939*38fd1498Szrj        *  Note that data access with this operator is unchecked and
3940*38fd1498Szrj        *  out_of_range lookups are not defined. (For checked lookups
3941*38fd1498Szrj        *  see at().)
3942*38fd1498Szrj        */
3943*38fd1498Szrj       const_reference
3944*38fd1498Szrj       operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT
3945*38fd1498Szrj       {
3946*38fd1498Szrj 	__glibcxx_assert(__pos <= size());
3947*38fd1498Szrj 	return _M_data()[__pos];
3948*38fd1498Szrj       }
3949*38fd1498Szrj 
3950*38fd1498Szrj       /**
3951*38fd1498Szrj        *  @brief  Subscript access to the data contained in the %string.
3952*38fd1498Szrj        *  @param  __pos  The index of the character to access.
3953*38fd1498Szrj        *  @return  Read/write reference to the character.
3954*38fd1498Szrj        *
3955*38fd1498Szrj        *  This operator allows for easy, array-style, data access.
3956*38fd1498Szrj        *  Note that data access with this operator is unchecked and
3957*38fd1498Szrj        *  out_of_range lookups are not defined. (For checked lookups
3958*38fd1498Szrj        *  see at().)  Unshares the string.
3959*38fd1498Szrj        */
3960*38fd1498Szrj       reference
3961*38fd1498Szrj       operator[](size_type __pos)
3962*38fd1498Szrj       {
3963*38fd1498Szrj         // Allow pos == size() both in C++98 mode, as v3 extension,
3964*38fd1498Szrj 	// and in C++11 mode.
3965*38fd1498Szrj 	__glibcxx_assert(__pos <= size());
3966*38fd1498Szrj         // In pedantic mode be strict in C++98 mode.
3967*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos < size());
3968*38fd1498Szrj 	_M_leak();
3969*38fd1498Szrj 	return _M_data()[__pos];
3970*38fd1498Szrj       }
3971*38fd1498Szrj 
3972*38fd1498Szrj       /**
3973*38fd1498Szrj        *  @brief  Provides access to the data contained in the %string.
3974*38fd1498Szrj        *  @param __n The index of the character to access.
3975*38fd1498Szrj        *  @return  Read-only (const) reference to the character.
3976*38fd1498Szrj        *  @throw  std::out_of_range  If @a n is an invalid index.
3977*38fd1498Szrj        *
3978*38fd1498Szrj        *  This function provides for safer data access.  The parameter is
3979*38fd1498Szrj        *  first checked that it is in the range of the string.  The function
3980*38fd1498Szrj        *  throws out_of_range if the check fails.
3981*38fd1498Szrj        */
3982*38fd1498Szrj       const_reference
3983*38fd1498Szrj       at(size_type __n) const
3984*38fd1498Szrj       {
3985*38fd1498Szrj 	if (__n >= this->size())
3986*38fd1498Szrj 	  __throw_out_of_range_fmt(__N("basic_string::at: __n "
3987*38fd1498Szrj 				       "(which is %zu) >= this->size() "
3988*38fd1498Szrj 				       "(which is %zu)"),
3989*38fd1498Szrj 				   __n, this->size());
3990*38fd1498Szrj 	return _M_data()[__n];
3991*38fd1498Szrj       }
3992*38fd1498Szrj 
3993*38fd1498Szrj       /**
3994*38fd1498Szrj        *  @brief  Provides access to the data contained in the %string.
3995*38fd1498Szrj        *  @param __n The index of the character to access.
3996*38fd1498Szrj        *  @return  Read/write reference to the character.
3997*38fd1498Szrj        *  @throw  std::out_of_range  If @a n is an invalid index.
3998*38fd1498Szrj        *
3999*38fd1498Szrj        *  This function provides for safer data access.  The parameter is
4000*38fd1498Szrj        *  first checked that it is in the range of the string.  The function
4001*38fd1498Szrj        *  throws out_of_range if the check fails.  Success results in
4002*38fd1498Szrj        *  unsharing the string.
4003*38fd1498Szrj        */
4004*38fd1498Szrj       reference
4005*38fd1498Szrj       at(size_type __n)
4006*38fd1498Szrj       {
4007*38fd1498Szrj 	if (__n >= size())
4008*38fd1498Szrj 	  __throw_out_of_range_fmt(__N("basic_string::at: __n "
4009*38fd1498Szrj 				       "(which is %zu) >= this->size() "
4010*38fd1498Szrj 				       "(which is %zu)"),
4011*38fd1498Szrj 				   __n, this->size());
4012*38fd1498Szrj 	_M_leak();
4013*38fd1498Szrj 	return _M_data()[__n];
4014*38fd1498Szrj       }
4015*38fd1498Szrj 
4016*38fd1498Szrj #if __cplusplus >= 201103L
4017*38fd1498Szrj       /**
4018*38fd1498Szrj        *  Returns a read/write reference to the data at the first
4019*38fd1498Szrj        *  element of the %string.
4020*38fd1498Szrj        */
4021*38fd1498Szrj       reference
4022*38fd1498Szrj       front()
4023*38fd1498Szrj       {
4024*38fd1498Szrj 	__glibcxx_assert(!empty());
4025*38fd1498Szrj 	return operator[](0);
4026*38fd1498Szrj       }
4027*38fd1498Szrj 
4028*38fd1498Szrj       /**
4029*38fd1498Szrj        *  Returns a read-only (constant) reference to the data at the first
4030*38fd1498Szrj        *  element of the %string.
4031*38fd1498Szrj        */
4032*38fd1498Szrj       const_reference
4033*38fd1498Szrj       front() const noexcept
4034*38fd1498Szrj       {
4035*38fd1498Szrj 	__glibcxx_assert(!empty());
4036*38fd1498Szrj 	return operator[](0);
4037*38fd1498Szrj       }
4038*38fd1498Szrj 
4039*38fd1498Szrj       /**
4040*38fd1498Szrj        *  Returns a read/write reference to the data at the last
4041*38fd1498Szrj        *  element of the %string.
4042*38fd1498Szrj        */
4043*38fd1498Szrj       reference
4044*38fd1498Szrj       back()
4045*38fd1498Szrj       {
4046*38fd1498Szrj 	__glibcxx_assert(!empty());
4047*38fd1498Szrj 	return operator[](this->size() - 1);
4048*38fd1498Szrj       }
4049*38fd1498Szrj 
4050*38fd1498Szrj       /**
4051*38fd1498Szrj        *  Returns a read-only (constant) reference to the data at the
4052*38fd1498Szrj        *  last element of the %string.
4053*38fd1498Szrj        */
4054*38fd1498Szrj       const_reference
4055*38fd1498Szrj       back() const noexcept
4056*38fd1498Szrj       {
4057*38fd1498Szrj 	__glibcxx_assert(!empty());
4058*38fd1498Szrj 	return operator[](this->size() - 1);
4059*38fd1498Szrj       }
4060*38fd1498Szrj #endif
4061*38fd1498Szrj 
4062*38fd1498Szrj       // Modifiers:
4063*38fd1498Szrj       /**
4064*38fd1498Szrj        *  @brief  Append a string to this string.
4065*38fd1498Szrj        *  @param __str  The string to append.
4066*38fd1498Szrj        *  @return  Reference to this string.
4067*38fd1498Szrj        */
4068*38fd1498Szrj       basic_string&
4069*38fd1498Szrj       operator+=(const basic_string& __str)
4070*38fd1498Szrj       { return this->append(__str); }
4071*38fd1498Szrj 
4072*38fd1498Szrj       /**
4073*38fd1498Szrj        *  @brief  Append a C string.
4074*38fd1498Szrj        *  @param __s  The C string to append.
4075*38fd1498Szrj        *  @return  Reference to this string.
4076*38fd1498Szrj        */
4077*38fd1498Szrj       basic_string&
4078*38fd1498Szrj       operator+=(const _CharT* __s)
4079*38fd1498Szrj       { return this->append(__s); }
4080*38fd1498Szrj 
4081*38fd1498Szrj       /**
4082*38fd1498Szrj        *  @brief  Append a character.
4083*38fd1498Szrj        *  @param __c  The character to append.
4084*38fd1498Szrj        *  @return  Reference to this string.
4085*38fd1498Szrj        */
4086*38fd1498Szrj       basic_string&
4087*38fd1498Szrj       operator+=(_CharT __c)
4088*38fd1498Szrj       {
4089*38fd1498Szrj 	this->push_back(__c);
4090*38fd1498Szrj 	return *this;
4091*38fd1498Szrj       }
4092*38fd1498Szrj 
4093*38fd1498Szrj #if __cplusplus >= 201103L
4094*38fd1498Szrj       /**
4095*38fd1498Szrj        *  @brief  Append an initializer_list of characters.
4096*38fd1498Szrj        *  @param __l  The initializer_list of characters to be appended.
4097*38fd1498Szrj        *  @return  Reference to this string.
4098*38fd1498Szrj        */
4099*38fd1498Szrj       basic_string&
4100*38fd1498Szrj       operator+=(initializer_list<_CharT> __l)
4101*38fd1498Szrj       { return this->append(__l.begin(), __l.size()); }
4102*38fd1498Szrj #endif // C++11
4103*38fd1498Szrj 
4104*38fd1498Szrj #if __cplusplus > 201402L
4105*38fd1498Szrj       /**
4106*38fd1498Szrj        *  @brief  Append a string_view.
4107*38fd1498Szrj        *  @param __svt The object convertible to string_view to be appended.
4108*38fd1498Szrj        *  @return  Reference to this string.
4109*38fd1498Szrj        */
4110*38fd1498Szrj       template<typename _Tp>
4111*38fd1498Szrj 	_If_sv<_Tp, basic_string&>
4112*38fd1498Szrj 	operator+=(const _Tp& __svt)
4113*38fd1498Szrj 	{ return this->append(__svt); }
4114*38fd1498Szrj #endif // C++17
4115*38fd1498Szrj 
4116*38fd1498Szrj       /**
4117*38fd1498Szrj        *  @brief  Append a string to this string.
4118*38fd1498Szrj        *  @param __str  The string to append.
4119*38fd1498Szrj        *  @return  Reference to this string.
4120*38fd1498Szrj        */
4121*38fd1498Szrj       basic_string&
4122*38fd1498Szrj       append(const basic_string& __str);
4123*38fd1498Szrj 
4124*38fd1498Szrj       /**
4125*38fd1498Szrj        *  @brief  Append a substring.
4126*38fd1498Szrj        *  @param __str  The string to append.
4127*38fd1498Szrj        *  @param __pos  Index of the first character of str to append.
4128*38fd1498Szrj        *  @param __n  The number of characters to append.
4129*38fd1498Szrj        *  @return  Reference to this string.
4130*38fd1498Szrj        *  @throw  std::out_of_range if @a __pos is not a valid index.
4131*38fd1498Szrj        *
4132*38fd1498Szrj        *  This function appends @a __n characters from @a __str
4133*38fd1498Szrj        *  starting at @a __pos to this string.  If @a __n is is larger
4134*38fd1498Szrj        *  than the number of available characters in @a __str, the
4135*38fd1498Szrj        *  remainder of @a __str is appended.
4136*38fd1498Szrj        */
4137*38fd1498Szrj       basic_string&
4138*38fd1498Szrj       append(const basic_string& __str, size_type __pos, size_type __n);
4139*38fd1498Szrj 
4140*38fd1498Szrj       /**
4141*38fd1498Szrj        *  @brief  Append a C substring.
4142*38fd1498Szrj        *  @param __s  The C string to append.
4143*38fd1498Szrj        *  @param __n  The number of characters to append.
4144*38fd1498Szrj        *  @return  Reference to this string.
4145*38fd1498Szrj        */
4146*38fd1498Szrj       basic_string&
4147*38fd1498Szrj       append(const _CharT* __s, size_type __n);
4148*38fd1498Szrj 
4149*38fd1498Szrj       /**
4150*38fd1498Szrj        *  @brief  Append a C string.
4151*38fd1498Szrj        *  @param __s  The C string to append.
4152*38fd1498Szrj        *  @return  Reference to this string.
4153*38fd1498Szrj        */
4154*38fd1498Szrj       basic_string&
4155*38fd1498Szrj       append(const _CharT* __s)
4156*38fd1498Szrj       {
4157*38fd1498Szrj 	__glibcxx_requires_string(__s);
4158*38fd1498Szrj 	return this->append(__s, traits_type::length(__s));
4159*38fd1498Szrj       }
4160*38fd1498Szrj 
4161*38fd1498Szrj       /**
4162*38fd1498Szrj        *  @brief  Append multiple characters.
4163*38fd1498Szrj        *  @param __n  The number of characters to append.
4164*38fd1498Szrj        *  @param __c  The character to use.
4165*38fd1498Szrj        *  @return  Reference to this string.
4166*38fd1498Szrj        *
4167*38fd1498Szrj        *  Appends __n copies of __c to this string.
4168*38fd1498Szrj        */
4169*38fd1498Szrj       basic_string&
4170*38fd1498Szrj       append(size_type __n, _CharT __c);
4171*38fd1498Szrj 
4172*38fd1498Szrj #if __cplusplus >= 201103L
4173*38fd1498Szrj       /**
4174*38fd1498Szrj        *  @brief  Append an initializer_list of characters.
4175*38fd1498Szrj        *  @param __l  The initializer_list of characters to append.
4176*38fd1498Szrj        *  @return  Reference to this string.
4177*38fd1498Szrj        */
4178*38fd1498Szrj       basic_string&
4179*38fd1498Szrj       append(initializer_list<_CharT> __l)
4180*38fd1498Szrj       { return this->append(__l.begin(), __l.size()); }
4181*38fd1498Szrj #endif // C++11
4182*38fd1498Szrj 
4183*38fd1498Szrj       /**
4184*38fd1498Szrj        *  @brief  Append a range of characters.
4185*38fd1498Szrj        *  @param __first  Iterator referencing the first character to append.
4186*38fd1498Szrj        *  @param __last  Iterator marking the end of the range.
4187*38fd1498Szrj        *  @return  Reference to this string.
4188*38fd1498Szrj        *
4189*38fd1498Szrj        *  Appends characters in the range [__first,__last) to this string.
4190*38fd1498Szrj        */
4191*38fd1498Szrj       template<class _InputIterator>
4192*38fd1498Szrj         basic_string&
4193*38fd1498Szrj         append(_InputIterator __first, _InputIterator __last)
4194*38fd1498Szrj         { return this->replace(_M_iend(), _M_iend(), __first, __last); }
4195*38fd1498Szrj 
4196*38fd1498Szrj #if __cplusplus > 201402L
4197*38fd1498Szrj       /**
4198*38fd1498Szrj        *  @brief  Append a string_view.
4199*38fd1498Szrj        *  @param __svt The object convertible to string_view to be appended.
4200*38fd1498Szrj        *  @return  Reference to this string.
4201*38fd1498Szrj        */
4202*38fd1498Szrj       template<typename _Tp>
4203*38fd1498Szrj 	_If_sv<_Tp, basic_string&>
4204*38fd1498Szrj 	append(const _Tp& __svt)
4205*38fd1498Szrj 	{
4206*38fd1498Szrj 	  __sv_type __sv = __svt;
4207*38fd1498Szrj 	  return this->append(__sv.data(), __sv.size());
4208*38fd1498Szrj 	}
4209*38fd1498Szrj 
4210*38fd1498Szrj       /**
4211*38fd1498Szrj        *  @brief  Append a range of characters from a string_view.
4212*38fd1498Szrj        *  @param __svt The object convertible to string_view to be appended
4213*38fd1498Szrj        *               from.
4214*38fd1498Szrj        *  @param __pos The position in the string_view to append from.
4215*38fd1498Szrj        *  @param __n   The number of characters to append from the string_view.
4216*38fd1498Szrj        *  @return  Reference to this string.
4217*38fd1498Szrj        */
4218*38fd1498Szrj       template<typename _Tp>
4219*38fd1498Szrj         _If_sv<_Tp, basic_string&>
4220*38fd1498Szrj 	append(const _Tp& __svt, size_type __pos, size_type __n = npos)
4221*38fd1498Szrj 	{
4222*38fd1498Szrj 	  __sv_type __sv = __svt;
4223*38fd1498Szrj 	  return append(__sv.data()
4224*38fd1498Szrj 			+ __sv._M_check(__pos, "basic_string::append"),
4225*38fd1498Szrj 			__sv._M_limit(__pos, __n));
4226*38fd1498Szrj 	}
4227*38fd1498Szrj #endif // C++17
4228*38fd1498Szrj 
4229*38fd1498Szrj       /**
4230*38fd1498Szrj        *  @brief  Append a single character.
4231*38fd1498Szrj        *  @param __c  Character to append.
4232*38fd1498Szrj        */
4233*38fd1498Szrj       void
4234*38fd1498Szrj       push_back(_CharT __c)
4235*38fd1498Szrj       {
4236*38fd1498Szrj 	const size_type __len = 1 + this->size();
4237*38fd1498Szrj 	if (__len > this->capacity() || _M_rep()->_M_is_shared())
4238*38fd1498Szrj 	  this->reserve(__len);
4239*38fd1498Szrj 	traits_type::assign(_M_data()[this->size()], __c);
4240*38fd1498Szrj 	_M_rep()->_M_set_length_and_sharable(__len);
4241*38fd1498Szrj       }
4242*38fd1498Szrj 
4243*38fd1498Szrj       /**
4244*38fd1498Szrj        *  @brief  Set value to contents of another string.
4245*38fd1498Szrj        *  @param  __str  Source string to use.
4246*38fd1498Szrj        *  @return  Reference to this string.
4247*38fd1498Szrj        */
4248*38fd1498Szrj       basic_string&
4249*38fd1498Szrj       assign(const basic_string& __str);
4250*38fd1498Szrj 
4251*38fd1498Szrj #if __cplusplus >= 201103L
4252*38fd1498Szrj       /**
4253*38fd1498Szrj        *  @brief  Set value to contents of another string.
4254*38fd1498Szrj        *  @param  __str  Source string to use.
4255*38fd1498Szrj        *  @return  Reference to this string.
4256*38fd1498Szrj        *
4257*38fd1498Szrj        *  This function sets this string to the exact contents of @a __str.
4258*38fd1498Szrj        *  @a __str is a valid, but unspecified string.
4259*38fd1498Szrj        */
4260*38fd1498Szrj       // PR 58265, this should be noexcept.
4261*38fd1498Szrj       basic_string&
4262*38fd1498Szrj       assign(basic_string&& __str)
4263*38fd1498Szrj       {
4264*38fd1498Szrj 	this->swap(__str);
4265*38fd1498Szrj 	return *this;
4266*38fd1498Szrj       }
4267*38fd1498Szrj #endif // C++11
4268*38fd1498Szrj 
4269*38fd1498Szrj       /**
4270*38fd1498Szrj        *  @brief  Set value to a substring of a string.
4271*38fd1498Szrj        *  @param __str  The string to use.
4272*38fd1498Szrj        *  @param __pos  Index of the first character of str.
4273*38fd1498Szrj        *  @param __n  Number of characters to use.
4274*38fd1498Szrj        *  @return  Reference to this string.
4275*38fd1498Szrj        *  @throw  std::out_of_range if @a pos is not a valid index.
4276*38fd1498Szrj        *
4277*38fd1498Szrj        *  This function sets this string to the substring of @a __str
4278*38fd1498Szrj        *  consisting of @a __n characters at @a __pos.  If @a __n is
4279*38fd1498Szrj        *  is larger than the number of available characters in @a
4280*38fd1498Szrj        *  __str, the remainder of @a __str is used.
4281*38fd1498Szrj        */
4282*38fd1498Szrj       basic_string&
4283*38fd1498Szrj       assign(const basic_string& __str, size_type __pos, size_type __n)
4284*38fd1498Szrj       { return this->assign(__str._M_data()
4285*38fd1498Szrj 			    + __str._M_check(__pos, "basic_string::assign"),
4286*38fd1498Szrj 			    __str._M_limit(__pos, __n)); }
4287*38fd1498Szrj 
4288*38fd1498Szrj       /**
4289*38fd1498Szrj        *  @brief  Set value to a C substring.
4290*38fd1498Szrj        *  @param __s  The C string to use.
4291*38fd1498Szrj        *  @param __n  Number of characters to use.
4292*38fd1498Szrj        *  @return  Reference to this string.
4293*38fd1498Szrj        *
4294*38fd1498Szrj        *  This function sets the value of this string to the first @a __n
4295*38fd1498Szrj        *  characters of @a __s.  If @a __n is is larger than the number of
4296*38fd1498Szrj        *  available characters in @a __s, the remainder of @a __s is used.
4297*38fd1498Szrj        */
4298*38fd1498Szrj       basic_string&
4299*38fd1498Szrj       assign(const _CharT* __s, size_type __n);
4300*38fd1498Szrj 
4301*38fd1498Szrj       /**
4302*38fd1498Szrj        *  @brief  Set value to contents of a C string.
4303*38fd1498Szrj        *  @param __s  The C string to use.
4304*38fd1498Szrj        *  @return  Reference to this string.
4305*38fd1498Szrj        *
4306*38fd1498Szrj        *  This function sets the value of this string to the value of @a __s.
4307*38fd1498Szrj        *  The data is copied, so there is no dependence on @a __s once the
4308*38fd1498Szrj        *  function returns.
4309*38fd1498Szrj        */
4310*38fd1498Szrj       basic_string&
4311*38fd1498Szrj       assign(const _CharT* __s)
4312*38fd1498Szrj       {
4313*38fd1498Szrj 	__glibcxx_requires_string(__s);
4314*38fd1498Szrj 	return this->assign(__s, traits_type::length(__s));
4315*38fd1498Szrj       }
4316*38fd1498Szrj 
4317*38fd1498Szrj       /**
4318*38fd1498Szrj        *  @brief  Set value to multiple characters.
4319*38fd1498Szrj        *  @param __n  Length of the resulting string.
4320*38fd1498Szrj        *  @param __c  The character to use.
4321*38fd1498Szrj        *  @return  Reference to this string.
4322*38fd1498Szrj        *
4323*38fd1498Szrj        *  This function sets the value of this string to @a __n copies of
4324*38fd1498Szrj        *  character @a __c.
4325*38fd1498Szrj        */
4326*38fd1498Szrj       basic_string&
4327*38fd1498Szrj       assign(size_type __n, _CharT __c)
4328*38fd1498Szrj       { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
4329*38fd1498Szrj 
4330*38fd1498Szrj       /**
4331*38fd1498Szrj        *  @brief  Set value to a range of characters.
4332*38fd1498Szrj        *  @param __first  Iterator referencing the first character to append.
4333*38fd1498Szrj        *  @param __last  Iterator marking the end of the range.
4334*38fd1498Szrj        *  @return  Reference to this string.
4335*38fd1498Szrj        *
4336*38fd1498Szrj        *  Sets value of string to characters in the range [__first,__last).
4337*38fd1498Szrj       */
4338*38fd1498Szrj       template<class _InputIterator>
4339*38fd1498Szrj         basic_string&
4340*38fd1498Szrj         assign(_InputIterator __first, _InputIterator __last)
4341*38fd1498Szrj         { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
4342*38fd1498Szrj 
4343*38fd1498Szrj #if __cplusplus >= 201103L
4344*38fd1498Szrj       /**
4345*38fd1498Szrj        *  @brief  Set value to an initializer_list of characters.
4346*38fd1498Szrj        *  @param __l  The initializer_list of characters to assign.
4347*38fd1498Szrj        *  @return  Reference to this string.
4348*38fd1498Szrj        */
4349*38fd1498Szrj       basic_string&
4350*38fd1498Szrj       assign(initializer_list<_CharT> __l)
4351*38fd1498Szrj       { return this->assign(__l.begin(), __l.size()); }
4352*38fd1498Szrj #endif // C++11
4353*38fd1498Szrj 
4354*38fd1498Szrj #if __cplusplus > 201402L
4355*38fd1498Szrj       /**
4356*38fd1498Szrj        *  @brief  Set value from a string_view.
4357*38fd1498Szrj        *  @param __svt The source object convertible to string_view.
4358*38fd1498Szrj        *  @return  Reference to this string.
4359*38fd1498Szrj        */
4360*38fd1498Szrj       template<typename _Tp>
4361*38fd1498Szrj 	_If_sv<_Tp, basic_string&>
4362*38fd1498Szrj 	assign(const _Tp& __svt)
4363*38fd1498Szrj 	{
4364*38fd1498Szrj 	  __sv_type __sv = __svt;
4365*38fd1498Szrj 	  return this->assign(__sv.data(), __sv.size());
4366*38fd1498Szrj 	}
4367*38fd1498Szrj 
4368*38fd1498Szrj       /**
4369*38fd1498Szrj        *  @brief  Set value from a range of characters in a string_view.
4370*38fd1498Szrj        *  @param __svt  The source object convertible to string_view.
4371*38fd1498Szrj        *  @param __pos  The position in the string_view to assign from.
4372*38fd1498Szrj        *  @param __n  The number of characters to assign.
4373*38fd1498Szrj        *  @return  Reference to this string.
4374*38fd1498Szrj        */
4375*38fd1498Szrj       template<typename _Tp>
4376*38fd1498Szrj         _If_sv<_Tp, basic_string&>
4377*38fd1498Szrj         assign(const _Tp& __svt, size_type __pos, size_type __n = npos)
4378*38fd1498Szrj 	{
4379*38fd1498Szrj 	  __sv_type __sv = __svt;
4380*38fd1498Szrj 	  return assign(__sv.data()
4381*38fd1498Szrj 			+ __sv._M_check(__pos, "basic_string::assign"),
4382*38fd1498Szrj 			__sv._M_limit(__pos, __n));
4383*38fd1498Szrj 	}
4384*38fd1498Szrj #endif // C++17
4385*38fd1498Szrj 
4386*38fd1498Szrj       /**
4387*38fd1498Szrj        *  @brief  Insert multiple characters.
4388*38fd1498Szrj        *  @param __p  Iterator referencing location in string to insert at.
4389*38fd1498Szrj        *  @param __n  Number of characters to insert
4390*38fd1498Szrj        *  @param __c  The character to insert.
4391*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4392*38fd1498Szrj        *
4393*38fd1498Szrj        *  Inserts @a __n copies of character @a __c starting at the
4394*38fd1498Szrj        *  position referenced by iterator @a __p.  If adding
4395*38fd1498Szrj        *  characters causes the length to exceed max_size(),
4396*38fd1498Szrj        *  length_error is thrown.  The value of the string doesn't
4397*38fd1498Szrj        *  change if an error is thrown.
4398*38fd1498Szrj       */
4399*38fd1498Szrj       void
4400*38fd1498Szrj       insert(iterator __p, size_type __n, _CharT __c)
4401*38fd1498Szrj       {	this->replace(__p, __p, __n, __c);  }
4402*38fd1498Szrj 
4403*38fd1498Szrj       /**
4404*38fd1498Szrj        *  @brief  Insert a range of characters.
4405*38fd1498Szrj        *  @param __p  Iterator referencing location in string to insert at.
4406*38fd1498Szrj        *  @param __beg  Start of range.
4407*38fd1498Szrj        *  @param __end  End of range.
4408*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4409*38fd1498Szrj        *
4410*38fd1498Szrj        *  Inserts characters in range [__beg,__end).  If adding
4411*38fd1498Szrj        *  characters causes the length to exceed max_size(),
4412*38fd1498Szrj        *  length_error is thrown.  The value of the string doesn't
4413*38fd1498Szrj        *  change if an error is thrown.
4414*38fd1498Szrj       */
4415*38fd1498Szrj       template<class _InputIterator>
4416*38fd1498Szrj         void
4417*38fd1498Szrj         insert(iterator __p, _InputIterator __beg, _InputIterator __end)
4418*38fd1498Szrj         { this->replace(__p, __p, __beg, __end); }
4419*38fd1498Szrj 
4420*38fd1498Szrj #if __cplusplus >= 201103L
4421*38fd1498Szrj       /**
4422*38fd1498Szrj        *  @brief  Insert an initializer_list of characters.
4423*38fd1498Szrj        *  @param __p  Iterator referencing location in string to insert at.
4424*38fd1498Szrj        *  @param __l  The initializer_list of characters to insert.
4425*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4426*38fd1498Szrj        */
4427*38fd1498Szrj       void
4428*38fd1498Szrj       insert(iterator __p, initializer_list<_CharT> __l)
4429*38fd1498Szrj       {
4430*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
4431*38fd1498Szrj 	this->insert(__p - _M_ibegin(), __l.begin(), __l.size());
4432*38fd1498Szrj       }
4433*38fd1498Szrj #endif // C++11
4434*38fd1498Szrj 
4435*38fd1498Szrj       /**
4436*38fd1498Szrj        *  @brief  Insert value of a string.
4437*38fd1498Szrj        *  @param __pos1  Iterator referencing location in string to insert at.
4438*38fd1498Szrj        *  @param __str  The string to insert.
4439*38fd1498Szrj        *  @return  Reference to this string.
4440*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4441*38fd1498Szrj        *
4442*38fd1498Szrj        *  Inserts value of @a __str starting at @a __pos1.  If adding
4443*38fd1498Szrj        *  characters causes the length to exceed max_size(),
4444*38fd1498Szrj        *  length_error is thrown.  The value of the string doesn't
4445*38fd1498Szrj        *  change if an error is thrown.
4446*38fd1498Szrj       */
4447*38fd1498Szrj       basic_string&
4448*38fd1498Szrj       insert(size_type __pos1, const basic_string& __str)
4449*38fd1498Szrj       { return this->insert(__pos1, __str, size_type(0), __str.size()); }
4450*38fd1498Szrj 
4451*38fd1498Szrj       /**
4452*38fd1498Szrj        *  @brief  Insert a substring.
4453*38fd1498Szrj        *  @param __pos1  Iterator referencing location in string to insert at.
4454*38fd1498Szrj        *  @param __str  The string to insert.
4455*38fd1498Szrj        *  @param __pos2  Start of characters in str to insert.
4456*38fd1498Szrj        *  @param __n  Number of characters to insert.
4457*38fd1498Szrj        *  @return  Reference to this string.
4458*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4459*38fd1498Szrj        *  @throw  std::out_of_range  If @a pos1 > size() or
4460*38fd1498Szrj        *  @a __pos2 > @a str.size().
4461*38fd1498Szrj        *
4462*38fd1498Szrj        *  Starting at @a pos1, insert @a __n character of @a __str
4463*38fd1498Szrj        *  beginning with @a __pos2.  If adding characters causes the
4464*38fd1498Szrj        *  length to exceed max_size(), length_error is thrown.  If @a
4465*38fd1498Szrj        *  __pos1 is beyond the end of this string or @a __pos2 is
4466*38fd1498Szrj        *  beyond the end of @a __str, out_of_range is thrown.  The
4467*38fd1498Szrj        *  value of the string doesn't change if an error is thrown.
4468*38fd1498Szrj       */
4469*38fd1498Szrj       basic_string&
4470*38fd1498Szrj       insert(size_type __pos1, const basic_string& __str,
4471*38fd1498Szrj 	     size_type __pos2, size_type __n)
4472*38fd1498Szrj       { return this->insert(__pos1, __str._M_data()
4473*38fd1498Szrj 			    + __str._M_check(__pos2, "basic_string::insert"),
4474*38fd1498Szrj 			    __str._M_limit(__pos2, __n)); }
4475*38fd1498Szrj 
4476*38fd1498Szrj       /**
4477*38fd1498Szrj        *  @brief  Insert a C substring.
4478*38fd1498Szrj        *  @param __pos  Iterator referencing location in string to insert at.
4479*38fd1498Szrj        *  @param __s  The C string to insert.
4480*38fd1498Szrj        *  @param __n  The number of characters to insert.
4481*38fd1498Szrj        *  @return  Reference to this string.
4482*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4483*38fd1498Szrj        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
4484*38fd1498Szrj        *  string.
4485*38fd1498Szrj        *
4486*38fd1498Szrj        *  Inserts the first @a __n characters of @a __s starting at @a
4487*38fd1498Szrj        *  __pos.  If adding characters causes the length to exceed
4488*38fd1498Szrj        *  max_size(), length_error is thrown.  If @a __pos is beyond
4489*38fd1498Szrj        *  end(), out_of_range is thrown.  The value of the string
4490*38fd1498Szrj        *  doesn't change if an error is thrown.
4491*38fd1498Szrj       */
4492*38fd1498Szrj       basic_string&
4493*38fd1498Szrj       insert(size_type __pos, const _CharT* __s, size_type __n);
4494*38fd1498Szrj 
4495*38fd1498Szrj       /**
4496*38fd1498Szrj        *  @brief  Insert a C string.
4497*38fd1498Szrj        *  @param __pos  Iterator referencing location in string to insert at.
4498*38fd1498Szrj        *  @param __s  The C string to insert.
4499*38fd1498Szrj        *  @return  Reference to this string.
4500*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4501*38fd1498Szrj        *  @throw  std::out_of_range  If @a pos is beyond the end of this
4502*38fd1498Szrj        *  string.
4503*38fd1498Szrj        *
4504*38fd1498Szrj        *  Inserts the first @a n characters of @a __s starting at @a __pos.  If
4505*38fd1498Szrj        *  adding characters causes the length to exceed max_size(),
4506*38fd1498Szrj        *  length_error is thrown.  If @a __pos is beyond end(), out_of_range is
4507*38fd1498Szrj        *  thrown.  The value of the string doesn't change if an error is
4508*38fd1498Szrj        *  thrown.
4509*38fd1498Szrj       */
4510*38fd1498Szrj       basic_string&
4511*38fd1498Szrj       insert(size_type __pos, const _CharT* __s)
4512*38fd1498Szrj       {
4513*38fd1498Szrj 	__glibcxx_requires_string(__s);
4514*38fd1498Szrj 	return this->insert(__pos, __s, traits_type::length(__s));
4515*38fd1498Szrj       }
4516*38fd1498Szrj 
4517*38fd1498Szrj       /**
4518*38fd1498Szrj        *  @brief  Insert multiple characters.
4519*38fd1498Szrj        *  @param __pos  Index in string to insert at.
4520*38fd1498Szrj        *  @param __n  Number of characters to insert
4521*38fd1498Szrj        *  @param __c  The character to insert.
4522*38fd1498Szrj        *  @return  Reference to this string.
4523*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4524*38fd1498Szrj        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
4525*38fd1498Szrj        *  string.
4526*38fd1498Szrj        *
4527*38fd1498Szrj        *  Inserts @a __n copies of character @a __c starting at index
4528*38fd1498Szrj        *  @a __pos.  If adding characters causes the length to exceed
4529*38fd1498Szrj        *  max_size(), length_error is thrown.  If @a __pos > length(),
4530*38fd1498Szrj        *  out_of_range is thrown.  The value of the string doesn't
4531*38fd1498Szrj        *  change if an error is thrown.
4532*38fd1498Szrj       */
4533*38fd1498Szrj       basic_string&
4534*38fd1498Szrj       insert(size_type __pos, size_type __n, _CharT __c)
4535*38fd1498Szrj       { return _M_replace_aux(_M_check(__pos, "basic_string::insert"),
4536*38fd1498Szrj 			      size_type(0), __n, __c); }
4537*38fd1498Szrj 
4538*38fd1498Szrj       /**
4539*38fd1498Szrj        *  @brief  Insert one character.
4540*38fd1498Szrj        *  @param __p  Iterator referencing position in string to insert at.
4541*38fd1498Szrj        *  @param __c  The character to insert.
4542*38fd1498Szrj        *  @return  Iterator referencing newly inserted char.
4543*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4544*38fd1498Szrj        *
4545*38fd1498Szrj        *  Inserts character @a __c at position referenced by @a __p.
4546*38fd1498Szrj        *  If adding character causes the length to exceed max_size(),
4547*38fd1498Szrj        *  length_error is thrown.  If @a __p is beyond end of string,
4548*38fd1498Szrj        *  out_of_range is thrown.  The value of the string doesn't
4549*38fd1498Szrj        *  change if an error is thrown.
4550*38fd1498Szrj       */
4551*38fd1498Szrj       iterator
4552*38fd1498Szrj       insert(iterator __p, _CharT __c)
4553*38fd1498Szrj       {
4554*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
4555*38fd1498Szrj 	const size_type __pos = __p - _M_ibegin();
4556*38fd1498Szrj 	_M_replace_aux(__pos, size_type(0), size_type(1), __c);
4557*38fd1498Szrj 	_M_rep()->_M_set_leaked();
4558*38fd1498Szrj 	return iterator(_M_data() + __pos);
4559*38fd1498Szrj       }
4560*38fd1498Szrj 
4561*38fd1498Szrj #if __cplusplus > 201402L
4562*38fd1498Szrj       /**
4563*38fd1498Szrj        *  @brief  Insert a string_view.
4564*38fd1498Szrj        *  @param __pos  Iterator referencing position in string to insert at.
4565*38fd1498Szrj        *  @param __svt  The object convertible to string_view to insert.
4566*38fd1498Szrj        *  @return  Reference to this string.
4567*38fd1498Szrj       */
4568*38fd1498Szrj       template<typename _Tp>
4569*38fd1498Szrj 	_If_sv<_Tp, basic_string&>
4570*38fd1498Szrj 	insert(size_type __pos, const _Tp& __svt)
4571*38fd1498Szrj 	{
4572*38fd1498Szrj 	  __sv_type __sv = __svt;
4573*38fd1498Szrj 	  return this->insert(__pos, __sv.data(), __sv.size());
4574*38fd1498Szrj 	}
4575*38fd1498Szrj 
4576*38fd1498Szrj       /**
4577*38fd1498Szrj        *  @brief  Insert a string_view.
4578*38fd1498Szrj        *  @param __pos  Iterator referencing position in string to insert at.
4579*38fd1498Szrj        *  @param __svt  The object convertible to string_view to insert from.
4580*38fd1498Szrj        *  @param __pos  Iterator referencing position in string_view to insert
4581*38fd1498Szrj        *  from.
4582*38fd1498Szrj        *  @param __n    The number of characters to insert.
4583*38fd1498Szrj        *  @return  Reference to this string.
4584*38fd1498Szrj       */
4585*38fd1498Szrj       template<typename _Tp>
4586*38fd1498Szrj         _If_sv<_Tp, basic_string&>
4587*38fd1498Szrj         insert(size_type __pos1, const _Tp& __svt,
4588*38fd1498Szrj 	       size_type __pos2, size_type __n = npos)
4589*38fd1498Szrj 	{
4590*38fd1498Szrj 	  __sv_type __sv = __svt;
4591*38fd1498Szrj 	  return this->replace(__pos1, size_type(0), __sv.data()
4592*38fd1498Szrj 			       + __sv._M_check(__pos2, "basic_string::insert"),
4593*38fd1498Szrj 			       __sv._M_limit(__pos2, __n));
4594*38fd1498Szrj 	}
4595*38fd1498Szrj #endif // C++17
4596*38fd1498Szrj 
4597*38fd1498Szrj       /**
4598*38fd1498Szrj        *  @brief  Remove characters.
4599*38fd1498Szrj        *  @param __pos  Index of first character to remove (default 0).
4600*38fd1498Szrj        *  @param __n  Number of characters to remove (default remainder).
4601*38fd1498Szrj        *  @return  Reference to this string.
4602*38fd1498Szrj        *  @throw  std::out_of_range  If @a pos is beyond the end of this
4603*38fd1498Szrj        *  string.
4604*38fd1498Szrj        *
4605*38fd1498Szrj        *  Removes @a __n characters from this string starting at @a
4606*38fd1498Szrj        *  __pos.  The length of the string is reduced by @a __n.  If
4607*38fd1498Szrj        *  there are < @a __n characters to remove, the remainder of
4608*38fd1498Szrj        *  the string is truncated.  If @a __p is beyond end of string,
4609*38fd1498Szrj        *  out_of_range is thrown.  The value of the string doesn't
4610*38fd1498Szrj        *  change if an error is thrown.
4611*38fd1498Szrj       */
4612*38fd1498Szrj       basic_string&
4613*38fd1498Szrj       erase(size_type __pos = 0, size_type __n = npos)
4614*38fd1498Szrj       {
4615*38fd1498Szrj 	_M_mutate(_M_check(__pos, "basic_string::erase"),
4616*38fd1498Szrj 		  _M_limit(__pos, __n), size_type(0));
4617*38fd1498Szrj 	return *this;
4618*38fd1498Szrj       }
4619*38fd1498Szrj 
4620*38fd1498Szrj       /**
4621*38fd1498Szrj        *  @brief  Remove one character.
4622*38fd1498Szrj        *  @param __position  Iterator referencing the character to remove.
4623*38fd1498Szrj        *  @return  iterator referencing same location after removal.
4624*38fd1498Szrj        *
4625*38fd1498Szrj        *  Removes the character at @a __position from this string. The value
4626*38fd1498Szrj        *  of the string doesn't change if an error is thrown.
4627*38fd1498Szrj       */
4628*38fd1498Szrj       iterator
4629*38fd1498Szrj       erase(iterator __position)
4630*38fd1498Szrj       {
4631*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
4632*38fd1498Szrj 				 && __position < _M_iend());
4633*38fd1498Szrj 	const size_type __pos = __position - _M_ibegin();
4634*38fd1498Szrj 	_M_mutate(__pos, size_type(1), size_type(0));
4635*38fd1498Szrj 	_M_rep()->_M_set_leaked();
4636*38fd1498Szrj 	return iterator(_M_data() + __pos);
4637*38fd1498Szrj       }
4638*38fd1498Szrj 
4639*38fd1498Szrj       /**
4640*38fd1498Szrj        *  @brief  Remove a range of characters.
4641*38fd1498Szrj        *  @param __first  Iterator referencing the first character to remove.
4642*38fd1498Szrj        *  @param __last  Iterator referencing the end of the range.
4643*38fd1498Szrj        *  @return  Iterator referencing location of first after removal.
4644*38fd1498Szrj        *
4645*38fd1498Szrj        *  Removes the characters in the range [first,last) from this string.
4646*38fd1498Szrj        *  The value of the string doesn't change if an error is thrown.
4647*38fd1498Szrj       */
4648*38fd1498Szrj       iterator
4649*38fd1498Szrj       erase(iterator __first, iterator __last);
4650*38fd1498Szrj 
4651*38fd1498Szrj #if __cplusplus >= 201103L
4652*38fd1498Szrj       /**
4653*38fd1498Szrj        *  @brief  Remove the last character.
4654*38fd1498Szrj        *
4655*38fd1498Szrj        *  The string must be non-empty.
4656*38fd1498Szrj        */
4657*38fd1498Szrj       void
4658*38fd1498Szrj       pop_back() // FIXME C++11: should be noexcept.
4659*38fd1498Szrj       {
4660*38fd1498Szrj 	__glibcxx_assert(!empty());
4661*38fd1498Szrj 	erase(size() - 1, 1);
4662*38fd1498Szrj       }
4663*38fd1498Szrj #endif // C++11
4664*38fd1498Szrj 
4665*38fd1498Szrj       /**
4666*38fd1498Szrj        *  @brief  Replace characters with value from another string.
4667*38fd1498Szrj        *  @param __pos  Index of first character to replace.
4668*38fd1498Szrj        *  @param __n  Number of characters to be replaced.
4669*38fd1498Szrj        *  @param __str  String to insert.
4670*38fd1498Szrj        *  @return  Reference to this string.
4671*38fd1498Szrj        *  @throw  std::out_of_range  If @a pos is beyond the end of this
4672*38fd1498Szrj        *  string.
4673*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4674*38fd1498Szrj        *
4675*38fd1498Szrj        *  Removes the characters in the range [__pos,__pos+__n) from
4676*38fd1498Szrj        *  this string.  In place, the value of @a __str is inserted.
4677*38fd1498Szrj        *  If @a __pos is beyond end of string, out_of_range is thrown.
4678*38fd1498Szrj        *  If the length of the result exceeds max_size(), length_error
4679*38fd1498Szrj        *  is thrown.  The value of the string doesn't change if an
4680*38fd1498Szrj        *  error is thrown.
4681*38fd1498Szrj       */
4682*38fd1498Szrj       basic_string&
4683*38fd1498Szrj       replace(size_type __pos, size_type __n, const basic_string& __str)
4684*38fd1498Szrj       { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
4685*38fd1498Szrj 
4686*38fd1498Szrj       /**
4687*38fd1498Szrj        *  @brief  Replace characters with value from another string.
4688*38fd1498Szrj        *  @param __pos1  Index of first character to replace.
4689*38fd1498Szrj        *  @param __n1  Number of characters to be replaced.
4690*38fd1498Szrj        *  @param __str  String to insert.
4691*38fd1498Szrj        *  @param __pos2  Index of first character of str to use.
4692*38fd1498Szrj        *  @param __n2  Number of characters from str to use.
4693*38fd1498Szrj        *  @return  Reference to this string.
4694*38fd1498Szrj        *  @throw  std::out_of_range  If @a __pos1 > size() or @a __pos2 >
4695*38fd1498Szrj        *  __str.size().
4696*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4697*38fd1498Szrj        *
4698*38fd1498Szrj        *  Removes the characters in the range [__pos1,__pos1 + n) from this
4699*38fd1498Szrj        *  string.  In place, the value of @a __str is inserted.  If @a __pos is
4700*38fd1498Szrj        *  beyond end of string, out_of_range is thrown.  If the length of the
4701*38fd1498Szrj        *  result exceeds max_size(), length_error is thrown.  The value of the
4702*38fd1498Szrj        *  string doesn't change if an error is thrown.
4703*38fd1498Szrj       */
4704*38fd1498Szrj       basic_string&
4705*38fd1498Szrj       replace(size_type __pos1, size_type __n1, const basic_string& __str,
4706*38fd1498Szrj 	      size_type __pos2, size_type __n2)
4707*38fd1498Szrj       { return this->replace(__pos1, __n1, __str._M_data()
4708*38fd1498Szrj 			     + __str._M_check(__pos2, "basic_string::replace"),
4709*38fd1498Szrj 			     __str._M_limit(__pos2, __n2)); }
4710*38fd1498Szrj 
4711*38fd1498Szrj       /**
4712*38fd1498Szrj        *  @brief  Replace characters with value of a C substring.
4713*38fd1498Szrj        *  @param __pos  Index of first character to replace.
4714*38fd1498Szrj        *  @param __n1  Number of characters to be replaced.
4715*38fd1498Szrj        *  @param __s  C string to insert.
4716*38fd1498Szrj        *  @param __n2  Number of characters from @a s to use.
4717*38fd1498Szrj        *  @return  Reference to this string.
4718*38fd1498Szrj        *  @throw  std::out_of_range  If @a pos1 > size().
4719*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4720*38fd1498Szrj        *
4721*38fd1498Szrj        *  Removes the characters in the range [__pos,__pos + __n1)
4722*38fd1498Szrj        *  from this string.  In place, the first @a __n2 characters of
4723*38fd1498Szrj        *  @a __s are inserted, or all of @a __s if @a __n2 is too large.  If
4724*38fd1498Szrj        *  @a __pos is beyond end of string, out_of_range is thrown.  If
4725*38fd1498Szrj        *  the length of result exceeds max_size(), length_error is
4726*38fd1498Szrj        *  thrown.  The value of the string doesn't change if an error
4727*38fd1498Szrj        *  is thrown.
4728*38fd1498Szrj       */
4729*38fd1498Szrj       basic_string&
4730*38fd1498Szrj       replace(size_type __pos, size_type __n1, const _CharT* __s,
4731*38fd1498Szrj 	      size_type __n2);
4732*38fd1498Szrj 
4733*38fd1498Szrj       /**
4734*38fd1498Szrj        *  @brief  Replace characters with value of a C string.
4735*38fd1498Szrj        *  @param __pos  Index of first character to replace.
4736*38fd1498Szrj        *  @param __n1  Number of characters to be replaced.
4737*38fd1498Szrj        *  @param __s  C string to insert.
4738*38fd1498Szrj        *  @return  Reference to this string.
4739*38fd1498Szrj        *  @throw  std::out_of_range  If @a pos > size().
4740*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4741*38fd1498Szrj        *
4742*38fd1498Szrj        *  Removes the characters in the range [__pos,__pos + __n1)
4743*38fd1498Szrj        *  from this string.  In place, the characters of @a __s are
4744*38fd1498Szrj        *  inserted.  If @a __pos is beyond end of string, out_of_range
4745*38fd1498Szrj        *  is thrown.  If the length of result exceeds max_size(),
4746*38fd1498Szrj        *  length_error is thrown.  The value of the string doesn't
4747*38fd1498Szrj        *  change if an error is thrown.
4748*38fd1498Szrj       */
4749*38fd1498Szrj       basic_string&
4750*38fd1498Szrj       replace(size_type __pos, size_type __n1, const _CharT* __s)
4751*38fd1498Szrj       {
4752*38fd1498Szrj 	__glibcxx_requires_string(__s);
4753*38fd1498Szrj 	return this->replace(__pos, __n1, __s, traits_type::length(__s));
4754*38fd1498Szrj       }
4755*38fd1498Szrj 
4756*38fd1498Szrj       /**
4757*38fd1498Szrj        *  @brief  Replace characters with multiple characters.
4758*38fd1498Szrj        *  @param __pos  Index of first character to replace.
4759*38fd1498Szrj        *  @param __n1  Number of characters to be replaced.
4760*38fd1498Szrj        *  @param __n2  Number of characters to insert.
4761*38fd1498Szrj        *  @param __c  Character to insert.
4762*38fd1498Szrj        *  @return  Reference to this string.
4763*38fd1498Szrj        *  @throw  std::out_of_range  If @a __pos > size().
4764*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4765*38fd1498Szrj        *
4766*38fd1498Szrj        *  Removes the characters in the range [pos,pos + n1) from this
4767*38fd1498Szrj        *  string.  In place, @a __n2 copies of @a __c are inserted.
4768*38fd1498Szrj        *  If @a __pos is beyond end of string, out_of_range is thrown.
4769*38fd1498Szrj        *  If the length of result exceeds max_size(), length_error is
4770*38fd1498Szrj        *  thrown.  The value of the string doesn't change if an error
4771*38fd1498Szrj        *  is thrown.
4772*38fd1498Szrj       */
4773*38fd1498Szrj       basic_string&
4774*38fd1498Szrj       replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
4775*38fd1498Szrj       { return _M_replace_aux(_M_check(__pos, "basic_string::replace"),
4776*38fd1498Szrj 			      _M_limit(__pos, __n1), __n2, __c); }
4777*38fd1498Szrj 
4778*38fd1498Szrj       /**
4779*38fd1498Szrj        *  @brief  Replace range of characters with string.
4780*38fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
4781*38fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
4782*38fd1498Szrj        *  @param __str  String value to insert.
4783*38fd1498Szrj        *  @return  Reference to this string.
4784*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4785*38fd1498Szrj        *
4786*38fd1498Szrj        *  Removes the characters in the range [__i1,__i2).  In place,
4787*38fd1498Szrj        *  the value of @a __str is inserted.  If the length of result
4788*38fd1498Szrj        *  exceeds max_size(), length_error is thrown.  The value of
4789*38fd1498Szrj        *  the string doesn't change if an error is thrown.
4790*38fd1498Szrj       */
4791*38fd1498Szrj       basic_string&
4792*38fd1498Szrj       replace(iterator __i1, iterator __i2, const basic_string& __str)
4793*38fd1498Szrj       { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
4794*38fd1498Szrj 
4795*38fd1498Szrj       /**
4796*38fd1498Szrj        *  @brief  Replace range of characters with C substring.
4797*38fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
4798*38fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
4799*38fd1498Szrj        *  @param __s  C string value to insert.
4800*38fd1498Szrj        *  @param __n  Number of characters from s to insert.
4801*38fd1498Szrj        *  @return  Reference to this string.
4802*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4803*38fd1498Szrj        *
4804*38fd1498Szrj        *  Removes the characters in the range [__i1,__i2).  In place,
4805*38fd1498Szrj        *  the first @a __n characters of @a __s are inserted.  If the
4806*38fd1498Szrj        *  length of result exceeds max_size(), length_error is thrown.
4807*38fd1498Szrj        *  The value of the string doesn't change if an error is
4808*38fd1498Szrj        *  thrown.
4809*38fd1498Szrj       */
4810*38fd1498Szrj       basic_string&
4811*38fd1498Szrj       replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
4812*38fd1498Szrj       {
4813*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4814*38fd1498Szrj 				 && __i2 <= _M_iend());
4815*38fd1498Szrj 	return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
4816*38fd1498Szrj       }
4817*38fd1498Szrj 
4818*38fd1498Szrj       /**
4819*38fd1498Szrj        *  @brief  Replace range of characters with C string.
4820*38fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
4821*38fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
4822*38fd1498Szrj        *  @param __s  C string value to insert.
4823*38fd1498Szrj        *  @return  Reference to this string.
4824*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4825*38fd1498Szrj        *
4826*38fd1498Szrj        *  Removes the characters in the range [__i1,__i2).  In place,
4827*38fd1498Szrj        *  the characters of @a __s are inserted.  If the length of
4828*38fd1498Szrj        *  result exceeds max_size(), length_error is thrown.  The
4829*38fd1498Szrj        *  value of the string doesn't change if an error is thrown.
4830*38fd1498Szrj       */
4831*38fd1498Szrj       basic_string&
4832*38fd1498Szrj       replace(iterator __i1, iterator __i2, const _CharT* __s)
4833*38fd1498Szrj       {
4834*38fd1498Szrj 	__glibcxx_requires_string(__s);
4835*38fd1498Szrj 	return this->replace(__i1, __i2, __s, traits_type::length(__s));
4836*38fd1498Szrj       }
4837*38fd1498Szrj 
4838*38fd1498Szrj       /**
4839*38fd1498Szrj        *  @brief  Replace range of characters with multiple characters
4840*38fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
4841*38fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
4842*38fd1498Szrj        *  @param __n  Number of characters to insert.
4843*38fd1498Szrj        *  @param __c  Character to insert.
4844*38fd1498Szrj        *  @return  Reference to this string.
4845*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4846*38fd1498Szrj        *
4847*38fd1498Szrj        *  Removes the characters in the range [__i1,__i2).  In place,
4848*38fd1498Szrj        *  @a __n copies of @a __c are inserted.  If the length of
4849*38fd1498Szrj        *  result exceeds max_size(), length_error is thrown.  The
4850*38fd1498Szrj        *  value of the string doesn't change if an error is thrown.
4851*38fd1498Szrj       */
4852*38fd1498Szrj       basic_string&
4853*38fd1498Szrj       replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
4854*38fd1498Szrj       {
4855*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4856*38fd1498Szrj 				 && __i2 <= _M_iend());
4857*38fd1498Szrj 	return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
4858*38fd1498Szrj       }
4859*38fd1498Szrj 
4860*38fd1498Szrj       /**
4861*38fd1498Szrj        *  @brief  Replace range of characters with range.
4862*38fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
4863*38fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
4864*38fd1498Szrj        *  @param __k1  Iterator referencing start of range to insert.
4865*38fd1498Szrj        *  @param __k2  Iterator referencing end of range to insert.
4866*38fd1498Szrj        *  @return  Reference to this string.
4867*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4868*38fd1498Szrj        *
4869*38fd1498Szrj        *  Removes the characters in the range [__i1,__i2).  In place,
4870*38fd1498Szrj        *  characters in the range [__k1,__k2) are inserted.  If the
4871*38fd1498Szrj        *  length of result exceeds max_size(), length_error is thrown.
4872*38fd1498Szrj        *  The value of the string doesn't change if an error is
4873*38fd1498Szrj        *  thrown.
4874*38fd1498Szrj       */
4875*38fd1498Szrj       template<class _InputIterator>
4876*38fd1498Szrj         basic_string&
4877*38fd1498Szrj         replace(iterator __i1, iterator __i2,
4878*38fd1498Szrj 		_InputIterator __k1, _InputIterator __k2)
4879*38fd1498Szrj         {
4880*38fd1498Szrj 	  _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4881*38fd1498Szrj 				   && __i2 <= _M_iend());
4882*38fd1498Szrj 	  __glibcxx_requires_valid_range(__k1, __k2);
4883*38fd1498Szrj 	  typedef typename std::__is_integer<_InputIterator>::__type _Integral;
4884*38fd1498Szrj 	  return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
4885*38fd1498Szrj 	}
4886*38fd1498Szrj 
4887*38fd1498Szrj       // Specializations for the common case of pointer and iterator:
4888*38fd1498Szrj       // useful to avoid the overhead of temporary buffering in _M_replace.
4889*38fd1498Szrj       basic_string&
4890*38fd1498Szrj       replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
4891*38fd1498Szrj       {
4892*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4893*38fd1498Szrj 				 && __i2 <= _M_iend());
4894*38fd1498Szrj 	__glibcxx_requires_valid_range(__k1, __k2);
4895*38fd1498Szrj 	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
4896*38fd1498Szrj 			     __k1, __k2 - __k1);
4897*38fd1498Szrj       }
4898*38fd1498Szrj 
4899*38fd1498Szrj       basic_string&
4900*38fd1498Szrj       replace(iterator __i1, iterator __i2,
4901*38fd1498Szrj 	      const _CharT* __k1, const _CharT* __k2)
4902*38fd1498Szrj       {
4903*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4904*38fd1498Szrj 				 && __i2 <= _M_iend());
4905*38fd1498Szrj 	__glibcxx_requires_valid_range(__k1, __k2);
4906*38fd1498Szrj 	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
4907*38fd1498Szrj 			     __k1, __k2 - __k1);
4908*38fd1498Szrj       }
4909*38fd1498Szrj 
4910*38fd1498Szrj       basic_string&
4911*38fd1498Szrj       replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
4912*38fd1498Szrj       {
4913*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4914*38fd1498Szrj 				 && __i2 <= _M_iend());
4915*38fd1498Szrj 	__glibcxx_requires_valid_range(__k1, __k2);
4916*38fd1498Szrj 	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
4917*38fd1498Szrj 			     __k1.base(), __k2 - __k1);
4918*38fd1498Szrj       }
4919*38fd1498Szrj 
4920*38fd1498Szrj       basic_string&
4921*38fd1498Szrj       replace(iterator __i1, iterator __i2,
4922*38fd1498Szrj 	      const_iterator __k1, const_iterator __k2)
4923*38fd1498Szrj       {
4924*38fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4925*38fd1498Szrj 				 && __i2 <= _M_iend());
4926*38fd1498Szrj 	__glibcxx_requires_valid_range(__k1, __k2);
4927*38fd1498Szrj 	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
4928*38fd1498Szrj 			     __k1.base(), __k2 - __k1);
4929*38fd1498Szrj       }
4930*38fd1498Szrj 
4931*38fd1498Szrj #if __cplusplus >= 201103L
4932*38fd1498Szrj       /**
4933*38fd1498Szrj        *  @brief  Replace range of characters with initializer_list.
4934*38fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
4935*38fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
4936*38fd1498Szrj        *  @param __l  The initializer_list of characters to insert.
4937*38fd1498Szrj        *  @return  Reference to this string.
4938*38fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
4939*38fd1498Szrj        *
4940*38fd1498Szrj        *  Removes the characters in the range [__i1,__i2).  In place,
4941*38fd1498Szrj        *  characters in the range [__k1,__k2) are inserted.  If the
4942*38fd1498Szrj        *  length of result exceeds max_size(), length_error is thrown.
4943*38fd1498Szrj        *  The value of the string doesn't change if an error is
4944*38fd1498Szrj        *  thrown.
4945*38fd1498Szrj       */
4946*38fd1498Szrj       basic_string& replace(iterator __i1, iterator __i2,
4947*38fd1498Szrj 			    initializer_list<_CharT> __l)
4948*38fd1498Szrj       { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
4949*38fd1498Szrj #endif // C++11
4950*38fd1498Szrj 
4951*38fd1498Szrj #if __cplusplus > 201402L
4952*38fd1498Szrj       /**
4953*38fd1498Szrj        *  @brief  Replace range of characters with string_view.
4954*38fd1498Szrj        *  @param __pos  The position to replace at.
4955*38fd1498Szrj        *  @param __n    The number of characters to replace.
4956*38fd1498Szrj        *  @param __svt  The object convertible to string_view to insert.
4957*38fd1498Szrj        *  @return  Reference to this string.
4958*38fd1498Szrj       */
4959*38fd1498Szrj       template<typename _Tp>
4960*38fd1498Szrj 	_If_sv<_Tp, basic_string&>
4961*38fd1498Szrj 	replace(size_type __pos, size_type __n, const _Tp& __svt)
4962*38fd1498Szrj 	{
4963*38fd1498Szrj 	  __sv_type __sv = __svt;
4964*38fd1498Szrj 	  return this->replace(__pos, __n, __sv.data(), __sv.size());
4965*38fd1498Szrj 	}
4966*38fd1498Szrj 
4967*38fd1498Szrj       /**
4968*38fd1498Szrj        *  @brief  Replace range of characters with string_view.
4969*38fd1498Szrj        *  @param __pos1  The position to replace at.
4970*38fd1498Szrj        *  @param __n1    The number of characters to replace.
4971*38fd1498Szrj        *  @param __svt   The object convertible to string_view to insert from.
4972*38fd1498Szrj        *  @param __pos2  The position in the string_view to insert from.
4973*38fd1498Szrj        *  @param __n2    The number of characters to insert.
4974*38fd1498Szrj        *  @return  Reference to this string.
4975*38fd1498Szrj       */
4976*38fd1498Szrj       template<typename _Tp>
4977*38fd1498Szrj         _If_sv<_Tp, basic_string&>
4978*38fd1498Szrj         replace(size_type __pos1, size_type __n1, const _Tp& __svt,
4979*38fd1498Szrj 		size_type __pos2, size_type __n2 = npos)
4980*38fd1498Szrj 	{
4981*38fd1498Szrj 	  __sv_type __sv = __svt;
4982*38fd1498Szrj 	  return this->replace(__pos1, __n1,
4983*38fd1498Szrj 	      __sv.data() + __sv._M_check(__pos2, "basic_string::replace"),
4984*38fd1498Szrj 	      __sv._M_limit(__pos2, __n2));
4985*38fd1498Szrj 	}
4986*38fd1498Szrj 
4987*38fd1498Szrj       /**
4988*38fd1498Szrj        *  @brief  Replace range of characters with string_view.
4989*38fd1498Szrj        *  @param __i1    An iterator referencing the start position
4990*38fd1498Szrj           to replace at.
4991*38fd1498Szrj        *  @param __i2    An iterator referencing the end position
4992*38fd1498Szrj           for the replace.
4993*38fd1498Szrj        *  @param __svt   The object convertible to string_view to insert from.
4994*38fd1498Szrj        *  @return  Reference to this string.
4995*38fd1498Szrj       */
4996*38fd1498Szrj       template<typename _Tp>
4997*38fd1498Szrj 	_If_sv<_Tp, basic_string&>
4998*38fd1498Szrj 	replace(const_iterator __i1, const_iterator __i2, const _Tp& __svt)
4999*38fd1498Szrj 	{
5000*38fd1498Szrj 	  __sv_type __sv = __svt;
5001*38fd1498Szrj 	  return this->replace(__i1 - begin(), __i2 - __i1, __sv);
5002*38fd1498Szrj 	}
5003*38fd1498Szrj #endif // C++17
5004*38fd1498Szrj 
5005*38fd1498Szrj     private:
5006*38fd1498Szrj       template<class _Integer>
5007*38fd1498Szrj 	basic_string&
5008*38fd1498Szrj 	_M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
5009*38fd1498Szrj 			    _Integer __val, __true_type)
5010*38fd1498Szrj         { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
5011*38fd1498Szrj 
5012*38fd1498Szrj       template<class _InputIterator>
5013*38fd1498Szrj 	basic_string&
5014*38fd1498Szrj 	_M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
5015*38fd1498Szrj 			    _InputIterator __k2, __false_type);
5016*38fd1498Szrj 
5017*38fd1498Szrj       basic_string&
5018*38fd1498Szrj       _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
5019*38fd1498Szrj 		     _CharT __c);
5020*38fd1498Szrj 
5021*38fd1498Szrj       basic_string&
5022*38fd1498Szrj       _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s,
5023*38fd1498Szrj 		      size_type __n2);
5024*38fd1498Szrj 
5025*38fd1498Szrj       // _S_construct_aux is used to implement the 21.3.1 para 15 which
5026*38fd1498Szrj       // requires special behaviour if _InIter is an integral type
5027*38fd1498Szrj       template<class _InIterator>
5028*38fd1498Szrj         static _CharT*
5029*38fd1498Szrj         _S_construct_aux(_InIterator __beg, _InIterator __end,
5030*38fd1498Szrj 			 const _Alloc& __a, __false_type)
5031*38fd1498Szrj 	{
5032*38fd1498Szrj           typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
5033*38fd1498Szrj           return _S_construct(__beg, __end, __a, _Tag());
5034*38fd1498Szrj 	}
5035*38fd1498Szrj 
5036*38fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
5037*38fd1498Szrj       // 438. Ambiguity in the "do the right thing" clause
5038*38fd1498Szrj       template<class _Integer>
5039*38fd1498Szrj         static _CharT*
5040*38fd1498Szrj         _S_construct_aux(_Integer __beg, _Integer __end,
5041*38fd1498Szrj 			 const _Alloc& __a, __true_type)
5042*38fd1498Szrj         { return _S_construct_aux_2(static_cast<size_type>(__beg),
5043*38fd1498Szrj 				    __end, __a); }
5044*38fd1498Szrj 
5045*38fd1498Szrj       static _CharT*
5046*38fd1498Szrj       _S_construct_aux_2(size_type __req, _CharT __c, const _Alloc& __a)
5047*38fd1498Szrj       { return _S_construct(__req, __c, __a); }
5048*38fd1498Szrj 
5049*38fd1498Szrj       template<class _InIterator>
5050*38fd1498Szrj         static _CharT*
5051*38fd1498Szrj         _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a)
5052*38fd1498Szrj 	{
5053*38fd1498Szrj 	  typedef typename std::__is_integer<_InIterator>::__type _Integral;
5054*38fd1498Szrj 	  return _S_construct_aux(__beg, __end, __a, _Integral());
5055*38fd1498Szrj         }
5056*38fd1498Szrj 
5057*38fd1498Szrj       // For Input Iterators, used in istreambuf_iterators, etc.
5058*38fd1498Szrj       template<class _InIterator>
5059*38fd1498Szrj         static _CharT*
5060*38fd1498Szrj          _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
5061*38fd1498Szrj 		      input_iterator_tag);
5062*38fd1498Szrj 
5063*38fd1498Szrj       // For forward_iterators up to random_access_iterators, used for
5064*38fd1498Szrj       // string::iterator, _CharT*, etc.
5065*38fd1498Szrj       template<class _FwdIterator>
5066*38fd1498Szrj         static _CharT*
5067*38fd1498Szrj         _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a,
5068*38fd1498Szrj 		     forward_iterator_tag);
5069*38fd1498Szrj 
5070*38fd1498Szrj       static _CharT*
5071*38fd1498Szrj       _S_construct(size_type __req, _CharT __c, const _Alloc& __a);
5072*38fd1498Szrj 
5073*38fd1498Szrj     public:
5074*38fd1498Szrj 
5075*38fd1498Szrj       /**
5076*38fd1498Szrj        *  @brief  Copy substring into C string.
5077*38fd1498Szrj        *  @param __s  C string to copy value into.
5078*38fd1498Szrj        *  @param __n  Number of characters to copy.
5079*38fd1498Szrj        *  @param __pos  Index of first character to copy.
5080*38fd1498Szrj        *  @return  Number of characters actually copied
5081*38fd1498Szrj        *  @throw  std::out_of_range  If __pos > size().
5082*38fd1498Szrj        *
5083*38fd1498Szrj        *  Copies up to @a __n characters starting at @a __pos into the
5084*38fd1498Szrj        *  C string @a __s.  If @a __pos is %greater than size(),
5085*38fd1498Szrj        *  out_of_range is thrown.
5086*38fd1498Szrj       */
5087*38fd1498Szrj       size_type
5088*38fd1498Szrj       copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
5089*38fd1498Szrj 
5090*38fd1498Szrj       /**
5091*38fd1498Szrj        *  @brief  Swap contents with another string.
5092*38fd1498Szrj        *  @param __s  String to swap with.
5093*38fd1498Szrj        *
5094*38fd1498Szrj        *  Exchanges the contents of this string with that of @a __s in constant
5095*38fd1498Szrj        *  time.
5096*38fd1498Szrj       */
5097*38fd1498Szrj       // PR 58265, this should be noexcept.
5098*38fd1498Szrj       void
5099*38fd1498Szrj       swap(basic_string& __s);
5100*38fd1498Szrj 
5101*38fd1498Szrj       // String operations:
5102*38fd1498Szrj       /**
5103*38fd1498Szrj        *  @brief  Return const pointer to null-terminated contents.
5104*38fd1498Szrj        *
5105*38fd1498Szrj        *  This is a handle to internal data.  Do not modify or dire things may
5106*38fd1498Szrj        *  happen.
5107*38fd1498Szrj       */
5108*38fd1498Szrj       const _CharT*
5109*38fd1498Szrj       c_str() const _GLIBCXX_NOEXCEPT
5110*38fd1498Szrj       { return _M_data(); }
5111*38fd1498Szrj 
5112*38fd1498Szrj       /**
5113*38fd1498Szrj        *  @brief  Return const pointer to contents.
5114*38fd1498Szrj        *
5115*38fd1498Szrj        *  This is a pointer to internal data.  It is undefined to modify
5116*38fd1498Szrj        *  the contents through the returned pointer. To get a pointer that
5117*38fd1498Szrj        *  allows modifying the contents use @c &str[0] instead,
5118*38fd1498Szrj        *  (or in C++17 the non-const @c str.data() overload).
5119*38fd1498Szrj       */
5120*38fd1498Szrj       const _CharT*
5121*38fd1498Szrj       data() const _GLIBCXX_NOEXCEPT
5122*38fd1498Szrj       { return _M_data(); }
5123*38fd1498Szrj 
5124*38fd1498Szrj #if __cplusplus > 201402L
5125*38fd1498Szrj       /**
5126*38fd1498Szrj        *  @brief  Return non-const pointer to contents.
5127*38fd1498Szrj        *
5128*38fd1498Szrj        *  This is a pointer to the character sequence held by the string.
5129*38fd1498Szrj        *  Modifying the characters in the sequence is allowed.
5130*38fd1498Szrj       */
5131*38fd1498Szrj       _CharT*
5132*38fd1498Szrj       data() noexcept
5133*38fd1498Szrj       { return _M_data(); }
5134*38fd1498Szrj #endif
5135*38fd1498Szrj 
5136*38fd1498Szrj       /**
5137*38fd1498Szrj        *  @brief  Return copy of allocator used to construct this string.
5138*38fd1498Szrj       */
5139*38fd1498Szrj       allocator_type
5140*38fd1498Szrj       get_allocator() const _GLIBCXX_NOEXCEPT
5141*38fd1498Szrj       { return _M_dataplus; }
5142*38fd1498Szrj 
5143*38fd1498Szrj       /**
5144*38fd1498Szrj        *  @brief  Find position of a C substring.
5145*38fd1498Szrj        *  @param __s  C string to locate.
5146*38fd1498Szrj        *  @param __pos  Index of character to search from.
5147*38fd1498Szrj        *  @param __n  Number of characters from @a s to search for.
5148*38fd1498Szrj        *  @return  Index of start of first occurrence.
5149*38fd1498Szrj        *
5150*38fd1498Szrj        *  Starting from @a __pos, searches forward for the first @a
5151*38fd1498Szrj        *  __n characters in @a __s within this string.  If found,
5152*38fd1498Szrj        *  returns the index where it begins.  If not found, returns
5153*38fd1498Szrj        *  npos.
5154*38fd1498Szrj       */
5155*38fd1498Szrj       size_type
5156*38fd1498Szrj       find(const _CharT* __s, size_type __pos, size_type __n) const
5157*38fd1498Szrj       _GLIBCXX_NOEXCEPT;
5158*38fd1498Szrj 
5159*38fd1498Szrj       /**
5160*38fd1498Szrj        *  @brief  Find position of a string.
5161*38fd1498Szrj        *  @param __str  String to locate.
5162*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
5163*38fd1498Szrj        *  @return  Index of start of first occurrence.
5164*38fd1498Szrj        *
5165*38fd1498Szrj        *  Starting from @a __pos, searches forward for value of @a __str within
5166*38fd1498Szrj        *  this string.  If found, returns the index where it begins.  If not
5167*38fd1498Szrj        *  found, returns npos.
5168*38fd1498Szrj       */
5169*38fd1498Szrj       size_type
5170*38fd1498Szrj       find(const basic_string& __str, size_type __pos = 0) const
5171*38fd1498Szrj       _GLIBCXX_NOEXCEPT
5172*38fd1498Szrj       { return this->find(__str.data(), __pos, __str.size()); }
5173*38fd1498Szrj 
5174*38fd1498Szrj       /**
5175*38fd1498Szrj        *  @brief  Find position of a C string.
5176*38fd1498Szrj        *  @param __s  C string to locate.
5177*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
5178*38fd1498Szrj        *  @return  Index of start of first occurrence.
5179*38fd1498Szrj        *
5180*38fd1498Szrj        *  Starting from @a __pos, searches forward for the value of @a
5181*38fd1498Szrj        *  __s within this string.  If found, returns the index where
5182*38fd1498Szrj        *  it begins.  If not found, returns npos.
5183*38fd1498Szrj       */
5184*38fd1498Szrj       size_type
5185*38fd1498Szrj       find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
5186*38fd1498Szrj       {
5187*38fd1498Szrj 	__glibcxx_requires_string(__s);
5188*38fd1498Szrj 	return this->find(__s, __pos, traits_type::length(__s));
5189*38fd1498Szrj       }
5190*38fd1498Szrj 
5191*38fd1498Szrj       /**
5192*38fd1498Szrj        *  @brief  Find position of a character.
5193*38fd1498Szrj        *  @param __c  Character to locate.
5194*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
5195*38fd1498Szrj        *  @return  Index of first occurrence.
5196*38fd1498Szrj        *
5197*38fd1498Szrj        *  Starting from @a __pos, searches forward for @a __c within
5198*38fd1498Szrj        *  this string.  If found, returns the index where it was
5199*38fd1498Szrj        *  found.  If not found, returns npos.
5200*38fd1498Szrj       */
5201*38fd1498Szrj       size_type
5202*38fd1498Szrj       find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
5203*38fd1498Szrj 
5204*38fd1498Szrj #if __cplusplus > 201402L
5205*38fd1498Szrj       /**
5206*38fd1498Szrj        *  @brief  Find position of a string_view.
5207*38fd1498Szrj        *  @param __svt  The object convertible to string_view to locate.
5208*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
5209*38fd1498Szrj        *  @return  Index of start of first occurrence.
5210*38fd1498Szrj       */
5211*38fd1498Szrj       template<typename _Tp>
5212*38fd1498Szrj 	_If_sv<_Tp, size_type>
5213*38fd1498Szrj 	find(const _Tp& __svt, size_type __pos = 0) const
5214*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
5215*38fd1498Szrj 	{
5216*38fd1498Szrj 	  __sv_type __sv = __svt;
5217*38fd1498Szrj 	  return this->find(__sv.data(), __pos, __sv.size());
5218*38fd1498Szrj 	}
5219*38fd1498Szrj #endif // C++17
5220*38fd1498Szrj 
5221*38fd1498Szrj       /**
5222*38fd1498Szrj        *  @brief  Find last position of a string.
5223*38fd1498Szrj        *  @param __str  String to locate.
5224*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
5225*38fd1498Szrj        *  @return  Index of start of last occurrence.
5226*38fd1498Szrj        *
5227*38fd1498Szrj        *  Starting from @a __pos, searches backward for value of @a
5228*38fd1498Szrj        *  __str within this string.  If found, returns the index where
5229*38fd1498Szrj        *  it begins.  If not found, returns npos.
5230*38fd1498Szrj       */
5231*38fd1498Szrj       size_type
5232*38fd1498Szrj       rfind(const basic_string& __str, size_type __pos = npos) const
5233*38fd1498Szrj       _GLIBCXX_NOEXCEPT
5234*38fd1498Szrj       { return this->rfind(__str.data(), __pos, __str.size()); }
5235*38fd1498Szrj 
5236*38fd1498Szrj       /**
5237*38fd1498Szrj        *  @brief  Find last position of a C substring.
5238*38fd1498Szrj        *  @param __s  C string to locate.
5239*38fd1498Szrj        *  @param __pos  Index of character to search back from.
5240*38fd1498Szrj        *  @param __n  Number of characters from s to search for.
5241*38fd1498Szrj        *  @return  Index of start of last occurrence.
5242*38fd1498Szrj        *
5243*38fd1498Szrj        *  Starting from @a __pos, searches backward for the first @a
5244*38fd1498Szrj        *  __n characters in @a __s within this string.  If found,
5245*38fd1498Szrj        *  returns the index where it begins.  If not found, returns
5246*38fd1498Szrj        *  npos.
5247*38fd1498Szrj       */
5248*38fd1498Szrj       size_type
5249*38fd1498Szrj       rfind(const _CharT* __s, size_type __pos, size_type __n) const
5250*38fd1498Szrj       _GLIBCXX_NOEXCEPT;
5251*38fd1498Szrj 
5252*38fd1498Szrj       /**
5253*38fd1498Szrj        *  @brief  Find last position of a C string.
5254*38fd1498Szrj        *  @param __s  C string to locate.
5255*38fd1498Szrj        *  @param __pos  Index of character to start search at (default end).
5256*38fd1498Szrj        *  @return  Index of start of  last occurrence.
5257*38fd1498Szrj        *
5258*38fd1498Szrj        *  Starting from @a __pos, searches backward for the value of
5259*38fd1498Szrj        *  @a __s within this string.  If found, returns the index
5260*38fd1498Szrj        *  where it begins.  If not found, returns npos.
5261*38fd1498Szrj       */
5262*38fd1498Szrj       size_type
5263*38fd1498Szrj       rfind(const _CharT* __s, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
5264*38fd1498Szrj       {
5265*38fd1498Szrj 	__glibcxx_requires_string(__s);
5266*38fd1498Szrj 	return this->rfind(__s, __pos, traits_type::length(__s));
5267*38fd1498Szrj       }
5268*38fd1498Szrj 
5269*38fd1498Szrj       /**
5270*38fd1498Szrj        *  @brief  Find last position of a character.
5271*38fd1498Szrj        *  @param __c  Character to locate.
5272*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
5273*38fd1498Szrj        *  @return  Index of last occurrence.
5274*38fd1498Szrj        *
5275*38fd1498Szrj        *  Starting from @a __pos, searches backward for @a __c within
5276*38fd1498Szrj        *  this string.  If found, returns the index where it was
5277*38fd1498Szrj        *  found.  If not found, returns npos.
5278*38fd1498Szrj       */
5279*38fd1498Szrj       size_type
5280*38fd1498Szrj       rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
5281*38fd1498Szrj 
5282*38fd1498Szrj #if __cplusplus > 201402L
5283*38fd1498Szrj       /**
5284*38fd1498Szrj        *  @brief  Find last position of a string_view.
5285*38fd1498Szrj        *  @param __svt  The object convertible to string_view to locate.
5286*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
5287*38fd1498Szrj        *  @return  Index of start of last occurrence.
5288*38fd1498Szrj       */
5289*38fd1498Szrj       template<typename _Tp>
5290*38fd1498Szrj 	_If_sv<_Tp, size_type>
5291*38fd1498Szrj 	rfind(const _Tp& __svt, size_type __pos = npos) const
5292*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
5293*38fd1498Szrj 	{
5294*38fd1498Szrj 	  __sv_type __sv = __svt;
5295*38fd1498Szrj 	  return this->rfind(__sv.data(), __pos, __sv.size());
5296*38fd1498Szrj 	}
5297*38fd1498Szrj #endif // C++17
5298*38fd1498Szrj 
5299*38fd1498Szrj       /**
5300*38fd1498Szrj        *  @brief  Find position of a character of string.
5301*38fd1498Szrj        *  @param __str  String containing characters to locate.
5302*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
5303*38fd1498Szrj        *  @return  Index of first occurrence.
5304*38fd1498Szrj        *
5305*38fd1498Szrj        *  Starting from @a __pos, searches forward for one of the
5306*38fd1498Szrj        *  characters of @a __str within this string.  If found,
5307*38fd1498Szrj        *  returns the index where it was found.  If not found, returns
5308*38fd1498Szrj        *  npos.
5309*38fd1498Szrj       */
5310*38fd1498Szrj       size_type
5311*38fd1498Szrj       find_first_of(const basic_string& __str, size_type __pos = 0) const
5312*38fd1498Szrj       _GLIBCXX_NOEXCEPT
5313*38fd1498Szrj       { return this->find_first_of(__str.data(), __pos, __str.size()); }
5314*38fd1498Szrj 
5315*38fd1498Szrj       /**
5316*38fd1498Szrj        *  @brief  Find position of a character of C substring.
5317*38fd1498Szrj        *  @param __s  String containing characters to locate.
5318*38fd1498Szrj        *  @param __pos  Index of character to search from.
5319*38fd1498Szrj        *  @param __n  Number of characters from s to search for.
5320*38fd1498Szrj        *  @return  Index of first occurrence.
5321*38fd1498Szrj        *
5322*38fd1498Szrj        *  Starting from @a __pos, searches forward for one of the
5323*38fd1498Szrj        *  first @a __n characters of @a __s within this string.  If
5324*38fd1498Szrj        *  found, returns the index where it was found.  If not found,
5325*38fd1498Szrj        *  returns npos.
5326*38fd1498Szrj       */
5327*38fd1498Szrj       size_type
5328*38fd1498Szrj       find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
5329*38fd1498Szrj       _GLIBCXX_NOEXCEPT;
5330*38fd1498Szrj 
5331*38fd1498Szrj       /**
5332*38fd1498Szrj        *  @brief  Find position of a character of C string.
5333*38fd1498Szrj        *  @param __s  String containing characters to locate.
5334*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
5335*38fd1498Szrj        *  @return  Index of first occurrence.
5336*38fd1498Szrj        *
5337*38fd1498Szrj        *  Starting from @a __pos, searches forward for one of the
5338*38fd1498Szrj        *  characters of @a __s within this string.  If found, returns
5339*38fd1498Szrj        *  the index where it was found.  If not found, returns npos.
5340*38fd1498Szrj       */
5341*38fd1498Szrj       size_type
5342*38fd1498Szrj       find_first_of(const _CharT* __s, size_type __pos = 0) const
5343*38fd1498Szrj       _GLIBCXX_NOEXCEPT
5344*38fd1498Szrj       {
5345*38fd1498Szrj 	__glibcxx_requires_string(__s);
5346*38fd1498Szrj 	return this->find_first_of(__s, __pos, traits_type::length(__s));
5347*38fd1498Szrj       }
5348*38fd1498Szrj 
5349*38fd1498Szrj       /**
5350*38fd1498Szrj        *  @brief  Find position of a character.
5351*38fd1498Szrj        *  @param __c  Character to locate.
5352*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
5353*38fd1498Szrj        *  @return  Index of first occurrence.
5354*38fd1498Szrj        *
5355*38fd1498Szrj        *  Starting from @a __pos, searches forward for the character
5356*38fd1498Szrj        *  @a __c within this string.  If found, returns the index
5357*38fd1498Szrj        *  where it was found.  If not found, returns npos.
5358*38fd1498Szrj        *
5359*38fd1498Szrj        *  Note: equivalent to find(__c, __pos).
5360*38fd1498Szrj       */
5361*38fd1498Szrj       size_type
5362*38fd1498Szrj       find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
5363*38fd1498Szrj       { return this->find(__c, __pos); }
5364*38fd1498Szrj 
5365*38fd1498Szrj #if __cplusplus > 201402L
5366*38fd1498Szrj       /**
5367*38fd1498Szrj        *  @brief  Find position of a character of a string_view.
5368*38fd1498Szrj        *  @param __svt  An object convertible to string_view containing
5369*38fd1498Szrj        *                characters to locate.
5370*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
5371*38fd1498Szrj        *  @return  Index of first occurrence.
5372*38fd1498Szrj       */
5373*38fd1498Szrj       template<typename _Tp>
5374*38fd1498Szrj 	_If_sv<_Tp, size_type>
5375*38fd1498Szrj 	find_first_of(const _Tp& __svt, size_type __pos = 0) const
5376*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
5377*38fd1498Szrj 	{
5378*38fd1498Szrj 	  __sv_type __sv = __svt;
5379*38fd1498Szrj 	  return this->find_first_of(__sv.data(), __pos, __sv.size());
5380*38fd1498Szrj 	}
5381*38fd1498Szrj #endif // C++17
5382*38fd1498Szrj 
5383*38fd1498Szrj       /**
5384*38fd1498Szrj        *  @brief  Find last position of a character of string.
5385*38fd1498Szrj        *  @param __str  String containing characters to locate.
5386*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
5387*38fd1498Szrj        *  @return  Index of last occurrence.
5388*38fd1498Szrj        *
5389*38fd1498Szrj        *  Starting from @a __pos, searches backward for one of the
5390*38fd1498Szrj        *  characters of @a __str within this string.  If found,
5391*38fd1498Szrj        *  returns the index where it was found.  If not found, returns
5392*38fd1498Szrj        *  npos.
5393*38fd1498Szrj       */
5394*38fd1498Szrj       size_type
5395*38fd1498Szrj       find_last_of(const basic_string& __str, size_type __pos = npos) const
5396*38fd1498Szrj       _GLIBCXX_NOEXCEPT
5397*38fd1498Szrj       { return this->find_last_of(__str.data(), __pos, __str.size()); }
5398*38fd1498Szrj 
5399*38fd1498Szrj       /**
5400*38fd1498Szrj        *  @brief  Find last position of a character of C substring.
5401*38fd1498Szrj        *  @param __s  C string containing characters to locate.
5402*38fd1498Szrj        *  @param __pos  Index of character to search back from.
5403*38fd1498Szrj        *  @param __n  Number of characters from s to search for.
5404*38fd1498Szrj        *  @return  Index of last occurrence.
5405*38fd1498Szrj        *
5406*38fd1498Szrj        *  Starting from @a __pos, searches backward for one of the
5407*38fd1498Szrj        *  first @a __n characters of @a __s within this string.  If
5408*38fd1498Szrj        *  found, returns the index where it was found.  If not found,
5409*38fd1498Szrj        *  returns npos.
5410*38fd1498Szrj       */
5411*38fd1498Szrj       size_type
5412*38fd1498Szrj       find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
5413*38fd1498Szrj       _GLIBCXX_NOEXCEPT;
5414*38fd1498Szrj 
5415*38fd1498Szrj       /**
5416*38fd1498Szrj        *  @brief  Find last position of a character of C string.
5417*38fd1498Szrj        *  @param __s  C string containing characters to locate.
5418*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
5419*38fd1498Szrj        *  @return  Index of last occurrence.
5420*38fd1498Szrj        *
5421*38fd1498Szrj        *  Starting from @a __pos, searches backward for one of the
5422*38fd1498Szrj        *  characters of @a __s within this string.  If found, returns
5423*38fd1498Szrj        *  the index where it was found.  If not found, returns npos.
5424*38fd1498Szrj       */
5425*38fd1498Szrj       size_type
5426*38fd1498Szrj       find_last_of(const _CharT* __s, size_type __pos = npos) const
5427*38fd1498Szrj       _GLIBCXX_NOEXCEPT
5428*38fd1498Szrj       {
5429*38fd1498Szrj 	__glibcxx_requires_string(__s);
5430*38fd1498Szrj 	return this->find_last_of(__s, __pos, traits_type::length(__s));
5431*38fd1498Szrj       }
5432*38fd1498Szrj 
5433*38fd1498Szrj       /**
5434*38fd1498Szrj        *  @brief  Find last position of a character.
5435*38fd1498Szrj        *  @param __c  Character to locate.
5436*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
5437*38fd1498Szrj        *  @return  Index of last occurrence.
5438*38fd1498Szrj        *
5439*38fd1498Szrj        *  Starting from @a __pos, searches backward for @a __c within
5440*38fd1498Szrj        *  this string.  If found, returns the index where it was
5441*38fd1498Szrj        *  found.  If not found, returns npos.
5442*38fd1498Szrj        *
5443*38fd1498Szrj        *  Note: equivalent to rfind(__c, __pos).
5444*38fd1498Szrj       */
5445*38fd1498Szrj       size_type
5446*38fd1498Szrj       find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
5447*38fd1498Szrj       { return this->rfind(__c, __pos); }
5448*38fd1498Szrj 
5449*38fd1498Szrj #if __cplusplus > 201402L
5450*38fd1498Szrj       /**
5451*38fd1498Szrj        *  @brief  Find last position of a character of string.
5452*38fd1498Szrj        *  @param __svt  An object convertible to string_view containing
5453*38fd1498Szrj        *                characters to locate.
5454*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
5455*38fd1498Szrj        *  @return  Index of last occurrence.
5456*38fd1498Szrj       */
5457*38fd1498Szrj       template<typename _Tp>
5458*38fd1498Szrj 	_If_sv<_Tp, size_type>
5459*38fd1498Szrj 	find_last_of(const _Tp& __svt, size_type __pos = npos) const
5460*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
5461*38fd1498Szrj 	{
5462*38fd1498Szrj 	  __sv_type __sv = __svt;
5463*38fd1498Szrj 	  return this->find_last_of(__sv.data(), __pos, __sv.size());
5464*38fd1498Szrj 	}
5465*38fd1498Szrj #endif // C++17
5466*38fd1498Szrj 
5467*38fd1498Szrj       /**
5468*38fd1498Szrj        *  @brief  Find position of a character not in string.
5469*38fd1498Szrj        *  @param __str  String containing characters to avoid.
5470*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
5471*38fd1498Szrj        *  @return  Index of first occurrence.
5472*38fd1498Szrj        *
5473*38fd1498Szrj        *  Starting from @a __pos, searches forward for a character not contained
5474*38fd1498Szrj        *  in @a __str within this string.  If found, returns the index where it
5475*38fd1498Szrj        *  was found.  If not found, returns npos.
5476*38fd1498Szrj       */
5477*38fd1498Szrj       size_type
5478*38fd1498Szrj       find_first_not_of(const basic_string& __str, size_type __pos = 0) const
5479*38fd1498Szrj       _GLIBCXX_NOEXCEPT
5480*38fd1498Szrj       { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
5481*38fd1498Szrj 
5482*38fd1498Szrj       /**
5483*38fd1498Szrj        *  @brief  Find position of a character not in C substring.
5484*38fd1498Szrj        *  @param __s  C string containing characters to avoid.
5485*38fd1498Szrj        *  @param __pos  Index of character to search from.
5486*38fd1498Szrj        *  @param __n  Number of characters from __s to consider.
5487*38fd1498Szrj        *  @return  Index of first occurrence.
5488*38fd1498Szrj        *
5489*38fd1498Szrj        *  Starting from @a __pos, searches forward for a character not
5490*38fd1498Szrj        *  contained in the first @a __n characters of @a __s within
5491*38fd1498Szrj        *  this string.  If found, returns the index where it was
5492*38fd1498Szrj        *  found.  If not found, returns npos.
5493*38fd1498Szrj       */
5494*38fd1498Szrj       size_type
5495*38fd1498Szrj       find_first_not_of(const _CharT* __s, size_type __pos,
5496*38fd1498Szrj 			size_type __n) const _GLIBCXX_NOEXCEPT;
5497*38fd1498Szrj 
5498*38fd1498Szrj       /**
5499*38fd1498Szrj        *  @brief  Find position of a character not in C string.
5500*38fd1498Szrj        *  @param __s  C string containing characters to avoid.
5501*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
5502*38fd1498Szrj        *  @return  Index of first occurrence.
5503*38fd1498Szrj        *
5504*38fd1498Szrj        *  Starting from @a __pos, searches forward for a character not
5505*38fd1498Szrj        *  contained in @a __s within this string.  If found, returns
5506*38fd1498Szrj        *  the index where it was found.  If not found, returns npos.
5507*38fd1498Szrj       */
5508*38fd1498Szrj       size_type
5509*38fd1498Szrj       find_first_not_of(const _CharT* __s, size_type __pos = 0) const
5510*38fd1498Szrj       _GLIBCXX_NOEXCEPT
5511*38fd1498Szrj       {
5512*38fd1498Szrj 	__glibcxx_requires_string(__s);
5513*38fd1498Szrj 	return this->find_first_not_of(__s, __pos, traits_type::length(__s));
5514*38fd1498Szrj       }
5515*38fd1498Szrj 
5516*38fd1498Szrj       /**
5517*38fd1498Szrj        *  @brief  Find position of a different character.
5518*38fd1498Szrj        *  @param __c  Character to avoid.
5519*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
5520*38fd1498Szrj        *  @return  Index of first occurrence.
5521*38fd1498Szrj        *
5522*38fd1498Szrj        *  Starting from @a __pos, searches forward for a character
5523*38fd1498Szrj        *  other than @a __c within this string.  If found, returns the
5524*38fd1498Szrj        *  index where it was found.  If not found, returns npos.
5525*38fd1498Szrj       */
5526*38fd1498Szrj       size_type
5527*38fd1498Szrj       find_first_not_of(_CharT __c, size_type __pos = 0) const
5528*38fd1498Szrj       _GLIBCXX_NOEXCEPT;
5529*38fd1498Szrj 
5530*38fd1498Szrj #if __cplusplus > 201402L
5531*38fd1498Szrj       /**
5532*38fd1498Szrj        *  @brief  Find position of a character not in a string_view.
5533*38fd1498Szrj        *  @param __svt  An object convertible to string_view containing
5534*38fd1498Szrj        *                characters to avoid.
5535*38fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
5536*38fd1498Szrj        *  @return  Index of first occurrence.
5537*38fd1498Szrj        */
5538*38fd1498Szrj       template<typename _Tp>
5539*38fd1498Szrj 	_If_sv<_Tp, size_type>
5540*38fd1498Szrj 	find_first_not_of(const _Tp& __svt, size_type __pos = 0) const
5541*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
5542*38fd1498Szrj 	{
5543*38fd1498Szrj 	  __sv_type __sv = __svt;
5544*38fd1498Szrj 	  return this->find_first_not_of(__sv.data(), __pos, __sv.size());
5545*38fd1498Szrj 	}
5546*38fd1498Szrj #endif // C++17
5547*38fd1498Szrj 
5548*38fd1498Szrj       /**
5549*38fd1498Szrj        *  @brief  Find last position of a character not in string.
5550*38fd1498Szrj        *  @param __str  String containing characters to avoid.
5551*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
5552*38fd1498Szrj        *  @return  Index of last occurrence.
5553*38fd1498Szrj        *
5554*38fd1498Szrj        *  Starting from @a __pos, searches backward for a character
5555*38fd1498Szrj        *  not contained in @a __str within this string.  If found,
5556*38fd1498Szrj        *  returns the index where it was found.  If not found, returns
5557*38fd1498Szrj        *  npos.
5558*38fd1498Szrj       */
5559*38fd1498Szrj       size_type
5560*38fd1498Szrj       find_last_not_of(const basic_string& __str, size_type __pos = npos) const
5561*38fd1498Szrj       _GLIBCXX_NOEXCEPT
5562*38fd1498Szrj       { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
5563*38fd1498Szrj 
5564*38fd1498Szrj       /**
5565*38fd1498Szrj        *  @brief  Find last position of a character not in C substring.
5566*38fd1498Szrj        *  @param __s  C string containing characters to avoid.
5567*38fd1498Szrj        *  @param __pos  Index of character to search back from.
5568*38fd1498Szrj        *  @param __n  Number of characters from s to consider.
5569*38fd1498Szrj        *  @return  Index of last occurrence.
5570*38fd1498Szrj        *
5571*38fd1498Szrj        *  Starting from @a __pos, searches backward for a character not
5572*38fd1498Szrj        *  contained in the first @a __n characters of @a __s within this string.
5573*38fd1498Szrj        *  If found, returns the index where it was found.  If not found,
5574*38fd1498Szrj        *  returns npos.
5575*38fd1498Szrj       */
5576*38fd1498Szrj       size_type
5577*38fd1498Szrj       find_last_not_of(const _CharT* __s, size_type __pos,
5578*38fd1498Szrj 		       size_type __n) const _GLIBCXX_NOEXCEPT;
5579*38fd1498Szrj       /**
5580*38fd1498Szrj        *  @brief  Find last position of a character not in C string.
5581*38fd1498Szrj        *  @param __s  C string containing characters to avoid.
5582*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
5583*38fd1498Szrj        *  @return  Index of last occurrence.
5584*38fd1498Szrj        *
5585*38fd1498Szrj        *  Starting from @a __pos, searches backward for a character
5586*38fd1498Szrj        *  not contained in @a __s within this string.  If found,
5587*38fd1498Szrj        *  returns the index where it was found.  If not found, returns
5588*38fd1498Szrj        *  npos.
5589*38fd1498Szrj       */
5590*38fd1498Szrj       size_type
5591*38fd1498Szrj       find_last_not_of(const _CharT* __s, size_type __pos = npos) const
5592*38fd1498Szrj       _GLIBCXX_NOEXCEPT
5593*38fd1498Szrj       {
5594*38fd1498Szrj 	__glibcxx_requires_string(__s);
5595*38fd1498Szrj 	return this->find_last_not_of(__s, __pos, traits_type::length(__s));
5596*38fd1498Szrj       }
5597*38fd1498Szrj 
5598*38fd1498Szrj       /**
5599*38fd1498Szrj        *  @brief  Find last position of a different character.
5600*38fd1498Szrj        *  @param __c  Character to avoid.
5601*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
5602*38fd1498Szrj        *  @return  Index of last occurrence.
5603*38fd1498Szrj        *
5604*38fd1498Szrj        *  Starting from @a __pos, searches backward for a character other than
5605*38fd1498Szrj        *  @a __c within this string.  If found, returns the index where it was
5606*38fd1498Szrj        *  found.  If not found, returns npos.
5607*38fd1498Szrj       */
5608*38fd1498Szrj       size_type
5609*38fd1498Szrj       find_last_not_of(_CharT __c, size_type __pos = npos) const
5610*38fd1498Szrj       _GLIBCXX_NOEXCEPT;
5611*38fd1498Szrj 
5612*38fd1498Szrj #if __cplusplus > 201402L
5613*38fd1498Szrj       /**
5614*38fd1498Szrj        *  @brief  Find last position of a character not in a string_view.
5615*38fd1498Szrj        *  @param __svt  An object convertible to string_view containing
5616*38fd1498Szrj        *                characters to avoid.
5617*38fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
5618*38fd1498Szrj        *  @return  Index of last occurrence.
5619*38fd1498Szrj        */
5620*38fd1498Szrj       template<typename _Tp>
5621*38fd1498Szrj 	_If_sv<_Tp, size_type>
5622*38fd1498Szrj 	find_last_not_of(const _Tp& __svt, size_type __pos = npos) const
5623*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
5624*38fd1498Szrj 	{
5625*38fd1498Szrj 	  __sv_type __sv = __svt;
5626*38fd1498Szrj 	  return this->find_last_not_of(__sv.data(), __pos, __sv.size());
5627*38fd1498Szrj 	}
5628*38fd1498Szrj #endif // C++17
5629*38fd1498Szrj 
5630*38fd1498Szrj       /**
5631*38fd1498Szrj        *  @brief  Get a substring.
5632*38fd1498Szrj        *  @param __pos  Index of first character (default 0).
5633*38fd1498Szrj        *  @param __n  Number of characters in substring (default remainder).
5634*38fd1498Szrj        *  @return  The new string.
5635*38fd1498Szrj        *  @throw  std::out_of_range  If __pos > size().
5636*38fd1498Szrj        *
5637*38fd1498Szrj        *  Construct and return a new string using the @a __n
5638*38fd1498Szrj        *  characters starting at @a __pos.  If the string is too
5639*38fd1498Szrj        *  short, use the remainder of the characters.  If @a __pos is
5640*38fd1498Szrj        *  beyond the end of the string, out_of_range is thrown.
5641*38fd1498Szrj       */
5642*38fd1498Szrj       basic_string
5643*38fd1498Szrj       substr(size_type __pos = 0, size_type __n = npos) const
5644*38fd1498Szrj       { return basic_string(*this,
5645*38fd1498Szrj 			    _M_check(__pos, "basic_string::substr"), __n); }
5646*38fd1498Szrj 
5647*38fd1498Szrj       /**
5648*38fd1498Szrj        *  @brief  Compare to a string.
5649*38fd1498Szrj        *  @param __str  String to compare against.
5650*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
5651*38fd1498Szrj        *
5652*38fd1498Szrj        *  Returns an integer < 0 if this string is ordered before @a
5653*38fd1498Szrj        *  __str, 0 if their values are equivalent, or > 0 if this
5654*38fd1498Szrj        *  string is ordered after @a __str.  Determines the effective
5655*38fd1498Szrj        *  length rlen of the strings to compare as the smallest of
5656*38fd1498Szrj        *  size() and str.size().  The function then compares the two
5657*38fd1498Szrj        *  strings by calling traits::compare(data(), str.data(),rlen).
5658*38fd1498Szrj        *  If the result of the comparison is nonzero returns it,
5659*38fd1498Szrj        *  otherwise the shorter one is ordered first.
5660*38fd1498Szrj       */
5661*38fd1498Szrj       int
5662*38fd1498Szrj       compare(const basic_string& __str) const
5663*38fd1498Szrj       {
5664*38fd1498Szrj 	const size_type __size = this->size();
5665*38fd1498Szrj 	const size_type __osize = __str.size();
5666*38fd1498Szrj 	const size_type __len = std::min(__size, __osize);
5667*38fd1498Szrj 
5668*38fd1498Szrj 	int __r = traits_type::compare(_M_data(), __str.data(), __len);
5669*38fd1498Szrj 	if (!__r)
5670*38fd1498Szrj 	  __r = _S_compare(__size, __osize);
5671*38fd1498Szrj 	return __r;
5672*38fd1498Szrj       }
5673*38fd1498Szrj 
5674*38fd1498Szrj #if __cplusplus > 201402L
5675*38fd1498Szrj       /**
5676*38fd1498Szrj        *  @brief  Compare to a string_view.
5677*38fd1498Szrj        *  @param __svt An object convertible to string_view to compare against.
5678*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
5679*38fd1498Szrj        */
5680*38fd1498Szrj       template<typename _Tp>
5681*38fd1498Szrj 	_If_sv<_Tp, int>
5682*38fd1498Szrj 	compare(const _Tp& __svt) const
5683*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
5684*38fd1498Szrj 	{
5685*38fd1498Szrj 	   __sv_type __sv = __svt;
5686*38fd1498Szrj 	  const size_type __size = this->size();
5687*38fd1498Szrj 	  const size_type __osize = __sv.size();
5688*38fd1498Szrj 	  const size_type __len = std::min(__size, __osize);
5689*38fd1498Szrj 
5690*38fd1498Szrj 	  int __r = traits_type::compare(_M_data(), __sv.data(), __len);
5691*38fd1498Szrj 	  if (!__r)
5692*38fd1498Szrj 	    __r = _S_compare(__size, __osize);
5693*38fd1498Szrj 	  return __r;
5694*38fd1498Szrj 	}
5695*38fd1498Szrj 
5696*38fd1498Szrj       /**
5697*38fd1498Szrj        *  @brief  Compare to a string_view.
5698*38fd1498Szrj        *  @param __pos  A position in the string to start comparing from.
5699*38fd1498Szrj        *  @param __n  The number of characters to compare.
5700*38fd1498Szrj        *  @param __svt  An object convertible to string_view to compare
5701*38fd1498Szrj        *                against.
5702*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
5703*38fd1498Szrj        */
5704*38fd1498Szrj       template<typename _Tp>
5705*38fd1498Szrj 	_If_sv<_Tp, int>
5706*38fd1498Szrj 	compare(size_type __pos, size_type __n, const _Tp& __svt) const
5707*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
5708*38fd1498Szrj 	{
5709*38fd1498Szrj 	  __sv_type __sv = __svt;
5710*38fd1498Szrj 	  return __sv_type(*this).substr(__pos, __n).compare(__sv);
5711*38fd1498Szrj 	}
5712*38fd1498Szrj 
5713*38fd1498Szrj       /**
5714*38fd1498Szrj        *  @brief  Compare to a string_view.
5715*38fd1498Szrj        *  @param __pos1  A position in the string to start comparing from.
5716*38fd1498Szrj        *  @param __n1  The number of characters to compare.
5717*38fd1498Szrj        *  @param __svt   An object convertible to string_view to compare
5718*38fd1498Szrj        *                 against.
5719*38fd1498Szrj        *  @param __pos2  A position in the string_view to start comparing from.
5720*38fd1498Szrj        *  @param __n2  The number of characters to compare.
5721*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
5722*38fd1498Szrj        */
5723*38fd1498Szrj       template<typename _Tp>
5724*38fd1498Szrj 	_If_sv<_Tp, int>
5725*38fd1498Szrj 	compare(size_type __pos1, size_type __n1, const _Tp& __svt,
5726*38fd1498Szrj 		size_type __pos2, size_type __n2 = npos) const
5727*38fd1498Szrj 	noexcept(is_same<_Tp, __sv_type>::value)
5728*38fd1498Szrj 	{
5729*38fd1498Szrj 	  __sv_type __sv = __svt;
5730*38fd1498Szrj 	  return __sv_type(*this)
5731*38fd1498Szrj 	    .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
5732*38fd1498Szrj 	}
5733*38fd1498Szrj #endif // C++17
5734*38fd1498Szrj 
5735*38fd1498Szrj       /**
5736*38fd1498Szrj        *  @brief  Compare substring to a string.
5737*38fd1498Szrj        *  @param __pos  Index of first character of substring.
5738*38fd1498Szrj        *  @param __n  Number of characters in substring.
5739*38fd1498Szrj        *  @param __str  String to compare against.
5740*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
5741*38fd1498Szrj        *
5742*38fd1498Szrj        *  Form the substring of this string from the @a __n characters
5743*38fd1498Szrj        *  starting at @a __pos.  Returns an integer < 0 if the
5744*38fd1498Szrj        *  substring is ordered before @a __str, 0 if their values are
5745*38fd1498Szrj        *  equivalent, or > 0 if the substring is ordered after @a
5746*38fd1498Szrj        *  __str.  Determines the effective length rlen of the strings
5747*38fd1498Szrj        *  to compare as the smallest of the length of the substring
5748*38fd1498Szrj        *  and @a __str.size().  The function then compares the two
5749*38fd1498Szrj        *  strings by calling
5750*38fd1498Szrj        *  traits::compare(substring.data(),str.data(),rlen).  If the
5751*38fd1498Szrj        *  result of the comparison is nonzero returns it, otherwise
5752*38fd1498Szrj        *  the shorter one is ordered first.
5753*38fd1498Szrj       */
5754*38fd1498Szrj       int
5755*38fd1498Szrj       compare(size_type __pos, size_type __n, const basic_string& __str) const;
5756*38fd1498Szrj 
5757*38fd1498Szrj       /**
5758*38fd1498Szrj        *  @brief  Compare substring to a substring.
5759*38fd1498Szrj        *  @param __pos1  Index of first character of substring.
5760*38fd1498Szrj        *  @param __n1  Number of characters in substring.
5761*38fd1498Szrj        *  @param __str  String to compare against.
5762*38fd1498Szrj        *  @param __pos2  Index of first character of substring of str.
5763*38fd1498Szrj        *  @param __n2  Number of characters in substring of str.
5764*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
5765*38fd1498Szrj        *
5766*38fd1498Szrj        *  Form the substring of this string from the @a __n1
5767*38fd1498Szrj        *  characters starting at @a __pos1.  Form the substring of @a
5768*38fd1498Szrj        *  __str from the @a __n2 characters starting at @a __pos2.
5769*38fd1498Szrj        *  Returns an integer < 0 if this substring is ordered before
5770*38fd1498Szrj        *  the substring of @a __str, 0 if their values are equivalent,
5771*38fd1498Szrj        *  or > 0 if this substring is ordered after the substring of
5772*38fd1498Szrj        *  @a __str.  Determines the effective length rlen of the
5773*38fd1498Szrj        *  strings to compare as the smallest of the lengths of the
5774*38fd1498Szrj        *  substrings.  The function then compares the two strings by
5775*38fd1498Szrj        *  calling
5776*38fd1498Szrj        *  traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
5777*38fd1498Szrj        *  If the result of the comparison is nonzero returns it,
5778*38fd1498Szrj        *  otherwise the shorter one is ordered first.
5779*38fd1498Szrj       */
5780*38fd1498Szrj       int
5781*38fd1498Szrj       compare(size_type __pos1, size_type __n1, const basic_string& __str,
5782*38fd1498Szrj 	      size_type __pos2, size_type __n2) const;
5783*38fd1498Szrj 
5784*38fd1498Szrj       /**
5785*38fd1498Szrj        *  @brief  Compare to a C string.
5786*38fd1498Szrj        *  @param __s  C string to compare against.
5787*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
5788*38fd1498Szrj        *
5789*38fd1498Szrj        *  Returns an integer < 0 if this string is ordered before @a __s, 0 if
5790*38fd1498Szrj        *  their values are equivalent, or > 0 if this string is ordered after
5791*38fd1498Szrj        *  @a __s.  Determines the effective length rlen of the strings to
5792*38fd1498Szrj        *  compare as the smallest of size() and the length of a string
5793*38fd1498Szrj        *  constructed from @a __s.  The function then compares the two strings
5794*38fd1498Szrj        *  by calling traits::compare(data(),s,rlen).  If the result of the
5795*38fd1498Szrj        *  comparison is nonzero returns it, otherwise the shorter one is
5796*38fd1498Szrj        *  ordered first.
5797*38fd1498Szrj       */
5798*38fd1498Szrj       int
5799*38fd1498Szrj       compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT;
5800*38fd1498Szrj 
5801*38fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
5802*38fd1498Szrj       // 5 String::compare specification questionable
5803*38fd1498Szrj       /**
5804*38fd1498Szrj        *  @brief  Compare substring to a C string.
5805*38fd1498Szrj        *  @param __pos  Index of first character of substring.
5806*38fd1498Szrj        *  @param __n1  Number of characters in substring.
5807*38fd1498Szrj        *  @param __s  C string to compare against.
5808*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
5809*38fd1498Szrj        *
5810*38fd1498Szrj        *  Form the substring of this string from the @a __n1
5811*38fd1498Szrj        *  characters starting at @a pos.  Returns an integer < 0 if
5812*38fd1498Szrj        *  the substring is ordered before @a __s, 0 if their values
5813*38fd1498Szrj        *  are equivalent, or > 0 if the substring is ordered after @a
5814*38fd1498Szrj        *  __s.  Determines the effective length rlen of the strings to
5815*38fd1498Szrj        *  compare as the smallest of the length of the substring and
5816*38fd1498Szrj        *  the length of a string constructed from @a __s.  The
5817*38fd1498Szrj        *  function then compares the two string by calling
5818*38fd1498Szrj        *  traits::compare(substring.data(),__s,rlen).  If the result of
5819*38fd1498Szrj        *  the comparison is nonzero returns it, otherwise the shorter
5820*38fd1498Szrj        *  one is ordered first.
5821*38fd1498Szrj       */
5822*38fd1498Szrj       int
5823*38fd1498Szrj       compare(size_type __pos, size_type __n1, const _CharT* __s) const;
5824*38fd1498Szrj 
5825*38fd1498Szrj       /**
5826*38fd1498Szrj        *  @brief  Compare substring against a character %array.
5827*38fd1498Szrj        *  @param __pos  Index of first character of substring.
5828*38fd1498Szrj        *  @param __n1  Number of characters in substring.
5829*38fd1498Szrj        *  @param __s  character %array to compare against.
5830*38fd1498Szrj        *  @param __n2  Number of characters of s.
5831*38fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
5832*38fd1498Szrj        *
5833*38fd1498Szrj        *  Form the substring of this string from the @a __n1
5834*38fd1498Szrj        *  characters starting at @a __pos.  Form a string from the
5835*38fd1498Szrj        *  first @a __n2 characters of @a __s.  Returns an integer < 0
5836*38fd1498Szrj        *  if this substring is ordered before the string from @a __s,
5837*38fd1498Szrj        *  0 if their values are equivalent, or > 0 if this substring
5838*38fd1498Szrj        *  is ordered after the string from @a __s.  Determines the
5839*38fd1498Szrj        *  effective length rlen of the strings to compare as the
5840*38fd1498Szrj        *  smallest of the length of the substring and @a __n2.  The
5841*38fd1498Szrj        *  function then compares the two strings by calling
5842*38fd1498Szrj        *  traits::compare(substring.data(),s,rlen).  If the result of
5843*38fd1498Szrj        *  the comparison is nonzero returns it, otherwise the shorter
5844*38fd1498Szrj        *  one is ordered first.
5845*38fd1498Szrj        *
5846*38fd1498Szrj        *  NB: s must have at least n2 characters, &apos;\\0&apos; has
5847*38fd1498Szrj        *  no special meaning.
5848*38fd1498Szrj       */
5849*38fd1498Szrj       int
5850*38fd1498Szrj       compare(size_type __pos, size_type __n1, const _CharT* __s,
5851*38fd1498Szrj 	      size_type __n2) const;
5852*38fd1498Szrj 
5853*38fd1498Szrj # ifdef _GLIBCXX_TM_TS_INTERNAL
5854*38fd1498Szrj       friend void
5855*38fd1498Szrj       ::_txnal_cow_string_C1_for_exceptions(void* that, const char* s,
5856*38fd1498Szrj 					    void* exc);
5857*38fd1498Szrj       friend const char*
5858*38fd1498Szrj       ::_txnal_cow_string_c_str(const void *that);
5859*38fd1498Szrj       friend void
5860*38fd1498Szrj       ::_txnal_cow_string_D1(void *that);
5861*38fd1498Szrj       friend void
5862*38fd1498Szrj       ::_txnal_cow_string_D1_commit(void *that);
5863*38fd1498Szrj # endif
5864*38fd1498Szrj   };
5865*38fd1498Szrj #endif  // !_GLIBCXX_USE_CXX11_ABI
5866*38fd1498Szrj 
5867*38fd1498Szrj #if __cpp_deduction_guides >= 201606
5868*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CXX11
5869*38fd1498Szrj   template<typename _InputIterator, typename _CharT
5870*38fd1498Szrj 	     = typename iterator_traits<_InputIterator>::value_type,
5871*38fd1498Szrj 	   typename _Allocator = allocator<_CharT>,
5872*38fd1498Szrj 	   typename = _RequireInputIter<_InputIterator>,
5873*38fd1498Szrj 	   typename = _RequireAllocator<_Allocator>>
5874*38fd1498Szrj     basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
5875*38fd1498Szrj       -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
5876*38fd1498Szrj _GLIBCXX_END_NAMESPACE_CXX11
5877*38fd1498Szrj #endif
5878*38fd1498Szrj 
5879*38fd1498Szrj   // operator+
5880*38fd1498Szrj   /**
5881*38fd1498Szrj    *  @brief  Concatenate two strings.
5882*38fd1498Szrj    *  @param __lhs  First string.
5883*38fd1498Szrj    *  @param __rhs  Last string.
5884*38fd1498Szrj    *  @return  New string with value of @a __lhs followed by @a __rhs.
5885*38fd1498Szrj    */
5886*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
5887*38fd1498Szrj     basic_string<_CharT, _Traits, _Alloc>
5888*38fd1498Szrj     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
5889*38fd1498Szrj 	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
5890*38fd1498Szrj     {
5891*38fd1498Szrj       basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
5892*38fd1498Szrj       __str.append(__rhs);
5893*38fd1498Szrj       return __str;
5894*38fd1498Szrj     }
5895*38fd1498Szrj 
5896*38fd1498Szrj   /**
5897*38fd1498Szrj    *  @brief  Concatenate C string and string.
5898*38fd1498Szrj    *  @param __lhs  First string.
5899*38fd1498Szrj    *  @param __rhs  Last string.
5900*38fd1498Szrj    *  @return  New string with value of @a __lhs followed by @a __rhs.
5901*38fd1498Szrj    */
5902*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
5903*38fd1498Szrj     basic_string<_CharT,_Traits,_Alloc>
5904*38fd1498Szrj     operator+(const _CharT* __lhs,
5905*38fd1498Szrj 	      const basic_string<_CharT,_Traits,_Alloc>& __rhs);
5906*38fd1498Szrj 
5907*38fd1498Szrj   /**
5908*38fd1498Szrj    *  @brief  Concatenate character and string.
5909*38fd1498Szrj    *  @param __lhs  First string.
5910*38fd1498Szrj    *  @param __rhs  Last string.
5911*38fd1498Szrj    *  @return  New string with @a __lhs followed by @a __rhs.
5912*38fd1498Szrj    */
5913*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
5914*38fd1498Szrj     basic_string<_CharT,_Traits,_Alloc>
5915*38fd1498Szrj     operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs);
5916*38fd1498Szrj 
5917*38fd1498Szrj   /**
5918*38fd1498Szrj    *  @brief  Concatenate string and C string.
5919*38fd1498Szrj    *  @param __lhs  First string.
5920*38fd1498Szrj    *  @param __rhs  Last string.
5921*38fd1498Szrj    *  @return  New string with @a __lhs followed by @a __rhs.
5922*38fd1498Szrj    */
5923*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
5924*38fd1498Szrj     inline basic_string<_CharT, _Traits, _Alloc>
5925*38fd1498Szrj     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
5926*38fd1498Szrj 	      const _CharT* __rhs)
5927*38fd1498Szrj     {
5928*38fd1498Szrj       basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
5929*38fd1498Szrj       __str.append(__rhs);
5930*38fd1498Szrj       return __str;
5931*38fd1498Szrj     }
5932*38fd1498Szrj 
5933*38fd1498Szrj   /**
5934*38fd1498Szrj    *  @brief  Concatenate string and character.
5935*38fd1498Szrj    *  @param __lhs  First string.
5936*38fd1498Szrj    *  @param __rhs  Last string.
5937*38fd1498Szrj    *  @return  New string with @a __lhs followed by @a __rhs.
5938*38fd1498Szrj    */
5939*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
5940*38fd1498Szrj     inline basic_string<_CharT, _Traits, _Alloc>
5941*38fd1498Szrj     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
5942*38fd1498Szrj     {
5943*38fd1498Szrj       typedef basic_string<_CharT, _Traits, _Alloc>	__string_type;
5944*38fd1498Szrj       typedef typename __string_type::size_type		__size_type;
5945*38fd1498Szrj       __string_type __str(__lhs);
5946*38fd1498Szrj       __str.append(__size_type(1), __rhs);
5947*38fd1498Szrj       return __str;
5948*38fd1498Szrj     }
5949*38fd1498Szrj 
5950*38fd1498Szrj #if __cplusplus >= 201103L
5951*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
5952*38fd1498Szrj     inline basic_string<_CharT, _Traits, _Alloc>
5953*38fd1498Szrj     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
5954*38fd1498Szrj 	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
5955*38fd1498Szrj     { return std::move(__lhs.append(__rhs)); }
5956*38fd1498Szrj 
5957*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
5958*38fd1498Szrj     inline basic_string<_CharT, _Traits, _Alloc>
5959*38fd1498Szrj     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
5960*38fd1498Szrj 	      basic_string<_CharT, _Traits, _Alloc>&& __rhs)
5961*38fd1498Szrj     { return std::move(__rhs.insert(0, __lhs)); }
5962*38fd1498Szrj 
5963*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
5964*38fd1498Szrj     inline basic_string<_CharT, _Traits, _Alloc>
5965*38fd1498Szrj     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
5966*38fd1498Szrj 	      basic_string<_CharT, _Traits, _Alloc>&& __rhs)
5967*38fd1498Szrj     {
5968*38fd1498Szrj       const auto __size = __lhs.size() + __rhs.size();
5969*38fd1498Szrj       const bool __cond = (__size > __lhs.capacity()
5970*38fd1498Szrj 			   && __size <= __rhs.capacity());
5971*38fd1498Szrj       return __cond ? std::move(__rhs.insert(0, __lhs))
5972*38fd1498Szrj 	            : std::move(__lhs.append(__rhs));
5973*38fd1498Szrj     }
5974*38fd1498Szrj 
5975*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
5976*38fd1498Szrj     inline basic_string<_CharT, _Traits, _Alloc>
5977*38fd1498Szrj     operator+(const _CharT* __lhs,
5978*38fd1498Szrj 	      basic_string<_CharT, _Traits, _Alloc>&& __rhs)
5979*38fd1498Szrj     { return std::move(__rhs.insert(0, __lhs)); }
5980*38fd1498Szrj 
5981*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
5982*38fd1498Szrj     inline basic_string<_CharT, _Traits, _Alloc>
5983*38fd1498Szrj     operator+(_CharT __lhs,
5984*38fd1498Szrj 	      basic_string<_CharT, _Traits, _Alloc>&& __rhs)
5985*38fd1498Szrj     { return std::move(__rhs.insert(0, 1, __lhs)); }
5986*38fd1498Szrj 
5987*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
5988*38fd1498Szrj     inline basic_string<_CharT, _Traits, _Alloc>
5989*38fd1498Szrj     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
5990*38fd1498Szrj 	      const _CharT* __rhs)
5991*38fd1498Szrj     { return std::move(__lhs.append(__rhs)); }
5992*38fd1498Szrj 
5993*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
5994*38fd1498Szrj     inline basic_string<_CharT, _Traits, _Alloc>
5995*38fd1498Szrj     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
5996*38fd1498Szrj 	      _CharT __rhs)
5997*38fd1498Szrj     { return std::move(__lhs.append(1, __rhs)); }
5998*38fd1498Szrj #endif
5999*38fd1498Szrj 
6000*38fd1498Szrj   // operator ==
6001*38fd1498Szrj   /**
6002*38fd1498Szrj    *  @brief  Test equivalence of two strings.
6003*38fd1498Szrj    *  @param __lhs  First string.
6004*38fd1498Szrj    *  @param __rhs  Second string.
6005*38fd1498Szrj    *  @return  True if @a __lhs.compare(@a __rhs) == 0.  False otherwise.
6006*38fd1498Szrj    */
6007*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6008*38fd1498Szrj     inline bool
6009*38fd1498Szrj     operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6010*38fd1498Szrj 	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6011*38fd1498Szrj     _GLIBCXX_NOEXCEPT
6012*38fd1498Szrj     { return __lhs.compare(__rhs) == 0; }
6013*38fd1498Szrj 
6014*38fd1498Szrj   template<typename _CharT>
6015*38fd1498Szrj     inline
6016*38fd1498Szrj     typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, bool>::__type
6017*38fd1498Szrj     operator==(const basic_string<_CharT>& __lhs,
6018*38fd1498Szrj 	       const basic_string<_CharT>& __rhs) _GLIBCXX_NOEXCEPT
6019*38fd1498Szrj     { return (__lhs.size() == __rhs.size()
6020*38fd1498Szrj 	      && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
6021*38fd1498Szrj 						    __lhs.size())); }
6022*38fd1498Szrj 
6023*38fd1498Szrj   /**
6024*38fd1498Szrj    *  @brief  Test equivalence of C string and string.
6025*38fd1498Szrj    *  @param __lhs  C string.
6026*38fd1498Szrj    *  @param __rhs  String.
6027*38fd1498Szrj    *  @return  True if @a __rhs.compare(@a __lhs) == 0.  False otherwise.
6028*38fd1498Szrj    */
6029*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6030*38fd1498Szrj     inline bool
6031*38fd1498Szrj     operator==(const _CharT* __lhs,
6032*38fd1498Szrj 	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6033*38fd1498Szrj     { return __rhs.compare(__lhs) == 0; }
6034*38fd1498Szrj 
6035*38fd1498Szrj   /**
6036*38fd1498Szrj    *  @brief  Test equivalence of string and C string.
6037*38fd1498Szrj    *  @param __lhs  String.
6038*38fd1498Szrj    *  @param __rhs  C string.
6039*38fd1498Szrj    *  @return  True if @a __lhs.compare(@a __rhs) == 0.  False otherwise.
6040*38fd1498Szrj    */
6041*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6042*38fd1498Szrj     inline bool
6043*38fd1498Szrj     operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6044*38fd1498Szrj 	       const _CharT* __rhs)
6045*38fd1498Szrj     { return __lhs.compare(__rhs) == 0; }
6046*38fd1498Szrj 
6047*38fd1498Szrj   // operator !=
6048*38fd1498Szrj   /**
6049*38fd1498Szrj    *  @brief  Test difference of two strings.
6050*38fd1498Szrj    *  @param __lhs  First string.
6051*38fd1498Szrj    *  @param __rhs  Second string.
6052*38fd1498Szrj    *  @return  True if @a __lhs.compare(@a __rhs) != 0.  False otherwise.
6053*38fd1498Szrj    */
6054*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6055*38fd1498Szrj     inline bool
6056*38fd1498Szrj     operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6057*38fd1498Szrj 	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6058*38fd1498Szrj     _GLIBCXX_NOEXCEPT
6059*38fd1498Szrj     { return !(__lhs == __rhs); }
6060*38fd1498Szrj 
6061*38fd1498Szrj   /**
6062*38fd1498Szrj    *  @brief  Test difference of C string and string.
6063*38fd1498Szrj    *  @param __lhs  C string.
6064*38fd1498Szrj    *  @param __rhs  String.
6065*38fd1498Szrj    *  @return  True if @a __rhs.compare(@a __lhs) != 0.  False otherwise.
6066*38fd1498Szrj    */
6067*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6068*38fd1498Szrj     inline bool
6069*38fd1498Szrj     operator!=(const _CharT* __lhs,
6070*38fd1498Szrj 	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6071*38fd1498Szrj     { return !(__lhs == __rhs); }
6072*38fd1498Szrj 
6073*38fd1498Szrj   /**
6074*38fd1498Szrj    *  @brief  Test difference of string and C string.
6075*38fd1498Szrj    *  @param __lhs  String.
6076*38fd1498Szrj    *  @param __rhs  C string.
6077*38fd1498Szrj    *  @return  True if @a __lhs.compare(@a __rhs) != 0.  False otherwise.
6078*38fd1498Szrj    */
6079*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6080*38fd1498Szrj     inline bool
6081*38fd1498Szrj     operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6082*38fd1498Szrj 	       const _CharT* __rhs)
6083*38fd1498Szrj     { return !(__lhs == __rhs); }
6084*38fd1498Szrj 
6085*38fd1498Szrj   // operator <
6086*38fd1498Szrj   /**
6087*38fd1498Szrj    *  @brief  Test if string precedes string.
6088*38fd1498Szrj    *  @param __lhs  First string.
6089*38fd1498Szrj    *  @param __rhs  Second string.
6090*38fd1498Szrj    *  @return  True if @a __lhs precedes @a __rhs.  False otherwise.
6091*38fd1498Szrj    */
6092*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6093*38fd1498Szrj     inline bool
6094*38fd1498Szrj     operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6095*38fd1498Szrj 	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6096*38fd1498Szrj     _GLIBCXX_NOEXCEPT
6097*38fd1498Szrj     { return __lhs.compare(__rhs) < 0; }
6098*38fd1498Szrj 
6099*38fd1498Szrj   /**
6100*38fd1498Szrj    *  @brief  Test if string precedes C string.
6101*38fd1498Szrj    *  @param __lhs  String.
6102*38fd1498Szrj    *  @param __rhs  C string.
6103*38fd1498Szrj    *  @return  True if @a __lhs precedes @a __rhs.  False otherwise.
6104*38fd1498Szrj    */
6105*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6106*38fd1498Szrj     inline bool
6107*38fd1498Szrj     operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6108*38fd1498Szrj 	      const _CharT* __rhs)
6109*38fd1498Szrj     { return __lhs.compare(__rhs) < 0; }
6110*38fd1498Szrj 
6111*38fd1498Szrj   /**
6112*38fd1498Szrj    *  @brief  Test if C string precedes string.
6113*38fd1498Szrj    *  @param __lhs  C string.
6114*38fd1498Szrj    *  @param __rhs  String.
6115*38fd1498Szrj    *  @return  True if @a __lhs precedes @a __rhs.  False otherwise.
6116*38fd1498Szrj    */
6117*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6118*38fd1498Szrj     inline bool
6119*38fd1498Szrj     operator<(const _CharT* __lhs,
6120*38fd1498Szrj 	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6121*38fd1498Szrj     { return __rhs.compare(__lhs) > 0; }
6122*38fd1498Szrj 
6123*38fd1498Szrj   // operator >
6124*38fd1498Szrj   /**
6125*38fd1498Szrj    *  @brief  Test if string follows string.
6126*38fd1498Szrj    *  @param __lhs  First string.
6127*38fd1498Szrj    *  @param __rhs  Second string.
6128*38fd1498Szrj    *  @return  True if @a __lhs follows @a __rhs.  False otherwise.
6129*38fd1498Szrj    */
6130*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6131*38fd1498Szrj     inline bool
6132*38fd1498Szrj     operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6133*38fd1498Szrj 	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6134*38fd1498Szrj     _GLIBCXX_NOEXCEPT
6135*38fd1498Szrj     { return __lhs.compare(__rhs) > 0; }
6136*38fd1498Szrj 
6137*38fd1498Szrj   /**
6138*38fd1498Szrj    *  @brief  Test if string follows C string.
6139*38fd1498Szrj    *  @param __lhs  String.
6140*38fd1498Szrj    *  @param __rhs  C string.
6141*38fd1498Szrj    *  @return  True if @a __lhs follows @a __rhs.  False otherwise.
6142*38fd1498Szrj    */
6143*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6144*38fd1498Szrj     inline bool
6145*38fd1498Szrj     operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6146*38fd1498Szrj 	      const _CharT* __rhs)
6147*38fd1498Szrj     { return __lhs.compare(__rhs) > 0; }
6148*38fd1498Szrj 
6149*38fd1498Szrj   /**
6150*38fd1498Szrj    *  @brief  Test if C string follows string.
6151*38fd1498Szrj    *  @param __lhs  C string.
6152*38fd1498Szrj    *  @param __rhs  String.
6153*38fd1498Szrj    *  @return  True if @a __lhs follows @a __rhs.  False otherwise.
6154*38fd1498Szrj    */
6155*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6156*38fd1498Szrj     inline bool
6157*38fd1498Szrj     operator>(const _CharT* __lhs,
6158*38fd1498Szrj 	      const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6159*38fd1498Szrj     { return __rhs.compare(__lhs) < 0; }
6160*38fd1498Szrj 
6161*38fd1498Szrj   // operator <=
6162*38fd1498Szrj   /**
6163*38fd1498Szrj    *  @brief  Test if string doesn't follow string.
6164*38fd1498Szrj    *  @param __lhs  First string.
6165*38fd1498Szrj    *  @param __rhs  Second string.
6166*38fd1498Szrj    *  @return  True if @a __lhs doesn't follow @a __rhs.  False otherwise.
6167*38fd1498Szrj    */
6168*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6169*38fd1498Szrj     inline bool
6170*38fd1498Szrj     operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6171*38fd1498Szrj 	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6172*38fd1498Szrj     _GLIBCXX_NOEXCEPT
6173*38fd1498Szrj     { return __lhs.compare(__rhs) <= 0; }
6174*38fd1498Szrj 
6175*38fd1498Szrj   /**
6176*38fd1498Szrj    *  @brief  Test if string doesn't follow C string.
6177*38fd1498Szrj    *  @param __lhs  String.
6178*38fd1498Szrj    *  @param __rhs  C string.
6179*38fd1498Szrj    *  @return  True if @a __lhs doesn't follow @a __rhs.  False otherwise.
6180*38fd1498Szrj    */
6181*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6182*38fd1498Szrj     inline bool
6183*38fd1498Szrj     operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6184*38fd1498Szrj 	       const _CharT* __rhs)
6185*38fd1498Szrj     { return __lhs.compare(__rhs) <= 0; }
6186*38fd1498Szrj 
6187*38fd1498Szrj   /**
6188*38fd1498Szrj    *  @brief  Test if C string doesn't follow string.
6189*38fd1498Szrj    *  @param __lhs  C string.
6190*38fd1498Szrj    *  @param __rhs  String.
6191*38fd1498Szrj    *  @return  True if @a __lhs doesn't follow @a __rhs.  False otherwise.
6192*38fd1498Szrj    */
6193*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6194*38fd1498Szrj     inline bool
6195*38fd1498Szrj     operator<=(const _CharT* __lhs,
6196*38fd1498Szrj 	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6197*38fd1498Szrj     { return __rhs.compare(__lhs) >= 0; }
6198*38fd1498Szrj 
6199*38fd1498Szrj   // operator >=
6200*38fd1498Szrj   /**
6201*38fd1498Szrj    *  @brief  Test if string doesn't precede string.
6202*38fd1498Szrj    *  @param __lhs  First string.
6203*38fd1498Szrj    *  @param __rhs  Second string.
6204*38fd1498Szrj    *  @return  True if @a __lhs doesn't precede @a __rhs.  False otherwise.
6205*38fd1498Szrj    */
6206*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6207*38fd1498Szrj     inline bool
6208*38fd1498Szrj     operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6209*38fd1498Szrj 	       const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6210*38fd1498Szrj     _GLIBCXX_NOEXCEPT
6211*38fd1498Szrj     { return __lhs.compare(__rhs) >= 0; }
6212*38fd1498Szrj 
6213*38fd1498Szrj   /**
6214*38fd1498Szrj    *  @brief  Test if string doesn't precede C string.
6215*38fd1498Szrj    *  @param __lhs  String.
6216*38fd1498Szrj    *  @param __rhs  C string.
6217*38fd1498Szrj    *  @return  True if @a __lhs doesn't precede @a __rhs.  False otherwise.
6218*38fd1498Szrj    */
6219*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6220*38fd1498Szrj     inline bool
6221*38fd1498Szrj     operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6222*38fd1498Szrj 	       const _CharT* __rhs)
6223*38fd1498Szrj     { return __lhs.compare(__rhs) >= 0; }
6224*38fd1498Szrj 
6225*38fd1498Szrj   /**
6226*38fd1498Szrj    *  @brief  Test if C string doesn't precede string.
6227*38fd1498Szrj    *  @param __lhs  C string.
6228*38fd1498Szrj    *  @param __rhs  String.
6229*38fd1498Szrj    *  @return  True if @a __lhs doesn't precede @a __rhs.  False otherwise.
6230*38fd1498Szrj    */
6231*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6232*38fd1498Szrj     inline bool
6233*38fd1498Szrj     operator>=(const _CharT* __lhs,
6234*38fd1498Szrj 	     const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6235*38fd1498Szrj     { return __rhs.compare(__lhs) <= 0; }
6236*38fd1498Szrj 
6237*38fd1498Szrj   /**
6238*38fd1498Szrj    *  @brief  Swap contents of two strings.
6239*38fd1498Szrj    *  @param __lhs  First string.
6240*38fd1498Szrj    *  @param __rhs  Second string.
6241*38fd1498Szrj    *
6242*38fd1498Szrj    *  Exchanges the contents of @a __lhs and @a __rhs in constant time.
6243*38fd1498Szrj    */
6244*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6245*38fd1498Szrj     inline void
6246*38fd1498Szrj     swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
6247*38fd1498Szrj 	 basic_string<_CharT, _Traits, _Alloc>& __rhs)
6248*38fd1498Szrj     _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
6249*38fd1498Szrj     { __lhs.swap(__rhs); }
6250*38fd1498Szrj 
6251*38fd1498Szrj 
6252*38fd1498Szrj   /**
6253*38fd1498Szrj    *  @brief  Read stream into a string.
6254*38fd1498Szrj    *  @param __is  Input stream.
6255*38fd1498Szrj    *  @param __str  Buffer to store into.
6256*38fd1498Szrj    *  @return  Reference to the input stream.
6257*38fd1498Szrj    *
6258*38fd1498Szrj    *  Stores characters from @a __is into @a __str until whitespace is
6259*38fd1498Szrj    *  found, the end of the stream is encountered, or str.max_size()
6260*38fd1498Szrj    *  is reached.  If is.width() is non-zero, that is the limit on the
6261*38fd1498Szrj    *  number of characters stored into @a __str.  Any previous
6262*38fd1498Szrj    *  contents of @a __str are erased.
6263*38fd1498Szrj    */
6264*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6265*38fd1498Szrj     basic_istream<_CharT, _Traits>&
6266*38fd1498Szrj     operator>>(basic_istream<_CharT, _Traits>& __is,
6267*38fd1498Szrj 	       basic_string<_CharT, _Traits, _Alloc>& __str);
6268*38fd1498Szrj 
6269*38fd1498Szrj   template<>
6270*38fd1498Szrj     basic_istream<char>&
6271*38fd1498Szrj     operator>>(basic_istream<char>& __is, basic_string<char>& __str);
6272*38fd1498Szrj 
6273*38fd1498Szrj   /**
6274*38fd1498Szrj    *  @brief  Write string to a stream.
6275*38fd1498Szrj    *  @param __os  Output stream.
6276*38fd1498Szrj    *  @param __str  String to write out.
6277*38fd1498Szrj    *  @return  Reference to the output stream.
6278*38fd1498Szrj    *
6279*38fd1498Szrj    *  Output characters of @a __str into os following the same rules as for
6280*38fd1498Szrj    *  writing a C string.
6281*38fd1498Szrj    */
6282*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6283*38fd1498Szrj     inline basic_ostream<_CharT, _Traits>&
6284*38fd1498Szrj     operator<<(basic_ostream<_CharT, _Traits>& __os,
6285*38fd1498Szrj 	       const basic_string<_CharT, _Traits, _Alloc>& __str)
6286*38fd1498Szrj     {
6287*38fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
6288*38fd1498Szrj       // 586. string inserter not a formatted function
6289*38fd1498Szrj       return __ostream_insert(__os, __str.data(), __str.size());
6290*38fd1498Szrj     }
6291*38fd1498Szrj 
6292*38fd1498Szrj   /**
6293*38fd1498Szrj    *  @brief  Read a line from stream into a string.
6294*38fd1498Szrj    *  @param __is  Input stream.
6295*38fd1498Szrj    *  @param __str  Buffer to store into.
6296*38fd1498Szrj    *  @param __delim  Character marking end of line.
6297*38fd1498Szrj    *  @return  Reference to the input stream.
6298*38fd1498Szrj    *
6299*38fd1498Szrj    *  Stores characters from @a __is into @a __str until @a __delim is
6300*38fd1498Szrj    *  found, the end of the stream is encountered, or str.max_size()
6301*38fd1498Szrj    *  is reached.  Any previous contents of @a __str are erased.  If
6302*38fd1498Szrj    *  @a __delim is encountered, it is extracted but not stored into
6303*38fd1498Szrj    *  @a __str.
6304*38fd1498Szrj    */
6305*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6306*38fd1498Szrj     basic_istream<_CharT, _Traits>&
6307*38fd1498Szrj     getline(basic_istream<_CharT, _Traits>& __is,
6308*38fd1498Szrj 	    basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
6309*38fd1498Szrj 
6310*38fd1498Szrj   /**
6311*38fd1498Szrj    *  @brief  Read a line from stream into a string.
6312*38fd1498Szrj    *  @param __is  Input stream.
6313*38fd1498Szrj    *  @param __str  Buffer to store into.
6314*38fd1498Szrj    *  @return  Reference to the input stream.
6315*38fd1498Szrj    *
6316*38fd1498Szrj    *  Stores characters from is into @a __str until &apos;\n&apos; is
6317*38fd1498Szrj    *  found, the end of the stream is encountered, or str.max_size()
6318*38fd1498Szrj    *  is reached.  Any previous contents of @a __str are erased.  If
6319*38fd1498Szrj    *  end of line is encountered, it is extracted but not stored into
6320*38fd1498Szrj    *  @a __str.
6321*38fd1498Szrj    */
6322*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6323*38fd1498Szrj     inline basic_istream<_CharT, _Traits>&
6324*38fd1498Szrj     getline(basic_istream<_CharT, _Traits>& __is,
6325*38fd1498Szrj 	    basic_string<_CharT, _Traits, _Alloc>& __str)
6326*38fd1498Szrj     { return std::getline(__is, __str, __is.widen('\n')); }
6327*38fd1498Szrj 
6328*38fd1498Szrj #if __cplusplus >= 201103L
6329*38fd1498Szrj   /// Read a line from an rvalue stream into a string.
6330*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6331*38fd1498Szrj     inline basic_istream<_CharT, _Traits>&
6332*38fd1498Szrj     getline(basic_istream<_CharT, _Traits>&& __is,
6333*38fd1498Szrj 	    basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
6334*38fd1498Szrj     { return std::getline(__is, __str, __delim); }
6335*38fd1498Szrj 
6336*38fd1498Szrj   /// Read a line from an rvalue stream into a string.
6337*38fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc>
6338*38fd1498Szrj     inline basic_istream<_CharT, _Traits>&
6339*38fd1498Szrj     getline(basic_istream<_CharT, _Traits>&& __is,
6340*38fd1498Szrj 	    basic_string<_CharT, _Traits, _Alloc>& __str)
6341*38fd1498Szrj     { return std::getline(__is, __str); }
6342*38fd1498Szrj #endif
6343*38fd1498Szrj 
6344*38fd1498Szrj   template<>
6345*38fd1498Szrj     basic_istream<char>&
6346*38fd1498Szrj     getline(basic_istream<char>& __in, basic_string<char>& __str,
6347*38fd1498Szrj 	    char __delim);
6348*38fd1498Szrj 
6349*38fd1498Szrj #ifdef _GLIBCXX_USE_WCHAR_T
6350*38fd1498Szrj   template<>
6351*38fd1498Szrj     basic_istream<wchar_t>&
6352*38fd1498Szrj     getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
6353*38fd1498Szrj 	    wchar_t __delim);
6354*38fd1498Szrj #endif
6355*38fd1498Szrj 
6356*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
6357*38fd1498Szrj } // namespace
6358*38fd1498Szrj 
6359*38fd1498Szrj #if __cplusplus >= 201103L
6360*38fd1498Szrj 
6361*38fd1498Szrj #include <ext/string_conversions.h>
6362*38fd1498Szrj 
6363*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default)
6364*38fd1498Szrj {
6365*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
6366*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CXX11
6367*38fd1498Szrj 
6368*38fd1498Szrj #if _GLIBCXX_USE_C99_STDLIB
6369*38fd1498Szrj   // 21.4 Numeric Conversions [string.conversions].
6370*38fd1498Szrj   inline int
6371*38fd1498Szrj   stoi(const string& __str, size_t* __idx = 0, int __base = 10)
6372*38fd1498Szrj   { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
6373*38fd1498Szrj 					__idx, __base); }
6374*38fd1498Szrj 
6375*38fd1498Szrj   inline long
6376*38fd1498Szrj   stol(const string& __str, size_t* __idx = 0, int __base = 10)
6377*38fd1498Szrj   { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
6378*38fd1498Szrj 			     __idx, __base); }
6379*38fd1498Szrj 
6380*38fd1498Szrj   inline unsigned long
6381*38fd1498Szrj   stoul(const string& __str, size_t* __idx = 0, int __base = 10)
6382*38fd1498Szrj   { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
6383*38fd1498Szrj 			     __idx, __base); }
6384*38fd1498Szrj 
6385*38fd1498Szrj   inline long long
6386*38fd1498Szrj   stoll(const string& __str, size_t* __idx = 0, int __base = 10)
6387*38fd1498Szrj   { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
6388*38fd1498Szrj 			     __idx, __base); }
6389*38fd1498Szrj 
6390*38fd1498Szrj   inline unsigned long long
6391*38fd1498Szrj   stoull(const string& __str, size_t* __idx = 0, int __base = 10)
6392*38fd1498Szrj   { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
6393*38fd1498Szrj 			     __idx, __base); }
6394*38fd1498Szrj 
6395*38fd1498Szrj   // NB: strtof vs strtod.
6396*38fd1498Szrj   inline float
6397*38fd1498Szrj   stof(const string& __str, size_t* __idx = 0)
6398*38fd1498Szrj   { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
6399*38fd1498Szrj 
6400*38fd1498Szrj   inline double
6401*38fd1498Szrj   stod(const string& __str, size_t* __idx = 0)
6402*38fd1498Szrj   { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
6403*38fd1498Szrj 
6404*38fd1498Szrj   inline long double
6405*38fd1498Szrj   stold(const string& __str, size_t* __idx = 0)
6406*38fd1498Szrj   { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
6407*38fd1498Szrj #endif // _GLIBCXX_USE_C99_STDLIB
6408*38fd1498Szrj 
6409*38fd1498Szrj #if _GLIBCXX_USE_C99_STDIO
6410*38fd1498Szrj   // NB: (v)snprintf vs sprintf.
6411*38fd1498Szrj 
6412*38fd1498Szrj   // DR 1261.
6413*38fd1498Szrj   inline string
6414*38fd1498Szrj   to_string(int __val)
6415*38fd1498Szrj   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(int),
6416*38fd1498Szrj 					   "%d", __val); }
6417*38fd1498Szrj 
6418*38fd1498Szrj   inline string
6419*38fd1498Szrj   to_string(unsigned __val)
6420*38fd1498Szrj   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
6421*38fd1498Szrj 					   4 * sizeof(unsigned),
6422*38fd1498Szrj 					   "%u", __val); }
6423*38fd1498Szrj 
6424*38fd1498Szrj   inline string
6425*38fd1498Szrj   to_string(long __val)
6426*38fd1498Szrj   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(long),
6427*38fd1498Szrj 					   "%ld", __val); }
6428*38fd1498Szrj 
6429*38fd1498Szrj   inline string
6430*38fd1498Szrj   to_string(unsigned long __val)
6431*38fd1498Szrj   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
6432*38fd1498Szrj 					   4 * sizeof(unsigned long),
6433*38fd1498Szrj 					   "%lu", __val); }
6434*38fd1498Szrj 
6435*38fd1498Szrj   inline string
6436*38fd1498Szrj   to_string(long long __val)
6437*38fd1498Szrj   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
6438*38fd1498Szrj 					   4 * sizeof(long long),
6439*38fd1498Szrj 					   "%lld", __val); }
6440*38fd1498Szrj 
6441*38fd1498Szrj   inline string
6442*38fd1498Szrj   to_string(unsigned long long __val)
6443*38fd1498Szrj   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
6444*38fd1498Szrj 					   4 * sizeof(unsigned long long),
6445*38fd1498Szrj 					   "%llu", __val); }
6446*38fd1498Szrj 
6447*38fd1498Szrj   inline string
6448*38fd1498Szrj   to_string(float __val)
6449*38fd1498Szrj   {
6450*38fd1498Szrj     const int __n =
6451*38fd1498Szrj       __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
6452*38fd1498Szrj     return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
6453*38fd1498Szrj 					   "%f", __val);
6454*38fd1498Szrj   }
6455*38fd1498Szrj 
6456*38fd1498Szrj   inline string
6457*38fd1498Szrj   to_string(double __val)
6458*38fd1498Szrj   {
6459*38fd1498Szrj     const int __n =
6460*38fd1498Szrj       __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
6461*38fd1498Szrj     return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
6462*38fd1498Szrj 					   "%f", __val);
6463*38fd1498Szrj   }
6464*38fd1498Szrj 
6465*38fd1498Szrj   inline string
6466*38fd1498Szrj   to_string(long double __val)
6467*38fd1498Szrj   {
6468*38fd1498Szrj     const int __n =
6469*38fd1498Szrj       __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
6470*38fd1498Szrj     return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
6471*38fd1498Szrj 					   "%Lf", __val);
6472*38fd1498Szrj   }
6473*38fd1498Szrj #endif // _GLIBCXX_USE_C99_STDIO
6474*38fd1498Szrj 
6475*38fd1498Szrj #if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR
6476*38fd1498Szrj   inline int
6477*38fd1498Szrj   stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
6478*38fd1498Szrj   { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
6479*38fd1498Szrj 					__idx, __base); }
6480*38fd1498Szrj 
6481*38fd1498Szrj   inline long
6482*38fd1498Szrj   stol(const wstring& __str, size_t* __idx = 0, int __base = 10)
6483*38fd1498Szrj   { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
6484*38fd1498Szrj 			     __idx, __base); }
6485*38fd1498Szrj 
6486*38fd1498Szrj   inline unsigned long
6487*38fd1498Szrj   stoul(const wstring& __str, size_t* __idx = 0, int __base = 10)
6488*38fd1498Szrj   { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
6489*38fd1498Szrj 			     __idx, __base); }
6490*38fd1498Szrj 
6491*38fd1498Szrj   inline long long
6492*38fd1498Szrj   stoll(const wstring& __str, size_t* __idx = 0, int __base = 10)
6493*38fd1498Szrj   { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
6494*38fd1498Szrj 			     __idx, __base); }
6495*38fd1498Szrj 
6496*38fd1498Szrj   inline unsigned long long
6497*38fd1498Szrj   stoull(const wstring& __str, size_t* __idx = 0, int __base = 10)
6498*38fd1498Szrj   { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
6499*38fd1498Szrj 			     __idx, __base); }
6500*38fd1498Szrj 
6501*38fd1498Szrj   // NB: wcstof vs wcstod.
6502*38fd1498Szrj   inline float
6503*38fd1498Szrj   stof(const wstring& __str, size_t* __idx = 0)
6504*38fd1498Szrj   { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
6505*38fd1498Szrj 
6506*38fd1498Szrj   inline double
6507*38fd1498Szrj   stod(const wstring& __str, size_t* __idx = 0)
6508*38fd1498Szrj   { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
6509*38fd1498Szrj 
6510*38fd1498Szrj   inline long double
6511*38fd1498Szrj   stold(const wstring& __str, size_t* __idx = 0)
6512*38fd1498Szrj   { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
6513*38fd1498Szrj 
6514*38fd1498Szrj #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
6515*38fd1498Szrj   // DR 1261.
6516*38fd1498Szrj   inline wstring
6517*38fd1498Szrj   to_wstring(int __val)
6518*38fd1498Szrj   { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(int),
6519*38fd1498Szrj 					    L"%d", __val); }
6520*38fd1498Szrj 
6521*38fd1498Szrj   inline wstring
6522*38fd1498Szrj   to_wstring(unsigned __val)
6523*38fd1498Szrj   { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6524*38fd1498Szrj 					    4 * sizeof(unsigned),
6525*38fd1498Szrj 					    L"%u", __val); }
6526*38fd1498Szrj 
6527*38fd1498Szrj   inline wstring
6528*38fd1498Szrj   to_wstring(long __val)
6529*38fd1498Szrj   { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(long),
6530*38fd1498Szrj 					    L"%ld", __val); }
6531*38fd1498Szrj 
6532*38fd1498Szrj   inline wstring
6533*38fd1498Szrj   to_wstring(unsigned long __val)
6534*38fd1498Szrj   { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6535*38fd1498Szrj 					    4 * sizeof(unsigned long),
6536*38fd1498Szrj 					    L"%lu", __val); }
6537*38fd1498Szrj 
6538*38fd1498Szrj   inline wstring
6539*38fd1498Szrj   to_wstring(long long __val)
6540*38fd1498Szrj   { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6541*38fd1498Szrj 					    4 * sizeof(long long),
6542*38fd1498Szrj 					    L"%lld", __val); }
6543*38fd1498Szrj 
6544*38fd1498Szrj   inline wstring
6545*38fd1498Szrj   to_wstring(unsigned long long __val)
6546*38fd1498Szrj   { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6547*38fd1498Szrj 					    4 * sizeof(unsigned long long),
6548*38fd1498Szrj 					    L"%llu", __val); }
6549*38fd1498Szrj 
6550*38fd1498Szrj   inline wstring
6551*38fd1498Szrj   to_wstring(float __val)
6552*38fd1498Szrj   {
6553*38fd1498Szrj     const int __n =
6554*38fd1498Szrj       __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
6555*38fd1498Szrj     return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
6556*38fd1498Szrj 					    L"%f", __val);
6557*38fd1498Szrj   }
6558*38fd1498Szrj 
6559*38fd1498Szrj   inline wstring
6560*38fd1498Szrj   to_wstring(double __val)
6561*38fd1498Szrj   {
6562*38fd1498Szrj     const int __n =
6563*38fd1498Szrj       __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
6564*38fd1498Szrj     return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
6565*38fd1498Szrj 					    L"%f", __val);
6566*38fd1498Szrj   }
6567*38fd1498Szrj 
6568*38fd1498Szrj   inline wstring
6569*38fd1498Szrj   to_wstring(long double __val)
6570*38fd1498Szrj   {
6571*38fd1498Szrj     const int __n =
6572*38fd1498Szrj       __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
6573*38fd1498Szrj     return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
6574*38fd1498Szrj 					    L"%Lf", __val);
6575*38fd1498Szrj   }
6576*38fd1498Szrj #endif // _GLIBCXX_HAVE_BROKEN_VSWPRINTF
6577*38fd1498Szrj #endif // _GLIBCXX_USE_WCHAR_T && _GLIBCXX_USE_C99_WCHAR
6578*38fd1498Szrj 
6579*38fd1498Szrj _GLIBCXX_END_NAMESPACE_CXX11
6580*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
6581*38fd1498Szrj } // namespace
6582*38fd1498Szrj 
6583*38fd1498Szrj #endif /* C++11 */
6584*38fd1498Szrj 
6585*38fd1498Szrj #if __cplusplus >= 201103L
6586*38fd1498Szrj 
6587*38fd1498Szrj #include <bits/functional_hash.h>
6588*38fd1498Szrj 
6589*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default)
6590*38fd1498Szrj {
6591*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
6592*38fd1498Szrj 
6593*38fd1498Szrj   // DR 1182.
6594*38fd1498Szrj 
6595*38fd1498Szrj #ifndef _GLIBCXX_COMPATIBILITY_CXX0X
6596*38fd1498Szrj   /// std::hash specialization for string.
6597*38fd1498Szrj   template<>
6598*38fd1498Szrj     struct hash<string>
6599*38fd1498Szrj     : public __hash_base<size_t, string>
6600*38fd1498Szrj     {
6601*38fd1498Szrj       size_t
6602*38fd1498Szrj       operator()(const string& __s) const noexcept
6603*38fd1498Szrj       { return std::_Hash_impl::hash(__s.data(), __s.length()); }
6604*38fd1498Szrj     };
6605*38fd1498Szrj 
6606*38fd1498Szrj   template<>
6607*38fd1498Szrj     struct __is_fast_hash<hash<string>> : std::false_type
6608*38fd1498Szrj     { };
6609*38fd1498Szrj 
6610*38fd1498Szrj #ifdef _GLIBCXX_USE_WCHAR_T
6611*38fd1498Szrj   /// std::hash specialization for wstring.
6612*38fd1498Szrj   template<>
6613*38fd1498Szrj     struct hash<wstring>
6614*38fd1498Szrj     : public __hash_base<size_t, wstring>
6615*38fd1498Szrj     {
6616*38fd1498Szrj       size_t
6617*38fd1498Szrj       operator()(const wstring& __s) const noexcept
6618*38fd1498Szrj       { return std::_Hash_impl::hash(__s.data(),
6619*38fd1498Szrj                                      __s.length() * sizeof(wchar_t)); }
6620*38fd1498Szrj     };
6621*38fd1498Szrj 
6622*38fd1498Szrj   template<>
6623*38fd1498Szrj     struct __is_fast_hash<hash<wstring>> : std::false_type
6624*38fd1498Szrj     { };
6625*38fd1498Szrj #endif
6626*38fd1498Szrj #endif /* _GLIBCXX_COMPATIBILITY_CXX0X */
6627*38fd1498Szrj 
6628*38fd1498Szrj #ifdef _GLIBCXX_USE_C99_STDINT_TR1
6629*38fd1498Szrj   /// std::hash specialization for u16string.
6630*38fd1498Szrj   template<>
6631*38fd1498Szrj     struct hash<u16string>
6632*38fd1498Szrj     : public __hash_base<size_t, u16string>
6633*38fd1498Szrj     {
6634*38fd1498Szrj       size_t
6635*38fd1498Szrj       operator()(const u16string& __s) const noexcept
6636*38fd1498Szrj       { return std::_Hash_impl::hash(__s.data(),
6637*38fd1498Szrj                                      __s.length() * sizeof(char16_t)); }
6638*38fd1498Szrj     };
6639*38fd1498Szrj 
6640*38fd1498Szrj   template<>
6641*38fd1498Szrj     struct __is_fast_hash<hash<u16string>> : std::false_type
6642*38fd1498Szrj     { };
6643*38fd1498Szrj 
6644*38fd1498Szrj   /// std::hash specialization for u32string.
6645*38fd1498Szrj   template<>
6646*38fd1498Szrj     struct hash<u32string>
6647*38fd1498Szrj     : public __hash_base<size_t, u32string>
6648*38fd1498Szrj     {
6649*38fd1498Szrj       size_t
6650*38fd1498Szrj       operator()(const u32string& __s) const noexcept
6651*38fd1498Szrj       { return std::_Hash_impl::hash(__s.data(),
6652*38fd1498Szrj                                      __s.length() * sizeof(char32_t)); }
6653*38fd1498Szrj     };
6654*38fd1498Szrj 
6655*38fd1498Szrj   template<>
6656*38fd1498Szrj     struct __is_fast_hash<hash<u32string>> : std::false_type
6657*38fd1498Szrj     { };
6658*38fd1498Szrj #endif
6659*38fd1498Szrj 
6660*38fd1498Szrj #if __cplusplus > 201103L
6661*38fd1498Szrj 
6662*38fd1498Szrj #define __cpp_lib_string_udls 201304
6663*38fd1498Szrj 
6664*38fd1498Szrj   inline namespace literals
6665*38fd1498Szrj   {
6666*38fd1498Szrj   inline namespace string_literals
6667*38fd1498Szrj   {
6668*38fd1498Szrj #pragma GCC diagnostic push
6669*38fd1498Szrj #pragma GCC diagnostic ignored "-Wliteral-suffix"
6670*38fd1498Szrj     _GLIBCXX_DEFAULT_ABI_TAG
6671*38fd1498Szrj     inline basic_string<char>
6672*38fd1498Szrj     operator""s(const char* __str, size_t __len)
6673*38fd1498Szrj     { return basic_string<char>{__str, __len}; }
6674*38fd1498Szrj 
6675*38fd1498Szrj #ifdef _GLIBCXX_USE_WCHAR_T
6676*38fd1498Szrj     _GLIBCXX_DEFAULT_ABI_TAG
6677*38fd1498Szrj     inline basic_string<wchar_t>
6678*38fd1498Szrj     operator""s(const wchar_t* __str, size_t __len)
6679*38fd1498Szrj     { return basic_string<wchar_t>{__str, __len}; }
6680*38fd1498Szrj #endif
6681*38fd1498Szrj 
6682*38fd1498Szrj #ifdef _GLIBCXX_USE_C99_STDINT_TR1
6683*38fd1498Szrj     _GLIBCXX_DEFAULT_ABI_TAG
6684*38fd1498Szrj     inline basic_string<char16_t>
6685*38fd1498Szrj     operator""s(const char16_t* __str, size_t __len)
6686*38fd1498Szrj     { return basic_string<char16_t>{__str, __len}; }
6687*38fd1498Szrj 
6688*38fd1498Szrj     _GLIBCXX_DEFAULT_ABI_TAG
6689*38fd1498Szrj     inline basic_string<char32_t>
6690*38fd1498Szrj     operator""s(const char32_t* __str, size_t __len)
6691*38fd1498Szrj     { return basic_string<char32_t>{__str, __len}; }
6692*38fd1498Szrj #endif
6693*38fd1498Szrj 
6694*38fd1498Szrj #pragma GCC diagnostic pop
6695*38fd1498Szrj   } // inline namespace string_literals
6696*38fd1498Szrj   } // inline namespace literals
6697*38fd1498Szrj 
6698*38fd1498Szrj #endif // __cplusplus > 201103L
6699*38fd1498Szrj 
6700*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
6701*38fd1498Szrj } // namespace std
6702*38fd1498Szrj 
6703*38fd1498Szrj #endif // C++11
6704*38fd1498Szrj 
6705*38fd1498Szrj #endif /* _BASIC_STRING_H */
6706