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);
347 {
return _M_dataplus; }
350 const allocator_type&
351 _M_get_allocator()
const
352 {
return _M_dataplus; }
355 __attribute__((__always_inline__))
358 _M_init_local_buf() _GLIBCXX_NOEXCEPT
360#if __glibcxx_is_constant_evaluated
361 if (std::is_constant_evaluated())
362 for (size_type __i = 0; __i <= _S_local_capacity; ++__i)
363 _M_local_buf[__i] = _CharT();
367 __attribute__((__always_inline__))
370 _M_use_local_data() _GLIBCXX_NOEXCEPT
372#if __cpp_lib_is_constant_evaluated
375 return _M_local_data();
380#ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
383 template<
typename _Tp,
bool _Requires =
384 !__are_same<_Tp, _CharT*>::__value
385 && !__are_same<_Tp, const _CharT*>::__value
386 && !__are_same<_Tp, iterator>::__value
387 && !__are_same<_Tp, const_iterator>::__value>
388 struct __enable_if_not_native_iterator
389 {
typedef basic_string& __type; };
390 template<
typename _Tp>
391 struct __enable_if_not_native_iterator<_Tp, false> { };
396 _M_check(size_type __pos,
const char* __s)
const
398 if (__pos > this->
size())
399 __throw_out_of_range_fmt(__N(
"%s: __pos (which is %zu) > "
400 "this->size() (which is %zu)"),
401 __s, __pos, this->
size());
407 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
410 __throw_length_error(__N(__s));
417 _M_limit(size_type __pos, size_type __off)
const _GLIBCXX_NOEXCEPT
419 const bool __testoff = __off < this->
size() - __pos;
420 return __testoff ? __off : this->
size() - __pos;
425 _M_disjunct(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
427 return (less<const _CharT*>()(__s, _M_data())
428 || less<const _CharT*>()(_M_data() + this->
size(), __s));
435 _S_copy(_CharT* __d,
const _CharT* __s, size_type __n)
438 traits_type::assign(*__d, *__s);
440 traits_type::copy(__d, __s, __n);
445 _S_move(_CharT* __d,
const _CharT* __s, size_type __n)
448 traits_type::assign(*__d, *__s);
450 traits_type::move(__d, __s, __n);
455 _S_assign(_CharT* __d, size_type __n, _CharT __c)
458 traits_type::assign(*__d, __c);
460 traits_type::assign(__d, __n, __c);
465 template<
class _Iterator>
468 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
470 for (; __k1 != __k2; ++__k1, (void)++__p)
471 traits_type::assign(*__p, *__k1);
476 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
477 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
481 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
483 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
487 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
488 { _S_copy(__p, __k1, __k2 - __k1); }
492 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
494 { _S_copy(__p, __k1, __k2 - __k1); }
498 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
500 const difference_type __d = difference_type(__n1 - __n2);
502 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
503 return __gnu_cxx::__numeric_traits<int>::__max;
504 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
505 return __gnu_cxx::__numeric_traits<int>::__min;
516 _M_mutate(size_type __pos, size_type __len1,
const _CharT* __s,
521 _M_erase(size_type __pos, size_type __n);
533 _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value)
534#if __cpp_concepts && __glibcxx_type_trait_variable_templates
535 requires is_default_constructible_v<_Alloc>
537 : _M_dataplus(_M_local_data())
549 : _M_dataplus(_M_local_data(), __a)
561 : _M_dataplus(_M_local_data(),
562 _Alloc_traits::_S_select_on_copy(__str._M_get_allocator()))
564 _M_construct(__str._M_data(), __str._M_data() + __str.length(),
578 const _Alloc& __a = _Alloc())
579 : _M_dataplus(_M_local_data(), __a)
581 const _CharT* __start = __str._M_data()
582 + __str._M_check(__pos,
"basic_string::basic_string");
583 _M_construct(__start, __start + __str._M_limit(__pos,
npos),
596 : _M_dataplus(_M_local_data())
598 const _CharT* __start = __str._M_data()
599 + __str._M_check(__pos,
"basic_string::basic_string");
600 _M_construct(__start, __start + __str._M_limit(__pos, __n),
613 size_type __n,
const _Alloc& __a)
614 : _M_dataplus(_M_local_data(), __a)
616 const _CharT* __start
617 = __str._M_data() + __str._M_check(__pos,
"string::string");
618 _M_construct(__start, __start + __str._M_limit(__pos, __n),
633 const _Alloc& __a = _Alloc())
634 : _M_dataplus(_M_local_data(), __a)
637 if (__s == 0 && __n > 0)
638 std::__throw_logic_error(__N(
"basic_string: "
639 "construction from null is not valid"));
648#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
651 template<
typename = _RequireAllocator<_Alloc>>
654 basic_string(
const _CharT* __s,
const _Alloc& __a = _Alloc())
655 : _M_dataplus(_M_local_data(), __a)
659 std::__throw_logic_error(__N(
"basic_string: "
660 "construction from null is not valid"));
661 const _CharT* __end = __s + traits_type::length(__s);
662 _M_construct(__s, __end, forward_iterator_tag());
671#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
674 template<
typename = _RequireAllocator<_Alloc>>
677 basic_string(size_type __n, _CharT __c,
const _Alloc& __a = _Alloc())
678 : _M_dataplus(_M_local_data(), __a)
679 { _M_construct(__n, __c); }
681#if __cplusplus >= 201103L
691 : _M_dataplus(_M_local_data(),
std::move(__str._M_get_allocator()))
693 if (__str._M_is_local())
696 traits_type::copy(_M_local_buf, __str._M_local_buf,
701 _M_data(__str._M_data());
702 _M_capacity(__str._M_allocated_capacity);
708 _M_length(__str.length());
709 __str._M_data(__str._M_use_local_data());
710 __str._M_set_length(0);
719 basic_string(initializer_list<_CharT> __l,
const _Alloc& __a = _Alloc())
720 : _M_dataplus(_M_local_data(), __a)
725 : _M_dataplus(_M_local_data(), __a)
730 noexcept(_Alloc_traits::_S_always_equal())
731 : _M_dataplus(_M_local_data(), __a)
733 if (__str._M_is_local())
736 traits_type::copy(_M_local_buf, __str._M_local_buf,
738 _M_length(__str.length());
739 __str._M_set_length(0);
741 else if (_Alloc_traits::_S_always_equal()
742 || __str.get_allocator() == __a)
744 _M_data(__str._M_data());
745 _M_length(__str.length());
746 _M_capacity(__str._M_allocated_capacity);
747 __str._M_data(__str._M_use_local_data());
748 __str._M_set_length(0);
755#if __cplusplus >= 202100L
766#if __cplusplus >= 201103L
767 template<
typename _InputIterator,
768 typename = std::_RequireInputIter<_InputIterator>>
770 template<
typename _InputIterator>
773 basic_string(_InputIterator __beg, _InputIterator __end,
774 const _Alloc& __a = _Alloc())
775 : _M_dataplus(_M_local_data(), __a), _M_string_length(0)
777#if __cplusplus >= 201103L
780 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
781 _M_construct_aux(__beg, __end, _Integral());
785#if __cplusplus >= 201703L
793 template<
typename _Tp,
794 typename = enable_if_t<is_convertible_v<const _Tp&, __sv_type>>>
796 basic_string(
const _Tp& __t, size_type __pos, size_type __n,
797 const _Alloc& __a = _Alloc())
805 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
808 basic_string(
const _Tp& __t,
const _Alloc& __a = _Alloc())
809 :
basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
827 return this->
assign(__str);
837 {
return this->
assign(__s); }
854#if __cplusplus >= 201103L
867 noexcept(_Alloc_traits::_S_nothrow_move())
869 const bool __equal_allocs = _Alloc_traits::_S_always_equal()
870 || _M_get_allocator() == __str._M_get_allocator();
871 if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign()
875 _M_destroy(_M_allocated_capacity);
876 _M_data(_M_local_data());
880 std::__alloc_on_move(_M_get_allocator(), __str._M_get_allocator());
882 if (__str._M_is_local())
890 this->_S_copy(_M_data(), __str._M_data(), __str.size());
891 _M_set_length(__str.size());
894 else if (_Alloc_traits::_S_propagate_on_move_assign() || __equal_allocs)
897 pointer __data =
nullptr;
898 size_type __capacity;
905 __capacity = _M_allocated_capacity;
908 _M_destroy(_M_allocated_capacity);
911 _M_data(__str._M_data());
912 _M_length(__str.length());
913 _M_capacity(__str._M_allocated_capacity);
916 __str._M_data(__data);
917 __str._M_capacity(__capacity);
920 __str._M_data(__str._M_use_local_data());
936 this->
assign(__l.begin(), __l.size());
941#if __cplusplus >= 201703L
946 template<
typename _Tp>
948 _If_sv<_Tp, basic_string&>
950 {
return this->
assign(__svt); }
957 operator __sv_type() const noexcept
958 {
return __sv_type(
data(),
size()); }
966 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
968 begin() _GLIBCXX_NOEXCEPT
969 {
return iterator(_M_data()); }
975 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
977 begin() const _GLIBCXX_NOEXCEPT
978 {
return const_iterator(_M_data()); }
984 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
986 end() _GLIBCXX_NOEXCEPT
987 {
return iterator(_M_data() + this->
size()); }
993 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
995 end() const _GLIBCXX_NOEXCEPT
996 {
return const_iterator(_M_data() + this->
size()); }
1003 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1005 rbegin() _GLIBCXX_NOEXCEPT
1006 {
return reverse_iterator(this->
end()); }
1013 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1014 const_reverse_iterator
1015 rbegin() const _GLIBCXX_NOEXCEPT
1016 {
return const_reverse_iterator(this->
end()); }
1023 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1025 rend() _GLIBCXX_NOEXCEPT
1026 {
return reverse_iterator(this->
begin()); }
1033 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1034 const_reverse_iterator
1035 rend() const _GLIBCXX_NOEXCEPT
1036 {
return const_reverse_iterator(this->
begin()); }
1038#if __cplusplus >= 201103L
1043 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1046 {
return const_iterator(this->_M_data()); }
1052 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1054 cend() const noexcept
1055 {
return const_iterator(this->_M_data() + this->
size()); }
1062 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1063 const_reverse_iterator
1065 {
return const_reverse_iterator(this->
end()); }
1072 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1073 const_reverse_iterator
1074 crend() const noexcept
1075 {
return const_reverse_iterator(this->
begin()); }
1082 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1084 size() const _GLIBCXX_NOEXCEPT
1086 size_type __sz = _M_string_length;
1088 __builtin_unreachable ();
1094 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1096 length() const _GLIBCXX_NOEXCEPT
1100 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1104 const size_t __diffmax
1105 = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max /
sizeof(_CharT);
1106 const size_t __allocmax = _Alloc_traits::max_size(_M_get_allocator());
1107 return (
std::min)(__diffmax, __allocmax) - 1;
1120 _GLIBCXX20_CONSTEXPR
1122 resize(size_type __n, _CharT __c);
1134 _GLIBCXX20_CONSTEXPR
1137 { this->
resize(__n, _CharT()); }
1139#if __cplusplus >= 201103L
1140#pragma GCC diagnostic push
1141#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1143 _GLIBCXX20_CONSTEXPR
1147#pragma GCC diagnostic pop
1150#ifdef __glibcxx_string_resize_and_overwrite
1180 template<
typename _Operation>
1182 resize_and_overwrite(size_type __n, _Operation __op);
1185#if __cplusplus >= 201103L
1187 template<
typename _Operation>
1188 _GLIBCXX20_CONSTEXPR
void
1196 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1200 size_t __sz = _M_is_local() ? size_type(_S_local_capacity)
1201 : _M_allocated_capacity;
1202 if (__sz < _S_local_capacity || __sz >
max_size ())
1203 __builtin_unreachable ();
1224 _GLIBCXX20_CONSTEXPR
1231#if __cplusplus > 201703L
1232 [[deprecated(
"use shrink_to_fit() instead")]]
1234 _GLIBCXX20_CONSTEXPR
1241 _GLIBCXX20_CONSTEXPR
1243 clear() _GLIBCXX_NOEXCEPT
1244 { _M_set_length(0); }
1250 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1252 empty() const _GLIBCXX_NOEXCEPT
1253 {
return _M_string_length == 0; }
1266 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1268 operator[] (size_type __pos)
const _GLIBCXX_NOEXCEPT
1270 __glibcxx_assert(__pos <=
size());
1271 return _M_data()[__pos];
1284 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1290 __glibcxx_assert(__pos <=
size());
1292 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos <
size());
1293 return _M_data()[__pos];
1306 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1308 at(size_type __n)
const
1310 if (__n >= this->
size())
1311 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1312 "(which is %zu) >= this->size() "
1315 return _M_data()[__n];
1328 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1333 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1334 "(which is %zu) >= this->size() "
1337 return _M_data()[__n];
1340#if __cplusplus >= 201103L
1345 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1349 __glibcxx_assert(!
empty());
1357 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1359 front() const noexcept
1361 __glibcxx_assert(!
empty());
1369 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1373 __glibcxx_assert(!
empty());
1381 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1383 back() const noexcept
1385 __glibcxx_assert(!
empty());
1396 _GLIBCXX20_CONSTEXPR
1399 {
return this->
append(__str); }
1406 _GLIBCXX20_CONSTEXPR
1409 {
return this->
append(__s); }
1416 _GLIBCXX20_CONSTEXPR
1424#if __cplusplus >= 201103L
1430 _GLIBCXX20_CONSTEXPR
1433 {
return this->
append(__l.begin(), __l.size()); }
1436#if __cplusplus >= 201703L
1442 template<
typename _Tp>
1443 _GLIBCXX20_CONSTEXPR
1444 _If_sv<_Tp, basic_string&>
1446 {
return this->
append(__svt); }
1454 _GLIBCXX20_CONSTEXPR
1457 {
return this->
append(__str._M_data(), __str.size()); }
1472 _GLIBCXX20_CONSTEXPR
1475 {
return this->
append(__str._M_data()
1476 + __str._M_check(__pos,
"basic_string::append"),
1477 __str._M_limit(__pos, __n)); }
1485 _GLIBCXX20_CONSTEXPR
1487 append(
const _CharT* __s, size_type __n)
1489 __glibcxx_requires_string_len(__s, __n);
1490 _M_check_length(size_type(0), __n,
"basic_string::append");
1491 return _M_append(__s, __n);
1499 _GLIBCXX20_CONSTEXPR
1501 append(
const _CharT* __s)
1503 __glibcxx_requires_string(__s);
1504 const size_type __n = traits_type::length(__s);
1505 _M_check_length(size_type(0), __n,
"basic_string::append");
1506 return _M_append(__s, __n);
1517 _GLIBCXX20_CONSTEXPR
1519 append(size_type __n, _CharT __c)
1520 {
return _M_replace_aux(this->
size(), size_type(0), __n, __c); }
1522#if __cplusplus >= 201103L
1528 _GLIBCXX20_CONSTEXPR
1530 append(initializer_list<_CharT> __l)
1531 {
return this->
append(__l.begin(), __l.size()); }
1542#if __cplusplus >= 201103L
1543 template<
class _InputIterator,
1544 typename = std::_RequireInputIter<_InputIterator>>
1545 _GLIBCXX20_CONSTEXPR
1547 template<
class _InputIterator>
1550 append(_InputIterator __first, _InputIterator __last)
1553#if __cplusplus >= 201703L
1559 template<
typename _Tp>
1560 _GLIBCXX20_CONSTEXPR
1561 _If_sv<_Tp, basic_string&>
1564 __sv_type __sv = __svt;
1565 return this->
append(__sv.data(), __sv.size());
1575 template<
typename _Tp>
1576 _GLIBCXX20_CONSTEXPR
1577 _If_sv<_Tp, basic_string&>
1578 append(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
1580 __sv_type __sv = __svt;
1581 return _M_append(__sv.data()
1582 + std::__sv_check(__sv.size(), __pos,
"basic_string::append"),
1583 std::__sv_limit(__sv.size(), __pos, __n));
1591 _GLIBCXX20_CONSTEXPR
1595 const size_type __size = this->
size();
1597 this->_M_mutate(__size, size_type(0), 0, size_type(1));
1598 traits_type::assign(this->_M_data()[__size], __c);
1599 this->_M_set_length(__size + 1);
1607 _GLIBCXX20_CONSTEXPR
1611#if __cplusplus >= 201103L
1612 if (_Alloc_traits::_S_propagate_on_copy_assign())
1614 if (!_Alloc_traits::_S_always_equal() && !_M_is_local()
1615 && _M_get_allocator() != __str._M_get_allocator())
1619 if (__str.size() <= _S_local_capacity)
1621 _M_destroy(_M_allocated_capacity);
1622 _M_data(_M_use_local_data());
1627 const auto __len = __str.size();
1628 auto __alloc = __str._M_get_allocator();
1630 auto __ptr = _S_allocate(__alloc, __len + 1);
1631 _M_destroy(_M_allocated_capacity);
1634 _M_set_length(__len);
1637 std::__alloc_on_copy(_M_get_allocator(), __str._M_get_allocator());
1640 this->_M_assign(__str);
1644#if __cplusplus >= 201103L
1653 _GLIBCXX20_CONSTEXPR
1656 noexcept(_Alloc_traits::_S_nothrow_move())
1677 _GLIBCXX20_CONSTEXPR
1680 {
return _M_replace(size_type(0), this->
size(), __str._M_data()
1681 + __str._M_check(__pos,
"basic_string::assign"),
1682 __str._M_limit(__pos, __n)); }
1694 _GLIBCXX20_CONSTEXPR
1696 assign(
const _CharT* __s, size_type __n)
1698 __glibcxx_requires_string_len(__s, __n);
1699 return _M_replace(size_type(0), this->
size(), __s, __n);
1711 _GLIBCXX20_CONSTEXPR
1713 assign(
const _CharT* __s)
1715 __glibcxx_requires_string(__s);
1716 return _M_replace(size_type(0), this->
size(), __s,
1717 traits_type::length(__s));
1729 _GLIBCXX20_CONSTEXPR
1731 assign(size_type __n, _CharT __c)
1732 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
1742#if __cplusplus >= 201103L
1743#pragma GCC diagnostic push
1744#pragma GCC diagnostic ignored "-Wc++17-extensions"
1745 template<
class _InputIterator,
1746 typename = std::_RequireInputIter<_InputIterator>>
1747 _GLIBCXX20_CONSTEXPR
1749 assign(_InputIterator __first, _InputIterator __last)
1751 using _IterTraits = iterator_traits<_InputIterator>;
1752 if constexpr (is_pointer<
decltype(std::__niter_base(__first))>::value
1753 && is_same<
typename _IterTraits::value_type,
1756 __glibcxx_requires_valid_range(__first, __last);
1757 return _M_replace(size_type(0),
size(),
1758 std::__niter_base(__first), __last - __first);
1760#if __cplusplus >= 202002L
1761 else if constexpr (contiguous_iterator<_InputIterator>
1762 && is_same_v<iter_value_t<_InputIterator>,
1765 __glibcxx_requires_valid_range(__first, __last);
1766 return _M_replace(size_type(0),
size(),
1773#pragma GCC diagnostic pop
1775 template<
class _InputIterator>
1777 assign(_InputIterator __first, _InputIterator __last)
1781#if __cplusplus >= 201103L
1787 _GLIBCXX20_CONSTEXPR
1789 assign(initializer_list<_CharT> __l)
1793 const size_type __n = __l.
size();
1799 _S_copy(_M_data(), __l.begin(), __n);
1806#if __cplusplus >= 201703L
1812 template<
typename _Tp>
1813 _GLIBCXX20_CONSTEXPR
1814 _If_sv<_Tp, basic_string&>
1817 __sv_type __sv = __svt;
1818 return this->
assign(__sv.data(), __sv.size());
1828 template<
typename _Tp>
1829 _GLIBCXX20_CONSTEXPR
1830 _If_sv<_Tp, basic_string&>
1831 assign(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
1833 __sv_type __sv = __svt;
1834 return _M_replace(size_type(0), this->
size(),
1836 + std::__sv_check(__sv.size(), __pos,
"basic_string::assign"),
1837 std::__sv_limit(__sv.size(), __pos, __n));
1841#if __cplusplus >= 201103L
1857 _GLIBCXX20_CONSTEXPR
1859 insert(const_iterator __p, size_type __n, _CharT __c)
1861 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1862 const size_type __pos = __p -
begin();
1863 this->
replace(__p, __p, __n, __c);
1864 return iterator(this->_M_data() + __pos);
1881 insert(iterator __p, size_type __n, _CharT __c)
1882 { this->
replace(__p, __p, __n, __c); }
1885#if __cplusplus >= 201103L
1900 template<
class _InputIterator,
1901 typename = std::_RequireInputIter<_InputIterator>>
1902 _GLIBCXX20_CONSTEXPR
1904 insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
1906 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1907 const size_type __pos = __p -
begin();
1908 this->
replace(__p, __p, __beg, __end);
1909 return iterator(this->_M_data() + __pos);
1924 template<
class _InputIterator>
1926 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1927 { this->
replace(__p, __p, __beg, __end); }
1930#if __cplusplus >= 201103L
1937 _GLIBCXX20_CONSTEXPR
1939 insert(const_iterator __p, initializer_list<_CharT> __l)
1940 {
return this->
insert(__p, __l.begin(), __l.end()); }
1942#ifdef _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
1945 insert(iterator __p, initializer_list<_CharT> __l)
1947 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1948 this->
insert(__p -
begin(), __l.begin(), __l.size());
1965 _GLIBCXX20_CONSTEXPR
1968 {
return this->
replace(__pos1, size_type(0),
1969 __str._M_data(), __str.size()); }
1989 _GLIBCXX20_CONSTEXPR
1992 size_type __pos2, size_type __n =
npos)
1993 {
return this->
replace(__pos1, size_type(0), __str._M_data()
1994 + __str._M_check(__pos2,
"basic_string::insert"),
1995 __str._M_limit(__pos2, __n)); }
2013 _GLIBCXX20_CONSTEXPR
2015 insert(size_type __pos,
const _CharT* __s, size_type __n)
2016 {
return this->
replace(__pos, size_type(0), __s, __n); }
2033 _GLIBCXX20_CONSTEXPR
2035 insert(size_type __pos,
const _CharT* __s)
2037 __glibcxx_requires_string(__s);
2038 return this->
replace(__pos, size_type(0), __s,
2039 traits_type::length(__s));
2058 _GLIBCXX20_CONSTEXPR
2060 insert(size_type __pos, size_type __n, _CharT __c)
2061 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
2062 size_type(0), __n, __c); }
2077 _GLIBCXX20_CONSTEXPR
2079 insert(__const_iterator __p, _CharT __c)
2081 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
2082 const size_type __pos = __p -
begin();
2083 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
2084 return iterator(_M_data() + __pos);
2087#if __cplusplus >= 201703L
2094 template<
typename _Tp>
2095 _GLIBCXX20_CONSTEXPR
2096 _If_sv<_Tp, basic_string&>
2097 insert(size_type __pos,
const _Tp& __svt)
2099 __sv_type __sv = __svt;
2100 return this->
insert(__pos, __sv.data(), __sv.size());
2111 template<
typename _Tp>
2112 _GLIBCXX20_CONSTEXPR
2113 _If_sv<_Tp, basic_string&>
2114 insert(size_type __pos1,
const _Tp& __svt,
2115 size_type __pos2, size_type __n =
npos)
2117 __sv_type __sv = __svt;
2118 return this->
replace(__pos1, size_type(0),
2120 + std::__sv_check(__sv.size(), __pos2,
"basic_string::insert"),
2121 std::__sv_limit(__sv.size(), __pos2, __n));
2140 _GLIBCXX20_CONSTEXPR
2142 erase(size_type __pos = 0, size_type __n =
npos)
2144 _M_check(__pos,
"basic_string::erase");
2146 this->_M_set_length(__pos);
2148 this->_M_erase(__pos, _M_limit(__pos, __n));
2160 _GLIBCXX20_CONSTEXPR
2162 erase(__const_iterator __position)
2164 _GLIBCXX_DEBUG_PEDASSERT(__position >=
begin()
2165 && __position <
end());
2166 const size_type __pos = __position -
begin();
2167 this->_M_erase(__pos, size_type(1));
2168 return iterator(_M_data() + __pos);
2180 _GLIBCXX20_CONSTEXPR
2182 erase(__const_iterator __first, __const_iterator __last)
2184 _GLIBCXX_DEBUG_PEDASSERT(__first >=
begin() && __first <= __last
2185 && __last <=
end());
2186 const size_type __pos = __first -
begin();
2187 if (__last ==
end())
2188 this->_M_set_length(__pos);
2190 this->_M_erase(__pos, __last - __first);
2191 return iterator(this->_M_data() + __pos);
2194#if __cplusplus >= 201103L
2200 _GLIBCXX20_CONSTEXPR
2204 __glibcxx_assert(!
empty());
2205 _M_erase(
size() - 1, 1);
2226 _GLIBCXX20_CONSTEXPR
2229 {
return this->
replace(__pos, __n, __str._M_data(), __str.size()); }
2249 _GLIBCXX20_CONSTEXPR
2252 size_type __pos2, size_type __n2 =
npos)
2253 {
return this->
replace(__pos1, __n1, __str._M_data()
2254 + __str._M_check(__pos2,
"basic_string::replace"),
2255 __str._M_limit(__pos2, __n2)); }
2275 _GLIBCXX20_CONSTEXPR
2277 replace(size_type __pos, size_type __n1,
const _CharT* __s,
2280 __glibcxx_requires_string_len(__s, __n2);
2281 return _M_replace(_M_check(__pos,
"basic_string::replace"),
2282 _M_limit(__pos, __n1), __s, __n2);
2301 _GLIBCXX20_CONSTEXPR
2303 replace(size_type __pos, size_type __n1,
const _CharT* __s)
2305 __glibcxx_requires_string(__s);
2306 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
2326 _GLIBCXX20_CONSTEXPR
2328 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
2329 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
2330 _M_limit(__pos, __n1), __n2, __c); }
2345 _GLIBCXX20_CONSTEXPR
2347 replace(__const_iterator __i1, __const_iterator __i2,
2349 {
return this->
replace(__i1, __i2, __str._M_data(), __str.size()); }
2366 _GLIBCXX20_CONSTEXPR
2368 replace(__const_iterator __i1, __const_iterator __i2,
2369 const _CharT* __s, size_type __n)
2371 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2373 return this->
replace(__i1 -
begin(), __i2 - __i1, __s, __n);
2389 _GLIBCXX20_CONSTEXPR
2391 replace(__const_iterator __i1, __const_iterator __i2,
const _CharT* __s)
2393 __glibcxx_requires_string(__s);
2394 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
2411 _GLIBCXX20_CONSTEXPR
2413 replace(__const_iterator __i1, __const_iterator __i2, size_type __n,
2416 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2418 return _M_replace_aux(__i1 -
begin(), __i2 - __i1, __n, __c);
2436#if __cplusplus >= 201103L
2437 template<
class _InputIterator,
2438 typename = std::_RequireInputIter<_InputIterator>>
2439 _GLIBCXX20_CONSTEXPR
2441 replace(const_iterator __i1, const_iterator __i2,
2442 _InputIterator __k1, _InputIterator __k2)
2444 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2446 __glibcxx_requires_valid_range(__k1, __k2);
2447 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
2448 std::__false_type());
2451 template<
class _InputIterator>
2452#ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
2453 typename __enable_if_not_native_iterator<_InputIterator>::__type
2457 replace(iterator __i1, iterator __i2,
2458 _InputIterator __k1, _InputIterator __k2)
2460 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2462 __glibcxx_requires_valid_range(__k1, __k2);
2463 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
2464 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
2470 _GLIBCXX20_CONSTEXPR
2472 replace(__const_iterator __i1, __const_iterator __i2,
2473 _CharT* __k1, _CharT* __k2)
2475 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2477 __glibcxx_requires_valid_range(__k1, __k2);
2482 _GLIBCXX20_CONSTEXPR
2484 replace(__const_iterator __i1, __const_iterator __i2,
2485 const _CharT* __k1,
const _CharT* __k2)
2487 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2489 __glibcxx_requires_valid_range(__k1, __k2);
2494 _GLIBCXX20_CONSTEXPR
2496 replace(__const_iterator __i1, __const_iterator __i2,
2497 iterator __k1, iterator __k2)
2499 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2501 __glibcxx_requires_valid_range(__k1, __k2);
2503 __k1.base(), __k2 - __k1);
2506 _GLIBCXX20_CONSTEXPR
2508 replace(__const_iterator __i1, __const_iterator __i2,
2509 const_iterator __k1, const_iterator __k2)
2511 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2513 __glibcxx_requires_valid_range(__k1, __k2);
2515 __k1.base(), __k2 - __k1);
2518#if __cplusplus >= 201103L
2533 _GLIBCXX20_CONSTEXPR
2535 initializer_list<_CharT> __l)
2536 {
return this->
replace(__i1, __i2, __l.begin(), __l.size()); }
2539#if __cplusplus >= 201703L
2547 template<
typename _Tp>
2548 _GLIBCXX20_CONSTEXPR
2549 _If_sv<_Tp, basic_string&>
2550 replace(size_type __pos, size_type __n,
const _Tp& __svt)
2552 __sv_type __sv = __svt;
2553 return this->
replace(__pos, __n, __sv.data(), __sv.size());
2565 template<
typename _Tp>
2566 _GLIBCXX20_CONSTEXPR
2567 _If_sv<_Tp, basic_string&>
2568 replace(size_type __pos1, size_type __n1,
const _Tp& __svt,
2569 size_type __pos2, size_type __n2 =
npos)
2571 __sv_type __sv = __svt;
2572 return this->
replace(__pos1, __n1,
2574 + std::__sv_check(__sv.size(), __pos2,
"basic_string::replace"),
2575 std::__sv_limit(__sv.size(), __pos2, __n2));
2587 template<
typename _Tp>
2588 _GLIBCXX20_CONSTEXPR
2589 _If_sv<_Tp, basic_string&>
2590 replace(const_iterator __i1, const_iterator __i2,
const _Tp& __svt)
2592 __sv_type __sv = __svt;
2593 return this->
replace(__i1 -
begin(), __i2 - __i1, __sv);
2598 template<
class _Integer>
2599 _GLIBCXX20_CONSTEXPR
2601 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2602 _Integer __n, _Integer __val, __true_type)
2603 {
return _M_replace_aux(__i1 -
begin(), __i2 - __i1, __n, __val); }
2605 template<
class _InputIterator>
2606 _GLIBCXX20_CONSTEXPR
2608 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2609 _InputIterator __k1, _InputIterator __k2,
2612 _GLIBCXX20_CONSTEXPR
2614 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
2617 __attribute__((__noinline__, __noclone__, __cold__))
void
2618 _M_replace_cold(pointer __p, size_type __len1,
const _CharT* __s,
2619 const size_type __len2,
const size_type __how_much);
2621 _GLIBCXX20_CONSTEXPR
2623 _M_replace(size_type __pos, size_type __len1,
const _CharT* __s,
2624 const size_type __len2);
2626 _GLIBCXX20_CONSTEXPR
2628 _M_append(
const _CharT* __s, size_type __n);
2644 _GLIBCXX20_CONSTEXPR
2646 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
2655 _GLIBCXX20_CONSTEXPR
2666 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2668 c_str() const _GLIBCXX_NOEXCEPT
2669 {
return _M_data(); }
2679 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2681 data() const _GLIBCXX_NOEXCEPT
2682 {
return _M_data(); }
2684#if __cplusplus >= 201703L
2691 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2694 {
return _M_data(); }
2700 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2703 {
return _M_get_allocator(); }
2717 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2719 find(
const _CharT* __s, size_type __pos, size_type __n)
const
2732 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2736 {
return this->
find(__str.data(), __pos, __str.size()); }
2738#if __cplusplus >= 201703L
2745 template<
typename _Tp>
2746 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2747 _If_sv<_Tp, size_type>
2748 find(
const _Tp& __svt, size_type __pos = 0) const
2749 noexcept(is_same<_Tp, __sv_type>::value)
2751 __sv_type __sv = __svt;
2752 return this->
find(__sv.data(), __pos, __sv.size());
2766 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2768 find(
const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2770 __glibcxx_requires_string(__s);
2771 return this->
find(__s, __pos, traits_type::length(__s));
2784 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2786 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
2798 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2802 {
return this->
rfind(__str.data(), __pos, __str.size()); }
2804#if __cplusplus >= 201703L
2811 template<
typename _Tp>
2812 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2813 _If_sv<_Tp, size_type>
2814 rfind(
const _Tp& __svt, size_type __pos =
npos)
const
2815 noexcept(is_same<_Tp, __sv_type>::value)
2817 __sv_type __sv = __svt;
2818 return this->
rfind(__sv.data(), __pos, __sv.size());
2834 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2836 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
2849 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2851 rfind(
const _CharT* __s, size_type __pos =
npos)
const
2853 __glibcxx_requires_string(__s);
2854 return this->
rfind(__s, __pos, traits_type::length(__s));
2867 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2869 rfind(_CharT __c, size_type __pos =
npos)
const _GLIBCXX_NOEXCEPT;
2882 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2886 {
return this->
find_first_of(__str.data(), __pos, __str.size()); }
2888#if __cplusplus >= 201703L
2896 template<
typename _Tp>
2897 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2898 _If_sv<_Tp, size_type>
2900 noexcept(is_same<_Tp, __sv_type>::value)
2902 __sv_type __sv = __svt;
2903 return this->
find_first_of(__sv.data(), __pos, __sv.size());
2919 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2921 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2934 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2939 __glibcxx_requires_string(__s);
2940 return this->
find_first_of(__s, __pos, traits_type::length(__s));
2955 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2957 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2958 {
return this->
find(__c, __pos); }
2971 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2975 {
return this->
find_last_of(__str.data(), __pos, __str.size()); }
2977#if __cplusplus >= 201703L
2985 template<
typename _Tp>
2986 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2987 _If_sv<_Tp, size_type>
2989 noexcept(is_same<_Tp, __sv_type>::value)
2991 __sv_type __sv = __svt;
2992 return this->
find_last_of(__sv.data(), __pos, __sv.size());
3008 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3010 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
3023 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3028 __glibcxx_requires_string(__s);
3029 return this->
find_last_of(__s, __pos, traits_type::length(__s));
3044 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3047 {
return this->
rfind(__c, __pos); }
3059 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3065#if __cplusplus >= 201703L
3073 template<
typename _Tp>
3074 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3075 _If_sv<_Tp, size_type>
3077 noexcept(is_same<_Tp, __sv_type>::value)
3079 __sv_type __sv = __svt;
3096 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3099 size_type __n)
const _GLIBCXX_NOEXCEPT;
3111 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3116 __glibcxx_requires_string(__s);
3130 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3146 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3152#if __cplusplus >= 201703L
3160 template<
typename _Tp>
3161 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3162 _If_sv<_Tp, size_type>
3164 noexcept(is_same<_Tp, __sv_type>::value)
3166 __sv_type __sv = __svt;
3183 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3186 size_type __n)
const _GLIBCXX_NOEXCEPT;
3198 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3203 __glibcxx_requires_string(__s);
3217 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3234 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3236 substr(size_type __pos = 0, size_type __n =
npos)
const
3238 _M_check(__pos,
"basic_string::substr"), __n); }
3254 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3258 const size_type __size = this->
size();
3259 const size_type __osize = __str.size();
3260 const size_type __len =
std::min(__size, __osize);
3262 int __r = traits_type::compare(_M_data(), __str.data(), __len);
3264 __r = _S_compare(__size, __osize);
3268#if __cplusplus >= 201703L
3274 template<
typename _Tp>
3275 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3277 compare(
const _Tp& __svt)
const
3278 noexcept(is_same<_Tp, __sv_type>::value)
3280 __sv_type __sv = __svt;
3281 const size_type __size = this->
size();
3282 const size_type __osize = __sv.size();
3283 const size_type __len =
std::min(__size, __osize);
3285 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
3287 __r = _S_compare(__size, __osize);
3299 template<
typename _Tp>
3300 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3302 compare(size_type __pos, size_type __n,
const _Tp& __svt)
const
3303 noexcept(is_same<_Tp, __sv_type>::value)
3305 __sv_type __sv = __svt;
3306 return __sv_type(*this).substr(__pos, __n).compare(__sv);
3319 template<
typename _Tp>
3320 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3322 compare(size_type __pos1, size_type __n1,
const _Tp& __svt,
3323 size_type __pos2, size_type __n2 =
npos)
const
3324 noexcept(is_same<_Tp, __sv_type>::value)
3326 __sv_type __sv = __svt;
3327 return __sv_type(*
this)
3328 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3351 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3355 _M_check(__pos,
"basic_string::compare");
3356 __n = _M_limit(__pos, __n);
3357 const size_type __osize = __str.size();
3358 const size_type __len =
std::min(__n, __osize);
3359 int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len);
3361 __r = _S_compare(__n, __osize);
3388 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3391 size_type __pos2, size_type __n2 =
npos)
const
3393 _M_check(__pos1,
"basic_string::compare");
3394 __str._M_check(__pos2,
"basic_string::compare");
3395 __n1 = _M_limit(__pos1, __n1);
3396 __n2 = __str._M_limit(__pos2, __n2);
3397 const size_type __len =
std::min(__n1, __n2);
3398 int __r = traits_type::compare(_M_data() + __pos1,
3399 __str.data() + __pos2, __len);
3401 __r = _S_compare(__n1, __n2);
3419 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3421 compare(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
3423 __glibcxx_requires_string(__s);
3424 const size_type __size = this->
size();
3425 const size_type __osize = traits_type::length(__s);
3426 const size_type __len =
std::min(__size, __osize);
3427 int __r = traits_type::compare(_M_data(), __s, __len);
3429 __r = _S_compare(__size, __osize);
3454 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3456 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const
3458 __glibcxx_requires_string(__s);
3459 _M_check(__pos,
"basic_string::compare");
3460 __n1 = _M_limit(__pos, __n1);
3461 const size_type __osize = traits_type::length(__s);
3462 const size_type __len =
std::min(__n1, __osize);
3463 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
3465 __r = _S_compare(__n1, __osize);
3493 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3495 compare(size_type __pos, size_type __n1,
const _CharT* __s,
3496 size_type __n2)
const
3498 __glibcxx_requires_string_len(__s, __n2);
3499 _M_check(__pos,
"basic_string::compare");
3500 __n1 = _M_limit(__pos, __n1);
3501 const size_type __len =
std::min(__n1, __n2);
3502 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
3504 __r = _S_compare(__n1, __n2);
3508#if __cplusplus >= 202002L
3511 starts_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
3512 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3516 starts_with(_CharT __x)
const noexcept
3517 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3519 [[nodiscard, __gnu__::__nonnull__]]
3521 starts_with(
const _CharT* __x)
const noexcept
3522 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3526 ends_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
3527 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3531 ends_with(_CharT __x)
const noexcept
3532 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3534 [[nodiscard, __gnu__::__nonnull__]]
3536 ends_with(
const _CharT* __x)
const noexcept
3537 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3540#if __cplusplus > 202002L
3543 contains(basic_string_view<_CharT, _Traits> __x)
const noexcept
3544 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3548 contains(_CharT __x)
const noexcept
3549 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3551 [[nodiscard, __gnu__::__nonnull__]]
3553 contains(
const _CharT* __x)
const noexcept
3554 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3558 template<
typename,
typename,
typename>
friend class basic_stringbuf;
3560_GLIBCXX_END_NAMESPACE_CXX11
3561_GLIBCXX_END_NAMESPACE_VERSION
3565namespace std _GLIBCXX_VISIBILITY(default)
3567_GLIBCXX_BEGIN_NAMESPACE_VERSION
3569#if __cpp_deduction_guides >= 201606
3570_GLIBCXX_BEGIN_NAMESPACE_CXX11
3571 template<
typename _InputIterator,
typename _CharT
3572 =
typename iterator_traits<_InputIterator>::value_type,
3573 typename _Allocator = allocator<_CharT>,
3574 typename = _RequireInputIter<_InputIterator>,
3575 typename = _RequireAllocator<_Allocator>>
3576 basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
3577 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
3581 template<
typename _CharT,
typename _Traits,
3582 typename _Allocator = allocator<_CharT>,
3583 typename = _RequireAllocator<_Allocator>>
3584 basic_string(basic_string_view<_CharT, _Traits>,
const _Allocator& = _Allocator())
3585 -> basic_string<_CharT, _Traits, _Allocator>;
3587 template<
typename _CharT,
typename _Traits,
3588 typename _Allocator = allocator<_CharT>,
3589 typename = _RequireAllocator<_Allocator>>
3590 basic_string(basic_string_view<_CharT, _Traits>,
3591 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
3592 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
3593 const _Allocator& = _Allocator())
3594 -> basic_string<_CharT, _Traits, _Allocator>;
3595_GLIBCXX_END_NAMESPACE_CXX11
3598 template<
typename _Str>
3599 _GLIBCXX20_CONSTEXPR
3601 __str_concat(
typename _Str::value_type
const* __lhs,
3602 typename _Str::size_type __lhs_len,
3603 typename _Str::value_type
const* __rhs,
3604 typename _Str::size_type __rhs_len,
3605 typename _Str::allocator_type
const& __a)
3607 typedef typename _Str::allocator_type allocator_type;
3609 _Str __str(_Alloc_traits::_S_select_on_copy(__a));
3610 __str.reserve(__lhs_len + __rhs_len);
3611 __str.append(__lhs, __lhs_len);
3612 __str.append(__rhs, __rhs_len);
3623 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3624 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3625 inline basic_string<_CharT, _Traits, _Alloc>
3630 return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(),
3631 __rhs.c_str(), __rhs.size(),
3632 __lhs.get_allocator());
3641 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3642 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3643 inline basic_string<_CharT,_Traits,_Alloc>
3647 __glibcxx_requires_string(__lhs);
3649 return std::__str_concat<_Str>(__lhs, _Traits::length(__lhs),
3650 __rhs.c_str(), __rhs.size(),
3651 __rhs.get_allocator());
3660 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3661 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3662 inline basic_string<_CharT,_Traits,_Alloc>
3666 return std::__str_concat<_Str>(__builtin_addressof(__lhs), 1,
3667 __rhs.c_str(), __rhs.size(),
3668 __rhs.get_allocator());
3677 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3678 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3679 inline basic_string<_CharT, _Traits, _Alloc>
3681 const _CharT* __rhs)
3683 __glibcxx_requires_string(__rhs);
3685 return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(),
3686 __rhs, _Traits::length(__rhs),
3687 __lhs.get_allocator());
3695 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3696 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3697 inline basic_string<_CharT, _Traits, _Alloc>
3701 return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(),
3702 __builtin_addressof(__rhs), 1,
3703 __lhs.get_allocator());
3706#if __cplusplus >= 201103L
3707 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3708 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3709 inline basic_string<_CharT, _Traits, _Alloc>
3710 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3711 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3712 {
return std::move(__lhs.append(__rhs)); }
3714 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3715 _GLIBCXX20_CONSTEXPR
3716 inline basic_string<_CharT, _Traits, _Alloc>
3717 operator+(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3718 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3719 {
return std::move(__rhs.insert(0, __lhs)); }
3721 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3722 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3723 inline basic_string<_CharT, _Traits, _Alloc>
3724 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3725 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3727#if _GLIBCXX_USE_CXX11_ABI
3728 using _Alloc_traits = allocator_traits<_Alloc>;
3729 bool __use_rhs =
false;
3730 if _GLIBCXX17_CONSTEXPR (
typename _Alloc_traits::is_always_equal{})
3732 else if (__lhs.get_allocator() == __rhs.get_allocator())
3737 const auto __size = __lhs.size() + __rhs.size();
3738 if (__size > __lhs.capacity() && __size <= __rhs.capacity())
3739 return std::move(__rhs.insert(0, __lhs));
3744 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3745 _GLIBCXX_NODISCARD _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3746 inline basic_string<_CharT, _Traits, _Alloc>
3748 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3749 {
return std::move(__rhs.insert(0, __lhs)); }
3751 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3752 _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, 1, __lhs)); }
3758 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3759 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3760 inline basic_string<_CharT, _Traits, _Alloc>
3761 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3762 const _CharT* __rhs)
3763 {
return std::move(__lhs.append(__rhs)); }
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,
3770 {
return std::move(__lhs.append(1, __rhs)); }
3773#if __glibcxx_string_view >= 202403L
3775 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3777 constexpr basic_string<_CharT, _Traits, _Alloc>
3778 operator+(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3779 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs)
3781 using _Str = basic_string<_CharT, _Traits, _Alloc>;
3782 return std::__str_concat<_Str>(__lhs.data(), __lhs.size(),
3783 __rhs.data(), __rhs.size(),
3784 __lhs.get_allocator());
3788 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3790 constexpr basic_string<_CharT, _Traits, _Alloc>
3791 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3792 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs)
3798 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3800 constexpr basic_string<_CharT, _Traits, _Alloc>
3801 operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
3802 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3804 using _Str = basic_string<_CharT, _Traits, _Alloc>;
3805 return std::__str_concat<_Str>(__lhs.data(), __lhs.size(),
3806 __rhs.data(), __rhs.size(),
3807 __rhs.get_allocator());
3811 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3813 constexpr basic_string<_CharT, _Traits, _Alloc>
3814 operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
3815 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3817 return std::move(__rhs.insert(0, __lhs));
3828 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3829 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3835 return __lhs.size() == __rhs.size()
3836 && !_Traits::compare(__lhs.data(), __rhs.data(), __lhs.size());
3845 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3846 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
3849 const _CharT* __rhs)
3851 return __lhs.size() == _Traits::length(__rhs)
3852 && !_Traits::compare(__lhs.data(), __rhs, __lhs.size());
3855#if __cpp_lib_three_way_comparison
3863 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3868 ->
decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
3869 {
return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); }
3878 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3882 const _CharT* __rhs)
noexcept
3883 ->
decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
3884 {
return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); }
3892 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3895 operator==(
const _CharT* __lhs,
3896 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3897 {
return __rhs == __lhs; }
3906 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3909 operator!=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3910 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3912 {
return !(__lhs == __rhs); }
3920 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3923 operator!=(
const _CharT* __lhs,
3924 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3925 {
return !(__rhs == __lhs); }
3933 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3936 operator!=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3937 const _CharT* __rhs)
3938 {
return !(__lhs == __rhs); }
3947 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3950 operator<(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3951 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3953 {
return __lhs.compare(__rhs) < 0; }
3961 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3964 operator<(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3965 const _CharT* __rhs)
3966 {
return __lhs.compare(__rhs) < 0; }
3974 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3978 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3979 {
return __rhs.compare(__lhs) > 0; }
3988 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3991 operator>(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3992 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3994 {
return __lhs.compare(__rhs) > 0; }
4002 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4005 operator>(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4006 const _CharT* __rhs)
4007 {
return __lhs.compare(__rhs) > 0; }
4015 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4019 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4020 {
return __rhs.compare(__lhs) < 0; }
4029 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4032 operator<=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4033 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4035 {
return __lhs.compare(__rhs) <= 0; }
4043 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4046 operator<=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4047 const _CharT* __rhs)
4048 {
return __lhs.compare(__rhs) <= 0; }
4056 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4060 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4061 {
return __rhs.compare(__lhs) >= 0; }
4070 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4073 operator>=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4074 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4076 {
return __lhs.compare(__rhs) >= 0; }
4084 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4087 operator>=(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4088 const _CharT* __rhs)
4089 {
return __lhs.compare(__rhs) >= 0; }
4097 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4101 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4102 {
return __rhs.compare(__lhs) <= 0; }
4112 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4113 _GLIBCXX20_CONSTEXPR
4117 _GLIBCXX_NOEXCEPT_IF(
noexcept(__lhs.swap(__rhs)))
4118 { __lhs.swap(__rhs); }
4133 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4134 basic_istream<_CharT, _Traits>&
4135 operator>>(basic_istream<_CharT, _Traits>& __is,
4136 basic_string<_CharT, _Traits, _Alloc>& __str);
4139 basic_istream<char>&
4151 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4158 return __ostream_insert(__os, __str.data(), __str.size());
4174 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4175 basic_istream<_CharT, _Traits>&
4176 getline(basic_istream<_CharT, _Traits>& __is,
4177 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
4191 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4192 inline basic_istream<_CharT, _Traits>&
4197#if __cplusplus >= 201103L
4199 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4200 inline basic_istream<_CharT, _Traits>&
4206 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4207 inline basic_istream<_CharT, _Traits>&
4214 basic_istream<char>&
4215 getline(basic_istream<char>& __in, basic_string<char>& __str,
4218#ifdef _GLIBCXX_USE_WCHAR_T
4220 basic_istream<wchar_t>&
4221 getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
4225_GLIBCXX_END_NAMESPACE_VERSION
4228#if __cplusplus >= 201103L
4233namespace std _GLIBCXX_VISIBILITY(default)
4235_GLIBCXX_BEGIN_NAMESPACE_VERSION
4236_GLIBCXX_BEGIN_NAMESPACE_CXX11
4240 stoi(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4241 {
return __gnu_cxx::__stoa<long, int>(&std::strtol,
"stoi", __str.c_str(),
4245 stol(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4246 {
return __gnu_cxx::__stoa(&std::strtol,
"stol", __str.c_str(),
4249 inline unsigned long
4250 stoul(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4251 {
return __gnu_cxx::__stoa(&std::strtoul,
"stoul", __str.c_str(),
4254#if _GLIBCXX_USE_C99_STDLIB
4256 stoll(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4257 {
return __gnu_cxx::__stoa(&std::strtoll,
"stoll", __str.c_str(),
4260 inline unsigned long long
4261 stoull(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4262 {
return __gnu_cxx::__stoa(&std::strtoull,
"stoull", __str.c_str(),
4264#elif __LONG_WIDTH__ == __LONG_LONG_WIDTH__
4266 stoll(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4267 {
return std::stol(__str, __idx, __base); }
4269 inline unsigned long long
4270 stoull(
const string& __str,
size_t* __idx = 0,
int __base = 10)
4271 {
return std::stoul(__str, __idx, __base); }
4275 stod(
const string& __str,
size_t* __idx = 0)
4276 {
return __gnu_cxx::__stoa(&std::strtod,
"stod", __str.c_str(), __idx); }
4278#if _GLIBCXX_HAVE_STRTOF
4281 stof(
const string& __str,
size_t* __idx = 0)
4282 {
return __gnu_cxx::__stoa(&std::strtof,
"stof", __str.c_str(), __idx); }
4285 stof(
const string& __str,
size_t* __idx = 0)
4287 double __d = std::stod(__str, __idx);
4288 if (__builtin_isfinite(__d) && __d != 0.0)
4290 double __abs_d = __builtin_fabs(__d);
4291 if (__abs_d < __FLT_MIN__ || __abs_d > __FLT_MAX__)
4294 std::__throw_out_of_range(
"stof");
4301#if _GLIBCXX_HAVE_STRTOLD && ! _GLIBCXX_HAVE_BROKEN_STRTOLD
4303 stold(
const string& __str,
size_t* __idx = 0)
4304 {
return __gnu_cxx::__stoa(&std::strtold,
"stold", __str.c_str(), __idx); }
4305#elif __DBL_MANT_DIG__ == __LDBL_MANT_DIG__
4307 stold(
const string& __str,
size_t* __idx = 0)
4308 {
return std::stod(__str, __idx); }
4316 to_string(
int __val)
4317#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_INT__) <= 32
4321 const bool __neg = __val < 0;
4322 const unsigned __uval = __neg ? (unsigned)~__val + 1u : __val;
4323 const auto __len = __detail::__to_chars_len(__uval);
4325 __str.__resize_and_overwrite(__neg + __len, [=](
char* __p,
size_t __n) {
4327 __detail::__to_chars_10_impl(__p + (
int)__neg, __len, __uval);
4335 to_string(
unsigned __val)
4336#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_INT__) <= 32
4340 const auto __len = __detail::__to_chars_len(__val);
4342 __str.__resize_and_overwrite(__len, [__val](
char* __p,
size_t __n) {
4343 __detail::__to_chars_10_impl(__p, __n, __val);
4351 to_string(
long __val)
4352#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_LONG__) <= 32
4356 const bool __neg = __val < 0;
4357 const unsigned long __uval = __neg ? (
unsigned long)~__val + 1ul : __val;
4358 const auto __len = __detail::__to_chars_len(__uval);
4360 __str.__resize_and_overwrite(__neg + __len, [=](
char* __p,
size_t __n) {
4362 __detail::__to_chars_10_impl(__p + (
int)__neg, __len, __uval);
4370 to_string(
unsigned long __val)
4371#if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_LONG__) <= 32
4375 const auto __len = __detail::__to_chars_len(__val);
4377 __str.__resize_and_overwrite(__len, [__val](
char* __p,
size_t __n) {
4378 __detail::__to_chars_10_impl(__p, __n, __val);
4386 to_string(
long long __val)
4388 const bool __neg = __val < 0;
4389 const unsigned long long __uval
4390 = __neg ? (
unsigned long long)~__val + 1ull : __val;
4391 const auto __len = __detail::__to_chars_len(__uval);
4393 __str.__resize_and_overwrite(__neg + __len, [=](
char* __p,
size_t __n) {
4395 __detail::__to_chars_10_impl(__p + (
int)__neg, __len, __uval);
4403 to_string(
unsigned long long __val)
4405 const auto __len = __detail::__to_chars_len(__val);
4407 __str.__resize_and_overwrite(__len, [__val](
char* __p,
size_t __n) {
4408 __detail::__to_chars_10_impl(__p, __n, __val);
4414#if __glibcxx_to_string >= 202306L
4418 to_string(
float __val)
4423 __str.resize_and_overwrite(__len,
4424 [__val, &__len] (
char* __p,
size_t __n) {
4425 auto [__end, __err] = std::to_chars(__p, __p + __n, __val);
4426 if (__err == errc{}) [[likely]]
4431 }
while (__str.empty());
4437 to_string(
double __val)
4442 __str.resize_and_overwrite(__len,
4443 [__val, &__len] (
char* __p,
size_t __n) {
4444 auto [__end, __err] = std::to_chars(__p, __p + __n, __val);
4445 if (__err == errc{}) [[likely]]
4450 }
while (__str.empty());
4456 to_string(
long double __val)
4461 __str.resize_and_overwrite(__len,
4462 [__val, &__len] (
char* __p,
size_t __n) {
4463 auto [__end, __err] = std::to_chars(__p, __p + __n, __val);
4464 if (__err == errc{}) [[likely]]
4469 }
while (__str.empty());
4472#elif _GLIBCXX_USE_C99_STDIO
4473#pragma GCC diagnostic push
4474#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
4479 to_string(
float __val)
4482 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
4483 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
4489 to_string(
double __val)
4492 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
4493 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
4499 to_string(
long double __val)
4502 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
4503 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
4506#pragma GCC diagnostic pop
4509#if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR
4511 stoi(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4512 {
return __gnu_cxx::__stoa<long, int>(&std::wcstol,
"stoi", __str.c_str(),
4516 stol(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4517 {
return __gnu_cxx::__stoa(&std::wcstol,
"stol", __str.c_str(),
4520 inline unsigned long
4521 stoul(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4522 {
return __gnu_cxx::__stoa(&std::wcstoul,
"stoul", __str.c_str(),
4526 stoll(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4527 {
return __gnu_cxx::__stoa(&std::wcstoll,
"stoll", __str.c_str(),
4530 inline unsigned long long
4531 stoull(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
4532 {
return __gnu_cxx::__stoa(&std::wcstoull,
"stoull", __str.c_str(),
4537 stof(
const wstring& __str,
size_t* __idx = 0)
4538 {
return __gnu_cxx::__stoa(&std::wcstof,
"stof", __str.c_str(), __idx); }
4541 stod(
const wstring& __str,
size_t* __idx = 0)
4542 {
return __gnu_cxx::__stoa(&std::wcstod,
"stod", __str.c_str(), __idx); }
4545 stold(
const wstring& __str,
size_t* __idx = 0)
4546 {
return __gnu_cxx::__stoa(&std::wcstold,
"stold", __str.c_str(), __idx); }
4549#ifdef _GLIBCXX_USE_WCHAR_T
4550#pragma GCC diagnostic push
4551#pragma GCC diagnostic ignored "-Wc++17-extensions"
4552 _GLIBCXX20_CONSTEXPR
4554 __to_wstring_numeric(
const char* __s,
int __len,
wchar_t* __wout)
4558 if constexpr (wchar_t(
'0') == L
'0' && wchar_t(
'-') == L
'-'
4559 && wchar_t(
'.') == L
'.' && wchar_t(
'e') == L
'e')
4561 for (
int __i = 0; __i < __len; ++__i)
4562 __wout[__i] = (
wchar_t) __s[__i];
4567 for (
int __i =
'0'; __i <=
'9'; ++__i)
4568 __wc[__i] = L
'0' + __i;
4591 for (
int __i = 0; __i < __len; ++__i)
4592 __wout[__i] = __wc[(
int)__s[__i]];
4596#if __glibcxx_constexpr_string >= 201907L
4600#if __cplusplus >= 201703L
4601 __to_wstring_numeric(string_view __s)
4603 __to_wstring_numeric(
const string& __s)
4606 if constexpr (wchar_t(
'0') == L
'0' && wchar_t(
'-') == L
'-'
4607 && wchar_t(
'.') == L
'.' && wchar_t(
'e') == L
'e')
4608 return wstring(__s.data(), __s.data() + __s.size());
4612 auto __f = __s.data();
4613 __ws.__resize_and_overwrite(__s.size(),
4614 [__f] (
wchar_t* __to,
int __n) {
4615 std::__to_wstring_numeric(__f, __n, __to);
4621#pragma GCC diagnostic pop
4625 to_wstring(
int __val)
4626 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4630 to_wstring(
unsigned __val)
4631 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4635 to_wstring(
long __val)
4636 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4640 to_wstring(
unsigned long __val)
4641 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4645 to_wstring(
long long __val)
4646 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4650 to_wstring(
unsigned long long __val)
4651 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4653#if __glibcxx_to_string || _GLIBCXX_USE_C99_STDIO
4656 to_wstring(
float __val)
4657 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4661 to_wstring(
double __val)
4662 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4666 to_wstring(
long double __val)
4667 {
return std::__to_wstring_numeric(std::to_string(__val)); }
4671_GLIBCXX_END_NAMESPACE_CXX11
4672_GLIBCXX_END_NAMESPACE_VERSION
4677#if __cplusplus >= 201103L
4681namespace std _GLIBCXX_VISIBILITY(default)
4683_GLIBCXX_BEGIN_NAMESPACE_VERSION
4688 template<
typename _CharT,
typename _Alloc,
4689 typename _StrT = basic_string<_CharT, char_traits<_CharT>, _Alloc>>
4690 struct __str_hash_base
4691 :
public __hash_base<size_t, _StrT>
4695 operator()(
const _StrT& __s)
const noexcept
4696 {
return _Hash_impl::hash(__s.data(), __s.length() *
sizeof(_CharT)); }
4699#ifndef _GLIBCXX_COMPATIBILITY_CXX0X
4701 template<
typename _Alloc>
4703 :
public __str_hash_base<char, _Alloc>
4707 template<
typename _Alloc>
4709 :
public __str_hash_base<wchar_t, _Alloc>
4712 template<
typename _Alloc>
4719#ifdef _GLIBCXX_USE_CHAR8_T
4721 template<
typename _Alloc>
4722 struct hash<basic_string<char8_t, char_traits<char8_t>, _Alloc>>
4723 :
public __str_hash_base<char8_t, _Alloc>
4728 template<
typename _Alloc>
4730 :
public __str_hash_base<char16_t, _Alloc>
4734 template<
typename _Alloc>
4736 :
public __str_hash_base<char32_t, _Alloc>
4739#if ! _GLIBCXX_INLINE_VERSION
4745#ifdef _GLIBCXX_USE_CHAR8_T
4746 template<>
struct __is_fast_hash<hash<u8string>> :
std::false_type { };
4750 template<
typename _CharT,
typename _Traits,
typename _Alloc>
4751 struct __is_fast_hash<hash<basic_string<_CharT, _Traits, _Alloc>>>
4756#ifdef __glibcxx_string_udls
4757 inline namespace literals
4759 inline namespace string_literals
4761#pragma GCC diagnostic push
4762#pragma GCC diagnostic ignored "-Wliteral-suffix"
4764#if __glibcxx_constexpr_string >= 201907L
4765# define _GLIBCXX_STRING_CONSTEXPR constexpr
4767# define _GLIBCXX_STRING_CONSTEXPR
4770 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4771 inline basic_string<char>
4772 operator""s(
const char* __str,
size_t __len)
4773 {
return basic_string<char>{__str, __len}; }
4775 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4776 inline basic_string<wchar_t>
4777 operator""s(
const wchar_t* __str,
size_t __len)
4778 {
return basic_string<wchar_t>{__str, __len}; }
4780#ifdef _GLIBCXX_USE_CHAR8_T
4781 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4782 inline basic_string<char8_t>
4783 operator""s(
const char8_t* __str,
size_t __len)
4784 {
return basic_string<char8_t>{__str, __len}; }
4787 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4788 inline basic_string<char16_t>
4789 operator""s(
const char16_t* __str,
size_t __len)
4790 {
return basic_string<char16_t>{__str, __len}; }
4792 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4793 inline basic_string<char32_t>
4794 operator""s(
const char32_t* __str,
size_t __len)
4795 {
return basic_string<char32_t>{__str, __len}; }
4797#undef _GLIBCXX_STRING_CONSTEXPR
4798#pragma GCC diagnostic pop
4803#if __cplusplus >= 201703L
4804 namespace __detail::__variant
4806 template<
typename>
struct _Never_valueless_alt;
4810 template<
typename _Tp,
typename _Traits,
typename _Alloc>
4811 struct _Never_valueless_alt<
std::basic_string<_Tp, _Traits, _Alloc>>
4813 is_nothrow_move_constructible<std::basic_string<_Tp, _Traits, _Alloc>>,
4814 is_nothrow_move_assignable<std::basic_string<_Tp, _Traits, _Alloc>>
4820_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.