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
115 template<
typename _CharT,
typename _Traits,
typename _Alloc>
118 typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
119 rebind<_CharT>::other _CharT_alloc_type;
120 typedef __gnu_cxx::__alloc_traits<_CharT_alloc_type> _CharT_alloc_traits;
124 typedef _Traits traits_type;
125 typedef typename _Traits::char_type value_type;
126 typedef _Alloc allocator_type;
127 typedef typename _CharT_alloc_traits::size_type size_type;
128 typedef typename _CharT_alloc_traits::difference_type difference_type;
129#if __cplusplus < 201103L
130 typedef typename _CharT_alloc_type::reference reference;
131 typedef typename _CharT_alloc_type::const_reference const_reference;
133 typedef value_type& reference;
134 typedef const value_type& const_reference;
136 typedef typename _CharT_alloc_traits::pointer pointer;
137 typedef typename _CharT_alloc_traits::const_pointer const_pointer;
138 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
139 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
141 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
142 typedef std::reverse_iterator<iterator> reverse_iterator;
146 typedef iterator __const_iterator;
166 size_type _M_capacity;
167 _Atomic_word _M_refcount;
170 struct _Rep : _Rep_base
173 typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
174 rebind<char>::other _Raw_bytes_alloc;
189 static const size_type _S_max_size;
190 static const _CharT _S_terminal;
194 static size_type _S_empty_rep_storage[];
197 _S_empty_rep() _GLIBCXX_NOEXCEPT
202 void* __p =
reinterpret_cast<void*
>(&_S_empty_rep_storage);
203 return *
reinterpret_cast<_Rep*
>(__p);
207 _M_is_leaked() const _GLIBCXX_NOEXCEPT
209#if defined(__GTHREADS)
214 return __atomic_load_n(&this->_M_refcount, __ATOMIC_RELAXED) < 0;
216 return this->_M_refcount < 0;
221 _M_is_shared() const _GLIBCXX_NOEXCEPT
223#if defined(__GTHREADS)
229 if (!__gnu_cxx::__is_single_threaded())
230 return __atomic_load_n(&this->_M_refcount, __ATOMIC_ACQUIRE) > 0;
232 return this->_M_refcount > 0;
236 _M_set_leaked() _GLIBCXX_NOEXCEPT
237 { this->_M_refcount = -1; }
240 _M_set_sharable() _GLIBCXX_NOEXCEPT
241 { this->_M_refcount = 0; }
244 _M_set_length_and_sharable(size_type __n) _GLIBCXX_NOEXCEPT
246#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
247 if (__builtin_expect(
this != &_S_empty_rep(),
false))
250 this->_M_set_sharable();
251 this->_M_length = __n;
252 traits_type::assign(this->_M_refdata()[__n], _S_terminal);
260 {
return reinterpret_cast<_CharT*
>(
this + 1); }
263 _M_grab(
const _Alloc& __alloc1,
const _Alloc& __alloc2)
265 return (!_M_is_leaked() && __alloc1 == __alloc2)
266 ? _M_refcopy() : _M_clone(__alloc1);
271 _S_create(size_type, size_type,
const _Alloc&);
274 _M_dispose(
const _Alloc& __a) _GLIBCXX_NOEXCEPT
276#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
277 if (__builtin_expect(
this != &_S_empty_rep(),
false))
281 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount);
290 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
293 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount);
300 _M_destroy(
const _Alloc&)
throw();
305#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
306 if (__builtin_expect(
this != &_S_empty_rep(),
false))
308 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
313 _M_clone(
const _Alloc&, size_type __res = 0);
317 struct _Alloc_hider : _Alloc
319 _Alloc_hider(_CharT* __dat,
const _Alloc& __a) _GLIBCXX_NOEXCEPT
320 : _Alloc(__a), _M_p(__dat) { }
330 static const size_type
npos =
static_cast<size_type
>(-1);
334 mutable _Alloc_hider _M_dataplus;
337 _M_data() const _GLIBCXX_NOEXCEPT
338 {
return _M_dataplus._M_p; }
341 _M_data(_CharT* __p) _GLIBCXX_NOEXCEPT
342 {
return (_M_dataplus._M_p = __p); }
345 _M_rep() const _GLIBCXX_NOEXCEPT
346 {
return &((
reinterpret_cast<_Rep*
> (_M_data()))[-1]); }
351 _M_ibegin() const _GLIBCXX_NOEXCEPT
352 {
return iterator(_M_data()); }
355 _M_iend() const _GLIBCXX_NOEXCEPT
356 {
return iterator(_M_data() + this->
size()); }
361 if (!_M_rep()->_M_is_leaked())
366 _M_check(size_type __pos,
const char* __s)
const
368 if (__pos > this->
size())
369 __throw_out_of_range_fmt(__N(
"%s: __pos (which is %zu) > "
370 "this->size() (which is %zu)"),
371 __s, __pos, this->
size());
376 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
379 __throw_length_error(__N(__s));
384 _M_limit(size_type __pos, size_type __off)
const _GLIBCXX_NOEXCEPT
386 const bool __testoff = __off < this->
size() - __pos;
387 return __testoff ? __off : this->
size() - __pos;
392 _M_disjunct(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
394 return (less<const _CharT*>()(__s, _M_data())
395 || less<const _CharT*>()(_M_data() + this->
size(), __s));
401 _M_copy(_CharT* __d,
const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
404 traits_type::assign(*__d, *__s);
406 traits_type::copy(__d, __s, __n);
410 _M_move(_CharT* __d,
const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
413 traits_type::assign(*__d, *__s);
415 traits_type::move(__d, __s, __n);
419 _M_assign(_CharT* __d, size_type __n, _CharT __c) _GLIBCXX_NOEXCEPT
422 traits_type::assign(*__d, __c);
424 traits_type::assign(__d, __n, __c);
429 template<
class _Iterator>
431 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
433 for (; __k1 != __k2; ++__k1, (void)++__p)
434 traits_type::assign(*__p, *__k1);
438 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
439 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
442 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
444 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
447 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
448 { _M_copy(__p, __k1, __k2 - __k1); }
451 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
453 { _M_copy(__p, __k1, __k2 - __k1); }
456 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
458 const difference_type __d = difference_type(__n1 - __n2);
460 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
461 return __gnu_cxx::__numeric_traits<int>::__max;
462 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
463 return __gnu_cxx::__numeric_traits<int>::__min;
469 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
475 _S_empty_rep() _GLIBCXX_NOEXCEPT
476 {
return _Rep::_S_empty_rep(); }
478#if __cplusplus >= 201703L
480 typedef basic_string_view<_CharT, _Traits> __sv_type;
482 template<
typename _Tp,
typename _Res>
484 __and_<is_convertible<const _Tp&, __sv_type>,
485 __not_<is_convertible<const _Tp*, const basic_string*>>,
486 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
491 _S_to_string_view(__sv_type __svt)
noexcept
500 explicit __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
512 : basic_string(__svw._M_sv.
data(), __svw._M_sv.
size(), __a) { }
524#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
526 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc())
528 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc())
537 : _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a)
546 : _M_dataplus(__str._M_rep()->_M_grab(_Alloc(__str.
get_allocator()),
560 const _Alloc& __a = _Alloc());
578 size_type __n,
const _Alloc& __a);
590 const _Alloc& __a = _Alloc())
591 : _M_dataplus(_S_construct(__s, __s + __n, __a), __a)
599#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
602 template<
typename = _RequireAllocator<_Alloc>>
605 : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::
length(__s) :
606 __s +
npos, __a), __a)
616 : _M_dataplus(_S_construct(__n, __c, __a), __a)
619#if __cplusplus >= 201103L
628 : _M_dataplus(
std::move(__str._M_dataplus))
630#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
632 __str._M_data(_S_empty_rep()._M_refdata());
638 if (_M_rep()->_M_is_shared())
639 __gnu_cxx::__atomic_add_dispatch(&_M_rep()->_M_refcount, 1);
641 _M_rep()->_M_refcount = 1;
651 : _M_dataplus(_S_construct(__l.
begin(), __l.
end(), __a), __a)
655 : _M_dataplus(__str._M_rep()->_M_grab(__a, __str.
get_allocator()), __a)
659 : _M_dataplus(__str._M_data(), __a)
661 if (__a == __str.get_allocator())
663#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
664 __str._M_data(_S_empty_rep()._M_refdata());
666 __str._M_data(_S_construct(size_type(), _CharT(), __a));
670 _M_dataplus._M_p = _S_construct(__str.begin(), __str.end(), __a);
674#if __cplusplus >= 202100L
676 basic_string&
operator=(nullptr_t) =
delete;
685 template<
class _InputIterator>
687 const _Alloc& __a = _Alloc())
688 : _M_dataplus(_S_construct(__beg, __end, __a), __a)
691#if __cplusplus >= 201703L
699 template<
typename _Tp,
702 const _Alloc& __a = _Alloc())
703 : basic_string(_S_to_string_view(__t).
substr(__pos, __n), __a) { }
710 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
713 : basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
728 {
return this->
assign(__str); }
736 {
return this->
assign(__s); }
752#if __cplusplus >= 201103L
776 this->
assign(__l.begin(), __l.size());
781#if __cplusplus >= 201703L
786 template<
typename _Tp>
787 _If_sv<_Tp, basic_string&>
789 {
return this->
assign(__svt); }
795 operator __sv_type() const noexcept
796 {
return __sv_type(
data(),
size()); }
808 return iterator(_M_data());
817 {
return const_iterator(_M_data()); }
827 return iterator(_M_data() + this->
size());
835 end() const _GLIBCXX_NOEXCEPT
836 {
return const_iterator(_M_data() + this->
size()); }
845 {
return reverse_iterator(this->
end()); }
852 const_reverse_iterator
854 {
return const_reverse_iterator(this->
end()); }
863 {
return reverse_iterator(this->
begin()); }
870 const_reverse_iterator
872 {
return const_reverse_iterator(this->
begin()); }
874#if __cplusplus >= 201103L
881 {
return const_iterator(this->_M_data()); }
889 {
return const_iterator(this->_M_data() + this->
size()); }
896 const_reverse_iterator
898 {
return const_reverse_iterator(this->
end()); }
905 const_reverse_iterator
907 {
return const_reverse_iterator(this->
begin()); }
918#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 && __OPTIMIZE__
919 if (_S_empty_rep()._M_length != 0)
920 __builtin_unreachable();
922 return _M_rep()->_M_length;
934 {
return _Rep::_S_max_size; }
961 { this->
resize(__n, _CharT()); }
963#if __cplusplus >= 201103L
964#pragma GCC diagnostic push
965#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
970#pragma GCC diagnostic pop
979 {
return _M_rep()->_M_capacity; }
1002#if __cplusplus > 201703L
1003 [[deprecated(
"use shrink_to_fit() instead")]]
1011#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
1015 if (_M_rep()->_M_is_shared())
1018 _M_data(_S_empty_rep()._M_refdata());
1021 _M_rep()->_M_set_length_and_sharable(0);
1027 { _M_mutate(0, this->
size(), 0); }
1034 _GLIBCXX_NODISCARD
bool
1036 {
return this->
size() == 0; }
1052 __glibcxx_assert(__pos <=
size());
1053 return _M_data()[__pos];
1071 __glibcxx_assert(__pos <=
size());
1073 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos <
size());
1075 return _M_data()[__pos];
1091 if (__n >= this->
size())
1092 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1093 "(which is %zu) >= this->size() "
1096 return _M_data()[__n];
1114 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1115 "(which is %zu) >= this->size() "
1119 return _M_data()[__n];
1122#if __cplusplus >= 201103L
1130 __glibcxx_assert(!
empty());
1141 __glibcxx_assert(!
empty());
1152 __glibcxx_assert(!
empty());
1163 __glibcxx_assert(!
empty());
1176 {
return this->
append(__str); }
1185 {
return this->
append(__s); }
1199#if __cplusplus >= 201103L
1207 {
return this->
append(__l.begin(), __l.size()); }
1210#if __cplusplus >= 201703L
1216 template<
typename _Tp>
1217 _If_sv<_Tp, basic_string&>
1219 {
return this->
append(__svt); }
1244 append(
const basic_string& __str, size_type __pos, size_type __n =
npos);
1263 __glibcxx_requires_string(__s);
1264 return this->
append(__s, traits_type::length(__s));
1278#if __cplusplus >= 201103L
1286 {
return this->
append(__l.begin(), __l.size()); }
1297 template<
class _InputIterator>
1299 append(_InputIterator __first, _InputIterator __last)
1300 {
return this->
replace(_M_iend(), _M_iend(), __first, __last); }
1302#if __cplusplus >= 201703L
1308 template<
typename _Tp>
1309 _If_sv<_Tp, basic_string&>
1312 __sv_type __sv = __svt;
1313 return this->
append(__sv.data(), __sv.size());
1324 template<
typename _Tp>
1325 _If_sv<_Tp, basic_string&>
1328 __sv_type __sv = __svt;
1329 return append(__sv.data()
1330 + std::__sv_check(__sv.size(), __pos,
"basic_string::append"),
1331 std::__sv_limit(__sv.size(), __pos, __n));
1342 const size_type __len = 1 + this->
size();
1343 if (__len > this->
capacity() || _M_rep()->_M_is_shared())
1345 traits_type::assign(_M_data()[this->
size()], __c);
1346 _M_rep()->_M_set_length_and_sharable(__len);
1357#if __cplusplus >= 201103L
1389 assign(
const basic_string& __str, size_type __pos, size_type __n =
npos)
1390 {
return this->
assign(__str._M_data()
1391 + __str._M_check(__pos,
"basic_string::assign"),
1392 __str._M_limit(__pos, __n)); }
1419 __glibcxx_requires_string(__s);
1420 return this->
assign(__s, traits_type::length(__s));
1434 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
1444 template<
class _InputIterator>
1446 assign(_InputIterator __first, _InputIterator __last)
1447 {
return this->
replace(_M_ibegin(), _M_iend(), __first, __last); }
1449#if __cplusplus >= 201103L
1457 {
return this->
assign(__l.begin(), __l.size()); }
1460#if __cplusplus >= 201703L
1466 template<
typename _Tp>
1467 _If_sv<_Tp, basic_string&>
1470 __sv_type __sv = __svt;
1471 return this->
assign(__sv.data(), __sv.size());
1481 template<
typename _Tp>
1482 _If_sv<_Tp, basic_string&>
1485 __sv_type __sv = __svt;
1486 return assign(__sv.data()
1487 + std::__sv_check(__sv.size(), __pos,
"basic_string::assign"),
1488 std::__sv_limit(__sv.size(), __pos, __n));
1506 insert(iterator __p, size_type __n, _CharT __c)
1507 { this->
replace(__p, __p, __n, __c); }
1521 template<
class _InputIterator>
1523 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1524 { this->
replace(__p, __p, __beg, __end); }
1526#if __cplusplus >= 201103L
1536 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1537 this->
insert(__p - _M_ibegin(), __l.begin(), __l.size());
1554 insert(size_type __pos1,
const basic_string& __str)
1555 {
return this->
insert(__pos1, __str, size_type(0), __str.size()); }
1576 insert(size_type __pos1,
const basic_string& __str,
1577 size_type __pos2, size_type __n =
npos)
1578 {
return this->
insert(__pos1, __str._M_data()
1579 + __str._M_check(__pos2,
"basic_string::insert"),
1580 __str._M_limit(__pos2, __n)); }
1599 insert(size_type __pos,
const _CharT* __s, size_type __n);
1619 __glibcxx_requires_string(__s);
1620 return this->
insert(__pos, __s, traits_type::length(__s));
1640 insert(size_type __pos, size_type __n, _CharT __c)
1641 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
1642 size_type(0), __n, __c); }
1660 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1661 const size_type __pos = __p - _M_ibegin();
1662 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1663 _M_rep()->_M_set_leaked();
1664 return iterator(_M_data() + __pos);
1667#if __cplusplus >= 201703L
1674 template<
typename _Tp>
1675 _If_sv<_Tp, basic_string&>
1678 __sv_type __sv = __svt;
1679 return this->
insert(__pos, __sv.data(), __sv.size());
1690 template<
typename _Tp>
1691 _If_sv<_Tp, basic_string&>
1693 size_type __pos2, size_type __n =
npos)
1695 __sv_type __sv = __svt;
1696 return this->
replace(__pos1, size_type(0), __sv.data()
1697 + std::__sv_check(__sv.size(), __pos2,
"basic_string::insert"),
1698 std::__sv_limit(__sv.size(), __pos2, __n));
1720 _M_mutate(_M_check(__pos,
"basic_string::erase"),
1721 _M_limit(__pos, __n), size_type(0));
1736 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1737 && __position < _M_iend());
1738 const size_type __pos = __position - _M_ibegin();
1739 _M_mutate(__pos, size_type(1), size_type(0));
1740 _M_rep()->_M_set_leaked();
1741 return iterator(_M_data() + __pos);
1754 erase(iterator __first, iterator __last);
1756#if __cplusplus >= 201103L
1765 __glibcxx_assert(!
empty());
1788 replace(size_type __pos, size_type __n,
const basic_string& __str)
1789 {
return this->
replace(__pos, __n, __str._M_data(), __str.size()); }
1810 replace(size_type __pos1, size_type __n1,
const basic_string& __str,
1811 size_type __pos2, size_type __n2 =
npos)
1812 {
return this->
replace(__pos1, __n1, __str._M_data()
1813 + __str._M_check(__pos2,
"basic_string::replace"),
1814 __str._M_limit(__pos2, __n2)); }
1835 replace(size_type __pos, size_type __n1,
const _CharT* __s,
1855 replace(size_type __pos, size_type __n1,
const _CharT* __s)
1857 __glibcxx_requires_string(__s);
1858 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
1879 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1880 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
1881 _M_limit(__pos, __n1), __n2, __c); }
1897 replace(iterator __i1, iterator __i2,
const basic_string& __str)
1898 {
return this->
replace(__i1, __i2, __str._M_data(), __str.size()); }
1916 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
1918 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1919 && __i2 <= _M_iend());
1920 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1937 replace(iterator __i1, iterator __i2,
const _CharT* __s)
1939 __glibcxx_requires_string(__s);
1940 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
1958 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1960 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1961 && __i2 <= _M_iend());
1962 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1980 template<
class _InputIterator>
1983 _InputIterator __k1, _InputIterator __k2)
1985 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1986 && __i2 <= _M_iend());
1987 __glibcxx_requires_valid_range(__k1, __k2);
1988 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1989 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1997 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1998 && __i2 <= _M_iend());
1999 __glibcxx_requires_valid_range(__k1, __k2);
2000 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2005 replace(iterator __i1, iterator __i2,
2006 const _CharT* __k1,
const _CharT* __k2)
2008 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2009 && __i2 <= _M_iend());
2010 __glibcxx_requires_valid_range(__k1, __k2);
2011 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2016 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
2018 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2019 && __i2 <= _M_iend());
2020 __glibcxx_requires_valid_range(__k1, __k2);
2021 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2022 __k1.base(), __k2 - __k1);
2026 replace(iterator __i1, iterator __i2,
2027 const_iterator __k1, const_iterator __k2)
2029 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2030 && __i2 <= _M_iend());
2031 __glibcxx_requires_valid_range(__k1, __k2);
2032 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2033 __k1.base(), __k2 - __k1);
2036#if __cplusplus >= 201103L
2051 basic_string&
replace(iterator __i1, iterator __i2,
2053 {
return this->
replace(__i1, __i2, __l.begin(), __l.end()); }
2056#if __cplusplus >= 201703L
2064 template<
typename _Tp>
2065 _If_sv<_Tp, basic_string&>
2066 replace(size_type __pos, size_type __n,
const _Tp& __svt)
2068 __sv_type __sv = __svt;
2069 return this->
replace(__pos, __n, __sv.data(), __sv.size());
2081 template<
typename _Tp>
2082 _If_sv<_Tp, basic_string&>
2083 replace(size_type __pos1, size_type __n1,
const _Tp& __svt,
2084 size_type __pos2, size_type __n2 =
npos)
2086 __sv_type __sv = __svt;
2087 return this->
replace(__pos1, __n1,
2089 + std::__sv_check(__sv.size(), __pos2,
"basic_string::replace"),
2090 std::__sv_limit(__sv.size(), __pos2, __n2));
2102 template<
typename _Tp>
2103 _If_sv<_Tp, basic_string&>
2104 replace(const_iterator __i1, const_iterator __i2,
const _Tp& __svt)
2106 __sv_type __sv = __svt;
2107 return this->
replace(__i1 -
begin(), __i2 - __i1, __sv);
2112 template<
class _Integer>
2115 _Integer __val, __true_type)
2116 {
return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
2118 template<
class _InputIterator>
2120 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
2121 _InputIterator __k2, __false_type);
2124 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
2128 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
2133 template<
class _InIterator>
2135 _S_construct_aux(_InIterator __beg, _InIterator __end,
2136 const _Alloc& __a, __false_type)
2138 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
2139 return _S_construct(__beg, __end, __a, _Tag());
2144 template<
class _Integer>
2146 _S_construct_aux(_Integer __beg, _Integer __end,
2147 const _Alloc& __a, __true_type)
2148 {
return _S_construct_aux_2(
static_cast<size_type
>(__beg),
2152 _S_construct_aux_2(size_type __req, _CharT __c,
const _Alloc& __a)
2153 {
return _S_construct(__req, __c, __a); }
2155 template<
class _InIterator>
2157 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a)
2159 typedef typename std::__is_integer<_InIterator>::__type _Integral;
2160 return _S_construct_aux(__beg, __end, __a, _Integral());
2164 template<
class _InIterator>
2166 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
2167 input_iterator_tag);
2171 template<
class _FwdIterator>
2173 _S_construct(_FwdIterator __beg, _FwdIterator __end,
const _Alloc& __a,
2174 forward_iterator_tag);
2177 _S_construct(size_type __req, _CharT __c,
const _Alloc& __a);
2194 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
2216 {
return _M_data(); }
2228 {
return _M_data(); }
2230#if __cplusplus >= 201703L
2250 {
return _M_dataplus; }
2265 find(
const _CharT* __s, size_type __pos, size_type __n)
const
2279 find(
const basic_string& __str, size_type __pos = 0) const
2281 {
return this->
find(__str.data(), __pos, __str.size()); }
2294 find(
const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2296 __glibcxx_requires_string(__s);
2297 return this->
find(__s, __pos, traits_type::length(__s));
2311 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
2313#if __cplusplus >= 201703L
2320 template<
typename _Tp>
2321 _If_sv<_Tp, size_type>
2322 find(
const _Tp& __svt, size_type __pos = 0) const
2323 noexcept(
is_same<_Tp, __sv_type>::value)
2325 __sv_type __sv = __svt;
2326 return this->
find(__sv.data(), __pos, __sv.size());
2341 rfind(
const basic_string& __str, size_type __pos =
npos)
const
2343 {
return this->
rfind(__str.data(), __pos, __str.size()); }
2358 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
2372 rfind(
const _CharT* __s, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT
2374 __glibcxx_requires_string(__s);
2375 return this->
rfind(__s, __pos, traits_type::length(__s));
2389 rfind(_CharT __c, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT;
2391#if __cplusplus >= 201703L
2398 template<
typename _Tp>
2399 _If_sv<_Tp, size_type>
2401 noexcept(is_same<_Tp, __sv_type>::value)
2403 __sv_type __sv = __svt;
2404 return this->
rfind(__sv.data(), __pos, __sv.size());
2422 {
return this->
find_first_of(__str.data(), __pos, __str.size()); }
2454 __glibcxx_requires_string(__s);
2455 return this->
find_first_of(__s, __pos, traits_type::length(__s));
2472 {
return this->
find(__c, __pos); }
2474#if __cplusplus >= 201703L
2482 template<
typename _Tp>
2483 _If_sv<_Tp, size_type>
2485 noexcept(
is_same<_Tp, __sv_type>::value)
2487 __sv_type __sv = __svt;
2488 return this->
find_first_of(__sv.data(), __pos, __sv.size());
2506 {
return this->
find_last_of(__str.data(), __pos, __str.size()); }
2538 __glibcxx_requires_string(__s);
2539 return this->
find_last_of(__s, __pos, traits_type::length(__s));
2556 {
return this->
rfind(__c, __pos); }
2558#if __cplusplus >= 201703L
2566 template<
typename _Tp>
2567 _If_sv<_Tp, size_type>
2569 noexcept(is_same<_Tp, __sv_type>::value)
2571 __sv_type __sv = __svt;
2572 return this->
find_last_of(__sv.data(), __pos, __sv.size());
2605 size_type __n)
const _GLIBCXX_NOEXCEPT;
2621 __glibcxx_requires_string(__s);
2639#if __cplusplus >= 201703L
2647 template<
typename _Tp>
2648 _If_sv<_Tp, size_type>
2650 noexcept(
is_same<_Tp, __sv_type>::value)
2652 __sv_type __sv = __svt;
2687 size_type __n)
const _GLIBCXX_NOEXCEPT;
2703 __glibcxx_requires_string(__s);
2721#if __cplusplus >= 201703L
2729 template<
typename _Tp>
2730 _If_sv<_Tp, size_type>
2732 noexcept(is_same<_Tp, __sv_type>::value)
2734 __sv_type __sv = __svt;
2754 _M_check(__pos,
"basic_string::substr"), __n); }
2773 const size_type __size = this->
size();
2774 const size_type __osize = __str.size();
2775 const size_type __len =
std::min(__size, __osize);
2777 int __r = traits_type::compare(_M_data(), __str.data(), __len);
2779 __r = _S_compare(__size, __osize);
2783#if __cplusplus >= 201703L
2789 template<
typename _Tp>
2792 noexcept(is_same<_Tp, __sv_type>::value)
2794 __sv_type __sv = __svt;
2795 const size_type __size = this->
size();
2796 const size_type __osize = __sv.size();
2797 const size_type __len =
std::min(__size, __osize);
2799 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
2801 __r = _S_compare(__size, __osize);
2813 template<
typename _Tp>
2815 compare(size_type __pos, size_type __n,
const _Tp& __svt)
const
2816 noexcept(is_same<_Tp, __sv_type>::value)
2818 __sv_type __sv = __svt;
2819 return __sv_type(*this).substr(__pos, __n).compare(__sv);
2832 template<
typename _Tp>
2834 compare(size_type __pos1, size_type __n1,
const _Tp& __svt,
2835 size_type __pos2, size_type __n2 =
npos)
const
2836 noexcept(is_same<_Tp, __sv_type>::value)
2838 __sv_type __sv = __svt;
2839 return __sv_type(*
this)
2840 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
2864 compare(size_type __pos, size_type __n,
const basic_string& __str)
const;
2890 compare(size_type __pos1, size_type __n1,
const basic_string& __str,
2891 size_type __pos2, size_type __n2 =
npos)
const;
2908 compare(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT;
2932 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const;
2959 compare(size_type __pos, size_type __n1,
const _CharT* __s,
2960 size_type __n2)
const;
2962#if __cplusplus > 201703L
2965 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
2968 starts_with(_CharT __x)
const noexcept
2969 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
2972 starts_with(
const _CharT* __x)
const noexcept
2973 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
2976 ends_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
2977 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
2980 ends_with(_CharT __x)
const noexcept
2981 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
2984 ends_with(
const _CharT* __x)
const noexcept
2985 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
2988#if __cplusplus > 202011L
2990 contains(basic_string_view<_CharT, _Traits> __x)
const noexcept
2991 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
2994 contains(_CharT __x)
const noexcept
2995 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
2998 contains(
const _CharT* __x)
const noexcept
2999 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3002# ifdef _GLIBCXX_TM_TS_INTERNAL
3004 ::_txnal_cow_string_C1_for_exceptions(
void* that,
const char* s,
3007 ::_txnal_cow_string_c_str(
const void *that);
3009 ::_txnal_cow_string_D1(
void *that);
3011 ::_txnal_cow_string_D1_commit(
void *that);
3015 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3016 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
3018 _Rep::_S_max_size = (((npos -
sizeof(_Rep_base))/
sizeof(_CharT)) - 1) / 4;
3020 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3023 _Rep::_S_terminal = _CharT();
3025 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3026 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
3031 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3032 typename basic_string<_CharT, _Traits, _Alloc>::size_type
3033 basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_empty_rep_storage[
3034 (
sizeof(_Rep_base) +
sizeof(_CharT) +
sizeof(
size_type) - 1) /
3041 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3042 template<
typename _InIterator>
3045 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
3048#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3049 if (__beg == __end && __a == _Alloc())
3050 return _S_empty_rep()._M_refdata();
3055 while (__beg != __end && __len <
sizeof(__buf) /
sizeof(_CharT))
3057 __buf[__len++] = *__beg;
3060 _Rep* __r = _Rep::_S_create(__len,
size_type(0), __a);
3061 _M_copy(__r->_M_refdata(), __buf, __len);
3064 while (__beg != __end)
3066 if (__len == __r->_M_capacity)
3069 _Rep* __another = _Rep::_S_create(__len + 1, __len, __a);
3070 _M_copy(__another->_M_refdata(), __r->_M_refdata(), __len);
3071 __r->_M_destroy(__a);
3074 __r->_M_refdata()[__len++] = *__beg;
3080 __r->_M_destroy(__a);
3081 __throw_exception_again;
3083 __r->_M_set_length_and_sharable(__len);
3084 return __r->_M_refdata();
3087 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3088 template <
typename _InIterator>
3091 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
3094#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3095 if (__beg == __end && __a == _Alloc())
3096 return _S_empty_rep()._M_refdata();
3099 if (__gnu_cxx::__is_null_pointer(__beg) && __beg != __end)
3100 __throw_logic_error(__N(
"basic_string::_S_construct null not valid"));
3105 _Rep* __r = _Rep::_S_create(__dnew,
size_type(0), __a);
3107 { _S_copy_chars(__r->_M_refdata(), __beg, __end); }
3110 __r->_M_destroy(__a);
3111 __throw_exception_again;
3113 __r->_M_set_length_and_sharable(__dnew);
3114 return __r->_M_refdata();
3117 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3122#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3123 if (__n == 0 && __a == _Alloc())
3124 return _S_empty_rep()._M_refdata();
3127 _Rep* __r = _Rep::_S_create(__n,
size_type(0), __a);
3129 _M_assign(__r->_M_refdata(), __n, __c);
3131 __r->_M_set_length_and_sharable(__n);
3132 return __r->_M_refdata();
3135 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3138 : _M_dataplus(_S_construct(__str._M_data()
3139 + __str._M_check(__pos,
3140 "basic_string::basic_string"),
3141 __str._M_data() + __str._M_limit(__pos, npos)
3145 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3148 : _M_dataplus(_S_construct(__str._M_data()
3149 + __str._M_check(__pos,
3150 "basic_string::basic_string"),
3151 __str._M_data() + __str._M_limit(__pos, __n)
3152 + __pos, _Alloc()), _Alloc())
3155 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3159 : _M_dataplus(_S_construct(__str._M_data()
3160 + __str._M_check(__pos,
3161 "basic_string::basic_string"),
3162 __str._M_data() + __str._M_limit(__pos, __n)
3166 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3171 if (_M_rep() != __str._M_rep())
3174 const allocator_type __a = this->get_allocator();
3175 _CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.get_allocator());
3176 _M_rep()->_M_dispose(__a);
3182 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3187 __glibcxx_requires_string_len(__s, __n);
3188 _M_check_length(this->
size(), __n,
"basic_string::assign");
3189 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3190 return _M_replace_safe(
size_type(0), this->
size(), __s, __n);
3194 const size_type __pos = __s - _M_data();
3196 _M_copy(_M_data(), __s, __n);
3198 _M_move(_M_data(), __s, __n);
3199 _M_rep()->_M_set_length_and_sharable(__n);
3204 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3211 _M_check_length(
size_type(0), __n,
"basic_string::append");
3213 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3214 this->reserve(__len);
3215 _M_assign(_M_data() + this->
size(), __n, __c);
3216 _M_rep()->_M_set_length_and_sharable(__len);
3221 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3226 __glibcxx_requires_string_len(__s, __n);
3229 _M_check_length(
size_type(0), __n,
"basic_string::append");
3231 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3233 if (_M_disjunct(__s))
3234 this->reserve(__len);
3237 const size_type __off = __s - _M_data();
3238 this->reserve(__len);
3239 __s = _M_data() + __off;
3242 _M_copy(_M_data() + this->
size(), __s, __n);
3243 _M_rep()->_M_set_length_and_sharable(__len);
3248 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3257 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3258 this->reserve(__len);
3259 _M_copy(_M_data() + this->
size(), __str._M_data(), __size);
3260 _M_rep()->_M_set_length_and_sharable(__len);
3265 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3270 __str._M_check(__pos,
"basic_string::append");
3271 __n = __str._M_limit(__pos, __n);
3275 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3276 this->reserve(__len);
3277 _M_copy(_M_data() + this->
size(), __str._M_data() + __pos, __n);
3278 _M_rep()->_M_set_length_and_sharable(__len);
3283 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3288 __glibcxx_requires_string_len(__s, __n);
3289 _M_check(__pos,
"basic_string::insert");
3290 _M_check_length(
size_type(0), __n,
"basic_string::insert");
3291 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3292 return _M_replace_safe(__pos,
size_type(0), __s, __n);
3296 const size_type __off = __s - _M_data();
3297 _M_mutate(__pos, 0, __n);
3298 __s = _M_data() + __off;
3299 _CharT* __p = _M_data() + __pos;
3300 if (__s + __n <= __p)
3301 _M_copy(__p, __s, __n);
3302 else if (__s >= __p)
3303 _M_copy(__p, __s + __n, __n);
3307 _M_copy(__p, __s, __nleft);
3308 _M_copy(__p + __nleft, __p + __n, __n - __nleft);
3314 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3315 typename basic_string<_CharT, _Traits, _Alloc>::iterator
3317 erase(iterator __first, iterator __last)
3319 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
3320 && __last <= _M_iend());
3325 const size_type __size = __last - __first;
3328 const size_type __pos = __first - _M_ibegin();
3329 _M_mutate(__pos, __size, size_type(0));
3330 _M_rep()->_M_set_leaked();
3331 return iterator(_M_data() + __pos);
3337 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3343 __glibcxx_requires_string_len(__s, __n2);
3344 _M_check(__pos,
"basic_string::replace");
3345 __n1 = _M_limit(__pos, __n1);
3346 _M_check_length(__n1, __n2,
"basic_string::replace");
3348 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3349 return _M_replace_safe(__pos, __n1, __s, __n2);
3350 else if ((__left = __s + __n2 <= _M_data() + __pos)
3351 || _M_data() + __pos + __n1 <= __s)
3355 __left ? __off : (__off += __n2 - __n1);
3356 _M_mutate(__pos, __n1, __n2);
3357 _M_copy(_M_data() + __pos, _M_data() + __off, __n2);
3363 const basic_string __tmp(__s, __n2);
3364 return _M_replace_safe(__pos, __n1, __tmp._M_data(), __n2);
3368 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3373 const size_type __size =
sizeof(_Rep_base)
3374 + (this->_M_capacity + 1) *
sizeof(_CharT);
3375 _Raw_bytes_alloc(__a).deallocate(
reinterpret_cast<char*
>(
this), __size);
3378 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3390 if (_M_rep()->_M_is_shared())
3392 _M_rep()->_M_set_leaked();
3395 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3401 const size_type __new_size = __old_size + __len2 - __len1;
3402 const size_type __how_much = __old_size - __pos - __len1;
3404 if (__new_size > this->capacity() || _M_rep()->_M_is_shared())
3407 const allocator_type __a = get_allocator();
3408 _Rep* __r = _Rep::_S_create(__new_size, this->capacity(), __a);
3411 _M_copy(__r->_M_refdata(), _M_data(), __pos);
3413 _M_copy(__r->_M_refdata() + __pos + __len2,
3414 _M_data() + __pos + __len1, __how_much);
3416 _M_rep()->_M_dispose(__a);
3417 _M_data(__r->_M_refdata());
3419 else if (__how_much && __len1 != __len2)
3422 _M_move(_M_data() + __pos + __len2,
3423 _M_data() + __pos + __len1, __how_much);
3425 _M_rep()->_M_set_length_and_sharable(__new_size);
3428 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3433 const size_type __capacity =
capacity();
3439 if (__res <= __capacity)
3441 if (!_M_rep()->_M_is_shared())
3449 _CharT* __tmp = _M_rep()->_M_clone(__a, __res - this->
size());
3450 _M_rep()->_M_dispose(__a);
3454 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3457 swap(basic_string& __s)
3460 if (_M_rep()->_M_is_leaked())
3461 _M_rep()->_M_set_sharable();
3462 if (__s._M_rep()->_M_is_leaked())
3463 __s._M_rep()->_M_set_sharable();
3466 _CharT* __tmp = _M_data();
3467 _M_data(__s._M_data());
3473 const basic_string __tmp1(_M_ibegin(), _M_iend(),
3474 __s.get_allocator());
3475 const basic_string __tmp2(__s._M_ibegin(), __s._M_iend(),
3476 this->get_allocator());
3482 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3483 typename basic_string<_CharT, _Traits, _Alloc>::_Rep*
3486 const _Alloc& __alloc)
3490 if (__capacity > _S_max_size)
3491 __throw_length_error(__N(
"basic_string::_S_create"));
3517 const size_type __malloc_header_size = 4 *
sizeof(
void*);
3525 if (__capacity > __old_capacity && __capacity < 2 * __old_capacity)
3526 __capacity = 2 * __old_capacity;
3531 size_type __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
3533 const size_type __adj_size = __size + __malloc_header_size;
3534 if (__adj_size > __pagesize && __capacity > __old_capacity)
3536 const size_type __extra = __pagesize - __adj_size % __pagesize;
3537 __capacity += __extra /
sizeof(_CharT);
3539 if (__capacity > _S_max_size)
3540 __capacity = _S_max_size;
3541 __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
3546 void* __place = _Raw_bytes_alloc(__alloc).
allocate(__size);
3547 _Rep *__p =
new (__place) _Rep;
3548 __p->_M_capacity = __capacity;
3556 __p->_M_set_sharable();
3560 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3562 basic_string<_CharT, _Traits, _Alloc>::_Rep::
3563 _M_clone(
const _Alloc& __alloc, size_type __res)
3566 const size_type __requested_cap = this->_M_length + __res;
3567 _Rep* __r = _Rep::_S_create(__requested_cap, this->_M_capacity,
3569 if (this->_M_length)
3570 _M_copy(__r->_M_refdata(), _M_refdata(), this->_M_length);
3572 __r->_M_set_length_and_sharable(this->_M_length);
3573 return __r->_M_refdata();
3576 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3579 resize(size_type __n, _CharT __c)
3581 const size_type __size = this->
size();
3582 _M_check_length(__size, __n,
"basic_string::resize");
3584 this->
append(__n - __size, __c);
3585 else if (__n < __size)
3590 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3591 template<
typename _InputIterator>
3595 _InputIterator __k2, __false_type)
3599 _M_check_length(__n1, __s.size(),
"basic_string::_M_replace_dispatch");
3600 return _M_replace_safe(__i1 - _M_ibegin(), __n1, __s._M_data(),
3604 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3606 basic_string<_CharT, _Traits, _Alloc>::
3607 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
3610 _M_check_length(__n1, __n2,
"basic_string::_M_replace_aux");
3611 _M_mutate(__pos1, __n1, __n2);
3613 _M_assign(_M_data() + __pos1, __n2, __c);
3617 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3618 basic_string<_CharT, _Traits, _Alloc>&
3619 basic_string<_CharT, _Traits, _Alloc>::
3620 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
3623 _M_mutate(__pos1, __n1, __n2);
3625 _M_copy(_M_data() + __pos1, __s, __n2);
3629 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3639 _CharT* __tmp = _M_rep()->_M_clone(__a);
3640 _M_rep()->_M_dispose(__a);
3650 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3651 typename basic_string<_CharT, _Traits, _Alloc>::size_type
3653 copy(_CharT* __s, size_type __n, size_type __pos)
const
3655 _M_check(__pos,
"basic_string::copy");
3656 __n = _M_limit(__pos, __n);
3657 __glibcxx_requires_string_len(__s, __n);
3659 _M_copy(__s, _M_data() + __pos, __n);
3663_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.
A non-owning reference to a string.
Uniform interface to all allocator types.
static constexpr pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
Managing sequences of characters and character-like objects.
int compare(size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos) const
Compare substring to a substring.
const_reverse_iterator crbegin() const noexcept
basic_string & insert(size_type __pos, const _CharT *__s, size_type __n)
Insert a C substring.
void swap(basic_string &__s) noexcept(/*conditional */)
Swap contents with another string.
_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.
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.
basic_string & append(size_type __n, _CharT __c)
Append multiple characters.
size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
constexpr size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
iterator erase(iterator __first, iterator __last)
Remove a range of characters.
constexpr void clear() noexcept
_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.
size_type find_last_of(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find last position of a character of C substring.
basic_string(const _Alloc &__a)
Construct an empty string using allocator a.
constexpr size_type find_last_not_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character not in string.
size_type find_last_of(const _CharT *__s, size_type __pos=npos) const noexcept
Find last position of a character of C string.
_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.
void reserve(size_type __res_arg)
Attempt to preallocate enough memory for specified number of characters.
iterator erase(iterator __position)
Remove one character.
constexpr size_type find(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find position of a C substring.
size_type find(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a string.
size_type find_last_not_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character not in string.
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C string.
int compare(size_type __pos, size_type __n, const basic_string &__str) const
Compare substring to a string.
constexpr const _CharT * data() const noexcept
Return const pointer to contents.
basic_string(const basic_string &__str)
Construct string with copy of value of str.
int compare(const basic_string &__str) const
Compare to a string.
int compare(size_type __pos, size_type __n1, const _CharT *__s) const
Compare substring to a C string.
_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.
constexpr basic_string substr(size_type __pos=0, size_type __n=npos) const
basic_string & assign(const _CharT *__s, size_type __n)
Set value to a C substring.
int compare(size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) const
Compare substring against a character array.
_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.
constexpr basic_string & assign(const basic_string &__str)
Set value to contents of another string.
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.
constexpr size_type length() const noexcept
constexpr basic_string() noexcept(/*conditional */)
Default constructor creates an empty string.
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(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.
constexpr size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C string.
size_type length() const noexcept
Returns the number of characters in the string, not including any null-termination.
size_type find_last_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character of string.
size_type find_first_not_of(_CharT __c, size_type __pos=0) const noexcept
Find position of a different character.
basic_string & operator+=(const basic_string &__str)
Append a string to this string.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
size_type rfind(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a string.
constexpr size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
basic_string & operator+=(const _CharT *__s)
Append a C string.
basic_string(size_type __n, _CharT __c, const _Alloc &__a=_Alloc())
Construct string as multiple characters.
void shrink_to_fit() noexcept
A non-binding request to reduce capacity() to size().
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
_If_sv< _Tp, int > compare(const _Tp &__svt) const noexcept(is_same< _Tp, __sv_type >::value)
Compare to a string_view.
size_type find(_CharT __c, size_type __pos=0) const noexcept
Find position of a character.
const_reference at(size_type __n) const
Provides access to the data contained in the string.
const_reference back() const noexcept
const_reverse_iterator rend() const noexcept
const_iterator end() const noexcept
_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.
basic_string & replace(size_type __pos, size_type __n1, const _CharT *__s, size_type __n2)
Replace characters with value of a C substring.
size_type find_last_of(_CharT __c, size_type __pos=npos) const noexcept
Find last position of a character.
_If_sv< _Tp, basic_string & > replace(size_type __pos, size_type __n, const _Tp &__svt)
Replace range of characters with string_view.
constexpr size_type rfind(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a string.
constexpr basic_string & append(const basic_string &__str)
Append a string to this string.
const_iterator begin() const noexcept
basic_string & operator=(basic_string &&__str) noexcept(/*conditional */)
Move assign the value of str to this string.
basic_string & replace(iterator __i1, iterator __i2, initializer_list< _CharT > __l)
Replace range of characters with initializer_list.
constexpr basic_string & operator=(const basic_string &__str)
Assign the value of str to this string.
basic_string & operator+=(_CharT __c)
Append a character.
const_reverse_iterator crend() const noexcept
basic_string & operator=(const basic_string &__str)
Assign the value of str to this string.
basic_string & operator=(_CharT __c)
Set value to string of length 1.
void resize(size_type __n)
Resizes the string to the specified number of characters.
const_reverse_iterator rbegin() const noexcept
constexpr size_type find_last_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character of string.
size_type find_last_not_of(_CharT __c, size_type __pos=npos) const noexcept
Find last position of a different character.
constexpr iterator end() noexcept
constexpr iterator begin() noexcept
basic_string & append(const _CharT *__s, size_type __n)
Append a C substring.
basic_string & assign(_InputIterator __first, _InputIterator __last)
Set value to a range of characters.
basic_string & append(initializer_list< _CharT > __l)
Append an initializer_list of characters.
basic_string & append(const basic_string &__str, size_type __pos, size_type __n=npos)
Append a substring.
basic_string & append(_InputIterator __first, _InputIterator __last)
Append a range of characters.
_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 & assign(const basic_string &__str)
Set value to contents of another string.
basic_string(const _CharT *__s, const _Alloc &__a=_Alloc())
Construct string as copy of a C string.
constexpr void push_back(_CharT __c)
Append a single character.
size_type find_first_of(_CharT __c, size_type __pos=0) const noexcept
Find position of a character.
_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.
constexpr size_type find_first_not_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character not in string.
_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.
constexpr iterator insert(const_iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
basic_string & assign(const basic_string &__str, size_type __pos, size_type __n=npos)
Set value to a substring of a string.
constexpr size_type capacity() const noexcept
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
_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.
constexpr bool empty() const noexcept
size_type find(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find position of a C substring.
static const size_type npos
Value returned by various member functions when they fail.
constexpr basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
allocator_type get_allocator() const noexcept
Return copy of allocator used to construct this string.
basic_string & assign(const _CharT *__s)
Set value to contents of a C string.
basic_string & append(const basic_string &__str)
Append a string to this string.
size_type find_first_not_of(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find position of a character not in C substring.
basic_string & replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
Replace characters with multiple characters.
const_iterator cbegin() const noexcept
constexpr allocator_type get_allocator() const noexcept
constexpr basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
basic_string & replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
Replace range of characters with multiple characters.
basic_string & operator=(initializer_list< _CharT > __l)
Set value to string constructed from initializer list.
~basic_string() noexcept
Destroy the string instance.
size_type capacity() const noexcept
basic_string() noexcept
Default constructor creates an empty string.
size_type find_first_of(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find position of a character of C substring.
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 rfind(_CharT __c, size_type __pos=npos) const noexcept
Find last position of a character.
size_type max_size() const noexcept
Returns the size() of the largest possible string.
reference operator[](size_type __pos)
Subscript access to the data contained in the string.
basic_string & insert(size_type __pos, size_type __n, _CharT __c)
Insert multiple characters.
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
basic_string & replace(size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos)
Replace characters with value from another string.
constexpr size_type max_size() const noexcept
Returns the size() of the largest possible string.
_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.
constexpr void swap(basic_string &__s) noexcept
Swap contents with another string.
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.
constexpr const_reference operator[](size_type __pos) const noexcept
Subscript access to the data contained in the string.
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
size_type rfind(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find last position of a C substring.
size_type find_first_not_of(const _CharT *__s, size_type __pos=0) const noexcept
Find position of a character not in C string.
size_type find_last_not_of(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find last position of a character not in C substring.
reference at(size_type __n)
Provides access to the data contained in the string.
iterator insert(iterator __p, _CharT __c)
Insert one character.
Thrown as part of forced unwinding.
Forward iterators support a superset of input iterator operations.