34#ifndef _BASIC_STRING_H
35#define _BASIC_STRING_H 1
38#pragma GCC system_header
44#if __cplusplus >= 201103L
50#ifdef __glibcxx_string_view
54#if __cplusplus > 202302L
59#if ! _GLIBCXX_USE_CXX11_ABI
63namespace std _GLIBCXX_VISIBILITY(default)
65_GLIBCXX_BEGIN_NAMESPACE_VERSION
66_GLIBCXX_BEGIN_NAMESPACE_CXX11
88 template<
typename _CharT,
typename _Traits,
typename _Alloc>
91#if __cplusplus >= 202002L
92 static_assert(is_trivially_copyable_v<_CharT>
93 && is_trivially_default_constructible_v<_CharT>
94 && is_standard_layout_v<_CharT>);
95 static_assert(is_same_v<_CharT, typename _Traits::char_type>);
96 static_assert(is_same_v<_CharT, typename _Alloc::value_type>);
97 using _Char_alloc_type = _Alloc;
100 rebind<_CharT>::other _Char_alloc_type;
107 typedef _Traits traits_type;
108 typedef typename _Traits::char_type value_type;
109 typedef _Char_alloc_type allocator_type;
110 typedef typename _Alloc_traits::size_type size_type;
111 typedef typename _Alloc_traits::difference_type difference_type;
112 typedef typename _Alloc_traits::reference reference;
113 typedef typename _Alloc_traits::const_reference const_reference;
114 typedef typename _Alloc_traits::pointer pointer;
115 typedef typename _Alloc_traits::const_pointer const_pointer;
116 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
117 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
123 static const size_type
npos =
static_cast<size_type
>(-1);
127#if __cplusplus < 201103L
128 typedef iterator __const_iterator;
130 typedef const_iterator __const_iterator;
134 static _GLIBCXX20_CONSTEXPR pointer
135 _S_allocate(_Char_alloc_type& __a, size_type __n)
137 pointer __p = _Alloc_traits::allocate(__a, __n);
138#if __glibcxx_constexpr_string >= 201907L
141 if constexpr (!is_same_v<_Traits, char_traits<_CharT>>)
142 if (std::__is_constant_evaluated())
144 for (size_type __i = 0; __i < __n; ++__i)
145 std::construct_at(__builtin_addressof(__p[__i]));
150#ifdef __glibcxx_string_view
152 typedef basic_string_view<_CharT, _Traits> __sv_type;
154 template<
typename _Tp,
typename _Res>
156 __and_<is_convertible<const _Tp&, __sv_type>,
157 __not_<is_convertible<const _Tp*, const basic_string*>>,
158 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
164 _S_to_string_view(__sv_type __svt)
noexcept
173 _GLIBCXX20_CONSTEXPR
explicit
174 __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
192 struct _Alloc_hider : allocator_type
194#if __cplusplus < 201103L
195 _Alloc_hider(pointer __dat,
const _Alloc& __a = _Alloc())
196 : allocator_type(__a), _M_p(__dat) { }
199 _Alloc_hider(pointer __dat,
const _Alloc& __a)
200 : allocator_type(__a), _M_p(__dat) { }
203 _Alloc_hider(pointer __dat, _Alloc&& __a = _Alloc())
204 : allocator_type(
std::
move(__a)), _M_p(__dat) { }
210 _Alloc_hider _M_dataplus;
211 size_type _M_string_length;
213 enum { _S_local_capacity = 15 /
sizeof(_CharT) };
217 _CharT _M_local_buf[_S_local_capacity + 1];
218 size_type _M_allocated_capacity;
224 { _M_dataplus._M_p = __p; }
228 _M_length(size_type __length)
229 { _M_string_length = __length; }
234 {
return _M_dataplus._M_p; }
240#if __cplusplus >= 201103L
243 return pointer(_M_local_buf);
249 _M_local_data()
const
251#if __cplusplus >= 201103L
254 return const_pointer(_M_local_buf);
260 _M_capacity(size_type __capacity)
261 { _M_allocated_capacity = __capacity; }
265 _M_set_length(size_type __n)
268 traits_type::assign(_M_data()[__n], _CharT());
275 if (_M_data() == _M_local_data())
277 if (_M_string_length > _S_local_capacity)
278 __builtin_unreachable();
287 _M_create(size_type&, size_type);
294 _M_destroy(_M_allocated_capacity);
299 _M_destroy(size_type __size)
throw()
300 { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); }
302#if __cplusplus < 201103L || defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
305 template<
typename _InIterator>
307 _M_construct_aux(_InIterator __beg, _InIterator __end,
310 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
311 _M_construct(__beg, __end, _Tag());
316 template<
typename _Integer>
318 _M_construct_aux(_Integer __beg, _Integer __end, std::__true_type)
319 { _M_construct_aux_2(
static_cast<size_type
>(__beg), __end); }
322 _M_construct_aux_2(size_type __req, _CharT __c)
323 { _M_construct(__req, __c); }
327 template<
typename _InIterator>
330 _M_construct(_InIterator __beg, _InIterator __end,
335 template<
typename _FwdIterator>
338 _M_construct(_FwdIterator __beg, _FwdIterator __end,
343 _M_construct(size_type __req, _CharT __c);
347 template<
bool _Terminated>
350 _M_construct(
const _CharT *__c, size_type __n);
355 {
return _M_dataplus; }
358 const allocator_type&
359 _M_get_allocator()
const
360 {
return _M_dataplus; }
363 __attribute__((__always_inline__))
366 _M_init_local_buf() _GLIBCXX_NOEXCEPT
368#if __glibcxx_is_constant_evaluated
369 if (std::is_constant_evaluated())
370 for (size_type __i = 0; __i <= _S_local_capacity; ++__i)
371 _M_local_buf[__i] = _CharT();
375 __attribute__((__always_inline__))
378 _M_use_local_data() _GLIBCXX_NOEXCEPT
380#if __cpp_lib_is_constant_evaluated
383 return _M_local_data();
388#ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
391 template<
typename _Tp,
bool _Requires =
392 !__are_same<_Tp, _CharT*>::__value
393 && !__are_same<_Tp, const _CharT*>::__value
394 && !__are_same<_Tp, iterator>::__value
395 && !__are_same<_Tp, const_iterator>::__value>
396 struct __enable_if_not_native_iterator
397 {
typedef basic_string& __type; };
398 template<
typename _Tp>
399 struct __enable_if_not_native_iterator<_Tp, false> { };
404 _M_check(size_type __pos,
const char* __s)
const
406 if (__pos > this->
size())
407 __throw_out_of_range_fmt(__N(
"%s: __pos (which is %zu) > "
408 "this->size() (which is %zu)"),
409 __s, __pos, this->
size());
415 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
418 __throw_length_error(__N(__s));
425 _M_limit(size_type __pos, size_type __off)
const _GLIBCXX_NOEXCEPT
427 const bool __testoff = __off < this->
size() - __pos;
428 return __testoff ? __off : this->
size() - __pos;
433 _M_disjunct(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
435 return (less<const _CharT*>()(__s, _M_data())
436 || less<const _CharT*>()(_M_data() + this->
size(), __s));
443 _S_copy(_CharT* __d,
const _CharT* __s, size_type __n)
446 traits_type::assign(*__d, *__s);
448 traits_type::copy(__d, __s, __n);
453 _S_move(_CharT* __d,
const _CharT* __s, size_type __n)
456 traits_type::assign(*__d, *__s);
458 traits_type::move(__d, __s, __n);
463 _S_assign(_CharT* __d, size_type __n, _CharT __c)
466 traits_type::assign(*__d, __c);
468 traits_type::assign(__d, __n, __c);
473 template<
class _Iterator>
476 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
478 for (; __k1 != __k2; ++__k1, (void)++__p)
479 traits_type::assign(*__p, *__k1);
484 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
485 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
489 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
491 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
495 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
496 { _S_copy(__p, __k1, __k2 - __k1); }
500 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
502 { _S_copy(__p, __k1, __k2 - __k1); }
506 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
508 const difference_type __d = difference_type(__n1 - __n2);
510 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
511 return __gnu_cxx::__numeric_traits<int>::__max;
512 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
513 return __gnu_cxx::__numeric_traits<int>::__min;
524 _M_mutate(size_type __pos, size_type __len1,
const _CharT* __s,
529 _M_erase(size_type __pos, size_type __n);
541 _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value)
542#if __cpp_concepts && __glibcxx_type_trait_variable_templates
543 requires is_default_constructible_v<_Alloc>
545 : _M_dataplus(_M_local_data())
557 : _M_dataplus(_M_local_data(), __a)
569 : _M_dataplus(_M_local_data(),
570 _Alloc_traits::_S_select_on_copy(__str._M_get_allocator()))
572 _M_construct<true>(__str._M_data(), __str.length());
585 const _Alloc& __a = _Alloc())
586 : _M_dataplus(_M_local_data(), __a)
588 const _CharT* __start = __str._M_data()
589 + __str._M_check(__pos,
"basic_string::basic_string");
590 _M_construct(__start, __start + __str._M_limit(__pos,
npos),
603 : _M_dataplus(_M_local_data())
605 const _CharT* __start = __str._M_data()
606 + __str._M_check(__pos,
"basic_string::basic_string");
607 _M_construct(__start, __start + __str._M_limit(__pos, __n),
620 size_type __n,
const _Alloc& __a)
621 : _M_dataplus(_M_local_data(), __a)
623 const _CharT* __start
624 = __str._M_data() + __str._M_check(__pos,
"string::string");
625 _M_construct(__start, __start + __str._M_limit(__pos, __n),
640 const _Alloc& __a = _Alloc())
641 : _M_dataplus(_M_local_data(), __a)
644 if (__s == 0 && __n > 0)
645 std::__throw_logic_error(__N(
"basic_string: "
646 "construction from null is not valid"));
655#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
658 template<
typename = _RequireAllocator<_Alloc>>
661 basic_string(
const _CharT* __s,
const _Alloc& __a = _Alloc())
662 : _M_dataplus(_M_local_data(), __a)
666 std::__throw_logic_error(__N(
"basic_string: "
667 "construction from null is not valid"));
668 const _CharT* __end = __s + traits_type::length(__s);
669 _M_construct(__s, __end, forward_iterator_tag());
678#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
681 template<
typename = _RequireAllocator<_Alloc>>
684 basic_string(size_type __n, _CharT __c,
const _Alloc& __a = _Alloc())
685 : _M_dataplus(_M_local_data(), __a)
686 { _M_construct(__n, __c); }
688#if __cplusplus >= 201103L
698 : _M_dataplus(_M_local_data(),
std::move(__str._M_get_allocator()))
700 if (__str._M_is_local())
703 traits_type::copy(_M_local_buf, __str._M_local_buf,
708 _M_data(__str._M_data());
709 _M_capacity(__str._M_allocated_capacity);
715 _M_length(__str.length());
716 __str._M_data(__str._M_use_local_data());
717 __str._M_set_length(0);
726 basic_string(initializer_list<_CharT> __l,
const _Alloc& __a = _Alloc())
727 : _M_dataplus(_M_local_data(), __a)
732 : _M_dataplus(_M_local_data(), __a)
737 noexcept(_Alloc_traits::_S_always_equal())
738 : _M_dataplus(_M_local_data(), __a)
740 if (__str._M_is_local())
743 traits_type::copy(_M_local_buf, __str._M_local_buf,
745 _M_length(__str.length());
746 __str._M_set_length(0);
748 else if (_Alloc_traits::_S_always_equal()
749 || __str.get_allocator() == __a)
751 _M_data(__str._M_data());
752 _M_length(__str.length());
753 _M_capacity(__str._M_allocated_capacity);
754 __str._M_data(__str._M_use_local_data());
755 __str._M_set_length(0);
762#if __cplusplus >= 202100L
773#if __cplusplus >= 201103L
774 template<
typename _InputIterator,
775 typename = std::_RequireInputIter<_InputIterator>>
777 template<
typename _InputIterator>
780 basic_string(_InputIterator __beg, _InputIterator __end,
781 const _Alloc& __a = _Alloc())
782 : _M_dataplus(_M_local_data(), __a), _M_string_length(0)
784#if __cplusplus >= 201103L
787 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
788 _M_construct_aux(__beg, __end, _Integral());
792#ifdef __glibcxx_string_view
800 template<
typename _Tp,
801 typename = enable_if_t<is_convertible_v<const _Tp&, __sv_type>>>
803 basic_string(
const _Tp& __t, size_type __pos, size_type __n,
804 const _Alloc& __a = _Alloc())
812 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
815 basic_string(
const _Tp& __t,
const _Alloc& __a = _Alloc())
816 :
basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
834 return this->
assign(__str);
844 {
return this->
assign(__s); }
861#if __cplusplus >= 201103L
874 noexcept(_Alloc_traits::_S_nothrow_move())
876 const bool __equal_allocs = _Alloc_traits::_S_always_equal()
877 || _M_get_allocator() == __str._M_get_allocator();
878 if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign()
882 _M_destroy(_M_allocated_capacity);
883 _M_data(_M_local_data());
887 std::__alloc_on_move(_M_get_allocator(), __str._M_get_allocator());
889 if (__str._M_is_local())
897 this->_S_copy(_M_data(), __str._M_data(), __str.size());
898 _M_set_length(__str.size());
901 else if (_Alloc_traits::_S_propagate_on_move_assign() || __equal_allocs)
904 pointer __data =
nullptr;
905 size_type __capacity;
912 __capacity = _M_allocated_capacity;
915 _M_destroy(_M_allocated_capacity);
918 _M_data(__str._M_data());
919 _M_length(__str.length());
920 _M_capacity(__str._M_allocated_capacity);
923 __str._M_data(__data);
924 __str._M_capacity(__capacity);
927 __str._M_data(__str._M_use_local_data());
943 this->
assign(__l.begin(), __l.size());
948#ifdef __glibcxx_string_view
953 template<
typename _Tp>
955 _If_sv<_Tp, basic_string&>
957 {
return this->
assign(__svt); }
964 operator __sv_type() const noexcept
965 {
return __sv_type(
data(),
size()); }
973 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
975 begin() _GLIBCXX_NOEXCEPT
976 {
return iterator(_M_data()); }
982 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
984 begin() const _GLIBCXX_NOEXCEPT
985 {
return const_iterator(_M_data()); }
991 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
993 end() _GLIBCXX_NOEXCEPT
994 {
return iterator(_M_data() + this->
size()); }
1000 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1002 end() const _GLIBCXX_NOEXCEPT
1003 {
return const_iterator(_M_data() + this->
size()); }
1010 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1012 rbegin() _GLIBCXX_NOEXCEPT
1013 {
return reverse_iterator(this->
end()); }
1020 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1021 const_reverse_iterator
1022 rbegin() const _GLIBCXX_NOEXCEPT
1023 {
return const_reverse_iterator(this->
end()); }
1030 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1032 rend() _GLIBCXX_NOEXCEPT
1033 {
return reverse_iterator(this->
begin()); }
1040 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1041 const_reverse_iterator
1042 rend() const _GLIBCXX_NOEXCEPT
1043 {
return const_reverse_iterator(this->
begin()); }
1045#if __cplusplus >= 201103L
1050 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1053 {
return const_iterator(this->_M_data()); }
1059 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1061 cend() const noexcept
1062 {
return const_iterator(this->_M_data() + this->
size()); }
1069 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1070 const_reverse_iterator
1072 {
return const_reverse_iterator(this->
end()); }
1079 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1080 const_reverse_iterator
1081 crend() const noexcept
1082 {
return const_reverse_iterator(this->
begin()); }
1089 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1091 size() const _GLIBCXX_NOEXCEPT
1093 size_type __sz = _M_string_length;
1095 __builtin_unreachable ();
1101 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1103 length() const _GLIBCXX_NOEXCEPT
1107 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1111 const size_t __diffmax
1112 = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max /
sizeof(_CharT);
1113 const size_t __allocmax = _Alloc_traits::max_size(_M_get_allocator());
1114 return (
std::min)(__diffmax, __allocmax) - 1;
1127 _GLIBCXX20_CONSTEXPR
1129 resize(size_type __n, _CharT __c);
1141 _GLIBCXX20_CONSTEXPR
1144 { this->
resize(__n, _CharT()); }
1146#if __cplusplus >= 201103L
1147#pragma GCC diagnostic push
1148#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1150 _GLIBCXX20_CONSTEXPR
1154#pragma GCC diagnostic pop
1157#ifdef __glibcxx_string_resize_and_overwrite
1187 template<
typename _Operation>
1189 resize_and_overwrite(size_type __n, _Operation __op);
1192#if __cplusplus >= 201103L
1194 template<
typename _Operation>
1195 _GLIBCXX20_CONSTEXPR
void
1203 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1207 size_t __sz = _M_is_local() ? size_type(_S_local_capacity)
1208 : _M_allocated_capacity;
1209 if (__sz < _S_local_capacity || __sz >
max_size ())
1210 __builtin_unreachable ();
1231 _GLIBCXX20_CONSTEXPR
1238#if __cplusplus > 201703L
1239 [[deprecated(
"use shrink_to_fit() instead")]]
1241 _GLIBCXX20_CONSTEXPR
1248 _GLIBCXX20_CONSTEXPR
1250 clear() _GLIBCXX_NOEXCEPT
1251 { _M_set_length(0); }
1257 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1259 empty() const _GLIBCXX_NOEXCEPT
1260 {
return _M_string_length == 0; }
1273 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1275 operator[] (size_type __pos)
const _GLIBCXX_NOEXCEPT
1277 __glibcxx_assert(__pos <=
size());
1278 return _M_data()[__pos];
1291 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1297 __glibcxx_assert(__pos <=
size());
1299 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos <
size());
1300 return _M_data()[__pos];
1313 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1315 at(size_type __n)
const
1317 if (__n >= this->
size())
1318 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1319 "(which is %zu) >= this->size() "
1322 return _M_data()[__n];
1335 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1340 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1341 "(which is %zu) >= this->size() "
1344 return _M_data()[__n];
1347#if __cplusplus >= 201103L
1352 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1356 __glibcxx_assert(!
empty());
1364 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1366 front() const noexcept
1368 __glibcxx_assert(!
empty());
1376 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1380 __glibcxx_assert(!
empty());
1388 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1390 back() const noexcept
1392 __glibcxx_assert(!
empty());
1403 _GLIBCXX20_CONSTEXPR
1406 {
return this->
append(__str); }
1413 _GLIBCXX20_CONSTEXPR
1416 {
return this->
append(__s); }
1423 _GLIBCXX20_CONSTEXPR
1431#if __cplusplus >= 201103L
1437 _GLIBCXX20_CONSTEXPR
1440 {
return this->
append(__l.begin(), __l.size()); }
1443#ifdef __glibcxx_string_view
1449 template<
typename _Tp>
1450 _GLIBCXX20_CONSTEXPR
1451 _If_sv<_Tp, basic_string&>
1453 {
return this->
append(__svt); }
1461 _GLIBCXX20_CONSTEXPR
1464 {
return this->
append(__str._M_data(), __str.size()); }
1479 _GLIBCXX20_CONSTEXPR
1482 {
return this->
append(__str._M_data()
1483 + __str._M_check(__pos,
"basic_string::append"),
1484 __str._M_limit(__pos, __n)); }
1492 _GLIBCXX20_CONSTEXPR
1494 append(
const _CharT* __s, size_type __n)
1496 __glibcxx_requires_string_len(__s, __n);
1497 _M_check_length(size_type(0), __n,
"basic_string::append");
1498 return _M_append(__s, __n);
1506 _GLIBCXX20_CONSTEXPR
1508 append(
const _CharT* __s)
1510 __glibcxx_requires_string(__s);
1511 const size_type __n = traits_type::length(__s);
1512 _M_check_length(size_type(0), __n,
"basic_string::append");
1513 return _M_append(__s, __n);
1524 _GLIBCXX20_CONSTEXPR
1526 append(size_type __n, _CharT __c)
1527 {
return _M_replace_aux(this->
size(), size_type(0), __n, __c); }
1529#if __cplusplus >= 201103L
1535 _GLIBCXX20_CONSTEXPR
1537 append(initializer_list<_CharT> __l)
1538 {
return this->
append(__l.begin(), __l.size()); }
1549#if __cplusplus >= 201103L
1550 template<
class _InputIterator,
1551 typename = std::_RequireInputIter<_InputIterator>>
1552 _GLIBCXX20_CONSTEXPR
1554 template<
class _InputIterator>
1557 append(_InputIterator __first, _InputIterator __last)
1560#ifdef __glibcxx_string_view
1566 template<
typename _Tp>
1567 _GLIBCXX20_CONSTEXPR
1568 _If_sv<_Tp, basic_string&>
1571 __sv_type __sv = __svt;
1572 return this->
append(__sv.data(), __sv.size());
1582 template<
typename _Tp>
1583 _GLIBCXX20_CONSTEXPR
1584 _If_sv<_Tp, basic_string&>
1585 append(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
1587 __sv_type __sv = __svt;
1588 return _M_append(__sv.data()
1589 + std::__sv_check(__sv.size(), __pos,
"basic_string::append"),
1590 std::__sv_limit(__sv.size(), __pos, __n));
1598 _GLIBCXX20_CONSTEXPR
1602 const size_type __size = this->
size();
1604 this->_M_mutate(__size, size_type(0), 0, size_type(1));
1605 traits_type::assign(this->_M_data()[__size], __c);
1606 this->_M_set_length(__size + 1);
1614 _GLIBCXX20_CONSTEXPR
1618#if __cplusplus >= 201103L
1619 if (_Alloc_traits::_S_propagate_on_copy_assign())
1621 if (!_Alloc_traits::_S_always_equal() && !_M_is_local()
1622 && _M_get_allocator() != __str._M_get_allocator())
1626 if (__str.size() <= _S_local_capacity)
1628 _M_destroy(_M_allocated_capacity);
1629 _M_data(_M_use_local_data());
1634 const auto __len = __str.size();
1635 auto __alloc = __str._M_get_allocator();
1637 auto __ptr = _S_allocate(__alloc, __len + 1);
1638 _M_destroy(_M_allocated_capacity);
1641 _M_set_length(__len);
1644 std::__alloc_on_copy(_M_get_allocator(), __str._M_get_allocator());
1647 this->_M_assign(__str);
1651#if __cplusplus >= 201103L
1660 _GLIBCXX20_CONSTEXPR
1663 noexcept(_Alloc_traits::_S_nothrow_move())
1684 _GLIBCXX20_CONSTEXPR
1687 {
return _M_replace(size_type(0), this->
size(), __str._M_data()
1688 + __str._M_check(__pos,
"basic_string::assign"),
1689 __str._M_limit(__pos, __n)); }
1701 _GLIBCXX20_CONSTEXPR
1703 assign(
const _CharT* __s, size_type __n)
1705 __glibcxx_requires_string_len(__s, __n);
1706 return _M_replace(size_type(0), this->
size(), __s, __n);
1718 _GLIBCXX20_CONSTEXPR
1720 assign(
const _CharT* __s)
1722 __glibcxx_requires_string(__s);
1723 return _M_replace(size_type(0), this->
size(), __s,
1724 traits_type::length(__s));
1736 _GLIBCXX20_CONSTEXPR
1738 assign(size_type __n, _CharT __c)
1739 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
1749#if __cplusplus >= 201103L
1750#pragma GCC diagnostic push
1751#pragma GCC diagnostic ignored "-Wc++17-extensions"
1752 template<
class _InputIterator,
1753 typename = std::_RequireInputIter<_InputIterator>>
1754 _GLIBCXX20_CONSTEXPR
1756 assign(_InputIterator __first, _InputIterator __last)
1758 using _IterTraits = iterator_traits<_InputIterator>;
1759 if constexpr (is_pointer<
decltype(std::__niter_base(__first))>::value
1760 && is_same<
typename _IterTraits::value_type,
1763 __glibcxx_requires_valid_range(__first, __last);
1764 return _M_replace(size_type(0),
size(),
1765 std::__niter_base(__first), __last - __first);
1767#if __cplusplus >= 202002L
1768 else if constexpr (contiguous_iterator<_InputIterator>
1769 && is_same_v<iter_value_t<_InputIterator>,
1772 __glibcxx_requires_valid_range(__first, __last);
1773 return _M_replace(size_type(0),
size(),
1780#pragma GCC diagnostic pop
1782 template<
class _InputIterator>
1784 assign(_InputIterator __first, _InputIterator __last)
1788#if __cplusplus >= 201103L
1794 _GLIBCXX20_CONSTEXPR
1796 assign(initializer_list<_CharT> __l)
1800 const size_type __n = __l.
size();
1806 _S_copy(_M_data(), __l.begin(), __n);
1813#ifdef __glibcxx_string_view
1819 template<
typename _Tp>
1820 _GLIBCXX20_CONSTEXPR
1821 _If_sv<_Tp, basic_string&>
1824 __sv_type __sv = __svt;
1825 return this->
assign(__sv.data(), __sv.size());
1835 template<
typename _Tp>
1836 _GLIBCXX20_CONSTEXPR
1837 _If_sv<_Tp, basic_string&>
1838 assign(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
1840 __sv_type __sv = __svt;
1841 return _M_replace(size_type(0), this->
size(),
1843 + std::__sv_check(__sv.size(), __pos,
"basic_string::assign"),
1844 std::__sv_limit(__sv.size(), __pos, __n));
1848#if __cplusplus >= 201103L
1864 _GLIBCXX20_CONSTEXPR
1866 insert(const_iterator __p, size_type __n, _CharT __c)
1868 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1869 const size_type __pos = __p -
begin();
1870 this->
replace(__p, __p, __n, __c);
1871 return iterator(this->_M_data() + __pos);
1888 insert(iterator __p, size_type __n, _CharT __c)
1889 { this->
replace(__p, __p, __n, __c); }
1892#if __cplusplus >= 201103L
1907 template<
class _InputIterator,
1908 typename = std::_RequireInputIter<_InputIterator>>
1909 _GLIBCXX20_CONSTEXPR
1911 insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
1913 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1914 const size_type __pos = __p -
begin();
1915 this->
replace(__p, __p, __beg, __end);
1916 return iterator(this->_M_data() + __pos);
1931 template<
class _InputIterator>
1933 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1934 { this->
replace(__p, __p, __beg, __end); }
1937#if __cplusplus >= 201103L
1944 _GLIBCXX20_CONSTEXPR
1946 insert(const_iterator __p, initializer_list<_CharT> __l)
1947 {
return this->
insert(__p, __l.begin(), __l.end()); }
1949#ifdef _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
1952 insert(iterator __p, initializer_list<_CharT> __l)
1954 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1955 this->
insert(__p -
begin(), __l.begin(), __l.size());
1972 _GLIBCXX20_CONSTEXPR
1975 {
return this->
replace(__pos1, size_type(0),
1976 __str._M_data(), __str.size()); }
1996 _GLIBCXX20_CONSTEXPR
1999 size_type __pos2, size_type __n =
npos)
2000 {
return this->
replace(__pos1, size_type(0), __str._M_data()
2001 + __str._M_check(__pos2,
"basic_string::insert"),
2002 __str._M_limit(__pos2, __n)); }
2020 _GLIBCXX20_CONSTEXPR
2022 insert(size_type __pos,
const _CharT* __s, size_type __n)
2023 {
return this->
replace(__pos, size_type(0), __s, __n); }
2040 _GLIBCXX20_CONSTEXPR
2042 insert(size_type __pos,
const _CharT* __s)
2044 __glibcxx_requires_string(__s);
2045 return this->
replace(__pos, size_type(0), __s,
2046 traits_type::length(__s));
2065 _GLIBCXX20_CONSTEXPR
2067 insert(size_type __pos, size_type __n, _CharT __c)
2068 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
2069 size_type(0), __n, __c); }
2084 _GLIBCXX20_CONSTEXPR
2086 insert(__const_iterator __p, _CharT __c)
2088 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
2089 const size_type __pos = __p -
begin();
2090 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
2091 return iterator(_M_data() + __pos);
2094#ifdef __glibcxx_string_view
2101 template<
typename _Tp>
2102 _GLIBCXX20_CONSTEXPR
2103 _If_sv<_Tp, basic_string&>
2104 insert(size_type __pos,
const _Tp& __svt)
2106 __sv_type __sv = __svt;
2107 return this->
insert(__pos, __sv.data(), __sv.size());
2118 template<
typename _Tp>
2119 _GLIBCXX20_CONSTEXPR
2120 _If_sv<_Tp, basic_string&>
2121 insert(size_type __pos1,
const _Tp& __svt,
2122 size_type __pos2, size_type __n =
npos)
2124 __sv_type __sv = __svt;
2125 return this->
replace(__pos1, size_type(0),
2127 + std::__sv_check(__sv.size(), __pos2,
"basic_string::insert"),
2128 std::__sv_limit(__sv.size(), __pos2, __n));
2147 _GLIBCXX20_CONSTEXPR
2149 erase(size_type __pos = 0, size_type __n =
npos)
2151 _M_check(__pos,
"basic_string::erase");
2153 this->_M_set_length(__pos);
2155 this->_M_erase(__pos, _M_limit(__pos, __n));
2167 _GLIBCXX20_CONSTEXPR
2169 erase(__const_iterator __position)
2171 _GLIBCXX_DEBUG_PEDASSERT(__position >=
begin()
2172 && __position <
end());
2173 const size_type __pos = __position -
begin();
2174 this->_M_erase(__pos, size_type(1));
2175 return iterator(_M_data() + __pos);
2187 _GLIBCXX20_CONSTEXPR
2189 erase(__const_iterator __first, __const_iterator __last)
2191 _GLIBCXX_DEBUG_PEDASSERT(__first >=
begin() && __first <= __last
2192 && __last <=
end());
2193 const size_type __pos = __first -
begin();
2194 if (__last ==
end())
2195 this->_M_set_length(__pos);
2197 this->_M_erase(__pos, __last - __first);
2198 return iterator(this->_M_data() + __pos);
2201#if __cplusplus >= 201103L
2207 _GLIBCXX20_CONSTEXPR
2211 __glibcxx_assert(!
empty());
2212 _M_erase(
size() - 1, 1);
2233 _GLIBCXX20_CONSTEXPR
2236 {
return this->
replace(__pos, __n, __str._M_data(), __str.size()); }
2256 _GLIBCXX20_CONSTEXPR
2259 size_type __pos2, size_type __n2 =
npos)
2260 {
return this->
replace(__pos1, __n1, __str._M_data()
2261 + __str._M_check(__pos2,
"basic_string::replace"),
2262 __str._M_limit(__pos2, __n2)); }
2282 _GLIBCXX20_CONSTEXPR
2284 replace(size_type __pos, size_type __n1,
const _CharT* __s,
2287 __glibcxx_requires_string_len(__s, __n2);
2288 return _M_replace(_M_check(__pos,
"basic_string::replace"),
2289 _M_limit(__pos, __n1), __s, __n2);
2308 _GLIBCXX20_CONSTEXPR
2310 replace(size_type __pos, size_type __n1,
const _CharT* __s)
2312 __glibcxx_requires_string(__s);
2313 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
2333 _GLIBCXX20_CONSTEXPR
2335 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
2336 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
2337 _M_limit(__pos, __n1), __n2, __c); }
2352 _GLIBCXX20_CONSTEXPR
2354 replace(__const_iterator __i1, __const_iterator __i2,
2356 {
return this->
replace(__i1, __i2, __str._M_data(), __str.size()); }
2373 _GLIBCXX20_CONSTEXPR
2375 replace(__const_iterator __i1, __const_iterator __i2,
2376 const _CharT* __s, size_type __n)
2378 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2380 return this->
replace(__i1 -
begin(), __i2 - __i1, __s, __n);
2396 _GLIBCXX20_CONSTEXPR
2398 replace(__const_iterator __i1, __const_iterator __i2,
const _CharT* __s)
2400 __glibcxx_requires_string(__s);
2401 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
2418 _GLIBCXX20_CONSTEXPR
2420 replace(__const_iterator __i1, __const_iterator __i2, size_type __n,
2423 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2425 return _M_replace_aux(__i1 -
begin(), __i2 - __i1, __n, __c);
2443#if __cplusplus >= 201103L
2444 template<
class _InputIterator,
2445 typename = std::_RequireInputIter<_InputIterator>>
2446 _GLIBCXX20_CONSTEXPR
2448 replace(const_iterator __i1, const_iterator __i2,
2449 _InputIterator __k1, _InputIterator __k2)
2451 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2453 __glibcxx_requires_valid_range(__k1, __k2);
2454 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
2455 std::__false_type());
2458 template<
class _InputIterator>
2459#ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
2460 typename __enable_if_not_native_iterator<_InputIterator>::__type
2464 replace(iterator __i1, iterator __i2,
2465 _InputIterator __k1, _InputIterator __k2)
2467 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2469 __glibcxx_requires_valid_range(__k1, __k2);
2470 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
2471 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
2477 _GLIBCXX20_CONSTEXPR
2479 replace(__const_iterator __i1, __const_iterator __i2,
2480 _CharT* __k1, _CharT* __k2)
2482 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2484 __glibcxx_requires_valid_range(__k1, __k2);
2489 _GLIBCXX20_CONSTEXPR
2491 replace(__const_iterator __i1, __const_iterator __i2,
2492 const _CharT* __k1,
const _CharT* __k2)
2494 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2496 __glibcxx_requires_valid_range(__k1, __k2);
2501 _GLIBCXX20_CONSTEXPR
2503 replace(__const_iterator __i1, __const_iterator __i2,
2504 iterator __k1, iterator __k2)
2506 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2508 __glibcxx_requires_valid_range(__k1, __k2);
2510 __k1.base(), __k2 - __k1);
2513 _GLIBCXX20_CONSTEXPR
2515 replace(__const_iterator __i1, __const_iterator __i2,
2516 const_iterator __k1, const_iterator __k2)
2518 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2520 __glibcxx_requires_valid_range(__k1, __k2);
2522 __k1.base(), __k2 - __k1);
2525#if __cplusplus >= 201103L
2540 _GLIBCXX20_CONSTEXPR
2542 initializer_list<_CharT> __l)
2543 {
return this->
replace(__i1, __i2, __l.begin(), __l.size()); }
2546#ifdef __glibcxx_string_view
2554 template<
typename _Tp>
2555 _GLIBCXX20_CONSTEXPR
2556 _If_sv<_Tp, basic_string&>
2557 replace(size_type __pos, size_type __n,
const _Tp& __svt)
2559 __sv_type __sv = __svt;
2560 return this->
replace(__pos, __n, __sv.data(), __sv.size());
2572 template<
typename _Tp>
2573 _GLIBCXX20_CONSTEXPR
2574 _If_sv<_Tp, basic_string&>
2575 replace(size_type __pos1, size_type __n1,
const _Tp& __svt,
2576 size_type __pos2, size_type __n2 =
npos)
2578 __sv_type __sv = __svt;
2579 return this->
replace(__pos1, __n1,
2581 + std::__sv_check(__sv.size(), __pos2,
"basic_string::replace"),
2582 std::__sv_limit(__sv.size(), __pos2, __n2));
2594 template<
typename _Tp>
2595 _GLIBCXX20_CONSTEXPR
2596 _If_sv<_Tp, basic_string&>
2597 replace(const_iterator __i1, const_iterator __i2,
const _Tp& __svt)
2599 __sv_type __sv = __svt;
2600 return this->
replace(__i1 -
begin(), __i2 - __i1, __sv);
2605 template<
class _Integer>
2606 _GLIBCXX20_CONSTEXPR
2608 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2609 _Integer __n, _Integer __val, __true_type)
2610 {
return _M_replace_aux(__i1 -
begin(), __i2 - __i1, __n, __val); }
2612 template<
class _InputIterator>
2613 _GLIBCXX20_CONSTEXPR
2615 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2616 _InputIterator __k1, _InputIterator __k2,
2619 _GLIBCXX20_CONSTEXPR
2621 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
2624 __attribute__((__noinline__, __noclone__, __cold__))
void
2625 _M_replace_cold(pointer __p, size_type __len1,
const _CharT* __s,
2626 const size_type __len2,
const size_type __how_much);
2628 _GLIBCXX20_CONSTEXPR
2630 _M_replace(size_type __pos, size_type __len1,
const _CharT* __s,
2631 const size_type __len2);
2633 _GLIBCXX20_CONSTEXPR
2635 _M_append(
const _CharT* __s, size_type __n);
2651 _GLIBCXX20_CONSTEXPR
2653 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
2662 _GLIBCXX20_CONSTEXPR
2673 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2675 c_str() const _GLIBCXX_NOEXCEPT
2676 {
return _M_data(); }
2686 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2688 data() const _GLIBCXX_NOEXCEPT
2689 {
return _M_data(); }
2691#if __cplusplus >= 201703L
2698 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2701 {
return _M_data(); }
2707 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2710 {
return _M_get_allocator(); }
2724 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2726 find(
const _CharT* __s, size_type __pos, size_type __n)
const
2739 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2743 {
return this->
find(__str.data(), __pos, __str.size()); }
2745#ifdef __glibcxx_string_view
2752 template<
typename _Tp>
2753 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2754 _If_sv<_Tp, size_type>
2755 find(
const _Tp& __svt, size_type __pos = 0) const
2756 noexcept(is_same<_Tp, __sv_type>::value)
2758 __sv_type __sv = __svt;
2759 return this->
find(__sv.data(), __pos, __sv.size());
2773 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2775 find(
const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2777 __glibcxx_requires_string(__s);
2778 return this->
find(__s, __pos, traits_type::length(__s));
2791 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2793 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
2805 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2809 {
return this->
rfind(__str.data(), __pos, __str.size()); }
2811#ifdef __glibcxx_string_view
2818 template<
typename _Tp>
2819 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2820 _If_sv<_Tp, size_type>
2821 rfind(
const _Tp& __svt, size_type __pos =
npos)
const
2822 noexcept(is_same<_Tp, __sv_type>::value)
2824 __sv_type __sv = __svt;
2825 return this->
rfind(__sv.data(), __pos, __sv.size());
2841 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2843 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
2856 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2858 rfind(
const _CharT* __s, size_type __pos =
npos)
const
2860 __glibcxx_requires_string(__s);
2861 return this->
rfind(__s, __pos, traits_type::length(__s));
2874 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2876 rfind(_CharT __c, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT;
2889 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2893 {
return this->
find_first_of(__str.data(), __pos, __str.size()); }
2895#ifdef __glibcxx_string_view
2903 template<
typename _Tp>
2904 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2905 _If_sv<_Tp, size_type>
2907 noexcept(is_same<_Tp, __sv_type>::value)
2909 __sv_type __sv = __svt;
2910 return this->
find_first_of(__sv.data(), __pos, __sv.size());
2926 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2928 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2941 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2946 __glibcxx_requires_string(__s);
2947 return this->
find_first_of(__s, __pos, traits_type::length(__s));
2962 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2964 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2965 {
return this->
find(__c, __pos); }
2978 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2982 {
return this->
find_last_of(__str.data(), __pos, __str.size()); }
2984#ifdef __glibcxx_string_view
2992 template<
typename _Tp>
2993 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2994 _If_sv<_Tp, size_type>
2996 noexcept(is_same<_Tp, __sv_type>::value)
2998 __sv_type __sv = __svt;
2999 return this->
find_last_of(__sv.data(), __pos, __sv.size());
3015 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3017 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
3030 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3035 __glibcxx_requires_string(__s);
3036 return this->
find_last_of(__s, __pos, traits_type::length(__s));
3051 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3054 {
return this->
rfind(__c, __pos); }
3066 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3072#ifdef __glibcxx_string_view
3080 template<
typename _Tp>
3081 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3082 _If_sv<_Tp, size_type>
3084 noexcept(is_same<_Tp, __sv_type>::value)
3086 __sv_type __sv = __svt;
3103 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3106 size_type __n)
const _GLIBCXX_NOEXCEPT;
3118 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3123 __glibcxx_requires_string(__s);
3137 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3153 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3159#ifdef __glibcxx_string_view
3167 template<
typename _Tp>
3168 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3169 _If_sv<_Tp, size_type>
3171 noexcept(is_same<_Tp, __sv_type>::value)
3173 __sv_type __sv = __svt;
3190 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3193 size_type __n)
const _GLIBCXX_NOEXCEPT;
3205 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3210 __glibcxx_requires_string(__s);
3224 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3241 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3243 substr(size_type __pos = 0, size_type __n =
npos)
const
3245 _M_check(__pos,
"basic_string::substr"), __n); }
3261 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3265 const size_type __size = this->
size();
3266 const size_type __osize = __str.size();
3267 const size_type __len =
std::min(__size, __osize);
3269 int __r = traits_type::compare(_M_data(), __str.data(), __len);
3271 __r = _S_compare(__size, __osize);
3275#ifdef __glibcxx_string_view
3281 template<
typename _Tp>
3282 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3284 compare(
const _Tp& __svt)
const
3285 noexcept(is_same<_Tp, __sv_type>::value)
3287 __sv_type __sv = __svt;
3288 const size_type __size = this->
size();
3289 const size_type __osize = __sv.size();
3290 const size_type __len =
std::min(__size, __osize);
3292 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
3294 __r = _S_compare(__size, __osize);
3306 template<
typename _Tp>
3307 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3309 compare(size_type __pos, size_type __n,
const _Tp& __svt)
const
3310 noexcept(is_same<_Tp, __sv_type>::value)
3312 __sv_type __sv = __svt;
3313 return __sv_type(*this).substr(__pos, __n).compare(__sv);
3326 template<
typename _Tp>
3327 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3329 compare(size_type __pos1, size_type __n1,
const _Tp& __svt,
3330 size_type __pos2, size_type __n2 =
npos)
const
3331 noexcept(is_same<_Tp, __sv_type>::value)
3333 __sv_type __sv = __svt;
3334 return __sv_type(*
this)
3335 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3358 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3362 _M_check(__pos,
"basic_string::compare");
3363 __n = _M_limit(__pos, __n);
3364 const size_type __osize = __str.size();
3365 const size_type __len =
std::min(__n, __osize);
3366 int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len);
3368 __r = _S_compare(__n, __osize);
3395 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3398 size_type __pos2, size_type __n2 =
npos)
const
3400 _M_check(__pos1,
"basic_string::compare");
3401 __str._M_check(__pos2,
"basic_string::compare");
3402 __n1 = _M_limit(__pos1, __n1);
3403 __n2 = __str._M_limit(__pos2, __n2);
3404 const size_type __len =
std::min(__n1, __n2);
3405 int __r = traits_type::compare(_M_data() + __pos1,
3406 __str.data() + __pos2, __len);
3408 __r = _S_compare(__n1, __n2);
3426 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3428 compare(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
3430 __glibcxx_requires_string(__s);
3431 const size_type __size = this->
size();
3432 const size_type __osize = traits_type::length(__s);
3433 const size_type __len =
std::min(__size, __osize);
3434 int __r = traits_type::compare(_M_data(), __s, __len);
3436 __r = _S_compare(__size, __osize);
3461 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3463 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const
3465 __glibcxx_requires_string(__s);
3466 _M_check(__pos,
"basic_string::compare");
3467 __n1 = _M_limit(__pos, __n1);
3468 const size_type __osize = traits_type::length(__s);
3469 const size_type __len =
std::min(__n1, __osize);
3470 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
3472 __r = _S_compare(__n1, __osize);
3500 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3502 compare(size_type __pos, size_type __n1,
const _CharT* __s,
3503 size_type __n2)
const
3505 __glibcxx_requires_string_len(__s, __n2);
3506 _M_check(__pos,
"basic_string::compare");
3507 __n1 = _M_limit(__pos, __n1);
3508 const size_type __len =
std::min(__n1, __n2);
3509 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
3511 __r = _S_compare(__n1, __n2);
3515#if __cplusplus >= 202002L
3518 starts_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
3519 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3523 starts_with(_CharT __x)
const noexcept
3524 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3526 [[nodiscard, __gnu__::__nonnull__]]
3528 starts_with(
const _CharT* __x)
const noexcept
3529 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3533 ends_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
3534 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3538 ends_with(_CharT __x)
const noexcept
3539 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3541 [[nodiscard, __gnu__::__nonnull__]]
3543 ends_with(
const _CharT* __x)
const noexcept
3544 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3547#if __cplusplus > 202002L
3550 contains(basic_string_view<_CharT, _Traits> __x)
const noexcept
3551 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3555 contains(_CharT __x)
const noexcept
3556 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3558 [[nodiscard, __gnu__::__nonnull__]]
3560 contains(
const _CharT* __x)
const noexcept
3561 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3565 template<
typename,
typename,
typename>
friend class basic_stringbuf;
3567_GLIBCXX_END_NAMESPACE_CXX11
3568_GLIBCXX_END_NAMESPACE_VERSION
3572namespace std _GLIBCXX_VISIBILITY(default)
3574_GLIBCXX_BEGIN_NAMESPACE_VERSION
3576#if __cpp_deduction_guides >= 201606
3577_GLIBCXX_BEGIN_NAMESPACE_CXX11
3578 template<
typename _InputIterator,
typename _CharT
3579 =
typename iterator_traits<_InputIterator>::value_type,
3580 typename _Allocator = allocator<_CharT>,
3581 typename = _RequireInputIter<_InputIterator>,
3582 typename = _RequireAllocator<_Allocator>>
3583 basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
3584 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
3588 template<
typename _CharT,
typename _Traits,
3589 typename _Allocator = allocator<_CharT>,
3590 typename = _RequireAllocator<_Allocator>>
3591 basic_string(basic_string_view<_CharT, _Traits>,
const _Allocator& = _Allocator())
3592 -> basic_string<_CharT, _Traits, _Allocator>;
3594 template<
typename _CharT,
typename _Traits,
3595 typename _Allocator = allocator<_CharT>,
3596 typename = _RequireAllocator<_Allocator>>
3597 basic_string(basic_string_view<_CharT, _Traits>,
3598 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
3599 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
3600 const _Allocator& = _Allocator())
3601 -> basic_string<_CharT, _Traits, _Allocator>;
3602_GLIBCXX_END_NAMESPACE_CXX11
3605 template<
typename _Str>
3606 _GLIBCXX20_CONSTEXPR
3608 __str_concat(
typename _Str::value_type
const* __lhs,
3609 typename _Str::size_type __lhs_len,
3610 typename _Str::value_type
const* __rhs,
3611 typename _Str::size_type __rhs_len,
3612 typename _Str::allocator_type
const& __a)
3614 typedef typename _Str::allocator_type allocator_type;
3616 _Str __str(_Alloc_traits::_S_select_on_copy(__a));
3617 __str.reserve(__lhs_len + __rhs_len);
3618 __str.append(__lhs, __lhs_len);
3619 __str.append(__rhs, __rhs_len);
3630 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3631 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3632 inline basic_string<_CharT, _Traits, _Alloc>
3637 return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(),
3638 __rhs.c_str(), __rhs.size(),
3639 __lhs.get_allocator());
3648 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3649 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3650 inline basic_string<_CharT,_Traits,_Alloc>
3654 __glibcxx_requires_string(__lhs);
3656 return std::__str_concat<_Str>(__lhs, _Traits::length(__lhs),
3657 __rhs.c_str(), __rhs.size(),
3658 __rhs.get_allocator());
3667 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3668 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3669 inline basic_string<_CharT,_Traits,_Alloc>
3673 return std::__str_concat<_Str>(__builtin_addressof(__lhs), 1,
3674 __rhs.c_str(), __rhs.size(),
3675 __rhs.get_allocator());
3684 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3685 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3686 inline basic_string<_CharT, _Traits, _Alloc>
3688 const _CharT* __rhs)
3690 __glibcxx_requires_string(__rhs);
3692 return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(),
3693 __rhs, _Traits::length(__rhs),
3694 __lhs.get_allocator());
3702 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3703 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3704 inline basic_string<_CharT, _Traits, _Alloc>
3708 return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(),
3709 __builtin_addressof(__rhs), 1,
3710 __lhs.get_allocator());
3713#if __cplusplus >= 201103L
3714 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3715 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3716 inline basic_string<_CharT, _Traits, _Alloc>
3717 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3718 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3719 {
return std::move(__lhs.append(__rhs)); }
3721 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3722 _GLIBCXX20_CONSTEXPR
3723 inline basic_string<_CharT, _Traits, _Alloc>
3724 operator+(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3725 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3726 {
return std::move(__rhs.insert(0, __lhs)); }
3728 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3729 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3730 inline basic_string<_CharT, _Traits, _Alloc>
3731 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3732 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3734#if _GLIBCXX_USE_CXX11_ABI
3735 using _Alloc_traits = allocator_traits<_Alloc>;
3736 bool __use_rhs =
false;
3737 if _GLIBCXX17_CONSTEXPR (
typename _Alloc_traits::is_always_equal{})
3739 else if (__lhs.get_allocator() == __rhs.get_allocator())
3744 const auto __size = __lhs.size() + __rhs.size();
3745 if (__size > __lhs.capacity() && __size <= __rhs.capacity())
3746 return std::move(__rhs.insert(0, __lhs));
3751 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3752 _GLIBCXX_NODISCARD _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3753 inline basic_string<_CharT, _Traits, _Alloc>
3755 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3756 {
return std::move(__rhs.insert(0, __lhs)); }
3758 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3759 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3760 inline basic_string<_CharT, _Traits, _Alloc>
3762 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3763 {
return std::move(__rhs.insert(0, 1, __lhs)); }
3765 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3766 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3767 inline basic_string<_CharT, _Traits, _Alloc>
3768 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3769 const _CharT* __rhs)
3770 {
return std::move(__lhs.append(__rhs)); }
3772 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3773 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3774 inline basic_string<_CharT, _Traits, _Alloc>
3775 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3777 {
return std::move(__lhs.append(1, __rhs)); }
3780#if __glibcxx_string_view >= 202403L
3782 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3784 constexpr basic_string<_CharT, _Traits, _Alloc>
3785 operator+(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3786 type_identity_t<basic_string_view<_CharT, _Traits>> __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 __lhs.get_allocator());
3795 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3797 constexpr basic_string<_CharT, _Traits, _Alloc>
3798 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3799 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs)
3805 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3807 constexpr basic_string<_CharT, _Traits, _Alloc>
3808 operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
3809 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3811 using _Str = basic_string<_CharT, _Traits, _Alloc>;
3812 return std::__str_concat<_Str>(__lhs.data(), __lhs.size(),
3813 __rhs.data(), __rhs.size(),
3814 __rhs.get_allocator());
3818 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3820 constexpr basic_string<_CharT, _Traits, _Alloc>
3821 operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
3822 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3824 return std::move(__rhs.insert(0, __lhs));
3835 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3836 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3842 return __lhs.size() == __rhs.size()
3843 && !_Traits::compare(__lhs.data(), __rhs.data(), __lhs.size());
3852 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3853 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3856 const _CharT* __rhs)
3858 return __lhs.size() == _Traits::length(__rhs)
3859 && !_Traits::compare(__lhs.data(), __rhs, __lhs.size());
3862#if __cpp_lib_three_way_comparison
3870 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3875 ->
decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
3876 {
return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); }
3885 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3889 const _CharT* __rhs)
noexcept
3890 ->
decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
3891 {
return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); }
3899 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3902 operator==(
const _CharT* __lhs,
3903 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3904 {
return __rhs == __lhs; }
3913 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3916 operator!=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3917 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3919 {
return !(__lhs == __rhs); }
3927 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3930 operator!=(
const _CharT* __lhs,
3931 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3932 {
return !(__rhs == __lhs); }
3940 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3943 operator!=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3944 const _CharT* __rhs)
3945 {
return !(__lhs == __rhs); }
3954 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3957 operator<(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3958 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3960 {
return __lhs.compare(__rhs) < 0; }
3968 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3971 operator<(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3972 const _CharT* __rhs)
3973 {
return __lhs.compare(__rhs) < 0; }
3981 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3985 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3986 {
return __rhs.compare(__lhs) > 0; }
3995 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3998 operator>(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3999 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4001 {
return __lhs.compare(__rhs) > 0; }
4009 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4012 operator>(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4013 const _CharT* __rhs)
4014 {
return __lhs.compare(__rhs) > 0; }
4022 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4026 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4027 {
return __rhs.compare(__lhs) < 0; }
4036 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4039 operator<=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4040 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4042 {
return __lhs.compare(__rhs) <= 0; }
4050 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4053 operator<=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4054 const _CharT* __rhs)
4055 {
return __lhs.compare(__rhs) <= 0; }
4063 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4067 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4068 {
return __rhs.compare(__lhs) >= 0; }
4077 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4080 operator>=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4081 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4083 {
return __lhs.compare(__rhs) >= 0; }
4091 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4094 operator>=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4095 const _CharT* __rhs)
4096 {
return __lhs.compare(__rhs) >= 0; }
4104 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4108 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4109 {
return __rhs.compare(__lhs) <= 0; }
4119 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4120 _GLIBCXX20_CONSTEXPR
4124 _GLIBCXX_NOEXCEPT_IF(
noexcept(__lhs.swap(__rhs)))
4125 { __lhs.swap(__rhs); }
4140 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4141 basic_istream<_CharT, _Traits>&
4142 operator>>(basic_istream<_CharT, _Traits>& __is,
4143 basic_string<_CharT, _Traits, _Alloc>& __str);
4146 basic_istream<char>&
4158 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4165 return __ostream_insert(__os, __str.data(), __str.size());
4181 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4182 basic_istream<_CharT, _Traits>&
4183 getline(basic_istream<_CharT, _Traits>& __is,
4184 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
4198 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4199 inline basic_istream<_CharT, _Traits>&
4204#if __cplusplus >= 201103L
4206 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4207 inline basic_istream<_CharT, _Traits>&
4213 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4214 inline basic_istream<_CharT, _Traits>&
4221 basic_istream<char>&
4222 getline(basic_istream<char>& __in, basic_string<char>& __str,
4225#ifdef _GLIBCXX_USE_WCHAR_T
4227 basic_istream<wchar_t>&
4228 getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
4232_GLIBCXX_END_NAMESPACE_VERSION
4235#if __cplusplus >= 201103L
4240namespace std _GLIBCXX_VISIBILITY(default)
4242_GLIBCXX_BEGIN_NAMESPACE_VERSION
4243_GLIBCXX_BEGIN_NAMESPACE_CXX11
4247 stoi(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4248 {
return __gnu_cxx::__stoa<long, int>(&std::strtol,
"stoi", __str.c_str(),
4252 stol(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4253 {
return __gnu_cxx::__stoa(&std::strtol,
"stol", __str.c_str(),
4256 inline unsigned long
4257 stoul(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4258 {
return __gnu_cxx::__stoa(&std::strtoul,
"stoul", __str.c_str(),
4261#if _GLIBCXX_USE_C99_STDLIB
4263 stoll(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4264 {
return __gnu_cxx::__stoa(&std::strtoll,
"stoll", __str.c_str(),
4267 inline unsigned long long
4268 stoull(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4269 {
return __gnu_cxx::__stoa(&std::strtoull,
"stoull", __str.c_str(),
4271#elif __LONG_WIDTH__ == __LONG_LONG_WIDTH__
4273 stoll(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4274 {
return std::stol(__str, __idx, __base); }
4276 inline unsigned long long
4277 stoull(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4278 {
return std::stoul(__str, __idx, __base); }
4282 stod(
const string& __str,
size_t* __idx = 0)
4283 {
return __gnu_cxx::__stoa(&std::strtod,
"stod", __str.c_str(), __idx); }
4285#if _GLIBCXX_HAVE_STRTOF
4288 stof(
const string& __str,
size_t* __idx = 0)
4289 {
return __gnu_cxx::__stoa(&std::strtof,
"stof", __str.c_str(), __idx); }
4292 stof(
const string& __str,
size_t* __idx = 0)
4294 double __d = std::stod(__str, __idx);
4295 if (__builtin_isfinite(__d) && __d != 0.0)
4297 double __abs_d = __builtin_fabs(__d);
4298 if (__abs_d < __FLT_MIN__ || __abs_d > __FLT_MAX__)
4301 std::__throw_out_of_range(
"stof");
4308#if _GLIBCXX_HAVE_STRTOLD && ! _GLIBCXX_HAVE_BROKEN_STRTOLD
4310 stold(
const string& __str,
size_t* __idx = 0)
4311 {
return __gnu_cxx::__stoa(&std::strtold,
"stold", __str.c_str(), __idx); }
4312#elif __DBL_MANT_DIG__ == __LDBL_MANT_DIG__
4314 stold(
const string& __str,
size_t* __idx = 0)
4315 {
return std::stod(__str, __idx); }
4323 to_string(
int __val)
4324#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_INT__) <= 32
4328 const bool __neg = __val < 0;
4329 const unsigned __uval = __neg ? (unsigned)~__val + 1u : __val;
4330 const auto __len = __detail::__to_chars_len(__uval);
4332 __str.__resize_and_overwrite(__neg + __len, [=](
char* __p,
size_t __n) {
4334 __detail::__to_chars_10_impl(__p + (
int)__neg, __len, __uval);
4342 to_string(
unsigned __val)
4343#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_INT__) <= 32
4347 const auto __len = __detail::__to_chars_len(__val);
4349 __str.__resize_and_overwrite(__len, [__val](
char* __p,
size_t __n) {
4350 __detail::__to_chars_10_impl(__p, __n, __val);
4358 to_string(
long __val)
4359#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_LONG__) <= 32
4363 const bool __neg = __val < 0;
4364 const unsigned long __uval = __neg ? (
unsigned long)~__val + 1ul : __val;
4365 const auto __len = __detail::__to_chars_len(__uval);
4367 __str.__resize_and_overwrite(__neg + __len, [=](
char* __p,
size_t __n) {
4369 __detail::__to_chars_10_impl(__p + (
int)__neg, __len, __uval);
4377 to_string(
unsigned long __val)
4378#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_LONG__) <= 32
4382 const auto __len = __detail::__to_chars_len(__val);
4384 __str.__resize_and_overwrite(__len, [__val](
char* __p,
size_t __n) {
4385 __detail::__to_chars_10_impl(__p, __n, __val);
4393 to_string(
long long __val)
4395 const bool __neg = __val < 0;
4396 const unsigned long long __uval
4397 = __neg ? (
unsigned long long)~__val + 1ull : __val;
4398 const auto __len = __detail::__to_chars_len(__uval);
4400 __str.__resize_and_overwrite(__neg + __len, [=](
char* __p,
size_t __n) {
4402 __detail::__to_chars_10_impl(__p + (
int)__neg, __len, __uval);
4410 to_string(
unsigned long long __val)
4412 const auto __len = __detail::__to_chars_len(__val);
4414 __str.__resize_and_overwrite(__len, [__val](
char* __p,
size_t __n) {
4415 __detail::__to_chars_10_impl(__p, __n, __val);
4421#if __glibcxx_to_string >= 202306L
4425 to_string(
float __val)
4430 __str.resize_and_overwrite(__len,
4431 [__val, &__len] (
char* __p,
size_t __n) {
4432 auto [__end, __err] = std::to_chars(__p, __p + __n, __val);
4433 if (__err == errc{}) [[likely]]
4438 }
while (__str.empty());
4444 to_string(
double __val)
4449 __str.resize_and_overwrite(__len,
4450 [__val, &__len] (
char* __p,
size_t __n) {
4451 auto [__end, __err] = std::to_chars(__p, __p + __n, __val);
4452 if (__err == errc{}) [[likely]]
4457 }
while (__str.empty());
4463 to_string(
long double __val)
4468 __str.resize_and_overwrite(__len,
4469 [__val, &__len] (
char* __p,
size_t __n) {
4470 auto [__end, __err] = std::to_chars(__p, __p + __n, __val);
4471 if (__err == errc{}) [[likely]]
4476 }
while (__str.empty());
4479#elif _GLIBCXX_USE_C99_STDIO
4480#pragma GCC diagnostic push
4481#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
4486 to_string(
float __val)
4489 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
4490 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
4496 to_string(
double __val)
4499 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
4500 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
4506 to_string(
long double __val)
4509 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
4510 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
4513#pragma GCC diagnostic pop
4516#if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR
4518 stoi(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4519 {
return __gnu_cxx::__stoa<long, int>(&std::wcstol,
"stoi", __str.c_str(),
4523 stol(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4524 {
return __gnu_cxx::__stoa(&std::wcstol,
"stol", __str.c_str(),
4527 inline unsigned long
4528 stoul(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4529 {
return __gnu_cxx::__stoa(&std::wcstoul,
"stoul", __str.c_str(),
4533 stoll(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4534 {
return __gnu_cxx::__stoa(&std::wcstoll,
"stoll", __str.c_str(),
4537 inline unsigned long long
4538 stoull(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4539 {
return __gnu_cxx::__stoa(&std::wcstoull,
"stoull", __str.c_str(),
4544 stof(
const wstring& __str,
size_t* __idx = 0)
4545 {
return __gnu_cxx::__stoa(&std::wcstof,
"stof", __str.c_str(), __idx); }
4548 stod(
const wstring& __str,
size_t* __idx = 0)
4549 {
return __gnu_cxx::__stoa(&std::wcstod,
"stod", __str.c_str(), __idx); }
4552 stold(
const wstring& __str,
size_t* __idx = 0)
4553 {
return __gnu_cxx::__stoa(&std::wcstold,
"stold", __str.c_str(), __idx); }
4556#ifdef _GLIBCXX_USE_WCHAR_T
4557#pragma GCC diagnostic push
4558#pragma GCC diagnostic ignored "-Wc++17-extensions"
4559 _GLIBCXX20_CONSTEXPR
4561 __to_wstring_numeric(
const char* __s,
int __len,
wchar_t* __wout)
4565 if constexpr (wchar_t(
'0') == L
'0' && wchar_t(
'-') == L
'-'
4566 && wchar_t(
'.') == L
'.' && wchar_t(
'e') == L
'e')
4568 for (
int __i = 0; __i < __len; ++__i)
4569 __wout[__i] = (
wchar_t) __s[__i];
4574 for (
int __i =
'0'; __i <=
'9'; ++__i)
4575 __wc[__i] = L
'0' + __i;
4600 for (
int __i = 0; __i < __len; ++__i)
4601 __wout[__i] = __wc[(
int)__s[__i]];
4605#if __glibcxx_constexpr_string >= 201907L
4609#ifdef __glibcxx_string_view
4610 __to_wstring_numeric(string_view __s)
4612 __to_wstring_numeric(
const string& __s)
4615 if constexpr (wchar_t(
'0') == L
'0' && wchar_t(
'-') == L
'-'
4616 && wchar_t(
'.') == L
'.' && wchar_t(
'e') == L
'e')
4617 return wstring(__s.data(), __s.data() + __s.size());
4621 auto __f = __s.data();
4622 __ws.__resize_and_overwrite(__s.size(),
4623 [__f] (
wchar_t* __to,
int __n) {
4624 std::__to_wstring_numeric(__f, __n, __to);
4630#pragma GCC diagnostic pop
4634 to_wstring(
int __val)
4635 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4639 to_wstring(
unsigned __val)
4640 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4644 to_wstring(
long __val)
4645 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4649 to_wstring(
unsigned long __val)
4650 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4654 to_wstring(
long long __val)
4655 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4659 to_wstring(
unsigned long long __val)
4660 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4662#if __glibcxx_to_string || _GLIBCXX_USE_C99_STDIO
4665 to_wstring(
float __val)
4666 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4670 to_wstring(
double __val)
4671 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4675 to_wstring(
long double __val)
4676 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4680_GLIBCXX_END_NAMESPACE_CXX11
4681_GLIBCXX_END_NAMESPACE_VERSION
4686#if __cplusplus >= 201103L
4690namespace std _GLIBCXX_VISIBILITY(default)
4692_GLIBCXX_BEGIN_NAMESPACE_VERSION
4697 template<
typename _CharT,
typename _Alloc,
4698 typename _StrT = basic_string<_CharT, char_traits<_CharT>, _Alloc>>
4699 struct __str_hash_base
4700 :
public __hash_base<size_t, _StrT>
4704 operator()(
const _StrT& __s)
const noexcept
4705 {
return _Hash_impl::hash(__s.data(), __s.length() *
sizeof(_CharT)); }
4708#ifndef _GLIBCXX_COMPATIBILITY_CXX0X
4710 template<
typename _Alloc>
4712 :
public __str_hash_base<char, _Alloc>
4716 template<
typename _Alloc>
4718 :
public __str_hash_base<wchar_t, _Alloc>
4721 template<
typename _Alloc>
4728#ifdef _GLIBCXX_USE_CHAR8_T
4730 template<
typename _Alloc>
4731 struct hash<basic_string<char8_t, char_traits<char8_t>, _Alloc>>
4732 :
public __str_hash_base<char8_t, _Alloc>
4737 template<
typename _Alloc>
4739 :
public __str_hash_base<char16_t, _Alloc>
4743 template<
typename _Alloc>
4745 :
public __str_hash_base<char32_t, _Alloc>
4748#if ! _GLIBCXX_INLINE_VERSION
4754#ifdef _GLIBCXX_USE_CHAR8_T
4755 template<>
struct __is_fast_hash<hash<u8string>> :
std::false_type { };
4759 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4760 struct __is_fast_hash<hash<basic_string<_CharT, _Traits, _Alloc>>>
4765#ifdef __glibcxx_string_udls
4766 inline namespace literals
4768 inline namespace string_literals
4770#pragma GCC diagnostic push
4771#pragma GCC diagnostic ignored "-Wliteral-suffix"
4773#if __glibcxx_constexpr_string >= 201907L
4774# define _GLIBCXX_STRING_CONSTEXPR constexpr
4776# define _GLIBCXX_STRING_CONSTEXPR
4779 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4780 inline basic_string<char>
4781 operator""s(
const char* __str,
size_t __len)
4782 {
return basic_string<char>{__str, __len}; }
4784 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4785 inline basic_string<wchar_t>
4786 operator""s(
const wchar_t* __str,
size_t __len)
4787 {
return basic_string<wchar_t>{__str, __len}; }
4789#ifdef _GLIBCXX_USE_CHAR8_T
4790 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4791 inline basic_string<char8_t>
4792 operator""s(
const char8_t* __str,
size_t __len)
4793 {
return basic_string<char8_t>{__str, __len}; }
4796 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4797 inline basic_string<char16_t>
4798 operator""s(
const char16_t* __str,
size_t __len)
4799 {
return basic_string<char16_t>{__str, __len}; }
4801 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4802 inline basic_string<char32_t>
4803 operator""s(
const char32_t* __str,
size_t __len)
4804 {
return basic_string<char32_t>{__str, __len}; }
4806#undef _GLIBCXX_STRING_CONSTEXPR
4807#pragma GCC diagnostic pop
4812#ifdef __glibcxx_variant
4813 namespace __detail::__variant
4815 template<
typename>
struct _Never_valueless_alt;
4819 template<
typename _Tp,
typename _Traits,
typename _Alloc>
4820 struct _Never_valueless_alt<
std::basic_string<_Tp, _Traits, _Alloc>>
4822 is_nothrow_move_constructible<std::basic_string<_Tp, _Traits, _Alloc>>,
4823 is_nothrow_move_assignable<std::basic_string<_Tp, _Traits, _Alloc>>
4829_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.