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_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: 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; }
198 { return reinterpret_cast<_CharT*>(this + 1); }
201 operator[](size_t __s) throw()
202 { return _M_refdata() [__s]; }
205 _M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2)
207 return (!_M_is_leaked() && __alloc1 == __alloc2)
208 ? _M_refcopy() : _M_clone(__alloc1);
213 _S_create(size_t, const _Alloc&);
216 _M_dispose(const _Alloc& __a)
218 if (__builtin_expect(this != &_S_empty_rep(), false))
219 if (__exchange_and_add(&this->_M_refcount, -1) <= 0)
224 _M_destroy(const _Alloc&) throw();
229 if (__builtin_expect(this != &_S_empty_rep(), false))
230 __atomic_add(&this->_M_refcount, 1);
235 _M_clone(const _Alloc&, size_type __res = 0);
238 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
239 struct _Alloc_hider : _Alloc
241 _Alloc_hider(_CharT* __dat, const _Alloc& __a)
242 : _Alloc(__a), _M_p(__dat) { }
244 _CharT* _M_p; // The actual data.
248 // Data Members (public):
249 // NB: This is an unsigned type, and thus represents the maximum
250 // size that the allocator can hold.
252 /// Value returned by various member functions when they fail.
253 static const size_type npos = static_cast<size_type>(-1);
256 // Data Members (private):
257 mutable _Alloc_hider _M_dataplus;
261 { return _M_dataplus._M_p; }
265 { return (_M_dataplus._M_p = __p); }
269 { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }
271 // For the internal use we have functions similar to `begin'/`end'
272 // but they do not call _M_leak.
274 _M_ibegin() const { return iterator(_M_data()); }
277 _M_iend() const { return iterator(_M_data() + this->size()); }
280 _M_leak() // for use in begin() & non-const op[]
282 if (!_M_rep()->_M_is_leaked())
287 _M_check(size_type __pos, const char* __s) const
289 if (__pos > this->size())
290 __throw_out_of_range(__N(__s));
294 // NB: _M_limit doesn't check for a bad __pos value.
296 _M_limit(size_type __pos, size_type __off) const
298 const bool __testoff = __off < this->size() - __pos;
299 return __testoff ? __off : this->size() - __pos;
302 // _S_copy_chars is a separate template to permit specialization
303 // to optimize for the common case of pointers as iterators.
304 template<class _Iterator>
306 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
308 for (; __k1 != __k2; ++__k1, ++__p)
309 traits_type::assign(*__p, *__k1); // These types are off.
313 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2)
314 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
317 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
318 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
321 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2)
322 { traits_type::copy(__p, __k1, __k2 - __k1); }
325 _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
326 { traits_type::copy(__p, __k1, __k2 - __k1); }
329 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
336 { return _Rep::_S_empty_rep(); }
339 // Construct/copy/destroy:
340 // NB: We overload ctors in some cases instead of using default
341 // arguments, per 17.4.4.4 para. 2 item 2.
344 * @brief Default constructor creates an empty string.
350 * @brief Construct an empty string using allocator a.
353 basic_string(const _Alloc& __a);
355 // NB: per LWG issue 42, semantics different from IS:
357 * @brief Construct string with copy of value of @a str.
358 * @param str Source string.
360 basic_string(const basic_string& __str);
362 * @brief Construct string as copy of a substring.
363 * @param str Source string.
364 * @param pos Index of first character to copy from.
365 * @param n Number of characters to copy (default remainder).
367 basic_string(const basic_string& __str, size_type __pos,
368 size_type __n = npos);
370 * @brief Construct string as copy of a substring.
371 * @param str Source string.
372 * @param pos Index of first character to copy from.
373 * @param n Number of characters to copy.
374 * @param a Allocator to use.
376 basic_string(const basic_string& __str, size_type __pos,
377 size_type __n, const _Alloc& __a);
380 * @brief Construct string initialized by a character array.
381 * @param s Source character array.
382 * @param n Number of characters to copy.
383 * @param a Allocator to use (default is default allocator).
385 * NB: s must have at least n characters, '\0' has no special
388 basic_string(const _CharT* __s, size_type __n,
389 const _Alloc& __a = _Alloc());
391 * @brief Construct string as copy of a C string.
392 * @param s Source C string.
393 * @param a Allocator to use (default is default allocator).
395 basic_string(const _CharT* __s, const _Alloc& __a = _Alloc());
397 * @brief Construct string as multiple characters.
398 * @param n Number of characters.
399 * @param c Character to use.
400 * @param a Allocator to use (default is default allocator).
402 basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
405 * @brief Construct string as copy of a range.
406 * @param beg Start of range.
407 * @param end End of range.
408 * @param a Allocator to use (default is default allocator).
410 template<class _InputIterator>
411 basic_string(_InputIterator __beg, _InputIterator __end,
412 const _Alloc& __a = _Alloc());
415 * @brief Destroy the string instance.
418 { _M_rep()->_M_dispose(this->get_allocator()); }
421 * @brief Assign the value of @a str to this string.
422 * @param str Source string.
425 operator=(const basic_string& __str) { return this->assign(__str); }
428 * @brief Copy contents of @a s into this string.
429 * @param s Source null-terminated string.
432 operator=(const _CharT* __s) { return this->assign(__s); }
435 * @brief Set value to string of length 1.
436 * @param c Source character.
438 * Assigning to a character makes this string length 1 and
439 * (*this)[0] == @a c.
442 operator=(_CharT __c) { return this->assign(1, __c); }
446 * Returns a read/write iterator that points to the first character in
447 * the %string. Unshares the string.
453 return iterator(_M_data());
457 * Returns a read-only (constant) iterator that points to the first
458 * character in the %string.
462 { return const_iterator(_M_data()); }
465 * Returns a read/write iterator that points one past the last
466 * character in the %string. Unshares the string.
472 return iterator(_M_data() + this->size());
476 * Returns a read-only (constant) iterator that points one past the
477 * last character in the %string.
481 { return const_iterator(_M_data() + this->size()); }
484 * Returns a read/write reverse iterator that points to the last
485 * character in the %string. Iteration is done in reverse element
486 * order. Unshares the string.
490 { return reverse_iterator(this->end()); }
493 * Returns a read-only (constant) reverse iterator that points
494 * to the last character in the %string. Iteration is done in
495 * reverse element order.
497 const_reverse_iterator
499 { return const_reverse_iterator(this->end()); }
502 * Returns a read/write reverse iterator that points to one before the
503 * first character in the %string. Iteration is done in reverse
504 * element order. Unshares the string.
508 { return reverse_iterator(this->begin()); }
511 * Returns a read-only (constant) reverse iterator that points
512 * to one before the first character in the %string. Iteration
513 * is done in reverse element order.
515 const_reverse_iterator
517 { return const_reverse_iterator(this->begin()); }
521 /// Returns the number of characters in the string, not including any
522 /// null-termination.
524 size() const { return _M_rep()->_M_length; }
526 /// Returns the number of characters in the string, not including any
527 /// null-termination.
529 length() const { return _M_rep()->_M_length; }
531 /// Returns the size() of the largest possible %string.
533 max_size() const { return _Rep::_S_max_size; }
536 * @brief Resizes the %string to the specified number of characters.
537 * @param n Number of characters the %string should contain.
538 * @param c Character to fill any new elements.
540 * This function will %resize the %string to the specified
541 * number of characters. If the number is smaller than the
542 * %string's current size the %string is truncated, otherwise
543 * the %string is extended and new elements are set to @a c.
546 resize(size_type __n, _CharT __c);
549 * @brief Resizes the %string to the specified number of characters.
550 * @param n Number of characters the %string should contain.
552 * This function will resize the %string to the specified length. If
553 * the new size is smaller than the %string's current size the %string
554 * is truncated, otherwise the %string is extended and new characters
555 * are default-constructed. For basic types such as char, this means
559 resize(size_type __n) { this->resize(__n, _CharT()); }
562 * Returns the total number of characters that the %string can hold
563 * before needing to allocate more memory.
566 capacity() const { return _M_rep()->_M_capacity; }
569 * @brief Attempt to preallocate enough memory for specified number of
571 * @param n Number of characters required.
572 * @throw std::length_error If @a n exceeds @c max_size().
574 * This function attempts to reserve enough memory for the
575 * %string to hold the specified number of characters. If the
576 * number requested is more than max_size(), length_error is
579 * The advantage of this function is that if optimal code is a
580 * necessity and the user can determine the string length that will be
581 * required, the user can reserve the memory in %advance, and thus
582 * prevent a possible reallocation of memory and copying of %string
586 reserve(size_type __res_arg = 0);
589 * Erases the string, making it empty.
592 clear() { _M_mutate(0, this->size(), 0); }
595 * Returns true if the %string is empty. Equivalent to *this == "".
598 empty() const { return this->size() == 0; }
602 * @brief Subscript access to the data contained in the %string.
603 * @param n The index of the character to access.
604 * @return Read-only (constant) reference to the character.
606 * This operator allows for easy, array-style, data access.
607 * Note that data access with this operator is unchecked and
608 * out_of_range lookups are not defined. (For checked lookups
612 operator[] (size_type __pos) const
614 _GLIBCXX_DEBUG_ASSERT(__pos <= size());
615 return _M_data()[__pos];
619 * @brief Subscript access to the data contained in the %string.
620 * @param n The index of the character to access.
621 * @return Read/write reference to the character.
623 * This operator allows for easy, array-style, data access.
624 * Note that data access with this operator is unchecked and
625 * out_of_range lookups are not defined. (For checked lookups
626 * see at().) Unshares the string.
629 operator[](size_type __pos)
631 _GLIBCXX_DEBUG_ASSERT(__pos < size());
633 return _M_data()[__pos];
637 * @brief Provides access to the data contained in the %string.
638 * @param n The index of the character to access.
639 * @return Read-only (const) reference to the character.
640 * @throw std::out_of_range If @a n is an invalid index.
642 * This function provides for safer data access. The parameter is
643 * first checked that it is in the range of the string. The function
644 * throws out_of_range if the check fails.
647 at(size_type __n) const
649 if (__n >= this->size())
650 __throw_out_of_range(__N("basic_string::at"));
651 return _M_data()[__n];
655 * @brief Provides access to the data contained in the %string.
656 * @param n The index of the character to access.
657 * @return Read/write reference to the character.
658 * @throw std::out_of_range If @a n is an invalid index.
660 * This function provides for safer data access. The parameter is
661 * first checked that it is in the range of the string. The function
662 * throws out_of_range if the check fails. Success results in
663 * unsharing the string.
669 __throw_out_of_range(__N("basic_string::at"));
671 return _M_data()[__n];
676 * @brief Append a string to this string.
677 * @param str The string to append.
678 * @return Reference to this string.
681 operator+=(const basic_string& __str) { return this->append(__str); }
684 * @brief Append a C string.
685 * @param s The C string to append.
686 * @return Reference to this string.
689 operator+=(const _CharT* __s) { return this->append(__s); }
692 * @brief Append a character.
693 * @param s The character to append.
694 * @return Reference to this string.
697 operator+=(_CharT __c) { return this->append(size_type(1), __c); }
700 * @brief Append a string to this string.
701 * @param str The string to append.
702 * @return Reference to this string.
705 append(const basic_string& __str);
708 * @brief Append a substring.
709 * @param str The string to append.
710 * @param pos Index of the first character of str to append.
711 * @param n The number of characters to append.
712 * @return Reference to this string.
713 * @throw std::out_of_range if @a pos is not a valid index.
715 * This function appends @a n characters from @a str starting at @a pos
716 * to this string. If @a n is is larger than the number of available
717 * characters in @a str, the remainder of @a str is appended.
720 append(const basic_string& __str, size_type __pos, size_type __n);
723 * @brief Append a C substring.
724 * @param s The C string to append.
725 * @param n The number of characters to append.
726 * @return Reference to this string.
729 append(const _CharT* __s, size_type __n);
732 * @brief Append a C string.
733 * @param s The C string to append.
734 * @return Reference to this string.
737 append(const _CharT* __s)
739 __glibcxx_requires_string(__s);
740 return this->append(__s, traits_type::length(__s));
744 * @brief Append multiple characters.
745 * @param n The number of characters to append.
746 * @param c The character to use.
747 * @return Reference to this string.
749 * Appends n copies of c to this string.
752 append(size_type __n, _CharT __c)
753 { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
756 * @brief Append a range of characters.
757 * @param first Iterator referencing the first character to append.
758 * @param last Iterator marking the end of the range.
759 * @return Reference to this string.
761 * Appends characters in the range [first,last) to this string.
763 template<class _InputIterator>
765 append(_InputIterator __first, _InputIterator __last)
766 { return this->replace(_M_iend(), _M_iend(), __first, __last); }
769 * @brief Append a single character.
770 * @param c Character to append.
773 push_back(_CharT __c)
774 { this->replace(_M_iend(), _M_iend(), 1, __c); }
777 * @brief Set value to contents of another string.
778 * @param str Source string to use.
779 * @return Reference to this string.
782 assign(const basic_string& __str);
785 * @brief Set value to a substring of a string.
786 * @param str The string to use.
787 * @param pos Index of the first character of str.
788 * @param n Number of characters to use.
789 * @return Reference to this string.
790 * @throw std::out_of_range if @a pos is not a valid index.
792 * This function sets this string to the substring of @a str consisting
793 * of @a n characters at @a pos. If @a n is is larger than the number
794 * of available characters in @a str, the remainder of @a str is used.
797 assign(const basic_string& __str, size_type __pos, size_type __n);
800 * @brief Set value to a C substring.
801 * @param s The C string to use.
802 * @param n Number of characters to use.
803 * @return Reference to this string.
805 * This function sets the value of this string to the first @a n
806 * characters of @a s. If @a n is is larger than the number of
807 * available characters in @a s, the remainder of @a s is used.
810 assign(const _CharT* __s, size_type __n);
813 * @brief Set value to contents of a C string.
814 * @param s The C string to use.
815 * @return Reference to this string.
817 * This function sets the value of this string to the value of @a s.
818 * The data is copied, so there is no dependence on @a s once the
822 assign(const _CharT* __s)
824 __glibcxx_requires_string(__s);
825 return this->assign(__s, traits_type::length(__s));
829 * @brief Set value to multiple characters.
830 * @param n Length of the resulting string.
831 * @param c The character to use.
832 * @return Reference to this string.
834 * This function sets the value of this string to @a n copies of
838 assign(size_type __n, _CharT __c)
839 { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
842 * @brief Set value to a range of characters.
843 * @param first Iterator referencing the first character to append.
844 * @param last Iterator marking the end of the range.
845 * @return Reference to this string.
847 * Sets value of string to characters in the range [first,last).
849 template<class _InputIterator>
851 assign(_InputIterator __first, _InputIterator __last)
852 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
855 * @brief Insert multiple characters.
856 * @param p Iterator referencing location in string to insert at.
857 * @param n Number of characters to insert
858 * @param c The character to insert.
859 * @throw std::length_error If new length exceeds @c max_size().
861 * Inserts @a n copies of character @a c starting at the position
862 * referenced by iterator @a p. If adding characters causes the length
863 * to exceed max_size(), length_error is thrown. The value of the
864 * string doesn't change if an error is thrown.
867 insert(iterator __p, size_type __n, _CharT __c)
868 { this->replace(__p, __p, __n, __c); }
871 * @brief Insert a range of characters.
872 * @param p Iterator referencing location in string to insert at.
873 * @param beg Start of range.
874 * @param end End of range.
875 * @throw std::length_error If new length exceeds @c max_size().
877 * Inserts characters in range [beg,end). If adding characters causes
878 * the length to exceed max_size(), length_error is thrown. The value
879 * of the string doesn't change if an error is thrown.
881 template<class _InputIterator>
882 void insert(iterator __p, _InputIterator __beg, _InputIterator __end)
883 { this->replace(__p, __p, __beg, __end); }
886 * @brief Insert value of a string.
887 * @param pos1 Iterator referencing location in string to insert at.
888 * @param str The string to insert.
889 * @return Reference to this string.
890 * @throw std::length_error If new length exceeds @c max_size().
892 * Inserts value of @a str starting at @a pos1. If adding characters
893 * causes the length to exceed max_size(), length_error is thrown. The
894 * value of the string doesn't change if an error is thrown.
897 insert(size_type __pos1, const basic_string& __str)
898 { return this->insert(__pos1, __str, 0, __str.size()); }
901 * @brief Insert a substring.
902 * @param pos1 Iterator referencing location in string to insert at.
903 * @param str The string to insert.
904 * @param pos2 Start of characters in str to insert.
905 * @param n Number of characters to insert.
906 * @return Reference to this string.
907 * @throw std::length_error If new length exceeds @c max_size().
908 * @throw std::out_of_range If @a pos1 > size() or
909 * @a pos2 > @a str.size().
911 * Starting at @a pos1, insert @a n character of @a str beginning with
912 * @a pos2. If adding characters causes the length to exceed
913 * max_size(), length_error is thrown. If @a pos1 is beyond the end of
914 * this string or @a pos2 is beyond the end of @a str, out_of_range is
915 * thrown. The value of the string doesn't change if an error is
919 insert(size_type __pos1, const basic_string& __str,
920 size_type __pos2, size_type __n);
923 * @brief Insert a C substring.
924 * @param pos Iterator referencing location in string to insert at.
925 * @param s The C string to insert.
926 * @param n The number of characters to insert.
927 * @return Reference to this string.
928 * @throw std::length_error If new length exceeds @c max_size().
929 * @throw std::out_of_range If @a pos is beyond the end of this
932 * Inserts the first @a n characters of @a s starting at @a pos. If
933 * adding characters causes the length to exceed max_size(),
934 * length_error is thrown. If @a pos is beyond end(), out_of_range is
935 * thrown. The value of the string doesn't change if an error is
939 insert(size_type __pos, const _CharT* __s, size_type __n);
942 * @brief Insert a C string.
943 * @param pos Iterator referencing location in string to insert at.
944 * @param s The C string to insert.
945 * @return Reference to this string.
946 * @throw std::length_error If new length exceeds @c max_size().
947 * @throw std::out_of_range If @a pos is beyond the end of this
950 * Inserts the first @a n characters of @a s starting at @a pos. If
951 * adding characters causes the length to exceed max_size(),
952 * length_error is thrown. If @a pos is beyond end(), out_of_range is
953 * thrown. The value of the string doesn't change if an error is
957 insert(size_type __pos, const _CharT* __s)
959 __glibcxx_requires_string(__s);
960 return this->insert(__pos, __s, traits_type::length(__s));
964 * @brief Insert multiple characters.
965 * @param pos Index in string to insert at.
966 * @param n Number of characters to insert
967 * @param c The character to insert.
968 * @return Reference to this string.
969 * @throw std::length_error If new length exceeds @c max_size().
970 * @throw std::out_of_range If @a pos is beyond the end of this
973 * Inserts @a n copies of character @a c starting at index @a pos. If
974 * adding characters causes the length to exceed max_size(),
975 * length_error is thrown. If @a pos > length(), out_of_range is
976 * thrown. The value of the string doesn't change if an error is
980 insert(size_type __pos, size_type __n, _CharT __c)
982 const iterator __iterator = this->_M_ibegin()
983 + _M_check(__pos, "basic_string::insert");
984 return this->replace(__iterator, __iterator, __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->replace(__p, __p, 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_ibegin() + _M_check(__pos, "basic_string::erase"),
1047 _M_ibegin() + __pos + _M_limit(__pos, __n),
1048 _M_data(), _M_data());
1052 * @brief Remove one character.
1053 * @param position Iterator referencing the character to remove.
1054 * @return iterator referencing same location after removal.
1055 * @throw std::out_of_range If @a position is beyond the end of this
1058 * Removes the character at @a position from this string. If @a
1059 * position is beyond end of string, out_of_range is thrown. The value
1060 * of the string doesn't change if an error is thrown.
1063 erase(iterator __position)
1065 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1066 && __position < _M_iend());
1067 const size_type __i = __position - _M_ibegin();
1068 this->replace(__position, __position + 1, _M_data(), _M_data());
1069 _M_rep()->_M_set_leaked();
1070 return _M_ibegin() + __i;
1074 * @brief Remove a range of characters.
1075 * @param first Iterator referencing the first character to remove.
1076 * @param last Iterator referencing the end of the range.
1077 * @return Iterator referencing location of first after removal.
1078 * @throw std::out_of_range If @a first is beyond the end of this
1081 * Removes the characters in the range [first,last) from this string.
1082 * If @a first is beyond end of string, out_of_range is thrown. The
1083 * value of the string doesn't change if an error is thrown.
1086 erase(iterator __first, iterator __last)
1088 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1089 && __last <= _M_iend());
1090 const size_type __i = __first - _M_ibegin();
1091 this->replace(__first, __last, _M_data(), _M_data());
1092 _M_rep()->_M_set_leaked();
1093 return _M_ibegin() + __i;
1097 * @brief Replace characters with value from another string.
1098 * @param pos Index of first character to replace.
1099 * @param n Number of characters to be replaced.
1100 * @param str String to insert.
1101 * @return Reference to this string.
1102 * @throw std::out_of_range If @a pos is beyond the end of this
1104 * @throw std::length_error If new length exceeds @c max_size().
1106 * Removes the characters in the range [pos,pos+n) from this string.
1107 * In place, the value of @a str is inserted. If @a pos is beyond end
1108 * of string, out_of_range is thrown. If the length of the result
1109 * exceeds max_size(), length_error is thrown. The value of the string
1110 * doesn't change if an error is thrown.
1113 replace(size_type __pos, size_type __n, const basic_string& __str)
1114 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1117 * @brief Replace characters with value from another string.
1118 * @param pos1 Index of first character to replace.
1119 * @param n1 Number of characters to be replaced.
1120 * @param str String to insert.
1121 * @param pos2 Index of first character of str to use.
1122 * @param n2 Number of characters from str to use.
1123 * @return Reference to this string.
1124 * @throw std::out_of_range If @a pos1 > size() or @a pos2 >
1126 * @throw std::length_error If new length exceeds @c max_size().
1128 * Removes the characters in the range [pos1,pos1 + n) from this
1129 * string. In place, the value of @a str is inserted. If @a pos is
1130 * beyond end of string, out_of_range is thrown. If the length of the
1131 * result exceeds max_size(), length_error is thrown. The value of the
1132 * string doesn't change if an error is thrown.
1135 replace(size_type __pos1, size_type __n1, const basic_string& __str,
1136 size_type __pos2, size_type __n2);
1139 * @brief Replace characters with value of a C substring.
1140 * @param pos Index of first character to replace.
1141 * @param n1 Number of characters to be replaced.
1142 * @param str C string to insert.
1143 * @param n2 Number of characters from str to use.
1144 * @return Reference to this string.
1145 * @throw std::out_of_range If @a pos1 > size().
1146 * @throw std::length_error If new length exceeds @c max_size().
1148 * Removes the characters in the range [pos,pos + n1) from this string.
1149 * In place, the first @a n2 characters of @a str are inserted, or all
1150 * of @a str if @a n2 is too large. If @a pos is beyond end of string,
1151 * out_of_range is thrown. If the length of result exceeds max_size(),
1152 * length_error is thrown. The value of the string doesn't change if
1153 * an error is thrown.
1156 replace(size_type __pos, size_type __n1, const _CharT* __s,
1160 * @brief Replace characters with value of a C string.
1161 * @param pos Index of first character to replace.
1162 * @param n1 Number of characters to be replaced.
1163 * @param str C string to insert.
1164 * @return Reference to this string.
1165 * @throw std::out_of_range If @a pos > size().
1166 * @throw std::length_error If new length exceeds @c max_size().
1168 * Removes the characters in the range [pos,pos + n1) from this string.
1169 * In place, the first @a n characters of @a str are inserted. If @a
1170 * pos is beyond end of string, out_of_range is thrown. If the length
1171 * of result exceeds max_size(), length_error is thrown. The value of
1172 * the string doesn't change if an error is thrown.
1175 replace(size_type __pos, size_type __n1, const _CharT* __s)
1177 __glibcxx_requires_string(__s);
1178 return this->replace(__pos, __n1, __s, traits_type::length(__s));
1182 * @brief Replace characters with multiple characters.
1183 * @param pos Index of first character to replace.
1184 * @param n1 Number of characters to be replaced.
1185 * @param n2 Number of characters to insert.
1186 * @param c Character to insert.
1187 * @return Reference to this string.
1188 * @throw std::out_of_range If @a pos > size().
1189 * @throw std::length_error If new length exceeds @c max_size().
1191 * Removes the characters in the range [pos,pos + n1) from this string.
1192 * In place, @a n2 copies of @a c are inserted. If @a pos is beyond
1193 * end of string, out_of_range is thrown. If the length of result
1194 * exceeds max_size(), length_error is thrown. The value of the string
1195 * doesn't change if an error is thrown.
1198 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1199 { return this->replace(_M_ibegin() + _M_check(__pos, "basic_string::replace"),
1200 _M_ibegin() + __pos + _M_limit(__pos, __n1),
1204 * @brief Replace range of characters with string.
1205 * @param i1 Iterator referencing start of range to replace.
1206 * @param i2 Iterator referencing end of range to replace.
1207 * @param str String value to insert.
1208 * @return Reference to this string.
1209 * @throw std::length_error If new length exceeds @c max_size().
1211 * Removes the characters in the range [i1,i2). In place, the value of
1212 * @a str is inserted. If the length of result exceeds max_size(),
1213 * length_error is thrown. The value of the string doesn't change if
1214 * an error is thrown.
1217 replace(iterator __i1, iterator __i2, const basic_string& __str)
1219 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1220 && __i2 <= _M_iend());
1221 return this->replace(__i1, __i2, __str._M_data(), __str.size());
1225 * @brief Replace range of characters with C substring.
1226 * @param i1 Iterator referencing start of range to replace.
1227 * @param i2 Iterator referencing end of range to replace.
1228 * @param s C string value to insert.
1229 * @param n Number of characters from s to insert.
1230 * @return Reference to this string.
1231 * @throw std::length_error If new length exceeds @c max_size().
1233 * Removes the characters in the range [i1,i2). In place, the first @a
1234 * n characters of @a s are inserted. If the length of result exceeds
1235 * max_size(), length_error is thrown. The value of the string doesn't
1236 * change if an error is thrown.
1239 replace(iterator __i1, iterator __i2,
1240 const _CharT* __s, size_type __n)
1241 { return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n); }
1244 * @brief Replace range of characters with C string.
1245 * @param i1 Iterator referencing start of range to replace.
1246 * @param i2 Iterator referencing end of range to replace.
1247 * @param s C string value to insert.
1248 * @return Reference to this string.
1249 * @throw std::length_error If new length exceeds @c max_size().
1251 * Removes the characters in the range [i1,i2). In place, the
1252 * characters of @a s are inserted. If the length of result exceeds
1253 * max_size(), length_error is thrown. The value of the string doesn't
1254 * change if an error is thrown.
1257 replace(iterator __i1, iterator __i2, const _CharT* __s)
1259 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1260 && __i2 <= _M_iend());
1261 __glibcxx_requires_string(__s);
1262 return this->replace(__i1, __i2, __s, traits_type::length(__s));
1266 * @brief Replace range of characters with multiple characters
1267 * @param i1 Iterator referencing start of range to replace.
1268 * @param i2 Iterator referencing end of range to replace.
1269 * @param n Number of characters to insert.
1270 * @param c Character to insert.
1271 * @return Reference to this string.
1272 * @throw std::length_error If new length exceeds @c max_size().
1274 * Removes the characters in the range [i1,i2). In place, @a n copies
1275 * of @a c are inserted. If the length of result exceeds max_size(),
1276 * length_error is thrown. The value of the string doesn't change if
1277 * an error is thrown.
1280 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1282 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1283 && __i2 <= _M_iend());
1284 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1288 * @brief Replace range of characters with range.
1289 * @param i1 Iterator referencing start of range to replace.
1290 * @param i2 Iterator referencing end of range to replace.
1291 * @param k1 Iterator referencing start of range to insert.
1292 * @param k2 Iterator referencing end of range to insert.
1293 * @return Reference to this string.
1294 * @throw std::length_error If new length exceeds @c max_size().
1296 * Removes the characters in the range [i1,i2). In place, characters
1297 * in the range [k1,k2) are inserted. If the length of result exceeds
1298 * max_size(), length_error is thrown. The value of the string doesn't
1299 * change if an error is thrown.
1301 template<class _InputIterator>
1303 replace(iterator __i1, iterator __i2,
1304 _InputIterator __k1, _InputIterator __k2)
1306 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1307 && __i2 <= _M_iend());
1308 __glibcxx_requires_valid_range(__k1, __k2);
1309 typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
1310 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1313 // Specializations for the common case of pointer and iterator:
1314 // useful to avoid the overhead of temporary buffering in _M_replace.
1316 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1318 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1319 && __i2 <= _M_iend());
1320 __glibcxx_requires_valid_range(__k1, __k2);
1321 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1326 replace(iterator __i1, iterator __i2,
1327 const _CharT* __k1, const _CharT* __k2)
1329 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1330 && __i2 <= _M_iend());
1331 __glibcxx_requires_valid_range(__k1, __k2);
1332 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1337 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1339 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1340 && __i2 <= _M_iend());
1341 __glibcxx_requires_valid_range(__k1, __k2);
1342 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1343 __k1.base(), __k2 - __k1);
1347 replace(iterator __i1, iterator __i2,
1348 const_iterator __k1, const_iterator __k2)
1350 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1351 && __i2 <= _M_iend());
1352 __glibcxx_requires_valid_range(__k1, __k2);
1353 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1354 __k1.base(), __k2 - __k1);
1358 template<class _Integer>
1360 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1361 _Integer __val, __true_type)
1362 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1364 template<class _InputIterator>
1366 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1367 _InputIterator __k2, __false_type)
1368 { return _M_replace(__i1, __i2, __k1, __k2); }
1371 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, _CharT __c);
1373 template<class _InputIterator>
1375 _M_replace(iterator __i1, iterator __i2, _InputIterator __k1,
1376 _InputIterator __k2);
1379 _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s,
1382 // _S_construct_aux is used to implement the 21.3.1 para 15 which
1383 // requires special behaviour if _InIter is an integral type
1384 template<class _InIterator>
1386 _S_construct_aux(_InIterator __beg, _InIterator __end, const _Alloc& __a,
1389 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
1390 return _S_construct(__beg, __end, __a, _Tag());
1393 template<class _InIterator>
1395 _S_construct_aux(_InIterator __beg, _InIterator __end, const _Alloc& __a,
1398 return _S_construct(static_cast<size_type>(__beg),
1399 static_cast<value_type>(__end), __a);
1402 template<class _InIterator>
1404 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a)
1406 typedef typename _Is_integer<_InIterator>::_Integral _Integral;
1407 return _S_construct_aux(__beg, __end, __a, _Integral());
1410 // For Input Iterators, used in istreambuf_iterators, etc.
1411 template<class _InIterator>
1413 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
1414 input_iterator_tag);
1416 // For forward_iterators up to random_access_iterators, used for
1417 // string::iterator, _CharT*, etc.
1418 template<class _FwdIterator>
1420 _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a,
1421 forward_iterator_tag);
1424 _S_construct(size_type __req, _CharT __c, const _Alloc& __a);
1429 * @brief Copy substring into C string.
1430 * @param s C string to copy value into.
1431 * @param n Number of characters to copy.
1432 * @param pos Index of first character to copy.
1433 * @return Number of characters actually copied
1434 * @throw std::out_of_range If pos > size().
1436 * Copies up to @a n characters starting at @a pos into the C string @a
1437 * s. If @a pos is greater than size(), out_of_range is thrown.
1440 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1443 * @brief Swap contents with another string.
1444 * @param s String to swap with.
1446 * Exchanges the contents of this string with that of @a s in constant
1450 swap(basic_string& __s);
1452 // String operations:
1454 * @brief Return const pointer to null-terminated contents.
1456 * This is a handle to internal data. Do not modify or dire things may
1461 { return _M_data(); }
1464 * @brief Return const pointer to contents.
1466 * This is a handle to internal data. It may not be null-terminated.
1467 * Do not modify or dire things may happen.
1470 data() const { return _M_data(); }
1473 * @brief Return copy of allocator used to construct this string.
1476 get_allocator() const { return _M_dataplus; }
1479 * @brief Find position of a C substring.
1480 * @param s C string to locate.
1481 * @param pos Index of character to search from.
1482 * @param n Number of characters from @a s to search for.
1483 * @return Index of start of first occurrence.
1485 * Starting from @a pos, searches forward for the first @a n characters
1486 * in @a s within this string. If found, returns the index where it
1487 * begins. If not found, returns npos.
1490 find(const _CharT* __s, size_type __pos, size_type __n) const;
1493 * @brief Find position of a string.
1494 * @param str String to locate.
1495 * @param pos Index of character to search from (default 0).
1496 * @return Index of start of first occurrence.
1498 * Starting from @a pos, searches forward for value of @a str within
1499 * this string. If found, returns the index where it begins. If not
1500 * found, returns npos.
1503 find(const basic_string& __str, size_type __pos = 0) const
1504 { return this->find(__str.data(), __pos, __str.size()); }
1507 * @brief Find position of a C string.
1508 * @param s C string to locate.
1509 * @param pos Index of character to search from (default 0).
1510 * @return Index of start of first occurrence.
1512 * Starting from @a pos, searches forward for the value of @a s within
1513 * this string. If found, returns the index where it begins. If not
1514 * found, returns npos.
1517 find(const _CharT* __s, size_type __pos = 0) const
1519 __glibcxx_requires_string(__s);
1520 return this->find(__s, __pos, traits_type::length(__s));
1524 * @brief Find position of a character.
1525 * @param c Character to locate.
1526 * @param pos Index of character to search from (default 0).
1527 * @return Index of first occurrence.
1529 * Starting from @a pos, searches forward for @a c within this string.
1530 * If found, returns the index where it was found. If not found,
1534 find(_CharT __c, size_type __pos = 0) const;
1537 * @brief Find last position of a string.
1538 * @param str String to locate.
1539 * @param pos Index of character to search back from (default end).
1540 * @return Index of start of last occurrence.
1542 * Starting from @a pos, searches backward for value of @a str within
1543 * this string. If found, returns the index where it begins. If not
1544 * found, returns npos.
1547 rfind(const basic_string& __str, size_type __pos = npos) const
1548 { return this->rfind(__str.data(), __pos, __str.size()); }
1551 * @brief Find last position of a C substring.
1552 * @param s C string to locate.
1553 * @param pos Index of character to search back from.
1554 * @param n Number of characters from s to search for.
1555 * @return Index of start of last occurrence.
1557 * Starting from @a pos, searches backward for the first @a n
1558 * characters in @a s within this string. If found, returns the index
1559 * where it begins. If not found, returns npos.
1562 rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1565 * @brief Find last position of a C string.
1566 * @param s C string to locate.
1567 * @param pos Index of character to start search at (default 0).
1568 * @return Index of start of last occurrence.
1570 * Starting from @a pos, searches backward for the value of @a s within
1571 * this string. If found, returns the index where it begins. If not
1572 * found, returns npos.
1575 rfind(const _CharT* __s, size_type __pos = npos) const
1577 __glibcxx_requires_string(__s);
1578 return this->rfind(__s, __pos, traits_type::length(__s));
1582 * @brief Find last position of a character.
1583 * @param c Character to locate.
1584 * @param pos Index of character to search back from (default 0).
1585 * @return Index of last occurrence.
1587 * Starting from @a pos, searches backward for @a c within this string.
1588 * If found, returns the index where it was found. If not found,
1592 rfind(_CharT __c, size_type __pos = npos) const;
1595 * @brief Find position of a character of string.
1596 * @param str String containing characters to locate.
1597 * @param pos Index of character to search from (default 0).
1598 * @return Index of first occurrence.
1600 * Starting from @a pos, searches forward for one of the characters of
1601 * @a str within this string. If found, returns the index where it was
1602 * found. If not found, returns npos.
1605 find_first_of(const basic_string& __str, size_type __pos = 0) const
1606 { return this->find_first_of(__str.data(), __pos, __str.size()); }
1609 * @brief Find position of a character of C substring.
1610 * @param s String containing characters to locate.
1611 * @param pos Index of character to search from (default 0).
1612 * @param n Number of characters from s to search for.
1613 * @return Index of first occurrence.
1615 * Starting from @a pos, searches forward for one of the first @a n
1616 * characters of @a s within this string. If found, returns the index
1617 * where it was found. If not found, returns npos.
1620 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1623 * @brief Find position of a character of C string.
1624 * @param s String containing characters to locate.
1625 * @param pos Index of character to search from (default 0).
1626 * @return Index of first occurrence.
1628 * Starting from @a pos, searches forward for one of the characters of
1629 * @a s within this string. If found, returns the index where it was
1630 * found. If not found, returns npos.
1633 find_first_of(const _CharT* __s, size_type __pos = 0) const
1635 __glibcxx_requires_string(__s);
1636 return this->find_first_of(__s, __pos, traits_type::length(__s));
1640 * @brief Find position of a character.
1641 * @param c Character to locate.
1642 * @param pos Index of character to search from (default 0).
1643 * @return Index of first occurrence.
1645 * Starting from @a pos, searches forward for the character @a c within
1646 * this string. If found, returns the index where it was found. If
1647 * not found, returns npos.
1649 * Note: equivalent to find(c, pos).
1652 find_first_of(_CharT __c, size_type __pos = 0) const
1653 { return this->find(__c, __pos); }
1656 * @brief Find last position of a character of string.
1657 * @param str String containing characters to locate.
1658 * @param pos Index of character to search back from (default end).
1659 * @return Index of last occurrence.
1661 * Starting from @a pos, searches backward for one of the characters of
1662 * @a str within this string. If found, returns the index where it was
1663 * found. If not found, returns npos.
1666 find_last_of(const basic_string& __str, size_type __pos = npos) const
1667 { return this->find_last_of(__str.data(), __pos, __str.size()); }
1670 * @brief Find last position of a character of C substring.
1671 * @param s C string containing characters to locate.
1672 * @param pos Index of character to search back from (default end).
1673 * @param n Number of characters from s to search for.
1674 * @return Index of last occurrence.
1676 * Starting from @a pos, searches backward for one of the first @a n
1677 * characters of @a s within this string. If found, returns the index
1678 * where it was found. If not found, returns npos.
1681 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1684 * @brief Find last position of a character of C string.
1685 * @param s C string containing characters to locate.
1686 * @param pos Index of character to search back from (default end).
1687 * @return Index of last occurrence.
1689 * Starting from @a pos, searches backward for one of the characters of
1690 * @a s within this string. If found, returns the index where it was
1691 * found. If not found, returns npos.
1694 find_last_of(const _CharT* __s, size_type __pos = npos) const
1696 __glibcxx_requires_string(__s);
1697 return this->find_last_of(__s, __pos, traits_type::length(__s));
1701 * @brief Find last position of a character.
1702 * @param c Character to locate.
1703 * @param pos Index of character to search back from (default 0).
1704 * @return Index of last occurrence.
1706 * Starting from @a pos, searches backward for @a c within this string.
1707 * If found, returns the index where it was found. If not found,
1710 * Note: equivalent to rfind(c, pos).
1713 find_last_of(_CharT __c, size_type __pos = npos) const
1714 { return this->rfind(__c, __pos); }
1717 * @brief Find position of a character not in string.
1718 * @param str String containing characters to avoid.
1719 * @param pos Index of character to search from (default 0).
1720 * @return Index of first occurrence.
1722 * Starting from @a pos, searches forward for a character not contained
1723 * in @a str within this string. If found, returns the index where it
1724 * was found. If not found, returns npos.
1727 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
1728 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1731 * @brief Find position of a character not in C substring.
1732 * @param s C string containing characters to avoid.
1733 * @param pos Index of character to search from (default 0).
1734 * @param n Number of characters from s to consider.
1735 * @return Index of first occurrence.
1737 * Starting from @a pos, searches forward for a character not contained
1738 * in the first @a n characters of @a s within this string. If found,
1739 * returns the index where it was found. If not found, returns npos.
1742 find_first_not_of(const _CharT* __s, size_type __pos,
1743 size_type __n) const;
1746 * @brief Find position of a character not in C string.
1747 * @param s C string containing characters to avoid.
1748 * @param pos Index of character to search from (default 0).
1749 * @return Index of first occurrence.
1751 * Starting from @a pos, searches forward for a character not contained
1752 * in @a s within this string. If found, returns the index where it
1753 * was found. If not found, returns npos.
1756 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1758 __glibcxx_requires_string(__s);
1759 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1763 * @brief Find position of a different character.
1764 * @param c Character to avoid.
1765 * @param pos Index of character to search from (default 0).
1766 * @return Index of first occurrence.
1768 * Starting from @a pos, searches forward for a character other than @a c
1769 * within this string. If found, returns the index where it was found.
1770 * If not found, returns npos.
1773 find_first_not_of(_CharT __c, size_type __pos = 0) const;
1776 * @brief Find last position of a character not in string.
1777 * @param str String containing characters to avoid.
1778 * @param pos Index of character to search from (default 0).
1779 * @return Index of first occurrence.
1781 * Starting from @a pos, searches backward for a character not
1782 * contained in @a str within this string. If found, returns the index
1783 * where it was found. If not found, returns npos.
1786 find_last_not_of(const basic_string& __str, size_type __pos = npos) const
1787 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1790 * @brief Find last position of a character not in C substring.
1791 * @param s C string containing characters to avoid.
1792 * @param pos Index of character to search from (default 0).
1793 * @param n Number of characters from s to consider.
1794 * @return Index of first occurrence.
1796 * Starting from @a pos, searches backward for a character not
1797 * contained in the first @a n characters of @a s within this string.
1798 * If found, returns the index where it was found. If not found,
1802 find_last_not_of(const _CharT* __s, size_type __pos,
1803 size_type __n) const;
1805 * @brief Find position of a character not in C string.
1806 * @param s C string containing characters to avoid.
1807 * @param pos Index of character to search from (default 0).
1808 * @return Index of first occurrence.
1810 * Starting from @a pos, searches backward for a character not
1811 * contained in @a s within this string. If found, returns the index
1812 * where it was found. If not found, returns npos.
1815 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1817 __glibcxx_requires_string(__s);
1818 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1822 * @brief Find last position of a different character.
1823 * @param c Character to avoid.
1824 * @param pos Index of character to search from (default 0).
1825 * @return Index of first occurrence.
1827 * Starting from @a pos, searches backward for a character other than
1828 * @a c within this string. If found, returns the index where it was
1829 * found. If not found, returns npos.
1832 find_last_not_of(_CharT __c, size_type __pos = npos) const;
1835 * @brief Get a substring.
1836 * @param pos Index of first character (default 0).
1837 * @param n Number of characters in substring (default remainder).
1838 * @return The new string.
1839 * @throw std::out_of_range If pos > size().
1841 * Construct and return a new string using the @a n characters starting
1842 * at @a pos. If the string is too short, use the remainder of the
1843 * characters. If @a pos is beyond the end of the string, out_of_range
1847 substr(size_type __pos = 0, size_type __n = npos) const
1848 { return basic_string(*this, _M_check(__pos, "basic_string::substr"), __n); }
1851 * @brief Compare to a string.
1852 * @param str String to compare against.
1853 * @return Integer < 0, 0, or > 0.
1855 * Returns an integer < 0 if this string is ordered before @a str, 0 if
1856 * their values are equivalent, or > 0 if this string is ordered after
1857 * @a str. If the lengths of @a str and this string are different, the
1858 * shorter one is ordered first. If they are the same, returns the
1859 * result of traits::compare(data(),str.data(),size());
1862 compare(const basic_string& __str) const
1864 const size_type __size = this->size();
1865 const size_type __osize = __str.size();
1866 const size_type __len = std::min(__size, __osize);
1868 int __r = traits_type::compare(_M_data(), __str.data(), __len);
1870 __r = __size - __osize;
1875 * @brief Compare substring to a string.
1876 * @param pos Index of first character of substring.
1877 * @param n Number of characters in substring.
1878 * @param str String to compare against.
1879 * @return Integer < 0, 0, or > 0.
1881 * Form the substring of this string from the @a n characters starting
1882 * at @a pos. Returns an integer < 0 if the substring is ordered
1883 * before @a str, 0 if their values are equivalent, or > 0 if the
1884 * substring is ordered after @a str. If the lengths @a of str and the
1885 * substring are different, the shorter one is ordered first. If they
1886 * are the same, returns the result of
1887 * traits::compare(substring.data(),str.data(),size());
1890 compare(size_type __pos, size_type __n, const basic_string& __str) const;
1893 * @brief Compare substring to a substring.
1894 * @param pos1 Index of first character of substring.
1895 * @param n1 Number of characters in substring.
1896 * @param str String to compare against.
1897 * @param pos2 Index of first character of substring of str.
1898 * @param n2 Number of characters in substring of str.
1899 * @return Integer < 0, 0, or > 0.
1901 * Form the substring of this string from the @a n1 characters starting
1902 * at @a pos1. Form the substring of @a str from the @a n2 characters
1903 * starting at @a pos2. Returns an integer < 0 if this substring is
1904 * ordered before the substring of @a str, 0 if their values are
1905 * equivalent, or > 0 if this substring is ordered after the substring
1906 * of @a str. If the lengths of the substring of @a str and this
1907 * substring are different, the shorter one is ordered first. If they
1908 * are the same, returns the result of
1909 * traits::compare(substring.data(),str.substr(pos2,n2).data(),size());
1912 compare(size_type __pos1, size_type __n1, const basic_string& __str,
1913 size_type __pos2, size_type __n2) const;
1916 * @brief Compare to a C string.
1917 * @param s C string to compare against.
1918 * @return Integer < 0, 0, or > 0.
1920 * Returns an integer < 0 if this string is ordered before @a s, 0 if
1921 * their values are equivalent, or > 0 if this string is ordered after
1922 * @a s. If the lengths of @a s and this string are different, the
1923 * shorter one is ordered first. If they are the same, returns the
1924 * result of traits::compare(data(),s,size());
1927 compare(const _CharT* __s) const;
1929 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1930 // 5 String::compare specification questionable
1932 * @brief Compare substring to a C string.
1933 * @param pos Index of first character of substring.
1934 * @param n1 Number of characters in substring.
1935 * @param s C string to compare against.
1936 * @return Integer < 0, 0, or > 0.
1938 * Form the substring of this string from the @a n1 characters starting
1939 * at @a pos. Returns an integer < 0 if the substring is ordered
1940 * before @a s, 0 if their values are equivalent, or > 0 if the
1941 * substring is ordered after @a s. If the lengths of @a s and the
1942 * substring are different, the shorter one is ordered first. If they
1943 * are the same, returns the result of
1944 * traits::compare(substring.data(),s,size());
1947 compare(size_type __pos, size_type __n1, const _CharT* __s) const;
1950 * @brief Compare substring against a character array.
1951 * @param pos1 Index of first character of substring.
1952 * @param n1 Number of characters in substring.
1953 * @param s character array to compare against.
1954 * @param n2 Number of characters of s.
1955 * @return Integer < 0, 0, or > 0.
1957 * Form the substring of this string from the @a n1 characters starting
1958 * at @a pos1. Form a string from the first @a n2 characters of @a s.
1959 * Returns an integer < 0 if this substring is ordered before the string
1960 * from @a s, 0 if their values are equivalent, or > 0 if this substring
1961 * is ordered after the string from @a s. If the lengths of this substring
1962 * and @a n2 are different, the shorter one is ordered first. If they are
1963 * the same, returns the result of traits::compare(substring.data(),s,size());
1965 * NB: s must have at least n2 characters, '\0' has no special
1969 compare(size_type __pos, size_type __n1, const _CharT* __s,
1970 size_type __n2) const;
1974 template<typename _CharT, typename _Traits, typename _Alloc>
1975 inline basic_string<_CharT, _Traits, _Alloc>::
1977 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
1981 * @brief Concatenate two strings.
1982 * @param lhs First string.
1983 * @param rhs Last string.
1984 * @return New string with value of @a lhs followed by @a rhs.
1986 template<typename _CharT, typename _Traits, typename _Alloc>
1987 basic_string<_CharT, _Traits, _Alloc>
1988 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
1989 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
1991 basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
1992 __str.append(__rhs);
1997 * @brief Concatenate C string and string.
1998 * @param lhs First string.
1999 * @param rhs Last string.
2000 * @return New string with value of @a lhs followed by @a rhs.
2002 template<typename _CharT, typename _Traits, typename _Alloc>
2003 basic_string<_CharT,_Traits,_Alloc>
2004 operator+(const _CharT* __lhs,
2005 const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2008 * @brief Concatenate character and string.
2009 * @param lhs First string.
2010 * @param rhs Last string.
2011 * @return New string with @a lhs followed by @a rhs.
2013 template<typename _CharT, typename _Traits, typename _Alloc>
2014 basic_string<_CharT,_Traits,_Alloc>
2015 operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2018 * @brief Concatenate string and C string.
2019 * @param lhs First string.
2020 * @param rhs Last string.
2021 * @return New string with @a lhs followed by @a rhs.
2023 template<typename _CharT, typename _Traits, typename _Alloc>
2024 inline basic_string<_CharT, _Traits, _Alloc>
2025 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2026 const _CharT* __rhs)
2028 basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
2029 __str.append(__rhs);
2034 * @brief Concatenate string and character.
2035 * @param lhs First string.
2036 * @param rhs Last string.
2037 * @return New string with @a lhs followed by @a rhs.
2039 template<typename _CharT, typename _Traits, typename _Alloc>
2040 inline basic_string<_CharT, _Traits, _Alloc>
2041 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
2043 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
2044 typedef typename __string_type::size_type __size_type;
2045 __string_type __str(__lhs);
2046 __str.append(__size_type(1), __rhs);
2052 * @brief Test equivalence of two strings.
2053 * @param lhs First string.
2054 * @param rhs Second string.
2055 * @return True if @a lhs.compare(@a rhs) == 0. False otherwise.
2057 template<typename _CharT, typename _Traits, typename _Alloc>
2059 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2060 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2061 { return __lhs.compare(__rhs) == 0; }
2064 * @brief Test equivalence of C string and string.
2065 * @param lhs C string.
2066 * @param rhs String.
2067 * @return True if @a rhs.compare(@a lhs) == 0. False otherwise.
2069 template<typename _CharT, typename _Traits, typename _Alloc>
2071 operator==(const _CharT* __lhs,
2072 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2073 { return __rhs.compare(__lhs) == 0; }
2076 * @brief Test equivalence of string and C string.
2077 * @param lhs String.
2078 * @param rhs C string.
2079 * @return True if @a lhs.compare(@a rhs) == 0. False otherwise.
2081 template<typename _CharT, typename _Traits, typename _Alloc>
2083 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2084 const _CharT* __rhs)
2085 { return __lhs.compare(__rhs) == 0; }
2089 * @brief Test difference of two strings.
2090 * @param lhs First string.
2091 * @param rhs Second string.
2092 * @return True if @a lhs.compare(@a rhs) != 0. False otherwise.
2094 template<typename _CharT, typename _Traits, typename _Alloc>
2096 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2097 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2098 { return __rhs.compare(__lhs) != 0; }
2101 * @brief Test difference of C string and string.
2102 * @param lhs C string.
2103 * @param rhs String.
2104 * @return True if @a rhs.compare(@a lhs) != 0. False otherwise.
2106 template<typename _CharT, typename _Traits, typename _Alloc>
2108 operator!=(const _CharT* __lhs,
2109 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2110 { return __rhs.compare(__lhs) != 0; }
2113 * @brief Test difference of string and C string.
2114 * @param lhs String.
2115 * @param rhs C string.
2116 * @return True if @a lhs.compare(@a rhs) != 0. False otherwise.
2118 template<typename _CharT, typename _Traits, typename _Alloc>
2120 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2121 const _CharT* __rhs)
2122 { return __lhs.compare(__rhs) != 0; }
2126 * @brief Test if string precedes string.
2127 * @param lhs First string.
2128 * @param rhs Second string.
2129 * @return True if @a lhs precedes @a rhs. False otherwise.
2131 template<typename _CharT, typename _Traits, typename _Alloc>
2133 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2134 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2135 { return __lhs.compare(__rhs) < 0; }
2138 * @brief Test if string precedes C string.
2139 * @param lhs String.
2140 * @param rhs C string.
2141 * @return True if @a lhs precedes @a rhs. False otherwise.
2143 template<typename _CharT, typename _Traits, typename _Alloc>
2145 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2146 const _CharT* __rhs)
2147 { return __lhs.compare(__rhs) < 0; }
2150 * @brief Test if C string precedes string.
2151 * @param lhs C string.
2152 * @param rhs String.
2153 * @return True if @a lhs precedes @a rhs. False otherwise.
2155 template<typename _CharT, typename _Traits, typename _Alloc>
2157 operator<(const _CharT* __lhs,
2158 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2159 { return __rhs.compare(__lhs) > 0; }
2163 * @brief Test if string follows string.
2164 * @param lhs First string.
2165 * @param rhs Second string.
2166 * @return True if @a lhs follows @a rhs. False otherwise.
2168 template<typename _CharT, typename _Traits, typename _Alloc>
2170 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2171 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2172 { return __lhs.compare(__rhs) > 0; }
2175 * @brief Test if string follows C string.
2176 * @param lhs String.
2177 * @param rhs C string.
2178 * @return True if @a lhs follows @a rhs. False otherwise.
2180 template<typename _CharT, typename _Traits, typename _Alloc>
2182 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2183 const _CharT* __rhs)
2184 { return __lhs.compare(__rhs) > 0; }
2187 * @brief Test if C string follows string.
2188 * @param lhs C string.
2189 * @param rhs String.
2190 * @return True if @a lhs follows @a rhs. False otherwise.
2192 template<typename _CharT, typename _Traits, typename _Alloc>
2194 operator>(const _CharT* __lhs,
2195 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2196 { return __rhs.compare(__lhs) < 0; }
2200 * @brief Test if string doesn't follow string.
2201 * @param lhs First string.
2202 * @param rhs Second string.
2203 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2205 template<typename _CharT, typename _Traits, typename _Alloc>
2207 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2208 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2209 { return __lhs.compare(__rhs) <= 0; }
2212 * @brief Test if string doesn't follow C string.
2213 * @param lhs String.
2214 * @param rhs C string.
2215 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2217 template<typename _CharT, typename _Traits, typename _Alloc>
2219 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2220 const _CharT* __rhs)
2221 { return __lhs.compare(__rhs) <= 0; }
2224 * @brief Test if C string doesn't follow string.
2225 * @param lhs C string.
2226 * @param rhs String.
2227 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2229 template<typename _CharT, typename _Traits, typename _Alloc>
2231 operator<=(const _CharT* __lhs,
2232 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2233 { return __rhs.compare(__lhs) >= 0; }
2237 * @brief Test if string doesn't precede string.
2238 * @param lhs First string.
2239 * @param rhs Second string.
2240 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2242 template<typename _CharT, typename _Traits, typename _Alloc>
2244 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2245 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2246 { return __lhs.compare(__rhs) >= 0; }
2249 * @brief Test if string doesn't precede C string.
2250 * @param lhs String.
2251 * @param rhs C string.
2252 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2254 template<typename _CharT, typename _Traits, typename _Alloc>
2256 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2257 const _CharT* __rhs)
2258 { return __lhs.compare(__rhs) >= 0; }
2261 * @brief Test if C string doesn't precede string.
2262 * @param lhs C string.
2263 * @param rhs String.
2264 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2266 template<typename _CharT, typename _Traits, typename _Alloc>
2268 operator>=(const _CharT* __lhs,
2269 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2270 { return __rhs.compare(__lhs) <= 0; }
2273 * @brief Swap contents of two strings.
2274 * @param lhs First string.
2275 * @param rhs Second string.
2277 * Exchanges the contents of @a lhs and @a rhs in constant time.
2279 template<typename _CharT, typename _Traits, typename _Alloc>
2281 swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
2282 basic_string<_CharT, _Traits, _Alloc>& __rhs)
2283 { __lhs.swap(__rhs); }
2286 * @brief Read stream into a string.
2287 * @param is Input stream.
2288 * @param str Buffer to store into.
2289 * @return Reference to the input stream.
2291 * Stores characters from @a is into @a str until whitespace is found, the
2292 * end of the stream is encountered, or str.max_size() is reached. If
2293 * is.width() is non-zero, that is the limit on the number of characters
2294 * stored into @a str. Any previous contents of @a str are erased.
2296 template<typename _CharT, typename _Traits, typename _Alloc>
2297 basic_istream<_CharT, _Traits>&
2298 operator>>(basic_istream<_CharT, _Traits>& __is,
2299 basic_string<_CharT, _Traits, _Alloc>& __str);
2302 * @brief Write string to a stream.
2303 * @param os Output stream.
2304 * @param str String to write out.
2305 * @return Reference to the output stream.
2307 * Output characters of @a str into os following the same rules as for
2308 * writing a C string.
2310 template<typename _CharT, typename _Traits, typename _Alloc>
2311 basic_ostream<_CharT, _Traits>&
2312 operator<<(basic_ostream<_CharT, _Traits>& __os,
2313 const basic_string<_CharT, _Traits, _Alloc>& __str);
2316 * @brief Read a line from stream into a string.
2317 * @param is Input stream.
2318 * @param str Buffer to store into.
2319 * @param delim Character marking end of line.
2320 * @return Reference to the input stream.
2322 * Stores characters from @a is into @a str until @a delim is found, the
2323 * end of the stream is encountered, or str.max_size() is reached. If
2324 * is.width() is non-zero, that is the limit on the number of characters
2325 * stored into @a str. Any previous contents of @a str are erased. If @a
2326 * delim was encountered, it is extracted but not stored into @a str.
2328 template<typename _CharT, typename _Traits, typename _Alloc>
2329 basic_istream<_CharT,_Traits>&
2330 getline(basic_istream<_CharT, _Traits>& __is,
2331 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
2334 * @brief Read a line from stream into a string.
2335 * @param is Input stream.
2336 * @param str Buffer to store into.
2337 * @return Reference to the input stream.
2339 * Stores characters from is into @a str until '\n' is found, the end of
2340 * the stream is encountered, or str.max_size() is reached. If is.width()
2341 * is non-zero, that is the limit on the number of characters stored into
2342 * @a str. Any previous contents of @a str are erased. If end of line was
2343 * encountered, it is extracted but not stored into @a str.
2345 template<typename _CharT, typename _Traits, typename _Alloc>
2346 inline basic_istream<_CharT,_Traits>&
2347 getline(basic_istream<_CharT, _Traits>& __is,
2348 basic_string<_CharT, _Traits, _Alloc>& __str);
2351 #endif /* _BASIC_STRING_H */