1 // Components for manipulating sequences of characters -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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_state
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>
114 typedef _Traits traits_type;
115 typedef typename _Traits::char_type value_type;
116 typedef _Alloc allocator_type;
117 typedef typename _Alloc::size_type size_type;
118 typedef typename _Alloc::difference_type difference_type;
119 typedef typename _Alloc::reference reference;
120 typedef typename _Alloc::const_reference const_reference;
121 typedef typename _Alloc::pointer pointer;
122 typedef typename _Alloc::const_pointer const_pointer;
123 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
124 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
126 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
127 typedef std::reverse_iterator<iterator> reverse_iterator;
130 // _Rep: string representation
132 // 1. String really contains _M_length + 1 characters; last is set
133 // to 0 only on call to c_str(). We avoid instantiating
134 // _CharT() where the interface does not require it.
135 // 2. _M_capacity >= _M_length
136 // Allocated memory is always _M_capacity + (1 * sizeof(_CharT)).
137 // 3. _M_refcount has three states:
138 // -1: leaked, one reference, no ref-copies allowed, non-const.
139 // 0: one reference, non-const.
140 // n>0: n + 1 references, operations require a lock, const.
141 // 4. All fields==0 is an empty string, given the extra storage
142 // beyond-the-end for a null terminator; thus, the shared
143 // empty string representation needs no constructor.
148 size_type _M_capacity;
149 _Atomic_word _M_refcount;
152 struct _Rep : _Rep_base
155 typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc;
157 // (Public) Data members:
159 // The maximum number of individual char_type elements of an
160 // individual string is determined by _S_max_size. This is the
161 // value that will be returned by max_size(). (Whereas npos
162 // is the maximum number of bytes the allocator can allocate.)
163 // If one was to divvy up the theoretical largest size string,
164 // with a terminating character and m _CharT elements, it'd
166 // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
168 // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
169 // In addition, this implementation quarters this amount.
170 static const size_type _S_max_size;
171 static const _CharT _S_terminal;
173 // The following storage is init'd to 0 by the linker, resulting
174 // (carefully) in an empty string with one reference.
175 static size_type _S_empty_rep_storage[];
179 { return *reinterpret_cast<_Rep*>(&_S_empty_rep_storage); }
183 { return this->_M_refcount < 0; }
187 { return this->_M_refcount > 0; }
191 { this->_M_refcount = -1; }
195 { this->_M_refcount = 0; }
199 { return reinterpret_cast<_CharT*>(this + 1); }
202 operator[](size_t __s) throw()
203 { return _M_refdata() [__s]; }
206 _M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2)
208 return (!_M_is_leaked() && __alloc1 == __alloc2)
209 ? _M_refcopy() : _M_clone(__alloc1);
214 _S_create(size_t, const _Alloc&);
217 _M_dispose(const _Alloc& __a)
219 if (__builtin_expect(this != &_S_empty_rep(), false))
220 if (__exchange_and_add(&this->_M_refcount, -1) <= 0)
225 _M_destroy(const _Alloc&) throw();
230 if (__builtin_expect(this != &_S_empty_rep(), false))
231 __atomic_add(&this->_M_refcount, 1);
236 _M_clone(const _Alloc&, size_type __res = 0);
239 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
240 struct _Alloc_hider : _Alloc
242 _Alloc_hider(_CharT* __dat, const _Alloc& __a)
243 : _Alloc(__a), _M_p(__dat) { }
245 _CharT* _M_p; // The actual data.
249 // Data Members (public):
250 // NB: This is an unsigned type, and thus represents the maximum
251 // size that the allocator can hold.
253 /// Value returned by various member functions when they fail.
254 static const size_type npos = static_cast<size_type>(-1);
257 // Data Members (private):
258 mutable _Alloc_hider _M_dataplus;
262 { return _M_dataplus._M_p; }
266 { return (_M_dataplus._M_p = __p); }
270 { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }
272 // For the internal use we have functions similar to `begin'/`end'
273 // but they do not call _M_leak.
275 _M_ibegin() const { return iterator(_M_data()); }
278 _M_iend() const { return iterator(_M_data() + this->size()); }
281 _M_leak() // for use in begin() & non-const op[]
283 if (!_M_rep()->_M_is_leaked())
288 _M_check(size_type __pos) const
290 if (__pos > this->size())
291 __throw_out_of_range(__N("basic_string::_M_check"));
292 return _M_ibegin() + __pos;
295 // NB: _M_fold doesn't check for a bad __pos1 value.
297 _M_fold(size_type __pos, size_type __off) const
299 const bool __testoff = __off < this->size() - __pos;
300 const size_type __newoff = __testoff ? __off : this->size() - __pos;
301 return (_M_ibegin() + __pos + __newoff);
304 // _S_copy_chars is a separate template to permit specialization
305 // to optimize for the common case of pointers as iterators.
306 template<class _Iterator>
308 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
310 for (; __k1 != __k2; ++__k1, ++__p)
311 traits_type::assign(*__p, *__k1); // These types are off.
315 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2)
316 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
319 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
320 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
323 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2)
324 { traits_type::copy(__p, __k1, __k2 - __k1); }
327 _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
328 { traits_type::copy(__p, __k1, __k2 - __k1); }
331 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
338 { return _Rep::_S_empty_rep(); }
341 // Construct/copy/destroy:
342 // NB: We overload ctors in some cases instead of using default
343 // arguments, per 17.4.4.4 para. 2 item 2.
346 * @brief Default constructor creates an empty string.
352 * @brief Construct an empty string using allocator a.
355 basic_string(const _Alloc& __a);
357 // NB: per LWG issue 42, semantics different from IS:
359 * @brief Construct string with copy of value of @a str.
360 * @param str Source string.
362 basic_string(const basic_string& __str);
364 * @brief Construct string as copy of a substring.
365 * @param str Source string.
366 * @param pos Index of first character to copy from.
367 * @param n Number of characters to copy (default remainder).
369 basic_string(const basic_string& __str, size_type __pos,
370 size_type __n = npos);
372 * @brief Construct string as copy of a substring.
373 * @param str Source string.
374 * @param pos Index of first character to copy from.
375 * @param n Number of characters to copy.
376 * @param a Allocator to use.
378 basic_string(const basic_string& __str, size_type __pos,
379 size_type __n, const _Alloc& __a);
382 * @brief Construct string initialized by a character array.
383 * @param s Source character array.
384 * @param n Number of characters to copy.
385 * @param a Allocator to use (default is default allocator).
387 * NB: s must have at least n characters, '\0' has no special
390 basic_string(const _CharT* __s, size_type __n,
391 const _Alloc& __a = _Alloc());
393 * @brief Construct string as copy of a C string.
394 * @param s Source C string.
395 * @param a Allocator to use (default is default allocator).
397 basic_string(const _CharT* __s, const _Alloc& __a = _Alloc());
399 * @brief Construct string as multiple characters.
400 * @param n Number of characters.
401 * @param c Character to use.
402 * @param a Allocator to use (default is default allocator).
404 basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
407 * @brief Construct string as copy of a range.
408 * @param beg Start of range.
409 * @param end End of range.
410 * @param a Allocator to use (default is default allocator).
412 template<class _InputIterator>
413 basic_string(_InputIterator __beg, _InputIterator __end,
414 const _Alloc& __a = _Alloc());
417 * @brief Destroy the string instance.
420 { _M_rep()->_M_dispose(this->get_allocator()); }
423 * @brief Assign the value of @a str to this string.
424 * @param str Source string.
427 operator=(const basic_string& __str) { return this->assign(__str); }
430 * @brief Copy contents of @a s into this string.
431 * @param s Source null-terminated string.
434 operator=(const _CharT* __s) { return this->assign(__s); }
437 * @brief Set value to string of length 1.
438 * @param c Source character.
440 * Assigning to a character makes this string length 1 and
441 * (*this)[0] == @a c.
444 operator=(_CharT __c) { return this->assign(1, __c); }
448 * Returns a read/write iterator that points to the first character in
449 * the %string. Unshares the string.
455 return iterator(_M_data());
459 * Returns a read-only (constant) iterator that points to the first
460 * character in the %string.
464 { return const_iterator(_M_data()); }
467 * Returns a read/write iterator that points one past the last
468 * character in the %string. Unshares the string.
474 return iterator(_M_data() + this->size());
478 * Returns a read-only (constant) iterator that points one past the
479 * last character in the %string.
483 { return const_iterator(_M_data() + this->size()); }
486 * Returns a read/write reverse iterator that points to the last
487 * character in the %string. Iteration is done in reverse element
488 * order. Unshares the string.
492 { return reverse_iterator(this->end()); }
495 * Returns a read-only (constant) reverse iterator that points
496 * to the last character in the %string. Iteration is done in
497 * reverse element order.
499 const_reverse_iterator
501 { return const_reverse_iterator(this->end()); }
504 * Returns a read/write reverse iterator that points to one before the
505 * first character in the %string. Iteration is done in reverse
506 * element order. Unshares the string.
510 { return reverse_iterator(this->begin()); }
513 * Returns a read-only (constant) reverse iterator that points
514 * to one before the first character in the %string. Iteration
515 * is done in reverse element order.
517 const_reverse_iterator
519 { return const_reverse_iterator(this->begin()); }
523 /// Returns the number of characters in the string, not including any
524 /// null-termination.
526 size() const { return _M_rep()->_M_length; }
528 /// Returns the number of characters in the string, not including any
529 /// null-termination.
531 length() const { return _M_rep()->_M_length; }
533 /// Returns the size() of the largest possible %string.
535 max_size() const { return _Rep::_S_max_size; }
538 * @brief Resizes the %string to the specified number of characters.
539 * @param n Number of characters the %string should contain.
540 * @param c Character to fill any new elements.
542 * This function will %resize the %string to the specified
543 * number of characters. If the number is smaller than the
544 * %string's current size the %string is truncated, otherwise
545 * the %string is extended and new elements are set to @a c.
548 resize(size_type __n, _CharT __c);
551 * @brief Resizes the %string to the specified number of characters.
552 * @param n Number of characters the %string should contain.
554 * This function will resize the %string to the specified length. If
555 * the new size is smaller than the %string's current size the %string
556 * is truncated, otherwise the %string is extended and new characters
557 * are default-constructed. For basic types such as char, this means
561 resize(size_type __n) { this->resize(__n, _CharT()); }
564 * Returns the total number of characters that the %string can hold
565 * before needing to allocate more memory.
568 capacity() const { return _M_rep()->_M_capacity; }
571 * @brief Attempt to preallocate enough memory for specified number of
573 * @param n Number of characters required.
574 * @throw std::length_error If @a n exceeds @c max_size().
576 * This function attempts to reserve enough memory for the
577 * %string to hold the specified number of characters. If the
578 * number requested is more than max_size(), length_error is
581 * The advantage of this function is that if optimal code is a
582 * necessity and the user can determine the string length that will be
583 * required, the user can reserve the memory in %advance, and thus
584 * prevent a possible reallocation of memory and copying of %string
588 reserve(size_type __res_arg = 0);
591 * Erases the string, making it empty.
594 clear() { _M_mutate(0, this->size(), 0); }
597 * Returns true if the %string is empty. Equivalent to *this == "".
600 empty() const { return this->size() == 0; }
604 * @brief Subscript access to the data contained in the %string.
605 * @param n The index of the character to access.
606 * @return Read-only (constant) reference to the character.
608 * This operator allows for easy, array-style, data access.
609 * Note that data access with this operator is unchecked and
610 * out_of_range lookups are not defined. (For checked lookups
614 operator[] (size_type __pos) const
616 _GLIBCXX_DEBUG_ASSERT(__pos <= size());
617 return _M_data()[__pos];
621 * @brief Subscript access to the data contained in the %string.
622 * @param n The index of the character to access.
623 * @return Read/write reference to the character.
625 * This operator allows for easy, array-style, data access.
626 * Note that data access with this operator is unchecked and
627 * out_of_range lookups are not defined. (For checked lookups
628 * see at().) Unshares the string.
631 operator[](size_type __pos)
633 _GLIBCXX_DEBUG_ASSERT(__pos < size());
635 return _M_data()[__pos];
639 * @brief Provides access to the data contained in the %string.
640 * @param n The index of the character to access.
641 * @return Read-only (const) reference to the character.
642 * @throw std::out_of_range If @a n is an invalid index.
644 * This function provides for safer data access. The parameter is
645 * first checked that it is in the range of the string. The function
646 * throws out_of_range if the check fails.
649 at(size_type __n) const
651 if (__n >= this->size())
652 __throw_out_of_range(__N("basic_string::at"));
653 return _M_data()[__n];
657 * @brief Provides access to the data contained in the %string.
658 * @param n The index of the character to access.
659 * @return Read/write reference to the character.
660 * @throw std::out_of_range If @a n is an invalid index.
662 * This function provides for safer data access. The parameter is
663 * first checked that it is in the range of the string. The function
664 * throws out_of_range if the check fails. Success results in
665 * unsharing the string.
671 __throw_out_of_range(__N("basic_string::at"));
673 return _M_data()[__n];
678 * @brief Append a string to this string.
679 * @param str The string to append.
680 * @return Reference to this string.
683 operator+=(const basic_string& __str) { return this->append(__str); }
686 * @brief Append a C string.
687 * @param s The C string to append.
688 * @return Reference to this string.
691 operator+=(const _CharT* __s) { return this->append(__s); }
694 * @brief Append a character.
695 * @param s The character to append.
696 * @return Reference to this string.
699 operator+=(_CharT __c) { return this->append(size_type(1), __c); }
702 * @brief Append a string to this string.
703 * @param str The string to append.
704 * @return Reference to this string.
707 append(const basic_string& __str);
710 * @brief Append a substring.
711 * @param str The string to append.
712 * @param pos Index of the first character of str to append.
713 * @param n The number of characters to append.
714 * @return Reference to this string.
715 * @throw std::out_of_range if @a pos is not a valid index.
717 * This function appends @a n characters from @a str starting at @a pos
718 * to this string. If @a n is is larger than the number of available
719 * characters in @a str, the remainder of @a str is appended.
722 append(const basic_string& __str, size_type __pos, size_type __n);
725 * @brief Append a C substring.
726 * @param s The C string to append.
727 * @param n The number of characters to append.
728 * @return Reference to this string.
731 append(const _CharT* __s, size_type __n);
734 * @brief Append a C string.
735 * @param s The C string to append.
736 * @return Reference to this string.
739 append(const _CharT* __s)
741 __glibcxx_requires_string(__s);
742 return this->append(__s, traits_type::length(__s));
746 * @brief Append multiple characters.
747 * @param n The number of characters to append.
748 * @param c The character to use.
749 * @return Reference to this string.
751 * Appends n copies of c to this string.
754 append(size_type __n, _CharT __c);
757 * @brief Append a range of characters.
758 * @param first Iterator referencing the first character to append.
759 * @param last Iterator marking the end of the range.
760 * @return Reference to this string.
762 * Appends characters in the range [first,last) to this string.
764 template<class _InputIterator>
766 append(_InputIterator __first, _InputIterator __last)
767 { return this->replace(_M_iend(), _M_iend(), __first, __last); }
770 * @brief Append a single character.
771 * @param c Character to append.
774 push_back(_CharT __c)
775 { this->replace(_M_iend(), _M_iend(), 1, __c); }
778 * @brief Set value to contents of another string.
779 * @param str Source string to use.
780 * @return Reference to this string.
783 assign(const basic_string& __str);
786 * @brief Set value to a substring of a string.
787 * @param str The string to use.
788 * @param pos Index of the first character of str.
789 * @param n Number of characters to use.
790 * @return Reference to this string.
791 * @throw std::out_of_range if @a pos is not a valid index.
793 * This function sets this string to the substring of @a str consisting
794 * of @a n characters at @a pos. If @a n is is larger than the number
795 * of available characters in @a str, the remainder of @a str is used.
798 assign(const basic_string& __str, size_type __pos, size_type __n);
801 * @brief Set value to a C substring.
802 * @param s The C string to use.
803 * @param n Number of characters to use.
804 * @return Reference to this string.
806 * This function sets the value of this string to the first @a n
807 * characters of @a s. If @a n is is larger than the number of
808 * available characters in @a s, the remainder of @a s is used.
811 assign(const _CharT* __s, size_type __n);
814 * @brief Set value to contents of a C string.
815 * @param s The C string to use.
816 * @return Reference to this string.
818 * This function sets the value of this string to the value of @a s.
819 * The data is copied, so there is no dependence on @a s once the
823 assign(const _CharT* __s)
825 __glibcxx_requires_string(__s);
826 return this->assign(__s, traits_type::length(__s));
830 * @brief Set value to multiple characters.
831 * @param n Length of the resulting string.
832 * @param c The character to use.
833 * @return Reference to this string.
835 * This function sets the value of this string to @a n copies of
839 assign(size_type __n, _CharT __c)
840 { return this->replace(_M_ibegin(), _M_iend(), __n, __c); }
843 * @brief Set value to a range of characters.
844 * @param first Iterator referencing the first character to append.
845 * @param last Iterator marking the end of the range.
846 * @return Reference to this string.
848 * Sets value of string to characters in the range [first,last).
850 template<class _InputIterator>
852 assign(_InputIterator __first, _InputIterator __last)
853 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
856 * @brief Insert multiple characters.
857 * @param p Iterator referencing location in string to insert at.
858 * @param n Number of characters to insert
859 * @param c The character to insert.
860 * @throw std::length_error If new length exceeds @c max_size().
862 * Inserts @a n copies of character @a c starting at the position
863 * referenced by iterator @a p. If adding characters causes the length
864 * to exceed max_size(), length_error is thrown. The value of the
865 * string doesn't change if an error is thrown.
868 insert(iterator __p, size_type __n, _CharT __c)
869 { this->replace(__p, __p, __n, __c); }
872 * @brief Insert a range of characters.
873 * @param p Iterator referencing location in string to insert at.
874 * @param beg Start of range.
875 * @param end End of range.
876 * @throw std::length_error If new length exceeds @c max_size().
878 * Inserts characters in range [beg,end). If adding characters causes
879 * the length to exceed max_size(), length_error is thrown. The value
880 * of the string doesn't change if an error is thrown.
882 template<class _InputIterator>
883 void insert(iterator __p, _InputIterator __beg, _InputIterator __end)
884 { this->replace(__p, __p, __beg, __end); }
887 * @brief Insert value of a string.
888 * @param pos1 Iterator referencing location in string to insert at.
889 * @param str The string to insert.
890 * @return Reference to this string.
891 * @throw std::length_error If new length exceeds @c max_size().
893 * Inserts value of @a str starting at @a pos1. If adding characters
894 * causes the length to exceed max_size(), length_error is thrown. The
895 * value of the string doesn't change if an error is thrown.
898 insert(size_type __pos1, const basic_string& __str)
899 { return this->insert(__pos1, __str, 0, __str.size()); }
902 * @brief Insert a substring.
903 * @param pos1 Iterator referencing location in string to insert at.
904 * @param str The string to insert.
905 * @param pos2 Start of characters in str to insert.
906 * @param n Number of characters to insert.
907 * @return Reference to this string.
908 * @throw std::length_error If new length exceeds @c max_size().
909 * @throw std::out_of_range If @a pos1 > size() or
910 * @a pos2 > @a str.size().
912 * Starting at @a pos1, insert @a n character of @a str beginning with
913 * @a pos2. If adding characters causes the length to exceed
914 * max_size(), length_error is thrown. If @a pos1 is beyond the end of
915 * this string or @a pos2 is beyond the end of @a str, out_of_range is
916 * thrown. The value of the string doesn't change if an error is
920 insert(size_type __pos1, const basic_string& __str,
921 size_type __pos2, size_type __n);
924 * @brief Insert a C substring.
925 * @param pos Iterator referencing location in string to insert at.
926 * @param s The C string to insert.
927 * @param n The number of characters to insert.
928 * @return Reference to this string.
929 * @throw std::length_error If new length exceeds @c max_size().
930 * @throw std::out_of_range If @a pos is beyond the end of this
933 * Inserts the first @a n characters of @a s starting at @a pos. If
934 * adding characters causes the length to exceed max_size(),
935 * length_error is thrown. If @a pos is beyond end(), out_of_range is
936 * thrown. The value of the string doesn't change if an error is
940 insert(size_type __pos, const _CharT* __s, size_type __n);
943 * @brief Insert a C string.
944 * @param pos Iterator referencing location in string to insert at.
945 * @param s The C string to insert.
946 * @return Reference to this string.
947 * @throw std::length_error If new length exceeds @c max_size().
948 * @throw std::out_of_range If @a pos is beyond the end of this
951 * Inserts the first @a n characters of @a s starting at @a pos. If
952 * adding characters causes the length to exceed max_size(),
953 * length_error is thrown. If @a pos is beyond end(), out_of_range is
954 * thrown. The value of the string doesn't change if an error is
958 insert(size_type __pos, const _CharT* __s)
960 __glibcxx_requires_string(__s);
961 return this->insert(__pos, __s, traits_type::length(__s));
965 * @brief Insert multiple characters.
966 * @param pos Index in string to insert at.
967 * @param n Number of characters to insert
968 * @param c The character to insert.
969 * @return Reference to this string.
970 * @throw std::length_error If new length exceeds @c max_size().
971 * @throw std::out_of_range If @a pos is beyond the end of this
974 * Inserts @a n copies of character @a c starting at index @a pos. If
975 * adding characters causes the length to exceed max_size(),
976 * length_error is thrown. If @a pos > length(), out_of_range is
977 * thrown. The value of the string doesn't change if an error is
981 insert(size_type __pos, size_type __n, _CharT __c)
983 this->insert(_M_check(__pos), __n, __c);
988 * @brief Insert one character.
989 * @param p Iterator referencing position in string to insert at.
990 * @param c The character to insert.
991 * @return Iterator referencing newly inserted char.
992 * @throw std::length_error If new length exceeds @c max_size().
993 * @throw std::out_of_range If @a p is beyond the end of this string.
995 * Inserts character @a c at position referenced by @a p. If adding
996 * character causes the length to exceed max_size(), length_error is
997 * thrown. If @a p is beyond end of string, out_of_range is thrown.
998 * The value of the string doesn't change if an error is thrown.
1001 insert(iterator __p, _CharT __c)
1003 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1004 const size_type __pos = __p - _M_ibegin();
1005 this->insert(_M_check(__pos), size_type(1), __c);
1006 _M_rep()->_M_set_leaked();
1007 return this->_M_ibegin() + __pos;
1010 #ifdef _GLIBCXX_DEPRECATED
1012 * @brief Insert one default-constructed character.
1013 * @param p Iterator referencing position in string to insert at.
1014 * @return Iterator referencing newly inserted char.
1015 * @throw std::length_error If new length exceeds @c max_size().
1016 * @throw std::out_of_range If @a p is beyond the end of this string.
1018 * Inserts a default-constructed character at position
1019 * referenced by @a p. If adding character causes the length
1020 * to exceed max_size(), length_error is thrown. If @a p is
1021 * beyond end of string, out_of_range is thrown. The value of
1022 * the string doesn't change if an error is thrown.
1025 insert(iterator __p)
1026 { return this->insert(__p, _CharT()); }
1027 #endif /* _GLIBCXX_DEPRECATED */
1030 * @brief Remove characters.
1031 * @param pos Index of first character to remove (default 0).
1032 * @param n Number of characters to remove (default remainder).
1033 * @return Reference to this string.
1034 * @throw std::out_of_range If @a pos is beyond the end of this
1037 * Removes @a n characters from this string starting at @a pos. The
1038 * length of the string is reduced by @a n. If there are < @a n
1039 * characters to remove, the remainder of the string is truncated. If
1040 * @a p is beyond end of string, out_of_range is thrown. The value of
1041 * the string doesn't change if an error is thrown.
1044 erase(size_type __pos = 0, size_type __n = npos)
1046 return this->replace(_M_check(__pos), _M_fold(__pos, __n),
1047 _M_data(), _M_data());
1051 * @brief Remove one character.
1052 * @param position Iterator referencing the character to remove.
1053 * @return iterator referencing same location after removal.
1054 * @throw std::out_of_range If @a position is beyond the end of this
1057 * Removes the character at @a position from this string. If @a
1058 * position is beyond end of string, out_of_range is thrown. The value
1059 * of the string doesn't change if an error is thrown.
1062 erase(iterator __position)
1064 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1065 && __position < _M_iend());
1066 const size_type __i = __position - _M_ibegin();
1067 this->replace(__position, __position + 1, _M_data(), _M_data());
1068 _M_rep()->_M_set_leaked();
1069 return _M_ibegin() + __i;
1073 * @brief Remove a range of characters.
1074 * @param first Iterator referencing the first character to remove.
1075 * @param last Iterator referencing the end of the range.
1076 * @return Iterator referencing location of first after removal.
1077 * @throw std::out_of_range If @a first is beyond the end of this
1080 * Removes the characters in the range [first,last) from this string.
1081 * If @a first is beyond end of string, out_of_range is thrown. The
1082 * value of the string doesn't change if an error is thrown.
1085 erase(iterator __first, iterator __last)
1087 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1088 && __last <= _M_iend());
1089 const size_type __i = __first - _M_ibegin();
1090 this->replace(__first, __last, _M_data(), _M_data());
1091 _M_rep()->_M_set_leaked();
1092 return _M_ibegin() + __i;
1096 * @brief Replace characters with value from another string.
1097 * @param pos Index of first character to replace.
1098 * @param n Number of characters to be replaced.
1099 * @param str String to insert.
1100 * @return Reference to this string.
1101 * @throw std::out_of_range If @a pos is beyond the end of this
1103 * @throw std::length_error If new length exceeds @c max_size().
1105 * Removes the characters in the range [pos,pos+n) from this string.
1106 * In place, the value of @a str is inserted. If @a pos is beyond end
1107 * of string, out_of_range is thrown. If the length of the result
1108 * exceeds max_size(), length_error is thrown. The value of the string
1109 * doesn't change if an error is thrown.
1112 replace(size_type __pos, size_type __n, const basic_string& __str)
1113 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1116 * @brief Replace characters with value from another string.
1117 * @param pos1 Index of first character to replace.
1118 * @param n1 Number of characters to be replaced.
1119 * @param str String to insert.
1120 * @param pos2 Index of first character of str to use.
1121 * @param n2 Number of characters from str to use.
1122 * @return Reference to this string.
1123 * @throw std::out_of_range If @a pos1 > size() or @a pos2 >
1125 * @throw std::length_error If new length exceeds @c max_size().
1127 * Removes the characters in the range [pos1,pos1 + n) from this
1128 * string. In place, the value of @a str is inserted. If @a pos is
1129 * beyond end of string, out_of_range is thrown. If the length of the
1130 * result exceeds max_size(), length_error is thrown. The value of the
1131 * string doesn't change if an error is thrown.
1134 replace(size_type __pos1, size_type __n1, const basic_string& __str,
1135 size_type __pos2, size_type __n2);
1138 * @brief Replace characters with value of a C substring.
1139 * @param pos Index of first character to replace.
1140 * @param n1 Number of characters to be replaced.
1141 * @param str C string to insert.
1142 * @param n2 Number of characters from str to use.
1143 * @return Reference to this string.
1144 * @throw std::out_of_range If @a pos1 > size().
1145 * @throw std::length_error If new length exceeds @c max_size().
1147 * Removes the characters in the range [pos,pos + n1) from this string.
1148 * In place, the first @a n2 characters of @a str are inserted, or all
1149 * of @a str if @a n2 is too large. If @a pos is beyond end of string,
1150 * out_of_range is thrown. If the length of result exceeds max_size(),
1151 * length_error is thrown. The value of the string doesn't change if
1152 * an error is thrown.
1155 replace(size_type __pos, size_type __n1, const _CharT* __s,
1159 * @brief Replace characters with value of a C string.
1160 * @param pos Index of first character to replace.
1161 * @param n1 Number of characters to be replaced.
1162 * @param str C string to insert.
1163 * @return Reference to this string.
1164 * @throw std::out_of_range If @a pos > size().
1165 * @throw std::length_error If new length exceeds @c max_size().
1167 * Removes the characters in the range [pos,pos + n1) from this string.
1168 * In place, the first @a n characters of @a str are inserted. If @a
1169 * pos is beyond end of string, out_of_range is thrown. If the length
1170 * of result exceeds max_size(), length_error is thrown. The value of
1171 * the string doesn't change if an error is thrown.
1174 replace(size_type __pos, size_type __n1, const _CharT* __s)
1176 __glibcxx_requires_string(__s);
1177 return this->replace(__pos, __n1, __s, traits_type::length(__s));
1181 * @brief Replace characters with multiple characters.
1182 * @param pos Index of first character to replace.
1183 * @param n1 Number of characters to be replaced.
1184 * @param n2 Number of characters to insert.
1185 * @param c Character to insert.
1186 * @return Reference to this string.
1187 * @throw std::out_of_range If @a pos > size().
1188 * @throw std::length_error If new length exceeds @c max_size().
1190 * Removes the characters in the range [pos,pos + n1) from this string.
1191 * In place, @a n2 copies of @a c are inserted. If @a pos is beyond
1192 * end of string, out_of_range is thrown. If the length of result
1193 * exceeds max_size(), length_error is thrown. The value of the string
1194 * doesn't change if an error is thrown.
1197 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1198 { return this->replace(_M_check(__pos), _M_fold(__pos, __n1), __n2, __c); }
1201 * @brief Replace range of characters with string.
1202 * @param i1 Iterator referencing start of range to replace.
1203 * @param i2 Iterator referencing end of range to replace.
1204 * @param str String value to insert.
1205 * @return Reference to this string.
1206 * @throw std::length_error If new length exceeds @c max_size().
1208 * Removes the characters in the range [i1,i2). In place, the value of
1209 * @a str is inserted. If the length of result exceeds max_size(),
1210 * length_error is thrown. The value of the string doesn't change if
1211 * an error is thrown.
1214 replace(iterator __i1, iterator __i2, const basic_string& __str)
1216 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1217 && __i2 <= _M_iend());
1218 return this->replace(__i1, __i2, __str._M_data(), __str.size());
1222 * @brief Replace range of characters with C substring.
1223 * @param i1 Iterator referencing start of range to replace.
1224 * @param i2 Iterator referencing end of range to replace.
1225 * @param s C string value to insert.
1226 * @param n Number of characters from s to insert.
1227 * @return Reference to this string.
1228 * @throw std::length_error If new length exceeds @c max_size().
1230 * Removes the characters in the range [i1,i2). In place, the first @a
1231 * n characters of @a s are inserted. If the length of result exceeds
1232 * max_size(), length_error is thrown. The value of the string doesn't
1233 * change if an error is thrown.
1236 replace(iterator __i1, iterator __i2,
1237 const _CharT* __s, size_type __n)
1238 { return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n); }
1241 * @brief Replace range of characters with C string.
1242 * @param i1 Iterator referencing start of range to replace.
1243 * @param i2 Iterator referencing end of range to replace.
1244 * @param s C string value to insert.
1245 * @return Reference to this string.
1246 * @throw std::length_error If new length exceeds @c max_size().
1248 * Removes the characters in the range [i1,i2). In place, the
1249 * characters of @a s are inserted. If the length of result exceeds
1250 * max_size(), length_error is thrown. The value of the string doesn't
1251 * change if an error is thrown.
1254 replace(iterator __i1, iterator __i2, const _CharT* __s)
1256 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1257 && __i2 <= _M_iend());
1258 __glibcxx_requires_string(__s);
1259 return this->replace(__i1, __i2, __s, traits_type::length(__s));
1263 * @brief Replace range of characters with multiple characters
1264 * @param i1 Iterator referencing start of range to replace.
1265 * @param i2 Iterator referencing end of range to replace.
1266 * @param n Number of characters to insert.
1267 * @param c Character to insert.
1268 * @return Reference to this string.
1269 * @throw std::length_error If new length exceeds @c max_size().
1271 * Removes the characters in the range [i1,i2). In place, @a n copies
1272 * of @a c are inserted. If the length of result exceeds max_size(),
1273 * length_error is thrown. The value of the string doesn't change if
1274 * an error is thrown.
1277 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1279 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1280 && __i2 <= _M_iend());
1281 return _M_replace_aux(__i1, __i2, __n, __c);
1285 * @brief Replace range of characters with range.
1286 * @param i1 Iterator referencing start of range to replace.
1287 * @param i2 Iterator referencing end of range to replace.
1288 * @param k1 Iterator referencing start of range to insert.
1289 * @param k2 Iterator referencing end of range to insert.
1290 * @return Reference to this string.
1291 * @throw std::length_error If new length exceeds @c max_size().
1293 * Removes the characters in the range [i1,i2). In place, characters
1294 * in the range [k1,k2) are inserted. If the length of result exceeds
1295 * max_size(), length_error is thrown. The value of the string doesn't
1296 * change if an error is thrown.
1298 template<class _InputIterator>
1300 replace(iterator __i1, iterator __i2,
1301 _InputIterator __k1, _InputIterator __k2)
1303 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1304 && __i2 <= _M_iend());
1305 __glibcxx_requires_valid_range(__k1, __k2);
1306 typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
1307 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1310 // Specializations for the common case of pointer and iterator:
1311 // useful to avoid the overhead of temporary buffering in _M_replace.
1313 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1315 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1316 && __i2 <= _M_iend());
1317 __glibcxx_requires_valid_range(__k1, __k2);
1318 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1323 replace(iterator __i1, iterator __i2,
1324 const _CharT* __k1, const _CharT* __k2)
1326 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1327 && __i2 <= _M_iend());
1328 __glibcxx_requires_valid_range(__k1, __k2);
1329 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1334 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1336 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1337 && __i2 <= _M_iend());
1338 __glibcxx_requires_valid_range(__k1, __k2);
1339 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1340 __k1.base(), __k2 - __k1);
1344 replace(iterator __i1, iterator __i2,
1345 const_iterator __k1, const_iterator __k2)
1347 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1348 && __i2 <= _M_iend());
1349 __glibcxx_requires_valid_range(__k1, __k2);
1350 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1351 __k1.base(), __k2 - __k1);
1355 template<class _Integer>
1357 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1358 _Integer __val, __true_type)
1359 { return _M_replace_aux(__i1, __i2, __n, __val); }
1361 template<class _InputIterator>
1363 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1364 _InputIterator __k2, __false_type)
1366 typedef typename iterator_traits<_InputIterator>::iterator_category
1368 return _M_replace(__i1, __i2, __k1, __k2, _Category());
1372 _M_replace_aux(iterator __i1, iterator __i2, size_type __n2, _CharT __c);
1374 template<class _InputIterator>
1376 _M_replace(iterator __i1, iterator __i2, _InputIterator __k1,
1377 _InputIterator __k2, input_iterator_tag);
1379 template<class _ForwardIterator>
1381 _M_replace_safe(iterator __i1, iterator __i2, _ForwardIterator __k1,
1382 _ForwardIterator __k2);
1384 // _S_construct_aux is used to implement the 21.3.1 para 15 which
1385 // requires special behaviour if _InIter is an integral type
1386 template<class _InIterator>
1388 _S_construct_aux(_InIterator __beg, _InIterator __end, const _Alloc& __a,
1391 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
1392 return _S_construct(__beg, __end, __a, _Tag());
1395 template<class _InIterator>
1397 _S_construct_aux(_InIterator __beg, _InIterator __end, const _Alloc& __a,
1400 return _S_construct(static_cast<size_type>(__beg),
1401 static_cast<value_type>(__end), __a);
1404 template<class _InIterator>
1406 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a)
1408 typedef typename _Is_integer<_InIterator>::_Integral _Integral;
1409 return _S_construct_aux(__beg, __end, __a, _Integral());
1412 // For Input Iterators, used in istreambuf_iterators, etc.
1413 template<class _InIterator>
1415 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
1416 input_iterator_tag);
1418 // For forward_iterators up to random_access_iterators, used for
1419 // string::iterator, _CharT*, etc.
1420 template<class _FwdIterator>
1422 _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a,
1423 forward_iterator_tag);
1426 _S_construct(size_type __req, _CharT __c, const _Alloc& __a);
1431 * @brief Copy substring into C string.
1432 * @param s C string to copy value into.
1433 * @param n Number of characters to copy.
1434 * @param pos Index of first character to copy.
1435 * @return Number of characters actually copied
1436 * @throw std::out_of_range If pos > size().
1438 * Copies up to @a n characters starting at @a pos into the C string @a
1439 * s. If @a pos is greater than size(), out_of_range is thrown.
1442 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1445 * @brief Swap contents with another string.
1446 * @param s String to swap with.
1448 * Exchanges the contents of this string with that of @a s in constant
1452 swap(basic_string& __s);
1454 // String operations:
1456 * @brief Return const pointer to null-terminated contents.
1458 * This is a handle to internal data. Do not modify or dire things may
1464 // MT: This assumes concurrent writes are OK.
1465 const size_type __n = this->size();
1466 traits_type::assign(_M_data()[__n], _Rep::_S_terminal);
1471 * @brief Return const pointer to contents.
1473 * This is a handle to internal data. It may not be null-terminated.
1474 * Do not modify or dire things may happen.
1477 data() const { return _M_data(); }
1480 * @brief Return copy of allocator used to construct this string.
1483 get_allocator() const { return _M_dataplus; }
1486 * @brief Find position of a C substring.
1487 * @param s C string to locate.
1488 * @param pos Index of character to search from.
1489 * @param n Number of characters from @a s to search for.
1490 * @return Index of start of first occurrence.
1492 * Starting from @a pos, searches forward for the first @a n characters
1493 * in @a s within this string. If found, returns the index where it
1494 * begins. If not found, returns npos.
1497 find(const _CharT* __s, size_type __pos, size_type __n) const;
1500 * @brief Find position of a string.
1501 * @param str String to locate.
1502 * @param pos Index of character to search from (default 0).
1503 * @return Index of start of first occurrence.
1505 * Starting from @a pos, searches forward for value of @a str within
1506 * this string. If found, returns the index where it begins. If not
1507 * found, returns npos.
1510 find(const basic_string& __str, size_type __pos = 0) const
1511 { return this->find(__str.data(), __pos, __str.size()); }
1514 * @brief Find position of a C string.
1515 * @param s C string to locate.
1516 * @param pos Index of character to search from (default 0).
1517 * @return Index of start of first occurrence.
1519 * Starting from @a pos, searches forward for the value of @a s within
1520 * this string. If found, returns the index where it begins. If not
1521 * found, returns npos.
1524 find(const _CharT* __s, size_type __pos = 0) const
1526 __glibcxx_requires_string(__s);
1527 return this->find(__s, __pos, traits_type::length(__s));
1531 * @brief Find position of a character.
1532 * @param c Character to locate.
1533 * @param pos Index of character to search from (default 0).
1534 * @return Index of first occurrence.
1536 * Starting from @a pos, searches forward for @a c within this string.
1537 * If found, returns the index where it was found. If not found,
1541 find(_CharT __c, size_type __pos = 0) const;
1544 * @brief Find last position of a string.
1545 * @param str String to locate.
1546 * @param pos Index of character to search back from (default end).
1547 * @return Index of start of last occurrence.
1549 * Starting from @a pos, searches backward for value of @a str within
1550 * this string. If found, returns the index where it begins. If not
1551 * found, returns npos.
1554 rfind(const basic_string& __str, size_type __pos = npos) const
1555 { return this->rfind(__str.data(), __pos, __str.size()); }
1558 * @brief Find last position of a C substring.
1559 * @param s C string to locate.
1560 * @param pos Index of character to search back from.
1561 * @param n Number of characters from s to search for.
1562 * @return Index of start of last occurrence.
1564 * Starting from @a pos, searches backward for the first @a n
1565 * characters in @a s within this string. If found, returns the index
1566 * where it begins. If not found, returns npos.
1569 rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1572 * @brief Find last position of a C string.
1573 * @param s C string to locate.
1574 * @param pos Index of character to start search at (default 0).
1575 * @return Index of start of last occurrence.
1577 * Starting from @a pos, searches backward for the value of @a s within
1578 * this string. If found, returns the index where it begins. If not
1579 * found, returns npos.
1582 rfind(const _CharT* __s, size_type __pos = npos) const
1584 __glibcxx_requires_string(__s);
1585 return this->rfind(__s, __pos, traits_type::length(__s));
1589 * @brief Find last position of a character.
1590 * @param c Character to locate.
1591 * @param pos Index of character to search back from (default 0).
1592 * @return Index of last occurrence.
1594 * Starting from @a pos, searches backward for @a c within this string.
1595 * If found, returns the index where it was found. If not found,
1599 rfind(_CharT __c, size_type __pos = npos) const;
1602 * @brief Find position of a character of string.
1603 * @param str String containing characters to locate.
1604 * @param pos Index of character to search from (default 0).
1605 * @return Index of first occurrence.
1607 * Starting from @a pos, searches forward for one of the characters of
1608 * @a str within this string. If found, returns the index where it was
1609 * found. If not found, returns npos.
1612 find_first_of(const basic_string& __str, size_type __pos = 0) const
1613 { return this->find_first_of(__str.data(), __pos, __str.size()); }
1616 * @brief Find position of a character of C substring.
1617 * @param s String containing characters to locate.
1618 * @param pos Index of character to search from (default 0).
1619 * @param n Number of characters from s to search for.
1620 * @return Index of first occurrence.
1622 * Starting from @a pos, searches forward for one of the first @a n
1623 * characters of @a s within this string. If found, returns the index
1624 * where it was found. If not found, returns npos.
1627 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1630 * @brief Find position of a character of C string.
1631 * @param s String containing characters to locate.
1632 * @param pos Index of character to search from (default 0).
1633 * @return Index of first occurrence.
1635 * Starting from @a pos, searches forward for one of the characters of
1636 * @a s within this string. If found, returns the index where it was
1637 * found. If not found, returns npos.
1640 find_first_of(const _CharT* __s, size_type __pos = 0) const
1642 __glibcxx_requires_string(__s);
1643 return this->find_first_of(__s, __pos, traits_type::length(__s));
1647 * @brief Find position of a character.
1648 * @param c Character to locate.
1649 * @param pos Index of character to search from (default 0).
1650 * @return Index of first occurrence.
1652 * Starting from @a pos, searches forward for the character @a c within
1653 * this string. If found, returns the index where it was found. If
1654 * not found, returns npos.
1656 * Note: equivalent to find(c, pos).
1659 find_first_of(_CharT __c, size_type __pos = 0) const
1660 { return this->find(__c, __pos); }
1663 * @brief Find last position of a character of string.
1664 * @param str String containing characters to locate.
1665 * @param pos Index of character to search back from (default end).
1666 * @return Index of last occurrence.
1668 * Starting from @a pos, searches backward for one of the characters of
1669 * @a str within this string. If found, returns the index where it was
1670 * found. If not found, returns npos.
1673 find_last_of(const basic_string& __str, size_type __pos = npos) const
1674 { return this->find_last_of(__str.data(), __pos, __str.size()); }
1677 * @brief Find last position of a character of C substring.
1678 * @param s C string containing characters to locate.
1679 * @param pos Index of character to search back from (default end).
1680 * @param n Number of characters from s to search for.
1681 * @return Index of last occurrence.
1683 * Starting from @a pos, searches backward for one of the first @a n
1684 * characters of @a s within this string. If found, returns the index
1685 * where it was found. If not found, returns npos.
1688 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1691 * @brief Find last position of a character of C string.
1692 * @param s C string containing characters to locate.
1693 * @param pos Index of character to search back from (default end).
1694 * @return Index of last occurrence.
1696 * Starting from @a pos, searches backward for one of the characters of
1697 * @a s within this string. If found, returns the index where it was
1698 * found. If not found, returns npos.
1701 find_last_of(const _CharT* __s, size_type __pos = npos) const
1703 __glibcxx_requires_string(__s);
1704 return this->find_last_of(__s, __pos, traits_type::length(__s));
1708 * @brief Find last position of a character.
1709 * @param c Character to locate.
1710 * @param pos Index of character to search back from (default 0).
1711 * @return Index of last occurrence.
1713 * Starting from @a pos, searches backward for @a c within this string.
1714 * If found, returns the index where it was found. If not found,
1717 * Note: equivalent to rfind(c, pos).
1720 find_last_of(_CharT __c, size_type __pos = npos) const
1721 { return this->rfind(__c, __pos); }
1724 * @brief Find position of a character not in string.
1725 * @param str String containing characters to avoid.
1726 * @param pos Index of character to search from (default 0).
1727 * @return Index of first occurrence.
1729 * Starting from @a pos, searches forward for a character not contained
1730 * in @a str within this string. If found, returns the index where it
1731 * was found. If not found, returns npos.
1734 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
1735 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1738 * @brief Find position of a character not in C substring.
1739 * @param s C string containing characters to avoid.
1740 * @param pos Index of character to search from (default 0).
1741 * @param n Number of characters from s to consider.
1742 * @return Index of first occurrence.
1744 * Starting from @a pos, searches forward for a character not contained
1745 * in the first @a n characters of @a s within this string. If found,
1746 * returns the index where it was found. If not found, returns npos.
1749 find_first_not_of(const _CharT* __s, size_type __pos,
1750 size_type __n) const;
1753 * @brief Find position of a character not in C string.
1754 * @param s C string containing characters to avoid.
1755 * @param pos Index of character to search from (default 0).
1756 * @return Index of first occurrence.
1758 * Starting from @a pos, searches forward for a character not contained
1759 * in @a s within this string. If found, returns the index where it
1760 * was found. If not found, returns npos.
1763 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1765 __glibcxx_requires_string(__s);
1766 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1770 * @brief Find position of a different character.
1771 * @param c Character to avoid.
1772 * @param pos Index of character to search from (default 0).
1773 * @return Index of first occurrence.
1775 * Starting from @a pos, searches forward for a character other than @a c
1776 * within this string. If found, returns the index where it was found.
1777 * If not found, returns npos.
1780 find_first_not_of(_CharT __c, size_type __pos = 0) const;
1783 * @brief Find last position of a character not in string.
1784 * @param str String containing characters to avoid.
1785 * @param pos Index of character to search from (default 0).
1786 * @return Index of first occurrence.
1788 * Starting from @a pos, searches backward for a character not
1789 * contained in @a str within this string. If found, returns the index
1790 * where it was found. If not found, returns npos.
1793 find_last_not_of(const basic_string& __str, size_type __pos = npos) const
1794 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1797 * @brief Find last position of a character not in C substring.
1798 * @param s C string containing characters to avoid.
1799 * @param pos Index of character to search from (default 0).
1800 * @param n Number of characters from s to consider.
1801 * @return Index of first occurrence.
1803 * Starting from @a pos, searches backward for a character not
1804 * contained in the first @a n characters of @a s within this string.
1805 * If found, returns the index where it was found. If not found,
1809 find_last_not_of(const _CharT* __s, size_type __pos,
1810 size_type __n) const;
1812 * @brief Find position of a character not in C string.
1813 * @param s C string containing characters to avoid.
1814 * @param pos Index of character to search from (default 0).
1815 * @return Index of first occurrence.
1817 * Starting from @a pos, searches backward for a character not
1818 * contained in @a s within this string. If found, returns the index
1819 * where it was found. If not found, returns npos.
1822 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1824 __glibcxx_requires_string(__s);
1825 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1829 * @brief Find last position of a different character.
1830 * @param c Character to avoid.
1831 * @param pos Index of character to search from (default 0).
1832 * @return Index of first occurrence.
1834 * Starting from @a pos, searches backward for a character other than
1835 * @a c within this string. If found, returns the index where it was
1836 * found. If not found, returns npos.
1839 find_last_not_of(_CharT __c, size_type __pos = npos) const;
1842 * @brief Get a substring.
1843 * @param pos Index of first character (default 0).
1844 * @param n Number of characters in substring (default remainder).
1845 * @return The new string.
1846 * @throw std::out_of_range If pos > size().
1848 * Construct and return a new string using the @a n characters starting
1849 * at @a pos. If the string is too short, use the remainder of the
1850 * characters. If @a pos is beyond the end of the string, out_of_range
1854 substr(size_type __pos = 0, size_type __n = npos) const
1856 if (__pos > this->size())
1857 __throw_out_of_range(__N("basic_string::substr"));
1858 return basic_string(*this, __pos, __n);
1862 * @brief Compare to a string.
1863 * @param str String to compare against.
1864 * @return Integer < 0, 0, or > 0.
1866 * Returns an integer < 0 if this string is ordered before @a str, 0 if
1867 * their values are equivalent, or > 0 if this string is ordered after
1868 * @a str. If the lengths of @a str and this string are different, the
1869 * shorter one is ordered first. If they are the same, returns the
1870 * result of traits::compare(data(),str.data(),size());
1873 compare(const basic_string& __str) const
1875 const size_type __size = this->size();
1876 const size_type __osize = __str.size();
1877 const size_type __len = std::min(__size, __osize);
1879 int __r = traits_type::compare(_M_data(), __str.data(), __len);
1881 __r = __size - __osize;
1886 * @brief Compare substring to a string.
1887 * @param pos Index of first character of substring.
1888 * @param n Number of characters in substring.
1889 * @param str String to compare against.
1890 * @return Integer < 0, 0, or > 0.
1892 * Form the substring of this string from the @a n characters starting
1893 * at @a pos. Returns an integer < 0 if the substring is ordered
1894 * before @a str, 0 if their values are equivalent, or > 0 if the
1895 * substring is ordered after @a str. If the lengths @a of str and the
1896 * substring are different, the shorter one is ordered first. If they
1897 * are the same, returns the result of
1898 * traits::compare(substring.data(),str.data(),size());
1901 compare(size_type __pos, size_type __n, const basic_string& __str) const;
1904 * @brief Compare substring to a substring.
1905 * @param pos1 Index of first character of substring.
1906 * @param n1 Number of characters in substring.
1907 * @param str String to compare against.
1908 * @param pos2 Index of first character of substring of str.
1909 * @param n2 Number of characters in substring of str.
1910 * @return Integer < 0, 0, or > 0.
1912 * Form the substring of this string from the @a n1 characters starting
1913 * at @a pos1. Form the substring of @a str from the @a n2 characters
1914 * starting at @a pos2. Returns an integer < 0 if this substring is
1915 * ordered before the substring of @a str, 0 if their values are
1916 * equivalent, or > 0 if this substring is ordered after the substring
1917 * of @a str. If the lengths of the substring of @a str and this
1918 * substring are different, the shorter one is ordered first. If they
1919 * are the same, returns the result of
1920 * traits::compare(substring.data(),str.substr(pos2,n2).data(),size());
1923 compare(size_type __pos1, size_type __n1, const basic_string& __str,
1924 size_type __pos2, size_type __n2) const;
1927 * @brief Compare to a C string.
1928 * @param s C string to compare against.
1929 * @return Integer < 0, 0, or > 0.
1931 * Returns an integer < 0 if this string is ordered before @a s, 0 if
1932 * their values are equivalent, or > 0 if this string is ordered after
1933 * @a s. If the lengths of @a s and this string are different, the
1934 * shorter one is ordered first. If they are the same, returns the
1935 * result of traits::compare(data(),s,size());
1938 compare(const _CharT* __s) const;
1940 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1941 // 5 String::compare specification questionable
1943 * @brief Compare substring to a C string.
1944 * @param pos Index of first character of substring.
1945 * @param n1 Number of characters in substring.
1946 * @param s C string to compare against.
1947 * @return Integer < 0, 0, or > 0.
1949 * Form the substring of this string from the @a n1 characters starting
1950 * at @a pos. Returns an integer < 0 if the substring is ordered
1951 * before @a s, 0 if their values are equivalent, or > 0 if the
1952 * substring is ordered after @a s. If the lengths of @a s and the
1953 * substring are different, the shorter one is ordered first. If they
1954 * are the same, returns the result of
1955 * traits::compare(substring.data(),s,size());
1958 compare(size_type __pos, size_type __n1, const _CharT* __s) const;
1961 * @brief Compare substring against a character array.
1962 * @param pos1 Index of first character of substring.
1963 * @param n1 Number of characters in substring.
1964 * @param s character array to compare against.
1965 * @param n2 Number of characters of s.
1966 * @return Integer < 0, 0, or > 0.
1968 * Form the substring of this string from the @a n1 characters starting
1969 * at @a pos1. Form a string from the first @a n2 characters of @a s.
1970 * Returns an integer < 0 if this substring is ordered before the string
1971 * from @a s, 0 if their values are equivalent, or > 0 if this substring
1972 * is ordered after the string from @a s. If the lengths of this substring
1973 * and @a n2 are different, the shorter one is ordered first. If they are
1974 * the same, returns the result of traits::compare(substring.data(),s,size());
1976 * NB: s must have at least n2 characters, '\0' has no special
1980 compare(size_type __pos, size_type __n1, const _CharT* __s,
1981 size_type __n2) const;
1985 template<typename _CharT, typename _Traits, typename _Alloc>
1986 inline basic_string<_CharT, _Traits, _Alloc>::
1988 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
1992 * @brief Concatenate two strings.
1993 * @param lhs First string.
1994 * @param rhs Last string.
1995 * @return New string with value of @a lhs followed by @a rhs.
1997 template<typename _CharT, typename _Traits, typename _Alloc>
1998 basic_string<_CharT, _Traits, _Alloc>
1999 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2000 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2002 basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
2003 __str.append(__rhs);
2008 * @brief Concatenate C string and string.
2009 * @param lhs First string.
2010 * @param rhs Last string.
2011 * @return New string with value of @a lhs followed by @a rhs.
2013 template<typename _CharT, typename _Traits, typename _Alloc>
2014 basic_string<_CharT,_Traits,_Alloc>
2015 operator+(const _CharT* __lhs,
2016 const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2019 * @brief Concatenate character and string.
2020 * @param lhs First string.
2021 * @param rhs Last string.
2022 * @return New string with @a lhs followed by @a rhs.
2024 template<typename _CharT, typename _Traits, typename _Alloc>
2025 basic_string<_CharT,_Traits,_Alloc>
2026 operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2029 * @brief Concatenate string and C string.
2030 * @param lhs First string.
2031 * @param rhs Last string.
2032 * @return New string with @a lhs followed by @a rhs.
2034 template<typename _CharT, typename _Traits, typename _Alloc>
2035 inline basic_string<_CharT, _Traits, _Alloc>
2036 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2037 const _CharT* __rhs)
2039 basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
2040 __str.append(__rhs);
2045 * @brief Concatenate string and character.
2046 * @param lhs First string.
2047 * @param rhs Last string.
2048 * @return New string with @a lhs followed by @a rhs.
2050 template<typename _CharT, typename _Traits, typename _Alloc>
2051 inline basic_string<_CharT, _Traits, _Alloc>
2052 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
2054 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
2055 typedef typename __string_type::size_type __size_type;
2056 __string_type __str(__lhs);
2057 __str.append(__size_type(1), __rhs);
2063 * @brief Test equivalence of two strings.
2064 * @param lhs First string.
2065 * @param rhs Second string.
2066 * @return True if @a lhs.compare(@a rhs) == 0. False otherwise.
2068 template<typename _CharT, typename _Traits, typename _Alloc>
2070 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2071 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2072 { return __lhs.compare(__rhs) == 0; }
2075 * @brief Test equivalence of C string and string.
2076 * @param lhs C string.
2077 * @param rhs String.
2078 * @return True if @a rhs.compare(@a lhs) == 0. False otherwise.
2080 template<typename _CharT, typename _Traits, typename _Alloc>
2082 operator==(const _CharT* __lhs,
2083 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2084 { return __rhs.compare(__lhs) == 0; }
2087 * @brief Test equivalence of string and C string.
2088 * @param lhs String.
2089 * @param rhs C string.
2090 * @return True if @a lhs.compare(@a rhs) == 0. False otherwise.
2092 template<typename _CharT, typename _Traits, typename _Alloc>
2094 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2095 const _CharT* __rhs)
2096 { return __lhs.compare(__rhs) == 0; }
2100 * @brief Test difference of two strings.
2101 * @param lhs First string.
2102 * @param rhs Second string.
2103 * @return True if @a lhs.compare(@a rhs) != 0. False otherwise.
2105 template<typename _CharT, typename _Traits, typename _Alloc>
2107 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2108 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2109 { return __rhs.compare(__lhs) != 0; }
2112 * @brief Test difference of C string and string.
2113 * @param lhs C string.
2114 * @param rhs String.
2115 * @return True if @a rhs.compare(@a lhs) != 0. False otherwise.
2117 template<typename _CharT, typename _Traits, typename _Alloc>
2119 operator!=(const _CharT* __lhs,
2120 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2121 { return __rhs.compare(__lhs) != 0; }
2124 * @brief Test difference of string and C string.
2125 * @param lhs String.
2126 * @param rhs C string.
2127 * @return True if @a lhs.compare(@a rhs) != 0. False otherwise.
2129 template<typename _CharT, typename _Traits, typename _Alloc>
2131 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2132 const _CharT* __rhs)
2133 { return __lhs.compare(__rhs) != 0; }
2137 * @brief Test if string precedes string.
2138 * @param lhs First string.
2139 * @param rhs Second string.
2140 * @return True if @a lhs precedes @a rhs. False otherwise.
2142 template<typename _CharT, typename _Traits, typename _Alloc>
2144 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2145 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2146 { return __lhs.compare(__rhs) < 0; }
2149 * @brief Test if string precedes C string.
2150 * @param lhs String.
2151 * @param rhs C string.
2152 * @return True if @a lhs precedes @a rhs. False otherwise.
2154 template<typename _CharT, typename _Traits, typename _Alloc>
2156 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2157 const _CharT* __rhs)
2158 { return __lhs.compare(__rhs) < 0; }
2161 * @brief Test if C string precedes string.
2162 * @param lhs C string.
2163 * @param rhs String.
2164 * @return True if @a lhs precedes @a rhs. False otherwise.
2166 template<typename _CharT, typename _Traits, typename _Alloc>
2168 operator<(const _CharT* __lhs,
2169 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2170 { return __rhs.compare(__lhs) > 0; }
2174 * @brief Test if string follows string.
2175 * @param lhs First string.
2176 * @param rhs Second string.
2177 * @return True if @a lhs follows @a rhs. False otherwise.
2179 template<typename _CharT, typename _Traits, typename _Alloc>
2181 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2182 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2183 { return __lhs.compare(__rhs) > 0; }
2186 * @brief Test if string follows C string.
2187 * @param lhs String.
2188 * @param rhs C string.
2189 * @return True if @a lhs follows @a rhs. False otherwise.
2191 template<typename _CharT, typename _Traits, typename _Alloc>
2193 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2194 const _CharT* __rhs)
2195 { return __lhs.compare(__rhs) > 0; }
2198 * @brief Test if C string follows string.
2199 * @param lhs C string.
2200 * @param rhs String.
2201 * @return True if @a lhs follows @a rhs. False otherwise.
2203 template<typename _CharT, typename _Traits, typename _Alloc>
2205 operator>(const _CharT* __lhs,
2206 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2207 { return __rhs.compare(__lhs) < 0; }
2211 * @brief Test if string doesn't follow string.
2212 * @param lhs First string.
2213 * @param rhs Second string.
2214 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2216 template<typename _CharT, typename _Traits, typename _Alloc>
2218 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2219 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2220 { return __lhs.compare(__rhs) <= 0; }
2223 * @brief Test if string doesn't follow C string.
2224 * @param lhs String.
2225 * @param rhs C string.
2226 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2228 template<typename _CharT, typename _Traits, typename _Alloc>
2230 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2231 const _CharT* __rhs)
2232 { return __lhs.compare(__rhs) <= 0; }
2235 * @brief Test if C string doesn't follow string.
2236 * @param lhs C string.
2237 * @param rhs String.
2238 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2240 template<typename _CharT, typename _Traits, typename _Alloc>
2242 operator<=(const _CharT* __lhs,
2243 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2244 { return __rhs.compare(__lhs) >= 0; }
2248 * @brief Test if string doesn't precede string.
2249 * @param lhs First string.
2250 * @param rhs Second string.
2251 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2253 template<typename _CharT, typename _Traits, typename _Alloc>
2255 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2256 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2257 { return __lhs.compare(__rhs) >= 0; }
2260 * @brief Test if string doesn't precede C string.
2261 * @param lhs String.
2262 * @param rhs C string.
2263 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2265 template<typename _CharT, typename _Traits, typename _Alloc>
2267 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2268 const _CharT* __rhs)
2269 { return __lhs.compare(__rhs) >= 0; }
2272 * @brief Test if C string doesn't precede string.
2273 * @param lhs C string.
2274 * @param rhs String.
2275 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2277 template<typename _CharT, typename _Traits, typename _Alloc>
2279 operator>=(const _CharT* __lhs,
2280 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2281 { return __rhs.compare(__lhs) <= 0; }
2284 * @brief Swap contents of two strings.
2285 * @param lhs First string.
2286 * @param rhs Second string.
2288 * Exchanges the contents of @a lhs and @a rhs in constant time.
2290 template<typename _CharT, typename _Traits, typename _Alloc>
2292 swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
2293 basic_string<_CharT, _Traits, _Alloc>& __rhs)
2294 { __lhs.swap(__rhs); }
2297 * @brief Read stream into a string.
2298 * @param is Input stream.
2299 * @param str Buffer to store into.
2300 * @return Reference to the input stream.
2302 * Stores characters from @a is into @a str until whitespace is found, the
2303 * end of the stream is encountered, or str.max_size() is reached. If
2304 * is.width() is non-zero, that is the limit on the number of characters
2305 * stored into @a str. Any previous contents of @a str are erased.
2307 template<typename _CharT, typename _Traits, typename _Alloc>
2308 basic_istream<_CharT, _Traits>&
2309 operator>>(basic_istream<_CharT, _Traits>& __is,
2310 basic_string<_CharT, _Traits, _Alloc>& __str);
2313 * @brief Write string to a stream.
2314 * @param os Output stream.
2315 * @param str String to write out.
2316 * @return Reference to the output stream.
2318 * Output characters of @a str into os following the same rules as for
2319 * writing a C string.
2321 template<typename _CharT, typename _Traits, typename _Alloc>
2322 basic_ostream<_CharT, _Traits>&
2323 operator<<(basic_ostream<_CharT, _Traits>& __os,
2324 const basic_string<_CharT, _Traits, _Alloc>& __str);
2327 * @brief Read a line from stream into a string.
2328 * @param is Input stream.
2329 * @param str Buffer to store into.
2330 * @param delim Character marking end of line.
2331 * @return Reference to the input stream.
2333 * Stores characters from @a is into @a str until @a delim is found, the
2334 * end of the stream is encountered, or str.max_size() is reached. If
2335 * is.width() is non-zero, that is the limit on the number of characters
2336 * stored into @a str. Any previous contents of @a str are erased. If @a
2337 * delim was encountered, it is extracted but not stored into @a str.
2339 template<typename _CharT, typename _Traits, typename _Alloc>
2340 basic_istream<_CharT,_Traits>&
2341 getline(basic_istream<_CharT, _Traits>& __is,
2342 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
2345 * @brief Read a line from stream into a string.
2346 * @param is Input stream.
2347 * @param str Buffer to store into.
2348 * @return Reference to the input stream.
2350 * Stores characters from is into @a str until '\n' is found, the end of
2351 * the stream is encountered, or str.max_size() is reached. If is.width()
2352 * is non-zero, that is the limit on the number of characters stored into
2353 * @a str. Any previous contents of @a str are erased. If end of line was
2354 * encountered, it is extracted but not stored into @a str.
2356 template<typename _CharT, typename _Traits, typename _Alloc>
2357 inline basic_istream<_CharT,_Traits>&
2358 getline(basic_istream<_CharT, _Traits>& __is,
2359 basic_string<_CharT, _Traits, _Alloc>& __str);
2362 #endif /* _BASIC_STRING_H */