1 // Components for manipulating sequences of characters -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
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_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>
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: due to 21.3.4
133 // must be kept null-terminated.
134 // 2. _M_capacity >= _M_length
135 // Allocated memory is always (_M_capacity + 1) * sizeof(_CharT).
136 // 3. _M_refcount has three states:
137 // -1: leaked, one reference, no ref-copies allowed, non-const.
138 // 0: one reference, non-const.
139 // n>0: n + 1 references, operations require a lock, const.
140 // 4. All fields==0 is an empty string, given the extra storage
141 // beyond-the-end for a null terminator; thus, the shared
142 // empty string representation needs no constructor.
147 size_type _M_capacity;
148 _Atomic_word _M_refcount;
151 struct _Rep : _Rep_base
154 typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc;
156 // (Public) Data members:
158 // The maximum number of individual char_type elements of an
159 // individual string is determined by _S_max_size. This is the
160 // value that will be returned by max_size(). (Whereas npos
161 // is the maximum number of bytes the allocator can allocate.)
162 // If one was to divvy up the theoretical largest size string,
163 // with a terminating character and m _CharT elements, it'd
165 // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
167 // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
168 // In addition, this implementation quarters this amount.
169 static const size_type _S_max_size;
170 static const _CharT _S_terminal;
172 // The following storage is init'd to 0 by the linker, resulting
173 // (carefully) in an empty string with one reference.
174 static size_type _S_empty_rep_storage[];
178 { return *reinterpret_cast<_Rep*>(&_S_empty_rep_storage); }
182 { return this->_M_refcount < 0; }
186 { return this->_M_refcount > 0; }
190 { this->_M_refcount = -1; }
194 { this->_M_refcount = 0; }
197 _M_set_length_and_sharable(size_type __n)
199 this->_M_set_sharable(); // One reference.
200 this->_M_length = __n;
201 this->_M_refdata()[__n] = _S_terminal; // grrr. (per 21.3.4)
202 // You cannot leave those LWG people alone for a second.
207 { return reinterpret_cast<_CharT*>(this + 1); }
210 _M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2)
212 return (!_M_is_leaked() && __alloc1 == __alloc2)
213 ? _M_refcopy() : _M_clone(__alloc1);
218 _S_create(size_type, size_type, const _Alloc&);
221 _M_dispose(const _Alloc& __a)
223 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
224 if (__builtin_expect(this != &_S_empty_rep(), false))
226 if (__gnu_cxx::__exchange_and_add(&this->_M_refcount, -1) <= 0)
231 _M_destroy(const _Alloc&) throw();
236 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
237 if (__builtin_expect(this != &_S_empty_rep(), false))
239 __gnu_cxx::__atomic_add(&this->_M_refcount, 1);
244 _M_clone(const _Alloc&, size_type __res = 0);
247 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
248 struct _Alloc_hider : _Alloc
250 _Alloc_hider(_CharT* __dat, const _Alloc& __a)
251 : _Alloc(__a), _M_p(__dat) { }
253 _CharT* _M_p; // The actual data.
257 // Data Members (public):
258 // NB: This is an unsigned type, and thus represents the maximum
259 // size that the allocator can hold.
261 /// Value returned by various member functions when they fail.
262 static const size_type npos = static_cast<size_type>(-1);
265 // Data Members (private):
266 mutable _Alloc_hider _M_dataplus;
270 { return _M_dataplus._M_p; }
274 { return (_M_dataplus._M_p = __p); }
278 { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }
280 // For the internal use we have functions similar to `begin'/`end'
281 // but they do not call _M_leak.
284 { return iterator(_M_data()); }
288 { return iterator(_M_data() + this->size()); }
291 _M_leak() // for use in begin() & non-const op[]
293 if (!_M_rep()->_M_is_leaked())
298 _M_check(size_type __pos, const char* __s) const
300 if (__pos > this->size())
301 __throw_out_of_range(__N(__s));
306 _M_check_length(size_type __n1, size_type __n2, const char* __s) const
308 if (this->max_size() - (this->size() - __n1) < __n2)
309 __throw_length_error(__N(__s));
312 // NB: _M_limit doesn't check for a bad __pos value.
314 _M_limit(size_type __pos, size_type __off) const
316 const bool __testoff = __off < this->size() - __pos;
317 return __testoff ? __off : this->size() - __pos;
320 // True if _Rep and source do not overlap.
322 _M_disjunct(const _CharT* __s) const
324 return (less<const _CharT*>()(__s, _M_data())
325 || less<const _CharT*>()(_M_data() + this->size(), __s));
328 // When __n = 1 way faster than the general multichar
329 // traits_type::copy/move/assign.
331 _M_copy(_CharT* __d, const _CharT* __s, size_type __n)
334 traits_type::assign(*__d, *__s);
336 traits_type::copy(__d, __s, __n);
340 _M_move(_CharT* __d, const _CharT* __s, size_type __n)
343 traits_type::assign(*__d, *__s);
345 traits_type::move(__d, __s, __n);
349 _M_assign(_CharT* __d, size_type __n, _CharT __c)
352 traits_type::assign(*__d, __c);
354 traits_type::assign(__d, __n, __c);
357 // _S_copy_chars is a separate template to permit specialization
358 // to optimize for the common case of pointers as iterators.
359 template<class _Iterator>
361 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
363 for (; __k1 != __k2; ++__k1, ++__p)
364 traits_type::assign(*__p, *__k1); // These types are off.
368 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2)
369 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
372 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
373 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
376 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2)
377 { _M_copy(__p, __k1, __k2 - __k1); }
380 _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
381 { _M_copy(__p, __k1, __k2 - __k1); }
384 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
391 { return _Rep::_S_empty_rep(); }
394 // Construct/copy/destroy:
395 // NB: We overload ctors in some cases instead of using default
396 // arguments, per 17.4.4.4 para. 2 item 2.
399 * @brief Default constructor creates an empty string.
405 * @brief Construct an empty string using allocator a.
408 basic_string(const _Alloc& __a);
410 // NB: per LWG issue 42, semantics different from IS:
412 * @brief Construct string with copy of value of @a str.
413 * @param str Source string.
415 basic_string(const basic_string& __str);
417 * @brief Construct string as copy of a substring.
418 * @param str Source string.
419 * @param pos Index of first character to copy from.
420 * @param n Number of characters to copy (default remainder).
422 basic_string(const basic_string& __str, size_type __pos,
423 size_type __n = npos);
425 * @brief Construct string as copy of a substring.
426 * @param str Source string.
427 * @param pos Index of first character to copy from.
428 * @param n Number of characters to copy.
429 * @param a Allocator to use.
431 basic_string(const basic_string& __str, size_type __pos,
432 size_type __n, const _Alloc& __a);
435 * @brief Construct string initialized by a character array.
436 * @param s Source character array.
437 * @param n Number of characters to copy.
438 * @param a Allocator to use (default is default allocator).
440 * NB: s must have at least n characters, '\0' has no special
443 basic_string(const _CharT* __s, size_type __n,
444 const _Alloc& __a = _Alloc());
446 * @brief Construct string as copy of a C string.
447 * @param s Source C string.
448 * @param a Allocator to use (default is default allocator).
450 basic_string(const _CharT* __s, const _Alloc& __a = _Alloc());
452 * @brief Construct string as multiple characters.
453 * @param n Number of characters.
454 * @param c Character to use.
455 * @param a Allocator to use (default is default allocator).
457 basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
460 * @brief Construct string as copy of a range.
461 * @param beg Start of range.
462 * @param end End of range.
463 * @param a Allocator to use (default is default allocator).
465 template<class _InputIterator>
466 basic_string(_InputIterator __beg, _InputIterator __end,
467 const _Alloc& __a = _Alloc());
470 * @brief Destroy the string instance.
473 { _M_rep()->_M_dispose(this->get_allocator()); }
476 * @brief Assign the value of @a str to this string.
477 * @param str Source string.
480 operator=(const basic_string& __str)
481 { return this->assign(__str); }
484 * @brief Copy contents of @a s into this string.
485 * @param s Source null-terminated string.
488 operator=(const _CharT* __s)
489 { return this->assign(__s); }
492 * @brief Set value to string of length 1.
493 * @param c Source character.
495 * Assigning to a character makes this string length 1 and
496 * (*this)[0] == @a c.
499 operator=(_CharT __c)
501 this->assign(1, __c);
507 * Returns a read/write iterator that points to the first character in
508 * the %string. Unshares the string.
514 return iterator(_M_data());
518 * Returns a read-only (constant) iterator that points to the first
519 * character in the %string.
523 { return const_iterator(_M_data()); }
526 * Returns a read/write iterator that points one past the last
527 * character in the %string. Unshares the string.
533 return iterator(_M_data() + this->size());
537 * Returns a read-only (constant) iterator that points one past the
538 * last character in the %string.
542 { return const_iterator(_M_data() + this->size()); }
545 * Returns a read/write reverse iterator that points to the last
546 * character in the %string. Iteration is done in reverse element
547 * order. Unshares the string.
551 { return reverse_iterator(this->end()); }
554 * Returns a read-only (constant) reverse iterator that points
555 * to the last character in the %string. Iteration is done in
556 * reverse element order.
558 const_reverse_iterator
560 { return const_reverse_iterator(this->end()); }
563 * Returns a read/write reverse iterator that points to one before the
564 * first character in the %string. Iteration is done in reverse
565 * element order. Unshares the string.
569 { return reverse_iterator(this->begin()); }
572 * Returns a read-only (constant) reverse iterator that points
573 * to one before the first character in the %string. Iteration
574 * is done in reverse element order.
576 const_reverse_iterator
578 { return const_reverse_iterator(this->begin()); }
582 /// Returns the number of characters in the string, not including any
583 /// null-termination.
586 { return _M_rep()->_M_length; }
588 /// Returns the number of characters in the string, not including any
589 /// null-termination.
592 { return _M_rep()->_M_length; }
594 /// Returns the size() of the largest possible %string.
597 { return _Rep::_S_max_size; }
600 * @brief Resizes the %string to the specified number of characters.
601 * @param n Number of characters the %string should contain.
602 * @param c Character to fill any new elements.
604 * This function will %resize the %string to the specified
605 * number of characters. If the number is smaller than the
606 * %string's current size the %string is truncated, otherwise
607 * the %string is extended and new elements are set to @a c.
610 resize(size_type __n, _CharT __c);
613 * @brief Resizes the %string to the specified number of characters.
614 * @param n Number of characters the %string should contain.
616 * This function will resize the %string to the specified length. If
617 * the new size is smaller than the %string's current size the %string
618 * is truncated, otherwise the %string is extended and new characters
619 * are default-constructed. For basic types such as char, this means
623 resize(size_type __n)
624 { this->resize(__n, _CharT()); }
627 * Returns the total number of characters that the %string can hold
628 * before needing to allocate more memory.
632 { return _M_rep()->_M_capacity; }
635 * @brief Attempt to preallocate enough memory for specified number of
637 * @param n Number of characters required.
638 * @throw std::length_error If @a n exceeds @c max_size().
640 * This function attempts to reserve enough memory for the
641 * %string to hold the specified number of characters. If the
642 * number requested is more than max_size(), length_error is
645 * The advantage of this function is that if optimal code is a
646 * necessity and the user can determine the string length that will be
647 * required, the user can reserve the memory in %advance, and thus
648 * prevent a possible reallocation of memory and copying of %string
652 reserve(size_type __res_arg = 0);
655 * Erases the string, making it empty.
659 { _M_mutate(0, this->size(), 0); }
662 * Returns true if the %string is empty. Equivalent to *this == "".
666 { return this->size() == 0; }
670 * @brief Subscript access to the data contained in the %string.
671 * @param n The index of the character to access.
672 * @return Read-only (constant) reference to the character.
674 * This operator allows for easy, array-style, data access.
675 * Note that data access with this operator is unchecked and
676 * out_of_range lookups are not defined. (For checked lookups
680 operator[] (size_type __pos) const
682 _GLIBCXX_DEBUG_ASSERT(__pos <= size());
683 return _M_data()[__pos];
687 * @brief Subscript access to the data contained in the %string.
688 * @param n The index of the character to access.
689 * @return Read/write reference to the character.
691 * This operator allows for easy, array-style, data access.
692 * Note that data access with this operator is unchecked and
693 * out_of_range lookups are not defined. (For checked lookups
694 * see at().) Unshares the string.
697 operator[](size_type __pos)
699 _GLIBCXX_DEBUG_ASSERT(__pos < size());
701 return _M_data()[__pos];
705 * @brief Provides access to the data contained in the %string.
706 * @param n The index of the character to access.
707 * @return Read-only (const) reference to the character.
708 * @throw std::out_of_range If @a n is an invalid index.
710 * This function provides for safer data access. The parameter is
711 * first checked that it is in the range of the string. The function
712 * throws out_of_range if the check fails.
715 at(size_type __n) const
717 if (__n >= this->size())
718 __throw_out_of_range(__N("basic_string::at"));
719 return _M_data()[__n];
723 * @brief Provides access to the data contained in the %string.
724 * @param n The index of the character to access.
725 * @return Read/write reference to the character.
726 * @throw std::out_of_range If @a n is an invalid index.
728 * This function provides for safer data access. The parameter is
729 * first checked that it is in the range of the string. The function
730 * throws out_of_range if the check fails. Success results in
731 * unsharing the string.
737 __throw_out_of_range(__N("basic_string::at"));
739 return _M_data()[__n];
744 * @brief Append a string to this string.
745 * @param str The string to append.
746 * @return Reference to this string.
749 operator+=(const basic_string& __str)
750 { return this->append(__str); }
753 * @brief Append a C string.
754 * @param s The C string to append.
755 * @return Reference to this string.
758 operator+=(const _CharT* __s)
759 { return this->append(__s); }
762 * @brief Append a character.
763 * @param s The character to append.
764 * @return Reference to this string.
767 operator+=(_CharT __c)
769 this->push_back(__c);
774 * @brief Append a string to this string.
775 * @param str The string to append.
776 * @return Reference to this string.
779 append(const basic_string& __str);
782 * @brief Append a substring.
783 * @param str The string to append.
784 * @param pos Index of the first character of str to append.
785 * @param n The number of characters to append.
786 * @return Reference to this string.
787 * @throw std::out_of_range if @a pos is not a valid index.
789 * This function appends @a n characters from @a str starting at @a pos
790 * to this string. If @a n is is larger than the number of available
791 * characters in @a str, the remainder of @a str is appended.
794 append(const basic_string& __str, size_type __pos, size_type __n);
797 * @brief Append a C substring.
798 * @param s The C string to append.
799 * @param n The number of characters to append.
800 * @return Reference to this string.
803 append(const _CharT* __s, size_type __n);
806 * @brief Append a C string.
807 * @param s The C string to append.
808 * @return Reference to this string.
811 append(const _CharT* __s)
813 __glibcxx_requires_string(__s);
814 return this->append(__s, traits_type::length(__s));
818 * @brief Append multiple characters.
819 * @param n The number of characters to append.
820 * @param c The character to use.
821 * @return Reference to this string.
823 * Appends n copies of c to this string.
826 append(size_type __n, _CharT __c);
829 * @brief Append a range of characters.
830 * @param first Iterator referencing the first character to append.
831 * @param last Iterator marking the end of the range.
832 * @return Reference to this string.
834 * Appends characters in the range [first,last) to this string.
836 template<class _InputIterator>
838 append(_InputIterator __first, _InputIterator __last)
839 { return this->replace(_M_iend(), _M_iend(), __first, __last); }
842 * @brief Append a single character.
843 * @param c Character to append.
846 push_back(_CharT __c)
848 const size_type __len = 1 + this->size();
849 if (__len > this->capacity() || _M_rep()->_M_is_shared())
850 this->reserve(__len);
851 traits_type::assign(_M_data()[this->size()], __c);
852 _M_rep()->_M_set_length_and_sharable(__len);
856 * @brief Set value to contents of another string.
857 * @param str Source string to use.
858 * @return Reference to this string.
861 assign(const basic_string& __str)
863 if (_M_rep() != __str._M_rep())
866 const allocator_type __a = this->get_allocator();
867 _CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.get_allocator());
868 _M_rep()->_M_dispose(__a);
875 * @brief Set value to a substring of a string.
876 * @param str The string to use.
877 * @param pos Index of the first character of str.
878 * @param n Number of characters to use.
879 * @return Reference to this string.
880 * @throw std::out_of_range if @a pos is not a valid index.
882 * This function sets this string to the substring of @a str consisting
883 * of @a n characters at @a pos. If @a n is is larger than the number
884 * of available characters in @a str, the remainder of @a str is used.
887 assign(const basic_string& __str, size_type __pos, size_type __n)
888 { return this->assign(__str._M_data()
889 + __str._M_check(__pos, "basic_string::assign"),
890 __str._M_limit(__pos, __n)); }
893 * @brief Set value to a C substring.
894 * @param s The C string to use.
895 * @param n Number of characters to use.
896 * @return Reference to this string.
898 * This function sets the value of this string to the first @a n
899 * characters of @a s. If @a n is is larger than the number of
900 * available characters in @a s, the remainder of @a s is used.
903 assign(const _CharT* __s, size_type __n);
906 * @brief Set value to contents of a C string.
907 * @param s The C string to use.
908 * @return Reference to this string.
910 * This function sets the value of this string to the value of @a s.
911 * The data is copied, so there is no dependence on @a s once the
915 assign(const _CharT* __s)
917 __glibcxx_requires_string(__s);
918 return this->assign(__s, traits_type::length(__s));
922 * @brief Set value to multiple characters.
923 * @param n Length of the resulting string.
924 * @param c The character to use.
925 * @return Reference to this string.
927 * This function sets the value of this string to @a n copies of
931 assign(size_type __n, _CharT __c)
932 { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
935 * @brief Set value to a range of characters.
936 * @param first Iterator referencing the first character to append.
937 * @param last Iterator marking the end of the range.
938 * @return Reference to this string.
940 * Sets value of string to characters in the range [first,last).
942 template<class _InputIterator>
944 assign(_InputIterator __first, _InputIterator __last)
945 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
948 * @brief Insert multiple characters.
949 * @param p Iterator referencing location in string to insert at.
950 * @param n Number of characters to insert
951 * @param c The character to insert.
952 * @throw std::length_error If new length exceeds @c max_size().
954 * Inserts @a n copies of character @a c starting at the position
955 * referenced by iterator @a p. If adding characters causes the length
956 * to exceed max_size(), length_error is thrown. The value of the
957 * string doesn't change if an error is thrown.
960 insert(iterator __p, size_type __n, _CharT __c)
961 { this->replace(__p, __p, __n, __c); }
964 * @brief Insert a range of characters.
965 * @param p Iterator referencing location in string to insert at.
966 * @param beg Start of range.
967 * @param end End of range.
968 * @throw std::length_error If new length exceeds @c max_size().
970 * Inserts characters in range [beg,end). If adding characters causes
971 * the length to exceed max_size(), length_error is thrown. The value
972 * of the string doesn't change if an error is thrown.
974 template<class _InputIterator>
976 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
977 { this->replace(__p, __p, __beg, __end); }
980 * @brief Insert value of a string.
981 * @param pos1 Iterator referencing location in string to insert at.
982 * @param str The string to insert.
983 * @return Reference to this string.
984 * @throw std::length_error If new length exceeds @c max_size().
986 * Inserts value of @a str starting at @a pos1. If adding characters
987 * causes the length to exceed max_size(), length_error is thrown. The
988 * value of the string doesn't change if an error is thrown.
991 insert(size_type __pos1, const basic_string& __str)
992 { return this->insert(__pos1, __str, size_type(0), __str.size()); }
995 * @brief Insert a substring.
996 * @param pos1 Iterator referencing location in string to insert at.
997 * @param str The string to insert.
998 * @param pos2 Start of characters in str to insert.
999 * @param n Number of characters to insert.
1000 * @return Reference to this string.
1001 * @throw std::length_error If new length exceeds @c max_size().
1002 * @throw std::out_of_range If @a pos1 > size() or
1003 * @a pos2 > @a str.size().
1005 * Starting at @a pos1, insert @a n character of @a str beginning with
1006 * @a pos2. If adding characters causes the length to exceed
1007 * max_size(), length_error is thrown. If @a pos1 is beyond the end of
1008 * this string or @a pos2 is beyond the end of @a str, out_of_range is
1009 * thrown. The value of the string doesn't change if an error is
1013 insert(size_type __pos1, const basic_string& __str,
1014 size_type __pos2, size_type __n)
1015 { return this->insert(__pos1, __str._M_data()
1016 + __str._M_check(__pos2, "basic_string::insert"),
1017 __str._M_limit(__pos2, __n)); }
1020 * @brief Insert a C substring.
1021 * @param pos Iterator referencing location in string to insert at.
1022 * @param s The C string to insert.
1023 * @param n The number of characters to insert.
1024 * @return Reference to this string.
1025 * @throw std::length_error If new length exceeds @c max_size().
1026 * @throw std::out_of_range If @a pos is beyond the end of this
1029 * Inserts the first @a n characters of @a s starting at @a pos. If
1030 * adding characters causes the length to exceed max_size(),
1031 * length_error is thrown. If @a pos is beyond end(), out_of_range is
1032 * thrown. The value of the string doesn't change if an error is
1036 insert(size_type __pos, const _CharT* __s, size_type __n);
1039 * @brief Insert a C string.
1040 * @param pos Iterator referencing location in string to insert at.
1041 * @param s The C string to insert.
1042 * @return Reference to this string.
1043 * @throw std::length_error If new length exceeds @c max_size().
1044 * @throw std::out_of_range If @a pos is beyond the end of this
1047 * Inserts the first @a n characters of @a s starting at @a pos. If
1048 * adding characters causes the length to exceed max_size(),
1049 * length_error is thrown. If @a pos is beyond end(), out_of_range is
1050 * thrown. The value of the string doesn't change if an error is
1054 insert(size_type __pos, const _CharT* __s)
1056 __glibcxx_requires_string(__s);
1057 return this->insert(__pos, __s, traits_type::length(__s));
1061 * @brief Insert multiple characters.
1062 * @param pos Index in string to insert at.
1063 * @param n Number of characters to insert
1064 * @param c The character to insert.
1065 * @return Reference to this string.
1066 * @throw std::length_error If new length exceeds @c max_size().
1067 * @throw std::out_of_range If @a pos is beyond the end of this
1070 * Inserts @a n copies of character @a c starting at index @a pos. If
1071 * adding characters causes the length to exceed max_size(),
1072 * length_error is thrown. If @a pos > length(), out_of_range is
1073 * thrown. The value of the string doesn't change if an error is
1077 insert(size_type __pos, size_type __n, _CharT __c)
1078 { return _M_replace_aux(_M_check(__pos, "basic_string::insert"),
1079 size_type(0), __n, __c); }
1082 * @brief Insert one character.
1083 * @param p Iterator referencing position in string to insert at.
1084 * @param c The character to insert.
1085 * @return Iterator referencing newly inserted char.
1086 * @throw std::length_error If new length exceeds @c max_size().
1088 * Inserts character @a c at position referenced by @a p. If adding
1089 * character causes the length to exceed max_size(), length_error is
1090 * thrown. If @a p is beyond end of string, out_of_range is thrown.
1091 * The value of the string doesn't change if an error is thrown.
1094 insert(iterator __p, _CharT __c)
1096 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1097 const size_type __pos = __p - _M_ibegin();
1098 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1099 _M_rep()->_M_set_leaked();
1100 return this->_M_ibegin() + __pos;
1104 * @brief Remove characters.
1105 * @param pos Index of first character to remove (default 0).
1106 * @param n Number of characters to remove (default remainder).
1107 * @return Reference to this string.
1108 * @throw std::out_of_range If @a pos is beyond the end of this
1111 * Removes @a n characters from this string starting at @a pos. The
1112 * length of the string is reduced by @a n. If there are < @a n
1113 * characters to remove, the remainder of the string is truncated. If
1114 * @a p is beyond end of string, out_of_range is thrown. The value of
1115 * the string doesn't change if an error is thrown.
1118 erase(size_type __pos = 0, size_type __n = npos)
1120 _M_mutate(_M_check(__pos, "basic_string::erase"),
1121 _M_limit(__pos, __n), size_type(0));
1126 * @brief Remove one character.
1127 * @param position Iterator referencing the character to remove.
1128 * @return iterator referencing same location after removal.
1130 * Removes the character at @a position from this string. The value
1131 * of the string doesn't change if an error is thrown.
1134 erase(iterator __position)
1136 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1137 && __position < _M_iend());
1138 const size_type __pos = __position - _M_ibegin();
1139 _M_mutate(__pos, size_type(1), size_type(0));
1140 _M_rep()->_M_set_leaked();
1141 return _M_ibegin() + __pos;
1145 * @brief Remove a range of characters.
1146 * @param first Iterator referencing the first character to remove.
1147 * @param last Iterator referencing the end of the range.
1148 * @return Iterator referencing location of first after removal.
1150 * Removes the characters in the range [first,last) from this string.
1151 * The value of the string doesn't change if an error is thrown.
1154 erase(iterator __first, iterator __last)
1156 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1157 && __last <= _M_iend());
1158 const size_type __pos = __first - _M_ibegin();
1159 _M_mutate(__pos, __last - __first, size_type(0));
1160 _M_rep()->_M_set_leaked();
1161 return _M_ibegin() + __pos;
1165 * @brief Replace characters with value from another string.
1166 * @param pos Index of first character to replace.
1167 * @param n Number of characters to be replaced.
1168 * @param str String to insert.
1169 * @return Reference to this string.
1170 * @throw std::out_of_range If @a pos is beyond the end of this
1172 * @throw std::length_error If new length exceeds @c max_size().
1174 * Removes the characters in the range [pos,pos+n) from this string.
1175 * In place, the value of @a str is inserted. If @a pos is beyond end
1176 * of string, out_of_range is thrown. If the length of the result
1177 * exceeds max_size(), length_error is thrown. The value of the string
1178 * doesn't change if an error is thrown.
1181 replace(size_type __pos, size_type __n, const basic_string& __str)
1182 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1185 * @brief Replace characters with value from another string.
1186 * @param pos1 Index of first character to replace.
1187 * @param n1 Number of characters to be replaced.
1188 * @param str String to insert.
1189 * @param pos2 Index of first character of str to use.
1190 * @param n2 Number of characters from str to use.
1191 * @return Reference to this string.
1192 * @throw std::out_of_range If @a pos1 > size() or @a pos2 >
1194 * @throw std::length_error If new length exceeds @c max_size().
1196 * Removes the characters in the range [pos1,pos1 + n) from this
1197 * string. In place, the value of @a str is inserted. If @a pos is
1198 * beyond end of string, out_of_range is thrown. If the length of the
1199 * result exceeds max_size(), length_error is thrown. The value of the
1200 * string doesn't change if an error is thrown.
1203 replace(size_type __pos1, size_type __n1, const basic_string& __str,
1204 size_type __pos2, size_type __n2)
1205 { return this->replace(__pos1, __n1, __str._M_data()
1206 + __str._M_check(__pos2, "basic_string::replace"),
1207 __str._M_limit(__pos2, __n2)); }
1210 * @brief Replace characters with value of a C substring.
1211 * @param pos Index of first character to replace.
1212 * @param n1 Number of characters to be replaced.
1213 * @param str C string to insert.
1214 * @param n2 Number of characters from str to use.
1215 * @return Reference to this string.
1216 * @throw std::out_of_range If @a pos1 > size().
1217 * @throw std::length_error If new length exceeds @c max_size().
1219 * Removes the characters in the range [pos,pos + n1) from this string.
1220 * In place, the first @a n2 characters of @a str are inserted, or all
1221 * of @a str if @a n2 is too large. If @a pos is beyond end of string,
1222 * out_of_range is thrown. If the length of result exceeds max_size(),
1223 * length_error is thrown. The value of the string doesn't change if
1224 * an error is thrown.
1227 replace(size_type __pos, size_type __n1, const _CharT* __s,
1231 * @brief Replace characters with value of a C string.
1232 * @param pos Index of first character to replace.
1233 * @param n1 Number of characters to be replaced.
1234 * @param str C string to insert.
1235 * @return Reference to this string.
1236 * @throw std::out_of_range If @a pos > size().
1237 * @throw std::length_error If new length exceeds @c max_size().
1239 * Removes the characters in the range [pos,pos + n1) from this string.
1240 * In place, the first @a n characters of @a str are inserted. If @a
1241 * pos is beyond end of string, out_of_range is thrown. If the length
1242 * of result exceeds max_size(), length_error is thrown. The value of
1243 * the string doesn't change if an error is thrown.
1246 replace(size_type __pos, size_type __n1, const _CharT* __s)
1248 __glibcxx_requires_string(__s);
1249 return this->replace(__pos, __n1, __s, traits_type::length(__s));
1253 * @brief Replace characters with multiple characters.
1254 * @param pos Index of first character to replace.
1255 * @param n1 Number of characters to be replaced.
1256 * @param n2 Number of characters to insert.
1257 * @param c Character to insert.
1258 * @return Reference to this string.
1259 * @throw std::out_of_range If @a pos > size().
1260 * @throw std::length_error If new length exceeds @c max_size().
1262 * Removes the characters in the range [pos,pos + n1) from this string.
1263 * In place, @a n2 copies of @a c are inserted. If @a pos is beyond
1264 * end of string, out_of_range is thrown. If the length of result
1265 * exceeds max_size(), length_error is thrown. The value of the string
1266 * doesn't change if an error is thrown.
1269 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1270 { return _M_replace_aux(_M_check(__pos, "basic_string::replace"),
1271 _M_limit(__pos, __n1), __n2, __c); }
1274 * @brief Replace range of characters with string.
1275 * @param i1 Iterator referencing start of range to replace.
1276 * @param i2 Iterator referencing end of range to replace.
1277 * @param str String value to insert.
1278 * @return Reference to this string.
1279 * @throw std::length_error If new length exceeds @c max_size().
1281 * Removes the characters in the range [i1,i2). In place, the value of
1282 * @a str is inserted. If the length of result exceeds max_size(),
1283 * length_error is thrown. The value of the string doesn't change if
1284 * an error is thrown.
1287 replace(iterator __i1, iterator __i2, const basic_string& __str)
1288 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1291 * @brief Replace range of characters with C substring.
1292 * @param i1 Iterator referencing start of range to replace.
1293 * @param i2 Iterator referencing end of range to replace.
1294 * @param s C string value to insert.
1295 * @param n Number of characters from s to insert.
1296 * @return Reference to this string.
1297 * @throw std::length_error If new length exceeds @c max_size().
1299 * Removes the characters in the range [i1,i2). In place, the first @a
1300 * n characters of @a s are inserted. If the length of result exceeds
1301 * max_size(), length_error is thrown. The value of the string doesn't
1302 * change if an error is thrown.
1305 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1307 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1308 && __i2 <= _M_iend());
1309 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1313 * @brief Replace range of characters with C string.
1314 * @param i1 Iterator referencing start of range to replace.
1315 * @param i2 Iterator referencing end of range to replace.
1316 * @param s C string value to insert.
1317 * @return Reference to this string.
1318 * @throw std::length_error If new length exceeds @c max_size().
1320 * Removes the characters in the range [i1,i2). In place, the
1321 * characters of @a s are inserted. If the length of result exceeds
1322 * max_size(), length_error is thrown. The value of the string doesn't
1323 * change if an error is thrown.
1326 replace(iterator __i1, iterator __i2, const _CharT* __s)
1328 __glibcxx_requires_string(__s);
1329 return this->replace(__i1, __i2, __s, traits_type::length(__s));
1333 * @brief Replace range of characters with multiple characters
1334 * @param i1 Iterator referencing start of range to replace.
1335 * @param i2 Iterator referencing end of range to replace.
1336 * @param n Number of characters to insert.
1337 * @param c Character to insert.
1338 * @return Reference to this string.
1339 * @throw std::length_error If new length exceeds @c max_size().
1341 * Removes the characters in the range [i1,i2). In place, @a n copies
1342 * of @a c are inserted. If the length of result exceeds max_size(),
1343 * length_error is thrown. The value of the string doesn't change if
1344 * an error is thrown.
1347 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1349 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1350 && __i2 <= _M_iend());
1351 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1355 * @brief Replace range of characters with range.
1356 * @param i1 Iterator referencing start of range to replace.
1357 * @param i2 Iterator referencing end of range to replace.
1358 * @param k1 Iterator referencing start of range to insert.
1359 * @param k2 Iterator referencing end of range to insert.
1360 * @return Reference to this string.
1361 * @throw std::length_error If new length exceeds @c max_size().
1363 * Removes the characters in the range [i1,i2). In place, characters
1364 * in the range [k1,k2) are inserted. If the length of result exceeds
1365 * max_size(), length_error is thrown. The value of the string doesn't
1366 * change if an error is thrown.
1368 template<class _InputIterator>
1370 replace(iterator __i1, iterator __i2,
1371 _InputIterator __k1, _InputIterator __k2)
1373 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1374 && __i2 <= _M_iend());
1375 __glibcxx_requires_valid_range(__k1, __k2);
1376 typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
1377 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1380 // Specializations for the common case of pointer and iterator:
1381 // useful to avoid the overhead of temporary buffering in _M_replace.
1383 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1385 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1386 && __i2 <= _M_iend());
1387 __glibcxx_requires_valid_range(__k1, __k2);
1388 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1393 replace(iterator __i1, iterator __i2,
1394 const _CharT* __k1, const _CharT* __k2)
1396 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1397 && __i2 <= _M_iend());
1398 __glibcxx_requires_valid_range(__k1, __k2);
1399 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1404 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1406 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1407 && __i2 <= _M_iend());
1408 __glibcxx_requires_valid_range(__k1, __k2);
1409 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1410 __k1.base(), __k2 - __k1);
1414 replace(iterator __i1, iterator __i2,
1415 const_iterator __k1, const_iterator __k2)
1417 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1418 && __i2 <= _M_iend());
1419 __glibcxx_requires_valid_range(__k1, __k2);
1420 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1421 __k1.base(), __k2 - __k1);
1425 template<class _Integer>
1427 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1428 _Integer __val, __true_type)
1429 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1431 template<class _InputIterator>
1433 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1434 _InputIterator __k2, __false_type);
1437 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1440 _M_check_length(__n1, __n2, "basic_string::_M_replace_aux");
1441 _M_mutate(__pos1, __n1, __n2);
1443 _M_assign(_M_data() + __pos1, __n2, __c);
1448 _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s,
1451 _M_mutate(__pos1, __n1, __n2);
1453 _M_copy(_M_data() + __pos1, __s, __n2);
1457 // _S_construct_aux is used to implement the 21.3.1 para 15 which
1458 // requires special behaviour if _InIter is an integral type
1459 template<class _InIterator>
1461 _S_construct_aux(_InIterator __beg, _InIterator __end,
1462 const _Alloc& __a, __false_type)
1464 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
1465 return _S_construct(__beg, __end, __a, _Tag());
1468 template<class _InIterator>
1470 _S_construct_aux(_InIterator __beg, _InIterator __end,
1471 const _Alloc& __a, __true_type)
1472 { return _S_construct(static_cast<size_type>(__beg),
1473 static_cast<value_type>(__end), __a); }
1475 template<class _InIterator>
1477 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a)
1479 typedef typename _Is_integer<_InIterator>::_Integral _Integral;
1480 return _S_construct_aux(__beg, __end, __a, _Integral());
1483 // For Input Iterators, used in istreambuf_iterators, etc.
1484 template<class _InIterator>
1486 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
1487 input_iterator_tag);
1489 // For forward_iterators up to random_access_iterators, used for
1490 // string::iterator, _CharT*, etc.
1491 template<class _FwdIterator>
1493 _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a,
1494 forward_iterator_tag);
1497 _S_construct(size_type __req, _CharT __c, const _Alloc& __a);
1502 * @brief Copy substring into C string.
1503 * @param s C string to copy value into.
1504 * @param n Number of characters to copy.
1505 * @param pos Index of first character to copy.
1506 * @return Number of characters actually copied
1507 * @throw std::out_of_range If pos > size().
1509 * Copies up to @a n characters starting at @a pos into the C string @a
1510 * s. If @a pos is greater than size(), out_of_range is thrown.
1513 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1516 * @brief Swap contents with another string.
1517 * @param s String to swap with.
1519 * Exchanges the contents of this string with that of @a s in constant
1523 swap(basic_string& __s);
1525 // String operations:
1527 * @brief Return const pointer to null-terminated contents.
1529 * This is a handle to internal data. Do not modify or dire things may
1534 { return _M_data(); }
1537 * @brief Return const pointer to contents.
1539 * This is a handle to internal data. Do not modify or dire things may
1544 { return _M_data(); }
1547 * @brief Return copy of allocator used to construct this string.
1550 get_allocator() const
1551 { return _M_dataplus; }
1554 * @brief Find position of a C substring.
1555 * @param s C string to locate.
1556 * @param pos Index of character to search from.
1557 * @param n Number of characters from @a s to search for.
1558 * @return Index of start of first occurrence.
1560 * Starting from @a pos, searches forward for the first @a n characters
1561 * in @a s within this string. If found, returns the index where it
1562 * begins. If not found, returns npos.
1565 find(const _CharT* __s, size_type __pos, size_type __n) const;
1568 * @brief Find position of a string.
1569 * @param str String to locate.
1570 * @param pos Index of character to search from (default 0).
1571 * @return Index of start of first occurrence.
1573 * Starting from @a pos, searches forward for value of @a str within
1574 * this string. If found, returns the index where it begins. If not
1575 * found, returns npos.
1578 find(const basic_string& __str, size_type __pos = 0) const
1579 { return this->find(__str.data(), __pos, __str.size()); }
1582 * @brief Find position of a C string.
1583 * @param s C string to locate.
1584 * @param pos Index of character to search from (default 0).
1585 * @return Index of start of first occurrence.
1587 * Starting from @a pos, searches forward for the value of @a s within
1588 * this string. If found, returns the index where it begins. If not
1589 * found, returns npos.
1592 find(const _CharT* __s, size_type __pos = 0) const
1594 __glibcxx_requires_string(__s);
1595 return this->find(__s, __pos, traits_type::length(__s));
1599 * @brief Find position of a character.
1600 * @param c Character to locate.
1601 * @param pos Index of character to search from (default 0).
1602 * @return Index of first occurrence.
1604 * Starting from @a pos, searches forward for @a c within this string.
1605 * If found, returns the index where it was found. If not found,
1609 find(_CharT __c, size_type __pos = 0) const;
1612 * @brief Find last position of a string.
1613 * @param str String to locate.
1614 * @param pos Index of character to search back from (default end).
1615 * @return Index of start of last occurrence.
1617 * Starting from @a pos, searches backward for value of @a str within
1618 * this string. If found, returns the index where it begins. If not
1619 * found, returns npos.
1622 rfind(const basic_string& __str, size_type __pos = npos) const
1623 { return this->rfind(__str.data(), __pos, __str.size()); }
1626 * @brief Find last position of a C substring.
1627 * @param s C string to locate.
1628 * @param pos Index of character to search back from.
1629 * @param n Number of characters from s to search for.
1630 * @return Index of start of last occurrence.
1632 * Starting from @a pos, searches backward for the first @a n
1633 * characters in @a s within this string. If found, returns the index
1634 * where it begins. If not found, returns npos.
1637 rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1640 * @brief Find last position of a C string.
1641 * @param s C string to locate.
1642 * @param pos Index of character to start search at (default 0).
1643 * @return Index of start of last occurrence.
1645 * Starting from @a pos, searches backward for the value of @a s within
1646 * this string. If found, returns the index where it begins. If not
1647 * found, returns npos.
1650 rfind(const _CharT* __s, size_type __pos = npos) const
1652 __glibcxx_requires_string(__s);
1653 return this->rfind(__s, __pos, traits_type::length(__s));
1657 * @brief Find last position of a character.
1658 * @param c Character to locate.
1659 * @param pos Index of character to search back from (default 0).
1660 * @return Index of last occurrence.
1662 * Starting from @a pos, searches backward for @a c within this string.
1663 * If found, returns the index where it was found. If not found,
1667 rfind(_CharT __c, size_type __pos = npos) const;
1670 * @brief Find position of a character of string.
1671 * @param str String containing characters to locate.
1672 * @param pos Index of character to search from (default 0).
1673 * @return Index of first occurrence.
1675 * Starting from @a pos, searches forward for one of the characters of
1676 * @a str within this string. If found, returns the index where it was
1677 * found. If not found, returns npos.
1680 find_first_of(const basic_string& __str, size_type __pos = 0) const
1681 { return this->find_first_of(__str.data(), __pos, __str.size()); }
1684 * @brief Find position of a character of C substring.
1685 * @param s String containing characters to locate.
1686 * @param pos Index of character to search from (default 0).
1687 * @param n Number of characters from s to search for.
1688 * @return Index of first occurrence.
1690 * Starting from @a pos, searches forward for one of the first @a n
1691 * characters of @a s within this string. If found, returns the index
1692 * where it was found. If not found, returns npos.
1695 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1698 * @brief Find position of a character of C string.
1699 * @param s String containing characters to locate.
1700 * @param pos Index of character to search from (default 0).
1701 * @return Index of first occurrence.
1703 * Starting from @a pos, searches forward for one of the characters of
1704 * @a s within this string. If found, returns the index where it was
1705 * found. If not found, returns npos.
1708 find_first_of(const _CharT* __s, size_type __pos = 0) const
1710 __glibcxx_requires_string(__s);
1711 return this->find_first_of(__s, __pos, traits_type::length(__s));
1715 * @brief Find position of a character.
1716 * @param c Character to locate.
1717 * @param pos Index of character to search from (default 0).
1718 * @return Index of first occurrence.
1720 * Starting from @a pos, searches forward for the character @a c within
1721 * this string. If found, returns the index where it was found. If
1722 * not found, returns npos.
1724 * Note: equivalent to find(c, pos).
1727 find_first_of(_CharT __c, size_type __pos = 0) const
1728 { return this->find(__c, __pos); }
1731 * @brief Find last position of a character of string.
1732 * @param str String containing characters to locate.
1733 * @param pos Index of character to search back from (default end).
1734 * @return Index of last occurrence.
1736 * Starting from @a pos, searches backward for one of the characters of
1737 * @a str within this string. If found, returns the index where it was
1738 * found. If not found, returns npos.
1741 find_last_of(const basic_string& __str, size_type __pos = npos) const
1742 { return this->find_last_of(__str.data(), __pos, __str.size()); }
1745 * @brief Find last position of a character of C substring.
1746 * @param s C string containing characters to locate.
1747 * @param pos Index of character to search back from (default end).
1748 * @param n Number of characters from s to search for.
1749 * @return Index of last occurrence.
1751 * Starting from @a pos, searches backward for one of the first @a n
1752 * characters of @a s within this string. If found, returns the index
1753 * where it was found. If not found, returns npos.
1756 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1759 * @brief Find last position of a character of C string.
1760 * @param s C string containing characters to locate.
1761 * @param pos Index of character to search back from (default end).
1762 * @return Index of last occurrence.
1764 * Starting from @a pos, searches backward for one of the characters of
1765 * @a s within this string. If found, returns the index where it was
1766 * found. If not found, returns npos.
1769 find_last_of(const _CharT* __s, size_type __pos = npos) const
1771 __glibcxx_requires_string(__s);
1772 return this->find_last_of(__s, __pos, traits_type::length(__s));
1776 * @brief Find last position of a character.
1777 * @param c Character to locate.
1778 * @param pos Index of character to search back from (default 0).
1779 * @return Index of last occurrence.
1781 * Starting from @a pos, searches backward for @a c within this string.
1782 * If found, returns the index where it was found. If not found,
1785 * Note: equivalent to rfind(c, pos).
1788 find_last_of(_CharT __c, size_type __pos = npos) const
1789 { return this->rfind(__c, __pos); }
1792 * @brief Find position of a character not in string.
1793 * @param str String containing characters to avoid.
1794 * @param pos Index of character to search from (default 0).
1795 * @return Index of first occurrence.
1797 * Starting from @a pos, searches forward for a character not contained
1798 * in @a str within this string. If found, returns the index where it
1799 * was found. If not found, returns npos.
1802 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
1803 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1806 * @brief Find position of a character not in C substring.
1807 * @param s C string containing characters to avoid.
1808 * @param pos Index of character to search from (default 0).
1809 * @param n Number of characters from s to consider.
1810 * @return Index of first occurrence.
1812 * Starting from @a pos, searches forward for a character not contained
1813 * in the first @a n characters of @a s within this string. If found,
1814 * returns the index where it was found. If not found, returns npos.
1817 find_first_not_of(const _CharT* __s, size_type __pos,
1818 size_type __n) const;
1821 * @brief Find position of a character not in C string.
1822 * @param s C string containing characters to avoid.
1823 * @param pos Index of character to search from (default 0).
1824 * @return Index of first occurrence.
1826 * Starting from @a pos, searches forward for a character not contained
1827 * in @a s within this string. If found, returns the index where it
1828 * was found. If not found, returns npos.
1831 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1833 __glibcxx_requires_string(__s);
1834 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1838 * @brief Find position of a different character.
1839 * @param c Character to avoid.
1840 * @param pos Index of character to search from (default 0).
1841 * @return Index of first occurrence.
1843 * Starting from @a pos, searches forward for a character other than @a c
1844 * within this string. If found, returns the index where it was found.
1845 * If not found, returns npos.
1848 find_first_not_of(_CharT __c, size_type __pos = 0) const;
1851 * @brief Find last position of a character not in string.
1852 * @param str String containing characters to avoid.
1853 * @param pos Index of character to search from (default 0).
1854 * @return Index of first occurrence.
1856 * Starting from @a pos, searches backward for a character not
1857 * contained in @a str within this string. If found, returns the index
1858 * where it was found. If not found, returns npos.
1861 find_last_not_of(const basic_string& __str, size_type __pos = npos) const
1862 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1865 * @brief Find last position of a character not in C substring.
1866 * @param s C string containing characters to avoid.
1867 * @param pos Index of character to search from (default 0).
1868 * @param n Number of characters from s to consider.
1869 * @return Index of first occurrence.
1871 * Starting from @a pos, searches backward for a character not
1872 * contained in the first @a n characters of @a s within this string.
1873 * If found, returns the index where it was found. If not found,
1877 find_last_not_of(const _CharT* __s, size_type __pos,
1878 size_type __n) const;
1880 * @brief Find position of a character not in C string.
1881 * @param s C string containing characters to avoid.
1882 * @param pos Index of character to search from (default 0).
1883 * @return Index of first occurrence.
1885 * Starting from @a pos, searches backward for a character not
1886 * contained in @a s within this string. If found, returns the index
1887 * where it was found. If not found, returns npos.
1890 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1892 __glibcxx_requires_string(__s);
1893 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1897 * @brief Find last position of a different character.
1898 * @param c Character to avoid.
1899 * @param pos Index of character to search from (default 0).
1900 * @return Index of first occurrence.
1902 * Starting from @a pos, searches backward for a character other than
1903 * @a c within this string. If found, returns the index where it was
1904 * found. If not found, returns npos.
1907 find_last_not_of(_CharT __c, size_type __pos = npos) const;
1910 * @brief Get a substring.
1911 * @param pos Index of first character (default 0).
1912 * @param n Number of characters in substring (default remainder).
1913 * @return The new string.
1914 * @throw std::out_of_range If pos > size().
1916 * Construct and return a new string using the @a n characters starting
1917 * at @a pos. If the string is too short, use the remainder of the
1918 * characters. If @a pos is beyond the end of the string, out_of_range
1922 substr(size_type __pos = 0, size_type __n = npos) const
1923 { return basic_string(*this,
1924 _M_check(__pos, "basic_string::substr"), __n); }
1927 * @brief Compare to a string.
1928 * @param str String to compare against.
1929 * @return Integer < 0, 0, or > 0.
1931 * Returns an integer < 0 if this string is ordered before @a str, 0 if
1932 * their values are equivalent, or > 0 if this string is ordered after
1933 * @a str. If the lengths of @a str 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(),str.data(),size());
1938 compare(const basic_string& __str) const
1940 const size_type __size = this->size();
1941 const size_type __osize = __str.size();
1942 const size_type __len = std::min(__size, __osize);
1944 int __r = traits_type::compare(_M_data(), __str.data(), __len);
1946 __r = __size - __osize;
1951 * @brief Compare substring to a string.
1952 * @param pos Index of first character of substring.
1953 * @param n Number of characters in substring.
1954 * @param str String to compare against.
1955 * @return Integer < 0, 0, or > 0.
1957 * Form the substring of this string from the @a n characters starting
1958 * at @a pos. Returns an integer < 0 if the substring is ordered
1959 * before @a str, 0 if their values are equivalent, or > 0 if the
1960 * substring is ordered after @a str. If the lengths @a of str and the
1961 * substring are different, the shorter one is ordered first. If they
1962 * are the same, returns the result of
1963 * traits::compare(substring.data(),str.data(),size());
1966 compare(size_type __pos, size_type __n, const basic_string& __str) const;
1969 * @brief Compare substring to a substring.
1970 * @param pos1 Index of first character of substring.
1971 * @param n1 Number of characters in substring.
1972 * @param str String to compare against.
1973 * @param pos2 Index of first character of substring of str.
1974 * @param n2 Number of characters in substring of str.
1975 * @return Integer < 0, 0, or > 0.
1977 * Form the substring of this string from the @a n1 characters starting
1978 * at @a pos1. Form the substring of @a str from the @a n2 characters
1979 * starting at @a pos2. Returns an integer < 0 if this substring is
1980 * ordered before the substring of @a str, 0 if their values are
1981 * equivalent, or > 0 if this substring is ordered after the substring
1982 * of @a str. If the lengths of the substring of @a str and this
1983 * substring are different, the shorter one is ordered first. If they
1984 * are the same, returns the result of
1985 * traits::compare(substring.data(),str.substr(pos2,n2).data(),size());
1988 compare(size_type __pos1, size_type __n1, const basic_string& __str,
1989 size_type __pos2, size_type __n2) const;
1992 * @brief Compare to a C string.
1993 * @param s C string to compare against.
1994 * @return Integer < 0, 0, or > 0.
1996 * Returns an integer < 0 if this string is ordered before @a s, 0 if
1997 * their values are equivalent, or > 0 if this string is ordered after
1998 * @a s. If the lengths of @a s and this string are different, the
1999 * shorter one is ordered first. If they are the same, returns the
2000 * result of traits::compare(data(),s,size());
2003 compare(const _CharT* __s) const;
2005 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2006 // 5 String::compare specification questionable
2008 * @brief Compare substring to a C string.
2009 * @param pos Index of first character of substring.
2010 * @param n1 Number of characters in substring.
2011 * @param s C string to compare against.
2012 * @return Integer < 0, 0, or > 0.
2014 * Form the substring of this string from the @a n1 characters starting
2015 * at @a pos. Returns an integer < 0 if the substring is ordered
2016 * before @a s, 0 if their values are equivalent, or > 0 if the
2017 * substring is ordered after @a s. If the lengths of @a s and the
2018 * substring are different, the shorter one is ordered first. If they
2019 * are the same, returns the result of
2020 * traits::compare(substring.data(),s,size());
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. If the lengths of this
2038 * substring and @a n2 are different, the shorter one is ordered first.
2039 * If they are the same, returns the result of
2040 * traits::compare(substring.data(),s,size());
2042 * NB: s must have at least n2 characters, '\0' has no special
2046 compare(size_type __pos, size_type __n1, const _CharT* __s,
2047 size_type __n2) const;
2050 template<typename _CharT, typename _Traits, typename _Alloc>
2051 inline basic_string<_CharT, _Traits, _Alloc>::
2053 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
2054 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
2056 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()) { }
2061 * @brief Concatenate two strings.
2062 * @param lhs First string.
2063 * @param rhs Last string.
2064 * @return New string with value of @a lhs followed by @a rhs.
2066 template<typename _CharT, typename _Traits, typename _Alloc>
2067 basic_string<_CharT, _Traits, _Alloc>
2068 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2069 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2071 basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
2072 __str.append(__rhs);
2077 * @brief Concatenate C string and string.
2078 * @param lhs First string.
2079 * @param rhs Last string.
2080 * @return New string with value of @a lhs followed by @a rhs.
2082 template<typename _CharT, typename _Traits, typename _Alloc>
2083 basic_string<_CharT,_Traits,_Alloc>
2084 operator+(const _CharT* __lhs,
2085 const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2088 * @brief Concatenate character and string.
2089 * @param lhs First string.
2090 * @param rhs Last string.
2091 * @return New string with @a lhs followed by @a rhs.
2093 template<typename _CharT, typename _Traits, typename _Alloc>
2094 basic_string<_CharT,_Traits,_Alloc>
2095 operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2098 * @brief Concatenate string and C string.
2099 * @param lhs First string.
2100 * @param rhs Last string.
2101 * @return New string with @a lhs followed by @a rhs.
2103 template<typename _CharT, typename _Traits, typename _Alloc>
2104 inline basic_string<_CharT, _Traits, _Alloc>
2105 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2106 const _CharT* __rhs)
2108 basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
2109 __str.append(__rhs);
2114 * @brief Concatenate string and character.
2115 * @param lhs First string.
2116 * @param rhs Last string.
2117 * @return New string with @a lhs followed by @a rhs.
2119 template<typename _CharT, typename _Traits, typename _Alloc>
2120 inline basic_string<_CharT, _Traits, _Alloc>
2121 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
2123 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
2124 typedef typename __string_type::size_type __size_type;
2125 __string_type __str(__lhs);
2126 __str.append(__size_type(1), __rhs);
2132 * @brief Test equivalence of two strings.
2133 * @param lhs First string.
2134 * @param rhs Second string.
2135 * @return True if @a lhs.compare(@a rhs) == 0. False otherwise.
2137 template<typename _CharT, typename _Traits, typename _Alloc>
2139 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2140 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2141 { return __lhs.compare(__rhs) == 0; }
2144 * @brief Test equivalence of C string and string.
2145 * @param lhs C string.
2146 * @param rhs String.
2147 * @return True if @a rhs.compare(@a lhs) == 0. False otherwise.
2149 template<typename _CharT, typename _Traits, typename _Alloc>
2151 operator==(const _CharT* __lhs,
2152 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2153 { return __rhs.compare(__lhs) == 0; }
2156 * @brief Test equivalence of string and C string.
2157 * @param lhs String.
2158 * @param rhs C string.
2159 * @return True if @a lhs.compare(@a rhs) == 0. False otherwise.
2161 template<typename _CharT, typename _Traits, typename _Alloc>
2163 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2164 const _CharT* __rhs)
2165 { return __lhs.compare(__rhs) == 0; }
2169 * @brief Test difference of two strings.
2170 * @param lhs First string.
2171 * @param rhs Second string.
2172 * @return True if @a lhs.compare(@a rhs) != 0. False otherwise.
2174 template<typename _CharT, typename _Traits, typename _Alloc>
2176 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2177 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2178 { return __rhs.compare(__lhs) != 0; }
2181 * @brief Test difference of C string and string.
2182 * @param lhs C string.
2183 * @param rhs String.
2184 * @return True if @a rhs.compare(@a lhs) != 0. False otherwise.
2186 template<typename _CharT, typename _Traits, typename _Alloc>
2188 operator!=(const _CharT* __lhs,
2189 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2190 { return __rhs.compare(__lhs) != 0; }
2193 * @brief Test difference of string and C string.
2194 * @param lhs String.
2195 * @param rhs C string.
2196 * @return True if @a lhs.compare(@a rhs) != 0. False otherwise.
2198 template<typename _CharT, typename _Traits, typename _Alloc>
2200 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2201 const _CharT* __rhs)
2202 { return __lhs.compare(__rhs) != 0; }
2206 * @brief Test if string precedes string.
2207 * @param lhs First string.
2208 * @param rhs Second string.
2209 * @return True if @a lhs precedes @a rhs. False otherwise.
2211 template<typename _CharT, typename _Traits, typename _Alloc>
2213 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2214 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2215 { return __lhs.compare(__rhs) < 0; }
2218 * @brief Test if string precedes C string.
2219 * @param lhs String.
2220 * @param rhs C string.
2221 * @return True if @a lhs precedes @a rhs. False otherwise.
2223 template<typename _CharT, typename _Traits, typename _Alloc>
2225 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2226 const _CharT* __rhs)
2227 { return __lhs.compare(__rhs) < 0; }
2230 * @brief Test if C string precedes string.
2231 * @param lhs C string.
2232 * @param rhs String.
2233 * @return True if @a lhs precedes @a rhs. False otherwise.
2235 template<typename _CharT, typename _Traits, typename _Alloc>
2237 operator<(const _CharT* __lhs,
2238 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2239 { return __rhs.compare(__lhs) > 0; }
2243 * @brief Test if string follows string.
2244 * @param lhs First string.
2245 * @param rhs Second string.
2246 * @return True if @a lhs follows @a rhs. False otherwise.
2248 template<typename _CharT, typename _Traits, typename _Alloc>
2250 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2251 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2252 { return __lhs.compare(__rhs) > 0; }
2255 * @brief Test if string follows C string.
2256 * @param lhs String.
2257 * @param rhs C string.
2258 * @return True if @a lhs follows @a rhs. False otherwise.
2260 template<typename _CharT, typename _Traits, typename _Alloc>
2262 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2263 const _CharT* __rhs)
2264 { return __lhs.compare(__rhs) > 0; }
2267 * @brief Test if C string follows string.
2268 * @param lhs C string.
2269 * @param rhs String.
2270 * @return True if @a lhs follows @a rhs. False otherwise.
2272 template<typename _CharT, typename _Traits, typename _Alloc>
2274 operator>(const _CharT* __lhs,
2275 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2276 { return __rhs.compare(__lhs) < 0; }
2280 * @brief Test if string doesn't follow string.
2281 * @param lhs First string.
2282 * @param rhs Second string.
2283 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2285 template<typename _CharT, typename _Traits, typename _Alloc>
2287 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2288 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2289 { return __lhs.compare(__rhs) <= 0; }
2292 * @brief Test if string doesn't follow C string.
2293 * @param lhs String.
2294 * @param rhs C string.
2295 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2297 template<typename _CharT, typename _Traits, typename _Alloc>
2299 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2300 const _CharT* __rhs)
2301 { return __lhs.compare(__rhs) <= 0; }
2304 * @brief Test if C string doesn't follow string.
2305 * @param lhs C string.
2306 * @param rhs String.
2307 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2309 template<typename _CharT, typename _Traits, typename _Alloc>
2311 operator<=(const _CharT* __lhs,
2312 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2313 { return __rhs.compare(__lhs) >= 0; }
2317 * @brief Test if string doesn't precede string.
2318 * @param lhs First string.
2319 * @param rhs Second string.
2320 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2322 template<typename _CharT, typename _Traits, typename _Alloc>
2324 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2325 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2326 { return __lhs.compare(__rhs) >= 0; }
2329 * @brief Test if string doesn't precede C string.
2330 * @param lhs String.
2331 * @param rhs C string.
2332 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2334 template<typename _CharT, typename _Traits, typename _Alloc>
2336 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2337 const _CharT* __rhs)
2338 { return __lhs.compare(__rhs) >= 0; }
2341 * @brief Test if C string doesn't precede string.
2342 * @param lhs C string.
2343 * @param rhs String.
2344 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2346 template<typename _CharT, typename _Traits, typename _Alloc>
2348 operator>=(const _CharT* __lhs,
2349 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2350 { return __rhs.compare(__lhs) <= 0; }
2353 * @brief Swap contents of two strings.
2354 * @param lhs First string.
2355 * @param rhs Second string.
2357 * Exchanges the contents of @a lhs and @a rhs in constant time.
2359 template<typename _CharT, typename _Traits, typename _Alloc>
2361 swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
2362 basic_string<_CharT, _Traits, _Alloc>& __rhs)
2363 { __lhs.swap(__rhs); }
2366 * @brief Read stream into a string.
2367 * @param is Input stream.
2368 * @param str Buffer to store into.
2369 * @return Reference to the input stream.
2371 * Stores characters from @a is into @a str until whitespace is found, the
2372 * end of the stream is encountered, or str.max_size() is reached. If
2373 * is.width() is non-zero, that is the limit on the number of characters
2374 * stored into @a str. Any previous contents of @a str are erased.
2376 template<typename _CharT, typename _Traits, typename _Alloc>
2377 basic_istream<_CharT, _Traits>&
2378 operator>>(basic_istream<_CharT, _Traits>& __is,
2379 basic_string<_CharT, _Traits, _Alloc>& __str);
2382 * @brief Write string to a stream.
2383 * @param os Output stream.
2384 * @param str String to write out.
2385 * @return Reference to the output stream.
2387 * Output characters of @a str into os following the same rules as for
2388 * writing a C string.
2390 template<typename _CharT, typename _Traits, typename _Alloc>
2391 basic_ostream<_CharT, _Traits>&
2392 operator<<(basic_ostream<_CharT, _Traits>& __os,
2393 const basic_string<_CharT, _Traits, _Alloc>& __str);
2396 * @brief Read a line from stream into a string.
2397 * @param is Input stream.
2398 * @param str Buffer to store into.
2399 * @param delim Character marking end of line.
2400 * @return Reference to the input stream.
2402 * Stores characters from @a is into @a str until @a delim is found, the
2403 * end of the stream is encountered, or str.max_size() is reached. If
2404 * is.width() is non-zero, that is the limit on the number of characters
2405 * stored into @a str. Any previous contents of @a str are erased. If @a
2406 * delim was encountered, it is extracted but not stored into @a str.
2408 template<typename _CharT, typename _Traits, typename _Alloc>
2409 basic_istream<_CharT,_Traits>&
2410 getline(basic_istream<_CharT, _Traits>& __is,
2411 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
2414 * @brief Read a line from stream into a string.
2415 * @param is Input stream.
2416 * @param str Buffer to store into.
2417 * @return Reference to the input stream.
2419 * Stores characters from is into @a str until '\n' is found, the end of
2420 * the stream is encountered, or str.max_size() is reached. If is.width()
2421 * is non-zero, that is the limit on the number of characters stored into
2422 * @a str. Any previous contents of @a str are erased. If end of line was
2423 * encountered, it is extracted but not stored into @a str.
2425 template<typename _CharT, typename _Traits, typename _Alloc>
2426 inline basic_istream<_CharT,_Traits>&
2427 getline(basic_istream<_CharT, _Traits>& __is,
2428 basic_string<_CharT, _Traits, _Alloc>& __str);
2431 #endif /* _BASIC_STRING_H */