1 // Components for manipulating sequences of characters -*- C++ -*-
3 // Copyright (C) 1997-2022 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file bits/basic_string.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{string}
31 // ISO C++ 14882: 21 Strings library
34 #ifndef _BASIC_STRING_H
35 #define _BASIC_STRING_H 1
37 #pragma GCC system_header
39 #include <ext/atomicity.h>
40 #include <ext/alloc_traits.h>
41 #include <debug/debug.h>
43 #if __cplusplus >= 201103L
44 #include <initializer_list>
47 #if __cplusplus >= 201703L
48 # include <string_view>
51 #if ! _GLIBCXX_USE_CXX11_ABI
52 # include "cow_string.h"
54 namespace std
_GLIBCXX_VISIBILITY(default)
56 _GLIBCXX_BEGIN_NAMESPACE_VERSION
57 _GLIBCXX_BEGIN_NAMESPACE_CXX11
59 #ifdef __cpp_lib_is_constant_evaluated
60 // Support P0980R1 in C++20.
61 # define __cpp_lib_constexpr_string 201907L
62 #elif __cplusplus >= 201703L && _GLIBCXX_HAVE_IS_CONSTANT_EVALUATED
63 // Support P0426R1 changes to char_traits in C++17.
64 # define __cpp_lib_constexpr_string 201611L
68 * @class basic_string basic_string.h <string>
69 * @brief Managing sequences of characters and character-like objects.
74 * @tparam _CharT Type of character
75 * @tparam _Traits Traits for character type, defaults to
76 * char_traits<_CharT>.
77 * @tparam _Alloc Allocator type, defaults to allocator<_CharT>.
79 * Meets the requirements of a <a href="tables.html#65">container</a>, a
80 * <a href="tables.html#66">reversible container</a>, and a
81 * <a href="tables.html#67">sequence</a>. Of the
82 * <a href="tables.html#68">optional sequence requirements</a>, only
83 * @c push_back, @c at, and @c %array access are supported.
85 template<typename _CharT
, typename _Traits
, typename _Alloc
>
88 typedef typename
__gnu_cxx::__alloc_traits
<_Alloc
>::template
89 rebind
<_CharT
>::other _Char_alloc_type
;
91 #if __cpp_lib_constexpr_string < 201907L
92 typedef __gnu_cxx::__alloc_traits
<_Char_alloc_type
> _Alloc_traits
;
94 template<typename _Traits2
, typename _Dummy_for_PR85282
>
95 struct _Alloc_traits_impl
: __gnu_cxx::__alloc_traits
<_Char_alloc_type
>
97 typedef __gnu_cxx::__alloc_traits
<_Char_alloc_type
> _Base
;
99 [[__gnu__::__always_inline__
]]
100 static constexpr typename
_Base::pointer
101 allocate(_Char_alloc_type
& __a
, typename
_Base::size_type __n
)
103 pointer __p
= _Base::allocate(__a
, __n
);
104 if (std::is_constant_evaluated())
105 // Begin the lifetime of characters in allocated storage.
106 for (size_type __i
= 0; __i
< __n
; ++__i
)
107 std::construct_at(__builtin_addressof(__p
[__i
]));
112 template<typename _Dummy_for_PR85282
>
113 struct _Alloc_traits_impl
<char_traits
<_CharT
>, _Dummy_for_PR85282
>
114 : __gnu_cxx::__alloc_traits
<_Char_alloc_type
>
116 // std::char_traits begins the lifetime of characters.
119 using _Alloc_traits
= _Alloc_traits_impl
<_Traits
, void>;
124 typedef _Traits traits_type
;
125 typedef typename
_Traits::char_type value_type
;
126 typedef _Char_alloc_type allocator_type
;
127 typedef typename
_Alloc_traits::size_type size_type
;
128 typedef typename
_Alloc_traits::difference_type difference_type
;
129 typedef typename
_Alloc_traits::reference reference
;
130 typedef typename
_Alloc_traits::const_reference const_reference
;
131 typedef typename
_Alloc_traits::pointer pointer
;
132 typedef typename
_Alloc_traits::const_pointer const_pointer
;
133 typedef __gnu_cxx::__normal_iterator
<pointer
, basic_string
> iterator
;
134 typedef __gnu_cxx::__normal_iterator
<const_pointer
, basic_string
>
136 typedef std::reverse_iterator
<const_iterator
> const_reverse_iterator
;
137 typedef std::reverse_iterator
<iterator
> reverse_iterator
;
139 /// Value returned by various member functions when they fail.
140 static const size_type npos
= static_cast<size_type
>(-1);
143 // type used for positions in insert, erase etc.
144 #if __cplusplus < 201103L
145 typedef iterator __const_iterator
;
147 typedef const_iterator __const_iterator
;
151 #if __cplusplus >= 201703L
152 // A helper type for avoiding boiler-plate.
153 typedef basic_string_view
<_CharT
, _Traits
> __sv_type
;
155 template<typename _Tp
, typename _Res
>
156 using _If_sv
= enable_if_t
<
157 __and_
<is_convertible
<const _Tp
&, __sv_type
>,
158 __not_
<is_convertible
<const _Tp
*, const basic_string
*>>,
159 __not_
<is_convertible
<const _Tp
&, const _CharT
*>>>::value
,
162 // Allows an implicit conversion to __sv_type.
165 _S_to_string_view(__sv_type __svt
) noexcept
168 // Wraps a string_view by explicit conversion and thus
169 // allows to add an internal constructor that does not
170 // participate in overload resolution when a string_view
174 _GLIBCXX20_CONSTEXPR
explicit
175 __sv_wrapper(__sv_type __sv
) noexcept
: _M_sv(__sv
) { }
181 * @brief Only internally used: Construct string from a string view
183 * @param __svw string view wrapper.
184 * @param __a Allocator to use.
188 basic_string(__sv_wrapper __svw
, const _Alloc
& __a
)
189 : basic_string(__svw
._M_sv
.data(), __svw
._M_sv
.size(), __a
) { }
192 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
193 struct _Alloc_hider
: allocator_type
// TODO check __is_final
195 #if __cplusplus < 201103L
196 _Alloc_hider(pointer __dat
, const _Alloc
& __a
= _Alloc())
197 : allocator_type(__a
), _M_p(__dat
) { }
200 _Alloc_hider(pointer __dat
, const _Alloc
& __a
)
201 : allocator_type(__a
), _M_p(__dat
) { }
204 _Alloc_hider(pointer __dat
, _Alloc
&& __a
= _Alloc())
205 : allocator_type(std::move(__a
)), _M_p(__dat
) { }
208 pointer _M_p
; // The actual data.
211 _Alloc_hider _M_dataplus
;
212 size_type _M_string_length
;
214 enum { _S_local_capacity
= 15 / sizeof(_CharT
) };
218 _CharT _M_local_buf
[_S_local_capacity
+ 1];
219 size_type _M_allocated_capacity
;
225 { _M_dataplus
._M_p
= __p
; }
229 _M_length(size_type __length
)
230 { _M_string_length
= __length
; }
235 { return _M_dataplus
._M_p
; }
241 #if __cplusplus >= 201103L
242 return std::pointer_traits
<pointer
>::pointer_to(*_M_local_buf
);
244 return pointer(_M_local_buf
);
250 _M_local_data() const
252 #if __cplusplus >= 201103L
253 return std::pointer_traits
<const_pointer
>::pointer_to(*_M_local_buf
);
255 return const_pointer(_M_local_buf
);
261 _M_capacity(size_type __capacity
)
262 { _M_allocated_capacity
= __capacity
; }
266 _M_set_length(size_type __n
)
269 traits_type::assign(_M_data()[__n
], _CharT());
275 { return _M_data() == _M_local_data(); }
280 _M_create(size_type
&, size_type
);
287 _M_destroy(_M_allocated_capacity
);
292 _M_destroy(size_type __size
) throw()
293 { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size
+ 1); }
295 #if __cplusplus < 201103L || defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
296 // _M_construct_aux is used to implement the 21.3.1 para 15 which
297 // requires special behaviour if _InIterator is an integral type
298 template<typename _InIterator
>
300 _M_construct_aux(_InIterator __beg
, _InIterator __end
,
303 typedef typename iterator_traits
<_InIterator
>::iterator_category _Tag
;
304 _M_construct(__beg
, __end
, _Tag());
307 // _GLIBCXX_RESOLVE_LIB_DEFECTS
308 // 438. Ambiguity in the "do the right thing" clause
309 template<typename _Integer
>
311 _M_construct_aux(_Integer __beg
, _Integer __end
, std::__true_type
)
312 { _M_construct_aux_2(static_cast<size_type
>(__beg
), __end
); }
315 _M_construct_aux_2(size_type __req
, _CharT __c
)
316 { _M_construct(__req
, __c
); }
319 // For Input Iterators, used in istreambuf_iterators, etc.
320 template<typename _InIterator
>
323 _M_construct(_InIterator __beg
, _InIterator __end
,
324 std::input_iterator_tag
);
326 // For forward_iterators up to random_access_iterators, used for
327 // string::iterator, _CharT*, etc.
328 template<typename _FwdIterator
>
331 _M_construct(_FwdIterator __beg
, _FwdIterator __end
,
332 std::forward_iterator_tag
);
336 _M_construct(size_type __req
, _CharT __c
);
341 { return _M_dataplus
; }
344 const allocator_type
&
345 _M_get_allocator() const
346 { return _M_dataplus
; }
348 // Ensure that _M_local_buf is the active member of the union.
349 __attribute__((__always_inline__
))
352 _M_use_local_data() _GLIBCXX_NOEXCEPT
354 #if __cpp_lib_is_constant_evaluated
355 if (std::is_constant_evaluated())
356 _M_local_buf
[0] = _CharT();
358 return _M_local_data();
363 #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
364 // The explicit instantiations in misc-inst.cc require this due to
365 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64063
366 template<typename _Tp
, bool _Requires
=
367 !__are_same
<_Tp
, _CharT
*>::__value
368 && !__are_same
<_Tp
, const _CharT
*>::__value
369 && !__are_same
<_Tp
, iterator
>::__value
370 && !__are_same
<_Tp
, const_iterator
>::__value
>
371 struct __enable_if_not_native_iterator
372 { typedef basic_string
& __type
; };
373 template<typename _Tp
>
374 struct __enable_if_not_native_iterator
<_Tp
, false> { };
379 _M_check(size_type __pos
, const char* __s
) const
381 if (__pos
> this->size())
382 __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
383 "this->size() (which is %zu)"),
384 __s
, __pos
, this->size());
390 _M_check_length(size_type __n1
, size_type __n2
, const char* __s
) const
392 if (this->max_size() - (this->size() - __n1
) < __n2
)
393 __throw_length_error(__N(__s
));
397 // NB: _M_limit doesn't check for a bad __pos value.
400 _M_limit(size_type __pos
, size_type __off
) const _GLIBCXX_NOEXCEPT
402 const bool __testoff
= __off
< this->size() - __pos
;
403 return __testoff
? __off
: this->size() - __pos
;
406 // True if _Rep and source do not overlap.
408 _M_disjunct(const _CharT
* __s
) const _GLIBCXX_NOEXCEPT
410 return (less
<const _CharT
*>()(__s
, _M_data())
411 || less
<const _CharT
*>()(_M_data() + this->size(), __s
));
414 // When __n = 1 way faster than the general multichar
415 // traits_type::copy/move/assign.
418 _S_copy(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
421 traits_type::assign(*__d
, *__s
);
423 traits_type::copy(__d
, __s
, __n
);
428 _S_move(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
431 traits_type::assign(*__d
, *__s
);
433 traits_type::move(__d
, __s
, __n
);
438 _S_assign(_CharT
* __d
, size_type __n
, _CharT __c
)
441 traits_type::assign(*__d
, __c
);
443 traits_type::assign(__d
, __n
, __c
);
446 // _S_copy_chars is a separate template to permit specialization
447 // to optimize for the common case of pointers as iterators.
448 template<class _Iterator
>
451 _S_copy_chars(_CharT
* __p
, _Iterator __k1
, _Iterator __k2
)
453 for (; __k1
!= __k2
; ++__k1
, (void)++__p
)
454 traits_type::assign(*__p
, *__k1
); // These types are off.
459 _S_copy_chars(_CharT
* __p
, iterator __k1
, iterator __k2
) _GLIBCXX_NOEXCEPT
460 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
464 _S_copy_chars(_CharT
* __p
, const_iterator __k1
, const_iterator __k2
)
466 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
470 _S_copy_chars(_CharT
* __p
, _CharT
* __k1
, _CharT
* __k2
) _GLIBCXX_NOEXCEPT
471 { _S_copy(__p
, __k1
, __k2
- __k1
); }
475 _S_copy_chars(_CharT
* __p
, const _CharT
* __k1
, const _CharT
* __k2
)
477 { _S_copy(__p
, __k1
, __k2
- __k1
); }
481 _S_compare(size_type __n1
, size_type __n2
) _GLIBCXX_NOEXCEPT
483 const difference_type __d
= difference_type(__n1
- __n2
);
485 if (__d
> __gnu_cxx::__numeric_traits
<int>::__max
)
486 return __gnu_cxx::__numeric_traits
<int>::__max
;
487 else if (__d
< __gnu_cxx::__numeric_traits
<int>::__min
)
488 return __gnu_cxx::__numeric_traits
<int>::__min
;
495 _M_assign(const basic_string
&);
499 _M_mutate(size_type __pos
, size_type __len1
, const _CharT
* __s
,
504 _M_erase(size_type __pos
, size_type __n
);
507 // Construct/copy/destroy:
508 // NB: We overload ctors in some cases instead of using default
509 // arguments, per 17.4.4.4 para. 2 item 2.
512 * @brief Default constructor creates an empty string.
516 _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible
<_Alloc
>::value
)
517 : _M_dataplus(_M_local_data())
524 * @brief Construct an empty string using allocator @a a.
528 basic_string(const _Alloc
& __a
) _GLIBCXX_NOEXCEPT
529 : _M_dataplus(_M_local_data(), __a
)
536 * @brief Construct string with copy of value of @a __str.
537 * @param __str Source string.
540 basic_string(const basic_string
& __str
)
541 : _M_dataplus(_M_local_data(),
542 _Alloc_traits::_S_select_on_copy(__str
._M_get_allocator()))
544 _M_construct(__str
._M_data(), __str
._M_data() + __str
.length(),
545 std::forward_iterator_tag());
548 // _GLIBCXX_RESOLVE_LIB_DEFECTS
549 // 2583. no way to supply an allocator for basic_string(str, pos)
551 * @brief Construct string as copy of a substring.
552 * @param __str Source string.
553 * @param __pos Index of first character to copy from.
554 * @param __a Allocator to use.
557 basic_string(const basic_string
& __str
, size_type __pos
,
558 const _Alloc
& __a
= _Alloc())
559 : _M_dataplus(_M_local_data(), __a
)
561 const _CharT
* __start
= __str
._M_data()
562 + __str
._M_check(__pos
, "basic_string::basic_string");
563 _M_construct(__start
, __start
+ __str
._M_limit(__pos
, npos
),
564 std::forward_iterator_tag());
568 * @brief Construct string as copy of a substring.
569 * @param __str Source string.
570 * @param __pos Index of first character to copy from.
571 * @param __n Number of characters to copy.
574 basic_string(const basic_string
& __str
, size_type __pos
,
576 : _M_dataplus(_M_local_data())
578 const _CharT
* __start
= __str
._M_data()
579 + __str
._M_check(__pos
, "basic_string::basic_string");
580 _M_construct(__start
, __start
+ __str
._M_limit(__pos
, __n
),
581 std::forward_iterator_tag());
585 * @brief Construct string as copy of a substring.
586 * @param __str Source string.
587 * @param __pos Index of first character to copy from.
588 * @param __n Number of characters to copy.
589 * @param __a Allocator to use.
592 basic_string(const basic_string
& __str
, size_type __pos
,
593 size_type __n
, const _Alloc
& __a
)
594 : _M_dataplus(_M_local_data(), __a
)
596 const _CharT
* __start
597 = __str
._M_data() + __str
._M_check(__pos
, "string::string");
598 _M_construct(__start
, __start
+ __str
._M_limit(__pos
, __n
),
599 std::forward_iterator_tag());
603 * @brief Construct string initialized by a character %array.
604 * @param __s Source character %array.
605 * @param __n Number of characters to copy.
606 * @param __a Allocator to use (default is default allocator).
608 * NB: @a __s must have at least @a __n characters, '\\0'
609 * has no special meaning.
612 basic_string(const _CharT
* __s
, size_type __n
,
613 const _Alloc
& __a
= _Alloc())
614 : _M_dataplus(_M_local_data(), __a
)
616 // NB: Not required, but considered best practice.
617 if (__s
== 0 && __n
> 0)
618 std::__throw_logic_error(__N("basic_string: "
619 "construction from null is not valid"));
620 _M_construct(__s
, __s
+ __n
, std::forward_iterator_tag());
624 * @brief Construct string as copy of a C string.
625 * @param __s Source C string.
626 * @param __a Allocator to use (default is default allocator).
628 #if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
629 // _GLIBCXX_RESOLVE_LIB_DEFECTS
630 // 3076. basic_string CTAD ambiguity
631 template<typename
= _RequireAllocator
<_Alloc
>>
634 basic_string(const _CharT
* __s
, const _Alloc
& __a
= _Alloc())
635 : _M_dataplus(_M_local_data(), __a
)
637 // NB: Not required, but considered best practice.
639 std::__throw_logic_error(__N("basic_string: "
640 "construction from null is not valid"));
641 const _CharT
* __end
= __s
+ traits_type::length(__s
);
642 _M_construct(__s
, __end
, forward_iterator_tag());
646 * @brief Construct string as multiple characters.
647 * @param __n Number of characters.
648 * @param __c Character to use.
649 * @param __a Allocator to use (default is default allocator).
651 #if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
652 // _GLIBCXX_RESOLVE_LIB_DEFECTS
653 // 3076. basic_string CTAD ambiguity
654 template<typename
= _RequireAllocator
<_Alloc
>>
657 basic_string(size_type __n
, _CharT __c
, const _Alloc
& __a
= _Alloc())
658 : _M_dataplus(_M_local_data(), __a
)
659 { _M_construct(__n
, __c
); }
661 #if __cplusplus >= 201103L
663 * @brief Move construct string.
664 * @param __str Source string.
666 * The newly-created string contains the exact contents of @a __str.
667 * @a __str is a valid, but unspecified string.
670 basic_string(basic_string
&& __str
) noexcept
671 : _M_dataplus(_M_local_data(), std::move(__str
._M_get_allocator()))
673 if (__str
._M_is_local())
675 traits_type::copy(_M_local_buf
, __str
._M_local_buf
,
680 _M_data(__str
._M_data());
681 _M_capacity(__str
._M_allocated_capacity
);
684 // Must use _M_length() here not _M_set_length() because
685 // basic_stringbuf relies on writing into unallocated capacity so
686 // we mess up the contents if we put a '\0' in the string.
687 _M_length(__str
.length());
688 __str
._M_data(__str
._M_local_data());
689 __str
._M_set_length(0);
693 * @brief Construct string from an initializer %list.
694 * @param __l std::initializer_list of characters.
695 * @param __a Allocator to use (default is default allocator).
698 basic_string(initializer_list
<_CharT
> __l
, const _Alloc
& __a
= _Alloc())
699 : _M_dataplus(_M_local_data(), __a
)
700 { _M_construct(__l
.begin(), __l
.end(), std::forward_iterator_tag()); }
703 basic_string(const basic_string
& __str
, const _Alloc
& __a
)
704 : _M_dataplus(_M_local_data(), __a
)
705 { _M_construct(__str
.begin(), __str
.end(), std::forward_iterator_tag()); }
708 basic_string(basic_string
&& __str
, const _Alloc
& __a
)
709 noexcept(_Alloc_traits::_S_always_equal())
710 : _M_dataplus(_M_local_data(), __a
)
712 if (__str
._M_is_local())
714 traits_type::copy(_M_local_buf
, __str
._M_local_buf
,
716 _M_length(__str
.length());
717 __str
._M_set_length(0);
719 else if (_Alloc_traits::_S_always_equal()
720 || __str
.get_allocator() == __a
)
722 _M_data(__str
._M_data());
723 _M_length(__str
.length());
724 _M_capacity(__str
._M_allocated_capacity
);
725 __str
._M_data(__str
._M_local_buf
);
726 __str
._M_set_length(0);
729 _M_construct(__str
.begin(), __str
.end(), std::forward_iterator_tag());
732 basic_string(nullptr_t
) = delete;
733 basic_string
& operator=(nullptr_t
) = delete;
737 * @brief Construct string as copy of a range.
738 * @param __beg Start of range.
739 * @param __end End of range.
740 * @param __a Allocator to use (default is default allocator).
742 #if __cplusplus >= 201103L
743 template<typename _InputIterator
,
744 typename
= std::_RequireInputIter
<_InputIterator
>>
746 template<typename _InputIterator
>
749 basic_string(_InputIterator __beg
, _InputIterator __end
,
750 const _Alloc
& __a
= _Alloc())
751 : _M_dataplus(_M_local_data(), __a
)
753 #if __cplusplus >= 201103L
754 _M_construct(__beg
, __end
, std::__iterator_category(__beg
));
756 typedef typename
std::__is_integer
<_InputIterator
>::__type _Integral
;
757 _M_construct_aux(__beg
, __end
, _Integral());
761 #if __cplusplus >= 201703L
763 * @brief Construct string from a substring of a string_view.
764 * @param __t Source object convertible to string view.
765 * @param __pos The index of the first character to copy from __t.
766 * @param __n The number of characters to copy from __t.
767 * @param __a Allocator to use.
769 template<typename _Tp
, typename
= _If_sv
<_Tp
, void>>
771 basic_string(const _Tp
& __t
, size_type __pos
, size_type __n
,
772 const _Alloc
& __a
= _Alloc())
773 : basic_string(_S_to_string_view(__t
).substr(__pos
, __n
), __a
) { }
776 * @brief Construct string from a string_view.
777 * @param __t Source object convertible to string view.
778 * @param __a Allocator to use (default is default allocator).
780 template<typename _Tp
, typename
= _If_sv
<_Tp
, void>>
783 basic_string(const _Tp
& __t
, const _Alloc
& __a
= _Alloc())
784 : basic_string(__sv_wrapper(_S_to_string_view(__t
)), __a
) { }
788 * @brief Destroy the string instance.
795 * @brief Assign the value of @a str to this string.
796 * @param __str Source string.
800 operator=(const basic_string
& __str
)
802 return this->assign(__str
);
806 * @brief Copy contents of @a s into this string.
807 * @param __s Source null-terminated string.
811 operator=(const _CharT
* __s
)
812 { return this->assign(__s
); }
815 * @brief Set value to string of length 1.
816 * @param __c Source character.
818 * Assigning to a character makes this string length 1 and
819 * (*this)[0] == @a c.
823 operator=(_CharT __c
)
825 this->assign(1, __c
);
829 #if __cplusplus >= 201103L
831 * @brief Move assign the value of @a str to this string.
832 * @param __str Source string.
834 * The contents of @a str are moved into this string (without copying).
835 * @a str is a valid, but unspecified string.
837 // _GLIBCXX_RESOLVE_LIB_DEFECTS
838 // 2063. Contradictory requirements for string move assignment
841 operator=(basic_string
&& __str
)
842 noexcept(_Alloc_traits::_S_nothrow_move())
844 if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign()
845 && !_Alloc_traits::_S_always_equal()
846 && _M_get_allocator() != __str
._M_get_allocator())
848 // Destroy existing storage before replacing allocator.
849 _M_destroy(_M_allocated_capacity
);
850 _M_data(_M_local_data());
853 // Replace allocator if POCMA is true.
854 std::__alloc_on_move(_M_get_allocator(), __str
._M_get_allocator());
856 if (__str
._M_is_local())
858 // We've always got room for a short string, just copy it
859 // (unless this is a self-move, because that would violate the
860 // char_traits::copy precondition that the ranges don't overlap).
861 if (__builtin_expect(std::__addressof(__str
) != this, true))
864 this->_S_copy(_M_data(), __str
._M_data(), __str
.size());
865 _M_set_length(__str
.size());
868 else if (_Alloc_traits::_S_propagate_on_move_assign()
869 || _Alloc_traits::_S_always_equal()
870 || _M_get_allocator() == __str
._M_get_allocator())
872 // Just move the allocated pointer, our allocator can free it.
873 pointer __data
= nullptr;
874 size_type __capacity
;
877 if (_Alloc_traits::_S_always_equal())
879 // __str can reuse our existing storage.
881 __capacity
= _M_allocated_capacity
;
883 else // __str can't use it, so free it.
884 _M_destroy(_M_allocated_capacity
);
887 _M_data(__str
._M_data());
888 _M_length(__str
.length());
889 _M_capacity(__str
._M_allocated_capacity
);
892 __str
._M_data(__data
);
893 __str
._M_capacity(__capacity
);
896 __str
._M_data(__str
._M_local_buf
);
898 else // Need to do a deep copy
905 * @brief Set value to string constructed from initializer %list.
906 * @param __l std::initializer_list.
910 operator=(initializer_list
<_CharT
> __l
)
912 this->assign(__l
.begin(), __l
.size());
917 #if __cplusplus >= 201703L
919 * @brief Set value to string constructed from a string_view.
920 * @param __svt An object convertible to string_view.
922 template<typename _Tp
>
924 _If_sv
<_Tp
, basic_string
&>
925 operator=(const _Tp
& __svt
)
926 { return this->assign(__svt
); }
929 * @brief Convert to a string_view.
930 * @return A string_view.
933 operator __sv_type() const noexcept
934 { return __sv_type(data(), size()); }
939 * Returns a read/write iterator that points to the first character in
944 begin() _GLIBCXX_NOEXCEPT
945 { return iterator(_M_data()); }
948 * Returns a read-only (constant) iterator that points to the first
949 * character in the %string.
953 begin() const _GLIBCXX_NOEXCEPT
954 { return const_iterator(_M_data()); }
957 * Returns a read/write iterator that points one past the last
958 * character in the %string.
962 end() _GLIBCXX_NOEXCEPT
963 { return iterator(_M_data() + this->size()); }
966 * Returns a read-only (constant) iterator that points one past the
967 * last character in the %string.
971 end() const _GLIBCXX_NOEXCEPT
972 { return const_iterator(_M_data() + this->size()); }
975 * Returns a read/write reverse iterator that points to the last
976 * character in the %string. Iteration is done in reverse element
981 rbegin() _GLIBCXX_NOEXCEPT
982 { return reverse_iterator(this->end()); }
985 * Returns a read-only (constant) reverse iterator that points
986 * to the last character in the %string. Iteration is done in
987 * reverse element order.
990 const_reverse_iterator
991 rbegin() const _GLIBCXX_NOEXCEPT
992 { return const_reverse_iterator(this->end()); }
995 * Returns a read/write reverse iterator that points to one before the
996 * first character in the %string. Iteration is done in reverse
1001 rend() _GLIBCXX_NOEXCEPT
1002 { return reverse_iterator(this->begin()); }
1005 * Returns a read-only (constant) reverse iterator that points
1006 * to one before the first character in the %string. Iteration
1007 * is done in reverse element order.
1009 _GLIBCXX20_CONSTEXPR
1010 const_reverse_iterator
1011 rend() const _GLIBCXX_NOEXCEPT
1012 { return const_reverse_iterator(this->begin()); }
1014 #if __cplusplus >= 201103L
1016 * Returns a read-only (constant) iterator that points to the first
1017 * character in the %string.
1019 _GLIBCXX20_CONSTEXPR
1021 cbegin() const noexcept
1022 { return const_iterator(this->_M_data()); }
1025 * Returns a read-only (constant) iterator that points one past the
1026 * last character in the %string.
1028 _GLIBCXX20_CONSTEXPR
1030 cend() const noexcept
1031 { return const_iterator(this->_M_data() + this->size()); }
1034 * Returns a read-only (constant) reverse iterator that points
1035 * to the last character in the %string. Iteration is done in
1036 * reverse element order.
1038 _GLIBCXX20_CONSTEXPR
1039 const_reverse_iterator
1040 crbegin() const noexcept
1041 { return const_reverse_iterator(this->end()); }
1044 * Returns a read-only (constant) reverse iterator that points
1045 * to one before the first character in the %string. Iteration
1046 * is done in reverse element order.
1048 _GLIBCXX20_CONSTEXPR
1049 const_reverse_iterator
1050 crend() const noexcept
1051 { return const_reverse_iterator(this->begin()); }
1056 /// Returns the number of characters in the string, not including any
1057 /// null-termination.
1058 _GLIBCXX20_CONSTEXPR
1060 size() const _GLIBCXX_NOEXCEPT
1061 { return _M_string_length
; }
1063 /// Returns the number of characters in the string, not including any
1064 /// null-termination.
1065 _GLIBCXX20_CONSTEXPR
1067 length() const _GLIBCXX_NOEXCEPT
1068 { return _M_string_length
; }
1070 /// Returns the size() of the largest possible %string.
1071 _GLIBCXX20_CONSTEXPR
1073 max_size() const _GLIBCXX_NOEXCEPT
1074 { return (_Alloc_traits::max_size(_M_get_allocator()) - 1) / 2; }
1077 * @brief Resizes the %string to the specified number of characters.
1078 * @param __n Number of characters the %string should contain.
1079 * @param __c Character to fill any new elements.
1081 * This function will %resize the %string to the specified
1082 * number of characters. If the number is smaller than the
1083 * %string's current size the %string is truncated, otherwise
1084 * the %string is extended and new elements are %set to @a __c.
1086 _GLIBCXX20_CONSTEXPR
1088 resize(size_type __n
, _CharT __c
);
1091 * @brief Resizes the %string to the specified number of characters.
1092 * @param __n Number of characters the %string should contain.
1094 * This function will resize the %string to the specified length. If
1095 * the new size is smaller than the %string's current size the %string
1096 * is truncated, otherwise the %string is extended and new characters
1097 * are default-constructed. For basic types such as char, this means
1098 * setting them to 0.
1100 _GLIBCXX20_CONSTEXPR
1102 resize(size_type __n
)
1103 { this->resize(__n
, _CharT()); }
1105 #if __cplusplus >= 201103L
1106 #pragma GCC diagnostic push
1107 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1108 /// A non-binding request to reduce capacity() to size().
1109 _GLIBCXX20_CONSTEXPR
1111 shrink_to_fit() noexcept
1113 #pragma GCC diagnostic pop
1116 #if __cplusplus > 202002L
1117 #define __cpp_lib_string_resize_and_overwrite 202110L
1118 template<typename _Operation
>
1120 resize_and_overwrite(size_type __n
, _Operation __op
);
1124 * Returns the total number of characters that the %string can hold
1125 * before needing to allocate more memory.
1127 _GLIBCXX20_CONSTEXPR
1129 capacity() const _GLIBCXX_NOEXCEPT
1131 return _M_is_local() ? size_type(_S_local_capacity
)
1132 : _M_allocated_capacity
;
1136 * @brief Attempt to preallocate enough memory for specified number of
1138 * @param __res_arg Number of characters required.
1139 * @throw std::length_error If @a __res_arg exceeds @c max_size().
1141 * This function attempts to reserve enough memory for the
1142 * %string to hold the specified number of characters. If the
1143 * number requested is more than max_size(), length_error is
1146 * The advantage of this function is that if optimal code is a
1147 * necessity and the user can determine the string length that will be
1148 * required, the user can reserve the memory in %advance, and thus
1149 * prevent a possible reallocation of memory and copying of %string
1152 _GLIBCXX20_CONSTEXPR
1154 reserve(size_type __res_arg
);
1157 * Equivalent to shrink_to_fit().
1159 #if __cplusplus > 201703L
1160 [[deprecated("use shrink_to_fit() instead")]]
1162 _GLIBCXX20_CONSTEXPR
1167 * Erases the string, making it empty.
1169 _GLIBCXX20_CONSTEXPR
1171 clear() _GLIBCXX_NOEXCEPT
1172 { _M_set_length(0); }
1175 * Returns true if the %string is empty. Equivalent to
1176 * <code>*this == ""</code>.
1178 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1180 empty() const _GLIBCXX_NOEXCEPT
1181 { return this->size() == 0; }
1185 * @brief Subscript access to the data contained in the %string.
1186 * @param __pos The index of the character to access.
1187 * @return Read-only (constant) reference to the character.
1189 * This operator allows for easy, array-style, data access.
1190 * Note that data access with this operator is unchecked and
1191 * out_of_range lookups are not defined. (For checked lookups
1194 _GLIBCXX20_CONSTEXPR
1196 operator[] (size_type __pos
) const _GLIBCXX_NOEXCEPT
1198 __glibcxx_assert(__pos
<= size());
1199 return _M_data()[__pos
];
1203 * @brief Subscript access to the data contained in the %string.
1204 * @param __pos The index of the character to access.
1205 * @return Read/write reference to the character.
1207 * This operator allows for easy, array-style, data access.
1208 * Note that data access with this operator is unchecked and
1209 * out_of_range lookups are not defined. (For checked lookups
1212 _GLIBCXX20_CONSTEXPR
1214 operator[](size_type __pos
)
1216 // Allow pos == size() both in C++98 mode, as v3 extension,
1217 // and in C++11 mode.
1218 __glibcxx_assert(__pos
<= size());
1219 // In pedantic mode be strict in C++98 mode.
1220 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus
>= 201103L || __pos
< size());
1221 return _M_data()[__pos
];
1225 * @brief Provides access to the data contained in the %string.
1226 * @param __n The index of the character to access.
1227 * @return Read-only (const) reference to the character.
1228 * @throw std::out_of_range If @a n is an invalid index.
1230 * This function provides for safer data access. The parameter is
1231 * first checked that it is in the range of the string. The function
1232 * throws out_of_range if the check fails.
1234 _GLIBCXX20_CONSTEXPR
1236 at(size_type __n
) const
1238 if (__n
>= this->size())
1239 __throw_out_of_range_fmt(__N("basic_string::at: __n "
1240 "(which is %zu) >= this->size() "
1243 return _M_data()[__n
];
1247 * @brief Provides access to the data contained in the %string.
1248 * @param __n The index of the character to access.
1249 * @return Read/write reference to the character.
1250 * @throw std::out_of_range If @a n is an invalid index.
1252 * This function provides for safer data access. The parameter is
1253 * first checked that it is in the range of the string. The function
1254 * throws out_of_range if the check fails.
1256 _GLIBCXX20_CONSTEXPR
1261 __throw_out_of_range_fmt(__N("basic_string::at: __n "
1262 "(which is %zu) >= this->size() "
1265 return _M_data()[__n
];
1268 #if __cplusplus >= 201103L
1270 * Returns a read/write reference to the data at the first
1271 * element of the %string.
1273 _GLIBCXX20_CONSTEXPR
1277 __glibcxx_assert(!empty());
1278 return operator[](0);
1282 * Returns a read-only (constant) reference to the data at the first
1283 * element of the %string.
1285 _GLIBCXX20_CONSTEXPR
1287 front() const noexcept
1289 __glibcxx_assert(!empty());
1290 return operator[](0);
1294 * Returns a read/write reference to the data at the last
1295 * element of the %string.
1297 _GLIBCXX20_CONSTEXPR
1301 __glibcxx_assert(!empty());
1302 return operator[](this->size() - 1);
1306 * Returns a read-only (constant) reference to the data at the
1307 * last element of the %string.
1309 _GLIBCXX20_CONSTEXPR
1311 back() const noexcept
1313 __glibcxx_assert(!empty());
1314 return operator[](this->size() - 1);
1320 * @brief Append a string to this string.
1321 * @param __str The string to append.
1322 * @return Reference to this string.
1324 _GLIBCXX20_CONSTEXPR
1326 operator+=(const basic_string
& __str
)
1327 { return this->append(__str
); }
1330 * @brief Append a C string.
1331 * @param __s The C string to append.
1332 * @return Reference to this string.
1334 _GLIBCXX20_CONSTEXPR
1336 operator+=(const _CharT
* __s
)
1337 { return this->append(__s
); }
1340 * @brief Append a character.
1341 * @param __c The character to append.
1342 * @return Reference to this string.
1344 _GLIBCXX20_CONSTEXPR
1346 operator+=(_CharT __c
)
1348 this->push_back(__c
);
1352 #if __cplusplus >= 201103L
1354 * @brief Append an initializer_list of characters.
1355 * @param __l The initializer_list of characters to be appended.
1356 * @return Reference to this string.
1358 _GLIBCXX20_CONSTEXPR
1360 operator+=(initializer_list
<_CharT
> __l
)
1361 { return this->append(__l
.begin(), __l
.size()); }
1364 #if __cplusplus >= 201703L
1366 * @brief Append a string_view.
1367 * @param __svt An object convertible to string_view to be appended.
1368 * @return Reference to this string.
1370 template<typename _Tp
>
1371 _GLIBCXX20_CONSTEXPR
1372 _If_sv
<_Tp
, basic_string
&>
1373 operator+=(const _Tp
& __svt
)
1374 { return this->append(__svt
); }
1378 * @brief Append a string to this string.
1379 * @param __str The string to append.
1380 * @return Reference to this string.
1382 _GLIBCXX20_CONSTEXPR
1384 append(const basic_string
& __str
)
1385 { return this->append(__str
._M_data(), __str
.size()); }
1388 * @brief Append a substring.
1389 * @param __str The string to append.
1390 * @param __pos Index of the first character of str to append.
1391 * @param __n The number of characters to append.
1392 * @return Reference to this string.
1393 * @throw std::out_of_range if @a __pos is not a valid index.
1395 * This function appends @a __n characters from @a __str
1396 * starting at @a __pos to this string. If @a __n is is larger
1397 * than the number of available characters in @a __str, the
1398 * remainder of @a __str is appended.
1400 _GLIBCXX20_CONSTEXPR
1402 append(const basic_string
& __str
, size_type __pos
, size_type __n
= npos
)
1403 { return this->append(__str
._M_data()
1404 + __str
._M_check(__pos
, "basic_string::append"),
1405 __str
._M_limit(__pos
, __n
)); }
1408 * @brief Append a C substring.
1409 * @param __s The C string to append.
1410 * @param __n The number of characters to append.
1411 * @return Reference to this string.
1413 _GLIBCXX20_CONSTEXPR
1415 append(const _CharT
* __s
, size_type __n
)
1417 __glibcxx_requires_string_len(__s
, __n
);
1418 _M_check_length(size_type(0), __n
, "basic_string::append");
1419 return _M_append(__s
, __n
);
1423 * @brief Append a C string.
1424 * @param __s The C string to append.
1425 * @return Reference to this string.
1427 _GLIBCXX20_CONSTEXPR
1429 append(const _CharT
* __s
)
1431 __glibcxx_requires_string(__s
);
1432 const size_type __n
= traits_type::length(__s
);
1433 _M_check_length(size_type(0), __n
, "basic_string::append");
1434 return _M_append(__s
, __n
);
1438 * @brief Append multiple characters.
1439 * @param __n The number of characters to append.
1440 * @param __c The character to use.
1441 * @return Reference to this string.
1443 * Appends __n copies of __c to this string.
1445 _GLIBCXX20_CONSTEXPR
1447 append(size_type __n
, _CharT __c
)
1448 { return _M_replace_aux(this->size(), size_type(0), __n
, __c
); }
1450 #if __cplusplus >= 201103L
1452 * @brief Append an initializer_list of characters.
1453 * @param __l The initializer_list of characters to append.
1454 * @return Reference to this string.
1456 _GLIBCXX20_CONSTEXPR
1458 append(initializer_list
<_CharT
> __l
)
1459 { return this->append(__l
.begin(), __l
.size()); }
1463 * @brief Append a range of characters.
1464 * @param __first Iterator referencing the first character to append.
1465 * @param __last Iterator marking the end of the range.
1466 * @return Reference to this string.
1468 * Appends characters in the range [__first,__last) to this string.
1470 #if __cplusplus >= 201103L
1471 template<class _InputIterator
,
1472 typename
= std::_RequireInputIter
<_InputIterator
>>
1473 _GLIBCXX20_CONSTEXPR
1475 template<class _InputIterator
>
1478 append(_InputIterator __first
, _InputIterator __last
)
1479 { return this->replace(end(), end(), __first
, __last
); }
1481 #if __cplusplus >= 201703L
1483 * @brief Append a string_view.
1484 * @param __svt An object convertible to string_view to be appended.
1485 * @return Reference to this string.
1487 template<typename _Tp
>
1488 _GLIBCXX20_CONSTEXPR
1489 _If_sv
<_Tp
, basic_string
&>
1490 append(const _Tp
& __svt
)
1492 __sv_type __sv
= __svt
;
1493 return this->append(__sv
.data(), __sv
.size());
1497 * @brief Append a range of characters from a string_view.
1498 * @param __svt An object convertible to string_view to be appended from.
1499 * @param __pos The position in the string_view to append from.
1500 * @param __n The number of characters to append from the string_view.
1501 * @return Reference to this string.
1503 template<typename _Tp
>
1504 _GLIBCXX20_CONSTEXPR
1505 _If_sv
<_Tp
, basic_string
&>
1506 append(const _Tp
& __svt
, size_type __pos
, size_type __n
= npos
)
1508 __sv_type __sv
= __svt
;
1509 return _M_append(__sv
.data()
1510 + std::__sv_check(__sv
.size(), __pos
, "basic_string::append"),
1511 std::__sv_limit(__sv
.size(), __pos
, __n
));
1516 * @brief Append a single character.
1517 * @param __c Character to append.
1519 _GLIBCXX20_CONSTEXPR
1521 push_back(_CharT __c
)
1523 const size_type __size
= this->size();
1524 if (__size
+ 1 > this->capacity())
1525 this->_M_mutate(__size
, size_type(0), 0, size_type(1));
1526 traits_type::assign(this->_M_data()[__size
], __c
);
1527 this->_M_set_length(__size
+ 1);
1531 * @brief Set value to contents of another string.
1532 * @param __str Source string to use.
1533 * @return Reference to this string.
1535 _GLIBCXX20_CONSTEXPR
1537 assign(const basic_string
& __str
)
1539 #if __cplusplus >= 201103L
1540 if (_Alloc_traits::_S_propagate_on_copy_assign())
1542 if (!_Alloc_traits::_S_always_equal() && !_M_is_local()
1543 && _M_get_allocator() != __str
._M_get_allocator())
1545 // Propagating allocator cannot free existing storage so must
1546 // deallocate it before replacing current allocator.
1547 if (__str
.size() <= _S_local_capacity
)
1549 _M_destroy(_M_allocated_capacity
);
1550 _M_data(_M_use_local_data());
1555 const auto __len
= __str
.size();
1556 auto __alloc
= __str
._M_get_allocator();
1557 // If this allocation throws there are no effects:
1558 auto __ptr
= _Alloc_traits::allocate(__alloc
, __len
+ 1);
1559 _M_destroy(_M_allocated_capacity
);
1562 _M_set_length(__len
);
1565 std::__alloc_on_copy(_M_get_allocator(), __str
._M_get_allocator());
1568 this->_M_assign(__str
);
1572 #if __cplusplus >= 201103L
1574 * @brief Set value to contents of another string.
1575 * @param __str Source string to use.
1576 * @return Reference to this string.
1578 * This function sets this string to the exact contents of @a __str.
1579 * @a __str is a valid, but unspecified string.
1581 _GLIBCXX20_CONSTEXPR
1583 assign(basic_string
&& __str
)
1584 noexcept(_Alloc_traits::_S_nothrow_move())
1586 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1587 // 2063. Contradictory requirements for string move assignment
1588 return *this = std::move(__str
);
1593 * @brief Set value to a substring of a string.
1594 * @param __str The string to use.
1595 * @param __pos Index of the first character of str.
1596 * @param __n Number of characters to use.
1597 * @return Reference to this string.
1598 * @throw std::out_of_range if @a pos is not a valid index.
1600 * This function sets this string to the substring of @a __str
1601 * consisting of @a __n characters at @a __pos. If @a __n is
1602 * is larger than the number of available characters in @a
1603 * __str, the remainder of @a __str is used.
1605 _GLIBCXX20_CONSTEXPR
1607 assign(const basic_string
& __str
, size_type __pos
, size_type __n
= npos
)
1608 { return _M_replace(size_type(0), this->size(), __str
._M_data()
1609 + __str
._M_check(__pos
, "basic_string::assign"),
1610 __str
._M_limit(__pos
, __n
)); }
1613 * @brief Set value to a C substring.
1614 * @param __s The C string to use.
1615 * @param __n Number of characters to use.
1616 * @return Reference to this string.
1618 * This function sets the value of this string to the first @a __n
1619 * characters of @a __s. If @a __n is is larger than the number of
1620 * available characters in @a __s, the remainder of @a __s is used.
1622 _GLIBCXX20_CONSTEXPR
1624 assign(const _CharT
* __s
, size_type __n
)
1626 __glibcxx_requires_string_len(__s
, __n
);
1627 return _M_replace(size_type(0), this->size(), __s
, __n
);
1631 * @brief Set value to contents of a C string.
1632 * @param __s The C string to use.
1633 * @return Reference to this string.
1635 * This function sets the value of this string to the value of @a __s.
1636 * The data is copied, so there is no dependence on @a __s once the
1639 _GLIBCXX20_CONSTEXPR
1641 assign(const _CharT
* __s
)
1643 __glibcxx_requires_string(__s
);
1644 return _M_replace(size_type(0), this->size(), __s
,
1645 traits_type::length(__s
));
1649 * @brief Set value to multiple characters.
1650 * @param __n Length of the resulting string.
1651 * @param __c The character to use.
1652 * @return Reference to this string.
1654 * This function sets the value of this string to @a __n copies of
1657 _GLIBCXX20_CONSTEXPR
1659 assign(size_type __n
, _CharT __c
)
1660 { return _M_replace_aux(size_type(0), this->size(), __n
, __c
); }
1663 * @brief Set value to a range of characters.
1664 * @param __first Iterator referencing the first character to append.
1665 * @param __last Iterator marking the end of the range.
1666 * @return Reference to this string.
1668 * Sets value of string to characters in the range [__first,__last).
1670 #if __cplusplus >= 201103L
1671 template<class _InputIterator
,
1672 typename
= std::_RequireInputIter
<_InputIterator
>>
1673 _GLIBCXX20_CONSTEXPR
1675 template<class _InputIterator
>
1678 assign(_InputIterator __first
, _InputIterator __last
)
1679 { return this->replace(begin(), end(), __first
, __last
); }
1681 #if __cplusplus >= 201103L
1683 * @brief Set value to an initializer_list of characters.
1684 * @param __l The initializer_list of characters to assign.
1685 * @return Reference to this string.
1687 _GLIBCXX20_CONSTEXPR
1689 assign(initializer_list
<_CharT
> __l
)
1690 { return this->assign(__l
.begin(), __l
.size()); }
1693 #if __cplusplus >= 201703L
1695 * @brief Set value from a string_view.
1696 * @param __svt The source object convertible to string_view.
1697 * @return Reference to this string.
1699 template<typename _Tp
>
1700 _GLIBCXX20_CONSTEXPR
1701 _If_sv
<_Tp
, basic_string
&>
1702 assign(const _Tp
& __svt
)
1704 __sv_type __sv
= __svt
;
1705 return this->assign(__sv
.data(), __sv
.size());
1709 * @brief Set value from a range of characters in a string_view.
1710 * @param __svt The source object convertible to string_view.
1711 * @param __pos The position in the string_view to assign from.
1712 * @param __n The number of characters to assign.
1713 * @return Reference to this string.
1715 template<typename _Tp
>
1716 _GLIBCXX20_CONSTEXPR
1717 _If_sv
<_Tp
, basic_string
&>
1718 assign(const _Tp
& __svt
, size_type __pos
, size_type __n
= npos
)
1720 __sv_type __sv
= __svt
;
1721 return _M_replace(size_type(0), this->size(),
1723 + std::__sv_check(__sv
.size(), __pos
, "basic_string::assign"),
1724 std::__sv_limit(__sv
.size(), __pos
, __n
));
1728 #if __cplusplus >= 201103L
1730 * @brief Insert multiple characters.
1731 * @param __p Const_iterator referencing location in string to
1733 * @param __n Number of characters to insert
1734 * @param __c The character to insert.
1735 * @return Iterator referencing the first inserted char.
1736 * @throw std::length_error If new length exceeds @c max_size().
1738 * Inserts @a __n copies of character @a __c starting at the
1739 * position referenced by iterator @a __p. If adding
1740 * characters causes the length to exceed max_size(),
1741 * length_error is thrown. The value of the string doesn't
1742 * change if an error is thrown.
1744 _GLIBCXX20_CONSTEXPR
1746 insert(const_iterator __p
, size_type __n
, _CharT __c
)
1748 _GLIBCXX_DEBUG_PEDASSERT(__p
>= begin() && __p
<= end());
1749 const size_type __pos
= __p
- begin();
1750 this->replace(__p
, __p
, __n
, __c
);
1751 return iterator(this->_M_data() + __pos
);
1755 * @brief Insert multiple characters.
1756 * @param __p Iterator referencing location in string to insert at.
1757 * @param __n Number of characters to insert
1758 * @param __c The character to insert.
1759 * @throw std::length_error If new length exceeds @c max_size().
1761 * Inserts @a __n copies of character @a __c starting at the
1762 * position referenced by iterator @a __p. If adding
1763 * characters causes the length to exceed max_size(),
1764 * length_error is thrown. The value of the string doesn't
1765 * change if an error is thrown.
1768 insert(iterator __p
, size_type __n
, _CharT __c
)
1769 { this->replace(__p
, __p
, __n
, __c
); }
1772 #if __cplusplus >= 201103L
1774 * @brief Insert a range of characters.
1775 * @param __p Const_iterator referencing location in string to
1777 * @param __beg Start of range.
1778 * @param __end End of range.
1779 * @return Iterator referencing the first inserted char.
1780 * @throw std::length_error If new length exceeds @c max_size().
1782 * Inserts characters in range [beg,end). If adding characters
1783 * causes the length to exceed max_size(), length_error is
1784 * thrown. The value of the string doesn't change if an error
1787 template<class _InputIterator
,
1788 typename
= std::_RequireInputIter
<_InputIterator
>>
1789 _GLIBCXX20_CONSTEXPR
1791 insert(const_iterator __p
, _InputIterator __beg
, _InputIterator __end
)
1793 _GLIBCXX_DEBUG_PEDASSERT(__p
>= begin() && __p
<= end());
1794 const size_type __pos
= __p
- begin();
1795 this->replace(__p
, __p
, __beg
, __end
);
1796 return iterator(this->_M_data() + __pos
);
1800 * @brief Insert a range of characters.
1801 * @param __p Iterator referencing location in string to insert at.
1802 * @param __beg Start of range.
1803 * @param __end End of range.
1804 * @throw std::length_error If new length exceeds @c max_size().
1806 * Inserts characters in range [__beg,__end). If adding
1807 * characters causes the length to exceed max_size(),
1808 * length_error is thrown. The value of the string doesn't
1809 * change if an error is thrown.
1811 template<class _InputIterator
>
1813 insert(iterator __p
, _InputIterator __beg
, _InputIterator __end
)
1814 { this->replace(__p
, __p
, __beg
, __end
); }
1817 #if __cplusplus >= 201103L
1819 * @brief Insert an initializer_list of characters.
1820 * @param __p Iterator referencing location in string to insert at.
1821 * @param __l The initializer_list of characters to insert.
1822 * @throw std::length_error If new length exceeds @c max_size().
1824 _GLIBCXX20_CONSTEXPR
1826 insert(const_iterator __p
, initializer_list
<_CharT
> __l
)
1827 { return this->insert(__p
, __l
.begin(), __l
.end()); }
1829 #ifdef _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
1830 // See PR libstdc++/83328
1832 insert(iterator __p
, initializer_list
<_CharT
> __l
)
1834 _GLIBCXX_DEBUG_PEDASSERT(__p
>= begin() && __p
<= end());
1835 this->insert(__p
- begin(), __l
.begin(), __l
.size());
1841 * @brief Insert value of a string.
1842 * @param __pos1 Position in string to insert at.
1843 * @param __str The string to insert.
1844 * @return Reference to this string.
1845 * @throw std::length_error If new length exceeds @c max_size().
1847 * Inserts value of @a __str starting at @a __pos1. If adding
1848 * characters causes the length to exceed max_size(),
1849 * length_error is thrown. The value of the string doesn't
1850 * change if an error is thrown.
1852 _GLIBCXX20_CONSTEXPR
1854 insert(size_type __pos1
, const basic_string
& __str
)
1855 { return this->replace(__pos1
, size_type(0),
1856 __str
._M_data(), __str
.size()); }
1859 * @brief Insert a substring.
1860 * @param __pos1 Position in string to insert at.
1861 * @param __str The string to insert.
1862 * @param __pos2 Start of characters in str to insert.
1863 * @param __n Number of characters to insert.
1864 * @return Reference to this string.
1865 * @throw std::length_error If new length exceeds @c max_size().
1866 * @throw std::out_of_range If @a pos1 > size() or
1867 * @a __pos2 > @a str.size().
1869 * Starting at @a pos1, insert @a __n character of @a __str
1870 * beginning with @a __pos2. If adding characters causes the
1871 * length to exceed max_size(), length_error is thrown. If @a
1872 * __pos1 is beyond the end of this string or @a __pos2 is
1873 * beyond the end of @a __str, out_of_range is thrown. The
1874 * value of the string doesn't change if an error is thrown.
1876 _GLIBCXX20_CONSTEXPR
1878 insert(size_type __pos1
, const basic_string
& __str
,
1879 size_type __pos2
, size_type __n
= npos
)
1880 { return this->replace(__pos1
, size_type(0), __str
._M_data()
1881 + __str
._M_check(__pos2
, "basic_string::insert"),
1882 __str
._M_limit(__pos2
, __n
)); }
1885 * @brief Insert a C substring.
1886 * @param __pos Position in string to insert at.
1887 * @param __s The C string to insert.
1888 * @param __n The number of characters to insert.
1889 * @return Reference to this string.
1890 * @throw std::length_error If new length exceeds @c max_size().
1891 * @throw std::out_of_range If @a __pos is beyond the end of this
1894 * Inserts the first @a __n characters of @a __s starting at @a
1895 * __pos. If adding characters causes the length to exceed
1896 * max_size(), length_error is thrown. If @a __pos is beyond
1897 * end(), out_of_range is thrown. The value of the string
1898 * doesn't change if an error is thrown.
1900 _GLIBCXX20_CONSTEXPR
1902 insert(size_type __pos
, const _CharT
* __s
, size_type __n
)
1903 { return this->replace(__pos
, size_type(0), __s
, __n
); }
1906 * @brief Insert a C string.
1907 * @param __pos Position in string to insert at.
1908 * @param __s The C string to insert.
1909 * @return Reference to this string.
1910 * @throw std::length_error If new length exceeds @c max_size().
1911 * @throw std::out_of_range If @a pos is beyond the end of this
1914 * Inserts the first @a n characters of @a __s starting at @a __pos. If
1915 * adding characters causes the length to exceed max_size(),
1916 * length_error is thrown. If @a __pos is beyond end(), out_of_range is
1917 * thrown. The value of the string doesn't change if an error is
1920 _GLIBCXX20_CONSTEXPR
1922 insert(size_type __pos
, const _CharT
* __s
)
1924 __glibcxx_requires_string(__s
);
1925 return this->replace(__pos
, size_type(0), __s
,
1926 traits_type::length(__s
));
1930 * @brief Insert multiple characters.
1931 * @param __pos Index in string to insert at.
1932 * @param __n Number of characters to insert
1933 * @param __c The character to insert.
1934 * @return Reference to this string.
1935 * @throw std::length_error If new length exceeds @c max_size().
1936 * @throw std::out_of_range If @a __pos is beyond the end of this
1939 * Inserts @a __n copies of character @a __c starting at index
1940 * @a __pos. If adding characters causes the length to exceed
1941 * max_size(), length_error is thrown. If @a __pos > length(),
1942 * out_of_range is thrown. The value of the string doesn't
1943 * change if an error is thrown.
1945 _GLIBCXX20_CONSTEXPR
1947 insert(size_type __pos
, size_type __n
, _CharT __c
)
1948 { return _M_replace_aux(_M_check(__pos
, "basic_string::insert"),
1949 size_type(0), __n
, __c
); }
1952 * @brief Insert one character.
1953 * @param __p Iterator referencing position in string to insert at.
1954 * @param __c The character to insert.
1955 * @return Iterator referencing newly inserted char.
1956 * @throw std::length_error If new length exceeds @c max_size().
1958 * Inserts character @a __c at position referenced by @a __p.
1959 * If adding character causes the length to exceed max_size(),
1960 * length_error is thrown. If @a __p is beyond end of string,
1961 * out_of_range is thrown. The value of the string doesn't
1962 * change if an error is thrown.
1964 _GLIBCXX20_CONSTEXPR
1966 insert(__const_iterator __p
, _CharT __c
)
1968 _GLIBCXX_DEBUG_PEDASSERT(__p
>= begin() && __p
<= end());
1969 const size_type __pos
= __p
- begin();
1970 _M_replace_aux(__pos
, size_type(0), size_type(1), __c
);
1971 return iterator(_M_data() + __pos
);
1974 #if __cplusplus >= 201703L
1976 * @brief Insert a string_view.
1977 * @param __pos Position in string to insert at.
1978 * @param __svt The object convertible to string_view to insert.
1979 * @return Reference to this string.
1981 template<typename _Tp
>
1982 _GLIBCXX20_CONSTEXPR
1983 _If_sv
<_Tp
, basic_string
&>
1984 insert(size_type __pos
, const _Tp
& __svt
)
1986 __sv_type __sv
= __svt
;
1987 return this->insert(__pos
, __sv
.data(), __sv
.size());
1991 * @brief Insert a string_view.
1992 * @param __pos1 Position in string to insert at.
1993 * @param __svt The object convertible to string_view to insert from.
1994 * @param __pos2 Start of characters in str to insert.
1995 * @param __n The number of characters to insert.
1996 * @return Reference to this string.
1998 template<typename _Tp
>
1999 _GLIBCXX20_CONSTEXPR
2000 _If_sv
<_Tp
, basic_string
&>
2001 insert(size_type __pos1
, const _Tp
& __svt
,
2002 size_type __pos2
, size_type __n
= npos
)
2004 __sv_type __sv
= __svt
;
2005 return this->replace(__pos1
, size_type(0),
2007 + std::__sv_check(__sv
.size(), __pos2
, "basic_string::insert"),
2008 std::__sv_limit(__sv
.size(), __pos2
, __n
));
2013 * @brief Remove characters.
2014 * @param __pos Index of first character to remove (default 0).
2015 * @param __n Number of characters to remove (default remainder).
2016 * @return Reference to this string.
2017 * @throw std::out_of_range If @a pos is beyond the end of this
2020 * Removes @a __n characters from this string starting at @a
2021 * __pos. The length of the string is reduced by @a __n. If
2022 * there are < @a __n characters to remove, the remainder of
2023 * the string is truncated. If @a __p is beyond end of string,
2024 * out_of_range is thrown. The value of the string doesn't
2025 * change if an error is thrown.
2027 _GLIBCXX20_CONSTEXPR
2029 erase(size_type __pos
= 0, size_type __n
= npos
)
2031 _M_check(__pos
, "basic_string::erase");
2033 this->_M_set_length(__pos
);
2035 this->_M_erase(__pos
, _M_limit(__pos
, __n
));
2040 * @brief Remove one character.
2041 * @param __position Iterator referencing the character to remove.
2042 * @return iterator referencing same location after removal.
2044 * Removes the character at @a __position from this string. The value
2045 * of the string doesn't change if an error is thrown.
2047 _GLIBCXX20_CONSTEXPR
2049 erase(__const_iterator __position
)
2051 _GLIBCXX_DEBUG_PEDASSERT(__position
>= begin()
2052 && __position
< end());
2053 const size_type __pos
= __position
- begin();
2054 this->_M_erase(__pos
, size_type(1));
2055 return iterator(_M_data() + __pos
);
2059 * @brief Remove a range of characters.
2060 * @param __first Iterator referencing the first character to remove.
2061 * @param __last Iterator referencing the end of the range.
2062 * @return Iterator referencing location of first after removal.
2064 * Removes the characters in the range [first,last) from this string.
2065 * The value of the string doesn't change if an error is thrown.
2067 _GLIBCXX20_CONSTEXPR
2069 erase(__const_iterator __first
, __const_iterator __last
)
2071 _GLIBCXX_DEBUG_PEDASSERT(__first
>= begin() && __first
<= __last
2072 && __last
<= end());
2073 const size_type __pos
= __first
- begin();
2074 if (__last
== end())
2075 this->_M_set_length(__pos
);
2077 this->_M_erase(__pos
, __last
- __first
);
2078 return iterator(this->_M_data() + __pos
);
2081 #if __cplusplus >= 201103L
2083 * @brief Remove the last character.
2085 * The string must be non-empty.
2087 _GLIBCXX20_CONSTEXPR
2091 __glibcxx_assert(!empty());
2092 _M_erase(size() - 1, 1);
2097 * @brief Replace characters with value from another string.
2098 * @param __pos Index of first character to replace.
2099 * @param __n Number of characters to be replaced.
2100 * @param __str String to insert.
2101 * @return Reference to this string.
2102 * @throw std::out_of_range If @a pos is beyond the end of this
2104 * @throw std::length_error If new length exceeds @c max_size().
2106 * Removes the characters in the range [__pos,__pos+__n) from
2107 * this string. In place, the value of @a __str is inserted.
2108 * If @a __pos is beyond end of string, out_of_range is thrown.
2109 * If the length of the result exceeds max_size(), length_error
2110 * is thrown. The value of the string doesn't change if an
2113 _GLIBCXX20_CONSTEXPR
2115 replace(size_type __pos
, size_type __n
, const basic_string
& __str
)
2116 { return this->replace(__pos
, __n
, __str
._M_data(), __str
.size()); }
2119 * @brief Replace characters with value from another string.
2120 * @param __pos1 Index of first character to replace.
2121 * @param __n1 Number of characters to be replaced.
2122 * @param __str String to insert.
2123 * @param __pos2 Index of first character of str to use.
2124 * @param __n2 Number of characters from str to use.
2125 * @return Reference to this string.
2126 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
2128 * @throw std::length_error If new length exceeds @c max_size().
2130 * Removes the characters in the range [__pos1,__pos1 + n) from this
2131 * string. In place, the value of @a __str is inserted. If @a __pos is
2132 * beyond end of string, out_of_range is thrown. If the length of the
2133 * result exceeds max_size(), length_error is thrown. The value of the
2134 * string doesn't change if an error is thrown.
2136 _GLIBCXX20_CONSTEXPR
2138 replace(size_type __pos1
, size_type __n1
, const basic_string
& __str
,
2139 size_type __pos2
, size_type __n2
= npos
)
2140 { return this->replace(__pos1
, __n1
, __str
._M_data()
2141 + __str
._M_check(__pos2
, "basic_string::replace"),
2142 __str
._M_limit(__pos2
, __n2
)); }
2145 * @brief Replace characters with value of a C substring.
2146 * @param __pos Index of first character to replace.
2147 * @param __n1 Number of characters to be replaced.
2148 * @param __s C string to insert.
2149 * @param __n2 Number of characters from @a s to use.
2150 * @return Reference to this string.
2151 * @throw std::out_of_range If @a pos1 > size().
2152 * @throw std::length_error If new length exceeds @c max_size().
2154 * Removes the characters in the range [__pos,__pos + __n1)
2155 * from this string. In place, the first @a __n2 characters of
2156 * @a __s are inserted, or all of @a __s if @a __n2 is too large. If
2157 * @a __pos is beyond end of string, out_of_range is thrown. If
2158 * the length of result exceeds max_size(), length_error is
2159 * thrown. The value of the string doesn't change if an error
2162 _GLIBCXX20_CONSTEXPR
2164 replace(size_type __pos
, size_type __n1
, const _CharT
* __s
,
2167 __glibcxx_requires_string_len(__s
, __n2
);
2168 return _M_replace(_M_check(__pos
, "basic_string::replace"),
2169 _M_limit(__pos
, __n1
), __s
, __n2
);
2173 * @brief Replace characters with value of a C string.
2174 * @param __pos Index of first character to replace.
2175 * @param __n1 Number of characters to be replaced.
2176 * @param __s C string to insert.
2177 * @return Reference to this string.
2178 * @throw std::out_of_range If @a pos > size().
2179 * @throw std::length_error If new length exceeds @c max_size().
2181 * Removes the characters in the range [__pos,__pos + __n1)
2182 * from this string. In place, the characters of @a __s are
2183 * inserted. If @a __pos is beyond end of string, out_of_range
2184 * is thrown. If the length of result exceeds max_size(),
2185 * length_error is thrown. The value of the string doesn't
2186 * change if an error is thrown.
2188 _GLIBCXX20_CONSTEXPR
2190 replace(size_type __pos
, size_type __n1
, const _CharT
* __s
)
2192 __glibcxx_requires_string(__s
);
2193 return this->replace(__pos
, __n1
, __s
, traits_type::length(__s
));
2197 * @brief Replace characters with multiple characters.
2198 * @param __pos Index of first character to replace.
2199 * @param __n1 Number of characters to be replaced.
2200 * @param __n2 Number of characters to insert.
2201 * @param __c Character to insert.
2202 * @return Reference to this string.
2203 * @throw std::out_of_range If @a __pos > size().
2204 * @throw std::length_error If new length exceeds @c max_size().
2206 * Removes the characters in the range [pos,pos + n1) from this
2207 * string. In place, @a __n2 copies of @a __c are inserted.
2208 * If @a __pos is beyond end of string, out_of_range is thrown.
2209 * If the length of result exceeds max_size(), length_error is
2210 * thrown. The value of the string doesn't change if an error
2213 _GLIBCXX20_CONSTEXPR
2215 replace(size_type __pos
, size_type __n1
, size_type __n2
, _CharT __c
)
2216 { return _M_replace_aux(_M_check(__pos
, "basic_string::replace"),
2217 _M_limit(__pos
, __n1
), __n2
, __c
); }
2220 * @brief Replace range of characters with string.
2221 * @param __i1 Iterator referencing start of range to replace.
2222 * @param __i2 Iterator referencing end of range to replace.
2223 * @param __str String value to insert.
2224 * @return Reference to this string.
2225 * @throw std::length_error If new length exceeds @c max_size().
2227 * Removes the characters in the range [__i1,__i2). In place,
2228 * the value of @a __str is inserted. If the length of result
2229 * exceeds max_size(), length_error is thrown. The value of
2230 * the string doesn't change if an error is thrown.
2232 _GLIBCXX20_CONSTEXPR
2234 replace(__const_iterator __i1
, __const_iterator __i2
,
2235 const basic_string
& __str
)
2236 { return this->replace(__i1
, __i2
, __str
._M_data(), __str
.size()); }
2239 * @brief Replace range of characters with C substring.
2240 * @param __i1 Iterator referencing start of range to replace.
2241 * @param __i2 Iterator referencing end of range to replace.
2242 * @param __s C string value to insert.
2243 * @param __n Number of characters from s to insert.
2244 * @return Reference to this string.
2245 * @throw std::length_error If new length exceeds @c max_size().
2247 * Removes the characters in the range [__i1,__i2). In place,
2248 * the first @a __n characters of @a __s are inserted. If the
2249 * length of result exceeds max_size(), length_error is thrown.
2250 * The value of the string doesn't change if an error is
2253 _GLIBCXX20_CONSTEXPR
2255 replace(__const_iterator __i1
, __const_iterator __i2
,
2256 const _CharT
* __s
, size_type __n
)
2258 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
2260 return this->replace(__i1
- begin(), __i2
- __i1
, __s
, __n
);
2264 * @brief Replace range of characters with C string.
2265 * @param __i1 Iterator referencing start of range to replace.
2266 * @param __i2 Iterator referencing end of range to replace.
2267 * @param __s C string value to insert.
2268 * @return Reference to this string.
2269 * @throw std::length_error If new length exceeds @c max_size().
2271 * Removes the characters in the range [__i1,__i2). In place,
2272 * the characters of @a __s are inserted. If the length of
2273 * result exceeds max_size(), length_error is thrown. The
2274 * value of the string doesn't change if an error is thrown.
2276 _GLIBCXX20_CONSTEXPR
2278 replace(__const_iterator __i1
, __const_iterator __i2
, const _CharT
* __s
)
2280 __glibcxx_requires_string(__s
);
2281 return this->replace(__i1
, __i2
, __s
, traits_type::length(__s
));
2285 * @brief Replace range of characters with multiple characters
2286 * @param __i1 Iterator referencing start of range to replace.
2287 * @param __i2 Iterator referencing end of range to replace.
2288 * @param __n Number of characters to insert.
2289 * @param __c Character to insert.
2290 * @return Reference to this string.
2291 * @throw std::length_error If new length exceeds @c max_size().
2293 * Removes the characters in the range [__i1,__i2). In place,
2294 * @a __n copies of @a __c are inserted. If the length of
2295 * result exceeds max_size(), length_error is thrown. The
2296 * value of the string doesn't change if an error is thrown.
2298 _GLIBCXX20_CONSTEXPR
2300 replace(__const_iterator __i1
, __const_iterator __i2
, size_type __n
,
2303 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
2305 return _M_replace_aux(__i1
- begin(), __i2
- __i1
, __n
, __c
);
2309 * @brief Replace range of characters with range.
2310 * @param __i1 Iterator referencing start of range to replace.
2311 * @param __i2 Iterator referencing end of range to replace.
2312 * @param __k1 Iterator referencing start of range to insert.
2313 * @param __k2 Iterator referencing end of range to insert.
2314 * @return Reference to this string.
2315 * @throw std::length_error If new length exceeds @c max_size().
2317 * Removes the characters in the range [__i1,__i2). In place,
2318 * characters in the range [__k1,__k2) are inserted. If the
2319 * length of result exceeds max_size(), length_error is thrown.
2320 * The value of the string doesn't change if an error is
2323 #if __cplusplus >= 201103L
2324 template<class _InputIterator
,
2325 typename
= std::_RequireInputIter
<_InputIterator
>>
2326 _GLIBCXX20_CONSTEXPR
2328 replace(const_iterator __i1
, const_iterator __i2
,
2329 _InputIterator __k1
, _InputIterator __k2
)
2331 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
2333 __glibcxx_requires_valid_range(__k1
, __k2
);
2334 return this->_M_replace_dispatch(__i1
, __i2
, __k1
, __k2
,
2335 std::__false_type());
2338 template<class _InputIterator
>
2339 #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
2340 typename __enable_if_not_native_iterator
<_InputIterator
>::__type
2344 replace(iterator __i1
, iterator __i2
,
2345 _InputIterator __k1
, _InputIterator __k2
)
2347 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
2349 __glibcxx_requires_valid_range(__k1
, __k2
);
2350 typedef typename
std::__is_integer
<_InputIterator
>::__type _Integral
;
2351 return _M_replace_dispatch(__i1
, __i2
, __k1
, __k2
, _Integral());
2355 // Specializations for the common case of pointer and iterator:
2356 // useful to avoid the overhead of temporary buffering in _M_replace.
2357 _GLIBCXX20_CONSTEXPR
2359 replace(__const_iterator __i1
, __const_iterator __i2
,
2360 _CharT
* __k1
, _CharT
* __k2
)
2362 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
2364 __glibcxx_requires_valid_range(__k1
, __k2
);
2365 return this->replace(__i1
- begin(), __i2
- __i1
,
2369 _GLIBCXX20_CONSTEXPR
2371 replace(__const_iterator __i1
, __const_iterator __i2
,
2372 const _CharT
* __k1
, const _CharT
* __k2
)
2374 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
2376 __glibcxx_requires_valid_range(__k1
, __k2
);
2377 return this->replace(__i1
- begin(), __i2
- __i1
,
2381 _GLIBCXX20_CONSTEXPR
2383 replace(__const_iterator __i1
, __const_iterator __i2
,
2384 iterator __k1
, iterator __k2
)
2386 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
2388 __glibcxx_requires_valid_range(__k1
, __k2
);
2389 return this->replace(__i1
- begin(), __i2
- __i1
,
2390 __k1
.base(), __k2
- __k1
);
2393 _GLIBCXX20_CONSTEXPR
2395 replace(__const_iterator __i1
, __const_iterator __i2
,
2396 const_iterator __k1
, const_iterator __k2
)
2398 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
2400 __glibcxx_requires_valid_range(__k1
, __k2
);
2401 return this->replace(__i1
- begin(), __i2
- __i1
,
2402 __k1
.base(), __k2
- __k1
);
2405 #if __cplusplus >= 201103L
2407 * @brief Replace range of characters with initializer_list.
2408 * @param __i1 Iterator referencing start of range to replace.
2409 * @param __i2 Iterator referencing end of range to replace.
2410 * @param __l The initializer_list of characters to insert.
2411 * @return Reference to this string.
2412 * @throw std::length_error If new length exceeds @c max_size().
2414 * Removes the characters in the range [__i1,__i2). In place,
2415 * characters in the range [__k1,__k2) are inserted. If the
2416 * length of result exceeds max_size(), length_error is thrown.
2417 * The value of the string doesn't change if an error is
2420 _GLIBCXX20_CONSTEXPR
2421 basic_string
& replace(const_iterator __i1
, const_iterator __i2
,
2422 initializer_list
<_CharT
> __l
)
2423 { return this->replace(__i1
, __i2
, __l
.begin(), __l
.size()); }
2426 #if __cplusplus >= 201703L
2428 * @brief Replace range of characters with string_view.
2429 * @param __pos The position to replace at.
2430 * @param __n The number of characters to replace.
2431 * @param __svt The object convertible to string_view to insert.
2432 * @return Reference to this string.
2434 template<typename _Tp
>
2435 _GLIBCXX20_CONSTEXPR
2436 _If_sv
<_Tp
, basic_string
&>
2437 replace(size_type __pos
, size_type __n
, const _Tp
& __svt
)
2439 __sv_type __sv
= __svt
;
2440 return this->replace(__pos
, __n
, __sv
.data(), __sv
.size());
2444 * @brief Replace range of characters with string_view.
2445 * @param __pos1 The position to replace at.
2446 * @param __n1 The number of characters to replace.
2447 * @param __svt The object convertible to string_view to insert from.
2448 * @param __pos2 The position in the string_view to insert from.
2449 * @param __n2 The number of characters to insert.
2450 * @return Reference to this string.
2452 template<typename _Tp
>
2453 _GLIBCXX20_CONSTEXPR
2454 _If_sv
<_Tp
, basic_string
&>
2455 replace(size_type __pos1
, size_type __n1
, const _Tp
& __svt
,
2456 size_type __pos2
, size_type __n2
= npos
)
2458 __sv_type __sv
= __svt
;
2459 return this->replace(__pos1
, __n1
,
2461 + std::__sv_check(__sv
.size(), __pos2
, "basic_string::replace"),
2462 std::__sv_limit(__sv
.size(), __pos2
, __n2
));
2466 * @brief Replace range of characters with string_view.
2467 * @param __i1 An iterator referencing the start position
2469 * @param __i2 An iterator referencing the end position
2471 * @param __svt The object convertible to string_view to insert from.
2472 * @return Reference to this string.
2474 template<typename _Tp
>
2475 _GLIBCXX20_CONSTEXPR
2476 _If_sv
<_Tp
, basic_string
&>
2477 replace(const_iterator __i1
, const_iterator __i2
, const _Tp
& __svt
)
2479 __sv_type __sv
= __svt
;
2480 return this->replace(__i1
- begin(), __i2
- __i1
, __sv
);
2485 template<class _Integer
>
2486 _GLIBCXX20_CONSTEXPR
2488 _M_replace_dispatch(const_iterator __i1
, const_iterator __i2
,
2489 _Integer __n
, _Integer __val
, __true_type
)
2490 { return _M_replace_aux(__i1
- begin(), __i2
- __i1
, __n
, __val
); }
2492 template<class _InputIterator
>
2493 _GLIBCXX20_CONSTEXPR
2495 _M_replace_dispatch(const_iterator __i1
, const_iterator __i2
,
2496 _InputIterator __k1
, _InputIterator __k2
,
2499 _GLIBCXX20_CONSTEXPR
2501 _M_replace_aux(size_type __pos1
, size_type __n1
, size_type __n2
,
2504 _GLIBCXX20_CONSTEXPR
2506 _M_replace(size_type __pos
, size_type __len1
, const _CharT
* __s
,
2507 const size_type __len2
);
2509 _GLIBCXX20_CONSTEXPR
2511 _M_append(const _CharT
* __s
, size_type __n
);
2516 * @brief Copy substring into C string.
2517 * @param __s C string to copy value into.
2518 * @param __n Number of characters to copy.
2519 * @param __pos Index of first character to copy.
2520 * @return Number of characters actually copied
2521 * @throw std::out_of_range If __pos > size().
2523 * Copies up to @a __n characters starting at @a __pos into the
2524 * C string @a __s. If @a __pos is %greater than size(),
2525 * out_of_range is thrown.
2527 _GLIBCXX20_CONSTEXPR
2529 copy(_CharT
* __s
, size_type __n
, size_type __pos
= 0) const;
2532 * @brief Swap contents with another string.
2533 * @param __s String to swap with.
2535 * Exchanges the contents of this string with that of @a __s in constant
2538 _GLIBCXX20_CONSTEXPR
2540 swap(basic_string
& __s
) _GLIBCXX_NOEXCEPT
;
2542 // String operations:
2544 * @brief Return const pointer to null-terminated contents.
2546 * This is a handle to internal data. Do not modify or dire things may
2549 _GLIBCXX20_CONSTEXPR
2551 c_str() const _GLIBCXX_NOEXCEPT
2552 { return _M_data(); }
2555 * @brief Return const pointer to contents.
2557 * This is a pointer to internal data. It is undefined to modify
2558 * the contents through the returned pointer. To get a pointer that
2559 * allows modifying the contents use @c &str[0] instead,
2560 * (or in C++17 the non-const @c str.data() overload).
2562 _GLIBCXX20_CONSTEXPR
2564 data() const _GLIBCXX_NOEXCEPT
2565 { return _M_data(); }
2567 #if __cplusplus >= 201703L
2569 * @brief Return non-const pointer to contents.
2571 * This is a pointer to the character sequence held by the string.
2572 * Modifying the characters in the sequence is allowed.
2574 _GLIBCXX20_CONSTEXPR
2577 { return _M_data(); }
2581 * @brief Return copy of allocator used to construct this string.
2583 _GLIBCXX20_CONSTEXPR
2585 get_allocator() const _GLIBCXX_NOEXCEPT
2586 { return _M_get_allocator(); }
2589 * @brief Find position of a C substring.
2590 * @param __s C string to locate.
2591 * @param __pos Index of character to search from.
2592 * @param __n Number of characters from @a s to search for.
2593 * @return Index of start of first occurrence.
2595 * Starting from @a __pos, searches forward for the first @a
2596 * __n characters in @a __s within this string. If found,
2597 * returns the index where it begins. If not found, returns
2600 _GLIBCXX20_CONSTEXPR
2602 find(const _CharT
* __s
, size_type __pos
, size_type __n
) const
2606 * @brief Find position of a string.
2607 * @param __str String to locate.
2608 * @param __pos Index of character to search from (default 0).
2609 * @return Index of start of first occurrence.
2611 * Starting from @a __pos, searches forward for value of @a __str within
2612 * this string. If found, returns the index where it begins. If not
2613 * found, returns npos.
2615 _GLIBCXX20_CONSTEXPR
2617 find(const basic_string
& __str
, size_type __pos
= 0) const
2619 { return this->find(__str
.data(), __pos
, __str
.size()); }
2621 #if __cplusplus >= 201703L
2623 * @brief Find position of a string_view.
2624 * @param __svt The object convertible to string_view to locate.
2625 * @param __pos Index of character to search from (default 0).
2626 * @return Index of start of first occurrence.
2628 template<typename _Tp
>
2629 _GLIBCXX20_CONSTEXPR
2630 _If_sv
<_Tp
, size_type
>
2631 find(const _Tp
& __svt
, size_type __pos
= 0) const
2632 noexcept(is_same
<_Tp
, __sv_type
>::value
)
2634 __sv_type __sv
= __svt
;
2635 return this->find(__sv
.data(), __pos
, __sv
.size());
2640 * @brief Find position of a C string.
2641 * @param __s C string to locate.
2642 * @param __pos Index of character to search from (default 0).
2643 * @return Index of start of first occurrence.
2645 * Starting from @a __pos, searches forward for the value of @a
2646 * __s within this string. If found, returns the index where
2647 * it begins. If not found, returns npos.
2649 _GLIBCXX20_CONSTEXPR
2651 find(const _CharT
* __s
, size_type __pos
= 0) const _GLIBCXX_NOEXCEPT
2653 __glibcxx_requires_string(__s
);
2654 return this->find(__s
, __pos
, traits_type::length(__s
));
2658 * @brief Find position of a character.
2659 * @param __c Character to locate.
2660 * @param __pos Index of character to search from (default 0).
2661 * @return Index of first occurrence.
2663 * Starting from @a __pos, searches forward for @a __c within
2664 * this string. If found, returns the index where it was
2665 * found. If not found, returns npos.
2667 _GLIBCXX20_CONSTEXPR
2669 find(_CharT __c
, size_type __pos
= 0) const _GLIBCXX_NOEXCEPT
;
2672 * @brief Find last position of a string.
2673 * @param __str String to locate.
2674 * @param __pos Index of character to search back from (default end).
2675 * @return Index of start of last occurrence.
2677 * Starting from @a __pos, searches backward for value of @a
2678 * __str within this string. If found, returns the index where
2679 * it begins. If not found, returns npos.
2681 _GLIBCXX20_CONSTEXPR
2683 rfind(const basic_string
& __str
, size_type __pos
= npos
) const
2685 { return this->rfind(__str
.data(), __pos
, __str
.size()); }
2687 #if __cplusplus >= 201703L
2689 * @brief Find last position of a string_view.
2690 * @param __svt The object convertible to string_view to locate.
2691 * @param __pos Index of character to search back from (default end).
2692 * @return Index of start of last occurrence.
2694 template<typename _Tp
>
2695 _GLIBCXX20_CONSTEXPR
2696 _If_sv
<_Tp
, size_type
>
2697 rfind(const _Tp
& __svt
, size_type __pos
= npos
) const
2698 noexcept(is_same
<_Tp
, __sv_type
>::value
)
2700 __sv_type __sv
= __svt
;
2701 return this->rfind(__sv
.data(), __pos
, __sv
.size());
2706 * @brief Find last position of a C substring.
2707 * @param __s C string to locate.
2708 * @param __pos Index of character to search back from.
2709 * @param __n Number of characters from s to search for.
2710 * @return Index of start of last occurrence.
2712 * Starting from @a __pos, searches backward for the first @a
2713 * __n characters in @a __s within this string. If found,
2714 * returns the index where it begins. If not found, returns
2717 _GLIBCXX20_CONSTEXPR
2719 rfind(const _CharT
* __s
, size_type __pos
, size_type __n
) const
2723 * @brief Find last position of a C string.
2724 * @param __s C string to locate.
2725 * @param __pos Index of character to start search at (default end).
2726 * @return Index of start of last occurrence.
2728 * Starting from @a __pos, searches backward for the value of
2729 * @a __s within this string. If found, returns the index
2730 * where it begins. If not found, returns npos.
2732 _GLIBCXX20_CONSTEXPR
2734 rfind(const _CharT
* __s
, size_type __pos
= npos
) const
2736 __glibcxx_requires_string(__s
);
2737 return this->rfind(__s
, __pos
, traits_type::length(__s
));
2741 * @brief Find last position of a character.
2742 * @param __c Character to locate.
2743 * @param __pos Index of character to search back from (default end).
2744 * @return Index of last occurrence.
2746 * Starting from @a __pos, searches backward for @a __c within
2747 * this string. If found, returns the index where it was
2748 * found. If not found, returns npos.
2750 _GLIBCXX20_CONSTEXPR
2752 rfind(_CharT __c
, size_type __pos
= npos
) const _GLIBCXX_NOEXCEPT
;
2755 * @brief Find position of a character of string.
2756 * @param __str String containing characters to locate.
2757 * @param __pos Index of character to search from (default 0).
2758 * @return Index of first occurrence.
2760 * Starting from @a __pos, searches forward for one of the
2761 * characters of @a __str within this string. If found,
2762 * returns the index where it was found. If not found, returns
2765 _GLIBCXX20_CONSTEXPR
2767 find_first_of(const basic_string
& __str
, size_type __pos
= 0) const
2769 { return this->find_first_of(__str
.data(), __pos
, __str
.size()); }
2771 #if __cplusplus >= 201703L
2773 * @brief Find position of a character of a string_view.
2774 * @param __svt An object convertible to string_view containing
2775 * characters to locate.
2776 * @param __pos Index of character to search from (default 0).
2777 * @return Index of first occurrence.
2779 template<typename _Tp
>
2780 _GLIBCXX20_CONSTEXPR
2781 _If_sv
<_Tp
, size_type
>
2782 find_first_of(const _Tp
& __svt
, size_type __pos
= 0) const
2783 noexcept(is_same
<_Tp
, __sv_type
>::value
)
2785 __sv_type __sv
= __svt
;
2786 return this->find_first_of(__sv
.data(), __pos
, __sv
.size());
2791 * @brief Find position of a character of C substring.
2792 * @param __s String containing characters to locate.
2793 * @param __pos Index of character to search from.
2794 * @param __n Number of characters from s to search for.
2795 * @return Index of first occurrence.
2797 * Starting from @a __pos, searches forward for one of the
2798 * first @a __n characters of @a __s within this string. If
2799 * found, returns the index where it was found. If not found,
2802 _GLIBCXX20_CONSTEXPR
2804 find_first_of(const _CharT
* __s
, size_type __pos
, size_type __n
) const
2808 * @brief Find position of a character of C string.
2809 * @param __s String containing characters to locate.
2810 * @param __pos Index of character to search from (default 0).
2811 * @return Index of first occurrence.
2813 * Starting from @a __pos, searches forward for one of the
2814 * characters of @a __s within this string. If found, returns
2815 * the index where it was found. If not found, returns npos.
2817 _GLIBCXX20_CONSTEXPR
2819 find_first_of(const _CharT
* __s
, size_type __pos
= 0) const
2822 __glibcxx_requires_string(__s
);
2823 return this->find_first_of(__s
, __pos
, traits_type::length(__s
));
2827 * @brief Find position of a character.
2828 * @param __c Character to locate.
2829 * @param __pos Index of character to search from (default 0).
2830 * @return Index of first occurrence.
2832 * Starting from @a __pos, searches forward for the character
2833 * @a __c within this string. If found, returns the index
2834 * where it was found. If not found, returns npos.
2836 * Note: equivalent to find(__c, __pos).
2838 _GLIBCXX20_CONSTEXPR
2840 find_first_of(_CharT __c
, size_type __pos
= 0) const _GLIBCXX_NOEXCEPT
2841 { return this->find(__c
, __pos
); }
2844 * @brief Find last position of a character of string.
2845 * @param __str String containing characters to locate.
2846 * @param __pos Index of character to search back from (default end).
2847 * @return Index of last occurrence.
2849 * Starting from @a __pos, searches backward for one of the
2850 * characters of @a __str within this string. If found,
2851 * returns the index where it was found. If not found, returns
2854 _GLIBCXX20_CONSTEXPR
2856 find_last_of(const basic_string
& __str
, size_type __pos
= npos
) const
2858 { return this->find_last_of(__str
.data(), __pos
, __str
.size()); }
2860 #if __cplusplus >= 201703L
2862 * @brief Find last position of a character of string.
2863 * @param __svt An object convertible to string_view containing
2864 * characters to locate.
2865 * @param __pos Index of character to search back from (default end).
2866 * @return Index of last occurrence.
2868 template<typename _Tp
>
2869 _GLIBCXX20_CONSTEXPR
2870 _If_sv
<_Tp
, size_type
>
2871 find_last_of(const _Tp
& __svt
, size_type __pos
= npos
) const
2872 noexcept(is_same
<_Tp
, __sv_type
>::value
)
2874 __sv_type __sv
= __svt
;
2875 return this->find_last_of(__sv
.data(), __pos
, __sv
.size());
2880 * @brief Find last position of a character of C substring.
2881 * @param __s C string containing characters to locate.
2882 * @param __pos Index of character to search back from.
2883 * @param __n Number of characters from s to search for.
2884 * @return Index of last occurrence.
2886 * Starting from @a __pos, searches backward for one of the
2887 * first @a __n characters of @a __s within this string. If
2888 * found, returns the index where it was found. If not found,
2891 _GLIBCXX20_CONSTEXPR
2893 find_last_of(const _CharT
* __s
, size_type __pos
, size_type __n
) const
2897 * @brief Find last position of a character of C string.
2898 * @param __s C string containing characters to locate.
2899 * @param __pos Index of character to search back from (default end).
2900 * @return Index of last occurrence.
2902 * Starting from @a __pos, searches backward for one of the
2903 * characters of @a __s within this string. If found, returns
2904 * the index where it was found. If not found, returns npos.
2906 _GLIBCXX20_CONSTEXPR
2908 find_last_of(const _CharT
* __s
, size_type __pos
= npos
) const
2911 __glibcxx_requires_string(__s
);
2912 return this->find_last_of(__s
, __pos
, traits_type::length(__s
));
2916 * @brief Find last position of a character.
2917 * @param __c Character to locate.
2918 * @param __pos Index of character to search back from (default end).
2919 * @return Index of last occurrence.
2921 * Starting from @a __pos, searches backward for @a __c within
2922 * this string. If found, returns the index where it was
2923 * found. If not found, returns npos.
2925 * Note: equivalent to rfind(__c, __pos).
2927 _GLIBCXX20_CONSTEXPR
2929 find_last_of(_CharT __c
, size_type __pos
= npos
) const _GLIBCXX_NOEXCEPT
2930 { return this->rfind(__c
, __pos
); }
2933 * @brief Find position of a character not in string.
2934 * @param __str String containing characters to avoid.
2935 * @param __pos Index of character to search from (default 0).
2936 * @return Index of first occurrence.
2938 * Starting from @a __pos, searches forward for a character not contained
2939 * in @a __str within this string. If found, returns the index where it
2940 * was found. If not found, returns npos.
2942 _GLIBCXX20_CONSTEXPR
2944 find_first_not_of(const basic_string
& __str
, size_type __pos
= 0) const
2946 { return this->find_first_not_of(__str
.data(), __pos
, __str
.size()); }
2948 #if __cplusplus >= 201703L
2950 * @brief Find position of a character not in a string_view.
2951 * @param __svt A object convertible to string_view containing
2952 * characters to avoid.
2953 * @param __pos Index of character to search from (default 0).
2954 * @return Index of first occurrence.
2956 template<typename _Tp
>
2957 _If_sv
<_Tp
, size_type
>
2958 _GLIBCXX20_CONSTEXPR
2959 find_first_not_of(const _Tp
& __svt
, size_type __pos
= 0) const
2960 noexcept(is_same
<_Tp
, __sv_type
>::value
)
2962 __sv_type __sv
= __svt
;
2963 return this->find_first_not_of(__sv
.data(), __pos
, __sv
.size());
2968 * @brief Find position of a character not in C substring.
2969 * @param __s C string containing characters to avoid.
2970 * @param __pos Index of character to search from.
2971 * @param __n Number of characters from __s to consider.
2972 * @return Index of first occurrence.
2974 * Starting from @a __pos, searches forward for a character not
2975 * contained in the first @a __n characters of @a __s within
2976 * this string. If found, returns the index where it was
2977 * found. If not found, returns npos.
2979 _GLIBCXX20_CONSTEXPR
2981 find_first_not_of(const _CharT
* __s
, size_type __pos
,
2982 size_type __n
) const _GLIBCXX_NOEXCEPT
;
2985 * @brief Find position of a character not in C string.
2986 * @param __s C string containing characters to avoid.
2987 * @param __pos Index of character to search from (default 0).
2988 * @return Index of first occurrence.
2990 * Starting from @a __pos, searches forward for a character not
2991 * contained in @a __s within this string. If found, returns
2992 * the index where it was found. If not found, returns npos.
2994 _GLIBCXX20_CONSTEXPR
2996 find_first_not_of(const _CharT
* __s
, size_type __pos
= 0) const
2999 __glibcxx_requires_string(__s
);
3000 return this->find_first_not_of(__s
, __pos
, traits_type::length(__s
));
3004 * @brief Find position of a different character.
3005 * @param __c Character to avoid.
3006 * @param __pos Index of character to search from (default 0).
3007 * @return Index of first occurrence.
3009 * Starting from @a __pos, searches forward for a character
3010 * other than @a __c within this string. If found, returns the
3011 * index where it was found. If not found, returns npos.
3013 _GLIBCXX20_CONSTEXPR
3015 find_first_not_of(_CharT __c
, size_type __pos
= 0) const
3019 * @brief Find last position of a character not in string.
3020 * @param __str String containing characters to avoid.
3021 * @param __pos Index of character to search back from (default end).
3022 * @return Index of last occurrence.
3024 * Starting from @a __pos, searches backward for a character
3025 * not contained in @a __str within this string. If found,
3026 * returns the index where it was found. If not found, returns
3029 _GLIBCXX20_CONSTEXPR
3031 find_last_not_of(const basic_string
& __str
, size_type __pos
= npos
) const
3033 { return this->find_last_not_of(__str
.data(), __pos
, __str
.size()); }
3035 #if __cplusplus >= 201703L
3037 * @brief Find last position of a character not in a string_view.
3038 * @param __svt An object convertible to string_view containing
3039 * characters to avoid.
3040 * @param __pos Index of character to search back from (default end).
3041 * @return Index of last occurrence.
3043 template<typename _Tp
>
3044 _GLIBCXX20_CONSTEXPR
3045 _If_sv
<_Tp
, size_type
>
3046 find_last_not_of(const _Tp
& __svt
, size_type __pos
= npos
) const
3047 noexcept(is_same
<_Tp
, __sv_type
>::value
)
3049 __sv_type __sv
= __svt
;
3050 return this->find_last_not_of(__sv
.data(), __pos
, __sv
.size());
3055 * @brief Find last position of a character not in C substring.
3056 * @param __s C string containing characters to avoid.
3057 * @param __pos Index of character to search back from.
3058 * @param __n Number of characters from s to consider.
3059 * @return Index of last occurrence.
3061 * Starting from @a __pos, searches backward for a character not
3062 * contained in the first @a __n characters of @a __s within this string.
3063 * If found, returns the index where it was found. If not found,
3066 _GLIBCXX20_CONSTEXPR
3068 find_last_not_of(const _CharT
* __s
, size_type __pos
,
3069 size_type __n
) const _GLIBCXX_NOEXCEPT
;
3071 * @brief Find last position of a character not in C string.
3072 * @param __s C string containing characters to avoid.
3073 * @param __pos Index of character to search back from (default end).
3074 * @return Index of last occurrence.
3076 * Starting from @a __pos, searches backward for a character
3077 * not contained in @a __s within this string. If found,
3078 * returns the index where it was found. If not found, returns
3081 _GLIBCXX20_CONSTEXPR
3083 find_last_not_of(const _CharT
* __s
, size_type __pos
= npos
) const
3086 __glibcxx_requires_string(__s
);
3087 return this->find_last_not_of(__s
, __pos
, traits_type::length(__s
));
3091 * @brief Find last position of a different character.
3092 * @param __c Character to avoid.
3093 * @param __pos Index of character to search back from (default end).
3094 * @return Index of last occurrence.
3096 * Starting from @a __pos, searches backward for a character other than
3097 * @a __c within this string. If found, returns the index where it was
3098 * found. If not found, returns npos.
3100 _GLIBCXX20_CONSTEXPR
3102 find_last_not_of(_CharT __c
, size_type __pos
= npos
) const
3106 * @brief Get a substring.
3107 * @param __pos Index of first character (default 0).
3108 * @param __n Number of characters in substring (default remainder).
3109 * @return The new string.
3110 * @throw std::out_of_range If __pos > size().
3112 * Construct and return a new string using the @a __n
3113 * characters starting at @a __pos. If the string is too
3114 * short, use the remainder of the characters. If @a __pos is
3115 * beyond the end of the string, out_of_range is thrown.
3117 _GLIBCXX20_CONSTEXPR
3119 substr(size_type __pos
= 0, size_type __n
= npos
) const
3120 { return basic_string(*this,
3121 _M_check(__pos
, "basic_string::substr"), __n
); }
3124 * @brief Compare to a string.
3125 * @param __str String to compare against.
3126 * @return Integer < 0, 0, or > 0.
3128 * Returns an integer < 0 if this string is ordered before @a
3129 * __str, 0 if their values are equivalent, or > 0 if this
3130 * string is ordered after @a __str. Determines the effective
3131 * length rlen of the strings to compare as the smallest of
3132 * size() and str.size(). The function then compares the two
3133 * strings by calling traits::compare(data(), str.data(),rlen).
3134 * If the result of the comparison is nonzero returns it,
3135 * otherwise the shorter one is ordered first.
3137 _GLIBCXX20_CONSTEXPR
3139 compare(const basic_string
& __str
) const
3141 const size_type __size
= this->size();
3142 const size_type __osize
= __str
.size();
3143 const size_type __len
= std::min(__size
, __osize
);
3145 int __r
= traits_type::compare(_M_data(), __str
.data(), __len
);
3147 __r
= _S_compare(__size
, __osize
);
3151 #if __cplusplus >= 201703L
3153 * @brief Compare to a string_view.
3154 * @param __svt An object convertible to string_view to compare against.
3155 * @return Integer < 0, 0, or > 0.
3157 template<typename _Tp
>
3158 _GLIBCXX20_CONSTEXPR
3160 compare(const _Tp
& __svt
) const
3161 noexcept(is_same
<_Tp
, __sv_type
>::value
)
3163 __sv_type __sv
= __svt
;
3164 const size_type __size
= this->size();
3165 const size_type __osize
= __sv
.size();
3166 const size_type __len
= std::min(__size
, __osize
);
3168 int __r
= traits_type::compare(_M_data(), __sv
.data(), __len
);
3170 __r
= _S_compare(__size
, __osize
);
3175 * @brief Compare to a string_view.
3176 * @param __pos A position in the string to start comparing from.
3177 * @param __n The number of characters to compare.
3178 * @param __svt An object convertible to string_view to compare
3180 * @return Integer < 0, 0, or > 0.
3182 template<typename _Tp
>
3183 _GLIBCXX20_CONSTEXPR
3185 compare(size_type __pos
, size_type __n
, const _Tp
& __svt
) const
3186 noexcept(is_same
<_Tp
, __sv_type
>::value
)
3188 __sv_type __sv
= __svt
;
3189 return __sv_type(*this).substr(__pos
, __n
).compare(__sv
);
3193 * @brief Compare to a string_view.
3194 * @param __pos1 A position in the string to start comparing from.
3195 * @param __n1 The number of characters to compare.
3196 * @param __svt An object convertible to string_view to compare
3198 * @param __pos2 A position in the string_view to start comparing from.
3199 * @param __n2 The number of characters to compare.
3200 * @return Integer < 0, 0, or > 0.
3202 template<typename _Tp
>
3203 _GLIBCXX20_CONSTEXPR
3205 compare(size_type __pos1
, size_type __n1
, const _Tp
& __svt
,
3206 size_type __pos2
, size_type __n2
= npos
) const
3207 noexcept(is_same
<_Tp
, __sv_type
>::value
)
3209 __sv_type __sv
= __svt
;
3210 return __sv_type(*this)
3211 .substr(__pos1
, __n1
).compare(__sv
.substr(__pos2
, __n2
));
3216 * @brief Compare substring to a string.
3217 * @param __pos Index of first character of substring.
3218 * @param __n Number of characters in substring.
3219 * @param __str String to compare against.
3220 * @return Integer < 0, 0, or > 0.
3222 * Form the substring of this string from the @a __n characters
3223 * starting at @a __pos. Returns an integer < 0 if the
3224 * substring is ordered before @a __str, 0 if their values are
3225 * equivalent, or > 0 if the substring is ordered after @a
3226 * __str. Determines the effective length rlen of the strings
3227 * to compare as the smallest of the length of the substring
3228 * and @a __str.size(). The function then compares the two
3229 * strings by calling
3230 * traits::compare(substring.data(),str.data(),rlen). If the
3231 * result of the comparison is nonzero returns it, otherwise
3232 * the shorter one is ordered first.
3234 _GLIBCXX20_CONSTEXPR
3236 compare(size_type __pos
, size_type __n
, const basic_string
& __str
) const;
3239 * @brief Compare substring to a substring.
3240 * @param __pos1 Index of first character of substring.
3241 * @param __n1 Number of characters in substring.
3242 * @param __str String to compare against.
3243 * @param __pos2 Index of first character of substring of str.
3244 * @param __n2 Number of characters in substring of str.
3245 * @return Integer < 0, 0, or > 0.
3247 * Form the substring of this string from the @a __n1
3248 * characters starting at @a __pos1. Form the substring of @a
3249 * __str from the @a __n2 characters starting at @a __pos2.
3250 * Returns an integer < 0 if this substring is ordered before
3251 * the substring of @a __str, 0 if their values are equivalent,
3252 * or > 0 if this substring is ordered after the substring of
3253 * @a __str. Determines the effective length rlen of the
3254 * strings to compare as the smallest of the lengths of the
3255 * substrings. The function then compares the two strings by
3257 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
3258 * If the result of the comparison is nonzero returns it,
3259 * otherwise the shorter one is ordered first.
3261 _GLIBCXX20_CONSTEXPR
3263 compare(size_type __pos1
, size_type __n1
, const basic_string
& __str
,
3264 size_type __pos2
, size_type __n2
= npos
) const;
3267 * @brief Compare to a C string.
3268 * @param __s C string to compare against.
3269 * @return Integer < 0, 0, or > 0.
3271 * Returns an integer < 0 if this string is ordered before @a __s, 0 if
3272 * their values are equivalent, or > 0 if this string is ordered after
3273 * @a __s. Determines the effective length rlen of the strings to
3274 * compare as the smallest of size() and the length of a string
3275 * constructed from @a __s. The function then compares the two strings
3276 * by calling traits::compare(data(),s,rlen). If the result of the
3277 * comparison is nonzero returns it, otherwise the shorter one is
3280 _GLIBCXX20_CONSTEXPR
3282 compare(const _CharT
* __s
) const _GLIBCXX_NOEXCEPT
;
3284 // _GLIBCXX_RESOLVE_LIB_DEFECTS
3285 // 5 String::compare specification questionable
3287 * @brief Compare substring to a C string.
3288 * @param __pos Index of first character of substring.
3289 * @param __n1 Number of characters in substring.
3290 * @param __s C string to compare against.
3291 * @return Integer < 0, 0, or > 0.
3293 * Form the substring of this string from the @a __n1
3294 * characters starting at @a pos. Returns an integer < 0 if
3295 * the substring is ordered before @a __s, 0 if their values
3296 * are equivalent, or > 0 if the substring is ordered after @a
3297 * __s. Determines the effective length rlen of the strings to
3298 * compare as the smallest of the length of the substring and
3299 * the length of a string constructed from @a __s. The
3300 * function then compares the two string by calling
3301 * traits::compare(substring.data(),__s,rlen). If the result of
3302 * the comparison is nonzero returns it, otherwise the shorter
3303 * one is ordered first.
3305 _GLIBCXX20_CONSTEXPR
3307 compare(size_type __pos
, size_type __n1
, const _CharT
* __s
) const;
3310 * @brief Compare substring against a character %array.
3311 * @param __pos Index of first character of substring.
3312 * @param __n1 Number of characters in substring.
3313 * @param __s character %array to compare against.
3314 * @param __n2 Number of characters of s.
3315 * @return Integer < 0, 0, or > 0.
3317 * Form the substring of this string from the @a __n1
3318 * characters starting at @a __pos. Form a string from the
3319 * first @a __n2 characters of @a __s. Returns an integer < 0
3320 * if this substring is ordered before the string from @a __s,
3321 * 0 if their values are equivalent, or > 0 if this substring
3322 * is ordered after the string from @a __s. Determines the
3323 * effective length rlen of the strings to compare as the
3324 * smallest of the length of the substring and @a __n2. The
3325 * function then compares the two strings by calling
3326 * traits::compare(substring.data(),s,rlen). If the result of
3327 * the comparison is nonzero returns it, otherwise the shorter
3328 * one is ordered first.
3330 * NB: s must have at least n2 characters, '\\0' has
3331 * no special meaning.
3333 _GLIBCXX20_CONSTEXPR
3335 compare(size_type __pos
, size_type __n1
, const _CharT
* __s
,
3336 size_type __n2
) const;
3338 #if __cplusplus >= 202002L
3340 starts_with(basic_string_view
<_CharT
, _Traits
> __x
) const noexcept
3341 { return __sv_type(this->data(), this->size()).starts_with(__x
); }
3344 starts_with(_CharT __x
) const noexcept
3345 { return __sv_type(this->data(), this->size()).starts_with(__x
); }
3348 starts_with(const _CharT
* __x
) const noexcept
3349 { return __sv_type(this->data(), this->size()).starts_with(__x
); }
3352 ends_with(basic_string_view
<_CharT
, _Traits
> __x
) const noexcept
3353 { return __sv_type(this->data(), this->size()).ends_with(__x
); }
3356 ends_with(_CharT __x
) const noexcept
3357 { return __sv_type(this->data(), this->size()).ends_with(__x
); }
3360 ends_with(const _CharT
* __x
) const noexcept
3361 { return __sv_type(this->data(), this->size()).ends_with(__x
); }
3364 #if __cplusplus > 202002L
3366 contains(basic_string_view
<_CharT
, _Traits
> __x
) const noexcept
3367 { return __sv_type(this->data(), this->size()).contains(__x
); }
3370 contains(_CharT __x
) const noexcept
3371 { return __sv_type(this->data(), this->size()).contains(__x
); }
3374 contains(const _CharT
* __x
) const noexcept
3375 { return __sv_type(this->data(), this->size()).contains(__x
); }
3378 // Allow basic_stringbuf::__xfer_bufptrs to call _M_length:
3379 template<typename
, typename
, typename
> friend class basic_stringbuf
;
3381 _GLIBCXX_END_NAMESPACE_CXX11
3382 _GLIBCXX_END_NAMESPACE_VERSION
3384 #endif // _GLIBCXX_USE_CXX11_ABI
3386 namespace std
_GLIBCXX_VISIBILITY(default)
3388 _GLIBCXX_BEGIN_NAMESPACE_VERSION
3390 #if __cpp_deduction_guides >= 201606
3391 _GLIBCXX_BEGIN_NAMESPACE_CXX11
3392 template<typename _InputIterator
, typename _CharT
3393 = typename iterator_traits
<_InputIterator
>::value_type
,
3394 typename _Allocator
= allocator
<_CharT
>,
3395 typename
= _RequireInputIter
<_InputIterator
>,
3396 typename
= _RequireAllocator
<_Allocator
>>
3397 basic_string(_InputIterator
, _InputIterator
, _Allocator
= _Allocator())
3398 -> basic_string
<_CharT
, char_traits
<_CharT
>, _Allocator
>;
3400 // _GLIBCXX_RESOLVE_LIB_DEFECTS
3401 // 3075. basic_string needs deduction guides from basic_string_view
3402 template<typename _CharT
, typename _Traits
,
3403 typename _Allocator
= allocator
<_CharT
>,
3404 typename
= _RequireAllocator
<_Allocator
>>
3405 basic_string(basic_string_view
<_CharT
, _Traits
>, const _Allocator
& = _Allocator())
3406 -> basic_string
<_CharT
, _Traits
, _Allocator
>;
3408 template<typename _CharT
, typename _Traits
,
3409 typename _Allocator
= allocator
<_CharT
>,
3410 typename
= _RequireAllocator
<_Allocator
>>
3411 basic_string(basic_string_view
<_CharT
, _Traits
>,
3412 typename basic_string
<_CharT
, _Traits
, _Allocator
>::size_type
,
3413 typename basic_string
<_CharT
, _Traits
, _Allocator
>::size_type
,
3414 const _Allocator
& = _Allocator())
3415 -> basic_string
<_CharT
, _Traits
, _Allocator
>;
3416 _GLIBCXX_END_NAMESPACE_CXX11
3421 * @brief Concatenate two strings.
3422 * @param __lhs First string.
3423 * @param __rhs Last string.
3424 * @return New string with value of @a __lhs followed by @a __rhs.
3426 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3427 _GLIBCXX20_CONSTEXPR
3428 basic_string
<_CharT
, _Traits
, _Alloc
>
3429 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3430 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
3432 basic_string
<_CharT
, _Traits
, _Alloc
> __str(__lhs
);
3433 __str
.append(__rhs
);
3438 * @brief Concatenate C string and string.
3439 * @param __lhs First string.
3440 * @param __rhs Last string.
3441 * @return New string with value of @a __lhs followed by @a __rhs.
3443 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3444 _GLIBCXX20_CONSTEXPR
3445 basic_string
<_CharT
,_Traits
,_Alloc
>
3446 operator+(const _CharT
* __lhs
,
3447 const basic_string
<_CharT
,_Traits
,_Alloc
>& __rhs
);
3450 * @brief Concatenate character and string.
3451 * @param __lhs First string.
3452 * @param __rhs Last string.
3453 * @return New string with @a __lhs followed by @a __rhs.
3455 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3456 _GLIBCXX20_CONSTEXPR
3457 basic_string
<_CharT
,_Traits
,_Alloc
>
3458 operator+(_CharT __lhs
, const basic_string
<_CharT
,_Traits
,_Alloc
>& __rhs
);
3461 * @brief Concatenate string and C string.
3462 * @param __lhs First string.
3463 * @param __rhs Last string.
3464 * @return New string with @a __lhs followed by @a __rhs.
3466 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3467 _GLIBCXX20_CONSTEXPR
3468 inline basic_string
<_CharT
, _Traits
, _Alloc
>
3469 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3470 const _CharT
* __rhs
)
3472 basic_string
<_CharT
, _Traits
, _Alloc
> __str(__lhs
);
3473 __str
.append(__rhs
);
3478 * @brief Concatenate string and character.
3479 * @param __lhs First string.
3480 * @param __rhs Last string.
3481 * @return New string with @a __lhs followed by @a __rhs.
3483 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3484 _GLIBCXX20_CONSTEXPR
3485 inline basic_string
<_CharT
, _Traits
, _Alloc
>
3486 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
, _CharT __rhs
)
3488 typedef basic_string
<_CharT
, _Traits
, _Alloc
> __string_type
;
3489 typedef typename
__string_type::size_type __size_type
;
3490 __string_type
__str(__lhs
);
3491 __str
.append(__size_type(1), __rhs
);
3495 #if __cplusplus >= 201103L
3496 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3497 _GLIBCXX20_CONSTEXPR
3498 inline basic_string
<_CharT
, _Traits
, _Alloc
>
3499 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
3500 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
3501 { return std::move(__lhs
.append(__rhs
)); }
3503 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3504 _GLIBCXX20_CONSTEXPR
3505 inline basic_string
<_CharT
, _Traits
, _Alloc
>
3506 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3507 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
3508 { return std::move(__rhs
.insert(0, __lhs
)); }
3510 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3511 _GLIBCXX20_CONSTEXPR
3512 inline basic_string
<_CharT
, _Traits
, _Alloc
>
3513 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
3514 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
3516 #if _GLIBCXX_USE_CXX11_ABI
3517 using _Alloc_traits
= allocator_traits
<_Alloc
>;
3518 bool __use_rhs
= false;
3519 if _GLIBCXX17_CONSTEXPR (typename
_Alloc_traits::is_always_equal
{})
3521 else if (__lhs
.get_allocator() == __rhs
.get_allocator())
3526 const auto __size
= __lhs
.size() + __rhs
.size();
3527 if (__size
> __lhs
.capacity() && __size
<= __rhs
.capacity())
3528 return std::move(__rhs
.insert(0, __lhs
));
3530 return std::move(__lhs
.append(__rhs
));
3533 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3534 _GLIBCXX20_CONSTEXPR
3535 inline basic_string
<_CharT
, _Traits
, _Alloc
>
3536 operator+(const _CharT
* __lhs
,
3537 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
3538 { return std::move(__rhs
.insert(0, __lhs
)); }
3540 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3541 _GLIBCXX20_CONSTEXPR
3542 inline basic_string
<_CharT
, _Traits
, _Alloc
>
3543 operator+(_CharT __lhs
,
3544 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
3545 { return std::move(__rhs
.insert(0, 1, __lhs
)); }
3547 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3548 _GLIBCXX20_CONSTEXPR
3549 inline basic_string
<_CharT
, _Traits
, _Alloc
>
3550 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
3551 const _CharT
* __rhs
)
3552 { return std::move(__lhs
.append(__rhs
)); }
3554 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3555 _GLIBCXX20_CONSTEXPR
3556 inline basic_string
<_CharT
, _Traits
, _Alloc
>
3557 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
3559 { return std::move(__lhs
.append(1, __rhs
)); }
3564 * @brief Test equivalence of two strings.
3565 * @param __lhs First string.
3566 * @param __rhs Second string.
3567 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
3569 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3570 _GLIBCXX20_CONSTEXPR
3572 operator==(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3573 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
3575 { return __lhs
.compare(__rhs
) == 0; }
3577 template<typename _CharT
>
3578 _GLIBCXX20_CONSTEXPR
3580 typename
__gnu_cxx::__enable_if
<__is_char
<_CharT
>::__value
, bool>::__type
3581 operator==(const basic_string
<_CharT
>& __lhs
,
3582 const basic_string
<_CharT
>& __rhs
) _GLIBCXX_NOEXCEPT
3583 { return (__lhs
.size() == __rhs
.size()
3584 && !std::char_traits
<_CharT
>::compare(__lhs
.data(), __rhs
.data(),
3588 * @brief Test equivalence of string and C string.
3589 * @param __lhs String.
3590 * @param __rhs C string.
3591 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
3593 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3594 _GLIBCXX20_CONSTEXPR
3596 operator==(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3597 const _CharT
* __rhs
)
3598 { return __lhs
.compare(__rhs
) == 0; }
3600 #if __cpp_lib_three_way_comparison
3602 * @brief Three-way comparison of a string and a C string.
3603 * @param __lhs A string.
3604 * @param __rhs A null-terminated string.
3605 * @return A value indicating whether `__lhs` is less than, equal to,
3606 * greater than, or incomparable with `__rhs`.
3608 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3610 operator<=>(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3611 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
) noexcept
3612 -> decltype(__detail::__char_traits_cmp_cat
<_Traits
>(0))
3613 { return __detail::__char_traits_cmp_cat
<_Traits
>(__lhs
.compare(__rhs
)); }
3616 * @brief Three-way comparison of a string and a C string.
3617 * @param __lhs A string.
3618 * @param __rhs A null-terminated string.
3619 * @return A value indicating whether `__lhs` is less than, equal to,
3620 * greater than, or incomparable with `__rhs`.
3622 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3624 operator<=>(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3625 const _CharT
* __rhs
) noexcept
3626 -> decltype(__detail::__char_traits_cmp_cat
<_Traits
>(0))
3627 { return __detail::__char_traits_cmp_cat
<_Traits
>(__lhs
.compare(__rhs
)); }
3630 * @brief Test equivalence of C string and string.
3631 * @param __lhs C string.
3632 * @param __rhs String.
3633 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
3635 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3637 operator==(const _CharT
* __lhs
,
3638 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
3639 { return __rhs
.compare(__lhs
) == 0; }
3643 * @brief Test difference of two strings.
3644 * @param __lhs First string.
3645 * @param __rhs Second string.
3646 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
3648 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3650 operator!=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3651 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
3653 { return !(__lhs
== __rhs
); }
3656 * @brief Test difference of C string and string.
3657 * @param __lhs C string.
3658 * @param __rhs String.
3659 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
3661 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3663 operator!=(const _CharT
* __lhs
,
3664 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
3665 { return !(__lhs
== __rhs
); }
3668 * @brief Test difference of string and C string.
3669 * @param __lhs String.
3670 * @param __rhs C string.
3671 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
3673 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3675 operator!=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3676 const _CharT
* __rhs
)
3677 { return !(__lhs
== __rhs
); }
3681 * @brief Test if string precedes string.
3682 * @param __lhs First string.
3683 * @param __rhs Second string.
3684 * @return True if @a __lhs precedes @a __rhs. False otherwise.
3686 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3688 operator<(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3689 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
3691 { return __lhs
.compare(__rhs
) < 0; }
3694 * @brief Test if string precedes C string.
3695 * @param __lhs String.
3696 * @param __rhs C string.
3697 * @return True if @a __lhs precedes @a __rhs. False otherwise.
3699 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3701 operator<(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3702 const _CharT
* __rhs
)
3703 { return __lhs
.compare(__rhs
) < 0; }
3706 * @brief Test if C string precedes string.
3707 * @param __lhs C string.
3708 * @param __rhs String.
3709 * @return True if @a __lhs precedes @a __rhs. False otherwise.
3711 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3713 operator<(const _CharT
* __lhs
,
3714 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
3715 { return __rhs
.compare(__lhs
) > 0; }
3719 * @brief Test if string follows string.
3720 * @param __lhs First string.
3721 * @param __rhs Second string.
3722 * @return True if @a __lhs follows @a __rhs. False otherwise.
3724 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3726 operator>(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3727 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
3729 { return __lhs
.compare(__rhs
) > 0; }
3732 * @brief Test if string follows C string.
3733 * @param __lhs String.
3734 * @param __rhs C string.
3735 * @return True if @a __lhs follows @a __rhs. False otherwise.
3737 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3739 operator>(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3740 const _CharT
* __rhs
)
3741 { return __lhs
.compare(__rhs
) > 0; }
3744 * @brief Test if C string follows string.
3745 * @param __lhs C string.
3746 * @param __rhs String.
3747 * @return True if @a __lhs follows @a __rhs. False otherwise.
3749 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3751 operator>(const _CharT
* __lhs
,
3752 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
3753 { return __rhs
.compare(__lhs
) < 0; }
3757 * @brief Test if string doesn't follow string.
3758 * @param __lhs First string.
3759 * @param __rhs Second string.
3760 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
3762 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3764 operator<=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3765 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
3767 { return __lhs
.compare(__rhs
) <= 0; }
3770 * @brief Test if string doesn't follow C string.
3771 * @param __lhs String.
3772 * @param __rhs C string.
3773 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
3775 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3777 operator<=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3778 const _CharT
* __rhs
)
3779 { return __lhs
.compare(__rhs
) <= 0; }
3782 * @brief Test if C string doesn't follow string.
3783 * @param __lhs C string.
3784 * @param __rhs String.
3785 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
3787 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3789 operator<=(const _CharT
* __lhs
,
3790 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
3791 { return __rhs
.compare(__lhs
) >= 0; }
3795 * @brief Test if string doesn't precede string.
3796 * @param __lhs First string.
3797 * @param __rhs Second string.
3798 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
3800 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3802 operator>=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3803 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
3805 { return __lhs
.compare(__rhs
) >= 0; }
3808 * @brief Test if string doesn't precede C string.
3809 * @param __lhs String.
3810 * @param __rhs C string.
3811 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
3813 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3815 operator>=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3816 const _CharT
* __rhs
)
3817 { return __lhs
.compare(__rhs
) >= 0; }
3820 * @brief Test if C string doesn't precede string.
3821 * @param __lhs C string.
3822 * @param __rhs String.
3823 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
3825 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3827 operator>=(const _CharT
* __lhs
,
3828 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
3829 { return __rhs
.compare(__lhs
) <= 0; }
3830 #endif // three-way comparison
3833 * @brief Swap contents of two strings.
3834 * @param __lhs First string.
3835 * @param __rhs Second string.
3837 * Exchanges the contents of @a __lhs and @a __rhs in constant time.
3839 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3840 _GLIBCXX20_CONSTEXPR
3842 swap(basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
3843 basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
3844 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs
.swap(__rhs
)))
3845 { __lhs
.swap(__rhs
); }
3849 * @brief Read stream into a string.
3850 * @param __is Input stream.
3851 * @param __str Buffer to store into.
3852 * @return Reference to the input stream.
3854 * Stores characters from @a __is into @a __str until whitespace is
3855 * found, the end of the stream is encountered, or str.max_size()
3856 * is reached. If is.width() is non-zero, that is the limit on the
3857 * number of characters stored into @a __str. Any previous
3858 * contents of @a __str are erased.
3860 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3861 basic_istream
<_CharT
, _Traits
>&
3862 operator>>(basic_istream
<_CharT
, _Traits
>& __is
,
3863 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
);
3866 basic_istream
<char>&
3867 operator>>(basic_istream
<char>& __is
, basic_string
<char>& __str
);
3870 * @brief Write string to a stream.
3871 * @param __os Output stream.
3872 * @param __str String to write out.
3873 * @return Reference to the output stream.
3875 * Output characters of @a __str into os following the same rules as for
3876 * writing a C string.
3878 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3879 inline basic_ostream
<_CharT
, _Traits
>&
3880 operator<<(basic_ostream
<_CharT
, _Traits
>& __os
,
3881 const basic_string
<_CharT
, _Traits
, _Alloc
>& __str
)
3883 // _GLIBCXX_RESOLVE_LIB_DEFECTS
3884 // 586. string inserter not a formatted function
3885 return __ostream_insert(__os
, __str
.data(), __str
.size());
3889 * @brief Read a line from stream into a string.
3890 * @param __is Input stream.
3891 * @param __str Buffer to store into.
3892 * @param __delim Character marking end of line.
3893 * @return Reference to the input stream.
3895 * Stores characters from @a __is into @a __str until @a __delim is
3896 * found, the end of the stream is encountered, or str.max_size()
3897 * is reached. Any previous contents of @a __str are erased. If
3898 * @a __delim is encountered, it is extracted but not stored into
3901 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3902 basic_istream
<_CharT
, _Traits
>&
3903 getline(basic_istream
<_CharT
, _Traits
>& __is
,
3904 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
, _CharT __delim
);
3907 * @brief Read a line from stream into a string.
3908 * @param __is Input stream.
3909 * @param __str Buffer to store into.
3910 * @return Reference to the input stream.
3912 * Stores characters from is into @a __str until '\n' is
3913 * found, the end of the stream is encountered, or str.max_size()
3914 * is reached. Any previous contents of @a __str are erased. If
3915 * end of line is encountered, it is extracted but not stored into
3918 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3919 inline basic_istream
<_CharT
, _Traits
>&
3920 getline(basic_istream
<_CharT
, _Traits
>& __is
,
3921 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
)
3922 { return std::getline(__is
, __str
, __is
.widen('\n')); }
3924 #if __cplusplus >= 201103L
3925 /// Read a line from an rvalue stream into a string.
3926 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3927 inline basic_istream
<_CharT
, _Traits
>&
3928 getline(basic_istream
<_CharT
, _Traits
>&& __is
,
3929 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
, _CharT __delim
)
3930 { return std::getline(__is
, __str
, __delim
); }
3932 /// Read a line from an rvalue stream into a string.
3933 template<typename _CharT
, typename _Traits
, typename _Alloc
>
3934 inline basic_istream
<_CharT
, _Traits
>&
3935 getline(basic_istream
<_CharT
, _Traits
>&& __is
,
3936 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
)
3937 { return std::getline(__is
, __str
); }
3941 basic_istream
<char>&
3942 getline(basic_istream
<char>& __in
, basic_string
<char>& __str
,
3945 #ifdef _GLIBCXX_USE_WCHAR_T
3947 basic_istream
<wchar_t>&
3948 getline(basic_istream
<wchar_t>& __in
, basic_string
<wchar_t>& __str
,
3952 _GLIBCXX_END_NAMESPACE_VERSION
3955 #if __cplusplus >= 201103L
3957 #include <ext/string_conversions.h>
3958 #include <bits/charconv.h>
3960 namespace std
_GLIBCXX_VISIBILITY(default)
3962 _GLIBCXX_BEGIN_NAMESPACE_VERSION
3963 _GLIBCXX_BEGIN_NAMESPACE_CXX11
3965 #if _GLIBCXX_USE_C99_STDLIB
3966 // 21.4 Numeric Conversions [string.conversions].
3968 stoi(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
3969 { return __gnu_cxx::__stoa
<long, int>(&std::strtol
, "stoi", __str
.c_str(),
3973 stol(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
3974 { return __gnu_cxx::__stoa(&std::strtol
, "stol", __str
.c_str(),
3977 inline unsigned long
3978 stoul(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
3979 { return __gnu_cxx::__stoa(&std::strtoul
, "stoul", __str
.c_str(),
3983 stoll(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
3984 { return __gnu_cxx::__stoa(&std::strtoll
, "stoll", __str
.c_str(),
3987 inline unsigned long long
3988 stoull(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
3989 { return __gnu_cxx::__stoa(&std::strtoull
, "stoull", __str
.c_str(),
3992 // NB: strtof vs strtod.
3994 stof(const string
& __str
, size_t* __idx
= 0)
3995 { return __gnu_cxx::__stoa(&std::strtof
, "stof", __str
.c_str(), __idx
); }
3998 stod(const string
& __str
, size_t* __idx
= 0)
3999 { return __gnu_cxx::__stoa(&std::strtod
, "stod", __str
.c_str(), __idx
); }
4002 stold(const string
& __str
, size_t* __idx
= 0)
4003 { return __gnu_cxx::__stoa(&std::strtold
, "stold", __str
.c_str(), __idx
); }
4004 #endif // _GLIBCXX_USE_C99_STDLIB
4006 // DR 1261. Insufficent overloads for to_string / to_wstring
4009 to_string(int __val
)
4010 #if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_INT__) <= 32
4011 noexcept
// any 32-bit value fits in the SSO buffer
4014 const bool __neg
= __val
< 0;
4015 const unsigned __uval
= __neg
? (unsigned)~__val
+ 1u : __val
;
4016 const auto __len
= __detail::__to_chars_len(__uval
);
4017 string
__str(__neg
+ __len
, '-');
4018 __detail::__to_chars_10_impl(&__str
[__neg
], __len
, __uval
);
4023 to_string(unsigned __val
)
4024 #if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_INT__) <= 32
4025 noexcept
// any 32-bit value fits in the SSO buffer
4028 string
__str(__detail::__to_chars_len(__val
), '\0');
4029 __detail::__to_chars_10_impl(&__str
[0], __str
.size(), __val
);
4034 to_string(long __val
)
4035 #if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_LONG__) <= 32
4036 noexcept
// any 32-bit value fits in the SSO buffer
4039 const bool __neg
= __val
< 0;
4040 const unsigned long __uval
= __neg
? (unsigned long)~__val
+ 1ul : __val
;
4041 const auto __len
= __detail::__to_chars_len(__uval
);
4042 string
__str(__neg
+ __len
, '-');
4043 __detail::__to_chars_10_impl(&__str
[__neg
], __len
, __uval
);
4048 to_string(unsigned long __val
)
4049 #if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_LONG__) <= 32
4050 noexcept
// any 32-bit value fits in the SSO buffer
4053 string
__str(__detail::__to_chars_len(__val
), '\0');
4054 __detail::__to_chars_10_impl(&__str
[0], __str
.size(), __val
);
4059 to_string(long long __val
)
4061 const bool __neg
= __val
< 0;
4062 const unsigned long long __uval
4063 = __neg
? (unsigned long long)~__val
+ 1ull : __val
;
4064 const auto __len
= __detail::__to_chars_len(__uval
);
4065 string
__str(__neg
+ __len
, '-');
4066 __detail::__to_chars_10_impl(&__str
[__neg
], __len
, __uval
);
4071 to_string(unsigned long long __val
)
4073 string
__str(__detail::__to_chars_len(__val
), '\0');
4074 __detail::__to_chars_10_impl(&__str
[0], __str
.size(), __val
);
4078 #if _GLIBCXX_USE_C99_STDIO
4079 // NB: (v)snprintf vs sprintf.
4082 to_string(float __val
)
4085 __gnu_cxx::__numeric_traits
<float>::__max_exponent10
+ 20;
4086 return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, __n
,
4091 to_string(double __val
)
4094 __gnu_cxx::__numeric_traits
<double>::__max_exponent10
+ 20;
4095 return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, __n
,
4100 to_string(long double __val
)
4103 __gnu_cxx::__numeric_traits
<long double>::__max_exponent10
+ 20;
4104 return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, __n
,
4107 #endif // _GLIBCXX_USE_C99_STDIO
4109 #if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR
4111 stoi(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
4112 { return __gnu_cxx::__stoa
<long, int>(&std::wcstol
, "stoi", __str
.c_str(),
4116 stol(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
4117 { return __gnu_cxx::__stoa(&std::wcstol
, "stol", __str
.c_str(),
4120 inline unsigned long
4121 stoul(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
4122 { return __gnu_cxx::__stoa(&std::wcstoul
, "stoul", __str
.c_str(),
4126 stoll(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
4127 { return __gnu_cxx::__stoa(&std::wcstoll
, "stoll", __str
.c_str(),
4130 inline unsigned long long
4131 stoull(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
4132 { return __gnu_cxx::__stoa(&std::wcstoull
, "stoull", __str
.c_str(),
4135 // NB: wcstof vs wcstod.
4137 stof(const wstring
& __str
, size_t* __idx
= 0)
4138 { return __gnu_cxx::__stoa(&std::wcstof
, "stof", __str
.c_str(), __idx
); }
4141 stod(const wstring
& __str
, size_t* __idx
= 0)
4142 { return __gnu_cxx::__stoa(&std::wcstod
, "stod", __str
.c_str(), __idx
); }
4145 stold(const wstring
& __str
, size_t* __idx
= 0)
4146 { return __gnu_cxx::__stoa(&std::wcstold
, "stold", __str
.c_str(), __idx
); }
4148 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
4151 to_wstring(int __val
)
4152 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, 4 * sizeof(int),
4156 to_wstring(unsigned __val
)
4157 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
4158 4 * sizeof(unsigned),
4162 to_wstring(long __val
)
4163 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, 4 * sizeof(long),
4167 to_wstring(unsigned long __val
)
4168 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
4169 4 * sizeof(unsigned long),
4173 to_wstring(long long __val
)
4174 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
4175 4 * sizeof(long long),
4179 to_wstring(unsigned long long __val
)
4180 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
4181 4 * sizeof(unsigned long long),
4185 to_wstring(float __val
)
4188 __gnu_cxx::__numeric_traits
<float>::__max_exponent10
+ 20;
4189 return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, __n
,
4194 to_wstring(double __val
)
4197 __gnu_cxx::__numeric_traits
<double>::__max_exponent10
+ 20;
4198 return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, __n
,
4203 to_wstring(long double __val
)
4206 __gnu_cxx::__numeric_traits
<long double>::__max_exponent10
+ 20;
4207 return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, __n
,
4210 #endif // _GLIBCXX_HAVE_BROKEN_VSWPRINTF
4211 #endif // _GLIBCXX_USE_WCHAR_T && _GLIBCXX_USE_C99_WCHAR
4213 _GLIBCXX_END_NAMESPACE_CXX11
4214 _GLIBCXX_END_NAMESPACE_VERSION
4219 #if __cplusplus >= 201103L
4221 #include <bits/functional_hash.h>
4223 namespace std
_GLIBCXX_VISIBILITY(default)
4225 _GLIBCXX_BEGIN_NAMESPACE_VERSION
4229 #ifndef _GLIBCXX_COMPATIBILITY_CXX0X
4230 /// std::hash specialization for string.
4233 : public __hash_base
<size_t, string
>
4236 operator()(const string
& __s
) const noexcept
4237 { return std::_Hash_impl::hash(__s
.data(), __s
.length()); }
4241 struct __is_fast_hash
<hash
<string
>> : std::false_type
4244 /// std::hash specialization for wstring.
4246 struct hash
<wstring
>
4247 : public __hash_base
<size_t, wstring
>
4250 operator()(const wstring
& __s
) const noexcept
4251 { return std::_Hash_impl::hash(__s
.data(),
4252 __s
.length() * sizeof(wchar_t)); }
4256 struct __is_fast_hash
<hash
<wstring
>> : std::false_type
4258 #endif /* _GLIBCXX_COMPATIBILITY_CXX0X */
4260 #ifdef _GLIBCXX_USE_CHAR8_T
4261 /// std::hash specialization for u8string.
4263 struct hash
<u8string
>
4264 : public __hash_base
<size_t, u8string
>
4267 operator()(const u8string
& __s
) const noexcept
4268 { return std::_Hash_impl::hash(__s
.data(),
4269 __s
.length() * sizeof(char8_t
)); }
4273 struct __is_fast_hash
<hash
<u8string
>> : std::false_type
4277 /// std::hash specialization for u16string.
4279 struct hash
<u16string
>
4280 : public __hash_base
<size_t, u16string
>
4283 operator()(const u16string
& __s
) const noexcept
4284 { return std::_Hash_impl::hash(__s
.data(),
4285 __s
.length() * sizeof(char16_t
)); }
4289 struct __is_fast_hash
<hash
<u16string
>> : std::false_type
4292 /// std::hash specialization for u32string.
4294 struct hash
<u32string
>
4295 : public __hash_base
<size_t, u32string
>
4298 operator()(const u32string
& __s
) const noexcept
4299 { return std::_Hash_impl::hash(__s
.data(),
4300 __s
.length() * sizeof(char32_t
)); }
4304 struct __is_fast_hash
<hash
<u32string
>> : std::false_type
4307 #if __cplusplus >= 201402L
4309 #define __cpp_lib_string_udls 201304
4311 inline namespace literals
4313 inline namespace string_literals
4315 #pragma GCC diagnostic push
4316 #pragma GCC diagnostic ignored "-Wliteral-suffix"
4318 #if __cpp_lib_constexpr_string >= 201907L
4319 # define _GLIBCXX_STRING_CONSTEXPR constexpr
4321 # define _GLIBCXX_STRING_CONSTEXPR
4324 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4325 inline basic_string
<char>
4326 operator""s(const char* __str
, size_t __len
)
4327 { return basic_string
<char>{__str
, __len
}; }
4329 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4330 inline basic_string
<wchar_t>
4331 operator""s(const wchar_t* __str
, size_t __len
)
4332 { return basic_string
<wchar_t>{__str
, __len
}; }
4334 #ifdef _GLIBCXX_USE_CHAR8_T
4335 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4336 inline basic_string
<char8_t
>
4337 operator""s(const char8_t
* __str
, size_t __len
)
4338 { return basic_string
<char8_t
>{__str
, __len
}; }
4341 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4342 inline basic_string
<char16_t
>
4343 operator""s(const char16_t
* __str
, size_t __len
)
4344 { return basic_string
<char16_t
>{__str
, __len
}; }
4346 _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
4347 inline basic_string
<char32_t
>
4348 operator""s(const char32_t
* __str
, size_t __len
)
4349 { return basic_string
<char32_t
>{__str
, __len
}; }
4351 #undef _GLIBCXX_STRING_CONSTEXPR
4352 #pragma GCC diagnostic pop
4353 } // inline namespace string_literals
4354 } // inline namespace literals
4356 #if __cplusplus >= 201703L
4357 namespace __detail::__variant
4359 template<typename
> struct _Never_valueless_alt
; // see <variant>
4361 // Provide the strong exception-safety guarantee when emplacing a
4362 // basic_string into a variant, but only if moving the string cannot throw.
4363 template<typename _Tp
, typename _Traits
, typename _Alloc
>
4364 struct _Never_valueless_alt
<std::basic_string
<_Tp
, _Traits
, _Alloc
>>
4366 is_nothrow_move_constructible
<std::basic_string
<_Tp
, _Traits
, _Alloc
>>,
4367 is_nothrow_move_assignable
<std::basic_string
<_Tp
, _Traits
, _Alloc
>>
4370 } // namespace __detail::__variant
4374 _GLIBCXX_END_NAMESPACE_VERSION
4379 #endif /* _BASIC_STRING_H */