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>
48 _GLIBCXX_BEGIN_NAMESPACE(std)
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 // NB: Mild hack to avoid strict-aliasing warnings. Note that
182 // _S_empty_rep_storage is never modified and the punning should
183 // be reasonably safe in this case.
184 void* __p = reinterpret_cast<void*>(&_S_empty_rep_storage);
185 return *reinterpret_cast<_Rep*>(__p);
190 { return this->_M_refcount < 0; }
194 { return this->_M_refcount > 0; }
198 { this->_M_refcount = -1; }
202 { this->_M_refcount = 0; }
205 _M_set_length_and_sharable(size_type __n)
207 this->_M_set_sharable(); // One reference.
208 this->_M_length = __n;
209 traits_type::assign(this->_M_refdata()[__n], _S_terminal);
210 // grrr. (per 21.3.4)
211 // You cannot leave those LWG people alone for a second.
216 { return reinterpret_cast<_CharT*>(this + 1); }
219 _M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2)
221 return (!_M_is_leaked() && __alloc1 == __alloc2)
222 ? _M_refcopy() : _M_clone(__alloc1);
227 _S_create(size_type, size_type, const _Alloc&);
230 _M_dispose(const _Alloc& __a)
232 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
233 if (__builtin_expect(this != &_S_empty_rep(), false))
235 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
241 _M_destroy(const _Alloc&) throw();
246 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
247 if (__builtin_expect(this != &_S_empty_rep(), false))
249 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
254 _M_clone(const _Alloc&, size_type __res = 0);
257 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
258 struct _Alloc_hider : _Alloc
260 _Alloc_hider(_CharT* __dat, const _Alloc& __a)
261 : _Alloc(__a), _M_p(__dat) { }
263 _CharT* _M_p; // The actual data.
267 // Data Members (public):
268 // NB: This is an unsigned type, and thus represents the maximum
269 // size that the allocator can hold.
270 /// Value returned by various member functions when they fail.
271 static const size_type npos = static_cast<size_type>(-1);
274 // Data Members (private):
275 mutable _Alloc_hider _M_dataplus;
279 { return _M_dataplus._M_p; }
283 { return (_M_dataplus._M_p = __p); }
287 { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }
289 // For the internal use we have functions similar to `begin'/`end'
290 // but they do not call _M_leak.
293 { return iterator(_M_data()); }
297 { return iterator(_M_data() + this->size()); }
300 _M_leak() // for use in begin() & non-const op[]
302 if (!_M_rep()->_M_is_leaked())
307 _M_check(size_type __pos, const char* __s) const
309 if (__pos > this->size())
310 __throw_out_of_range(__N(__s));
315 _M_check_length(size_type __n1, size_type __n2, const char* __s) const
317 if (this->max_size() - (this->size() - __n1) < __n2)
318 __throw_length_error(__N(__s));
321 // NB: _M_limit doesn't check for a bad __pos value.
323 _M_limit(size_type __pos, size_type __off) const
325 const bool __testoff = __off < this->size() - __pos;
326 return __testoff ? __off : this->size() - __pos;
329 // True if _Rep and source do not overlap.
331 _M_disjunct(const _CharT* __s) const
333 return (less<const _CharT*>()(__s, _M_data())
334 || less<const _CharT*>()(_M_data() + this->size(), __s));
337 // When __n = 1 way faster than the general multichar
338 // traits_type::copy/move/assign.
340 _M_copy(_CharT* __d, const _CharT* __s, size_type __n)
343 traits_type::assign(*__d, *__s);
345 traits_type::copy(__d, __s, __n);
349 _M_move(_CharT* __d, const _CharT* __s, size_type __n)
352 traits_type::assign(*__d, *__s);
354 traits_type::move(__d, __s, __n);
358 _M_assign(_CharT* __d, size_type __n, _CharT __c)
361 traits_type::assign(*__d, __c);
363 traits_type::assign(__d, __n, __c);
366 // _S_copy_chars is a separate template to permit specialization
367 // to optimize for the common case of pointers as iterators.
368 template<class _Iterator>
370 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
372 for (; __k1 != __k2; ++__k1, ++__p)
373 traits_type::assign(*__p, *__k1); // These types are off.
377 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2)
378 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
381 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
382 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
385 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2)
386 { _M_copy(__p, __k1, __k2 - __k1); }
389 _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
390 { _M_copy(__p, __k1, __k2 - __k1); }
393 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
400 { return _Rep::_S_empty_rep(); }
403 // Construct/copy/destroy:
404 // NB: We overload ctors in some cases instead of using default
405 // arguments, per 17.4.4.4 para. 2 item 2.
408 * @brief Default constructor creates an empty string.
414 * @brief Construct an empty string using allocator @a a.
417 basic_string(const _Alloc& __a);
419 // NB: per LWG issue 42, semantics different from IS:
421 * @brief Construct string with copy of value of @a str.
422 * @param str Source string.
424 basic_string(const basic_string& __str);
426 * @brief Construct string as copy of a substring.
427 * @param str Source string.
428 * @param pos Index of first character to copy from.
429 * @param n Number of characters to copy (default remainder).
431 basic_string(const basic_string& __str, size_type __pos,
432 size_type __n = npos);
434 * @brief Construct string as copy of a substring.
435 * @param str Source string.
436 * @param pos Index of first character to copy from.
437 * @param n Number of characters to copy.
438 * @param a Allocator to use.
440 basic_string(const basic_string& __str, size_type __pos,
441 size_type __n, const _Alloc& __a);
444 * @brief Construct string initialized by a character array.
445 * @param s Source character array.
446 * @param n Number of characters to copy.
447 * @param a Allocator to use (default is default allocator).
449 * NB: @a s must have at least @a n characters, '\0' has no special
452 basic_string(const _CharT* __s, size_type __n,
453 const _Alloc& __a = _Alloc());
455 * @brief Construct string as copy of a C string.
456 * @param s Source C string.
457 * @param a Allocator to use (default is default allocator).
459 basic_string(const _CharT* __s, const _Alloc& __a = _Alloc());
461 * @brief Construct string as multiple characters.
462 * @param n Number of characters.
463 * @param c Character to use.
464 * @param a Allocator to use (default is default allocator).
466 basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
469 * @brief Construct string as copy of a range.
470 * @param beg Start of range.
471 * @param end End of range.
472 * @param a Allocator to use (default is default allocator).
474 template<class _InputIterator>
475 basic_string(_InputIterator __beg, _InputIterator __end,
476 const _Alloc& __a = _Alloc());
479 * @brief Destroy the string instance.
482 { _M_rep()->_M_dispose(this->get_allocator()); }
485 * @brief Assign the value of @a str to this string.
486 * @param str Source string.
489 operator=(const basic_string& __str)
490 { return this->assign(__str); }
493 * @brief Copy contents of @a s into this string.
494 * @param s Source null-terminated string.
497 operator=(const _CharT* __s)
498 { return this->assign(__s); }
501 * @brief Set value to string of length 1.
502 * @param c Source character.
504 * Assigning to a character makes this string length 1 and
505 * (*this)[0] == @a c.
508 operator=(_CharT __c)
510 this->assign(1, __c);
516 * Returns a read/write iterator that points to the first character in
517 * the %string. Unshares the string.
523 return iterator(_M_data());
527 * Returns a read-only (constant) iterator that points to the first
528 * character in the %string.
532 { return const_iterator(_M_data()); }
535 * Returns a read/write iterator that points one past the last
536 * character in the %string. Unshares the string.
542 return iterator(_M_data() + this->size());
546 * Returns a read-only (constant) iterator that points one past the
547 * last character in the %string.
551 { return const_iterator(_M_data() + this->size()); }
554 * Returns a read/write reverse iterator that points to the last
555 * character in the %string. Iteration is done in reverse element
556 * order. Unshares the string.
560 { return reverse_iterator(this->end()); }
563 * Returns a read-only (constant) reverse iterator that points
564 * to the last character in the %string. Iteration is done in
565 * reverse element order.
567 const_reverse_iterator
569 { return const_reverse_iterator(this->end()); }
572 * Returns a read/write reverse iterator that points to one before the
573 * first character in the %string. Iteration is done in reverse
574 * element order. Unshares the string.
578 { return reverse_iterator(this->begin()); }
581 * Returns a read-only (constant) reverse iterator that points
582 * to one before the first character in the %string. Iteration
583 * is done in reverse element order.
585 const_reverse_iterator
587 { return const_reverse_iterator(this->begin()); }
591 /// Returns the number of characters in the string, not including any
592 /// null-termination.
595 { return _M_rep()->_M_length; }
597 /// Returns the number of characters in the string, not including any
598 /// null-termination.
601 { return _M_rep()->_M_length; }
603 /// Returns the size() of the largest possible %string.
606 { return _Rep::_S_max_size; }
609 * @brief Resizes the %string to the specified number of characters.
610 * @param n Number of characters the %string should contain.
611 * @param c Character to fill any new elements.
613 * This function will %resize the %string to the specified
614 * number of characters. If the number is smaller than the
615 * %string's current size the %string is truncated, otherwise
616 * the %string is extended and new elements are set to @a c.
619 resize(size_type __n, _CharT __c);
622 * @brief Resizes the %string to the specified number of characters.
623 * @param n Number of characters the %string should contain.
625 * This function will resize the %string to the specified length. If
626 * the new size is smaller than the %string's current size the %string
627 * is truncated, otherwise the %string is extended and new characters
628 * are default-constructed. For basic types such as char, this means
632 resize(size_type __n)
633 { this->resize(__n, _CharT()); }
636 * Returns the total number of characters that the %string can hold
637 * before needing to allocate more memory.
641 { return _M_rep()->_M_capacity; }
644 * @brief Attempt to preallocate enough memory for specified number of
646 * @param res_arg Number of characters required.
647 * @throw std::length_error If @a res_arg exceeds @c max_size().
649 * This function attempts to reserve enough memory for the
650 * %string to hold the specified number of characters. If the
651 * number requested is more than max_size(), length_error is
654 * The advantage of this function is that if optimal code is a
655 * necessity and the user can determine the string length that will be
656 * required, the user can reserve the memory in %advance, and thus
657 * prevent a possible reallocation of memory and copying of %string
661 reserve(size_type __res_arg = 0);
664 * Erases the string, making it empty.
668 { _M_mutate(0, this->size(), 0); }
671 * Returns true if the %string is empty. Equivalent to *this == "".
675 { return this->size() == 0; }
679 * @brief Subscript access to the data contained in the %string.
680 * @param pos The index of the character to access.
681 * @return Read-only (constant) reference to the character.
683 * This operator allows for easy, array-style, data access.
684 * Note that data access with this operator is unchecked and
685 * out_of_range lookups are not defined. (For checked lookups
689 operator[] (size_type __pos) const
691 _GLIBCXX_DEBUG_ASSERT(__pos <= size());
692 return _M_data()[__pos];
696 * @brief Subscript access to the data contained in the %string.
697 * @param pos The index of the character to access.
698 * @return Read/write reference to the character.
700 * This operator allows for easy, array-style, data access.
701 * Note that data access with this operator is unchecked and
702 * out_of_range lookups are not defined. (For checked lookups
703 * see at().) Unshares the string.
706 operator[](size_type __pos)
708 // allow pos == size() as v3 extension:
709 _GLIBCXX_DEBUG_ASSERT(__pos <= size());
710 // but be strict in pedantic mode:
711 _GLIBCXX_DEBUG_PEDASSERT(__pos < size());
713 return _M_data()[__pos];
717 * @brief Provides access to the data contained in the %string.
718 * @param n The index of the character to access.
719 * @return Read-only (const) reference to the character.
720 * @throw std::out_of_range If @a n is an invalid index.
722 * This function provides for safer data access. The parameter is
723 * first checked that it is in the range of the string. The function
724 * throws out_of_range if the check fails.
727 at(size_type __n) const
729 if (__n >= this->size())
730 __throw_out_of_range(__N("basic_string::at"));
731 return _M_data()[__n];
735 * @brief Provides access to the data contained in the %string.
736 * @param n The index of the character to access.
737 * @return Read/write reference to the character.
738 * @throw std::out_of_range If @a n is an invalid index.
740 * This function provides for safer data access. The parameter is
741 * first checked that it is in the range of the string. The function
742 * throws out_of_range if the check fails. Success results in
743 * unsharing the string.
749 __throw_out_of_range(__N("basic_string::at"));
751 return _M_data()[__n];
756 * @brief Append a string to this string.
757 * @param str The string to append.
758 * @return Reference to this string.
761 operator+=(const basic_string& __str)
762 { return this->append(__str); }
765 * @brief Append a C string.
766 * @param s The C string to append.
767 * @return Reference to this string.
770 operator+=(const _CharT* __s)
771 { return this->append(__s); }
774 * @brief Append a character.
775 * @param c The character to append.
776 * @return Reference to this string.
779 operator+=(_CharT __c)
781 this->push_back(__c);
786 * @brief Append a string to this string.
787 * @param str The string to append.
788 * @return Reference to this string.
791 append(const basic_string& __str);
794 * @brief Append a substring.
795 * @param str The string to append.
796 * @param pos Index of the first character of str to append.
797 * @param n The number of characters to append.
798 * @return Reference to this string.
799 * @throw std::out_of_range if @a pos is not a valid index.
801 * This function appends @a n characters from @a str starting at @a pos
802 * to this string. If @a n is is larger than the number of available
803 * characters in @a str, the remainder of @a str is appended.
806 append(const basic_string& __str, size_type __pos, size_type __n);
809 * @brief Append a C substring.
810 * @param s The C string to append.
811 * @param n The number of characters to append.
812 * @return Reference to this string.
815 append(const _CharT* __s, size_type __n);
818 * @brief Append a C string.
819 * @param s The C string to append.
820 * @return Reference to this string.
823 append(const _CharT* __s)
825 __glibcxx_requires_string(__s);
826 return this->append(__s, traits_type::length(__s));
830 * @brief Append multiple characters.
831 * @param n The number of characters to append.
832 * @param c The character to use.
833 * @return Reference to this string.
835 * Appends n copies of c to this string.
838 append(size_type __n, _CharT __c);
841 * @brief Append a range of characters.
842 * @param first Iterator referencing the first character to append.
843 * @param last Iterator marking the end of the range.
844 * @return Reference to this string.
846 * Appends characters in the range [first,last) to this string.
848 template<class _InputIterator>
850 append(_InputIterator __first, _InputIterator __last)
851 { return this->replace(_M_iend(), _M_iend(), __first, __last); }
854 * @brief Append a single character.
855 * @param c Character to append.
858 push_back(_CharT __c)
860 const size_type __len = 1 + this->size();
861 if (__len > this->capacity() || _M_rep()->_M_is_shared())
862 this->reserve(__len);
863 traits_type::assign(_M_data()[this->size()], __c);
864 _M_rep()->_M_set_length_and_sharable(__len);
868 * @brief Set value to contents of another string.
869 * @param str Source string to use.
870 * @return Reference to this string.
873 assign(const basic_string& __str);
876 * @brief Set value to a substring of a string.
877 * @param str The string to use.
878 * @param pos Index of the first character of str.
879 * @param n Number of characters to use.
880 * @return Reference to this string.
881 * @throw std::out_of_range if @a pos is not a valid index.
883 * This function sets this string to the substring of @a str consisting
884 * of @a n characters at @a pos. If @a n is is larger than the number
885 * of available characters in @a str, the remainder of @a str is used.
888 assign(const basic_string& __str, size_type __pos, size_type __n)
889 { return this->assign(__str._M_data()
890 + __str._M_check(__pos, "basic_string::assign"),
891 __str._M_limit(__pos, __n)); }
894 * @brief Set value to a C substring.
895 * @param s The C string to use.
896 * @param n Number of characters to use.
897 * @return Reference to this string.
899 * This function sets the value of this string to the first @a n
900 * characters of @a s. If @a n is is larger than the number of
901 * available characters in @a s, the remainder of @a s is used.
904 assign(const _CharT* __s, size_type __n);
907 * @brief Set value to contents of a C string.
908 * @param s The C string to use.
909 * @return Reference to this string.
911 * This function sets the value of this string to the value of @a s.
912 * The data is copied, so there is no dependence on @a s once the
916 assign(const _CharT* __s)
918 __glibcxx_requires_string(__s);
919 return this->assign(__s, traits_type::length(__s));
923 * @brief Set value to multiple characters.
924 * @param n Length of the resulting string.
925 * @param c The character to use.
926 * @return Reference to this string.
928 * This function sets the value of this string to @a n copies of
932 assign(size_type __n, _CharT __c)
933 { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
936 * @brief Set value to a range of characters.
937 * @param first Iterator referencing the first character to append.
938 * @param last Iterator marking the end of the range.
939 * @return Reference to this string.
941 * Sets value of string to characters in the range [first,last).
943 template<class _InputIterator>
945 assign(_InputIterator __first, _InputIterator __last)
946 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
949 * @brief Insert multiple characters.
950 * @param p Iterator referencing location in string to insert at.
951 * @param n Number of characters to insert
952 * @param c The character to insert.
953 * @throw std::length_error If new length exceeds @c max_size().
955 * Inserts @a n copies of character @a c starting at the position
956 * referenced by iterator @a p. If adding characters causes the length
957 * to exceed max_size(), length_error is thrown. The value of the
958 * string doesn't change if an error is thrown.
961 insert(iterator __p, size_type __n, _CharT __c)
962 { this->replace(__p, __p, __n, __c); }
965 * @brief Insert a range of characters.
966 * @param p Iterator referencing location in string to insert at.
967 * @param beg Start of range.
968 * @param end End of range.
969 * @throw std::length_error If new length exceeds @c max_size().
971 * Inserts characters in range [beg,end). If adding characters causes
972 * the length to exceed max_size(), length_error is thrown. The value
973 * of the string doesn't change if an error is thrown.
975 template<class _InputIterator>
977 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
978 { this->replace(__p, __p, __beg, __end); }
981 * @brief Insert value of a string.
982 * @param pos1 Iterator referencing location in string to insert at.
983 * @param str The string to insert.
984 * @return Reference to this string.
985 * @throw std::length_error If new length exceeds @c max_size().
987 * Inserts value of @a str starting at @a pos1. If adding characters
988 * causes the length to exceed max_size(), length_error is thrown. The
989 * value of the string doesn't change if an error is thrown.
992 insert(size_type __pos1, const basic_string& __str)
993 { return this->insert(__pos1, __str, size_type(0), __str.size()); }
996 * @brief Insert a substring.
997 * @param pos1 Iterator referencing location in string to insert at.
998 * @param str The string to insert.
999 * @param pos2 Start of characters in str to insert.
1000 * @param n Number of characters to insert.
1001 * @return Reference to this string.
1002 * @throw std::length_error If new length exceeds @c max_size().
1003 * @throw std::out_of_range If @a pos1 > size() or
1004 * @a pos2 > @a str.size().
1006 * Starting at @a pos1, insert @a n character of @a str beginning with
1007 * @a pos2. If adding characters causes the length to exceed
1008 * max_size(), length_error is thrown. If @a pos1 is beyond the end of
1009 * this string or @a pos2 is beyond the end of @a str, out_of_range is
1010 * thrown. The value of the string doesn't change if an error is
1014 insert(size_type __pos1, const basic_string& __str,
1015 size_type __pos2, size_type __n)
1016 { return this->insert(__pos1, __str._M_data()
1017 + __str._M_check(__pos2, "basic_string::insert"),
1018 __str._M_limit(__pos2, __n)); }
1021 * @brief Insert a C substring.
1022 * @param pos Iterator referencing location in string to insert at.
1023 * @param s The C string to insert.
1024 * @param n The number of characters to insert.
1025 * @return Reference to this string.
1026 * @throw std::length_error If new length exceeds @c max_size().
1027 * @throw std::out_of_range If @a pos is beyond the end of this
1030 * Inserts the first @a n characters of @a s starting at @a pos. If
1031 * adding characters causes the length to exceed max_size(),
1032 * length_error is thrown. If @a pos is beyond end(), out_of_range is
1033 * thrown. The value of the string doesn't change if an error is
1037 insert(size_type __pos, const _CharT* __s, size_type __n);
1040 * @brief Insert a C string.
1041 * @param pos Iterator referencing location in string to insert at.
1042 * @param s The C string to insert.
1043 * @return Reference to this string.
1044 * @throw std::length_error If new length exceeds @c max_size().
1045 * @throw std::out_of_range If @a pos is beyond the end of this
1048 * Inserts the first @a n characters of @a s starting at @a pos. If
1049 * adding characters causes the length to exceed max_size(),
1050 * length_error is thrown. If @a pos is beyond end(), out_of_range is
1051 * thrown. The value of the string doesn't change if an error is
1055 insert(size_type __pos, const _CharT* __s)
1057 __glibcxx_requires_string(__s);
1058 return this->insert(__pos, __s, traits_type::length(__s));
1062 * @brief Insert multiple characters.
1063 * @param pos Index in string to insert at.
1064 * @param n Number of characters to insert
1065 * @param c The character to insert.
1066 * @return Reference to this string.
1067 * @throw std::length_error If new length exceeds @c max_size().
1068 * @throw std::out_of_range If @a pos is beyond the end of this
1071 * Inserts @a n copies of character @a c starting at index @a pos. If
1072 * adding characters causes the length to exceed max_size(),
1073 * length_error is thrown. If @a pos > length(), out_of_range is
1074 * thrown. The value of the string doesn't change if an error is
1078 insert(size_type __pos, size_type __n, _CharT __c)
1079 { return _M_replace_aux(_M_check(__pos, "basic_string::insert"),
1080 size_type(0), __n, __c); }
1083 * @brief Insert one character.
1084 * @param p Iterator referencing position in string to insert at.
1085 * @param c The character to insert.
1086 * @return Iterator referencing newly inserted char.
1087 * @throw std::length_error If new length exceeds @c max_size().
1089 * Inserts character @a c at position referenced by @a p. If adding
1090 * character causes the length to exceed max_size(), length_error is
1091 * thrown. If @a p is beyond end of string, out_of_range is thrown.
1092 * The value of the string doesn't change if an error is thrown.
1095 insert(iterator __p, _CharT __c)
1097 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1098 const size_type __pos = __p - _M_ibegin();
1099 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1100 _M_rep()->_M_set_leaked();
1101 return iterator(_M_data() + __pos);
1105 * @brief Remove characters.
1106 * @param pos Index of first character to remove (default 0).
1107 * @param n Number of characters to remove (default remainder).
1108 * @return Reference to this string.
1109 * @throw std::out_of_range If @a pos is beyond the end of this
1112 * Removes @a n characters from this string starting at @a pos. The
1113 * length of the string is reduced by @a n. If there are < @a n
1114 * characters to remove, the remainder of the string is truncated. If
1115 * @a p is beyond end of string, out_of_range is thrown. The value of
1116 * the string doesn't change if an error is thrown.
1119 erase(size_type __pos = 0, size_type __n = npos)
1121 _M_mutate(_M_check(__pos, "basic_string::erase"),
1122 _M_limit(__pos, __n), size_type(0));
1127 * @brief Remove one character.
1128 * @param position Iterator referencing the character to remove.
1129 * @return iterator referencing same location after removal.
1131 * Removes the character at @a position from this string. The value
1132 * of the string doesn't change if an error is thrown.
1135 erase(iterator __position)
1137 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1138 && __position < _M_iend());
1139 const size_type __pos = __position - _M_ibegin();
1140 _M_mutate(__pos, size_type(1), size_type(0));
1141 _M_rep()->_M_set_leaked();
1142 return iterator(_M_data() + __pos);
1146 * @brief Remove a range of characters.
1147 * @param first Iterator referencing the first character to remove.
1148 * @param last Iterator referencing the end of the range.
1149 * @return Iterator referencing location of first after removal.
1151 * Removes the characters in the range [first,last) from this string.
1152 * The value of the string doesn't change if an error is thrown.
1155 erase(iterator __first, iterator __last)
1157 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1158 && __last <= _M_iend());
1159 const size_type __pos = __first - _M_ibegin();
1160 _M_mutate(__pos, __last - __first, size_type(0));
1161 _M_rep()->_M_set_leaked();
1162 return iterator(_M_data() + __pos);
1166 * @brief Replace characters with value from another string.
1167 * @param pos Index of first character to replace.
1168 * @param n Number of characters to be replaced.
1169 * @param str String to insert.
1170 * @return Reference to this string.
1171 * @throw std::out_of_range If @a pos is beyond the end of this
1173 * @throw std::length_error If new length exceeds @c max_size().
1175 * Removes the characters in the range [pos,pos+n) from this string.
1176 * In place, the value of @a str is inserted. If @a pos is beyond end
1177 * of string, out_of_range is thrown. If the length of the result
1178 * exceeds max_size(), length_error is thrown. The value of the string
1179 * doesn't change if an error is thrown.
1182 replace(size_type __pos, size_type __n, const basic_string& __str)
1183 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1186 * @brief Replace characters with value from another string.
1187 * @param pos1 Index of first character to replace.
1188 * @param n1 Number of characters to be replaced.
1189 * @param str String to insert.
1190 * @param pos2 Index of first character of str to use.
1191 * @param n2 Number of characters from str to use.
1192 * @return Reference to this string.
1193 * @throw std::out_of_range If @a pos1 > size() or @a pos2 >
1195 * @throw std::length_error If new length exceeds @c max_size().
1197 * Removes the characters in the range [pos1,pos1 + n) from this
1198 * string. In place, the value of @a str is inserted. If @a pos is
1199 * beyond end of string, out_of_range is thrown. If the length of the
1200 * result exceeds max_size(), length_error is thrown. The value of the
1201 * string doesn't change if an error is thrown.
1204 replace(size_type __pos1, size_type __n1, const basic_string& __str,
1205 size_type __pos2, size_type __n2)
1206 { return this->replace(__pos1, __n1, __str._M_data()
1207 + __str._M_check(__pos2, "basic_string::replace"),
1208 __str._M_limit(__pos2, __n2)); }
1211 * @brief Replace characters with value of a C substring.
1212 * @param pos Index of first character to replace.
1213 * @param n1 Number of characters to be replaced.
1214 * @param s C string to insert.
1215 * @param n2 Number of characters from @a s to use.
1216 * @return Reference to this string.
1217 * @throw std::out_of_range If @a pos1 > size().
1218 * @throw std::length_error If new length exceeds @c max_size().
1220 * Removes the characters in the range [pos,pos + n1) from this string.
1221 * In place, the first @a n2 characters of @a s are inserted, or all
1222 * of @a s if @a n2 is too large. If @a pos is beyond end of string,
1223 * out_of_range is thrown. If the length of result exceeds max_size(),
1224 * length_error is thrown. The value of the string doesn't change if
1225 * an error is thrown.
1228 replace(size_type __pos, size_type __n1, const _CharT* __s,
1232 * @brief Replace characters with value of a C string.
1233 * @param pos Index of first character to replace.
1234 * @param n1 Number of characters to be replaced.
1235 * @param s C string to insert.
1236 * @return Reference to this string.
1237 * @throw std::out_of_range If @a pos > size().
1238 * @throw std::length_error If new length exceeds @c max_size().
1240 * Removes the characters in the range [pos,pos + n1) from this string.
1241 * In place, the first @a n characters of @a s are inserted. If @a
1242 * pos is beyond end of string, out_of_range is thrown. If the length
1243 * of result exceeds max_size(), length_error is thrown. The value of
1244 * the string doesn't change if an error is thrown.
1247 replace(size_type __pos, size_type __n1, const _CharT* __s)
1249 __glibcxx_requires_string(__s);
1250 return this->replace(__pos, __n1, __s, traits_type::length(__s));
1254 * @brief Replace characters with multiple characters.
1255 * @param pos Index of first character to replace.
1256 * @param n1 Number of characters to be replaced.
1257 * @param n2 Number of characters to insert.
1258 * @param c Character to insert.
1259 * @return Reference to this string.
1260 * @throw std::out_of_range If @a pos > size().
1261 * @throw std::length_error If new length exceeds @c max_size().
1263 * Removes the characters in the range [pos,pos + n1) from this string.
1264 * In place, @a n2 copies of @a c are inserted. If @a pos is beyond
1265 * end of string, out_of_range is thrown. If the length of result
1266 * exceeds max_size(), length_error is thrown. The value of the string
1267 * doesn't change if an error is thrown.
1270 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1271 { return _M_replace_aux(_M_check(__pos, "basic_string::replace"),
1272 _M_limit(__pos, __n1), __n2, __c); }
1275 * @brief Replace range of characters with string.
1276 * @param i1 Iterator referencing start of range to replace.
1277 * @param i2 Iterator referencing end of range to replace.
1278 * @param str String value to insert.
1279 * @return Reference to this string.
1280 * @throw std::length_error If new length exceeds @c max_size().
1282 * Removes the characters in the range [i1,i2). In place, the value of
1283 * @a str is inserted. If the length of result exceeds max_size(),
1284 * length_error is thrown. The value of the string doesn't change if
1285 * an error is thrown.
1288 replace(iterator __i1, iterator __i2, const basic_string& __str)
1289 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1292 * @brief Replace range of characters with C substring.
1293 * @param i1 Iterator referencing start of range to replace.
1294 * @param i2 Iterator referencing end of range to replace.
1295 * @param s C string value to insert.
1296 * @param n Number of characters from s to insert.
1297 * @return Reference to this string.
1298 * @throw std::length_error If new length exceeds @c max_size().
1300 * Removes the characters in the range [i1,i2). In place, the first @a
1301 * n characters of @a s are inserted. If the length of result exceeds
1302 * max_size(), length_error is thrown. The value of the string doesn't
1303 * change if an error is thrown.
1306 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1308 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1309 && __i2 <= _M_iend());
1310 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1314 * @brief Replace range of characters with C string.
1315 * @param i1 Iterator referencing start of range to replace.
1316 * @param i2 Iterator referencing end of range to replace.
1317 * @param s C string value to insert.
1318 * @return Reference to this string.
1319 * @throw std::length_error If new length exceeds @c max_size().
1321 * Removes the characters in the range [i1,i2). In place, the
1322 * characters of @a s are inserted. If the length of result exceeds
1323 * max_size(), length_error is thrown. The value of the string doesn't
1324 * change if an error is thrown.
1327 replace(iterator __i1, iterator __i2, const _CharT* __s)
1329 __glibcxx_requires_string(__s);
1330 return this->replace(__i1, __i2, __s, traits_type::length(__s));
1334 * @brief Replace range of characters with multiple characters
1335 * @param i1 Iterator referencing start of range to replace.
1336 * @param i2 Iterator referencing end of range to replace.
1337 * @param n Number of characters to insert.
1338 * @param c Character to insert.
1339 * @return Reference to this string.
1340 * @throw std::length_error If new length exceeds @c max_size().
1342 * Removes the characters in the range [i1,i2). In place, @a n copies
1343 * of @a c are inserted. If the length of result exceeds max_size(),
1344 * length_error is thrown. The value of the string doesn't change if
1345 * an error is thrown.
1348 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1350 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1351 && __i2 <= _M_iend());
1352 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1356 * @brief Replace range of characters with range.
1357 * @param i1 Iterator referencing start of range to replace.
1358 * @param i2 Iterator referencing end of range to replace.
1359 * @param k1 Iterator referencing start of range to insert.
1360 * @param k2 Iterator referencing end of range to insert.
1361 * @return Reference to this string.
1362 * @throw std::length_error If new length exceeds @c max_size().
1364 * Removes the characters in the range [i1,i2). In place, characters
1365 * in the range [k1,k2) are inserted. If the length of result exceeds
1366 * max_size(), length_error is thrown. The value of the string doesn't
1367 * change if an error is thrown.
1369 template<class _InputIterator>
1371 replace(iterator __i1, iterator __i2,
1372 _InputIterator __k1, _InputIterator __k2)
1374 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1375 && __i2 <= _M_iend());
1376 __glibcxx_requires_valid_range(__k1, __k2);
1377 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1378 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1381 // Specializations for the common case of pointer and iterator:
1382 // useful to avoid the overhead of temporary buffering in _M_replace.
1384 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1386 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1387 && __i2 <= _M_iend());
1388 __glibcxx_requires_valid_range(__k1, __k2);
1389 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1394 replace(iterator __i1, iterator __i2,
1395 const _CharT* __k1, const _CharT* __k2)
1397 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1398 && __i2 <= _M_iend());
1399 __glibcxx_requires_valid_range(__k1, __k2);
1400 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1405 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1407 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1408 && __i2 <= _M_iend());
1409 __glibcxx_requires_valid_range(__k1, __k2);
1410 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1411 __k1.base(), __k2 - __k1);
1415 replace(iterator __i1, iterator __i2,
1416 const_iterator __k1, const_iterator __k2)
1418 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1419 && __i2 <= _M_iend());
1420 __glibcxx_requires_valid_range(__k1, __k2);
1421 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1422 __k1.base(), __k2 - __k1);
1426 template<class _Integer>
1428 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1429 _Integer __val, __true_type)
1430 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1432 template<class _InputIterator>
1434 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1435 _InputIterator __k2, __false_type);
1438 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1442 _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s,
1445 // _S_construct_aux is used to implement the 21.3.1 para 15 which
1446 // requires special behaviour if _InIter is an integral type
1447 template<class _InIterator>
1449 _S_construct_aux(_InIterator __beg, _InIterator __end,
1450 const _Alloc& __a, __false_type)
1452 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
1453 return _S_construct(__beg, __end, __a, _Tag());
1456 template<class _InIterator>
1458 _S_construct_aux(_InIterator __beg, _InIterator __end,
1459 const _Alloc& __a, __true_type)
1460 { return _S_construct(static_cast<size_type>(__beg),
1461 static_cast<value_type>(__end), __a); }
1463 template<class _InIterator>
1465 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a)
1467 typedef typename std::__is_integer<_InIterator>::__type _Integral;
1468 return _S_construct_aux(__beg, __end, __a, _Integral());
1471 // For Input Iterators, used in istreambuf_iterators, etc.
1472 template<class _InIterator>
1474 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
1475 input_iterator_tag);
1477 // For forward_iterators up to random_access_iterators, used for
1478 // string::iterator, _CharT*, etc.
1479 template<class _FwdIterator>
1481 _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a,
1482 forward_iterator_tag);
1485 _S_construct(size_type __req, _CharT __c, const _Alloc& __a);
1490 * @brief Copy substring into C string.
1491 * @param s C string to copy value into.
1492 * @param n Number of characters to copy.
1493 * @param pos Index of first character to copy.
1494 * @return Number of characters actually copied
1495 * @throw std::out_of_range If pos > size().
1497 * Copies up to @a n characters starting at @a pos into the C string @a
1498 * s. If @a pos is greater than size(), out_of_range is thrown.
1501 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1504 * @brief Swap contents with another string.
1505 * @param s String to swap with.
1507 * Exchanges the contents of this string with that of @a s in constant
1511 swap(basic_string& __s);
1513 // String operations:
1515 * @brief Return const pointer to null-terminated contents.
1517 * This is a handle to internal data. Do not modify or dire things may
1522 { return _M_data(); }
1525 * @brief Return const pointer to contents.
1527 * This is a handle to internal data. Do not modify or dire things may
1532 { return _M_data(); }
1535 * @brief Return copy of allocator used to construct this string.
1538 get_allocator() const
1539 { return _M_dataplus; }
1542 * @brief Find position of a C substring.
1543 * @param s C string to locate.
1544 * @param pos Index of character to search from.
1545 * @param n Number of characters from @a s to search for.
1546 * @return Index of start of first occurrence.
1548 * Starting from @a pos, searches forward for the first @a n characters
1549 * in @a s within this string. If found, returns the index where it
1550 * begins. If not found, returns npos.
1553 find(const _CharT* __s, size_type __pos, size_type __n) const;
1556 * @brief Find position of a string.
1557 * @param str String to locate.
1558 * @param pos Index of character to search from (default 0).
1559 * @return Index of start of first occurrence.
1561 * Starting from @a pos, searches forward for value of @a str within
1562 * this string. If found, returns the index where it begins. If not
1563 * found, returns npos.
1566 find(const basic_string& __str, size_type __pos = 0) const
1567 { return this->find(__str.data(), __pos, __str.size()); }
1570 * @brief Find position of a C string.
1571 * @param s C string to locate.
1572 * @param pos Index of character to search from (default 0).
1573 * @return Index of start of first occurrence.
1575 * Starting from @a pos, searches forward for the value of @a s within
1576 * this string. If found, returns the index where it begins. If not
1577 * found, returns npos.
1580 find(const _CharT* __s, size_type __pos = 0) const
1582 __glibcxx_requires_string(__s);
1583 return this->find(__s, __pos, traits_type::length(__s));
1587 * @brief Find position of a character.
1588 * @param c Character to locate.
1589 * @param pos Index of character to search from (default 0).
1590 * @return Index of first occurrence.
1592 * Starting from @a pos, searches forward for @a c within this string.
1593 * If found, returns the index where it was found. If not found,
1597 find(_CharT __c, size_type __pos = 0) const;
1600 * @brief Find last position of a string.
1601 * @param str String to locate.
1602 * @param pos Index of character to search back from (default end).
1603 * @return Index of start of last occurrence.
1605 * Starting from @a pos, searches backward for value of @a str within
1606 * this string. If found, returns the index where it begins. If not
1607 * found, returns npos.
1610 rfind(const basic_string& __str, size_type __pos = npos) const
1611 { return this->rfind(__str.data(), __pos, __str.size()); }
1614 * @brief Find last position of a C substring.
1615 * @param s C string to locate.
1616 * @param pos Index of character to search back from.
1617 * @param n Number of characters from s to search for.
1618 * @return Index of start of last occurrence.
1620 * Starting from @a pos, searches backward for the first @a n
1621 * characters in @a s within this string. If found, returns the index
1622 * where it begins. If not found, returns npos.
1625 rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1628 * @brief Find last position of a C string.
1629 * @param s C string to locate.
1630 * @param pos Index of character to start search at (default 0).
1631 * @return Index of start of last occurrence.
1633 * Starting from @a pos, searches backward for the value of @a s within
1634 * this string. If found, returns the index where it begins. If not
1635 * found, returns npos.
1638 rfind(const _CharT* __s, size_type __pos = npos) const
1640 __glibcxx_requires_string(__s);
1641 return this->rfind(__s, __pos, traits_type::length(__s));
1645 * @brief Find last position of a character.
1646 * @param c Character to locate.
1647 * @param pos Index of character to search back from (default 0).
1648 * @return Index of last occurrence.
1650 * Starting from @a pos, searches backward for @a c within this string.
1651 * If found, returns the index where it was found. If not found,
1655 rfind(_CharT __c, size_type __pos = npos) const;
1658 * @brief Find position of a character of string.
1659 * @param str String containing characters to locate.
1660 * @param pos Index of character to search from (default 0).
1661 * @return Index of first occurrence.
1663 * Starting from @a pos, searches forward for one of the characters of
1664 * @a str within this string. If found, returns the index where it was
1665 * found. If not found, returns npos.
1668 find_first_of(const basic_string& __str, size_type __pos = 0) const
1669 { return this->find_first_of(__str.data(), __pos, __str.size()); }
1672 * @brief Find position of a character of C substring.
1673 * @param s String containing characters to locate.
1674 * @param pos Index of character to search from (default 0).
1675 * @param n Number of characters from s to search for.
1676 * @return Index of first occurrence.
1678 * Starting from @a pos, searches forward for one of the first @a n
1679 * characters of @a s within this string. If found, returns the index
1680 * where it was found. If not found, returns npos.
1683 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1686 * @brief Find position of a character of C string.
1687 * @param s String containing characters to locate.
1688 * @param pos Index of character to search from (default 0).
1689 * @return Index of first occurrence.
1691 * Starting from @a pos, searches forward for one of the characters of
1692 * @a s within this string. If found, returns the index where it was
1693 * found. If not found, returns npos.
1696 find_first_of(const _CharT* __s, size_type __pos = 0) const
1698 __glibcxx_requires_string(__s);
1699 return this->find_first_of(__s, __pos, traits_type::length(__s));
1703 * @brief Find position of a character.
1704 * @param c Character to locate.
1705 * @param pos Index of character to search from (default 0).
1706 * @return Index of first occurrence.
1708 * Starting from @a pos, searches forward for the character @a c within
1709 * this string. If found, returns the index where it was found. If
1710 * not found, returns npos.
1712 * Note: equivalent to find(c, pos).
1715 find_first_of(_CharT __c, size_type __pos = 0) const
1716 { return this->find(__c, __pos); }
1719 * @brief Find last position of a character of string.
1720 * @param str String containing characters to locate.
1721 * @param pos Index of character to search back from (default end).
1722 * @return Index of last occurrence.
1724 * Starting from @a pos, searches backward for one of the characters of
1725 * @a str within this string. If found, returns the index where it was
1726 * found. If not found, returns npos.
1729 find_last_of(const basic_string& __str, size_type __pos = npos) const
1730 { return this->find_last_of(__str.data(), __pos, __str.size()); }
1733 * @brief Find last position of a character of C substring.
1734 * @param s C string containing characters to locate.
1735 * @param pos Index of character to search back from (default end).
1736 * @param n Number of characters from s to search for.
1737 * @return Index of last occurrence.
1739 * Starting from @a pos, searches backward for one of the first @a n
1740 * characters of @a s within this string. If found, returns the index
1741 * where it was found. If not found, returns npos.
1744 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1747 * @brief Find last position of a character of C string.
1748 * @param s C string containing characters to locate.
1749 * @param pos Index of character to search back from (default end).
1750 * @return Index of last occurrence.
1752 * Starting from @a pos, searches backward for one of the characters of
1753 * @a s within this string. If found, returns the index where it was
1754 * found. If not found, returns npos.
1757 find_last_of(const _CharT* __s, size_type __pos = npos) const
1759 __glibcxx_requires_string(__s);
1760 return this->find_last_of(__s, __pos, traits_type::length(__s));
1764 * @brief Find last position of a character.
1765 * @param c Character to locate.
1766 * @param pos Index of character to search back from (default 0).
1767 * @return Index of last occurrence.
1769 * Starting from @a pos, searches backward for @a c within this string.
1770 * If found, returns the index where it was found. If not found,
1773 * Note: equivalent to rfind(c, pos).
1776 find_last_of(_CharT __c, size_type __pos = npos) const
1777 { return this->rfind(__c, __pos); }
1780 * @brief Find position of a character not in string.
1781 * @param str String containing characters to avoid.
1782 * @param pos Index of character to search from (default 0).
1783 * @return Index of first occurrence.
1785 * Starting from @a pos, searches forward for a character not contained
1786 * in @a str within this string. If found, returns the index where it
1787 * was found. If not found, returns npos.
1790 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
1791 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1794 * @brief Find position of a character not in C substring.
1795 * @param s C string containing characters to avoid.
1796 * @param pos Index of character to search from (default 0).
1797 * @param n Number of characters from s to consider.
1798 * @return Index of first occurrence.
1800 * Starting from @a pos, searches forward for a character not contained
1801 * in the first @a n characters of @a s within this string. If found,
1802 * returns the index where it was found. If not found, returns npos.
1805 find_first_not_of(const _CharT* __s, size_type __pos,
1806 size_type __n) const;
1809 * @brief Find position of a character not in C string.
1810 * @param s C string containing characters to avoid.
1811 * @param pos Index of character to search from (default 0).
1812 * @return Index of first occurrence.
1814 * Starting from @a pos, searches forward for a character not contained
1815 * in @a s within this string. If found, returns the index where it
1816 * was found. If not found, returns npos.
1819 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1821 __glibcxx_requires_string(__s);
1822 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1826 * @brief Find position of a different character.
1827 * @param c Character to avoid.
1828 * @param pos Index of character to search from (default 0).
1829 * @return Index of first occurrence.
1831 * Starting from @a pos, searches forward for a character other than @a c
1832 * within this string. If found, returns the index where it was found.
1833 * If not found, returns npos.
1836 find_first_not_of(_CharT __c, size_type __pos = 0) const;
1839 * @brief Find last position of a character not in string.
1840 * @param str String containing characters to avoid.
1841 * @param pos Index of character to search from (default 0).
1842 * @return Index of first occurrence.
1844 * Starting from @a pos, searches backward for a character not
1845 * contained in @a str within this string. If found, returns the index
1846 * where it was found. If not found, returns npos.
1849 find_last_not_of(const basic_string& __str, size_type __pos = npos) const
1850 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1853 * @brief Find last position of a character not in C substring.
1854 * @param s C string containing characters to avoid.
1855 * @param pos Index of character to search from (default 0).
1856 * @param n Number of characters from s to consider.
1857 * @return Index of first occurrence.
1859 * Starting from @a pos, searches backward for a character not
1860 * contained in the first @a n characters of @a s within this string.
1861 * If found, returns the index where it was found. If not found,
1865 find_last_not_of(const _CharT* __s, size_type __pos,
1866 size_type __n) const;
1868 * @brief Find position of a character not in C string.
1869 * @param s C string containing characters to avoid.
1870 * @param pos Index of character to search from (default 0).
1871 * @return Index of first occurrence.
1873 * Starting from @a pos, searches backward for a character not
1874 * contained in @a s within this string. If found, returns the index
1875 * where it was found. If not found, returns npos.
1878 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1880 __glibcxx_requires_string(__s);
1881 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1885 * @brief Find last position of a different character.
1886 * @param c Character to avoid.
1887 * @param pos Index of character to search from (default 0).
1888 * @return Index of first occurrence.
1890 * Starting from @a pos, searches backward for a character other than
1891 * @a c within this string. If found, returns the index where it was
1892 * found. If not found, returns npos.
1895 find_last_not_of(_CharT __c, size_type __pos = npos) const;
1898 * @brief Get a substring.
1899 * @param pos Index of first character (default 0).
1900 * @param n Number of characters in substring (default remainder).
1901 * @return The new string.
1902 * @throw std::out_of_range If pos > size().
1904 * Construct and return a new string using the @a n characters starting
1905 * at @a pos. If the string is too short, use the remainder of the
1906 * characters. If @a pos is beyond the end of the string, out_of_range
1910 substr(size_type __pos = 0, size_type __n = npos) const
1911 { return basic_string(*this,
1912 _M_check(__pos, "basic_string::substr"), __n); }
1915 * @brief Compare to a string.
1916 * @param str String to compare against.
1917 * @return Integer < 0, 0, or > 0.
1919 * Returns an integer < 0 if this string is ordered before @a str, 0 if
1920 * their values are equivalent, or > 0 if this string is ordered after
1921 * @a str. Determines the effective length rlen of the strings to
1922 * compare as the smallest of size() and str.size(). The function
1923 * then compares the two strings by calling traits::compare(data(),
1924 * str.data(),rlen). If the result of the comparison is nonzero returns
1925 * it, otherwise the shorter one is ordered first.
1928 compare(const basic_string& __str) const
1930 const size_type __size = this->size();
1931 const size_type __osize = __str.size();
1932 const size_type __len = std::min(__size, __osize);
1934 int __r = traits_type::compare(_M_data(), __str.data(), __len);
1936 __r = __size - __osize;
1941 * @brief Compare substring to a string.
1942 * @param pos Index of first character of substring.
1943 * @param n Number of characters in substring.
1944 * @param str String to compare against.
1945 * @return Integer < 0, 0, or > 0.
1947 * Form the substring of this string from the @a n characters starting
1948 * at @a pos. Returns an integer < 0 if the substring is ordered
1949 * before @a str, 0 if their values are equivalent, or > 0 if the
1950 * substring is ordered after @a str. Determines the effective length
1951 * rlen of the strings to compare as the smallest of the length of the
1952 * substring and @a str.size(). The function then compares the two
1953 * strings by calling traits::compare(substring.data(),str.data(),rlen).
1954 * If the result of the comparison is nonzero returns it, otherwise the
1955 * shorter one is ordered first.
1958 compare(size_type __pos, size_type __n, const basic_string& __str) const;
1961 * @brief Compare substring to a substring.
1962 * @param pos1 Index of first character of substring.
1963 * @param n1 Number of characters in substring.
1964 * @param str String to compare against.
1965 * @param pos2 Index of first character of substring of str.
1966 * @param n2 Number of characters in substring of str.
1967 * @return Integer < 0, 0, or > 0.
1969 * Form the substring of this string from the @a n1 characters starting
1970 * at @a pos1. Form the substring of @a str from the @a n2 characters
1971 * starting at @a pos2. Returns an integer < 0 if this substring is
1972 * ordered before the substring of @a str, 0 if their values are
1973 * equivalent, or > 0 if this substring is ordered after the substring
1974 * of @a str. Determines the effective length rlen of the strings
1975 * to compare as the smallest of the lengths of the substrings. The
1976 * function then compares the two strings by calling
1977 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
1978 * If the result of the comparison is nonzero returns it, otherwise the
1979 * shorter one is ordered first.
1982 compare(size_type __pos1, size_type __n1, const basic_string& __str,
1983 size_type __pos2, size_type __n2) const;
1986 * @brief Compare to a C string.
1987 * @param s C string to compare against.
1988 * @return Integer < 0, 0, or > 0.
1990 * Returns an integer < 0 if this string is ordered before @a s, 0 if
1991 * their values are equivalent, or > 0 if this string is ordered after
1992 * @a s. Determines the effective length rlen of the strings to
1993 * compare as the smallest of size() and the length of a string
1994 * constructed from @a s. The function then compares the two strings
1995 * by calling traits::compare(data(),s,rlen). If the result of the
1996 * comparison is nonzero returns it, otherwise the shorter one is
2000 compare(const _CharT* __s) const;
2002 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2003 // 5 String::compare specification questionable
2005 * @brief Compare substring to a C string.
2006 * @param pos Index of first character of substring.
2007 * @param n1 Number of characters in substring.
2008 * @param s C string to compare against.
2009 * @return Integer < 0, 0, or > 0.
2011 * Form the substring of this string from the @a n1 characters starting
2012 * at @a pos. Returns an integer < 0 if the substring is ordered
2013 * before @a s, 0 if their values are equivalent, or > 0 if the
2014 * substring is ordered after @a s. Determines the effective length
2015 * rlen of the strings to compare as the smallest of the length of the
2016 * substring and the length of a string constructed from @a s. The
2017 * function then compares the two string by calling
2018 * traits::compare(substring.data(),s,rlen). If the result of the
2019 * comparison is nonzero returns it, otherwise the shorter one is
2023 compare(size_type __pos, size_type __n1, const _CharT* __s) const;
2026 * @brief Compare substring against a character array.
2027 * @param pos1 Index of first character of substring.
2028 * @param n1 Number of characters in substring.
2029 * @param s character array to compare against.
2030 * @param n2 Number of characters of s.
2031 * @return Integer < 0, 0, or > 0.
2033 * Form the substring of this string from the @a n1 characters starting
2034 * at @a pos1. Form a string from the first @a n2 characters of @a s.
2035 * Returns an integer < 0 if this substring is ordered before the string
2036 * from @a s, 0 if their values are equivalent, or > 0 if this substring
2037 * is ordered after the string from @a s. Determines the effective
2038 * length rlen of the strings to compare as the smallest of the length
2039 * of the substring and @a n2. The function then compares the two
2040 * strings by calling traits::compare(substring.data(),s,rlen). If the
2041 * result of the comparison is nonzero returns it, otherwise the shorter
2042 * one is ordered first.
2044 * NB: s must have at least n2 characters, '\0' has no special
2048 compare(size_type __pos, size_type __n1, const _CharT* __s,
2049 size_type __n2) const;
2052 template<typename _CharT, typename _Traits, typename _Alloc>
2053 inline basic_string<_CharT, _Traits, _Alloc>::
2055 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
2056 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
2058 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()) { }
2063 * @brief Concatenate two strings.
2064 * @param lhs First string.
2065 * @param rhs Last string.
2066 * @return New string with value of @a lhs followed by @a rhs.
2068 template<typename _CharT, typename _Traits, typename _Alloc>
2069 basic_string<_CharT, _Traits, _Alloc>
2070 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2071 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2073 basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
2074 __str.append(__rhs);
2079 * @brief Concatenate C string and string.
2080 * @param lhs First string.
2081 * @param rhs Last string.
2082 * @return New string with value of @a lhs followed by @a rhs.
2084 template<typename _CharT, typename _Traits, typename _Alloc>
2085 basic_string<_CharT,_Traits,_Alloc>
2086 operator+(const _CharT* __lhs,
2087 const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2090 * @brief Concatenate character and string.
2091 * @param lhs First string.
2092 * @param rhs Last string.
2093 * @return New string with @a lhs followed by @a rhs.
2095 template<typename _CharT, typename _Traits, typename _Alloc>
2096 basic_string<_CharT,_Traits,_Alloc>
2097 operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2100 * @brief Concatenate string and C string.
2101 * @param lhs First string.
2102 * @param rhs Last string.
2103 * @return New string with @a lhs followed by @a rhs.
2105 template<typename _CharT, typename _Traits, typename _Alloc>
2106 inline basic_string<_CharT, _Traits, _Alloc>
2107 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2108 const _CharT* __rhs)
2110 basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
2111 __str.append(__rhs);
2116 * @brief Concatenate string and character.
2117 * @param lhs First string.
2118 * @param rhs Last string.
2119 * @return New string with @a lhs followed by @a rhs.
2121 template<typename _CharT, typename _Traits, typename _Alloc>
2122 inline basic_string<_CharT, _Traits, _Alloc>
2123 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
2125 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
2126 typedef typename __string_type::size_type __size_type;
2127 __string_type __str(__lhs);
2128 __str.append(__size_type(1), __rhs);
2134 * @brief Test equivalence of two strings.
2135 * @param lhs First string.
2136 * @param rhs Second string.
2137 * @return True if @a lhs.compare(@a rhs) == 0. False otherwise.
2139 template<typename _CharT, typename _Traits, typename _Alloc>
2141 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2142 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2143 { return __lhs.compare(__rhs) == 0; }
2146 * @brief Test equivalence of C string and string.
2147 * @param lhs C string.
2148 * @param rhs String.
2149 * @return True if @a rhs.compare(@a lhs) == 0. False otherwise.
2151 template<typename _CharT, typename _Traits, typename _Alloc>
2153 operator==(const _CharT* __lhs,
2154 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2155 { return __rhs.compare(__lhs) == 0; }
2158 * @brief Test equivalence of string and C string.
2159 * @param lhs String.
2160 * @param rhs C string.
2161 * @return True if @a lhs.compare(@a rhs) == 0. False otherwise.
2163 template<typename _CharT, typename _Traits, typename _Alloc>
2165 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2166 const _CharT* __rhs)
2167 { return __lhs.compare(__rhs) == 0; }
2171 * @brief Test difference of two strings.
2172 * @param lhs First string.
2173 * @param rhs Second string.
2174 * @return True if @a lhs.compare(@a rhs) != 0. False otherwise.
2176 template<typename _CharT, typename _Traits, typename _Alloc>
2178 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2179 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2180 { return __rhs.compare(__lhs) != 0; }
2183 * @brief Test difference of C string and string.
2184 * @param lhs C string.
2185 * @param rhs String.
2186 * @return True if @a rhs.compare(@a lhs) != 0. False otherwise.
2188 template<typename _CharT, typename _Traits, typename _Alloc>
2190 operator!=(const _CharT* __lhs,
2191 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2192 { return __rhs.compare(__lhs) != 0; }
2195 * @brief Test difference of string and C string.
2196 * @param lhs String.
2197 * @param rhs C string.
2198 * @return True if @a lhs.compare(@a rhs) != 0. False otherwise.
2200 template<typename _CharT, typename _Traits, typename _Alloc>
2202 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2203 const _CharT* __rhs)
2204 { return __lhs.compare(__rhs) != 0; }
2208 * @brief Test if string precedes string.
2209 * @param lhs First string.
2210 * @param rhs Second string.
2211 * @return True if @a lhs precedes @a rhs. False otherwise.
2213 template<typename _CharT, typename _Traits, typename _Alloc>
2215 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2216 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2217 { return __lhs.compare(__rhs) < 0; }
2220 * @brief Test if string precedes C string.
2221 * @param lhs String.
2222 * @param rhs C string.
2223 * @return True if @a lhs precedes @a rhs. False otherwise.
2225 template<typename _CharT, typename _Traits, typename _Alloc>
2227 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2228 const _CharT* __rhs)
2229 { return __lhs.compare(__rhs) < 0; }
2232 * @brief Test if C string precedes string.
2233 * @param lhs C string.
2234 * @param rhs String.
2235 * @return True if @a lhs precedes @a rhs. False otherwise.
2237 template<typename _CharT, typename _Traits, typename _Alloc>
2239 operator<(const _CharT* __lhs,
2240 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2241 { return __rhs.compare(__lhs) > 0; }
2245 * @brief Test if string follows string.
2246 * @param lhs First string.
2247 * @param rhs Second string.
2248 * @return True if @a lhs follows @a rhs. False otherwise.
2250 template<typename _CharT, typename _Traits, typename _Alloc>
2252 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2253 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2254 { return __lhs.compare(__rhs) > 0; }
2257 * @brief Test if string follows C string.
2258 * @param lhs String.
2259 * @param rhs C string.
2260 * @return True if @a lhs follows @a rhs. False otherwise.
2262 template<typename _CharT, typename _Traits, typename _Alloc>
2264 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2265 const _CharT* __rhs)
2266 { return __lhs.compare(__rhs) > 0; }
2269 * @brief Test if C string follows string.
2270 * @param lhs C string.
2271 * @param rhs String.
2272 * @return True if @a lhs follows @a rhs. False otherwise.
2274 template<typename _CharT, typename _Traits, typename _Alloc>
2276 operator>(const _CharT* __lhs,
2277 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2278 { return __rhs.compare(__lhs) < 0; }
2282 * @brief Test if string doesn't follow string.
2283 * @param lhs First string.
2284 * @param rhs Second string.
2285 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2287 template<typename _CharT, typename _Traits, typename _Alloc>
2289 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2290 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2291 { return __lhs.compare(__rhs) <= 0; }
2294 * @brief Test if string doesn't follow C string.
2295 * @param lhs String.
2296 * @param rhs C string.
2297 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2299 template<typename _CharT, typename _Traits, typename _Alloc>
2301 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2302 const _CharT* __rhs)
2303 { return __lhs.compare(__rhs) <= 0; }
2306 * @brief Test if C string doesn't follow string.
2307 * @param lhs C string.
2308 * @param rhs String.
2309 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2311 template<typename _CharT, typename _Traits, typename _Alloc>
2313 operator<=(const _CharT* __lhs,
2314 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2315 { return __rhs.compare(__lhs) >= 0; }
2319 * @brief Test if string doesn't precede string.
2320 * @param lhs First string.
2321 * @param rhs Second string.
2322 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2324 template<typename _CharT, typename _Traits, typename _Alloc>
2326 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2327 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2328 { return __lhs.compare(__rhs) >= 0; }
2331 * @brief Test if string doesn't precede C string.
2332 * @param lhs String.
2333 * @param rhs C string.
2334 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2336 template<typename _CharT, typename _Traits, typename _Alloc>
2338 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2339 const _CharT* __rhs)
2340 { return __lhs.compare(__rhs) >= 0; }
2343 * @brief Test if C string doesn't precede string.
2344 * @param lhs C string.
2345 * @param rhs String.
2346 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2348 template<typename _CharT, typename _Traits, typename _Alloc>
2350 operator>=(const _CharT* __lhs,
2351 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2352 { return __rhs.compare(__lhs) <= 0; }
2355 * @brief Swap contents of two strings.
2356 * @param lhs First string.
2357 * @param rhs Second string.
2359 * Exchanges the contents of @a lhs and @a rhs in constant time.
2361 template<typename _CharT, typename _Traits, typename _Alloc>
2363 swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
2364 basic_string<_CharT, _Traits, _Alloc>& __rhs)
2365 { __lhs.swap(__rhs); }
2368 * @brief Read stream into a string.
2369 * @param is Input stream.
2370 * @param str Buffer to store into.
2371 * @return Reference to the input stream.
2373 * Stores characters from @a is into @a str until whitespace is found, the
2374 * end of the stream is encountered, or str.max_size() is reached. If
2375 * is.width() is non-zero, that is the limit on the number of characters
2376 * stored into @a str. Any previous contents of @a str are erased.
2378 template<typename _CharT, typename _Traits, typename _Alloc>
2379 basic_istream<_CharT, _Traits>&
2380 operator>>(basic_istream<_CharT, _Traits>& __is,
2381 basic_string<_CharT, _Traits, _Alloc>& __str);
2384 basic_istream<char>&
2385 operator>>(basic_istream<char>& __is, basic_string<char>& __str);
2388 * @brief Write string to a stream.
2389 * @param os Output stream.
2390 * @param str String to write out.
2391 * @return Reference to the output stream.
2393 * Output characters of @a str into os following the same rules as for
2394 * writing a C string.
2396 template<typename _CharT, typename _Traits, typename _Alloc>
2397 basic_ostream<_CharT, _Traits>&
2398 operator<<(basic_ostream<_CharT, _Traits>& __os,
2399 const basic_string<_CharT, _Traits, _Alloc>& __str);
2402 * @brief Read a line from stream into a string.
2403 * @param is Input stream.
2404 * @param str Buffer to store into.
2405 * @param delim Character marking end of line.
2406 * @return Reference to the input stream.
2408 * Stores characters from @a is into @a str until @a delim is found, the
2409 * end of the stream is encountered, or str.max_size() is reached. If
2410 * is.width() is non-zero, that is the limit on the number of characters
2411 * stored into @a str. Any previous contents of @a str are erased. If @a
2412 * delim was encountered, it is extracted but not stored into @a str.
2414 template<typename _CharT, typename _Traits, typename _Alloc>
2415 basic_istream<_CharT, _Traits>&
2416 getline(basic_istream<_CharT, _Traits>& __is,
2417 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
2420 * @brief Read a line from stream into a string.
2421 * @param is Input stream.
2422 * @param str Buffer to store into.
2423 * @return Reference to the input stream.
2425 * Stores characters from is into @a str until '\n' is found, the end of
2426 * the stream is encountered, or str.max_size() is reached. If is.width()
2427 * is non-zero, that is the limit on the number of characters stored into
2428 * @a str. Any previous contents of @a str are erased. If end of line was
2429 * encountered, it is extracted but not stored into @a str.
2431 template<typename _CharT, typename _Traits, typename _Alloc>
2432 inline basic_istream<_CharT, _Traits>&
2433 getline(basic_istream<_CharT, _Traits>& __is,
2434 basic_string<_CharT, _Traits, _Alloc>& __str);
2437 basic_istream<char>&
2438 getline(basic_istream<char>& __in, basic_string<char>& __str,
2441 #ifdef _GLIBCXX_USE_WCHAR_T
2443 basic_istream<wchar_t>&
2444 getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
2448 _GLIBCXX_END_NAMESPACE
2450 #endif /* _BASIC_STRING_H */