33 #define _COW_STRING_H 1
35 #if ! _GLIBCXX_USE_CXX11_ABI
37 #ifdef __cpp_lib_is_constant_evaluated
39 # define __cpp_lib_constexpr_string 201811L
40 #elif __cplusplus >= 201703L && _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
42 # define __cpp_lib_constexpr_string 201611L
45 namespace std _GLIBCXX_VISIBILITY(default)
47 _GLIBCXX_BEGIN_NAMESPACE_VERSION
111 template<
typename _CharT,
typename _Traits,
typename _Alloc>
115 rebind<_CharT>::other _CharT_alloc_type;
120 typedef _Traits traits_type;
121 typedef typename _Traits::char_type value_type;
122 typedef _Alloc allocator_type;
123 typedef typename _CharT_alloc_traits::size_type size_type;
124 typedef typename _CharT_alloc_traits::difference_type difference_type;
125 #if __cplusplus < 201103L
126 typedef typename _CharT_alloc_type::reference reference;
127 typedef typename _CharT_alloc_type::const_reference const_reference;
129 typedef value_type& reference;
130 typedef const value_type& const_reference;
132 typedef typename _CharT_alloc_traits::pointer pointer;
133 typedef typename _CharT_alloc_traits::const_pointer const_pointer;
134 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
135 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
142 typedef iterator __const_iterator;
162 size_type _M_capacity;
163 _Atomic_word _M_refcount;
166 struct _Rep : _Rep_base
170 rebind<char>::other _Raw_bytes_alloc;
185 static const size_type _S_max_size;
186 static const _CharT _S_terminal;
190 static size_type _S_empty_rep_storage[];
193 _S_empty_rep() _GLIBCXX_NOEXCEPT
198 void* __p =
reinterpret_cast<void*
>(&_S_empty_rep_storage);
199 return *
reinterpret_cast<_Rep*
>(__p);
203 _M_is_leaked()
const _GLIBCXX_NOEXCEPT
205 #if defined(__GTHREADS)
210 return __atomic_load_n(&this->_M_refcount, __ATOMIC_RELAXED) < 0;
212 return this->_M_refcount < 0;
217 _M_is_shared()
const _GLIBCXX_NOEXCEPT
219 #if defined(__GTHREADS)
225 return __atomic_load_n(&this->_M_refcount, __ATOMIC_ACQUIRE) > 0;
227 return this->_M_refcount > 0;
232 _M_set_leaked() _GLIBCXX_NOEXCEPT
233 { this->_M_refcount = -1; }
236 _M_set_sharable() _GLIBCXX_NOEXCEPT
237 { this->_M_refcount = 0; }
240 _M_set_length_and_sharable(size_type __n) _GLIBCXX_NOEXCEPT
242 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
243 if (__builtin_expect(
this != &_S_empty_rep(),
false))
246 this->_M_set_sharable();
247 this->_M_length = __n;
248 traits_type::assign(this->_M_refdata()[__n], _S_terminal);
256 {
return reinterpret_cast<_CharT*
>(
this + 1); }
259 _M_grab(
const _Alloc& __alloc1,
const _Alloc& __alloc2)
261 return (!_M_is_leaked() && __alloc1 == __alloc2)
262 ? _M_refcopy() : _M_clone(__alloc1);
267 _S_create(size_type, size_type,
const _Alloc&);
270 _M_dispose(
const _Alloc& __a) _GLIBCXX_NOEXCEPT
272 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
273 if (__builtin_expect(
this != &_S_empty_rep(),
false))
277 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount);
286 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
289 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount);
296 _M_destroy(
const _Alloc&)
throw();
301 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
302 if (__builtin_expect(
this != &_S_empty_rep(),
false))
304 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
309 _M_clone(
const _Alloc&, size_type __res = 0);
313 struct _Alloc_hider : _Alloc
315 _Alloc_hider(_CharT* __dat,
const _Alloc& __a) _GLIBCXX_NOEXCEPT
316 : _Alloc(__a), _M_p(__dat) { }
326 static const size_type
npos =
static_cast<size_type
>(-1);
330 mutable _Alloc_hider _M_dataplus;
333 _M_data() const _GLIBCXX_NOEXCEPT
334 {
return _M_dataplus._M_p; }
337 _M_data(_CharT* __p) _GLIBCXX_NOEXCEPT
338 {
return (_M_dataplus._M_p = __p); }
341 _M_rep() const _GLIBCXX_NOEXCEPT
342 {
return &((
reinterpret_cast<_Rep*
> (_M_data()))[-1]); }
347 _M_ibegin() const _GLIBCXX_NOEXCEPT
348 {
return iterator(_M_data()); }
351 _M_iend() const _GLIBCXX_NOEXCEPT
352 {
return iterator(_M_data() + this->
size()); }
357 if (!_M_rep()->_M_is_leaked())
362 _M_check(size_type __pos,
const char* __s)
const
364 if (__pos > this->
size())
365 __throw_out_of_range_fmt(__N(
"%s: __pos (which is %zu) > "
366 "this->size() (which is %zu)"),
367 __s, __pos, this->
size());
372 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
375 __throw_length_error(__N(__s));
380 _M_limit(size_type __pos, size_type __off)
const _GLIBCXX_NOEXCEPT
382 const bool __testoff = __off < this->
size() - __pos;
383 return __testoff ? __off : this->
size() - __pos;
388 _M_disjunct(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
390 return (less<const _CharT*>()(__s, _M_data())
391 || less<const _CharT*>()(_M_data() + this->
size(), __s));
397 _M_copy(_CharT* __d,
const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
400 traits_type::assign(*__d, *__s);
402 traits_type::copy(__d, __s, __n);
406 _M_move(_CharT* __d,
const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
409 traits_type::assign(*__d, *__s);
411 traits_type::move(__d, __s, __n);
415 _M_assign(_CharT* __d, size_type __n, _CharT __c) _GLIBCXX_NOEXCEPT
418 traits_type::assign(*__d, __c);
420 traits_type::assign(__d, __n, __c);
425 template<
class _Iterator>
427 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
429 for (; __k1 != __k2; ++__k1, (void)++__p)
430 traits_type::assign(*__p, *__k1);
434 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
435 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
438 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
440 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
443 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
444 { _M_copy(__p, __k1, __k2 - __k1); }
447 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
449 { _M_copy(__p, __k1, __k2 - __k1); }
452 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
454 const difference_type __d = difference_type(__n1 - __n2);
456 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
457 return __gnu_cxx::__numeric_traits<int>::__max;
458 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
459 return __gnu_cxx::__numeric_traits<int>::__min;
465 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
471 _S_empty_rep() _GLIBCXX_NOEXCEPT
472 {
return _Rep::_S_empty_rep(); }
474 #if __cplusplus >= 201703L
476 typedef basic_string_view<_CharT, _Traits> __sv_type;
478 template<
typename _Tp,
typename _Res>
480 __and_<is_convertible<const _Tp&, __sv_type>,
481 __not_<is_convertible<const _Tp*, const basic_string*>>,
482 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
487 _S_to_string_view(__sv_type __svt) noexcept
496 explicit __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
520 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
522 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc())
524 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc())
533 : _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a)
542 : _M_dataplus(__str._M_rep()->_M_grab(_Alloc(__str.
get_allocator()),
556 const _Alloc& __a = _Alloc());
574 size_type __n,
const _Alloc& __a);
586 const _Alloc& __a = _Alloc())
587 : _M_dataplus(_S_construct(__s, __s + __n, __a), __a)
595 #if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
598 template<
typename = _RequireAllocator<_Alloc>>
601 : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::
length(__s) :
602 __s +
npos, __a), __a)
612 : _M_dataplus(_S_construct(__n, __c, __a), __a)
615 #if __cplusplus >= 201103L
624 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
625 : _M_dataplus(
std::move(__str._M_dataplus))
627 __str._M_data(_S_empty_rep()._M_refdata());
630 : _M_dataplus(__str._M_rep())
636 if (_M_rep()->_M_is_leaked())
637 __gnu_cxx::__atomic_add_dispatch(&_M_rep()->_M_refcount, 2);
639 __gnu_cxx::__atomic_add_dispatch(&_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);
681 template<
class _InputIterator>
683 const _Alloc& __a = _Alloc())
684 : _M_dataplus(_S_construct(__beg, __end, __a), __a)
687 #if __cplusplus >= 201703L
695 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
697 const _Alloc& __a = _Alloc())
705 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
708 :
basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
723 {
return this->
assign(__str); }
731 {
return this->
assign(__s); }
747 #if __cplusplus >= 201103L
771 this->
assign(__l.begin(), __l.size());
776 #if __cplusplus >= 201703L
781 template<
typename _Tp>
782 _If_sv<_Tp, basic_string&>
784 {
return this->
assign(__svt); }
803 return iterator(_M_data());
812 {
return const_iterator(_M_data()); }
822 return iterator(_M_data() + this->
size());
830 end() const _GLIBCXX_NOEXCEPT
831 {
return const_iterator(_M_data() + this->
size()); }
847 const_reverse_iterator
865 const_reverse_iterator
869 #if __cplusplus >= 201103L
876 {
return const_iterator(this->_M_data()); }
884 {
return const_iterator(this->_M_data() + this->
size()); }
891 const_reverse_iterator
900 const_reverse_iterator
911 {
return _M_rep()->_M_length; }
917 {
return _M_rep()->_M_length; }
922 {
return _Rep::_S_max_size; }
949 { this->
resize(__n, _CharT()); }
951 #if __cplusplus >= 201103L
952 #pragma GCC diagnostic push
953 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
958 #pragma GCC diagnostic pop
967 {
return _M_rep()->_M_capacity; }
990 #if __cplusplus > 201703L
991 [[deprecated(
"use shrink_to_fit() instead")]]
999 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
1003 if (_M_rep()->_M_is_shared())
1006 _M_data(_S_empty_rep()._M_refdata());
1009 _M_rep()->_M_set_length_and_sharable(0);
1015 { _M_mutate(0, this->
size(), 0); }
1022 _GLIBCXX_NODISCARD
bool
1024 {
return this->
size() == 0; }
1040 __glibcxx_assert(__pos <=
size());
1041 return _M_data()[__pos];
1059 __glibcxx_assert(__pos <=
size());
1061 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos <
size());
1063 return _M_data()[__pos];
1079 if (__n >= this->
size())
1080 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1081 "(which is %zu) >= this->size() "
1084 return _M_data()[__n];
1102 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1103 "(which is %zu) >= this->size() "
1107 return _M_data()[__n];
1110 #if __cplusplus >= 201103L
1118 __glibcxx_assert(!
empty());
1129 __glibcxx_assert(!
empty());
1140 __glibcxx_assert(!
empty());
1151 __glibcxx_assert(!
empty());
1164 {
return this->
append(__str); }
1173 {
return this->
append(__s); }
1187 #if __cplusplus >= 201103L
1195 {
return this->
append(__l.begin(), __l.size()); }
1198 #if __cplusplus >= 201703L
1204 template<
typename _Tp>
1205 _If_sv<_Tp, basic_string&>
1207 {
return this->
append(__svt); }
1251 __glibcxx_requires_string(__s);
1252 return this->
append(__s, traits_type::length(__s));
1266 #if __cplusplus >= 201103L
1274 {
return this->
append(__l.begin(), __l.size()); }
1285 template<
class _InputIterator>
1287 append(_InputIterator __first, _InputIterator __last)
1288 {
return this->
replace(_M_iend(), _M_iend(), __first, __last); }
1290 #if __cplusplus >= 201703L
1296 template<
typename _Tp>
1297 _If_sv<_Tp, basic_string&>
1301 return this->
append(__sv.data(), __sv.size());
1312 template<
typename _Tp>
1313 _If_sv<_Tp, basic_string&>
1317 return append(__sv.data()
1318 + std::__sv_check(__sv.size(), __pos,
"basic_string::append"),
1319 std::__sv_limit(__sv.size(), __pos, __n));
1330 const size_type __len = 1 + this->
size();
1331 if (__len > this->
capacity() || _M_rep()->_M_is_shared())
1333 traits_type::assign(_M_data()[this->
size()], __c);
1334 _M_rep()->_M_set_length_and_sharable(__len);
1345 #if __cplusplus >= 201103L
1378 {
return this->
assign(__str._M_data()
1379 + __str._M_check(__pos,
"basic_string::assign"),
1380 __str._M_limit(__pos, __n)); }
1407 __glibcxx_requires_string(__s);
1408 return this->
assign(__s, traits_type::length(__s));
1422 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
1432 template<
class _InputIterator>
1434 assign(_InputIterator __first, _InputIterator __last)
1435 {
return this->
replace(_M_ibegin(), _M_iend(), __first, __last); }
1437 #if __cplusplus >= 201103L
1445 {
return this->
assign(__l.begin(), __l.size()); }
1448 #if __cplusplus >= 201703L
1454 template<
typename _Tp>
1455 _If_sv<_Tp, basic_string&>
1459 return this->
assign(__sv.data(), __sv.size());
1469 template<
typename _Tp>
1470 _If_sv<_Tp, basic_string&>
1474 return assign(__sv.data()
1475 + std::__sv_check(__sv.size(), __pos,
"basic_string::assign"),
1476 std::__sv_limit(__sv.size(), __pos, __n));
1494 insert(iterator __p, size_type __n, _CharT __c)
1495 { this->
replace(__p, __p, __n, __c); }
1509 template<
class _InputIterator>
1511 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1512 { this->
replace(__p, __p, __beg, __end); }
1514 #if __cplusplus >= 201103L
1524 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1525 this->
insert(__p - _M_ibegin(), __l.begin(), __l.size());
1543 {
return this->
insert(__pos1, __str, size_type(0), __str.
size()); }
1565 size_type __pos2, size_type __n =
npos)
1566 {
return this->
insert(__pos1, __str._M_data()
1567 + __str._M_check(__pos2,
"basic_string::insert"),
1568 __str._M_limit(__pos2, __n)); }
1587 insert(size_type __pos,
const _CharT* __s, size_type __n);
1607 __glibcxx_requires_string(__s);
1608 return this->
insert(__pos, __s, traits_type::length(__s));
1628 insert(size_type __pos, size_type __n, _CharT __c)
1629 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
1630 size_type(0), __n, __c); }
1648 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1649 const size_type __pos = __p - _M_ibegin();
1650 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1651 _M_rep()->_M_set_leaked();
1652 return iterator(_M_data() + __pos);
1655 #if __cplusplus >= 201703L
1662 template<
typename _Tp>
1663 _If_sv<_Tp, basic_string&>
1667 return this->
insert(__pos, __sv.data(), __sv.size());
1678 template<
typename _Tp>
1679 _If_sv<_Tp, basic_string&>
1681 size_type __pos2, size_type __n =
npos)
1684 return this->
replace(__pos1, size_type(0), __sv.data()
1685 + std::__sv_check(__sv.size(), __pos2,
"basic_string::insert"),
1686 std::__sv_limit(__sv.size(), __pos2, __n));
1708 _M_mutate(_M_check(__pos,
"basic_string::erase"),
1709 _M_limit(__pos, __n), size_type(0));
1724 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1725 && __position < _M_iend());
1726 const size_type __pos = __position - _M_ibegin();
1727 _M_mutate(__pos, size_type(1), size_type(0));
1728 _M_rep()->_M_set_leaked();
1729 return iterator(_M_data() + __pos);
1742 erase(iterator __first, iterator __last);
1744 #if __cplusplus >= 201103L
1753 __glibcxx_assert(!
empty());
1777 {
return this->
replace(__pos, __n, __str._M_data(), __str.
size()); }
1799 size_type __pos2, size_type __n2 =
npos)
1800 {
return this->
replace(__pos1, __n1, __str._M_data()
1801 + __str._M_check(__pos2,
"basic_string::replace"),
1802 __str._M_limit(__pos2, __n2)); }
1823 replace(size_type __pos, size_type __n1,
const _CharT* __s,
1843 replace(size_type __pos, size_type __n1,
const _CharT* __s)
1845 __glibcxx_requires_string(__s);
1846 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
1867 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1868 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
1869 _M_limit(__pos, __n1), __n2, __c); }
1886 {
return this->
replace(__i1, __i2, __str._M_data(), __str.
size()); }
1904 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
1906 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1907 && __i2 <= _M_iend());
1908 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1925 replace(iterator __i1, iterator __i2,
const _CharT* __s)
1927 __glibcxx_requires_string(__s);
1928 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
1946 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1948 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1949 && __i2 <= _M_iend());
1950 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1968 template<
class _InputIterator>
1971 _InputIterator __k1, _InputIterator __k2)
1973 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1974 && __i2 <= _M_iend());
1975 __glibcxx_requires_valid_range(__k1, __k2);
1976 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1977 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1985 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1986 && __i2 <= _M_iend());
1987 __glibcxx_requires_valid_range(__k1, __k2);
1988 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
1993 replace(iterator __i1, iterator __i2,
1994 const _CharT* __k1,
const _CharT* __k2)
1996 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1997 && __i2 <= _M_iend());
1998 __glibcxx_requires_valid_range(__k1, __k2);
1999 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2004 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
2006 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2007 && __i2 <= _M_iend());
2008 __glibcxx_requires_valid_range(__k1, __k2);
2009 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2010 __k1.base(), __k2 - __k1);
2014 replace(iterator __i1, iterator __i2,
2015 const_iterator __k1, const_iterator __k2)
2017 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
2018 && __i2 <= _M_iend());
2019 __glibcxx_requires_valid_range(__k1, __k2);
2020 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
2021 __k1.base(), __k2 - __k1);
2024 #if __cplusplus >= 201103L
2041 {
return this->
replace(__i1, __i2, __l.begin(), __l.end()); }
2044 #if __cplusplus >= 201703L
2052 template<
typename _Tp>
2053 _If_sv<_Tp, basic_string&>
2054 replace(size_type __pos, size_type __n,
const _Tp& __svt)
2057 return this->
replace(__pos, __n, __sv.data(), __sv.size());
2069 template<
typename _Tp>
2070 _If_sv<_Tp, basic_string&>
2071 replace(size_type __pos1, size_type __n1,
const _Tp& __svt,
2072 size_type __pos2, size_type __n2 =
npos)
2075 return this->
replace(__pos1, __n1,
2077 + std::__sv_check(__sv.size(), __pos2,
"basic_string::replace"),
2078 std::__sv_limit(__sv.size(), __pos2, __n2));
2090 template<
typename _Tp>
2091 _If_sv<_Tp, basic_string&>
2092 replace(const_iterator __i1, const_iterator __i2,
const _Tp& __svt)
2095 return this->
replace(__i1 -
begin(), __i2 - __i1, __sv);
2100 template<
class _Integer>
2103 _Integer __val, __true_type)
2104 {
return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
2106 template<
class _InputIterator>
2108 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
2109 _InputIterator __k2, __false_type);
2112 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
2116 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
2121 template<
class _InIterator>
2123 _S_construct_aux(_InIterator __beg, _InIterator __end,
2124 const _Alloc& __a, __false_type)
2126 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
2127 return _S_construct(__beg, __end, __a, _Tag());
2132 template<
class _Integer>
2134 _S_construct_aux(_Integer __beg, _Integer __end,
2135 const _Alloc& __a, __true_type)
2136 {
return _S_construct_aux_2(
static_cast<size_type
>(__beg),
2140 _S_construct_aux_2(size_type __req, _CharT __c,
const _Alloc& __a)
2141 {
return _S_construct(__req, __c, __a); }
2143 template<
class _InIterator>
2145 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a)
2147 typedef typename std::__is_integer<_InIterator>::__type _Integral;
2148 return _S_construct_aux(__beg, __end, __a, _Integral());
2152 template<
class _InIterator>
2154 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
2155 input_iterator_tag);
2159 template<
class _FwdIterator>
2161 _S_construct(_FwdIterator __beg, _FwdIterator __end,
const _Alloc& __a,
2162 forward_iterator_tag);
2165 _S_construct(size_type __req, _CharT __c,
const _Alloc& __a);
2182 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
2204 {
return _M_data(); }
2216 {
return _M_data(); }
2218 #if __cplusplus >= 201703L
2238 {
return _M_dataplus; }
2253 find(
const _CharT* __s, size_type __pos, size_type __n)
const
2269 {
return this->
find(__str.
data(), __pos, __str.
size()); }
2282 find(
const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2284 __glibcxx_requires_string(__s);
2285 return this->
find(__s, __pos, traits_type::length(__s));
2299 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
2301 #if __cplusplus >= 201703L
2308 template<
typename _Tp>
2309 _If_sv<_Tp, size_type>
2310 find(
const _Tp& __svt, size_type __pos = 0) const
2314 return this->
find(__sv.data(), __pos, __sv.size());
2346 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
2360 rfind(
const _CharT* __s, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT
2362 __glibcxx_requires_string(__s);
2363 return this->
rfind(__s, __pos, traits_type::length(__s));
2377 rfind(_CharT __c, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT;
2379 #if __cplusplus >= 201703L
2386 template<
typename _Tp>
2387 _If_sv<_Tp, size_type>
2392 return this->
rfind(__sv.data(), __pos, __sv.size());
2425 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2442 __glibcxx_requires_string(__s);
2443 return this->
find_first_of(__s, __pos, traits_type::length(__s));
2460 {
return this->
find(__c, __pos); }
2462 #if __cplusplus >= 201703L
2470 template<
typename _Tp>
2471 _If_sv<_Tp, size_type>
2476 return this->
find_first_of(__sv.data(), __pos, __sv.size());
2509 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2526 __glibcxx_requires_string(__s);
2527 return this->
find_last_of(__s, __pos, traits_type::length(__s));
2544 {
return this->
rfind(__c, __pos); }
2546 #if __cplusplus >= 201703L
2554 template<
typename _Tp>
2555 _If_sv<_Tp, size_type>
2560 return this->
find_last_of(__sv.data(), __pos, __sv.size());
2593 size_type __n)
const _GLIBCXX_NOEXCEPT;
2609 __glibcxx_requires_string(__s);
2627 #if __cplusplus >= 201703L
2635 template<
typename _Tp>
2636 _If_sv<_Tp, size_type>
2675 size_type __n)
const _GLIBCXX_NOEXCEPT;
2691 __glibcxx_requires_string(__s);
2709 #if __cplusplus >= 201703L
2717 template<
typename _Tp>
2718 _If_sv<_Tp, size_type>
2742 _M_check(__pos,
"basic_string::substr"), __n); }
2761 const size_type __size = this->
size();
2762 const size_type __osize = __str.
size();
2763 const size_type __len =
std::min(__size, __osize);
2765 int __r = traits_type::compare(_M_data(), __str.
data(), __len);
2767 __r = _S_compare(__size, __osize);
2771 #if __cplusplus >= 201703L
2777 template<
typename _Tp>
2783 const size_type __size = this->
size();
2784 const size_type __osize = __sv.size();
2785 const size_type __len =
std::min(__size, __osize);
2787 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
2789 __r = _S_compare(__size, __osize);
2801 template<
typename _Tp>
2803 compare(size_type __pos, size_type __n,
const _Tp& __svt)
const
2807 return __sv_type(*this).substr(__pos, __n).compare(__sv);
2820 template<
typename _Tp>
2822 compare(size_type __pos1, size_type __n1,
const _Tp& __svt,
2823 size_type __pos2, size_type __n2 =
npos)
const
2828 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
2879 size_type __pos2, size_type __n2 =
npos)
const;
2896 compare(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT;
2920 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const;
2947 compare(size_type __pos, size_type __n1,
const _CharT* __s,
2948 size_type __n2)
const;
2950 #if __cplusplus > 201703L
2953 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
2956 starts_with(_CharT __x)
const noexcept
2957 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
2960 starts_with(
const _CharT* __x)
const noexcept
2961 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
2964 ends_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
2965 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
2968 ends_with(_CharT __x)
const noexcept
2969 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
2972 ends_with(
const _CharT* __x)
const noexcept
2973 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
2976 #if __cplusplus > 202011L
2978 contains(basic_string_view<_CharT, _Traits> __x)
const noexcept
2979 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
2982 contains(_CharT __x)
const noexcept
2983 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
2986 contains(
const _CharT* __x)
const noexcept
2987 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
2990 # ifdef _GLIBCXX_TM_TS_INTERNAL
2992 ::_txnal_cow_string_C1_for_exceptions(
void* that,
const char* s,
2995 ::_txnal_cow_string_c_str(
const void *that);
2997 ::_txnal_cow_string_D1(
void *that);
2999 ::_txnal_cow_string_D1_commit(
void *that);
3003 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3004 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
3005 basic_string<_CharT, _Traits, _Alloc>::
3006 _Rep::_S_max_size = (((npos -
sizeof(_Rep_base))/
sizeof(_CharT)) - 1) / 4;
3008 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3010 basic_string<_CharT, _Traits, _Alloc>::
3011 _Rep::_S_terminal = _CharT();
3013 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3014 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
3019 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3020 typename basic_string<_CharT, _Traits, _Alloc>::size_type
3021 basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_empty_rep_storage[
3022 (
sizeof(_Rep_base) +
sizeof(_CharT) +
sizeof(size_type) - 1) /
3029 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3030 template<
typename _InIterator>
3032 basic_string<_CharT, _Traits, _Alloc>::
3033 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
3036 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3037 if (__beg == __end && __a == _Alloc())
3038 return _S_empty_rep()._M_refdata();
3042 size_type __len = 0;
3043 while (__beg != __end && __len <
sizeof(__buf) /
sizeof(_CharT))
3045 __buf[__len++] = *__beg;
3048 _Rep* __r = _Rep::_S_create(__len, size_type(0), __a);
3049 _M_copy(__r->_M_refdata(), __buf, __len);
3052 while (__beg != __end)
3054 if (__len == __r->_M_capacity)
3057 _Rep* __another = _Rep::_S_create(__len + 1, __len, __a);
3058 _M_copy(__another->_M_refdata(), __r->_M_refdata(), __len);
3059 __r->_M_destroy(__a);
3062 __r->_M_refdata()[__len++] = *__beg;
3068 __r->_M_destroy(__a);
3069 __throw_exception_again;
3071 __r->_M_set_length_and_sharable(__len);
3072 return __r->_M_refdata();
3075 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3076 template <
typename _InIterator>
3078 basic_string<_CharT, _Traits, _Alloc>::
3079 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
3080 forward_iterator_tag)
3082 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3083 if (__beg == __end && __a == _Alloc())
3084 return _S_empty_rep()._M_refdata();
3087 if (__gnu_cxx::__is_null_pointer(__beg) && __beg != __end)
3088 __throw_logic_error(__N(
"basic_string::_S_construct null not valid"));
3090 const size_type __dnew =
static_cast<size_type
>(
std::distance(__beg,
3093 _Rep* __r = _Rep::_S_create(__dnew, size_type(0), __a);
3095 { _S_copy_chars(__r->_M_refdata(), __beg, __end); }
3098 __r->_M_destroy(__a);
3099 __throw_exception_again;
3101 __r->_M_set_length_and_sharable(__dnew);
3102 return __r->_M_refdata();
3105 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3107 basic_string<_CharT, _Traits, _Alloc>::
3108 _S_construct(size_type __n, _CharT __c,
const _Alloc& __a)
3110 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3111 if (__n == 0 && __a == _Alloc())
3112 return _S_empty_rep()._M_refdata();
3115 _Rep* __r = _Rep::_S_create(__n, size_type(0), __a);
3117 _M_assign(__r->_M_refdata(), __n, __c);
3119 __r->_M_set_length_and_sharable(__n);
3120 return __r->_M_refdata();
3123 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3126 : _M_dataplus(_S_construct(__str._M_data()
3127 + __str._M_check(__pos,
3128 "basic_string::basic_string"),
3129 __str._M_data() + __str._M_limit(__pos, npos)
3133 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3136 : _M_dataplus(_S_construct(__str._M_data()
3137 + __str._M_check(__pos,
3138 "basic_string::basic_string"),
3139 __str._M_data() + __str._M_limit(__pos, __n)
3140 + __pos, _Alloc()), _Alloc())
3143 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3146 size_type __n,
const _Alloc& __a)
3147 : _M_dataplus(_S_construct(__str._M_data()
3148 + __str._M_check(__pos,
3149 "basic_string::basic_string"),
3150 __str._M_data() + __str._M_limit(__pos, __n)
3154 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3159 if (_M_rep() != __str._M_rep())
3162 const allocator_type __a = this->get_allocator();
3163 _CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.
get_allocator());
3164 _M_rep()->_M_dispose(__a);
3170 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3173 assign(
const _CharT* __s, size_type __n)
3175 __glibcxx_requires_string_len(__s, __n);
3176 _M_check_length(this->
size(), __n,
"basic_string::assign");
3177 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3178 return _M_replace_safe(size_type(0), this->
size(), __s, __n);
3182 const size_type __pos = __s - _M_data();
3184 _M_copy(_M_data(), __s, __n);
3186 _M_move(_M_data(), __s, __n);
3187 _M_rep()->_M_set_length_and_sharable(__n);
3192 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3195 append(size_type __n, _CharT __c)
3199 _M_check_length(size_type(0), __n,
"basic_string::append");
3200 const size_type __len = __n + this->
size();
3201 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3202 this->reserve(__len);
3203 _M_assign(_M_data() + this->
size(), __n, __c);
3204 _M_rep()->_M_set_length_and_sharable(__len);
3209 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3212 append(
const _CharT* __s, size_type __n)
3214 __glibcxx_requires_string_len(__s, __n);
3217 _M_check_length(size_type(0), __n,
"basic_string::append");
3218 const size_type __len = __n + this->
size();
3219 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3221 if (_M_disjunct(__s))
3222 this->reserve(__len);
3225 const size_type __off = __s - _M_data();
3226 this->reserve(__len);
3227 __s = _M_data() + __off;
3230 _M_copy(_M_data() + this->
size(), __s, __n);
3231 _M_rep()->_M_set_length_and_sharable(__len);
3236 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3241 const size_type __size = __str.
size();
3244 const size_type __len = __size + this->
size();
3245 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3246 this->reserve(__len);
3247 _M_copy(_M_data() + this->
size(), __str._M_data(), __size);
3248 _M_rep()->_M_set_length_and_sharable(__len);
3253 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3258 __str._M_check(__pos,
"basic_string::append");
3259 __n = __str._M_limit(__pos, __n);
3262 const size_type __len = __n + this->
size();
3263 if (__len > this->capacity() || _M_rep()->_M_is_shared())
3264 this->reserve(__len);
3265 _M_copy(_M_data() + this->
size(), __str._M_data() + __pos, __n);
3266 _M_rep()->_M_set_length_and_sharable(__len);
3271 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3274 insert(size_type __pos,
const _CharT* __s, size_type __n)
3276 __glibcxx_requires_string_len(__s, __n);
3277 _M_check(__pos,
"basic_string::insert");
3278 _M_check_length(size_type(0), __n,
"basic_string::insert");
3279 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3280 return _M_replace_safe(__pos, size_type(0), __s, __n);
3284 const size_type __off = __s - _M_data();
3285 _M_mutate(__pos, 0, __n);
3286 __s = _M_data() + __off;
3287 _CharT* __p = _M_data() + __pos;
3288 if (__s + __n <= __p)
3289 _M_copy(__p, __s, __n);
3290 else if (__s >= __p)
3291 _M_copy(__p, __s + __n, __n);
3294 const size_type __nleft = __p - __s;
3295 _M_copy(__p, __s, __nleft);
3296 _M_copy(__p + __nleft, __p + __n, __n - __nleft);
3302 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3303 typename basic_string<_CharT, _Traits, _Alloc>::iterator
3305 erase(iterator __first, iterator __last)
3307 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
3308 && __last <= _M_iend());
3313 const size_type __size = __last - __first;
3316 const size_type __pos = __first - _M_ibegin();
3317 _M_mutate(__pos, __size, size_type(0));
3318 _M_rep()->_M_set_leaked();
3319 return iterator(_M_data() + __pos);
3325 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3328 replace(size_type __pos, size_type __n1,
const _CharT* __s,
3331 __glibcxx_requires_string_len(__s, __n2);
3332 _M_check(__pos,
"basic_string::replace");
3333 __n1 = _M_limit(__pos, __n1);
3334 _M_check_length(__n1, __n2,
"basic_string::replace");
3336 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
3337 return _M_replace_safe(__pos, __n1, __s, __n2);
3338 else if ((__left = __s + __n2 <= _M_data() + __pos)
3339 || _M_data() + __pos + __n1 <= __s)
3342 size_type __off = __s - _M_data();
3343 __left ? __off : (__off += __n2 - __n1);
3344 _M_mutate(__pos, __n1, __n2);
3345 _M_copy(_M_data() + __pos, _M_data() + __off, __n2);
3352 return _M_replace_safe(__pos, __n1, __tmp._M_data(), __n2);
3356 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3361 const size_type __size =
sizeof(_Rep_base)
3362 + (this->_M_capacity + 1) *
sizeof(_CharT);
3363 _Raw_bytes_alloc(__a).deallocate(
reinterpret_cast<char*
>(
this), __size);
3366 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3368 basic_string<_CharT, _Traits, _Alloc>::
3371 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3372 if (_M_rep() == &_S_empty_rep())
3375 if (_M_rep()->_M_is_shared())
3377 _M_rep()->_M_set_leaked();
3380 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3382 basic_string<_CharT, _Traits, _Alloc>::
3383 _M_mutate(size_type __pos, size_type __len1, size_type __len2)
3385 const size_type __old_size = this->
size();
3386 const size_type __new_size = __old_size + __len2 - __len1;
3387 const size_type __how_much = __old_size - __pos - __len1;
3389 if (__new_size > this->capacity() || _M_rep()->_M_is_shared())
3392 const allocator_type __a = get_allocator();
3393 _Rep* __r = _Rep::_S_create(__new_size, this->capacity(), __a);
3396 _M_copy(__r->_M_refdata(), _M_data(), __pos);
3398 _M_copy(__r->_M_refdata() + __pos + __len2,
3399 _M_data() + __pos + __len1, __how_much);
3401 _M_rep()->_M_dispose(__a);
3402 _M_data(__r->_M_refdata());
3404 else if (__how_much && __len1 != __len2)
3407 _M_move(_M_data() + __pos + __len2,
3408 _M_data() + __pos + __len1, __how_much);
3410 _M_rep()->_M_set_length_and_sharable(__new_size);
3413 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3418 const size_type __capacity = capacity();
3424 if (__res <= __capacity)
3426 if (!_M_rep()->_M_is_shared())
3433 const allocator_type __a = get_allocator();
3434 _CharT* __tmp = _M_rep()->_M_clone(__a, __res - this->
size());
3435 _M_rep()->_M_dispose(__a);
3439 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3445 if (_M_rep()->_M_is_leaked())
3446 _M_rep()->_M_set_sharable();
3447 if (__s._M_rep()->_M_is_leaked())
3448 __s._M_rep()->_M_set_sharable();
3449 if (this->get_allocator() == __s.get_allocator())
3451 _CharT* __tmp = _M_data();
3452 _M_data(__s._M_data());
3459 __s.get_allocator());
3460 const basic_string __tmp2(__s._M_ibegin(), __s._M_iend(),
3461 this->get_allocator());
3467 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3470 _S_create(size_type __capacity, size_type __old_capacity,
3471 const _Alloc& __alloc)
3475 if (__capacity > _S_max_size)
3476 __throw_length_error(__N(
"basic_string::_S_create"));
3501 const size_type __pagesize = 4096;
3502 const size_type __malloc_header_size = 4 *
sizeof(
void*);
3510 if (__capacity > __old_capacity && __capacity < 2 * __old_capacity)
3511 __capacity = 2 * __old_capacity;
3516 size_type __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
3518 const size_type __adj_size = __size + __malloc_header_size;
3519 if (__adj_size > __pagesize && __capacity > __old_capacity)
3521 const size_type __extra = __pagesize - __adj_size % __pagesize;
3522 __capacity += __extra /
sizeof(_CharT);
3524 if (__capacity > _S_max_size)
3525 __capacity = _S_max_size;
3526 __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
3531 void* __place = _Raw_bytes_alloc(__alloc).allocate(__size);
3532 _Rep *__p =
new (__place) _Rep;
3533 __p->_M_capacity = __capacity;
3541 __p->_M_set_sharable();
3545 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3547 basic_string<_CharT, _Traits, _Alloc>::_Rep::
3548 _M_clone(
const _Alloc& __alloc, size_type __res)
3551 const size_type __requested_cap = this->_M_length + __res;
3552 _Rep* __r = _Rep::_S_create(__requested_cap, this->_M_capacity,
3554 if (this->_M_length)
3555 _M_copy(__r->_M_refdata(), _M_refdata(), this->_M_length);
3557 __r->_M_set_length_and_sharable(this->_M_length);
3558 return __r->_M_refdata();
3561 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3564 resize(size_type __n, _CharT __c)
3566 const size_type __size = this->
size();
3567 _M_check_length(__size, __n,
"basic_string::resize");
3569 this->append(__n - __size, __c);
3570 else if (__n < __size)
3575 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3576 template<
typename _InputIterator>
3580 _InputIterator __k2, __false_type)
3583 const size_type __n1 = __i2 - __i1;
3584 _M_check_length(__n1, __s.size(),
"basic_string::_M_replace_dispatch");
3585 return _M_replace_safe(__i1 - _M_ibegin(), __n1, __s._M_data(),
3589 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3590 basic_string<_CharT, _Traits, _Alloc>&
3591 basic_string<_CharT, _Traits, _Alloc>::
3592 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
3595 _M_check_length(__n1, __n2,
"basic_string::_M_replace_aux");
3596 _M_mutate(__pos1, __n1, __n2);
3598 _M_assign(_M_data() + __pos1, __n2, __c);
3602 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3603 basic_string<_CharT, _Traits, _Alloc>&
3604 basic_string<_CharT, _Traits, _Alloc>::
3605 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
3608 _M_mutate(__pos1, __n1, __n2);
3610 _M_copy(_M_data() + __pos1, __s, __n2);
3614 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3619 #if __cpp_exceptions
3620 if (length() < capacity() || _M_rep()->_M_is_shared())
3623 const allocator_type __a = get_allocator();
3624 _CharT* __tmp = _M_rep()->_M_clone(__a);
3625 _M_rep()->_M_dispose(__a);
3635 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3636 typename basic_string<_CharT, _Traits, _Alloc>::size_type
3638 copy(_CharT* __s, size_type __n, size_type __pos)
const
3640 _M_check(__pos,
"basic_string::copy");
3641 __n = _M_limit(__pos, __n);
3642 __glibcxx_requires_string_len(__s, __n);
3644 _M_copy(__s, _M_data() + __pos, __n);
3648 _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 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.
basic_string & assign(size_type __n, _CharT __c)
Set value to multiple characters.
_If_sv< _Tp, basic_string & > append(const _Tp &__svt)
Append a string_view.
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
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(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
Replace characters with multiple characters.
basic_string & replace(iterator __i1, iterator __i2, const _CharT *__s)
Replace range of characters with 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.
size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
basic_string & append(_InputIterator __first, _InputIterator __last)
Append a range of characters.
basic_string & operator=(initializer_list< _CharT > __l)
Set value to string constructed from initializer list.
iterator erase(iterator __first, iterator __last)
Remove a range of characters.
_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(const _Alloc &__a)
Construct an empty string using allocator a.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
basic_string & assign(const _CharT *__s)
Set value to contents of a C 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 & > append(const _Tp &__svt, size_type __pos, size_type __n=npos)
Append a range of characters from a string_view.
void insert(iterator __p, initializer_list< _CharT > __l)
Insert an initializer_list of characters.
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.
_If_sv< _Tp, basic_string & > operator=(const _Tp &__svt)
Set value to string constructed from a string_view.
basic_string(const basic_string &__str)
Construct string with copy of value of str.
basic_string & replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
Replace range of characters with multiple characters.
int compare(const basic_string &__str) const
Compare to a string.
_If_sv< _Tp, basic_string & > replace(const_iterator __i1, const_iterator __i2, const _Tp &__svt)
Replace range of characters with string_view.
basic_string & operator=(const _CharT *__s)
Copy contents of s into this 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.
_If_sv< _Tp, basic_string & > insert(size_type __pos, const _Tp &__svt)
Insert a string_view.
basic_string & replace(size_type __pos, size_type __n1, const _CharT *__s)
Replace characters with value of a C 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 & operator+=(const basic_string &__str)
Append a string to this string.
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.
reverse_iterator rbegin()
basic_string & operator+=(initializer_list< _CharT > __l)
Append an initializer_list of characters.
_If_sv< _Tp, basic_string & > operator+=(const _Tp &__svt)
Append a string_view.
basic_string(initializer_list< _CharT > __l, const _Alloc &__a=_Alloc())
Construct string from an initializer list.
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another 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(size_type __pos, size_type __n1, const _CharT *__s, size_type __n2)
Replace characters with value of a C substring.
_If_sv< _Tp, basic_string & > replace(size_type __pos, size_type __n, const _Tp &__svt)
Replace range of characters with string_view.
basic_string & assign(_InputIterator __first, _InputIterator __last)
Set value to a range of characters.
void pop_back()
Remove the last character.
basic_string & insert(size_type __pos1, const basic_string &__str)
Insert value of a string.
_If_sv< _Tp, basic_string & > assign(const _Tp &__svt)
Set value from a string_view.
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 & replace(iterator __i1, iterator __i2, initializer_list< _CharT > __l)
Replace range of characters with initializer_list.
basic_string & insert(size_type __pos, const _CharT *__s, size_type __n)
Insert a C substring.
basic_string & insert(size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n=npos)
Insert a substring.
_If_sv< _Tp, int > compare(const _Tp &__svt) const noexcept(is_same< _Tp, __sv_type >::value)
Compare to 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 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 & assign(initializer_list< _CharT > __l)
Set value to an initializer_list of characters.
basic_string(size_type __n, _CharT __c, const _Alloc &__a=_Alloc())
Construct string as multiple 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.
void shrink_to_fit() noexcept
A non-binding request to reduce capacity() to size().
basic_string & replace(iterator __i1, iterator __i2, const _CharT *__s, size_type __n)
Replace range of characters with C substring.
basic_string & assign(basic_string &&__str) noexcept(allocator_traits< _Alloc >::is_always_equal::value)
Set value to contents of another string.
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
void reserve()
Equivalent to shrink_to_fit().
const _CharT * data() const noexcept
Return const pointer to contents.
basic_string & operator=(_CharT __c)
Set value to string of length 1.
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
_If_sv< _Tp, basic_string & > insert(size_type __pos1, const _Tp &__svt, size_type __pos2, size_type __n=npos)
Insert a string_view.
const_iterator end() const noexcept
basic_string & operator+=(_CharT __c)
Append a character.
size_type find_last_of(_CharT __c, size_type __pos=npos) const noexcept
Find last position of a character.
_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.
basic_string & append(const basic_string &__str)
Append a string to this string.
_CharT * data() noexcept
Return non-const pointer to contents.
const_iterator begin() const noexcept
_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_reverse_iterator crend() const noexcept
void resize(size_type __n)
Resizes the string to the specified number of characters.
const_reverse_iterator rbegin() const noexcept
_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, 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 & operator=(const basic_string &__str)
Assign the value of str to this string.
const_reference operator[](size_type __pos) const noexcept
Subscript access to the data contained in the string.
basic_string(const _CharT *__s, const _Alloc &__a=_Alloc())
Construct string as copy of a C string.
basic_string & operator=(basic_string &&__str) noexcept(/*conditional */)
Move assign the value of str to this string.
size_type find_first_of(_CharT __c, size_type __pos=0) const noexcept
Find position of a character.
basic_string & replace(iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2)
Replace range of characters with range.
bool empty() const noexcept
basic_string & append(initializer_list< _CharT > __l)
Append an initializer_list of characters.
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 & insert(size_type __pos, const _CharT *__s)
Insert a C string.
const_iterator cbegin() const noexcept
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
basic_string & replace(iterator __i1, iterator __i2, const basic_string &__str)
Replace range of characters with string.
~basic_string() noexcept
Destroy the string instance.
size_type capacity() const noexcept
basic_string & operator+=(const _CharT *__s)
Append a C string.
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.
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.
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 & append(const _CharT *__s, size_type __n)
Append a C substring.
_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.
basic_string(const _CharT *__s, size_type __n, const _Alloc &__a=_Alloc())
Construct string initialized by a character array.
basic_string & assign(const basic_string &__str, size_type __pos, size_type __n=npos)
Set value to a substring of a string.
basic_string & append(const _CharT *__s)
Append a C 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.
_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.
iterator insert(iterator __p, _CharT __c)
Insert one character.
Thrown as part of forced unwinding.
Uniform interface to C++98 and C++11 allocators.