34 #ifndef _BASIC_STRING_H
35 #define _BASIC_STRING_H 1
37 #pragma GCC system_header
43 #if __cplusplus >= 201103L
47 #if __cplusplus >= 201703L
48 # include <string_view>
52 namespace std _GLIBCXX_VISIBILITY(default)
54 _GLIBCXX_BEGIN_NAMESPACE_VERSION
56 #if _GLIBCXX_USE_CXX11_ABI
57 _GLIBCXX_BEGIN_NAMESPACE_CXX11
76 template<
typename _CharT,
typename _Traits,
typename _Alloc>
80 rebind<_CharT>::other _Char_alloc_type;
85 typedef _Traits traits_type;
86 typedef typename _Traits::char_type value_type;
87 typedef _Char_alloc_type allocator_type;
88 typedef typename _Alloc_traits::size_type size_type;
89 typedef typename _Alloc_traits::difference_type difference_type;
90 typedef typename _Alloc_traits::reference reference;
91 typedef typename _Alloc_traits::const_reference const_reference;
92 typedef typename _Alloc_traits::pointer pointer;
93 typedef typename _Alloc_traits::const_pointer const_pointer;
94 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
95 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
101 static const size_type
npos =
static_cast<size_type
>(-1);
105 #if __cplusplus < 201103L
106 typedef iterator __const_iterator;
108 typedef const_iterator __const_iterator;
112 #if __cplusplus >= 201703L
114 typedef basic_string_view<_CharT, _Traits> __sv_type;
116 template<
typename _Tp,
typename _Res>
118 __and_<is_convertible<const _Tp&, __sv_type>,
119 __not_<is_convertible<const _Tp*, const basic_string*>>,
120 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
125 _S_to_string_view(__sv_type __svt) noexcept
134 explicit __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
150 struct _Alloc_hider : allocator_type
152 #if __cplusplus < 201103L
153 _Alloc_hider(pointer __dat,
const _Alloc& __a = _Alloc())
154 : allocator_type(__a), _M_p(__dat) { }
156 _Alloc_hider(pointer __dat,
const _Alloc& __a)
157 : allocator_type(__a), _M_p(__dat) { }
159 _Alloc_hider(pointer __dat, _Alloc&& __a = _Alloc())
160 : allocator_type(
std::
move(__a)), _M_p(__dat) { }
166 _Alloc_hider _M_dataplus;
167 size_type _M_string_length;
169 enum { _S_local_capacity = 15 /
sizeof(_CharT) };
173 _CharT _M_local_buf[_S_local_capacity + 1];
174 size_type _M_allocated_capacity;
179 { _M_dataplus._M_p = __p; }
182 _M_length(size_type __length)
183 { _M_string_length = __length; }
187 {
return _M_dataplus._M_p; }
192 #if __cplusplus >= 201103L
195 return pointer(_M_local_buf);
200 _M_local_data()
const
202 #if __cplusplus >= 201103L
205 return const_pointer(_M_local_buf);
210 _M_capacity(size_type __capacity)
211 { _M_allocated_capacity = __capacity; }
214 _M_set_length(size_type __n)
217 traits_type::assign(_M_data()[__n], _CharT());
222 {
return _M_data() == _M_local_data(); }
226 _M_create(size_type&, size_type);
232 _M_destroy(_M_allocated_capacity);
236 _M_destroy(size_type __size)
throw()
237 { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); }
241 template<
typename _InIterator>
243 _M_construct_aux(_InIterator __beg, _InIterator __end,
246 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
247 _M_construct(__beg, __end, _Tag());
252 template<
typename _Integer>
254 _M_construct_aux(_Integer __beg, _Integer __end, std::__true_type)
255 { _M_construct_aux_2(
static_cast<size_type
>(__beg), __end); }
258 _M_construct_aux_2(size_type __req, _CharT __c)
259 { _M_construct(__req, __c); }
261 template<
typename _InIterator>
263 _M_construct(_InIterator __beg, _InIterator __end)
265 typedef typename std::__is_integer<_InIterator>::__type _Integral;
266 _M_construct_aux(__beg, __end, _Integral());
270 template<
typename _InIterator>
272 _M_construct(_InIterator __beg, _InIterator __end,
277 template<
typename _FwdIterator>
279 _M_construct(_FwdIterator __beg, _FwdIterator __end,
283 _M_construct(size_type __req, _CharT __c);
287 {
return _M_dataplus; }
289 const allocator_type&
290 _M_get_allocator()
const
291 {
return _M_dataplus; }
295 #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
298 template<
typename _Tp,
bool _Requires =
299 !__are_same<_Tp, _CharT*>::__value
300 && !__are_same<_Tp, const _CharT*>::__value
301 && !__are_same<_Tp, iterator>::__value
302 && !__are_same<_Tp, const_iterator>::__value>
303 struct __enable_if_not_native_iterator
305 template<
typename _Tp>
306 struct __enable_if_not_native_iterator<_Tp, false> { };
310 _M_check(size_type __pos,
const char* __s)
const
312 if (__pos > this->
size())
313 __throw_out_of_range_fmt(__N(
"%s: __pos (which is %zu) > "
314 "this->size() (which is %zu)"),
315 __s, __pos, this->
size());
320 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
323 __throw_length_error(__N(__s));
329 _M_limit(size_type __pos, size_type __off)
const _GLIBCXX_NOEXCEPT
331 const bool __testoff = __off < this->
size() - __pos;
332 return __testoff ? __off : this->
size() - __pos;
337 _M_disjunct(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
339 return (less<const _CharT*>()(__s, _M_data())
340 || less<const _CharT*>()(_M_data() + this->
size(), __s));
346 _S_copy(_CharT* __d,
const _CharT* __s, size_type __n)
349 traits_type::assign(*__d, *__s);
351 traits_type::copy(__d, __s, __n);
355 _S_move(_CharT* __d,
const _CharT* __s, size_type __n)
358 traits_type::assign(*__d, *__s);
364 _S_assign(_CharT* __d, size_type __n, _CharT __c)
367 traits_type::assign(*__d, __c);
369 traits_type::assign(__d, __n, __c);
374 template<
class _Iterator>
376 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
378 for (; __k1 != __k2; ++__k1, (void)++__p)
379 traits_type::assign(*__p, *__k1);
383 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
384 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
387 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
389 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
392 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
393 { _S_copy(__p, __k1, __k2 - __k1); }
396 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
398 { _S_copy(__p, __k1, __k2 - __k1); }
401 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
403 const difference_type __d = difference_type(__n1 - __n2);
405 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
406 return __gnu_cxx::__numeric_traits<int>::__max;
407 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
408 return __gnu_cxx::__numeric_traits<int>::__min;
417 _M_mutate(size_type __pos, size_type __len1,
const _CharT* __s,
421 _M_erase(size_type __pos, size_type __n);
432 _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value)
433 : _M_dataplus(_M_local_data())
434 { _M_set_length(0); }
441 : _M_dataplus(_M_local_data(), __a)
442 { _M_set_length(0); }
449 : _M_dataplus(_M_local_data(),
450 _Alloc_traits::_S_select_on_copy(__str._M_get_allocator()))
451 { _M_construct(__str._M_data(), __str._M_data() + __str.length()); }
462 const _Alloc& __a = _Alloc())
463 : _M_dataplus(_M_local_data(), __a)
465 const _CharT* __start = __str._M_data()
466 + __str._M_check(__pos,
"basic_string::basic_string");
467 _M_construct(__start, __start + __str._M_limit(__pos,
npos));
478 : _M_dataplus(_M_local_data())
480 const _CharT* __start = __str._M_data()
481 + __str._M_check(__pos,
"basic_string::basic_string");
482 _M_construct(__start, __start + __str._M_limit(__pos, __n));
493 size_type __n,
const _Alloc& __a)
494 : _M_dataplus(_M_local_data(), __a)
496 const _CharT* __start
497 = __str._M_data() + __str._M_check(__pos,
"string::string");
498 _M_construct(__start, __start + __str._M_limit(__pos, __n));
511 const _Alloc& __a = _Alloc())
512 : _M_dataplus(_M_local_data(), __a)
513 { _M_construct(__s, __s + __n); }
520 #if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
523 template<
typename = _RequireAllocator<_Alloc>>
525 basic_string(
const _CharT* __s,
const _Alloc& __a = _Alloc())
526 : _M_dataplus(_M_local_data(), __a)
527 { _M_construct(__s, __s ? __s + traits_type::length(__s) : __s+
npos); }
535 #if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
538 template<
typename = _RequireAllocator<_Alloc>>
540 basic_string(size_type __n, _CharT __c,
const _Alloc& __a = _Alloc())
541 : _M_dataplus(_M_local_data(), __a)
542 { _M_construct(__n, __c); }
544 #if __cplusplus >= 201103L
553 : _M_dataplus(_M_local_data(),
std::move(__str._M_get_allocator()))
555 if (__str._M_is_local())
557 traits_type::copy(_M_local_buf, __str._M_local_buf,
558 _S_local_capacity + 1);
562 _M_data(__str._M_data());
563 _M_capacity(__str._M_allocated_capacity);
569 _M_length(__str.length());
570 __str._M_data(__str._M_local_data());
571 __str._M_set_length(0);
579 basic_string(initializer_list<_CharT> __l,
const _Alloc& __a = _Alloc())
580 : _M_dataplus(_M_local_data(), __a)
581 { _M_construct(__l.begin(), __l.end()); }
584 : _M_dataplus(_M_local_data(), __a)
585 { _M_construct(__str.begin(), __str.end()); }
588 noexcept(_Alloc_traits::_S_always_equal())
589 : _M_dataplus(_M_local_data(), __a)
591 if (__str._M_is_local())
593 traits_type::copy(_M_local_buf, __str._M_local_buf,
594 _S_local_capacity + 1);
595 _M_length(__str.length());
596 __str._M_set_length(0);
598 else if (_Alloc_traits::_S_always_equal()
599 || __str.get_allocator() == __a)
601 _M_data(__str._M_data());
602 _M_length(__str.length());
603 _M_capacity(__str._M_allocated_capacity);
604 __str._M_data(__str._M_local_buf);
605 __str._M_set_length(0);
608 _M_construct(__str.begin(), __str.end());
619 #if __cplusplus >= 201103L
620 template<
typename _InputIterator,
621 typename = std::_RequireInputIter<_InputIterator>>
623 template<
typename _InputIterator>
625 basic_string(_InputIterator __beg, _InputIterator __end,
626 const _Alloc& __a = _Alloc())
627 : _M_dataplus(_M_local_data(), __a)
628 { _M_construct(__beg, __end); }
630 #if __cplusplus >= 201703L
638 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
639 basic_string(
const _Tp& __t, size_type __pos, size_type __n,
640 const _Alloc& __a = _Alloc())
648 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
650 basic_string(
const _Tp& __t,
const _Alloc& __a = _Alloc())
651 :
basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
667 return this->
assign(__str);
676 {
return this->
assign(__s); }
692 #if __cplusplus >= 201103L
704 noexcept(_Alloc_traits::_S_nothrow_move())
706 if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign()
707 && !_Alloc_traits::_S_always_equal()
708 && _M_get_allocator() != __str._M_get_allocator())
711 _M_destroy(_M_allocated_capacity);
712 _M_data(_M_local_data());
716 std::__alloc_on_move(_M_get_allocator(), __str._M_get_allocator());
718 if (__str._M_is_local())
722 this->_S_copy(_M_data(), __str._M_data(), __str.size());
723 _M_set_length(__str.size());
725 else if (_Alloc_traits::_S_propagate_on_move_assign()
726 || _Alloc_traits::_S_always_equal()
727 || _M_get_allocator() == __str._M_get_allocator())
730 pointer __data =
nullptr;
731 size_type __capacity;
734 if (_Alloc_traits::_S_always_equal())
738 __capacity = _M_allocated_capacity;
741 _M_destroy(_M_allocated_capacity);
744 _M_data(__str._M_data());
745 _M_length(__str.length());
746 _M_capacity(__str._M_allocated_capacity);
749 __str._M_data(__data);
750 __str._M_capacity(__capacity);
753 __str._M_data(__str._M_local_buf);
768 this->
assign(__l.begin(), __l.size());
773 #if __cplusplus >= 201703L
778 template<
typename _Tp>
779 _If_sv<_Tp, basic_string&>
781 {
return this->
assign(__svt); }
787 operator __sv_type() const noexcept
788 {
return __sv_type(
data(),
size()); }
797 begin() _GLIBCXX_NOEXCEPT
798 {
return iterator(_M_data()); }
805 begin() const _GLIBCXX_NOEXCEPT
806 {
return const_iterator(_M_data()); }
813 end() _GLIBCXX_NOEXCEPT
814 {
return iterator(_M_data() + this->
size()); }
821 end() const _GLIBCXX_NOEXCEPT
822 {
return const_iterator(_M_data() + this->
size()); }
830 rbegin() _GLIBCXX_NOEXCEPT
831 {
return reverse_iterator(this->
end()); }
838 const_reverse_iterator
839 rbegin() const _GLIBCXX_NOEXCEPT
840 {
return const_reverse_iterator(this->
end()); }
848 rend() _GLIBCXX_NOEXCEPT
849 {
return reverse_iterator(this->
begin()); }
856 const_reverse_iterator
857 rend() const _GLIBCXX_NOEXCEPT
858 {
return const_reverse_iterator(this->
begin()); }
860 #if __cplusplus >= 201103L
867 {
return const_iterator(this->_M_data()); }
874 cend() const noexcept
875 {
return const_iterator(this->_M_data() + this->
size()); }
882 const_reverse_iterator
884 {
return const_reverse_iterator(this->
end()); }
891 const_reverse_iterator
892 crend() const noexcept
893 {
return const_reverse_iterator(this->
begin()); }
901 size() const _GLIBCXX_NOEXCEPT
902 {
return _M_string_length; }
907 length() const _GLIBCXX_NOEXCEPT
908 {
return _M_string_length; }
913 {
return (_Alloc_traits::max_size(_M_get_allocator()) - 1) / 2; }
926 resize(size_type __n, _CharT __c);
940 { this->
resize(__n, _CharT()); }
942 #if __cplusplus >= 201103L
966 return _M_is_local() ? size_type(_S_local_capacity)
967 : _M_allocated_capacity;
988 reserve(size_type __res_arg = 0);
994 clear() _GLIBCXX_NOEXCEPT
995 { _M_set_length(0); }
1001 _GLIBCXX_NODISCARD
bool
1002 empty() const _GLIBCXX_NOEXCEPT
1003 {
return this->
size() == 0; }
1017 operator[] (size_type __pos)
const _GLIBCXX_NOEXCEPT
1019 __glibcxx_assert(__pos <=
size());
1020 return _M_data()[__pos];
1038 __glibcxx_assert(__pos <=
size());
1040 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos <
size());
1041 return _M_data()[__pos];
1055 at(size_type __n)
const
1057 if (__n >= this->
size())
1058 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1059 "(which is %zu) >= this->size() "
1062 return _M_data()[__n];
1079 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1080 "(which is %zu) >= this->size() "
1083 return _M_data()[__n];
1086 #if __cplusplus >= 201103L
1094 __glibcxx_assert(!
empty());
1103 front() const noexcept
1105 __glibcxx_assert(!
empty());
1116 __glibcxx_assert(!
empty());
1125 back() const noexcept
1127 __glibcxx_assert(!
empty());
1140 {
return this->
append(__str); }
1149 {
return this->
append(__s); }
1163 #if __cplusplus >= 201103L
1171 {
return this->
append(__l.begin(), __l.size()); }
1174 #if __cplusplus >= 201703L
1180 template<
typename _Tp>
1181 _If_sv<_Tp, basic_string&>
1183 {
return this->
append(__svt); }
1193 {
return _M_append(__str._M_data(), __str.size()); }
1210 {
return _M_append(__str._M_data()
1211 + __str._M_check(__pos,
"basic_string::append"),
1212 __str._M_limit(__pos, __n)); }
1221 append(
const _CharT* __s, size_type __n)
1223 __glibcxx_requires_string_len(__s, __n);
1224 _M_check_length(size_type(0), __n,
"basic_string::append");
1225 return _M_append(__s, __n);
1234 append(
const _CharT* __s)
1236 __glibcxx_requires_string(__s);
1237 const size_type __n = traits_type::length(__s);
1238 _M_check_length(size_type(0), __n,
"basic_string::append");
1239 return _M_append(__s, __n);
1251 append(size_type __n, _CharT __c)
1252 {
return _M_replace_aux(this->
size(), size_type(0), __n, __c); }
1254 #if __cplusplus >= 201103L
1261 append(initializer_list<_CharT> __l)
1262 {
return this->
append(__l.begin(), __l.size()); }
1273 #if __cplusplus >= 201103L
1274 template<
class _InputIterator,
1275 typename = std::_RequireInputIter<_InputIterator>>
1277 template<
class _InputIterator>
1280 append(_InputIterator __first, _InputIterator __last)
1283 #if __cplusplus >= 201703L
1289 template<
typename _Tp>
1290 _If_sv<_Tp, basic_string&>
1293 __sv_type __sv = __svt;
1294 return this->
append(__sv.data(), __sv.size());
1304 template<
typename _Tp>
1305 _If_sv<_Tp, basic_string&>
1306 append(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
1308 __sv_type __sv = __svt;
1309 return _M_append(__sv.data()
1310 + std::__sv_check(__sv.size(), __pos,
"basic_string::append"),
1311 std::__sv_limit(__sv.size(), __pos, __n));
1322 const size_type __size = this->
size();
1324 this->_M_mutate(__size, size_type(0), 0, size_type(1));
1325 traits_type::assign(this->_M_data()[__size], __c);
1326 this->_M_set_length(__size + 1);
1337 #if __cplusplus >= 201103L
1338 if (_Alloc_traits::_S_propagate_on_copy_assign())
1340 if (!_Alloc_traits::_S_always_equal() && !_M_is_local()
1341 && _M_get_allocator() != __str._M_get_allocator())
1345 if (__str.size() <= _S_local_capacity)
1347 _M_destroy(_M_allocated_capacity);
1348 _M_data(_M_local_data());
1353 const auto __len = __str.size();
1354 auto __alloc = __str._M_get_allocator();
1356 auto __ptr = _Alloc_traits::allocate(__alloc, __len + 1);
1357 _M_destroy(_M_allocated_capacity);
1360 _M_set_length(__len);
1363 std::__alloc_on_copy(_M_get_allocator(), __str._M_get_allocator());
1366 this->_M_assign(__str);
1370 #if __cplusplus >= 201103L
1381 noexcept(_Alloc_traits::_S_nothrow_move())
1404 {
return _M_replace(size_type(0), this->
size(), __str._M_data()
1405 + __str._M_check(__pos,
"basic_string::assign"),
1406 __str._M_limit(__pos, __n)); }
1419 assign(
const _CharT* __s, size_type __n)
1421 __glibcxx_requires_string_len(__s, __n);
1422 return _M_replace(size_type(0), this->
size(), __s, __n);
1435 assign(
const _CharT* __s)
1437 __glibcxx_requires_string(__s);
1438 return _M_replace(size_type(0), this->
size(), __s,
1439 traits_type::length(__s));
1452 assign(size_type __n, _CharT __c)
1453 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
1463 #if __cplusplus >= 201103L
1464 template<
class _InputIterator,
1465 typename = std::_RequireInputIter<_InputIterator>>
1467 template<
class _InputIterator>
1470 assign(_InputIterator __first, _InputIterator __last)
1473 #if __cplusplus >= 201103L
1480 assign(initializer_list<_CharT> __l)
1481 {
return this->
assign(__l.begin(), __l.size()); }
1484 #if __cplusplus >= 201703L
1490 template<
typename _Tp>
1491 _If_sv<_Tp, basic_string&>
1494 __sv_type __sv = __svt;
1495 return this->
assign(__sv.data(), __sv.size());
1505 template<
typename _Tp>
1506 _If_sv<_Tp, basic_string&>
1507 assign(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
1509 __sv_type __sv = __svt;
1510 return _M_replace(size_type(0), this->
size(),
1512 + std::__sv_check(__sv.size(), __pos,
"basic_string::assign"),
1513 std::__sv_limit(__sv.size(), __pos, __n));
1517 #if __cplusplus >= 201103L
1534 insert(const_iterator __p, size_type __n, _CharT __c)
1536 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1537 const size_type __pos = __p -
begin();
1538 this->
replace(__p, __p, __n, __c);
1539 return iterator(this->_M_data() + __pos);
1556 insert(iterator __p, size_type __n, _CharT __c)
1557 { this->
replace(__p, __p, __n, __c); }
1560 #if __cplusplus >= 201103L
1575 template<
class _InputIterator,
1576 typename = std::_RequireInputIter<_InputIterator>>
1578 insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
1580 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1581 const size_type __pos = __p -
begin();
1582 this->
replace(__p, __p, __beg, __end);
1583 return iterator(this->_M_data() + __pos);
1598 template<
class _InputIterator>
1600 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1601 { this->
replace(__p, __p, __beg, __end); }
1604 #if __cplusplus >= 201103L
1612 insert(const_iterator __p, initializer_list<_CharT> __l)
1613 {
return this->
insert(__p, __l.begin(), __l.end()); }
1615 #ifdef _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
1618 insert(iterator __p, initializer_list<_CharT> __l)
1620 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1621 this->
insert(__p -
begin(), __l.begin(), __l.size());
1640 {
return this->
replace(__pos1, size_type(0),
1641 __str._M_data(), __str.size()); }
1663 size_type __pos2, size_type __n =
npos)
1664 {
return this->
replace(__pos1, size_type(0), __str._M_data()
1665 + __str._M_check(__pos2,
"basic_string::insert"),
1666 __str._M_limit(__pos2, __n)); }
1685 insert(size_type __pos,
const _CharT* __s, size_type __n)
1686 {
return this->
replace(__pos, size_type(0), __s, __n); }
1704 insert(size_type __pos,
const _CharT* __s)
1706 __glibcxx_requires_string(__s);
1707 return this->
replace(__pos, size_type(0), __s,
1708 traits_type::length(__s));
1728 insert(size_type __pos, size_type __n, _CharT __c)
1729 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
1730 size_type(0), __n, __c); }
1746 insert(__const_iterator __p, _CharT __c)
1748 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1749 const size_type __pos = __p -
begin();
1750 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1751 return iterator(_M_data() + __pos);
1754 #if __cplusplus >= 201703L
1761 template<
typename _Tp>
1762 _If_sv<_Tp, basic_string&>
1763 insert(size_type __pos,
const _Tp& __svt)
1765 __sv_type __sv = __svt;
1766 return this->
insert(__pos, __sv.data(), __sv.size());
1777 template<
typename _Tp>
1778 _If_sv<_Tp, basic_string&>
1779 insert(size_type __pos1,
const _Tp& __svt,
1780 size_type __pos2, size_type __n =
npos)
1782 __sv_type __sv = __svt;
1783 return this->
replace(__pos1, size_type(0),
1785 + std::__sv_check(__sv.size(), __pos2,
"basic_string::insert"),
1786 std::__sv_limit(__sv.size(), __pos2, __n));
1806 erase(size_type __pos = 0, size_type __n =
npos)
1808 _M_check(__pos,
"basic_string::erase");
1810 this->_M_set_length(__pos);
1812 this->_M_erase(__pos, _M_limit(__pos, __n));
1825 erase(__const_iterator __position)
1827 _GLIBCXX_DEBUG_PEDASSERT(__position >=
begin()
1828 && __position <
end());
1829 const size_type __pos = __position -
begin();
1830 this->_M_erase(__pos, size_type(1));
1831 return iterator(_M_data() + __pos);
1844 erase(__const_iterator __first, __const_iterator __last)
1846 _GLIBCXX_DEBUG_PEDASSERT(__first >=
begin() && __first <= __last
1847 && __last <=
end());
1848 const size_type __pos = __first -
begin();
1849 if (__last ==
end())
1850 this->_M_set_length(__pos);
1852 this->_M_erase(__pos, __last - __first);
1853 return iterator(this->_M_data() + __pos);
1856 #if __cplusplus >= 201103L
1865 __glibcxx_assert(!
empty());
1866 _M_erase(
size() - 1, 1);
1889 {
return this->
replace(__pos, __n, __str._M_data(), __str.size()); }
1911 size_type __pos2, size_type __n2 =
npos)
1912 {
return this->
replace(__pos1, __n1, __str._M_data()
1913 + __str._M_check(__pos2,
"basic_string::replace"),
1914 __str._M_limit(__pos2, __n2)); }
1935 replace(size_type __pos, size_type __n1,
const _CharT* __s,
1938 __glibcxx_requires_string_len(__s, __n2);
1939 return _M_replace(_M_check(__pos,
"basic_string::replace"),
1940 _M_limit(__pos, __n1), __s, __n2);
1960 replace(size_type __pos, size_type __n1,
const _CharT* __s)
1962 __glibcxx_requires_string(__s);
1963 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
1984 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1985 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
1986 _M_limit(__pos, __n1), __n2, __c); }
2002 replace(__const_iterator __i1, __const_iterator __i2,
2004 {
return this->
replace(__i1, __i2, __str._M_data(), __str.size()); }
2022 replace(__const_iterator __i1, __const_iterator __i2,
2023 const _CharT* __s, size_type __n)
2025 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2027 return this->
replace(__i1 -
begin(), __i2 - __i1, __s, __n);
2044 replace(__const_iterator __i1, __const_iterator __i2,
const _CharT* __s)
2046 __glibcxx_requires_string(__s);
2047 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
2065 replace(__const_iterator __i1, __const_iterator __i2, size_type __n,
2068 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2070 return _M_replace_aux(__i1 -
begin(), __i2 - __i1, __n, __c);
2088 #if __cplusplus >= 201103L
2089 template<
class _InputIterator,
2090 typename = std::_RequireInputIter<_InputIterator>>
2092 replace(const_iterator __i1, const_iterator __i2,
2093 _InputIterator __k1, _InputIterator __k2)
2095 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2097 __glibcxx_requires_valid_range(__k1, __k2);
2098 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
2099 std::__false_type());
2102 template<
class _InputIterator>
2103 #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
2104 typename __enable_if_not_native_iterator<_InputIterator>::__type
2108 replace(iterator __i1, iterator __i2,
2109 _InputIterator __k1, _InputIterator __k2)
2111 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2113 __glibcxx_requires_valid_range(__k1, __k2);
2114 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
2115 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
2122 replace(__const_iterator __i1, __const_iterator __i2,
2123 _CharT* __k1, _CharT* __k2)
2125 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2127 __glibcxx_requires_valid_range(__k1, __k2);
2133 replace(__const_iterator __i1, __const_iterator __i2,
2134 const _CharT* __k1,
const _CharT* __k2)
2136 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2138 __glibcxx_requires_valid_range(__k1, __k2);
2144 replace(__const_iterator __i1, __const_iterator __i2,
2145 iterator __k1, iterator __k2)
2147 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2149 __glibcxx_requires_valid_range(__k1, __k2);
2151 __k1.base(), __k2 - __k1);
2155 replace(__const_iterator __i1, __const_iterator __i2,
2156 const_iterator __k1, const_iterator __k2)
2158 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2160 __glibcxx_requires_valid_range(__k1, __k2);
2162 __k1.base(), __k2 - __k1);
2165 #if __cplusplus >= 201103L
2181 initializer_list<_CharT> __l)
2182 {
return this->
replace(__i1, __i2, __l.begin(), __l.size()); }
2185 #if __cplusplus >= 201703L
2193 template<
typename _Tp>
2194 _If_sv<_Tp, basic_string&>
2195 replace(size_type __pos, size_type __n,
const _Tp& __svt)
2197 __sv_type __sv = __svt;
2198 return this->
replace(__pos, __n, __sv.data(), __sv.size());
2210 template<
typename _Tp>
2211 _If_sv<_Tp, basic_string&>
2212 replace(size_type __pos1, size_type __n1,
const _Tp& __svt,
2213 size_type __pos2, size_type __n2 =
npos)
2215 __sv_type __sv = __svt;
2216 return this->
replace(__pos1, __n1,
2218 + std::__sv_check(__sv.size(), __pos2,
"basic_string::replace"),
2219 std::__sv_limit(__sv.size(), __pos2, __n2));
2231 template<
typename _Tp>
2232 _If_sv<_Tp, basic_string&>
2233 replace(const_iterator __i1, const_iterator __i2,
const _Tp& __svt)
2235 __sv_type __sv = __svt;
2236 return this->
replace(__i1 -
begin(), __i2 - __i1, __sv);
2241 template<
class _Integer>
2243 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2244 _Integer __n, _Integer __val, __true_type)
2245 {
return _M_replace_aux(__i1 -
begin(), __i2 - __i1, __n, __val); }
2247 template<
class _InputIterator>
2249 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2250 _InputIterator __k1, _InputIterator __k2,
2254 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
2258 _M_replace(size_type __pos, size_type __len1,
const _CharT* __s,
2259 const size_type __len2);
2262 _M_append(
const _CharT* __s, size_type __n);
2279 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
2299 c_str() const _GLIBCXX_NOEXCEPT
2300 {
return _M_data(); }
2311 data() const _GLIBCXX_NOEXCEPT
2312 {
return _M_data(); }
2314 #if __cplusplus >= 201703L
2323 {
return _M_data(); }
2331 {
return _M_get_allocator(); }
2346 find(
const _CharT* __s, size_type __pos, size_type __n)
const
2362 {
return this->
find(__str.data(), __pos, __str.size()); }
2364 #if __cplusplus >= 201703L
2371 template<
typename _Tp>
2372 _If_sv<_Tp, size_type>
2373 find(
const _Tp& __svt, size_type __pos = 0) const
2374 noexcept(is_same<_Tp, __sv_type>::value)
2376 __sv_type __sv = __svt;
2377 return this->
find(__sv.data(), __pos, __sv.size());
2392 find(
const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2394 __glibcxx_requires_string(__s);
2395 return this->
find(__s, __pos, traits_type::length(__s));
2409 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
2424 {
return this->
rfind(__str.data(), __pos, __str.size()); }
2426 #if __cplusplus >= 201703L
2433 template<
typename _Tp>
2434 _If_sv<_Tp, size_type>
2435 rfind(
const _Tp& __svt, size_type __pos =
npos)
const
2436 noexcept(is_same<_Tp, __sv_type>::value)
2438 __sv_type __sv = __svt;
2439 return this->
rfind(__sv.data(), __pos, __sv.size());
2456 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
2470 rfind(
const _CharT* __s, size_type __pos =
npos)
const
2472 __glibcxx_requires_string(__s);
2473 return this->
rfind(__s, __pos, traits_type::length(__s));
2487 rfind(_CharT __c, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT;
2503 {
return this->
find_first_of(__str.data(), __pos, __str.size()); }
2505 #if __cplusplus >= 201703L
2513 template<
typename _Tp>
2514 _If_sv<_Tp, size_type>
2516 noexcept(is_same<_Tp, __sv_type>::value)
2518 __sv_type __sv = __svt;
2519 return this->
find_first_of(__sv.data(), __pos, __sv.size());
2536 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2553 __glibcxx_requires_string(__s);
2554 return this->
find_first_of(__s, __pos, traits_type::length(__s));
2570 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2571 {
return this->
find(__c, __pos); }
2587 {
return this->
find_last_of(__str.data(), __pos, __str.size()); }
2589 #if __cplusplus >= 201703L
2597 template<
typename _Tp>
2598 _If_sv<_Tp, size_type>
2600 noexcept(is_same<_Tp, __sv_type>::value)
2602 __sv_type __sv = __svt;
2603 return this->
find_last_of(__sv.data(), __pos, __sv.size());
2620 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2637 __glibcxx_requires_string(__s);
2638 return this->
find_last_of(__s, __pos, traits_type::length(__s));
2655 {
return this->
rfind(__c, __pos); }
2672 #if __cplusplus >= 201703L
2680 template<
typename _Tp>
2681 _If_sv<_Tp, size_type>
2683 noexcept(is_same<_Tp, __sv_type>::value)
2685 __sv_type __sv = __svt;
2704 size_type __n)
const _GLIBCXX_NOEXCEPT;
2720 __glibcxx_requires_string(__s);
2754 #if __cplusplus >= 201703L
2762 template<
typename _Tp>
2763 _If_sv<_Tp, size_type>
2765 noexcept(is_same<_Tp, __sv_type>::value)
2767 __sv_type __sv = __svt;
2786 size_type __n)
const _GLIBCXX_NOEXCEPT;
2802 __glibcxx_requires_string(__s);
2833 substr(size_type __pos = 0, size_type __n =
npos)
const
2835 _M_check(__pos,
"basic_string::substr"), __n); }
2854 const size_type __size = this->
size();
2855 const size_type __osize = __str.size();
2856 const size_type __len =
std::min(__size, __osize);
2858 int __r = traits_type::compare(_M_data(), __str.data(), __len);
2860 __r = _S_compare(__size, __osize);
2864 #if __cplusplus >= 201703L
2870 template<
typename _Tp>
2872 compare(
const _Tp& __svt)
const
2873 noexcept(is_same<_Tp, __sv_type>::value)
2875 __sv_type __sv = __svt;
2876 const size_type __size = this->
size();
2877 const size_type __osize = __sv.size();
2878 const size_type __len =
std::min(__size, __osize);
2880 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
2882 __r = _S_compare(__size, __osize);
2894 template<
typename _Tp>
2896 compare(size_type __pos, size_type __n,
const _Tp& __svt)
const
2897 noexcept(is_same<_Tp, __sv_type>::value)
2899 __sv_type __sv = __svt;
2900 return __sv_type(*this).substr(__pos, __n).compare(__sv);
2913 template<
typename _Tp>
2915 compare(size_type __pos1, size_type __n1,
const _Tp& __svt,
2916 size_type __pos2, size_type __n2 =
npos)
const
2917 noexcept(is_same<_Tp, __sv_type>::value)
2919 __sv_type __sv = __svt;
2920 return __sv_type(*
this)
2921 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
2972 size_type __pos2, size_type __n2 =
npos)
const;
2989 compare(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT;
3013 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const;
3040 compare(size_type __pos, size_type __n1,
const _CharT* __s,
3041 size_type __n2)
const;
3043 #if __cplusplus > 201703L
3045 starts_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
3046 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3049 starts_with(_CharT __x)
const noexcept
3050 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3053 starts_with(
const _CharT* __x)
const noexcept
3054 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3057 ends_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
3058 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3061 ends_with(_CharT __x)
const noexcept
3062 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3065 ends_with(
const _CharT* __x)
const noexcept
3066 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3070 template<
typename,
typename,
typename>
friend class basic_stringbuf;
3072 _GLIBCXX_END_NAMESPACE_CXX11
3073 #else // !_GLIBCXX_USE_CXX11_ABI
3138 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3142 rebind<_CharT>::other _CharT_alloc_type;
3147 typedef _Traits traits_type;
3148 typedef typename _Traits::char_type value_type;
3149 typedef _Alloc allocator_type;
3150 typedef typename _CharT_alloc_type::size_type size_type;
3151 typedef typename _CharT_alloc_type::difference_type difference_type;
3152 #if __cplusplus < 201103L
3153 typedef typename _CharT_alloc_type::reference reference;
3154 typedef typename _CharT_alloc_type::const_reference const_reference;
3156 typedef value_type& reference;
3157 typedef const value_type& const_reference;
3159 typedef typename _CharT_alloc_traits::pointer pointer;
3160 typedef typename _CharT_alloc_traits::const_pointer const_pointer;
3161 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
3162 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
3169 typedef iterator __const_iterator;
3188 size_type _M_length;
3189 size_type _M_capacity;
3190 _Atomic_word _M_refcount;
3193 struct _Rep : _Rep_base
3197 rebind<char>::other _Raw_bytes_alloc;
3212 static const size_type _S_max_size;
3213 static const _CharT _S_terminal;
3217 static size_type _S_empty_rep_storage[];
3220 _S_empty_rep() _GLIBCXX_NOEXCEPT
3225 void* __p =
reinterpret_cast<void*
>(&_S_empty_rep_storage);
3226 return *
reinterpret_cast<_Rep*
>(__p);
3230 _M_is_leaked()
const _GLIBCXX_NOEXCEPT
3232 #if defined(__GTHREADS)
3237 return __atomic_load_n(&this->_M_refcount, __ATOMIC_RELAXED) < 0;
3239 return this->_M_refcount < 0;
3244 _M_is_shared()
const _GLIBCXX_NOEXCEPT
3246 #if defined(__GTHREADS)
3252 return __atomic_load_n(&this->_M_refcount, __ATOMIC_ACQUIRE) > 0;
3254 return this->_M_refcount > 0;
3259 _M_set_leaked() _GLIBCXX_NOEXCEPT
3260 { this->_M_refcount = -1; }
3263 _M_set_sharable() _GLIBCXX_NOEXCEPT
3264 { this->_M_refcount = 0; }
3267 _M_set_length_and_sharable(size_type __n) _GLIBCXX_NOEXCEPT
3269 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3270 if (__builtin_expect(
this != &_S_empty_rep(),
false))
3273 this->_M_set_sharable();
3274 this->_M_length = __n;
3275 traits_type::assign(this->_M_refdata()[__n], _S_terminal);
3282 _M_refdata()
throw()
3283 {
return reinterpret_cast<_CharT*
>(
this + 1); }
3286 _M_grab(
const _Alloc& __alloc1,
const _Alloc& __alloc2)
3288 return (!_M_is_leaked() && __alloc1 == __alloc2)
3289 ? _M_refcopy() : _M_clone(__alloc1);
3294 _S_create(size_type, size_type,
const _Alloc&);
3297 _M_dispose(
const _Alloc& __a) _GLIBCXX_NOEXCEPT
3299 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3300 if (__builtin_expect(
this != &_S_empty_rep(),
false))
3304 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount);
3313 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
3316 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount);
3323 _M_destroy(
const _Alloc&)
throw();
3326 _M_refcopy()
throw()
3328 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3329 if (__builtin_expect(
this != &_S_empty_rep(),
false))
3331 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
3332 return _M_refdata();
3336 _M_clone(
const _Alloc&, size_type __res = 0);
3340 struct _Alloc_hider : _Alloc
3342 _Alloc_hider(_CharT* __dat,
const _Alloc& __a) _GLIBCXX_NOEXCEPT
3343 : _Alloc(__a), _M_p(__dat) { }
3353 static const size_type
npos =
static_cast<size_type
>(-1);
3357 mutable _Alloc_hider _M_dataplus;
3360 _M_data() const _GLIBCXX_NOEXCEPT
3361 {
return _M_dataplus._M_p; }
3364 _M_data(_CharT* __p) _GLIBCXX_NOEXCEPT
3365 {
return (_M_dataplus._M_p = __p); }
3368 _M_rep() const _GLIBCXX_NOEXCEPT
3369 {
return &((
reinterpret_cast<_Rep*
> (_M_data()))[-1]); }
3374 _M_ibegin() const _GLIBCXX_NOEXCEPT
3375 {
return iterator(_M_data()); }
3378 _M_iend() const _GLIBCXX_NOEXCEPT
3379 {
return iterator(_M_data() + this->
size()); }
3384 if (!_M_rep()->_M_is_leaked())
3389 _M_check(size_type __pos,
const char* __s)
const
3391 if (__pos > this->
size())
3392 __throw_out_of_range_fmt(__N(
"%s: __pos (which is %zu) > "
3393 "this->size() (which is %zu)"),
3394 __s, __pos, this->
size());
3399 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
3402 __throw_length_error(__N(__s));
3407 _M_limit(size_type __pos, size_type __off)
const _GLIBCXX_NOEXCEPT
3409 const bool __testoff = __off < this->
size() - __pos;
3410 return __testoff ? __off : this->
size() - __pos;
3415 _M_disjunct(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
3417 return (less<const _CharT*>()(__s, _M_data())
3418 || less<const _CharT*>()(_M_data() + this->
size(), __s));
3424 _M_copy(_CharT* __d,
const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
3427 traits_type::assign(*__d, *__s);
3429 traits_type::copy(__d, __s, __n);
3433 _M_move(_CharT* __d,
const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
3436 traits_type::assign(*__d, *__s);
3442 _M_assign(_CharT* __d, size_type __n, _CharT __c) _GLIBCXX_NOEXCEPT
3445 traits_type::assign(*__d, __c);
3447 traits_type::assign(__d, __n, __c);
3452 template<
class _Iterator>
3454 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
3456 for (; __k1 != __k2; ++__k1, (void)++__p)
3457 traits_type::assign(*__p, *__k1);
3461 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
3462 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
3465 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
3467 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
3470 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
3471 { _M_copy(__p, __k1, __k2 - __k1); }
3474 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
3476 { _M_copy(__p, __k1, __k2 - __k1); }
3479 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
3481 const difference_type __d = difference_type(__n1 - __n2);
3483 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
3484 return __gnu_cxx::__numeric_traits<int>::__max;
3485 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
3486 return __gnu_cxx::__numeric_traits<int>::__min;
3492 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
3498 _S_empty_rep() _GLIBCXX_NOEXCEPT
3499 {
return _Rep::_S_empty_rep(); }
3501 #if __cplusplus >= 201703L
3503 typedef basic_string_view<_CharT, _Traits> __sv_type;
3505 template<
typename _Tp,
typename _Res>
3507 __and_<is_convertible<const _Tp&, __sv_type>,
3508 __not_<is_convertible<const _Tp*, const basic_string*>>,
3509 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
3514 _S_to_string_view(__sv_type __svt) noexcept
3523 explicit __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
3547 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3549 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc())
3551 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc())
3577 const _Alloc& __a = _Alloc());
3595 size_type __n,
const _Alloc& __a);
3607 const _Alloc& __a = _Alloc());
3613 basic_string(
const _CharT* __s,
const _Alloc& __a = _Alloc());
3620 basic_string(size_type __n, _CharT __c,
const _Alloc& __a = _Alloc());
3622 #if __cplusplus >= 201103L
3631 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3634 : _M_dataplus(
std::move(__str._M_dataplus))
3636 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3637 __str._M_data(_S_empty_rep()._M_refdata());
3639 __str._M_data(_S_construct(size_type(), _CharT(),
get_allocator()));
3651 : _M_dataplus(__str._M_rep()->_M_grab(__a, __str.
get_allocator()), __a)
3655 : _M_dataplus(__str._M_data(), __a)
3657 if (__a == __str.get_allocator())
3659 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3660 __str._M_data(_S_empty_rep()._M_refdata());
3662 __str._M_data(_S_construct(size_type(), _CharT(), __a));
3666 _M_dataplus._M_p = _S_construct(__str.begin(), __str.end(), __a);
3676 template<
class _InputIterator>
3677 basic_string(_InputIterator __beg, _InputIterator __end,
3678 const _Alloc& __a = _Alloc());
3680 #if __cplusplus >= 201703L
3688 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
3689 basic_string(
const _Tp& __t, size_type __pos, size_type __n,
3690 const _Alloc& __a = _Alloc())
3698 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
3700 basic_string(
const _Tp& __t,
const _Alloc& __a = _Alloc())
3701 :
basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
3716 {
return this->
assign(__str); }
3724 {
return this->
assign(__s); }
3740 #if __cplusplus >= 201103L
3764 this->
assign(__l.begin(), __l.size());
3769 #if __cplusplus >= 201703L
3774 template<
typename _Tp>
3775 _If_sv<_Tp, basic_string&>
3777 {
return this->
assign(__svt); }
3783 operator __sv_type() const noexcept
3784 {
return __sv_type(
data(),
size()); }
3796 return iterator(_M_data());
3805 {
return const_iterator(_M_data()); }
3815 return iterator(_M_data() + this->
size());
3824 {
return const_iterator(_M_data() + this->
size()); }
3840 const_reverse_iterator
3858 const_reverse_iterator
3862 #if __cplusplus >= 201103L
3869 {
return const_iterator(this->_M_data()); }
3877 {
return const_iterator(this->_M_data() + this->
size()); }
3884 const_reverse_iterator
3893 const_reverse_iterator
3904 {
return _M_rep()->_M_length; }
3910 {
return _M_rep()->_M_length; }
3915 {
return _Rep::_S_max_size; }
3928 resize(size_type __n, _CharT __c);
3942 { this->
resize(__n, _CharT()); }
3944 #if __cplusplus >= 201103L
3949 #if __cpp_exceptions
3967 {
return _M_rep()->_M_capacity; }
3987 reserve(size_type __res_arg = 0);
3992 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3996 if (_M_rep()->_M_is_shared())
3999 _M_data(_S_empty_rep()._M_refdata());
4002 _M_rep()->_M_set_length_and_sharable(0);
4008 { _M_mutate(0, this->
size(), 0); }
4015 _GLIBCXX_NODISCARD
bool
4017 {
return this->
size() == 0; }
4033 __glibcxx_assert(__pos <=
size());
4034 return _M_data()[__pos];
4052 __glibcxx_assert(__pos <=
size());
4054 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos <
size());
4056 return _M_data()[__pos];
4072 if (__n >= this->
size())
4073 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
4074 "(which is %zu) >= this->size() "
4077 return _M_data()[__n];
4095 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
4096 "(which is %zu) >= this->size() "
4100 return _M_data()[__n];
4103 #if __cplusplus >= 201103L
4111 __glibcxx_assert(!
empty());
4122 __glibcxx_assert(!
empty());
4133 __glibcxx_assert(!
empty());
4144 __glibcxx_assert(!
empty());
4157 {
return this->
append(__str); }
4166 {
return this->
append(__s); }
4180 #if __cplusplus >= 201103L
4188 {
return this->
append(__l.begin(), __l.size()); }
4191 #if __cplusplus >= 201703L
4197 template<
typename _Tp>
4198 _If_sv<_Tp, basic_string&>
4200 {
return this->
append(__svt); }
4234 append(
const _CharT* __s, size_type __n);
4244 __glibcxx_requires_string(__s);
4245 return this->
append(__s, traits_type::length(__s));
4257 append(size_type __n, _CharT __c);
4259 #if __cplusplus >= 201103L
4267 {
return this->
append(__l.begin(), __l.size()); }
4278 template<
class _InputIterator>
4280 append(_InputIterator __first, _InputIterator __last)
4281 {
return this->
replace(_M_iend(), _M_iend(), __first, __last); }
4283 #if __cplusplus >= 201703L
4289 template<
typename _Tp>
4290 _If_sv<_Tp, basic_string&>
4293 __sv_type __sv = __svt;
4294 return this->
append(__sv.data(), __sv.size());
4305 template<
typename _Tp>
4306 _If_sv<_Tp, basic_string&>
4307 append(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
4309 __sv_type __sv = __svt;
4310 return append(__sv.data()
4311 + std::__sv_check(__sv.size(), __pos,
"basic_string::append"),
4312 std::__sv_limit(__sv.size(), __pos, __n));
4323 const size_type __len = 1 + this->
size();
4324 if (__len > this->
capacity() || _M_rep()->_M_is_shared())
4326 traits_type::assign(_M_data()[this->
size()], __c);
4327 _M_rep()->_M_set_length_and_sharable(__len);
4338 #if __cplusplus >= 201103L
4371 {
return this->
assign(__str._M_data()
4372 + __str._M_check(__pos,
"basic_string::assign"),
4373 __str._M_limit(__pos, __n)); }
4386 assign(
const _CharT* __s, size_type __n);
4400 __glibcxx_requires_string(__s);
4401 return this->
assign(__s, traits_type::length(__s));
4415 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
4425 template<
class _InputIterator>
4427 assign(_InputIterator __first, _InputIterator __last)
4428 {
return this->
replace(_M_ibegin(), _M_iend(), __first, __last); }
4430 #if __cplusplus >= 201103L
4438 {
return this->
assign(__l.begin(), __l.size()); }
4441 #if __cplusplus >= 201703L
4447 template<
typename _Tp>
4448 _If_sv<_Tp, basic_string&>
4451 __sv_type __sv = __svt;
4452 return this->
assign(__sv.data(), __sv.size());
4462 template<
typename _Tp>
4463 _If_sv<_Tp, basic_string&>
4464 assign(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
4466 __sv_type __sv = __svt;
4467 return assign(__sv.data()
4468 + std::__sv_check(__sv.size(), __pos,
"basic_string::assign"),
4469 std::__sv_limit(__sv.size(), __pos, __n));
4487 insert(iterator __p, size_type __n, _CharT __c)
4488 { this->
replace(__p, __p, __n, __c); }
4502 template<
class _InputIterator>
4504 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
4505 { this->
replace(__p, __p, __beg, __end); }
4507 #if __cplusplus >= 201103L
4517 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
4518 this->
insert(__p - _M_ibegin(), __l.begin(), __l.size());
4536 {
return this->
insert(__pos1, __str, size_type(0), __str.size()); }
4558 size_type __pos2, size_type __n =
npos)
4559 {
return this->
insert(__pos1, __str._M_data()
4560 + __str._M_check(__pos2,
"basic_string::insert"),
4561 __str._M_limit(__pos2, __n)); }
4580 insert(size_type __pos,
const _CharT* __s, size_type __n);
4600 __glibcxx_requires_string(__s);
4601 return this->
insert(__pos, __s, traits_type::length(__s));
4621 insert(size_type __pos, size_type __n, _CharT __c)
4622 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
4623 size_type(0), __n, __c); }
4641 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
4642 const size_type __pos = __p - _M_ibegin();
4643 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
4644 _M_rep()->_M_set_leaked();
4645 return iterator(_M_data() + __pos);
4648 #if __cplusplus >= 201703L
4655 template<
typename _Tp>
4656 _If_sv<_Tp, basic_string&>
4657 insert(size_type __pos,
const _Tp& __svt)
4659 __sv_type __sv = __svt;
4660 return this->
insert(__pos, __sv.data(), __sv.size());
4672 template<
typename _Tp>
4673 _If_sv<_Tp, basic_string&>
4674 insert(size_type __pos1,
const _Tp& __svt,
4675 size_type __pos2, size_type __n =
npos)
4677 __sv_type __sv = __svt;
4678 return this->
replace(__pos1, size_type(0), __sv.data()
4679 + std::__sv_check(__sv.size(), __pos2,
"basic_string::insert"),
4680 std::__sv_limit(__sv.size(), __pos2, __n));
4702 _M_mutate(_M_check(__pos,
"basic_string::erase"),
4703 _M_limit(__pos, __n), size_type(0));
4718 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
4719 && __position < _M_iend());
4720 const size_type __pos = __position - _M_ibegin();
4721 _M_mutate(__pos, size_type(1), size_type(0));
4722 _M_rep()->_M_set_leaked();
4723 return iterator(_M_data() + __pos);
4738 #if __cplusplus >= 201103L
4747 __glibcxx_assert(!
empty());
4771 {
return this->
replace(__pos, __n, __str._M_data(), __str.size()); }
4793 size_type __pos2, size_type __n2 =
npos)
4794 {
return this->
replace(__pos1, __n1, __str._M_data()
4795 + __str._M_check(__pos2,
"basic_string::replace"),
4796 __str._M_limit(__pos2, __n2)); }
4817 replace(size_type __pos, size_type __n1,
const _CharT* __s,
4837 replace(size_type __pos, size_type __n1,
const _CharT* __s)
4839 __glibcxx_requires_string(__s);
4840 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
4861 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
4862 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
4863 _M_limit(__pos, __n1), __n2, __c); }
4880 {
return this->
replace(__i1, __i2, __str._M_data(), __str.size()); }
4898 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
4900 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4901 && __i2 <= _M_iend());
4902 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
4919 replace(iterator __i1, iterator __i2,
const _CharT* __s)
4921 __glibcxx_requires_string(__s);
4922 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
4940 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
4942 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4943 && __i2 <= _M_iend());
4944 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
4962 template<
class _InputIterator>
4965 _InputIterator __k1, _InputIterator __k2)
4967 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4968 && __i2 <= _M_iend());
4969 __glibcxx_requires_valid_range(__k1, __k2);
4970 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
4971 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
4979 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4980 && __i2 <= _M_iend());
4981 __glibcxx_requires_valid_range(__k1, __k2);
4982 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
4987 replace(iterator __i1, iterator __i2,
4988 const _CharT* __k1,
const _CharT* __k2)
4990 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4991 && __i2 <= _M_iend());
4992 __glibcxx_requires_valid_range(__k1, __k2);
4993 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
4998 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
5000 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
5001 && __i2 <= _M_iend());
5002 __glibcxx_requires_valid_range(__k1, __k2);
5003 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
5004 __k1.base(), __k2 - __k1);
5008 replace(iterator __i1, iterator __i2,
5009 const_iterator __k1, const_iterator __k2)
5011 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
5012 && __i2 <= _M_iend());
5013 __glibcxx_requires_valid_range(__k1, __k2);
5014 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
5015 __k1.base(), __k2 - __k1);
5018 #if __cplusplus >= 201103L
5035 {
return this->
replace(__i1, __i2, __l.begin(), __l.end()); }
5038 #if __cplusplus >= 201703L
5046 template<
typename _Tp>
5047 _If_sv<_Tp, basic_string&>
5048 replace(size_type __pos, size_type __n,
const _Tp& __svt)
5050 __sv_type __sv = __svt;
5051 return this->
replace(__pos, __n, __sv.data(), __sv.size());
5063 template<
typename _Tp>
5064 _If_sv<_Tp, basic_string&>
5065 replace(size_type __pos1, size_type __n1,
const _Tp& __svt,
5066 size_type __pos2, size_type __n2 =
npos)
5068 __sv_type __sv = __svt;
5069 return this->
replace(__pos1, __n1,
5071 + std::__sv_check(__sv.size(), __pos2,
"basic_string::replace"),
5072 std::__sv_limit(__sv.size(), __pos2, __n2));
5084 template<
typename _Tp>
5085 _If_sv<_Tp, basic_string&>
5086 replace(const_iterator __i1, const_iterator __i2,
const _Tp& __svt)
5088 __sv_type __sv = __svt;
5089 return this->
replace(__i1 -
begin(), __i2 - __i1, __sv);
5094 template<
class _Integer>
5096 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
5097 _Integer __val, __true_type)
5098 {
return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
5100 template<
class _InputIterator>
5102 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
5103 _InputIterator __k2, __false_type);
5106 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
5110 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
5115 template<
class _InIterator>
5117 _S_construct_aux(_InIterator __beg, _InIterator __end,
5118 const _Alloc& __a, __false_type)
5120 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
5121 return _S_construct(__beg, __end, __a, _Tag());
5126 template<
class _Integer>
5128 _S_construct_aux(_Integer __beg, _Integer __end,
5129 const _Alloc& __a, __true_type)
5130 {
return _S_construct_aux_2(
static_cast<size_type
>(__beg),
5134 _S_construct_aux_2(size_type __req, _CharT __c,
const _Alloc& __a)
5135 {
return _S_construct(__req, __c, __a); }
5137 template<
class _InIterator>
5139 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a)
5141 typedef typename std::__is_integer<_InIterator>::__type _Integral;
5142 return _S_construct_aux(__beg, __end, __a, _Integral());
5146 template<
class _InIterator>
5148 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
5149 input_iterator_tag);
5153 template<
class _FwdIterator>
5155 _S_construct(_FwdIterator __beg, _FwdIterator __end,
const _Alloc& __a,
5156 forward_iterator_tag);
5159 _S_construct(size_type __req, _CharT __c,
const _Alloc& __a);
5176 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
5187 _GLIBCXX_NOEXCEPT_IF(allocator_traits<_Alloc>::is_always_equal::value);
5198 {
return _M_data(); }
5210 {
return _M_data(); }
5212 #if __cplusplus >= 201703L
5232 {
return _M_dataplus; }
5247 find(
const _CharT* __s, size_type __pos, size_type __n)
const
5263 {
return this->
find(__str.data(), __pos, __str.size()); }
5276 find(
const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
5278 __glibcxx_requires_string(__s);
5279 return this->
find(__s, __pos, traits_type::length(__s));
5293 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
5295 #if __cplusplus >= 201703L
5302 template<
typename _Tp>
5303 _If_sv<_Tp, size_type>
5304 find(
const _Tp& __svt, size_type __pos = 0) const
5305 noexcept(
is_same<_Tp, __sv_type>::value)
5307 __sv_type __sv = __svt;
5308 return this->
find(__sv.data(), __pos, __sv.size());
5325 {
return this->
rfind(__str.data(), __pos, __str.size()); }
5340 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
5354 rfind(
const _CharT* __s, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT
5356 __glibcxx_requires_string(__s);
5357 return this->
rfind(__s, __pos, traits_type::length(__s));
5371 rfind(_CharT __c, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT;
5373 #if __cplusplus >= 201703L
5380 template<
typename _Tp>
5381 _If_sv<_Tp, size_type>
5382 rfind(
const _Tp& __svt, size_type __pos =
npos)
const
5385 __sv_type __sv = __svt;
5386 return this->
rfind(__sv.data(), __pos, __sv.size());
5404 {
return this->
find_first_of(__str.data(), __pos, __str.size()); }
5419 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
5436 __glibcxx_requires_string(__s);
5437 return this->
find_first_of(__s, __pos, traits_type::length(__s));
5454 {
return this->
find(__c, __pos); }
5456 #if __cplusplus >= 201703L
5464 template<
typename _Tp>
5465 _If_sv<_Tp, size_type>
5467 noexcept(
is_same<_Tp, __sv_type>::value)
5469 __sv_type __sv = __svt;
5470 return this->
find_first_of(__sv.data(), __pos, __sv.size());
5488 {
return this->
find_last_of(__str.data(), __pos, __str.size()); }
5503 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
5520 __glibcxx_requires_string(__s);
5521 return this->
find_last_of(__s, __pos, traits_type::length(__s));
5538 {
return this->
rfind(__c, __pos); }
5540 #if __cplusplus >= 201703L
5548 template<
typename _Tp>
5549 _If_sv<_Tp, size_type>
5553 __sv_type __sv = __svt;
5554 return this->
find_last_of(__sv.data(), __pos, __sv.size());
5587 size_type __n)
const _GLIBCXX_NOEXCEPT;
5603 __glibcxx_requires_string(__s);
5621 #if __cplusplus >= 201703L
5629 template<
typename _Tp>
5630 _If_sv<_Tp, size_type>
5632 noexcept(
is_same<_Tp, __sv_type>::value)
5634 __sv_type __sv = __svt;
5669 size_type __n)
const _GLIBCXX_NOEXCEPT;
5685 __glibcxx_requires_string(__s);
5703 #if __cplusplus >= 201703L
5711 template<
typename _Tp>
5712 _If_sv<_Tp, size_type>
5716 __sv_type __sv = __svt;
5736 _M_check(__pos,
"basic_string::substr"), __n); }
5755 const size_type __size = this->
size();
5756 const size_type __osize = __str.size();
5757 const size_type __len =
std::min(__size, __osize);
5759 int __r = traits_type::compare(_M_data(), __str.data(), __len);
5761 __r = _S_compare(__size, __osize);
5765 #if __cplusplus >= 201703L
5771 template<
typename _Tp>
5773 compare(
const _Tp& __svt)
const
5776 __sv_type __sv = __svt;
5777 const size_type __size = this->
size();
5778 const size_type __osize = __sv.size();
5779 const size_type __len =
std::min(__size, __osize);
5781 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
5783 __r = _S_compare(__size, __osize);
5795 template<
typename _Tp>
5797 compare(size_type __pos, size_type __n,
const _Tp& __svt)
const
5798 noexcept(is_same<_Tp, __sv_type>::value)
5800 __sv_type __sv = __svt;
5801 return __sv_type(*this).substr(__pos, __n).compare(__sv);
5814 template<
typename _Tp>
5816 compare(size_type __pos1, size_type __n1,
const _Tp& __svt,
5817 size_type __pos2, size_type __n2 =
npos)
const
5818 noexcept(is_same<_Tp, __sv_type>::value)
5820 __sv_type __sv = __svt;
5821 return __sv_type(*
this)
5822 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
5873 size_type __pos2, size_type __n2 =
npos)
const;
5890 compare(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT;
5914 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const;
5941 compare(size_type __pos, size_type __n1,
const _CharT* __s,
5942 size_type __n2)
const;
5944 #if __cplusplus > 201703L
5946 starts_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
5947 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
5950 starts_with(_CharT __x)
const noexcept
5951 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
5954 starts_with(
const _CharT* __x)
const noexcept
5955 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
5958 ends_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
5959 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
5962 ends_with(_CharT __x)
const noexcept
5963 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
5966 ends_with(
const _CharT* __x)
const noexcept
5967 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
5970 # ifdef _GLIBCXX_TM_TS_INTERNAL
5972 ::_txnal_cow_string_C1_for_exceptions(
void* that,
const char* s,
5975 ::_txnal_cow_string_c_str(
const void *that);
5977 ::_txnal_cow_string_D1(
void *that);
5979 ::_txnal_cow_string_D1_commit(
void *that);
5982 #endif // !_GLIBCXX_USE_CXX11_ABI
5984 #if __cpp_deduction_guides >= 201606
5985 _GLIBCXX_BEGIN_NAMESPACE_CXX11
5986 template<
typename _InputIterator,
typename _CharT
5987 =
typename iterator_traits<_InputIterator>::value_type,
5988 typename _Allocator = allocator<_CharT>,
5989 typename = _RequireInputIter<_InputIterator>,
5990 typename = _RequireAllocator<_Allocator>>
5991 basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
5992 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
5996 template<
typename _CharT,
typename _Traits,
5997 typename _Allocator = allocator<_CharT>,
5998 typename = _RequireAllocator<_Allocator>>
5999 basic_string(basic_string_view<_CharT, _Traits>,
const _Allocator& = _Allocator())
6000 -> basic_string<_CharT, _Traits, _Allocator>;
6002 template<
typename _CharT,
typename _Traits,
6003 typename _Allocator = allocator<_CharT>,
6004 typename = _RequireAllocator<_Allocator>>
6005 basic_string(basic_string_view<_CharT, _Traits>,
6006 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
6007 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
6008 const _Allocator& = _Allocator())
6009 -> basic_string<_CharT, _Traits, _Allocator>;
6010 _GLIBCXX_END_NAMESPACE_CXX11
6020 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6021 basic_string<_CharT, _Traits, _Alloc>
6026 __str.append(__rhs);
6036 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6037 basic_string<_CharT,_Traits,_Alloc>
6039 const basic_string<_CharT,_Traits,_Alloc>& __rhs);
6047 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6048 basic_string<_CharT,_Traits,_Alloc>
6049 operator+(_CharT __lhs,
const basic_string<_CharT,_Traits,_Alloc>& __rhs);
6057 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6058 inline basic_string<_CharT, _Traits, _Alloc>
6060 const _CharT* __rhs)
6063 __str.append(__rhs);
6073 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6074 inline basic_string<_CharT, _Traits, _Alloc>
6078 typedef typename __string_type::size_type __size_type;
6079 __string_type __str(__lhs);
6080 __str.append(__size_type(1), __rhs);
6084 #if __cplusplus >= 201103L
6085 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6086 inline basic_string<_CharT, _Traits, _Alloc>
6087 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
6088 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6089 {
return std::move(__lhs.append(__rhs)); }
6091 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6092 inline basic_string<_CharT, _Traits, _Alloc>
6093 operator+(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6094 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
6095 {
return std::move(__rhs.insert(0, __lhs)); }
6097 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6098 inline basic_string<_CharT, _Traits, _Alloc>
6099 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
6100 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
6102 #if _GLIBCXX_USE_CXX11_ABI
6103 using _Alloc_traits = allocator_traits<_Alloc>;
6104 bool __use_rhs =
false;
6105 if _GLIBCXX17_CONSTEXPR (
typename _Alloc_traits::is_always_equal{})
6107 else if (__lhs.get_allocator() == __rhs.get_allocator())
6112 const auto __size = __lhs.size() + __rhs.size();
6113 if (__size > __lhs.capacity() && __size <= __rhs.capacity())
6114 return std::move(__rhs.insert(0, __lhs));
6119 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6120 inline basic_string<_CharT, _Traits, _Alloc>
6122 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
6123 {
return std::move(__rhs.insert(0, __lhs)); }
6125 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6126 inline basic_string<_CharT, _Traits, _Alloc>
6128 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
6129 {
return std::move(__rhs.insert(0, 1, __lhs)); }
6131 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6132 inline basic_string<_CharT, _Traits, _Alloc>
6133 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
6134 const _CharT* __rhs)
6135 {
return std::move(__lhs.append(__rhs)); }
6137 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6138 inline basic_string<_CharT, _Traits, _Alloc>
6139 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
6141 {
return std::move(__lhs.append(1, __rhs)); }
6151 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6156 {
return __lhs.compare(__rhs) == 0; }
6158 template<
typename _CharT>
6160 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
bool>::__type
6161 operator==(
const basic_string<_CharT>& __lhs,
6162 const basic_string<_CharT>& __rhs) _GLIBCXX_NOEXCEPT
6163 {
return (__lhs.size() == __rhs.size()
6173 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6175 operator==(
const _CharT* __lhs,
6177 {
return __rhs.compare(__lhs) == 0; }
6185 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6188 const _CharT* __rhs)
6189 {
return __lhs.compare(__rhs) == 0; }
6198 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6203 {
return !(__lhs == __rhs); }
6211 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6213 operator!=(
const _CharT* __lhs,
6215 {
return !(__lhs == __rhs); }
6223 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6226 const _CharT* __rhs)
6227 {
return !(__lhs == __rhs); }
6236 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6241 {
return __lhs.compare(__rhs) < 0; }
6249 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6252 const _CharT* __rhs)
6253 {
return __lhs.compare(__rhs) < 0; }
6261 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6263 operator<(
const _CharT* __lhs,
6265 {
return __rhs.compare(__lhs) > 0; }
6274 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6279 {
return __lhs.compare(__rhs) > 0; }
6287 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6290 const _CharT* __rhs)
6291 {
return __lhs.compare(__rhs) > 0; }
6299 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6301 operator>(
const _CharT* __lhs,
6303 {
return __rhs.compare(__lhs) < 0; }
6312 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6317 {
return __lhs.compare(__rhs) <= 0; }
6325 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6328 const _CharT* __rhs)
6329 {
return __lhs.compare(__rhs) <= 0; }
6337 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6339 operator<=(
const _CharT* __lhs,
6341 {
return __rhs.compare(__lhs) >= 0; }
6350 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6355 {
return __lhs.compare(__rhs) >= 0; }
6363 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6366 const _CharT* __rhs)
6367 {
return __lhs.compare(__rhs) >= 0; }
6375 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6377 operator>=(
const _CharT* __lhs,
6379 {
return __rhs.compare(__lhs) <= 0; }
6388 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6392 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
6393 { __lhs.swap(__rhs); }
6408 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6409 basic_istream<_CharT, _Traits>&
6410 operator>>(basic_istream<_CharT, _Traits>& __is,
6411 basic_string<_CharT, _Traits, _Alloc>& __str);
6414 basic_istream<char>&
6415 operator>>(basic_istream<char>& __is, basic_string<char>& __str);
6426 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6427 inline basic_ostream<_CharT, _Traits>&
6433 return __ostream_insert(__os, __str.data(), __str.size());
6449 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6450 basic_istream<_CharT, _Traits>&
6451 getline(basic_istream<_CharT, _Traits>& __is,
6452 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
6466 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6467 inline basic_istream<_CharT, _Traits>&
6470 {
return std::getline(__is, __str, __is.widen(
'\n')); }
6472 #if __cplusplus >= 201103L
6474 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6475 inline basic_istream<_CharT, _Traits>&
6481 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6482 inline basic_istream<_CharT, _Traits>&
6489 basic_istream<char>&
6490 getline(basic_istream<char>& __in, basic_string<char>& __str,
6493 #ifdef _GLIBCXX_USE_WCHAR_T
6495 basic_istream<wchar_t>&
6496 getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
6500 _GLIBCXX_END_NAMESPACE_VERSION
6503 #if __cplusplus >= 201103L
6508 namespace std _GLIBCXX_VISIBILITY(default)
6510 _GLIBCXX_BEGIN_NAMESPACE_VERSION
6511 _GLIBCXX_BEGIN_NAMESPACE_CXX11
6513 #if _GLIBCXX_USE_C99_STDLIB
6516 stoi(
const string& __str,
size_t* __idx = 0,
int __base = 10)
6517 {
return __gnu_cxx::__stoa<long, int>(&std::strtol,
"stoi", __str.c_str(),
6521 stol(
const string& __str,
size_t* __idx = 0,
int __base = 10)
6522 {
return __gnu_cxx::__stoa(&std::strtol,
"stol", __str.c_str(),
6525 inline unsigned long
6526 stoul(
const string& __str,
size_t* __idx = 0,
int __base = 10)
6527 {
return __gnu_cxx::__stoa(&std::strtoul,
"stoul", __str.c_str(),
6531 stoll(
const string& __str,
size_t* __idx = 0,
int __base = 10)
6532 {
return __gnu_cxx::__stoa(&std::strtoll,
"stoll", __str.c_str(),
6535 inline unsigned long long
6536 stoull(
const string& __str,
size_t* __idx = 0,
int __base = 10)
6537 {
return __gnu_cxx::__stoa(&std::strtoull,
"stoull", __str.c_str(),
6542 stof(
const string& __str,
size_t* __idx = 0)
6543 {
return __gnu_cxx::__stoa(&std::strtof,
"stof", __str.c_str(), __idx); }
6546 stod(
const string& __str,
size_t* __idx = 0)
6547 {
return __gnu_cxx::__stoa(&std::strtod,
"stod", __str.c_str(), __idx); }
6550 stold(
const string& __str,
size_t* __idx = 0)
6551 {
return __gnu_cxx::__stoa(&std::strtold,
"stold", __str.c_str(), __idx); }
6552 #endif // _GLIBCXX_USE_C99_STDLIB
6557 to_string(
int __val)
6559 const bool __neg = __val < 0;
6560 const unsigned __uval = __neg ? (unsigned)~__val + 1u : __val;
6561 const auto __len = __detail::__to_chars_len(__uval);
6562 string __str(__neg + __len,
'-');
6563 __detail::__to_chars_10_impl(&__str[__neg], __len, __uval);
6568 to_string(
unsigned __val)
6570 string __str(__detail::__to_chars_len(__val),
'\0');
6571 __detail::__to_chars_10_impl(&__str[0], __str.size(), __val);
6576 to_string(
long __val)
6578 const bool __neg = __val < 0;
6579 const unsigned long __uval = __neg ? (
unsigned long)~__val + 1ul : __val;
6580 const auto __len = __detail::__to_chars_len(__uval);
6581 string __str(__neg + __len,
'-');
6582 __detail::__to_chars_10_impl(&__str[__neg], __len, __uval);
6587 to_string(
unsigned long __val)
6589 string __str(__detail::__to_chars_len(__val),
'\0');
6590 __detail::__to_chars_10_impl(&__str[0], __str.size(), __val);
6595 to_string(
long long __val)
6597 const bool __neg = __val < 0;
6598 const unsigned long long __uval
6599 = __neg ? (
unsigned long long)~__val + 1ull : __val;
6600 const auto __len = __detail::__to_chars_len(__uval);
6601 string __str(__neg + __len,
'-');
6602 __detail::__to_chars_10_impl(&__str[__neg], __len, __uval);
6607 to_string(
unsigned long long __val)
6609 string __str(__detail::__to_chars_len(__val),
'\0');
6610 __detail::__to_chars_10_impl(&__str[0], __str.size(), __val);
6614 #if _GLIBCXX_USE_C99_STDIO
6618 to_string(
float __val)
6621 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
6622 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
6627 to_string(
double __val)
6630 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
6631 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
6636 to_string(
long double __val)
6639 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
6640 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
6643 #endif // _GLIBCXX_USE_C99_STDIO
6645 #if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR
6647 stoi(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
6648 {
return __gnu_cxx::__stoa<long, int>(&std::wcstol,
"stoi", __str.c_str(),
6652 stol(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
6653 {
return __gnu_cxx::__stoa(&std::wcstol,
"stol", __str.c_str(),
6656 inline unsigned long
6657 stoul(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
6658 {
return __gnu_cxx::__stoa(&std::wcstoul,
"stoul", __str.c_str(),
6662 stoll(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
6663 {
return __gnu_cxx::__stoa(&std::wcstoll,
"stoll", __str.c_str(),
6666 inline unsigned long long
6667 stoull(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
6668 {
return __gnu_cxx::__stoa(&std::wcstoull,
"stoull", __str.c_str(),
6673 stof(
const wstring& __str,
size_t* __idx = 0)
6674 {
return __gnu_cxx::__stoa(&std::wcstof,
"stof", __str.c_str(), __idx); }
6677 stod(
const wstring& __str,
size_t* __idx = 0)
6678 {
return __gnu_cxx::__stoa(&std::wcstod,
"stod", __str.c_str(), __idx); }
6681 stold(
const wstring& __str,
size_t* __idx = 0)
6682 {
return __gnu_cxx::__stoa(&std::wcstold,
"stold", __str.c_str(), __idx); }
6684 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
6687 to_wstring(
int __val)
6688 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 *
sizeof(
int),
6692 to_wstring(
unsigned __val)
6693 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6694 4 *
sizeof(
unsigned),
6698 to_wstring(
long __val)
6699 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 *
sizeof(
long),
6703 to_wstring(
unsigned long __val)
6704 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6705 4 *
sizeof(
unsigned long),
6709 to_wstring(
long long __val)
6710 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6711 4 *
sizeof(
long long),
6715 to_wstring(
unsigned long long __val)
6716 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6717 4 *
sizeof(
unsigned long long),
6721 to_wstring(
float __val)
6724 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
6725 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
6730 to_wstring(
double __val)
6733 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
6734 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
6739 to_wstring(
long double __val)
6742 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
6743 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
6746 #endif // _GLIBCXX_HAVE_BROKEN_VSWPRINTF
6747 #endif // _GLIBCXX_USE_WCHAR_T && _GLIBCXX_USE_C99_WCHAR
6749 _GLIBCXX_END_NAMESPACE_CXX11
6750 _GLIBCXX_END_NAMESPACE_VERSION
6755 #if __cplusplus >= 201103L
6759 namespace std _GLIBCXX_VISIBILITY(default)
6761 _GLIBCXX_BEGIN_NAMESPACE_VERSION
6765 #ifndef _GLIBCXX_COMPATIBILITY_CXX0X
6769 :
public __hash_base<size_t, string>
6772 operator()(
const string& __s)
const noexcept
6773 {
return std::_Hash_impl::hash(__s.
data(), __s.
length()); }
6780 #ifdef _GLIBCXX_USE_WCHAR_T
6784 :
public __hash_base<size_t, wstring>
6787 operator()(
const wstring& __s)
const noexcept
6788 {
return std::_Hash_impl::hash(__s.
data(),
6789 __s.
length() *
sizeof(
wchar_t)); }
6798 #ifdef _GLIBCXX_USE_CHAR8_T
6801 struct hash<u8string>
6802 :
public __hash_base<size_t, u8string>
6805 operator()(
const u8string& __s)
const noexcept
6806 {
return std::_Hash_impl::hash(__s.data(),
6807 __s.length() *
sizeof(char8_t)); }
6818 :
public __hash_base<size_t, u16string>
6821 operator()(
const u16string& __s)
const noexcept
6822 {
return std::_Hash_impl::hash(__s.
data(),
6823 __s.
length() *
sizeof(char16_t)); }
6833 :
public __hash_base<size_t, u32string>
6836 operator()(
const u32string& __s)
const noexcept
6837 {
return std::_Hash_impl::hash(__s.
data(),
6838 __s.
length() *
sizeof(char32_t)); }
6845 #if __cplusplus >= 201402L
6847 #define __cpp_lib_string_udls 201304
6849 inline namespace literals
6851 inline namespace string_literals
6853 #pragma GCC diagnostic push
6854 #pragma GCC diagnostic ignored "-Wliteral-suffix"
6855 _GLIBCXX_DEFAULT_ABI_TAG
6856 inline basic_string<char>
6857 operator""s(
const char* __str,
size_t __len)
6858 {
return basic_string<char>{__str, __len}; }
6860 #ifdef _GLIBCXX_USE_WCHAR_T
6861 _GLIBCXX_DEFAULT_ABI_TAG
6862 inline basic_string<wchar_t>
6863 operator""s(
const wchar_t* __str,
size_t __len)
6864 {
return basic_string<wchar_t>{__str, __len}; }
6867 #ifdef _GLIBCXX_USE_CHAR8_T
6868 _GLIBCXX_DEFAULT_ABI_TAG
6869 inline basic_string<char8_t>
6870 operator""s(
const char8_t* __str,
size_t __len)
6871 {
return basic_string<char8_t>{__str, __len}; }
6874 _GLIBCXX_DEFAULT_ABI_TAG
6875 inline basic_string<char16_t>
6876 operator""s(
const char16_t* __str,
size_t __len)
6877 {
return basic_string<char16_t>{__str, __len}; }
6879 _GLIBCXX_DEFAULT_ABI_TAG
6880 inline basic_string<char32_t>
6881 operator""s(
const char32_t* __str,
size_t __len)
6882 {
return basic_string<char32_t>{__str, __len}; }
6884 #pragma GCC diagnostic pop
6888 #if __cplusplus >= 201703L
6889 namespace __detail::__variant
6891 template<
typename>
struct _Never_valueless_alt;
6895 template<
typename _Tp,
typename _Traits,
typename _Alloc>
6896 struct _Never_valueless_alt<
std::basic_string<_Tp, _Traits, _Alloc>>
6898 is_nothrow_move_constructible<std::basic_string<_Tp, _Traits, _Alloc>>,
6899 is_nothrow_move_assignable<std::basic_string<_Tp, _Traits, _Alloc>>
6906 _GLIBCXX_END_NAMESPACE_VERSION