1 // Components for manipulating sequences of characters -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 // 2006, 2007, 2008, 2009, 2010, 2011
5 // Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // Under Section 7 of GPL version 3, you are granted additional
19 // permissions described in the GCC Runtime Library Exception, version
20 // 3.1, as published by the Free Software Foundation.
22 // You should have received a copy of the GNU General Public License and
23 // a copy of the GCC Runtime Library Exception along with this program;
24 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 // <http://www.gnu.org/licenses/>.
27 /** @file bits/basic_string.h
28 * This is an internal header file, included by other library headers.
29 * Do not attempt to use it directly. @headername{string}
33 // ISO C++ 14882: 21 Strings library
36 #ifndef _BASIC_STRING_H
37 #define _BASIC_STRING_H 1
39 #pragma GCC system_header
41 #include <ext/atomicity.h>
42 #include <debug/debug.h>
43 #ifdef __GXX_EXPERIMENTAL_CXX0X__
44 #include <initializer_list>
47 namespace std
_GLIBCXX_VISIBILITY(default)
49 _GLIBCXX_BEGIN_NAMESPACE_VERSION
52 * @class basic_string basic_string.h <string>
53 * @brief Managing sequences of characters and character-like objects.
58 * Meets the requirements of a <a href="tables.html#65">container</a>, a
59 * <a href="tables.html#66">reversible container</a>, and a
60 * <a href="tables.html#67">sequence</a>. Of the
61 * <a href="tables.html#68">optional sequence requirements</a>, only
62 * @c push_back, @c at, and @c %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 @a 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 <em>empty string</em> _Rep object already @a 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.
107 // 21.3 Template class basic_string
108 template<typename _CharT
, typename _Traits
, typename _Alloc
>
111 typedef typename
_Alloc::template rebind
<_CharT
>::other _CharT_alloc_type
;
115 typedef _Traits traits_type
;
116 typedef typename
_Traits::char_type value_type
;
117 typedef _Alloc allocator_type
;
118 typedef typename
_CharT_alloc_type::size_type size_type
;
119 typedef typename
_CharT_alloc_type::difference_type difference_type
;
120 typedef typename
_CharT_alloc_type::reference reference
;
121 typedef typename
_CharT_alloc_type::const_reference const_reference
;
122 typedef typename
_CharT_alloc_type::pointer pointer
;
123 typedef typename
_CharT_alloc_type::const_pointer const_pointer
;
124 typedef __gnu_cxx::__normal_iterator
<pointer
, basic_string
> iterator
;
125 typedef __gnu_cxx::__normal_iterator
<const_pointer
, basic_string
>
127 typedef std::reverse_iterator
<const_iterator
> const_reverse_iterator
;
128 typedef std::reverse_iterator
<iterator
> reverse_iterator
;
131 // _Rep: string representation
133 // 1. String really contains _M_length + 1 characters: due to 21.3.4
134 // must be kept null-terminated.
135 // 2. _M_capacity >= _M_length
136 // Allocated memory is always (_M_capacity + 1) * sizeof(_CharT).
137 // 3. _M_refcount has three states:
138 // -1: leaked, one reference, no ref-copies allowed, non-const.
139 // 0: one reference, non-const.
140 // n>0: n + 1 references, operations require a lock, const.
141 // 4. All fields==0 is an empty string, given the extra storage
142 // beyond-the-end for a null terminator; thus, the shared
143 // empty string representation needs no constructor.
148 size_type _M_capacity
;
149 _Atomic_word _M_refcount
;
152 struct _Rep
: _Rep_base
155 typedef typename
_Alloc::template rebind
<char>::other _Raw_bytes_alloc
;
157 // (Public) Data members:
159 // The maximum number of individual char_type elements of an
160 // individual string is determined by _S_max_size. This is the
161 // value that will be returned by max_size(). (Whereas npos
162 // is the maximum number of bytes the allocator can allocate.)
163 // If one was to divvy up the theoretical largest size string,
164 // with a terminating character and m _CharT elements, it'd
166 // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
168 // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
169 // In addition, this implementation quarters this amount.
170 static const size_type _S_max_size
;
171 static const _CharT _S_terminal
;
173 // The following storage is init'd to 0 by the linker, resulting
174 // (carefully) in an empty string with one reference.
175 static size_type _S_empty_rep_storage
[];
180 // NB: Mild hack to avoid strict-aliasing warnings. Note that
181 // _S_empty_rep_storage is never modified and the punning should
182 // be reasonably safe in this case.
183 void* __p
= reinterpret_cast<void*>(&_S_empty_rep_storage
);
184 return *reinterpret_cast<_Rep
*>(__p
);
189 { return this->_M_refcount
< 0; }
193 { return this->_M_refcount
> 0; }
197 { this->_M_refcount
= -1; }
201 { this->_M_refcount
= 0; }
204 _M_set_length_and_sharable(size_type __n
)
206 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
207 if (__builtin_expect(this != &_S_empty_rep(), false))
210 this->_M_set_sharable(); // One reference.
211 this->_M_length
= __n
;
212 traits_type::assign(this->_M_refdata()[__n
], _S_terminal
);
213 // grrr. (per 21.3.4)
214 // You cannot leave those LWG people alone for a second.
220 { return reinterpret_cast<_CharT
*>(this + 1); }
223 _M_grab(const _Alloc
& __alloc1
, const _Alloc
& __alloc2
)
225 return (!_M_is_leaked() && __alloc1
== __alloc2
)
226 ? _M_refcopy() : _M_clone(__alloc1
);
231 _S_create(size_type
, size_type
, const _Alloc
&);
234 _M_dispose(const _Alloc
& __a
)
236 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
237 if (__builtin_expect(this != &_S_empty_rep(), false))
240 // Be race-detector-friendly. For more info see bits/c++config.
241 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount
);
242 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount
,
245 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount
);
252 _M_destroy(const _Alloc
&) throw();
257 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
258 if (__builtin_expect(this != &_S_empty_rep(), false))
260 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount
, 1);
265 _M_clone(const _Alloc
&, size_type __res
= 0);
268 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
269 struct _Alloc_hider
: _Alloc
271 _Alloc_hider(_CharT
* __dat
, const _Alloc
& __a
)
272 : _Alloc(__a
), _M_p(__dat
) { }
274 _CharT
* _M_p
; // The actual data.
278 // Data Members (public):
279 // NB: This is an unsigned type, and thus represents the maximum
280 // size that the allocator can hold.
281 /// Value returned by various member functions when they fail.
282 static const size_type npos
= static_cast<size_type
>(-1);
285 // Data Members (private):
286 mutable _Alloc_hider _M_dataplus
;
290 { return _M_dataplus
._M_p
; }
294 { return (_M_dataplus
._M_p
= __p
); }
298 { return &((reinterpret_cast<_Rep
*> (_M_data()))[-1]); }
300 // For the internal use we have functions similar to `begin'/`end'
301 // but they do not call _M_leak.
304 { return iterator(_M_data()); }
308 { return iterator(_M_data() + this->size()); }
311 _M_leak() // for use in begin() & non-const op[]
313 if (!_M_rep()->_M_is_leaked())
318 _M_check(size_type __pos
, const char* __s
) const
320 if (__pos
> this->size())
321 __throw_out_of_range(__N(__s
));
326 _M_check_length(size_type __n1
, size_type __n2
, const char* __s
) const
328 if (this->max_size() - (this->size() - __n1
) < __n2
)
329 __throw_length_error(__N(__s
));
332 // NB: _M_limit doesn't check for a bad __pos value.
334 _M_limit(size_type __pos
, size_type __off
) const
336 const bool __testoff
= __off
< this->size() - __pos
;
337 return __testoff
? __off
: this->size() - __pos
;
340 // True if _Rep and source do not overlap.
342 _M_disjunct(const _CharT
* __s
) const
344 return (less
<const _CharT
*>()(__s
, _M_data())
345 || less
<const _CharT
*>()(_M_data() + this->size(), __s
));
348 // When __n = 1 way faster than the general multichar
349 // traits_type::copy/move/assign.
351 _M_copy(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
354 traits_type::assign(*__d
, *__s
);
356 traits_type::copy(__d
, __s
, __n
);
360 _M_move(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
363 traits_type::assign(*__d
, *__s
);
365 traits_type::move(__d
, __s
, __n
);
369 _M_assign(_CharT
* __d
, size_type __n
, _CharT __c
)
372 traits_type::assign(*__d
, __c
);
374 traits_type::assign(__d
, __n
, __c
);
377 // _S_copy_chars is a separate template to permit specialization
378 // to optimize for the common case of pointers as iterators.
379 template<class _Iterator
>
381 _S_copy_chars(_CharT
* __p
, _Iterator __k1
, _Iterator __k2
)
383 for (; __k1
!= __k2
; ++__k1
, ++__p
)
384 traits_type::assign(*__p
, *__k1
); // These types are off.
388 _S_copy_chars(_CharT
* __p
, iterator __k1
, iterator __k2
)
389 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
392 _S_copy_chars(_CharT
* __p
, const_iterator __k1
, const_iterator __k2
)
393 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
396 _S_copy_chars(_CharT
* __p
, _CharT
* __k1
, _CharT
* __k2
)
397 { _M_copy(__p
, __k1
, __k2
- __k1
); }
400 _S_copy_chars(_CharT
* __p
, const _CharT
* __k1
, const _CharT
* __k2
)
401 { _M_copy(__p
, __k1
, __k2
- __k1
); }
404 _S_compare(size_type __n1
, size_type __n2
)
406 const difference_type __d
= difference_type(__n1
- __n2
);
408 if (__d
> __gnu_cxx::__numeric_traits
<int>::__max
)
409 return __gnu_cxx::__numeric_traits
<int>::__max
;
410 else if (__d
< __gnu_cxx::__numeric_traits
<int>::__min
)
411 return __gnu_cxx::__numeric_traits
<int>::__min
;
417 _M_mutate(size_type __pos
, size_type __len1
, size_type __len2
);
424 { return _Rep::_S_empty_rep(); }
427 // Construct/copy/destroy:
428 // NB: We overload ctors in some cases instead of using default
429 // arguments, per 17.4.4.4 para. 2 item 2.
432 * @brief Default constructor creates an empty string.
435 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
436 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
438 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()){ }
442 * @brief Construct an empty string using allocator @a a.
445 basic_string(const _Alloc
& __a
);
447 // NB: per LWG issue 42, semantics different from IS:
449 * @brief Construct string with copy of value of @a str.
450 * @param __str Source string.
452 basic_string(const basic_string
& __str
);
454 * @brief Construct string as copy of a substring.
455 * @param __str Source string.
456 * @param __pos Index of first character to copy from.
457 * @param __n Number of characters to copy (default remainder).
459 basic_string(const basic_string
& __str
, size_type __pos
,
460 size_type __n
= npos
);
462 * @brief Construct string as copy of a substring.
463 * @param __str Source string.
464 * @param __pos Index of first character to copy from.
465 * @param __n Number of characters to copy.
466 * @param __a Allocator to use.
468 basic_string(const basic_string
& __str
, size_type __pos
,
469 size_type __n
, const _Alloc
& __a
);
472 * @brief Construct string initialized by a character %array.
473 * @param __s Source character %array.
474 * @param __n Number of characters to copy.
475 * @param __a Allocator to use (default is default allocator).
477 * NB: @a __s must have at least @a __n characters, '\\0'
478 * has no special meaning.
480 basic_string(const _CharT
* __s
, size_type __n
,
481 const _Alloc
& __a
= _Alloc());
483 * @brief Construct string as copy of a C string.
484 * @param __s Source C string.
485 * @param __a Allocator to use (default is default allocator).
487 basic_string(const _CharT
* __s
, const _Alloc
& __a
= _Alloc());
489 * @brief Construct string as multiple characters.
490 * @param __n Number of characters.
491 * @param __c Character to use.
492 * @param __a Allocator to use (default is default allocator).
494 basic_string(size_type __n
, _CharT __c
, const _Alloc
& __a
= _Alloc());
496 #ifdef __GXX_EXPERIMENTAL_CXX0X__
498 * @brief Move construct string.
499 * @param __str Source string.
501 * The newly-created string contains the exact contents of @a __str.
502 * @a __str is a valid, but unspecified string.
504 basic_string(basic_string
&& __str
) noexcept
505 : _M_dataplus(__str
._M_dataplus
)
507 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
508 __str
._M_data(_S_empty_rep()._M_refdata());
510 __str
._M_data(_S_construct(size_type(), _CharT(), get_allocator()));
515 * @brief Construct string from an initializer %list.
516 * @param __l std::initializer_list of characters.
517 * @param __a Allocator to use (default is default allocator).
519 basic_string(initializer_list
<_CharT
> __l
, const _Alloc
& __a
= _Alloc());
520 #endif // __GXX_EXPERIMENTAL_CXX0X__
523 * @brief Construct string as copy of a range.
524 * @param __beg Start of range.
525 * @param __end End of range.
526 * @param __a Allocator to use (default is default allocator).
528 template<class _InputIterator
>
529 basic_string(_InputIterator __beg
, _InputIterator __end
,
530 const _Alloc
& __a
= _Alloc());
533 * @brief Destroy the string instance.
535 ~basic_string() _GLIBCXX_NOEXCEPT
536 { _M_rep()->_M_dispose(this->get_allocator()); }
539 * @brief Assign the value of @a str to this string.
540 * @param __str Source string.
543 operator=(const basic_string
& __str
)
544 { return this->assign(__str
); }
547 * @brief Copy contents of @a s into this string.
548 * @param __s Source null-terminated string.
551 operator=(const _CharT
* __s
)
552 { return this->assign(__s
); }
555 * @brief Set value to string of length 1.
556 * @param __c Source character.
558 * Assigning to a character makes this string length 1 and
559 * (*this)[0] == @a c.
562 operator=(_CharT __c
)
564 this->assign(1, __c
);
568 #ifdef __GXX_EXPERIMENTAL_CXX0X__
570 * @brief Move assign the value of @a str to this string.
571 * @param __str Source string.
573 * The contents of @a str are moved into this string (without copying).
574 * @a str is a valid, but unspecified string.
577 operator=(basic_string
&& __str
)
585 * @brief Set value to string constructed from initializer %list.
586 * @param __l std::initializer_list.
589 operator=(initializer_list
<_CharT
> __l
)
591 this->assign(__l
.begin(), __l
.size());
594 #endif // __GXX_EXPERIMENTAL_CXX0X__
598 * Returns a read/write iterator that points to the first character in
599 * the %string. Unshares the string.
602 begin() _GLIBCXX_NOEXCEPT
605 return iterator(_M_data());
609 * Returns a read-only (constant) iterator that points to the first
610 * character in the %string.
613 begin() const _GLIBCXX_NOEXCEPT
614 { return const_iterator(_M_data()); }
617 * Returns a read/write iterator that points one past the last
618 * character in the %string. Unshares the string.
621 end() _GLIBCXX_NOEXCEPT
624 return iterator(_M_data() + this->size());
628 * Returns a read-only (constant) iterator that points one past the
629 * last character in the %string.
632 end() const _GLIBCXX_NOEXCEPT
633 { return const_iterator(_M_data() + this->size()); }
636 * Returns a read/write reverse iterator that points to the last
637 * character in the %string. Iteration is done in reverse element
638 * order. Unshares the string.
641 rbegin() _GLIBCXX_NOEXCEPT
642 { return reverse_iterator(this->end()); }
645 * Returns a read-only (constant) reverse iterator that points
646 * to the last character in the %string. Iteration is done in
647 * reverse element order.
649 const_reverse_iterator
650 rbegin() const _GLIBCXX_NOEXCEPT
651 { return const_reverse_iterator(this->end()); }
654 * Returns a read/write reverse iterator that points to one before the
655 * first character in the %string. Iteration is done in reverse
656 * element order. Unshares the string.
659 rend() _GLIBCXX_NOEXCEPT
660 { return reverse_iterator(this->begin()); }
663 * Returns a read-only (constant) reverse iterator that points
664 * to one before the first character in the %string. Iteration
665 * is done in reverse element order.
667 const_reverse_iterator
668 rend() const _GLIBCXX_NOEXCEPT
669 { return const_reverse_iterator(this->begin()); }
671 #ifdef __GXX_EXPERIMENTAL_CXX0X__
673 * Returns a read-only (constant) iterator that points to the first
674 * character in the %string.
677 cbegin() const noexcept
678 { return const_iterator(this->_M_data()); }
681 * Returns a read-only (constant) iterator that points one past the
682 * last character in the %string.
685 cend() const noexcept
686 { return const_iterator(this->_M_data() + this->size()); }
689 * Returns a read-only (constant) reverse iterator that points
690 * to the last character in the %string. Iteration is done in
691 * reverse element order.
693 const_reverse_iterator
694 crbegin() const noexcept
695 { return const_reverse_iterator(this->end()); }
698 * Returns a read-only (constant) reverse iterator that points
699 * to one before the first character in the %string. Iteration
700 * is done in reverse element order.
702 const_reverse_iterator
703 crend() const noexcept
704 { return const_reverse_iterator(this->begin()); }
709 /// Returns the number of characters in the string, not including any
710 /// null-termination.
712 size() const _GLIBCXX_NOEXCEPT
713 { return _M_rep()->_M_length
; }
715 /// Returns the number of characters in the string, not including any
716 /// null-termination.
718 length() const _GLIBCXX_NOEXCEPT
719 { return _M_rep()->_M_length
; }
721 /// Returns the size() of the largest possible %string.
723 max_size() const _GLIBCXX_NOEXCEPT
724 { return _Rep::_S_max_size
; }
727 * @brief Resizes the %string to the specified number of characters.
728 * @param __n Number of characters the %string should contain.
729 * @param __c Character to fill any new elements.
731 * This function will %resize the %string to the specified
732 * number of characters. If the number is smaller than the
733 * %string's current size the %string is truncated, otherwise
734 * the %string is extended and new elements are %set to @a __c.
737 resize(size_type __n
, _CharT __c
);
740 * @brief Resizes the %string to the specified number of characters.
741 * @param __n Number of characters the %string should contain.
743 * This function will resize the %string to the specified length. If
744 * the new size is smaller than the %string's current size the %string
745 * is truncated, otherwise the %string is extended and new characters
746 * are default-constructed. For basic types such as char, this means
750 resize(size_type __n
)
751 { this->resize(__n
, _CharT()); }
753 #ifdef __GXX_EXPERIMENTAL_CXX0X__
754 /// A non-binding request to reduce capacity() to size().
758 if (capacity() > size())
769 * Returns the total number of characters that the %string can hold
770 * before needing to allocate more memory.
773 capacity() const _GLIBCXX_NOEXCEPT
774 { return _M_rep()->_M_capacity
; }
777 * @brief Attempt to preallocate enough memory for specified number of
779 * @param __res_arg Number of characters required.
780 * @throw std::length_error If @a __res_arg exceeds @c max_size().
782 * This function attempts to reserve enough memory for the
783 * %string to hold the specified number of characters. If the
784 * number requested is more than max_size(), length_error is
787 * The advantage of this function is that if optimal code is a
788 * necessity and the user can determine the string length that will be
789 * required, the user can reserve the memory in %advance, and thus
790 * prevent a possible reallocation of memory and copying of %string
794 reserve(size_type __res_arg
= 0);
797 * Erases the string, making it empty.
800 clear() _GLIBCXX_NOEXCEPT
801 { _M_mutate(0, this->size(), 0); }
804 * Returns true if the %string is empty. Equivalent to
805 * <code>*this == ""</code>.
808 empty() const _GLIBCXX_NOEXCEPT
809 { return this->size() == 0; }
813 * @brief Subscript access to the data contained in the %string.
814 * @param __pos The index of the character to access.
815 * @return Read-only (constant) reference to the character.
817 * This operator allows for easy, array-style, data access.
818 * Note that data access with this operator is unchecked and
819 * out_of_range lookups are not defined. (For checked lookups
823 operator[] (size_type __pos
) const
825 _GLIBCXX_DEBUG_ASSERT(__pos
<= size());
826 return _M_data()[__pos
];
830 * @brief Subscript access to the data contained in the %string.
831 * @param __pos The index of the character to access.
832 * @return Read/write reference to the character.
834 * This operator allows for easy, array-style, data access.
835 * Note that data access with this operator is unchecked and
836 * out_of_range lookups are not defined. (For checked lookups
837 * see at().) Unshares the string.
840 operator[](size_type __pos
)
842 // allow pos == size() as v3 extension:
843 _GLIBCXX_DEBUG_ASSERT(__pos
<= size());
844 // but be strict in pedantic mode:
845 _GLIBCXX_DEBUG_PEDASSERT(__pos
< size());
847 return _M_data()[__pos
];
851 * @brief Provides access to the data contained in the %string.
852 * @param __n The index of the character to access.
853 * @return Read-only (const) reference to the character.
854 * @throw std::out_of_range If @a n is an invalid index.
856 * This function provides for safer data access. The parameter is
857 * first checked that it is in the range of the string. The function
858 * throws out_of_range if the check fails.
861 at(size_type __n
) const
863 if (__n
>= this->size())
864 __throw_out_of_range(__N("basic_string::at"));
865 return _M_data()[__n
];
868 #ifdef __GXX_EXPERIMENTAL_CXX0X__
870 * Returns a read/write reference to the data at the first
871 * element of the %string.
875 { return operator[](0); }
878 * Returns a read-only (constant) reference to the data at the first
879 * element of the %string.
883 { return operator[](0); }
886 * Returns a read/write reference to the data at the last
887 * element of the %string.
891 { return operator[](this->size() - 1); }
894 * Returns a read-only (constant) reference to the data at the
895 * last element of the %string.
899 { return operator[](this->size() - 1); }
903 * @brief Provides access to the data contained in the %string.
904 * @param __n The index of the character to access.
905 * @return Read/write reference to the character.
906 * @throw std::out_of_range If @a n is an invalid index.
908 * This function provides for safer data access. The parameter is
909 * first checked that it is in the range of the string. The function
910 * throws out_of_range if the check fails. Success results in
911 * unsharing the string.
917 __throw_out_of_range(__N("basic_string::at"));
919 return _M_data()[__n
];
924 * @brief Append a string to this string.
925 * @param __str The string to append.
926 * @return Reference to this string.
929 operator+=(const basic_string
& __str
)
930 { return this->append(__str
); }
933 * @brief Append a C string.
934 * @param __s The C string to append.
935 * @return Reference to this string.
938 operator+=(const _CharT
* __s
)
939 { return this->append(__s
); }
942 * @brief Append a character.
943 * @param __c The character to append.
944 * @return Reference to this string.
947 operator+=(_CharT __c
)
949 this->push_back(__c
);
953 #ifdef __GXX_EXPERIMENTAL_CXX0X__
955 * @brief Append an initializer_list of characters.
956 * @param __l The initializer_list of characters to be appended.
957 * @return Reference to this string.
960 operator+=(initializer_list
<_CharT
> __l
)
961 { return this->append(__l
.begin(), __l
.size()); }
962 #endif // __GXX_EXPERIMENTAL_CXX0X__
965 * @brief Append a string to this string.
966 * @param __str The string to append.
967 * @return Reference to this string.
970 append(const basic_string
& __str
);
973 * @brief Append a substring.
974 * @param __str The string to append.
975 * @param __pos Index of the first character of str to append.
976 * @param __n The number of characters to append.
977 * @return Reference to this string.
978 * @throw std::out_of_range if @a __pos is not a valid index.
980 * This function appends @a __n characters from @a __str
981 * starting at @a __pos to this string. If @a __n is is larger
982 * than the number of available characters in @a __str, the
983 * remainder of @a __str is appended.
986 append(const basic_string
& __str
, size_type __pos
, size_type __n
);
989 * @brief Append a C substring.
990 * @param __s The C string to append.
991 * @param __n The number of characters to append.
992 * @return Reference to this string.
995 append(const _CharT
* __s
, size_type __n
);
998 * @brief Append a C string.
999 * @param __s The C string to append.
1000 * @return Reference to this string.
1003 append(const _CharT
* __s
)
1005 __glibcxx_requires_string(__s
);
1006 return this->append(__s
, traits_type::length(__s
));
1010 * @brief Append multiple characters.
1011 * @param __n The number of characters to append.
1012 * @param __c The character to use.
1013 * @return Reference to this string.
1015 * Appends __n copies of __c to this string.
1018 append(size_type __n
, _CharT __c
);
1020 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1022 * @brief Append an initializer_list of characters.
1023 * @param __l The initializer_list of characters to append.
1024 * @return Reference to this string.
1027 append(initializer_list
<_CharT
> __l
)
1028 { return this->append(__l
.begin(), __l
.size()); }
1029 #endif // __GXX_EXPERIMENTAL_CXX0X__
1032 * @brief Append a range of characters.
1033 * @param __first Iterator referencing the first character to append.
1034 * @param __last Iterator marking the end of the range.
1035 * @return Reference to this string.
1037 * Appends characters in the range [__first,__last) to this string.
1039 template<class _InputIterator
>
1041 append(_InputIterator __first
, _InputIterator __last
)
1042 { return this->replace(_M_iend(), _M_iend(), __first
, __last
); }
1045 * @brief Append a single character.
1046 * @param __c Character to append.
1049 push_back(_CharT __c
)
1051 const size_type __len
= 1 + this->size();
1052 if (__len
> this->capacity() || _M_rep()->_M_is_shared())
1053 this->reserve(__len
);
1054 traits_type::assign(_M_data()[this->size()], __c
);
1055 _M_rep()->_M_set_length_and_sharable(__len
);
1059 * @brief Set value to contents of another string.
1060 * @param __str Source string to use.
1061 * @return Reference to this string.
1064 assign(const basic_string
& __str
);
1066 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1068 * @brief Set value to contents of another string.
1069 * @param __str Source string to use.
1070 * @return Reference to this string.
1072 * This function sets this string to the exact contents of @a __str.
1073 * @a __str is a valid, but unspecified string.
1076 assign(basic_string
&& __str
)
1081 #endif // __GXX_EXPERIMENTAL_CXX0X__
1084 * @brief Set value to a substring of a string.
1085 * @param __str The string to use.
1086 * @param __pos Index of the first character of str.
1087 * @param __n Number of characters to use.
1088 * @return Reference to this string.
1089 * @throw std::out_of_range if @a pos is not a valid index.
1091 * This function sets this string to the substring of @a __str
1092 * consisting of @a __n characters at @a __pos. If @a __n is
1093 * is larger than the number of available characters in @a
1094 * __str, the remainder of @a __str is used.
1097 assign(const basic_string
& __str
, size_type __pos
, size_type __n
)
1098 { return this->assign(__str
._M_data()
1099 + __str
._M_check(__pos
, "basic_string::assign"),
1100 __str
._M_limit(__pos
, __n
)); }
1103 * @brief Set value to a C substring.
1104 * @param __s The C string to use.
1105 * @param __n Number of characters to use.
1106 * @return Reference to this string.
1108 * This function sets the value of this string to the first @a __n
1109 * characters of @a __s. If @a __n is is larger than the number of
1110 * available characters in @a __s, the remainder of @a __s is used.
1113 assign(const _CharT
* __s
, size_type __n
);
1116 * @brief Set value to contents of a C string.
1117 * @param __s The C string to use.
1118 * @return Reference to this string.
1120 * This function sets the value of this string to the value of @a __s.
1121 * The data is copied, so there is no dependence on @a __s once the
1125 assign(const _CharT
* __s
)
1127 __glibcxx_requires_string(__s
);
1128 return this->assign(__s
, traits_type::length(__s
));
1132 * @brief Set value to multiple characters.
1133 * @param __n Length of the resulting string.
1134 * @param __c The character to use.
1135 * @return Reference to this string.
1137 * This function sets the value of this string to @a __n copies of
1141 assign(size_type __n
, _CharT __c
)
1142 { return _M_replace_aux(size_type(0), this->size(), __n
, __c
); }
1145 * @brief Set value to a range of characters.
1146 * @param __first Iterator referencing the first character to append.
1147 * @param __last Iterator marking the end of the range.
1148 * @return Reference to this string.
1150 * Sets value of string to characters in the range [__first,__last).
1152 template<class _InputIterator
>
1154 assign(_InputIterator __first
, _InputIterator __last
)
1155 { return this->replace(_M_ibegin(), _M_iend(), __first
, __last
); }
1157 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1159 * @brief Set value to an initializer_list of characters.
1160 * @param __l The initializer_list of characters to assign.
1161 * @return Reference to this string.
1164 assign(initializer_list
<_CharT
> __l
)
1165 { return this->assign(__l
.begin(), __l
.size()); }
1166 #endif // __GXX_EXPERIMENTAL_CXX0X__
1169 * @brief Insert multiple characters.
1170 * @param __p Iterator referencing location in string to insert at.
1171 * @param __n Number of characters to insert
1172 * @param __c The character to insert.
1173 * @throw std::length_error If new length exceeds @c max_size().
1175 * Inserts @a __n copies of character @a __c starting at the
1176 * position referenced by iterator @a __p. If adding
1177 * characters causes the length to exceed max_size(),
1178 * length_error is thrown. The value of the string doesn't
1179 * change if an error is thrown.
1182 insert(iterator __p
, size_type __n
, _CharT __c
)
1183 { this->replace(__p
, __p
, __n
, __c
); }
1186 * @brief Insert a range of characters.
1187 * @param __p Iterator referencing location in string to insert at.
1188 * @param __beg Start of range.
1189 * @param __end End of range.
1190 * @throw std::length_error If new length exceeds @c max_size().
1192 * Inserts characters in range [__beg,__end). If adding
1193 * characters causes the length to exceed max_size(),
1194 * length_error is thrown. The value of the string doesn't
1195 * change if an error is thrown.
1197 template<class _InputIterator
>
1199 insert(iterator __p
, _InputIterator __beg
, _InputIterator __end
)
1200 { this->replace(__p
, __p
, __beg
, __end
); }
1202 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1204 * @brief Insert an initializer_list of characters.
1205 * @param __p Iterator referencing location in string to insert at.
1206 * @param __l The initializer_list of characters to insert.
1207 * @throw std::length_error If new length exceeds @c max_size().
1210 insert(iterator __p
, initializer_list
<_CharT
> __l
)
1212 _GLIBCXX_DEBUG_PEDASSERT(__p
>= _M_ibegin() && __p
<= _M_iend());
1213 this->insert(__p
- _M_ibegin(), __l
.begin(), __l
.size());
1215 #endif // __GXX_EXPERIMENTAL_CXX0X__
1218 * @brief Insert value of a string.
1219 * @param __pos1 Iterator referencing location in string to insert at.
1220 * @param __str The string to insert.
1221 * @return Reference to this string.
1222 * @throw std::length_error If new length exceeds @c max_size().
1224 * Inserts value of @a __str starting at @a __pos1. If adding
1225 * characters causes the length to exceed max_size(),
1226 * length_error is thrown. The value of the string doesn't
1227 * change if an error is thrown.
1230 insert(size_type __pos1
, const basic_string
& __str
)
1231 { return this->insert(__pos1
, __str
, size_type(0), __str
.size()); }
1234 * @brief Insert a substring.
1235 * @param __pos1 Iterator referencing location in string to insert at.
1236 * @param __str The string to insert.
1237 * @param __pos2 Start of characters in str to insert.
1238 * @param __n Number of characters to insert.
1239 * @return Reference to this string.
1240 * @throw std::length_error If new length exceeds @c max_size().
1241 * @throw std::out_of_range If @a pos1 > size() or
1242 * @a __pos2 > @a str.size().
1244 * Starting at @a pos1, insert @a __n character of @a __str
1245 * beginning with @a __pos2. If adding characters causes the
1246 * length to exceed max_size(), length_error is thrown. If @a
1247 * __pos1 is beyond the end of this string or @a __pos2 is
1248 * beyond the end of @a __str, out_of_range is thrown. The
1249 * value of the string doesn't change if an error is thrown.
1252 insert(size_type __pos1
, const basic_string
& __str
,
1253 size_type __pos2
, size_type __n
)
1254 { return this->insert(__pos1
, __str
._M_data()
1255 + __str
._M_check(__pos2
, "basic_string::insert"),
1256 __str
._M_limit(__pos2
, __n
)); }
1259 * @brief Insert a C substring.
1260 * @param __pos Iterator referencing location in string to insert at.
1261 * @param __s The C string to insert.
1262 * @param __n The number of characters to insert.
1263 * @return Reference to this string.
1264 * @throw std::length_error If new length exceeds @c max_size().
1265 * @throw std::out_of_range If @a __pos is beyond the end of this
1268 * Inserts the first @a __n characters of @a __s starting at @a
1269 * __pos. If adding characters causes the length to exceed
1270 * max_size(), length_error is thrown. If @a __pos is beyond
1271 * end(), out_of_range is thrown. The value of the string
1272 * doesn't change if an error is thrown.
1275 insert(size_type __pos
, const _CharT
* __s
, size_type __n
);
1278 * @brief Insert a C string.
1279 * @param __pos Iterator referencing location in string to insert at.
1280 * @param __s The C string to insert.
1281 * @return Reference to this string.
1282 * @throw std::length_error If new length exceeds @c max_size().
1283 * @throw std::out_of_range If @a pos is beyond the end of this
1286 * Inserts the first @a n characters of @a __s starting at @a __pos. If
1287 * adding characters causes the length to exceed max_size(),
1288 * length_error is thrown. If @a __pos is beyond end(), out_of_range is
1289 * thrown. The value of the string doesn't change if an error is
1293 insert(size_type __pos
, const _CharT
* __s
)
1295 __glibcxx_requires_string(__s
);
1296 return this->insert(__pos
, __s
, traits_type::length(__s
));
1300 * @brief Insert multiple characters.
1301 * @param __pos Index in string to insert at.
1302 * @param __n Number of characters to insert
1303 * @param __c The character to insert.
1304 * @return Reference to this string.
1305 * @throw std::length_error If new length exceeds @c max_size().
1306 * @throw std::out_of_range If @a __pos is beyond the end of this
1309 * Inserts @a __n copies of character @a __c starting at index
1310 * @a __pos. If adding characters causes the length to exceed
1311 * max_size(), length_error is thrown. If @a __pos > length(),
1312 * out_of_range is thrown. The value of the string doesn't
1313 * change if an error is thrown.
1316 insert(size_type __pos
, size_type __n
, _CharT __c
)
1317 { return _M_replace_aux(_M_check(__pos
, "basic_string::insert"),
1318 size_type(0), __n
, __c
); }
1321 * @brief Insert one character.
1322 * @param __p Iterator referencing position in string to insert at.
1323 * @param __c The character to insert.
1324 * @return Iterator referencing newly inserted char.
1325 * @throw std::length_error If new length exceeds @c max_size().
1327 * Inserts character @a __c at position referenced by @a __p.
1328 * If adding character causes the length to exceed max_size(),
1329 * length_error is thrown. If @a __p is beyond end of string,
1330 * out_of_range is thrown. The value of the string doesn't
1331 * change if an error is thrown.
1334 insert(iterator __p
, _CharT __c
)
1336 _GLIBCXX_DEBUG_PEDASSERT(__p
>= _M_ibegin() && __p
<= _M_iend());
1337 const size_type __pos
= __p
- _M_ibegin();
1338 _M_replace_aux(__pos
, size_type(0), size_type(1), __c
);
1339 _M_rep()->_M_set_leaked();
1340 return iterator(_M_data() + __pos
);
1344 * @brief Remove characters.
1345 * @param __pos Index of first character to remove (default 0).
1346 * @param __n Number of characters to remove (default remainder).
1347 * @return Reference to this string.
1348 * @throw std::out_of_range If @a pos is beyond the end of this
1351 * Removes @a __n characters from this string starting at @a
1352 * __pos. The length of the string is reduced by @a __n. If
1353 * there are < @a __n characters to remove, the remainder of
1354 * the string is truncated. If @a __p is beyond end of string,
1355 * out_of_range is thrown. The value of the string doesn't
1356 * change if an error is thrown.
1359 erase(size_type __pos
= 0, size_type __n
= npos
)
1361 _M_mutate(_M_check(__pos
, "basic_string::erase"),
1362 _M_limit(__pos
, __n
), size_type(0));
1367 * @brief Remove one character.
1368 * @param __position Iterator referencing the character to remove.
1369 * @return iterator referencing same location after removal.
1371 * Removes the character at @a __position from this string. The value
1372 * of the string doesn't change if an error is thrown.
1375 erase(iterator __position
)
1377 _GLIBCXX_DEBUG_PEDASSERT(__position
>= _M_ibegin()
1378 && __position
< _M_iend());
1379 const size_type __pos
= __position
- _M_ibegin();
1380 _M_mutate(__pos
, size_type(1), size_type(0));
1381 _M_rep()->_M_set_leaked();
1382 return iterator(_M_data() + __pos
);
1386 * @brief Remove a range of characters.
1387 * @param __first Iterator referencing the first character to remove.
1388 * @param __last Iterator referencing the end of the range.
1389 * @return Iterator referencing location of first after removal.
1391 * Removes the characters in the range [first,last) from this string.
1392 * The value of the string doesn't change if an error is thrown.
1395 erase(iterator __first
, iterator __last
);
1398 * @brief Replace characters with value from another string.
1399 * @param __pos Index of first character to replace.
1400 * @param __n Number of characters to be replaced.
1401 * @param __str String to insert.
1402 * @return Reference to this string.
1403 * @throw std::out_of_range If @a pos is beyond the end of this
1405 * @throw std::length_error If new length exceeds @c max_size().
1407 * Removes the characters in the range [__pos,__pos+__n) from
1408 * this string. In place, the value of @a __str is inserted.
1409 * If @a __pos is beyond end of string, out_of_range is thrown.
1410 * If the length of the result exceeds max_size(), length_error
1411 * is thrown. The value of the string doesn't change if an
1415 replace(size_type __pos
, size_type __n
, const basic_string
& __str
)
1416 { return this->replace(__pos
, __n
, __str
._M_data(), __str
.size()); }
1419 * @brief Replace characters with value from another string.
1420 * @param __pos1 Index of first character to replace.
1421 * @param __n1 Number of characters to be replaced.
1422 * @param __str String to insert.
1423 * @param __pos2 Index of first character of str to use.
1424 * @param __n2 Number of characters from str to use.
1425 * @return Reference to this string.
1426 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
1428 * @throw std::length_error If new length exceeds @c max_size().
1430 * Removes the characters in the range [__pos1,__pos1 + n) from this
1431 * string. In place, the value of @a __str is inserted. If @a __pos is
1432 * beyond end of string, out_of_range is thrown. If the length of the
1433 * result exceeds max_size(), length_error is thrown. The value of the
1434 * string doesn't change if an error is thrown.
1437 replace(size_type __pos1
, size_type __n1
, const basic_string
& __str
,
1438 size_type __pos2
, size_type __n2
)
1439 { return this->replace(__pos1
, __n1
, __str
._M_data()
1440 + __str
._M_check(__pos2
, "basic_string::replace"),
1441 __str
._M_limit(__pos2
, __n2
)); }
1444 * @brief Replace characters with value of a C substring.
1445 * @param __pos Index of first character to replace.
1446 * @param __n1 Number of characters to be replaced.
1447 * @param __s C string to insert.
1448 * @param __n2 Number of characters from @a s to use.
1449 * @return Reference to this string.
1450 * @throw std::out_of_range If @a pos1 > size().
1451 * @throw std::length_error If new length exceeds @c max_size().
1453 * Removes the characters in the range [__pos,__pos + __n1)
1454 * from this string. In place, the first @a __n2 characters of
1455 * @a __s are inserted, or all of @a __s if @a __n2 is too large. If
1456 * @a __pos is beyond end of string, out_of_range is thrown. If
1457 * the length of result exceeds max_size(), length_error is
1458 * thrown. The value of the string doesn't change if an error
1462 replace(size_type __pos
, size_type __n1
, const _CharT
* __s
,
1466 * @brief Replace characters with value of a C string.
1467 * @param __pos Index of first character to replace.
1468 * @param __n1 Number of characters to be replaced.
1469 * @param __s C string to insert.
1470 * @return Reference to this string.
1471 * @throw std::out_of_range If @a pos > size().
1472 * @throw std::length_error If new length exceeds @c max_size().
1474 * Removes the characters in the range [__pos,__pos + __n1)
1475 * from this string. In place, the characters of @a __s are
1476 * inserted. If @a __pos is beyond end of string, out_of_range
1477 * is thrown. If the length of result exceeds max_size(),
1478 * length_error is thrown. The value of the string doesn't
1479 * change if an error is thrown.
1482 replace(size_type __pos
, size_type __n1
, const _CharT
* __s
)
1484 __glibcxx_requires_string(__s
);
1485 return this->replace(__pos
, __n1
, __s
, traits_type::length(__s
));
1489 * @brief Replace characters with multiple characters.
1490 * @param __pos Index of first character to replace.
1491 * @param __n1 Number of characters to be replaced.
1492 * @param __n2 Number of characters to insert.
1493 * @param __c Character to insert.
1494 * @return Reference to this string.
1495 * @throw std::out_of_range If @a __pos > size().
1496 * @throw std::length_error If new length exceeds @c max_size().
1498 * Removes the characters in the range [pos,pos + n1) from this
1499 * string. In place, @a __n2 copies of @a __c are inserted.
1500 * If @a __pos is beyond end of string, out_of_range is thrown.
1501 * If the length of result exceeds max_size(), length_error is
1502 * thrown. The value of the string doesn't change if an error
1506 replace(size_type __pos
, size_type __n1
, size_type __n2
, _CharT __c
)
1507 { return _M_replace_aux(_M_check(__pos
, "basic_string::replace"),
1508 _M_limit(__pos
, __n1
), __n2
, __c
); }
1511 * @brief Replace range of characters with string.
1512 * @param __i1 Iterator referencing start of range to replace.
1513 * @param __i2 Iterator referencing end of range to replace.
1514 * @param __str String value to insert.
1515 * @return Reference to this string.
1516 * @throw std::length_error If new length exceeds @c max_size().
1518 * Removes the characters in the range [__i1,__i2). In place,
1519 * the value of @a __str is inserted. If the length of result
1520 * exceeds max_size(), length_error is thrown. The value of
1521 * the string doesn't change if an error is thrown.
1524 replace(iterator __i1
, iterator __i2
, const basic_string
& __str
)
1525 { return this->replace(__i1
, __i2
, __str
._M_data(), __str
.size()); }
1528 * @brief Replace range of characters with C substring.
1529 * @param __i1 Iterator referencing start of range to replace.
1530 * @param __i2 Iterator referencing end of range to replace.
1531 * @param __s C string value to insert.
1532 * @param __n Number of characters from s to insert.
1533 * @return Reference to this string.
1534 * @throw std::length_error If new length exceeds @c max_size().
1536 * Removes the characters in the range [__i1,__i2). In place,
1537 * the first @a __n characters of @a __s are inserted. If the
1538 * length of result exceeds max_size(), length_error is thrown.
1539 * The value of the string doesn't change if an error is
1543 replace(iterator __i1
, iterator __i2
, const _CharT
* __s
, size_type __n
)
1545 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1546 && __i2
<= _M_iend());
1547 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
, __s
, __n
);
1551 * @brief Replace range of characters with C string.
1552 * @param __i1 Iterator referencing start of range to replace.
1553 * @param __i2 Iterator referencing end of range to replace.
1554 * @param __s C string value to insert.
1555 * @return Reference to this string.
1556 * @throw std::length_error If new length exceeds @c max_size().
1558 * Removes the characters in the range [__i1,__i2). In place,
1559 * the characters of @a __s are inserted. If the length of
1560 * result exceeds max_size(), length_error is thrown. The
1561 * value of the string doesn't change if an error is thrown.
1564 replace(iterator __i1
, iterator __i2
, const _CharT
* __s
)
1566 __glibcxx_requires_string(__s
);
1567 return this->replace(__i1
, __i2
, __s
, traits_type::length(__s
));
1571 * @brief Replace range of characters with multiple characters
1572 * @param __i1 Iterator referencing start of range to replace.
1573 * @param __i2 Iterator referencing end of range to replace.
1574 * @param __n Number of characters to insert.
1575 * @param __c Character to insert.
1576 * @return Reference to this string.
1577 * @throw std::length_error If new length exceeds @c max_size().
1579 * Removes the characters in the range [__i1,__i2). In place,
1580 * @a __n copies of @a __c are inserted. If the length of
1581 * result exceeds max_size(), length_error is thrown. The
1582 * value of the string doesn't change if an error is thrown.
1585 replace(iterator __i1
, iterator __i2
, size_type __n
, _CharT __c
)
1587 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1588 && __i2
<= _M_iend());
1589 return _M_replace_aux(__i1
- _M_ibegin(), __i2
- __i1
, __n
, __c
);
1593 * @brief Replace range of characters with range.
1594 * @param __i1 Iterator referencing start of range to replace.
1595 * @param __i2 Iterator referencing end of range to replace.
1596 * @param __k1 Iterator referencing start of range to insert.
1597 * @param __k2 Iterator referencing end of range to insert.
1598 * @return Reference to this string.
1599 * @throw std::length_error If new length exceeds @c max_size().
1601 * Removes the characters in the range [__i1,__i2). In place,
1602 * characters in the range [__k1,__k2) are inserted. If the
1603 * length of result exceeds max_size(), length_error is thrown.
1604 * The value of the string doesn't change if an error is
1607 template<class _InputIterator
>
1609 replace(iterator __i1
, iterator __i2
,
1610 _InputIterator __k1
, _InputIterator __k2
)
1612 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1613 && __i2
<= _M_iend());
1614 __glibcxx_requires_valid_range(__k1
, __k2
);
1615 typedef typename
std::__is_integer
<_InputIterator
>::__type _Integral
;
1616 return _M_replace_dispatch(__i1
, __i2
, __k1
, __k2
, _Integral());
1619 // Specializations for the common case of pointer and iterator:
1620 // useful to avoid the overhead of temporary buffering in _M_replace.
1622 replace(iterator __i1
, iterator __i2
, _CharT
* __k1
, _CharT
* __k2
)
1624 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1625 && __i2
<= _M_iend());
1626 __glibcxx_requires_valid_range(__k1
, __k2
);
1627 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1632 replace(iterator __i1
, iterator __i2
,
1633 const _CharT
* __k1
, const _CharT
* __k2
)
1635 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1636 && __i2
<= _M_iend());
1637 __glibcxx_requires_valid_range(__k1
, __k2
);
1638 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1643 replace(iterator __i1
, iterator __i2
, iterator __k1
, iterator __k2
)
1645 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1646 && __i2
<= _M_iend());
1647 __glibcxx_requires_valid_range(__k1
, __k2
);
1648 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1649 __k1
.base(), __k2
- __k1
);
1653 replace(iterator __i1
, iterator __i2
,
1654 const_iterator __k1
, const_iterator __k2
)
1656 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1657 && __i2
<= _M_iend());
1658 __glibcxx_requires_valid_range(__k1
, __k2
);
1659 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1660 __k1
.base(), __k2
- __k1
);
1663 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1665 * @brief Replace range of characters with initializer_list.
1666 * @param __i1 Iterator referencing start of range to replace.
1667 * @param __i2 Iterator referencing end of range to replace.
1668 * @param __l The initializer_list of characters to insert.
1669 * @return Reference to this string.
1670 * @throw std::length_error If new length exceeds @c max_size().
1672 * Removes the characters in the range [__i1,__i2). In place,
1673 * characters in the range [__k1,__k2) are inserted. If the
1674 * length of result exceeds max_size(), length_error is thrown.
1675 * The value of the string doesn't change if an error is
1678 basic_string
& replace(iterator __i1
, iterator __i2
,
1679 initializer_list
<_CharT
> __l
)
1680 { return this->replace(__i1
, __i2
, __l
.begin(), __l
.end()); }
1681 #endif // __GXX_EXPERIMENTAL_CXX0X__
1684 template<class _Integer
>
1686 _M_replace_dispatch(iterator __i1
, iterator __i2
, _Integer __n
,
1687 _Integer __val
, __true_type
)
1688 { return _M_replace_aux(__i1
- _M_ibegin(), __i2
- __i1
, __n
, __val
); }
1690 template<class _InputIterator
>
1692 _M_replace_dispatch(iterator __i1
, iterator __i2
, _InputIterator __k1
,
1693 _InputIterator __k2
, __false_type
);
1696 _M_replace_aux(size_type __pos1
, size_type __n1
, size_type __n2
,
1700 _M_replace_safe(size_type __pos1
, size_type __n1
, const _CharT
* __s
,
1703 // _S_construct_aux is used to implement the 21.3.1 para 15 which
1704 // requires special behaviour if _InIter is an integral type
1705 template<class _InIterator
>
1707 _S_construct_aux(_InIterator __beg
, _InIterator __end
,
1708 const _Alloc
& __a
, __false_type
)
1710 typedef typename iterator_traits
<_InIterator
>::iterator_category _Tag
;
1711 return _S_construct(__beg
, __end
, __a
, _Tag());
1714 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1715 // 438. Ambiguity in the "do the right thing" clause
1716 template<class _Integer
>
1718 _S_construct_aux(_Integer __beg
, _Integer __end
,
1719 const _Alloc
& __a
, __true_type
)
1720 { return _S_construct_aux_2(static_cast<size_type
>(__beg
),
1724 _S_construct_aux_2(size_type __req
, _CharT __c
, const _Alloc
& __a
)
1725 { return _S_construct(__req
, __c
, __a
); }
1727 template<class _InIterator
>
1729 _S_construct(_InIterator __beg
, _InIterator __end
, const _Alloc
& __a
)
1731 typedef typename
std::__is_integer
<_InIterator
>::__type _Integral
;
1732 return _S_construct_aux(__beg
, __end
, __a
, _Integral());
1735 // For Input Iterators, used in istreambuf_iterators, etc.
1736 template<class _InIterator
>
1738 _S_construct(_InIterator __beg
, _InIterator __end
, const _Alloc
& __a
,
1739 input_iterator_tag
);
1741 // For forward_iterators up to random_access_iterators, used for
1742 // string::iterator, _CharT*, etc.
1743 template<class _FwdIterator
>
1745 _S_construct(_FwdIterator __beg
, _FwdIterator __end
, const _Alloc
& __a
,
1746 forward_iterator_tag
);
1749 _S_construct(size_type __req
, _CharT __c
, const _Alloc
& __a
);
1754 * @brief Copy substring into C string.
1755 * @param __s C string to copy value into.
1756 * @param __n Number of characters to copy.
1757 * @param __pos Index of first character to copy.
1758 * @return Number of characters actually copied
1759 * @throw std::out_of_range If __pos > size().
1761 * Copies up to @a __n characters starting at @a __pos into the
1762 * C string @a __s. If @a __pos is %greater than size(),
1763 * out_of_range is thrown.
1766 copy(_CharT
* __s
, size_type __n
, size_type __pos
= 0) const;
1769 * @brief Swap contents with another string.
1770 * @param __s String to swap with.
1772 * Exchanges the contents of this string with that of @a __s in constant
1776 swap(basic_string
& __s
);
1778 // String operations:
1780 * @brief Return const pointer to null-terminated contents.
1782 * This is a handle to internal data. Do not modify or dire things may
1786 c_str() const _GLIBCXX_NOEXCEPT
1787 { return _M_data(); }
1790 * @brief Return const pointer to contents.
1792 * This is a handle to internal data. Do not modify or dire things may
1796 data() const _GLIBCXX_NOEXCEPT
1797 { return _M_data(); }
1800 * @brief Return copy of allocator used to construct this string.
1803 get_allocator() const _GLIBCXX_NOEXCEPT
1804 { return _M_dataplus
; }
1807 * @brief Find position of a C substring.
1808 * @param __s C string to locate.
1809 * @param __pos Index of character to search from.
1810 * @param __n Number of characters from @a s to search for.
1811 * @return Index of start of first occurrence.
1813 * Starting from @a __pos, searches forward for the first @a
1814 * __n characters in @a __s within this string. If found,
1815 * returns the index where it begins. If not found, returns
1819 find(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
1822 * @brief Find position of a string.
1823 * @param __str String to locate.
1824 * @param __pos Index of character to search from (default 0).
1825 * @return Index of start of first occurrence.
1827 * Starting from @a __pos, searches forward for value of @a __str within
1828 * this string. If found, returns the index where it begins. If not
1829 * found, returns npos.
1832 find(const basic_string
& __str
, size_type __pos
= 0) const
1834 { return this->find(__str
.data(), __pos
, __str
.size()); }
1837 * @brief Find position of a C string.
1838 * @param __s C string to locate.
1839 * @param __pos Index of character to search from (default 0).
1840 * @return Index of start of first occurrence.
1842 * Starting from @a __pos, searches forward for the value of @a
1843 * __s within this string. If found, returns the index where
1844 * it begins. If not found, returns npos.
1847 find(const _CharT
* __s
, size_type __pos
= 0) const
1849 __glibcxx_requires_string(__s
);
1850 return this->find(__s
, __pos
, traits_type::length(__s
));
1854 * @brief Find position of a character.
1855 * @param __c Character to locate.
1856 * @param __pos Index of character to search from (default 0).
1857 * @return Index of first occurrence.
1859 * Starting from @a __pos, searches forward for @a __c within
1860 * this string. If found, returns the index where it was
1861 * found. If not found, returns npos.
1864 find(_CharT __c
, size_type __pos
= 0) const _GLIBCXX_NOEXCEPT
;
1867 * @brief Find last position of a string.
1868 * @param __str String to locate.
1869 * @param __pos Index of character to search back from (default end).
1870 * @return Index of start of last occurrence.
1872 * Starting from @a __pos, searches backward for value of @a
1873 * __str within this string. If found, returns the index where
1874 * it begins. If not found, returns npos.
1877 rfind(const basic_string
& __str
, size_type __pos
= npos
) const
1879 { return this->rfind(__str
.data(), __pos
, __str
.size()); }
1882 * @brief Find last position of a C substring.
1883 * @param __s C string to locate.
1884 * @param __pos Index of character to search back from.
1885 * @param __n Number of characters from s to search for.
1886 * @return Index of start of last occurrence.
1888 * Starting from @a __pos, searches backward for the first @a
1889 * __n characters in @a __s within this string. If found,
1890 * returns the index where it begins. If not found, returns
1894 rfind(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
1897 * @brief Find last position of a C string.
1898 * @param __s C string to locate.
1899 * @param __pos Index of character to start search at (default end).
1900 * @return Index of start of last occurrence.
1902 * Starting from @a __pos, searches backward for the value of
1903 * @a __s within this string. If found, returns the index
1904 * where it begins. If not found, returns npos.
1907 rfind(const _CharT
* __s
, size_type __pos
= npos
) const
1909 __glibcxx_requires_string(__s
);
1910 return this->rfind(__s
, __pos
, traits_type::length(__s
));
1914 * @brief Find last position of a character.
1915 * @param __c Character to locate.
1916 * @param __pos Index of character to search back from (default end).
1917 * @return Index of last occurrence.
1919 * Starting from @a __pos, searches backward for @a __c within
1920 * this string. If found, returns the index where it was
1921 * found. If not found, returns npos.
1924 rfind(_CharT __c
, size_type __pos
= npos
) const _GLIBCXX_NOEXCEPT
;
1927 * @brief Find position of a character of string.
1928 * @param __str String containing characters to locate.
1929 * @param __pos Index of character to search from (default 0).
1930 * @return Index of first occurrence.
1932 * Starting from @a __pos, searches forward for one of the
1933 * characters of @a __str within this string. If found,
1934 * returns the index where it was found. If not found, returns
1938 find_first_of(const basic_string
& __str
, size_type __pos
= 0) const
1940 { return this->find_first_of(__str
.data(), __pos
, __str
.size()); }
1943 * @brief Find position of a character of C substring.
1944 * @param __s String containing characters to locate.
1945 * @param __pos Index of character to search from.
1946 * @param __n Number of characters from s to search for.
1947 * @return Index of first occurrence.
1949 * Starting from @a __pos, searches forward for one of the
1950 * first @a __n characters of @a __s within this string. If
1951 * found, returns the index where it was found. If not found,
1955 find_first_of(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
1958 * @brief Find position of a character of C string.
1959 * @param __s String containing characters to locate.
1960 * @param __pos Index of character to search from (default 0).
1961 * @return Index of first occurrence.
1963 * Starting from @a __pos, searches forward for one of the
1964 * characters of @a __s within this string. If found, returns
1965 * the index where it was found. If not found, returns npos.
1968 find_first_of(const _CharT
* __s
, size_type __pos
= 0) const
1970 __glibcxx_requires_string(__s
);
1971 return this->find_first_of(__s
, __pos
, traits_type::length(__s
));
1975 * @brief Find position of a character.
1976 * @param __c Character to locate.
1977 * @param __pos Index of character to search from (default 0).
1978 * @return Index of first occurrence.
1980 * Starting from @a __pos, searches forward for the character
1981 * @a __c within this string. If found, returns the index
1982 * where it was found. If not found, returns npos.
1984 * Note: equivalent to find(__c, __pos).
1987 find_first_of(_CharT __c
, size_type __pos
= 0) const _GLIBCXX_NOEXCEPT
1988 { return this->find(__c
, __pos
); }
1991 * @brief Find last position of a character of string.
1992 * @param __str String containing characters to locate.
1993 * @param __pos Index of character to search back from (default end).
1994 * @return Index of last occurrence.
1996 * Starting from @a __pos, searches backward for one of the
1997 * characters of @a __str within this string. If found,
1998 * returns the index where it was found. If not found, returns
2002 find_last_of(const basic_string
& __str
, size_type __pos
= npos
) const
2004 { return this->find_last_of(__str
.data(), __pos
, __str
.size()); }
2007 * @brief Find last position of a character of C substring.
2008 * @param __s C string containing characters to locate.
2009 * @param __pos Index of character to search back from.
2010 * @param __n Number of characters from s to search for.
2011 * @return Index of last occurrence.
2013 * Starting from @a __pos, searches backward for one of the
2014 * first @a __n characters of @a __s within this string. If
2015 * found, returns the index where it was found. If not found,
2019 find_last_of(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
2022 * @brief Find last position of a character of C string.
2023 * @param __s C string containing characters to locate.
2024 * @param __pos Index of character to search back from (default end).
2025 * @return Index of last occurrence.
2027 * Starting from @a __pos, searches backward for one of the
2028 * characters of @a __s within this string. If found, returns
2029 * the index where it was found. If not found, returns npos.
2032 find_last_of(const _CharT
* __s
, size_type __pos
= npos
) const
2034 __glibcxx_requires_string(__s
);
2035 return this->find_last_of(__s
, __pos
, traits_type::length(__s
));
2039 * @brief Find last position of a character.
2040 * @param __c Character to locate.
2041 * @param __pos Index of character to search back from (default end).
2042 * @return Index of last occurrence.
2044 * Starting from @a __pos, searches backward for @a __c within
2045 * this string. If found, returns the index where it was
2046 * found. If not found, returns npos.
2048 * Note: equivalent to rfind(__c, __pos).
2051 find_last_of(_CharT __c
, size_type __pos
= npos
) const _GLIBCXX_NOEXCEPT
2052 { return this->rfind(__c
, __pos
); }
2055 * @brief Find position of a character not in string.
2056 * @param __str String containing characters to avoid.
2057 * @param __pos Index of character to search from (default 0).
2058 * @return Index of first occurrence.
2060 * Starting from @a __pos, searches forward for a character not contained
2061 * in @a __str within this string. If found, returns the index where it
2062 * was found. If not found, returns npos.
2065 find_first_not_of(const basic_string
& __str
, size_type __pos
= 0) const
2067 { return this->find_first_not_of(__str
.data(), __pos
, __str
.size()); }
2070 * @brief Find position of a character not in C substring.
2071 * @param __s C string containing characters to avoid.
2072 * @param __pos Index of character to search from.
2073 * @param __n Number of characters from __s to consider.
2074 * @return Index of first occurrence.
2076 * Starting from @a __pos, searches forward for a character not
2077 * contained in the first @a __n characters of @a __s within
2078 * this string. If found, returns the index where it was
2079 * found. If not found, returns npos.
2082 find_first_not_of(const _CharT
* __s
, size_type __pos
,
2083 size_type __n
) const;
2086 * @brief Find position of a character not in C string.
2087 * @param __s C string containing characters to avoid.
2088 * @param __pos Index of character to search from (default 0).
2089 * @return Index of first occurrence.
2091 * Starting from @a __pos, searches forward for a character not
2092 * contained in @a __s within this string. If found, returns
2093 * the index where it was found. If not found, returns npos.
2096 find_first_not_of(const _CharT
* __s
, size_type __pos
= 0) const
2098 __glibcxx_requires_string(__s
);
2099 return this->find_first_not_of(__s
, __pos
, traits_type::length(__s
));
2103 * @brief Find position of a different character.
2104 * @param __c Character to avoid.
2105 * @param __pos Index of character to search from (default 0).
2106 * @return Index of first occurrence.
2108 * Starting from @a __pos, searches forward for a character
2109 * other than @a __c within this string. If found, returns the
2110 * index where it was found. If not found, returns npos.
2113 find_first_not_of(_CharT __c
, size_type __pos
= 0) const
2117 * @brief Find last position of a character not in string.
2118 * @param __str String containing characters to avoid.
2119 * @param __pos Index of character to search back from (default end).
2120 * @return Index of last occurrence.
2122 * Starting from @a __pos, searches backward for a character
2123 * not contained in @a __str within this string. If found,
2124 * returns the index where it was found. If not found, returns
2128 find_last_not_of(const basic_string
& __str
, size_type __pos
= npos
) const
2130 { return this->find_last_not_of(__str
.data(), __pos
, __str
.size()); }
2133 * @brief Find last position of a character not in C substring.
2134 * @param __s C string containing characters to avoid.
2135 * @param __pos Index of character to search back from.
2136 * @param __n Number of characters from s to consider.
2137 * @return Index of last occurrence.
2139 * Starting from @a __pos, searches backward for a character not
2140 * contained in the first @a __n characters of @a __s within this string.
2141 * If found, returns the index where it was found. If not found,
2145 find_last_not_of(const _CharT
* __s
, size_type __pos
,
2146 size_type __n
) const;
2148 * @brief Find last position of a character not in C string.
2149 * @param __s C string containing characters to avoid.
2150 * @param __pos Index of character to search back from (default end).
2151 * @return Index of last occurrence.
2153 * Starting from @a __pos, searches backward for a character
2154 * not contained in @a __s within this string. If found,
2155 * returns the index where it was found. If not found, returns
2159 find_last_not_of(const _CharT
* __s
, size_type __pos
= npos
) const
2161 __glibcxx_requires_string(__s
);
2162 return this->find_last_not_of(__s
, __pos
, traits_type::length(__s
));
2166 * @brief Find last position of a different character.
2167 * @param __c Character to avoid.
2168 * @param __pos Index of character to search back from (default end).
2169 * @return Index of last occurrence.
2171 * Starting from @a __pos, searches backward for a character other than
2172 * @a __c within this string. If found, returns the index where it was
2173 * found. If not found, returns npos.
2176 find_last_not_of(_CharT __c
, size_type __pos
= npos
) const
2180 * @brief Get a substring.
2181 * @param __pos Index of first character (default 0).
2182 * @param __n Number of characters in substring (default remainder).
2183 * @return The new string.
2184 * @throw std::out_of_range If __pos > size().
2186 * Construct and return a new string using the @a __n
2187 * characters starting at @a __pos. If the string is too
2188 * short, use the remainder of the characters. If @a __pos is
2189 * beyond the end of the string, out_of_range is thrown.
2192 substr(size_type __pos
= 0, size_type __n
= npos
) const
2193 { return basic_string(*this,
2194 _M_check(__pos
, "basic_string::substr"), __n
); }
2197 * @brief Compare to a string.
2198 * @param __str String to compare against.
2199 * @return Integer < 0, 0, or > 0.
2201 * Returns an integer < 0 if this string is ordered before @a
2202 * __str, 0 if their values are equivalent, or > 0 if this
2203 * string is ordered after @a __str. Determines the effective
2204 * length rlen of the strings to compare as the smallest of
2205 * size() and str.size(). The function then compares the two
2206 * strings by calling traits::compare(data(), str.data(),rlen).
2207 * If the result of the comparison is nonzero returns it,
2208 * otherwise the shorter one is ordered first.
2211 compare(const basic_string
& __str
) const
2213 const size_type __size
= this->size();
2214 const size_type __osize
= __str
.size();
2215 const size_type __len
= std::min(__size
, __osize
);
2217 int __r
= traits_type::compare(_M_data(), __str
.data(), __len
);
2219 __r
= _S_compare(__size
, __osize
);
2224 * @brief Compare substring to a string.
2225 * @param __pos Index of first character of substring.
2226 * @param __n Number of characters in substring.
2227 * @param __str String to compare against.
2228 * @return Integer < 0, 0, or > 0.
2230 * Form the substring of this string from the @a __n characters
2231 * starting at @a __pos. Returns an integer < 0 if the
2232 * substring is ordered before @a __str, 0 if their values are
2233 * equivalent, or > 0 if the substring is ordered after @a
2234 * __str. Determines the effective length rlen of the strings
2235 * to compare as the smallest of the length of the substring
2236 * and @a __str.size(). The function then compares the two
2237 * strings by calling
2238 * traits::compare(substring.data(),str.data(),rlen). If the
2239 * result of the comparison is nonzero returns it, otherwise
2240 * the shorter one is ordered first.
2243 compare(size_type __pos
, size_type __n
, const basic_string
& __str
) const;
2246 * @brief Compare substring to a substring.
2247 * @param __pos1 Index of first character of substring.
2248 * @param __n1 Number of characters in substring.
2249 * @param __str String to compare against.
2250 * @param __pos2 Index of first character of substring of str.
2251 * @param __n2 Number of characters in substring of str.
2252 * @return Integer < 0, 0, or > 0.
2254 * Form the substring of this string from the @a __n1
2255 * characters starting at @a __pos1. Form the substring of @a
2256 * __str from the @a __n2 characters starting at @a __pos2.
2257 * Returns an integer < 0 if this substring is ordered before
2258 * the substring of @a __str, 0 if their values are equivalent,
2259 * or > 0 if this substring is ordered after the substring of
2260 * @a __str. Determines the effective length rlen of the
2261 * strings to compare as the smallest of the lengths of the
2262 * substrings. The function then compares the two strings by
2264 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
2265 * If the result of the comparison is nonzero returns it,
2266 * otherwise the shorter one is ordered first.
2269 compare(size_type __pos1
, size_type __n1
, const basic_string
& __str
,
2270 size_type __pos2
, size_type __n2
) const;
2273 * @brief Compare to a C string.
2274 * @param __s C string to compare against.
2275 * @return Integer < 0, 0, or > 0.
2277 * Returns an integer < 0 if this string is ordered before @a __s, 0 if
2278 * their values are equivalent, or > 0 if this string is ordered after
2279 * @a __s. Determines the effective length rlen of the strings to
2280 * compare as the smallest of size() and the length of a string
2281 * constructed from @a __s. The function then compares the two strings
2282 * by calling traits::compare(data(),s,rlen). If the result of the
2283 * comparison is nonzero returns it, otherwise the shorter one is
2287 compare(const _CharT
* __s
) const;
2289 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2290 // 5 String::compare specification questionable
2292 * @brief Compare substring to a C string.
2293 * @param __pos Index of first character of substring.
2294 * @param __n1 Number of characters in substring.
2295 * @param __s C string to compare against.
2296 * @return Integer < 0, 0, or > 0.
2298 * Form the substring of this string from the @a __n1
2299 * characters starting at @a pos. Returns an integer < 0 if
2300 * the substring is ordered before @a __s, 0 if their values
2301 * are equivalent, or > 0 if the substring is ordered after @a
2302 * __s. Determines the effective length rlen of the strings to
2303 * compare as the smallest of the length of the substring and
2304 * the length of a string constructed from @a __s. The
2305 * function then compares the two string by calling
2306 * traits::compare(substring.data(),__s,rlen). If the result of
2307 * the comparison is nonzero returns it, otherwise the shorter
2308 * one is ordered first.
2311 compare(size_type __pos
, size_type __n1
, const _CharT
* __s
) const;
2314 * @brief Compare substring against a character %array.
2315 * @param __pos Index of first character of substring.
2316 * @param __n1 Number of characters in substring.
2317 * @param __s character %array to compare against.
2318 * @param __n2 Number of characters of s.
2319 * @return Integer < 0, 0, or > 0.
2321 * Form the substring of this string from the @a __n1
2322 * characters starting at @a __pos. Form a string from the
2323 * first @a __n2 characters of @a __s. Returns an integer < 0
2324 * if this substring is ordered before the string from @a __s,
2325 * 0 if their values are equivalent, or > 0 if this substring
2326 * is ordered after the string from @a __s. Determines the
2327 * effective length rlen of the strings to compare as the
2328 * smallest of the length of the substring and @a __n2. The
2329 * function then compares the two strings by calling
2330 * traits::compare(substring.data(),s,rlen). If the result of
2331 * the comparison is nonzero returns it, otherwise the shorter
2332 * one is ordered first.
2334 * NB: s must have at least n2 characters, '\\0' has
2335 * no special meaning.
2338 compare(size_type __pos
, size_type __n1
, const _CharT
* __s
,
2339 size_type __n2
) const;
2344 * @brief Concatenate two strings.
2345 * @param __lhs First string.
2346 * @param __rhs Last string.
2347 * @return New string with value of @a __lhs followed by @a __rhs.
2349 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2350 basic_string
<_CharT
, _Traits
, _Alloc
>
2351 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2352 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2354 basic_string
<_CharT
, _Traits
, _Alloc
> __str(__lhs
);
2355 __str
.append(__rhs
);
2360 * @brief Concatenate C string and string.
2361 * @param __lhs First string.
2362 * @param __rhs Last string.
2363 * @return New string with value of @a __lhs followed by @a __rhs.
2365 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2366 basic_string
<_CharT
,_Traits
,_Alloc
>
2367 operator+(const _CharT
* __lhs
,
2368 const basic_string
<_CharT
,_Traits
,_Alloc
>& __rhs
);
2371 * @brief Concatenate character and string.
2372 * @param __lhs First string.
2373 * @param __rhs Last string.
2374 * @return New string with @a __lhs followed by @a __rhs.
2376 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2377 basic_string
<_CharT
,_Traits
,_Alloc
>
2378 operator+(_CharT __lhs
, const basic_string
<_CharT
,_Traits
,_Alloc
>& __rhs
);
2381 * @brief Concatenate string and C string.
2382 * @param __lhs First string.
2383 * @param __rhs Last string.
2384 * @return New string with @a __lhs followed by @a __rhs.
2386 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2387 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2388 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2389 const _CharT
* __rhs
)
2391 basic_string
<_CharT
, _Traits
, _Alloc
> __str(__lhs
);
2392 __str
.append(__rhs
);
2397 * @brief Concatenate string and character.
2398 * @param __lhs First string.
2399 * @param __rhs Last string.
2400 * @return New string with @a __lhs followed by @a __rhs.
2402 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2403 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2404 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
, _CharT __rhs
)
2406 typedef basic_string
<_CharT
, _Traits
, _Alloc
> __string_type
;
2407 typedef typename
__string_type::size_type __size_type
;
2408 __string_type
__str(__lhs
);
2409 __str
.append(__size_type(1), __rhs
);
2413 #ifdef __GXX_EXPERIMENTAL_CXX0X__
2414 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2415 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2416 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
2417 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2418 { return std::move(__lhs
.append(__rhs
)); }
2420 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2421 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2422 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2423 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
2424 { return std::move(__rhs
.insert(0, __lhs
)); }
2426 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2427 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2428 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
2429 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
2431 const auto __size
= __lhs
.size() + __rhs
.size();
2432 const bool __cond
= (__size
> __lhs
.capacity()
2433 && __size
<= __rhs
.capacity());
2434 return __cond
? std::move(__rhs
.insert(0, __lhs
))
2435 : std::move(__lhs
.append(__rhs
));
2438 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2439 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2440 operator+(const _CharT
* __lhs
,
2441 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
2442 { return std::move(__rhs
.insert(0, __lhs
)); }
2444 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2445 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2446 operator+(_CharT __lhs
,
2447 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
2448 { return std::move(__rhs
.insert(0, 1, __lhs
)); }
2450 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2451 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2452 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
2453 const _CharT
* __rhs
)
2454 { return std::move(__lhs
.append(__rhs
)); }
2456 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2457 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2458 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
2460 { return std::move(__lhs
.append(1, __rhs
)); }
2465 * @brief Test equivalence of two strings.
2466 * @param __lhs First string.
2467 * @param __rhs Second string.
2468 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2470 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2472 operator==(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2473 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2474 { return __lhs
.compare(__rhs
) == 0; }
2476 template<typename _CharT
>
2478 typename
__gnu_cxx::__enable_if
<__is_char
<_CharT
>::__value
, bool>::__type
2479 operator==(const basic_string
<_CharT
>& __lhs
,
2480 const basic_string
<_CharT
>& __rhs
)
2481 { return (__lhs
.size() == __rhs
.size()
2482 && !std::char_traits
<_CharT
>::compare(__lhs
.data(), __rhs
.data(),
2486 * @brief Test equivalence of C string and string.
2487 * @param __lhs C string.
2488 * @param __rhs String.
2489 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
2491 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2493 operator==(const _CharT
* __lhs
,
2494 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2495 { return __rhs
.compare(__lhs
) == 0; }
2498 * @brief Test equivalence of string and C string.
2499 * @param __lhs String.
2500 * @param __rhs C string.
2501 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2503 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2505 operator==(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2506 const _CharT
* __rhs
)
2507 { return __lhs
.compare(__rhs
) == 0; }
2511 * @brief Test difference of two strings.
2512 * @param __lhs First string.
2513 * @param __rhs Second string.
2514 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2516 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2518 operator!=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2519 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2520 { return !(__lhs
== __rhs
); }
2523 * @brief Test difference of C string and string.
2524 * @param __lhs C string.
2525 * @param __rhs String.
2526 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
2528 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2530 operator!=(const _CharT
* __lhs
,
2531 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2532 { return !(__lhs
== __rhs
); }
2535 * @brief Test difference of string and C string.
2536 * @param __lhs String.
2537 * @param __rhs C string.
2538 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2540 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2542 operator!=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2543 const _CharT
* __rhs
)
2544 { return !(__lhs
== __rhs
); }
2548 * @brief Test if string precedes string.
2549 * @param __lhs First string.
2550 * @param __rhs Second string.
2551 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2553 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2555 operator<(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2556 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2557 { return __lhs
.compare(__rhs
) < 0; }
2560 * @brief Test if string precedes C string.
2561 * @param __lhs String.
2562 * @param __rhs C string.
2563 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2565 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2567 operator<(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2568 const _CharT
* __rhs
)
2569 { return __lhs
.compare(__rhs
) < 0; }
2572 * @brief Test if C string precedes string.
2573 * @param __lhs C string.
2574 * @param __rhs String.
2575 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2577 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2579 operator<(const _CharT
* __lhs
,
2580 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2581 { return __rhs
.compare(__lhs
) > 0; }
2585 * @brief Test if string follows string.
2586 * @param __lhs First string.
2587 * @param __rhs Second string.
2588 * @return True if @a __lhs follows @a __rhs. False otherwise.
2590 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2592 operator>(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2593 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2594 { return __lhs
.compare(__rhs
) > 0; }
2597 * @brief Test if string follows C string.
2598 * @param __lhs String.
2599 * @param __rhs C string.
2600 * @return True if @a __lhs follows @a __rhs. False otherwise.
2602 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2604 operator>(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2605 const _CharT
* __rhs
)
2606 { return __lhs
.compare(__rhs
) > 0; }
2609 * @brief Test if C string follows string.
2610 * @param __lhs C string.
2611 * @param __rhs String.
2612 * @return True if @a __lhs follows @a __rhs. False otherwise.
2614 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2616 operator>(const _CharT
* __lhs
,
2617 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2618 { return __rhs
.compare(__lhs
) < 0; }
2622 * @brief Test if string doesn't follow string.
2623 * @param __lhs First string.
2624 * @param __rhs Second string.
2625 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2627 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2629 operator<=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2630 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2631 { return __lhs
.compare(__rhs
) <= 0; }
2634 * @brief Test if string doesn't follow C string.
2635 * @param __lhs String.
2636 * @param __rhs C string.
2637 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2639 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2641 operator<=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2642 const _CharT
* __rhs
)
2643 { return __lhs
.compare(__rhs
) <= 0; }
2646 * @brief Test if C string doesn't follow string.
2647 * @param __lhs C string.
2648 * @param __rhs String.
2649 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2651 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2653 operator<=(const _CharT
* __lhs
,
2654 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2655 { return __rhs
.compare(__lhs
) >= 0; }
2659 * @brief Test if string doesn't precede string.
2660 * @param __lhs First string.
2661 * @param __rhs Second string.
2662 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2664 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2666 operator>=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2667 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2668 { return __lhs
.compare(__rhs
) >= 0; }
2671 * @brief Test if string doesn't precede C string.
2672 * @param __lhs String.
2673 * @param __rhs C string.
2674 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2676 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2678 operator>=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2679 const _CharT
* __rhs
)
2680 { return __lhs
.compare(__rhs
) >= 0; }
2683 * @brief Test if C string doesn't precede string.
2684 * @param __lhs C string.
2685 * @param __rhs String.
2686 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2688 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2690 operator>=(const _CharT
* __lhs
,
2691 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2692 { return __rhs
.compare(__lhs
) <= 0; }
2695 * @brief Swap contents of two strings.
2696 * @param __lhs First string.
2697 * @param __rhs Second string.
2699 * Exchanges the contents of @a __lhs and @a __rhs in constant time.
2701 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2703 swap(basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2704 basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2705 { __lhs
.swap(__rhs
); }
2708 * @brief Read stream into a string.
2709 * @param __is Input stream.
2710 * @param __str Buffer to store into.
2711 * @return Reference to the input stream.
2713 * Stores characters from @a __is into @a __str until whitespace is
2714 * found, the end of the stream is encountered, or str.max_size()
2715 * is reached. If is.width() is non-zero, that is the limit on the
2716 * number of characters stored into @a __str. Any previous
2717 * contents of @a __str are erased.
2719 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2720 basic_istream
<_CharT
, _Traits
>&
2721 operator>>(basic_istream
<_CharT
, _Traits
>& __is
,
2722 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
);
2725 basic_istream
<char>&
2726 operator>>(basic_istream
<char>& __is
, basic_string
<char>& __str
);
2729 * @brief Write string to a stream.
2730 * @param __os Output stream.
2731 * @param __str String to write out.
2732 * @return Reference to the output stream.
2734 * Output characters of @a __str into os following the same rules as for
2735 * writing a C string.
2737 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2738 inline basic_ostream
<_CharT
, _Traits
>&
2739 operator<<(basic_ostream
<_CharT
, _Traits
>& __os
,
2740 const basic_string
<_CharT
, _Traits
, _Alloc
>& __str
)
2742 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2743 // 586. string inserter not a formatted function
2744 return __ostream_insert(__os
, __str
.data(), __str
.size());
2748 * @brief Read a line from stream into a string.
2749 * @param __is Input stream.
2750 * @param __str Buffer to store into.
2751 * @param __delim Character marking end of line.
2752 * @return Reference to the input stream.
2754 * Stores characters from @a __is into @a __str until @a __delim is
2755 * found, the end of the stream is encountered, or str.max_size()
2756 * is reached. If is.width() is non-zero, that is the limit on the
2757 * number of characters stored into @a __str. Any previous
2758 * contents of @a __str are erased. If @a __delim was encountered,
2759 * it is extracted but not stored into @a __str.
2761 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2762 basic_istream
<_CharT
, _Traits
>&
2763 getline(basic_istream
<_CharT
, _Traits
>& __is
,
2764 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
, _CharT __delim
);
2767 * @brief Read a line from stream into a string.
2768 * @param __is Input stream.
2769 * @param __str Buffer to store into.
2770 * @return Reference to the input stream.
2772 * Stores characters from is into @a __str until '\n' is
2773 * found, the end of the stream is encountered, or str.max_size()
2774 * is reached. If __is.width() is non-zero, that is the limit on
2775 * the number of characters stored into @a __str. Any previous
2776 * contents of @a __str are erased. If end of line was
2777 * encountered, it is extracted but not stored into @a __str.
2779 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2780 inline basic_istream
<_CharT
, _Traits
>&
2781 getline(basic_istream
<_CharT
, _Traits
>& __is
,
2782 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
)
2783 { return getline(__is
, __str
, __is
.widen('\n')); }
2786 basic_istream
<char>&
2787 getline(basic_istream
<char>& __in
, basic_string
<char>& __str
,
2790 #ifdef _GLIBCXX_USE_WCHAR_T
2792 basic_istream
<wchar_t>&
2793 getline(basic_istream
<wchar_t>& __in
, basic_string
<wchar_t>& __str
,
2797 _GLIBCXX_END_NAMESPACE_VERSION
2800 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99) \
2801 && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
2803 #include <ext/string_conversions.h>
2805 namespace std
_GLIBCXX_VISIBILITY(default)
2807 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2809 // 21.4 Numeric Conversions [string.conversions].
2811 stoi(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
2812 { return __gnu_cxx::__stoa
<long, int>(&std::strtol
, "stoi", __str
.c_str(),
2816 stol(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
2817 { return __gnu_cxx::__stoa(&std::strtol
, "stol", __str
.c_str(),
2820 inline unsigned long
2821 stoul(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
2822 { return __gnu_cxx::__stoa(&std::strtoul
, "stoul", __str
.c_str(),
2826 stoll(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
2827 { return __gnu_cxx::__stoa(&std::strtoll
, "stoll", __str
.c_str(),
2830 inline unsigned long long
2831 stoull(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
2832 { return __gnu_cxx::__stoa(&std::strtoull
, "stoull", __str
.c_str(),
2835 // NB: strtof vs strtod.
2837 stof(const string
& __str
, size_t* __idx
= 0)
2838 { return __gnu_cxx::__stoa(&std::strtof
, "stof", __str
.c_str(), __idx
); }
2841 stod(const string
& __str
, size_t* __idx
= 0)
2842 { return __gnu_cxx::__stoa(&std::strtod
, "stod", __str
.c_str(), __idx
); }
2845 stold(const string
& __str
, size_t* __idx
= 0)
2846 { return __gnu_cxx::__stoa(&std::strtold
, "stold", __str
.c_str(), __idx
); }
2848 // NB: (v)snprintf vs sprintf.
2852 to_string(int __val
)
2853 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, 4 * sizeof(int),
2857 to_string(unsigned __val
)
2858 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
2859 4 * sizeof(unsigned),
2863 to_string(long __val
)
2864 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, 4 * sizeof(long),
2868 to_string(unsigned long __val
)
2869 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
2870 4 * sizeof(unsigned long),
2874 to_string(long long __val
)
2875 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
2876 4 * sizeof(long long),
2880 to_string(unsigned long long __val
)
2881 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
2882 4 * sizeof(unsigned long long),
2886 to_string(float __val
)
2889 __gnu_cxx::__numeric_traits
<float>::__max_exponent10
+ 20;
2890 return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, __n
,
2895 to_string(double __val
)
2898 __gnu_cxx::__numeric_traits
<double>::__max_exponent10
+ 20;
2899 return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, __n
,
2904 to_string(long double __val
)
2907 __gnu_cxx::__numeric_traits
<long double>::__max_exponent10
+ 20;
2908 return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, __n
,
2912 #ifdef _GLIBCXX_USE_WCHAR_T
2914 stoi(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
2915 { return __gnu_cxx::__stoa
<long, int>(&std::wcstol
, "stoi", __str
.c_str(),
2919 stol(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
2920 { return __gnu_cxx::__stoa(&std::wcstol
, "stol", __str
.c_str(),
2923 inline unsigned long
2924 stoul(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
2925 { return __gnu_cxx::__stoa(&std::wcstoul
, "stoul", __str
.c_str(),
2929 stoll(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
2930 { return __gnu_cxx::__stoa(&std::wcstoll
, "stoll", __str
.c_str(),
2933 inline unsigned long long
2934 stoull(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
2935 { return __gnu_cxx::__stoa(&std::wcstoull
, "stoull", __str
.c_str(),
2938 // NB: wcstof vs wcstod.
2940 stof(const wstring
& __str
, size_t* __idx
= 0)
2941 { return __gnu_cxx::__stoa(&std::wcstof
, "stof", __str
.c_str(), __idx
); }
2944 stod(const wstring
& __str
, size_t* __idx
= 0)
2945 { return __gnu_cxx::__stoa(&std::wcstod
, "stod", __str
.c_str(), __idx
); }
2948 stold(const wstring
& __str
, size_t* __idx
= 0)
2949 { return __gnu_cxx::__stoa(&std::wcstold
, "stold", __str
.c_str(), __idx
); }
2953 to_wstring(int __val
)
2954 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, 4 * sizeof(int),
2958 to_wstring(unsigned __val
)
2959 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
2960 4 * sizeof(unsigned),
2964 to_wstring(long __val
)
2965 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, 4 * sizeof(long),
2969 to_wstring(unsigned long __val
)
2970 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
2971 4 * sizeof(unsigned long),
2975 to_wstring(long long __val
)
2976 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
2977 4 * sizeof(long long),
2981 to_wstring(unsigned long long __val
)
2982 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
2983 4 * sizeof(unsigned long long),
2987 to_wstring(float __val
)
2990 __gnu_cxx::__numeric_traits
<float>::__max_exponent10
+ 20;
2991 return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, __n
,
2996 to_wstring(double __val
)
2999 __gnu_cxx::__numeric_traits
<double>::__max_exponent10
+ 20;
3000 return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, __n
,
3005 to_wstring(long double __val
)
3008 __gnu_cxx::__numeric_traits
<long double>::__max_exponent10
+ 20;
3009 return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, __n
,
3014 _GLIBCXX_END_NAMESPACE_VERSION
3017 #endif /* __GXX_EXPERIMENTAL_CXX0X__ && _GLIBCXX_USE_C99 ... */
3019 #ifdef __GXX_EXPERIMENTAL_CXX0X__
3021 #include <bits/functional_hash.h>
3023 namespace std
_GLIBCXX_VISIBILITY(default)
3025 _GLIBCXX_BEGIN_NAMESPACE_VERSION
3029 #ifndef _GLIBCXX_COMPATIBILITY_CXX0X
3030 /// std::hash specialization for string.
3033 : public __hash_base
<size_t, string
>
3036 operator()(const string
& __s
) const
3037 { return std::_Hash_impl::hash(__s
.data(), __s
.length()); }
3040 #ifdef _GLIBCXX_USE_WCHAR_T
3041 /// std::hash specialization for wstring.
3043 struct hash
<wstring
>
3044 : public __hash_base
<size_t, wstring
>
3047 operator()(const wstring
& __s
) const
3048 { return std::_Hash_impl::hash(__s
.data(),
3049 __s
.length() * sizeof(wchar_t)); }
3052 #endif /* _GLIBCXX_COMPATIBILITY_CXX0X */
3054 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
3055 /// std::hash specialization for u16string.
3057 struct hash
<u16string
>
3058 : public __hash_base
<size_t, u16string
>
3061 operator()(const u16string
& __s
) const
3062 { return std::_Hash_impl::hash(__s
.data(),
3063 __s
.length() * sizeof(char16_t
)); }
3066 /// std::hash specialization for u32string.
3068 struct hash
<u32string
>
3069 : public __hash_base
<size_t, u32string
>
3072 operator()(const u32string
& __s
) const
3073 { return std::_Hash_impl::hash(__s
.data(),
3074 __s
.length() * sizeof(char32_t
)); }
3078 _GLIBCXX_END_NAMESPACE_VERSION
3081 #endif /* __GXX_EXPERIMENTAL_CXX0X__ */
3083 #endif /* _BASIC_STRING_H */