33#define _COW_STRING_H 1
35#if ! _GLIBCXX_USE_CXX11_ABI
39#ifdef __cpp_lib_is_constant_evaluated
41# define __cpp_lib_constexpr_string 201811L
42#elif __cplusplus >= 201703L && _GLIBCXX_HAVE_IS_CONSTANT_EVALUATED
44# define __cpp_lib_constexpr_string 201611L
47namespace std _GLIBCXX_VISIBILITY(default)
49_GLIBCXX_BEGIN_NAMESPACE_VERSION
113 template<
typename _CharT,
typename _Traits,
typename _Alloc>
117 rebind<_CharT>::other _CharT_alloc_type;
122 typedef _Traits traits_type;
123 typedef typename _Traits::char_type value_type;
124 typedef _Alloc allocator_type;
125 typedef typename _CharT_alloc_traits::size_type size_type;
126 typedef typename _CharT_alloc_traits::difference_type difference_type;
127#if __cplusplus < 201103L
128 typedef typename _CharT_alloc_type::reference reference;
129 typedef typename _CharT_alloc_type::const_reference const_reference;
131 typedef value_type& reference;
132 typedef const value_type& const_reference;
134 typedef typename _CharT_alloc_traits::pointer pointer;
135 typedef typename _CharT_alloc_traits::const_pointer const_pointer;
136 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
137 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
144 typedef iterator __const_iterator;
164 size_type _M_capacity;
165 _Atomic_word _M_refcount;
168 struct _Rep : _Rep_base
172 rebind<char>::other _Raw_bytes_alloc;
187 static const size_type _S_max_size;
188 static const _CharT _S_terminal;
192 static size_type _S_empty_rep_storage[];
195 _S_empty_rep() _GLIBCXX_NOEXCEPT
200 void* __p =
reinterpret_cast<void*
>(&_S_empty_rep_storage);
201 return *
reinterpret_cast<_Rep*
>(__p);
205 _M_is_leaked()
const _GLIBCXX_NOEXCEPT
207#if defined(__GTHREADS)
212 return __atomic_load_n(&this->_M_refcount, __ATOMIC_RELAXED) < 0;
214 return this->_M_refcount < 0;
219 _M_is_shared()
const _GLIBCXX_NOEXCEPT
221#if defined(__GTHREADS)
227 if (!__gnu_cxx::__is_single_threaded())
228 return __atomic_load_n(&this->_M_refcount, __ATOMIC_ACQUIRE) > 0;
230 return this->_M_refcount > 0;
234 _M_set_leaked() _GLIBCXX_NOEXCEPT
235 { this->_M_refcount = -1; }
238 _M_set_sharable() _GLIBCXX_NOEXCEPT
239 { this->_M_refcount = 0; }
242 _M_set_length_and_sharable(size_type __n) _GLIBCXX_NOEXCEPT
244#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
245 if (__builtin_expect(
this != &_S_empty_rep(),
false))
248 this->_M_set_sharable();
249 this->_M_length = __n;
250 traits_type::assign(this->_M_refdata()[__n], _S_terminal);
258 {
return reinterpret_cast<_CharT*
>(
this + 1); }
261 _M_grab(
const _Alloc& __alloc1,
const _Alloc& __alloc2)
263 return (!_M_is_leaked() && __alloc1 == __alloc2)
264 ? _M_refcopy() : _M_clone(__alloc1);
269 _S_create(size_type, size_type,
const _Alloc&);
272 _M_dispose(
const _Alloc& __a) _GLIBCXX_NOEXCEPT
274#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
275 if (__builtin_expect(
this != &_S_empty_rep(),
false))
279 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount);
288 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
291 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount);
298 _M_destroy(
const _Alloc&)
throw();
303#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
304 if (__builtin_expect(
this != &_S_empty_rep(),
false))
306 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
311 _M_clone(
const _Alloc&, size_type __res = 0);
315 struct _Alloc_hider : _Alloc
317 _Alloc_hider(_CharT* __dat,
const _Alloc& __a) _GLIBCXX_NOEXCEPT
318 : _Alloc(__a), _M_p(__dat) { }
328 static const size_type
npos =
static_cast<size_type
>(-1);
332 mutable _Alloc_hider _M_dataplus;
335 _M_data() const _GLIBCXX_NOEXCEPT
336 {
return _M_dataplus._M_p; }
339 _M_data(_CharT* __p) _GLIBCXX_NOEXCEPT
340 {
return (_M_dataplus._M_p = __p); }
343 _M_rep() const _GLIBCXX_NOEXCEPT
344 {
return &((
reinterpret_cast<_Rep*
> (_M_data()))[-1]); }
349 _M_ibegin() const _GLIBCXX_NOEXCEPT
350 {
return iterator(_M_data()); }
353 _M_iend() const _GLIBCXX_NOEXCEPT
354 {
return iterator(_M_data() + this->
size()); }
359 if (!_M_rep()->_M_is_leaked())
364 _M_check(size_type __pos,
const char* __s)
const
366 if (__pos > this->
size())
367 __throw_out_of_range_fmt(__N(
"%s: __pos (which is %zu) > "
368 "this->size() (which is %zu)"),
369 __s, __pos, this->
size());
374 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
377 __throw_length_error(__N(__s));
382 _M_limit(size_type __pos, size_type __off)
const _GLIBCXX_NOEXCEPT
384 const bool __testoff = __off < this->
size() - __pos;
385 return __testoff ? __off : this->
size() - __pos;
390 _M_disjunct(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
392 return (less<const _CharT*>()(__s, _M_data())
393 || less<const _CharT*>()(_M_data() + this->
size(), __s));
399 _M_copy(_CharT* __d,
const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
402 traits_type::assign(*__d, *__s);
404 traits_type::copy(__d, __s, __n);
408 _M_move(_CharT* __d,
const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
411 traits_type::assign(*__d, *__s);
413 traits_type::move(__d, __s, __n);
417 _M_assign(_CharT* __d, size_type __n, _CharT __c) _GLIBCXX_NOEXCEPT
420 traits_type::assign(*__d, __c);
422 traits_type::assign(__d, __n, __c);
427 template<
class _Iterator>
429 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
431 for (; __k1 != __k2; ++__k1, (void)++__p)
432 traits_type::assign(*__p, *__k1);
436 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
437 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
440 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
442 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
445 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
446 { _M_copy(__p, __k1, __k2 - __k1); }
449 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
451 { _M_copy(__p, __k1, __k2 - __k1); }
454 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
456 const difference_type __d = difference_type(__n1 - __n2);
458 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
459 return __gnu_cxx::__numeric_traits<int>::__max;
460 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
461 return __gnu_cxx::__numeric_traits<int>::__min;
467 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
473 _S_empty_rep() _GLIBCXX_NOEXCEPT
474 {
return _Rep::_S_empty_rep(); }
476#if __cplusplus >= 201703L
478 typedef basic_string_view<_CharT, _Traits> __sv_type;
480 template<
typename _Tp,
typename _Res>
482 __and_<is_convertible<const _Tp&, __sv_type>,
483 __not_<is_convertible<const _Tp*, const basic_string*>>,
484 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
489 _S_to_string_view(__sv_type __svt)
noexcept
498 explicit __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
522#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
524 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc())
526 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc())
535 : _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a)
544 : _M_dataplus(__str._M_rep()->_M_grab(_Alloc(__str.
get_allocator()),
558 const _Alloc& __a = _Alloc());
576 size_type __n,
const _Alloc& __a);
588 const _Alloc& __a = _Alloc())
589 : _M_dataplus(_S_construct(__s, __s + __n, __a), __a)
597#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
600 template<
typename = _RequireAllocator<_Alloc>>
603 : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::
length(__s) :
604 __s +
npos, __a), __a)
614 : _M_dataplus(_S_construct(__n, __c, __a), __a)
617#if __cplusplus >= 201103L
626 : _M_dataplus(
std::move(__str._M_dataplus))
628#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
630 __str._M_data(_S_empty_rep()._M_refdata());
636 if (_M_rep()->_M_is_shared())
637 __gnu_cxx::__atomic_add_dispatch(&_M_rep()->_M_refcount, 1);
639 _M_rep()->_M_refcount = 1;
649 : _M_dataplus(_S_construct(__l.
begin(), __l.
end(), __a), __a)
653 : _M_dataplus(__str._M_rep()->_M_grab(__a, __str.
get_allocator()), __a)
657 : _M_dataplus(__str._M_data(), __a)
661#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
662 __str._M_data(_S_empty_rep()._M_refdata());
664 __str._M_data(_S_construct(size_type(), _CharT(), __a));
668 _M_dataplus._M_p = _S_construct(__str.
begin(), __str.
end(), __a);
672#if __cplusplus >= 202100L
683 template<
class _InputIterator>
685 const _Alloc& __a = _Alloc())
686 : _M_dataplus(_S_construct(__beg, __end, __a), __a)
689#if __cplusplus >= 201703L
697 template<
typename _Tp,
700 const _Alloc& __a = _Alloc())
708 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
711 :
basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
726 {
return this->
assign(__str); }
734 {
return this->
assign(__s); }
750#if __cplusplus >= 201103L
774 this->
assign(__l.begin(), __l.size());
779#if __cplusplus >= 201703L
784 template<
typename _Tp>
785 _If_sv<_Tp, basic_string&>
787 {
return this->
assign(__svt); }
806 return iterator(_M_data());
815 {
return const_iterator(_M_data()); }
825 return iterator(_M_data() + this->
size());
833 end() const _GLIBCXX_NOEXCEPT
834 {
return const_iterator(_M_data() + this->
size()); }
850 const_reverse_iterator
868 const_reverse_iterator
872#if __cplusplus >= 201103L
879 {
return const_iterator(this->_M_data()); }
887 {
return const_iterator(this->_M_data() + this->
size()); }
894 const_reverse_iterator
903 const_reverse_iterator
916#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 && __OPTIMIZE__
917 if (_S_empty_rep()._M_length != 0)
918 __builtin_unreachable();
920 return _M_rep()->_M_length;
932 {
return _Rep::_S_max_size; }
959 { this->
resize(__n, _CharT()); }
961#if __cplusplus >= 201103L
962#pragma GCC diagnostic push
963#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
968#pragma GCC diagnostic pop
977 {
return _M_rep()->_M_capacity; }
1000#if __cplusplus > 201703L
1001 [[deprecated(
"use shrink_to_fit() instead")]]
1009#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
1013 if (_M_rep()->_M_is_shared())
1016 _M_data(_S_empty_rep()._M_refdata());
1019 _M_rep()->_M_set_length_and_sharable(0);
1025 { _M_mutate(0, this->
size(), 0); }
1032 _GLIBCXX_NODISCARD
bool
1034 {
return this->
size() == 0; }
1050 __glibcxx_assert(__pos <=
size());
1051 return _M_data()[__pos];
1069 __glibcxx_assert(__pos <=
size());
1071 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos <
size());
1073 return _M_data()[__pos];
1089 if (__n >= this->
size())
1090 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1091 "(which is %zu) >= this->size() "
1094 return _M_data()[__n];
1112 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1113 "(which is %zu) >= this->size() "
1117 return _M_data()[__n];
1120#if __cplusplus >= 201103L
1128 __glibcxx_assert(!
empty());
1139 __glibcxx_assert(!
empty());
1150 __glibcxx_assert(!
empty());
1161 __glibcxx_assert(!
empty());
1174 {
return this->
append(__str); }
1183 {
return this->
append(__s); }
1197#if __cplusplus >= 201103L
1205 {
return this->
append(__l.begin(), __l.size()); }
1208#if __cplusplus >= 201703L
1214 template<
typename _Tp>
1215 _If_sv<_Tp, basic_string&>
1217 {
return this->
append(__svt); }
1261 __glibcxx_requires_string(__s);
1262 return this->
append(__s, traits_type::length(__s));
1276#if __cplusplus >= 201103L
1284 {
return this->
append(__l.begin(), __l.size()); }
1295 template<
class _InputIterator>
1297 append(_InputIterator __first, _InputIterator __last)
1298 {
return this->
replace(_M_iend(), _M_iend(), __first, __last); }
1300#if __cplusplus >= 201703L
1306 template<
typename _Tp>
1307 _If_sv<_Tp, basic_string&>
1311 return this->
append(__sv.data(), __sv.size());
1322 template<
typename _Tp>
1323 _If_sv<_Tp, basic_string&>
1327 return append(__sv.data()
1328 + std::__sv_check(__sv.size(), __pos,
"basic_string::append"),
1329 std::__sv_limit(__sv.size(), __pos, __n));
1340 const size_type __len = 1 + this->
size();
1341 if (__len > this->
capacity() || _M_rep()->_M_is_shared())
1343 traits_type::assign(_M_data()[this->
size()], __c);
1344 _M_rep()->_M_set_length_and_sharable(__len);
1355#if __cplusplus >= 201103L
1388 {
return this->
assign(__str._M_data()
1389 + __str._M_check(__pos,
"basic_string::assign"),
1390 __str._M_limit(__pos, __n)); }
1417 __glibcxx_requires_string(__s);
1418 return this->
assign(__s, traits_type::length(__s));
1432 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
1442 template<
class _InputIterator>
1444 assign(_InputIterator __first, _InputIterator __last)
1445 {
return this->
replace(_M_ibegin(), _M_iend(), __first, __last); }
1447#if __cplusplus >= 201103L
1455 {
return this->
assign(__l.begin(), __l.size()); }
1458#if __cplusplus >= 201703L
1464 template<
typename _Tp>
1465 _If_sv<_Tp, basic_string&>
1469 return this->
assign(__sv.data(), __sv.size());
1479 template<
typename _Tp>
1480 _If_sv<_Tp, basic_string&>
1484 return assign(__sv.data()
1485 + std::__sv_check(__sv.size(), __pos,
"basic_string::assign"),
1486 std::__sv_limit(__sv.size(), __pos, __n));
1504 insert(iterator __p, size_type __n, _CharT __c)
1505 { this->
replace(__p, __p, __n, __c); }
1519 template<
class _InputIterator>
1521 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1522 { this->
replace(__p, __p, __beg, __end); }
1524#if __cplusplus >= 201103L
1534 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1535 this->
insert(__p - _M_ibegin(), __l.begin(), __l.size());
1553 {
return this->
insert(__pos1, __str, size_type(0), __str.
size()); }
1575 size_type __pos2, size_type __n =
npos)
1576 {
return this->
insert(__pos1, __str._M_data()
1577 + __str._M_check(__pos2,
"basic_string::insert"),
1578 __str._M_limit(__pos2, __n)); }
1597 insert(size_type __pos,
const _CharT* __s, size_type __n);
1617 __glibcxx_requires_string(__s);
1618 return this->
insert(__pos, __s, traits_type::length(__s));
1638 insert(size_type __pos, size_type __n, _CharT __c)
1639 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
1640 size_type(0), __n, __c); }
1658 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1659 const size_type __pos = __p - _M_ibegin();
1660 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1661 _M_rep()->_M_set_leaked();
1662 return iterator(_M_data() + __pos);
1665#if __cplusplus >= 201703L
1672 template<
typename _Tp>
1673 _If_sv<_Tp, basic_string&>
1677 return this->
insert(__pos, __sv.data(), __sv.size());
1688 template<
typename _Tp>
1689 _If_sv<_Tp, basic_string&>
1691 size_type __pos2, size_type __n =
npos)
1694 return this->
replace(__pos1, size_type(0), __sv.data()
1695 + std::__sv_check(__sv.size(), __pos2,
"basic_string::insert"),
1696 std::__sv_limit(__sv.size(), __pos2, __n));
1718 _M_mutate(_M_check(__pos,
"basic_string::erase"),
1719 _M_limit(__pos, __n), size_type(0));
1734 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1735 && __position < _M_iend());
1736 const size_type __pos = __position - _M_ibegin();
1737 _M_mutate(__pos, size_type(1), size_type(0));
1738 _M_rep()->_M_set_leaked();
1739 return iterator(_M_data() + __pos);
1752 erase(iterator __first, iterator __last);
1754#if __cplusplus >= 201103L
1763 __glibcxx_assert(!
empty());
1787 {
return this->
replace(__pos, __n, __str._M_data(), __str.
size()); }
1809 size_type __pos2, size_type __n2 =
npos)
1810 {
return this->
replace(__pos1, __n1, __str._M_data()
1811 + __str._M_check(__pos2,
"basic_string::replace"),
1812 __str._M_limit(__pos2, __n2)); }
1833 replace(size_type __pos, size_type __n1,
const _CharT* __s,
1853 replace(size_type __pos, size_type __n1,
const _CharT* __s)
1855 __glibcxx_requires_string(__s);
1856 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
1877 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1878 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
1879 _M_limit(__pos, __n1), __n2, __c); }
1896 {
return this->
replace(__i1, __i2, __str._M_data(), __str.
size()); }
1914 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
1916 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1917 && __i2 <= _M_iend());
1918 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1935 replace(iterator __i1, iterator __i2,
const _CharT* __s)
1937 __glibcxx_requires_string(__s);
1938 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
1956 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1958 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1959 && __i2 <= _M_iend());
1960 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1978 template<
class _InputIterator>
1981 _InputIterator __k1, _InputIterator __k2)
1983 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1984 && __i2 <= _M_iend());
1985 __glibcxx_requires_valid_range(__k1, __k2);
1986 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1987 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1995 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1996 && __i2 <= _M_iend());
1997 __glibcxx_requires_valid_range(__k1, __k2);
1998 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2003 replace(iterator __i1, iterator __i2,
2004 const _CharT* __k1,
const _CharT* __k2)
2006 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2007 && __i2 <= _M_iend());
2008 __glibcxx_requires_valid_range(__k1, __k2);
2009 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2014 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
2016 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2017 && __i2 <= _M_iend());
2018 __glibcxx_requires_valid_range(__k1, __k2);
2019 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2020 __k1.base(), __k2 - __k1);
2024 replace(iterator __i1, iterator __i2,
2025 const_iterator __k1, const_iterator __k2)
2027 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2028 && __i2 <= _M_iend());
2029 __glibcxx_requires_valid_range(__k1, __k2);
2030 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2031 __k1.base(), __k2 - __k1);
2034#if __cplusplus >= 201103L
2051 {
return this->
replace(__i1, __i2, __l.begin(), __l.end()); }
2054#if __cplusplus >= 201703L
2062 template<
typename _Tp>
2063 _If_sv<_Tp, basic_string&>
2064 replace(size_type __pos, size_type __n,
const _Tp& __svt)
2067 return this->
replace(__pos, __n, __sv.data(), __sv.size());
2079 template<
typename _Tp>
2080 _If_sv<_Tp, basic_string&>
2081 replace(size_type __pos1, size_type __n1,
const _Tp& __svt,
2082 size_type __pos2, size_type __n2 =
npos)
2085 return this->
replace(__pos1, __n1,
2087 + std::__sv_check(__sv.size(), __pos2,
"basic_string::replace"),
2088 std::__sv_limit(__sv.size(), __pos2, __n2));
2100 template<
typename _Tp>
2101 _If_sv<_Tp, basic_string&>
2102 replace(const_iterator __i1, const_iterator __i2,
const _Tp& __svt)
2105 return this->
replace(__i1 -
begin(), __i2 - __i1, __sv);
2110 template<
class _Integer>
2113 _Integer __val, __true_type)
2114 {
return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
2116 template<
class _InputIterator>
2118 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
2119 _InputIterator __k2, __false_type);
2122 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
2126 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
2131 template<
class _InIterator>
2133 _S_construct_aux(_InIterator __beg, _InIterator __end,
2134 const _Alloc& __a, __false_type)
2136 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
2137 return _S_construct(__beg, __end, __a, _Tag());
2142 template<
class _Integer>
2144 _S_construct_aux(_Integer __beg, _Integer __end,
2145 const _Alloc& __a, __true_type)
2146 {
return _S_construct_aux_2(
static_cast<size_type
>(__beg),
2150 _S_construct_aux_2(size_type __req, _CharT __c,
const _Alloc& __a)
2151 {
return _S_construct(__req, __c, __a); }
2153 template<
class _InIterator>
2155 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a)
2157 typedef typename std::__is_integer<_InIterator>::__type _Integral;
2158 return _S_construct_aux(__beg, __end, __a, _Integral());
2162 template<
class _InIterator>
2164 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
2165 input_iterator_tag);
2169 template<
class _FwdIterator>
2171 _S_construct(_FwdIterator __beg, _FwdIterator __end,
const _Alloc& __a,
2172 forward_iterator_tag);
2175 _S_construct(size_type __req, _CharT __c,
const _Alloc& __a);
2192 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
2214 {
return _M_data(); }
2226 {
return _M_data(); }
2228#if __cplusplus >= 201703L
2248 {
return _M_dataplus; }
2263 find(
const _CharT* __s, size_type __pos, size_type __n)
const
2279 {
return this->
find(__str.
data(), __pos, __str.
size()); }
2292 find(
const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2294 __glibcxx_requires_string(__s);
2295 return this->
find(__s, __pos, traits_type::length(__s));
2309 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
2311#if __cplusplus >= 201703L
2318 template<
typename _Tp>
2319 _If_sv<_Tp, size_type>
2320 find(
const _Tp& __svt, size_type __pos = 0) const
2324 return this->
find(__sv.data(), __pos, __sv.size());
2356 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
2370 rfind(
const _CharT* __s, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT
2372 __glibcxx_requires_string(__s);
2373 return this->
rfind(__s, __pos, traits_type::length(__s));
2387 rfind(_CharT __c, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT;
2389#if __cplusplus >= 201703L
2396 template<
typename _Tp>
2397 _If_sv<_Tp, size_type>
2402 return this->
rfind(__sv.data(), __pos, __sv.size());
2435 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2452 __glibcxx_requires_string(__s);
2453 return this->
find_first_of(__s, __pos, traits_type::length(__s));
2470 {
return this->
find(__c, __pos); }
2472#if __cplusplus >= 201703L
2480 template<
typename _Tp>
2481 _If_sv<_Tp, size_type>
2486 return this->
find_first_of(__sv.data(), __pos, __sv.size());
2519 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2536 __glibcxx_requires_string(__s);
2537 return this->
find_last_of(__s, __pos, traits_type::length(__s));
2554 {
return this->
rfind(__c, __pos); }
2556#if __cplusplus >= 201703L
2564 template<
typename _Tp>
2565 _If_sv<_Tp, size_type>
2570 return this->
find_last_of(__sv.data(), __pos, __sv.size());
2603 size_type __n)
const _GLIBCXX_NOEXCEPT;
2619 __glibcxx_requires_string(__s);
2637#if __cplusplus >= 201703L
2645 template<
typename _Tp>
2646 _If_sv<_Tp, size_type>
2685 size_type __n)
const _GLIBCXX_NOEXCEPT;
2701 __glibcxx_requires_string(__s);
2719#if __cplusplus >= 201703L
2727 template<
typename _Tp>
2728 _If_sv<_Tp, size_type>
2752 _M_check(__pos,
"basic_string::substr"), __n); }
2771 const size_type __size = this->
size();
2772 const size_type __osize = __str.
size();
2773 const size_type __len =
std::min(__size, __osize);
2775 int __r = traits_type::compare(_M_data(), __str.
data(), __len);
2777 __r = _S_compare(__size, __osize);
2781#if __cplusplus >= 201703L
2787 template<
typename _Tp>
2793 const size_type __size = this->
size();
2794 const size_type __osize = __sv.size();
2795 const size_type __len =
std::min(__size, __osize);
2797 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
2799 __r = _S_compare(__size, __osize);
2811 template<
typename _Tp>
2813 compare(size_type __pos, size_type __n,
const _Tp& __svt)
const
2817 return __sv_type(*this).substr(__pos, __n).compare(__sv);
2830 template<
typename _Tp>
2832 compare(size_type __pos1, size_type __n1,
const _Tp& __svt,
2833 size_type __pos2, size_type __n2 =
npos)
const
2838 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
2864 _M_check(__pos,
"basic_string::compare");
2865 __n = _M_limit(__pos, __n);
2866 const size_type __osize = __str.
size();
2867 const size_type __len =
std::min(__n, __osize);
2868 int __r = traits_type::compare(_M_data() + __pos, __str.
data(), __len);
2870 __r = _S_compare(__n, __osize);
2899 size_type __pos2, size_type __n2 =
npos)
const
2901 _M_check(__pos1,
"basic_string::compare");
2902 __str._M_check(__pos2,
"basic_string::compare");
2903 __n1 = _M_limit(__pos1, __n1);
2904 __n2 = __str._M_limit(__pos2, __n2);
2905 const size_type __len =
std::min(__n1, __n2);
2906 int __r = traits_type::compare(_M_data() + __pos1,
2907 __str.
data() + __pos2, __len);
2909 __r = _S_compare(__n1, __n2);
2928 compare(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
2930 __glibcxx_requires_string(__s);
2931 const size_type __size = this->
size();
2932 const size_type __osize = traits_type::length(__s);
2933 const size_type __len =
std::min(__size, __osize);
2934 int __r = traits_type::compare(_M_data(), __s, __len);
2936 __r = _S_compare(__size, __osize);
2962 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const
2964 __glibcxx_requires_string(__s);
2965 _M_check(__pos,
"basic_string::compare");
2966 __n1 = _M_limit(__pos, __n1);
2967 const size_type __osize = traits_type::length(__s);
2968 const size_type __len =
std::min(__n1, __osize);
2969 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
2971 __r = _S_compare(__n1, __osize);
3000 compare(size_type __pos, size_type __n1,
const _CharT* __s,
3001 size_type __n2)
const
3003 __glibcxx_requires_string_len(__s, __n2);
3004 _M_check(__pos,
"basic_string::compare");
3005 __n1 = _M_limit(__pos, __n1);
3006 const size_type __len =
std::min(__n1, __n2);
3007 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
3009 __r = _S_compare(__n1, __n2);
3013#if __cplusplus > 201703L
3016 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3019 starts_with(_CharT __x)
const noexcept
3020 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3022 [[__gnu__::__nonnull__]]
3024 starts_with(
const _CharT* __x)
const noexcept
3025 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3028 ends_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
3029 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3032 ends_with(_CharT __x)
const noexcept
3033 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3035 [[__gnu__::__nonnull__]]
3037 ends_with(
const _CharT* __x)
const noexcept
3038 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3041#if __cplusplus > 202011L
3043 contains(basic_string_view<_CharT, _Traits> __x)
const noexcept
3044 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3047 contains(_CharT __x)
const noexcept
3048 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3050 [[__gnu__::__nonnull__]]
3052 contains(
const _CharT* __x)
const noexcept
3053 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3056# ifdef _GLIBCXX_TM_TS_INTERNAL
3058 ::_txnal_cow_string_C1_for_exceptions(
void* that,
const char* s,
3061 ::_txnal_cow_string_c_str(
const void *that);
3063 ::_txnal_cow_string_D1(
void *that);
3065 ::_txnal_cow_string_D1_commit(
void *that);
3069 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3070 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
3071 basic_string<_CharT, _Traits, _Alloc>::
3072 _Rep::_S_max_size = (((npos -
sizeof(_Rep_base))/
sizeof(_CharT)) - 1) / 4;
3074 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3076 basic_string<_CharT, _Traits, _Alloc>::
3077 _Rep::_S_terminal = _CharT();
3079 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3080 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
3085 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3086 typename basic_string<_CharT, _Traits, _Alloc>::size_type
3087 basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_empty_rep_storage[
3088 (
sizeof(_Rep_base) +
sizeof(_CharT) +
sizeof(size_type) - 1) /
3095 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3096 template<
typename _InIterator>
3098 basic_string<_CharT, _Traits, _Alloc>::
3099 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
3102#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3103 if (__beg == __end && __a == _Alloc())
3104 return _S_empty_rep()._M_refdata();
3108 size_type __len = 0;
3109 while (__beg != __end && __len <
sizeof(__buf) /
sizeof(_CharT))
3111 __buf[__len++] = *__beg;
3114 _Rep* __r = _Rep::_S_create(__len, size_type(0), __a);
3115 _M_copy(__r->_M_refdata(), __buf, __len);
3118 while (__beg != __end)
3120 if (__len == __r->_M_capacity)
3123 _Rep* __another = _Rep::_S_create(__len + 1, __len, __a);
3124 _M_copy(__another->_M_refdata(), __r->_M_refdata(), __len);
3125 __r->_M_destroy(__a);
3128 __r->_M_refdata()[__len++] = *__beg;
3134 __r->_M_destroy(__a);
3135 __throw_exception_again;
3137 __r->_M_set_length_and_sharable(__len);
3138 return __r->_M_refdata();
3141 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3142 template <
typename _InIterator>
3144 basic_string<_CharT, _Traits, _Alloc>::
3145 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
3146 forward_iterator_tag)
3148#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3149 if (__beg == __end && __a == _Alloc())
3150 return _S_empty_rep()._M_refdata();
3153 if (__gnu_cxx::__is_null_pointer(__beg) && __beg != __end)
3154 __throw_logic_error(__N(
"basic_string::_S_construct null not valid"));
3156 const size_type __dnew =
static_cast<size_type
>(
std::distance(__beg,
3159 _Rep* __r = _Rep::_S_create(__dnew, size_type(0), __a);
3161 { _S_copy_chars(__r->_M_refdata(), __beg, __end); }
3164 __r->_M_destroy(__a);
3165 __throw_exception_again;
3167 __r->_M_set_length_and_sharable(__dnew);
3168 return __r->_M_refdata();
3171 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3173 basic_string<_CharT, _Traits, _Alloc>::
3174 _S_construct(size_type __n, _CharT __c,
const _Alloc& __a)
3176#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3177 if (__n == 0 && __a == _Alloc())
3178 return _S_empty_rep()._M_refdata();
3181 _Rep* __r = _Rep::_S_create(__n, size_type(0), __a);
3183 _M_assign(__r->_M_refdata(), __n, __c);
3185 __r->_M_set_length_and_sharable(__n);
3186 return __r->_M_refdata();
3189 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3192 : _M_dataplus(_S_construct(__str._M_data()
3193 + __str._M_check(__pos,
3194 "basic_string::basic_string"),
3195 __str._M_data() + __str._M_limit(__pos, npos)
3199 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3202 : _M_dataplus(_S_construct(__str._M_data()
3203 + __str._M_check(__pos,
3204 "basic_string::basic_string"),
3205 __str._M_data() + __str._M_limit(__pos, __n)
3206 + __pos, _Alloc()), _Alloc())
3209 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3212 size_type __n,
const _Alloc& __a)
3213 : _M_dataplus(_S_construct(__str._M_data()
3214 + __str._M_check(__pos,
3215 "basic_string::basic_string"),
3216 __str._M_data() + __str._M_limit(__pos, __n)
3220 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3225 if (_M_rep() != __str._M_rep())
3228 const allocator_type __a = this->get_allocator();
3229 _CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.
get_allocator());
3230 _M_rep()->_M_dispose(__a);
3236 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3239 assign(
const _CharT* __s, size_type __n)
3241 __glibcxx_requires_string_len(__s, __n);
3242 _M_check_length(this->
size(), __n,
"basic_string::assign");
3243 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3244 return _M_replace_safe(size_type(0), this->
size(), __s, __n);
3248 const size_type __pos = __s - _M_data();
3250 _M_copy(_M_data(), __s, __n);
3252 _M_move(_M_data(), __s, __n);
3253 _M_rep()->_M_set_length_and_sharable(__n);
3258 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3261 append(size_type __n, _CharT __c)
3265 _M_check_length(size_type(0), __n,
"basic_string::append");
3266 const size_type __len = __n + this->
size();
3267 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3268 this->reserve(__len);
3269 _M_assign(_M_data() + this->
size(), __n, __c);
3270 _M_rep()->_M_set_length_and_sharable(__len);
3275 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3278 append(
const _CharT* __s, size_type __n)
3280 __glibcxx_requires_string_len(__s, __n);
3283 _M_check_length(size_type(0), __n,
"basic_string::append");
3284 const size_type __len = __n + this->
size();
3285 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3287 if (_M_disjunct(__s))
3288 this->reserve(__len);
3291 const size_type __off = __s - _M_data();
3292 this->reserve(__len);
3293 __s = _M_data() + __off;
3296 _M_copy(_M_data() + this->
size(), __s, __n);
3297 _M_rep()->_M_set_length_and_sharable(__len);
3302 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3307 const size_type __size = __str.
size();
3310 const size_type __len = __size + this->
size();
3311 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3312 this->reserve(__len);
3313 _M_copy(_M_data() + this->
size(), __str._M_data(), __size);
3314 _M_rep()->_M_set_length_and_sharable(__len);
3319 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3324 __str._M_check(__pos,
"basic_string::append");
3325 __n = __str._M_limit(__pos, __n);
3328 const size_type __len = __n + this->
size();
3329 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3330 this->reserve(__len);
3331 _M_copy(_M_data() + this->
size(), __str._M_data() + __pos, __n);
3332 _M_rep()->_M_set_length_and_sharable(__len);
3337 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3340 insert(size_type __pos,
const _CharT* __s, size_type __n)
3342 __glibcxx_requires_string_len(__s, __n);
3343 _M_check(__pos,
"basic_string::insert");
3344 _M_check_length(size_type(0), __n,
"basic_string::insert");
3345 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3346 return _M_replace_safe(__pos, size_type(0), __s, __n);
3350 const size_type __off = __s - _M_data();
3351 _M_mutate(__pos, 0, __n);
3352 __s = _M_data() + __off;
3353 _CharT* __p = _M_data() + __pos;
3354 if (__s + __n <= __p)
3355 _M_copy(__p, __s, __n);
3356 else if (__s >= __p)
3357 _M_copy(__p, __s + __n, __n);
3360 const size_type __nleft = __p - __s;
3361 _M_copy(__p, __s, __nleft);
3362 _M_copy(__p + __nleft, __p + __n, __n - __nleft);
3368 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3369 typename basic_string<_CharT, _Traits, _Alloc>::iterator
3371 erase(iterator __first, iterator __last)
3373 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
3374 && __last <= _M_iend());
3379 const size_type __size = __last - __first;
3382 const size_type __pos = __first - _M_ibegin();
3383 _M_mutate(__pos, __size, size_type(0));
3384 _M_rep()->_M_set_leaked();
3385 return iterator(_M_data() + __pos);
3391 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3394 replace(size_type __pos, size_type __n1,
const _CharT* __s,
3397 __glibcxx_requires_string_len(__s, __n2);
3398 _M_check(__pos,
"basic_string::replace");
3399 __n1 = _M_limit(__pos, __n1);
3400 _M_check_length(__n1, __n2,
"basic_string::replace");
3402 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3403 return _M_replace_safe(__pos, __n1, __s, __n2);
3404 else if ((__left = __s + __n2 <= _M_data() + __pos)
3405 || _M_data() + __pos + __n1 <= __s)
3408 size_type __off = __s - _M_data();
3409 __left ? __off : (__off += __n2 - __n1);
3410 _M_mutate(__pos, __n1, __n2);
3411 _M_copy(_M_data() + __pos, _M_data() + __off, __n2);
3418 return _M_replace_safe(__pos, __n1, __tmp._M_data(), __n2);
3422 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3427 const size_type __size =
sizeof(_Rep_base)
3428 + (this->_M_capacity + 1) *
sizeof(_CharT);
3429 _Raw_bytes_alloc(__a).deallocate(
reinterpret_cast<char*
>(
this), __size);
3432 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3434 basic_string<_CharT, _Traits, _Alloc>::
3444 if (_M_rep()->_M_is_shared())
3446 _M_rep()->_M_set_leaked();
3449 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3451 basic_string<_CharT, _Traits, _Alloc>::
3452 _M_mutate(size_type __pos, size_type __len1, size_type __len2)
3454 const size_type __old_size = this->
size();
3455 const size_type __new_size = __old_size + __len2 - __len1;
3456 const size_type __how_much = __old_size - __pos - __len1;
3458 if (__new_size > this->capacity() || _M_rep()->_M_is_shared())
3461 const allocator_type __a = get_allocator();
3462 _Rep* __r = _Rep::_S_create(__new_size, this->capacity(), __a);
3465 _M_copy(__r->_M_refdata(), _M_data(), __pos);
3467 _M_copy(__r->_M_refdata() + __pos + __len2,
3468 _M_data() + __pos + __len1, __how_much);
3470 _M_rep()->_M_dispose(__a);
3471 _M_data(__r->_M_refdata());
3473 else if (__how_much && __len1 != __len2)
3476 _M_move(_M_data() + __pos + __len2,
3477 _M_data() + __pos + __len1, __how_much);
3479 _M_rep()->_M_set_length_and_sharable(__new_size);
3482 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3487 const size_type __capacity = capacity();
3493 if (__res <= __capacity)
3495 if (!_M_rep()->_M_is_shared())
3502 const allocator_type __a = get_allocator();
3503 _CharT* __tmp = _M_rep()->_M_clone(__a, __res - this->
size());
3504 _M_rep()->_M_dispose(__a);
3508 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3514 if (_M_rep()->_M_is_leaked())
3515 _M_rep()->_M_set_sharable();
3516 if (__s._M_rep()->_M_is_leaked())
3517 __s._M_rep()->_M_set_sharable();
3518 if (this->get_allocator() == __s.get_allocator())
3520 _CharT* __tmp = _M_data();
3521 _M_data(__s._M_data());
3528 __s.get_allocator());
3529 const basic_string __tmp2(__s._M_ibegin(), __s._M_iend(),
3530 this->get_allocator());
3536 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3539 _S_create(size_type __capacity, size_type __old_capacity,
3540 const _Alloc& __alloc)
3544 if (__capacity > _S_max_size)
3545 __throw_length_error(__N(
"basic_string::_S_create"));
3570 const size_type __pagesize = 4096;
3571 const size_type __malloc_header_size = 4 *
sizeof(
void*);
3579 if (__capacity > __old_capacity && __capacity < 2 * __old_capacity)
3580 __capacity = 2 * __old_capacity;
3585 size_type __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
3587 const size_type __adj_size = __size + __malloc_header_size;
3588 if (__adj_size > __pagesize && __capacity > __old_capacity)
3590 const size_type __extra = __pagesize - __adj_size % __pagesize;
3591 __capacity += __extra /
sizeof(_CharT);
3593 if (__capacity > _S_max_size)
3594 __capacity = _S_max_size;
3595 __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
3600 void* __place = _Raw_bytes_alloc(__alloc).allocate(__size);
3601 _Rep *__p =
new (__place) _Rep;
3602 __p->_M_capacity = __capacity;
3610 __p->_M_set_sharable();
3614 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3616 basic_string<_CharT, _Traits, _Alloc>::_Rep::
3617 _M_clone(
const _Alloc& __alloc, size_type __res)
3620 const size_type __requested_cap = this->_M_length + __res;
3621 _Rep* __r = _Rep::_S_create(__requested_cap, this->_M_capacity,
3623 if (this->_M_length)
3624 _M_copy(__r->_M_refdata(), _M_refdata(), this->_M_length);
3626 __r->_M_set_length_and_sharable(this->_M_length);
3627 return __r->_M_refdata();
3630 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3633 resize(size_type __n, _CharT __c)
3635 const size_type __size = this->
size();
3636 _M_check_length(__size, __n,
"basic_string::resize");
3638 this->append(__n - __size, __c);
3639 else if (__n < __size)
3644 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3645 template<
typename _InputIterator>
3649 _InputIterator __k2, __false_type)
3652 const size_type __n1 = __i2 - __i1;
3653 _M_check_length(__n1, __s.size(),
"basic_string::_M_replace_dispatch");
3654 return _M_replace_safe(__i1 - _M_ibegin(), __n1, __s._M_data(),
3658 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3659 basic_string<_CharT, _Traits, _Alloc>&
3660 basic_string<_CharT, _Traits, _Alloc>::
3661 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
3664 _M_check_length(__n1, __n2,
"basic_string::_M_replace_aux");
3665 _M_mutate(__pos1, __n1, __n2);
3667 _M_assign(_M_data() + __pos1, __n2, __c);
3671 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3672 basic_string<_CharT, _Traits, _Alloc>&
3673 basic_string<_CharT, _Traits, _Alloc>::
3674 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
3677 _M_mutate(__pos1, __n1, __n2);
3679 _M_copy(_M_data() + __pos1, __s, __n2);
3683 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3689 if (length() < capacity() || _M_rep()->_M_is_shared())
3692 const allocator_type __a = get_allocator();
3693 _CharT* __tmp = _M_rep()->_M_clone(__a);
3694 _M_rep()->_M_dispose(__a);
3704 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3705 typename basic_string<_CharT, _Traits, _Alloc>::size_type
3707 copy(_CharT* __s, size_type __n, size_type __pos)
const
3709 _M_check(__pos,
"basic_string::copy");
3710 __n = _M_limit(__pos, __n);
3711 __glibcxx_requires_string_len(__s, __n);
3713 _M_copy(__s, _M_data() + __pos, __n);
3717_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.
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.