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
914 {
return _M_rep()->_M_length; }
920 {
return _M_rep()->_M_length; }
925 {
return _Rep::_S_max_size; }
952 { this->
resize(__n, _CharT()); }
954#if __cplusplus >= 201103L
955#pragma GCC diagnostic push
956#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
961#pragma GCC diagnostic pop
970 {
return _M_rep()->_M_capacity; }
993#if __cplusplus > 201703L
994 [[deprecated(
"use shrink_to_fit() instead")]]
1002#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
1006 if (_M_rep()->_M_is_shared())
1009 _M_data(_S_empty_rep()._M_refdata());
1012 _M_rep()->_M_set_length_and_sharable(0);
1018 { _M_mutate(0, this->
size(), 0); }
1025 _GLIBCXX_NODISCARD
bool
1027 {
return this->
size() == 0; }
1043 __glibcxx_assert(__pos <=
size());
1044 return _M_data()[__pos];
1062 __glibcxx_assert(__pos <=
size());
1064 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos <
size());
1066 return _M_data()[__pos];
1082 if (__n >= this->
size())
1083 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1084 "(which is %zu) >= this->size() "
1087 return _M_data()[__n];
1105 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1106 "(which is %zu) >= this->size() "
1110 return _M_data()[__n];
1113#if __cplusplus >= 201103L
1121 __glibcxx_assert(!
empty());
1132 __glibcxx_assert(!
empty());
1143 __glibcxx_assert(!
empty());
1154 __glibcxx_assert(!
empty());
1167 {
return this->
append(__str); }
1176 {
return this->
append(__s); }
1190#if __cplusplus >= 201103L
1198 {
return this->
append(__l.begin(), __l.size()); }
1201#if __cplusplus >= 201703L
1207 template<
typename _Tp>
1208 _If_sv<_Tp, basic_string&>
1210 {
return this->
append(__svt); }
1254 __glibcxx_requires_string(__s);
1255 return this->
append(__s, traits_type::length(__s));
1269#if __cplusplus >= 201103L
1277 {
return this->
append(__l.begin(), __l.size()); }
1288 template<
class _InputIterator>
1290 append(_InputIterator __first, _InputIterator __last)
1291 {
return this->
replace(_M_iend(), _M_iend(), __first, __last); }
1293#if __cplusplus >= 201703L
1299 template<
typename _Tp>
1300 _If_sv<_Tp, basic_string&>
1304 return this->
append(__sv.data(), __sv.size());
1315 template<
typename _Tp>
1316 _If_sv<_Tp, basic_string&>
1320 return append(__sv.data()
1321 + std::__sv_check(__sv.size(), __pos,
"basic_string::append"),
1322 std::__sv_limit(__sv.size(), __pos, __n));
1333 const size_type __len = 1 + this->
size();
1334 if (__len > this->
capacity() || _M_rep()->_M_is_shared())
1336 traits_type::assign(_M_data()[this->
size()], __c);
1337 _M_rep()->_M_set_length_and_sharable(__len);
1348#if __cplusplus >= 201103L
1381 {
return this->
assign(__str._M_data()
1382 + __str._M_check(__pos,
"basic_string::assign"),
1383 __str._M_limit(__pos, __n)); }
1410 __glibcxx_requires_string(__s);
1411 return this->
assign(__s, traits_type::length(__s));
1425 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
1435 template<
class _InputIterator>
1437 assign(_InputIterator __first, _InputIterator __last)
1438 {
return this->
replace(_M_ibegin(), _M_iend(), __first, __last); }
1440#if __cplusplus >= 201103L
1448 {
return this->
assign(__l.begin(), __l.size()); }
1451#if __cplusplus >= 201703L
1457 template<
typename _Tp>
1458 _If_sv<_Tp, basic_string&>
1462 return this->
assign(__sv.data(), __sv.size());
1472 template<
typename _Tp>
1473 _If_sv<_Tp, basic_string&>
1477 return assign(__sv.data()
1478 + std::__sv_check(__sv.size(), __pos,
"basic_string::assign"),
1479 std::__sv_limit(__sv.size(), __pos, __n));
1497 insert(iterator __p, size_type __n, _CharT __c)
1498 { this->
replace(__p, __p, __n, __c); }
1512 template<
class _InputIterator>
1514 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1515 { this->
replace(__p, __p, __beg, __end); }
1517#if __cplusplus >= 201103L
1527 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1528 this->
insert(__p - _M_ibegin(), __l.begin(), __l.size());
1546 {
return this->
insert(__pos1, __str, size_type(0), __str.
size()); }
1568 size_type __pos2, size_type __n =
npos)
1569 {
return this->
insert(__pos1, __str._M_data()
1570 + __str._M_check(__pos2,
"basic_string::insert"),
1571 __str._M_limit(__pos2, __n)); }
1590 insert(size_type __pos,
const _CharT* __s, size_type __n);
1610 __glibcxx_requires_string(__s);
1611 return this->
insert(__pos, __s, traits_type::length(__s));
1631 insert(size_type __pos, size_type __n, _CharT __c)
1632 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
1633 size_type(0), __n, __c); }
1651 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1652 const size_type __pos = __p - _M_ibegin();
1653 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1654 _M_rep()->_M_set_leaked();
1655 return iterator(_M_data() + __pos);
1658#if __cplusplus >= 201703L
1665 template<
typename _Tp>
1666 _If_sv<_Tp, basic_string&>
1670 return this->
insert(__pos, __sv.data(), __sv.size());
1681 template<
typename _Tp>
1682 _If_sv<_Tp, basic_string&>
1684 size_type __pos2, size_type __n =
npos)
1687 return this->
replace(__pos1, size_type(0), __sv.data()
1688 + std::__sv_check(__sv.size(), __pos2,
"basic_string::insert"),
1689 std::__sv_limit(__sv.size(), __pos2, __n));
1711 _M_mutate(_M_check(__pos,
"basic_string::erase"),
1712 _M_limit(__pos, __n), size_type(0));
1727 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1728 && __position < _M_iend());
1729 const size_type __pos = __position - _M_ibegin();
1730 _M_mutate(__pos, size_type(1), size_type(0));
1731 _M_rep()->_M_set_leaked();
1732 return iterator(_M_data() + __pos);
1745 erase(iterator __first, iterator __last);
1747#if __cplusplus >= 201103L
1756 __glibcxx_assert(!
empty());
1780 {
return this->
replace(__pos, __n, __str._M_data(), __str.
size()); }
1802 size_type __pos2, size_type __n2 =
npos)
1803 {
return this->
replace(__pos1, __n1, __str._M_data()
1804 + __str._M_check(__pos2,
"basic_string::replace"),
1805 __str._M_limit(__pos2, __n2)); }
1826 replace(size_type __pos, size_type __n1,
const _CharT* __s,
1846 replace(size_type __pos, size_type __n1,
const _CharT* __s)
1848 __glibcxx_requires_string(__s);
1849 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
1870 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1871 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
1872 _M_limit(__pos, __n1), __n2, __c); }
1889 {
return this->
replace(__i1, __i2, __str._M_data(), __str.
size()); }
1907 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
1909 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1910 && __i2 <= _M_iend());
1911 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1928 replace(iterator __i1, iterator __i2,
const _CharT* __s)
1930 __glibcxx_requires_string(__s);
1931 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
1949 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1951 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1952 && __i2 <= _M_iend());
1953 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1971 template<
class _InputIterator>
1974 _InputIterator __k1, _InputIterator __k2)
1976 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1977 && __i2 <= _M_iend());
1978 __glibcxx_requires_valid_range(__k1, __k2);
1979 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1980 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1988 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1989 && __i2 <= _M_iend());
1990 __glibcxx_requires_valid_range(__k1, __k2);
1991 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
1996 replace(iterator __i1, iterator __i2,
1997 const _CharT* __k1,
const _CharT* __k2)
1999 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2000 && __i2 <= _M_iend());
2001 __glibcxx_requires_valid_range(__k1, __k2);
2002 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2007 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
2009 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2010 && __i2 <= _M_iend());
2011 __glibcxx_requires_valid_range(__k1, __k2);
2012 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2013 __k1.base(), __k2 - __k1);
2017 replace(iterator __i1, iterator __i2,
2018 const_iterator __k1, const_iterator __k2)
2020 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2021 && __i2 <= _M_iend());
2022 __glibcxx_requires_valid_range(__k1, __k2);
2023 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2024 __k1.base(), __k2 - __k1);
2027#if __cplusplus >= 201103L
2044 {
return this->
replace(__i1, __i2, __l.begin(), __l.end()); }
2047#if __cplusplus >= 201703L
2055 template<
typename _Tp>
2056 _If_sv<_Tp, basic_string&>
2057 replace(size_type __pos, size_type __n,
const _Tp& __svt)
2060 return this->
replace(__pos, __n, __sv.data(), __sv.size());
2072 template<
typename _Tp>
2073 _If_sv<_Tp, basic_string&>
2074 replace(size_type __pos1, size_type __n1,
const _Tp& __svt,
2075 size_type __pos2, size_type __n2 =
npos)
2078 return this->
replace(__pos1, __n1,
2080 + std::__sv_check(__sv.size(), __pos2,
"basic_string::replace"),
2081 std::__sv_limit(__sv.size(), __pos2, __n2));
2093 template<
typename _Tp>
2094 _If_sv<_Tp, basic_string&>
2095 replace(const_iterator __i1, const_iterator __i2,
const _Tp& __svt)
2098 return this->
replace(__i1 -
begin(), __i2 - __i1, __sv);
2103 template<
class _Integer>
2106 _Integer __val, __true_type)
2107 {
return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
2109 template<
class _InputIterator>
2111 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
2112 _InputIterator __k2, __false_type);
2115 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
2119 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
2124 template<
class _InIterator>
2126 _S_construct_aux(_InIterator __beg, _InIterator __end,
2127 const _Alloc& __a, __false_type)
2129 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
2130 return _S_construct(__beg, __end, __a, _Tag());
2135 template<
class _Integer>
2137 _S_construct_aux(_Integer __beg, _Integer __end,
2138 const _Alloc& __a, __true_type)
2139 {
return _S_construct_aux_2(
static_cast<size_type
>(__beg),
2143 _S_construct_aux_2(size_type __req, _CharT __c,
const _Alloc& __a)
2144 {
return _S_construct(__req, __c, __a); }
2146 template<
class _InIterator>
2148 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a)
2150 typedef typename std::__is_integer<_InIterator>::__type _Integral;
2151 return _S_construct_aux(__beg, __end, __a, _Integral());
2155 template<
class _InIterator>
2157 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
2158 input_iterator_tag);
2162 template<
class _FwdIterator>
2164 _S_construct(_FwdIterator __beg, _FwdIterator __end,
const _Alloc& __a,
2165 forward_iterator_tag);
2168 _S_construct(size_type __req, _CharT __c,
const _Alloc& __a);
2185 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
2207 {
return _M_data(); }
2219 {
return _M_data(); }
2221#if __cplusplus >= 201703L
2241 {
return _M_dataplus; }
2256 find(
const _CharT* __s, size_type __pos, size_type __n)
const
2272 {
return this->
find(__str.
data(), __pos, __str.
size()); }
2285 find(
const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2287 __glibcxx_requires_string(__s);
2288 return this->
find(__s, __pos, traits_type::length(__s));
2302 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
2304#if __cplusplus >= 201703L
2311 template<
typename _Tp>
2312 _If_sv<_Tp, size_type>
2313 find(
const _Tp& __svt, size_type __pos = 0) const
2317 return this->
find(__sv.data(), __pos, __sv.size());
2349 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
2363 rfind(
const _CharT* __s, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT
2365 __glibcxx_requires_string(__s);
2366 return this->
rfind(__s, __pos, traits_type::length(__s));
2380 rfind(_CharT __c, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT;
2382#if __cplusplus >= 201703L
2389 template<
typename _Tp>
2390 _If_sv<_Tp, size_type>
2395 return this->
rfind(__sv.data(), __pos, __sv.size());
2428 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2445 __glibcxx_requires_string(__s);
2446 return this->
find_first_of(__s, __pos, traits_type::length(__s));
2463 {
return this->
find(__c, __pos); }
2465#if __cplusplus >= 201703L
2473 template<
typename _Tp>
2474 _If_sv<_Tp, size_type>
2479 return this->
find_first_of(__sv.data(), __pos, __sv.size());
2512 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2529 __glibcxx_requires_string(__s);
2530 return this->
find_last_of(__s, __pos, traits_type::length(__s));
2547 {
return this->
rfind(__c, __pos); }
2549#if __cplusplus >= 201703L
2557 template<
typename _Tp>
2558 _If_sv<_Tp, size_type>
2563 return this->
find_last_of(__sv.data(), __pos, __sv.size());
2596 size_type __n)
const _GLIBCXX_NOEXCEPT;
2612 __glibcxx_requires_string(__s);
2630#if __cplusplus >= 201703L
2638 template<
typename _Tp>
2639 _If_sv<_Tp, size_type>
2678 size_type __n)
const _GLIBCXX_NOEXCEPT;
2694 __glibcxx_requires_string(__s);
2712#if __cplusplus >= 201703L
2720 template<
typename _Tp>
2721 _If_sv<_Tp, size_type>
2745 _M_check(__pos,
"basic_string::substr"), __n); }
2764 const size_type __size = this->
size();
2765 const size_type __osize = __str.
size();
2766 const size_type __len =
std::min(__size, __osize);
2768 int __r = traits_type::compare(_M_data(), __str.
data(), __len);
2770 __r = _S_compare(__size, __osize);
2774#if __cplusplus >= 201703L
2780 template<
typename _Tp>
2786 const size_type __size = this->
size();
2787 const size_type __osize = __sv.size();
2788 const size_type __len =
std::min(__size, __osize);
2790 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
2792 __r = _S_compare(__size, __osize);
2804 template<
typename _Tp>
2806 compare(size_type __pos, size_type __n,
const _Tp& __svt)
const
2810 return __sv_type(*this).substr(__pos, __n).compare(__sv);
2823 template<
typename _Tp>
2825 compare(size_type __pos1, size_type __n1,
const _Tp& __svt,
2826 size_type __pos2, size_type __n2 =
npos)
const
2831 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
2855 compare(size_type __pos, size_type __n,
const basic_string& __str)
const;
2881 compare(size_type __pos1, size_type __n1,
const basic_string& __str,
2882 size_type __pos2, size_type __n2 =
npos)
const;
2899 compare(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT;
2923 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const;
2950 compare(size_type __pos, size_type __n1,
const _CharT* __s,
2951 size_type __n2)
const;
2953#if __cplusplus > 201703L
2956 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
2959 starts_with(_CharT __x)
const noexcept
2960 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
2963 starts_with(
const _CharT* __x)
const noexcept
2964 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
2967 ends_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
2968 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
2971 ends_with(_CharT __x)
const noexcept
2972 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
2975 ends_with(
const _CharT* __x)
const noexcept
2976 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
2979#if __cplusplus > 202011L
2981 contains(basic_string_view<_CharT, _Traits> __x)
const noexcept
2982 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
2985 contains(_CharT __x)
const noexcept
2986 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
2989 contains(
const _CharT* __x)
const noexcept
2990 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
2993# ifdef _GLIBCXX_TM_TS_INTERNAL
2995 ::_txnal_cow_string_C1_for_exceptions(
void* that,
const char* s,
2998 ::_txnal_cow_string_c_str(
const void *that);
3000 ::_txnal_cow_string_D1(
void *that);
3002 ::_txnal_cow_string_D1_commit(
void *that);
3006 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3007 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
3008 basic_string<_CharT, _Traits, _Alloc>::
3009 _Rep::_S_max_size = (((npos -
sizeof(_Rep_base))/
sizeof(_CharT)) - 1) / 4;
3011 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3013 basic_string<_CharT, _Traits, _Alloc>::
3014 _Rep::_S_terminal = _CharT();
3016 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3017 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
3022 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3023 typename basic_string<_CharT, _Traits, _Alloc>::size_type
3024 basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_empty_rep_storage[
3025 (
sizeof(_Rep_base) +
sizeof(_CharT) +
sizeof(size_type) - 1) /
3032 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3033 template<
typename _InIterator>
3035 basic_string<_CharT, _Traits, _Alloc>::
3036 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
3039#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3040 if (__beg == __end && __a == _Alloc())
3041 return _S_empty_rep()._M_refdata();
3045 size_type __len = 0;
3046 while (__beg != __end && __len <
sizeof(__buf) /
sizeof(_CharT))
3048 __buf[__len++] = *__beg;
3051 _Rep* __r = _Rep::_S_create(__len, size_type(0), __a);
3052 _M_copy(__r->_M_refdata(), __buf, __len);
3055 while (__beg != __end)
3057 if (__len == __r->_M_capacity)
3060 _Rep* __another = _Rep::_S_create(__len + 1, __len, __a);
3061 _M_copy(__another->_M_refdata(), __r->_M_refdata(), __len);
3062 __r->_M_destroy(__a);
3065 __r->_M_refdata()[__len++] = *__beg;
3071 __r->_M_destroy(__a);
3072 __throw_exception_again;
3074 __r->_M_set_length_and_sharable(__len);
3075 return __r->_M_refdata();
3078 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3079 template <
typename _InIterator>
3081 basic_string<_CharT, _Traits, _Alloc>::
3082 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
3083 forward_iterator_tag)
3085#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3086 if (__beg == __end && __a == _Alloc())
3087 return _S_empty_rep()._M_refdata();
3090 if (__gnu_cxx::__is_null_pointer(__beg) && __beg != __end)
3091 __throw_logic_error(__N(
"basic_string::_S_construct null not valid"));
3093 const size_type __dnew =
static_cast<size_type
>(
std::distance(__beg,
3096 _Rep* __r = _Rep::_S_create(__dnew, size_type(0), __a);
3098 { _S_copy_chars(__r->_M_refdata(), __beg, __end); }
3101 __r->_M_destroy(__a);
3102 __throw_exception_again;
3104 __r->_M_set_length_and_sharable(__dnew);
3105 return __r->_M_refdata();
3108 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3110 basic_string<_CharT, _Traits, _Alloc>::
3111 _S_construct(size_type __n, _CharT __c,
const _Alloc& __a)
3113#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3114 if (__n == 0 && __a == _Alloc())
3115 return _S_empty_rep()._M_refdata();
3118 _Rep* __r = _Rep::_S_create(__n, size_type(0), __a);
3120 _M_assign(__r->_M_refdata(), __n, __c);
3122 __r->_M_set_length_and_sharable(__n);
3123 return __r->_M_refdata();
3126 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3129 : _M_dataplus(_S_construct(__str._M_data()
3130 + __str._M_check(__pos,
3131 "basic_string::basic_string"),
3132 __str._M_data() + __str._M_limit(__pos, npos)
3136 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3139 : _M_dataplus(_S_construct(__str._M_data()
3140 + __str._M_check(__pos,
3141 "basic_string::basic_string"),
3142 __str._M_data() + __str._M_limit(__pos, __n)
3143 + __pos, _Alloc()), _Alloc())
3146 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3149 size_type __n,
const _Alloc& __a)
3150 : _M_dataplus(_S_construct(__str._M_data()
3151 + __str._M_check(__pos,
3152 "basic_string::basic_string"),
3153 __str._M_data() + __str._M_limit(__pos, __n)
3157 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3162 if (_M_rep() != __str._M_rep())
3165 const allocator_type __a = this->get_allocator();
3166 _CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.
get_allocator());
3167 _M_rep()->_M_dispose(__a);
3173 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3176 assign(
const _CharT* __s, size_type __n)
3178 __glibcxx_requires_string_len(__s, __n);
3179 _M_check_length(this->
size(), __n,
"basic_string::assign");
3180 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3181 return _M_replace_safe(size_type(0), this->
size(), __s, __n);
3185 const size_type __pos = __s - _M_data();
3187 _M_copy(_M_data(), __s, __n);
3189 _M_move(_M_data(), __s, __n);
3190 _M_rep()->_M_set_length_and_sharable(__n);
3195 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3198 append(size_type __n, _CharT __c)
3202 _M_check_length(size_type(0), __n,
"basic_string::append");
3203 const size_type __len = __n + this->
size();
3204 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3205 this->reserve(__len);
3206 _M_assign(_M_data() + this->
size(), __n, __c);
3207 _M_rep()->_M_set_length_and_sharable(__len);
3212 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3215 append(
const _CharT* __s, size_type __n)
3217 __glibcxx_requires_string_len(__s, __n);
3220 _M_check_length(size_type(0), __n,
"basic_string::append");
3221 const size_type __len = __n + this->
size();
3222 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3224 if (_M_disjunct(__s))
3225 this->reserve(__len);
3228 const size_type __off = __s - _M_data();
3229 this->reserve(__len);
3230 __s = _M_data() + __off;
3233 _M_copy(_M_data() + this->
size(), __s, __n);
3234 _M_rep()->_M_set_length_and_sharable(__len);
3239 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3244 const size_type __size = __str.
size();
3247 const size_type __len = __size + this->
size();
3248 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3249 this->reserve(__len);
3250 _M_copy(_M_data() + this->
size(), __str._M_data(), __size);
3251 _M_rep()->_M_set_length_and_sharable(__len);
3256 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3261 __str._M_check(__pos,
"basic_string::append");
3262 __n = __str._M_limit(__pos, __n);
3265 const size_type __len = __n + this->
size();
3266 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3267 this->reserve(__len);
3268 _M_copy(_M_data() + this->
size(), __str._M_data() + __pos, __n);
3269 _M_rep()->_M_set_length_and_sharable(__len);
3274 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3277 insert(size_type __pos,
const _CharT* __s, size_type __n)
3279 __glibcxx_requires_string_len(__s, __n);
3280 _M_check(__pos,
"basic_string::insert");
3281 _M_check_length(size_type(0), __n,
"basic_string::insert");
3282 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3283 return _M_replace_safe(__pos, size_type(0), __s, __n);
3287 const size_type __off = __s - _M_data();
3288 _M_mutate(__pos, 0, __n);
3289 __s = _M_data() + __off;
3290 _CharT* __p = _M_data() + __pos;
3291 if (__s + __n <= __p)
3292 _M_copy(__p, __s, __n);
3293 else if (__s >= __p)
3294 _M_copy(__p, __s + __n, __n);
3297 const size_type __nleft = __p - __s;
3298 _M_copy(__p, __s, __nleft);
3299 _M_copy(__p + __nleft, __p + __n, __n - __nleft);
3305 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3306 typename basic_string<_CharT, _Traits, _Alloc>::iterator
3308 erase(iterator __first, iterator __last)
3310 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
3311 && __last <= _M_iend());
3316 const size_type __size = __last - __first;
3319 const size_type __pos = __first - _M_ibegin();
3320 _M_mutate(__pos, __size, size_type(0));
3321 _M_rep()->_M_set_leaked();
3322 return iterator(_M_data() + __pos);
3328 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3331 replace(size_type __pos, size_type __n1,
const _CharT* __s,
3334 __glibcxx_requires_string_len(__s, __n2);
3335 _M_check(__pos,
"basic_string::replace");
3336 __n1 = _M_limit(__pos, __n1);
3337 _M_check_length(__n1, __n2,
"basic_string::replace");
3339 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3340 return _M_replace_safe(__pos, __n1, __s, __n2);
3341 else if ((__left = __s + __n2 <= _M_data() + __pos)
3342 || _M_data() + __pos + __n1 <= __s)
3345 size_type __off = __s - _M_data();
3346 __left ? __off : (__off += __n2 - __n1);
3347 _M_mutate(__pos, __n1, __n2);
3348 _M_copy(_M_data() + __pos, _M_data() + __off, __n2);
3355 return _M_replace_safe(__pos, __n1, __tmp._M_data(), __n2);
3359 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3364 const size_type __size =
sizeof(_Rep_base)
3365 + (this->_M_capacity + 1) *
sizeof(_CharT);
3366 _Raw_bytes_alloc(__a).deallocate(
reinterpret_cast<char*
>(
this), __size);
3369 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3371 basic_string<_CharT, _Traits, _Alloc>::
3381 if (_M_rep()->_M_is_shared())
3383 _M_rep()->_M_set_leaked();
3386 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3388 basic_string<_CharT, _Traits, _Alloc>::
3389 _M_mutate(size_type __pos, size_type __len1, size_type __len2)
3391 const size_type __old_size = this->
size();
3392 const size_type __new_size = __old_size + __len2 - __len1;
3393 const size_type __how_much = __old_size - __pos - __len1;
3395 if (__new_size > this->capacity() || _M_rep()->_M_is_shared())
3398 const allocator_type __a = get_allocator();
3399 _Rep* __r = _Rep::_S_create(__new_size, this->capacity(), __a);
3402 _M_copy(__r->_M_refdata(), _M_data(), __pos);
3404 _M_copy(__r->_M_refdata() + __pos + __len2,
3405 _M_data() + __pos + __len1, __how_much);
3407 _M_rep()->_M_dispose(__a);
3408 _M_data(__r->_M_refdata());
3410 else if (__how_much && __len1 != __len2)
3413 _M_move(_M_data() + __pos + __len2,
3414 _M_data() + __pos + __len1, __how_much);
3416 _M_rep()->_M_set_length_and_sharable(__new_size);
3419 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3424 const size_type __capacity = capacity();
3430 if (__res <= __capacity)
3432 if (!_M_rep()->_M_is_shared())
3439 const allocator_type __a = get_allocator();
3440 _CharT* __tmp = _M_rep()->_M_clone(__a, __res - this->
size());
3441 _M_rep()->_M_dispose(__a);
3445 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3451 if (_M_rep()->_M_is_leaked())
3452 _M_rep()->_M_set_sharable();
3453 if (__s._M_rep()->_M_is_leaked())
3454 __s._M_rep()->_M_set_sharable();
3455 if (this->get_allocator() == __s.get_allocator())
3457 _CharT* __tmp = _M_data();
3458 _M_data(__s._M_data());
3465 __s.get_allocator());
3466 const basic_string __tmp2(__s._M_ibegin(), __s._M_iend(),
3467 this->get_allocator());
3473 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3476 _S_create(size_type __capacity, size_type __old_capacity,
3477 const _Alloc& __alloc)
3481 if (__capacity > _S_max_size)
3482 __throw_length_error(__N(
"basic_string::_S_create"));
3507 const size_type __pagesize = 4096;
3508 const size_type __malloc_header_size = 4 *
sizeof(
void*);
3516 if (__capacity > __old_capacity && __capacity < 2 * __old_capacity)
3517 __capacity = 2 * __old_capacity;
3522 size_type __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
3524 const size_type __adj_size = __size + __malloc_header_size;
3525 if (__adj_size > __pagesize && __capacity > __old_capacity)
3527 const size_type __extra = __pagesize - __adj_size % __pagesize;
3528 __capacity += __extra /
sizeof(_CharT);
3530 if (__capacity > _S_max_size)
3531 __capacity = _S_max_size;
3532 __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
3537 void* __place = _Raw_bytes_alloc(__alloc).allocate(__size);
3538 _Rep *__p =
new (__place) _Rep;
3539 __p->_M_capacity = __capacity;
3547 __p->_M_set_sharable();
3551 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3553 basic_string<_CharT, _Traits, _Alloc>::_Rep::
3554 _M_clone(
const _Alloc& __alloc, size_type __res)
3557 const size_type __requested_cap = this->_M_length + __res;
3558 _Rep* __r = _Rep::_S_create(__requested_cap, this->_M_capacity,
3560 if (this->_M_length)
3561 _M_copy(__r->_M_refdata(), _M_refdata(), this->_M_length);
3563 __r->_M_set_length_and_sharable(this->_M_length);
3564 return __r->_M_refdata();
3567 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3570 resize(size_type __n, _CharT __c)
3572 const size_type __size = this->
size();
3573 _M_check_length(__size, __n,
"basic_string::resize");
3575 this->append(__n - __size, __c);
3576 else if (__n < __size)
3581 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3582 template<
typename _InputIterator>
3586 _InputIterator __k2, __false_type)
3589 const size_type __n1 = __i2 - __i1;
3590 _M_check_length(__n1, __s.size(),
"basic_string::_M_replace_dispatch");
3591 return _M_replace_safe(__i1 - _M_ibegin(), __n1, __s._M_data(),
3595 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3596 basic_string<_CharT, _Traits, _Alloc>&
3597 basic_string<_CharT, _Traits, _Alloc>::
3598 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
3601 _M_check_length(__n1, __n2,
"basic_string::_M_replace_aux");
3602 _M_mutate(__pos1, __n1, __n2);
3604 _M_assign(_M_data() + __pos1, __n2, __c);
3608 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3609 basic_string<_CharT, _Traits, _Alloc>&
3610 basic_string<_CharT, _Traits, _Alloc>::
3611 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
3614 _M_mutate(__pos1, __n1, __n2);
3616 _M_copy(_M_data() + __pos1, __s, __n2);
3620 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3626 if (length() < capacity() || _M_rep()->_M_is_shared())
3629 const allocator_type __a = get_allocator();
3630 _CharT* __tmp = _M_rep()->_M_clone(__a);
3631 _M_rep()->_M_dispose(__a);
3641 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3642 typename basic_string<_CharT, _Traits, _Alloc>::size_type
3644 copy(_CharT* __s, size_type __n, size_type __pos)
const
3646 _M_check(__pos,
"basic_string::copy");
3647 __n = _M_limit(__pos, __n);
3648 __glibcxx_requires_string_len(__s, __n);
3650 _M_copy(__s, _M_data() + __pos, __n);
3654_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.
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.
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.
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.
_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.
_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.