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>
110 typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
111 rebind<_CharT>::other _CharT_alloc_type;
112 typedef __gnu_cxx::__alloc_traits<_CharT_alloc_type> _CharT_alloc_traits;
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>
133 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
134 typedef std::reverse_iterator<iterator> reverse_iterator;
138 typedef iterator __const_iterator;
158 size_type _M_capacity;
159 _Atomic_word _M_refcount;
162 struct _Rep : _Rep_base
165 typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
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,
static_cast<_CharT
>(*__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#ifdef __glibcxx_string_view
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
519#if __cpp_concepts && __glibcxx_type_trait_variable_templates
520 requires is_default_constructible_v<_Alloc>
522#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
523 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc())
525 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc())
534 : _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a)
543 : _M_dataplus(__str._M_rep()->_M_grab(_Alloc(__str.
get_allocator()),
557 const _Alloc& __a = _Alloc());
575 size_type __n,
const _Alloc& __a);
587 const _Alloc& __a = _Alloc())
588 : _M_dataplus(_S_construct(__s, __s + __n, __a), __a)
596#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
599 template<
typename = _RequireAllocator<_Alloc>>
602 : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::
length(__s) :
603 __s +
npos, __a), __a)
613 : _M_dataplus(_S_construct(__n, __c, __a), __a)
616#if __cplusplus >= 201103L
625 : _M_dataplus(
std::move(__str._M_dataplus))
627#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
629 __str._M_data(_S_empty_rep()._M_refdata());
635 if (_M_rep()->_M_is_shared())
636 __gnu_cxx::__atomic_add_dispatch(&_M_rep()->_M_refcount, 1);
638 _M_rep()->_M_refcount = 1;
642#if __glibcxx_containers_ranges
647 template<__detail::__container_compatible_range<_CharT> _Rg>
648 basic_string(from_range_t, _Rg&& __rg,
const _Alloc& __a = _Alloc())
653 const auto __n =
static_cast<size_type>(ranges::distance(__rg));
658 pointer __p = _M_data();
659 if constexpr (
requires {
662 -> convertible_to<const _CharT*>;
667 auto __first = ranges::begin(__rg);
668 const auto __last = ranges::end(__rg);
669 for (; __first != __last; ++__first)
670 traits_type::assign(*__p++,
static_cast<_CharT
>(*__first));
672 _M_rep()->_M_set_length_and_sharable(__n);
676 auto __first = ranges::begin(__rg);
677 const auto __last = ranges::end(__rg);
678 for (; __first != __last; ++__first)
690 : _M_dataplus(_S_construct(__l.
begin(), __l.
end(), __a), __a)
694 : _M_dataplus(__str._M_rep()->_M_grab(__a, __str.
get_allocator()), __a)
698 : _M_dataplus(__str._M_data(), __a)
700 if (__a == __str.get_allocator())
702#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
703 __str._M_data(_S_empty_rep()._M_refdata());
705 __str._M_data(_S_construct(size_type(), _CharT(), __a));
709 _M_dataplus._M_p = _S_construct(__str.begin(), __str.end(), __a);
713#if __cplusplus >= 202100L
724 template<
class _InputIterator>
726 const _Alloc& __a = _Alloc())
727 : _M_dataplus(_S_construct(__beg, __end, __a), __a)
730#ifdef __glibcxx_string_view
738 template<
typename _Tp,
741 const _Alloc& __a = _Alloc())
749 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
751 basic_string(
const _Tp& __t,
const _Alloc& __a = _Alloc())
752 :
basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
767 {
return this->
assign(__str); }
775 {
return this->
assign(__s); }
791#if __cplusplus >= 201103L
815 this->
assign(__l.begin(), __l.size());
820#ifdef __glibcxx_string_view
825 template<
typename _Tp>
826 _If_sv<_Tp, basic_string&>
827 operator=(
const _Tp& __svt)
828 {
return this->
assign(__svt); }
834 operator __sv_type() const noexcept
835 {
return __sv_type(
data(),
size()); }
847 return iterator(_M_data());
856 {
return const_iterator(_M_data()); }
866 return iterator(_M_data() + this->
size());
874 end() const _GLIBCXX_NOEXCEPT
875 {
return const_iterator(_M_data() + this->
size()); }
884 {
return reverse_iterator(this->
end()); }
891 const_reverse_iterator
893 {
return const_reverse_iterator(this->
end()); }
902 {
return reverse_iterator(this->
begin()); }
909 const_reverse_iterator
911 {
return const_reverse_iterator(this->
begin()); }
913#if __cplusplus >= 201103L
920 {
return const_iterator(this->_M_data()); }
928 {
return const_iterator(this->_M_data() + this->
size()); }
935 const_reverse_iterator
937 {
return const_reverse_iterator(this->
end()); }
944 const_reverse_iterator
946 {
return const_reverse_iterator(this->
begin()); }
957#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 && __OPTIMIZE__
958 if (_S_empty_rep()._M_length != 0)
959 __builtin_unreachable();
961 return _M_rep()->_M_length;
973 {
return _Rep::_S_max_size; }
1000 { this->
resize(__n, _CharT()); }
1002#if __cplusplus >= 201103L
1003#pragma GCC diagnostic push
1004#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1009#pragma GCC diagnostic pop
1012#ifdef __glibcxx_string_resize_and_overwrite
1042 template<
typename _Operation>
1044 resize_and_overwrite(
size_type __n, _Operation __op);
1047#if __cplusplus >= 201103L
1049 template<
typename _Operation>
1060 {
return _M_rep()->_M_capacity; }
1083#if __cplusplus >= 202002L
1084 [[deprecated(
"use shrink_to_fit() instead")]]
1092#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
1096 if (_M_rep()->_M_is_shared())
1099 _M_data(_S_empty_rep()._M_refdata());
1102 _M_rep()->_M_set_length_and_sharable(0);
1108 { _M_mutate(0, this->
size(), 0); }
1115 _GLIBCXX_NODISCARD
bool
1117 {
return this->
size() == 0; }
1133 __glibcxx_assert(__pos <=
size());
1134 return _M_data()[__pos];
1152 __glibcxx_assert(__pos <=
size());
1154 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos <
size());
1156 return _M_data()[__pos];
1172 if (__n >= this->
size())
1173 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1174 "(which is %zu) >= this->size() "
1177 return _M_data()[__n];
1195 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1196 "(which is %zu) >= this->size() "
1200 return _M_data()[__n];
1203#if __cplusplus >= 201103L
1211 __glibcxx_assert(!
empty());
1222 __glibcxx_assert(!
empty());
1233 __glibcxx_assert(!
empty());
1244 __glibcxx_assert(!
empty());
1257 {
return this->
append(__str); }
1266 {
return this->
append(__s); }
1280#if __cplusplus >= 201103L
1288 {
return this->
append(__l.begin(), __l.size()); }
1291#ifdef __glibcxx_string_view
1297 template<
typename _Tp>
1298 _If_sv<_Tp, basic_string&>
1300 {
return this->
append(__svt); }
1344 __glibcxx_requires_string(__s);
1345 return this->
append(__s, traits_type::length(__s));
1359#if __glibcxx_containers_ranges
1364 template<__detail::__container_compatible_range<_CharT> _Rg>
1366 append_range(_Rg&& __rg)
1375#if __cplusplus >= 201103L
1383 {
return this->
append(__l.begin(), __l.size()); }
1394 template<
class _InputIterator>
1396 append(_InputIterator __first, _InputIterator __last)
1397 {
return this->
replace(_M_iend(), _M_iend(), __first, __last); }
1399#ifdef __glibcxx_string_view
1405 template<
typename _Tp>
1406 _If_sv<_Tp, basic_string&>
1409 __sv_type __sv = __svt;
1410 return this->
append(__sv.data(), __sv.size());
1421 template<
typename _Tp>
1422 _If_sv<_Tp, basic_string&>
1423 append(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
1425 __sv_type __sv = __svt;
1426 return append(__sv.data()
1427 + std::__sv_check(__sv.size(), __pos,
"basic_string::append"),
1428 std::__sv_limit(__sv.size(), __pos, __n));
1441 append(
const _CharT* __s, size_type __pos, size_type __n)
1452 const size_type __len = 1 + this->
size();
1453 if (__len > this->
capacity() || _M_rep()->_M_is_shared())
1455 traits_type::assign(_M_data()[this->
size()], __c);
1456 _M_rep()->_M_set_length_and_sharable(__len);
1467#if __cplusplus >= 201103L
1500 {
return this->
assign(__str._M_data()
1501 + __str._M_check(__pos,
"basic_string::assign"),
1502 __str._M_limit(__pos, __n)); }
1529 __glibcxx_requires_string(__s);
1530 return this->
assign(__s, traits_type::length(__s));
1544 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
1554 template<
class _InputIterator>
1556 assign(_InputIterator __first, _InputIterator __last)
1557 {
return this->
replace(_M_ibegin(), _M_iend(), __first, __last); }
1559#if __glibcxx_containers_ranges
1564 template<__detail::__container_compatible_range<_CharT> _Rg>
1566 assign_range(_Rg&& __rg)
1575#if __cplusplus >= 201103L
1583 {
return this->
assign(__l.begin(), __l.size()); }
1586#ifdef __glibcxx_string_view
1592 template<
typename _Tp>
1593 _If_sv<_Tp, basic_string&>
1596 __sv_type __sv = __svt;
1597 return this->
assign(__sv.data(), __sv.size());
1607 template<
typename _Tp>
1608 _If_sv<_Tp, basic_string&>
1609 assign(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
1611 __sv_type __sv = __svt;
1612 return assign(__sv.data()
1613 + std::__sv_check(__sv.size(), __pos,
"basic_string::assign"),
1614 std::__sv_limit(__sv.size(), __pos, __n));
1627 assign(
const _CharT* __s, size_type __pos, size_type __n)
1645 insert(iterator __p, size_type __n, _CharT __c)
1646 { this->
replace(__p, __p, __n, __c); }
1660 template<
class _InputIterator>
1662 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1663 { this->
replace(__p, __p, __beg, __end); }
1665#if __glibcxx_containers_ranges
1670 template<__detail::__container_compatible_range<_CharT> _Rg>
1672 insert_range(const_iterator __p, _Rg&& __rg)
1674 auto __pos = __p -
cbegin();
1677 if (ranges::empty(__rg))
1678 return begin() + __pos;
1688 return begin() + __pos;
1692#if __cplusplus >= 201103L
1702 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1703 this->
insert(__p - _M_ibegin(), __l.begin(), __l.size());
1721 {
return this->
insert(__pos1, __str, size_type(0), __str.size()); }
1743 size_type __pos2, size_type __n =
npos)
1744 {
return this->
insert(__pos1, __str._M_data()
1745 + __str._M_check(__pos2,
"basic_string::insert"),
1746 __str._M_limit(__pos2, __n)); }
1765 insert(size_type __pos,
const _CharT* __s, size_type __n);
1785 __glibcxx_requires_string(__s);
1786 return this->
insert(__pos, __s, traits_type::length(__s));
1806 insert(size_type __pos, size_type __n, _CharT __c)
1807 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
1808 size_type(0), __n, __c); }
1826 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1827 const size_type __pos = __p - _M_ibegin();
1828 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1829 _M_rep()->_M_set_leaked();
1830 return iterator(_M_data() + __pos);
1833#ifdef __glibcxx_string_view
1840 template<
typename _Tp>
1841 _If_sv<_Tp, basic_string&>
1844 __sv_type __sv = __svt;
1845 return this->
insert(__pos, __sv.data(), __sv.size());
1856 template<
typename _Tp>
1857 _If_sv<_Tp, basic_string&>
1858 insert(size_type __pos1,
const _Tp& __svt,
1859 size_type __pos2, size_type __n =
npos)
1861 __sv_type __sv = __svt;
1862 return this->
replace(__pos1, size_type(0), __sv.data()
1863 + std::__sv_check(__sv.size(), __pos2,
"basic_string::insert"),
1864 std::__sv_limit(__sv.size(), __pos2, __n));
1886 _M_mutate(_M_check(__pos,
"basic_string::erase"),
1887 _M_limit(__pos, __n), size_type(0));
1902 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1903 && __position < _M_iend());
1904 const size_type __pos = __position - _M_ibegin();
1905 _M_mutate(__pos, size_type(1), size_type(0));
1906 _M_rep()->_M_set_leaked();
1907 return iterator(_M_data() + __pos);
1920 erase(iterator __first, iterator __last);
1922#if __cplusplus >= 201103L
1931 __glibcxx_assert(!
empty());
1955 {
return this->
replace(__pos, __n, __str._M_data(), __str.size()); }
1977 size_type __pos2, size_type __n2 =
npos)
1978 {
return this->
replace(__pos1, __n1, __str._M_data()
1979 + __str._M_check(__pos2,
"basic_string::replace"),
1980 __str._M_limit(__pos2, __n2)); }
2001 replace(size_type __pos, size_type __n1,
const _CharT* __s,
2021 replace(size_type __pos, size_type __n1,
const _CharT* __s)
2023 __glibcxx_requires_string(__s);
2024 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
2045 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
2046 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
2047 _M_limit(__pos, __n1), __n2, __c); }
2064 {
return this->
replace(__i1, __i2, __str._M_data(), __str.size()); }
2082 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
2084 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2085 && __i2 <= _M_iend());
2086 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
2103 replace(iterator __i1, iterator __i2,
const _CharT* __s)
2105 __glibcxx_requires_string(__s);
2106 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
2124 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
2126 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2127 && __i2 <= _M_iend());
2128 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
2146 template<
class _InputIterator>
2149 _InputIterator __k1, _InputIterator __k2)
2151 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2152 && __i2 <= _M_iend());
2153 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
2154 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
2162 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2163 && __i2 <= _M_iend());
2164 __glibcxx_requires_valid_range(__k1, __k2);
2165 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2170 replace(iterator __i1, iterator __i2,
2171 const _CharT* __k1,
const _CharT* __k2)
2173 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2174 && __i2 <= _M_iend());
2175 __glibcxx_requires_valid_range(__k1, __k2);
2176 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2181 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
2183 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2184 && __i2 <= _M_iend());
2185 __glibcxx_requires_valid_range(__k1, __k2);
2186 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2187 __k1.base(), __k2 - __k1);
2191 replace(iterator __i1, iterator __i2,
2192 const_iterator __k1, const_iterator __k2)
2194 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2195 && __i2 <= _M_iend());
2196 __glibcxx_requires_valid_range(__k1, __k2);
2197 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2198 __k1.base(), __k2 - __k1);
2201#if __glibcxx_containers_ranges
2206 template<__detail::__container_compatible_range<_CharT> _Rg>
2208 replace_with_range(const_iterator __i1, const_iterator __i2, _Rg&& __rg)
2222#if __cplusplus >= 201103L
2239 {
return this->
replace(__i1, __i2, __l.begin(), __l.end()); }
2242#ifdef __glibcxx_string_view
2250 template<
typename _Tp>
2251 _If_sv<_Tp, basic_string&>
2254 __sv_type __sv = __svt;
2255 return this->
replace(__pos, __n, __sv.data(), __sv.size());
2267 template<
typename _Tp>
2268 _If_sv<_Tp, basic_string&>
2269 replace(size_type __pos1, size_type __n1,
const _Tp& __svt,
2270 size_type __pos2, size_type __n2 =
npos)
2272 __sv_type __sv = __svt;
2273 return this->
replace(__pos1, __n1,
2275 + std::__sv_check(__sv.size(), __pos2,
"basic_string::replace"),
2276 std::__sv_limit(__sv.size(), __pos2, __n2));
2288 template<
typename _Tp>
2289 _If_sv<_Tp, basic_string&>
2290 replace(const_iterator __i1, const_iterator __i2,
const _Tp& __svt)
2292 __sv_type __sv = __svt;
2293 return this->
replace(__i1 -
begin(), __i2 - __i1, __sv);
2298 template<
class _Integer>
2300 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
2301 _Integer __val, __true_type)
2302 {
return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
2304 template<
class _InputIterator>
2306 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
2307 _InputIterator __k2, __false_type);
2310 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
2314 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
2319 template<
class _InIterator>
2321 _S_construct_aux(_InIterator __beg, _InIterator __end,
2322 const _Alloc& __a, __false_type)
2324 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
2325 return _S_construct(__beg, __end, __a, _Tag());
2330 template<
class _Integer>
2332 _S_construct_aux(_Integer __beg, _Integer __end,
2333 const _Alloc& __a, __true_type)
2334 {
return _S_construct_aux_2(
static_cast<size_type
>(__beg),
2338 _S_construct_aux_2(size_type __req, _CharT __c,
const _Alloc& __a)
2339 {
return _S_construct(__req, __c, __a); }
2341 template<
class _InIterator>
2343 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a)
2345 typedef typename std::__is_integer<_InIterator>::__type _Integral;
2346 return _S_construct_aux(__beg, __end, __a, _Integral());
2350 template<
class _InIterator>
2352 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
2353 input_iterator_tag);
2357 template<
class _FwdIterator>
2359 _S_construct(_FwdIterator __beg, _FwdIterator __end,
const _Alloc& __a,
2360 forward_iterator_tag);
2363 _S_construct(size_type __req, _CharT __c,
const _Alloc& __a);
2380 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
2402 {
return _M_data(); }
2414 {
return _M_data(); }
2416#if __cplusplus >= 201703L
2441 {
return _M_dataplus; }
2456 find(
const _CharT* __s, size_type __pos, size_type __n)
const
2472 {
return this->
find(__str.data(), __pos, __str.size()); }
2485 find(
const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2487 __glibcxx_requires_string(__s);
2488 return this->
find(__s, __pos, traits_type::length(__s));
2502 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
2504#ifdef __glibcxx_string_view
2511 template<
typename _Tp>
2512 _If_sv<_Tp, size_type>
2513 find(
const _Tp& __svt, size_type __pos = 0) const
2514 noexcept(
is_same<_Tp, __sv_type>::value)
2516 __sv_type __sv = __svt;
2517 return this->
find(__sv.data(), __pos, __sv.size());
2534 {
return this->
rfind(__str.data(), __pos, __str.size()); }
2549 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
2563 rfind(
const _CharT* __s, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT
2565 __glibcxx_requires_string(__s);
2566 return this->
rfind(__s, __pos, traits_type::length(__s));
2580 rfind(_CharT __c, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT;
2582#ifdef __glibcxx_string_view
2589 template<
typename _Tp>
2590 _If_sv<_Tp, size_type>
2591 rfind(
const _Tp& __svt, size_type __pos =
npos)
const
2594 __sv_type __sv = __svt;
2595 return this->
rfind(__sv.data(), __pos, __sv.size());
2613 {
return this->
find_first_of(__str.data(), __pos, __str.size()); }
2645 __glibcxx_requires_string(__s);
2646 return this->
find_first_of(__s, __pos, traits_type::length(__s));
2663 {
return this->
find(__c, __pos); }
2665#ifdef __glibcxx_string_view
2673 template<
typename _Tp>
2674 _If_sv<_Tp, size_type>
2676 noexcept(
is_same<_Tp, __sv_type>::value)
2678 __sv_type __sv = __svt;
2679 return this->
find_first_of(__sv.data(), __pos, __sv.size());
2697 {
return this->
find_last_of(__str.data(), __pos, __str.size()); }
2729 __glibcxx_requires_string(__s);
2730 return this->
find_last_of(__s, __pos, traits_type::length(__s));
2747 {
return this->
rfind(__c, __pos); }
2749#ifdef __glibcxx_string_view
2757 template<
typename _Tp>
2758 _If_sv<_Tp, size_type>
2762 __sv_type __sv = __svt;
2763 return this->
find_last_of(__sv.data(), __pos, __sv.size());
2796 size_type __n)
const _GLIBCXX_NOEXCEPT;
2812 __glibcxx_requires_string(__s);
2830#ifdef __glibcxx_string_view
2838 template<
typename _Tp>
2839 _If_sv<_Tp, size_type>
2841 noexcept(
is_same<_Tp, __sv_type>::value)
2843 __sv_type __sv = __svt;
2878 size_type __n)
const _GLIBCXX_NOEXCEPT;
2894 __glibcxx_requires_string(__s);
2912#ifdef __glibcxx_string_view
2920 template<
typename _Tp>
2921 _If_sv<_Tp, size_type>
2925 __sv_type __sv = __svt;
2945 _M_check(__pos,
"basic_string::substr"), __n); }
2947#ifdef __glibcxx_string_subview
2963 {
return __sv_type(*this).subview(__pos, __n); }
2983 const size_type __size = this->
size();
2984 const size_type __osize = __str.size();
2985 const size_type __len =
std::min(__size, __osize);
2987 int __r = traits_type::compare(_M_data(), __str.data(), __len);
2989 __r = _S_compare(__size, __osize);
2993#ifdef __glibcxx_string_view
2999 template<
typename _Tp>
3001 compare(
const _Tp& __svt)
const
3004 __sv_type __sv = __svt;
3006 const size_type __osize = __sv.size();
3009 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
3011 __r = _S_compare(__size, __osize);
3023 template<
typename _Tp>
3025 compare(size_type __pos, size_type __n,
const _Tp& __svt)
const
3027 __sv_type __sv = __svt;
3028 return __sv_type(*this).substr(__pos, __n).compare(__sv);
3041 template<
typename _Tp>
3043 compare(size_type __pos1, size_type __n1,
const _Tp& __svt,
3044 size_type __pos2, size_type __n2 =
npos)
const
3046 __sv_type __sv = __svt;
3047 return __sv_type(*
this)
3048 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3074 _M_check(__pos,
"basic_string::compare");
3075 __n = _M_limit(__pos, __n);
3076 const size_type __osize = __str.size();
3077 const size_type __len =
std::min(__n, __osize);
3078 int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len);
3080 __r = _S_compare(__n, __osize);
3109 size_type __pos2, size_type __n2 =
npos)
const
3111 _M_check(__pos1,
"basic_string::compare");
3112 __str._M_check(__pos2,
"basic_string::compare");
3113 __n1 = _M_limit(__pos1, __n1);
3114 __n2 = __str._M_limit(__pos2, __n2);
3115 const size_type __len =
std::min(__n1, __n2);
3116 int __r = traits_type::compare(_M_data() + __pos1,
3117 __str.data() + __pos2, __len);
3119 __r = _S_compare(__n1, __n2);
3138 compare(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
3140 __glibcxx_requires_string(__s);
3141 const size_type __size = this->
size();
3142 const size_type __osize = traits_type::length(__s);
3143 const size_type __len =
std::min(__size, __osize);
3144 int __r = traits_type::compare(_M_data(), __s, __len);
3146 __r = _S_compare(__size, __osize);
3172 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const
3174 __glibcxx_requires_string(__s);
3175 _M_check(__pos,
"basic_string::compare");
3176 __n1 = _M_limit(__pos, __n1);
3177 const size_type __osize = traits_type::length(__s);
3178 const size_type __len =
std::min(__n1, __osize);
3179 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
3181 __r = _S_compare(__n1, __osize);
3210 compare(size_type __pos, size_type __n1,
const _CharT* __s,
3211 size_type __n2)
const
3213 __glibcxx_requires_string_len(__s, __n2);
3214 _M_check(__pos,
"basic_string::compare");
3215 __n1 = _M_limit(__pos, __n1);
3216 const size_type __len =
std::min(__n1, __n2);
3217 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
3219 __r = _S_compare(__n1, __n2);
3223#if __cplusplus >= 202002L
3226 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3229 starts_with(_CharT __x)
const noexcept
3230 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3232 [[__gnu__::__nonnull__]]
3234 starts_with(
const _CharT* __x)
const noexcept
3235 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3238 ends_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
3239 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3242 ends_with(_CharT __x)
const noexcept
3243 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3245 [[__gnu__::__nonnull__]]
3247 ends_with(
const _CharT* __x)
const noexcept
3248 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3251#if __cplusplus > 202011L
3253 contains(basic_string_view<_CharT, _Traits> __x)
const noexcept
3254 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3257 contains(_CharT __x)
const noexcept
3258 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3260 [[__gnu__::__nonnull__]]
3262 contains(
const _CharT* __x)
const noexcept
3263 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3266# ifdef _GLIBCXX_TM_TS_INTERNAL
3268 ::_txnal_cow_string_C1_for_exceptions(
void* that,
const char* s,
3271 ::_txnal_cow_string_c_str(
const void *that);
3273 ::_txnal_cow_string_D1(
void *that);
3275 ::_txnal_cow_string_D1_commit(
void *that);
3279 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3280 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
3282 _Rep::_S_max_size = (((npos -
sizeof(_Rep_base))/
sizeof(_CharT)) - 1) / 4;
3284 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3287 _Rep::_S_terminal = _CharT();
3289 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3290 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
3295 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3296 typename basic_string<_CharT, _Traits, _Alloc>::size_type
3297 basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_empty_rep_storage[
3298 (
sizeof(_Rep_base) +
sizeof(_CharT) +
sizeof(
size_type) - 1) /
3305 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3306 template<
typename _InIterator>
3309 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
3312#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3313 if (__beg == __end && __a == _Alloc())
3314 return _S_empty_rep()._M_refdata();
3319 while (__beg != __end && __len <
sizeof(__buf) /
sizeof(_CharT))
3321 __buf[__len++] = *__beg;
3324 _Rep* __r = _Rep::_S_create(__len,
size_type(0), __a);
3325 _M_copy(__r->_M_refdata(), __buf, __len);
3328 while (__beg != __end)
3330 if (__len == __r->_M_capacity)
3333 _Rep* __another = _Rep::_S_create(__len + 1, __len, __a);
3334 _M_copy(__another->_M_refdata(), __r->_M_refdata(), __len);
3335 __r->_M_destroy(__a);
3338 __r->_M_refdata()[__len++] = *__beg;
3344 __r->_M_destroy(__a);
3345 __throw_exception_again;
3347 __r->_M_set_length_and_sharable(__len);
3348 return __r->_M_refdata();
3351 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3352 template <
typename _InIterator>
3355 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
3358#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3359 if (__beg == __end && __a == _Alloc())
3360 return _S_empty_rep()._M_refdata();
3363 if (__gnu_cxx::__is_null_pointer(__beg) && __beg != __end)
3364 __throw_logic_error(__N(
"basic_string::_S_construct null not valid"));
3369 _Rep* __r = _Rep::_S_create(__dnew,
size_type(0), __a);
3371 { _S_copy_chars(__r->_M_refdata(), __beg, __end); }
3374 __r->_M_destroy(__a);
3375 __throw_exception_again;
3377 __r->_M_set_length_and_sharable(__dnew);
3378 return __r->_M_refdata();
3381 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3386#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3387 if (__n == 0 && __a == _Alloc())
3388 return _S_empty_rep()._M_refdata();
3391 _Rep* __r = _Rep::_S_create(__n,
size_type(0), __a);
3393 _M_assign(__r->_M_refdata(), __n, __c);
3395 __r->_M_set_length_and_sharable(__n);
3396 return __r->_M_refdata();
3399 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3402 : _M_dataplus(_S_construct(__str._M_data()
3403 + __str._M_check(__pos,
3404 "basic_string::basic_string"),
3405 __str._M_data() + __str._M_limit(__pos, npos)
3409 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3412 : _M_dataplus(_S_construct(__str._M_data()
3413 + __str._M_check(__pos,
3414 "basic_string::basic_string"),
3415 __str._M_data() + __str._M_limit(__pos, __n)
3416 + __pos, _Alloc()), _Alloc())
3419 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3423 : _M_dataplus(_S_construct(__str._M_data()
3424 + __str._M_check(__pos,
3425 "basic_string::basic_string"),
3426 __str._M_data() + __str._M_limit(__pos, __n)
3430 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3435 if (_M_rep() != __str._M_rep())
3438 const allocator_type __a = this->get_allocator();
3439 _CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.get_allocator());
3440 _M_rep()->_M_dispose(__a);
3446 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3451 __glibcxx_requires_string_len(__s, __n);
3452 _M_check_length(this->
size(), __n,
"basic_string::assign");
3453 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3454 return _M_replace_safe(
size_type(0), this->
size(), __s, __n);
3458 const size_type __pos = __s - _M_data();
3460 _M_copy(_M_data(), __s, __n);
3462 _M_move(_M_data(), __s, __n);
3463 _M_rep()->_M_set_length_and_sharable(__n);
3468 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3475 _M_check_length(
size_type(0), __n,
"basic_string::append");
3477 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3478 this->reserve(__len);
3479 _M_assign(_M_data() + this->
size(), __n, __c);
3480 _M_rep()->_M_set_length_and_sharable(__len);
3485 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3490 __glibcxx_requires_string_len(__s, __n);
3493 _M_check_length(
size_type(0), __n,
"basic_string::append");
3495 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3497 if (_M_disjunct(__s))
3498 this->reserve(__len);
3501 const size_type __off = __s - _M_data();
3502 this->reserve(__len);
3503 __s = _M_data() + __off;
3506 _M_copy(_M_data() + this->
size(), __s, __n);
3507 _M_rep()->_M_set_length_and_sharable(__len);
3512 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3521 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3522 this->reserve(__len);
3523 _M_copy(_M_data() + this->
size(), __str._M_data(), __size);
3524 _M_rep()->_M_set_length_and_sharable(__len);
3529 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3534 __str._M_check(__pos,
"basic_string::append");
3535 __n = __str._M_limit(__pos, __n);
3539 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3540 this->reserve(__len);
3541 _M_copy(_M_data() + this->
size(), __str._M_data() + __pos, __n);
3542 _M_rep()->_M_set_length_and_sharable(__len);
3547 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3552 __glibcxx_requires_string_len(__s, __n);
3553 _M_check(__pos,
"basic_string::insert");
3554 _M_check_length(
size_type(0), __n,
"basic_string::insert");
3555 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3556 return _M_replace_safe(__pos,
size_type(0), __s, __n);
3560 const size_type __off = __s - _M_data();
3561 _M_mutate(__pos, 0, __n);
3562 __s = _M_data() + __off;
3563 _CharT* __p = _M_data() + __pos;
3564 if (__s + __n <= __p)
3565 _M_copy(__p, __s, __n);
3566 else if (__s >= __p)
3567 _M_copy(__p, __s + __n, __n);
3571 _M_copy(__p, __s, __nleft);
3572 _M_copy(__p + __nleft, __p + __n, __n - __nleft);
3578 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3579 typename basic_string<_CharT, _Traits, _Alloc>::iterator
3581 erase(iterator __first, iterator __last)
3583 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
3584 && __last <= _M_iend());
3589 const size_type __size = __last - __first;
3592 const size_type __pos = __first - _M_ibegin();
3593 _M_mutate(__pos, __size, size_type(0));
3594 _M_rep()->_M_set_leaked();
3595 return iterator(_M_data() + __pos);
3601 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3607 __glibcxx_requires_string_len(__s, __n2);
3608 _M_check(__pos,
"basic_string::replace");
3609 __n1 = _M_limit(__pos, __n1);
3610 _M_check_length(__n1, __n2,
"basic_string::replace");
3612 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3613 return _M_replace_safe(__pos, __n1, __s, __n2);
3614 else if ((__left = __s + __n2 <= _M_data() + __pos)
3615 || _M_data() + __pos + __n1 <= __s)
3619 __left ? __off : (__off += __n2 - __n1);
3620 _M_mutate(__pos, __n1, __n2);
3621 _M_copy(_M_data() + __pos, _M_data() + __off, __n2);
3627 const basic_string __tmp(__s, __n2);
3628 return _M_replace_safe(__pos, __n1, __tmp._M_data(), __n2);
3632 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3637 const size_type __size =
sizeof(_Rep_base)
3638 + (this->_M_capacity + 1) *
sizeof(_CharT);
3639 _Raw_bytes_alloc(__a).deallocate(
reinterpret_cast<char*
>(
this), __size);
3642 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3654 if (_M_rep()->_M_is_shared())
3656 _M_rep()->_M_set_leaked();
3659 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3665 const size_type __new_size = __old_size + __len2 - __len1;
3666 const size_type __how_much = __old_size - __pos - __len1;
3668 if (__new_size > this->capacity() || _M_rep()->_M_is_shared())
3671 const allocator_type __a = get_allocator();
3672 _Rep* __r = _Rep::_S_create(__new_size, this->capacity(), __a);
3675 _M_copy(__r->_M_refdata(), _M_data(), __pos);
3677 _M_copy(__r->_M_refdata() + __pos + __len2,
3678 _M_data() + __pos + __len1, __how_much);
3680 _M_rep()->_M_dispose(__a);
3681 _M_data(__r->_M_refdata());
3683 else if (__how_much && __len1 != __len2)
3686 _M_move(_M_data() + __pos + __len2,
3687 _M_data() + __pos + __len1, __how_much);
3689 _M_rep()->_M_set_length_and_sharable(__new_size);
3692 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3697 const size_type __capacity =
capacity();
3703 if (__res <= __capacity)
3705 if (!_M_rep()->_M_is_shared())
3713 _CharT* __tmp = _M_rep()->_M_clone(__a, __res - this->
size());
3714 _M_rep()->_M_dispose(__a);
3718 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3724 if (_M_rep()->_M_is_leaked())
3725 _M_rep()->_M_set_sharable();
3726 if (__s._M_rep()->_M_is_leaked())
3727 __s._M_rep()->_M_set_sharable();
3730 _CharT* __tmp = _M_data();
3731 _M_data(__s._M_data());
3738 __s.get_allocator());
3739 const basic_string __tmp2(__s._M_ibegin(), __s._M_iend(),
3740 this->get_allocator());
3746 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3747 typename basic_string<_CharT, _Traits, _Alloc>::_Rep*
3750 const _Alloc& __alloc)
3754 if (__capacity > _S_max_size)
3755 __throw_length_error(__N(
"basic_string::_S_create"));
3781 const size_type __malloc_header_size = 4 *
sizeof(
void*);
3789 if (__capacity > __old_capacity && __capacity < 2 * __old_capacity)
3790 __capacity = 2 * __old_capacity;
3795 size_type __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
3797 const size_type __adj_size = __size + __malloc_header_size;
3798 if (__adj_size > __pagesize && __capacity > __old_capacity)
3800 const size_type __extra = __pagesize - __adj_size % __pagesize;
3801 __capacity += __extra /
sizeof(_CharT);
3803 if (__capacity > _S_max_size)
3804 __capacity = _S_max_size;
3805 __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
3810 void* __place = _Raw_bytes_alloc(__alloc).
allocate(__size);
3811 _Rep *__p =
new (__place) _Rep;
3812 __p->_M_capacity = __capacity;
3820 __p->_M_set_sharable();
3824 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3827 _M_clone(
const _Alloc& __alloc, size_type __res)
3830 const size_type __requested_cap = this->_M_length + __res;
3831 _Rep* __r = _Rep::_S_create(__requested_cap, this->_M_capacity,
3833 if (this->_M_length)
3834 _M_copy(__r->_M_refdata(), _M_refdata(), this->_M_length);
3836 __r->_M_set_length_and_sharable(this->_M_length);
3837 return __r->_M_refdata();
3840 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3843 resize(size_type __n, _CharT __c)
3845 const size_type __size = this->
size();
3846 _M_check_length(__size, __n,
"basic_string::resize");
3848 this->
append(__n - __size, __c);
3849 else if (__n < __size)
3854 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3855 template<
typename _InputIterator>
3859 _InputIterator __k2, __false_type)
3861 __glibcxx_requires_valid_range(__k1, __k2);
3864 _M_check_length(__n1, __s.size(),
"basic_string::_M_replace_dispatch");
3865 return _M_replace_safe(__i1 - _M_ibegin(), __n1, __s._M_data(),
3869 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3871 basic_string<_CharT, _Traits, _Alloc>::
3872 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
3875 _M_check_length(__n1, __n2,
"basic_string::_M_replace_aux");
3876 _M_mutate(__pos1, __n1, __n2);
3878 _M_assign(_M_data() + __pos1, __n2, __c);
3882 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3888 _M_mutate(__pos1, __n1, __n2);
3890 _M_copy(_M_data() + __pos1, __s, __n2);
3894 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3904 _CharT* __tmp = _M_rep()->_M_clone(__a);
3905 _M_rep()->_M_dispose(__a);
3915 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3916 typename basic_string<_CharT, _Traits, _Alloc>::size_type
3918 copy(_CharT* __s, size_type __n, size_type __pos)
const
3920 _M_check(__pos,
"basic_string::copy");
3921 __n = _M_limit(__pos, __n);
3922 __glibcxx_requires_string_len(__s, __n);
3924 _M_copy(__s, _M_data() + __pos, __n);
3929#ifdef __glibcxx_string_resize_and_overwrite
3930 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3931 template<
typename _Operation>
3932 [[__gnu__::__always_inline__]]
3936 { resize_and_overwrite<_Operation&>(__n, __op); }
3939#if __cplusplus >= 201103L
3940 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3941 template<
typename _Operation>
3944#ifdef __glibcxx_string_resize_and_overwrite
3945 resize_and_overwrite(
const size_type __n, _Operation __op)
3950 const size_type __capacity =
capacity();
3952 if (__n > __capacity || _M_rep()->_M_is_shared())
3955 struct _Terminator {
3956 ~_Terminator() { _M_this->_M_rep()->_M_set_length_and_sharable(_M_r); }
3957 basic_string* _M_this;
3960 _Terminator __term{
this, 0};
3961 auto __r =
std::move(__op)(__p + 0, __n + 0);
3962#ifdef __cpp_lib_concepts
3963 static_assert(ranges::__detail::__is_integer_like<
decltype(__r)>);
3965 static_assert(__gnu_cxx::__is_integer_nonstrict<
decltype(__r)>::__value,
3966 "resize_and_overwrite operation must return an integer");
3968 _GLIBCXX_DEBUG_ASSERT(__r >= 0 && size_type(__r) <= __n);
3969 __term._M_r = size_type(__r);
3970 if (__term._M_r > __n)
3971 __builtin_unreachable();
3976_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 _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
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.
A non-owning reference to a string.
static constexpr pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
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
basic_string & insert(size_type __pos, const _CharT *__s, size_type __n)
Insert a C substring.
void swap(basic_string &__s) noexcept(/*conditional */)
Swap contents with another string.
basic_string & operator=(const _CharT *__s)
Copy contents of s into this string.
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.
constexpr basic_string() noexcept(/*conditional */)
Default constructor creates an empty 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.
basic_string & append(size_type __n, _CharT __c)
Append multiple characters.
size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
constexpr size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
iterator erase(iterator __first, iterator __last)
Remove a range of characters.
constexpr void clear() noexcept
const _CharT * data() const noexcept
Return const pointer to contents.
size_type find_last_of(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find last position of a character of C substring.
basic_string(const _Alloc &__a)
Construct an empty string using allocator a.
constexpr 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.
size_type find_last_of(const _CharT *__s, size_type __pos=npos) const noexcept
Find last position of a character of C string.
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.
void reserve(size_type __res_arg)
Attempt to preallocate enough memory for specified number of characters.
iterator erase(iterator __position)
Remove one character.
constexpr 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.
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.
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C string.
int compare(size_type __pos, size_type __n, const basic_string &__str) const
Compare substring to a string.
basic_string() noexcept
Default constructor creates an empty string.
constexpr const _CharT * data() const noexcept
Return const pointer to contents.
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.
constexpr basic_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
basic_string & assign(const _CharT *__s, size_type __n)
Set value to a C substring.
int compare(size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) const
Compare substring against a character array.
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.
constexpr basic_string & assign(const basic_string &__str)
Set value to contents of another string.
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.
constexpr size_type length() const noexcept
basic_string(const basic_string &__str, size_type __pos, size_type __n, const _Alloc &__a)
Construct string as copy of a 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.
void pop_back()
Remove the last character.
basic_string(basic_string &&__str) noexcept
Move construct string.
constexpr 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.
constexpr const_iterator cbegin() const noexcept
size_type find_first_not_of(_CharT __c, size_type __pos=0) const noexcept
Find position of a different character.
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.
constexpr size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of 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.
_CharT * data() noexcept(false)
Return non-const pointer to contents.
size_type find(_CharT __c, size_type __pos=0) const noexcept
Find position of a character.
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
constexpr void __resize_and_overwrite(size_type __n, _Operation __op)
Non-standard version of resize_and_overwrite for C++11 and above.
basic_string & replace(size_type __pos, size_type __n1, const _CharT *__s, size_type __n2)
Replace characters with value of a C substring.
size_type find_last_of(_CharT __c, size_type __pos=npos) const noexcept
Find last position of a character.
constexpr size_type rfind(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a string.
constexpr 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
constexpr size_type find_last_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character of string.
size_type find_last_not_of(_CharT __c, size_type __pos=npos) const noexcept
Find last position of a different character.
constexpr iterator end() noexcept
constexpr iterator begin() noexcept
basic_string & append(const _CharT *__s, size_type __n)
Append a C substring.
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(const basic_string &__str, size_type __pos, size_type __n=npos)
Append a substring.
basic_string & append(_InputIterator __first, _InputIterator __last)
Append a range of characters.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
basic_string(const _CharT *__s, const _Alloc &__a=_Alloc())
Construct string as copy of a C string.
constexpr void push_back(_CharT __c)
Append a single character.
size_type find_first_of(_CharT __c, size_type __pos=0) const noexcept
Find position of a character.
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
constexpr size_type find_first_not_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character not in string.
basic_string & insert(size_type __pos, const _CharT *__s)
Insert a C string.
constexpr iterator insert(const_iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
basic_string & assign(const basic_string &__str, size_type __pos, size_type __n=npos)
Set value to a substring of a string.
constexpr size_type capacity() const noexcept
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
basic_string & replace(size_type __pos, size_type __n1, const _CharT *__s)
Replace characters with value of a C string.
constexpr bool empty() const noexcept
size_type find(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find position of a C substring.
static const size_type npos
Value returned by various member functions when they fail.
constexpr basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
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 & append(const basic_string &__str)
Append a string to this string.
size_type find_first_not_of(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find position of a character not in C substring.
basic_string & replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
Replace characters with multiple characters.
const_iterator cbegin() const noexcept
constexpr allocator_type get_allocator() const noexcept
constexpr basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
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
size_type find_first_of(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find position of a character of C substring.
constexpr basic_string_view< _CharT, _Traits > subview(size_type __pos=0, size_type __n=npos) const
Get a subview.
void insert(iterator __p, _InputIterator __beg, _InputIterator __end)
Insert a range of characters.
constexpr int compare(const basic_string &__str) const
Compare to a string.
size_type find_first_of(const _CharT *__s, size_type __pos=0) const noexcept
Find position of a character of C string.
size_type rfind(_CharT __c, size_type __pos=npos) const noexcept
Find last position of a character.
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.
constexpr size_type max_size() const noexcept
Returns the size() of the largest possible string.
basic_string(const _CharT *__s, size_type __n, const _Alloc &__a=_Alloc())
Construct string initialized by a character array.
constexpr void swap(basic_string &__s) noexcept
Swap contents with another string.
basic_string & append(const _CharT *__s)
Append a C string.
constexpr const_reference operator[](size_type __pos) const noexcept
Subscript access to the data contained in the string.
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
size_type rfind(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find last position of a C substring.
constexpr basic_string & operator+=(const basic_string &__str)
Append a string to this 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.
size_type find_last_not_of(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find last position of a character not in C substring.
constexpr const_iterator cend() const noexcept
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.
Forward iterators support a superset of input iterator operations.
[range.sized] The sized_range concept.
A range for which ranges::begin returns a forward iterator.
A range for which ranges::begin returns a contiguous iterator.