34#ifndef _BASIC_STRING_H
35#define _BASIC_STRING_H 1
38#pragma GCC system_header
44#if __cplusplus >= 201103L
48#if __cplusplus >= 201703L
52#if __cplusplus > 202302L
58#if ! _GLIBCXX_USE_CXX11_ABI
62namespace std _GLIBCXX_VISIBILITY(default)
64_GLIBCXX_BEGIN_NAMESPACE_VERSION
65_GLIBCXX_BEGIN_NAMESPACE_CXX11
87 template<
typename _CharT,
typename _Traits,
typename _Alloc>
90#if __cplusplus >= 202002L
91 static_assert(is_same_v<_CharT, typename _Traits::char_type>);
92 static_assert(is_same_v<_CharT, typename _Alloc::value_type>);
93 using _Char_alloc_type = _Alloc;
96 rebind<_CharT>::other _Char_alloc_type;
103 typedef _Traits traits_type;
104 typedef typename _Traits::char_type value_type;
105 typedef _Char_alloc_type allocator_type;
106 typedef typename _Alloc_traits::size_type size_type;
107 typedef typename _Alloc_traits::difference_type difference_type;
108 typedef typename _Alloc_traits::reference reference;
109 typedef typename _Alloc_traits::const_reference const_reference;
110 typedef typename _Alloc_traits::pointer pointer;
111 typedef typename _Alloc_traits::const_pointer const_pointer;
112 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
113 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
119 static const size_type
npos =
static_cast<size_type
>(-1);
123#if __cplusplus < 201103L
124 typedef iterator __const_iterator;
126 typedef const_iterator __const_iterator;
130 static _GLIBCXX20_CONSTEXPR pointer
131 _S_allocate(_Char_alloc_type& __a, size_type __n)
133 pointer __p = _Alloc_traits::allocate(__a, __n);
134#if __glibcxx_constexpr_string >= 201907L
137 if constexpr (!is_same_v<_Traits, char_traits<_CharT>>)
138 if (std::__is_constant_evaluated())
140 for (size_type __i = 0; __i < __n; ++__i)
141 std::construct_at(__builtin_addressof(__p[__i]));
146#if __cplusplus >= 201703L
148 typedef basic_string_view<_CharT, _Traits> __sv_type;
150 template<
typename _Tp,
typename _Res>
152 __and_<is_convertible<const _Tp&, __sv_type>,
153 __not_<is_convertible<const _Tp*, const basic_string*>>,
154 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
160 _S_to_string_view(__sv_type __svt)
noexcept
169 _GLIBCXX20_CONSTEXPR
explicit
170 __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
188 struct _Alloc_hider : allocator_type
190#if __cplusplus < 201103L
191 _Alloc_hider(pointer __dat,
const _Alloc& __a = _Alloc())
192 : allocator_type(__a), _M_p(__dat) { }
195 _Alloc_hider(pointer __dat,
const _Alloc& __a)
196 : allocator_type(__a), _M_p(__dat) { }
199 _Alloc_hider(pointer __dat, _Alloc&& __a = _Alloc())
200 : allocator_type(
std::
move(__a)), _M_p(__dat) { }
206 _Alloc_hider _M_dataplus;
207 size_type _M_string_length;
209 enum { _S_local_capacity = 15 /
sizeof(_CharT) };
213 _CharT _M_local_buf[_S_local_capacity + 1];
214 size_type _M_allocated_capacity;
220 { _M_dataplus._M_p = __p; }
224 _M_length(size_type __length)
225 { _M_string_length = __length; }
230 {
return _M_dataplus._M_p; }
236#if __cplusplus >= 201103L
239 return pointer(_M_local_buf);
245 _M_local_data()
const
247#if __cplusplus >= 201103L
250 return const_pointer(_M_local_buf);
256 _M_capacity(size_type __capacity)
257 { _M_allocated_capacity = __capacity; }
261 _M_set_length(size_type __n)
264 traits_type::assign(_M_data()[__n], _CharT());
271 if (_M_data() == _M_local_data())
273 if (_M_string_length > _S_local_capacity)
274 __builtin_unreachable();
283 _M_create(size_type&, size_type);
290 _M_destroy(_M_allocated_capacity);
295 _M_destroy(size_type __size)
throw()
296 { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); }
298#if __cplusplus < 201103L || defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
301 template<
typename _InIterator>
303 _M_construct_aux(_InIterator __beg, _InIterator __end,
306 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
307 _M_construct(__beg, __end, _Tag());
312 template<
typename _Integer>
314 _M_construct_aux(_Integer __beg, _Integer __end, std::__true_type)
315 { _M_construct_aux_2(
static_cast<size_type
>(__beg), __end); }
318 _M_construct_aux_2(size_type __req, _CharT __c)
319 { _M_construct(__req, __c); }
323 template<
typename _InIterator>
326 _M_construct(_InIterator __beg, _InIterator __end,
331 template<
typename _FwdIterator>
334 _M_construct(_FwdIterator __beg, _FwdIterator __end,
339 _M_construct(size_type __req, _CharT __c);
344 {
return _M_dataplus; }
347 const allocator_type&
348 _M_get_allocator()
const
349 {
return _M_dataplus; }
352 __attribute__((__always_inline__))
355 _M_init_local_buf() _GLIBCXX_NOEXCEPT
357#if __glibcxx_is_constant_evaluated
358 if (std::is_constant_evaluated())
359 for (size_type __i = 0; __i <= _S_local_capacity; ++__i)
360 _M_local_buf[__i] = _CharT();
364 __attribute__((__always_inline__))
367 _M_use_local_data() _GLIBCXX_NOEXCEPT
369#if __cpp_lib_is_constant_evaluated
372 return _M_local_data();
377#ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
380 template<
typename _Tp,
bool _Requires =
381 !__are_same<_Tp, _CharT*>::__value
382 && !__are_same<_Tp, const _CharT*>::__value
383 && !__are_same<_Tp, iterator>::__value
384 && !__are_same<_Tp, const_iterator>::__value>
385 struct __enable_if_not_native_iterator
386 {
typedef basic_string& __type; };
387 template<
typename _Tp>
388 struct __enable_if_not_native_iterator<_Tp, false> { };
393 _M_check(size_type __pos,
const char* __s)
const
395 if (__pos > this->
size())
396 __throw_out_of_range_fmt(__N(
"%s: __pos (which is %zu) > "
397 "this->size() (which is %zu)"),
398 __s, __pos, this->
size());
404 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
407 __throw_length_error(__N(__s));
414 _M_limit(size_type __pos, size_type __off)
const _GLIBCXX_NOEXCEPT
416 const bool __testoff = __off < this->
size() - __pos;
417 return __testoff ? __off : this->
size() - __pos;
422 _M_disjunct(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
424 return (less<const _CharT*>()(__s, _M_data())
425 || less<const _CharT*>()(_M_data() + this->
size(), __s));
432 _S_copy(_CharT* __d,
const _CharT* __s, size_type __n)
435 traits_type::assign(*__d, *__s);
437 traits_type::copy(__d, __s, __n);
442 _S_move(_CharT* __d,
const _CharT* __s, size_type __n)
445 traits_type::assign(*__d, *__s);
447 traits_type::move(__d, __s, __n);
452 _S_assign(_CharT* __d, size_type __n, _CharT __c)
455 traits_type::assign(*__d, __c);
457 traits_type::assign(__d, __n, __c);
462 template<
class _Iterator>
465 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
467 for (; __k1 != __k2; ++__k1, (void)++__p)
468 traits_type::assign(*__p, *__k1);
473 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
474 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
478 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
480 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
484 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
485 { _S_copy(__p, __k1, __k2 - __k1); }
489 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
491 { _S_copy(__p, __k1, __k2 - __k1); }
495 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
497 const difference_type __d = difference_type(__n1 - __n2);
499 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
500 return __gnu_cxx::__numeric_traits<int>::__max;
501 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
502 return __gnu_cxx::__numeric_traits<int>::__min;
513 _M_mutate(size_type __pos, size_type __len1,
const _CharT* __s,
518 _M_erase(size_type __pos, size_type __n);
530 _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value)
531#if __cpp_concepts && __glibcxx_type_trait_variable_templates
532 requires is_default_constructible_v<_Alloc>
534 : _M_dataplus(_M_local_data())
546 : _M_dataplus(_M_local_data(), __a)
558 : _M_dataplus(_M_local_data(),
559 _Alloc_traits::_S_select_on_copy(__str._M_get_allocator()))
561 _M_construct(__str._M_data(), __str._M_data() + __str.length(),
575 const _Alloc& __a = _Alloc())
576 : _M_dataplus(_M_local_data(), __a)
578 const _CharT* __start = __str._M_data()
579 + __str._M_check(__pos,
"basic_string::basic_string");
580 _M_construct(__start, __start + __str._M_limit(__pos,
npos),
593 : _M_dataplus(_M_local_data())
595 const _CharT* __start = __str._M_data()
596 + __str._M_check(__pos,
"basic_string::basic_string");
597 _M_construct(__start, __start + __str._M_limit(__pos, __n),
610 size_type __n,
const _Alloc& __a)
611 : _M_dataplus(_M_local_data(), __a)
613 const _CharT* __start
614 = __str._M_data() + __str._M_check(__pos,
"string::string");
615 _M_construct(__start, __start + __str._M_limit(__pos, __n),
630 const _Alloc& __a = _Alloc())
631 : _M_dataplus(_M_local_data(), __a)
634 if (__s == 0 && __n > 0)
635 std::__throw_logic_error(__N(
"basic_string: "
636 "construction from null is not valid"));
645#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
648 template<
typename = _RequireAllocator<_Alloc>>
651 basic_string(
const _CharT* __s,
const _Alloc& __a = _Alloc())
652 : _M_dataplus(_M_local_data(), __a)
656 std::__throw_logic_error(__N(
"basic_string: "
657 "construction from null is not valid"));
658 const _CharT* __end = __s + traits_type::length(__s);
659 _M_construct(__s, __end, forward_iterator_tag());
668#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
671 template<
typename = _RequireAllocator<_Alloc>>
674 basic_string(size_type __n, _CharT __c,
const _Alloc& __a = _Alloc())
675 : _M_dataplus(_M_local_data(), __a)
676 { _M_construct(__n, __c); }
678#if __cplusplus >= 201103L
688 : _M_dataplus(_M_local_data(),
std::move(__str._M_get_allocator()))
690 if (__str._M_is_local())
693 traits_type::copy(_M_local_buf, __str._M_local_buf,
698 _M_data(__str._M_data());
699 _M_capacity(__str._M_allocated_capacity);
705 _M_length(__str.length());
706 __str._M_data(__str._M_use_local_data());
707 __str._M_set_length(0);
716 basic_string(initializer_list<_CharT> __l,
const _Alloc& __a = _Alloc())
717 : _M_dataplus(_M_local_data(), __a)
722 : _M_dataplus(_M_local_data(), __a)
727 noexcept(_Alloc_traits::_S_always_equal())
728 : _M_dataplus(_M_local_data(), __a)
730 if (__str._M_is_local())
733 traits_type::copy(_M_local_buf, __str._M_local_buf,
735 _M_length(__str.length());
736 __str._M_set_length(0);
738 else if (_Alloc_traits::_S_always_equal()
739 || __str.get_allocator() == __a)
741 _M_data(__str._M_data());
742 _M_length(__str.length());
743 _M_capacity(__str._M_allocated_capacity);
744 __str._M_data(__str._M_use_local_data());
745 __str._M_set_length(0);
752#if __cplusplus >= 202100L
763#if __cplusplus >= 201103L
764 template<
typename _InputIterator,
765 typename = std::_RequireInputIter<_InputIterator>>
767 template<
typename _InputIterator>
770 basic_string(_InputIterator __beg, _InputIterator __end,
771 const _Alloc& __a = _Alloc())
772 : _M_dataplus(_M_local_data(), __a), _M_string_length(0)
774#if __cplusplus >= 201103L
777 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
778 _M_construct_aux(__beg, __end, _Integral());
782#if __cplusplus >= 201703L
790 template<
typename _Tp,
791 typename = enable_if_t<is_convertible_v<const _Tp&, __sv_type>>>
793 basic_string(
const _Tp& __t, size_type __pos, size_type __n,
794 const _Alloc& __a = _Alloc())
802 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
805 basic_string(
const _Tp& __t,
const _Alloc& __a = _Alloc())
806 :
basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
824 return this->
assign(__str);
834 {
return this->
assign(__s); }
851#if __cplusplus >= 201103L
864 noexcept(_Alloc_traits::_S_nothrow_move())
866 const bool __equal_allocs = _Alloc_traits::_S_always_equal()
867 || _M_get_allocator() == __str._M_get_allocator();
868 if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign()
872 _M_destroy(_M_allocated_capacity);
873 _M_data(_M_local_data());
877 std::__alloc_on_move(_M_get_allocator(), __str._M_get_allocator());
879 if (__str._M_is_local())
887 this->_S_copy(_M_data(), __str._M_data(), __str.size());
888 _M_set_length(__str.size());
891 else if (_Alloc_traits::_S_propagate_on_move_assign() || __equal_allocs)
894 pointer __data =
nullptr;
895 size_type __capacity;
902 __capacity = _M_allocated_capacity;
905 _M_destroy(_M_allocated_capacity);
908 _M_data(__str._M_data());
909 _M_length(__str.length());
910 _M_capacity(__str._M_allocated_capacity);
913 __str._M_data(__data);
914 __str._M_capacity(__capacity);
917 __str._M_data(__str._M_use_local_data());
933 this->
assign(__l.begin(), __l.size());
938#if __cplusplus >= 201703L
943 template<
typename _Tp>
945 _If_sv<_Tp, basic_string&>
947 {
return this->
assign(__svt); }
954 operator __sv_type() const noexcept
955 {
return __sv_type(
data(),
size()); }
963 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
965 begin() _GLIBCXX_NOEXCEPT
966 {
return iterator(_M_data()); }
972 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
974 begin() const _GLIBCXX_NOEXCEPT
975 {
return const_iterator(_M_data()); }
981 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
983 end() _GLIBCXX_NOEXCEPT
984 {
return iterator(_M_data() + this->
size()); }
990 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
992 end() const _GLIBCXX_NOEXCEPT
993 {
return const_iterator(_M_data() + this->
size()); }
1000 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1002 rbegin() _GLIBCXX_NOEXCEPT
1003 {
return reverse_iterator(this->
end()); }
1010 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1011 const_reverse_iterator
1012 rbegin() const _GLIBCXX_NOEXCEPT
1013 {
return const_reverse_iterator(this->
end()); }
1020 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1022 rend() _GLIBCXX_NOEXCEPT
1023 {
return reverse_iterator(this->
begin()); }
1030 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1031 const_reverse_iterator
1032 rend() const _GLIBCXX_NOEXCEPT
1033 {
return const_reverse_iterator(this->
begin()); }
1035#if __cplusplus >= 201103L
1040 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1043 {
return const_iterator(this->_M_data()); }
1049 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1051 cend() const noexcept
1052 {
return const_iterator(this->_M_data() + this->
size()); }
1059 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1060 const_reverse_iterator
1062 {
return const_reverse_iterator(this->
end()); }
1069 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1070 const_reverse_iterator
1071 crend() const noexcept
1072 {
return const_reverse_iterator(this->
begin()); }
1079 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1081 size() const _GLIBCXX_NOEXCEPT
1082 {
return _M_string_length; }
1086 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1088 length() const _GLIBCXX_NOEXCEPT
1089 {
return _M_string_length; }
1092 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1095 {
return (_Alloc_traits::max_size(_M_get_allocator()) - 1) / 2; }
1107 _GLIBCXX20_CONSTEXPR
1109 resize(size_type __n, _CharT __c);
1121 _GLIBCXX20_CONSTEXPR
1124 { this->
resize(__n, _CharT()); }
1126#if __cplusplus >= 201103L
1127#pragma GCC diagnostic push
1128#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1130 _GLIBCXX20_CONSTEXPR
1134#pragma GCC diagnostic pop
1137#ifdef __glibcxx_string_resize_and_overwrite
1167 template<
typename _Operation>
1169 resize_and_overwrite(size_type __n, _Operation __op);
1172#if __cplusplus >= 201103L
1174 template<
typename _Operation>
1175 _GLIBCXX20_CONSTEXPR
void
1183 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1187 return _M_is_local() ? size_type(_S_local_capacity)
1188 : _M_allocated_capacity;
1208 _GLIBCXX20_CONSTEXPR
1215#if __cplusplus > 201703L
1216 [[deprecated(
"use shrink_to_fit() instead")]]
1218 _GLIBCXX20_CONSTEXPR
1225 _GLIBCXX20_CONSTEXPR
1227 clear() _GLIBCXX_NOEXCEPT
1228 { _M_set_length(0); }
1234 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1236 empty() const _GLIBCXX_NOEXCEPT
1237 {
return this->
size() == 0; }
1250 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1252 operator[] (size_type __pos)
const _GLIBCXX_NOEXCEPT
1254 __glibcxx_assert(__pos <=
size());
1255 return _M_data()[__pos];
1268 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1274 __glibcxx_assert(__pos <=
size());
1276 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos <
size());
1277 return _M_data()[__pos];
1290 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1292 at(size_type __n)
const
1294 if (__n >= this->
size())
1295 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1296 "(which is %zu) >= this->size() "
1299 return _M_data()[__n];
1312 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1317 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1318 "(which is %zu) >= this->size() "
1321 return _M_data()[__n];
1324#if __cplusplus >= 201103L
1329 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1333 __glibcxx_assert(!
empty());
1341 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1343 front() const noexcept
1345 __glibcxx_assert(!
empty());
1353 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1357 __glibcxx_assert(!
empty());
1365 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1367 back() const noexcept
1369 __glibcxx_assert(!
empty());
1380 _GLIBCXX20_CONSTEXPR
1383 {
return this->
append(__str); }
1390 _GLIBCXX20_CONSTEXPR
1393 {
return this->
append(__s); }
1400 _GLIBCXX20_CONSTEXPR
1408#if __cplusplus >= 201103L
1414 _GLIBCXX20_CONSTEXPR
1417 {
return this->
append(__l.begin(), __l.size()); }
1420#if __cplusplus >= 201703L
1426 template<
typename _Tp>
1427 _GLIBCXX20_CONSTEXPR
1428 _If_sv<_Tp, basic_string&>
1430 {
return this->
append(__svt); }
1438 _GLIBCXX20_CONSTEXPR
1441 {
return this->
append(__str._M_data(), __str.size()); }
1456 _GLIBCXX20_CONSTEXPR
1459 {
return this->
append(__str._M_data()
1460 + __str._M_check(__pos,
"basic_string::append"),
1461 __str._M_limit(__pos, __n)); }
1469 _GLIBCXX20_CONSTEXPR
1471 append(
const _CharT* __s, size_type __n)
1473 __glibcxx_requires_string_len(__s, __n);
1474 _M_check_length(size_type(0), __n,
"basic_string::append");
1475 return _M_append(__s, __n);
1483 _GLIBCXX20_CONSTEXPR
1485 append(
const _CharT* __s)
1487 __glibcxx_requires_string(__s);
1488 const size_type __n = traits_type::length(__s);
1489 _M_check_length(size_type(0), __n,
"basic_string::append");
1490 return _M_append(__s, __n);
1501 _GLIBCXX20_CONSTEXPR
1503 append(size_type __n, _CharT __c)
1504 {
return _M_replace_aux(this->
size(), size_type(0), __n, __c); }
1506#if __cplusplus >= 201103L
1512 _GLIBCXX20_CONSTEXPR
1514 append(initializer_list<_CharT> __l)
1515 {
return this->
append(__l.begin(), __l.size()); }
1526#if __cplusplus >= 201103L
1527 template<
class _InputIterator,
1528 typename = std::_RequireInputIter<_InputIterator>>
1529 _GLIBCXX20_CONSTEXPR
1531 template<
class _InputIterator>
1534 append(_InputIterator __first, _InputIterator __last)
1537#if __cplusplus >= 201703L
1543 template<
typename _Tp>
1544 _GLIBCXX20_CONSTEXPR
1545 _If_sv<_Tp, basic_string&>
1548 __sv_type __sv = __svt;
1549 return this->
append(__sv.data(), __sv.size());
1559 template<
typename _Tp>
1560 _GLIBCXX20_CONSTEXPR
1561 _If_sv<_Tp, basic_string&>
1562 append(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
1564 __sv_type __sv = __svt;
1565 return _M_append(__sv.data()
1566 + std::__sv_check(__sv.size(), __pos,
"basic_string::append"),
1567 std::__sv_limit(__sv.size(), __pos, __n));
1575 _GLIBCXX20_CONSTEXPR
1579 const size_type __size = this->
size();
1581 this->_M_mutate(__size, size_type(0), 0, size_type(1));
1582 traits_type::assign(this->_M_data()[__size], __c);
1583 this->_M_set_length(__size + 1);
1591 _GLIBCXX20_CONSTEXPR
1595#if __cplusplus >= 201103L
1596 if (_Alloc_traits::_S_propagate_on_copy_assign())
1598 if (!_Alloc_traits::_S_always_equal() && !_M_is_local()
1599 && _M_get_allocator() != __str._M_get_allocator())
1603 if (__str.size() <= _S_local_capacity)
1605 _M_destroy(_M_allocated_capacity);
1606 _M_data(_M_use_local_data());
1611 const auto __len = __str.size();
1612 auto __alloc = __str._M_get_allocator();
1614 auto __ptr = _S_allocate(__alloc, __len + 1);
1615 _M_destroy(_M_allocated_capacity);
1618 _M_set_length(__len);
1621 std::__alloc_on_copy(_M_get_allocator(), __str._M_get_allocator());
1624 this->_M_assign(__str);
1628#if __cplusplus >= 201103L
1637 _GLIBCXX20_CONSTEXPR
1640 noexcept(_Alloc_traits::_S_nothrow_move())
1661 _GLIBCXX20_CONSTEXPR
1664 {
return _M_replace(size_type(0), this->
size(), __str._M_data()
1665 + __str._M_check(__pos,
"basic_string::assign"),
1666 __str._M_limit(__pos, __n)); }
1678 _GLIBCXX20_CONSTEXPR
1680 assign(
const _CharT* __s, size_type __n)
1682 __glibcxx_requires_string_len(__s, __n);
1683 return _M_replace(size_type(0), this->
size(), __s, __n);
1695 _GLIBCXX20_CONSTEXPR
1697 assign(
const _CharT* __s)
1699 __glibcxx_requires_string(__s);
1700 return _M_replace(size_type(0), this->
size(), __s,
1701 traits_type::length(__s));
1713 _GLIBCXX20_CONSTEXPR
1715 assign(size_type __n, _CharT __c)
1716 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
1726#if __cplusplus >= 201103L
1727#pragma GCC diagnostic push
1728#pragma GCC diagnostic ignored "-Wc++17-extensions"
1729 template<
class _InputIterator,
1730 typename = std::_RequireInputIter<_InputIterator>>
1731 _GLIBCXX20_CONSTEXPR
1733 assign(_InputIterator __first, _InputIterator __last)
1735 using _IterTraits = iterator_traits<_InputIterator>;
1736 if constexpr (is_pointer<
decltype(std::__niter_base(__first))>::value
1737 && is_same<
typename _IterTraits::value_type,
1740 __glibcxx_requires_valid_range(__first, __last);
1741 return _M_replace(size_type(0),
size(),
1742 std::__niter_base(__first), __last - __first);
1744#if __cplusplus >= 202002L
1745 else if constexpr (contiguous_iterator<_InputIterator>
1746 && is_same_v<iter_value_t<_InputIterator>,
1749 __glibcxx_requires_valid_range(__first, __last);
1750 return _M_replace(size_type(0),
size(),
1757#pragma GCC diagnostic pop
1759 template<
class _InputIterator>
1761 assign(_InputIterator __first, _InputIterator __last)
1765#if __cplusplus >= 201103L
1771 _GLIBCXX20_CONSTEXPR
1773 assign(initializer_list<_CharT> __l)
1777 const size_type __n = __l.
size();
1783 _S_copy(_M_data(), __l.begin(), __n);
1790#if __cplusplus >= 201703L
1796 template<
typename _Tp>
1797 _GLIBCXX20_CONSTEXPR
1798 _If_sv<_Tp, basic_string&>
1801 __sv_type __sv = __svt;
1802 return this->
assign(__sv.data(), __sv.size());
1812 template<
typename _Tp>
1813 _GLIBCXX20_CONSTEXPR
1814 _If_sv<_Tp, basic_string&>
1815 assign(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
1817 __sv_type __sv = __svt;
1818 return _M_replace(size_type(0), this->
size(),
1820 + std::__sv_check(__sv.size(), __pos,
"basic_string::assign"),
1821 std::__sv_limit(__sv.size(), __pos, __n));
1825#if __cplusplus >= 201103L
1841 _GLIBCXX20_CONSTEXPR
1843 insert(const_iterator __p, size_type __n, _CharT __c)
1845 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1846 const size_type __pos = __p -
begin();
1847 this->
replace(__p, __p, __n, __c);
1848 return iterator(this->_M_data() + __pos);
1865 insert(iterator __p, size_type __n, _CharT __c)
1866 { this->
replace(__p, __p, __n, __c); }
1869#if __cplusplus >= 201103L
1884 template<
class _InputIterator,
1885 typename = std::_RequireInputIter<_InputIterator>>
1886 _GLIBCXX20_CONSTEXPR
1888 insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
1890 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1891 const size_type __pos = __p -
begin();
1892 this->
replace(__p, __p, __beg, __end);
1893 return iterator(this->_M_data() + __pos);
1908 template<
class _InputIterator>
1910 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1911 { this->
replace(__p, __p, __beg, __end); }
1914#if __cplusplus >= 201103L
1921 _GLIBCXX20_CONSTEXPR
1923 insert(const_iterator __p, initializer_list<_CharT> __l)
1924 {
return this->
insert(__p, __l.begin(), __l.end()); }
1926#ifdef _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
1929 insert(iterator __p, initializer_list<_CharT> __l)
1931 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1932 this->
insert(__p -
begin(), __l.begin(), __l.size());
1949 _GLIBCXX20_CONSTEXPR
1952 {
return this->
replace(__pos1, size_type(0),
1953 __str._M_data(), __str.size()); }
1973 _GLIBCXX20_CONSTEXPR
1976 size_type __pos2, size_type __n =
npos)
1977 {
return this->
replace(__pos1, size_type(0), __str._M_data()
1978 + __str._M_check(__pos2,
"basic_string::insert"),
1979 __str._M_limit(__pos2, __n)); }
1997 _GLIBCXX20_CONSTEXPR
1999 insert(size_type __pos,
const _CharT* __s, size_type __n)
2000 {
return this->
replace(__pos, size_type(0), __s, __n); }
2017 _GLIBCXX20_CONSTEXPR
2019 insert(size_type __pos,
const _CharT* __s)
2021 __glibcxx_requires_string(__s);
2022 return this->
replace(__pos, size_type(0), __s,
2023 traits_type::length(__s));
2042 _GLIBCXX20_CONSTEXPR
2044 insert(size_type __pos, size_type __n, _CharT __c)
2045 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
2046 size_type(0), __n, __c); }
2061 _GLIBCXX20_CONSTEXPR
2063 insert(__const_iterator __p, _CharT __c)
2065 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
2066 const size_type __pos = __p -
begin();
2067 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
2068 return iterator(_M_data() + __pos);
2071#if __cplusplus >= 201703L
2078 template<
typename _Tp>
2079 _GLIBCXX20_CONSTEXPR
2080 _If_sv<_Tp, basic_string&>
2081 insert(size_type __pos,
const _Tp& __svt)
2083 __sv_type __sv = __svt;
2084 return this->
insert(__pos, __sv.data(), __sv.size());
2095 template<
typename _Tp>
2096 _GLIBCXX20_CONSTEXPR
2097 _If_sv<_Tp, basic_string&>
2098 insert(size_type __pos1,
const _Tp& __svt,
2099 size_type __pos2, size_type __n =
npos)
2101 __sv_type __sv = __svt;
2102 return this->
replace(__pos1, size_type(0),
2104 + std::__sv_check(__sv.size(), __pos2,
"basic_string::insert"),
2105 std::__sv_limit(__sv.size(), __pos2, __n));
2124 _GLIBCXX20_CONSTEXPR
2126 erase(size_type __pos = 0, size_type __n =
npos)
2128 _M_check(__pos,
"basic_string::erase");
2130 this->_M_set_length(__pos);
2132 this->_M_erase(__pos, _M_limit(__pos, __n));
2144 _GLIBCXX20_CONSTEXPR
2146 erase(__const_iterator __position)
2148 _GLIBCXX_DEBUG_PEDASSERT(__position >=
begin()
2149 && __position <
end());
2150 const size_type __pos = __position -
begin();
2151 this->_M_erase(__pos, size_type(1));
2152 return iterator(_M_data() + __pos);
2164 _GLIBCXX20_CONSTEXPR
2166 erase(__const_iterator __first, __const_iterator __last)
2168 _GLIBCXX_DEBUG_PEDASSERT(__first >=
begin() && __first <= __last
2169 && __last <=
end());
2170 const size_type __pos = __first -
begin();
2171 if (__last ==
end())
2172 this->_M_set_length(__pos);
2174 this->_M_erase(__pos, __last - __first);
2175 return iterator(this->_M_data() + __pos);
2178#if __cplusplus >= 201103L
2184 _GLIBCXX20_CONSTEXPR
2188 __glibcxx_assert(!
empty());
2189 _M_erase(
size() - 1, 1);
2210 _GLIBCXX20_CONSTEXPR
2213 {
return this->
replace(__pos, __n, __str._M_data(), __str.size()); }
2233 _GLIBCXX20_CONSTEXPR
2236 size_type __pos2, size_type __n2 =
npos)
2237 {
return this->
replace(__pos1, __n1, __str._M_data()
2238 + __str._M_check(__pos2,
"basic_string::replace"),
2239 __str._M_limit(__pos2, __n2)); }
2259 _GLIBCXX20_CONSTEXPR
2261 replace(size_type __pos, size_type __n1,
const _CharT* __s,
2264 __glibcxx_requires_string_len(__s, __n2);
2265 return _M_replace(_M_check(__pos,
"basic_string::replace"),
2266 _M_limit(__pos, __n1), __s, __n2);
2285 _GLIBCXX20_CONSTEXPR
2287 replace(size_type __pos, size_type __n1,
const _CharT* __s)
2289 __glibcxx_requires_string(__s);
2290 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
2310 _GLIBCXX20_CONSTEXPR
2312 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
2313 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
2314 _M_limit(__pos, __n1), __n2, __c); }
2329 _GLIBCXX20_CONSTEXPR
2331 replace(__const_iterator __i1, __const_iterator __i2,
2333 {
return this->
replace(__i1, __i2, __str._M_data(), __str.size()); }
2350 _GLIBCXX20_CONSTEXPR
2352 replace(__const_iterator __i1, __const_iterator __i2,
2353 const _CharT* __s, size_type __n)
2355 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2357 return this->
replace(__i1 -
begin(), __i2 - __i1, __s, __n);
2373 _GLIBCXX20_CONSTEXPR
2375 replace(__const_iterator __i1, __const_iterator __i2,
const _CharT* __s)
2377 __glibcxx_requires_string(__s);
2378 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
2395 _GLIBCXX20_CONSTEXPR
2397 replace(__const_iterator __i1, __const_iterator __i2, size_type __n,
2400 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2402 return _M_replace_aux(__i1 -
begin(), __i2 - __i1, __n, __c);
2420#if __cplusplus >= 201103L
2421 template<
class _InputIterator,
2422 typename = std::_RequireInputIter<_InputIterator>>
2423 _GLIBCXX20_CONSTEXPR
2425 replace(const_iterator __i1, const_iterator __i2,
2426 _InputIterator __k1, _InputIterator __k2)
2428 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2430 __glibcxx_requires_valid_range(__k1, __k2);
2431 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
2432 std::__false_type());
2435 template<
class _InputIterator>
2436#ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
2437 typename __enable_if_not_native_iterator<_InputIterator>::__type
2441 replace(iterator __i1, iterator __i2,
2442 _InputIterator __k1, _InputIterator __k2)
2444 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2446 __glibcxx_requires_valid_range(__k1, __k2);
2447 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
2448 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
2454 _GLIBCXX20_CONSTEXPR
2456 replace(__const_iterator __i1, __const_iterator __i2,
2457 _CharT* __k1, _CharT* __k2)
2459 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2461 __glibcxx_requires_valid_range(__k1, __k2);
2466 _GLIBCXX20_CONSTEXPR
2468 replace(__const_iterator __i1, __const_iterator __i2,
2469 const _CharT* __k1,
const _CharT* __k2)
2471 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2473 __glibcxx_requires_valid_range(__k1, __k2);
2478 _GLIBCXX20_CONSTEXPR
2480 replace(__const_iterator __i1, __const_iterator __i2,
2481 iterator __k1, iterator __k2)
2483 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2485 __glibcxx_requires_valid_range(__k1, __k2);
2487 __k1.base(), __k2 - __k1);
2490 _GLIBCXX20_CONSTEXPR
2492 replace(__const_iterator __i1, __const_iterator __i2,
2493 const_iterator __k1, const_iterator __k2)
2495 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2497 __glibcxx_requires_valid_range(__k1, __k2);
2499 __k1.base(), __k2 - __k1);
2502#if __cplusplus >= 201103L
2517 _GLIBCXX20_CONSTEXPR
2519 initializer_list<_CharT> __l)
2520 {
return this->
replace(__i1, __i2, __l.begin(), __l.size()); }
2523#if __cplusplus >= 201703L
2531 template<
typename _Tp>
2532 _GLIBCXX20_CONSTEXPR
2533 _If_sv<_Tp, basic_string&>
2534 replace(size_type __pos, size_type __n,
const _Tp& __svt)
2536 __sv_type __sv = __svt;
2537 return this->
replace(__pos, __n, __sv.data(), __sv.size());
2549 template<
typename _Tp>
2550 _GLIBCXX20_CONSTEXPR
2551 _If_sv<_Tp, basic_string&>
2552 replace(size_type __pos1, size_type __n1,
const _Tp& __svt,
2553 size_type __pos2, size_type __n2 =
npos)
2555 __sv_type __sv = __svt;
2556 return this->
replace(__pos1, __n1,
2558 + std::__sv_check(__sv.size(), __pos2,
"basic_string::replace"),
2559 std::__sv_limit(__sv.size(), __pos2, __n2));
2571 template<
typename _Tp>
2572 _GLIBCXX20_CONSTEXPR
2573 _If_sv<_Tp, basic_string&>
2574 replace(const_iterator __i1, const_iterator __i2,
const _Tp& __svt)
2576 __sv_type __sv = __svt;
2577 return this->
replace(__i1 -
begin(), __i2 - __i1, __sv);
2582 template<
class _Integer>
2583 _GLIBCXX20_CONSTEXPR
2585 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2586 _Integer __n, _Integer __val, __true_type)
2587 {
return _M_replace_aux(__i1 -
begin(), __i2 - __i1, __n, __val); }
2589 template<
class _InputIterator>
2590 _GLIBCXX20_CONSTEXPR
2592 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2593 _InputIterator __k1, _InputIterator __k2,
2596 _GLIBCXX20_CONSTEXPR
2598 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
2601 __attribute__((__noinline__, __noclone__, __cold__))
void
2602 _M_replace_cold(pointer __p, size_type __len1,
const _CharT* __s,
2603 const size_type __len2,
const size_type __how_much);
2605 _GLIBCXX20_CONSTEXPR
2607 _M_replace(size_type __pos, size_type __len1,
const _CharT* __s,
2608 const size_type __len2);
2610 _GLIBCXX20_CONSTEXPR
2612 _M_append(
const _CharT* __s, size_type __n);
2628 _GLIBCXX20_CONSTEXPR
2630 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
2639 _GLIBCXX20_CONSTEXPR
2650 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2652 c_str() const _GLIBCXX_NOEXCEPT
2653 {
return _M_data(); }
2663 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2665 data() const _GLIBCXX_NOEXCEPT
2666 {
return _M_data(); }
2668#if __cplusplus >= 201703L
2675 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2678 {
return _M_data(); }
2684 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2687 {
return _M_get_allocator(); }
2701 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2703 find(
const _CharT* __s, size_type __pos, size_type __n)
const
2716 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2720 {
return this->
find(__str.data(), __pos, __str.size()); }
2722#if __cplusplus >= 201703L
2729 template<
typename _Tp>
2730 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2731 _If_sv<_Tp, size_type>
2732 find(
const _Tp& __svt, size_type __pos = 0) const
2733 noexcept(is_same<_Tp, __sv_type>::value)
2735 __sv_type __sv = __svt;
2736 return this->
find(__sv.data(), __pos, __sv.size());
2750 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2752 find(
const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2754 __glibcxx_requires_string(__s);
2755 return this->
find(__s, __pos, traits_type::length(__s));
2768 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2770 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
2782 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2786 {
return this->
rfind(__str.data(), __pos, __str.size()); }
2788#if __cplusplus >= 201703L
2795 template<
typename _Tp>
2796 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2797 _If_sv<_Tp, size_type>
2798 rfind(
const _Tp& __svt, size_type __pos =
npos)
const
2799 noexcept(is_same<_Tp, __sv_type>::value)
2801 __sv_type __sv = __svt;
2802 return this->
rfind(__sv.data(), __pos, __sv.size());
2818 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2820 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
2833 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2835 rfind(
const _CharT* __s, size_type __pos =
npos)
const
2837 __glibcxx_requires_string(__s);
2838 return this->
rfind(__s, __pos, traits_type::length(__s));
2851 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2853 rfind(_CharT __c, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT;
2866 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2870 {
return this->
find_first_of(__str.data(), __pos, __str.size()); }
2872#if __cplusplus >= 201703L
2880 template<
typename _Tp>
2881 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2882 _If_sv<_Tp, size_type>
2884 noexcept(is_same<_Tp, __sv_type>::value)
2886 __sv_type __sv = __svt;
2887 return this->
find_first_of(__sv.data(), __pos, __sv.size());
2903 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2905 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2918 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2923 __glibcxx_requires_string(__s);
2924 return this->
find_first_of(__s, __pos, traits_type::length(__s));
2939 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2941 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2942 {
return this->
find(__c, __pos); }
2955 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2959 {
return this->
find_last_of(__str.data(), __pos, __str.size()); }
2961#if __cplusplus >= 201703L
2969 template<
typename _Tp>
2970 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2971 _If_sv<_Tp, size_type>
2973 noexcept(is_same<_Tp, __sv_type>::value)
2975 __sv_type __sv = __svt;
2976 return this->
find_last_of(__sv.data(), __pos, __sv.size());
2992 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2994 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
3007 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3012 __glibcxx_requires_string(__s);
3013 return this->
find_last_of(__s, __pos, traits_type::length(__s));
3028 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3031 {
return this->
rfind(__c, __pos); }
3043 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3049#if __cplusplus >= 201703L
3057 template<
typename _Tp>
3058 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3059 _If_sv<_Tp, size_type>
3061 noexcept(is_same<_Tp, __sv_type>::value)
3063 __sv_type __sv = __svt;
3080 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3083 size_type __n)
const _GLIBCXX_NOEXCEPT;
3095 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3100 __glibcxx_requires_string(__s);
3114 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3130 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3136#if __cplusplus >= 201703L
3144 template<
typename _Tp>
3145 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3146 _If_sv<_Tp, size_type>
3148 noexcept(is_same<_Tp, __sv_type>::value)
3150 __sv_type __sv = __svt;
3167 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3170 size_type __n)
const _GLIBCXX_NOEXCEPT;
3182 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3187 __glibcxx_requires_string(__s);
3201 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3218 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3220 substr(size_type __pos = 0, size_type __n =
npos)
const
3222 _M_check(__pos,
"basic_string::substr"), __n); }
3238 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3242 const size_type __size = this->
size();
3243 const size_type __osize = __str.size();
3244 const size_type __len =
std::min(__size, __osize);
3246 int __r = traits_type::compare(_M_data(), __str.data(), __len);
3248 __r = _S_compare(__size, __osize);
3252#if __cplusplus >= 201703L
3258 template<
typename _Tp>
3259 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3261 compare(
const _Tp& __svt)
const
3262 noexcept(is_same<_Tp, __sv_type>::value)
3264 __sv_type __sv = __svt;
3265 const size_type __size = this->
size();
3266 const size_type __osize = __sv.size();
3267 const size_type __len =
std::min(__size, __osize);
3269 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
3271 __r = _S_compare(__size, __osize);
3283 template<
typename _Tp>
3284 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3286 compare(size_type __pos, size_type __n,
const _Tp& __svt)
const
3287 noexcept(is_same<_Tp, __sv_type>::value)
3289 __sv_type __sv = __svt;
3290 return __sv_type(*this).substr(__pos, __n).compare(__sv);
3303 template<
typename _Tp>
3304 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3306 compare(size_type __pos1, size_type __n1,
const _Tp& __svt,
3307 size_type __pos2, size_type __n2 =
npos)
const
3308 noexcept(is_same<_Tp, __sv_type>::value)
3310 __sv_type __sv = __svt;
3311 return __sv_type(*
this)
3312 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3335 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3339 _M_check(__pos,
"basic_string::compare");
3340 __n = _M_limit(__pos, __n);
3341 const size_type __osize = __str.size();
3342 const size_type __len =
std::min(__n, __osize);
3343 int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len);
3345 __r = _S_compare(__n, __osize);
3372 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3375 size_type __pos2, size_type __n2 =
npos)
const
3377 _M_check(__pos1,
"basic_string::compare");
3378 __str._M_check(__pos2,
"basic_string::compare");
3379 __n1 = _M_limit(__pos1, __n1);
3380 __n2 = __str._M_limit(__pos2, __n2);
3381 const size_type __len =
std::min(__n1, __n2);
3382 int __r = traits_type::compare(_M_data() + __pos1,
3383 __str.data() + __pos2, __len);
3385 __r = _S_compare(__n1, __n2);
3403 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3405 compare(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
3407 __glibcxx_requires_string(__s);
3408 const size_type __size = this->
size();
3409 const size_type __osize = traits_type::length(__s);
3410 const size_type __len =
std::min(__size, __osize);
3411 int __r = traits_type::compare(_M_data(), __s, __len);
3413 __r = _S_compare(__size, __osize);
3438 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3440 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const
3442 __glibcxx_requires_string(__s);
3443 _M_check(__pos,
"basic_string::compare");
3444 __n1 = _M_limit(__pos, __n1);
3445 const size_type __osize = traits_type::length(__s);
3446 const size_type __len =
std::min(__n1, __osize);
3447 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
3449 __r = _S_compare(__n1, __osize);
3477 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3479 compare(size_type __pos, size_type __n1,
const _CharT* __s,
3480 size_type __n2)
const
3482 __glibcxx_requires_string_len(__s, __n2);
3483 _M_check(__pos,
"basic_string::compare");
3484 __n1 = _M_limit(__pos, __n1);
3485 const size_type __len =
std::min(__n1, __n2);
3486 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
3488 __r = _S_compare(__n1, __n2);
3492#if __cplusplus >= 202002L
3495 starts_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
3496 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3500 starts_with(_CharT __x)
const noexcept
3501 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3503 [[nodiscard, __gnu__::__nonnull__]]
3505 starts_with(
const _CharT* __x)
const noexcept
3506 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3510 ends_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
3511 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3515 ends_with(_CharT __x)
const noexcept
3516 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3518 [[nodiscard, __gnu__::__nonnull__]]
3520 ends_with(
const _CharT* __x)
const noexcept
3521 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3524#if __cplusplus > 202002L
3527 contains(basic_string_view<_CharT, _Traits> __x)
const noexcept
3528 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3532 contains(_CharT __x)
const noexcept
3533 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3535 [[nodiscard, __gnu__::__nonnull__]]
3537 contains(
const _CharT* __x)
const noexcept
3538 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3542 template<
typename,
typename,
typename>
friend class basic_stringbuf;
3544_GLIBCXX_END_NAMESPACE_CXX11
3545_GLIBCXX_END_NAMESPACE_VERSION
3549namespace std _GLIBCXX_VISIBILITY(default)
3551_GLIBCXX_BEGIN_NAMESPACE_VERSION
3553#if __cpp_deduction_guides >= 201606
3554_GLIBCXX_BEGIN_NAMESPACE_CXX11
3555 template<
typename _InputIterator,
typename _CharT
3556 =
typename iterator_traits<_InputIterator>::value_type,
3557 typename _Allocator = allocator<_CharT>,
3558 typename = _RequireInputIter<_InputIterator>,
3559 typename = _RequireAllocator<_Allocator>>
3560 basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
3561 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
3565 template<
typename _CharT,
typename _Traits,
3566 typename _Allocator = allocator<_CharT>,
3567 typename = _RequireAllocator<_Allocator>>
3568 basic_string(basic_string_view<_CharT, _Traits>,
const _Allocator& = _Allocator())
3569 -> basic_string<_CharT, _Traits, _Allocator>;
3571 template<
typename _CharT,
typename _Traits,
3572 typename _Allocator = allocator<_CharT>,
3573 typename = _RequireAllocator<_Allocator>>
3574 basic_string(basic_string_view<_CharT, _Traits>,
3575 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
3576 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
3577 const _Allocator& = _Allocator())
3578 -> basic_string<_CharT, _Traits, _Allocator>;
3579_GLIBCXX_END_NAMESPACE_CXX11
3582 template<
typename _Str>
3583 _GLIBCXX20_CONSTEXPR
3585 __str_concat(
typename _Str::value_type
const* __lhs,
3586 typename _Str::size_type __lhs_len,
3587 typename _Str::value_type
const* __rhs,
3588 typename _Str::size_type __rhs_len,
3589 typename _Str::allocator_type
const& __a)
3591 typedef typename _Str::allocator_type allocator_type;
3593 _Str __str(_Alloc_traits::_S_select_on_copy(__a));
3594 __str.reserve(__lhs_len + __rhs_len);
3595 __str.append(__lhs, __lhs_len);
3596 __str.append(__rhs, __rhs_len);
3607 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3608 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3609 inline basic_string<_CharT, _Traits, _Alloc>
3614 return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(),
3615 __rhs.c_str(), __rhs.size(),
3616 __lhs.get_allocator());
3625 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3626 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3627 inline basic_string<_CharT,_Traits,_Alloc>
3631 __glibcxx_requires_string(__lhs);
3633 return std::__str_concat<_Str>(__lhs, _Traits::length(__lhs),
3634 __rhs.c_str(), __rhs.size(),
3635 __rhs.get_allocator());
3644 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3645 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3646 inline basic_string<_CharT,_Traits,_Alloc>
3650 return std::__str_concat<_Str>(__builtin_addressof(__lhs), 1,
3651 __rhs.c_str(), __rhs.size(),
3652 __rhs.get_allocator());
3661 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3662 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3663 inline basic_string<_CharT, _Traits, _Alloc>
3665 const _CharT* __rhs)
3667 __glibcxx_requires_string(__rhs);
3669 return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(),
3670 __rhs, _Traits::length(__rhs),
3671 __lhs.get_allocator());
3679 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3680 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3681 inline basic_string<_CharT, _Traits, _Alloc>
3685 return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(),
3686 __builtin_addressof(__rhs), 1,
3687 __lhs.get_allocator());
3690#if __cplusplus >= 201103L
3691 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3692 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3693 inline basic_string<_CharT, _Traits, _Alloc>
3694 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3695 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3696 {
return std::move(__lhs.append(__rhs)); }
3698 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3699 _GLIBCXX20_CONSTEXPR
3700 inline basic_string<_CharT, _Traits, _Alloc>
3701 operator+(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3702 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3703 {
return std::move(__rhs.insert(0, __lhs)); }
3705 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3706 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3707 inline basic_string<_CharT, _Traits, _Alloc>
3708 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3709 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3711#if _GLIBCXX_USE_CXX11_ABI
3712 using _Alloc_traits = allocator_traits<_Alloc>;
3713 bool __use_rhs =
false;
3714 if _GLIBCXX17_CONSTEXPR (
typename _Alloc_traits::is_always_equal{})
3716 else if (__lhs.get_allocator() == __rhs.get_allocator())
3721 const auto __size = __lhs.size() + __rhs.size();
3722 if (__size > __lhs.capacity() && __size <= __rhs.capacity())
3723 return std::move(__rhs.insert(0, __lhs));
3728 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3729 _GLIBCXX_NODISCARD _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3730 inline basic_string<_CharT, _Traits, _Alloc>
3732 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3733 {
return std::move(__rhs.insert(0, __lhs)); }
3735 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3736 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3737 inline basic_string<_CharT, _Traits, _Alloc>
3739 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3740 {
return std::move(__rhs.insert(0, 1, __lhs)); }
3742 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3743 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3744 inline basic_string<_CharT, _Traits, _Alloc>
3745 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3746 const _CharT* __rhs)
3747 {
return std::move(__lhs.append(__rhs)); }
3749 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3750 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3751 inline basic_string<_CharT, _Traits, _Alloc>
3752 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3754 {
return std::move(__lhs.append(1, __rhs)); }
3757#if __glibcxx_string_view >= 202403L
3759 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3761 constexpr basic_string<_CharT, _Traits, _Alloc>
3762 operator+(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3763 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs)
3765 using _Str = basic_string<_CharT, _Traits, _Alloc>;
3766 return std::__str_concat<_Str>(__lhs.data(), __lhs.size(),
3767 __rhs.data(), __rhs.size(),
3768 __lhs.get_allocator());
3772 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3774 constexpr basic_string<_CharT, _Traits, _Alloc>
3775 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3776 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs)
3782 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3784 constexpr basic_string<_CharT, _Traits, _Alloc>
3785 operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
3786 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3788 using _Str = basic_string<_CharT, _Traits, _Alloc>;
3789 return std::__str_concat<_Str>(__lhs.data(), __lhs.size(),
3790 __rhs.data(), __rhs.size(),
3791 __rhs.get_allocator());
3795 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3797 constexpr basic_string<_CharT, _Traits, _Alloc>
3798 operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
3799 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3801 return std::move(__rhs.insert(0, __lhs));
3812 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3813 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3819 return __lhs.size() == __rhs.size()
3820 && !_Traits::compare(__lhs.data(), __rhs.data(), __lhs.size());
3829 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3830 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3833 const _CharT* __rhs)
3835 return __lhs.size() == _Traits::length(__rhs)
3836 && !_Traits::compare(__lhs.data(), __rhs, __lhs.size());
3839#if __cpp_lib_three_way_comparison
3847 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3852 ->
decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
3853 {
return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); }
3862 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3866 const _CharT* __rhs)
noexcept
3867 ->
decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
3868 {
return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); }
3876 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3879 operator==(
const _CharT* __lhs,
3880 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3881 {
return __rhs == __lhs; }
3890 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3893 operator!=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3894 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3896 {
return !(__lhs == __rhs); }
3904 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3907 operator!=(
const _CharT* __lhs,
3908 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3909 {
return !(__rhs == __lhs); }
3917 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3920 operator!=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3921 const _CharT* __rhs)
3922 {
return !(__lhs == __rhs); }
3931 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3934 operator<(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3935 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3937 {
return __lhs.compare(__rhs) < 0; }
3945 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3948 operator<(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3949 const _CharT* __rhs)
3950 {
return __lhs.compare(__rhs) < 0; }
3958 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3962 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3963 {
return __rhs.compare(__lhs) > 0; }
3972 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3975 operator>(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3976 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3978 {
return __lhs.compare(__rhs) > 0; }
3986 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3989 operator>(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3990 const _CharT* __rhs)
3991 {
return __lhs.compare(__rhs) > 0; }
3999 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4003 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4004 {
return __rhs.compare(__lhs) < 0; }
4013 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4016 operator<=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4017 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4019 {
return __lhs.compare(__rhs) <= 0; }
4027 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4030 operator<=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4031 const _CharT* __rhs)
4032 {
return __lhs.compare(__rhs) <= 0; }
4040 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4044 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4045 {
return __rhs.compare(__lhs) >= 0; }
4054 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4057 operator>=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4058 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4060 {
return __lhs.compare(__rhs) >= 0; }
4068 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4071 operator>=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4072 const _CharT* __rhs)
4073 {
return __lhs.compare(__rhs) >= 0; }
4081 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4085 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4086 {
return __rhs.compare(__lhs) <= 0; }
4096 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4097 _GLIBCXX20_CONSTEXPR
4101 _GLIBCXX_NOEXCEPT_IF(
noexcept(__lhs.swap(__rhs)))
4102 { __lhs.swap(__rhs); }
4117 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4118 basic_istream<_CharT, _Traits>&
4119 operator>>(basic_istream<_CharT, _Traits>& __is,
4120 basic_string<_CharT, _Traits, _Alloc>& __str);
4123 basic_istream<char>&
4135 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4142 return __ostream_insert(__os, __str.data(), __str.size());
4158 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4159 basic_istream<_CharT, _Traits>&
4160 getline(basic_istream<_CharT, _Traits>& __is,
4161 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
4175 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4176 inline basic_istream<_CharT, _Traits>&
4181#if __cplusplus >= 201103L
4183 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4184 inline basic_istream<_CharT, _Traits>&
4190 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4191 inline basic_istream<_CharT, _Traits>&
4198 basic_istream<char>&
4199 getline(basic_istream<char>& __in, basic_string<char>& __str,
4202#ifdef _GLIBCXX_USE_WCHAR_T
4204 basic_istream<wchar_t>&
4205 getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
4209_GLIBCXX_END_NAMESPACE_VERSION
4212#if __cplusplus >= 201103L
4217namespace std _GLIBCXX_VISIBILITY(default)
4219_GLIBCXX_BEGIN_NAMESPACE_VERSION
4220_GLIBCXX_BEGIN_NAMESPACE_CXX11
4224 stoi(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4225 {
return __gnu_cxx::__stoa<long, int>(&std::strtol,
"stoi", __str.c_str(),
4229 stol(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4230 {
return __gnu_cxx::__stoa(&std::strtol,
"stol", __str.c_str(),
4233 inline unsigned long
4234 stoul(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4235 {
return __gnu_cxx::__stoa(&std::strtoul,
"stoul", __str.c_str(),
4238#if _GLIBCXX_USE_C99_STDLIB
4240 stoll(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4241 {
return __gnu_cxx::__stoa(&std::strtoll,
"stoll", __str.c_str(),
4244 inline unsigned long long
4245 stoull(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4246 {
return __gnu_cxx::__stoa(&std::strtoull,
"stoull", __str.c_str(),
4248#elif __LONG_WIDTH__ == __LONG_LONG_WIDTH__
4250 stoll(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4251 {
return std::stol(__str, __idx, __base); }
4253 inline unsigned long long
4254 stoull(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4255 {
return std::stoul(__str, __idx, __base); }
4259 stod(
const string& __str,
size_t* __idx = 0)
4260 {
return __gnu_cxx::__stoa(&std::strtod,
"stod", __str.c_str(), __idx); }
4262#if _GLIBCXX_HAVE_STRTOF
4265 stof(
const string& __str,
size_t* __idx = 0)
4266 {
return __gnu_cxx::__stoa(&std::strtof,
"stof", __str.c_str(), __idx); }
4269 stof(
const string& __str,
size_t* __idx = 0)
4271 double __d = std::stod(__str, __idx);
4272 if (__builtin_isfinite(__d) && __d != 0.0)
4274 double __abs_d = __builtin_fabs(__d);
4275 if (__abs_d < __FLT_MIN__ || __abs_d > __FLT_MAX__)
4278 std::__throw_out_of_range(
"stof");
4285#if _GLIBCXX_HAVE_STRTOLD && ! _GLIBCXX_HAVE_BROKEN_STRTOLD
4287 stold(
const string& __str,
size_t* __idx = 0)
4288 {
return __gnu_cxx::__stoa(&std::strtold,
"stold", __str.c_str(), __idx); }
4289#elif __DBL_MANT_DIG__ == __LDBL_MANT_DIG__
4291 stold(
const string& __str,
size_t* __idx = 0)
4292 {
return std::stod(__str, __idx); }
4300 to_string(
int __val)
4301#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_INT__) <= 32
4305 const bool __neg = __val < 0;
4306 const unsigned __uval = __neg ? (unsigned)~__val + 1u : __val;
4307 const auto __len = __detail::__to_chars_len(__uval);
4309 __str.__resize_and_overwrite(__neg + __len, [=](
char* __p,
size_t __n) {
4311 __detail::__to_chars_10_impl(__p + (
int)__neg, __len, __uval);
4319 to_string(
unsigned __val)
4320#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_INT__) <= 32
4324 const auto __len = __detail::__to_chars_len(__val);
4326 __str.__resize_and_overwrite(__len, [__val](
char* __p,
size_t __n) {
4327 __detail::__to_chars_10_impl(__p, __n, __val);
4335 to_string(
long __val)
4336#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_LONG__) <= 32
4340 const bool __neg = __val < 0;
4341 const unsigned long __uval = __neg ? (
unsigned long)~__val + 1ul : __val;
4342 const auto __len = __detail::__to_chars_len(__uval);
4344 __str.__resize_and_overwrite(__neg + __len, [=](
char* __p,
size_t __n) {
4346 __detail::__to_chars_10_impl(__p + (
int)__neg, __len, __uval);
4354 to_string(
unsigned long __val)
4355#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_LONG__) <= 32
4359 const auto __len = __detail::__to_chars_len(__val);
4361 __str.__resize_and_overwrite(__len, [__val](
char* __p,
size_t __n) {
4362 __detail::__to_chars_10_impl(__p, __n, __val);
4370 to_string(
long long __val)
4372 const bool __neg = __val < 0;
4373 const unsigned long long __uval
4374 = __neg ? (
unsigned long long)~__val + 1ull : __val;
4375 const auto __len = __detail::__to_chars_len(__uval);
4377 __str.__resize_and_overwrite(__neg + __len, [=](
char* __p,
size_t __n) {
4379 __detail::__to_chars_10_impl(__p + (
int)__neg, __len, __uval);
4387 to_string(
unsigned long long __val)
4389 const auto __len = __detail::__to_chars_len(__val);
4391 __str.__resize_and_overwrite(__len, [__val](
char* __p,
size_t __n) {
4392 __detail::__to_chars_10_impl(__p, __n, __val);
4398#if __glibcxx_to_string >= 202306L
4402 to_string(
float __val)
4407 __str.resize_and_overwrite(__len,
4408 [__val, &__len] (
char* __p,
size_t __n) {
4409 auto [__end, __err] = std::to_chars(__p, __p + __n, __val);
4410 if (__err == errc{}) [[likely]]
4415 }
while (__str.empty());
4421 to_string(
double __val)
4426 __str.resize_and_overwrite(__len,
4427 [__val, &__len] (
char* __p,
size_t __n) {
4428 auto [__end, __err] = std::to_chars(__p, __p + __n, __val);
4429 if (__err == errc{}) [[likely]]
4434 }
while (__str.empty());
4440 to_string(
long double __val)
4445 __str.resize_and_overwrite(__len,
4446 [__val, &__len] (
char* __p,
size_t __n) {
4447 auto [__end, __err] = std::to_chars(__p, __p + __n, __val);
4448 if (__err == errc{}) [[likely]]
4453 }
while (__str.empty());
4456#elif _GLIBCXX_USE_C99_STDIO
4457#pragma GCC diagnostic push
4458#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
4463 to_string(
float __val)
4466 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
4467 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
4473 to_string(
double __val)
4476 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
4477 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
4483 to_string(
long double __val)
4486 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
4487 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
4490#pragma GCC diagnostic pop
4493#if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR
4495 stoi(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4496 {
return __gnu_cxx::__stoa<long, int>(&std::wcstol,
"stoi", __str.c_str(),
4500 stol(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4501 {
return __gnu_cxx::__stoa(&std::wcstol,
"stol", __str.c_str(),
4504 inline unsigned long
4505 stoul(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4506 {
return __gnu_cxx::__stoa(&std::wcstoul,
"stoul", __str.c_str(),
4510 stoll(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4511 {
return __gnu_cxx::__stoa(&std::wcstoll,
"stoll", __str.c_str(),
4514 inline unsigned long long
4515 stoull(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4516 {
return __gnu_cxx::__stoa(&std::wcstoull,
"stoull", __str.c_str(),
4521 stof(
const wstring& __str,
size_t* __idx = 0)
4522 {
return __gnu_cxx::__stoa(&std::wcstof,
"stof", __str.c_str(), __idx); }
4525 stod(
const wstring& __str,
size_t* __idx = 0)
4526 {
return __gnu_cxx::__stoa(&std::wcstod,
"stod", __str.c_str(), __idx); }
4529 stold(
const wstring& __str,
size_t* __idx = 0)
4530 {
return __gnu_cxx::__stoa(&std::wcstold,
"stold", __str.c_str(), __idx); }
4533#ifdef _GLIBCXX_USE_WCHAR_T
4534#pragma GCC diagnostic push
4535#pragma GCC diagnostic ignored "-Wc++17-extensions"
4536 _GLIBCXX20_CONSTEXPR
4538 __to_wstring_numeric(
const char* __s,
int __len,
wchar_t* __wout)
4542 if constexpr (wchar_t(
'0') == L
'0' && wchar_t(
'-') == L
'-'
4543 && wchar_t(
'.') == L
'.' && wchar_t(
'e') == L
'e')
4545 for (
int __i = 0; __i < __len; ++__i)
4546 __wout[__i] = (
wchar_t) __s[__i];
4551 for (
int __i =
'0'; __i <=
'9'; ++__i)
4552 __wc[__i] = L
'0' + __i;
4575 for (
int __i = 0; __i < __len; ++__i)
4576 __wout[__i] = __wc[(
int)__s[__i]];
4580#if __glibcxx_constexpr_string >= 201907L
4584#if __cplusplus >= 201703L
4585 __to_wstring_numeric(string_view __s)
4587 __to_wstring_numeric(
const string& __s)
4590 if constexpr (wchar_t(
'0') == L
'0' && wchar_t(
'-') == L
'-'
4591 && wchar_t(
'.') == L
'.' && wchar_t(
'e') == L
'e')
4592 return wstring(__s.data(), __s.data() + __s.size());
4596 auto __f = __s.data();
4597 __ws.__resize_and_overwrite(__s.size(),
4598 [__f] (
wchar_t* __to,
int __n) {
4599 std::__to_wstring_numeric(__f, __n, __to);
4605#pragma GCC diagnostic pop
4609 to_wstring(
int __val)
4610 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4614 to_wstring(
unsigned __val)
4615 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4619 to_wstring(
long __val)
4620 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4624 to_wstring(
unsigned long __val)
4625 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4629 to_wstring(
long long __val)
4630 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4634 to_wstring(
unsigned long long __val)
4635 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4637#if __glibcxx_to_string || _GLIBCXX_USE_C99_STDIO
4640 to_wstring(
float __val)
4641 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4645 to_wstring(
double __val)
4646 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4650 to_wstring(
long double __val)
4651 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4655_GLIBCXX_END_NAMESPACE_CXX11
4656_GLIBCXX_END_NAMESPACE_VERSION
4661#if __cplusplus >= 201103L
4665namespace std _GLIBCXX_VISIBILITY(default)
4667_GLIBCXX_BEGIN_NAMESPACE_VERSION
4672 template<
typename _CharT,
typename _Alloc,
4673 typename _StrT = basic_string<_CharT, char_traits<_CharT>, _Alloc>>
4674 struct __str_hash_base
4675 :
public __hash_base<size_t, _StrT>
4679 operator()(
const _StrT& __s)
const noexcept
4680 {
return _Hash_impl::hash(__s.data(), __s.length() *
sizeof(_CharT)); }
4683#ifndef _GLIBCXX_COMPATIBILITY_CXX0X
4685 template<
typename _Alloc>
4687 :
public __str_hash_base<char, _Alloc>
4691 template<
typename _Alloc>
4693 :
public __str_hash_base<wchar_t, _Alloc>
4696 template<
typename _Alloc>
4703#ifdef _GLIBCXX_USE_CHAR8_T
4705 template<
typename _Alloc>
4706 struct hash<basic_string<char8_t, char_traits<char8_t>, _Alloc>>
4707 :
public __str_hash_base<char8_t, _Alloc>
4712 template<
typename _Alloc>
4714 :
public __str_hash_base<char16_t, _Alloc>
4718 template<
typename _Alloc>
4720 :
public __str_hash_base<char32_t, _Alloc>
4723#if ! _GLIBCXX_INLINE_VERSION
4729#ifdef _GLIBCXX_USE_CHAR8_T
4730 template<>
struct __is_fast_hash<hash<u8string>> :
std::false_type { };
4734 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4735 struct __is_fast_hash<hash<basic_string<_CharT, _Traits, _Alloc>>>
4740#ifdef __glibcxx_string_udls
4741 inline namespace literals
4743 inline namespace string_literals
4745#pragma GCC diagnostic push
4746#pragma GCC diagnostic ignored "-Wliteral-suffix"
4748#if __glibcxx_constexpr_string >= 201907L
4749# define _GLIBCXX_STRING_CONSTEXPR constexpr
4751# define _GLIBCXX_STRING_CONSTEXPR
4754 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4755 inline basic_string<char>
4756 operator""s(
const char* __str,
size_t __len)
4757 {
return basic_string<char>{__str, __len}; }
4759 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4760 inline basic_string<wchar_t>
4761 operator""s(
const wchar_t* __str,
size_t __len)
4762 {
return basic_string<wchar_t>{__str, __len}; }
4764#ifdef _GLIBCXX_USE_CHAR8_T
4765 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4766 inline basic_string<char8_t>
4767 operator""s(
const char8_t* __str,
size_t __len)
4768 {
return basic_string<char8_t>{__str, __len}; }
4771 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4772 inline basic_string<char16_t>
4773 operator""s(
const char16_t* __str,
size_t __len)
4774 {
return basic_string<char16_t>{__str, __len}; }
4776 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4777 inline basic_string<char32_t>
4778 operator""s(
const char32_t* __str,
size_t __len)
4779 {
return basic_string<char32_t>{__str, __len}; }
4781#undef _GLIBCXX_STRING_CONSTEXPR
4782#pragma GCC diagnostic pop
4787#if __cplusplus >= 201703L
4788 namespace __detail::__variant
4790 template<
typename>
struct _Never_valueless_alt;
4794 template<
typename _Tp,
typename _Traits,
typename _Alloc>
4795 struct _Never_valueless_alt<
std::basic_string<_Tp, _Traits, _Alloc>>
4797 is_nothrow_move_constructible<std::basic_string<_Tp, _Traits, _Alloc>>,
4798 is_nothrow_move_assignable<std::basic_string<_Tp, _Traits, _Alloc>>
4804_GLIBCXX_END_NAMESPACE_VERSION
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator<(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
constexpr _Tp * to_address(_Tp *__ptr) noexcept
Obtain address referenced by a pointer to an object.
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
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 _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
basic_string< char32_t > u32string
A string of char32_t.
basic_string< char16_t > u16string
A string of char16_t.
basic_string< wchar_t > wstring
A string of wchar_t.
ISO C++ entities toplevel namespace is std.
basic_istream< _CharT, _Traits > & getline(basic_istream< _CharT, _Traits > &__is, basic_string< _CharT, _Traits, _Alloc > &__str, _CharT __delim)
Read a line from stream into a string.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
char_type widen(char __c) const
Widens characters.
Template class basic_istream.
Template class basic_ostream.
Primary class template hash.
Basis for explicit traits specializations.
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.
void push_back(_CharT __c)
Append a single character.
const_iterator cend() const noexcept
size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
const _CharT * data() const noexcept
Return const pointer to contents.
void __resize_and_overwrite(size_type __n, _Operation __op)
Non-standard version of resize_and_overwrite for C++11 and above.
basic_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
size_type find(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find position of a C substring.
size_type find_last_not_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character not in string.
int compare(const basic_string &__str) const
Compare to a string.
size_type find_first_not_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character not in string.
void insert(iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
reverse_iterator rbegin()
void pop_back()
Remove the last character.
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 & operator+=(const basic_string &__str)
Append a string to this string.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
size_type rfind(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a string.
void shrink_to_fit() noexcept
A non-binding request to reduce capacity() to size().
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
void reserve()
Equivalent to shrink_to_fit().
const_reference at(size_type __n) const
Provides access to the data contained in the string.
basic_string & append(const basic_string &__str)
Append a string to this string.
const_reverse_iterator crend() const noexcept
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.
bool empty() const noexcept
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
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.
const_iterator cbegin() const noexcept
~basic_string() noexcept
Destroy the string instance.
size_type capacity() const noexcept
basic_string() noexcept
Default constructor creates an empty string.
size_type max_size() const noexcept
Returns the size() of the largest possible string.
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
Uniform interface to all pointer-like types.
Forward iterators support a superset of input iterator operations.
Uniform interface to C++98 and C++11 allocators.