33#define _COW_STRING_H 1
35#if ! _GLIBCXX_USE_CXX11_ABI
39namespace std _GLIBCXX_VISIBILITY(default)
41_GLIBCXX_BEGIN_NAMESPACE_VERSION
107 template<
typename _CharT,
typename _Traits,
typename _Alloc>
111 rebind<_CharT>::other _CharT_alloc_type;
116 typedef _Traits traits_type;
117 typedef typename _Traits::char_type value_type;
118 typedef _Alloc allocator_type;
119 typedef typename _CharT_alloc_traits::size_type size_type;
120 typedef typename _CharT_alloc_traits::difference_type difference_type;
121#if __cplusplus < 201103L
122 typedef typename _CharT_alloc_type::reference reference;
123 typedef typename _CharT_alloc_type::const_reference const_reference;
125 typedef value_type& reference;
126 typedef const value_type& const_reference;
128 typedef typename _CharT_alloc_traits::pointer pointer;
129 typedef typename _CharT_alloc_traits::const_pointer const_pointer;
130 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
131 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
138 typedef iterator __const_iterator;
158 size_type _M_capacity;
159 _Atomic_word _M_refcount;
162 struct _Rep : _Rep_base
166 rebind<char>::other _Raw_bytes_alloc;
181 static const size_type _S_max_size;
182 static const _CharT _S_terminal;
186 static size_type _S_empty_rep_storage[];
189 _S_empty_rep() _GLIBCXX_NOEXCEPT
194 void* __p =
reinterpret_cast<void*
>(&_S_empty_rep_storage);
195 return *
reinterpret_cast<_Rep*
>(__p);
199 _M_is_leaked()
const _GLIBCXX_NOEXCEPT
201#if defined(__GTHREADS)
206 return __atomic_load_n(&this->_M_refcount, __ATOMIC_RELAXED) < 0;
208 return this->_M_refcount < 0;
213 _M_is_shared()
const _GLIBCXX_NOEXCEPT
215#if defined(__GTHREADS)
221 if (!__gnu_cxx::__is_single_threaded())
222 return __atomic_load_n(&this->_M_refcount, __ATOMIC_ACQUIRE) > 0;
224 return this->_M_refcount > 0;
228 _M_set_leaked() _GLIBCXX_NOEXCEPT
229 { this->_M_refcount = -1; }
232 _M_set_sharable() _GLIBCXX_NOEXCEPT
233 { this->_M_refcount = 0; }
236 _M_set_length_and_sharable(size_type __n) _GLIBCXX_NOEXCEPT
238#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
239 if (__builtin_expect(
this != &_S_empty_rep(),
false))
242 this->_M_set_sharable();
243 this->_M_length = __n;
244 traits_type::assign(this->_M_refdata()[__n], _S_terminal);
252 {
return reinterpret_cast<_CharT*
>(
this + 1); }
255 _M_grab(
const _Alloc& __alloc1,
const _Alloc& __alloc2)
257 return (!_M_is_leaked() && __alloc1 == __alloc2)
258 ? _M_refcopy() : _M_clone(__alloc1);
263 _S_create(size_type, size_type,
const _Alloc&);
266 _M_dispose(
const _Alloc& __a) _GLIBCXX_NOEXCEPT
268#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
269 if (__builtin_expect(
this != &_S_empty_rep(),
false))
273 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount);
282 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
285 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount);
292 _M_destroy(
const _Alloc&)
throw();
297#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
298 if (__builtin_expect(
this != &_S_empty_rep(),
false))
300 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
305 _M_clone(
const _Alloc&, size_type __res = 0);
309 struct _Alloc_hider : _Alloc
311 _Alloc_hider(_CharT* __dat,
const _Alloc& __a) _GLIBCXX_NOEXCEPT
312 : _Alloc(__a), _M_p(__dat) { }
322 static const size_type
npos =
static_cast<size_type
>(-1);
326 mutable _Alloc_hider _M_dataplus;
329 _M_data() const _GLIBCXX_NOEXCEPT
330 {
return _M_dataplus._M_p; }
333 _M_data(_CharT* __p) _GLIBCXX_NOEXCEPT
334 {
return (_M_dataplus._M_p = __p); }
337 _M_rep() const _GLIBCXX_NOEXCEPT
338 {
return &((
reinterpret_cast<_Rep*
> (_M_data()))[-1]); }
343 _M_ibegin() const _GLIBCXX_NOEXCEPT
344 {
return iterator(_M_data()); }
347 _M_iend() const _GLIBCXX_NOEXCEPT
348 {
return iterator(_M_data() + this->
size()); }
353 if (!_M_rep()->_M_is_leaked())
358 _M_check(size_type __pos,
const char* __s)
const
360 if (__pos > this->
size())
361 __throw_out_of_range_fmt(__N(
"%s: __pos (which is %zu) > "
362 "this->size() (which is %zu)"),
363 __s, __pos, this->
size());
368 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
371 __throw_length_error(__N(__s));
376 _M_limit(size_type __pos, size_type __off)
const _GLIBCXX_NOEXCEPT
378 const bool __testoff = __off < this->
size() - __pos;
379 return __testoff ? __off : this->
size() - __pos;
384 _M_disjunct(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
386 return (less<const _CharT*>()(__s, _M_data())
387 || less<const _CharT*>()(_M_data() + this->
size(), __s));
393 _M_copy(_CharT* __d,
const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
396 traits_type::assign(*__d, *__s);
398 traits_type::copy(__d, __s, __n);
402 _M_move(_CharT* __d,
const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
405 traits_type::assign(*__d, *__s);
407 traits_type::move(__d, __s, __n);
411 _M_assign(_CharT* __d, size_type __n, _CharT __c) _GLIBCXX_NOEXCEPT
414 traits_type::assign(*__d, __c);
416 traits_type::assign(__d, __n, __c);
421 template<
class _Iterator>
423 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
425 for (; __k1 != __k2; ++__k1, (void)++__p)
426 traits_type::assign(*__p, *__k1);
430 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
431 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
434 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
436 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
439 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
440 { _M_copy(__p, __k1, __k2 - __k1); }
443 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
445 { _M_copy(__p, __k1, __k2 - __k1); }
448 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
450 const difference_type __d = difference_type(__n1 - __n2);
452 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
453 return __gnu_cxx::__numeric_traits<int>::__max;
454 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
455 return __gnu_cxx::__numeric_traits<int>::__min;
461 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
467 _S_empty_rep() _GLIBCXX_NOEXCEPT
468 {
return _Rep::_S_empty_rep(); }
470#if __cplusplus >= 201703L
472 typedef basic_string_view<_CharT, _Traits> __sv_type;
474 template<
typename _Tp,
typename _Res>
476 __and_<is_convertible<const _Tp&, __sv_type>,
477 __not_<is_convertible<const _Tp*, const basic_string*>>,
478 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
483 _S_to_string_view(__sv_type __svt)
noexcept
492 explicit __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
516#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
518 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc())
520 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc())
529 : _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a)
538 : _M_dataplus(__str._M_rep()->_M_grab(_Alloc(__str.
get_allocator()),
552 const _Alloc& __a = _Alloc());
570 size_type __n,
const _Alloc& __a);
582 const _Alloc& __a = _Alloc())
583 : _M_dataplus(_S_construct(__s, __s + __n, __a), __a)
591#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
594 template<
typename = _RequireAllocator<_Alloc>>
597 : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::
length(__s) :
598 __s +
npos, __a), __a)
608 : _M_dataplus(_S_construct(__n, __c, __a), __a)
611#if __cplusplus >= 201103L
620 : _M_dataplus(
std::move(__str._M_dataplus))
622#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
624 __str._M_data(_S_empty_rep()._M_refdata());
630 if (_M_rep()->_M_is_shared())
631 __gnu_cxx::__atomic_add_dispatch(&_M_rep()->_M_refcount, 1);
633 _M_rep()->_M_refcount = 1;
643 : _M_dataplus(_S_construct(__l.
begin(), __l.
end(), __a), __a)
647 : _M_dataplus(__str._M_rep()->_M_grab(__a, __str.
get_allocator()), __a)
651 : _M_dataplus(__str._M_data(), __a)
655#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
656 __str._M_data(_S_empty_rep()._M_refdata());
658 __str._M_data(_S_construct(size_type(), _CharT(), __a));
662 _M_dataplus._M_p = _S_construct(__str.
begin(), __str.
end(), __a);
666#if __cplusplus >= 202100L
677 template<
class _InputIterator>
679 const _Alloc& __a = _Alloc())
680 : _M_dataplus(_S_construct(__beg, __end, __a), __a)
683#if __cplusplus >= 201703L
691 template<
typename _Tp,
694 const _Alloc& __a = _Alloc())
702 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
705 :
basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
720 {
return this->
assign(__str); }
728 {
return this->
assign(__s); }
744#if __cplusplus >= 201103L
768 this->
assign(__l.begin(), __l.size());
773#if __cplusplus >= 201703L
778 template<
typename _Tp>
779 _If_sv<_Tp, basic_string&>
781 {
return this->
assign(__svt); }
800 return iterator(_M_data());
809 {
return const_iterator(_M_data()); }
819 return iterator(_M_data() + this->
size());
827 end() const _GLIBCXX_NOEXCEPT
828 {
return const_iterator(_M_data() + this->
size()); }
844 const_reverse_iterator
862 const_reverse_iterator
866#if __cplusplus >= 201103L
873 {
return const_iterator(this->_M_data()); }
881 {
return const_iterator(this->_M_data() + this->
size()); }
888 const_reverse_iterator
897 const_reverse_iterator
910#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 && __OPTIMIZE__
911 if (_S_empty_rep()._M_length != 0)
912 __builtin_unreachable();
914 return _M_rep()->_M_length;
926 {
return _Rep::_S_max_size; }
953 { this->
resize(__n, _CharT()); }
955#if __cplusplus >= 201103L
956#pragma GCC diagnostic push
957#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
962#pragma GCC diagnostic pop
965#ifdef __glibcxx_string_resize_and_overwrite
995 template<
typename _Operation>
997 resize_and_overwrite(size_type __n, _Operation __op);
1000#if __cplusplus >= 201103L
1002 template<
typename _Operation>
1013 {
return _M_rep()->_M_capacity; }
1036#if __cplusplus > 201703L
1037 [[deprecated(
"use shrink_to_fit() instead")]]
1045#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
1049 if (_M_rep()->_M_is_shared())
1052 _M_data(_S_empty_rep()._M_refdata());
1055 _M_rep()->_M_set_length_and_sharable(0);
1061 { _M_mutate(0, this->
size(), 0); }
1068 _GLIBCXX_NODISCARD
bool
1070 {
return this->
size() == 0; }
1086 __glibcxx_assert(__pos <=
size());
1087 return _M_data()[__pos];
1105 __glibcxx_assert(__pos <=
size());
1107 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos <
size());
1109 return _M_data()[__pos];
1125 if (__n >= this->
size())
1126 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1127 "(which is %zu) >= this->size() "
1130 return _M_data()[__n];
1148 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1149 "(which is %zu) >= this->size() "
1153 return _M_data()[__n];
1156#if __cplusplus >= 201103L
1164 __glibcxx_assert(!
empty());
1175 __glibcxx_assert(!
empty());
1186 __glibcxx_assert(!
empty());
1197 __glibcxx_assert(!
empty());
1210 {
return this->
append(__str); }
1219 {
return this->
append(__s); }
1233#if __cplusplus >= 201103L
1241 {
return this->
append(__l.begin(), __l.size()); }
1244#if __cplusplus >= 201703L
1250 template<
typename _Tp>
1251 _If_sv<_Tp, basic_string&>
1253 {
return this->
append(__svt); }
1297 __glibcxx_requires_string(__s);
1298 return this->
append(__s, traits_type::length(__s));
1312#if __cplusplus >= 201103L
1320 {
return this->
append(__l.begin(), __l.size()); }
1331 template<
class _InputIterator>
1333 append(_InputIterator __first, _InputIterator __last)
1334 {
return this->
replace(_M_iend(), _M_iend(), __first, __last); }
1336#if __cplusplus >= 201703L
1342 template<
typename _Tp>
1343 _If_sv<_Tp, basic_string&>
1347 return this->
append(__sv.data(), __sv.size());
1358 template<
typename _Tp>
1359 _If_sv<_Tp, basic_string&>
1363 return append(__sv.data()
1364 + std::__sv_check(__sv.size(), __pos,
"basic_string::append"),
1365 std::__sv_limit(__sv.size(), __pos, __n));
1376 const size_type __len = 1 + this->
size();
1377 if (__len > this->
capacity() || _M_rep()->_M_is_shared())
1379 traits_type::assign(_M_data()[this->
size()], __c);
1380 _M_rep()->_M_set_length_and_sharable(__len);
1391#if __cplusplus >= 201103L
1424 {
return this->
assign(__str._M_data()
1425 + __str._M_check(__pos,
"basic_string::assign"),
1426 __str._M_limit(__pos, __n)); }
1453 __glibcxx_requires_string(__s);
1454 return this->
assign(__s, traits_type::length(__s));
1468 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
1478 template<
class _InputIterator>
1480 assign(_InputIterator __first, _InputIterator __last)
1481 {
return this->
replace(_M_ibegin(), _M_iend(), __first, __last); }
1483#if __cplusplus >= 201103L
1491 {
return this->
assign(__l.begin(), __l.size()); }
1494#if __cplusplus >= 201703L
1500 template<
typename _Tp>
1501 _If_sv<_Tp, basic_string&>
1505 return this->
assign(__sv.data(), __sv.size());
1515 template<
typename _Tp>
1516 _If_sv<_Tp, basic_string&>
1520 return assign(__sv.data()
1521 + std::__sv_check(__sv.size(), __pos,
"basic_string::assign"),
1522 std::__sv_limit(__sv.size(), __pos, __n));
1540 insert(iterator __p, size_type __n, _CharT __c)
1541 { this->
replace(__p, __p, __n, __c); }
1555 template<
class _InputIterator>
1557 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1558 { this->
replace(__p, __p, __beg, __end); }
1560#if __cplusplus >= 201103L
1570 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1571 this->
insert(__p - _M_ibegin(), __l.begin(), __l.size());
1589 {
return this->
insert(__pos1, __str, size_type(0), __str.
size()); }
1611 size_type __pos2, size_type __n =
npos)
1612 {
return this->
insert(__pos1, __str._M_data()
1613 + __str._M_check(__pos2,
"basic_string::insert"),
1614 __str._M_limit(__pos2, __n)); }
1633 insert(size_type __pos,
const _CharT* __s, size_type __n);
1653 __glibcxx_requires_string(__s);
1654 return this->
insert(__pos, __s, traits_type::length(__s));
1674 insert(size_type __pos, size_type __n, _CharT __c)
1675 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
1676 size_type(0), __n, __c); }
1694 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1695 const size_type __pos = __p - _M_ibegin();
1696 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1697 _M_rep()->_M_set_leaked();
1698 return iterator(_M_data() + __pos);
1701#if __cplusplus >= 201703L
1708 template<
typename _Tp>
1709 _If_sv<_Tp, basic_string&>
1713 return this->
insert(__pos, __sv.data(), __sv.size());
1724 template<
typename _Tp>
1725 _If_sv<_Tp, basic_string&>
1727 size_type __pos2, size_type __n =
npos)
1730 return this->
replace(__pos1, size_type(0), __sv.data()
1731 + std::__sv_check(__sv.size(), __pos2,
"basic_string::insert"),
1732 std::__sv_limit(__sv.size(), __pos2, __n));
1754 _M_mutate(_M_check(__pos,
"basic_string::erase"),
1755 _M_limit(__pos, __n), size_type(0));
1770 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1771 && __position < _M_iend());
1772 const size_type __pos = __position - _M_ibegin();
1773 _M_mutate(__pos, size_type(1), size_type(0));
1774 _M_rep()->_M_set_leaked();
1775 return iterator(_M_data() + __pos);
1788 erase(iterator __first, iterator __last);
1790#if __cplusplus >= 201103L
1799 __glibcxx_assert(!
empty());
1823 {
return this->
replace(__pos, __n, __str._M_data(), __str.
size()); }
1845 size_type __pos2, size_type __n2 =
npos)
1846 {
return this->
replace(__pos1, __n1, __str._M_data()
1847 + __str._M_check(__pos2,
"basic_string::replace"),
1848 __str._M_limit(__pos2, __n2)); }
1869 replace(size_type __pos, size_type __n1,
const _CharT* __s,
1889 replace(size_type __pos, size_type __n1,
const _CharT* __s)
1891 __glibcxx_requires_string(__s);
1892 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
1913 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1914 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
1915 _M_limit(__pos, __n1), __n2, __c); }
1932 {
return this->
replace(__i1, __i2, __str._M_data(), __str.
size()); }
1950 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
1952 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1953 && __i2 <= _M_iend());
1954 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1971 replace(iterator __i1, iterator __i2,
const _CharT* __s)
1973 __glibcxx_requires_string(__s);
1974 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
1992 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1994 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1995 && __i2 <= _M_iend());
1996 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
2014 template<
class _InputIterator>
2017 _InputIterator __k1, _InputIterator __k2)
2019 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2020 && __i2 <= _M_iend());
2021 __glibcxx_requires_valid_range(__k1, __k2);
2022 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
2023 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
2031 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2032 && __i2 <= _M_iend());
2033 __glibcxx_requires_valid_range(__k1, __k2);
2034 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2039 replace(iterator __i1, iterator __i2,
2040 const _CharT* __k1,
const _CharT* __k2)
2042 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2043 && __i2 <= _M_iend());
2044 __glibcxx_requires_valid_range(__k1, __k2);
2045 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2050 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
2052 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2053 && __i2 <= _M_iend());
2054 __glibcxx_requires_valid_range(__k1, __k2);
2055 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2056 __k1.base(), __k2 - __k1);
2060 replace(iterator __i1, iterator __i2,
2061 const_iterator __k1, const_iterator __k2)
2063 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2064 && __i2 <= _M_iend());
2065 __glibcxx_requires_valid_range(__k1, __k2);
2066 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2067 __k1.base(), __k2 - __k1);
2070#if __cplusplus >= 201103L
2087 {
return this->
replace(__i1, __i2, __l.begin(), __l.end()); }
2090#if __cplusplus >= 201703L
2098 template<
typename _Tp>
2099 _If_sv<_Tp, basic_string&>
2100 replace(size_type __pos, size_type __n,
const _Tp& __svt)
2103 return this->
replace(__pos, __n, __sv.data(), __sv.size());
2115 template<
typename _Tp>
2116 _If_sv<_Tp, basic_string&>
2117 replace(size_type __pos1, size_type __n1,
const _Tp& __svt,
2118 size_type __pos2, size_type __n2 =
npos)
2121 return this->
replace(__pos1, __n1,
2123 + std::__sv_check(__sv.size(), __pos2,
"basic_string::replace"),
2124 std::__sv_limit(__sv.size(), __pos2, __n2));
2136 template<
typename _Tp>
2137 _If_sv<_Tp, basic_string&>
2138 replace(const_iterator __i1, const_iterator __i2,
const _Tp& __svt)
2141 return this->
replace(__i1 -
begin(), __i2 - __i1, __sv);
2146 template<
class _Integer>
2149 _Integer __val, __true_type)
2150 {
return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
2152 template<
class _InputIterator>
2154 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
2155 _InputIterator __k2, __false_type);
2158 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
2162 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
2167 template<
class _InIterator>
2169 _S_construct_aux(_InIterator __beg, _InIterator __end,
2170 const _Alloc& __a, __false_type)
2172 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
2173 return _S_construct(__beg, __end, __a, _Tag());
2178 template<
class _Integer>
2180 _S_construct_aux(_Integer __beg, _Integer __end,
2181 const _Alloc& __a, __true_type)
2182 {
return _S_construct_aux_2(
static_cast<size_type
>(__beg),
2186 _S_construct_aux_2(size_type __req, _CharT __c,
const _Alloc& __a)
2187 {
return _S_construct(__req, __c, __a); }
2189 template<
class _InIterator>
2191 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a)
2193 typedef typename std::__is_integer<_InIterator>::__type _Integral;
2194 return _S_construct_aux(__beg, __end, __a, _Integral());
2198 template<
class _InIterator>
2200 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
2201 input_iterator_tag);
2205 template<
class _FwdIterator>
2207 _S_construct(_FwdIterator __beg, _FwdIterator __end,
const _Alloc& __a,
2208 forward_iterator_tag);
2211 _S_construct(size_type __req, _CharT __c,
const _Alloc& __a);
2228 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
2250 {
return _M_data(); }
2262 {
return _M_data(); }
2264#if __cplusplus >= 201703L
2284 {
return _M_dataplus; }
2299 find(
const _CharT* __s, size_type __pos, size_type __n)
const
2315 {
return this->
find(__str.
data(), __pos, __str.
size()); }
2328 find(
const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2330 __glibcxx_requires_string(__s);
2331 return this->
find(__s, __pos, traits_type::length(__s));
2345 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
2347#if __cplusplus >= 201703L
2354 template<
typename _Tp>
2355 _If_sv<_Tp, size_type>
2356 find(
const _Tp& __svt, size_type __pos = 0) const
2360 return this->
find(__sv.data(), __pos, __sv.size());
2392 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
2406 rfind(
const _CharT* __s, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT
2408 __glibcxx_requires_string(__s);
2409 return this->
rfind(__s, __pos, traits_type::length(__s));
2423 rfind(_CharT __c, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT;
2425#if __cplusplus >= 201703L
2432 template<
typename _Tp>
2433 _If_sv<_Tp, size_type>
2438 return this->
rfind(__sv.data(), __pos, __sv.size());
2471 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2488 __glibcxx_requires_string(__s);
2489 return this->
find_first_of(__s, __pos, traits_type::length(__s));
2506 {
return this->
find(__c, __pos); }
2508#if __cplusplus >= 201703L
2516 template<
typename _Tp>
2517 _If_sv<_Tp, size_type>
2522 return this->
find_first_of(__sv.data(), __pos, __sv.size());
2555 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2572 __glibcxx_requires_string(__s);
2573 return this->
find_last_of(__s, __pos, traits_type::length(__s));
2590 {
return this->
rfind(__c, __pos); }
2592#if __cplusplus >= 201703L
2600 template<
typename _Tp>
2601 _If_sv<_Tp, size_type>
2606 return this->
find_last_of(__sv.data(), __pos, __sv.size());
2639 size_type __n)
const _GLIBCXX_NOEXCEPT;
2655 __glibcxx_requires_string(__s);
2673#if __cplusplus >= 201703L
2681 template<
typename _Tp>
2682 _If_sv<_Tp, size_type>
2721 size_type __n)
const _GLIBCXX_NOEXCEPT;
2737 __glibcxx_requires_string(__s);
2755#if __cplusplus >= 201703L
2763 template<
typename _Tp>
2764 _If_sv<_Tp, size_type>
2788 _M_check(__pos,
"basic_string::substr"), __n); }
2807 const size_type __size = this->
size();
2808 const size_type __osize = __str.
size();
2809 const size_type __len =
std::min(__size, __osize);
2811 int __r = traits_type::compare(_M_data(), __str.
data(), __len);
2813 __r = _S_compare(__size, __osize);
2817#if __cplusplus >= 201703L
2823 template<
typename _Tp>
2829 const size_type __size = this->
size();
2830 const size_type __osize = __sv.size();
2831 const size_type __len =
std::min(__size, __osize);
2833 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
2835 __r = _S_compare(__size, __osize);
2847 template<
typename _Tp>
2849 compare(size_type __pos, size_type __n,
const _Tp& __svt)
const
2853 return __sv_type(*this).substr(__pos, __n).compare(__sv);
2866 template<
typename _Tp>
2868 compare(size_type __pos1, size_type __n1,
const _Tp& __svt,
2869 size_type __pos2, size_type __n2 =
npos)
const
2874 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
2900 _M_check(__pos,
"basic_string::compare");
2901 __n = _M_limit(__pos, __n);
2902 const size_type __osize = __str.
size();
2903 const size_type __len =
std::min(__n, __osize);
2904 int __r = traits_type::compare(_M_data() + __pos, __str.
data(), __len);
2906 __r = _S_compare(__n, __osize);
2935 size_type __pos2, size_type __n2 =
npos)
const
2937 _M_check(__pos1,
"basic_string::compare");
2938 __str._M_check(__pos2,
"basic_string::compare");
2939 __n1 = _M_limit(__pos1, __n1);
2940 __n2 = __str._M_limit(__pos2, __n2);
2941 const size_type __len =
std::min(__n1, __n2);
2942 int __r = traits_type::compare(_M_data() + __pos1,
2943 __str.
data() + __pos2, __len);
2945 __r = _S_compare(__n1, __n2);
2964 compare(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
2966 __glibcxx_requires_string(__s);
2967 const size_type __size = this->
size();
2968 const size_type __osize = traits_type::length(__s);
2969 const size_type __len =
std::min(__size, __osize);
2970 int __r = traits_type::compare(_M_data(), __s, __len);
2972 __r = _S_compare(__size, __osize);
2998 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const
3000 __glibcxx_requires_string(__s);
3001 _M_check(__pos,
"basic_string::compare");
3002 __n1 = _M_limit(__pos, __n1);
3003 const size_type __osize = traits_type::length(__s);
3004 const size_type __len =
std::min(__n1, __osize);
3005 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
3007 __r = _S_compare(__n1, __osize);
3036 compare(size_type __pos, size_type __n1,
const _CharT* __s,
3037 size_type __n2)
const
3039 __glibcxx_requires_string_len(__s, __n2);
3040 _M_check(__pos,
"basic_string::compare");
3041 __n1 = _M_limit(__pos, __n1);
3042 const size_type __len =
std::min(__n1, __n2);
3043 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
3045 __r = _S_compare(__n1, __n2);
3049#if __cplusplus > 201703L
3052 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3055 starts_with(_CharT __x)
const noexcept
3056 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3058 [[__gnu__::__nonnull__]]
3060 starts_with(
const _CharT* __x)
const noexcept
3061 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3064 ends_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
3065 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3068 ends_with(_CharT __x)
const noexcept
3069 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3071 [[__gnu__::__nonnull__]]
3073 ends_with(
const _CharT* __x)
const noexcept
3074 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3077#if __cplusplus > 202011L
3079 contains(basic_string_view<_CharT, _Traits> __x)
const noexcept
3080 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3083 contains(_CharT __x)
const noexcept
3084 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3086 [[__gnu__::__nonnull__]]
3088 contains(
const _CharT* __x)
const noexcept
3089 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3092# ifdef _GLIBCXX_TM_TS_INTERNAL
3094 ::_txnal_cow_string_C1_for_exceptions(
void* that,
const char* s,
3097 ::_txnal_cow_string_c_str(
const void *that);
3099 ::_txnal_cow_string_D1(
void *that);
3101 ::_txnal_cow_string_D1_commit(
void *that);
3105 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3106 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
3107 basic_string<_CharT, _Traits, _Alloc>::
3108 _Rep::_S_max_size = (((npos -
sizeof(_Rep_base))/
sizeof(_CharT)) - 1) / 4;
3110 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3112 basic_string<_CharT, _Traits, _Alloc>::
3113 _Rep::_S_terminal = _CharT();
3115 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3116 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
3121 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3122 typename basic_string<_CharT, _Traits, _Alloc>::size_type
3123 basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_empty_rep_storage[
3124 (
sizeof(_Rep_base) +
sizeof(_CharT) +
sizeof(size_type) - 1) /
3131 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3132 template<
typename _InIterator>
3134 basic_string<_CharT, _Traits, _Alloc>::
3135 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
3138#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3139 if (__beg == __end && __a == _Alloc())
3140 return _S_empty_rep()._M_refdata();
3144 size_type __len = 0;
3145 while (__beg != __end && __len <
sizeof(__buf) /
sizeof(_CharT))
3147 __buf[__len++] = *__beg;
3150 _Rep* __r = _Rep::_S_create(__len, size_type(0), __a);
3151 _M_copy(__r->_M_refdata(), __buf, __len);
3154 while (__beg != __end)
3156 if (__len == __r->_M_capacity)
3159 _Rep* __another = _Rep::_S_create(__len + 1, __len, __a);
3160 _M_copy(__another->_M_refdata(), __r->_M_refdata(), __len);
3161 __r->_M_destroy(__a);
3164 __r->_M_refdata()[__len++] = *__beg;
3170 __r->_M_destroy(__a);
3171 __throw_exception_again;
3173 __r->_M_set_length_and_sharable(__len);
3174 return __r->_M_refdata();
3177 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3178 template <
typename _InIterator>
3180 basic_string<_CharT, _Traits, _Alloc>::
3181 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
3182 forward_iterator_tag)
3184#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3185 if (__beg == __end && __a == _Alloc())
3186 return _S_empty_rep()._M_refdata();
3189 if (__gnu_cxx::__is_null_pointer(__beg) && __beg != __end)
3190 __throw_logic_error(__N(
"basic_string::_S_construct null not valid"));
3192 const size_type __dnew =
static_cast<size_type
>(
std::distance(__beg,
3195 _Rep* __r = _Rep::_S_create(__dnew, size_type(0), __a);
3197 { _S_copy_chars(__r->_M_refdata(), __beg, __end); }
3200 __r->_M_destroy(__a);
3201 __throw_exception_again;
3203 __r->_M_set_length_and_sharable(__dnew);
3204 return __r->_M_refdata();
3207 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3209 basic_string<_CharT, _Traits, _Alloc>::
3210 _S_construct(size_type __n, _CharT __c,
const _Alloc& __a)
3212#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3213 if (__n == 0 && __a == _Alloc())
3214 return _S_empty_rep()._M_refdata();
3217 _Rep* __r = _Rep::_S_create(__n, size_type(0), __a);
3219 _M_assign(__r->_M_refdata(), __n, __c);
3221 __r->_M_set_length_and_sharable(__n);
3222 return __r->_M_refdata();
3225 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3228 : _M_dataplus(_S_construct(__str._M_data()
3229 + __str._M_check(__pos,
3230 "basic_string::basic_string"),
3231 __str._M_data() + __str._M_limit(__pos, npos)
3235 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3238 : _M_dataplus(_S_construct(__str._M_data()
3239 + __str._M_check(__pos,
3240 "basic_string::basic_string"),
3241 __str._M_data() + __str._M_limit(__pos, __n)
3242 + __pos, _Alloc()), _Alloc())
3245 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3248 size_type __n,
const _Alloc& __a)
3249 : _M_dataplus(_S_construct(__str._M_data()
3250 + __str._M_check(__pos,
3251 "basic_string::basic_string"),
3252 __str._M_data() + __str._M_limit(__pos, __n)
3256 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3261 if (_M_rep() != __str._M_rep())
3264 const allocator_type __a = this->get_allocator();
3265 _CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.
get_allocator());
3266 _M_rep()->_M_dispose(__a);
3272 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3275 assign(
const _CharT* __s, size_type __n)
3277 __glibcxx_requires_string_len(__s, __n);
3278 _M_check_length(this->
size(), __n,
"basic_string::assign");
3279 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3280 return _M_replace_safe(size_type(0), this->
size(), __s, __n);
3284 const size_type __pos = __s - _M_data();
3286 _M_copy(_M_data(), __s, __n);
3288 _M_move(_M_data(), __s, __n);
3289 _M_rep()->_M_set_length_and_sharable(__n);
3294 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3297 append(size_type __n, _CharT __c)
3301 _M_check_length(size_type(0), __n,
"basic_string::append");
3302 const size_type __len = __n + this->
size();
3303 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3304 this->reserve(__len);
3305 _M_assign(_M_data() + this->
size(), __n, __c);
3306 _M_rep()->_M_set_length_and_sharable(__len);
3311 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3314 append(
const _CharT* __s, size_type __n)
3316 __glibcxx_requires_string_len(__s, __n);
3319 _M_check_length(size_type(0), __n,
"basic_string::append");
3320 const size_type __len = __n + this->
size();
3321 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3323 if (_M_disjunct(__s))
3324 this->reserve(__len);
3327 const size_type __off = __s - _M_data();
3328 this->reserve(__len);
3329 __s = _M_data() + __off;
3332 _M_copy(_M_data() + this->
size(), __s, __n);
3333 _M_rep()->_M_set_length_and_sharable(__len);
3338 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3343 const size_type __size = __str.
size();
3346 const size_type __len = __size + this->
size();
3347 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3348 this->reserve(__len);
3349 _M_copy(_M_data() + this->
size(), __str._M_data(), __size);
3350 _M_rep()->_M_set_length_and_sharable(__len);
3355 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3360 __str._M_check(__pos,
"basic_string::append");
3361 __n = __str._M_limit(__pos, __n);
3364 const size_type __len = __n + this->
size();
3365 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3366 this->reserve(__len);
3367 _M_copy(_M_data() + this->
size(), __str._M_data() + __pos, __n);
3368 _M_rep()->_M_set_length_and_sharable(__len);
3373 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3376 insert(size_type __pos,
const _CharT* __s, size_type __n)
3378 __glibcxx_requires_string_len(__s, __n);
3379 _M_check(__pos,
"basic_string::insert");
3380 _M_check_length(size_type(0), __n,
"basic_string::insert");
3381 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3382 return _M_replace_safe(__pos, size_type(0), __s, __n);
3386 const size_type __off = __s - _M_data();
3387 _M_mutate(__pos, 0, __n);
3388 __s = _M_data() + __off;
3389 _CharT* __p = _M_data() + __pos;
3390 if (__s + __n <= __p)
3391 _M_copy(__p, __s, __n);
3392 else if (__s >= __p)
3393 _M_copy(__p, __s + __n, __n);
3396 const size_type __nleft = __p - __s;
3397 _M_copy(__p, __s, __nleft);
3398 _M_copy(__p + __nleft, __p + __n, __n - __nleft);
3404 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3405 typename basic_string<_CharT, _Traits, _Alloc>::iterator
3407 erase(iterator __first, iterator __last)
3409 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
3410 && __last <= _M_iend());
3415 const size_type __size = __last - __first;
3418 const size_type __pos = __first - _M_ibegin();
3419 _M_mutate(__pos, __size, size_type(0));
3420 _M_rep()->_M_set_leaked();
3421 return iterator(_M_data() + __pos);
3427 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3430 replace(size_type __pos, size_type __n1,
const _CharT* __s,
3433 __glibcxx_requires_string_len(__s, __n2);
3434 _M_check(__pos,
"basic_string::replace");
3435 __n1 = _M_limit(__pos, __n1);
3436 _M_check_length(__n1, __n2,
"basic_string::replace");
3438 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3439 return _M_replace_safe(__pos, __n1, __s, __n2);
3440 else if ((__left = __s + __n2 <= _M_data() + __pos)
3441 || _M_data() + __pos + __n1 <= __s)
3444 size_type __off = __s - _M_data();
3445 __left ? __off : (__off += __n2 - __n1);
3446 _M_mutate(__pos, __n1, __n2);
3447 _M_copy(_M_data() + __pos, _M_data() + __off, __n2);
3454 return _M_replace_safe(__pos, __n1, __tmp._M_data(), __n2);
3458 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3463 const size_type __size =
sizeof(_Rep_base)
3464 + (this->_M_capacity + 1) *
sizeof(_CharT);
3465 _Raw_bytes_alloc(__a).deallocate(
reinterpret_cast<char*
>(
this), __size);
3468 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3470 basic_string<_CharT, _Traits, _Alloc>::
3480 if (_M_rep()->_M_is_shared())
3482 _M_rep()->_M_set_leaked();
3485 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3487 basic_string<_CharT, _Traits, _Alloc>::
3488 _M_mutate(size_type __pos, size_type __len1, size_type __len2)
3490 const size_type __old_size = this->
size();
3491 const size_type __new_size = __old_size + __len2 - __len1;
3492 const size_type __how_much = __old_size - __pos - __len1;
3494 if (__new_size > this->capacity() || _M_rep()->_M_is_shared())
3497 const allocator_type __a = get_allocator();
3498 _Rep* __r = _Rep::_S_create(__new_size, this->capacity(), __a);
3501 _M_copy(__r->_M_refdata(), _M_data(), __pos);
3503 _M_copy(__r->_M_refdata() + __pos + __len2,
3504 _M_data() + __pos + __len1, __how_much);
3506 _M_rep()->_M_dispose(__a);
3507 _M_data(__r->_M_refdata());
3509 else if (__how_much && __len1 != __len2)
3512 _M_move(_M_data() + __pos + __len2,
3513 _M_data() + __pos + __len1, __how_much);
3515 _M_rep()->_M_set_length_and_sharable(__new_size);
3518 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3523 const size_type __capacity = capacity();
3529 if (__res <= __capacity)
3531 if (!_M_rep()->_M_is_shared())
3538 const allocator_type __a = get_allocator();
3539 _CharT* __tmp = _M_rep()->_M_clone(__a, __res - this->
size());
3540 _M_rep()->_M_dispose(__a);
3544 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3550 if (_M_rep()->_M_is_leaked())
3551 _M_rep()->_M_set_sharable();
3552 if (__s._M_rep()->_M_is_leaked())
3553 __s._M_rep()->_M_set_sharable();
3554 if (this->get_allocator() == __s.get_allocator())
3556 _CharT* __tmp = _M_data();
3557 _M_data(__s._M_data());
3564 __s.get_allocator());
3565 const basic_string __tmp2(__s._M_ibegin(), __s._M_iend(),
3566 this->get_allocator());
3572 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3575 _S_create(size_type __capacity, size_type __old_capacity,
3576 const _Alloc& __alloc)
3580 if (__capacity > _S_max_size)
3581 __throw_length_error(__N(
"basic_string::_S_create"));
3606 const size_type __pagesize = 4096;
3607 const size_type __malloc_header_size = 4 *
sizeof(
void*);
3615 if (__capacity > __old_capacity && __capacity < 2 * __old_capacity)
3616 __capacity = 2 * __old_capacity;
3621 size_type __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
3623 const size_type __adj_size = __size + __malloc_header_size;
3624 if (__adj_size > __pagesize && __capacity > __old_capacity)
3626 const size_type __extra = __pagesize - __adj_size % __pagesize;
3627 __capacity += __extra /
sizeof(_CharT);
3629 if (__capacity > _S_max_size)
3630 __capacity = _S_max_size;
3631 __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
3636 void* __place = _Raw_bytes_alloc(__alloc).allocate(__size);
3637 _Rep *__p =
new (__place) _Rep;
3638 __p->_M_capacity = __capacity;
3646 __p->_M_set_sharable();
3650 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3652 basic_string<_CharT, _Traits, _Alloc>::_Rep::
3653 _M_clone(
const _Alloc& __alloc, size_type __res)
3656 const size_type __requested_cap = this->_M_length + __res;
3657 _Rep* __r = _Rep::_S_create(__requested_cap, this->_M_capacity,
3659 if (this->_M_length)
3660 _M_copy(__r->_M_refdata(), _M_refdata(), this->_M_length);
3662 __r->_M_set_length_and_sharable(this->_M_length);
3663 return __r->_M_refdata();
3666 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3669 resize(size_type __n, _CharT __c)
3671 const size_type __size = this->
size();
3672 _M_check_length(__size, __n,
"basic_string::resize");
3674 this->append(__n - __size, __c);
3675 else if (__n < __size)
3680 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3681 template<
typename _InputIterator>
3685 _InputIterator __k2, __false_type)
3688 const size_type __n1 = __i2 - __i1;
3689 _M_check_length(__n1, __s.size(),
"basic_string::_M_replace_dispatch");
3690 return _M_replace_safe(__i1 - _M_ibegin(), __n1, __s._M_data(),
3694 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3695 basic_string<_CharT, _Traits, _Alloc>&
3696 basic_string<_CharT, _Traits, _Alloc>::
3697 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
3700 _M_check_length(__n1, __n2,
"basic_string::_M_replace_aux");
3701 _M_mutate(__pos1, __n1, __n2);
3703 _M_assign(_M_data() + __pos1, __n2, __c);
3707 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3708 basic_string<_CharT, _Traits, _Alloc>&
3709 basic_string<_CharT, _Traits, _Alloc>::
3710 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
3713 _M_mutate(__pos1, __n1, __n2);
3715 _M_copy(_M_data() + __pos1, __s, __n2);
3719 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3725 if (length() < capacity() || _M_rep()->_M_is_shared())
3728 const allocator_type __a = get_allocator();
3729 _CharT* __tmp = _M_rep()->_M_clone(__a);
3730 _M_rep()->_M_dispose(__a);
3740 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3741 typename basic_string<_CharT, _Traits, _Alloc>::size_type
3743 copy(_CharT* __s, size_type __n, size_type __pos)
const
3745 _M_check(__pos,
"basic_string::copy");
3746 __n = _M_limit(__pos, __n);
3747 __glibcxx_requires_string_len(__s, __n);
3749 _M_copy(__s, _M_data() + __pos, __n);
3754#ifdef __glibcxx_string_resize_and_overwrite
3755 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3756 template<
typename _Operation>
3757 [[__gnu__::__always_inline__]]
3761 { resize_and_overwrite<_Operation&>(__n, __op); }
3764#if __cplusplus >= 201103L
3765 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3766 template<
typename _Operation>
3768 basic_string<_CharT, _Traits, _Alloc>::
3769#ifdef __glibcxx_string_resize_and_overwrite
3770 resize_and_overwrite(
const size_type __n, _Operation __op)
3772 __resize_and_overwrite(
const size_type __n, _Operation __op)
3775 const size_type __capacity = capacity();
3777 if (__n > __capacity || _M_rep()->_M_is_shared())
3780 struct _Terminator {
3781 ~_Terminator() { _M_this->_M_rep()->_M_set_length_and_sharable(_M_r); }
3782 basic_string* _M_this;
3785 _Terminator __term{
this, 0};
3786 auto __r =
std::move(__op)(__p + 0, __n + 0);
3787#ifdef __cpp_lib_concepts
3788 static_assert(ranges::__detail::__is_integer_like<
decltype(__r)>);
3790 static_assert(__gnu_cxx::__is_integer_nonstrict<
decltype(__r)>::__value,
3791 "resize_and_overwrite operation must return an integer");
3793 _GLIBCXX_DEBUG_ASSERT(__r >= 0 && __r <= __n);
3794 __term._M_r = size_type(__r);
3795 if (__term._M_r > __n)
3796 __builtin_unreachable();
3801_GLIBCXX_END_NAMESPACE_VERSION
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
Return whether a container is empty.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
Uniform interface to all allocator types.
Managing sequences of characters and character-like objects.
int compare(size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos) const
Compare substring to a substring.
const_reverse_iterator crbegin() const noexcept
void swap(basic_string &__s) noexcept(/*conditional */)
Swap contents with another string.
_If_sv< _Tp, basic_string & > operator=(const _Tp &__svt)
Set value to string constructed from a string_view.
basic_string & operator=(const _CharT *__s)
Copy contents of s into this string.
basic_string & append(const basic_string &__str, size_type __pos, size_type __n=npos)
Append a substring.
void push_back(_CharT __c)
Append a single character.
const_iterator cend() const noexcept
basic_string & operator+=(initializer_list< _CharT > __l)
Append an initializer_list of characters.
size_type find(const _CharT *__s, size_type __pos=0) const noexcept
Find position of a C string.
basic_string(_InputIterator __beg, _InputIterator __end, const _Alloc &__a=_Alloc())
Construct string as copy of a range.
basic_string & replace(iterator __i1, iterator __i2, const _CharT *__s, size_type __n)
Replace range of characters with C substring.
basic_string & assign(initializer_list< _CharT > __l)
Set value to an initializer_list of characters.
size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
iterator erase(iterator __first, iterator __last)
Remove a range of characters.
_If_sv< _Tp, basic_string & > insert(size_type __pos1, const _Tp &__svt, size_type __pos2, size_type __n=npos)
Insert a string_view.
_If_sv< _Tp, int > compare(size_type __pos1, size_type __n1, const _Tp &__svt, size_type __pos2, size_type __n2=npos) const noexcept(is_same< _Tp, __sv_type >::value)
Compare to a string_view.
const _CharT * data() const noexcept
Return const pointer to contents.
basic_string(const _Alloc &__a)
Construct an empty string using allocator a.
size_type find_last_of(const _CharT *__s, size_type __pos=npos) const noexcept
Find last position of a character of C string.
_If_sv< _Tp, basic_string & > insert(size_type __pos, const _Tp &__svt)
Insert a string_view.
int compare(const _CharT *__s) const noexcept
Compare to a C string.
void insert(iterator __p, initializer_list< _CharT > __l)
Insert an initializer_list of characters.
basic_string & insert(size_type __pos1, const basic_string &__str)
Insert value of a string.
void __resize_and_overwrite(size_type __n, _Operation __op)
Non-standard version of resize_and_overwrite for C++11 and above.
size_type rfind(const _CharT *__s, size_type __pos=npos) const noexcept
Find last position of a C string.
basic_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
iterator erase(iterator __position)
Remove one character.
size_type find(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find position of a C substring.
size_type find(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a string.
basic_string & assign(const _CharT *__s, size_type __n)
Set value to a C substring.
size_type find_last_not_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character not in string.
int compare(size_type __pos, size_type __n, const basic_string &__str) const
Compare substring to a string.
basic_string(const basic_string &__str)
Construct string with copy of value of str.
int compare(const basic_string &__str) const
Compare to a string.
int compare(size_type __pos, size_type __n1, const _CharT *__s) const
Compare substring to a C string.
_If_sv< _Tp, size_type > find_last_not_of(const _Tp &__svt, size_type __pos=npos) const noexcept(is_same< _Tp, __sv_type >::value)
Find last position of a character not in a string_view.
int compare(size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) const
Compare substring against a character array.
_If_sv< _Tp, basic_string & > replace(size_type __pos1, size_type __n1, const _Tp &__svt, size_type __pos2, size_type __n2=npos)
Replace range of characters with string_view.
_If_sv< _Tp, basic_string & > replace(const_iterator __i1, const_iterator __i2, const _Tp &__svt)
Replace range of characters with string_view.
basic_string & replace(iterator __i1, iterator __i2, const basic_string &__str)
Replace range of characters with string.
basic_string(const basic_string &__str, size_type __pos, const _Alloc &__a=_Alloc())
Construct string as copy of a substring.
basic_string(const basic_string &__str, size_type __pos, size_type __n)
Construct string as copy of a substring.
size_type find_first_not_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character not in string.
const_reference front() const noexcept
size_type find_last_not_of(const _CharT *__s, size_type __pos=npos) const noexcept
Find last position of a character not in C string.
void insert(iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
basic_string & append(size_type __n, _CharT __c)
Append multiple characters.
basic_string(const _Tp &__t, size_type __pos, size_type __n, const _Alloc &__a=_Alloc())
Construct string from a substring of a string_view.
_If_sv< _Tp, basic_string & > assign(const _Tp &__svt)
Set value from a string_view.
reverse_iterator rbegin()
basic_string & insert(size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n=npos)
Insert a substring.
basic_string(initializer_list< _CharT > __l, const _Alloc &__a=_Alloc())
Construct string from an initializer list.
basic_string(const basic_string &__str, size_type __pos, size_type __n, const _Alloc &__a)
Construct string as copy of a substring.
basic_string(const _Tp &__t, const _Alloc &__a=_Alloc())
Construct string from a string_view.
basic_string & replace(size_type __pos, size_type __n1, const _CharT *__s, size_type __n2)
Replace characters with value of a C substring.
basic_string & replace(iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2)
Replace range of characters with range.
basic_string & assign(basic_string &&__str) noexcept(allocator_traits< _Alloc >::is_always_equal::value)
Set value to contents of another string.
_If_sv< _Tp, basic_string & > operator+=(const _Tp &__svt)
Append a string_view.
void pop_back()
Remove the last character.
basic_string(basic_string &&__str) noexcept
Move construct string.
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C string.
size_type length() const noexcept
Returns the number of characters in the string, not including any null-termination.
size_type find_last_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character of string.
basic_string & insert(size_type __pos, const _CharT *__s, size_type __n)
Insert a C substring.
basic_string & operator+=(const basic_string &__str)
Append a string to this string.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
size_type rfind(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a string.
basic_string & operator+=(const _CharT *__s)
Append a C string.
basic_string(size_type __n, _CharT __c, const _Alloc &__a=_Alloc())
Construct string as multiple characters.
void shrink_to_fit() noexcept
A non-binding request to reduce capacity() to size().
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
void reserve()
Equivalent to shrink_to_fit().
_If_sv< _Tp, int > compare(const _Tp &__svt) const noexcept(is_same< _Tp, __sv_type >::value)
Compare to a string_view.
const_reference at(size_type __n) const
Provides access to the data contained in the string.
const_reference back() const noexcept
const_reverse_iterator rend() const noexcept
const_iterator end() const noexcept
_If_sv< _Tp, size_type > find_first_of(const _Tp &__svt, size_type __pos=0) const noexcept(is_same< _Tp, __sv_type >::value)
Find position of a character of a string_view.
size_type find_last_of(_CharT __c, size_type __pos=npos) const noexcept
Find last position of a character.
_If_sv< _Tp, basic_string & > replace(size_type __pos, size_type __n, const _Tp &__svt)
Replace range of characters with string_view.
basic_string & append(const basic_string &__str)
Append a string to this string.
const_iterator begin() const noexcept
basic_string & operator=(basic_string &&__str) noexcept(/*conditional */)
Move assign the value of str to this string.
basic_string & replace(iterator __i1, iterator __i2, initializer_list< _CharT > __l)
Replace range of characters with initializer_list.
basic_string & operator+=(_CharT __c)
Append a character.
const_reverse_iterator crend() const noexcept
basic_string & operator=(const basic_string &__str)
Assign the value of str to this string.
basic_string & operator=(_CharT __c)
Set value to string of length 1.
void resize(size_type __n)
Resizes the string to the specified number of characters.
const_reverse_iterator rbegin() const noexcept
basic_string & assign(_InputIterator __first, _InputIterator __last)
Set value to a range of characters.
basic_string & append(initializer_list< _CharT > __l)
Append an initializer_list of characters.
basic_string & append(_InputIterator __first, _InputIterator __last)
Append a range of characters.
const_reference operator[](size_type __pos) const noexcept
Subscript access to the data contained in the string.
_If_sv< _Tp, basic_string & > assign(const _Tp &__svt, size_type __pos, size_type __n=npos)
Set value from a range of characters in a string_view.
basic_string(const _CharT *__s, const _Alloc &__a=_Alloc())
Construct string as copy of a C string.
size_type find_first_of(_CharT __c, size_type __pos=0) const noexcept
Find position of a character.
_If_sv< _Tp, basic_string & > append(const _Tp &__svt, size_type __pos, size_type __n=npos)
Append a range of characters from a string_view.
basic_string & assign(size_type __n, _CharT __c)
Set value to multiple characters.
basic_string & replace(iterator __i1, iterator __i2, const _CharT *__s)
Replace range of characters with C string.
bool empty() const noexcept
_If_sv< _Tp, basic_string & > append(const _Tp &__svt)
Append a string_view.
_If_sv< _Tp, size_type > find(const _Tp &__svt, size_type __pos=0) const noexcept(is_same< _Tp, __sv_type >::value)
Find position of a string_view.
basic_string & insert(size_type __pos, const _CharT *__s)
Insert a C string.
basic_string & assign(const basic_string &__str, size_type __pos, size_type __n=npos)
Set value to a substring of a string.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
_If_sv< _Tp, int > compare(size_type __pos, size_type __n, const _Tp &__svt) const noexcept(is_same< _Tp, __sv_type >::value)
Compare to a string_view.
basic_string & replace(size_type __pos, size_type __n1, const _CharT *__s)
Replace characters with value of a C string.
static const size_type npos
Value returned by various member functions when they fail.
allocator_type get_allocator() const noexcept
Return copy of allocator used to construct this string.
basic_string & assign(const _CharT *__s)
Set value to contents of a C string.
basic_string & replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
Replace characters with multiple characters.
const_iterator cbegin() const noexcept
basic_string & replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
Replace range of characters with multiple characters.
basic_string & operator=(initializer_list< _CharT > __l)
Set value to string constructed from initializer list.
~basic_string() noexcept
Destroy the string instance.
size_type capacity() const noexcept
basic_string() noexcept
Default constructor creates an empty string.
void insert(iterator __p, _InputIterator __beg, _InputIterator __end)
Insert a range of characters.
size_type find_first_of(const _CharT *__s, size_type __pos=0) const noexcept
Find position of a character of C string.
_If_sv< _Tp, size_type > find_first_not_of(const _Tp &__svt, size_type __pos=0) const noexcept(is_same< _Tp, __sv_type >::value)
Find position of a character not in a string_view.
_If_sv< _Tp, size_type > rfind(const _Tp &__svt, size_type __pos=npos) const noexcept(is_same< _Tp, __sv_type >::value)
Find last position of a string_view.
size_type max_size() const noexcept
Returns the size() of the largest possible string.
reference operator[](size_type __pos)
Subscript access to the data contained in the string.
basic_string & insert(size_type __pos, size_type __n, _CharT __c)
Insert multiple characters.
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
basic_string & replace(size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos)
Replace characters with value from another string.
basic_string & append(const _CharT *__s, size_type __n)
Append a C substring.
_CharT * data() noexcept
Return non-const pointer to contents.
basic_string(const _CharT *__s, size_type __n, const _Alloc &__a=_Alloc())
Construct string initialized by a character array.
basic_string & append(const _CharT *__s)
Append a C string.
_If_sv< _Tp, size_type > find_last_of(const _Tp &__svt, size_type __pos=npos) const noexcept(is_same< _Tp, __sv_type >::value)
Find last position of a character of string.
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
size_type find_first_not_of(const _CharT *__s, size_type __pos=0) const noexcept
Find position of a character not in C string.
reference at(size_type __n)
Provides access to the data contained in the string.
iterator insert(iterator __p, _CharT __c)
Insert one character.
Thrown as part of forced unwinding.
Uniform interface to C++98 and C++11 allocators.