1 // Components for manipulating sequences of characters -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 // ISO C++ 14882: 21 Strings library
35 /** @file basic_string.h
36 * This is an internal header file, included by other library headers.
37 * You should not attempt to use it directly.
40 #ifndef _BASIC_STRING_H
41 #define _BASIC_STRING_H 1
43 #pragma GCC system_header
45 #include <bits/atomicity.h>
46 #include <debug/debug.h>
51 * @class basic_string basic_string.h <string>
52 * @brief Managing sequences of characters and character-like objects.
57 * Meets the requirements of a <a href="tables.html#65">container</a>, a
58 * <a href="tables.html#66">reversible container</a>, and a
59 * <a href="tables.html#67">sequence</a>. Of the
60 * <a href="tables.html#68">optional sequence requirements</a>, only
61 * @c push_back, @c at, and array access are supported.
67 * Documentation? What's that?
68 * Nathan Myers <ncm@cantrip.org>.
70 * A string looks like this:
75 * [basic_string<char_type>] _M_capacity
76 * _M_dataplus _M_refcount
77 * _M_p ----------------> unnamed array of char_type
80 * Where the _M_p points to the first character in the string, and
81 * you cast it to a pointer-to-_Rep and subtract 1 to get a
82 * pointer to the header.
84 * This approach has the enormous advantage that a string object
85 * requires only one allocation. All the ugliness is confined
86 * within a single pair of inline functions, which each compile to
87 * a single "add" instruction: _Rep::_M_data(), and
88 * string::_M_rep(); and the allocation function which gets a
89 * block of raw bytes and with room enough and constructs a _Rep
90 * object at the front.
92 * The reason you want _M_data pointing to the character array and
93 * not the _Rep is so that the debugger can see the string
94 * contents. (Probably we should add a non-inline member to get
95 * the _Rep for the debugger to use, so users can check the actual
98 * Note that the _Rep object is a POD so that you can have a
99 * static "empty string" _Rep object already "constructed" before
100 * static constructors have run. The reference-count encoding is
101 * chosen so that a 0 indicates one reference, so you never try to
102 * destroy the empty-string _Rep object.
104 * All but the last paragraph is considered pretty conventional
105 * for a C++ string implementation.
108 // 21.3 Template class basic_string
109 template<typename _CharT
, typename _Traits
, typename _Alloc
>
112 typedef typename
_Alloc::template rebind
<_CharT
>::other _CharT_alloc_type
;
116 typedef _Traits traits_type
;
117 typedef typename
_Traits::char_type value_type
;
118 typedef _Alloc allocator_type
;
119 typedef typename
_CharT_alloc_type::size_type size_type
;
120 typedef typename
_CharT_alloc_type::difference_type difference_type
;
121 typedef typename
_CharT_alloc_type::reference reference
;
122 typedef typename
_CharT_alloc_type::const_reference const_reference
;
123 typedef typename
_CharT_alloc_type::pointer pointer
;
124 typedef typename
_CharT_alloc_type::const_pointer const_pointer
;
125 typedef __gnu_cxx::__normal_iterator
<pointer
, basic_string
> iterator
;
126 typedef __gnu_cxx::__normal_iterator
<const_pointer
, basic_string
>
128 typedef std::reverse_iterator
<const_iterator
> const_reverse_iterator
;
129 typedef std::reverse_iterator
<iterator
> reverse_iterator
;
132 // _Rep: string representation
134 // 1. String really contains _M_length + 1 characters: due to 21.3.4
135 // must be kept null-terminated.
136 // 2. _M_capacity >= _M_length
137 // Allocated memory is always (_M_capacity + 1) * sizeof(_CharT).
138 // 3. _M_refcount has three states:
139 // -1: leaked, one reference, no ref-copies allowed, non-const.
140 // 0: one reference, non-const.
141 // n>0: n + 1 references, operations require a lock, const.
142 // 4. All fields==0 is an empty string, given the extra storage
143 // beyond-the-end for a null terminator; thus, the shared
144 // empty string representation needs no constructor.
149 size_type _M_capacity
;
150 _Atomic_word _M_refcount
;
153 struct _Rep
: _Rep_base
156 typedef typename
_Alloc::template rebind
<char>::other _Raw_bytes_alloc
;
158 // (Public) Data members:
160 // The maximum number of individual char_type elements of an
161 // individual string is determined by _S_max_size. This is the
162 // value that will be returned by max_size(). (Whereas npos
163 // is the maximum number of bytes the allocator can allocate.)
164 // If one was to divvy up the theoretical largest size string,
165 // with a terminating character and m _CharT elements, it'd
167 // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
169 // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
170 // In addition, this implementation quarters this amount.
171 static const size_type _S_max_size
;
172 static const _CharT _S_terminal
;
174 // The following storage is init'd to 0 by the linker, resulting
175 // (carefully) in an empty string with one reference.
176 static size_type _S_empty_rep_storage
[];
181 void* __p
= reinterpret_cast<void*>(&_S_empty_rep_storage
);
182 return *reinterpret_cast<_Rep
*>(__p
);
187 { return this->_M_refcount
< 0; }
191 { return this->_M_refcount
> 0; }
195 { this->_M_refcount
= -1; }
199 { this->_M_refcount
= 0; }
202 _M_set_length_and_sharable(size_type __n
)
204 this->_M_set_sharable(); // One reference.
205 this->_M_length
= __n
;
206 traits_type::assign(this->_M_refdata()[__n
], _S_terminal
);
207 // grrr. (per 21.3.4)
208 // You cannot leave those LWG people alone for a second.
213 { return reinterpret_cast<_CharT
*>(this + 1); }
216 _M_grab(const _Alloc
& __alloc1
, const _Alloc
& __alloc2
)
218 return (!_M_is_leaked() && __alloc1
== __alloc2
)
219 ? _M_refcopy() : _M_clone(__alloc1
);
224 _S_create(size_type
, size_type
, const _Alloc
&);
227 _M_dispose(const _Alloc
& __a
)
229 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
230 if (__builtin_expect(this != &_S_empty_rep(), false))
232 if (__gnu_cxx::__exchange_and_add(&this->_M_refcount
, -1) <= 0)
237 _M_destroy(const _Alloc
&) throw();
242 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
243 if (__builtin_expect(this != &_S_empty_rep(), false))
245 __gnu_cxx::__atomic_add(&this->_M_refcount
, 1);
250 _M_clone(const _Alloc
&, size_type __res
= 0);
253 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
254 struct _Alloc_hider
: _Alloc
256 _Alloc_hider(_CharT
* __dat
, const _Alloc
& __a
)
257 : _Alloc(__a
), _M_p(__dat
) { }
259 _CharT
* _M_p
; // The actual data.
263 // Data Members (public):
264 // NB: This is an unsigned type, and thus represents the maximum
265 // size that the allocator can hold.
266 /// Value returned by various member functions when they fail.
267 static const size_type npos
= static_cast<size_type
>(-1);
270 // Data Members (private):
271 mutable _Alloc_hider _M_dataplus
;
275 { return _M_dataplus
._M_p
; }
279 { return (_M_dataplus
._M_p
= __p
); }
283 { return &((reinterpret_cast<_Rep
*> (_M_data()))[-1]); }
285 // For the internal use we have functions similar to `begin'/`end'
286 // but they do not call _M_leak.
289 { return iterator(_M_data()); }
293 { return iterator(_M_data() + this->size()); }
296 _M_leak() // for use in begin() & non-const op[]
298 if (!_M_rep()->_M_is_leaked())
303 _M_check(size_type __pos
, const char* __s
) const
305 if (__pos
> this->size())
306 __throw_out_of_range(__N(__s
));
311 _M_check_length(size_type __n1
, size_type __n2
, const char* __s
) const
313 if (this->max_size() - (this->size() - __n1
) < __n2
)
314 __throw_length_error(__N(__s
));
317 // NB: _M_limit doesn't check for a bad __pos value.
319 _M_limit(size_type __pos
, size_type __off
) const
321 const bool __testoff
= __off
< this->size() - __pos
;
322 return __testoff
? __off
: this->size() - __pos
;
325 // True if _Rep and source do not overlap.
327 _M_disjunct(const _CharT
* __s
) const
329 return (less
<const _CharT
*>()(__s
, _M_data())
330 || less
<const _CharT
*>()(_M_data() + this->size(), __s
));
333 // When __n = 1 way faster than the general multichar
334 // traits_type::copy/move/assign.
336 _M_copy(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
339 traits_type::assign(*__d
, *__s
);
341 traits_type::copy(__d
, __s
, __n
);
345 _M_move(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
348 traits_type::assign(*__d
, *__s
);
350 traits_type::move(__d
, __s
, __n
);
354 _M_assign(_CharT
* __d
, size_type __n
, _CharT __c
)
357 traits_type::assign(*__d
, __c
);
359 traits_type::assign(__d
, __n
, __c
);
362 // _S_copy_chars is a separate template to permit specialization
363 // to optimize for the common case of pointers as iterators.
364 template<class _Iterator
>
366 _S_copy_chars(_CharT
* __p
, _Iterator __k1
, _Iterator __k2
)
368 for (; __k1
!= __k2
; ++__k1
, ++__p
)
369 traits_type::assign(*__p
, *__k1
); // These types are off.
373 _S_copy_chars(_CharT
* __p
, iterator __k1
, iterator __k2
)
374 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
377 _S_copy_chars(_CharT
* __p
, const_iterator __k1
, const_iterator __k2
)
378 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
381 _S_copy_chars(_CharT
* __p
, _CharT
* __k1
, _CharT
* __k2
)
382 { _M_copy(__p
, __k1
, __k2
- __k1
); }
385 _S_copy_chars(_CharT
* __p
, const _CharT
* __k1
, const _CharT
* __k2
)
386 { _M_copy(__p
, __k1
, __k2
- __k1
); }
389 _M_mutate(size_type __pos
, size_type __len1
, size_type __len2
);
396 { return _Rep::_S_empty_rep(); }
399 // Construct/copy/destroy:
400 // NB: We overload ctors in some cases instead of using default
401 // arguments, per 17.4.4.4 para. 2 item 2.
404 * @brief Default constructor creates an empty string.
410 * @brief Construct an empty string using allocator @a a.
413 basic_string(const _Alloc
& __a
);
415 // NB: per LWG issue 42, semantics different from IS:
417 * @brief Construct string with copy of value of @a str.
418 * @param str Source string.
420 basic_string(const basic_string
& __str
);
422 * @brief Construct string as copy of a substring.
423 * @param str Source string.
424 * @param pos Index of first character to copy from.
425 * @param n Number of characters to copy (default remainder).
427 basic_string(const basic_string
& __str
, size_type __pos
,
428 size_type __n
= npos
);
430 * @brief Construct string as copy of a substring.
431 * @param str Source string.
432 * @param pos Index of first character to copy from.
433 * @param n Number of characters to copy.
434 * @param a Allocator to use.
436 basic_string(const basic_string
& __str
, size_type __pos
,
437 size_type __n
, const _Alloc
& __a
);
440 * @brief Construct string initialized by a character array.
441 * @param s Source character array.
442 * @param n Number of characters to copy.
443 * @param a Allocator to use (default is default allocator).
445 * NB: @a s must have at least @a n characters, '\0' has no special
448 basic_string(const _CharT
* __s
, size_type __n
,
449 const _Alloc
& __a
= _Alloc());
451 * @brief Construct string as copy of a C string.
452 * @param s Source C string.
453 * @param a Allocator to use (default is default allocator).
455 basic_string(const _CharT
* __s
, const _Alloc
& __a
= _Alloc());
457 * @brief Construct string as multiple characters.
458 * @param n Number of characters.
459 * @param c Character to use.
460 * @param a Allocator to use (default is default allocator).
462 basic_string(size_type __n
, _CharT __c
, const _Alloc
& __a
= _Alloc());
465 * @brief Construct string as copy of a range.
466 * @param beg Start of range.
467 * @param end End of range.
468 * @param a Allocator to use (default is default allocator).
470 template<class _InputIterator
>
471 basic_string(_InputIterator __beg
, _InputIterator __end
,
472 const _Alloc
& __a
= _Alloc());
475 * @brief Destroy the string instance.
478 { _M_rep()->_M_dispose(this->get_allocator()); }
481 * @brief Assign the value of @a str to this string.
482 * @param str Source string.
485 operator=(const basic_string
& __str
)
486 { return this->assign(__str
); }
489 * @brief Copy contents of @a s into this string.
490 * @param s Source null-terminated string.
493 operator=(const _CharT
* __s
)
494 { return this->assign(__s
); }
497 * @brief Set value to string of length 1.
498 * @param c Source character.
500 * Assigning to a character makes this string length 1 and
501 * (*this)[0] == @a c.
504 operator=(_CharT __c
)
506 this->assign(1, __c
);
512 * Returns a read/write iterator that points to the first character in
513 * the %string. Unshares the string.
519 return iterator(_M_data());
523 * Returns a read-only (constant) iterator that points to the first
524 * character in the %string.
528 { return const_iterator(_M_data()); }
531 * Returns a read/write iterator that points one past the last
532 * character in the %string. Unshares the string.
538 return iterator(_M_data() + this->size());
542 * Returns a read-only (constant) iterator that points one past the
543 * last character in the %string.
547 { return const_iterator(_M_data() + this->size()); }
550 * Returns a read/write reverse iterator that points to the last
551 * character in the %string. Iteration is done in reverse element
552 * order. Unshares the string.
556 { return reverse_iterator(this->end()); }
559 * Returns a read-only (constant) reverse iterator that points
560 * to the last character in the %string. Iteration is done in
561 * reverse element order.
563 const_reverse_iterator
565 { return const_reverse_iterator(this->end()); }
568 * Returns a read/write reverse iterator that points to one before the
569 * first character in the %string. Iteration is done in reverse
570 * element order. Unshares the string.
574 { return reverse_iterator(this->begin()); }
577 * Returns a read-only (constant) reverse iterator that points
578 * to one before the first character in the %string. Iteration
579 * is done in reverse element order.
581 const_reverse_iterator
583 { return const_reverse_iterator(this->begin()); }
587 /// Returns the number of characters in the string, not including any
588 /// null-termination.
591 { return _M_rep()->_M_length
; }
593 /// Returns the number of characters in the string, not including any
594 /// null-termination.
597 { return _M_rep()->_M_length
; }
599 /// Returns the size() of the largest possible %string.
602 { return _Rep::_S_max_size
; }
605 * @brief Resizes the %string to the specified number of characters.
606 * @param n Number of characters the %string should contain.
607 * @param c Character to fill any new elements.
609 * This function will %resize the %string to the specified
610 * number of characters. If the number is smaller than the
611 * %string's current size the %string is truncated, otherwise
612 * the %string is extended and new elements are set to @a c.
615 resize(size_type __n
, _CharT __c
);
618 * @brief Resizes the %string to the specified number of characters.
619 * @param n Number of characters the %string should contain.
621 * This function will resize the %string to the specified length. If
622 * the new size is smaller than the %string's current size the %string
623 * is truncated, otherwise the %string is extended and new characters
624 * are default-constructed. For basic types such as char, this means
628 resize(size_type __n
)
629 { this->resize(__n
, _CharT()); }
632 * Returns the total number of characters that the %string can hold
633 * before needing to allocate more memory.
637 { return _M_rep()->_M_capacity
; }
640 * @brief Attempt to preallocate enough memory for specified number of
642 * @param res_arg Number of characters required.
643 * @throw std::length_error If @a res_arg exceeds @c max_size().
645 * This function attempts to reserve enough memory for the
646 * %string to hold the specified number of characters. If the
647 * number requested is more than max_size(), length_error is
650 * The advantage of this function is that if optimal code is a
651 * necessity and the user can determine the string length that will be
652 * required, the user can reserve the memory in %advance, and thus
653 * prevent a possible reallocation of memory and copying of %string
657 reserve(size_type __res_arg
= 0);
660 * Erases the string, making it empty.
664 { _M_mutate(0, this->size(), 0); }
667 * Returns true if the %string is empty. Equivalent to *this == "".
671 { return this->size() == 0; }
675 * @brief Subscript access to the data contained in the %string.
676 * @param pos The index of the character to access.
677 * @return Read-only (constant) reference to the character.
679 * This operator allows for easy, array-style, data access.
680 * Note that data access with this operator is unchecked and
681 * out_of_range lookups are not defined. (For checked lookups
685 operator[] (size_type __pos
) const
687 _GLIBCXX_DEBUG_ASSERT(__pos
<= size());
688 return _M_data()[__pos
];
692 * @brief Subscript access to the data contained in the %string.
693 * @param pos The index of the character to access.
694 * @return Read/write reference to the character.
696 * This operator allows for easy, array-style, data access.
697 * Note that data access with this operator is unchecked and
698 * out_of_range lookups are not defined. (For checked lookups
699 * see at().) Unshares the string.
702 operator[](size_type __pos
)
704 // allow pos == size() as v3 extension:
705 _GLIBCXX_DEBUG_ASSERT(__pos
<= size());
706 // but be strict in pedantic mode:
707 _GLIBCXX_DEBUG_PEDASSERT(__pos
< size());
709 return _M_data()[__pos
];
713 * @brief Provides access to the data contained in the %string.
714 * @param n The index of the character to access.
715 * @return Read-only (const) reference to the character.
716 * @throw std::out_of_range If @a n is an invalid index.
718 * This function provides for safer data access. The parameter is
719 * first checked that it is in the range of the string. The function
720 * throws out_of_range if the check fails.
723 at(size_type __n
) const
725 if (__n
>= this->size())
726 __throw_out_of_range(__N("basic_string::at"));
727 return _M_data()[__n
];
731 * @brief Provides access to the data contained in the %string.
732 * @param n The index of the character to access.
733 * @return Read/write reference to the character.
734 * @throw std::out_of_range If @a n is an invalid index.
736 * This function provides for safer data access. The parameter is
737 * first checked that it is in the range of the string. The function
738 * throws out_of_range if the check fails. Success results in
739 * unsharing the string.
745 __throw_out_of_range(__N("basic_string::at"));
747 return _M_data()[__n
];
752 * @brief Append a string to this string.
753 * @param str The string to append.
754 * @return Reference to this string.
757 operator+=(const basic_string
& __str
)
758 { return this->append(__str
); }
761 * @brief Append a C string.
762 * @param s The C string to append.
763 * @return Reference to this string.
766 operator+=(const _CharT
* __s
)
767 { return this->append(__s
); }
770 * @brief Append a character.
771 * @param c The character to append.
772 * @return Reference to this string.
775 operator+=(_CharT __c
)
777 this->push_back(__c
);
782 * @brief Append a string to this string.
783 * @param str The string to append.
784 * @return Reference to this string.
787 append(const basic_string
& __str
);
790 * @brief Append a substring.
791 * @param str The string to append.
792 * @param pos Index of the first character of str to append.
793 * @param n The number of characters to append.
794 * @return Reference to this string.
795 * @throw std::out_of_range if @a pos is not a valid index.
797 * This function appends @a n characters from @a str starting at @a pos
798 * to this string. If @a n is is larger than the number of available
799 * characters in @a str, the remainder of @a str is appended.
802 append(const basic_string
& __str
, size_type __pos
, size_type __n
);
805 * @brief Append a C substring.
806 * @param s The C string to append.
807 * @param n The number of characters to append.
808 * @return Reference to this string.
811 append(const _CharT
* __s
, size_type __n
);
814 * @brief Append a C string.
815 * @param s The C string to append.
816 * @return Reference to this string.
819 append(const _CharT
* __s
)
821 __glibcxx_requires_string(__s
);
822 return this->append(__s
, traits_type::length(__s
));
826 * @brief Append multiple characters.
827 * @param n The number of characters to append.
828 * @param c The character to use.
829 * @return Reference to this string.
831 * Appends n copies of c to this string.
834 append(size_type __n
, _CharT __c
);
837 * @brief Append a range of characters.
838 * @param first Iterator referencing the first character to append.
839 * @param last Iterator marking the end of the range.
840 * @return Reference to this string.
842 * Appends characters in the range [first,last) to this string.
844 template<class _InputIterator
>
846 append(_InputIterator __first
, _InputIterator __last
)
847 { return this->replace(_M_iend(), _M_iend(), __first
, __last
); }
850 * @brief Append a single character.
851 * @param c Character to append.
854 push_back(_CharT __c
)
856 const size_type __len
= 1 + this->size();
857 if (__len
> this->capacity() || _M_rep()->_M_is_shared())
858 this->reserve(__len
);
859 traits_type::assign(_M_data()[this->size()], __c
);
860 _M_rep()->_M_set_length_and_sharable(__len
);
864 * @brief Set value to contents of another string.
865 * @param str Source string to use.
866 * @return Reference to this string.
869 assign(const basic_string
& __str
);
872 * @brief Set value to a substring of a string.
873 * @param str The string to use.
874 * @param pos Index of the first character of str.
875 * @param n Number of characters to use.
876 * @return Reference to this string.
877 * @throw std::out_of_range if @a pos is not a valid index.
879 * This function sets this string to the substring of @a str consisting
880 * of @a n characters at @a pos. If @a n is is larger than the number
881 * of available characters in @a str, the remainder of @a str is used.
884 assign(const basic_string
& __str
, size_type __pos
, size_type __n
)
885 { return this->assign(__str
._M_data()
886 + __str
._M_check(__pos
, "basic_string::assign"),
887 __str
._M_limit(__pos
, __n
)); }
890 * @brief Set value to a C substring.
891 * @param s The C string to use.
892 * @param n Number of characters to use.
893 * @return Reference to this string.
895 * This function sets the value of this string to the first @a n
896 * characters of @a s. If @a n is is larger than the number of
897 * available characters in @a s, the remainder of @a s is used.
900 assign(const _CharT
* __s
, size_type __n
);
903 * @brief Set value to contents of a C string.
904 * @param s The C string to use.
905 * @return Reference to this string.
907 * This function sets the value of this string to the value of @a s.
908 * The data is copied, so there is no dependence on @a s once the
912 assign(const _CharT
* __s
)
914 __glibcxx_requires_string(__s
);
915 return this->assign(__s
, traits_type::length(__s
));
919 * @brief Set value to multiple characters.
920 * @param n Length of the resulting string.
921 * @param c The character to use.
922 * @return Reference to this string.
924 * This function sets the value of this string to @a n copies of
928 assign(size_type __n
, _CharT __c
)
929 { return _M_replace_aux(size_type(0), this->size(), __n
, __c
); }
932 * @brief Set value to a range of characters.
933 * @param first Iterator referencing the first character to append.
934 * @param last Iterator marking the end of the range.
935 * @return Reference to this string.
937 * Sets value of string to characters in the range [first,last).
939 template<class _InputIterator
>
941 assign(_InputIterator __first
, _InputIterator __last
)
942 { return this->replace(_M_ibegin(), _M_iend(), __first
, __last
); }
945 * @brief Insert multiple characters.
946 * @param p Iterator referencing location in string to insert at.
947 * @param n Number of characters to insert
948 * @param c The character to insert.
949 * @throw std::length_error If new length exceeds @c max_size().
951 * Inserts @a n copies of character @a c starting at the position
952 * referenced by iterator @a p. If adding characters causes the length
953 * to exceed max_size(), length_error is thrown. The value of the
954 * string doesn't change if an error is thrown.
957 insert(iterator __p
, size_type __n
, _CharT __c
)
958 { this->replace(__p
, __p
, __n
, __c
); }
961 * @brief Insert a range of characters.
962 * @param p Iterator referencing location in string to insert at.
963 * @param beg Start of range.
964 * @param end End of range.
965 * @throw std::length_error If new length exceeds @c max_size().
967 * Inserts characters in range [beg,end). If adding characters causes
968 * the length to exceed max_size(), length_error is thrown. The value
969 * of the string doesn't change if an error is thrown.
971 template<class _InputIterator
>
973 insert(iterator __p
, _InputIterator __beg
, _InputIterator __end
)
974 { this->replace(__p
, __p
, __beg
, __end
); }
977 * @brief Insert value of a string.
978 * @param pos1 Iterator referencing location in string to insert at.
979 * @param str The string to insert.
980 * @return Reference to this string.
981 * @throw std::length_error If new length exceeds @c max_size().
983 * Inserts value of @a str starting at @a pos1. If adding characters
984 * causes the length to exceed max_size(), length_error is thrown. The
985 * value of the string doesn't change if an error is thrown.
988 insert(size_type __pos1
, const basic_string
& __str
)
989 { return this->insert(__pos1
, __str
, size_type(0), __str
.size()); }
992 * @brief Insert a substring.
993 * @param pos1 Iterator referencing location in string to insert at.
994 * @param str The string to insert.
995 * @param pos2 Start of characters in str to insert.
996 * @param n Number of characters to insert.
997 * @return Reference to this string.
998 * @throw std::length_error If new length exceeds @c max_size().
999 * @throw std::out_of_range If @a pos1 > size() or
1000 * @a pos2 > @a str.size().
1002 * Starting at @a pos1, insert @a n character of @a str beginning with
1003 * @a pos2. If adding characters causes the length to exceed
1004 * max_size(), length_error is thrown. If @a pos1 is beyond the end of
1005 * this string or @a pos2 is beyond the end of @a str, out_of_range is
1006 * thrown. The value of the string doesn't change if an error is
1010 insert(size_type __pos1
, const basic_string
& __str
,
1011 size_type __pos2
, size_type __n
)
1012 { return this->insert(__pos1
, __str
._M_data()
1013 + __str
._M_check(__pos2
, "basic_string::insert"),
1014 __str
._M_limit(__pos2
, __n
)); }
1017 * @brief Insert a C substring.
1018 * @param pos Iterator referencing location in string to insert at.
1019 * @param s The C string to insert.
1020 * @param n The number of characters to insert.
1021 * @return Reference to this string.
1022 * @throw std::length_error If new length exceeds @c max_size().
1023 * @throw std::out_of_range If @a pos is beyond the end of this
1026 * Inserts the first @a n characters of @a s starting at @a pos. If
1027 * adding characters causes the length to exceed max_size(),
1028 * length_error is thrown. If @a pos is beyond end(), out_of_range is
1029 * thrown. The value of the string doesn't change if an error is
1033 insert(size_type __pos
, const _CharT
* __s
, size_type __n
);
1036 * @brief Insert a C string.
1037 * @param pos Iterator referencing location in string to insert at.
1038 * @param s The C string to insert.
1039 * @return Reference to this string.
1040 * @throw std::length_error If new length exceeds @c max_size().
1041 * @throw std::out_of_range If @a pos is beyond the end of this
1044 * Inserts the first @a n characters of @a s starting at @a pos. If
1045 * adding characters causes the length to exceed max_size(),
1046 * length_error is thrown. If @a pos is beyond end(), out_of_range is
1047 * thrown. The value of the string doesn't change if an error is
1051 insert(size_type __pos
, const _CharT
* __s
)
1053 __glibcxx_requires_string(__s
);
1054 return this->insert(__pos
, __s
, traits_type::length(__s
));
1058 * @brief Insert multiple characters.
1059 * @param pos Index in string to insert at.
1060 * @param n Number of characters to insert
1061 * @param c The character to insert.
1062 * @return Reference to this string.
1063 * @throw std::length_error If new length exceeds @c max_size().
1064 * @throw std::out_of_range If @a pos is beyond the end of this
1067 * Inserts @a n copies of character @a c starting at index @a pos. If
1068 * adding characters causes the length to exceed max_size(),
1069 * length_error is thrown. If @a pos > length(), out_of_range is
1070 * thrown. The value of the string doesn't change if an error is
1074 insert(size_type __pos
, size_type __n
, _CharT __c
)
1075 { return _M_replace_aux(_M_check(__pos
, "basic_string::insert"),
1076 size_type(0), __n
, __c
); }
1079 * @brief Insert one character.
1080 * @param p Iterator referencing position in string to insert at.
1081 * @param c The character to insert.
1082 * @return Iterator referencing newly inserted char.
1083 * @throw std::length_error If new length exceeds @c max_size().
1085 * Inserts character @a c at position referenced by @a p. If adding
1086 * character causes the length to exceed max_size(), length_error is
1087 * thrown. If @a p is beyond end of string, out_of_range is thrown.
1088 * The value of the string doesn't change if an error is thrown.
1091 insert(iterator __p
, _CharT __c
)
1093 _GLIBCXX_DEBUG_PEDASSERT(__p
>= _M_ibegin() && __p
<= _M_iend());
1094 const size_type __pos
= __p
- _M_ibegin();
1095 _M_replace_aux(__pos
, size_type(0), size_type(1), __c
);
1096 _M_rep()->_M_set_leaked();
1097 return this->_M_ibegin() + __pos
;
1101 * @brief Remove characters.
1102 * @param pos Index of first character to remove (default 0).
1103 * @param n Number of characters to remove (default remainder).
1104 * @return Reference to this string.
1105 * @throw std::out_of_range If @a pos is beyond the end of this
1108 * Removes @a n characters from this string starting at @a pos. The
1109 * length of the string is reduced by @a n. If there are < @a n
1110 * characters to remove, the remainder of the string is truncated. If
1111 * @a p is beyond end of string, out_of_range is thrown. The value of
1112 * the string doesn't change if an error is thrown.
1115 erase(size_type __pos
= 0, size_type __n
= npos
)
1117 _M_mutate(_M_check(__pos
, "basic_string::erase"),
1118 _M_limit(__pos
, __n
), size_type(0));
1123 * @brief Remove one character.
1124 * @param position Iterator referencing the character to remove.
1125 * @return iterator referencing same location after removal.
1127 * Removes the character at @a position from this string. The value
1128 * of the string doesn't change if an error is thrown.
1131 erase(iterator __position
)
1133 _GLIBCXX_DEBUG_PEDASSERT(__position
>= _M_ibegin()
1134 && __position
< _M_iend());
1135 const size_type __pos
= __position
- _M_ibegin();
1136 _M_mutate(__pos
, size_type(1), size_type(0));
1137 _M_rep()->_M_set_leaked();
1138 return _M_ibegin() + __pos
;
1142 * @brief Remove a range of characters.
1143 * @param first Iterator referencing the first character to remove.
1144 * @param last Iterator referencing the end of the range.
1145 * @return Iterator referencing location of first after removal.
1147 * Removes the characters in the range [first,last) from this string.
1148 * The value of the string doesn't change if an error is thrown.
1151 erase(iterator __first
, iterator __last
)
1153 _GLIBCXX_DEBUG_PEDASSERT(__first
>= _M_ibegin() && __first
<= __last
1154 && __last
<= _M_iend());
1155 const size_type __pos
= __first
- _M_ibegin();
1156 _M_mutate(__pos
, __last
- __first
, size_type(0));
1157 _M_rep()->_M_set_leaked();
1158 return _M_ibegin() + __pos
;
1162 * @brief Replace characters with value from another string.
1163 * @param pos Index of first character to replace.
1164 * @param n Number of characters to be replaced.
1165 * @param str String to insert.
1166 * @return Reference to this string.
1167 * @throw std::out_of_range If @a pos is beyond the end of this
1169 * @throw std::length_error If new length exceeds @c max_size().
1171 * Removes the characters in the range [pos,pos+n) from this string.
1172 * In place, the value of @a str is inserted. If @a pos is beyond end
1173 * of string, out_of_range is thrown. If the length of the result
1174 * exceeds max_size(), length_error is thrown. The value of the string
1175 * doesn't change if an error is thrown.
1178 replace(size_type __pos
, size_type __n
, const basic_string
& __str
)
1179 { return this->replace(__pos
, __n
, __str
._M_data(), __str
.size()); }
1182 * @brief Replace characters with value from another string.
1183 * @param pos1 Index of first character to replace.
1184 * @param n1 Number of characters to be replaced.
1185 * @param str String to insert.
1186 * @param pos2 Index of first character of str to use.
1187 * @param n2 Number of characters from str to use.
1188 * @return Reference to this string.
1189 * @throw std::out_of_range If @a pos1 > size() or @a pos2 >
1191 * @throw std::length_error If new length exceeds @c max_size().
1193 * Removes the characters in the range [pos1,pos1 + n) from this
1194 * string. In place, the value of @a str is inserted. If @a pos is
1195 * beyond end of string, out_of_range is thrown. If the length of the
1196 * result exceeds max_size(), length_error is thrown. The value of the
1197 * string doesn't change if an error is thrown.
1200 replace(size_type __pos1
, size_type __n1
, const basic_string
& __str
,
1201 size_type __pos2
, size_type __n2
)
1202 { return this->replace(__pos1
, __n1
, __str
._M_data()
1203 + __str
._M_check(__pos2
, "basic_string::replace"),
1204 __str
._M_limit(__pos2
, __n2
)); }
1207 * @brief Replace characters with value of a C substring.
1208 * @param pos Index of first character to replace.
1209 * @param n1 Number of characters to be replaced.
1210 * @param s C string to insert.
1211 * @param n2 Number of characters from @a s to use.
1212 * @return Reference to this string.
1213 * @throw std::out_of_range If @a pos1 > size().
1214 * @throw std::length_error If new length exceeds @c max_size().
1216 * Removes the characters in the range [pos,pos + n1) from this string.
1217 * In place, the first @a n2 characters of @a s are inserted, or all
1218 * of @a s if @a n2 is too large. If @a pos is beyond end of string,
1219 * out_of_range is thrown. If the length of result exceeds max_size(),
1220 * length_error is thrown. The value of the string doesn't change if
1221 * an error is thrown.
1224 replace(size_type __pos
, size_type __n1
, const _CharT
* __s
,
1228 * @brief Replace characters with value of a C string.
1229 * @param pos Index of first character to replace.
1230 * @param n1 Number of characters to be replaced.
1231 * @param s C string to insert.
1232 * @return Reference to this string.
1233 * @throw std::out_of_range If @a pos > size().
1234 * @throw std::length_error If new length exceeds @c max_size().
1236 * Removes the characters in the range [pos,pos + n1) from this string.
1237 * In place, the first @a n characters of @a s are inserted. If @a
1238 * pos is beyond end of string, out_of_range is thrown. If the length
1239 * of result exceeds max_size(), length_error is thrown. The value of
1240 * the string doesn't change if an error is thrown.
1243 replace(size_type __pos
, size_type __n1
, const _CharT
* __s
)
1245 __glibcxx_requires_string(__s
);
1246 return this->replace(__pos
, __n1
, __s
, traits_type::length(__s
));
1250 * @brief Replace characters with multiple characters.
1251 * @param pos Index of first character to replace.
1252 * @param n1 Number of characters to be replaced.
1253 * @param n2 Number of characters to insert.
1254 * @param c Character to insert.
1255 * @return Reference to this string.
1256 * @throw std::out_of_range If @a pos > size().
1257 * @throw std::length_error If new length exceeds @c max_size().
1259 * Removes the characters in the range [pos,pos + n1) from this string.
1260 * In place, @a n2 copies of @a c are inserted. If @a pos is beyond
1261 * end of string, out_of_range is thrown. If the length of result
1262 * exceeds max_size(), length_error is thrown. The value of the string
1263 * doesn't change if an error is thrown.
1266 replace(size_type __pos
, size_type __n1
, size_type __n2
, _CharT __c
)
1267 { return _M_replace_aux(_M_check(__pos
, "basic_string::replace"),
1268 _M_limit(__pos
, __n1
), __n2
, __c
); }
1271 * @brief Replace range of characters with string.
1272 * @param i1 Iterator referencing start of range to replace.
1273 * @param i2 Iterator referencing end of range to replace.
1274 * @param str String value to insert.
1275 * @return Reference to this string.
1276 * @throw std::length_error If new length exceeds @c max_size().
1278 * Removes the characters in the range [i1,i2). In place, the value of
1279 * @a str is inserted. If the length of result exceeds max_size(),
1280 * length_error is thrown. The value of the string doesn't change if
1281 * an error is thrown.
1284 replace(iterator __i1
, iterator __i2
, const basic_string
& __str
)
1285 { return this->replace(__i1
, __i2
, __str
._M_data(), __str
.size()); }
1288 * @brief Replace range of characters with C substring.
1289 * @param i1 Iterator referencing start of range to replace.
1290 * @param i2 Iterator referencing end of range to replace.
1291 * @param s C string value to insert.
1292 * @param n Number of characters from s to insert.
1293 * @return Reference to this string.
1294 * @throw std::length_error If new length exceeds @c max_size().
1296 * Removes the characters in the range [i1,i2). In place, the first @a
1297 * n characters of @a s are inserted. If the length of result exceeds
1298 * max_size(), length_error is thrown. The value of the string doesn't
1299 * change if an error is thrown.
1302 replace(iterator __i1
, iterator __i2
, const _CharT
* __s
, size_type __n
)
1304 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1305 && __i2
<= _M_iend());
1306 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
, __s
, __n
);
1310 * @brief Replace range of characters with C string.
1311 * @param i1 Iterator referencing start of range to replace.
1312 * @param i2 Iterator referencing end of range to replace.
1313 * @param s C string value to insert.
1314 * @return Reference to this string.
1315 * @throw std::length_error If new length exceeds @c max_size().
1317 * Removes the characters in the range [i1,i2). In place, the
1318 * characters of @a s are inserted. If the length of result exceeds
1319 * max_size(), length_error is thrown. The value of the string doesn't
1320 * change if an error is thrown.
1323 replace(iterator __i1
, iterator __i2
, const _CharT
* __s
)
1325 __glibcxx_requires_string(__s
);
1326 return this->replace(__i1
, __i2
, __s
, traits_type::length(__s
));
1330 * @brief Replace range of characters with multiple characters
1331 * @param i1 Iterator referencing start of range to replace.
1332 * @param i2 Iterator referencing end of range to replace.
1333 * @param n Number of characters to insert.
1334 * @param c Character to insert.
1335 * @return Reference to this string.
1336 * @throw std::length_error If new length exceeds @c max_size().
1338 * Removes the characters in the range [i1,i2). In place, @a n copies
1339 * of @a c are inserted. If the length of result exceeds max_size(),
1340 * length_error is thrown. The value of the string doesn't change if
1341 * an error is thrown.
1344 replace(iterator __i1
, iterator __i2
, size_type __n
, _CharT __c
)
1346 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1347 && __i2
<= _M_iend());
1348 return _M_replace_aux(__i1
- _M_ibegin(), __i2
- __i1
, __n
, __c
);
1352 * @brief Replace range of characters with range.
1353 * @param i1 Iterator referencing start of range to replace.
1354 * @param i2 Iterator referencing end of range to replace.
1355 * @param k1 Iterator referencing start of range to insert.
1356 * @param k2 Iterator referencing end of range to insert.
1357 * @return Reference to this string.
1358 * @throw std::length_error If new length exceeds @c max_size().
1360 * Removes the characters in the range [i1,i2). In place, characters
1361 * in the range [k1,k2) are inserted. If the length of result exceeds
1362 * max_size(), length_error is thrown. The value of the string doesn't
1363 * change if an error is thrown.
1365 template<class _InputIterator
>
1367 replace(iterator __i1
, iterator __i2
,
1368 _InputIterator __k1
, _InputIterator __k2
)
1370 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1371 && __i2
<= _M_iend());
1372 __glibcxx_requires_valid_range(__k1
, __k2
);
1373 typedef typename
std::__is_integer
<_InputIterator
>::__type _Integral
;
1374 return _M_replace_dispatch(__i1
, __i2
, __k1
, __k2
, _Integral());
1377 // Specializations for the common case of pointer and iterator:
1378 // useful to avoid the overhead of temporary buffering in _M_replace.
1380 replace(iterator __i1
, iterator __i2
, _CharT
* __k1
, _CharT
* __k2
)
1382 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1383 && __i2
<= _M_iend());
1384 __glibcxx_requires_valid_range(__k1
, __k2
);
1385 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1390 replace(iterator __i1
, iterator __i2
,
1391 const _CharT
* __k1
, const _CharT
* __k2
)
1393 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1394 && __i2
<= _M_iend());
1395 __glibcxx_requires_valid_range(__k1
, __k2
);
1396 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1401 replace(iterator __i1
, iterator __i2
, iterator __k1
, iterator __k2
)
1403 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1404 && __i2
<= _M_iend());
1405 __glibcxx_requires_valid_range(__k1
, __k2
);
1406 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1407 __k1
.base(), __k2
- __k1
);
1411 replace(iterator __i1
, iterator __i2
,
1412 const_iterator __k1
, const_iterator __k2
)
1414 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1415 && __i2
<= _M_iend());
1416 __glibcxx_requires_valid_range(__k1
, __k2
);
1417 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1418 __k1
.base(), __k2
- __k1
);
1422 template<class _Integer
>
1424 _M_replace_dispatch(iterator __i1
, iterator __i2
, _Integer __n
,
1425 _Integer __val
, __true_type
)
1426 { return _M_replace_aux(__i1
- _M_ibegin(), __i2
- __i1
, __n
, __val
); }
1428 template<class _InputIterator
>
1430 _M_replace_dispatch(iterator __i1
, iterator __i2
, _InputIterator __k1
,
1431 _InputIterator __k2
, __false_type
);
1434 _M_replace_aux(size_type __pos1
, size_type __n1
, size_type __n2
,
1438 _M_replace_safe(size_type __pos1
, size_type __n1
, const _CharT
* __s
,
1441 // _S_construct_aux is used to implement the 21.3.1 para 15 which
1442 // requires special behaviour if _InIter is an integral type
1443 template<class _InIterator
>
1445 _S_construct_aux(_InIterator __beg
, _InIterator __end
,
1446 const _Alloc
& __a
, __false_type
)
1448 typedef typename iterator_traits
<_InIterator
>::iterator_category _Tag
;
1449 return _S_construct(__beg
, __end
, __a
, _Tag());
1452 template<class _InIterator
>
1454 _S_construct_aux(_InIterator __beg
, _InIterator __end
,
1455 const _Alloc
& __a
, __true_type
)
1456 { return _S_construct(static_cast<size_type
>(__beg
),
1457 static_cast<value_type
>(__end
), __a
); }
1459 template<class _InIterator
>
1461 _S_construct(_InIterator __beg
, _InIterator __end
, const _Alloc
& __a
)
1463 typedef typename
std::__is_integer
<_InIterator
>::__type _Integral
;
1464 return _S_construct_aux(__beg
, __end
, __a
, _Integral());
1467 // For Input Iterators, used in istreambuf_iterators, etc.
1468 template<class _InIterator
>
1470 _S_construct(_InIterator __beg
, _InIterator __end
, const _Alloc
& __a
,
1471 input_iterator_tag
);
1473 // For forward_iterators up to random_access_iterators, used for
1474 // string::iterator, _CharT*, etc.
1475 template<class _FwdIterator
>
1477 _S_construct(_FwdIterator __beg
, _FwdIterator __end
, const _Alloc
& __a
,
1478 forward_iterator_tag
);
1481 _S_construct(size_type __req
, _CharT __c
, const _Alloc
& __a
);
1486 * @brief Copy substring into C string.
1487 * @param s C string to copy value into.
1488 * @param n Number of characters to copy.
1489 * @param pos Index of first character to copy.
1490 * @return Number of characters actually copied
1491 * @throw std::out_of_range If pos > size().
1493 * Copies up to @a n characters starting at @a pos into the C string @a
1494 * s. If @a pos is greater than size(), out_of_range is thrown.
1497 copy(_CharT
* __s
, size_type __n
, size_type __pos
= 0) const;
1500 * @brief Swap contents with another string.
1501 * @param s String to swap with.
1503 * Exchanges the contents of this string with that of @a s in constant
1507 swap(basic_string
& __s
);
1509 // String operations:
1511 * @brief Return const pointer to null-terminated contents.
1513 * This is a handle to internal data. Do not modify or dire things may
1518 { return _M_data(); }
1521 * @brief Return const pointer to contents.
1523 * This is a handle to internal data. Do not modify or dire things may
1528 { return _M_data(); }
1531 * @brief Return copy of allocator used to construct this string.
1534 get_allocator() const
1535 { return _M_dataplus
; }
1538 * @brief Find position of a C substring.
1539 * @param s C string to locate.
1540 * @param pos Index of character to search from.
1541 * @param n Number of characters from @a s to search for.
1542 * @return Index of start of first occurrence.
1544 * Starting from @a pos, searches forward for the first @a n characters
1545 * in @a s within this string. If found, returns the index where it
1546 * begins. If not found, returns npos.
1549 find(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
1552 * @brief Find position of a string.
1553 * @param str String to locate.
1554 * @param pos Index of character to search from (default 0).
1555 * @return Index of start of first occurrence.
1557 * Starting from @a pos, searches forward for value of @a str within
1558 * this string. If found, returns the index where it begins. If not
1559 * found, returns npos.
1562 find(const basic_string
& __str
, size_type __pos
= 0) const
1563 { return this->find(__str
.data(), __pos
, __str
.size()); }
1566 * @brief Find position of a C string.
1567 * @param s C string to locate.
1568 * @param pos Index of character to search from (default 0).
1569 * @return Index of start of first occurrence.
1571 * Starting from @a pos, searches forward for the value of @a s within
1572 * this string. If found, returns the index where it begins. If not
1573 * found, returns npos.
1576 find(const _CharT
* __s
, size_type __pos
= 0) const
1578 __glibcxx_requires_string(__s
);
1579 return this->find(__s
, __pos
, traits_type::length(__s
));
1583 * @brief Find position of a character.
1584 * @param c Character to locate.
1585 * @param pos Index of character to search from (default 0).
1586 * @return Index of first occurrence.
1588 * Starting from @a pos, searches forward for @a c within this string.
1589 * If found, returns the index where it was found. If not found,
1593 find(_CharT __c
, size_type __pos
= 0) const;
1596 * @brief Find last position of a string.
1597 * @param str String to locate.
1598 * @param pos Index of character to search back from (default end).
1599 * @return Index of start of last occurrence.
1601 * Starting from @a pos, searches backward for value of @a str within
1602 * this string. If found, returns the index where it begins. If not
1603 * found, returns npos.
1606 rfind(const basic_string
& __str
, size_type __pos
= npos
) const
1607 { return this->rfind(__str
.data(), __pos
, __str
.size()); }
1610 * @brief Find last position of a C substring.
1611 * @param s C string to locate.
1612 * @param pos Index of character to search back from.
1613 * @param n Number of characters from s to search for.
1614 * @return Index of start of last occurrence.
1616 * Starting from @a pos, searches backward for the first @a n
1617 * characters in @a s within this string. If found, returns the index
1618 * where it begins. If not found, returns npos.
1621 rfind(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
1624 * @brief Find last position of a C string.
1625 * @param s C string to locate.
1626 * @param pos Index of character to start search at (default end).
1627 * @return Index of start of last occurrence.
1629 * Starting from @a pos, searches backward for the value of @a s within
1630 * this string. If found, returns the index where it begins. If not
1631 * found, returns npos.
1634 rfind(const _CharT
* __s
, size_type __pos
= npos
) const
1636 __glibcxx_requires_string(__s
);
1637 return this->rfind(__s
, __pos
, traits_type::length(__s
));
1641 * @brief Find last position of a character.
1642 * @param c Character to locate.
1643 * @param pos Index of character to search back from (default end).
1644 * @return Index of last occurrence.
1646 * Starting from @a pos, searches backward for @a c within this string.
1647 * If found, returns the index where it was found. If not found,
1651 rfind(_CharT __c
, size_type __pos
= npos
) const;
1654 * @brief Find position of a character of string.
1655 * @param str String containing characters to locate.
1656 * @param pos Index of character to search from (default 0).
1657 * @return Index of first occurrence.
1659 * Starting from @a pos, searches forward for one of the characters of
1660 * @a str within this string. If found, returns the index where it was
1661 * found. If not found, returns npos.
1664 find_first_of(const basic_string
& __str
, size_type __pos
= 0) const
1665 { return this->find_first_of(__str
.data(), __pos
, __str
.size()); }
1668 * @brief Find position of a character of C substring.
1669 * @param s String containing characters to locate.
1670 * @param pos Index of character to search from (default 0).
1671 * @param n Number of characters from s to search for.
1672 * @return Index of first occurrence.
1674 * Starting from @a pos, searches forward for one of the first @a n
1675 * characters of @a s within this string. If found, returns the index
1676 * where it was found. If not found, returns npos.
1679 find_first_of(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
1682 * @brief Find position of a character of C string.
1683 * @param s String containing characters to locate.
1684 * @param pos Index of character to search from (default 0).
1685 * @return Index of first occurrence.
1687 * Starting from @a pos, searches forward for one of the characters of
1688 * @a s within this string. If found, returns the index where it was
1689 * found. If not found, returns npos.
1692 find_first_of(const _CharT
* __s
, size_type __pos
= 0) const
1694 __glibcxx_requires_string(__s
);
1695 return this->find_first_of(__s
, __pos
, traits_type::length(__s
));
1699 * @brief Find position of a character.
1700 * @param c Character to locate.
1701 * @param pos Index of character to search from (default 0).
1702 * @return Index of first occurrence.
1704 * Starting from @a pos, searches forward for the character @a c within
1705 * this string. If found, returns the index where it was found. If
1706 * not found, returns npos.
1708 * Note: equivalent to find(c, pos).
1711 find_first_of(_CharT __c
, size_type __pos
= 0) const
1712 { return this->find(__c
, __pos
); }
1715 * @brief Find last position of a character of string.
1716 * @param str String containing characters to locate.
1717 * @param pos Index of character to search back from (default end).
1718 * @return Index of last occurrence.
1720 * Starting from @a pos, searches backward for one of the characters of
1721 * @a str within this string. If found, returns the index where it was
1722 * found. If not found, returns npos.
1725 find_last_of(const basic_string
& __str
, size_type __pos
= npos
) const
1726 { return this->find_last_of(__str
.data(), __pos
, __str
.size()); }
1729 * @brief Find last position of a character of C substring.
1730 * @param s C string containing characters to locate.
1731 * @param pos Index of character to search back from (default end).
1732 * @param n Number of characters from s to search for.
1733 * @return Index of last occurrence.
1735 * Starting from @a pos, searches backward for one of the first @a n
1736 * characters of @a s within this string. If found, returns the index
1737 * where it was found. If not found, returns npos.
1740 find_last_of(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
1743 * @brief Find last position of a character of C string.
1744 * @param s C string containing characters to locate.
1745 * @param pos Index of character to search back from (default end).
1746 * @return Index of last occurrence.
1748 * Starting from @a pos, searches backward for one of the characters of
1749 * @a s within this string. If found, returns the index where it was
1750 * found. If not found, returns npos.
1753 find_last_of(const _CharT
* __s
, size_type __pos
= npos
) const
1755 __glibcxx_requires_string(__s
);
1756 return this->find_last_of(__s
, __pos
, traits_type::length(__s
));
1760 * @brief Find last position of a character.
1761 * @param c Character to locate.
1762 * @param pos Index of character to search back from (default 0).
1763 * @return Index of last occurrence.
1765 * Starting from @a pos, searches backward for @a c within this string.
1766 * If found, returns the index where it was found. If not found,
1769 * Note: equivalent to rfind(c, pos).
1772 find_last_of(_CharT __c
, size_type __pos
= npos
) const
1773 { return this->rfind(__c
, __pos
); }
1776 * @brief Find position of a character not in string.
1777 * @param str String containing characters to avoid.
1778 * @param pos Index of character to search from (default 0).
1779 * @return Index of first occurrence.
1781 * Starting from @a pos, searches forward for a character not contained
1782 * in @a str within this string. If found, returns the index where it
1783 * was found. If not found, returns npos.
1786 find_first_not_of(const basic_string
& __str
, size_type __pos
= 0) const
1787 { return this->find_first_not_of(__str
.data(), __pos
, __str
.size()); }
1790 * @brief Find position of a character not in C substring.
1791 * @param s C string containing characters to avoid.
1792 * @param pos Index of character to search from (default 0).
1793 * @param n Number of characters from s to consider.
1794 * @return Index of first occurrence.
1796 * Starting from @a pos, searches forward for a character not contained
1797 * in the first @a n characters of @a s within this string. If found,
1798 * returns the index where it was found. If not found, returns npos.
1801 find_first_not_of(const _CharT
* __s
, size_type __pos
,
1802 size_type __n
) const;
1805 * @brief Find position of a character not in C string.
1806 * @param s C string containing characters to avoid.
1807 * @param pos Index of character to search from (default 0).
1808 * @return Index of first occurrence.
1810 * Starting from @a pos, searches forward for a character not contained
1811 * in @a s within this string. If found, returns the index where it
1812 * was found. If not found, returns npos.
1815 find_first_not_of(const _CharT
* __s
, size_type __pos
= 0) const
1817 __glibcxx_requires_string(__s
);
1818 return this->find_first_not_of(__s
, __pos
, traits_type::length(__s
));
1822 * @brief Find position of a different character.
1823 * @param c Character to avoid.
1824 * @param pos Index of character to search from (default 0).
1825 * @return Index of first occurrence.
1827 * Starting from @a pos, searches forward for a character other than @a c
1828 * within this string. If found, returns the index where it was found.
1829 * If not found, returns npos.
1832 find_first_not_of(_CharT __c
, size_type __pos
= 0) const;
1835 * @brief Find last position of a character not in string.
1836 * @param str String containing characters to avoid.
1837 * @param pos Index of character to search from (default 0).
1838 * @return Index of first occurrence.
1840 * Starting from @a pos, searches backward for a character not
1841 * contained in @a str within this string. If found, returns the index
1842 * where it was found. If not found, returns npos.
1845 find_last_not_of(const basic_string
& __str
, size_type __pos
= npos
) const
1846 { return this->find_last_not_of(__str
.data(), __pos
, __str
.size()); }
1849 * @brief Find last position of a character not in C substring.
1850 * @param s C string containing characters to avoid.
1851 * @param pos Index of character to search from (default 0).
1852 * @param n Number of characters from s to consider.
1853 * @return Index of first occurrence.
1855 * Starting from @a pos, searches backward for a character not
1856 * contained in the first @a n characters of @a s within this string.
1857 * If found, returns the index where it was found. If not found,
1861 find_last_not_of(const _CharT
* __s
, size_type __pos
,
1862 size_type __n
) const;
1864 * @brief Find position of a character not in C string.
1865 * @param s C string containing characters to avoid.
1866 * @param pos Index of character to search from (default 0).
1867 * @return Index of first occurrence.
1869 * Starting from @a pos, searches backward for a character not
1870 * contained in @a s within this string. If found, returns the index
1871 * where it was found. If not found, returns npos.
1874 find_last_not_of(const _CharT
* __s
, size_type __pos
= npos
) const
1876 __glibcxx_requires_string(__s
);
1877 return this->find_last_not_of(__s
, __pos
, traits_type::length(__s
));
1881 * @brief Find last position of a different character.
1882 * @param c Character to avoid.
1883 * @param pos Index of character to search from (default 0).
1884 * @return Index of first occurrence.
1886 * Starting from @a pos, searches backward for a character other than
1887 * @a c within this string. If found, returns the index where it was
1888 * found. If not found, returns npos.
1891 find_last_not_of(_CharT __c
, size_type __pos
= npos
) const;
1894 * @brief Get a substring.
1895 * @param pos Index of first character (default 0).
1896 * @param n Number of characters in substring (default remainder).
1897 * @return The new string.
1898 * @throw std::out_of_range If pos > size().
1900 * Construct and return a new string using the @a n characters starting
1901 * at @a pos. If the string is too short, use the remainder of the
1902 * characters. If @a pos is beyond the end of the string, out_of_range
1906 substr(size_type __pos
= 0, size_type __n
= npos
) const
1907 { return basic_string(*this,
1908 _M_check(__pos
, "basic_string::substr"), __n
); }
1911 * @brief Compare to a string.
1912 * @param str String to compare against.
1913 * @return Integer < 0, 0, or > 0.
1915 * Returns an integer < 0 if this string is ordered before @a str, 0 if
1916 * their values are equivalent, or > 0 if this string is ordered after
1917 * @a str. Determines the effective length rlen of the strings to
1918 * compare as the smallest of size() and str.size(). The function
1919 * then compares the two strings by calling traits::compare(data(),
1920 * str.data(),rlen). If the result of the comparison is nonzero returns
1921 * it, otherwise the shorter one is ordered first.
1924 compare(const basic_string
& __str
) const
1926 const size_type __size
= this->size();
1927 const size_type __osize
= __str
.size();
1928 const size_type __len
= std::min(__size
, __osize
);
1930 int __r
= traits_type::compare(_M_data(), __str
.data(), __len
);
1932 __r
= __size
- __osize
;
1937 * @brief Compare substring to a string.
1938 * @param pos Index of first character of substring.
1939 * @param n Number of characters in substring.
1940 * @param str String to compare against.
1941 * @return Integer < 0, 0, or > 0.
1943 * Form the substring of this string from the @a n characters starting
1944 * at @a pos. Returns an integer < 0 if the substring is ordered
1945 * before @a str, 0 if their values are equivalent, or > 0 if the
1946 * substring is ordered after @a str. Determines the effective length
1947 * rlen of the strings to compare as the smallest of the length of the
1948 * substring and @a str.size(). The function then compares the two
1949 * strings by calling traits::compare(substring.data(),str.data(),rlen).
1950 * If the result of the comparison is nonzero returns it, otherwise the
1951 * shorter one is ordered first.
1954 compare(size_type __pos
, size_type __n
, const basic_string
& __str
) const;
1957 * @brief Compare substring to a substring.
1958 * @param pos1 Index of first character of substring.
1959 * @param n1 Number of characters in substring.
1960 * @param str String to compare against.
1961 * @param pos2 Index of first character of substring of str.
1962 * @param n2 Number of characters in substring of str.
1963 * @return Integer < 0, 0, or > 0.
1965 * Form the substring of this string from the @a n1 characters starting
1966 * at @a pos1. Form the substring of @a str from the @a n2 characters
1967 * starting at @a pos2. Returns an integer < 0 if this substring is
1968 * ordered before the substring of @a str, 0 if their values are
1969 * equivalent, or > 0 if this substring is ordered after the substring
1970 * of @a str. Determines the effective length rlen of the strings
1971 * to compare as the smallest of the lengths of the substrings. The
1972 * function then compares the two strings by calling
1973 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
1974 * If the result of the comparison is nonzero returns it, otherwise the
1975 * shorter one is ordered first.
1978 compare(size_type __pos1
, size_type __n1
, const basic_string
& __str
,
1979 size_type __pos2
, size_type __n2
) const;
1982 * @brief Compare to a C string.
1983 * @param s C string to compare against.
1984 * @return Integer < 0, 0, or > 0.
1986 * Returns an integer < 0 if this string is ordered before @a s, 0 if
1987 * their values are equivalent, or > 0 if this string is ordered after
1988 * @a s. Determines the effective length rlen of the strings to
1989 * compare as the smallest of size() and the length of a string
1990 * constructed from @a s. The function then compares the two strings
1991 * by calling traits::compare(data(),s,rlen). If the result of the
1992 * comparison is nonzero returns it, otherwise the shorter one is
1996 compare(const _CharT
* __s
) const;
1998 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1999 // 5 String::compare specification questionable
2001 * @brief Compare substring to a C string.
2002 * @param pos Index of first character of substring.
2003 * @param n1 Number of characters in substring.
2004 * @param s C string to compare against.
2005 * @return Integer < 0, 0, or > 0.
2007 * Form the substring of this string from the @a n1 characters starting
2008 * at @a pos. Returns an integer < 0 if the substring is ordered
2009 * before @a s, 0 if their values are equivalent, or > 0 if the
2010 * substring is ordered after @a s. Determines the effective length
2011 * rlen of the strings to compare as the smallest of the length of the
2012 * substring and the length of a string constructed from @a s. The
2013 * function then compares the two string by calling
2014 * traits::compare(substring.data(),s,rlen). If the result of the
2015 * comparison is nonzero returns it, otherwise the shorter one is
2019 compare(size_type __pos
, size_type __n1
, const _CharT
* __s
) const;
2022 * @brief Compare substring against a character array.
2023 * @param pos1 Index of first character of substring.
2024 * @param n1 Number of characters in substring.
2025 * @param s character array to compare against.
2026 * @param n2 Number of characters of s.
2027 * @return Integer < 0, 0, or > 0.
2029 * Form the substring of this string from the @a n1 characters starting
2030 * at @a pos1. Form a string from the first @a n2 characters of @a s.
2031 * Returns an integer < 0 if this substring is ordered before the string
2032 * from @a s, 0 if their values are equivalent, or > 0 if this substring
2033 * is ordered after the string from @a s. Determines the effective
2034 * length rlen of the strings to compare as the smallest of the length
2035 * of the substring and @a n2. The function then compares the two
2036 * strings by calling traits::compare(substring.data(),s,rlen). If the
2037 * result of the comparison is nonzero returns it, otherwise the shorter
2038 * one is ordered first.
2040 * NB: s must have at least n2 characters, '\0' has no special
2044 compare(size_type __pos
, size_type __n1
, const _CharT
* __s
,
2045 size_type __n2
) const;
2048 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2049 inline basic_string
<_CharT
, _Traits
, _Alloc
>::
2051 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
2052 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
2054 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()) { }
2059 * @brief Concatenate two strings.
2060 * @param lhs First string.
2061 * @param rhs Last string.
2062 * @return New string with value of @a lhs followed by @a rhs.
2064 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2065 basic_string
<_CharT
, _Traits
, _Alloc
>
2066 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2067 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2069 basic_string
<_CharT
, _Traits
, _Alloc
> __str(__lhs
);
2070 __str
.append(__rhs
);
2075 * @brief Concatenate C string and string.
2076 * @param lhs First string.
2077 * @param rhs Last string.
2078 * @return New string with value of @a lhs followed by @a rhs.
2080 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2081 basic_string
<_CharT
,_Traits
,_Alloc
>
2082 operator+(const _CharT
* __lhs
,
2083 const basic_string
<_CharT
,_Traits
,_Alloc
>& __rhs
);
2086 * @brief Concatenate character and string.
2087 * @param lhs First string.
2088 * @param rhs Last string.
2089 * @return New string with @a lhs followed by @a rhs.
2091 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2092 basic_string
<_CharT
,_Traits
,_Alloc
>
2093 operator+(_CharT __lhs
, const basic_string
<_CharT
,_Traits
,_Alloc
>& __rhs
);
2096 * @brief Concatenate string and C string.
2097 * @param lhs First string.
2098 * @param rhs Last string.
2099 * @return New string with @a lhs followed by @a rhs.
2101 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2102 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2103 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2104 const _CharT
* __rhs
)
2106 basic_string
<_CharT
, _Traits
, _Alloc
> __str(__lhs
);
2107 __str
.append(__rhs
);
2112 * @brief Concatenate string and character.
2113 * @param lhs First string.
2114 * @param rhs Last string.
2115 * @return New string with @a lhs followed by @a rhs.
2117 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2118 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2119 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
, _CharT __rhs
)
2121 typedef basic_string
<_CharT
, _Traits
, _Alloc
> __string_type
;
2122 typedef typename
__string_type::size_type __size_type
;
2123 __string_type
__str(__lhs
);
2124 __str
.append(__size_type(1), __rhs
);
2130 * @brief Test equivalence of two strings.
2131 * @param lhs First string.
2132 * @param rhs Second string.
2133 * @return True if @a lhs.compare(@a rhs) == 0. False otherwise.
2135 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2137 operator==(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2138 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2139 { return __lhs
.compare(__rhs
) == 0; }
2142 * @brief Test equivalence of C string and string.
2143 * @param lhs C string.
2144 * @param rhs String.
2145 * @return True if @a rhs.compare(@a lhs) == 0. False otherwise.
2147 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2149 operator==(const _CharT
* __lhs
,
2150 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2151 { return __rhs
.compare(__lhs
) == 0; }
2154 * @brief Test equivalence of string and C string.
2155 * @param lhs String.
2156 * @param rhs C string.
2157 * @return True if @a lhs.compare(@a rhs) == 0. False otherwise.
2159 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2161 operator==(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2162 const _CharT
* __rhs
)
2163 { return __lhs
.compare(__rhs
) == 0; }
2167 * @brief Test difference of two strings.
2168 * @param lhs First string.
2169 * @param rhs Second string.
2170 * @return True if @a lhs.compare(@a rhs) != 0. False otherwise.
2172 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2174 operator!=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2175 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2176 { return __rhs
.compare(__lhs
) != 0; }
2179 * @brief Test difference of C string and string.
2180 * @param lhs C string.
2181 * @param rhs String.
2182 * @return True if @a rhs.compare(@a lhs) != 0. False otherwise.
2184 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2186 operator!=(const _CharT
* __lhs
,
2187 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2188 { return __rhs
.compare(__lhs
) != 0; }
2191 * @brief Test difference of string and C string.
2192 * @param lhs String.
2193 * @param rhs C string.
2194 * @return True if @a lhs.compare(@a rhs) != 0. False otherwise.
2196 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2198 operator!=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2199 const _CharT
* __rhs
)
2200 { return __lhs
.compare(__rhs
) != 0; }
2204 * @brief Test if string precedes string.
2205 * @param lhs First string.
2206 * @param rhs Second string.
2207 * @return True if @a lhs precedes @a rhs. False otherwise.
2209 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2211 operator<(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2212 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2213 { return __lhs
.compare(__rhs
) < 0; }
2216 * @brief Test if string precedes C string.
2217 * @param lhs String.
2218 * @param rhs C string.
2219 * @return True if @a lhs precedes @a rhs. False otherwise.
2221 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2223 operator<(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2224 const _CharT
* __rhs
)
2225 { return __lhs
.compare(__rhs
) < 0; }
2228 * @brief Test if C string precedes string.
2229 * @param lhs C string.
2230 * @param rhs String.
2231 * @return True if @a lhs precedes @a rhs. False otherwise.
2233 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2235 operator<(const _CharT
* __lhs
,
2236 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2237 { return __rhs
.compare(__lhs
) > 0; }
2241 * @brief Test if string follows string.
2242 * @param lhs First string.
2243 * @param rhs Second string.
2244 * @return True if @a lhs follows @a rhs. False otherwise.
2246 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2248 operator>(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2249 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2250 { return __lhs
.compare(__rhs
) > 0; }
2253 * @brief Test if string follows C string.
2254 * @param lhs String.
2255 * @param rhs C string.
2256 * @return True if @a lhs follows @a rhs. False otherwise.
2258 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2260 operator>(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2261 const _CharT
* __rhs
)
2262 { return __lhs
.compare(__rhs
) > 0; }
2265 * @brief Test if C string follows string.
2266 * @param lhs C string.
2267 * @param rhs String.
2268 * @return True if @a lhs follows @a rhs. False otherwise.
2270 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2272 operator>(const _CharT
* __lhs
,
2273 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2274 { return __rhs
.compare(__lhs
) < 0; }
2278 * @brief Test if string doesn't follow string.
2279 * @param lhs First string.
2280 * @param rhs Second string.
2281 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2283 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2285 operator<=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2286 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2287 { return __lhs
.compare(__rhs
) <= 0; }
2290 * @brief Test if string doesn't follow C string.
2291 * @param lhs String.
2292 * @param rhs C string.
2293 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2295 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2297 operator<=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2298 const _CharT
* __rhs
)
2299 { return __lhs
.compare(__rhs
) <= 0; }
2302 * @brief Test if C string doesn't follow string.
2303 * @param lhs C string.
2304 * @param rhs String.
2305 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2307 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2309 operator<=(const _CharT
* __lhs
,
2310 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2311 { return __rhs
.compare(__lhs
) >= 0; }
2315 * @brief Test if string doesn't precede string.
2316 * @param lhs First string.
2317 * @param rhs Second string.
2318 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2320 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2322 operator>=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2323 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2324 { return __lhs
.compare(__rhs
) >= 0; }
2327 * @brief Test if string doesn't precede C string.
2328 * @param lhs String.
2329 * @param rhs C string.
2330 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2332 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2334 operator>=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2335 const _CharT
* __rhs
)
2336 { return __lhs
.compare(__rhs
) >= 0; }
2339 * @brief Test if C string doesn't precede string.
2340 * @param lhs C string.
2341 * @param rhs String.
2342 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2344 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2346 operator>=(const _CharT
* __lhs
,
2347 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2348 { return __rhs
.compare(__lhs
) <= 0; }
2351 * @brief Swap contents of two strings.
2352 * @param lhs First string.
2353 * @param rhs Second string.
2355 * Exchanges the contents of @a lhs and @a rhs in constant time.
2357 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2359 swap(basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2360 basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2361 { __lhs
.swap(__rhs
); }
2364 * @brief Read stream into a string.
2365 * @param is Input stream.
2366 * @param str Buffer to store into.
2367 * @return Reference to the input stream.
2369 * Stores characters from @a is into @a str until whitespace is found, the
2370 * end of the stream is encountered, or str.max_size() is reached. If
2371 * is.width() is non-zero, that is the limit on the number of characters
2372 * stored into @a str. Any previous contents of @a str are erased.
2374 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2375 basic_istream
<_CharT
, _Traits
>&
2376 operator>>(basic_istream
<_CharT
, _Traits
>& __is
,
2377 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
);
2380 basic_istream
<char>&
2381 operator>>(basic_istream
<char>& __is
, basic_string
<char>& __str
);
2384 * @brief Write string to a stream.
2385 * @param os Output stream.
2386 * @param str String to write out.
2387 * @return Reference to the output stream.
2389 * Output characters of @a str into os following the same rules as for
2390 * writing a C string.
2392 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2393 basic_ostream
<_CharT
, _Traits
>&
2394 operator<<(basic_ostream
<_CharT
, _Traits
>& __os
,
2395 const basic_string
<_CharT
, _Traits
, _Alloc
>& __str
);
2398 * @brief Read a line from stream into a string.
2399 * @param is Input stream.
2400 * @param str Buffer to store into.
2401 * @param delim Character marking end of line.
2402 * @return Reference to the input stream.
2404 * Stores characters from @a is into @a str until @a delim is found, the
2405 * end of the stream is encountered, or str.max_size() is reached. If
2406 * is.width() is non-zero, that is the limit on the number of characters
2407 * stored into @a str. Any previous contents of @a str are erased. If @a
2408 * delim was encountered, it is extracted but not stored into @a str.
2410 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2411 basic_istream
<_CharT
, _Traits
>&
2412 getline(basic_istream
<_CharT
, _Traits
>& __is
,
2413 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
, _CharT __delim
);
2416 * @brief Read a line from stream into a string.
2417 * @param is Input stream.
2418 * @param str Buffer to store into.
2419 * @return Reference to the input stream.
2421 * Stores characters from is into @a str until '\n' is found, the end of
2422 * the stream is encountered, or str.max_size() is reached. If is.width()
2423 * is non-zero, that is the limit on the number of characters stored into
2424 * @a str. Any previous contents of @a str are erased. If end of line was
2425 * encountered, it is extracted but not stored into @a str.
2427 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2428 inline basic_istream
<_CharT
, _Traits
>&
2429 getline(basic_istream
<_CharT
, _Traits
>& __is
,
2430 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
);
2433 basic_istream
<char>&
2434 getline(basic_istream
<char>& __in
, basic_string
<char>& __str
,
2437 #ifdef _GLIBCXX_USE_WCHAR_T
2439 basic_istream
<wchar_t>&
2440 getline(basic_istream
<wchar_t>& __in
, basic_string
<wchar_t>& __str
,
2445 #endif /* _BASIC_STRING_H */