34 #ifndef _BASIC_STRING_H
35 #define _BASIC_STRING_H 1
37 #pragma GCC system_header
43 #if __cplusplus >= 201103L
47 #if __cplusplus >= 201703L
51 namespace std _GLIBCXX_VISIBILITY(default)
53 _GLIBCXX_BEGIN_NAMESPACE_VERSION
55 #ifdef __cpp_lib_is_constant_evaluated
57 # define __cpp_lib_constexpr_string 201811L
58 #elif __cplusplus >= 201703L
60 # define __cpp_lib_constexpr_string 201611L
61 #elif __cplusplus > 201703L
64 #if _GLIBCXX_USE_CXX11_ABI
65 _GLIBCXX_BEGIN_NAMESPACE_CXX11
84 template<
typename _CharT,
typename _Traits,
typename _Alloc>
88 rebind<_CharT>::other _Char_alloc_type;
93 typedef _Traits traits_type;
94 typedef typename _Traits::char_type value_type;
95 typedef _Char_alloc_type allocator_type;
96 typedef typename _Alloc_traits::size_type size_type;
97 typedef typename _Alloc_traits::difference_type difference_type;
98 typedef typename _Alloc_traits::reference reference;
99 typedef typename _Alloc_traits::const_reference const_reference;
100 typedef typename _Alloc_traits::pointer pointer;
101 typedef typename _Alloc_traits::const_pointer const_pointer;
102 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
103 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
109 static const size_type
npos =
static_cast<size_type
>(-1);
113 #if __cplusplus < 201103L
114 typedef iterator __const_iterator;
116 typedef const_iterator __const_iterator;
120 #if __cplusplus >= 201703L
122 typedef basic_string_view<_CharT, _Traits> __sv_type;
124 template<
typename _Tp,
typename _Res>
126 __and_<is_convertible<const _Tp&, __sv_type>,
127 __not_<is_convertible<const _Tp*, const basic_string*>>,
128 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
133 _S_to_string_view(__sv_type __svt)
noexcept
142 explicit __sv_wrapper(__sv_type __sv)
noexcept : _M_sv(__sv) { }
153 basic_string(__sv_wrapper __svw,
const _Alloc& __a)
154 : basic_string(__svw._M_sv.
data(), __svw._M_sv.
size(), __a) { }
158 struct _Alloc_hider : allocator_type
160 #if __cplusplus < 201103L
161 _Alloc_hider(pointer __dat,
const _Alloc& __a = _Alloc())
162 : allocator_type(__a), _M_p(__dat) { }
164 _Alloc_hider(pointer __dat,
const _Alloc& __a)
165 : allocator_type(__a), _M_p(__dat) { }
167 _Alloc_hider(pointer __dat, _Alloc&& __a = _Alloc())
168 : allocator_type(std::
move(__a)), _M_p(__dat) { }
174 _Alloc_hider _M_dataplus;
175 size_type _M_string_length;
177 enum { _S_local_capacity = 15 /
sizeof(_CharT) };
181 _CharT _M_local_buf[_S_local_capacity + 1];
182 size_type _M_allocated_capacity;
187 { _M_dataplus._M_p = __p; }
190 _M_length(size_type __length)
191 { _M_string_length = __length; }
195 {
return _M_dataplus._M_p; }
200 #if __cplusplus >= 201103L
203 return pointer(_M_local_buf);
208 _M_local_data()
const
210 #if __cplusplus >= 201103L
213 return const_pointer(_M_local_buf);
218 _M_capacity(size_type __capacity)
219 { _M_allocated_capacity = __capacity; }
222 _M_set_length(size_type __n)
225 traits_type::assign(_M_data()[__n], _CharT());
230 {
return _M_data() == _M_local_data(); }
234 _M_create(size_type&, size_type);
240 _M_destroy(_M_allocated_capacity);
244 _M_destroy(size_type __size)
throw()
245 { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); }
249 template<
typename _InIterator>
251 _M_construct_aux(_InIterator __beg, _InIterator __end,
254 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
255 _M_construct(__beg, __end, _Tag());
260 template<
typename _Integer>
262 _M_construct_aux(_Integer __beg, _Integer __end, std::__true_type)
263 { _M_construct_aux_2(static_cast<size_type>(__beg), __end); }
266 _M_construct_aux_2(size_type __req, _CharT __c)
267 { _M_construct(__req, __c); }
269 template<
typename _InIterator>
271 _M_construct(_InIterator __beg, _InIterator __end)
273 typedef typename std::__is_integer<_InIterator>::__type _Integral;
274 _M_construct_aux(__beg, __end, _Integral());
278 template<
typename _InIterator>
280 _M_construct(_InIterator __beg, _InIterator __end,
285 template<
typename _FwdIterator>
287 _M_construct(_FwdIterator __beg, _FwdIterator __end,
291 _M_construct(size_type __req, _CharT __c);
295 {
return _M_dataplus; }
297 const allocator_type&
298 _M_get_allocator()
const
299 {
return _M_dataplus; }
303 #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
306 template<
typename _Tp,
bool _Requires =
307 !__are_same<_Tp, _CharT*>::__value
308 && !__are_same<_Tp, const _CharT*>::__value
309 && !__are_same<_Tp, iterator>::__value
310 && !__are_same<_Tp, const_iterator>::__value>
311 struct __enable_if_not_native_iterator
312 {
typedef basic_string& __type; };
313 template<
typename _Tp>
314 struct __enable_if_not_native_iterator<_Tp, false> { };
318 _M_check(size_type __pos,
const char* __s)
const
320 if (__pos > this->
size())
321 __throw_out_of_range_fmt(__N(
"%s: __pos (which is %zu) > "
322 "this->size() (which is %zu)"),
323 __s, __pos, this->
size());
328 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
330 if (this->max_size() - (this->
size() - __n1) < __n2)
331 __throw_length_error(__N(__s));
337 _M_limit(size_type __pos, size_type __off)
const _GLIBCXX_NOEXCEPT
339 const bool __testoff = __off < this->
size() - __pos;
340 return __testoff ? __off : this->
size() - __pos;
345 _M_disjunct(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
347 return (less<const _CharT*>()(__s, _M_data())
348 || less<const _CharT*>()(_M_data() + this->
size(), __s));
354 _S_copy(_CharT* __d,
const _CharT* __s, size_type __n)
357 traits_type::assign(*__d, *__s);
359 traits_type::copy(__d, __s, __n);
363 _S_move(_CharT* __d,
const _CharT* __s, size_type __n)
366 traits_type::assign(*__d, *__s);
372 _S_assign(_CharT* __d, size_type __n, _CharT __c)
375 traits_type::assign(*__d, __c);
377 traits_type::assign(__d, __n, __c);
382 template<
class _Iterator>
384 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
386 for (; __k1 != __k2; ++__k1, (void)++__p)
387 traits_type::assign(*__p, *__k1);
391 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
392 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
395 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
397 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
400 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
401 { _S_copy(__p, __k1, __k2 - __k1); }
404 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
406 { _S_copy(__p, __k1, __k2 - __k1); }
409 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
411 const difference_type __d = difference_type(__n1 - __n2);
413 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
414 return __gnu_cxx::__numeric_traits<int>::__max;
415 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
416 return __gnu_cxx::__numeric_traits<int>::__min;
422 _M_assign(
const basic_string&);
425 _M_mutate(size_type __pos, size_type __len1,
const _CharT* __s,
429 _M_erase(size_type __pos, size_type __n);
440 _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value)
441 : _M_dataplus(_M_local_data())
442 { _M_set_length(0); }
448 basic_string(
const _Alloc& __a) _GLIBCXX_NOEXCEPT
449 : _M_dataplus(_M_local_data(), __a)
450 { _M_set_length(0); }
456 basic_string(
const basic_string& __str)
457 : _M_dataplus(_M_local_data(),
458 _Alloc_traits::_S_select_on_copy(__str._M_get_allocator()))
459 { _M_construct(__str._M_data(), __str._M_data() + __str.length()); }
469 basic_string(
const basic_string& __str, size_type __pos,
470 const _Alloc& __a = _Alloc())
471 : _M_dataplus(_M_local_data(), __a)
473 const _CharT* __start = __str._M_data()
474 + __str._M_check(__pos,
"basic_string::basic_string");
475 _M_construct(__start, __start + __str._M_limit(__pos,
npos));
484 basic_string(
const basic_string& __str, size_type __pos,
486 : _M_dataplus(_M_local_data())
488 const _CharT* __start = __str._M_data()
489 + __str._M_check(__pos,
"basic_string::basic_string");
490 _M_construct(__start, __start + __str._M_limit(__pos, __n));
500 basic_string(
const basic_string& __str, size_type __pos,
501 size_type __n,
const _Alloc& __a)
502 : _M_dataplus(_M_local_data(), __a)
504 const _CharT* __start
505 = __str._M_data() + __str._M_check(__pos,
"string::string");
506 _M_construct(__start, __start + __str._M_limit(__pos, __n));
518 basic_string(
const _CharT* __s, size_type __n,
519 const _Alloc& __a = _Alloc())
520 : _M_dataplus(_M_local_data(), __a)
521 { _M_construct(__s, __s + __n); }
528 #if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
531 template<
typename = _RequireAllocator<_Alloc>>
533 basic_string(
const _CharT* __s,
const _Alloc& __a = _Alloc())
534 : _M_dataplus(_M_local_data(), __a)
536 const _CharT* __end = __s ? __s + traits_type::length(__s)
538 : reinterpret_cast<const _CharT*>(__alignof__(_CharT));
539 _M_construct(__s, __end, random_access_iterator_tag());
548 #if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
551 template<
typename = _RequireAllocator<_Alloc>>
553 basic_string(size_type __n, _CharT __c,
const _Alloc& __a = _Alloc())
554 : _M_dataplus(_M_local_data(), __a)
555 { _M_construct(__n, __c); }
557 #if __cplusplus >= 201103L
565 basic_string(basic_string&& __str)
noexcept
566 : _M_dataplus(_M_local_data(), std::
move(__str._M_get_allocator()))
568 if (__str._M_is_local())
570 traits_type::copy(_M_local_buf, __str._M_local_buf,
571 _S_local_capacity + 1);
575 _M_data(__str._M_data());
576 _M_capacity(__str._M_allocated_capacity);
582 _M_length(__str.length());
583 __str._M_data(__str._M_local_data());
584 __str._M_set_length(0);
592 basic_string(initializer_list<_CharT> __l,
const _Alloc& __a = _Alloc())
593 : _M_dataplus(_M_local_data(), __a)
594 { _M_construct(__l.begin(), __l.end()); }
596 basic_string(
const basic_string& __str,
const _Alloc& __a)
597 : _M_dataplus(_M_local_data(), __a)
598 { _M_construct(__str.begin(), __str.end()); }
600 basic_string(basic_string&& __str,
const _Alloc& __a)
601 noexcept(_Alloc_traits::_S_always_equal())
602 : _M_dataplus(_M_local_data(), __a)
604 if (__str._M_is_local())
606 traits_type::copy(_M_local_buf, __str._M_local_buf,
607 _S_local_capacity + 1);
608 _M_length(__str.length());
609 __str._M_set_length(0);
611 else if (_Alloc_traits::_S_always_equal()
612 || __str.get_allocator() == __a)
614 _M_data(__str._M_data());
615 _M_length(__str.length());
616 _M_capacity(__str._M_allocated_capacity);
617 __str._M_data(__str._M_local_buf);
618 __str._M_set_length(0);
621 _M_construct(__str.begin(), __str.end());
632 #if __cplusplus >= 201103L
633 template<
typename _InputIterator,
634 typename = std::_RequireInputIter<_InputIterator>>
636 template<
typename _InputIterator>
638 basic_string(_InputIterator __beg, _InputIterator __end,
639 const _Alloc& __a = _Alloc())
640 : _M_dataplus(_M_local_data(), __a)
641 { _M_construct(__beg, __end); }
643 #if __cplusplus >= 201703L
651 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
652 basic_string(
const _Tp& __t, size_type __pos, size_type __n,
653 const _Alloc& __a = _Alloc())
654 : basic_string(_S_to_string_view(__t).
substr(__pos, __n), __a) { }
661 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
663 basic_string(
const _Tp& __t,
const _Alloc& __a = _Alloc())
664 : basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
680 return this->
assign(__str);
689 {
return this->
assign(__s); }
705 #if __cplusplus >= 201103L
717 noexcept(_Alloc_traits::_S_nothrow_move())
719 if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign()
720 && !_Alloc_traits::_S_always_equal()
721 && _M_get_allocator() != __str._M_get_allocator())
724 _M_destroy(_M_allocated_capacity);
725 _M_data(_M_local_data());
729 std::__alloc_on_move(_M_get_allocator(), __str._M_get_allocator());
731 if (__str._M_is_local())
739 this->_S_copy(_M_data(), __str._M_data(), __str.size());
740 _M_set_length(__str.size());
743 else if (_Alloc_traits::_S_propagate_on_move_assign()
744 || _Alloc_traits::_S_always_equal()
745 || _M_get_allocator() == __str._M_get_allocator())
748 pointer __data =
nullptr;
749 size_type __capacity;
752 if (_Alloc_traits::_S_always_equal())
756 __capacity = _M_allocated_capacity;
759 _M_destroy(_M_allocated_capacity);
762 _M_data(__str._M_data());
763 _M_length(__str.length());
764 _M_capacity(__str._M_allocated_capacity);
767 __str._M_data(__data);
768 __str._M_capacity(__capacity);
771 __str._M_data(__str._M_local_buf);
786 this->
assign(__l.begin(), __l.size());
791 #if __cplusplus >= 201703L
796 template<
typename _Tp>
797 _If_sv<_Tp, basic_string&>
799 {
return this->
assign(__svt); }
806 {
return __sv_type(
data(),
size()); }
815 begin() _GLIBCXX_NOEXCEPT
816 {
return iterator(_M_data()); }
823 begin() const _GLIBCXX_NOEXCEPT
824 {
return const_iterator(_M_data()); }
831 end() _GLIBCXX_NOEXCEPT
832 {
return iterator(_M_data() + this->
size()); }
839 end() const _GLIBCXX_NOEXCEPT
840 {
return const_iterator(_M_data() + this->
size()); }
848 rbegin() _GLIBCXX_NOEXCEPT
849 {
return reverse_iterator(this->
end()); }
856 const_reverse_iterator
857 rbegin() const _GLIBCXX_NOEXCEPT
858 {
return const_reverse_iterator(this->
end()); }
866 rend() _GLIBCXX_NOEXCEPT
867 {
return reverse_iterator(this->
begin()); }
874 const_reverse_iterator
875 rend() const _GLIBCXX_NOEXCEPT
876 {
return const_reverse_iterator(this->
begin()); }
878 #if __cplusplus >= 201103L
885 {
return const_iterator(this->_M_data()); }
893 {
return const_iterator(this->_M_data() + this->
size()); }
900 const_reverse_iterator
902 {
return const_reverse_iterator(this->
end()); }
909 const_reverse_iterator
911 {
return const_reverse_iterator(this->
begin()); }
919 size() const _GLIBCXX_NOEXCEPT
920 {
return _M_string_length; }
925 length() const _GLIBCXX_NOEXCEPT
926 {
return _M_string_length; }
930 max_size() const _GLIBCXX_NOEXCEPT
931 {
return (_Alloc_traits::max_size(_M_get_allocator()) - 1) / 2; }
944 resize(size_type __n, _CharT __c);
958 { this->
resize(__n, _CharT()); }
960 #if __cplusplus >= 201103L
961 #pragma GCC diagnostic push
962 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
967 #pragma GCC diagnostic pop
977 return _M_is_local() ? size_type(_S_local_capacity)
978 : _M_allocated_capacity;
1004 #if __cplusplus > 201703L
1005 [[deprecated(
"use shrink_to_fit() instead")]]
1014 clear() _GLIBCXX_NOEXCEPT
1015 { _M_set_length(0); }
1021 _GLIBCXX_NODISCARD
bool
1022 empty() const _GLIBCXX_NOEXCEPT
1023 {
return this->
size() == 0; }
1037 operator[] (size_type __pos)
const _GLIBCXX_NOEXCEPT
1039 __glibcxx_assert(__pos <=
size());
1040 return _M_data()[__pos];
1058 __glibcxx_assert(__pos <=
size());
1060 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos <
size());
1061 return _M_data()[__pos];
1075 at(size_type __n)
const
1077 if (__n >= this->
size())
1078 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1079 "(which is %zu) >= this->size() "
1082 return _M_data()[__n];
1099 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
1100 "(which is %zu) >= this->size() "
1103 return _M_data()[__n];
1106 #if __cplusplus >= 201103L
1114 __glibcxx_assert(!
empty());
1125 __glibcxx_assert(!
empty());
1136 __glibcxx_assert(!
empty());
1147 __glibcxx_assert(!
empty());
1160 {
return this->
append(__str); }
1169 {
return this->
append(__s); }
1183 #if __cplusplus >= 201103L
1191 {
return this->
append(__l.begin(), __l.size()); }
1194 #if __cplusplus >= 201703L
1200 template<
typename _Tp>
1201 _If_sv<_Tp, basic_string&>
1203 {
return this->
append(__svt); }
1212 append(
const basic_string& __str)
1213 {
return _M_append(__str._M_data(), __str.size()); }
1229 append(
const basic_string& __str, size_type __pos, size_type __n =
npos)
1230 {
return _M_append(__str._M_data()
1231 + __str._M_check(__pos,
"basic_string::append"),
1232 __str._M_limit(__pos, __n)); }
1241 append(
const _CharT* __s, size_type __n)
1243 __glibcxx_requires_string_len(__s, __n);
1244 _M_check_length(size_type(0), __n,
"basic_string::append");
1245 return _M_append(__s, __n);
1254 append(
const _CharT* __s)
1256 __glibcxx_requires_string(__s);
1257 const size_type __n = traits_type::length(__s);
1258 _M_check_length(size_type(0), __n,
"basic_string::append");
1259 return _M_append(__s, __n);
1271 append(size_type __n, _CharT __c)
1272 {
return _M_replace_aux(this->
size(), size_type(0), __n, __c); }
1274 #if __cplusplus >= 201103L
1281 append(initializer_list<_CharT> __l)
1282 {
return this->
append(__l.begin(), __l.size()); }
1293 #if __cplusplus >= 201103L
1294 template<
class _InputIterator,
1295 typename = std::_RequireInputIter<_InputIterator>>
1297 template<
class _InputIterator>
1300 append(_InputIterator __first, _InputIterator __last)
1303 #if __cplusplus >= 201703L
1309 template<
typename _Tp>
1310 _If_sv<_Tp, basic_string&>
1313 __sv_type __sv = __svt;
1314 return this->
append(__sv.data(), __sv.size());
1324 template<
typename _Tp>
1325 _If_sv<_Tp, basic_string&>
1326 append(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
1328 __sv_type __sv = __svt;
1329 return _M_append(__sv.data()
1330 + std::__sv_check(__sv.size(), __pos,
"basic_string::append"),
1331 std::__sv_limit(__sv.size(), __pos, __n));
1342 const size_type __size = this->
size();
1344 this->_M_mutate(__size, size_type(0), 0, size_type(1));
1345 traits_type::assign(this->_M_data()[__size], __c);
1346 this->_M_set_length(__size + 1);
1355 assign(
const basic_string& __str)
1357 #if __cplusplus >= 201103L
1358 if (_Alloc_traits::_S_propagate_on_copy_assign())
1360 if (!_Alloc_traits::_S_always_equal() && !_M_is_local()
1361 && _M_get_allocator() != __str._M_get_allocator())
1365 if (__str.size() <= _S_local_capacity)
1367 _M_destroy(_M_allocated_capacity);
1368 _M_data(_M_local_data());
1373 const auto __len = __str.size();
1374 auto __alloc = __str._M_get_allocator();
1376 auto __ptr = _Alloc_traits::allocate(__alloc, __len + 1);
1377 _M_destroy(_M_allocated_capacity);
1380 _M_set_length(__len);
1383 std::__alloc_on_copy(_M_get_allocator(), __str._M_get_allocator());
1386 this->_M_assign(__str);
1390 #if __cplusplus >= 201103L
1400 assign(basic_string&& __str)
1401 noexcept(_Alloc_traits::_S_nothrow_move())
1423 assign(
const basic_string& __str, size_type __pos, size_type __n =
npos)
1424 {
return _M_replace(size_type(0), this->
size(), __str._M_data()
1425 + __str._M_check(__pos,
"basic_string::assign"),
1426 __str._M_limit(__pos, __n)); }
1439 assign(
const _CharT* __s, size_type __n)
1441 __glibcxx_requires_string_len(__s, __n);
1442 return _M_replace(size_type(0), this->
size(), __s, __n);
1455 assign(
const _CharT* __s)
1457 __glibcxx_requires_string(__s);
1458 return _M_replace(size_type(0), this->
size(), __s,
1459 traits_type::length(__s));
1472 assign(size_type __n, _CharT __c)
1473 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
1483 #if __cplusplus >= 201103L
1484 template<
class _InputIterator,
1485 typename = std::_RequireInputIter<_InputIterator>>
1487 template<
class _InputIterator>
1490 assign(_InputIterator __first, _InputIterator __last)
1493 #if __cplusplus >= 201103L
1500 assign(initializer_list<_CharT> __l)
1501 {
return this->
assign(__l.begin(), __l.size()); }
1504 #if __cplusplus >= 201703L
1510 template<
typename _Tp>
1511 _If_sv<_Tp, basic_string&>
1514 __sv_type __sv = __svt;
1515 return this->
assign(__sv.data(), __sv.size());
1525 template<
typename _Tp>
1526 _If_sv<_Tp, basic_string&>
1527 assign(
const _Tp& __svt, size_type __pos, size_type __n =
npos)
1529 __sv_type __sv = __svt;
1530 return _M_replace(size_type(0), this->
size(),
1532 + std::__sv_check(__sv.size(), __pos,
"basic_string::assign"),
1533 std::__sv_limit(__sv.size(), __pos, __n));
1537 #if __cplusplus >= 201103L
1554 insert(const_iterator __p, size_type __n, _CharT __c)
1556 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1557 const size_type __pos = __p -
begin();
1558 this->
replace(__p, __p, __n, __c);
1559 return iterator(this->_M_data() + __pos);
1576 insert(iterator __p, size_type __n, _CharT __c)
1577 { this->
replace(__p, __p, __n, __c); }
1580 #if __cplusplus >= 201103L
1595 template<
class _InputIterator,
1596 typename = std::_RequireInputIter<_InputIterator>>
1598 insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
1600 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1601 const size_type __pos = __p -
begin();
1602 this->
replace(__p, __p, __beg, __end);
1603 return iterator(this->_M_data() + __pos);
1618 template<
class _InputIterator>
1620 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1621 { this->
replace(__p, __p, __beg, __end); }
1624 #if __cplusplus >= 201103L
1632 insert(const_iterator __p, initializer_list<_CharT> __l)
1633 {
return this->
insert(__p, __l.begin(), __l.end()); }
1635 #ifdef _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
1638 insert(iterator __p, initializer_list<_CharT> __l)
1640 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1641 this->
insert(__p -
begin(), __l.begin(), __l.size());
1659 insert(size_type __pos1,
const basic_string& __str)
1660 {
return this->
replace(__pos1, size_type(0),
1661 __str._M_data(), __str.size()); }
1682 insert(size_type __pos1,
const basic_string& __str,
1683 size_type __pos2, size_type __n =
npos)
1684 {
return this->
replace(__pos1, size_type(0), __str._M_data()
1685 + __str._M_check(__pos2,
"basic_string::insert"),
1686 __str._M_limit(__pos2, __n)); }
1705 insert(size_type __pos,
const _CharT* __s, size_type __n)
1706 {
return this->
replace(__pos, size_type(0), __s, __n); }
1724 insert(size_type __pos,
const _CharT* __s)
1726 __glibcxx_requires_string(__s);
1727 return this->
replace(__pos, size_type(0), __s,
1728 traits_type::length(__s));
1748 insert(size_type __pos, size_type __n, _CharT __c)
1749 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
1750 size_type(0), __n, __c); }
1766 insert(__const_iterator __p, _CharT __c)
1768 _GLIBCXX_DEBUG_PEDASSERT(__p >=
begin() && __p <=
end());
1769 const size_type __pos = __p -
begin();
1770 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1771 return iterator(_M_data() + __pos);
1774 #if __cplusplus >= 201703L
1781 template<
typename _Tp>
1782 _If_sv<_Tp, basic_string&>
1783 insert(size_type __pos,
const _Tp& __svt)
1785 __sv_type __sv = __svt;
1786 return this->
insert(__pos, __sv.data(), __sv.size());
1797 template<
typename _Tp>
1798 _If_sv<_Tp, basic_string&>
1799 insert(size_type __pos1,
const _Tp& __svt,
1800 size_type __pos2, size_type __n =
npos)
1802 __sv_type __sv = __svt;
1803 return this->
replace(__pos1, size_type(0),
1805 + std::__sv_check(__sv.size(), __pos2,
"basic_string::insert"),
1806 std::__sv_limit(__sv.size(), __pos2, __n));
1826 erase(size_type __pos = 0, size_type __n =
npos)
1828 _M_check(__pos,
"basic_string::erase");
1830 this->_M_set_length(__pos);
1832 this->_M_erase(__pos, _M_limit(__pos, __n));
1845 erase(__const_iterator __position)
1847 _GLIBCXX_DEBUG_PEDASSERT(__position >=
begin()
1848 && __position <
end());
1849 const size_type __pos = __position -
begin();
1850 this->_M_erase(__pos, size_type(1));
1851 return iterator(_M_data() + __pos);
1864 erase(__const_iterator __first, __const_iterator __last)
1866 _GLIBCXX_DEBUG_PEDASSERT(__first >=
begin() && __first <= __last
1867 && __last <=
end());
1868 const size_type __pos = __first -
begin();
1869 if (__last ==
end())
1870 this->_M_set_length(__pos);
1872 this->_M_erase(__pos, __last - __first);
1873 return iterator(this->_M_data() + __pos);
1876 #if __cplusplus >= 201103L
1885 __glibcxx_assert(!
empty());
1886 _M_erase(
size() - 1, 1);
1908 replace(size_type __pos, size_type __n,
const basic_string& __str)
1909 {
return this->
replace(__pos, __n, __str._M_data(), __str.size()); }
1930 replace(size_type __pos1, size_type __n1,
const basic_string& __str,
1931 size_type __pos2, size_type __n2 =
npos)
1932 {
return this->
replace(__pos1, __n1, __str._M_data()
1933 + __str._M_check(__pos2,
"basic_string::replace"),
1934 __str._M_limit(__pos2, __n2)); }
1955 replace(size_type __pos, size_type __n1,
const _CharT* __s,
1958 __glibcxx_requires_string_len(__s, __n2);
1959 return _M_replace(_M_check(__pos,
"basic_string::replace"),
1960 _M_limit(__pos, __n1), __s, __n2);
1980 replace(size_type __pos, size_type __n1,
const _CharT* __s)
1982 __glibcxx_requires_string(__s);
1983 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
2004 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
2005 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
2006 _M_limit(__pos, __n1), __n2, __c); }
2022 replace(__const_iterator __i1, __const_iterator __i2,
2023 const basic_string& __str)
2024 {
return this->
replace(__i1, __i2, __str._M_data(), __str.size()); }
2042 replace(__const_iterator __i1, __const_iterator __i2,
2043 const _CharT* __s, size_type __n)
2045 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2047 return this->
replace(__i1 -
begin(), __i2 - __i1, __s, __n);
2064 replace(__const_iterator __i1, __const_iterator __i2,
const _CharT* __s)
2066 __glibcxx_requires_string(__s);
2067 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
2085 replace(__const_iterator __i1, __const_iterator __i2, size_type __n,
2088 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2090 return _M_replace_aux(__i1 -
begin(), __i2 - __i1, __n, __c);
2108 #if __cplusplus >= 201103L
2109 template<
class _InputIterator,
2110 typename = std::_RequireInputIter<_InputIterator>>
2112 replace(const_iterator __i1, const_iterator __i2,
2113 _InputIterator __k1, _InputIterator __k2)
2115 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2117 __glibcxx_requires_valid_range(__k1, __k2);
2118 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
2119 std::__false_type());
2122 template<
class _InputIterator>
2123 #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
2124 typename __enable_if_not_native_iterator<_InputIterator>::__type
2128 replace(iterator __i1, iterator __i2,
2129 _InputIterator __k1, _InputIterator __k2)
2131 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2133 __glibcxx_requires_valid_range(__k1, __k2);
2134 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
2135 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
2142 replace(__const_iterator __i1, __const_iterator __i2,
2143 _CharT* __k1, _CharT* __k2)
2145 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2147 __glibcxx_requires_valid_range(__k1, __k2);
2153 replace(__const_iterator __i1, __const_iterator __i2,
2154 const _CharT* __k1,
const _CharT* __k2)
2156 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2158 __glibcxx_requires_valid_range(__k1, __k2);
2164 replace(__const_iterator __i1, __const_iterator __i2,
2165 iterator __k1, iterator __k2)
2167 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2169 __glibcxx_requires_valid_range(__k1, __k2);
2171 __k1.base(), __k2 - __k1);
2175 replace(__const_iterator __i1, __const_iterator __i2,
2176 const_iterator __k1, const_iterator __k2)
2178 _GLIBCXX_DEBUG_PEDASSERT(
begin() <= __i1 && __i1 <= __i2
2180 __glibcxx_requires_valid_range(__k1, __k2);
2182 __k1.base(), __k2 - __k1);
2185 #if __cplusplus >= 201103L
2200 basic_string&
replace(const_iterator __i1, const_iterator __i2,
2201 initializer_list<_CharT> __l)
2202 {
return this->
replace(__i1, __i2, __l.begin(), __l.size()); }
2205 #if __cplusplus >= 201703L
2213 template<
typename _Tp>
2214 _If_sv<_Tp, basic_string&>
2215 replace(size_type __pos, size_type __n,
const _Tp& __svt)
2217 __sv_type __sv = __svt;
2218 return this->
replace(__pos, __n, __sv.data(), __sv.size());
2230 template<
typename _Tp>
2231 _If_sv<_Tp, basic_string&>
2232 replace(size_type __pos1, size_type __n1,
const _Tp& __svt,
2233 size_type __pos2, size_type __n2 =
npos)
2235 __sv_type __sv = __svt;
2236 return this->
replace(__pos1, __n1,
2238 + std::__sv_check(__sv.size(), __pos2,
"basic_string::replace"),
2239 std::__sv_limit(__sv.size(), __pos2, __n2));
2251 template<
typename _Tp>
2252 _If_sv<_Tp, basic_string&>
2253 replace(const_iterator __i1, const_iterator __i2,
const _Tp& __svt)
2255 __sv_type __sv = __svt;
2256 return this->
replace(__i1 -
begin(), __i2 - __i1, __sv);
2261 template<
class _Integer>
2263 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2264 _Integer __n, _Integer __val, __true_type)
2265 {
return _M_replace_aux(__i1 -
begin(), __i2 - __i1, __n, __val); }
2267 template<
class _InputIterator>
2269 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2270 _InputIterator __k1, _InputIterator __k2,
2274 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
2278 _M_replace(size_type __pos, size_type __len1,
const _CharT* __s,
2279 const size_type __len2);
2282 _M_append(
const _CharT* __s, size_type __n);
2299 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
2309 swap(basic_string& __s) _GLIBCXX_NOEXCEPT;
2319 c_str() const _GLIBCXX_NOEXCEPT
2320 {
return _M_data(); }
2331 data() const _GLIBCXX_NOEXCEPT
2332 {
return _M_data(); }
2334 #if __cplusplus >= 201703L
2343 {
return _M_data(); }
2351 {
return _M_get_allocator(); }
2366 find(
const _CharT* __s, size_type __pos, size_type __n)
const
2380 find(
const basic_string& __str, size_type __pos = 0) const
2382 {
return this->
find(__str.data(), __pos, __str.size()); }
2384 #if __cplusplus >= 201703L
2391 template<
typename _Tp>
2392 _If_sv<_Tp, size_type>
2393 find(
const _Tp& __svt, size_type __pos = 0) const
2394 noexcept(is_same<_Tp, __sv_type>::value)
2396 __sv_type __sv = __svt;
2397 return this->
find(__sv.data(), __pos, __sv.size());
2412 find(
const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2414 __glibcxx_requires_string(__s);
2415 return this->
find(__s, __pos, traits_type::length(__s));
2429 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
2442 rfind(const basic_string& __str, size_type __pos =
npos) const
2444 {
return this->
rfind(__str.data(), __pos, __str.size()); }
2446 #if __cplusplus >= 201703L
2453 template<
typename _Tp>
2454 _If_sv<_Tp, size_type>
2455 rfind(
const _Tp& __svt, size_type __pos =
npos) const
2456 noexcept(is_same<_Tp, __sv_type>::value)
2458 __sv_type __sv = __svt;
2459 return this->
rfind(__sv.data(), __pos, __sv.size());
2476 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
2490 rfind(
const _CharT* __s, size_type __pos =
npos)
const
2492 __glibcxx_requires_string(__s);
2493 return this->
rfind(__s, __pos, traits_type::length(__s));
2507 rfind(_CharT __c, size_type __pos =
npos) const _GLIBCXX_NOEXCEPT;
2521 find_first_of(const basic_string& __str, size_type __pos = 0) const
2523 {
return this->
find_first_of(__str.data(), __pos, __str.size()); }
2525 #if __cplusplus >= 201703L
2533 template<
typename _Tp>
2534 _If_sv<_Tp, size_type>
2536 noexcept(is_same<_Tp, __sv_type>::value)
2538 __sv_type __sv = __svt;
2539 return this->
find_first_of(__sv.data(), __pos, __sv.size());
2556 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2573 __glibcxx_requires_string(__s);
2574 return this->
find_first_of(__s, __pos, traits_type::length(__s));
2590 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
2591 {
return this->
find(__c, __pos); }
2607 {
return this->
find_last_of(__str.data(), __pos, __str.size()); }
2609 #if __cplusplus >= 201703L
2617 template<
typename _Tp>
2618 _If_sv<_Tp, size_type>
2620 noexcept(is_same<_Tp, __sv_type>::value)
2622 __sv_type __sv = __svt;
2623 return this->
find_last_of(__sv.data(), __pos, __sv.size());
2640 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
2657 __glibcxx_requires_string(__s);
2658 return this->
find_last_of(__s, __pos, traits_type::length(__s));
2675 {
return this->
rfind(__c, __pos); }
2692 #if __cplusplus >= 201703L
2700 template<
typename _Tp>
2701 _If_sv<_Tp, size_type>
2703 noexcept(is_same<_Tp, __sv_type>::value)
2705 __sv_type __sv = __svt;
2724 size_type __n)
const _GLIBCXX_NOEXCEPT;
2740 __glibcxx_requires_string(__s);
2774 #if __cplusplus >= 201703L
2782 template<
typename _Tp>
2783 _If_sv<_Tp, size_type>
2785 noexcept(is_same<_Tp, __sv_type>::value)
2787 __sv_type __sv = __svt;
2806 size_type __n)
const _GLIBCXX_NOEXCEPT;
2822 __glibcxx_requires_string(__s);
2853 substr(size_type __pos = 0, size_type __n =
npos)
const
2854 {
return basic_string(*
this,
2855 _M_check(__pos,
"basic_string::substr"), __n); }
2872 compare(
const basic_string& __str)
const
2874 const size_type __size = this->
size();
2875 const size_type __osize = __str.size();
2876 const size_type __len =
std::min(__size, __osize);
2878 int __r = traits_type::compare(_M_data(), __str.data(), __len);
2880 __r = _S_compare(__size, __osize);
2884 #if __cplusplus >= 201703L
2890 template<
typename _Tp>
2892 compare(
const _Tp& __svt)
const
2893 noexcept(is_same<_Tp, __sv_type>::value)
2895 __sv_type __sv = __svt;
2896 const size_type __size = this->
size();
2897 const size_type __osize = __sv.size();
2898 const size_type __len =
std::min(__size, __osize);
2900 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
2902 __r = _S_compare(__size, __osize);
2914 template<
typename _Tp>
2916 compare(size_type __pos, size_type __n,
const _Tp& __svt)
const
2917 noexcept(is_same<_Tp, __sv_type>::value)
2919 __sv_type __sv = __svt;
2920 return __sv_type(*this).substr(__pos, __n).compare(__sv);
2933 template<
typename _Tp>
2935 compare(size_type __pos1, size_type __n1,
const _Tp& __svt,
2936 size_type __pos2, size_type __n2 = npos) const
2937 noexcept(is_same<_Tp, __sv_type>::value)
2939 __sv_type __sv = __svt;
2940 return __sv_type(*
this)
2941 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
2965 compare(size_type __pos, size_type __n,
const basic_string& __str)
const;
2991 compare(size_type __pos1, size_type __n1,
const basic_string& __str,
2992 size_type __pos2, size_type __n2 = npos)
const;
3009 compare(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT;
3033 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const;
3060 compare(size_type __pos, size_type __n1,
const _CharT* __s,
3061 size_type __n2)
const;
3063 #if __cplusplus > 201703L
3065 starts_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
3066 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3069 starts_with(_CharT __x)
const noexcept
3070 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3073 starts_with(
const _CharT* __x)
const noexcept
3074 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
3077 ends_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
3078 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3081 ends_with(_CharT __x)
const noexcept
3082 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3085 ends_with(
const _CharT* __x)
const noexcept
3086 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
3089 #if __cplusplus > 202002L
3091 contains(basic_string_view<_CharT, _Traits> __x)
const noexcept
3092 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3095 contains(_CharT __x)
const noexcept
3096 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3099 contains(
const _CharT* __x)
const noexcept
3100 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
3104 template<
typename,
typename,
typename>
friend class basic_stringbuf;
3106 _GLIBCXX_END_NAMESPACE_CXX11
3107 #else // !_GLIBCXX_USE_CXX11_ABI
3172 template<
typename _CharT,
typename _Traits,
typename _Alloc>
3176 rebind<_CharT>::other _CharT_alloc_type;
3181 typedef _Traits traits_type;
3182 typedef typename _Traits::char_type value_type;
3183 typedef _Alloc allocator_type;
3184 typedef typename _CharT_alloc_traits::size_type size_type;
3185 typedef typename _CharT_alloc_traits::difference_type difference_type;
3186 #if __cplusplus < 201103L
3187 typedef typename _CharT_alloc_type::reference reference;
3188 typedef typename _CharT_alloc_type::const_reference const_reference;
3190 typedef value_type& reference;
3191 typedef const value_type& const_reference;
3193 typedef typename _CharT_alloc_traits::pointer pointer;
3194 typedef typename _CharT_alloc_traits::const_pointer const_pointer;
3195 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
3196 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
3203 typedef iterator __const_iterator;
3222 size_type _M_length;
3223 size_type _M_capacity;
3224 _Atomic_word _M_refcount;
3227 struct _Rep : _Rep_base
3231 rebind<char>::other _Raw_bytes_alloc;
3246 static const size_type _S_max_size;
3247 static const _CharT _S_terminal;
3251 static size_type _S_empty_rep_storage[];
3254 _S_empty_rep() _GLIBCXX_NOEXCEPT
3259 void* __p =
reinterpret_cast<void*
>(&_S_empty_rep_storage);
3260 return *
reinterpret_cast<_Rep*
>(__p);
3264 _M_is_leaked()
const _GLIBCXX_NOEXCEPT
3266 #if defined(__GTHREADS)
3271 return __atomic_load_n(&this->_M_refcount, __ATOMIC_RELAXED) < 0;
3273 return this->_M_refcount < 0;
3278 _M_is_shared()
const _GLIBCXX_NOEXCEPT
3280 #if defined(__GTHREADS)
3286 return __atomic_load_n(&this->_M_refcount, __ATOMIC_ACQUIRE) > 0;
3288 return this->_M_refcount > 0;
3293 _M_set_leaked() _GLIBCXX_NOEXCEPT
3294 { this->_M_refcount = -1; }
3297 _M_set_sharable() _GLIBCXX_NOEXCEPT
3298 { this->_M_refcount = 0; }
3301 _M_set_length_and_sharable(size_type __n) _GLIBCXX_NOEXCEPT
3303 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3304 if (__builtin_expect(
this != &_S_empty_rep(),
false))
3307 this->_M_set_sharable();
3308 this->_M_length = __n;
3309 traits_type::assign(this->_M_refdata()[__n], _S_terminal);
3316 _M_refdata()
throw()
3317 {
return reinterpret_cast<_CharT*
>(
this + 1); }
3320 _M_grab(
const _Alloc& __alloc1,
const _Alloc& __alloc2)
3322 return (!_M_is_leaked() && __alloc1 == __alloc2)
3323 ? _M_refcopy() : _M_clone(__alloc1);
3328 _S_create(size_type, size_type,
const _Alloc&);
3331 _M_dispose(
const _Alloc& __a) _GLIBCXX_NOEXCEPT
3333 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3334 if (__builtin_expect(
this != &_S_empty_rep(),
false))
3338 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount);
3347 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
3350 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount);
3357 _M_destroy(
const _Alloc&)
throw();
3360 _M_refcopy()
throw()
3362 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3363 if (__builtin_expect(
this != &_S_empty_rep(),
false))
3365 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
3366 return _M_refdata();
3370 _M_clone(
const _Alloc&, size_type __res = 0);
3374 struct _Alloc_hider : _Alloc
3376 _Alloc_hider(_CharT* __dat,
const _Alloc& __a) _GLIBCXX_NOEXCEPT
3377 : _Alloc(__a), _M_p(__dat) { }
3387 static const size_type npos =
static_cast<size_type
>(-1);
3391 mutable _Alloc_hider _M_dataplus;
3394 _M_data() const _GLIBCXX_NOEXCEPT
3395 {
return _M_dataplus._M_p; }
3398 _M_data(_CharT* __p) _GLIBCXX_NOEXCEPT
3399 {
return (_M_dataplus._M_p = __p); }
3402 _M_rep() const _GLIBCXX_NOEXCEPT
3403 {
return &((
reinterpret_cast<_Rep*
> (_M_data()))[-1]); }
3408 _M_ibegin() const _GLIBCXX_NOEXCEPT
3409 {
return iterator(_M_data()); }
3412 _M_iend() const _GLIBCXX_NOEXCEPT
3413 {
return iterator(_M_data() + this->
size()); }
3418 if (!_M_rep()->_M_is_leaked())
3423 _M_check(size_type __pos,
const char* __s)
const
3425 if (__pos > this->
size())
3426 __throw_out_of_range_fmt(__N(
"%s: __pos (which is %zu) > "
3427 "this->size() (which is %zu)"),
3428 __s, __pos, this->
size());
3433 _M_check_length(size_type __n1, size_type __n2,
const char* __s)
const
3435 if (this->max_size() - (this->
size() - __n1) < __n2)
3436 __throw_length_error(__N(__s));
3441 _M_limit(size_type __pos, size_type __off)
const _GLIBCXX_NOEXCEPT
3443 const bool __testoff = __off < this->
size() - __pos;
3444 return __testoff ? __off : this->
size() - __pos;
3449 _M_disjunct(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT
3451 return (less<const _CharT*>()(__s, _M_data())
3452 || less<const _CharT*>()(_M_data() + this->
size(), __s));
3458 _M_copy(_CharT* __d,
const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
3461 traits_type::assign(*__d, *__s);
3463 traits_type::copy(__d, __s, __n);
3467 _M_move(_CharT* __d,
const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT
3470 traits_type::assign(*__d, *__s);
3476 _M_assign(_CharT* __d, size_type __n, _CharT __c) _GLIBCXX_NOEXCEPT
3479 traits_type::assign(*__d, __c);
3481 traits_type::assign(__d, __n, __c);
3486 template<
class _Iterator>
3488 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
3490 for (; __k1 != __k2; ++__k1, (void)++__p)
3491 traits_type::assign(*__p, *__k1);
3495 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
3496 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
3499 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
3501 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
3504 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
3505 { _M_copy(__p, __k1, __k2 - __k1); }
3508 _S_copy_chars(_CharT* __p,
const _CharT* __k1,
const _CharT* __k2)
3510 { _M_copy(__p, __k1, __k2 - __k1); }
3513 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
3515 const difference_type __d = difference_type(__n1 - __n2);
3517 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
3518 return __gnu_cxx::__numeric_traits<int>::__max;
3519 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
3520 return __gnu_cxx::__numeric_traits<int>::__min;
3526 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
3532 _S_empty_rep() _GLIBCXX_NOEXCEPT
3533 {
return _Rep::_S_empty_rep(); }
3535 #if __cplusplus >= 201703L
3537 typedef basic_string_view<_CharT, _Traits> __sv_type;
3539 template<
typename _Tp,
typename _Res>
3541 __and_<is_convertible<const _Tp&, __sv_type>,
3542 __not_<is_convertible<const _Tp*, const basic_string*>>,
3543 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
3548 _S_to_string_view(__sv_type __svt)
noexcept
3557 explicit __sv_wrapper(__sv_type __sv)
noexcept : _M_sv(__sv) { }
3568 basic_string(__sv_wrapper __svw,
const _Alloc& __a)
3569 : basic_string(__svw._M_sv.
data(), __svw._M_sv.
size(), __a) { }
3581 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3583 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc())
3585 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc())
3594 : _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a)
3603 : _M_dataplus(__str._M_rep()->_M_grab(_Alloc(__str.
get_allocator()),
3617 const _Alloc& __a = _Alloc());
3635 size_type __n,
const _Alloc& __a);
3647 const _Alloc& __a = _Alloc())
3648 : _M_dataplus(_S_construct(__s, __s + __n, __a), __a)
3656 #if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
3659 template<
typename = _RequireAllocator<_Alloc>>
3661 basic_string(
const _CharT* __s,
const _Alloc& __a = _Alloc())
3662 : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::length(__s) :
3663 __s + npos, __a), __a)
3672 basic_string(size_type __n, _CharT __c,
const _Alloc& __a = _Alloc())
3673 : _M_dataplus(_S_construct(__n, __c, __a), __a)
3676 #if __cplusplus >= 201103L
3685 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3688 : _M_dataplus(
std::move(__str._M_dataplus))
3690 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3691 __str._M_data(_S_empty_rep()._M_refdata());
3693 __str._M_data(_S_construct(size_type(), _CharT(),
get_allocator()));
3702 basic_string(initializer_list<_CharT> __l,
const _Alloc& __a = _Alloc())
3703 : _M_dataplus(_S_construct(__l.
begin(), __l.
end(), __a), __a)
3706 basic_string(
const basic_string& __str,
const _Alloc& __a)
3707 : _M_dataplus(__str._M_rep()->_M_grab(__a, __str.
get_allocator()), __a)
3710 basic_string(basic_string&& __str,
const _Alloc& __a)
3711 : _M_dataplus(__str._M_data(), __a)
3713 if (__a == __str.get_allocator())
3715 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3716 __str._M_data(_S_empty_rep()._M_refdata());
3718 __str._M_data(_S_construct(size_type(), _CharT(), __a));
3722 _M_dataplus._M_p = _S_construct(__str.begin(), __str.end(), __a);
3732 template<
class _InputIterator>
3733 basic_string(_InputIterator __beg, _InputIterator __end,
3734 const _Alloc& __a = _Alloc())
3735 : _M_dataplus(_S_construct(__beg, __end, __a), __a)
3738 #if __cplusplus >= 201703L
3746 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
3747 basic_string(
const _Tp& __t, size_type __pos, size_type __n,
3748 const _Alloc& __a = _Alloc())
3749 : basic_string(_S_to_string_view(__t).
substr(__pos, __n), __a) { }
3756 template<
typename _Tp,
typename = _If_sv<_Tp,
void>>
3758 basic_string(
const _Tp& __t,
const _Alloc& __a = _Alloc())
3759 : basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
3765 ~basic_string() _GLIBCXX_NOEXCEPT
3774 {
return this->
assign(__str); }
3782 {
return this->
assign(__s); }
3798 #if __cplusplus >= 201103L
3808 _GLIBCXX_NOEXCEPT_IF(allocator_traits<_Alloc>::is_always_equal::value)
3822 this->
assign(__l.begin(), __l.size());
3827 #if __cplusplus >= 201703L
3832 template<
typename _Tp>
3833 _If_sv<_Tp, basic_string&>
3835 {
return this->
assign(__svt); }
3841 operator __sv_type() const
noexcept
3842 {
return __sv_type(
data(),
size()); }
3854 return iterator(_M_data());
3862 begin() const _GLIBCXX_NOEXCEPT
3863 {
return const_iterator(_M_data()); }
3873 return iterator(_M_data() + this->
size());
3881 end() const _GLIBCXX_NOEXCEPT
3882 {
return const_iterator(_M_data() + this->
size()); }
3891 {
return reverse_iterator(this->
end()); }
3898 const_reverse_iterator
3899 rbegin() const _GLIBCXX_NOEXCEPT
3900 {
return const_reverse_iterator(this->
end()); }
3909 {
return reverse_iterator(this->
begin()); }
3916 const_reverse_iterator
3917 rend() const _GLIBCXX_NOEXCEPT
3918 {
return const_reverse_iterator(this->
begin()); }
3920 #if __cplusplus >= 201103L
3927 {
return const_iterator(this->_M_data()); }
3935 {
return const_iterator(this->_M_data() + this->
size()); }
3942 const_reverse_iterator
3944 {
return const_reverse_iterator(this->
end()); }
3951 const_reverse_iterator
3953 {
return const_reverse_iterator(this->
begin()); }
3961 size() const _GLIBCXX_NOEXCEPT
3962 {
return _M_rep()->_M_length; }
3967 length() const _GLIBCXX_NOEXCEPT
3968 {
return _M_rep()->_M_length; }
3972 max_size() const _GLIBCXX_NOEXCEPT
3973 {
return _Rep::_S_max_size; }
3986 resize(size_type __n, _CharT __c);
4000 { this->
resize(__n, _CharT()); }
4002 #if __cplusplus >= 201103L
4003 #pragma GCC diagnostic push
4004 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
4009 #pragma GCC diagnostic pop
4018 {
return _M_rep()->_M_capacity; }
4041 #if __cplusplus > 201703L
4042 [[deprecated(
"use shrink_to_fit() instead")]]
4050 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
4054 if (_M_rep()->_M_is_shared())
4057 _M_data(_S_empty_rep()._M_refdata());
4060 _M_rep()->_M_set_length_and_sharable(0);
4066 { _M_mutate(0, this->
size(), 0); }
4073 _GLIBCXX_NODISCARD
bool
4075 {
return this->
size() == 0; }
4091 __glibcxx_assert(__pos <=
size());
4092 return _M_data()[__pos];
4110 __glibcxx_assert(__pos <=
size());
4112 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos <
size());
4114 return _M_data()[__pos];
4130 if (__n >= this->
size())
4131 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
4132 "(which is %zu) >= this->size() "
4135 return _M_data()[__n];
4153 __throw_out_of_range_fmt(__N(
"basic_string::at: __n "
4154 "(which is %zu) >= this->size() "
4158 return _M_data()[__n];
4161 #if __cplusplus >= 201103L
4169 __glibcxx_assert(!
empty());
4180 __glibcxx_assert(!
empty());
4191 __glibcxx_assert(!
empty());
4202 __glibcxx_assert(!
empty());
4215 {
return this->
append(__str); }
4224 {
return this->
append(__s); }
4238 #if __cplusplus >= 201103L
4246 {
return this->
append(__l.begin(), __l.size()); }
4249 #if __cplusplus >= 201703L
4255 template<
typename _Tp>
4256 _If_sv<_Tp, basic_string&>
4258 {
return this->
append(__svt); }
4292 append(
const _CharT* __s, size_type __n);
4302 __glibcxx_requires_string(__s);
4303 return this->
append(__s, traits_type::length(__s));
4315 append(size_type __n, _CharT __c);
4317 #if __cplusplus >= 201103L
4325 {
return this->
append(__l.begin(), __l.size()); }
4336 template<
class _InputIterator>
4338 append(_InputIterator __first, _InputIterator __last)
4339 {
return this->
replace(_M_iend(), _M_iend(), __first, __last); }
4341 #if __cplusplus >= 201703L
4347 template<
typename _Tp>
4348 _If_sv<_Tp, basic_string&>
4352 return this->
append(__sv.data(), __sv.size());
4363 template<
typename _Tp>
4364 _If_sv<_Tp, basic_string&>
4365 append(
const _Tp& __svt, size_type __pos, size_type __n = npos)
4368 return append(__sv.data()
4369 + std::__sv_check(__sv.size(), __pos,
"basic_string::append"),
4370 std::__sv_limit(__sv.size(), __pos, __n));
4381 const size_type __len = 1 + this->
size();
4382 if (__len > this->
capacity() || _M_rep()->_M_is_shared())
4384 traits_type::assign(_M_data()[this->
size()], __c);
4385 _M_rep()->_M_set_length_and_sharable(__len);
4396 #if __cplusplus >= 201103L
4429 {
return this->
assign(__str._M_data()
4430 + __str._M_check(__pos,
"basic_string::assign"),
4431 __str._M_limit(__pos, __n)); }
4444 assign(
const _CharT* __s, size_type __n);
4458 __glibcxx_requires_string(__s);
4459 return this->
assign(__s, traits_type::length(__s));
4473 {
return _M_replace_aux(size_type(0), this->
size(), __n, __c); }
4483 template<
class _InputIterator>
4485 assign(_InputIterator __first, _InputIterator __last)
4486 {
return this->
replace(_M_ibegin(), _M_iend(), __first, __last); }
4488 #if __cplusplus >= 201103L
4496 {
return this->
assign(__l.begin(), __l.size()); }
4499 #if __cplusplus >= 201703L
4505 template<
typename _Tp>
4506 _If_sv<_Tp, basic_string&>
4510 return this->
assign(__sv.data(), __sv.size());
4520 template<
typename _Tp>
4521 _If_sv<_Tp, basic_string&>
4522 assign(
const _Tp& __svt, size_type __pos, size_type __n = npos)
4525 return assign(__sv.data()
4526 + std::__sv_check(__sv.size(), __pos,
"basic_string::assign"),
4527 std::__sv_limit(__sv.size(), __pos, __n));
4545 insert(iterator __p, size_type __n, _CharT __c)
4546 { this->
replace(__p, __p, __n, __c); }
4560 template<
class _InputIterator>
4562 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
4563 { this->
replace(__p, __p, __beg, __end); }
4565 #if __cplusplus >= 201103L
4575 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
4576 this->
insert(__p - _M_ibegin(), __l.begin(), __l.size());
4594 {
return this->
insert(__pos1, __str, size_type(0), __str.size()); }
4616 size_type __pos2, size_type __n = npos)
4617 {
return this->
insert(__pos1, __str._M_data()
4618 + __str._M_check(__pos2,
"basic_string::insert"),
4619 __str._M_limit(__pos2, __n)); }
4638 insert(size_type __pos,
const _CharT* __s, size_type __n);
4658 __glibcxx_requires_string(__s);
4659 return this->
insert(__pos, __s, traits_type::length(__s));
4679 insert(size_type __pos, size_type __n, _CharT __c)
4680 {
return _M_replace_aux(_M_check(__pos,
"basic_string::insert"),
4681 size_type(0), __n, __c); }
4699 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
4700 const size_type __pos = __p - _M_ibegin();
4701 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
4702 _M_rep()->_M_set_leaked();
4703 return iterator(_M_data() + __pos);
4706 #if __cplusplus >= 201703L
4713 template<
typename _Tp>
4714 _If_sv<_Tp, basic_string&>
4718 return this->
insert(__pos, __sv.data(), __sv.size());
4729 template<
typename _Tp>
4730 _If_sv<_Tp, basic_string&>
4732 size_type __pos2, size_type __n = npos)
4735 return this->
replace(__pos1, size_type(0), __sv.data()
4736 + std::__sv_check(__sv.size(), __pos2,
"basic_string::insert"),
4737 std::__sv_limit(__sv.size(), __pos2, __n));
4757 erase(size_type __pos = 0, size_type __n = npos)
4759 _M_mutate(_M_check(__pos,
"basic_string::erase"),
4760 _M_limit(__pos, __n), size_type(0));
4775 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
4776 && __position < _M_iend());
4777 const size_type __pos = __position - _M_ibegin();
4778 _M_mutate(__pos, size_type(1), size_type(0));
4779 _M_rep()->_M_set_leaked();
4780 return iterator(_M_data() + __pos);
4795 #if __cplusplus >= 201103L
4804 __glibcxx_assert(!
empty());
4828 {
return this->
replace(__pos, __n, __str._M_data(), __str.size()); }
4850 size_type __pos2, size_type __n2 = npos)
4851 {
return this->
replace(__pos1, __n1, __str._M_data()
4852 + __str._M_check(__pos2,
"basic_string::replace"),
4853 __str._M_limit(__pos2, __n2)); }
4874 replace(size_type __pos, size_type __n1,
const _CharT* __s,
4894 replace(size_type __pos, size_type __n1,
const _CharT* __s)
4896 __glibcxx_requires_string(__s);
4897 return this->
replace(__pos, __n1, __s, traits_type::length(__s));
4918 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
4919 {
return _M_replace_aux(_M_check(__pos,
"basic_string::replace"),
4920 _M_limit(__pos, __n1), __n2, __c); }
4937 {
return this->
replace(__i1, __i2, __str._M_data(), __str.size()); }
4955 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
4957 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4958 && __i2 <= _M_iend());
4959 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
4976 replace(iterator __i1, iterator __i2,
const _CharT* __s)
4978 __glibcxx_requires_string(__s);
4979 return this->
replace(__i1, __i2, __s, traits_type::length(__s));
4997 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
4999 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
5000 && __i2 <= _M_iend());
5001 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
5019 template<
class _InputIterator>
5022 _InputIterator __k1, _InputIterator __k2)
5024 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
5025 && __i2 <= _M_iend());
5026 __glibcxx_requires_valid_range(__k1, __k2);
5027 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
5028 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
5036 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
5037 && __i2 <= _M_iend());
5038 __glibcxx_requires_valid_range(__k1, __k2);
5039 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
5044 replace(iterator __i1, iterator __i2,
5045 const _CharT* __k1,
const _CharT* __k2)
5047 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
5048 && __i2 <= _M_iend());
5049 __glibcxx_requires_valid_range(__k1, __k2);
5050 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
5055 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
5057 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
5058 && __i2 <= _M_iend());
5059 __glibcxx_requires_valid_range(__k1, __k2);
5060 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
5061 __k1.base(), __k2 - __k1);
5065 replace(iterator __i1, iterator __i2,
5066 const_iterator __k1, const_iterator __k2)
5068 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
5069 && __i2 <= _M_iend());
5070 __glibcxx_requires_valid_range(__k1, __k2);
5071 return this->
replace(__i1 - _M_ibegin(), __i2 - __i1,
5072 __k1.base(), __k2 - __k1);
5075 #if __cplusplus >= 201103L
5092 {
return this->
replace(__i1, __i2, __l.begin(), __l.end()); }
5095 #if __cplusplus >= 201703L
5103 template<
typename _Tp>
5104 _If_sv<_Tp, basic_string&>
5105 replace(size_type __pos, size_type __n,
const _Tp& __svt)
5108 return this->
replace(__pos, __n, __sv.data(), __sv.size());
5120 template<
typename _Tp>
5121 _If_sv<_Tp, basic_string&>
5122 replace(size_type __pos1, size_type __n1,
const _Tp& __svt,
5123 size_type __pos2, size_type __n2 = npos)
5126 return this->
replace(__pos1, __n1,
5128 + std::__sv_check(__sv.size(), __pos2,
"basic_string::replace"),
5129 std::__sv_limit(__sv.size(), __pos2, __n2));
5141 template<
typename _Tp>
5142 _If_sv<_Tp, basic_string&>
5143 replace(const_iterator __i1, const_iterator __i2,
const _Tp& __svt)
5146 return this->
replace(__i1 -
begin(), __i2 - __i1, __sv);
5151 template<
class _Integer>
5154 _Integer __val, __true_type)
5155 {
return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
5157 template<
class _InputIterator>
5159 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
5160 _InputIterator __k2, __false_type);
5163 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
5167 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
5172 template<
class _InIterator>
5174 _S_construct_aux(_InIterator __beg, _InIterator __end,
5175 const _Alloc& __a, __false_type)
5177 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
5178 return _S_construct(__beg, __end, __a, _Tag());
5183 template<
class _Integer>
5185 _S_construct_aux(_Integer __beg, _Integer __end,
5186 const _Alloc& __a, __true_type)
5187 {
return _S_construct_aux_2(static_cast<size_type>(__beg),
5191 _S_construct_aux_2(size_type __req, _CharT __c,
const _Alloc& __a)
5192 {
return _S_construct(__req, __c, __a); }
5194 template<
class _InIterator>
5196 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a)
5198 typedef typename std::__is_integer<_InIterator>::__type _Integral;
5199 return _S_construct_aux(__beg, __end, __a, _Integral());
5203 template<
class _InIterator>
5205 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
5206 input_iterator_tag);
5210 template<
class _FwdIterator>
5212 _S_construct(_FwdIterator __beg, _FwdIterator __end,
const _Alloc& __a,
5213 forward_iterator_tag);
5216 _S_construct(size_type __req, _CharT __c,
const _Alloc& __a);
5233 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const;
5243 swap(basic_string& __s)
5244 _GLIBCXX_NOEXCEPT_IF(allocator_traits<_Alloc>::is_always_equal::value);
5255 {
return _M_data(); }
5267 {
return _M_data(); }
5269 #if __cplusplus >= 201703L
5289 {
return _M_dataplus; }
5304 find(
const _CharT* __s, size_type __pos, size_type __n)
const
5320 {
return this->
find(__str.data(), __pos, __str.size()); }
5333 find(
const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
5335 __glibcxx_requires_string(__s);
5336 return this->
find(__s, __pos, traits_type::length(__s));
5350 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
5352 #if __cplusplus >= 201703L
5359 template<
typename _Tp>
5360 _If_sv<_Tp, size_type>
5361 find(
const _Tp& __svt, size_type __pos = 0) const
5365 return this->
find(__sv.data(), __pos, __sv.size());
5382 {
return this->
rfind(__str.data(), __pos, __str.size()); }
5397 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
5411 rfind(
const _CharT* __s, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
5413 __glibcxx_requires_string(__s);
5414 return this->
rfind(__s, __pos, traits_type::length(__s));
5428 rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
5430 #if __cplusplus >= 201703L
5437 template<
typename _Tp>
5438 _If_sv<_Tp, size_type>
5439 rfind(
const _Tp& __svt, size_type __pos = npos) const
5443 return this->
rfind(__sv.data(), __pos, __sv.size());
5461 {
return this->
find_first_of(__str.data(), __pos, __str.size()); }
5476 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
5493 __glibcxx_requires_string(__s);
5494 return this->
find_first_of(__s, __pos, traits_type::length(__s));
5511 {
return this->
find(__c, __pos); }
5513 #if __cplusplus >= 201703L
5521 template<
typename _Tp>
5522 _If_sv<_Tp, size_type>
5527 return this->
find_first_of(__sv.data(), __pos, __sv.size());
5545 {
return this->
find_last_of(__str.data(), __pos, __str.size()); }
5560 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
5577 __glibcxx_requires_string(__s);
5578 return this->
find_last_of(__s, __pos, traits_type::length(__s));
5595 {
return this->
rfind(__c, __pos); }
5597 #if __cplusplus >= 201703L
5605 template<
typename _Tp>
5606 _If_sv<_Tp, size_type>
5611 return this->
find_last_of(__sv.data(), __pos, __sv.size());
5644 size_type __n)
const _GLIBCXX_NOEXCEPT;
5660 __glibcxx_requires_string(__s);
5678 #if __cplusplus >= 201703L
5686 template<
typename _Tp>
5687 _If_sv<_Tp, size_type>
5726 size_type __n)
const _GLIBCXX_NOEXCEPT;
5742 __glibcxx_requires_string(__s);
5760 #if __cplusplus >= 201703L
5768 template<
typename _Tp>
5769 _If_sv<_Tp, size_type>
5791 substr(size_type __pos = 0, size_type __n = npos)
const
5793 _M_check(__pos,
"basic_string::substr"), __n); }
5812 const size_type __size = this->
size();
5813 const size_type __osize = __str.size();
5814 const size_type __len =
std::min(__size, __osize);
5816 int __r = traits_type::compare(_M_data(), __str.data(), __len);
5818 __r = _S_compare(__size, __osize);
5822 #if __cplusplus >= 201703L
5828 template<
typename _Tp>
5834 const size_type __size = this->
size();
5835 const size_type __osize = __sv.size();
5836 const size_type __len =
std::min(__size, __osize);
5838 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
5840 __r = _S_compare(__size, __osize);
5852 template<
typename _Tp>
5854 compare(size_type __pos, size_type __n,
const _Tp& __svt)
const
5858 return __sv_type(*this).substr(__pos, __n).compare(__sv);
5871 template<
typename _Tp>
5873 compare(size_type __pos1, size_type __n1,
const _Tp& __svt,
5874 size_type __pos2, size_type __n2 = npos) const
5879 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
5930 size_type __pos2, size_type __n2 = npos)
const;
5947 compare(
const _CharT* __s)
const _GLIBCXX_NOEXCEPT;
5971 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const;
5998 compare(size_type __pos, size_type __n1,
const _CharT* __s,
5999 size_type __n2)
const;
6001 #if __cplusplus > 201703L
6004 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
6007 starts_with(_CharT __x)
const noexcept
6008 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
6011 starts_with(
const _CharT* __x)
const noexcept
6012 {
return __sv_type(this->
data(), this->
size()).starts_with(__x); }
6015 ends_with(basic_string_view<_CharT, _Traits> __x)
const noexcept
6016 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
6019 ends_with(_CharT __x)
const noexcept
6020 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
6023 ends_with(
const _CharT* __x)
const noexcept
6024 {
return __sv_type(this->
data(), this->
size()).ends_with(__x); }
6027 #if __cplusplus >= 202011L \
6028 || (__cplusplus == 202002L && !defined __STRICT_ANSI__)
6030 contains(basic_string_view<_CharT, _Traits> __x)
const noexcept
6031 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
6034 contains(_CharT __x)
const noexcept
6035 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
6038 contains(
const _CharT* __x)
const noexcept
6039 {
return __sv_type(this->
data(), this->
size()).contains(__x); }
6042 # ifdef _GLIBCXX_TM_TS_INTERNAL
6044 ::_txnal_cow_string_C1_for_exceptions(
void* that,
const char* s,
6047 ::_txnal_cow_string_c_str(
const void *that);
6049 ::_txnal_cow_string_D1(
void *that);
6051 ::_txnal_cow_string_D1_commit(
void *that);
6054 #endif // !_GLIBCXX_USE_CXX11_ABI
6056 #if __cpp_deduction_guides >= 201606
6057 _GLIBCXX_BEGIN_NAMESPACE_CXX11
6058 template<
typename _InputIterator,
typename _CharT
6059 =
typename iterator_traits<_InputIterator>::value_type,
6060 typename _Allocator = allocator<_CharT>,
6061 typename = _RequireInputIter<_InputIterator>,
6062 typename = _RequireAllocator<_Allocator>>
6063 basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
6064 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
6068 template<
typename _CharT,
typename _Traits,
6069 typename _Allocator = allocator<_CharT>,
6070 typename = _RequireAllocator<_Allocator>>
6071 basic_string(basic_string_view<_CharT, _Traits>,
const _Allocator& = _Allocator())
6072 -> basic_string<_CharT, _Traits, _Allocator>;
6074 template<
typename _CharT,
typename _Traits,
6075 typename _Allocator = allocator<_CharT>,
6076 typename = _RequireAllocator<_Allocator>>
6077 basic_string(basic_string_view<_CharT, _Traits>,
6078 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
6079 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
6080 const _Allocator& = _Allocator())
6081 -> basic_string<_CharT, _Traits, _Allocator>;
6082 _GLIBCXX_END_NAMESPACE_CXX11
6092 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6093 basic_string<_CharT, _Traits, _Alloc>
6098 __str.append(__rhs);
6108 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6109 basic_string<_CharT,_Traits,_Alloc>
6111 const basic_string<_CharT,_Traits,_Alloc>& __rhs);
6119 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6120 basic_string<_CharT,_Traits,_Alloc>
6121 operator+(_CharT __lhs,
const basic_string<_CharT,_Traits,_Alloc>& __rhs);
6129 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6130 inline basic_string<_CharT, _Traits, _Alloc>
6132 const _CharT* __rhs)
6135 __str.append(__rhs);
6145 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6146 inline basic_string<_CharT, _Traits, _Alloc>
6150 typedef typename __string_type::size_type __size_type;
6151 __string_type __str(__lhs);
6152 __str.append(__size_type(1), __rhs);
6156 #if __cplusplus >= 201103L
6157 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6158 inline basic_string<_CharT, _Traits, _Alloc>
6159 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
6160 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6161 {
return std::move(__lhs.append(__rhs)); }
6163 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6164 inline basic_string<_CharT, _Traits, _Alloc>
6165 operator+(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6166 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
6167 {
return std::move(__rhs.insert(0, __lhs)); }
6169 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6170 inline basic_string<_CharT, _Traits, _Alloc>
6171 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
6172 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
6174 #if _GLIBCXX_USE_CXX11_ABI
6175 using _Alloc_traits = allocator_traits<_Alloc>;
6176 bool __use_rhs =
false;
6177 if _GLIBCXX17_CONSTEXPR (
typename _Alloc_traits::is_always_equal{})
6179 else if (__lhs.get_allocator() == __rhs.get_allocator())
6184 const auto __size = __lhs.size() + __rhs.size();
6185 if (__size > __lhs.capacity() && __size <= __rhs.capacity())
6186 return std::move(__rhs.insert(0, __lhs));
6191 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6192 inline basic_string<_CharT, _Traits, _Alloc>
6194 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
6195 {
return std::move(__rhs.insert(0, __lhs)); }
6197 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6198 inline basic_string<_CharT, _Traits, _Alloc>
6200 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
6201 {
return std::move(__rhs.insert(0, 1, __lhs)); }
6203 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6204 inline basic_string<_CharT, _Traits, _Alloc>
6205 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
6206 const _CharT* __rhs)
6207 {
return std::move(__lhs.append(__rhs)); }
6209 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6210 inline basic_string<_CharT, _Traits, _Alloc>
6211 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
6213 {
return std::move(__lhs.append(1, __rhs)); }
6223 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6228 {
return __lhs.compare(__rhs) == 0; }
6230 template<
typename _CharT>
6232 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
bool>::__type
6233 operator==(
const basic_string<_CharT>& __lhs,
6234 const basic_string<_CharT>& __rhs) _GLIBCXX_NOEXCEPT
6235 {
return (__lhs.size() == __rhs.size()
6245 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6248 const _CharT* __rhs)
6249 {
return __lhs.compare(__rhs) == 0; }
6251 #if __cpp_lib_three_way_comparison
6259 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6261 operator<=>(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6262 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
noexcept
6263 -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
6264 {
return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); }
6273 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6275 operator<=>(
const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6277 -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
6278 {
return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); }
6286 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6288 operator==(
const _CharT* __lhs,
6290 {
return __rhs.compare(__lhs) == 0; }
6299 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6304 {
return !(__lhs == __rhs); }
6312 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6314 operator!=(
const _CharT* __lhs,
6316 {
return !(__lhs == __rhs); }
6324 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6327 const _CharT* __rhs)
6328 {
return !(__lhs == __rhs); }
6337 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6339 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6342 {
return __lhs.
compare(__rhs) < 0; }
6350 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6352 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6353 const _CharT* __rhs)
6354 {
return __lhs.compare(__rhs) < 0; }
6362 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6364 operator<(
const _CharT* __lhs,
6366 {
return __rhs.compare(__lhs) > 0; }
6375 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6380 {
return __lhs.compare(__rhs) > 0; }
6388 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6391 const _CharT* __rhs)
6392 {
return __lhs.compare(__rhs) > 0; }
6400 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6402 operator>(
const _CharT* __lhs,
6404 {
return __rhs.compare(__lhs) < 0; }
6413 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6415 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6418 {
return __lhs.
compare(__rhs) <= 0; }
6426 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6428 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6429 const _CharT* __rhs)
6430 {
return __lhs.compare(__rhs) <= 0; }
6438 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6440 operator<=(
const _CharT* __lhs,
6442 {
return __rhs.compare(__lhs) >= 0; }
6451 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6456 {
return __lhs.compare(__rhs) >= 0; }
6464 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6467 const _CharT* __rhs)
6468 {
return __lhs.compare(__rhs) >= 0; }
6476 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6478 operator>=(
const _CharT* __lhs,
6480 {
return __rhs.compare(__lhs) <= 0; }
6481 #endif // three-way comparison
6490 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6494 _GLIBCXX_NOEXCEPT_IF(
noexcept(__lhs.swap(__rhs)))
6495 { __lhs.swap(__rhs); }
6510 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6511 basic_istream<_CharT, _Traits>&
6512 operator>>(basic_istream<_CharT, _Traits>& __is,
6513 basic_string<_CharT, _Traits, _Alloc>& __str);
6516 basic_istream<char>&
6517 operator>>(basic_istream<char>& __is, basic_string<char>& __str);
6528 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6529 inline basic_ostream<_CharT, _Traits>&
6530 operator<<(basic_ostream<_CharT, _Traits>& __os,
6535 return __ostream_insert(__os, __str.data(), __str.size());
6551 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6552 basic_istream<_CharT, _Traits>&
6553 getline(basic_istream<_CharT, _Traits>& __is,
6554 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
6568 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6569 inline basic_istream<_CharT, _Traits>&
6574 #if __cplusplus >= 201103L
6576 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6577 inline basic_istream<_CharT, _Traits>&
6583 template<
typename _CharT,
typename _Traits,
typename _Alloc>
6584 inline basic_istream<_CharT, _Traits>&
6591 basic_istream<char>&
6592 getline(basic_istream<char>& __in, basic_string<char>& __str,
6595 #ifdef _GLIBCXX_USE_WCHAR_T
6597 basic_istream<wchar_t>&
6598 getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
6602 _GLIBCXX_END_NAMESPACE_VERSION
6605 #if __cplusplus >= 201103L
6610 namespace std _GLIBCXX_VISIBILITY(default)
6612 _GLIBCXX_BEGIN_NAMESPACE_VERSION
6613 _GLIBCXX_BEGIN_NAMESPACE_CXX11
6615 #if _GLIBCXX_USE_C99_STDLIB
6618 stoi(
const string& __str,
size_t* __idx = 0,
int __base = 10)
6619 {
return __gnu_cxx::__stoa<long, int>(&std::strtol,
"stoi", __str.c_str(),
6623 stol(
const string& __str,
size_t* __idx = 0,
int __base = 10)
6624 {
return __gnu_cxx::__stoa(&std::strtol,
"stol", __str.c_str(),
6627 inline unsigned long
6628 stoul(
const string& __str,
size_t* __idx = 0,
int __base = 10)
6629 {
return __gnu_cxx::__stoa(&std::strtoul,
"stoul", __str.c_str(),
6633 stoll(
const string& __str,
size_t* __idx = 0,
int __base = 10)
6634 {
return __gnu_cxx::__stoa(&std::strtoll,
"stoll", __str.c_str(),
6637 inline unsigned long long
6638 stoull(
const string& __str,
size_t* __idx = 0,
int __base = 10)
6639 {
return __gnu_cxx::__stoa(&std::strtoull,
"stoull", __str.c_str(),
6644 stof(
const string& __str,
size_t* __idx = 0)
6645 {
return __gnu_cxx::__stoa(&std::strtof,
"stof", __str.c_str(), __idx); }
6648 stod(
const string& __str,
size_t* __idx = 0)
6649 {
return __gnu_cxx::__stoa(&std::strtod,
"stod", __str.c_str(), __idx); }
6652 stold(
const string& __str,
size_t* __idx = 0)
6653 {
return __gnu_cxx::__stoa(&std::strtold,
"stold", __str.c_str(), __idx); }
6654 #endif // _GLIBCXX_USE_C99_STDLIB
6659 to_string(
int __val)
6661 const bool __neg = __val < 0;
6662 const unsigned __uval = __neg ? (unsigned)~__val + 1u : __val;
6663 const auto __len = __detail::__to_chars_len(__uval);
6664 string __str(__neg + __len,
'-');
6665 __detail::__to_chars_10_impl(&__str[__neg], __len, __uval);
6670 to_string(
unsigned __val)
6672 string __str(__detail::__to_chars_len(__val),
'\0');
6673 __detail::__to_chars_10_impl(&__str[0], __str.size(), __val);
6678 to_string(
long __val)
6680 const bool __neg = __val < 0;
6681 const unsigned long __uval = __neg ? (
unsigned long)~__val + 1ul : __val;
6682 const auto __len = __detail::__to_chars_len(__uval);
6683 string __str(__neg + __len,
'-');
6684 __detail::__to_chars_10_impl(&__str[__neg], __len, __uval);
6689 to_string(
unsigned long __val)
6691 string __str(__detail::__to_chars_len(__val),
'\0');
6692 __detail::__to_chars_10_impl(&__str[0], __str.size(), __val);
6697 to_string(
long long __val)
6699 const bool __neg = __val < 0;
6700 const unsigned long long __uval
6701 = __neg ? (
unsigned long long)~__val + 1ull : __val;
6702 const auto __len = __detail::__to_chars_len(__uval);
6703 string __str(__neg + __len,
'-');
6704 __detail::__to_chars_10_impl(&__str[__neg], __len, __uval);
6709 to_string(
unsigned long long __val)
6711 string __str(__detail::__to_chars_len(__val),
'\0');
6712 __detail::__to_chars_10_impl(&__str[0], __str.size(), __val);
6716 #if _GLIBCXX_USE_C99_STDIO
6720 to_string(
float __val)
6723 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
6724 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
6729 to_string(
double __val)
6732 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
6733 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
6738 to_string(
long double __val)
6741 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
6742 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
6745 #endif // _GLIBCXX_USE_C99_STDIO
6747 #if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR
6749 stoi(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
6750 {
return __gnu_cxx::__stoa<long, int>(&std::wcstol,
"stoi", __str.c_str(),
6754 stol(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
6755 {
return __gnu_cxx::__stoa(&std::wcstol,
"stol", __str.c_str(),
6758 inline unsigned long
6759 stoul(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
6760 {
return __gnu_cxx::__stoa(&std::wcstoul,
"stoul", __str.c_str(),
6764 stoll(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
6765 {
return __gnu_cxx::__stoa(&std::wcstoll,
"stoll", __str.c_str(),
6768 inline unsigned long long
6769 stoull(
const wstring& __str,
size_t* __idx = 0,
int __base = 10)
6770 {
return __gnu_cxx::__stoa(&std::wcstoull,
"stoull", __str.c_str(),
6775 stof(
const wstring& __str,
size_t* __idx = 0)
6776 {
return __gnu_cxx::__stoa(&std::wcstof,
"stof", __str.c_str(), __idx); }
6779 stod(
const wstring& __str,
size_t* __idx = 0)
6780 {
return __gnu_cxx::__stoa(&std::wcstod,
"stod", __str.c_str(), __idx); }
6783 stold(
const wstring& __str,
size_t* __idx = 0)
6784 {
return __gnu_cxx::__stoa(&std::wcstold,
"stold", __str.c_str(), __idx); }
6786 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
6789 to_wstring(
int __val)
6790 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 *
sizeof(int),
6794 to_wstring(
unsigned __val)
6795 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6796 4 *
sizeof(unsigned),
6800 to_wstring(
long __val)
6801 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 *
sizeof(long),
6805 to_wstring(
unsigned long __val)
6806 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6807 4 *
sizeof(
unsigned long),
6811 to_wstring(
long long __val)
6812 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6813 4 *
sizeof(
long long),
6817 to_wstring(
unsigned long long __val)
6818 {
return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6819 4 *
sizeof(
unsigned long long),
6823 to_wstring(
float __val)
6826 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
6827 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
6832 to_wstring(
double __val)
6835 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
6836 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
6841 to_wstring(
long double __val)
6844 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
6845 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
6848 #endif // _GLIBCXX_HAVE_BROKEN_VSWPRINTF
6849 #endif // _GLIBCXX_USE_WCHAR_T && _GLIBCXX_USE_C99_WCHAR
6851 _GLIBCXX_END_NAMESPACE_CXX11
6852 _GLIBCXX_END_NAMESPACE_VERSION
6857 #if __cplusplus >= 201103L
6861 namespace std _GLIBCXX_VISIBILITY(default)
6863 _GLIBCXX_BEGIN_NAMESPACE_VERSION
6867 #ifndef _GLIBCXX_COMPATIBILITY_CXX0X
6871 :
public __hash_base<size_t, string>
6874 operator()(
const string& __s)
const noexcept
6875 {
return std::_Hash_impl::hash(__s.
data(), __s.length()); }
6882 #ifdef _GLIBCXX_USE_WCHAR_T
6886 :
public __hash_base<size_t, wstring>
6889 operator()(
const wstring& __s)
const noexcept
6890 {
return std::_Hash_impl::hash(__s.
data(),
6891 __s.length() *
sizeof(wchar_t)); }
6900 #ifdef _GLIBCXX_USE_CHAR8_T
6903 struct hash<u8string>
6904 :
public __hash_base<size_t, u8string>
6907 operator()(
const u8string& __s)
const noexcept
6908 {
return std::_Hash_impl::hash(__s.data(),
6909 __s.length() *
sizeof(char8_t)); }
6920 :
public __hash_base<size_t, u16string>
6923 operator()(
const u16string& __s)
const noexcept
6924 {
return std::_Hash_impl::hash(__s.
data(),
6925 __s.length() *
sizeof(char16_t)); }
6935 :
public __hash_base<size_t, u32string>
6938 operator()(
const u32string& __s)
const noexcept
6939 {
return std::_Hash_impl::hash(__s.
data(),
6940 __s.length() *
sizeof(char32_t)); }
6947 #if __cplusplus >= 201402L
6949 #define __cpp_lib_string_udls 201304
6951 inline namespace literals
6953 inline namespace string_literals
6955 #pragma GCC diagnostic push
6956 #pragma GCC diagnostic ignored "-Wliteral-suffix"
6957 _GLIBCXX_DEFAULT_ABI_TAG
6958 inline basic_string<char>
6959 operator""s(
const char* __str,
size_t __len)
6960 {
return basic_string<char>{__str, __len}; }
6962 #ifdef _GLIBCXX_USE_WCHAR_T
6963 _GLIBCXX_DEFAULT_ABI_TAG
6964 inline basic_string<wchar_t>
6965 operator""s(
const wchar_t* __str,
size_t __len)
6966 {
return basic_string<wchar_t>{__str, __len}; }
6969 #ifdef _GLIBCXX_USE_CHAR8_T
6970 _GLIBCXX_DEFAULT_ABI_TAG
6971 inline basic_string<char8_t>
6972 operator""s(
const char8_t* __str,
size_t __len)
6973 {
return basic_string<char8_t>{__str, __len}; }
6976 _GLIBCXX_DEFAULT_ABI_TAG
6977 inline basic_string<char16_t>
6978 operator""s(
const char16_t* __str,
size_t __len)
6979 {
return basic_string<char16_t>{__str, __len}; }
6981 _GLIBCXX_DEFAULT_ABI_TAG
6982 inline basic_string<char32_t>
6983 operator""s(
const char32_t* __str,
size_t __len)
6984 {
return basic_string<char32_t>{__str, __len}; }
6986 #pragma GCC diagnostic pop
6990 #if __cplusplus >= 201703L
6991 namespace __detail::__variant
6993 template<
typename>
struct _Never_valueless_alt;
6997 template<
typename _Tp,
typename _Traits,
typename _Alloc>
6998 struct _Never_valueless_alt<std::basic_string<_Tp, _Traits, _Alloc>>
7000 is_nothrow_move_constructible<std::basic_string<_Tp, _Traits, _Alloc>>,
7001 is_nothrow_move_assignable<std::basic_string<_Tp, _Traits, _Alloc>>
7008 _GLIBCXX_END_NAMESPACE_VERSION
_If_sv< _Tp, basic_string & > insert(size_type __pos, const _Tp &__svt)
Insert a string_view.
const_reference operator[](size_type __pos) const noexcept
Subscript access to the data contained in the string.
constexpr auto cbegin(const _Container &__cont) noexcept(noexcept(std::begin(__cont))) -> decltype(std::begin(__cont))
Return an iterator pointing to the first element of the const container.
size_type find_first_of(const _CharT *__s, size_type __pos=0) const noexcept
Find position of a character of C string.
void resize(size_type __n)
Resizes the string to the specified number of characters.
_If_sv< _Tp, basic_string & > replace(size_type __pos1, size_type __n1, const _Tp &__svt, size_type __pos2, size_type __n2=npos)
Replace range of characters with string_view.
basic_string & replace(iterator __i1, iterator __i2, const _CharT *__s)
Replace range of characters with C string.
size_type find(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find position of a C substring.
size_type find(const _CharT *__s, size_type __pos=0) const noexcept
Find position of a C string.
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C string.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
basic_string & assign(const _CharT *__s)
Set value to contents of a C string.
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.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
basic_string & replace(iterator __i1, iterator __i2, const _CharT *__s, size_type __n)
Replace range of characters with C substring.
basic_string & replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
Replace characters with multiple characters.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Primary class template hash.
constexpr auto rend(_Container &__cont) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.
A non-owning reference to a string.
basic_string & append(const basic_string &__str)
Append a string to this string.
static const size_type npos
Value returned by various member functions when they fail.
const_reference back() const noexcept
basic_string & operator+=(_CharT __c)
Append a character.
_If_sv< _Tp, size_type > find_first_not_of(const _Tp &__svt, size_type __pos=0) const noexcept(is_same< _Tp, __sv_type >::value)
Find position of a character not in a string_view.
size_type find_first_of(_CharT __c, size_type __pos=0) const noexcept
Find position of a character.
iterator erase(iterator __position)
Remove one character.
Forward iterators support a superset of input iterator operations.
_If_sv< _Tp, int > compare(size_type __pos1, size_type __n1, const _Tp &__svt, size_type __pos2, size_type __n2=npos) const noexcept(is_same< _Tp, __sv_type >::value)
Compare to a string_view.
basic_string< wchar_t > wstring
A string of wchar_t.
basic_string & append(const _CharT *__s)
Append a C string.
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
_If_sv< _Tp, basic_string & > assign(const _Tp &__svt)
Set value from a string_view.
basic_string & operator+=(const basic_string &__str)
Append a string to this string.
reference at(size_type __n)
Provides access to the data contained in the string.
size_type find_last_not_of(const _CharT *__s, size_type __pos=npos) const noexcept
Find last position of a character not in C string.
basic_string & append(initializer_list< _CharT > __l)
Append an initializer_list of characters.
size_type rfind(const _CharT *__s, size_type __pos=npos) const noexcept
Find last position of a C string.
_If_sv< _Tp, int > compare(size_type __pos, size_type __n, const _Tp &__svt) const noexcept(is_same< _Tp, __sv_type >::value)
Compare to a string_view.
_If_sv< _Tp, basic_string & > replace(const_iterator __i1, const_iterator __i2, const _Tp &__svt)
Replace range of characters with string_view.
Uniform interface to C++98 and C++11 allocators.
void pop_back()
Remove the last character.
_If_sv< _Tp, basic_string & > operator+=(const _Tp &__svt)
Append a string_view.
size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
_If_sv< _Tp, size_type > rfind(const _Tp &__svt, size_type __pos=npos) const noexcept(is_same< _Tp, __sv_type >::value)
Find last position of a string_view.
basic_string & assign(size_type __n, _CharT __c)
Set value to multiple characters.
void insert(iterator __p, _InputIterator __beg, _InputIterator __end)
Insert a range of characters.
_Tp * begin(valarray< _Tp > &__va)
Return an iterator pointing to the first element of the valarray.
basic_string & assign(initializer_list< _CharT > __l)
Set value to an initializer_list of characters.
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 reserve()
Equivalent to shrink_to_fit().
constexpr auto crbegin(const _Container &__cont) -> decltype(std::rbegin(__cont))
Return a reverse iterator pointing to the last element of the const container.
_CharT * data() noexcept
Return non-const pointer to contents.
constexpr auto rbegin(_Container &__cont) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last element of the container.
basic_string & insert(size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n=npos)
Insert a substring.
_Tp * end(valarray< _Tp > &__va)
Return an iterator pointing to one past the last element of the valarray.
size_type find(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a string.
basic_string(const basic_string &__str)
Construct string with copy of value of str.
basic_string & replace(size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos)
Replace characters with value from another string.
void shrink_to_fit() noexcept
A non-binding request to reduce capacity() to size().
_If_sv< _Tp, size_type > find(const _Tp &__svt, size_type __pos=0) const noexcept(is_same< _Tp, __sv_type >::value)
Find position of a string_view.
size_type find_first_not_of(const _CharT *__s, size_type __pos=0) const noexcept
Find position of a character not in C string.
Managing sequences of characters and character-like objects.
_If_sv< _Tp, size_type > find_first_of(const _Tp &__svt, size_type __pos=0) const noexcept(is_same< _Tp, __sv_type >::value)
Find position of a character of a string_view.
const _CharT * data() const noexcept
Return const pointer to contents.
reference operator[](size_type __pos)
Subscript access to the data contained in the string.
_If_sv< _Tp, int > compare(const _Tp &__svt) const noexcept(is_same< _Tp, __sv_type >::value)
Compare to a string_view.
Template class basic_istream.
size_type rfind(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a string.
const_reference at(size_type __n) const
Provides access to the data contained in the string.
_If_sv< _Tp, size_type > find_last_of(const _Tp &__svt, size_type __pos=npos) const noexcept(is_same< _Tp, __sv_type >::value)
Find last position of a character of string.
void insert(iterator __p, initializer_list< _CharT > __l)
Insert an initializer_list of characters.
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
basic_string & replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
Replace range of characters with multiple characters.
constexpr auto cend(const _Container &__cont) noexcept(noexcept(std::end(__cont))) -> decltype(std::end(__cont))
Return an iterator pointing to one past the last element of the const container.
size_type capacity() const noexcept
_If_sv< _Tp, basic_string & > append(const _Tp &__svt, size_type __pos, size_type __n=npos)
Append a range of characters from a string_view.
char_type widen(char __c) const
Widens characters.
basic_string & insert(size_type __pos, const _CharT *__s)
Insert a C string.
basic_string & operator+=(initializer_list< _CharT > __l)
Append an initializer_list of characters.
void push_back(_CharT __c)
Append a single character.
basic_string & replace(iterator __i1, iterator __i2, initializer_list< _CharT > __l)
Replace range of characters with initializer_list.
Uniform interface to all allocator types.
constexpr _Iterator __base(_Iterator __it)
allocator_type get_allocator() const noexcept
Return copy of allocator used to construct this string.
basic_string & insert(size_type __pos, size_type __n, _CharT __c)
Insert multiple characters.
basic_string(const _Alloc &__a)
Construct an empty string using allocator a.
_If_sv< _Tp, basic_string & > replace(size_type __pos, size_type __n, const _Tp &__svt)
Replace range of characters with string_view.
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
_If_sv< _Tp, size_type > find_last_not_of(const _Tp &__svt, size_type __pos=npos) const noexcept(is_same< _Tp, __sv_type >::value)
Find last position of a character not in a string_view.
Uniform interface to all pointer-like types.
void insert(iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
basic_string & assign(const basic_string &__str, size_type __pos, size_type __n=npos)
Set value to a substring of a string.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
basic_string & append(_InputIterator __first, _InputIterator __last)
Append a range of characters.
bool empty() const noexcept
basic_string & operator+=(const _CharT *__s)
Append a C string.
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 & assign(_InputIterator __first, _InputIterator __last)
Set value to a range of characters.
_If_sv< _Tp, basic_string & > append(const _Tp &__svt)
Append a string_view.
_If_sv< _Tp, basic_string & > assign(const _Tp &__svt, size_type __pos, size_type __n=npos)
Set value from a range of characters in a string_view.
Basis for explicit traits specializations.
void noexcept()
Swap contents with another string.
int compare(const basic_string &__str) const
Compare to a string.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
basic_string & replace(iterator __i1, iterator __i2, const basic_string &__str)
Replace range of characters with string.
basic_string & replace(iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2)
Replace range of characters with range.
constexpr auto crend(const _Container &__cont) -> decltype(std::rend(__cont))
Return a reverse iterator pointing one past the first element of the const container.
iterator insert(iterator __p, _CharT __c)
Insert one character.
basic_string & replace(size_type __pos, size_type __n1, const _CharT *__s)
Replace characters with value of a C string.
basic_string(const _CharT *__s, size_type __n, const _Alloc &__a=_Alloc())
Construct string initialized by a character array.
size_type find_last_of(const _CharT *__s, size_type __pos=npos) const noexcept
Find last position of a character of C string.
size_type find_last_of(_CharT __c, size_type __pos=npos) const noexcept
Find last position of a character.
basic_string & insert(size_type __pos1, const basic_string &__str)
Insert value of a string.
const_reference front() const noexcept
basic_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
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.
_If_sv< _Tp, basic_string & > insert(size_type __pos1, const _Tp &__svt, size_type __pos2, size_type __n=npos)
Insert a string_view.
auto_ptr & operator=(auto_ptr &__a)
auto_ptr assignment operator.