1 // Components for manipulating sequences of characters -*- C++ -*-
3 // Copyright (C) 1997-2017 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 > 201402L
48 # include <string_view>
52 namespace std
_GLIBCXX_VISIBILITY(default)
54 _GLIBCXX_BEGIN_NAMESPACE_VERSION
56 #if _GLIBCXX_USE_CXX11_ABI
57 _GLIBCXX_BEGIN_NAMESPACE_CXX11
59 * @class basic_string basic_string.h <string>
60 * @brief Managing sequences of characters and character-like objects.
65 * @tparam _CharT Type of character
66 * @tparam _Traits Traits for character type, defaults to
67 * char_traits<_CharT>.
68 * @tparam _Alloc Allocator type, defaults to allocator<_CharT>.
70 * Meets the requirements of a <a href="tables.html#65">container</a>, a
71 * <a href="tables.html#66">reversible container</a>, and a
72 * <a href="tables.html#67">sequence</a>. Of the
73 * <a href="tables.html#68">optional sequence requirements</a>, only
74 * @c push_back, @c at, and @c %array access are supported.
76 template<typename _CharT
, typename _Traits
, typename _Alloc
>
79 typedef typename
__gnu_cxx::__alloc_traits
<_Alloc
>::template
80 rebind
<_CharT
>::other _Char_alloc_type
;
81 typedef __gnu_cxx::__alloc_traits
<_Char_alloc_type
> _Alloc_traits
;
85 typedef _Traits traits_type
;
86 typedef typename
_Traits::char_type value_type
;
87 typedef _Char_alloc_type allocator_type
;
88 typedef typename
_Alloc_traits::size_type size_type
;
89 typedef typename
_Alloc_traits::difference_type difference_type
;
90 typedef typename
_Alloc_traits::reference reference
;
91 typedef typename
_Alloc_traits::const_reference const_reference
;
92 typedef typename
_Alloc_traits::pointer pointer
;
93 typedef typename
_Alloc_traits::const_pointer const_pointer
;
94 typedef __gnu_cxx::__normal_iterator
<pointer
, basic_string
> iterator
;
95 typedef __gnu_cxx::__normal_iterator
<const_pointer
, basic_string
>
97 typedef std::reverse_iterator
<const_iterator
> const_reverse_iterator
;
98 typedef std::reverse_iterator
<iterator
> reverse_iterator
;
100 /// Value returned by various member functions when they fail.
101 static const size_type npos
= static_cast<size_type
>(-1);
104 // type used for positions in insert, erase etc.
105 #if __cplusplus < 201103L
106 typedef iterator __const_iterator
;
108 typedef const_iterator __const_iterator
;
111 #if __cplusplus > 201402L
112 // A helper type for avoiding boiler-plate.
113 typedef basic_string_view
<_CharT
, _Traits
> __sv_type
;
116 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
117 struct _Alloc_hider
: allocator_type
// TODO check __is_final
119 #if __cplusplus < 201103L
120 _Alloc_hider(pointer __dat
, const _Alloc
& __a
= _Alloc())
121 : allocator_type(__a
), _M_p(__dat
) { }
123 _Alloc_hider(pointer __dat
, const _Alloc
& __a
)
124 : allocator_type(__a
), _M_p(__dat
) { }
126 _Alloc_hider(pointer __dat
, _Alloc
&& __a
= _Alloc())
127 : allocator_type(std::move(__a
)), _M_p(__dat
) { }
130 pointer _M_p
; // The actual data.
133 _Alloc_hider _M_dataplus
;
134 size_type _M_string_length
;
136 enum { _S_local_capacity
= 15 / sizeof(_CharT
) };
140 _CharT _M_local_buf
[_S_local_capacity
+ 1];
141 size_type _M_allocated_capacity
;
146 { _M_dataplus
._M_p
= __p
; }
149 _M_length(size_type __length
)
150 { _M_string_length
= __length
; }
154 { return _M_dataplus
._M_p
; }
159 #if __cplusplus >= 201103L
160 return std::pointer_traits
<pointer
>::pointer_to(*_M_local_buf
);
162 return pointer(_M_local_buf
);
167 _M_local_data() const
169 #if __cplusplus >= 201103L
170 return std::pointer_traits
<const_pointer
>::pointer_to(*_M_local_buf
);
172 return const_pointer(_M_local_buf
);
177 _M_capacity(size_type __capacity
)
178 { _M_allocated_capacity
= __capacity
; }
181 _M_set_length(size_type __n
)
184 traits_type::assign(_M_data()[__n
], _CharT());
189 { return _M_data() == _M_local_data(); }
193 _M_create(size_type
&, size_type
);
199 _M_destroy(_M_allocated_capacity
);
203 _M_destroy(size_type __size
) throw()
204 { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size
+ 1); }
206 // _M_construct_aux is used to implement the 21.3.1 para 15 which
207 // requires special behaviour if _InIterator is an integral type
208 template<typename _InIterator
>
210 _M_construct_aux(_InIterator __beg
, _InIterator __end
,
213 typedef typename iterator_traits
<_InIterator
>::iterator_category _Tag
;
214 _M_construct(__beg
, __end
, _Tag());
217 // _GLIBCXX_RESOLVE_LIB_DEFECTS
218 // 438. Ambiguity in the "do the right thing" clause
219 template<typename _Integer
>
221 _M_construct_aux(_Integer __beg
, _Integer __end
, std::__true_type
)
222 { _M_construct_aux_2(static_cast<size_type
>(__beg
), __end
); }
225 _M_construct_aux_2(size_type __req
, _CharT __c
)
226 { _M_construct(__req
, __c
); }
228 template<typename _InIterator
>
230 _M_construct(_InIterator __beg
, _InIterator __end
)
232 typedef typename
std::__is_integer
<_InIterator
>::__type _Integral
;
233 _M_construct_aux(__beg
, __end
, _Integral());
236 // For Input Iterators, used in istreambuf_iterators, etc.
237 template<typename _InIterator
>
239 _M_construct(_InIterator __beg
, _InIterator __end
,
240 std::input_iterator_tag
);
242 // For forward_iterators up to random_access_iterators, used for
243 // string::iterator, _CharT*, etc.
244 template<typename _FwdIterator
>
246 _M_construct(_FwdIterator __beg
, _FwdIterator __end
,
247 std::forward_iterator_tag
);
250 _M_construct(size_type __req
, _CharT __c
);
254 { return _M_dataplus
; }
256 const allocator_type
&
257 _M_get_allocator() const
258 { return _M_dataplus
; }
262 #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
263 // The explicit instantiations in misc-inst.cc require this due to
264 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64063
265 template<typename _Tp
, bool _Requires
=
266 !__are_same
<_Tp
, _CharT
*>::__value
267 && !__are_same
<_Tp
, const _CharT
*>::__value
268 && !__are_same
<_Tp
, iterator
>::__value
269 && !__are_same
<_Tp
, const_iterator
>::__value
>
270 struct __enable_if_not_native_iterator
271 { typedef basic_string
& __type
; };
272 template<typename _Tp
>
273 struct __enable_if_not_native_iterator
<_Tp
, false> { };
277 _M_check(size_type __pos
, const char* __s
) const
279 if (__pos
> this->size())
280 __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
281 "this->size() (which is %zu)"),
282 __s
, __pos
, this->size());
287 _M_check_length(size_type __n1
, size_type __n2
, const char* __s
) const
289 if (this->max_size() - (this->size() - __n1
) < __n2
)
290 __throw_length_error(__N(__s
));
294 // NB: _M_limit doesn't check for a bad __pos value.
296 _M_limit(size_type __pos
, size_type __off
) const _GLIBCXX_NOEXCEPT
298 const bool __testoff
= __off
< this->size() - __pos
;
299 return __testoff
? __off
: this->size() - __pos
;
302 // True if _Rep and source do not overlap.
304 _M_disjunct(const _CharT
* __s
) const _GLIBCXX_NOEXCEPT
306 return (less
<const _CharT
*>()(__s
, _M_data())
307 || less
<const _CharT
*>()(_M_data() + this->size(), __s
));
310 // When __n = 1 way faster than the general multichar
311 // traits_type::copy/move/assign.
313 _S_copy(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
316 traits_type::assign(*__d
, *__s
);
318 traits_type::copy(__d
, __s
, __n
);
322 _S_move(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
325 traits_type::assign(*__d
, *__s
);
327 traits_type::move(__d
, __s
, __n
);
331 _S_assign(_CharT
* __d
, size_type __n
, _CharT __c
)
334 traits_type::assign(*__d
, __c
);
336 traits_type::assign(__d
, __n
, __c
);
339 // _S_copy_chars is a separate template to permit specialization
340 // to optimize for the common case of pointers as iterators.
341 template<class _Iterator
>
343 _S_copy_chars(_CharT
* __p
, _Iterator __k1
, _Iterator __k2
)
345 for (; __k1
!= __k2
; ++__k1
, (void)++__p
)
346 traits_type::assign(*__p
, *__k1
); // These types are off.
350 _S_copy_chars(_CharT
* __p
, iterator __k1
, iterator __k2
) _GLIBCXX_NOEXCEPT
351 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
354 _S_copy_chars(_CharT
* __p
, const_iterator __k1
, const_iterator __k2
)
356 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
359 _S_copy_chars(_CharT
* __p
, _CharT
* __k1
, _CharT
* __k2
) _GLIBCXX_NOEXCEPT
360 { _S_copy(__p
, __k1
, __k2
- __k1
); }
363 _S_copy_chars(_CharT
* __p
, const _CharT
* __k1
, const _CharT
* __k2
)
365 { _S_copy(__p
, __k1
, __k2
- __k1
); }
368 _S_compare(size_type __n1
, size_type __n2
) _GLIBCXX_NOEXCEPT
370 const difference_type __d
= difference_type(__n1
- __n2
);
372 if (__d
> __gnu_cxx::__numeric_traits
<int>::__max
)
373 return __gnu_cxx::__numeric_traits
<int>::__max
;
374 else if (__d
< __gnu_cxx::__numeric_traits
<int>::__min
)
375 return __gnu_cxx::__numeric_traits
<int>::__min
;
381 _M_assign(const basic_string
& __rcs
);
384 _M_mutate(size_type __pos
, size_type __len1
, const _CharT
* __s
,
388 _M_erase(size_type __pos
, size_type __n
);
391 // Construct/copy/destroy:
392 // NB: We overload ctors in some cases instead of using default
393 // arguments, per 17.4.4.4 para. 2 item 2.
396 * @brief Default constructor creates an empty string.
399 _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible
<_Alloc
>::value
)
400 : _M_dataplus(_M_local_data())
401 { _M_set_length(0); }
404 * @brief Construct an empty string using allocator @a a.
407 basic_string(const _Alloc
& __a
) _GLIBCXX_NOEXCEPT
408 : _M_dataplus(_M_local_data(), __a
)
409 { _M_set_length(0); }
412 * @brief Construct string with copy of value of @a __str.
413 * @param __str Source string.
415 basic_string(const basic_string
& __str
)
416 : _M_dataplus(_M_local_data(),
417 _Alloc_traits::_S_select_on_copy(__str
._M_get_allocator()))
418 { _M_construct(__str
._M_data(), __str
._M_data() + __str
.length()); }
420 // _GLIBCXX_RESOLVE_LIB_DEFECTS
421 // 2583. no way to supply an allocator for basic_string(str, pos)
423 * @brief Construct string as copy of a substring.
424 * @param __str Source string.
425 * @param __pos Index of first character to copy from.
426 * @param __a Allocator to use.
428 basic_string(const basic_string
& __str
, size_type __pos
,
429 const _Alloc
& __a
= _Alloc())
430 : _M_dataplus(_M_local_data(), __a
)
432 const _CharT
* __start
= __str
._M_data()
433 + __str
._M_check(__pos
, "basic_string::basic_string");
434 _M_construct(__start
, __start
+ __str
._M_limit(__pos
, npos
));
438 * @brief Construct string as copy of a substring.
439 * @param __str Source string.
440 * @param __pos Index of first character to copy from.
441 * @param __n Number of characters to copy.
443 basic_string(const basic_string
& __str
, size_type __pos
,
445 : _M_dataplus(_M_local_data())
447 const _CharT
* __start
= __str
._M_data()
448 + __str
._M_check(__pos
, "basic_string::basic_string");
449 _M_construct(__start
, __start
+ __str
._M_limit(__pos
, __n
));
453 * @brief Construct string as copy of a substring.
454 * @param __str Source string.
455 * @param __pos Index of first character to copy from.
456 * @param __n Number of characters to copy.
457 * @param __a Allocator to use.
459 basic_string(const basic_string
& __str
, size_type __pos
,
460 size_type __n
, const _Alloc
& __a
)
461 : _M_dataplus(_M_local_data(), __a
)
463 const _CharT
* __start
464 = __str
._M_data() + __str
._M_check(__pos
, "string::string");
465 _M_construct(__start
, __start
+ __str
._M_limit(__pos
, __n
));
469 * @brief Construct string initialized by a character %array.
470 * @param __s Source character %array.
471 * @param __n Number of characters to copy.
472 * @param __a Allocator to use (default is default allocator).
474 * NB: @a __s must have at least @a __n characters, '\\0'
475 * has no special meaning.
477 basic_string(const _CharT
* __s
, size_type __n
,
478 const _Alloc
& __a
= _Alloc())
479 : _M_dataplus(_M_local_data(), __a
)
480 { _M_construct(__s
, __s
+ __n
); }
483 * @brief Construct string as copy of a C string.
484 * @param __s Source C string.
485 * @param __a Allocator to use (default is default allocator).
487 basic_string(const _CharT
* __s
, const _Alloc
& __a
= _Alloc())
488 : _M_dataplus(_M_local_data(), __a
)
489 { _M_construct(__s
, __s
? __s
+ traits_type::length(__s
) : __s
+npos
); }
492 * @brief Construct string as multiple characters.
493 * @param __n Number of characters.
494 * @param __c Character to use.
495 * @param __a Allocator to use (default is default allocator).
497 basic_string(size_type __n
, _CharT __c
, const _Alloc
& __a
= _Alloc())
498 : _M_dataplus(_M_local_data(), __a
)
499 { _M_construct(__n
, __c
); }
501 #if __cplusplus >= 201103L
503 * @brief Move construct string.
504 * @param __str Source string.
506 * The newly-created string contains the exact contents of @a __str.
507 * @a __str is a valid, but unspecified string.
509 basic_string(basic_string
&& __str
) noexcept
510 : _M_dataplus(_M_local_data(), std::move(__str
._M_get_allocator()))
512 if (__str
._M_is_local())
514 traits_type::copy(_M_local_buf
, __str
._M_local_buf
,
515 _S_local_capacity
+ 1);
519 _M_data(__str
._M_data());
520 _M_capacity(__str
._M_allocated_capacity
);
523 // Must use _M_length() here not _M_set_length() because
524 // basic_stringbuf relies on writing into unallocated capacity so
525 // we mess up the contents if we put a '\0' in the string.
526 _M_length(__str
.length());
527 __str
._M_data(__str
._M_local_data());
528 __str
._M_set_length(0);
532 * @brief Construct string from an initializer %list.
533 * @param __l std::initializer_list of characters.
534 * @param __a Allocator to use (default is default allocator).
536 basic_string(initializer_list
<_CharT
> __l
, const _Alloc
& __a
= _Alloc())
537 : _M_dataplus(_M_local_data(), __a
)
538 { _M_construct(__l
.begin(), __l
.end()); }
540 basic_string(const basic_string
& __str
, const _Alloc
& __a
)
541 : _M_dataplus(_M_local_data(), __a
)
542 { _M_construct(__str
.begin(), __str
.end()); }
544 basic_string(basic_string
&& __str
, const _Alloc
& __a
)
545 noexcept(_Alloc_traits::_S_always_equal())
546 : _M_dataplus(_M_local_data(), __a
)
548 if (__str
._M_is_local())
550 traits_type::copy(_M_local_buf
, __str
._M_local_buf
,
551 _S_local_capacity
+ 1);
552 _M_length(__str
.length());
553 __str
._M_set_length(0);
555 else if (_Alloc_traits::_S_always_equal()
556 || __str
.get_allocator() == __a
)
558 _M_data(__str
._M_data());
559 _M_length(__str
.length());
560 _M_capacity(__str
._M_allocated_capacity
);
561 __str
._M_data(__str
._M_local_buf
);
562 __str
._M_set_length(0);
565 _M_construct(__str
.begin(), __str
.end());
571 * @brief Construct string as copy of a range.
572 * @param __beg Start of range.
573 * @param __end End of range.
574 * @param __a Allocator to use (default is default allocator).
576 #if __cplusplus >= 201103L
577 template<typename _InputIterator
,
578 typename
= std::_RequireInputIter
<_InputIterator
>>
580 template<typename _InputIterator
>
582 basic_string(_InputIterator __beg
, _InputIterator __end
,
583 const _Alloc
& __a
= _Alloc())
584 : _M_dataplus(_M_local_data(), __a
)
585 { _M_construct(__beg
, __end
); }
587 #if __cplusplus > 201402L
588 template<typename _Tp
, typename _Res
>
589 using _If_sv
= enable_if_t
<
590 __and_
<is_convertible
<const _Tp
&, __sv_type
>,
591 __not_
<is_convertible
<const _Tp
&, const _CharT
*>>>::value
,
595 * @brief Construct string from a substring of a string_view.
596 * @param __t Source string view.
597 * @param __pos The index of the first character to copy from __t.
598 * @param __n The number of characters to copy from __t.
599 * @param __a Allocator to use.
601 template<typename _Tp
, typename
= _If_sv
<_Tp
, void>>
602 basic_string(const _Tp
& __t
, size_type __pos
, size_type __n
,
603 const _Alloc
& __a
= _Alloc())
604 : basic_string(__sv_type(__t
).substr(__pos
, __n
), __a
) { }
607 * @brief Construct string from a string_view.
608 * @param __sv Source string view.
609 * @param __a Allocator to use (default is default allocator).
612 basic_string(__sv_type __sv
, const _Alloc
& __a
= _Alloc())
613 : basic_string(__sv
.data(), __sv
.size(), __a
) { }
617 * @brief Destroy the string instance.
623 * @brief Assign the value of @a str to this string.
624 * @param __str Source string.
627 operator=(const basic_string
& __str
)
629 #if __cplusplus >= 201103L
630 if (_Alloc_traits::_S_propagate_on_copy_assign())
632 if (!_Alloc_traits::_S_always_equal() && !_M_is_local()
633 && _M_get_allocator() != __str
._M_get_allocator())
635 // replacement allocator cannot free existing storage
636 _M_destroy(_M_allocated_capacity
);
637 _M_data(_M_local_data());
640 std::__alloc_on_copy(_M_get_allocator(), __str
._M_get_allocator());
643 return this->assign(__str
);
647 * @brief Copy contents of @a s into this string.
648 * @param __s Source null-terminated string.
651 operator=(const _CharT
* __s
)
652 { return this->assign(__s
); }
655 * @brief Set value to string of length 1.
656 * @param __c Source character.
658 * Assigning to a character makes this string length 1 and
659 * (*this)[0] == @a c.
662 operator=(_CharT __c
)
664 this->assign(1, __c
);
668 #if __cplusplus >= 201103L
670 * @brief Move assign the value of @a str to this string.
671 * @param __str Source string.
673 * The contents of @a str are moved into this string (without copying).
674 * @a str is a valid, but unspecified string.
676 // PR 58265, this should be noexcept.
677 // _GLIBCXX_RESOLVE_LIB_DEFECTS
678 // 2063. Contradictory requirements for string move assignment
680 operator=(basic_string
&& __str
)
681 noexcept(_Alloc_traits::_S_nothrow_move())
683 if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign()
684 && !_Alloc_traits::_S_always_equal()
685 && _M_get_allocator() != __str
._M_get_allocator())
687 // Destroy existing storage before replacing allocator.
688 _M_destroy(_M_allocated_capacity
);
689 _M_data(_M_local_data());
692 // Replace allocator if POCMA is true.
693 std::__alloc_on_move(_M_get_allocator(), __str
._M_get_allocator());
695 if (!__str
._M_is_local()
696 && (_Alloc_traits::_S_propagate_on_move_assign()
697 || _Alloc_traits::_S_always_equal()))
699 pointer __data
= nullptr;
700 size_type __capacity
;
703 if (_Alloc_traits::_S_always_equal())
706 __capacity
= _M_allocated_capacity
;
709 _M_destroy(_M_allocated_capacity
);
712 _M_data(__str
._M_data());
713 _M_length(__str
.length());
714 _M_capacity(__str
._M_allocated_capacity
);
717 __str
._M_data(__data
);
718 __str
._M_capacity(__capacity
);
721 __str
._M_data(__str
._M_local_buf
);
730 * @brief Set value to string constructed from initializer %list.
731 * @param __l std::initializer_list.
734 operator=(initializer_list
<_CharT
> __l
)
736 this->assign(__l
.begin(), __l
.size());
741 #if __cplusplus > 201402L
743 * @brief Set value to string constructed from a string_view.
744 * @param __sv A string_view.
747 operator=(__sv_type __sv
)
748 { return this->assign(__sv
); }
751 * @brief Convert to a string_view.
752 * @return A string_view.
754 operator __sv_type() const noexcept
755 { return __sv_type(data(), size()); }
760 * Returns a read/write iterator that points to the first character in
764 begin() _GLIBCXX_NOEXCEPT
765 { return iterator(_M_data()); }
768 * Returns a read-only (constant) iterator that points to the first
769 * character in the %string.
772 begin() const _GLIBCXX_NOEXCEPT
773 { return const_iterator(_M_data()); }
776 * Returns a read/write iterator that points one past the last
777 * character in the %string.
780 end() _GLIBCXX_NOEXCEPT
781 { return iterator(_M_data() + this->size()); }
784 * Returns a read-only (constant) iterator that points one past the
785 * last character in the %string.
788 end() const _GLIBCXX_NOEXCEPT
789 { return const_iterator(_M_data() + this->size()); }
792 * Returns a read/write reverse iterator that points to the last
793 * character in the %string. Iteration is done in reverse element
797 rbegin() _GLIBCXX_NOEXCEPT
798 { return reverse_iterator(this->end()); }
801 * Returns a read-only (constant) reverse iterator that points
802 * to the last character in the %string. Iteration is done in
803 * reverse element order.
805 const_reverse_iterator
806 rbegin() const _GLIBCXX_NOEXCEPT
807 { return const_reverse_iterator(this->end()); }
810 * Returns a read/write reverse iterator that points to one before the
811 * first character in the %string. Iteration is done in reverse
815 rend() _GLIBCXX_NOEXCEPT
816 { return reverse_iterator(this->begin()); }
819 * Returns a read-only (constant) reverse iterator that points
820 * to one before the first character in the %string. Iteration
821 * is done in reverse element order.
823 const_reverse_iterator
824 rend() const _GLIBCXX_NOEXCEPT
825 { return const_reverse_iterator(this->begin()); }
827 #if __cplusplus >= 201103L
829 * Returns a read-only (constant) iterator that points to the first
830 * character in the %string.
833 cbegin() const noexcept
834 { return const_iterator(this->_M_data()); }
837 * Returns a read-only (constant) iterator that points one past the
838 * last character in the %string.
841 cend() const noexcept
842 { return const_iterator(this->_M_data() + this->size()); }
845 * Returns a read-only (constant) reverse iterator that points
846 * to the last character in the %string. Iteration is done in
847 * reverse element order.
849 const_reverse_iterator
850 crbegin() const noexcept
851 { return const_reverse_iterator(this->end()); }
854 * Returns a read-only (constant) reverse iterator that points
855 * to one before the first character in the %string. Iteration
856 * is done in reverse element order.
858 const_reverse_iterator
859 crend() const noexcept
860 { return const_reverse_iterator(this->begin()); }
865 /// Returns the number of characters in the string, not including any
866 /// null-termination.
868 size() const _GLIBCXX_NOEXCEPT
869 { return _M_string_length
; }
871 /// Returns the number of characters in the string, not including any
872 /// null-termination.
874 length() const _GLIBCXX_NOEXCEPT
875 { return _M_string_length
; }
877 /// Returns the size() of the largest possible %string.
879 max_size() const _GLIBCXX_NOEXCEPT
880 { return (_Alloc_traits::max_size(_M_get_allocator()) - 1) / 2; }
883 * @brief Resizes the %string to the specified number of characters.
884 * @param __n Number of characters the %string should contain.
885 * @param __c Character to fill any new elements.
887 * This function will %resize the %string to the specified
888 * number of characters. If the number is smaller than the
889 * %string's current size the %string is truncated, otherwise
890 * the %string is extended and new elements are %set to @a __c.
893 resize(size_type __n
, _CharT __c
);
896 * @brief Resizes the %string to the specified number of characters.
897 * @param __n Number of characters the %string should contain.
899 * This function will resize the %string to the specified length. If
900 * the new size is smaller than the %string's current size the %string
901 * is truncated, otherwise the %string is extended and new characters
902 * are default-constructed. For basic types such as char, this means
906 resize(size_type __n
)
907 { this->resize(__n
, _CharT()); }
909 #if __cplusplus >= 201103L
910 /// A non-binding request to reduce capacity() to size().
912 shrink_to_fit() noexcept
915 if (capacity() > size())
927 * Returns the total number of characters that the %string can hold
928 * before needing to allocate more memory.
931 capacity() const _GLIBCXX_NOEXCEPT
933 return _M_is_local() ? size_type(_S_local_capacity
)
934 : _M_allocated_capacity
;
938 * @brief Attempt to preallocate enough memory for specified number of
940 * @param __res_arg Number of characters required.
941 * @throw std::length_error If @a __res_arg exceeds @c max_size().
943 * This function attempts to reserve enough memory for the
944 * %string to hold the specified number of characters. If the
945 * number requested is more than max_size(), length_error is
948 * The advantage of this function is that if optimal code is a
949 * necessity and the user can determine the string length that will be
950 * required, the user can reserve the memory in %advance, and thus
951 * prevent a possible reallocation of memory and copying of %string
955 reserve(size_type __res_arg
= 0);
958 * Erases the string, making it empty.
961 clear() _GLIBCXX_NOEXCEPT
962 { _M_set_length(0); }
965 * Returns true if the %string is empty. Equivalent to
966 * <code>*this == ""</code>.
969 empty() const _GLIBCXX_NOEXCEPT
970 { return this->size() == 0; }
974 * @brief Subscript access to the data contained in the %string.
975 * @param __pos The index of the character to access.
976 * @return Read-only (constant) reference to the character.
978 * This operator allows for easy, array-style, data access.
979 * Note that data access with this operator is unchecked and
980 * out_of_range lookups are not defined. (For checked lookups
984 operator[] (size_type __pos
) const _GLIBCXX_NOEXCEPT
986 __glibcxx_assert(__pos
<= size());
987 return _M_data()[__pos
];
991 * @brief Subscript access to the data contained in the %string.
992 * @param __pos The index of the character to access.
993 * @return Read/write reference to the character.
995 * This operator allows for easy, array-style, data access.
996 * Note that data access with this operator is unchecked and
997 * out_of_range lookups are not defined. (For checked lookups
1001 operator[](size_type __pos
)
1003 // Allow pos == size() both in C++98 mode, as v3 extension,
1004 // and in C++11 mode.
1005 __glibcxx_assert(__pos
<= size());
1006 // In pedantic mode be strict in C++98 mode.
1007 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus
>= 201103L || __pos
< size());
1008 return _M_data()[__pos
];
1012 * @brief Provides access to the data contained in the %string.
1013 * @param __n The index of the character to access.
1014 * @return Read-only (const) reference to the character.
1015 * @throw std::out_of_range If @a n is an invalid index.
1017 * This function provides for safer data access. The parameter is
1018 * first checked that it is in the range of the string. The function
1019 * throws out_of_range if the check fails.
1022 at(size_type __n
) const
1024 if (__n
>= this->size())
1025 __throw_out_of_range_fmt(__N("basic_string::at: __n "
1026 "(which is %zu) >= this->size() "
1029 return _M_data()[__n
];
1033 * @brief Provides access to the data contained in the %string.
1034 * @param __n The index of the character to access.
1035 * @return Read/write reference to the character.
1036 * @throw std::out_of_range If @a n is an invalid index.
1038 * This function provides for safer data access. The parameter is
1039 * first checked that it is in the range of the string. The function
1040 * throws out_of_range if the check fails.
1046 __throw_out_of_range_fmt(__N("basic_string::at: __n "
1047 "(which is %zu) >= this->size() "
1050 return _M_data()[__n
];
1053 #if __cplusplus >= 201103L
1055 * Returns a read/write reference to the data at the first
1056 * element of the %string.
1061 __glibcxx_assert(!empty());
1062 return operator[](0);
1066 * Returns a read-only (constant) reference to the data at the first
1067 * element of the %string.
1070 front() const noexcept
1072 __glibcxx_assert(!empty());
1073 return operator[](0);
1077 * Returns a read/write reference to the data at the last
1078 * element of the %string.
1083 __glibcxx_assert(!empty());
1084 return operator[](this->size() - 1);
1088 * Returns a read-only (constant) reference to the data at the
1089 * last element of the %string.
1092 back() const noexcept
1094 __glibcxx_assert(!empty());
1095 return operator[](this->size() - 1);
1101 * @brief Append a string to this string.
1102 * @param __str The string to append.
1103 * @return Reference to this string.
1106 operator+=(const basic_string
& __str
)
1107 { return this->append(__str
); }
1110 * @brief Append a C string.
1111 * @param __s The C string to append.
1112 * @return Reference to this string.
1115 operator+=(const _CharT
* __s
)
1116 { return this->append(__s
); }
1119 * @brief Append a character.
1120 * @param __c The character to append.
1121 * @return Reference to this string.
1124 operator+=(_CharT __c
)
1126 this->push_back(__c
);
1130 #if __cplusplus >= 201103L
1132 * @brief Append an initializer_list of characters.
1133 * @param __l The initializer_list of characters to be appended.
1134 * @return Reference to this string.
1137 operator+=(initializer_list
<_CharT
> __l
)
1138 { return this->append(__l
.begin(), __l
.size()); }
1141 #if __cplusplus > 201402L
1143 * @brief Append a string_view.
1144 * @param __sv The string_view to be appended.
1145 * @return Reference to this string.
1148 operator+=(__sv_type __sv
)
1149 { return this->append(__sv
); }
1153 * @brief Append a string to this string.
1154 * @param __str The string to append.
1155 * @return Reference to this string.
1158 append(const basic_string
& __str
)
1159 { return _M_append(__str
._M_data(), __str
.size()); }
1162 * @brief Append a substring.
1163 * @param __str The string to append.
1164 * @param __pos Index of the first character of str to append.
1165 * @param __n The number of characters to append.
1166 * @return Reference to this string.
1167 * @throw std::out_of_range if @a __pos is not a valid index.
1169 * This function appends @a __n characters from @a __str
1170 * starting at @a __pos to this string. If @a __n is is larger
1171 * than the number of available characters in @a __str, the
1172 * remainder of @a __str is appended.
1175 append(const basic_string
& __str
, size_type __pos
, size_type __n
)
1176 { return _M_append(__str
._M_data()
1177 + __str
._M_check(__pos
, "basic_string::append"),
1178 __str
._M_limit(__pos
, __n
)); }
1181 * @brief Append a C substring.
1182 * @param __s The C string to append.
1183 * @param __n The number of characters to append.
1184 * @return Reference to this string.
1187 append(const _CharT
* __s
, size_type __n
)
1189 __glibcxx_requires_string_len(__s
, __n
);
1190 _M_check_length(size_type(0), __n
, "basic_string::append");
1191 return _M_append(__s
, __n
);
1195 * @brief Append a C string.
1196 * @param __s The C string to append.
1197 * @return Reference to this string.
1200 append(const _CharT
* __s
)
1202 __glibcxx_requires_string(__s
);
1203 const size_type __n
= traits_type::length(__s
);
1204 _M_check_length(size_type(0), __n
, "basic_string::append");
1205 return _M_append(__s
, __n
);
1209 * @brief Append multiple characters.
1210 * @param __n The number of characters to append.
1211 * @param __c The character to use.
1212 * @return Reference to this string.
1214 * Appends __n copies of __c to this string.
1217 append(size_type __n
, _CharT __c
)
1218 { return _M_replace_aux(this->size(), size_type(0), __n
, __c
); }
1220 #if __cplusplus >= 201103L
1222 * @brief Append an initializer_list of characters.
1223 * @param __l The initializer_list of characters to append.
1224 * @return Reference to this string.
1227 append(initializer_list
<_CharT
> __l
)
1228 { return this->append(__l
.begin(), __l
.size()); }
1232 * @brief Append a range of characters.
1233 * @param __first Iterator referencing the first character to append.
1234 * @param __last Iterator marking the end of the range.
1235 * @return Reference to this string.
1237 * Appends characters in the range [__first,__last) to this string.
1239 #if __cplusplus >= 201103L
1240 template<class _InputIterator
,
1241 typename
= std::_RequireInputIter
<_InputIterator
>>
1243 template<class _InputIterator
>
1246 append(_InputIterator __first
, _InputIterator __last
)
1247 { return this->replace(end(), end(), __first
, __last
); }
1249 #if __cplusplus > 201402L
1251 * @brief Append a string_view.
1252 * @param __sv The string_view to be appended.
1253 * @return Reference to this string.
1256 append(__sv_type __sv
)
1257 { return this->append(__sv
.data(), __sv
.size()); }
1260 * @brief Append a range of characters from a string_view.
1261 * @param __sv The string_view to be appended from.
1262 * @param __pos The position in the string_view to append from.
1263 * @param __n The number of characters to append from the string_view.
1264 * @return Reference to this string.
1266 template <typename _Tp
>
1267 _If_sv
<_Tp
, basic_string
&>
1268 append(const _Tp
& __svt
, size_type __pos
, size_type __n
= npos
)
1270 __sv_type __sv
= __svt
;
1271 return _M_append(__sv
.data()
1272 + __sv
._M_check(__pos
, "basic_string::append"),
1273 __sv
._M_limit(__pos
, __n
));
1278 * @brief Append a single character.
1279 * @param __c Character to append.
1282 push_back(_CharT __c
)
1284 const size_type __size
= this->size();
1285 if (__size
+ 1 > this->capacity())
1286 this->_M_mutate(__size
, size_type(0), 0, size_type(1));
1287 traits_type::assign(this->_M_data()[__size
], __c
);
1288 this->_M_set_length(__size
+ 1);
1292 * @brief Set value to contents of another string.
1293 * @param __str Source string to use.
1294 * @return Reference to this string.
1297 assign(const basic_string
& __str
)
1299 this->_M_assign(__str
);
1303 #if __cplusplus >= 201103L
1305 * @brief Set value to contents of another string.
1306 * @param __str Source string to use.
1307 * @return Reference to this string.
1309 * This function sets this string to the exact contents of @a __str.
1310 * @a __str is a valid, but unspecified string.
1313 assign(basic_string
&& __str
)
1314 noexcept(_Alloc_traits::_S_nothrow_move())
1316 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1317 // 2063. Contradictory requirements for string move assignment
1318 return *this = std::move(__str
);
1323 * @brief Set value to a substring of a string.
1324 * @param __str The string to use.
1325 * @param __pos Index of the first character of str.
1326 * @param __n Number of characters to use.
1327 * @return Reference to this string.
1328 * @throw std::out_of_range if @a pos is not a valid index.
1330 * This function sets this string to the substring of @a __str
1331 * consisting of @a __n characters at @a __pos. If @a __n is
1332 * is larger than the number of available characters in @a
1333 * __str, the remainder of @a __str is used.
1336 assign(const basic_string
& __str
, size_type __pos
, size_type __n
)
1337 { return _M_replace(size_type(0), this->size(), __str
._M_data()
1338 + __str
._M_check(__pos
, "basic_string::assign"),
1339 __str
._M_limit(__pos
, __n
)); }
1342 * @brief Set value to a C substring.
1343 * @param __s The C string to use.
1344 * @param __n Number of characters to use.
1345 * @return Reference to this string.
1347 * This function sets the value of this string to the first @a __n
1348 * characters of @a __s. If @a __n is is larger than the number of
1349 * available characters in @a __s, the remainder of @a __s is used.
1352 assign(const _CharT
* __s
, size_type __n
)
1354 __glibcxx_requires_string_len(__s
, __n
);
1355 return _M_replace(size_type(0), this->size(), __s
, __n
);
1359 * @brief Set value to contents of a C string.
1360 * @param __s The C string to use.
1361 * @return Reference to this string.
1363 * This function sets the value of this string to the value of @a __s.
1364 * The data is copied, so there is no dependence on @a __s once the
1368 assign(const _CharT
* __s
)
1370 __glibcxx_requires_string(__s
);
1371 return _M_replace(size_type(0), this->size(), __s
,
1372 traits_type::length(__s
));
1376 * @brief Set value to multiple characters.
1377 * @param __n Length of the resulting string.
1378 * @param __c The character to use.
1379 * @return Reference to this string.
1381 * This function sets the value of this string to @a __n copies of
1385 assign(size_type __n
, _CharT __c
)
1386 { return _M_replace_aux(size_type(0), this->size(), __n
, __c
); }
1389 * @brief Set value to a range of characters.
1390 * @param __first Iterator referencing the first character to append.
1391 * @param __last Iterator marking the end of the range.
1392 * @return Reference to this string.
1394 * Sets value of string to characters in the range [__first,__last).
1396 #if __cplusplus >= 201103L
1397 template<class _InputIterator
,
1398 typename
= std::_RequireInputIter
<_InputIterator
>>
1400 template<class _InputIterator
>
1403 assign(_InputIterator __first
, _InputIterator __last
)
1404 { return this->replace(begin(), end(), __first
, __last
); }
1406 #if __cplusplus >= 201103L
1408 * @brief Set value to an initializer_list of characters.
1409 * @param __l The initializer_list of characters to assign.
1410 * @return Reference to this string.
1413 assign(initializer_list
<_CharT
> __l
)
1414 { return this->assign(__l
.begin(), __l
.size()); }
1417 #if __cplusplus > 201402L
1419 * @brief Set value from a string_view.
1420 * @param __sv The source string_view.
1421 * @return Reference to this string.
1424 assign(__sv_type __sv
)
1425 { return this->assign(__sv
.data(), __sv
.size()); }
1428 * @brief Set value from a range of characters in a string_view.
1429 * @param __sv The source string_view.
1430 * @param __pos The position in the string_view to assign from.
1431 * @param __n The number of characters to assign.
1432 * @return Reference to this string.
1434 template <typename _Tp
>
1435 _If_sv
<_Tp
, basic_string
&>
1436 assign(const _Tp
& __svt
, size_type __pos
, size_type __n
= npos
)
1438 __sv_type __sv
= __svt
;
1439 return _M_replace(size_type(0), this->size(), __sv
.data()
1440 + __sv
._M_check(__pos
, "basic_string::assign"),
1441 __sv
._M_limit(__pos
, __n
));
1445 #if __cplusplus >= 201103L
1447 * @brief Insert multiple characters.
1448 * @param __p Const_iterator referencing location in string to
1450 * @param __n Number of characters to insert
1451 * @param __c The character to insert.
1452 * @return Iterator referencing the first inserted char.
1453 * @throw std::length_error If new length exceeds @c max_size().
1455 * Inserts @a __n copies of character @a __c starting at the
1456 * position referenced by iterator @a __p. If adding
1457 * characters causes the length to exceed max_size(),
1458 * length_error is thrown. The value of the string doesn't
1459 * change if an error is thrown.
1462 insert(const_iterator __p
, size_type __n
, _CharT __c
)
1464 _GLIBCXX_DEBUG_PEDASSERT(__p
>= begin() && __p
<= end());
1465 const size_type __pos
= __p
- begin();
1466 this->replace(__p
, __p
, __n
, __c
);
1467 return iterator(this->_M_data() + __pos
);
1471 * @brief Insert multiple characters.
1472 * @param __p Iterator referencing location in string to insert at.
1473 * @param __n Number of characters to insert
1474 * @param __c The character to insert.
1475 * @throw std::length_error If new length exceeds @c max_size().
1477 * Inserts @a __n copies of character @a __c starting at the
1478 * position referenced by iterator @a __p. If adding
1479 * characters causes the length to exceed max_size(),
1480 * length_error is thrown. The value of the string doesn't
1481 * change if an error is thrown.
1484 insert(iterator __p
, size_type __n
, _CharT __c
)
1485 { this->replace(__p
, __p
, __n
, __c
); }
1488 #if __cplusplus >= 201103L
1490 * @brief Insert a range of characters.
1491 * @param __p Const_iterator referencing location in string to
1493 * @param __beg Start of range.
1494 * @param __end End of range.
1495 * @return Iterator referencing the first inserted char.
1496 * @throw std::length_error If new length exceeds @c max_size().
1498 * Inserts characters in range [beg,end). If adding characters
1499 * causes the length to exceed max_size(), length_error is
1500 * thrown. The value of the string doesn't change if an error
1503 template<class _InputIterator
,
1504 typename
= std::_RequireInputIter
<_InputIterator
>>
1506 insert(const_iterator __p
, _InputIterator __beg
, _InputIterator __end
)
1508 _GLIBCXX_DEBUG_PEDASSERT(__p
>= begin() && __p
<= end());
1509 const size_type __pos
= __p
- begin();
1510 this->replace(__p
, __p
, __beg
, __end
);
1511 return iterator(this->_M_data() + __pos
);
1515 * @brief Insert a range of characters.
1516 * @param __p Iterator referencing location in string to insert at.
1517 * @param __beg Start of range.
1518 * @param __end End of range.
1519 * @throw std::length_error If new length exceeds @c max_size().
1521 * Inserts characters in range [__beg,__end). If adding
1522 * characters causes the length to exceed max_size(),
1523 * length_error is thrown. The value of the string doesn't
1524 * change if an error is thrown.
1526 template<class _InputIterator
>
1528 insert(iterator __p
, _InputIterator __beg
, _InputIterator __end
)
1529 { this->replace(__p
, __p
, __beg
, __end
); }
1532 #if __cplusplus >= 201103L
1534 * @brief Insert an initializer_list of characters.
1535 * @param __p Iterator referencing location in string to insert at.
1536 * @param __l The initializer_list of characters to insert.
1537 * @throw std::length_error If new length exceeds @c max_size().
1540 insert(iterator __p
, initializer_list
<_CharT
> __l
)
1542 _GLIBCXX_DEBUG_PEDASSERT(__p
>= begin() && __p
<= end());
1543 this->insert(__p
- begin(), __l
.begin(), __l
.size());
1548 * @brief Insert value of a string.
1549 * @param __pos1 Iterator referencing location in string to insert at.
1550 * @param __str The string to insert.
1551 * @return Reference to this string.
1552 * @throw std::length_error If new length exceeds @c max_size().
1554 * Inserts value of @a __str starting at @a __pos1. If adding
1555 * characters causes the length to exceed max_size(),
1556 * length_error is thrown. The value of the string doesn't
1557 * change if an error is thrown.
1560 insert(size_type __pos1
, const basic_string
& __str
)
1561 { return this->replace(__pos1
, size_type(0),
1562 __str
._M_data(), __str
.size()); }
1565 * @brief Insert a substring.
1566 * @param __pos1 Iterator referencing location in string to insert at.
1567 * @param __str The string to insert.
1568 * @param __pos2 Start of characters in str to insert.
1569 * @param __n Number of characters to insert.
1570 * @return Reference to this string.
1571 * @throw std::length_error If new length exceeds @c max_size().
1572 * @throw std::out_of_range If @a pos1 > size() or
1573 * @a __pos2 > @a str.size().
1575 * Starting at @a pos1, insert @a __n character of @a __str
1576 * beginning with @a __pos2. If adding characters causes the
1577 * length to exceed max_size(), length_error is thrown. If @a
1578 * __pos1 is beyond the end of this string or @a __pos2 is
1579 * beyond the end of @a __str, out_of_range is thrown. The
1580 * value of the string doesn't change if an error is thrown.
1583 insert(size_type __pos1
, const basic_string
& __str
,
1584 size_type __pos2
, size_type __n
)
1585 { return this->replace(__pos1
, size_type(0), __str
._M_data()
1586 + __str
._M_check(__pos2
, "basic_string::insert"),
1587 __str
._M_limit(__pos2
, __n
)); }
1590 * @brief Insert a C substring.
1591 * @param __pos Iterator referencing location in string to insert at.
1592 * @param __s The C string to insert.
1593 * @param __n The number of characters to insert.
1594 * @return Reference to this string.
1595 * @throw std::length_error If new length exceeds @c max_size().
1596 * @throw std::out_of_range If @a __pos is beyond the end of this
1599 * Inserts the first @a __n characters of @a __s starting at @a
1600 * __pos. If adding characters causes the length to exceed
1601 * max_size(), length_error is thrown. If @a __pos is beyond
1602 * end(), out_of_range is thrown. The value of the string
1603 * doesn't change if an error is thrown.
1606 insert(size_type __pos
, const _CharT
* __s
, size_type __n
)
1607 { return this->replace(__pos
, size_type(0), __s
, __n
); }
1610 * @brief Insert a C string.
1611 * @param __pos Iterator referencing location in string to insert at.
1612 * @param __s The C string to insert.
1613 * @return Reference to this string.
1614 * @throw std::length_error If new length exceeds @c max_size().
1615 * @throw std::out_of_range If @a pos is beyond the end of this
1618 * Inserts the first @a n characters of @a __s starting at @a __pos. If
1619 * adding characters causes the length to exceed max_size(),
1620 * length_error is thrown. If @a __pos is beyond end(), out_of_range is
1621 * thrown. The value of the string doesn't change if an error is
1625 insert(size_type __pos
, const _CharT
* __s
)
1627 __glibcxx_requires_string(__s
);
1628 return this->replace(__pos
, size_type(0), __s
,
1629 traits_type::length(__s
));
1633 * @brief Insert multiple characters.
1634 * @param __pos Index in string to insert at.
1635 * @param __n Number of characters to insert
1636 * @param __c The character to insert.
1637 * @return Reference to this string.
1638 * @throw std::length_error If new length exceeds @c max_size().
1639 * @throw std::out_of_range If @a __pos is beyond the end of this
1642 * Inserts @a __n copies of character @a __c starting at index
1643 * @a __pos. If adding characters causes the length to exceed
1644 * max_size(), length_error is thrown. If @a __pos > length(),
1645 * out_of_range is thrown. The value of the string doesn't
1646 * change if an error is thrown.
1649 insert(size_type __pos
, size_type __n
, _CharT __c
)
1650 { return _M_replace_aux(_M_check(__pos
, "basic_string::insert"),
1651 size_type(0), __n
, __c
); }
1654 * @brief Insert one character.
1655 * @param __p Iterator referencing position in string to insert at.
1656 * @param __c The character to insert.
1657 * @return Iterator referencing newly inserted char.
1658 * @throw std::length_error If new length exceeds @c max_size().
1660 * Inserts character @a __c at position referenced by @a __p.
1661 * If adding character causes the length to exceed max_size(),
1662 * length_error is thrown. If @a __p is beyond end of string,
1663 * out_of_range is thrown. The value of the string doesn't
1664 * change if an error is thrown.
1667 insert(__const_iterator __p
, _CharT __c
)
1669 _GLIBCXX_DEBUG_PEDASSERT(__p
>= begin() && __p
<= end());
1670 const size_type __pos
= __p
- begin();
1671 _M_replace_aux(__pos
, size_type(0), size_type(1), __c
);
1672 return iterator(_M_data() + __pos
);
1675 #if __cplusplus > 201402L
1677 * @brief Insert a string_view.
1678 * @param __pos Iterator referencing position in string to insert at.
1679 * @param __sv The string_view to insert.
1680 * @return Reference to this string.
1683 insert(size_type __pos
, __sv_type __sv
)
1684 { return this->insert(__pos
, __sv
.data(), __sv
.size()); }
1687 * @brief Insert a string_view.
1688 * @param __pos Iterator referencing position in string to insert at.
1689 * @param __sv The string_view to insert from.
1690 * @param __pos Iterator referencing position in string_view to insert
1692 * @param __n The number of characters to insert.
1693 * @return Reference to this string.
1695 template <typename _Tp
>
1696 _If_sv
<_Tp
, basic_string
&>
1697 insert(size_type __pos1
, const _Tp
& __svt
,
1698 size_type __pos2
, size_type __n
= npos
)
1700 __sv_type __sv
= __svt
;
1701 return this->replace(__pos1
, size_type(0), __sv
.data()
1702 + __sv
._M_check(__pos2
, "basic_string::insert"),
1703 __sv
._M_limit(__pos2
, __n
));
1708 * @brief Remove characters.
1709 * @param __pos Index of first character to remove (default 0).
1710 * @param __n Number of characters to remove (default remainder).
1711 * @return Reference to this string.
1712 * @throw std::out_of_range If @a pos is beyond the end of this
1715 * Removes @a __n characters from this string starting at @a
1716 * __pos. The length of the string is reduced by @a __n. If
1717 * there are < @a __n characters to remove, the remainder of
1718 * the string is truncated. If @a __p is beyond end of string,
1719 * out_of_range is thrown. The value of the string doesn't
1720 * change if an error is thrown.
1723 erase(size_type __pos
= 0, size_type __n
= npos
)
1725 _M_check(__pos
, "basic_string::erase");
1727 this->_M_set_length(__pos
);
1729 this->_M_erase(__pos
, _M_limit(__pos
, __n
));
1734 * @brief Remove one character.
1735 * @param __position Iterator referencing the character to remove.
1736 * @return iterator referencing same location after removal.
1738 * Removes the character at @a __position from this string. The value
1739 * of the string doesn't change if an error is thrown.
1742 erase(__const_iterator __position
)
1744 _GLIBCXX_DEBUG_PEDASSERT(__position
>= begin()
1745 && __position
< end());
1746 const size_type __pos
= __position
- begin();
1747 this->_M_erase(__pos
, size_type(1));
1748 return iterator(_M_data() + __pos
);
1752 * @brief Remove a range of characters.
1753 * @param __first Iterator referencing the first character to remove.
1754 * @param __last Iterator referencing the end of the range.
1755 * @return Iterator referencing location of first after removal.
1757 * Removes the characters in the range [first,last) from this string.
1758 * The value of the string doesn't change if an error is thrown.
1761 erase(__const_iterator __first
, __const_iterator __last
)
1763 _GLIBCXX_DEBUG_PEDASSERT(__first
>= begin() && __first
<= __last
1764 && __last
<= end());
1765 const size_type __pos
= __first
- begin();
1766 if (__last
== end())
1767 this->_M_set_length(__pos
);
1769 this->_M_erase(__pos
, __last
- __first
);
1770 return iterator(this->_M_data() + __pos
);
1773 #if __cplusplus >= 201103L
1775 * @brief Remove the last character.
1777 * The string must be non-empty.
1782 __glibcxx_assert(!empty());
1783 _M_erase(size() - 1, 1);
1788 * @brief Replace characters with value from another string.
1789 * @param __pos Index of first character to replace.
1790 * @param __n Number of characters to be replaced.
1791 * @param __str String to insert.
1792 * @return Reference to this string.
1793 * @throw std::out_of_range If @a pos is beyond the end of this
1795 * @throw std::length_error If new length exceeds @c max_size().
1797 * Removes the characters in the range [__pos,__pos+__n) from
1798 * this string. In place, the value of @a __str is inserted.
1799 * If @a __pos is beyond end of string, out_of_range is thrown.
1800 * If the length of the result exceeds max_size(), length_error
1801 * is thrown. The value of the string doesn't change if an
1805 replace(size_type __pos
, size_type __n
, const basic_string
& __str
)
1806 { return this->replace(__pos
, __n
, __str
._M_data(), __str
.size()); }
1809 * @brief Replace characters with value from another string.
1810 * @param __pos1 Index of first character to replace.
1811 * @param __n1 Number of characters to be replaced.
1812 * @param __str String to insert.
1813 * @param __pos2 Index of first character of str to use.
1814 * @param __n2 Number of characters from str to use.
1815 * @return Reference to this string.
1816 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
1818 * @throw std::length_error If new length exceeds @c max_size().
1820 * Removes the characters in the range [__pos1,__pos1 + n) from this
1821 * string. In place, the value of @a __str is inserted. If @a __pos is
1822 * beyond end of string, out_of_range is thrown. If the length of the
1823 * result exceeds max_size(), length_error is thrown. The value of the
1824 * string doesn't change if an error is thrown.
1827 replace(size_type __pos1
, size_type __n1
, const basic_string
& __str
,
1828 size_type __pos2
, size_type __n2
)
1829 { return this->replace(__pos1
, __n1
, __str
._M_data()
1830 + __str
._M_check(__pos2
, "basic_string::replace"),
1831 __str
._M_limit(__pos2
, __n2
)); }
1834 * @brief Replace characters with value of a C substring.
1835 * @param __pos Index of first character to replace.
1836 * @param __n1 Number of characters to be replaced.
1837 * @param __s C string to insert.
1838 * @param __n2 Number of characters from @a s to use.
1839 * @return Reference to this string.
1840 * @throw std::out_of_range If @a pos1 > size().
1841 * @throw std::length_error If new length exceeds @c max_size().
1843 * Removes the characters in the range [__pos,__pos + __n1)
1844 * from this string. In place, the first @a __n2 characters of
1845 * @a __s are inserted, or all of @a __s if @a __n2 is too large. If
1846 * @a __pos is beyond end of string, out_of_range is thrown. If
1847 * the length of result exceeds max_size(), length_error is
1848 * thrown. The value of the string doesn't change if an error
1852 replace(size_type __pos
, size_type __n1
, const _CharT
* __s
,
1855 __glibcxx_requires_string_len(__s
, __n2
);
1856 return _M_replace(_M_check(__pos
, "basic_string::replace"),
1857 _M_limit(__pos
, __n1
), __s
, __n2
);
1861 * @brief Replace characters with value of a C string.
1862 * @param __pos Index of first character to replace.
1863 * @param __n1 Number of characters to be replaced.
1864 * @param __s C string to insert.
1865 * @return Reference to this string.
1866 * @throw std::out_of_range If @a pos > size().
1867 * @throw std::length_error If new length exceeds @c max_size().
1869 * Removes the characters in the range [__pos,__pos + __n1)
1870 * from this string. In place, the characters of @a __s are
1871 * inserted. If @a __pos is beyond end of string, out_of_range
1872 * is thrown. If the length of result exceeds max_size(),
1873 * length_error is thrown. The value of the string doesn't
1874 * change if an error is thrown.
1877 replace(size_type __pos
, size_type __n1
, const _CharT
* __s
)
1879 __glibcxx_requires_string(__s
);
1880 return this->replace(__pos
, __n1
, __s
, traits_type::length(__s
));
1884 * @brief Replace characters with multiple characters.
1885 * @param __pos Index of first character to replace.
1886 * @param __n1 Number of characters to be replaced.
1887 * @param __n2 Number of characters to insert.
1888 * @param __c Character to insert.
1889 * @return Reference to this string.
1890 * @throw std::out_of_range If @a __pos > size().
1891 * @throw std::length_error If new length exceeds @c max_size().
1893 * Removes the characters in the range [pos,pos + n1) from this
1894 * string. In place, @a __n2 copies of @a __c are inserted.
1895 * If @a __pos is beyond end of string, out_of_range is thrown.
1896 * If the length of result exceeds max_size(), length_error is
1897 * thrown. The value of the string doesn't change if an error
1901 replace(size_type __pos
, size_type __n1
, size_type __n2
, _CharT __c
)
1902 { return _M_replace_aux(_M_check(__pos
, "basic_string::replace"),
1903 _M_limit(__pos
, __n1
), __n2
, __c
); }
1906 * @brief Replace range of characters with string.
1907 * @param __i1 Iterator referencing start of range to replace.
1908 * @param __i2 Iterator referencing end of range to replace.
1909 * @param __str String value to insert.
1910 * @return Reference to this string.
1911 * @throw std::length_error If new length exceeds @c max_size().
1913 * Removes the characters in the range [__i1,__i2). In place,
1914 * the value of @a __str is inserted. If the length of result
1915 * exceeds max_size(), length_error is thrown. The value of
1916 * the string doesn't change if an error is thrown.
1919 replace(__const_iterator __i1
, __const_iterator __i2
,
1920 const basic_string
& __str
)
1921 { return this->replace(__i1
, __i2
, __str
._M_data(), __str
.size()); }
1924 * @brief Replace range of characters with C substring.
1925 * @param __i1 Iterator referencing start of range to replace.
1926 * @param __i2 Iterator referencing end of range to replace.
1927 * @param __s C string value to insert.
1928 * @param __n Number of characters from s to insert.
1929 * @return Reference to this string.
1930 * @throw std::length_error If new length exceeds @c max_size().
1932 * Removes the characters in the range [__i1,__i2). In place,
1933 * the first @a __n characters of @a __s are inserted. If the
1934 * length of result exceeds max_size(), length_error is thrown.
1935 * The value of the string doesn't change if an error is
1939 replace(__const_iterator __i1
, __const_iterator __i2
,
1940 const _CharT
* __s
, size_type __n
)
1942 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
1944 return this->replace(__i1
- begin(), __i2
- __i1
, __s
, __n
);
1948 * @brief Replace range of characters with C string.
1949 * @param __i1 Iterator referencing start of range to replace.
1950 * @param __i2 Iterator referencing end of range to replace.
1951 * @param __s C string value to insert.
1952 * @return Reference to this string.
1953 * @throw std::length_error If new length exceeds @c max_size().
1955 * Removes the characters in the range [__i1,__i2). In place,
1956 * the characters of @a __s are inserted. If the length of
1957 * result exceeds max_size(), length_error is thrown. The
1958 * value of the string doesn't change if an error is thrown.
1961 replace(__const_iterator __i1
, __const_iterator __i2
, const _CharT
* __s
)
1963 __glibcxx_requires_string(__s
);
1964 return this->replace(__i1
, __i2
, __s
, traits_type::length(__s
));
1968 * @brief Replace range of characters with multiple characters
1969 * @param __i1 Iterator referencing start of range to replace.
1970 * @param __i2 Iterator referencing end of range to replace.
1971 * @param __n Number of characters to insert.
1972 * @param __c Character to insert.
1973 * @return Reference to this string.
1974 * @throw std::length_error If new length exceeds @c max_size().
1976 * Removes the characters in the range [__i1,__i2). In place,
1977 * @a __n copies of @a __c are inserted. If the length of
1978 * result exceeds max_size(), length_error is thrown. The
1979 * value of the string doesn't change if an error is thrown.
1982 replace(__const_iterator __i1
, __const_iterator __i2
, size_type __n
,
1985 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
1987 return _M_replace_aux(__i1
- begin(), __i2
- __i1
, __n
, __c
);
1991 * @brief Replace range of characters with range.
1992 * @param __i1 Iterator referencing start of range to replace.
1993 * @param __i2 Iterator referencing end of range to replace.
1994 * @param __k1 Iterator referencing start of range to insert.
1995 * @param __k2 Iterator referencing end of range to insert.
1996 * @return Reference to this string.
1997 * @throw std::length_error If new length exceeds @c max_size().
1999 * Removes the characters in the range [__i1,__i2). In place,
2000 * characters in the range [__k1,__k2) are inserted. If the
2001 * length of result exceeds max_size(), length_error is thrown.
2002 * The value of the string doesn't change if an error is
2005 #if __cplusplus >= 201103L
2006 template<class _InputIterator
,
2007 typename
= std::_RequireInputIter
<_InputIterator
>>
2009 replace(const_iterator __i1
, const_iterator __i2
,
2010 _InputIterator __k1
, _InputIterator __k2
)
2012 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
2014 __glibcxx_requires_valid_range(__k1
, __k2
);
2015 return this->_M_replace_dispatch(__i1
, __i2
, __k1
, __k2
,
2016 std::__false_type());
2019 template<class _InputIterator
>
2020 #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
2021 typename __enable_if_not_native_iterator
<_InputIterator
>::__type
2025 replace(iterator __i1
, iterator __i2
,
2026 _InputIterator __k1
, _InputIterator __k2
)
2028 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
2030 __glibcxx_requires_valid_range(__k1
, __k2
);
2031 typedef typename
std::__is_integer
<_InputIterator
>::__type _Integral
;
2032 return _M_replace_dispatch(__i1
, __i2
, __k1
, __k2
, _Integral());
2036 // Specializations for the common case of pointer and iterator:
2037 // useful to avoid the overhead of temporary buffering in _M_replace.
2039 replace(__const_iterator __i1
, __const_iterator __i2
,
2040 _CharT
* __k1
, _CharT
* __k2
)
2042 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
2044 __glibcxx_requires_valid_range(__k1
, __k2
);
2045 return this->replace(__i1
- begin(), __i2
- __i1
,
2050 replace(__const_iterator __i1
, __const_iterator __i2
,
2051 const _CharT
* __k1
, const _CharT
* __k2
)
2053 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
2055 __glibcxx_requires_valid_range(__k1
, __k2
);
2056 return this->replace(__i1
- begin(), __i2
- __i1
,
2061 replace(__const_iterator __i1
, __const_iterator __i2
,
2062 iterator __k1
, iterator __k2
)
2064 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
2066 __glibcxx_requires_valid_range(__k1
, __k2
);
2067 return this->replace(__i1
- begin(), __i2
- __i1
,
2068 __k1
.base(), __k2
- __k1
);
2072 replace(__const_iterator __i1
, __const_iterator __i2
,
2073 const_iterator __k1
, const_iterator __k2
)
2075 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1
&& __i1
<= __i2
2077 __glibcxx_requires_valid_range(__k1
, __k2
);
2078 return this->replace(__i1
- begin(), __i2
- __i1
,
2079 __k1
.base(), __k2
- __k1
);
2082 #if __cplusplus >= 201103L
2084 * @brief Replace range of characters with initializer_list.
2085 * @param __i1 Iterator referencing start of range to replace.
2086 * @param __i2 Iterator referencing end of range to replace.
2087 * @param __l The initializer_list of characters to insert.
2088 * @return Reference to this string.
2089 * @throw std::length_error If new length exceeds @c max_size().
2091 * Removes the characters in the range [__i1,__i2). In place,
2092 * characters in the range [__k1,__k2) are inserted. If the
2093 * length of result exceeds max_size(), length_error is thrown.
2094 * The value of the string doesn't change if an error is
2097 basic_string
& replace(const_iterator __i1
, const_iterator __i2
,
2098 initializer_list
<_CharT
> __l
)
2099 { return this->replace(__i1
, __i2
, __l
.begin(), __l
.size()); }
2102 #if __cplusplus > 201402L
2104 * @brief Replace range of characters with string_view.
2105 * @param __pos The position to replace at.
2106 * @param __n The number of characters to replace.
2107 * @param __sv The string_view to insert.
2108 * @return Reference to this string.
2111 replace(size_type __pos
, size_type __n
, __sv_type __sv
)
2112 { return this->replace(__pos
, __n
, __sv
.data(), __sv
.size()); }
2115 * @brief Replace range of characters with string_view.
2116 * @param __pos1 The position to replace at.
2117 * @param __n1 The number of characters to replace.
2118 * @param __sv The string_view to insert from.
2119 * @param __pos2 The position in the string_view to insert from.
2120 * @param __n2 The number of characters to insert.
2121 * @return Reference to this string.
2123 template <typename _Tp
>
2124 _If_sv
<_Tp
, basic_string
&>
2125 replace(size_type __pos1
, size_type __n1
, const _Tp
& __svt
,
2126 size_type __pos2
, size_type __n2
= npos
)
2128 __sv_type __sv
= __svt
;
2129 return this->replace(__pos1
, __n1
, __sv
.data()
2130 + __sv
._M_check(__pos2
, "basic_string::replace"),
2131 __sv
._M_limit(__pos2
, __n2
));
2135 * @brief Replace range of characters with string_view.
2136 * @param __i1 An iterator referencing the start position
2138 * @param __i2 An iterator referencing the end position
2140 * @param __sv The string_view to insert from.
2141 * @return Reference to this string.
2144 replace(const_iterator __i1
, const_iterator __i2
, __sv_type __sv
)
2145 { return this->replace(__i1
- begin(), __i2
- __i1
, __sv
); }
2149 template<class _Integer
>
2151 _M_replace_dispatch(const_iterator __i1
, const_iterator __i2
,
2152 _Integer __n
, _Integer __val
, __true_type
)
2153 { return _M_replace_aux(__i1
- begin(), __i2
- __i1
, __n
, __val
); }
2155 template<class _InputIterator
>
2157 _M_replace_dispatch(const_iterator __i1
, const_iterator __i2
,
2158 _InputIterator __k1
, _InputIterator __k2
,
2162 _M_replace_aux(size_type __pos1
, size_type __n1
, size_type __n2
,
2166 _M_replace(size_type __pos
, size_type __len1
, const _CharT
* __s
,
2167 const size_type __len2
);
2170 _M_append(const _CharT
* __s
, size_type __n
);
2175 * @brief Copy substring into C string.
2176 * @param __s C string to copy value into.
2177 * @param __n Number of characters to copy.
2178 * @param __pos Index of first character to copy.
2179 * @return Number of characters actually copied
2180 * @throw std::out_of_range If __pos > size().
2182 * Copies up to @a __n characters starting at @a __pos into the
2183 * C string @a __s. If @a __pos is %greater than size(),
2184 * out_of_range is thrown.
2187 copy(_CharT
* __s
, size_type __n
, size_type __pos
= 0) const;
2190 * @brief Swap contents with another string.
2191 * @param __s String to swap with.
2193 * Exchanges the contents of this string with that of @a __s in constant
2197 swap(basic_string
& __s
) _GLIBCXX_NOEXCEPT
;
2199 // String operations:
2201 * @brief Return const pointer to null-terminated contents.
2203 * This is a handle to internal data. Do not modify or dire things may
2207 c_str() const _GLIBCXX_NOEXCEPT
2208 { return _M_data(); }
2211 * @brief Return const pointer to contents.
2213 * This is a pointer to internal data. It is undefined to modify
2214 * the contents through the returned pointer. To get a pointer that
2215 * allows modifying the contents use @c &str[0] instead,
2216 * (or in C++17 the non-const @c str.data() overload).
2219 data() const _GLIBCXX_NOEXCEPT
2220 { return _M_data(); }
2222 #if __cplusplus > 201402L
2224 * @brief Return non-const pointer to contents.
2226 * This is a pointer to the character sequence held by the string.
2227 * Modifying the characters in the sequence is allowed.
2231 { return _M_data(); }
2235 * @brief Return copy of allocator used to construct this string.
2238 get_allocator() const _GLIBCXX_NOEXCEPT
2239 { return _M_get_allocator(); }
2242 * @brief Find position of a C substring.
2243 * @param __s C string to locate.
2244 * @param __pos Index of character to search from.
2245 * @param __n Number of characters from @a s to search for.
2246 * @return Index of start of first occurrence.
2248 * Starting from @a __pos, searches forward for the first @a
2249 * __n characters in @a __s within this string. If found,
2250 * returns the index where it begins. If not found, returns
2254 find(const _CharT
* __s
, size_type __pos
, size_type __n
) const
2258 * @brief Find position of a string.
2259 * @param __str String to locate.
2260 * @param __pos Index of character to search from (default 0).
2261 * @return Index of start of first occurrence.
2263 * Starting from @a __pos, searches forward for value of @a __str within
2264 * this string. If found, returns the index where it begins. If not
2265 * found, returns npos.
2268 find(const basic_string
& __str
, size_type __pos
= 0) const
2270 { return this->find(__str
.data(), __pos
, __str
.size()); }
2272 #if __cplusplus > 201402L
2274 * @brief Find position of a string_view.
2275 * @param __sv The string_view to locate.
2276 * @param __pos Index of character to search from (default 0).
2277 * @return Index of start of first occurrence.
2280 find(__sv_type __sv
, size_type __pos
= 0) const noexcept
2281 { return this->find(__sv
.data(), __pos
, __sv
.size()); }
2285 * @brief Find position of a C string.
2286 * @param __s C string to locate.
2287 * @param __pos Index of character to search from (default 0).
2288 * @return Index of start of first occurrence.
2290 * Starting from @a __pos, searches forward for the value of @a
2291 * __s within this string. If found, returns the index where
2292 * it begins. If not found, returns npos.
2295 find(const _CharT
* __s
, size_type __pos
= 0) const _GLIBCXX_NOEXCEPT
2297 __glibcxx_requires_string(__s
);
2298 return this->find(__s
, __pos
, traits_type::length(__s
));
2302 * @brief Find position of a character.
2303 * @param __c Character to locate.
2304 * @param __pos Index of character to search from (default 0).
2305 * @return Index of first occurrence.
2307 * Starting from @a __pos, searches forward for @a __c within
2308 * this string. If found, returns the index where it was
2309 * found. If not found, returns npos.
2312 find(_CharT __c
, size_type __pos
= 0) const _GLIBCXX_NOEXCEPT
;
2315 * @brief Find last position of a string.
2316 * @param __str String to locate.
2317 * @param __pos Index of character to search back from (default end).
2318 * @return Index of start of last occurrence.
2320 * Starting from @a __pos, searches backward for value of @a
2321 * __str within this string. If found, returns the index where
2322 * it begins. If not found, returns npos.
2325 rfind(const basic_string
& __str
, size_type __pos
= npos
) const
2327 { return this->rfind(__str
.data(), __pos
, __str
.size()); }
2329 #if __cplusplus > 201402L
2331 * @brief Find last position of a string_view.
2332 * @param __sv The string_view to locate.
2333 * @param __pos Index of character to search back from (default end).
2334 * @return Index of start of last occurrence.
2337 rfind(__sv_type __sv
, size_type __pos
= npos
) const noexcept
2338 { return this->rfind(__sv
.data(), __pos
, __sv
.size()); }
2342 * @brief Find last position of a C substring.
2343 * @param __s C string to locate.
2344 * @param __pos Index of character to search back from.
2345 * @param __n Number of characters from s to search for.
2346 * @return Index of start of last occurrence.
2348 * Starting from @a __pos, searches backward for the first @a
2349 * __n characters in @a __s within this string. If found,
2350 * returns the index where it begins. If not found, returns
2354 rfind(const _CharT
* __s
, size_type __pos
, size_type __n
) const
2358 * @brief Find last position of a C string.
2359 * @param __s C string to locate.
2360 * @param __pos Index of character to start search at (default end).
2361 * @return Index of start of last occurrence.
2363 * Starting from @a __pos, searches backward for the value of
2364 * @a __s within this string. If found, returns the index
2365 * where it begins. If not found, returns npos.
2368 rfind(const _CharT
* __s
, size_type __pos
= npos
) const
2370 __glibcxx_requires_string(__s
);
2371 return this->rfind(__s
, __pos
, traits_type::length(__s
));
2375 * @brief Find last position of a character.
2376 * @param __c Character to locate.
2377 * @param __pos Index of character to search back from (default end).
2378 * @return Index of last occurrence.
2380 * Starting from @a __pos, searches backward for @a __c within
2381 * this string. If found, returns the index where it was
2382 * found. If not found, returns npos.
2385 rfind(_CharT __c
, size_type __pos
= npos
) const _GLIBCXX_NOEXCEPT
;
2388 * @brief Find position of a character of string.
2389 * @param __str String containing characters to locate.
2390 * @param __pos Index of character to search from (default 0).
2391 * @return Index of first occurrence.
2393 * Starting from @a __pos, searches forward for one of the
2394 * characters of @a __str within this string. If found,
2395 * returns the index where it was found. If not found, returns
2399 find_first_of(const basic_string
& __str
, size_type __pos
= 0) const
2401 { return this->find_first_of(__str
.data(), __pos
, __str
.size()); }
2403 #if __cplusplus > 201402L
2405 * @brief Find position of a character of a string_view.
2406 * @param __sv A string_view containing characters to locate.
2407 * @param __pos Index of character to search from (default 0).
2408 * @return Index of first occurrence.
2411 find_first_of(__sv_type __sv
, size_type __pos
= 0) const noexcept
2412 { return this->find_first_of(__sv
.data(), __pos
, __sv
.size()); }
2416 * @brief Find position of a character of C substring.
2417 * @param __s String containing characters to locate.
2418 * @param __pos Index of character to search from.
2419 * @param __n Number of characters from s to search for.
2420 * @return Index of first occurrence.
2422 * Starting from @a __pos, searches forward for one of the
2423 * first @a __n characters of @a __s within this string. If
2424 * found, returns the index where it was found. If not found,
2428 find_first_of(const _CharT
* __s
, size_type __pos
, size_type __n
) const
2432 * @brief Find position of a character of C string.
2433 * @param __s String containing characters to locate.
2434 * @param __pos Index of character to search from (default 0).
2435 * @return Index of first occurrence.
2437 * Starting from @a __pos, searches forward for one of the
2438 * characters of @a __s within this string. If found, returns
2439 * the index where it was found. If not found, returns npos.
2442 find_first_of(const _CharT
* __s
, size_type __pos
= 0) const
2445 __glibcxx_requires_string(__s
);
2446 return this->find_first_of(__s
, __pos
, traits_type::length(__s
));
2450 * @brief Find position of a character.
2451 * @param __c Character to locate.
2452 * @param __pos Index of character to search from (default 0).
2453 * @return Index of first occurrence.
2455 * Starting from @a __pos, searches forward for the character
2456 * @a __c within this string. If found, returns the index
2457 * where it was found. If not found, returns npos.
2459 * Note: equivalent to find(__c, __pos).
2462 find_first_of(_CharT __c
, size_type __pos
= 0) const _GLIBCXX_NOEXCEPT
2463 { return this->find(__c
, __pos
); }
2466 * @brief Find last position of a character of string.
2467 * @param __str String containing characters to locate.
2468 * @param __pos Index of character to search back from (default end).
2469 * @return Index of last occurrence.
2471 * Starting from @a __pos, searches backward for one of the
2472 * characters of @a __str within this string. If found,
2473 * returns the index where it was found. If not found, returns
2477 find_last_of(const basic_string
& __str
, size_type __pos
= npos
) const
2479 { return this->find_last_of(__str
.data(), __pos
, __str
.size()); }
2481 #if __cplusplus > 201402L
2483 * @brief Find last position of a character of string.
2484 * @param __sv A string_view containing characters to locate.
2485 * @param __pos Index of character to search back from (default end).
2486 * @return Index of last occurrence.
2489 find_last_of(__sv_type __sv
, size_type __pos
= npos
) const noexcept
2490 { return this->find_last_of(__sv
.data(), __pos
, __sv
.size()); }
2494 * @brief Find last position of a character of C substring.
2495 * @param __s C string containing characters to locate.
2496 * @param __pos Index of character to search back from.
2497 * @param __n Number of characters from s to search for.
2498 * @return Index of last occurrence.
2500 * Starting from @a __pos, searches backward for one of the
2501 * first @a __n characters of @a __s within this string. If
2502 * found, returns the index where it was found. If not found,
2506 find_last_of(const _CharT
* __s
, size_type __pos
, size_type __n
) const
2510 * @brief Find last position of a character of C string.
2511 * @param __s C string containing characters to locate.
2512 * @param __pos Index of character to search back from (default end).
2513 * @return Index of last occurrence.
2515 * Starting from @a __pos, searches backward for one of the
2516 * characters of @a __s within this string. If found, returns
2517 * the index where it was found. If not found, returns npos.
2520 find_last_of(const _CharT
* __s
, size_type __pos
= npos
) const
2523 __glibcxx_requires_string(__s
);
2524 return this->find_last_of(__s
, __pos
, traits_type::length(__s
));
2528 * @brief Find last position of a character.
2529 * @param __c Character to locate.
2530 * @param __pos Index of character to search back from (default end).
2531 * @return Index of last occurrence.
2533 * Starting from @a __pos, searches backward for @a __c within
2534 * this string. If found, returns the index where it was
2535 * found. If not found, returns npos.
2537 * Note: equivalent to rfind(__c, __pos).
2540 find_last_of(_CharT __c
, size_type __pos
= npos
) const _GLIBCXX_NOEXCEPT
2541 { return this->rfind(__c
, __pos
); }
2544 * @brief Find position of a character not in string.
2545 * @param __str String containing characters to avoid.
2546 * @param __pos Index of character to search from (default 0).
2547 * @return Index of first occurrence.
2549 * Starting from @a __pos, searches forward for a character not contained
2550 * in @a __str within this string. If found, returns the index where it
2551 * was found. If not found, returns npos.
2554 find_first_not_of(const basic_string
& __str
, size_type __pos
= 0) const
2556 { return this->find_first_not_of(__str
.data(), __pos
, __str
.size()); }
2558 #if __cplusplus > 201402L
2560 * @brief Find position of a character not in a string_view.
2561 * @param __sv A string_view containing characters to avoid.
2562 * @param __pos Index of character to search from (default 0).
2563 * @return Index of first occurrence.
2566 find_first_not_of(__sv_type __sv
, size_type __pos
= 0) const noexcept
2567 { return this->find_first_not_of(__sv
.data(), __pos
, __sv
.size()); }
2571 * @brief Find position of a character not in C substring.
2572 * @param __s C string containing characters to avoid.
2573 * @param __pos Index of character to search from.
2574 * @param __n Number of characters from __s to consider.
2575 * @return Index of first occurrence.
2577 * Starting from @a __pos, searches forward for a character not
2578 * contained in the first @a __n characters of @a __s within
2579 * this string. If found, returns the index where it was
2580 * found. If not found, returns npos.
2583 find_first_not_of(const _CharT
* __s
, size_type __pos
,
2584 size_type __n
) const _GLIBCXX_NOEXCEPT
;
2587 * @brief Find position of a character not in C string.
2588 * @param __s C string containing characters to avoid.
2589 * @param __pos Index of character to search from (default 0).
2590 * @return Index of first occurrence.
2592 * Starting from @a __pos, searches forward for a character not
2593 * contained in @a __s within this string. If found, returns
2594 * the index where it was found. If not found, returns npos.
2597 find_first_not_of(const _CharT
* __s
, size_type __pos
= 0) const
2600 __glibcxx_requires_string(__s
);
2601 return this->find_first_not_of(__s
, __pos
, traits_type::length(__s
));
2605 * @brief Find position of a different character.
2606 * @param __c Character to avoid.
2607 * @param __pos Index of character to search from (default 0).
2608 * @return Index of first occurrence.
2610 * Starting from @a __pos, searches forward for a character
2611 * other than @a __c within this string. If found, returns the
2612 * index where it was found. If not found, returns npos.
2615 find_first_not_of(_CharT __c
, size_type __pos
= 0) const
2619 * @brief Find last position of a character not in string.
2620 * @param __str String containing characters to avoid.
2621 * @param __pos Index of character to search back from (default end).
2622 * @return Index of last occurrence.
2624 * Starting from @a __pos, searches backward for a character
2625 * not contained in @a __str within this string. If found,
2626 * returns the index where it was found. If not found, returns
2630 find_last_not_of(const basic_string
& __str
, size_type __pos
= npos
) const
2632 { return this->find_last_not_of(__str
.data(), __pos
, __str
.size()); }
2634 #if __cplusplus > 201402L
2636 * @brief Find last position of a character not in a string_view.
2637 * @param __sv A string_view containing characters to avoid.
2638 * @param __pos Index of character to search back from (default end).
2639 * @return Index of last occurrence.
2642 find_last_not_of(__sv_type __sv
, size_type __pos
= npos
) const noexcept
2643 { return this->find_last_not_of(__sv
.data(), __pos
, __sv
.size()); }
2647 * @brief Find last position of a character not in C substring.
2648 * @param __s C string containing characters to avoid.
2649 * @param __pos Index of character to search back from.
2650 * @param __n Number of characters from s to consider.
2651 * @return Index of last occurrence.
2653 * Starting from @a __pos, searches backward for a character not
2654 * contained in the first @a __n characters of @a __s within this string.
2655 * If found, returns the index where it was found. If not found,
2659 find_last_not_of(const _CharT
* __s
, size_type __pos
,
2660 size_type __n
) const _GLIBCXX_NOEXCEPT
;
2662 * @brief Find last position of a character not in C string.
2663 * @param __s C string containing characters to avoid.
2664 * @param __pos Index of character to search back from (default end).
2665 * @return Index of last occurrence.
2667 * Starting from @a __pos, searches backward for a character
2668 * not contained in @a __s within this string. If found,
2669 * returns the index where it was found. If not found, returns
2673 find_last_not_of(const _CharT
* __s
, size_type __pos
= npos
) const
2676 __glibcxx_requires_string(__s
);
2677 return this->find_last_not_of(__s
, __pos
, traits_type::length(__s
));
2681 * @brief Find last position of a different character.
2682 * @param __c Character to avoid.
2683 * @param __pos Index of character to search back from (default end).
2684 * @return Index of last occurrence.
2686 * Starting from @a __pos, searches backward for a character other than
2687 * @a __c within this string. If found, returns the index where it was
2688 * found. If not found, returns npos.
2691 find_last_not_of(_CharT __c
, size_type __pos
= npos
) const
2695 * @brief Get a substring.
2696 * @param __pos Index of first character (default 0).
2697 * @param __n Number of characters in substring (default remainder).
2698 * @return The new string.
2699 * @throw std::out_of_range If __pos > size().
2701 * Construct and return a new string using the @a __n
2702 * characters starting at @a __pos. If the string is too
2703 * short, use the remainder of the characters. If @a __pos is
2704 * beyond the end of the string, out_of_range is thrown.
2707 substr(size_type __pos
= 0, size_type __n
= npos
) const
2708 { return basic_string(*this,
2709 _M_check(__pos
, "basic_string::substr"), __n
); }
2712 * @brief Compare to a string.
2713 * @param __str String to compare against.
2714 * @return Integer < 0, 0, or > 0.
2716 * Returns an integer < 0 if this string is ordered before @a
2717 * __str, 0 if their values are equivalent, or > 0 if this
2718 * string is ordered after @a __str. Determines the effective
2719 * length rlen of the strings to compare as the smallest of
2720 * size() and str.size(). The function then compares the two
2721 * strings by calling traits::compare(data(), str.data(),rlen).
2722 * If the result of the comparison is nonzero returns it,
2723 * otherwise the shorter one is ordered first.
2726 compare(const basic_string
& __str
) const
2728 const size_type __size
= this->size();
2729 const size_type __osize
= __str
.size();
2730 const size_type __len
= std::min(__size
, __osize
);
2732 int __r
= traits_type::compare(_M_data(), __str
.data(), __len
);
2734 __r
= _S_compare(__size
, __osize
);
2738 #if __cplusplus > 201402L
2740 * @brief Compare to a string_view.
2741 * @param __sv A string_view to compare against.
2742 * @return Integer < 0, 0, or > 0.
2745 compare(__sv_type __sv
) const
2747 const size_type __size
= this->size();
2748 const size_type __osize
= __sv
.size();
2749 const size_type __len
= std::min(__size
, __osize
);
2751 int __r
= traits_type::compare(_M_data(), __sv
.data(), __len
);
2753 __r
= _S_compare(__size
, __osize
);
2758 * @brief Compare to a string_view.
2759 * @param __pos A position in the string to start comparing from.
2760 * @param __n The number of characters to compare.
2761 * @param __sv A string_view to compare against.
2762 * @return Integer < 0, 0, or > 0.
2765 compare(size_type __pos
, size_type __n
, __sv_type __sv
) const
2766 { return __sv_type(*this).substr(__pos
, __n
).compare(__sv
); }
2769 * @brief Compare to a string_view.
2770 * @param __pos1 A position in the string to start comparing from.
2771 * @param __n1 The number of characters to compare.
2772 * @param __sv A string_view to compare against.
2773 * @param __pos2 A position in the string_view to start comparing from.
2774 * @param __n2 The number of characters to compare.
2775 * @return Integer < 0, 0, or > 0.
2777 template <typename _Tp
>
2779 compare(size_type __pos1
, size_type __n1
, const _Tp
& __svt
,
2780 size_type __pos2
, size_type __n2
= npos
) const
2782 __sv_type __sv
= __svt
;
2783 return __sv_type(*this)
2784 .substr(__pos1
, __n1
).compare(__sv
.substr(__pos2
, __n2
));
2789 * @brief Compare substring to a string.
2790 * @param __pos Index of first character of substring.
2791 * @param __n Number of characters in substring.
2792 * @param __str String to compare against.
2793 * @return Integer < 0, 0, or > 0.
2795 * Form the substring of this string from the @a __n characters
2796 * starting at @a __pos. Returns an integer < 0 if the
2797 * substring is ordered before @a __str, 0 if their values are
2798 * equivalent, or > 0 if the substring is ordered after @a
2799 * __str. Determines the effective length rlen of the strings
2800 * to compare as the smallest of the length of the substring
2801 * and @a __str.size(). The function then compares the two
2802 * strings by calling
2803 * traits::compare(substring.data(),str.data(),rlen). If the
2804 * result of the comparison is nonzero returns it, otherwise
2805 * the shorter one is ordered first.
2808 compare(size_type __pos
, size_type __n
, const basic_string
& __str
) const;
2811 * @brief Compare substring to a substring.
2812 * @param __pos1 Index of first character of substring.
2813 * @param __n1 Number of characters in substring.
2814 * @param __str String to compare against.
2815 * @param __pos2 Index of first character of substring of str.
2816 * @param __n2 Number of characters in substring of str.
2817 * @return Integer < 0, 0, or > 0.
2819 * Form the substring of this string from the @a __n1
2820 * characters starting at @a __pos1. Form the substring of @a
2821 * __str from the @a __n2 characters starting at @a __pos2.
2822 * Returns an integer < 0 if this substring is ordered before
2823 * the substring of @a __str, 0 if their values are equivalent,
2824 * or > 0 if this substring is ordered after the substring of
2825 * @a __str. Determines the effective length rlen of the
2826 * strings to compare as the smallest of the lengths of the
2827 * substrings. The function then compares the two strings by
2829 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
2830 * If the result of the comparison is nonzero returns it,
2831 * otherwise the shorter one is ordered first.
2834 compare(size_type __pos1
, size_type __n1
, const basic_string
& __str
,
2835 size_type __pos2
, size_type __n2
) const;
2838 * @brief Compare to a C string.
2839 * @param __s C string to compare against.
2840 * @return Integer < 0, 0, or > 0.
2842 * Returns an integer < 0 if this string is ordered before @a __s, 0 if
2843 * their values are equivalent, or > 0 if this string is ordered after
2844 * @a __s. Determines the effective length rlen of the strings to
2845 * compare as the smallest of size() and the length of a string
2846 * constructed from @a __s. The function then compares the two strings
2847 * by calling traits::compare(data(),s,rlen). If the result of the
2848 * comparison is nonzero returns it, otherwise the shorter one is
2852 compare(const _CharT
* __s
) const _GLIBCXX_NOEXCEPT
;
2854 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2855 // 5 String::compare specification questionable
2857 * @brief Compare substring to a C string.
2858 * @param __pos Index of first character of substring.
2859 * @param __n1 Number of characters in substring.
2860 * @param __s C string to compare against.
2861 * @return Integer < 0, 0, or > 0.
2863 * Form the substring of this string from the @a __n1
2864 * characters starting at @a pos. Returns an integer < 0 if
2865 * the substring is ordered before @a __s, 0 if their values
2866 * are equivalent, or > 0 if the substring is ordered after @a
2867 * __s. Determines the effective length rlen of the strings to
2868 * compare as the smallest of the length of the substring and
2869 * the length of a string constructed from @a __s. The
2870 * function then compares the two string by calling
2871 * traits::compare(substring.data(),__s,rlen). If the result of
2872 * the comparison is nonzero returns it, otherwise the shorter
2873 * one is ordered first.
2876 compare(size_type __pos
, size_type __n1
, const _CharT
* __s
) const;
2879 * @brief Compare substring against a character %array.
2880 * @param __pos Index of first character of substring.
2881 * @param __n1 Number of characters in substring.
2882 * @param __s character %array to compare against.
2883 * @param __n2 Number of characters of s.
2884 * @return Integer < 0, 0, or > 0.
2886 * Form the substring of this string from the @a __n1
2887 * characters starting at @a __pos. Form a string from the
2888 * first @a __n2 characters of @a __s. Returns an integer < 0
2889 * if this substring is ordered before the string from @a __s,
2890 * 0 if their values are equivalent, or > 0 if this substring
2891 * is ordered after the string from @a __s. Determines the
2892 * effective length rlen of the strings to compare as the
2893 * smallest of the length of the substring and @a __n2. The
2894 * function then compares the two strings by calling
2895 * traits::compare(substring.data(),s,rlen). If the result of
2896 * the comparison is nonzero returns it, otherwise the shorter
2897 * one is ordered first.
2899 * NB: s must have at least n2 characters, '\\0' has
2900 * no special meaning.
2903 compare(size_type __pos
, size_type __n1
, const _CharT
* __s
,
2904 size_type __n2
) const;
2906 _GLIBCXX_END_NAMESPACE_CXX11
2907 #else // !_GLIBCXX_USE_CXX11_ABI
2908 // Reference-counted COW string implentation
2911 * @class basic_string basic_string.h <string>
2912 * @brief Managing sequences of characters and character-like objects.
2915 * @ingroup sequences
2917 * @tparam _CharT Type of character
2918 * @tparam _Traits Traits for character type, defaults to
2919 * char_traits<_CharT>.
2920 * @tparam _Alloc Allocator type, defaults to allocator<_CharT>.
2922 * Meets the requirements of a <a href="tables.html#65">container</a>, a
2923 * <a href="tables.html#66">reversible container</a>, and a
2924 * <a href="tables.html#67">sequence</a>. Of the
2925 * <a href="tables.html#68">optional sequence requirements</a>, only
2926 * @c push_back, @c at, and @c %array access are supported.
2931 * Documentation? What's that?
2932 * Nathan Myers <ncm@cantrip.org>.
2934 * A string looks like this:
2939 * [basic_string<char_type>] _M_capacity
2940 * _M_dataplus _M_refcount
2941 * _M_p ----------------> unnamed array of char_type
2944 * Where the _M_p points to the first character in the string, and
2945 * you cast it to a pointer-to-_Rep and subtract 1 to get a
2946 * pointer to the header.
2948 * This approach has the enormous advantage that a string object
2949 * requires only one allocation. All the ugliness is confined
2950 * within a single %pair of inline functions, which each compile to
2951 * a single @a add instruction: _Rep::_M_data(), and
2952 * string::_M_rep(); and the allocation function which gets a
2953 * block of raw bytes and with room enough and constructs a _Rep
2954 * object at the front.
2956 * The reason you want _M_data pointing to the character %array and
2957 * not the _Rep is so that the debugger can see the string
2958 * contents. (Probably we should add a non-inline member to get
2959 * the _Rep for the debugger to use, so users can check the actual
2962 * Note that the _Rep object is a POD so that you can have a
2963 * static <em>empty string</em> _Rep object already @a constructed before
2964 * static constructors have run. The reference-count encoding is
2965 * chosen so that a 0 indicates one reference, so you never try to
2966 * destroy the empty-string _Rep object.
2968 * All but the last paragraph is considered pretty conventional
2969 * for a C++ string implementation.
2971 // 21.3 Template class basic_string
2972 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2975 typedef typename
_Alloc::template rebind
<_CharT
>::other _CharT_alloc_type
;
2979 typedef _Traits traits_type
;
2980 typedef typename
_Traits::char_type value_type
;
2981 typedef _Alloc allocator_type
;
2982 typedef typename
_CharT_alloc_type::size_type size_type
;
2983 typedef typename
_CharT_alloc_type::difference_type difference_type
;
2984 typedef typename
_CharT_alloc_type::reference reference
;
2985 typedef typename
_CharT_alloc_type::const_reference const_reference
;
2986 typedef typename
_CharT_alloc_type::pointer pointer
;
2987 typedef typename
_CharT_alloc_type::const_pointer const_pointer
;
2988 typedef __gnu_cxx::__normal_iterator
<pointer
, basic_string
> iterator
;
2989 typedef __gnu_cxx::__normal_iterator
<const_pointer
, basic_string
>
2991 typedef std::reverse_iterator
<const_iterator
> const_reverse_iterator
;
2992 typedef std::reverse_iterator
<iterator
> reverse_iterator
;
2995 // _Rep: string representation
2997 // 1. String really contains _M_length + 1 characters: due to 21.3.4
2998 // must be kept null-terminated.
2999 // 2. _M_capacity >= _M_length
3000 // Allocated memory is always (_M_capacity + 1) * sizeof(_CharT).
3001 // 3. _M_refcount has three states:
3002 // -1: leaked, one reference, no ref-copies allowed, non-const.
3003 // 0: one reference, non-const.
3004 // n>0: n + 1 references, operations require a lock, const.
3005 // 4. All fields==0 is an empty string, given the extra storage
3006 // beyond-the-end for a null terminator; thus, the shared
3007 // empty string representation needs no constructor.
3011 size_type _M_length
;
3012 size_type _M_capacity
;
3013 _Atomic_word _M_refcount
;
3016 struct _Rep
: _Rep_base
3019 typedef typename
_Alloc::template rebind
<char>::other _Raw_bytes_alloc
;
3021 // (Public) Data members:
3023 // The maximum number of individual char_type elements of an
3024 // individual string is determined by _S_max_size. This is the
3025 // value that will be returned by max_size(). (Whereas npos
3026 // is the maximum number of bytes the allocator can allocate.)
3027 // If one was to divvy up the theoretical largest size string,
3028 // with a terminating character and m _CharT elements, it'd
3030 // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
3032 // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
3033 // In addition, this implementation quarters this amount.
3034 static const size_type _S_max_size
;
3035 static const _CharT _S_terminal
;
3037 // The following storage is init'd to 0 by the linker, resulting
3038 // (carefully) in an empty string with one reference.
3039 static size_type _S_empty_rep_storage
[];
3042 _S_empty_rep() _GLIBCXX_NOEXCEPT
3044 // NB: Mild hack to avoid strict-aliasing warnings. Note that
3045 // _S_empty_rep_storage is never modified and the punning should
3046 // be reasonably safe in this case.
3047 void* __p
= reinterpret_cast<void*>(&_S_empty_rep_storage
);
3048 return *reinterpret_cast<_Rep
*>(__p
);
3052 _M_is_leaked() const _GLIBCXX_NOEXCEPT
3054 #if defined(__GTHREADS)
3055 // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose,
3056 // so we need to use an atomic load. However, _M_is_leaked
3057 // predicate does not change concurrently (i.e. the string is either
3058 // leaked or not), so a relaxed load is enough.
3059 return __atomic_load_n(&this->_M_refcount
, __ATOMIC_RELAXED
) < 0;
3061 return this->_M_refcount
< 0;
3066 _M_is_shared() const _GLIBCXX_NOEXCEPT
3068 #if defined(__GTHREADS)
3069 // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose,
3070 // so we need to use an atomic load. Another thread can drop last
3071 // but one reference concurrently with this check, so we need this
3072 // load to be acquire to synchronize with release fetch_and_add in
3074 return __atomic_load_n(&this->_M_refcount
, __ATOMIC_ACQUIRE
) > 0;
3076 return this->_M_refcount
> 0;
3081 _M_set_leaked() _GLIBCXX_NOEXCEPT
3082 { this->_M_refcount
= -1; }
3085 _M_set_sharable() _GLIBCXX_NOEXCEPT
3086 { this->_M_refcount
= 0; }
3089 _M_set_length_and_sharable(size_type __n
) _GLIBCXX_NOEXCEPT
3091 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3092 if (__builtin_expect(this != &_S_empty_rep(), false))
3095 this->_M_set_sharable(); // One reference.
3096 this->_M_length
= __n
;
3097 traits_type::assign(this->_M_refdata()[__n
], _S_terminal
);
3098 // grrr. (per 21.3.4)
3099 // You cannot leave those LWG people alone for a second.
3104 _M_refdata() throw()
3105 { return reinterpret_cast<_CharT
*>(this + 1); }
3108 _M_grab(const _Alloc
& __alloc1
, const _Alloc
& __alloc2
)
3110 return (!_M_is_leaked() && __alloc1
== __alloc2
)
3111 ? _M_refcopy() : _M_clone(__alloc1
);
3116 _S_create(size_type
, size_type
, const _Alloc
&);
3119 _M_dispose(const _Alloc
& __a
) _GLIBCXX_NOEXCEPT
3121 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3122 if (__builtin_expect(this != &_S_empty_rep(), false))
3125 // Be race-detector-friendly. For more info see bits/c++config.
3126 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount
);
3127 // Decrement of _M_refcount is acq_rel, because:
3128 // - all but last decrements need to release to synchronize with
3129 // the last decrement that will delete the object.
3130 // - the last decrement needs to acquire to synchronize with
3131 // all the previous decrements.
3132 // - last but one decrement needs to release to synchronize with
3133 // the acquire load in _M_is_shared that will conclude that
3134 // the object is not shared anymore.
3135 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount
,
3138 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount
);
3145 _M_destroy(const _Alloc
&) throw();
3148 _M_refcopy() throw()
3150 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3151 if (__builtin_expect(this != &_S_empty_rep(), false))
3153 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount
, 1);
3154 return _M_refdata();
3158 _M_clone(const _Alloc
&, size_type __res
= 0);
3161 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
3162 struct _Alloc_hider
: _Alloc
3164 _Alloc_hider(_CharT
* __dat
, const _Alloc
& __a
) _GLIBCXX_NOEXCEPT
3165 : _Alloc(__a
), _M_p(__dat
) { }
3167 _CharT
* _M_p
; // The actual data.
3171 // Data Members (public):
3172 // NB: This is an unsigned type, and thus represents the maximum
3173 // size that the allocator can hold.
3174 /// Value returned by various member functions when they fail.
3175 static const size_type npos
= static_cast<size_type
>(-1);
3178 // Data Members (private):
3179 mutable _Alloc_hider _M_dataplus
;
3182 _M_data() const _GLIBCXX_NOEXCEPT
3183 { return _M_dataplus
._M_p
; }
3186 _M_data(_CharT
* __p
) _GLIBCXX_NOEXCEPT
3187 { return (_M_dataplus
._M_p
= __p
); }
3190 _M_rep() const _GLIBCXX_NOEXCEPT
3191 { return &((reinterpret_cast<_Rep
*> (_M_data()))[-1]); }
3193 // For the internal use we have functions similar to `begin'/`end'
3194 // but they do not call _M_leak.
3196 _M_ibegin() const _GLIBCXX_NOEXCEPT
3197 { return iterator(_M_data()); }
3200 _M_iend() const _GLIBCXX_NOEXCEPT
3201 { return iterator(_M_data() + this->size()); }
3204 _M_leak() // for use in begin() & non-const op[]
3206 if (!_M_rep()->_M_is_leaked())
3211 _M_check(size_type __pos
, const char* __s
) const
3213 if (__pos
> this->size())
3214 __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
3215 "this->size() (which is %zu)"),
3216 __s
, __pos
, this->size());
3221 _M_check_length(size_type __n1
, size_type __n2
, const char* __s
) const
3223 if (this->max_size() - (this->size() - __n1
) < __n2
)
3224 __throw_length_error(__N(__s
));
3227 // NB: _M_limit doesn't check for a bad __pos value.
3229 _M_limit(size_type __pos
, size_type __off
) const _GLIBCXX_NOEXCEPT
3231 const bool __testoff
= __off
< this->size() - __pos
;
3232 return __testoff
? __off
: this->size() - __pos
;
3235 // True if _Rep and source do not overlap.
3237 _M_disjunct(const _CharT
* __s
) const _GLIBCXX_NOEXCEPT
3239 return (less
<const _CharT
*>()(__s
, _M_data())
3240 || less
<const _CharT
*>()(_M_data() + this->size(), __s
));
3243 // When __n = 1 way faster than the general multichar
3244 // traits_type::copy/move/assign.
3246 _M_copy(_CharT
* __d
, const _CharT
* __s
, size_type __n
) _GLIBCXX_NOEXCEPT
3249 traits_type::assign(*__d
, *__s
);
3251 traits_type::copy(__d
, __s
, __n
);
3255 _M_move(_CharT
* __d
, const _CharT
* __s
, size_type __n
) _GLIBCXX_NOEXCEPT
3258 traits_type::assign(*__d
, *__s
);
3260 traits_type::move(__d
, __s
, __n
);
3264 _M_assign(_CharT
* __d
, size_type __n
, _CharT __c
) _GLIBCXX_NOEXCEPT
3267 traits_type::assign(*__d
, __c
);
3269 traits_type::assign(__d
, __n
, __c
);
3272 // _S_copy_chars is a separate template to permit specialization
3273 // to optimize for the common case of pointers as iterators.
3274 template<class _Iterator
>
3276 _S_copy_chars(_CharT
* __p
, _Iterator __k1
, _Iterator __k2
)
3278 for (; __k1
!= __k2
; ++__k1
, (void)++__p
)
3279 traits_type::assign(*__p
, *__k1
); // These types are off.
3283 _S_copy_chars(_CharT
* __p
, iterator __k1
, iterator __k2
) _GLIBCXX_NOEXCEPT
3284 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
3287 _S_copy_chars(_CharT
* __p
, const_iterator __k1
, const_iterator __k2
)
3289 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
3292 _S_copy_chars(_CharT
* __p
, _CharT
* __k1
, _CharT
* __k2
) _GLIBCXX_NOEXCEPT
3293 { _M_copy(__p
, __k1
, __k2
- __k1
); }
3296 _S_copy_chars(_CharT
* __p
, const _CharT
* __k1
, const _CharT
* __k2
)
3298 { _M_copy(__p
, __k1
, __k2
- __k1
); }
3301 _S_compare(size_type __n1
, size_type __n2
) _GLIBCXX_NOEXCEPT
3303 const difference_type __d
= difference_type(__n1
- __n2
);
3305 if (__d
> __gnu_cxx::__numeric_traits
<int>::__max
)
3306 return __gnu_cxx::__numeric_traits
<int>::__max
;
3307 else if (__d
< __gnu_cxx::__numeric_traits
<int>::__min
)
3308 return __gnu_cxx::__numeric_traits
<int>::__min
;
3314 _M_mutate(size_type __pos
, size_type __len1
, size_type __len2
);
3320 _S_empty_rep() _GLIBCXX_NOEXCEPT
3321 { return _Rep::_S_empty_rep(); }
3324 // Construct/copy/destroy:
3325 // NB: We overload ctors in some cases instead of using default
3326 // arguments, per 17.4.4.4 para. 2 item 2.
3329 * @brief Default constructor creates an empty string.
3332 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3333 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
3335 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()){ }
3339 * @brief Construct an empty string using allocator @a a.
3342 basic_string(const _Alloc
& __a
);
3344 // NB: per LWG issue 42, semantics different from IS:
3346 * @brief Construct string with copy of value of @a str.
3347 * @param __str Source string.
3349 basic_string(const basic_string
& __str
);
3351 // _GLIBCXX_RESOLVE_LIB_DEFECTS
3352 // 2583. no way to supply an allocator for basic_string(str, pos)
3354 * @brief Construct string as copy of a substring.
3355 * @param __str Source string.
3356 * @param __pos Index of first character to copy from.
3357 * @param __a Allocator to use.
3359 basic_string(const basic_string
& __str
, size_type __pos
,
3360 const _Alloc
& __a
= _Alloc());
3363 * @brief Construct string as copy of a substring.
3364 * @param __str Source string.
3365 * @param __pos Index of first character to copy from.
3366 * @param __n Number of characters to copy.
3368 basic_string(const basic_string
& __str
, size_type __pos
,
3371 * @brief Construct string as copy of a substring.
3372 * @param __str Source string.
3373 * @param __pos Index of first character to copy from.
3374 * @param __n Number of characters to copy.
3375 * @param __a Allocator to use.
3377 basic_string(const basic_string
& __str
, size_type __pos
,
3378 size_type __n
, const _Alloc
& __a
);
3381 * @brief Construct string initialized by a character %array.
3382 * @param __s Source character %array.
3383 * @param __n Number of characters to copy.
3384 * @param __a Allocator to use (default is default allocator).
3386 * NB: @a __s must have at least @a __n characters, '\\0'
3387 * has no special meaning.
3389 basic_string(const _CharT
* __s
, size_type __n
,
3390 const _Alloc
& __a
= _Alloc());
3392 * @brief Construct string as copy of a C string.
3393 * @param __s Source C string.
3394 * @param __a Allocator to use (default is default allocator).
3396 basic_string(const _CharT
* __s
, const _Alloc
& __a
= _Alloc());
3398 * @brief Construct string as multiple characters.
3399 * @param __n Number of characters.
3400 * @param __c Character to use.
3401 * @param __a Allocator to use (default is default allocator).
3403 basic_string(size_type __n
, _CharT __c
, const _Alloc
& __a
= _Alloc());
3405 #if __cplusplus >= 201103L
3407 * @brief Move construct string.
3408 * @param __str Source string.
3410 * The newly-created string contains the exact contents of @a __str.
3411 * @a __str is a valid, but unspecified string.
3413 basic_string(basic_string
&& __str
)
3414 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3415 noexcept
// FIXME C++11: should always be noexcept.
3417 : _M_dataplus(__str
._M_dataplus
)
3419 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3420 __str
._M_data(_S_empty_rep()._M_refdata());
3422 __str
._M_data(_S_construct(size_type(), _CharT(), get_allocator()));
3427 * @brief Construct string from an initializer %list.
3428 * @param __l std::initializer_list of characters.
3429 * @param __a Allocator to use (default is default allocator).
3431 basic_string(initializer_list
<_CharT
> __l
, const _Alloc
& __a
= _Alloc());
3435 * @brief Construct string as copy of a range.
3436 * @param __beg Start of range.
3437 * @param __end End of range.
3438 * @param __a Allocator to use (default is default allocator).
3440 template<class _InputIterator
>
3441 basic_string(_InputIterator __beg
, _InputIterator __end
,
3442 const _Alloc
& __a
= _Alloc());
3445 * @brief Destroy the string instance.
3447 ~basic_string() _GLIBCXX_NOEXCEPT
3448 { _M_rep()->_M_dispose(this->get_allocator()); }
3451 * @brief Assign the value of @a str to this string.
3452 * @param __str Source string.
3455 operator=(const basic_string
& __str
)
3456 { return this->assign(__str
); }
3459 * @brief Copy contents of @a s into this string.
3460 * @param __s Source null-terminated string.
3463 operator=(const _CharT
* __s
)
3464 { return this->assign(__s
); }
3467 * @brief Set value to string of length 1.
3468 * @param __c Source character.
3470 * Assigning to a character makes this string length 1 and
3471 * (*this)[0] == @a c.
3474 operator=(_CharT __c
)
3476 this->assign(1, __c
);
3480 #if __cplusplus >= 201103L
3482 * @brief Move assign the value of @a str to this string.
3483 * @param __str Source string.
3485 * The contents of @a str are moved into this string (without copying).
3486 * @a str is a valid, but unspecified string.
3488 // PR 58265, this should be noexcept.
3490 operator=(basic_string
&& __str
)
3498 * @brief Set value to string constructed from initializer %list.
3499 * @param __l std::initializer_list.
3502 operator=(initializer_list
<_CharT
> __l
)
3504 this->assign(__l
.begin(), __l
.size());
3511 * Returns a read/write iterator that points to the first character in
3512 * the %string. Unshares the string.
3515 begin() // FIXME C++11: should be noexcept.
3518 return iterator(_M_data());
3522 * Returns a read-only (constant) iterator that points to the first
3523 * character in the %string.
3526 begin() const _GLIBCXX_NOEXCEPT
3527 { return const_iterator(_M_data()); }
3530 * Returns a read/write iterator that points one past the last
3531 * character in the %string. Unshares the string.
3534 end() // FIXME C++11: should be noexcept.
3537 return iterator(_M_data() + this->size());
3541 * Returns a read-only (constant) iterator that points one past the
3542 * last character in the %string.
3545 end() const _GLIBCXX_NOEXCEPT
3546 { return const_iterator(_M_data() + this->size()); }
3549 * Returns a read/write reverse iterator that points to the last
3550 * character in the %string. Iteration is done in reverse element
3551 * order. Unshares the string.
3554 rbegin() // FIXME C++11: should be noexcept.
3555 { return reverse_iterator(this->end()); }
3558 * Returns a read-only (constant) reverse iterator that points
3559 * to the last character in the %string. Iteration is done in
3560 * reverse element order.
3562 const_reverse_iterator
3563 rbegin() const _GLIBCXX_NOEXCEPT
3564 { return const_reverse_iterator(this->end()); }
3567 * Returns a read/write reverse iterator that points to one before the
3568 * first character in the %string. Iteration is done in reverse
3569 * element order. Unshares the string.
3572 rend() // FIXME C++11: should be noexcept.
3573 { return reverse_iterator(this->begin()); }
3576 * Returns a read-only (constant) reverse iterator that points
3577 * to one before the first character in the %string. Iteration
3578 * is done in reverse element order.
3580 const_reverse_iterator
3581 rend() const _GLIBCXX_NOEXCEPT
3582 { return const_reverse_iterator(this->begin()); }
3584 #if __cplusplus >= 201103L
3586 * Returns a read-only (constant) iterator that points to the first
3587 * character in the %string.
3590 cbegin() const noexcept
3591 { return const_iterator(this->_M_data()); }
3594 * Returns a read-only (constant) iterator that points one past the
3595 * last character in the %string.
3598 cend() const noexcept
3599 { return const_iterator(this->_M_data() + this->size()); }
3602 * Returns a read-only (constant) reverse iterator that points
3603 * to the last character in the %string. Iteration is done in
3604 * reverse element order.
3606 const_reverse_iterator
3607 crbegin() const noexcept
3608 { return const_reverse_iterator(this->end()); }
3611 * Returns a read-only (constant) reverse iterator that points
3612 * to one before the first character in the %string. Iteration
3613 * is done in reverse element order.
3615 const_reverse_iterator
3616 crend() const noexcept
3617 { return const_reverse_iterator(this->begin()); }
3622 /// Returns the number of characters in the string, not including any
3623 /// null-termination.
3625 size() const _GLIBCXX_NOEXCEPT
3626 { return _M_rep()->_M_length
; }
3628 /// Returns the number of characters in the string, not including any
3629 /// null-termination.
3631 length() const _GLIBCXX_NOEXCEPT
3632 { return _M_rep()->_M_length
; }
3634 /// Returns the size() of the largest possible %string.
3636 max_size() const _GLIBCXX_NOEXCEPT
3637 { return _Rep::_S_max_size
; }
3640 * @brief Resizes the %string to the specified number of characters.
3641 * @param __n Number of characters the %string should contain.
3642 * @param __c Character to fill any new elements.
3644 * This function will %resize the %string to the specified
3645 * number of characters. If the number is smaller than the
3646 * %string's current size the %string is truncated, otherwise
3647 * the %string is extended and new elements are %set to @a __c.
3650 resize(size_type __n
, _CharT __c
);
3653 * @brief Resizes the %string to the specified number of characters.
3654 * @param __n Number of characters the %string should contain.
3656 * This function will resize the %string to the specified length. If
3657 * the new size is smaller than the %string's current size the %string
3658 * is truncated, otherwise the %string is extended and new characters
3659 * are default-constructed. For basic types such as char, this means
3660 * setting them to 0.
3663 resize(size_type __n
)
3664 { this->resize(__n
, _CharT()); }
3666 #if __cplusplus >= 201103L
3667 /// A non-binding request to reduce capacity() to size().
3669 shrink_to_fit() _GLIBCXX_NOEXCEPT
3671 #if __cpp_exceptions
3672 if (capacity() > size())
3684 * Returns the total number of characters that the %string can hold
3685 * before needing to allocate more memory.
3688 capacity() const _GLIBCXX_NOEXCEPT
3689 { return _M_rep()->_M_capacity
; }
3692 * @brief Attempt to preallocate enough memory for specified number of
3694 * @param __res_arg Number of characters required.
3695 * @throw std::length_error If @a __res_arg exceeds @c max_size().
3697 * This function attempts to reserve enough memory for the
3698 * %string to hold the specified number of characters. If the
3699 * number requested is more than max_size(), length_error is
3702 * The advantage of this function is that if optimal code is a
3703 * necessity and the user can determine the string length that will be
3704 * required, the user can reserve the memory in %advance, and thus
3705 * prevent a possible reallocation of memory and copying of %string
3709 reserve(size_type __res_arg
= 0);
3712 * Erases the string, making it empty.
3714 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
3716 clear() _GLIBCXX_NOEXCEPT
3718 if (_M_rep()->_M_is_shared())
3720 _M_rep()->_M_dispose(this->get_allocator());
3721 _M_data(_S_empty_rep()._M_refdata());
3724 _M_rep()->_M_set_length_and_sharable(0);
3727 // PR 56166: this should not throw.
3730 { _M_mutate(0, this->size(), 0); }
3734 * Returns true if the %string is empty. Equivalent to
3735 * <code>*this == ""</code>.
3738 empty() const _GLIBCXX_NOEXCEPT
3739 { return this->size() == 0; }
3743 * @brief Subscript access to the data contained in the %string.
3744 * @param __pos The index of the character to access.
3745 * @return Read-only (constant) reference to the character.
3747 * This operator allows for easy, array-style, data access.
3748 * Note that data access with this operator is unchecked and
3749 * out_of_range lookups are not defined. (For checked lookups
3753 operator[] (size_type __pos
) const _GLIBCXX_NOEXCEPT
3755 __glibcxx_assert(__pos
<= size());
3756 return _M_data()[__pos
];
3760 * @brief Subscript access to the data contained in the %string.
3761 * @param __pos The index of the character to access.
3762 * @return Read/write reference to the character.
3764 * This operator allows for easy, array-style, data access.
3765 * Note that data access with this operator is unchecked and
3766 * out_of_range lookups are not defined. (For checked lookups
3767 * see at().) Unshares the string.
3770 operator[](size_type __pos
)
3772 // Allow pos == size() both in C++98 mode, as v3 extension,
3773 // and in C++11 mode.
3774 __glibcxx_assert(__pos
<= size());
3775 // In pedantic mode be strict in C++98 mode.
3776 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus
>= 201103L || __pos
< size());
3778 return _M_data()[__pos
];
3782 * @brief Provides access to the data contained in the %string.
3783 * @param __n The index of the character to access.
3784 * @return Read-only (const) reference to the character.
3785 * @throw std::out_of_range If @a n is an invalid index.
3787 * This function provides for safer data access. The parameter is
3788 * first checked that it is in the range of the string. The function
3789 * throws out_of_range if the check fails.
3792 at(size_type __n
) const
3794 if (__n
>= this->size())
3795 __throw_out_of_range_fmt(__N("basic_string::at: __n "
3796 "(which is %zu) >= this->size() "
3799 return _M_data()[__n
];
3803 * @brief Provides access to the data contained in the %string.
3804 * @param __n The index of the character to access.
3805 * @return Read/write reference to the character.
3806 * @throw std::out_of_range If @a n is an invalid index.
3808 * This function provides for safer data access. The parameter is
3809 * first checked that it is in the range of the string. The function
3810 * throws out_of_range if the check fails. Success results in
3811 * unsharing the string.
3817 __throw_out_of_range_fmt(__N("basic_string::at: __n "
3818 "(which is %zu) >= this->size() "
3822 return _M_data()[__n
];
3825 #if __cplusplus >= 201103L
3827 * Returns a read/write reference to the data at the first
3828 * element of the %string.
3833 __glibcxx_assert(!empty());
3834 return operator[](0);
3838 * Returns a read-only (constant) reference to the data at the first
3839 * element of the %string.
3842 front() const noexcept
3844 __glibcxx_assert(!empty());
3845 return operator[](0);
3849 * Returns a read/write reference to the data at the last
3850 * element of the %string.
3855 __glibcxx_assert(!empty());
3856 return operator[](this->size() - 1);
3860 * Returns a read-only (constant) reference to the data at the
3861 * last element of the %string.
3864 back() const noexcept
3866 __glibcxx_assert(!empty());
3867 return operator[](this->size() - 1);
3873 * @brief Append a string to this string.
3874 * @param __str The string to append.
3875 * @return Reference to this string.
3878 operator+=(const basic_string
& __str
)
3879 { return this->append(__str
); }
3882 * @brief Append a C string.
3883 * @param __s The C string to append.
3884 * @return Reference to this string.
3887 operator+=(const _CharT
* __s
)
3888 { return this->append(__s
); }
3891 * @brief Append a character.
3892 * @param __c The character to append.
3893 * @return Reference to this string.
3896 operator+=(_CharT __c
)
3898 this->push_back(__c
);
3902 #if __cplusplus >= 201103L
3904 * @brief Append an initializer_list of characters.
3905 * @param __l The initializer_list of characters to be appended.
3906 * @return Reference to this string.
3909 operator+=(initializer_list
<_CharT
> __l
)
3910 { return this->append(__l
.begin(), __l
.size()); }
3914 * @brief Append a string to this string.
3915 * @param __str The string to append.
3916 * @return Reference to this string.
3919 append(const basic_string
& __str
);
3922 * @brief Append a substring.
3923 * @param __str The string to append.
3924 * @param __pos Index of the first character of str to append.
3925 * @param __n The number of characters to append.
3926 * @return Reference to this string.
3927 * @throw std::out_of_range if @a __pos is not a valid index.
3929 * This function appends @a __n characters from @a __str
3930 * starting at @a __pos to this string. If @a __n is is larger
3931 * than the number of available characters in @a __str, the
3932 * remainder of @a __str is appended.
3935 append(const basic_string
& __str
, size_type __pos
, size_type __n
);
3938 * @brief Append a C substring.
3939 * @param __s The C string to append.
3940 * @param __n The number of characters to append.
3941 * @return Reference to this string.
3944 append(const _CharT
* __s
, size_type __n
);
3947 * @brief Append a C string.
3948 * @param __s The C string to append.
3949 * @return Reference to this string.
3952 append(const _CharT
* __s
)
3954 __glibcxx_requires_string(__s
);
3955 return this->append(__s
, traits_type::length(__s
));
3959 * @brief Append multiple characters.
3960 * @param __n The number of characters to append.
3961 * @param __c The character to use.
3962 * @return Reference to this string.
3964 * Appends __n copies of __c to this string.
3967 append(size_type __n
, _CharT __c
);
3969 #if __cplusplus >= 201103L
3971 * @brief Append an initializer_list of characters.
3972 * @param __l The initializer_list of characters to append.
3973 * @return Reference to this string.
3976 append(initializer_list
<_CharT
> __l
)
3977 { return this->append(__l
.begin(), __l
.size()); }
3981 * @brief Append a range of characters.
3982 * @param __first Iterator referencing the first character to append.
3983 * @param __last Iterator marking the end of the range.
3984 * @return Reference to this string.
3986 * Appends characters in the range [__first,__last) to this string.
3988 template<class _InputIterator
>
3990 append(_InputIterator __first
, _InputIterator __last
)
3991 { return this->replace(_M_iend(), _M_iend(), __first
, __last
); }
3994 * @brief Append a single character.
3995 * @param __c Character to append.
3998 push_back(_CharT __c
)
4000 const size_type __len
= 1 + this->size();
4001 if (__len
> this->capacity() || _M_rep()->_M_is_shared())
4002 this->reserve(__len
);
4003 traits_type::assign(_M_data()[this->size()], __c
);
4004 _M_rep()->_M_set_length_and_sharable(__len
);
4008 * @brief Set value to contents of another string.
4009 * @param __str Source string to use.
4010 * @return Reference to this string.
4013 assign(const basic_string
& __str
);
4015 #if __cplusplus >= 201103L
4017 * @brief Set value to contents of another string.
4018 * @param __str Source string to use.
4019 * @return Reference to this string.
4021 * This function sets this string to the exact contents of @a __str.
4022 * @a __str is a valid, but unspecified string.
4024 // PR 58265, this should be noexcept.
4026 assign(basic_string
&& __str
)
4034 * @brief Set value to a substring of a string.
4035 * @param __str The string to use.
4036 * @param __pos Index of the first character of str.
4037 * @param __n Number of characters to use.
4038 * @return Reference to this string.
4039 * @throw std::out_of_range if @a pos is not a valid index.
4041 * This function sets this string to the substring of @a __str
4042 * consisting of @a __n characters at @a __pos. If @a __n is
4043 * is larger than the number of available characters in @a
4044 * __str, the remainder of @a __str is used.
4047 assign(const basic_string
& __str
, size_type __pos
, size_type __n
)
4048 { return this->assign(__str
._M_data()
4049 + __str
._M_check(__pos
, "basic_string::assign"),
4050 __str
._M_limit(__pos
, __n
)); }
4053 * @brief Set value to a C substring.
4054 * @param __s The C string to use.
4055 * @param __n Number of characters to use.
4056 * @return Reference to this string.
4058 * This function sets the value of this string to the first @a __n
4059 * characters of @a __s. If @a __n is is larger than the number of
4060 * available characters in @a __s, the remainder of @a __s is used.
4063 assign(const _CharT
* __s
, size_type __n
);
4066 * @brief Set value to contents of a C string.
4067 * @param __s The C string to use.
4068 * @return Reference to this string.
4070 * This function sets the value of this string to the value of @a __s.
4071 * The data is copied, so there is no dependence on @a __s once the
4075 assign(const _CharT
* __s
)
4077 __glibcxx_requires_string(__s
);
4078 return this->assign(__s
, traits_type::length(__s
));
4082 * @brief Set value to multiple characters.
4083 * @param __n Length of the resulting string.
4084 * @param __c The character to use.
4085 * @return Reference to this string.
4087 * This function sets the value of this string to @a __n copies of
4091 assign(size_type __n
, _CharT __c
)
4092 { return _M_replace_aux(size_type(0), this->size(), __n
, __c
); }
4095 * @brief Set value to a range of characters.
4096 * @param __first Iterator referencing the first character to append.
4097 * @param __last Iterator marking the end of the range.
4098 * @return Reference to this string.
4100 * Sets value of string to characters in the range [__first,__last).
4102 template<class _InputIterator
>
4104 assign(_InputIterator __first
, _InputIterator __last
)
4105 { return this->replace(_M_ibegin(), _M_iend(), __first
, __last
); }
4107 #if __cplusplus >= 201103L
4109 * @brief Set value to an initializer_list of characters.
4110 * @param __l The initializer_list of characters to assign.
4111 * @return Reference to this string.
4114 assign(initializer_list
<_CharT
> __l
)
4115 { return this->assign(__l
.begin(), __l
.size()); }
4119 * @brief Insert multiple characters.
4120 * @param __p Iterator referencing location in string to insert at.
4121 * @param __n Number of characters to insert
4122 * @param __c The character to insert.
4123 * @throw std::length_error If new length exceeds @c max_size().
4125 * Inserts @a __n copies of character @a __c starting at the
4126 * position referenced by iterator @a __p. If adding
4127 * characters causes the length to exceed max_size(),
4128 * length_error is thrown. The value of the string doesn't
4129 * change if an error is thrown.
4132 insert(iterator __p
, size_type __n
, _CharT __c
)
4133 { this->replace(__p
, __p
, __n
, __c
); }
4136 * @brief Insert a range of characters.
4137 * @param __p Iterator referencing location in string to insert at.
4138 * @param __beg Start of range.
4139 * @param __end End of range.
4140 * @throw std::length_error If new length exceeds @c max_size().
4142 * Inserts characters in range [__beg,__end). If adding
4143 * characters causes the length to exceed max_size(),
4144 * length_error is thrown. The value of the string doesn't
4145 * change if an error is thrown.
4147 template<class _InputIterator
>
4149 insert(iterator __p
, _InputIterator __beg
, _InputIterator __end
)
4150 { this->replace(__p
, __p
, __beg
, __end
); }
4152 #if __cplusplus >= 201103L
4154 * @brief Insert an initializer_list of characters.
4155 * @param __p Iterator referencing location in string to insert at.
4156 * @param __l The initializer_list of characters to insert.
4157 * @throw std::length_error If new length exceeds @c max_size().
4160 insert(iterator __p
, initializer_list
<_CharT
> __l
)
4162 _GLIBCXX_DEBUG_PEDASSERT(__p
>= _M_ibegin() && __p
<= _M_iend());
4163 this->insert(__p
- _M_ibegin(), __l
.begin(), __l
.size());
4168 * @brief Insert value of a string.
4169 * @param __pos1 Iterator referencing location in string to insert at.
4170 * @param __str The string to insert.
4171 * @return Reference to this string.
4172 * @throw std::length_error If new length exceeds @c max_size().
4174 * Inserts value of @a __str starting at @a __pos1. If adding
4175 * characters causes the length to exceed max_size(),
4176 * length_error is thrown. The value of the string doesn't
4177 * change if an error is thrown.
4180 insert(size_type __pos1
, const basic_string
& __str
)
4181 { return this->insert(__pos1
, __str
, size_type(0), __str
.size()); }
4184 * @brief Insert a substring.
4185 * @param __pos1 Iterator referencing location in string to insert at.
4186 * @param __str The string to insert.
4187 * @param __pos2 Start of characters in str to insert.
4188 * @param __n Number of characters to insert.
4189 * @return Reference to this string.
4190 * @throw std::length_error If new length exceeds @c max_size().
4191 * @throw std::out_of_range If @a pos1 > size() or
4192 * @a __pos2 > @a str.size().
4194 * Starting at @a pos1, insert @a __n character of @a __str
4195 * beginning with @a __pos2. If adding characters causes the
4196 * length to exceed max_size(), length_error is thrown. If @a
4197 * __pos1 is beyond the end of this string or @a __pos2 is
4198 * beyond the end of @a __str, out_of_range is thrown. The
4199 * value of the string doesn't change if an error is thrown.
4202 insert(size_type __pos1
, const basic_string
& __str
,
4203 size_type __pos2
, size_type __n
)
4204 { return this->insert(__pos1
, __str
._M_data()
4205 + __str
._M_check(__pos2
, "basic_string::insert"),
4206 __str
._M_limit(__pos2
, __n
)); }
4209 * @brief Insert a C substring.
4210 * @param __pos Iterator referencing location in string to insert at.
4211 * @param __s The C string to insert.
4212 * @param __n The number of characters to insert.
4213 * @return Reference to this string.
4214 * @throw std::length_error If new length exceeds @c max_size().
4215 * @throw std::out_of_range If @a __pos is beyond the end of this
4218 * Inserts the first @a __n characters of @a __s starting at @a
4219 * __pos. If adding characters causes the length to exceed
4220 * max_size(), length_error is thrown. If @a __pos is beyond
4221 * end(), out_of_range is thrown. The value of the string
4222 * doesn't change if an error is thrown.
4225 insert(size_type __pos
, const _CharT
* __s
, size_type __n
);
4228 * @brief Insert a C string.
4229 * @param __pos Iterator referencing location in string to insert at.
4230 * @param __s The C string to insert.
4231 * @return Reference to this string.
4232 * @throw std::length_error If new length exceeds @c max_size().
4233 * @throw std::out_of_range If @a pos is beyond the end of this
4236 * Inserts the first @a n characters of @a __s starting at @a __pos. If
4237 * adding characters causes the length to exceed max_size(),
4238 * length_error is thrown. If @a __pos is beyond end(), out_of_range is
4239 * thrown. The value of the string doesn't change if an error is
4243 insert(size_type __pos
, const _CharT
* __s
)
4245 __glibcxx_requires_string(__s
);
4246 return this->insert(__pos
, __s
, traits_type::length(__s
));
4250 * @brief Insert multiple characters.
4251 * @param __pos Index in string to insert at.
4252 * @param __n Number of characters to insert
4253 * @param __c The character to insert.
4254 * @return Reference to this string.
4255 * @throw std::length_error If new length exceeds @c max_size().
4256 * @throw std::out_of_range If @a __pos is beyond the end of this
4259 * Inserts @a __n copies of character @a __c starting at index
4260 * @a __pos. If adding characters causes the length to exceed
4261 * max_size(), length_error is thrown. If @a __pos > length(),
4262 * out_of_range is thrown. The value of the string doesn't
4263 * change if an error is thrown.
4266 insert(size_type __pos
, size_type __n
, _CharT __c
)
4267 { return _M_replace_aux(_M_check(__pos
, "basic_string::insert"),
4268 size_type(0), __n
, __c
); }
4271 * @brief Insert one character.
4272 * @param __p Iterator referencing position in string to insert at.
4273 * @param __c The character to insert.
4274 * @return Iterator referencing newly inserted char.
4275 * @throw std::length_error If new length exceeds @c max_size().
4277 * Inserts character @a __c at position referenced by @a __p.
4278 * If adding character causes the length to exceed max_size(),
4279 * length_error is thrown. If @a __p is beyond end of string,
4280 * out_of_range is thrown. The value of the string doesn't
4281 * change if an error is thrown.
4284 insert(iterator __p
, _CharT __c
)
4286 _GLIBCXX_DEBUG_PEDASSERT(__p
>= _M_ibegin() && __p
<= _M_iend());
4287 const size_type __pos
= __p
- _M_ibegin();
4288 _M_replace_aux(__pos
, size_type(0), size_type(1), __c
);
4289 _M_rep()->_M_set_leaked();
4290 return iterator(_M_data() + __pos
);
4294 * @brief Remove characters.
4295 * @param __pos Index of first character to remove (default 0).
4296 * @param __n Number of characters to remove (default remainder).
4297 * @return Reference to this string.
4298 * @throw std::out_of_range If @a pos is beyond the end of this
4301 * Removes @a __n characters from this string starting at @a
4302 * __pos. The length of the string is reduced by @a __n. If
4303 * there are < @a __n characters to remove, the remainder of
4304 * the string is truncated. If @a __p is beyond end of string,
4305 * out_of_range is thrown. The value of the string doesn't
4306 * change if an error is thrown.
4309 erase(size_type __pos
= 0, size_type __n
= npos
)
4311 _M_mutate(_M_check(__pos
, "basic_string::erase"),
4312 _M_limit(__pos
, __n
), size_type(0));
4317 * @brief Remove one character.
4318 * @param __position Iterator referencing the character to remove.
4319 * @return iterator referencing same location after removal.
4321 * Removes the character at @a __position from this string. The value
4322 * of the string doesn't change if an error is thrown.
4325 erase(iterator __position
)
4327 _GLIBCXX_DEBUG_PEDASSERT(__position
>= _M_ibegin()
4328 && __position
< _M_iend());
4329 const size_type __pos
= __position
- _M_ibegin();
4330 _M_mutate(__pos
, size_type(1), size_type(0));
4331 _M_rep()->_M_set_leaked();
4332 return iterator(_M_data() + __pos
);
4336 * @brief Remove a range of characters.
4337 * @param __first Iterator referencing the first character to remove.
4338 * @param __last Iterator referencing the end of the range.
4339 * @return Iterator referencing location of first after removal.
4341 * Removes the characters in the range [first,last) from this string.
4342 * The value of the string doesn't change if an error is thrown.
4345 erase(iterator __first
, iterator __last
);
4347 #if __cplusplus >= 201103L
4349 * @brief Remove the last character.
4351 * The string must be non-empty.
4354 pop_back() // FIXME C++11: should be noexcept.
4356 __glibcxx_assert(!empty());
4357 erase(size() - 1, 1);
4362 * @brief Replace characters with value from another string.
4363 * @param __pos Index of first character to replace.
4364 * @param __n Number of characters to be replaced.
4365 * @param __str String to insert.
4366 * @return Reference to this string.
4367 * @throw std::out_of_range If @a pos is beyond the end of this
4369 * @throw std::length_error If new length exceeds @c max_size().
4371 * Removes the characters in the range [__pos,__pos+__n) from
4372 * this string. In place, the value of @a __str is inserted.
4373 * If @a __pos is beyond end of string, out_of_range is thrown.
4374 * If the length of the result exceeds max_size(), length_error
4375 * is thrown. The value of the string doesn't change if an
4379 replace(size_type __pos
, size_type __n
, const basic_string
& __str
)
4380 { return this->replace(__pos
, __n
, __str
._M_data(), __str
.size()); }
4383 * @brief Replace characters with value from another string.
4384 * @param __pos1 Index of first character to replace.
4385 * @param __n1 Number of characters to be replaced.
4386 * @param __str String to insert.
4387 * @param __pos2 Index of first character of str to use.
4388 * @param __n2 Number of characters from str to use.
4389 * @return Reference to this string.
4390 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
4392 * @throw std::length_error If new length exceeds @c max_size().
4394 * Removes the characters in the range [__pos1,__pos1 + n) from this
4395 * string. In place, the value of @a __str is inserted. If @a __pos is
4396 * beyond end of string, out_of_range is thrown. If the length of the
4397 * result exceeds max_size(), length_error is thrown. The value of the
4398 * string doesn't change if an error is thrown.
4401 replace(size_type __pos1
, size_type __n1
, const basic_string
& __str
,
4402 size_type __pos2
, size_type __n2
)
4403 { return this->replace(__pos1
, __n1
, __str
._M_data()
4404 + __str
._M_check(__pos2
, "basic_string::replace"),
4405 __str
._M_limit(__pos2
, __n2
)); }
4408 * @brief Replace characters with value of a C substring.
4409 * @param __pos Index of first character to replace.
4410 * @param __n1 Number of characters to be replaced.
4411 * @param __s C string to insert.
4412 * @param __n2 Number of characters from @a s to use.
4413 * @return Reference to this string.
4414 * @throw std::out_of_range If @a pos1 > size().
4415 * @throw std::length_error If new length exceeds @c max_size().
4417 * Removes the characters in the range [__pos,__pos + __n1)
4418 * from this string. In place, the first @a __n2 characters of
4419 * @a __s are inserted, or all of @a __s if @a __n2 is too large. If
4420 * @a __pos is beyond end of string, out_of_range is thrown. If
4421 * the length of result exceeds max_size(), length_error is
4422 * thrown. The value of the string doesn't change if an error
4426 replace(size_type __pos
, size_type __n1
, const _CharT
* __s
,
4430 * @brief Replace characters with value of a C string.
4431 * @param __pos Index of first character to replace.
4432 * @param __n1 Number of characters to be replaced.
4433 * @param __s C string to insert.
4434 * @return Reference to this string.
4435 * @throw std::out_of_range If @a pos > size().
4436 * @throw std::length_error If new length exceeds @c max_size().
4438 * Removes the characters in the range [__pos,__pos + __n1)
4439 * from this string. In place, the characters of @a __s are
4440 * inserted. If @a __pos is beyond end of string, out_of_range
4441 * is thrown. If the length of result exceeds max_size(),
4442 * length_error is thrown. The value of the string doesn't
4443 * change if an error is thrown.
4446 replace(size_type __pos
, size_type __n1
, const _CharT
* __s
)
4448 __glibcxx_requires_string(__s
);
4449 return this->replace(__pos
, __n1
, __s
, traits_type::length(__s
));
4453 * @brief Replace characters with multiple characters.
4454 * @param __pos Index of first character to replace.
4455 * @param __n1 Number of characters to be replaced.
4456 * @param __n2 Number of characters to insert.
4457 * @param __c Character to insert.
4458 * @return Reference to this string.
4459 * @throw std::out_of_range If @a __pos > size().
4460 * @throw std::length_error If new length exceeds @c max_size().
4462 * Removes the characters in the range [pos,pos + n1) from this
4463 * string. In place, @a __n2 copies of @a __c are inserted.
4464 * If @a __pos is beyond end of string, out_of_range is thrown.
4465 * If the length of result exceeds max_size(), length_error is
4466 * thrown. The value of the string doesn't change if an error
4470 replace(size_type __pos
, size_type __n1
, size_type __n2
, _CharT __c
)
4471 { return _M_replace_aux(_M_check(__pos
, "basic_string::replace"),
4472 _M_limit(__pos
, __n1
), __n2
, __c
); }
4475 * @brief Replace range of characters with string.
4476 * @param __i1 Iterator referencing start of range to replace.
4477 * @param __i2 Iterator referencing end of range to replace.
4478 * @param __str String value to insert.
4479 * @return Reference to this string.
4480 * @throw std::length_error If new length exceeds @c max_size().
4482 * Removes the characters in the range [__i1,__i2). In place,
4483 * the value of @a __str is inserted. If the length of result
4484 * exceeds max_size(), length_error is thrown. The value of
4485 * the string doesn't change if an error is thrown.
4488 replace(iterator __i1
, iterator __i2
, const basic_string
& __str
)
4489 { return this->replace(__i1
, __i2
, __str
._M_data(), __str
.size()); }
4492 * @brief Replace range of characters with C substring.
4493 * @param __i1 Iterator referencing start of range to replace.
4494 * @param __i2 Iterator referencing end of range to replace.
4495 * @param __s C string value to insert.
4496 * @param __n Number of characters from s to insert.
4497 * @return Reference to this string.
4498 * @throw std::length_error If new length exceeds @c max_size().
4500 * Removes the characters in the range [__i1,__i2). In place,
4501 * the first @a __n characters of @a __s are inserted. If the
4502 * length of result exceeds max_size(), length_error is thrown.
4503 * The value of the string doesn't change if an error is
4507 replace(iterator __i1
, iterator __i2
, const _CharT
* __s
, size_type __n
)
4509 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
4510 && __i2
<= _M_iend());
4511 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
, __s
, __n
);
4515 * @brief Replace range of characters with C string.
4516 * @param __i1 Iterator referencing start of range to replace.
4517 * @param __i2 Iterator referencing end of range to replace.
4518 * @param __s C string value to insert.
4519 * @return Reference to this string.
4520 * @throw std::length_error If new length exceeds @c max_size().
4522 * Removes the characters in the range [__i1,__i2). In place,
4523 * the characters of @a __s are inserted. If the length of
4524 * result exceeds max_size(), length_error is thrown. The
4525 * value of the string doesn't change if an error is thrown.
4528 replace(iterator __i1
, iterator __i2
, const _CharT
* __s
)
4530 __glibcxx_requires_string(__s
);
4531 return this->replace(__i1
, __i2
, __s
, traits_type::length(__s
));
4535 * @brief Replace range of characters with multiple characters
4536 * @param __i1 Iterator referencing start of range to replace.
4537 * @param __i2 Iterator referencing end of range to replace.
4538 * @param __n Number of characters to insert.
4539 * @param __c Character to insert.
4540 * @return Reference to this string.
4541 * @throw std::length_error If new length exceeds @c max_size().
4543 * Removes the characters in the range [__i1,__i2). In place,
4544 * @a __n copies of @a __c are inserted. If the length of
4545 * result exceeds max_size(), length_error is thrown. The
4546 * value of the string doesn't change if an error is thrown.
4549 replace(iterator __i1
, iterator __i2
, size_type __n
, _CharT __c
)
4551 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
4552 && __i2
<= _M_iend());
4553 return _M_replace_aux(__i1
- _M_ibegin(), __i2
- __i1
, __n
, __c
);
4557 * @brief Replace range of characters with range.
4558 * @param __i1 Iterator referencing start of range to replace.
4559 * @param __i2 Iterator referencing end of range to replace.
4560 * @param __k1 Iterator referencing start of range to insert.
4561 * @param __k2 Iterator referencing end of range to insert.
4562 * @return Reference to this string.
4563 * @throw std::length_error If new length exceeds @c max_size().
4565 * Removes the characters in the range [__i1,__i2). In place,
4566 * characters in the range [__k1,__k2) are inserted. If the
4567 * length of result exceeds max_size(), length_error is thrown.
4568 * The value of the string doesn't change if an error is
4571 template<class _InputIterator
>
4573 replace(iterator __i1
, iterator __i2
,
4574 _InputIterator __k1
, _InputIterator __k2
)
4576 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
4577 && __i2
<= _M_iend());
4578 __glibcxx_requires_valid_range(__k1
, __k2
);
4579 typedef typename
std::__is_integer
<_InputIterator
>::__type _Integral
;
4580 return _M_replace_dispatch(__i1
, __i2
, __k1
, __k2
, _Integral());
4583 // Specializations for the common case of pointer and iterator:
4584 // useful to avoid the overhead of temporary buffering in _M_replace.
4586 replace(iterator __i1
, iterator __i2
, _CharT
* __k1
, _CharT
* __k2
)
4588 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
4589 && __i2
<= _M_iend());
4590 __glibcxx_requires_valid_range(__k1
, __k2
);
4591 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
4596 replace(iterator __i1
, iterator __i2
,
4597 const _CharT
* __k1
, const _CharT
* __k2
)
4599 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
4600 && __i2
<= _M_iend());
4601 __glibcxx_requires_valid_range(__k1
, __k2
);
4602 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
4607 replace(iterator __i1
, iterator __i2
, iterator __k1
, iterator __k2
)
4609 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
4610 && __i2
<= _M_iend());
4611 __glibcxx_requires_valid_range(__k1
, __k2
);
4612 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
4613 __k1
.base(), __k2
- __k1
);
4617 replace(iterator __i1
, iterator __i2
,
4618 const_iterator __k1
, const_iterator __k2
)
4620 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
4621 && __i2
<= _M_iend());
4622 __glibcxx_requires_valid_range(__k1
, __k2
);
4623 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
4624 __k1
.base(), __k2
- __k1
);
4627 #if __cplusplus >= 201103L
4629 * @brief Replace range of characters with initializer_list.
4630 * @param __i1 Iterator referencing start of range to replace.
4631 * @param __i2 Iterator referencing end of range to replace.
4632 * @param __l The initializer_list of characters to insert.
4633 * @return Reference to this string.
4634 * @throw std::length_error If new length exceeds @c max_size().
4636 * Removes the characters in the range [__i1,__i2). In place,
4637 * characters in the range [__k1,__k2) are inserted. If the
4638 * length of result exceeds max_size(), length_error is thrown.
4639 * The value of the string doesn't change if an error is
4642 basic_string
& replace(iterator __i1
, iterator __i2
,
4643 initializer_list
<_CharT
> __l
)
4644 { return this->replace(__i1
, __i2
, __l
.begin(), __l
.end()); }
4648 template<class _Integer
>
4650 _M_replace_dispatch(iterator __i1
, iterator __i2
, _Integer __n
,
4651 _Integer __val
, __true_type
)
4652 { return _M_replace_aux(__i1
- _M_ibegin(), __i2
- __i1
, __n
, __val
); }
4654 template<class _InputIterator
>
4656 _M_replace_dispatch(iterator __i1
, iterator __i2
, _InputIterator __k1
,
4657 _InputIterator __k2
, __false_type
);
4660 _M_replace_aux(size_type __pos1
, size_type __n1
, size_type __n2
,
4664 _M_replace_safe(size_type __pos1
, size_type __n1
, const _CharT
* __s
,
4667 // _S_construct_aux is used to implement the 21.3.1 para 15 which
4668 // requires special behaviour if _InIter is an integral type
4669 template<class _InIterator
>
4671 _S_construct_aux(_InIterator __beg
, _InIterator __end
,
4672 const _Alloc
& __a
, __false_type
)
4674 typedef typename iterator_traits
<_InIterator
>::iterator_category _Tag
;
4675 return _S_construct(__beg
, __end
, __a
, _Tag());
4678 // _GLIBCXX_RESOLVE_LIB_DEFECTS
4679 // 438. Ambiguity in the "do the right thing" clause
4680 template<class _Integer
>
4682 _S_construct_aux(_Integer __beg
, _Integer __end
,
4683 const _Alloc
& __a
, __true_type
)
4684 { return _S_construct_aux_2(static_cast<size_type
>(__beg
),
4688 _S_construct_aux_2(size_type __req
, _CharT __c
, const _Alloc
& __a
)
4689 { return _S_construct(__req
, __c
, __a
); }
4691 template<class _InIterator
>
4693 _S_construct(_InIterator __beg
, _InIterator __end
, const _Alloc
& __a
)
4695 typedef typename
std::__is_integer
<_InIterator
>::__type _Integral
;
4696 return _S_construct_aux(__beg
, __end
, __a
, _Integral());
4699 // For Input Iterators, used in istreambuf_iterators, etc.
4700 template<class _InIterator
>
4702 _S_construct(_InIterator __beg
, _InIterator __end
, const _Alloc
& __a
,
4703 input_iterator_tag
);
4705 // For forward_iterators up to random_access_iterators, used for
4706 // string::iterator, _CharT*, etc.
4707 template<class _FwdIterator
>
4709 _S_construct(_FwdIterator __beg
, _FwdIterator __end
, const _Alloc
& __a
,
4710 forward_iterator_tag
);
4713 _S_construct(size_type __req
, _CharT __c
, const _Alloc
& __a
);
4718 * @brief Copy substring into C string.
4719 * @param __s C string to copy value into.
4720 * @param __n Number of characters to copy.
4721 * @param __pos Index of first character to copy.
4722 * @return Number of characters actually copied
4723 * @throw std::out_of_range If __pos > size().
4725 * Copies up to @a __n characters starting at @a __pos into the
4726 * C string @a __s. If @a __pos is %greater than size(),
4727 * out_of_range is thrown.
4730 copy(_CharT
* __s
, size_type __n
, size_type __pos
= 0) const;
4733 * @brief Swap contents with another string.
4734 * @param __s String to swap with.
4736 * Exchanges the contents of this string with that of @a __s in constant
4739 // PR 58265, this should be noexcept.
4741 swap(basic_string
& __s
);
4743 // String operations:
4745 * @brief Return const pointer to null-terminated contents.
4747 * This is a handle to internal data. Do not modify or dire things may
4751 c_str() const _GLIBCXX_NOEXCEPT
4752 { return _M_data(); }
4755 * @brief Return const pointer to contents.
4757 * This is a pointer to internal data. It is undefined to modify
4758 * the contents through the returned pointer. To get a pointer that
4759 * allows modifying the contents use @c &str[0] instead,
4760 * (or in C++17 the non-const @c str.data() overload).
4763 data() const _GLIBCXX_NOEXCEPT
4764 { return _M_data(); }
4766 #if __cplusplus > 201402L
4768 * @brief Return non-const pointer to contents.
4770 * This is a pointer to the character sequence held by the string.
4771 * Modifying the characters in the sequence is allowed.
4775 { return _M_data(); }
4779 * @brief Return copy of allocator used to construct this string.
4782 get_allocator() const _GLIBCXX_NOEXCEPT
4783 { return _M_dataplus
; }
4786 * @brief Find position of a C substring.
4787 * @param __s C string to locate.
4788 * @param __pos Index of character to search from.
4789 * @param __n Number of characters from @a s to search for.
4790 * @return Index of start of first occurrence.
4792 * Starting from @a __pos, searches forward for the first @a
4793 * __n characters in @a __s within this string. If found,
4794 * returns the index where it begins. If not found, returns
4798 find(const _CharT
* __s
, size_type __pos
, size_type __n
) const
4802 * @brief Find position of a string.
4803 * @param __str String to locate.
4804 * @param __pos Index of character to search from (default 0).
4805 * @return Index of start of first occurrence.
4807 * Starting from @a __pos, searches forward for value of @a __str within
4808 * this string. If found, returns the index where it begins. If not
4809 * found, returns npos.
4812 find(const basic_string
& __str
, size_type __pos
= 0) const
4814 { return this->find(__str
.data(), __pos
, __str
.size()); }
4817 * @brief Find position of a C string.
4818 * @param __s C string to locate.
4819 * @param __pos Index of character to search from (default 0).
4820 * @return Index of start of first occurrence.
4822 * Starting from @a __pos, searches forward for the value of @a
4823 * __s within this string. If found, returns the index where
4824 * it begins. If not found, returns npos.
4827 find(const _CharT
* __s
, size_type __pos
= 0) const _GLIBCXX_NOEXCEPT
4829 __glibcxx_requires_string(__s
);
4830 return this->find(__s
, __pos
, traits_type::length(__s
));
4834 * @brief Find position of a character.
4835 * @param __c Character to locate.
4836 * @param __pos Index of character to search from (default 0).
4837 * @return Index of first occurrence.
4839 * Starting from @a __pos, searches forward for @a __c within
4840 * this string. If found, returns the index where it was
4841 * found. If not found, returns npos.
4844 find(_CharT __c
, size_type __pos
= 0) const _GLIBCXX_NOEXCEPT
;
4847 * @brief Find last position of a string.
4848 * @param __str String to locate.
4849 * @param __pos Index of character to search back from (default end).
4850 * @return Index of start of last occurrence.
4852 * Starting from @a __pos, searches backward for value of @a
4853 * __str within this string. If found, returns the index where
4854 * it begins. If not found, returns npos.
4857 rfind(const basic_string
& __str
, size_type __pos
= npos
) const
4859 { return this->rfind(__str
.data(), __pos
, __str
.size()); }
4862 * @brief Find last position of a C substring.
4863 * @param __s C string to locate.
4864 * @param __pos Index of character to search back from.
4865 * @param __n Number of characters from s to search for.
4866 * @return Index of start of last occurrence.
4868 * Starting from @a __pos, searches backward for the first @a
4869 * __n characters in @a __s within this string. If found,
4870 * returns the index where it begins. If not found, returns
4874 rfind(const _CharT
* __s
, size_type __pos
, size_type __n
) const
4878 * @brief Find last position of a C string.
4879 * @param __s C string to locate.
4880 * @param __pos Index of character to start search at (default end).
4881 * @return Index of start of last occurrence.
4883 * Starting from @a __pos, searches backward for the value of
4884 * @a __s within this string. If found, returns the index
4885 * where it begins. If not found, returns npos.
4888 rfind(const _CharT
* __s
, size_type __pos
= npos
) const _GLIBCXX_NOEXCEPT
4890 __glibcxx_requires_string(__s
);
4891 return this->rfind(__s
, __pos
, traits_type::length(__s
));
4895 * @brief Find last position of a character.
4896 * @param __c Character to locate.
4897 * @param __pos Index of character to search back from (default end).
4898 * @return Index of last occurrence.
4900 * Starting from @a __pos, searches backward for @a __c within
4901 * this string. If found, returns the index where it was
4902 * found. If not found, returns npos.
4905 rfind(_CharT __c
, size_type __pos
= npos
) const _GLIBCXX_NOEXCEPT
;
4908 * @brief Find position of a character of string.
4909 * @param __str String containing characters to locate.
4910 * @param __pos Index of character to search from (default 0).
4911 * @return Index of first occurrence.
4913 * Starting from @a __pos, searches forward for one of the
4914 * characters of @a __str within this string. If found,
4915 * returns the index where it was found. If not found, returns
4919 find_first_of(const basic_string
& __str
, size_type __pos
= 0) const
4921 { return this->find_first_of(__str
.data(), __pos
, __str
.size()); }
4924 * @brief Find position of a character of C substring.
4925 * @param __s String containing characters to locate.
4926 * @param __pos Index of character to search from.
4927 * @param __n Number of characters from s to search for.
4928 * @return Index of first occurrence.
4930 * Starting from @a __pos, searches forward for one of the
4931 * first @a __n characters of @a __s within this string. If
4932 * found, returns the index where it was found. If not found,
4936 find_first_of(const _CharT
* __s
, size_type __pos
, size_type __n
) const
4940 * @brief Find position of a character of C string.
4941 * @param __s String containing characters to locate.
4942 * @param __pos Index of character to search from (default 0).
4943 * @return Index of first occurrence.
4945 * Starting from @a __pos, searches forward for one of the
4946 * characters of @a __s within this string. If found, returns
4947 * the index where it was found. If not found, returns npos.
4950 find_first_of(const _CharT
* __s
, size_type __pos
= 0) const
4953 __glibcxx_requires_string(__s
);
4954 return this->find_first_of(__s
, __pos
, traits_type::length(__s
));
4958 * @brief Find position of a character.
4959 * @param __c Character to locate.
4960 * @param __pos Index of character to search from (default 0).
4961 * @return Index of first occurrence.
4963 * Starting from @a __pos, searches forward for the character
4964 * @a __c within this string. If found, returns the index
4965 * where it was found. If not found, returns npos.
4967 * Note: equivalent to find(__c, __pos).
4970 find_first_of(_CharT __c
, size_type __pos
= 0) const _GLIBCXX_NOEXCEPT
4971 { return this->find(__c
, __pos
); }
4974 * @brief Find last position of a character of string.
4975 * @param __str String containing characters to locate.
4976 * @param __pos Index of character to search back from (default end).
4977 * @return Index of last occurrence.
4979 * Starting from @a __pos, searches backward for one of the
4980 * characters of @a __str within this string. If found,
4981 * returns the index where it was found. If not found, returns
4985 find_last_of(const basic_string
& __str
, size_type __pos
= npos
) const
4987 { return this->find_last_of(__str
.data(), __pos
, __str
.size()); }
4990 * @brief Find last position of a character of C substring.
4991 * @param __s C string containing characters to locate.
4992 * @param __pos Index of character to search back from.
4993 * @param __n Number of characters from s to search for.
4994 * @return Index of last occurrence.
4996 * Starting from @a __pos, searches backward for one of the
4997 * first @a __n characters of @a __s within this string. If
4998 * found, returns the index where it was found. If not found,
5002 find_last_of(const _CharT
* __s
, size_type __pos
, size_type __n
) const
5006 * @brief Find last position of a character of C string.
5007 * @param __s C string containing characters to locate.
5008 * @param __pos Index of character to search back from (default end).
5009 * @return Index of last occurrence.
5011 * Starting from @a __pos, searches backward for one of the
5012 * characters of @a __s within this string. If found, returns
5013 * the index where it was found. If not found, returns npos.
5016 find_last_of(const _CharT
* __s
, size_type __pos
= npos
) const
5019 __glibcxx_requires_string(__s
);
5020 return this->find_last_of(__s
, __pos
, traits_type::length(__s
));
5024 * @brief Find last position of a character.
5025 * @param __c Character to locate.
5026 * @param __pos Index of character to search back from (default end).
5027 * @return Index of last occurrence.
5029 * Starting from @a __pos, searches backward for @a __c within
5030 * this string. If found, returns the index where it was
5031 * found. If not found, returns npos.
5033 * Note: equivalent to rfind(__c, __pos).
5036 find_last_of(_CharT __c
, size_type __pos
= npos
) const _GLIBCXX_NOEXCEPT
5037 { return this->rfind(__c
, __pos
); }
5040 * @brief Find position of a character not in string.
5041 * @param __str String containing characters to avoid.
5042 * @param __pos Index of character to search from (default 0).
5043 * @return Index of first occurrence.
5045 * Starting from @a __pos, searches forward for a character not contained
5046 * in @a __str within this string. If found, returns the index where it
5047 * was found. If not found, returns npos.
5050 find_first_not_of(const basic_string
& __str
, size_type __pos
= 0) const
5052 { return this->find_first_not_of(__str
.data(), __pos
, __str
.size()); }
5055 * @brief Find position of a character not in C substring.
5056 * @param __s C string containing characters to avoid.
5057 * @param __pos Index of character to search from.
5058 * @param __n Number of characters from __s to consider.
5059 * @return Index of first occurrence.
5061 * Starting from @a __pos, searches forward for a character not
5062 * contained in the first @a __n characters of @a __s within
5063 * this string. If found, returns the index where it was
5064 * found. If not found, returns npos.
5067 find_first_not_of(const _CharT
* __s
, size_type __pos
,
5068 size_type __n
) const _GLIBCXX_NOEXCEPT
;
5071 * @brief Find position of a character not in C string.
5072 * @param __s C string containing characters to avoid.
5073 * @param __pos Index of character to search from (default 0).
5074 * @return Index of first occurrence.
5076 * Starting from @a __pos, searches forward for a character not
5077 * contained in @a __s within this string. If found, returns
5078 * the index where it was found. If not found, returns npos.
5081 find_first_not_of(const _CharT
* __s
, size_type __pos
= 0) const
5084 __glibcxx_requires_string(__s
);
5085 return this->find_first_not_of(__s
, __pos
, traits_type::length(__s
));
5089 * @brief Find position of a different character.
5090 * @param __c Character to avoid.
5091 * @param __pos Index of character to search from (default 0).
5092 * @return Index of first occurrence.
5094 * Starting from @a __pos, searches forward for a character
5095 * other than @a __c within this string. If found, returns the
5096 * index where it was found. If not found, returns npos.
5099 find_first_not_of(_CharT __c
, size_type __pos
= 0) const
5103 * @brief Find last position of a character not in string.
5104 * @param __str String containing characters to avoid.
5105 * @param __pos Index of character to search back from (default end).
5106 * @return Index of last occurrence.
5108 * Starting from @a __pos, searches backward for a character
5109 * not contained in @a __str within this string. If found,
5110 * returns the index where it was found. If not found, returns
5114 find_last_not_of(const basic_string
& __str
, size_type __pos
= npos
) const
5116 { return this->find_last_not_of(__str
.data(), __pos
, __str
.size()); }
5119 * @brief Find last position of a character not in C substring.
5120 * @param __s C string containing characters to avoid.
5121 * @param __pos Index of character to search back from.
5122 * @param __n Number of characters from s to consider.
5123 * @return Index of last occurrence.
5125 * Starting from @a __pos, searches backward for a character not
5126 * contained in the first @a __n characters of @a __s within this string.
5127 * If found, returns the index where it was found. If not found,
5131 find_last_not_of(const _CharT
* __s
, size_type __pos
,
5132 size_type __n
) const _GLIBCXX_NOEXCEPT
;
5134 * @brief Find last position of a character not in C string.
5135 * @param __s C string containing characters to avoid.
5136 * @param __pos Index of character to search back from (default end).
5137 * @return Index of last occurrence.
5139 * Starting from @a __pos, searches backward for a character
5140 * not contained in @a __s within this string. If found,
5141 * returns the index where it was found. If not found, returns
5145 find_last_not_of(const _CharT
* __s
, size_type __pos
= npos
) const
5148 __glibcxx_requires_string(__s
);
5149 return this->find_last_not_of(__s
, __pos
, traits_type::length(__s
));
5153 * @brief Find last position of a different character.
5154 * @param __c Character to avoid.
5155 * @param __pos Index of character to search back from (default end).
5156 * @return Index of last occurrence.
5158 * Starting from @a __pos, searches backward for a character other than
5159 * @a __c within this string. If found, returns the index where it was
5160 * found. If not found, returns npos.
5163 find_last_not_of(_CharT __c
, size_type __pos
= npos
) const
5167 * @brief Get a substring.
5168 * @param __pos Index of first character (default 0).
5169 * @param __n Number of characters in substring (default remainder).
5170 * @return The new string.
5171 * @throw std::out_of_range If __pos > size().
5173 * Construct and return a new string using the @a __n
5174 * characters starting at @a __pos. If the string is too
5175 * short, use the remainder of the characters. If @a __pos is
5176 * beyond the end of the string, out_of_range is thrown.
5179 substr(size_type __pos
= 0, size_type __n
= npos
) const
5180 { return basic_string(*this,
5181 _M_check(__pos
, "basic_string::substr"), __n
); }
5184 * @brief Compare to a string.
5185 * @param __str String to compare against.
5186 * @return Integer < 0, 0, or > 0.
5188 * Returns an integer < 0 if this string is ordered before @a
5189 * __str, 0 if their values are equivalent, or > 0 if this
5190 * string is ordered after @a __str. Determines the effective
5191 * length rlen of the strings to compare as the smallest of
5192 * size() and str.size(). The function then compares the two
5193 * strings by calling traits::compare(data(), str.data(),rlen).
5194 * If the result of the comparison is nonzero returns it,
5195 * otherwise the shorter one is ordered first.
5198 compare(const basic_string
& __str
) const
5200 const size_type __size
= this->size();
5201 const size_type __osize
= __str
.size();
5202 const size_type __len
= std::min(__size
, __osize
);
5204 int __r
= traits_type::compare(_M_data(), __str
.data(), __len
);
5206 __r
= _S_compare(__size
, __osize
);
5211 * @brief Compare substring to a string.
5212 * @param __pos Index of first character of substring.
5213 * @param __n Number of characters in substring.
5214 * @param __str String to compare against.
5215 * @return Integer < 0, 0, or > 0.
5217 * Form the substring of this string from the @a __n characters
5218 * starting at @a __pos. Returns an integer < 0 if the
5219 * substring is ordered before @a __str, 0 if their values are
5220 * equivalent, or > 0 if the substring is ordered after @a
5221 * __str. Determines the effective length rlen of the strings
5222 * to compare as the smallest of the length of the substring
5223 * and @a __str.size(). The function then compares the two
5224 * strings by calling
5225 * traits::compare(substring.data(),str.data(),rlen). If the
5226 * result of the comparison is nonzero returns it, otherwise
5227 * the shorter one is ordered first.
5230 compare(size_type __pos
, size_type __n
, const basic_string
& __str
) const;
5233 * @brief Compare substring to a substring.
5234 * @param __pos1 Index of first character of substring.
5235 * @param __n1 Number of characters in substring.
5236 * @param __str String to compare against.
5237 * @param __pos2 Index of first character of substring of str.
5238 * @param __n2 Number of characters in substring of str.
5239 * @return Integer < 0, 0, or > 0.
5241 * Form the substring of this string from the @a __n1
5242 * characters starting at @a __pos1. Form the substring of @a
5243 * __str from the @a __n2 characters starting at @a __pos2.
5244 * Returns an integer < 0 if this substring is ordered before
5245 * the substring of @a __str, 0 if their values are equivalent,
5246 * or > 0 if this substring is ordered after the substring of
5247 * @a __str. Determines the effective length rlen of the
5248 * strings to compare as the smallest of the lengths of the
5249 * substrings. The function then compares the two strings by
5251 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
5252 * If the result of the comparison is nonzero returns it,
5253 * otherwise the shorter one is ordered first.
5256 compare(size_type __pos1
, size_type __n1
, const basic_string
& __str
,
5257 size_type __pos2
, size_type __n2
) const;
5260 * @brief Compare to a C string.
5261 * @param __s C string to compare against.
5262 * @return Integer < 0, 0, or > 0.
5264 * Returns an integer < 0 if this string is ordered before @a __s, 0 if
5265 * their values are equivalent, or > 0 if this string is ordered after
5266 * @a __s. Determines the effective length rlen of the strings to
5267 * compare as the smallest of size() and the length of a string
5268 * constructed from @a __s. The function then compares the two strings
5269 * by calling traits::compare(data(),s,rlen). If the result of the
5270 * comparison is nonzero returns it, otherwise the shorter one is
5274 compare(const _CharT
* __s
) const _GLIBCXX_NOEXCEPT
;
5276 // _GLIBCXX_RESOLVE_LIB_DEFECTS
5277 // 5 String::compare specification questionable
5279 * @brief Compare substring to a C string.
5280 * @param __pos Index of first character of substring.
5281 * @param __n1 Number of characters in substring.
5282 * @param __s C string to compare against.
5283 * @return Integer < 0, 0, or > 0.
5285 * Form the substring of this string from the @a __n1
5286 * characters starting at @a pos. Returns an integer < 0 if
5287 * the substring is ordered before @a __s, 0 if their values
5288 * are equivalent, or > 0 if the substring is ordered after @a
5289 * __s. Determines the effective length rlen of the strings to
5290 * compare as the smallest of the length of the substring and
5291 * the length of a string constructed from @a __s. The
5292 * function then compares the two string by calling
5293 * traits::compare(substring.data(),__s,rlen). If the result of
5294 * the comparison is nonzero returns it, otherwise the shorter
5295 * one is ordered first.
5298 compare(size_type __pos
, size_type __n1
, const _CharT
* __s
) const;
5301 * @brief Compare substring against a character %array.
5302 * @param __pos Index of first character of substring.
5303 * @param __n1 Number of characters in substring.
5304 * @param __s character %array to compare against.
5305 * @param __n2 Number of characters of s.
5306 * @return Integer < 0, 0, or > 0.
5308 * Form the substring of this string from the @a __n1
5309 * characters starting at @a __pos. Form a string from the
5310 * first @a __n2 characters of @a __s. Returns an integer < 0
5311 * if this substring is ordered before the string from @a __s,
5312 * 0 if their values are equivalent, or > 0 if this substring
5313 * is ordered after the string from @a __s. Determines the
5314 * effective length rlen of the strings to compare as the
5315 * smallest of the length of the substring and @a __n2. The
5316 * function then compares the two strings by calling
5317 * traits::compare(substring.data(),s,rlen). If the result of
5318 * the comparison is nonzero returns it, otherwise the shorter
5319 * one is ordered first.
5321 * NB: s must have at least n2 characters, '\\0' has
5322 * no special meaning.
5325 compare(size_type __pos
, size_type __n1
, const _CharT
* __s
,
5326 size_type __n2
) const;
5328 # ifdef _GLIBCXX_TM_TS_INTERNAL
5330 ::_txnal_cow_string_C1_for_exceptions(void* that
, const char* s
,
5333 ::_txnal_cow_string_c_str(const void *that
);
5335 ::_txnal_cow_string_D1(void *that
);
5337 ::_txnal_cow_string_D1_commit(void *that
);
5340 #endif // !_GLIBCXX_USE_CXX11_ABI
5344 * @brief Concatenate two strings.
5345 * @param __lhs First string.
5346 * @param __rhs Last string.
5347 * @return New string with value of @a __lhs followed by @a __rhs.
5349 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5350 basic_string
<_CharT
, _Traits
, _Alloc
>
5351 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5352 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
5354 basic_string
<_CharT
, _Traits
, _Alloc
> __str(__lhs
);
5355 __str
.append(__rhs
);
5360 * @brief Concatenate C string and string.
5361 * @param __lhs First string.
5362 * @param __rhs Last string.
5363 * @return New string with value of @a __lhs followed by @a __rhs.
5365 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5366 basic_string
<_CharT
,_Traits
,_Alloc
>
5367 operator+(const _CharT
* __lhs
,
5368 const basic_string
<_CharT
,_Traits
,_Alloc
>& __rhs
);
5371 * @brief Concatenate character and string.
5372 * @param __lhs First string.
5373 * @param __rhs Last string.
5374 * @return New string with @a __lhs followed by @a __rhs.
5376 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5377 basic_string
<_CharT
,_Traits
,_Alloc
>
5378 operator+(_CharT __lhs
, const basic_string
<_CharT
,_Traits
,_Alloc
>& __rhs
);
5381 * @brief Concatenate string and C string.
5382 * @param __lhs First string.
5383 * @param __rhs Last string.
5384 * @return New string with @a __lhs followed by @a __rhs.
5386 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5387 inline basic_string
<_CharT
, _Traits
, _Alloc
>
5388 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5389 const _CharT
* __rhs
)
5391 basic_string
<_CharT
, _Traits
, _Alloc
> __str(__lhs
);
5392 __str
.append(__rhs
);
5397 * @brief Concatenate string and character.
5398 * @param __lhs First string.
5399 * @param __rhs Last string.
5400 * @return New string with @a __lhs followed by @a __rhs.
5402 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5403 inline basic_string
<_CharT
, _Traits
, _Alloc
>
5404 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
, _CharT __rhs
)
5406 typedef basic_string
<_CharT
, _Traits
, _Alloc
> __string_type
;
5407 typedef typename
__string_type::size_type __size_type
;
5408 __string_type
__str(__lhs
);
5409 __str
.append(__size_type(1), __rhs
);
5413 #if __cplusplus >= 201103L
5414 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5415 inline basic_string
<_CharT
, _Traits
, _Alloc
>
5416 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
5417 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
5418 { return std::move(__lhs
.append(__rhs
)); }
5420 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5421 inline basic_string
<_CharT
, _Traits
, _Alloc
>
5422 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5423 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
5424 { return std::move(__rhs
.insert(0, __lhs
)); }
5426 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5427 inline basic_string
<_CharT
, _Traits
, _Alloc
>
5428 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
5429 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
5431 const auto __size
= __lhs
.size() + __rhs
.size();
5432 const bool __cond
= (__size
> __lhs
.capacity()
5433 && __size
<= __rhs
.capacity());
5434 return __cond
? std::move(__rhs
.insert(0, __lhs
))
5435 : std::move(__lhs
.append(__rhs
));
5438 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5439 inline basic_string
<_CharT
, _Traits
, _Alloc
>
5440 operator+(const _CharT
* __lhs
,
5441 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
5442 { return std::move(__rhs
.insert(0, __lhs
)); }
5444 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5445 inline basic_string
<_CharT
, _Traits
, _Alloc
>
5446 operator+(_CharT __lhs
,
5447 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
5448 { return std::move(__rhs
.insert(0, 1, __lhs
)); }
5450 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5451 inline basic_string
<_CharT
, _Traits
, _Alloc
>
5452 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
5453 const _CharT
* __rhs
)
5454 { return std::move(__lhs
.append(__rhs
)); }
5456 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5457 inline basic_string
<_CharT
, _Traits
, _Alloc
>
5458 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
5460 { return std::move(__lhs
.append(1, __rhs
)); }
5465 * @brief Test equivalence of two strings.
5466 * @param __lhs First string.
5467 * @param __rhs Second string.
5468 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
5470 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5472 operator==(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5473 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
5475 { return __lhs
.compare(__rhs
) == 0; }
5477 template<typename _CharT
>
5479 typename
__gnu_cxx::__enable_if
<__is_char
<_CharT
>::__value
, bool>::__type
5480 operator==(const basic_string
<_CharT
>& __lhs
,
5481 const basic_string
<_CharT
>& __rhs
) _GLIBCXX_NOEXCEPT
5482 { return (__lhs
.size() == __rhs
.size()
5483 && !std::char_traits
<_CharT
>::compare(__lhs
.data(), __rhs
.data(),
5487 * @brief Test equivalence of C string and string.
5488 * @param __lhs C string.
5489 * @param __rhs String.
5490 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
5492 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5494 operator==(const _CharT
* __lhs
,
5495 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
5496 { return __rhs
.compare(__lhs
) == 0; }
5499 * @brief Test equivalence of string and C string.
5500 * @param __lhs String.
5501 * @param __rhs C string.
5502 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
5504 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5506 operator==(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5507 const _CharT
* __rhs
)
5508 { return __lhs
.compare(__rhs
) == 0; }
5512 * @brief Test difference of two strings.
5513 * @param __lhs First string.
5514 * @param __rhs Second string.
5515 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
5517 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5519 operator!=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5520 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
5522 { return !(__lhs
== __rhs
); }
5525 * @brief Test difference of C string and string.
5526 * @param __lhs C string.
5527 * @param __rhs String.
5528 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
5530 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5532 operator!=(const _CharT
* __lhs
,
5533 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
5534 { return !(__lhs
== __rhs
); }
5537 * @brief Test difference of string and C string.
5538 * @param __lhs String.
5539 * @param __rhs C string.
5540 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
5542 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5544 operator!=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5545 const _CharT
* __rhs
)
5546 { return !(__lhs
== __rhs
); }
5550 * @brief Test if string precedes string.
5551 * @param __lhs First string.
5552 * @param __rhs Second string.
5553 * @return True if @a __lhs precedes @a __rhs. False otherwise.
5555 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5557 operator<(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5558 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
5560 { return __lhs
.compare(__rhs
) < 0; }
5563 * @brief Test if string precedes C string.
5564 * @param __lhs String.
5565 * @param __rhs C string.
5566 * @return True if @a __lhs precedes @a __rhs. False otherwise.
5568 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5570 operator<(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5571 const _CharT
* __rhs
)
5572 { return __lhs
.compare(__rhs
) < 0; }
5575 * @brief Test if C string precedes string.
5576 * @param __lhs C string.
5577 * @param __rhs String.
5578 * @return True if @a __lhs precedes @a __rhs. False otherwise.
5580 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5582 operator<(const _CharT
* __lhs
,
5583 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
5584 { return __rhs
.compare(__lhs
) > 0; }
5588 * @brief Test if string follows string.
5589 * @param __lhs First string.
5590 * @param __rhs Second string.
5591 * @return True if @a __lhs follows @a __rhs. False otherwise.
5593 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5595 operator>(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5596 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
5598 { return __lhs
.compare(__rhs
) > 0; }
5601 * @brief Test if string follows C string.
5602 * @param __lhs String.
5603 * @param __rhs C string.
5604 * @return True if @a __lhs follows @a __rhs. False otherwise.
5606 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5608 operator>(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5609 const _CharT
* __rhs
)
5610 { return __lhs
.compare(__rhs
) > 0; }
5613 * @brief Test if C string follows string.
5614 * @param __lhs C string.
5615 * @param __rhs String.
5616 * @return True if @a __lhs follows @a __rhs. False otherwise.
5618 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5620 operator>(const _CharT
* __lhs
,
5621 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
5622 { return __rhs
.compare(__lhs
) < 0; }
5626 * @brief Test if string doesn't follow string.
5627 * @param __lhs First string.
5628 * @param __rhs Second string.
5629 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
5631 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5633 operator<=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5634 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
5636 { return __lhs
.compare(__rhs
) <= 0; }
5639 * @brief Test if string doesn't follow C string.
5640 * @param __lhs String.
5641 * @param __rhs C string.
5642 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
5644 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5646 operator<=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5647 const _CharT
* __rhs
)
5648 { return __lhs
.compare(__rhs
) <= 0; }
5651 * @brief Test if C string doesn't follow string.
5652 * @param __lhs C string.
5653 * @param __rhs String.
5654 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
5656 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5658 operator<=(const _CharT
* __lhs
,
5659 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
5660 { return __rhs
.compare(__lhs
) >= 0; }
5664 * @brief Test if string doesn't precede string.
5665 * @param __lhs First string.
5666 * @param __rhs Second string.
5667 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
5669 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5671 operator>=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5672 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
5674 { return __lhs
.compare(__rhs
) >= 0; }
5677 * @brief Test if string doesn't precede C string.
5678 * @param __lhs String.
5679 * @param __rhs C string.
5680 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
5682 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5684 operator>=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5685 const _CharT
* __rhs
)
5686 { return __lhs
.compare(__rhs
) >= 0; }
5689 * @brief Test if C string doesn't precede string.
5690 * @param __lhs C string.
5691 * @param __rhs String.
5692 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
5694 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5696 operator>=(const _CharT
* __lhs
,
5697 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
5698 { return __rhs
.compare(__lhs
) <= 0; }
5701 * @brief Swap contents of two strings.
5702 * @param __lhs First string.
5703 * @param __rhs Second string.
5705 * Exchanges the contents of @a __lhs and @a __rhs in constant time.
5707 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5709 swap(basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
5710 basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
5711 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs
.swap(__rhs
)))
5712 { __lhs
.swap(__rhs
); }
5716 * @brief Read stream into a string.
5717 * @param __is Input stream.
5718 * @param __str Buffer to store into.
5719 * @return Reference to the input stream.
5721 * Stores characters from @a __is into @a __str until whitespace is
5722 * found, the end of the stream is encountered, or str.max_size()
5723 * is reached. If is.width() is non-zero, that is the limit on the
5724 * number of characters stored into @a __str. Any previous
5725 * contents of @a __str are erased.
5727 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5728 basic_istream
<_CharT
, _Traits
>&
5729 operator>>(basic_istream
<_CharT
, _Traits
>& __is
,
5730 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
);
5733 basic_istream
<char>&
5734 operator>>(basic_istream
<char>& __is
, basic_string
<char>& __str
);
5737 * @brief Write string to a stream.
5738 * @param __os Output stream.
5739 * @param __str String to write out.
5740 * @return Reference to the output stream.
5742 * Output characters of @a __str into os following the same rules as for
5743 * writing a C string.
5745 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5746 inline basic_ostream
<_CharT
, _Traits
>&
5747 operator<<(basic_ostream
<_CharT
, _Traits
>& __os
,
5748 const basic_string
<_CharT
, _Traits
, _Alloc
>& __str
)
5750 // _GLIBCXX_RESOLVE_LIB_DEFECTS
5751 // 586. string inserter not a formatted function
5752 return __ostream_insert(__os
, __str
.data(), __str
.size());
5756 * @brief Read a line from stream into a string.
5757 * @param __is Input stream.
5758 * @param __str Buffer to store into.
5759 * @param __delim Character marking end of line.
5760 * @return Reference to the input stream.
5762 * Stores characters from @a __is into @a __str until @a __delim is
5763 * found, the end of the stream is encountered, or str.max_size()
5764 * is reached. Any previous contents of @a __str are erased. If
5765 * @a __delim is encountered, it is extracted but not stored into
5768 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5769 basic_istream
<_CharT
, _Traits
>&
5770 getline(basic_istream
<_CharT
, _Traits
>& __is
,
5771 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
, _CharT __delim
);
5774 * @brief Read a line from stream into a string.
5775 * @param __is Input stream.
5776 * @param __str Buffer to store into.
5777 * @return Reference to the input stream.
5779 * Stores characters from is into @a __str until '\n' is
5780 * found, the end of the stream is encountered, or str.max_size()
5781 * is reached. Any previous contents of @a __str are erased. If
5782 * end of line is encountered, it is extracted but not stored into
5785 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5786 inline basic_istream
<_CharT
, _Traits
>&
5787 getline(basic_istream
<_CharT
, _Traits
>& __is
,
5788 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
)
5789 { return std::getline(__is
, __str
, __is
.widen('\n')); }
5791 #if __cplusplus >= 201103L
5792 /// Read a line from an rvalue stream into a string.
5793 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5794 inline basic_istream
<_CharT
, _Traits
>&
5795 getline(basic_istream
<_CharT
, _Traits
>&& __is
,
5796 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
, _CharT __delim
)
5797 { return std::getline(__is
, __str
, __delim
); }
5799 /// Read a line from an rvalue stream into a string.
5800 template<typename _CharT
, typename _Traits
, typename _Alloc
>
5801 inline basic_istream
<_CharT
, _Traits
>&
5802 getline(basic_istream
<_CharT
, _Traits
>&& __is
,
5803 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
)
5804 { return std::getline(__is
, __str
); }
5808 basic_istream
<char>&
5809 getline(basic_istream
<char>& __in
, basic_string
<char>& __str
,
5812 #ifdef _GLIBCXX_USE_WCHAR_T
5814 basic_istream
<wchar_t>&
5815 getline(basic_istream
<wchar_t>& __in
, basic_string
<wchar_t>& __str
,
5819 _GLIBCXX_END_NAMESPACE_VERSION
5822 #if __cplusplus >= 201103L
5824 #include <ext/string_conversions.h>
5826 namespace std
_GLIBCXX_VISIBILITY(default)
5828 _GLIBCXX_BEGIN_NAMESPACE_VERSION
5829 _GLIBCXX_BEGIN_NAMESPACE_CXX11
5831 #if _GLIBCXX_USE_C99_STDLIB
5832 // 21.4 Numeric Conversions [string.conversions].
5834 stoi(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
5835 { return __gnu_cxx::__stoa
<long, int>(&std::strtol
, "stoi", __str
.c_str(),
5839 stol(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
5840 { return __gnu_cxx::__stoa(&std::strtol
, "stol", __str
.c_str(),
5843 inline unsigned long
5844 stoul(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
5845 { return __gnu_cxx::__stoa(&std::strtoul
, "stoul", __str
.c_str(),
5849 stoll(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
5850 { return __gnu_cxx::__stoa(&std::strtoll
, "stoll", __str
.c_str(),
5853 inline unsigned long long
5854 stoull(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
5855 { return __gnu_cxx::__stoa(&std::strtoull
, "stoull", __str
.c_str(),
5858 // NB: strtof vs strtod.
5860 stof(const string
& __str
, size_t* __idx
= 0)
5861 { return __gnu_cxx::__stoa(&std::strtof
, "stof", __str
.c_str(), __idx
); }
5864 stod(const string
& __str
, size_t* __idx
= 0)
5865 { return __gnu_cxx::__stoa(&std::strtod
, "stod", __str
.c_str(), __idx
); }
5868 stold(const string
& __str
, size_t* __idx
= 0)
5869 { return __gnu_cxx::__stoa(&std::strtold
, "stold", __str
.c_str(), __idx
); }
5870 #endif // _GLIBCXX_USE_C99_STDLIB
5872 #if _GLIBCXX_USE_C99_STDIO
5873 // NB: (v)snprintf vs sprintf.
5877 to_string(int __val
)
5878 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, 4 * sizeof(int),
5882 to_string(unsigned __val
)
5883 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
5884 4 * sizeof(unsigned),
5888 to_string(long __val
)
5889 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, 4 * sizeof(long),
5893 to_string(unsigned long __val
)
5894 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
5895 4 * sizeof(unsigned long),
5899 to_string(long long __val
)
5900 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
5901 4 * sizeof(long long),
5905 to_string(unsigned long long __val
)
5906 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
5907 4 * sizeof(unsigned long long),
5911 to_string(float __val
)
5914 __gnu_cxx::__numeric_traits
<float>::__max_exponent10
+ 20;
5915 return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, __n
,
5920 to_string(double __val
)
5923 __gnu_cxx::__numeric_traits
<double>::__max_exponent10
+ 20;
5924 return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, __n
,
5929 to_string(long double __val
)
5932 __gnu_cxx::__numeric_traits
<long double>::__max_exponent10
+ 20;
5933 return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, __n
,
5936 #endif // _GLIBCXX_USE_C99_STDIO
5938 #if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR
5940 stoi(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
5941 { return __gnu_cxx::__stoa
<long, int>(&std::wcstol
, "stoi", __str
.c_str(),
5945 stol(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
5946 { return __gnu_cxx::__stoa(&std::wcstol
, "stol", __str
.c_str(),
5949 inline unsigned long
5950 stoul(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
5951 { return __gnu_cxx::__stoa(&std::wcstoul
, "stoul", __str
.c_str(),
5955 stoll(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
5956 { return __gnu_cxx::__stoa(&std::wcstoll
, "stoll", __str
.c_str(),
5959 inline unsigned long long
5960 stoull(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
5961 { return __gnu_cxx::__stoa(&std::wcstoull
, "stoull", __str
.c_str(),
5964 // NB: wcstof vs wcstod.
5966 stof(const wstring
& __str
, size_t* __idx
= 0)
5967 { return __gnu_cxx::__stoa(&std::wcstof
, "stof", __str
.c_str(), __idx
); }
5970 stod(const wstring
& __str
, size_t* __idx
= 0)
5971 { return __gnu_cxx::__stoa(&std::wcstod
, "stod", __str
.c_str(), __idx
); }
5974 stold(const wstring
& __str
, size_t* __idx
= 0)
5975 { return __gnu_cxx::__stoa(&std::wcstold
, "stold", __str
.c_str(), __idx
); }
5977 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
5980 to_wstring(int __val
)
5981 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, 4 * sizeof(int),
5985 to_wstring(unsigned __val
)
5986 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
5987 4 * sizeof(unsigned),
5991 to_wstring(long __val
)
5992 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, 4 * sizeof(long),
5996 to_wstring(unsigned long __val
)
5997 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
5998 4 * sizeof(unsigned long),
6002 to_wstring(long long __val
)
6003 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
6004 4 * sizeof(long long),
6008 to_wstring(unsigned long long __val
)
6009 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
6010 4 * sizeof(unsigned long long),
6014 to_wstring(float __val
)
6017 __gnu_cxx::__numeric_traits
<float>::__max_exponent10
+ 20;
6018 return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, __n
,
6023 to_wstring(double __val
)
6026 __gnu_cxx::__numeric_traits
<double>::__max_exponent10
+ 20;
6027 return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, __n
,
6032 to_wstring(long double __val
)
6035 __gnu_cxx::__numeric_traits
<long double>::__max_exponent10
+ 20;
6036 return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, __n
,
6039 #endif // _GLIBCXX_HAVE_BROKEN_VSWPRINTF
6040 #endif // _GLIBCXX_USE_WCHAR_T && _GLIBCXX_USE_C99_WCHAR
6042 _GLIBCXX_END_NAMESPACE_CXX11
6043 _GLIBCXX_END_NAMESPACE_VERSION
6048 #if __cplusplus >= 201103L
6050 #include <bits/functional_hash.h>
6052 namespace std
_GLIBCXX_VISIBILITY(default)
6054 _GLIBCXX_BEGIN_NAMESPACE_VERSION
6058 #ifndef _GLIBCXX_COMPATIBILITY_CXX0X
6059 /// std::hash specialization for string.
6062 : public __hash_base
<size_t, string
>
6065 operator()(const string
& __s
) const noexcept
6066 { return std::_Hash_impl::hash(__s
.data(), __s
.length()); }
6070 struct __is_fast_hash
<hash
<string
>> : std::false_type
6073 #ifdef _GLIBCXX_USE_WCHAR_T
6074 /// std::hash specialization for wstring.
6076 struct hash
<wstring
>
6077 : public __hash_base
<size_t, wstring
>
6080 operator()(const wstring
& __s
) const noexcept
6081 { return std::_Hash_impl::hash(__s
.data(),
6082 __s
.length() * sizeof(wchar_t)); }
6086 struct __is_fast_hash
<hash
<wstring
>> : std::false_type
6089 #endif /* _GLIBCXX_COMPATIBILITY_CXX0X */
6091 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
6092 /// std::hash specialization for u16string.
6094 struct hash
<u16string
>
6095 : public __hash_base
<size_t, u16string
>
6098 operator()(const u16string
& __s
) const noexcept
6099 { return std::_Hash_impl::hash(__s
.data(),
6100 __s
.length() * sizeof(char16_t
)); }
6104 struct __is_fast_hash
<hash
<u16string
>> : std::false_type
6107 /// std::hash specialization for u32string.
6109 struct hash
<u32string
>
6110 : public __hash_base
<size_t, u32string
>
6113 operator()(const u32string
& __s
) const noexcept
6114 { return std::_Hash_impl::hash(__s
.data(),
6115 __s
.length() * sizeof(char32_t
)); }
6119 struct __is_fast_hash
<hash
<u32string
>> : std::false_type
6123 _GLIBCXX_END_NAMESPACE_VERSION
6125 #if __cplusplus > 201103L
6127 #define __cpp_lib_string_udls 201304
6129 inline namespace literals
6131 inline namespace string_literals
6133 _GLIBCXX_BEGIN_NAMESPACE_VERSION
6135 _GLIBCXX_DEFAULT_ABI_TAG
6136 inline basic_string
<char>
6137 operator""s(const char* __str
, size_t __len
)
6138 { return basic_string
<char>{__str
, __len
}; }
6140 #ifdef _GLIBCXX_USE_WCHAR_T
6141 _GLIBCXX_DEFAULT_ABI_TAG
6142 inline basic_string
<wchar_t>
6143 operator""s(const wchar_t* __str
, size_t __len
)
6144 { return basic_string
<wchar_t>{__str
, __len
}; }
6147 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
6148 _GLIBCXX_DEFAULT_ABI_TAG
6149 inline basic_string
<char16_t
>
6150 operator""s(const char16_t
* __str
, size_t __len
)
6151 { return basic_string
<char16_t
>{__str
, __len
}; }
6153 _GLIBCXX_DEFAULT_ABI_TAG
6154 inline basic_string
<char32_t
>
6155 operator""s(const char32_t
* __str
, size_t __len
)
6156 { return basic_string
<char32_t
>{__str
, __len
}; }
6159 _GLIBCXX_END_NAMESPACE_VERSION
6160 } // inline namespace string_literals
6161 } // inline namespace literals
6163 #endif // __cplusplus > 201103L
6169 #endif /* _BASIC_STRING_H */