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_trivially_copyable_v<_CharT>
92 && is_trivially_default_constructible_v<_CharT>
93 && is_standard_layout_v<_CharT>);
94 static_assert(is_same_v<_CharT, typename _Traits::char_type>);
95 static_assert(is_same_v<_CharT, typename _Alloc::value_type>);
96 using _Char_alloc_type = _Alloc;
99 rebind<_CharT>::other _Char_alloc_type;
106 typedef _Traits traits_type;
107 typedef typename _Traits::char_type value_type;
108 typedef _Char_alloc_type allocator_type;
109 typedef typename _Alloc_traits::size_type size_type;
110 typedef typename _Alloc_traits::difference_type difference_type;
111 typedef typename _Alloc_traits::reference reference;
112 typedef typename _Alloc_traits::const_reference const_reference;
113 typedef typename _Alloc_traits::pointer pointer;
114 typedef typename _Alloc_traits::const_pointer const_pointer;
115 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
116 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
122 static const size_type
npos =
static_cast<size_type
>(-1);
126#if __cplusplus < 201103L
127 typedef iterator __const_iterator;
129 typedef const_iterator __const_iterator;
133 static _GLIBCXX20_CONSTEXPR pointer
134 _S_allocate(_Char_alloc_type& __a, size_type __n)
136 pointer __p = _Alloc_traits::allocate(__a, __n);
137#if __glibcxx_constexpr_string >= 201907L
140 if constexpr (!is_same_v<_Traits, char_traits<_CharT>>)
141 if (std::__is_constant_evaluated())
143 for (size_type __i = 0; __i < __n; ++__i)
144 std::construct_at(__builtin_addressof(__p[__i]));
149#if __cplusplus >= 201703L
151 typedef basic_string_view<_CharT, _Traits> __sv_type;
153 template<
typename _Tp,
typename _Res>
155 __and_<is_convertible<const _Tp&, __sv_type>,
156 __not_<is_convertible<const _Tp*, const basic_string*>>,
157 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
163 _S_to_string_view(__sv_type __svt)
noexcept
172 _GLIBCXX20_CONSTEXPR
explicit
173 __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
191 struct _Alloc_hider : allocator_type
193#if __cplusplus < 201103L
194 _Alloc_hider(pointer __dat,
const _Alloc& __a = _Alloc())
195 : allocator_type(__a), _M_p(__dat) { }
198 _Alloc_hider(pointer __dat,
const _Alloc& __a)
199 : allocator_type(__a), _M_p(__dat) { }
202 _Alloc_hider(pointer __dat, _Alloc&& __a = _Alloc())
203 : allocator_type(
std::
move(__a)), _M_p(__dat) { }
209 _Alloc_hider _M_dataplus;
210 size_type _M_string_length;
212 enum { _S_local_capacity = 15 /
sizeof(_CharT) };
216 _CharT _M_local_buf[_S_local_capacity + 1];
217 size_type _M_allocated_capacity;
223 { _M_dataplus._M_p = __p; }
227 _M_length(size_type __length)
228 { _M_string_length = __length; }
233 {
return _M_dataplus._M_p; }
239#if __cplusplus >= 201103L
242 return pointer(_M_local_buf);
248 _M_local_data()
const
250#if __cplusplus >= 201103L
253 return const_pointer(_M_local_buf);
259 _M_capacity(size_type __capacity)
260 { _M_allocated_capacity = __capacity; }
264 _M_set_length(size_type __n)
267 traits_type::assign(_M_data()[__n], _CharT());
274 if (_M_data() == _M_local_data())
276 if (_M_string_length > _S_local_capacity)
277 __builtin_unreachable();
286 _M_create(size_type&, size_type);
293 _M_destroy(_M_allocated_capacity);
298 _M_destroy(size_type __size)
throw()
299 { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); }
301#if __cplusplus < 201103L || defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
304 template<
typename _InIterator>
306 _M_construct_aux(_InIterator __beg, _InIterator __end,
309 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
310 _M_construct(__beg, __end, _Tag());
315 template<
typename _Integer>
317 _M_construct_aux(_Integer __beg, _Integer __end, std::__true_type)
318 { _M_construct_aux_2(
static_cast<size_type
>(__beg), __end); }
321 _M_construct_aux_2(size_type __req, _CharT __c)
322 { _M_construct(__req, __c); }
326 template<
typename _InIterator>
329 _M_construct(_InIterator __beg, _InIterator __end,
334 template<
typename _FwdIterator>
337 _M_construct(_FwdIterator __beg, _FwdIterator __end,
342 _M_construct(size_type __req, _CharT __c);
346 template<
bool _Terminated>
349 _M_construct(
const _CharT *__c, size_type __n);
354 {
return _M_dataplus; }
357 const allocator_type&
358 _M_get_allocator()
const
359 {
return _M_dataplus; }
362 __attribute__((__always_inline__))
365 _M_init_local_buf() _GLIBCXX_NOEXCEPT
367#if __glibcxx_is_constant_evaluated
368 if (std::is_constant_evaluated())
369 for (size_type __i = 0; __i <= _S_local_capacity; ++__i)
370 _M_local_buf[__i] = _CharT();
374 __attribute__((__always_inline__))
377 _M_use_local_data() _GLIBCXX_NOEXCEPT
379#if __cpp_lib_is_constant_evaluated
382 return _M_local_data();
387#ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
390 template<
typename _Tp,
bool _Requires =
391 !__are_same<_Tp, _CharT*>::__value
392 && !__are_same<_Tp, const _CharT*>::__value
393 && !__are_same<_Tp, iterator>::__value
394 && !__are_same<_Tp, const_iterator>::__value>
395 struct __enable_if_not_native_iterator
396 {
typedef basic_string& __type; };
397 template<
typename _Tp>
398 struct __enable_if_not_native_iterator<_Tp, false> { };
403 _M_check(size_type __pos,
const char* __s)
const
405 if (__pos > this->
size())
406 __throw_out_of_range_fmt(__N(
"%s: __pos (which is %zu) > "
407 "this->size() (which is %zu)"),
408 __s, __pos, this->
size());
414 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
417 __throw_length_error(__N(__s));
424 _M_limit(size_type __pos, size_type __off)
const _GLIBCXX_NOEXCEPT
426 const bool __testoff = __off < this->
size() - __pos;
427 return __testoff ? __off : this->
size() - __pos;
432 _M_disjunct(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
434 return (less<const _CharT*>()(__s, _M_data())
435 || less<const _CharT*>()(_M_data() + this->
size(), __s));
442 _S_copy(_CharT* __d,
const _CharT* __s, size_type __n)
445 traits_type::assign(*__d, *__s);
447 traits_type::copy(__d, __s, __n);
452 _S_move(_CharT* __d,
const _CharT* __s, size_type __n)
455 traits_type::assign(*__d, *__s);
457 traits_type::move(__d, __s, __n);
462 _S_assign(_CharT* __d, size_type __n, _CharT __c)
465 traits_type::assign(*__d, __c);
467 traits_type::assign(__d, __n, __c);
472 template<
class _Iterator>
475 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
477 for (; __k1 != __k2; ++__k1, (void)++__p)
478 traits_type::assign(*__p, *__k1);
483 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
484 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
488 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
490 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
494 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
495 { _S_copy(__p, __k1, __k2 - __k1); }
499 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
501 { _S_copy(__p, __k1, __k2 - __k1); }
505 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
507 const difference_type __d = difference_type(__n1 - __n2);
509 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
510 return __gnu_cxx::__numeric_traits<int>::__max;
511 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
512 return __gnu_cxx::__numeric_traits<int>::__min;
523 _M_mutate(size_type __pos, size_type __len1,
const _CharT* __s,
528 _M_erase(size_type __pos, size_type __n);
540 _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value)
541#if __cpp_concepts && __glibcxx_type_trait_variable_templates
542 requires is_default_constructible_v<_Alloc>
544 : _M_dataplus(_M_local_data())
556 : _M_dataplus(_M_local_data(), __a)
568 : _M_dataplus(_M_local_data(),
569 _Alloc_traits::_S_select_on_copy(__str._M_get_allocator()))
571 _M_construct<true>(__str._M_data(), __str.length());
584 const _Alloc& __a = _Alloc())
585 : _M_dataplus(_M_local_data(), __a)
587 const _CharT* __start = __str._M_data()
588 + __str._M_check(__pos,
"basic_string::basic_string");
589 _M_construct(__start, __start + __str._M_limit(__pos,
npos),
602 : _M_dataplus(_M_local_data())
604 const _CharT* __start = __str._M_data()
605 + __str._M_check(__pos,
"basic_string::basic_string");
606 _M_construct(__start, __start + __str._M_limit(__pos, __n),
619 size_type __n,
const _Alloc& __a)
620 : _M_dataplus(_M_local_data(), __a)
622 const _CharT* __start
623 = __str._M_data() + __str._M_check(__pos,
"string::string");
624 _M_construct(__start, __start + __str._M_limit(__pos, __n),
639 const _Alloc& __a = _Alloc())
640 : _M_dataplus(_M_local_data(), __a)
643 if (__s == 0 && __n > 0)
644 std::__throw_logic_error(__N(
"basic_string: "
645 "construction from null is not valid"));
654#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
657 template<
typename = _RequireAllocator<_Alloc>>
660 basic_string(
const _CharT* __s,
const _Alloc& __a = _Alloc())
661 : _M_dataplus(_M_local_data(), __a)
665 std::__throw_logic_error(__N(
"basic_string: "
666 "construction from null is not valid"));
667 const _CharT* __end = __s + traits_type::length(__s);
668 _M_construct(__s, __end, forward_iterator_tag());
677#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
680 template<
typename = _RequireAllocator<_Alloc>>
683 basic_string(size_type __n, _CharT __c,
const _Alloc& __a = _Alloc())
684 : _M_dataplus(_M_local_data(), __a)
685 { _M_construct(__n, __c); }
687#if __cplusplus >= 201103L
697 : _M_dataplus(_M_local_data(),
std::move(__str._M_get_allocator()))
699 if (__str._M_is_local())
702 traits_type::copy(_M_local_buf, __str._M_local_buf,
707 _M_data(__str._M_data());
708 _M_capacity(__str._M_allocated_capacity);
714 _M_length(__str.length());
715 __str._M_data(__str._M_use_local_data());
716 __str._M_set_length(0);
725 basic_string(initializer_list<_CharT> __l,
const _Alloc& __a = _Alloc())
726 : _M_dataplus(_M_local_data(), __a)
731 : _M_dataplus(_M_local_data(), __a)
736 noexcept(_Alloc_traits::_S_always_equal())
737 : _M_dataplus(_M_local_data(), __a)
739 if (__str._M_is_local())
742 traits_type::copy(_M_local_buf, __str._M_local_buf,
744 _M_length(__str.length());
745 __str._M_set_length(0);
747 else if (_Alloc_traits::_S_always_equal()
748 || __str.get_allocator() == __a)
750 _M_data(__str._M_data());
751 _M_length(__str.length());
752 _M_capacity(__str._M_allocated_capacity);
753 __str._M_data(__str._M_use_local_data());
754 __str._M_set_length(0);
761#if __cplusplus >= 202100L
772#if __cplusplus >= 201103L
773 template<
typename _InputIterator,
774 typename = std::_RequireInputIter<_InputIterator>>
776 template<
typename _InputIterator>
779 basic_string(_InputIterator __beg, _InputIterator __end,
780 const _Alloc& __a = _Alloc())
781 : _M_dataplus(_M_local_data(), __a), _M_string_length(0)
783#if __cplusplus >= 201103L
786 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
787 _M_construct_aux(__beg, __end, _Integral());
791#if __cplusplus >= 201703L
799 template<
typename _Tp,
800 typename = enable_if_t<is_convertible_v<const _Tp&, __sv_type>>>
802 basic_string(
const _Tp& __t, size_type __pos, size_type __n,
803 const _Alloc& __a = _Alloc())
811 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
814 basic_string(
const _Tp& __t,
const _Alloc& __a = _Alloc())
815 :
basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
833 return this->
assign(__str);
843 {
return this->
assign(__s); }
860#if __cplusplus >= 201103L
873 noexcept(_Alloc_traits::_S_nothrow_move())
875 const bool __equal_allocs = _Alloc_traits::_S_always_equal()
876 || _M_get_allocator() == __str._M_get_allocator();
877 if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign()
881 _M_destroy(_M_allocated_capacity);
882 _M_data(_M_local_data());
886 std::__alloc_on_move(_M_get_allocator(), __str._M_get_allocator());
888 if (__str._M_is_local())
896 this->_S_copy(_M_data(), __str._M_data(), __str.size());
897 _M_set_length(__str.size());
900 else if (_Alloc_traits::_S_propagate_on_move_assign() || __equal_allocs)
903 pointer __data =
nullptr;
904 size_type __capacity;
911 __capacity = _M_allocated_capacity;
914 _M_destroy(_M_allocated_capacity);
917 _M_data(__str._M_data());
918 _M_length(__str.length());
919 _M_capacity(__str._M_allocated_capacity);
922 __str._M_data(__data);
923 __str._M_capacity(__capacity);
926 __str._M_data(__str._M_use_local_data());
942 this->
assign(__l.begin(), __l.size());
947#if __cplusplus >= 201703L
952 template<
typename _Tp>
954 _If_sv<_Tp, basic_string&>
956 {
return this->
assign(__svt); }
963 operator __sv_type() const noexcept
964 {
return __sv_type(
data(),
size()); }
972 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
974 begin() _GLIBCXX_NOEXCEPT
975 {
return iterator(_M_data()); }
981 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
983 begin() const _GLIBCXX_NOEXCEPT
984 {
return const_iterator(_M_data()); }
990 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
992 end() _GLIBCXX_NOEXCEPT
993 {
return iterator(_M_data() + this->
size()); }
999 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1001 end() const _GLIBCXX_NOEXCEPT
1002 {
return const_iterator(_M_data() + this->
size()); }
1009 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1011 rbegin() _GLIBCXX_NOEXCEPT
1012 {
return reverse_iterator(this->
end()); }
1019 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1020 const_reverse_iterator
1021 rbegin() const _GLIBCXX_NOEXCEPT
1022 {
return const_reverse_iterator(this->
end()); }
1029 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1031 rend() _GLIBCXX_NOEXCEPT
1032 {
return reverse_iterator(this->
begin()); }
1039 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1040 const_reverse_iterator
1041 rend() const _GLIBCXX_NOEXCEPT
1042 {
return const_reverse_iterator(this->
begin()); }
1044#if __cplusplus >= 201103L
1049 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1052 {
return const_iterator(this->_M_data()); }
1058 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1060 cend() const noexcept
1061 {
return const_iterator(this->_M_data() + this->
size()); }
1068 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1069 const_reverse_iterator
1071 {
return const_reverse_iterator(this->
end()); }
1078 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1079 const_reverse_iterator
1080 crend() const noexcept
1081 {
return const_reverse_iterator(this->
begin()); }
1088 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1090 size() const _GLIBCXX_NOEXCEPT
1092 size_type __sz = _M_string_length;
1094 __builtin_unreachable ();
1100 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1102 length() const _GLIBCXX_NOEXCEPT
1106 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1110 const size_t __diffmax
1111 = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max /
sizeof(_CharT);
1112 const size_t __allocmax = _Alloc_traits::max_size(_M_get_allocator());
1113 return (
std::min)(__diffmax, __allocmax) - 1;
1126 _GLIBCXX20_CONSTEXPR
1128 resize(size_type __n, _CharT __c);
1140 _GLIBCXX20_CONSTEXPR
1143 { this->
resize(__n, _CharT()); }
1145#if __cplusplus >= 201103L
1146#pragma GCC diagnostic push
1147#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1149 _GLIBCXX20_CONSTEXPR
1153#pragma GCC diagnostic pop
1156#ifdef __glibcxx_string_resize_and_overwrite
1186 template<
typename _Operation>
1188 resize_and_overwrite(size_type __n, _Operation __op);
1191#if __cplusplus >= 201103L
1193 template<
typename _Operation>
1194 _GLIBCXX20_CONSTEXPR
void
1202 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1206 size_t __sz = _M_is_local() ? size_type(_S_local_capacity)
1207 : _M_allocated_capacity;
1208 if (__sz < _S_local_capacity || __sz >
max_size ())
1209 __builtin_unreachable ();
1230 _GLIBCXX20_CONSTEXPR
1237#if __cplusplus > 201703L
1238 [[deprecated(
"use shrink_to_fit() instead")]]
1240 _GLIBCXX20_CONSTEXPR
1247 _GLIBCXX20_CONSTEXPR
1249 clear() _GLIBCXX_NOEXCEPT
1250 { _M_set_length(0); }
1256 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1258 empty() const _GLIBCXX_NOEXCEPT
1259 {
return _M_string_length == 0; }
1272 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1274 operator[] (size_type __pos)
const _GLIBCXX_NOEXCEPT
1276 __glibcxx_assert(__pos <=
size());
1277 return _M_data()[__pos];
1290 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1296 __glibcxx_assert(__pos <=
size());
1298 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos <
size());
1299 return _M_data()[__pos];
1312 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1314 at(size_type __n)
const
1316 if (__n >= this->
size())
1317 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1318 "(which is %zu) >= this->size() "
1321 return _M_data()[__n];
1334 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1339 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1340 "(which is %zu) >= this->size() "
1343 return _M_data()[__n];
1346#if __cplusplus >= 201103L
1351 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1355 __glibcxx_assert(!
empty());
1363 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1365 front() const noexcept
1367 __glibcxx_assert(!
empty());
1375 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1379 __glibcxx_assert(!
empty());
1387 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1389 back() const noexcept
1391 __glibcxx_assert(!
empty());
1402 _GLIBCXX20_CONSTEXPR
1405 {
return this->
append(__str); }
1412 _GLIBCXX20_CONSTEXPR
1415 {
return this->
append(__s); }
1422 _GLIBCXX20_CONSTEXPR
1430#if __cplusplus >= 201103L
1436 _GLIBCXX20_CONSTEXPR
1439 {
return this->
append(__l.begin(), __l.size()); }
1442#if __cplusplus >= 201703L
1448 template<
typename _Tp>
1449 _GLIBCXX20_CONSTEXPR
1450 _If_sv<_Tp, basic_string&>
1452 {
return this->
append(__svt); }
1460 _GLIBCXX20_CONSTEXPR
1463 {
return this->
append(__str._M_data(), __str.size()); }
1478 _GLIBCXX20_CONSTEXPR
1481 {
return this->
append(__str._M_data()
1482 + __str._M_check(__pos,
"basic_string::append"),
1483 __str._M_limit(__pos, __n)); }
1491 _GLIBCXX20_CONSTEXPR
1493 append(
const _CharT* __s, size_type __n)
1495 __glibcxx_requires_string_len(__s, __n);
1496 _M_check_length(size_type(0), __n,
"basic_string::append");
1497 return _M_append(__s, __n);
1505 _GLIBCXX20_CONSTEXPR
1507 append(
const _CharT* __s)
1509 __glibcxx_requires_string(__s);
1510 const size_type __n = traits_type::length(__s);
1511 _M_check_length(size_type(0), __n,
"basic_string::append");
1512 return _M_append(__s, __n);
1523 _GLIBCXX20_CONSTEXPR
1525 append(size_type __n, _CharT __c)
1526 {
return _M_replace_aux(this->
size(), size_type(0), __n, __c); }
1528#if __cplusplus >= 201103L
1534 _GLIBCXX20_CONSTEXPR
1536 append(initializer_list<_CharT> __l)
1537 {
return this->
append(__l.begin(), __l.size()); }
1548#if __cplusplus >= 201103L
1549 template<
class _InputIterator,
1550 typename = std::_RequireInputIter<_InputIterator>>
1551 _GLIBCXX20_CONSTEXPR
1553 template<
class _InputIterator>
1556 append(_InputIterator __first, _InputIterator __last)
1559#if __cplusplus >= 201703L
1565 template<
typename _Tp>
1566 _GLIBCXX20_CONSTEXPR
1567 _If_sv<_Tp, basic_string&>
1570 __sv_type __sv = __svt;
1571 return this->
append(__sv.data(), __sv.size());
1581 template<
typename _Tp>
1582 _GLIBCXX20_CONSTEXPR
1583 _If_sv<_Tp, basic_string&>
1584 append(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
1586 __sv_type __sv = __svt;
1587 return _M_append(__sv.data()
1588 + std::__sv_check(__sv.size(), __pos,
"basic_string::append"),
1589 std::__sv_limit(__sv.size(), __pos, __n));
1597 _GLIBCXX20_CONSTEXPR
1601 const size_type __size = this->
size();
1603 this->_M_mutate(__size, size_type(0), 0, size_type(1));
1604 traits_type::assign(this->_M_data()[__size], __c);
1605 this->_M_set_length(__size + 1);
1613 _GLIBCXX20_CONSTEXPR
1617#if __cplusplus >= 201103L
1618 if (_Alloc_traits::_S_propagate_on_copy_assign())
1620 if (!_Alloc_traits::_S_always_equal() && !_M_is_local()
1621 && _M_get_allocator() != __str._M_get_allocator())
1625 if (__str.size() <= _S_local_capacity)
1627 _M_destroy(_M_allocated_capacity);
1628 _M_data(_M_use_local_data());
1633 const auto __len = __str.size();
1634 auto __alloc = __str._M_get_allocator();
1636 auto __ptr = _S_allocate(__alloc, __len + 1);
1637 _M_destroy(_M_allocated_capacity);
1640 _M_set_length(__len);
1643 std::__alloc_on_copy(_M_get_allocator(), __str._M_get_allocator());
1646 this->_M_assign(__str);
1650#if __cplusplus >= 201103L
1659 _GLIBCXX20_CONSTEXPR
1662 noexcept(_Alloc_traits::_S_nothrow_move())
1683 _GLIBCXX20_CONSTEXPR
1686 {
return _M_replace(size_type(0), this->
size(), __str._M_data()
1687 + __str._M_check(__pos,
"basic_string::assign"),
1688 __str._M_limit(__pos, __n)); }
1700 _GLIBCXX20_CONSTEXPR
1702 assign(
const _CharT* __s, size_type __n)
1704 __glibcxx_requires_string_len(__s, __n);
1705 return _M_replace(size_type(0), this->
size(), __s, __n);
1717 _GLIBCXX20_CONSTEXPR
1719 assign(
const _CharT* __s)
1721 __glibcxx_requires_string(__s);
1722 return _M_replace(size_type(0), this->
size(), __s,
1723 traits_type::length(__s));
1735 _GLIBCXX20_CONSTEXPR
1737 assign(size_type __n, _CharT __c)
1738 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
1748#if __cplusplus >= 201103L
1749#pragma GCC diagnostic push
1750#pragma GCC diagnostic ignored "-Wc++17-extensions"
1751 template<
class _InputIterator,
1752 typename = std::_RequireInputIter<_InputIterator>>
1753 _GLIBCXX20_CONSTEXPR
1755 assign(_InputIterator __first, _InputIterator __last)
1757 using _IterTraits = iterator_traits<_InputIterator>;
1758 if constexpr (is_pointer<
decltype(std::__niter_base(__first))>::value
1759 && is_same<
typename _IterTraits::value_type,
1762 __glibcxx_requires_valid_range(__first, __last);
1763 return _M_replace(size_type(0),
size(),
1764 std::__niter_base(__first), __last - __first);
1766#if __cplusplus >= 202002L
1767 else if constexpr (contiguous_iterator<_InputIterator>
1768 && is_same_v<iter_value_t<_InputIterator>,
1771 __glibcxx_requires_valid_range(__first, __last);
1772 return _M_replace(size_type(0),
size(),
1779#pragma GCC diagnostic pop
1781 template<
class _InputIterator>
1783 assign(_InputIterator __first, _InputIterator __last)
1787#if __cplusplus >= 201103L
1793 _GLIBCXX20_CONSTEXPR
1795 assign(initializer_list<_CharT> __l)
1799 const size_type __n = __l.
size();
1805 _S_copy(_M_data(), __l.begin(), __n);
1812#if __cplusplus >= 201703L
1818 template<
typename _Tp>
1819 _GLIBCXX20_CONSTEXPR
1820 _If_sv<_Tp, basic_string&>
1823 __sv_type __sv = __svt;
1824 return this->
assign(__sv.data(), __sv.size());
1834 template<
typename _Tp>
1835 _GLIBCXX20_CONSTEXPR
1836 _If_sv<_Tp, basic_string&>
1837 assign(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
1839 __sv_type __sv = __svt;
1840 return _M_replace(size_type(0), this->
size(),
1842 + std::__sv_check(__sv.size(), __pos,
"basic_string::assign"),
1843 std::__sv_limit(__sv.size(), __pos, __n));
1847#if __cplusplus >= 201103L
1863 _GLIBCXX20_CONSTEXPR
1865 insert(const_iterator __p, size_type __n, _CharT __c)
1867 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1868 const size_type __pos = __p -
begin();
1869 this->
replace(__p, __p, __n, __c);
1870 return iterator(this->_M_data() + __pos);
1887 insert(iterator __p, size_type __n, _CharT __c)
1888 { this->
replace(__p, __p, __n, __c); }
1891#if __cplusplus >= 201103L
1906 template<
class _InputIterator,
1907 typename = std::_RequireInputIter<_InputIterator>>
1908 _GLIBCXX20_CONSTEXPR
1910 insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
1912 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1913 const size_type __pos = __p -
begin();
1914 this->
replace(__p, __p, __beg, __end);
1915 return iterator(this->_M_data() + __pos);
1930 template<
class _InputIterator>
1932 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1933 { this->
replace(__p, __p, __beg, __end); }
1936#if __cplusplus >= 201103L
1943 _GLIBCXX20_CONSTEXPR
1945 insert(const_iterator __p, initializer_list<_CharT> __l)
1946 {
return this->
insert(__p, __l.begin(), __l.end()); }
1948#ifdef _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
1951 insert(iterator __p, initializer_list<_CharT> __l)
1953 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1954 this->
insert(__p -
begin(), __l.begin(), __l.size());
1971 _GLIBCXX20_CONSTEXPR
1974 {
return this->
replace(__pos1, size_type(0),
1975 __str._M_data(), __str.size()); }
1995 _GLIBCXX20_CONSTEXPR
1998 size_type __pos2, size_type __n =
npos)
1999 {
return this->
replace(__pos1, size_type(0), __str._M_data()
2000 + __str._M_check(__pos2,
"basic_string::insert"),
2001 __str._M_limit(__pos2, __n)); }
2019 _GLIBCXX20_CONSTEXPR
2021 insert(size_type __pos,
const _CharT* __s, size_type __n)
2022 {
return this->
replace(__pos, size_type(0), __s, __n); }
2039 _GLIBCXX20_CONSTEXPR
2041 insert(size_type __pos,
const _CharT* __s)
2043 __glibcxx_requires_string(__s);
2044 return this->
replace(__pos, size_type(0), __s,
2045 traits_type::length(__s));
2064 _GLIBCXX20_CONSTEXPR
2066 insert(size_type __pos, size_type __n, _CharT __c)
2067 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
2068 size_type(0), __n, __c); }
2083 _GLIBCXX20_CONSTEXPR
2085 insert(__const_iterator __p, _CharT __c)
2087 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
2088 const size_type __pos = __p -
begin();
2089 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
2090 return iterator(_M_data() + __pos);
2093#if __cplusplus >= 201703L
2100 template<
typename _Tp>
2101 _GLIBCXX20_CONSTEXPR
2102 _If_sv<_Tp, basic_string&>
2103 insert(size_type __pos,
const _Tp& __svt)
2105 __sv_type __sv = __svt;
2106 return this->
insert(__pos, __sv.data(), __sv.size());
2117 template<
typename _Tp>
2118 _GLIBCXX20_CONSTEXPR
2119 _If_sv<_Tp, basic_string&>
2120 insert(size_type __pos1,
const _Tp& __svt,
2121 size_type __pos2, size_type __n =
npos)
2123 __sv_type __sv = __svt;
2124 return this->
replace(__pos1, size_type(0),
2126 + std::__sv_check(__sv.size(), __pos2,
"basic_string::insert"),
2127 std::__sv_limit(__sv.size(), __pos2, __n));
2146 _GLIBCXX20_CONSTEXPR
2148 erase(size_type __pos = 0, size_type __n =
npos)
2150 _M_check(__pos,
"basic_string::erase");
2152 this->_M_set_length(__pos);
2154 this->_M_erase(__pos, _M_limit(__pos, __n));
2166 _GLIBCXX20_CONSTEXPR
2168 erase(__const_iterator __position)
2170 _GLIBCXX_DEBUG_PEDASSERT(__position >=
begin()
2171 && __position <
end());
2172 const size_type __pos = __position -
begin();
2173 this->_M_erase(__pos, size_type(1));
2174 return iterator(_M_data() + __pos);
2186 _GLIBCXX20_CONSTEXPR
2188 erase(__const_iterator __first, __const_iterator __last)
2190 _GLIBCXX_DEBUG_PEDASSERT(__first >=
begin() && __first <= __last
2191 && __last <=
end());
2192 const size_type __pos = __first -
begin();
2193 if (__last ==
end())
2194 this->_M_set_length(__pos);
2196 this->_M_erase(__pos, __last - __first);
2197 return iterator(this->_M_data() + __pos);
2200#if __cplusplus >= 201103L
2206 _GLIBCXX20_CONSTEXPR
2210 __glibcxx_assert(!
empty());
2211 _M_erase(
size() - 1, 1);
2232 _GLIBCXX20_CONSTEXPR
2235 {
return this->
replace(__pos, __n, __str._M_data(), __str.size()); }
2255 _GLIBCXX20_CONSTEXPR
2258 size_type __pos2, size_type __n2 =
npos)
2259 {
return this->
replace(__pos1, __n1, __str._M_data()
2260 + __str._M_check(__pos2,
"basic_string::replace"),
2261 __str._M_limit(__pos2, __n2)); }
2281 _GLIBCXX20_CONSTEXPR
2283 replace(size_type __pos, size_type __n1,
const _CharT* __s,
2286 __glibcxx_requires_string_len(__s, __n2);
2287 return _M_replace(_M_check(__pos,
"basic_string::replace"),
2288 _M_limit(__pos, __n1), __s, __n2);
2307 _GLIBCXX20_CONSTEXPR
2309 replace(size_type __pos, size_type __n1,
const _CharT* __s)
2311 __glibcxx_requires_string(__s);
2312 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
2332 _GLIBCXX20_CONSTEXPR
2334 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
2335 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
2336 _M_limit(__pos, __n1), __n2, __c); }
2351 _GLIBCXX20_CONSTEXPR
2353 replace(__const_iterator __i1, __const_iterator __i2,
2355 {
return this->
replace(__i1, __i2, __str._M_data(), __str.size()); }
2372 _GLIBCXX20_CONSTEXPR
2374 replace(__const_iterator __i1, __const_iterator __i2,
2375 const _CharT* __s, size_type __n)
2377 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2379 return this->
replace(__i1 -
begin(), __i2 - __i1, __s, __n);
2395 _GLIBCXX20_CONSTEXPR
2397 replace(__const_iterator __i1, __const_iterator __i2,
const _CharT* __s)
2399 __glibcxx_requires_string(__s);
2400 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
2417 _GLIBCXX20_CONSTEXPR
2419 replace(__const_iterator __i1, __const_iterator __i2, size_type __n,
2422 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2424 return _M_replace_aux(__i1 -
begin(), __i2 - __i1, __n, __c);
2442#if __cplusplus >= 201103L
2443 template<
class _InputIterator,
2444 typename = std::_RequireInputIter<_InputIterator>>
2445 _GLIBCXX20_CONSTEXPR
2447 replace(const_iterator __i1, const_iterator __i2,
2448 _InputIterator __k1, _InputIterator __k2)
2450 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2452 __glibcxx_requires_valid_range(__k1, __k2);
2453 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
2454 std::__false_type());
2457 template<
class _InputIterator>
2458#ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
2459 typename __enable_if_not_native_iterator<_InputIterator>::__type
2463 replace(iterator __i1, iterator __i2,
2464 _InputIterator __k1, _InputIterator __k2)
2466 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2468 __glibcxx_requires_valid_range(__k1, __k2);
2469 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
2470 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
2476 _GLIBCXX20_CONSTEXPR
2478 replace(__const_iterator __i1, __const_iterator __i2,
2479 _CharT* __k1, _CharT* __k2)
2481 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2483 __glibcxx_requires_valid_range(__k1, __k2);
2488 _GLIBCXX20_CONSTEXPR
2490 replace(__const_iterator __i1, __const_iterator __i2,
2491 const _CharT* __k1,
const _CharT* __k2)
2493 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2495 __glibcxx_requires_valid_range(__k1, __k2);
2500 _GLIBCXX20_CONSTEXPR
2502 replace(__const_iterator __i1, __const_iterator __i2,
2503 iterator __k1, iterator __k2)
2505 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2507 __glibcxx_requires_valid_range(__k1, __k2);
2509 __k1.base(), __k2 - __k1);
2512 _GLIBCXX20_CONSTEXPR
2514 replace(__const_iterator __i1, __const_iterator __i2,
2515 const_iterator __k1, const_iterator __k2)
2517 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2519 __glibcxx_requires_valid_range(__k1, __k2);
2521 __k1.base(), __k2 - __k1);
2524#if __cplusplus >= 201103L
2539 _GLIBCXX20_CONSTEXPR
2541 initializer_list<_CharT> __l)
2542 {
return this->
replace(__i1, __i2, __l.begin(), __l.size()); }
2545#if __cplusplus >= 201703L
2553 template<
typename _Tp>
2554 _GLIBCXX20_CONSTEXPR
2555 _If_sv<_Tp, basic_string&>
2556 replace(size_type __pos, size_type __n,
const _Tp& __svt)
2558 __sv_type __sv = __svt;
2559 return this->
replace(__pos, __n, __sv.data(), __sv.size());
2571 template<
typename _Tp>
2572 _GLIBCXX20_CONSTEXPR
2573 _If_sv<_Tp, basic_string&>
2574 replace(size_type __pos1, size_type __n1,
const _Tp& __svt,
2575 size_type __pos2, size_type __n2 =
npos)
2577 __sv_type __sv = __svt;
2578 return this->
replace(__pos1, __n1,
2580 + std::__sv_check(__sv.size(), __pos2,
"basic_string::replace"),
2581 std::__sv_limit(__sv.size(), __pos2, __n2));
2593 template<
typename _Tp>
2594 _GLIBCXX20_CONSTEXPR
2595 _If_sv<_Tp, basic_string&>
2596 replace(const_iterator __i1, const_iterator __i2,
const _Tp& __svt)
2598 __sv_type __sv = __svt;
2599 return this->
replace(__i1 -
begin(), __i2 - __i1, __sv);
2604 template<
class _Integer>
2605 _GLIBCXX20_CONSTEXPR
2607 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2608 _Integer __n, _Integer __val, __true_type)
2609 {
return _M_replace_aux(__i1 -
begin(), __i2 - __i1, __n, __val); }
2611 template<
class _InputIterator>
2612 _GLIBCXX20_CONSTEXPR
2614 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2615 _InputIterator __k1, _InputIterator __k2,
2618 _GLIBCXX20_CONSTEXPR
2620 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
2623 __attribute__((__noinline__, __noclone__, __cold__))
void
2624 _M_replace_cold(pointer __p, size_type __len1,
const _CharT* __s,
2625 const size_type __len2,
const size_type __how_much);
2627 _GLIBCXX20_CONSTEXPR
2629 _M_replace(size_type __pos, size_type __len1,
const _CharT* __s,
2630 const size_type __len2);
2632 _GLIBCXX20_CONSTEXPR
2634 _M_append(
const _CharT* __s, size_type __n);
2650 _GLIBCXX20_CONSTEXPR
2652 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
2661 _GLIBCXX20_CONSTEXPR
2672 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2674 c_str() const _GLIBCXX_NOEXCEPT
2675 {
return _M_data(); }
2685 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2687 data() const _GLIBCXX_NOEXCEPT
2688 {
return _M_data(); }
2690#if __cplusplus >= 201703L
2697 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2700 {
return _M_data(); }
2706 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2709 {
return _M_get_allocator(); }
2723 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2725 find(
const _CharT* __s, size_type __pos, size_type __n)
const
2738 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2742 {
return this->
find(__str.data(), __pos, __str.size()); }
2744#if __cplusplus >= 201703L
2751 template<
typename _Tp>
2752 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2753 _If_sv<_Tp, size_type>
2754 find(
const _Tp& __svt, size_type __pos = 0) const
2755 noexcept(is_same<_Tp, __sv_type>::value)
2757 __sv_type __sv = __svt;
2758 return this->
find(__sv.data(), __pos, __sv.size());
2772 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2774 find(
const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2776 __glibcxx_requires_string(__s);
2777 return this->
find(__s, __pos, traits_type::length(__s));
2790 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2792 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
2804 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2808 {
return this->
rfind(__str.data(), __pos, __str.size()); }
2810#if __cplusplus >= 201703L
2817 template<
typename _Tp>
2818 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2819 _If_sv<_Tp, size_type>
2820 rfind(
const _Tp& __svt, size_type __pos =
npos)
const
2821 noexcept(is_same<_Tp, __sv_type>::value)
2823 __sv_type __sv = __svt;
2824 return this->
rfind(__sv.data(), __pos, __sv.size());
2840 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2842 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
2855 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2857 rfind(
const _CharT* __s, size_type __pos =
npos)
const
2859 __glibcxx_requires_string(__s);
2860 return this->
rfind(__s, __pos, traits_type::length(__s));
2873 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2875 rfind(_CharT __c, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT;
2888 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2892 {
return this->
find_first_of(__str.data(), __pos, __str.size()); }
2894#if __cplusplus >= 201703L
2902 template<
typename _Tp>
2903 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2904 _If_sv<_Tp, size_type>
2906 noexcept(is_same<_Tp, __sv_type>::value)
2908 __sv_type __sv = __svt;
2909 return this->
find_first_of(__sv.data(), __pos, __sv.size());
2925 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2927 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2940 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2945 __glibcxx_requires_string(__s);
2946 return this->
find_first_of(__s, __pos, traits_type::length(__s));
2961 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2963 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2964 {
return this->
find(__c, __pos); }
2977 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2981 {
return this->
find_last_of(__str.data(), __pos, __str.size()); }
2983#if __cplusplus >= 201703L
2991 template<
typename _Tp>
2992 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2993 _If_sv<_Tp, size_type>
2995 noexcept(is_same<_Tp, __sv_type>::value)
2997 __sv_type __sv = __svt;
2998 return this->
find_last_of(__sv.data(), __pos, __sv.size());
3014 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3016 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
3029 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3034 __glibcxx_requires_string(__s);
3035 return this->
find_last_of(__s, __pos, traits_type::length(__s));
3050 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3053 {
return this->
rfind(__c, __pos); }
3065 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3071#if __cplusplus >= 201703L
3079 template<
typename _Tp>
3080 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3081 _If_sv<_Tp, size_type>
3083 noexcept(is_same<_Tp, __sv_type>::value)
3085 __sv_type __sv = __svt;
3102 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3105 size_type __n)
const _GLIBCXX_NOEXCEPT;
3117 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3122 __glibcxx_requires_string(__s);
3136 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3152 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3158#if __cplusplus >= 201703L
3166 template<
typename _Tp>
3167 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3168 _If_sv<_Tp, size_type>
3170 noexcept(is_same<_Tp, __sv_type>::value)
3172 __sv_type __sv = __svt;
3189 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3192 size_type __n)
const _GLIBCXX_NOEXCEPT;
3204 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3209 __glibcxx_requires_string(__s);
3223 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3240 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3242 substr(size_type __pos = 0, size_type __n =
npos)
const
3244 _M_check(__pos,
"basic_string::substr"), __n); }
3260 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3264 const size_type __size = this->
size();
3265 const size_type __osize = __str.size();
3266 const size_type __len =
std::min(__size, __osize);
3268 int __r = traits_type::compare(_M_data(), __str.data(), __len);
3270 __r = _S_compare(__size, __osize);
3274#if __cplusplus >= 201703L
3280 template<
typename _Tp>
3281 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3283 compare(
const _Tp& __svt)
const
3284 noexcept(is_same<_Tp, __sv_type>::value)
3286 __sv_type __sv = __svt;
3287 const size_type __size = this->
size();
3288 const size_type __osize = __sv.size();
3289 const size_type __len =
std::min(__size, __osize);
3291 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
3293 __r = _S_compare(__size, __osize);
3305 template<
typename _Tp>
3306 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3308 compare(size_type __pos, size_type __n,
const _Tp& __svt)
const
3309 noexcept(is_same<_Tp, __sv_type>::value)
3311 __sv_type __sv = __svt;
3312 return __sv_type(*this).substr(__pos, __n).compare(__sv);
3325 template<
typename _Tp>
3326 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3328 compare(size_type __pos1, size_type __n1,
const _Tp& __svt,
3329 size_type __pos2, size_type __n2 =
npos)
const
3330 noexcept(is_same<_Tp, __sv_type>::value)
3332 __sv_type __sv = __svt;
3333 return __sv_type(*
this)
3334 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3357 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3361 _M_check(__pos,
"basic_string::compare");
3362 __n = _M_limit(__pos, __n);
3363 const size_type __osize = __str.size();
3364 const size_type __len =
std::min(__n, __osize);
3365 int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len);
3367 __r = _S_compare(__n, __osize);
3394 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3397 size_type __pos2, size_type __n2 =
npos)
const
3399 _M_check(__pos1,
"basic_string::compare");
3400 __str._M_check(__pos2,
"basic_string::compare");
3401 __n1 = _M_limit(__pos1, __n1);
3402 __n2 = __str._M_limit(__pos2, __n2);
3403 const size_type __len =
std::min(__n1, __n2);
3404 int __r = traits_type::compare(_M_data() + __pos1,
3405 __str.data() + __pos2, __len);
3407 __r = _S_compare(__n1, __n2);
3425 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3427 compare(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
3429 __glibcxx_requires_string(__s);
3430 const size_type __size = this->
size();
3431 const size_type __osize = traits_type::length(__s);
3432 const size_type __len =
std::min(__size, __osize);
3433 int __r = traits_type::compare(_M_data(), __s, __len);
3435 __r = _S_compare(__size, __osize);
3460 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3462 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const
3464 __glibcxx_requires_string(__s);
3465 _M_check(__pos,
"basic_string::compare");
3466 __n1 = _M_limit(__pos, __n1);
3467 const size_type __osize = traits_type::length(__s);
3468 const size_type __len =
std::min(__n1, __osize);
3469 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
3471 __r = _S_compare(__n1, __osize);
3499 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3501 compare(size_type __pos, size_type __n1,
const _CharT* __s,
3502 size_type __n2)
const
3504 __glibcxx_requires_string_len(__s, __n2);
3505 _M_check(__pos,
"basic_string::compare");
3506 __n1 = _M_limit(__pos, __n1);
3507 const size_type __len =
std::min(__n1, __n2);
3508 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
3510 __r = _S_compare(__n1, __n2);
3514#if __cplusplus >= 202002L
3517 starts_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
3518 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3522 starts_with(_CharT __x)
const noexcept
3523 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3525 [[nodiscard, __gnu__::__nonnull__]]
3527 starts_with(
const _CharT* __x)
const noexcept
3528 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3532 ends_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
3533 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3537 ends_with(_CharT __x)
const noexcept
3538 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3540 [[nodiscard, __gnu__::__nonnull__]]
3542 ends_with(
const _CharT* __x)
const noexcept
3543 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3546#if __cplusplus > 202002L
3549 contains(basic_string_view<_CharT, _Traits> __x)
const noexcept
3550 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3554 contains(_CharT __x)
const noexcept
3555 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3557 [[nodiscard, __gnu__::__nonnull__]]
3559 contains(
const _CharT* __x)
const noexcept
3560 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3564 template<
typename,
typename,
typename>
friend class basic_stringbuf;
3566_GLIBCXX_END_NAMESPACE_CXX11
3567_GLIBCXX_END_NAMESPACE_VERSION
3571namespace std _GLIBCXX_VISIBILITY(default)
3573_GLIBCXX_BEGIN_NAMESPACE_VERSION
3575#if __cpp_deduction_guides >= 201606
3576_GLIBCXX_BEGIN_NAMESPACE_CXX11
3577 template<
typename _InputIterator,
typename _CharT
3578 =
typename iterator_traits<_InputIterator>::value_type,
3579 typename _Allocator = allocator<_CharT>,
3580 typename = _RequireInputIter<_InputIterator>,
3581 typename = _RequireAllocator<_Allocator>>
3582 basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
3583 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
3587 template<
typename _CharT,
typename _Traits,
3588 typename _Allocator = allocator<_CharT>,
3589 typename = _RequireAllocator<_Allocator>>
3590 basic_string(basic_string_view<_CharT, _Traits>,
const _Allocator& = _Allocator())
3591 -> basic_string<_CharT, _Traits, _Allocator>;
3593 template<
typename _CharT,
typename _Traits,
3594 typename _Allocator = allocator<_CharT>,
3595 typename = _RequireAllocator<_Allocator>>
3596 basic_string(basic_string_view<_CharT, _Traits>,
3597 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
3598 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
3599 const _Allocator& = _Allocator())
3600 -> basic_string<_CharT, _Traits, _Allocator>;
3601_GLIBCXX_END_NAMESPACE_CXX11
3604 template<
typename _Str>
3605 _GLIBCXX20_CONSTEXPR
3607 __str_concat(
typename _Str::value_type
const* __lhs,
3608 typename _Str::size_type __lhs_len,
3609 typename _Str::value_type
const* __rhs,
3610 typename _Str::size_type __rhs_len,
3611 typename _Str::allocator_type
const& __a)
3613 typedef typename _Str::allocator_type allocator_type;
3615 _Str __str(_Alloc_traits::_S_select_on_copy(__a));
3616 __str.reserve(__lhs_len + __rhs_len);
3617 __str.append(__lhs, __lhs_len);
3618 __str.append(__rhs, __rhs_len);
3629 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3630 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3631 inline basic_string<_CharT, _Traits, _Alloc>
3636 return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(),
3637 __rhs.c_str(), __rhs.size(),
3638 __lhs.get_allocator());
3647 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3648 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3649 inline basic_string<_CharT,_Traits,_Alloc>
3653 __glibcxx_requires_string(__lhs);
3655 return std::__str_concat<_Str>(__lhs, _Traits::length(__lhs),
3656 __rhs.c_str(), __rhs.size(),
3657 __rhs.get_allocator());
3666 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3667 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3668 inline basic_string<_CharT,_Traits,_Alloc>
3672 return std::__str_concat<_Str>(__builtin_addressof(__lhs), 1,
3673 __rhs.c_str(), __rhs.size(),
3674 __rhs.get_allocator());
3683 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3684 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3685 inline basic_string<_CharT, _Traits, _Alloc>
3687 const _CharT* __rhs)
3689 __glibcxx_requires_string(__rhs);
3691 return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(),
3692 __rhs, _Traits::length(__rhs),
3693 __lhs.get_allocator());
3701 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3702 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3703 inline basic_string<_CharT, _Traits, _Alloc>
3707 return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(),
3708 __builtin_addressof(__rhs), 1,
3709 __lhs.get_allocator());
3712#if __cplusplus >= 201103L
3713 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3714 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3715 inline basic_string<_CharT, _Traits, _Alloc>
3716 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3717 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3718 {
return std::move(__lhs.append(__rhs)); }
3720 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3721 _GLIBCXX20_CONSTEXPR
3722 inline basic_string<_CharT, _Traits, _Alloc>
3723 operator+(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3724 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3725 {
return std::move(__rhs.insert(0, __lhs)); }
3727 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3728 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3729 inline basic_string<_CharT, _Traits, _Alloc>
3730 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3731 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3733#if _GLIBCXX_USE_CXX11_ABI
3734 using _Alloc_traits = allocator_traits<_Alloc>;
3735 bool __use_rhs =
false;
3736 if _GLIBCXX17_CONSTEXPR (
typename _Alloc_traits::is_always_equal{})
3738 else if (__lhs.get_allocator() == __rhs.get_allocator())
3743 const auto __size = __lhs.size() + __rhs.size();
3744 if (__size > __lhs.capacity() && __size <= __rhs.capacity())
3745 return std::move(__rhs.insert(0, __lhs));
3750 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3751 _GLIBCXX_NODISCARD _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3752 inline basic_string<_CharT, _Traits, _Alloc>
3754 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3755 {
return std::move(__rhs.insert(0, __lhs)); }
3757 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3758 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3759 inline basic_string<_CharT, _Traits, _Alloc>
3761 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3762 {
return std::move(__rhs.insert(0, 1, __lhs)); }
3764 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3765 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3766 inline basic_string<_CharT, _Traits, _Alloc>
3767 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3768 const _CharT* __rhs)
3769 {
return std::move(__lhs.append(__rhs)); }
3771 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3772 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3773 inline basic_string<_CharT, _Traits, _Alloc>
3774 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3776 {
return std::move(__lhs.append(1, __rhs)); }
3779#if __glibcxx_string_view >= 202403L
3781 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3783 constexpr basic_string<_CharT, _Traits, _Alloc>
3784 operator+(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3785 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs)
3787 using _Str = basic_string<_CharT, _Traits, _Alloc>;
3788 return std::__str_concat<_Str>(__lhs.data(), __lhs.size(),
3789 __rhs.data(), __rhs.size(),
3790 __lhs.get_allocator());
3794 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3796 constexpr basic_string<_CharT, _Traits, _Alloc>
3797 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3798 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs)
3804 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3806 constexpr basic_string<_CharT, _Traits, _Alloc>
3807 operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
3808 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3810 using _Str = basic_string<_CharT, _Traits, _Alloc>;
3811 return std::__str_concat<_Str>(__lhs.data(), __lhs.size(),
3812 __rhs.data(), __rhs.size(),
3813 __rhs.get_allocator());
3817 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3819 constexpr basic_string<_CharT, _Traits, _Alloc>
3820 operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
3821 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3823 return std::move(__rhs.insert(0, __lhs));
3834 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3835 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3841 return __lhs.size() == __rhs.size()
3842 && !_Traits::compare(__lhs.data(), __rhs.data(), __lhs.size());
3851 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3852 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3855 const _CharT* __rhs)
3857 return __lhs.size() == _Traits::length(__rhs)
3858 && !_Traits::compare(__lhs.data(), __rhs, __lhs.size());
3861#if __cpp_lib_three_way_comparison
3869 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3874 ->
decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
3875 {
return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); }
3884 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3888 const _CharT* __rhs)
noexcept
3889 ->
decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
3890 {
return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); }
3898 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3901 operator==(
const _CharT* __lhs,
3902 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3903 {
return __rhs == __lhs; }
3912 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3915 operator!=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3916 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3918 {
return !(__lhs == __rhs); }
3926 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3929 operator!=(
const _CharT* __lhs,
3930 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3931 {
return !(__rhs == __lhs); }
3939 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3942 operator!=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3943 const _CharT* __rhs)
3944 {
return !(__lhs == __rhs); }
3953 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3956 operator<(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3957 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3959 {
return __lhs.compare(__rhs) < 0; }
3967 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3970 operator<(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3971 const _CharT* __rhs)
3972 {
return __lhs.compare(__rhs) < 0; }
3980 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3984 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3985 {
return __rhs.compare(__lhs) > 0; }
3994 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3997 operator>(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3998 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4000 {
return __lhs.compare(__rhs) > 0; }
4008 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4011 operator>(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4012 const _CharT* __rhs)
4013 {
return __lhs.compare(__rhs) > 0; }
4021 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4025 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4026 {
return __rhs.compare(__lhs) < 0; }
4035 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4038 operator<=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4039 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4041 {
return __lhs.compare(__rhs) <= 0; }
4049 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4052 operator<=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4053 const _CharT* __rhs)
4054 {
return __lhs.compare(__rhs) <= 0; }
4062 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4066 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4067 {
return __rhs.compare(__lhs) >= 0; }
4076 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4079 operator>=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4080 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4082 {
return __lhs.compare(__rhs) >= 0; }
4090 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4093 operator>=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4094 const _CharT* __rhs)
4095 {
return __lhs.compare(__rhs) >= 0; }
4103 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4107 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4108 {
return __rhs.compare(__lhs) <= 0; }
4118 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4119 _GLIBCXX20_CONSTEXPR
4123 _GLIBCXX_NOEXCEPT_IF(
noexcept(__lhs.swap(__rhs)))
4124 { __lhs.swap(__rhs); }
4139 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4140 basic_istream<_CharT, _Traits>&
4141 operator>>(basic_istream<_CharT, _Traits>& __is,
4142 basic_string<_CharT, _Traits, _Alloc>& __str);
4145 basic_istream<char>&
4157 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4164 return __ostream_insert(__os, __str.data(), __str.size());
4180 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4181 basic_istream<_CharT, _Traits>&
4182 getline(basic_istream<_CharT, _Traits>& __is,
4183 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
4197 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4198 inline basic_istream<_CharT, _Traits>&
4203#if __cplusplus >= 201103L
4205 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4206 inline basic_istream<_CharT, _Traits>&
4212 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4213 inline basic_istream<_CharT, _Traits>&
4220 basic_istream<char>&
4221 getline(basic_istream<char>& __in, basic_string<char>& __str,
4224#ifdef _GLIBCXX_USE_WCHAR_T
4226 basic_istream<wchar_t>&
4227 getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
4231_GLIBCXX_END_NAMESPACE_VERSION
4234#if __cplusplus >= 201103L
4239namespace std _GLIBCXX_VISIBILITY(default)
4241_GLIBCXX_BEGIN_NAMESPACE_VERSION
4242_GLIBCXX_BEGIN_NAMESPACE_CXX11
4246 stoi(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4247 {
return __gnu_cxx::__stoa<long, int>(&std::strtol,
"stoi", __str.c_str(),
4251 stol(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4252 {
return __gnu_cxx::__stoa(&std::strtol,
"stol", __str.c_str(),
4255 inline unsigned long
4256 stoul(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4257 {
return __gnu_cxx::__stoa(&std::strtoul,
"stoul", __str.c_str(),
4260#if _GLIBCXX_USE_C99_STDLIB
4262 stoll(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4263 {
return __gnu_cxx::__stoa(&std::strtoll,
"stoll", __str.c_str(),
4266 inline unsigned long long
4267 stoull(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4268 {
return __gnu_cxx::__stoa(&std::strtoull,
"stoull", __str.c_str(),
4270#elif __LONG_WIDTH__ == __LONG_LONG_WIDTH__
4272 stoll(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4273 {
return std::stol(__str, __idx, __base); }
4275 inline unsigned long long
4276 stoull(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4277 {
return std::stoul(__str, __idx, __base); }
4281 stod(
const string& __str,
size_t* __idx = 0)
4282 {
return __gnu_cxx::__stoa(&std::strtod,
"stod", __str.c_str(), __idx); }
4284#if _GLIBCXX_HAVE_STRTOF
4287 stof(
const string& __str,
size_t* __idx = 0)
4288 {
return __gnu_cxx::__stoa(&std::strtof,
"stof", __str.c_str(), __idx); }
4291 stof(
const string& __str,
size_t* __idx = 0)
4293 double __d = std::stod(__str, __idx);
4294 if (__builtin_isfinite(__d) && __d != 0.0)
4296 double __abs_d = __builtin_fabs(__d);
4297 if (__abs_d < __FLT_MIN__ || __abs_d > __FLT_MAX__)
4300 std::__throw_out_of_range(
"stof");
4307#if _GLIBCXX_HAVE_STRTOLD && ! _GLIBCXX_HAVE_BROKEN_STRTOLD
4309 stold(
const string& __str,
size_t* __idx = 0)
4310 {
return __gnu_cxx::__stoa(&std::strtold,
"stold", __str.c_str(), __idx); }
4311#elif __DBL_MANT_DIG__ == __LDBL_MANT_DIG__
4313 stold(
const string& __str,
size_t* __idx = 0)
4314 {
return std::stod(__str, __idx); }
4322 to_string(
int __val)
4323#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_INT__) <= 32
4327 const bool __neg = __val < 0;
4328 const unsigned __uval = __neg ? (unsigned)~__val + 1u : __val;
4329 const auto __len = __detail::__to_chars_len(__uval);
4331 __str.__resize_and_overwrite(__neg + __len, [=](
char* __p,
size_t __n) {
4333 __detail::__to_chars_10_impl(__p + (
int)__neg, __len, __uval);
4341 to_string(
unsigned __val)
4342#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_INT__) <= 32
4346 const auto __len = __detail::__to_chars_len(__val);
4348 __str.__resize_and_overwrite(__len, [__val](
char* __p,
size_t __n) {
4349 __detail::__to_chars_10_impl(__p, __n, __val);
4357 to_string(
long __val)
4358#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_LONG__) <= 32
4362 const bool __neg = __val < 0;
4363 const unsigned long __uval = __neg ? (
unsigned long)~__val + 1ul : __val;
4364 const auto __len = __detail::__to_chars_len(__uval);
4366 __str.__resize_and_overwrite(__neg + __len, [=](
char* __p,
size_t __n) {
4368 __detail::__to_chars_10_impl(__p + (
int)__neg, __len, __uval);
4376 to_string(
unsigned long __val)
4377#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_LONG__) <= 32
4381 const auto __len = __detail::__to_chars_len(__val);
4383 __str.__resize_and_overwrite(__len, [__val](
char* __p,
size_t __n) {
4384 __detail::__to_chars_10_impl(__p, __n, __val);
4392 to_string(
long long __val)
4394 const bool __neg = __val < 0;
4395 const unsigned long long __uval
4396 = __neg ? (
unsigned long long)~__val + 1ull : __val;
4397 const auto __len = __detail::__to_chars_len(__uval);
4399 __str.__resize_and_overwrite(__neg + __len, [=](
char* __p,
size_t __n) {
4401 __detail::__to_chars_10_impl(__p + (
int)__neg, __len, __uval);
4409 to_string(
unsigned long long __val)
4411 const auto __len = __detail::__to_chars_len(__val);
4413 __str.__resize_and_overwrite(__len, [__val](
char* __p,
size_t __n) {
4414 __detail::__to_chars_10_impl(__p, __n, __val);
4420#if __glibcxx_to_string >= 202306L
4424 to_string(
float __val)
4429 __str.resize_and_overwrite(__len,
4430 [__val, &__len] (
char* __p,
size_t __n) {
4431 auto [__end, __err] = std::to_chars(__p, __p + __n, __val);
4432 if (__err == errc{}) [[likely]]
4437 }
while (__str.empty());
4443 to_string(
double __val)
4448 __str.resize_and_overwrite(__len,
4449 [__val, &__len] (
char* __p,
size_t __n) {
4450 auto [__end, __err] = std::to_chars(__p, __p + __n, __val);
4451 if (__err == errc{}) [[likely]]
4456 }
while (__str.empty());
4462 to_string(
long double __val)
4467 __str.resize_and_overwrite(__len,
4468 [__val, &__len] (
char* __p,
size_t __n) {
4469 auto [__end, __err] = std::to_chars(__p, __p + __n, __val);
4470 if (__err == errc{}) [[likely]]
4475 }
while (__str.empty());
4478#elif _GLIBCXX_USE_C99_STDIO
4479#pragma GCC diagnostic push
4480#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
4485 to_string(
float __val)
4488 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
4489 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
4495 to_string(
double __val)
4498 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
4499 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
4505 to_string(
long double __val)
4508 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
4509 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
4512#pragma GCC diagnostic pop
4515#if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR
4517 stoi(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4518 {
return __gnu_cxx::__stoa<long, int>(&std::wcstol,
"stoi", __str.c_str(),
4522 stol(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4523 {
return __gnu_cxx::__stoa(&std::wcstol,
"stol", __str.c_str(),
4526 inline unsigned long
4527 stoul(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4528 {
return __gnu_cxx::__stoa(&std::wcstoul,
"stoul", __str.c_str(),
4532 stoll(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4533 {
return __gnu_cxx::__stoa(&std::wcstoll,
"stoll", __str.c_str(),
4536 inline unsigned long long
4537 stoull(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4538 {
return __gnu_cxx::__stoa(&std::wcstoull,
"stoull", __str.c_str(),
4543 stof(
const wstring& __str,
size_t* __idx = 0)
4544 {
return __gnu_cxx::__stoa(&std::wcstof,
"stof", __str.c_str(), __idx); }
4547 stod(
const wstring& __str,
size_t* __idx = 0)
4548 {
return __gnu_cxx::__stoa(&std::wcstod,
"stod", __str.c_str(), __idx); }
4551 stold(
const wstring& __str,
size_t* __idx = 0)
4552 {
return __gnu_cxx::__stoa(&std::wcstold,
"stold", __str.c_str(), __idx); }
4555#ifdef _GLIBCXX_USE_WCHAR_T
4556#pragma GCC diagnostic push
4557#pragma GCC diagnostic ignored "-Wc++17-extensions"
4558 _GLIBCXX20_CONSTEXPR
4560 __to_wstring_numeric(
const char* __s,
int __len,
wchar_t* __wout)
4564 if constexpr (wchar_t(
'0') == L
'0' && wchar_t(
'-') == L
'-'
4565 && wchar_t(
'.') == L
'.' && wchar_t(
'e') == L
'e')
4567 for (
int __i = 0; __i < __len; ++__i)
4568 __wout[__i] = (
wchar_t) __s[__i];
4573 for (
int __i =
'0'; __i <=
'9'; ++__i)
4574 __wc[__i] = L
'0' + __i;
4599 for (
int __i = 0; __i < __len; ++__i)
4600 __wout[__i] = __wc[(
int)__s[__i]];
4604#if __glibcxx_constexpr_string >= 201907L
4608#if __cplusplus >= 201703L
4609 __to_wstring_numeric(string_view __s)
4611 __to_wstring_numeric(
const string& __s)
4614 if constexpr (wchar_t(
'0') == L
'0' && wchar_t(
'-') == L
'-'
4615 && wchar_t(
'.') == L
'.' && wchar_t(
'e') == L
'e')
4616 return wstring(__s.data(), __s.data() + __s.size());
4620 auto __f = __s.data();
4621 __ws.__resize_and_overwrite(__s.size(),
4622 [__f] (
wchar_t* __to,
int __n) {
4623 std::__to_wstring_numeric(__f, __n, __to);
4629#pragma GCC diagnostic pop
4633 to_wstring(
int __val)
4634 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4638 to_wstring(
unsigned __val)
4639 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4643 to_wstring(
long __val)
4644 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4648 to_wstring(
unsigned long __val)
4649 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4653 to_wstring(
long long __val)
4654 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4658 to_wstring(
unsigned long long __val)
4659 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4661#if __glibcxx_to_string || _GLIBCXX_USE_C99_STDIO
4664 to_wstring(
float __val)
4665 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4669 to_wstring(
double __val)
4670 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4674 to_wstring(
long double __val)
4675 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4679_GLIBCXX_END_NAMESPACE_CXX11
4680_GLIBCXX_END_NAMESPACE_VERSION
4685#if __cplusplus >= 201103L
4689namespace std _GLIBCXX_VISIBILITY(default)
4691_GLIBCXX_BEGIN_NAMESPACE_VERSION
4696 template<
typename _CharT,
typename _Alloc,
4697 typename _StrT = basic_string<_CharT, char_traits<_CharT>, _Alloc>>
4698 struct __str_hash_base
4699 :
public __hash_base<size_t, _StrT>
4703 operator()(
const _StrT& __s)
const noexcept
4704 {
return _Hash_impl::hash(__s.data(), __s.length() *
sizeof(_CharT)); }
4707#ifndef _GLIBCXX_COMPATIBILITY_CXX0X
4709 template<
typename _Alloc>
4711 :
public __str_hash_base<char, _Alloc>
4715 template<
typename _Alloc>
4717 :
public __str_hash_base<wchar_t, _Alloc>
4720 template<
typename _Alloc>
4727#ifdef _GLIBCXX_USE_CHAR8_T
4729 template<
typename _Alloc>
4730 struct hash<basic_string<char8_t, char_traits<char8_t>, _Alloc>>
4731 :
public __str_hash_base<char8_t, _Alloc>
4736 template<
typename _Alloc>
4738 :
public __str_hash_base<char16_t, _Alloc>
4742 template<
typename _Alloc>
4744 :
public __str_hash_base<char32_t, _Alloc>
4747#if ! _GLIBCXX_INLINE_VERSION
4753#ifdef _GLIBCXX_USE_CHAR8_T
4754 template<>
struct __is_fast_hash<hash<u8string>> :
std::false_type { };
4758 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4759 struct __is_fast_hash<hash<basic_string<_CharT, _Traits, _Alloc>>>
4764#ifdef __glibcxx_string_udls
4765 inline namespace literals
4767 inline namespace string_literals
4769#pragma GCC diagnostic push
4770#pragma GCC diagnostic ignored "-Wliteral-suffix"
4772#if __glibcxx_constexpr_string >= 201907L
4773# define _GLIBCXX_STRING_CONSTEXPR constexpr
4775# define _GLIBCXX_STRING_CONSTEXPR
4778 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4779 inline basic_string<char>
4780 operator""s(
const char* __str,
size_t __len)
4781 {
return basic_string<char>{__str, __len}; }
4783 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4784 inline basic_string<wchar_t>
4785 operator""s(
const wchar_t* __str,
size_t __len)
4786 {
return basic_string<wchar_t>{__str, __len}; }
4788#ifdef _GLIBCXX_USE_CHAR8_T
4789 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4790 inline basic_string<char8_t>
4791 operator""s(
const char8_t* __str,
size_t __len)
4792 {
return basic_string<char8_t>{__str, __len}; }
4795 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4796 inline basic_string<char16_t>
4797 operator""s(
const char16_t* __str,
size_t __len)
4798 {
return basic_string<char16_t>{__str, __len}; }
4800 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4801 inline basic_string<char32_t>
4802 operator""s(
const char32_t* __str,
size_t __len)
4803 {
return basic_string<char32_t>{__str, __len}; }
4805#undef _GLIBCXX_STRING_CONSTEXPR
4806#pragma GCC diagnostic pop
4811#if __cplusplus >= 201703L
4812 namespace __detail::__variant
4814 template<
typename>
struct _Never_valueless_alt;
4818 template<
typename _Tp,
typename _Traits,
typename _Alloc>
4819 struct _Never_valueless_alt<
std::basic_string<_Tp, _Traits, _Alloc>>
4821 is_nothrow_move_constructible<std::basic_string<_Tp, _Traits, _Alloc>>,
4822 is_nothrow_move_assignable<std::basic_string<_Tp, _Traits, _Alloc>>
4828_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.