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
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 #include <initializer_list>
45 _GLIBCXX_BEGIN_NAMESPACE(std
)
48 * @class basic_string basic_string.h <string>
49 * @brief Managing sequences of characters and character-like objects.
54 * Meets the requirements of a <a href="tables.html#65">container</a>, a
55 * <a href="tables.html#66">reversible container</a>, and a
56 * <a href="tables.html#67">sequence</a>. Of the
57 * <a href="tables.html#68">optional sequence requirements</a>, only
58 * @c push_back, @c at, and @c %array access are supported.
63 * Documentation? What's that?
64 * Nathan Myers <ncm@cantrip.org>.
66 * A string looks like this:
71 * [basic_string<char_type>] _M_capacity
72 * _M_dataplus _M_refcount
73 * _M_p ----------------> unnamed array of char_type
76 * Where the _M_p points to the first character in the string, and
77 * you cast it to a pointer-to-_Rep and subtract 1 to get a
78 * pointer to the header.
80 * This approach has the enormous advantage that a string object
81 * requires only one allocation. All the ugliness is confined
82 * within a single %pair of inline functions, which each compile to
83 * a single @a add instruction: _Rep::_M_data(), and
84 * string::_M_rep(); and the allocation function which gets a
85 * block of raw bytes and with room enough and constructs a _Rep
86 * object at the front.
88 * The reason you want _M_data pointing to the character %array and
89 * not the _Rep is so that the debugger can see the string
90 * contents. (Probably we should add a non-inline member to get
91 * the _Rep for the debugger to use, so users can check the actual
94 * Note that the _Rep object is a POD so that you can have a
95 * static <em>empty string</em> _Rep object already @a constructed before
96 * static constructors have run. The reference-count encoding is
97 * chosen so that a 0 indicates one reference, so you never try to
98 * destroy the empty-string _Rep object.
100 * All but the last paragraph is considered pretty conventional
101 * for a C++ string implementation.
103 // 21.3 Template class basic_string
104 template<typename _CharT
, typename _Traits
, typename _Alloc
>
107 typedef typename
_Alloc::template rebind
<_CharT
>::other _CharT_alloc_type
;
111 typedef _Traits traits_type
;
112 typedef typename
_Traits::char_type value_type
;
113 typedef _Alloc allocator_type
;
114 typedef typename
_CharT_alloc_type::size_type size_type
;
115 typedef typename
_CharT_alloc_type::difference_type difference_type
;
116 typedef typename
_CharT_alloc_type::reference reference
;
117 typedef typename
_CharT_alloc_type::const_reference const_reference
;
118 typedef typename
_CharT_alloc_type::pointer pointer
;
119 typedef typename
_CharT_alloc_type::const_pointer const_pointer
;
120 typedef __gnu_cxx::__normal_iterator
<pointer
, basic_string
> iterator
;
121 typedef __gnu_cxx::__normal_iterator
<const_pointer
, basic_string
>
123 typedef std::reverse_iterator
<const_iterator
> const_reverse_iterator
;
124 typedef std::reverse_iterator
<iterator
> reverse_iterator
;
127 // _Rep: string representation
129 // 1. String really contains _M_length + 1 characters: due to 21.3.4
130 // must be kept null-terminated.
131 // 2. _M_capacity >= _M_length
132 // Allocated memory is always (_M_capacity + 1) * sizeof(_CharT).
133 // 3. _M_refcount has three states:
134 // -1: leaked, one reference, no ref-copies allowed, non-const.
135 // 0: one reference, non-const.
136 // n>0: n + 1 references, operations require a lock, const.
137 // 4. All fields==0 is an empty string, given the extra storage
138 // beyond-the-end for a null terminator; thus, the shared
139 // empty string representation needs no constructor.
144 size_type _M_capacity
;
145 _Atomic_word _M_refcount
;
148 struct _Rep
: _Rep_base
151 typedef typename
_Alloc::template rebind
<char>::other _Raw_bytes_alloc
;
153 // (Public) Data members:
155 // The maximum number of individual char_type elements of an
156 // individual string is determined by _S_max_size. This is the
157 // value that will be returned by max_size(). (Whereas npos
158 // is the maximum number of bytes the allocator can allocate.)
159 // If one was to divvy up the theoretical largest size string,
160 // with a terminating character and m _CharT elements, it'd
162 // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
164 // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
165 // In addition, this implementation quarters this amount.
166 static const size_type _S_max_size
;
167 static const _CharT _S_terminal
;
169 // The following storage is init'd to 0 by the linker, resulting
170 // (carefully) in an empty string with one reference.
171 static size_type _S_empty_rep_storage
[];
176 // NB: Mild hack to avoid strict-aliasing warnings. Note that
177 // _S_empty_rep_storage is never modified and the punning should
178 // be reasonably safe in this case.
179 void* __p
= reinterpret_cast<void*>(&_S_empty_rep_storage
);
180 return *reinterpret_cast<_Rep
*>(__p
);
185 { return this->_M_refcount
< 0; }
189 { return this->_M_refcount
> 0; }
193 { this->_M_refcount
= -1; }
197 { this->_M_refcount
= 0; }
200 _M_set_length_and_sharable(size_type __n
)
202 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
203 if (__builtin_expect(this != &_S_empty_rep(), false))
206 this->_M_set_sharable(); // One reference.
207 this->_M_length
= __n
;
208 traits_type::assign(this->_M_refdata()[__n
], _S_terminal
);
209 // grrr. (per 21.3.4)
210 // You cannot leave those LWG people alone for a second.
216 { return reinterpret_cast<_CharT
*>(this + 1); }
219 _M_grab(const _Alloc
& __alloc1
, const _Alloc
& __alloc2
)
221 return (!_M_is_leaked() && __alloc1
== __alloc2
)
222 ? _M_refcopy() : _M_clone(__alloc1
);
227 _S_create(size_type
, size_type
, const _Alloc
&);
230 _M_dispose(const _Alloc
& __a
)
232 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
233 if (__builtin_expect(this != &_S_empty_rep(), false))
236 // Be race-detector-friendly. For more info see bits/c++config.
237 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount
);
238 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount
,
241 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount
);
248 _M_destroy(const _Alloc
&) throw();
253 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
254 if (__builtin_expect(this != &_S_empty_rep(), false))
256 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount
, 1);
261 _M_clone(const _Alloc
&, size_type __res
= 0);
264 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
265 struct _Alloc_hider
: _Alloc
267 _Alloc_hider(_CharT
* __dat
, const _Alloc
& __a
)
268 : _Alloc(__a
), _M_p(__dat
) { }
270 _CharT
* _M_p
; // The actual data.
274 // Data Members (public):
275 // NB: This is an unsigned type, and thus represents the maximum
276 // size that the allocator can hold.
277 /// Value returned by various member functions when they fail.
278 static const size_type npos
= static_cast<size_type
>(-1);
281 // Data Members (private):
282 mutable _Alloc_hider _M_dataplus
;
286 { return _M_dataplus
._M_p
; }
290 { return (_M_dataplus
._M_p
= __p
); }
294 { return &((reinterpret_cast<_Rep
*> (_M_data()))[-1]); }
296 // For the internal use we have functions similar to `begin'/`end'
297 // but they do not call _M_leak.
300 { return iterator(_M_data()); }
304 { return iterator(_M_data() + this->size()); }
307 _M_leak() // for use in begin() & non-const op[]
309 if (!_M_rep()->_M_is_leaked())
314 _M_check(size_type __pos
, const char* __s
) const
316 if (__pos
> this->size())
317 __throw_out_of_range(__N(__s
));
322 _M_check_length(size_type __n1
, size_type __n2
, const char* __s
) const
324 if (this->max_size() - (this->size() - __n1
) < __n2
)
325 __throw_length_error(__N(__s
));
328 // NB: _M_limit doesn't check for a bad __pos value.
330 _M_limit(size_type __pos
, size_type __off
) const
332 const bool __testoff
= __off
< this->size() - __pos
;
333 return __testoff
? __off
: this->size() - __pos
;
336 // True if _Rep and source do not overlap.
338 _M_disjunct(const _CharT
* __s
) const
340 return (less
<const _CharT
*>()(__s
, _M_data())
341 || less
<const _CharT
*>()(_M_data() + this->size(), __s
));
344 // When __n = 1 way faster than the general multichar
345 // traits_type::copy/move/assign.
347 _M_copy(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
350 traits_type::assign(*__d
, *__s
);
352 traits_type::copy(__d
, __s
, __n
);
356 _M_move(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
359 traits_type::assign(*__d
, *__s
);
361 traits_type::move(__d
, __s
, __n
);
365 _M_assign(_CharT
* __d
, size_type __n
, _CharT __c
)
368 traits_type::assign(*__d
, __c
);
370 traits_type::assign(__d
, __n
, __c
);
373 // _S_copy_chars is a separate template to permit specialization
374 // to optimize for the common case of pointers as iterators.
375 template<class _Iterator
>
377 _S_copy_chars(_CharT
* __p
, _Iterator __k1
, _Iterator __k2
)
379 for (; __k1
!= __k2
; ++__k1
, ++__p
)
380 traits_type::assign(*__p
, *__k1
); // These types are off.
384 _S_copy_chars(_CharT
* __p
, iterator __k1
, iterator __k2
)
385 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
388 _S_copy_chars(_CharT
* __p
, const_iterator __k1
, const_iterator __k2
)
389 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
392 _S_copy_chars(_CharT
* __p
, _CharT
* __k1
, _CharT
* __k2
)
393 { _M_copy(__p
, __k1
, __k2
- __k1
); }
396 _S_copy_chars(_CharT
* __p
, const _CharT
* __k1
, const _CharT
* __k2
)
397 { _M_copy(__p
, __k1
, __k2
- __k1
); }
400 _S_compare(size_type __n1
, size_type __n2
)
402 const difference_type __d
= difference_type(__n1
- __n2
);
404 if (__d
> __gnu_cxx::__numeric_traits
<int>::__max
)
405 return __gnu_cxx::__numeric_traits
<int>::__max
;
406 else if (__d
< __gnu_cxx::__numeric_traits
<int>::__min
)
407 return __gnu_cxx::__numeric_traits
<int>::__min
;
413 _M_mutate(size_type __pos
, size_type __len1
, size_type __len2
);
420 { return _Rep::_S_empty_rep(); }
423 // Construct/copy/destroy:
424 // NB: We overload ctors in some cases instead of using default
425 // arguments, per 17.4.4.4 para. 2 item 2.
428 * @brief Default constructor creates an empty string.
431 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
432 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
434 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()){ }
438 * @brief Construct an empty string using allocator @a a.
441 basic_string(const _Alloc
& __a
);
443 // NB: per LWG issue 42, semantics different from IS:
445 * @brief Construct string with copy of value of @a str.
446 * @param str Source string.
448 basic_string(const basic_string
& __str
);
450 * @brief Construct string as copy of a substring.
451 * @param str Source string.
452 * @param pos Index of first character to copy from.
453 * @param n Number of characters to copy (default remainder).
455 basic_string(const basic_string
& __str
, size_type __pos
,
456 size_type __n
= npos
);
458 * @brief Construct string as copy of a substring.
459 * @param str Source string.
460 * @param pos Index of first character to copy from.
461 * @param n Number of characters to copy.
462 * @param a Allocator to use.
464 basic_string(const basic_string
& __str
, size_type __pos
,
465 size_type __n
, const _Alloc
& __a
);
468 * @brief Construct string initialized by a character %array.
469 * @param s Source character %array.
470 * @param n Number of characters to copy.
471 * @param a Allocator to use (default is default allocator).
473 * NB: @a s must have at least @a n characters, '\\0'
474 * has no special meaning.
476 basic_string(const _CharT
* __s
, size_type __n
,
477 const _Alloc
& __a
= _Alloc());
479 * @brief Construct string as copy of a C string.
480 * @param s Source C string.
481 * @param a Allocator to use (default is default allocator).
483 basic_string(const _CharT
* __s
, const _Alloc
& __a
= _Alloc());
485 * @brief Construct string as multiple characters.
486 * @param n Number of characters.
487 * @param c Character to use.
488 * @param a Allocator to use (default is default allocator).
490 basic_string(size_type __n
, _CharT __c
, const _Alloc
& __a
= _Alloc());
492 #ifdef __GXX_EXPERIMENTAL_CXX0X__
494 * @brief Move construct string.
495 * @param str Source string.
497 * The newly-created string contains the exact contents of @a str.
498 * @a str is a valid, but unspecified string.
500 basic_string(basic_string
&& __str
)
501 : _M_dataplus(__str
._M_dataplus
)
503 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
504 __str
._M_data(_S_empty_rep()._M_refdata());
506 __str
._M_data(_S_construct(size_type(), _CharT(), get_allocator()));
511 * @brief Construct string from an initializer %list.
512 * @param l std::initializer_list of characters.
513 * @param a Allocator to use (default is default allocator).
515 basic_string(initializer_list
<_CharT
> __l
, const _Alloc
& __a
= _Alloc());
516 #endif // __GXX_EXPERIMENTAL_CXX0X__
519 * @brief Construct string as copy of a range.
520 * @param beg Start of range.
521 * @param end End of range.
522 * @param a Allocator to use (default is default allocator).
524 template<class _InputIterator
>
525 basic_string(_InputIterator __beg
, _InputIterator __end
,
526 const _Alloc
& __a
= _Alloc());
529 * @brief Destroy the string instance.
532 { _M_rep()->_M_dispose(this->get_allocator()); }
535 * @brief Assign the value of @a str to this string.
536 * @param str Source string.
539 operator=(const basic_string
& __str
)
540 { return this->assign(__str
); }
543 * @brief Copy contents of @a s into this string.
544 * @param s Source null-terminated string.
547 operator=(const _CharT
* __s
)
548 { return this->assign(__s
); }
551 * @brief Set value to string of length 1.
552 * @param c Source character.
554 * Assigning to a character makes this string length 1 and
555 * (*this)[0] == @a c.
558 operator=(_CharT __c
)
560 this->assign(1, __c
);
564 #ifdef __GXX_EXPERIMENTAL_CXX0X__
566 * @brief Move assign the value of @a str to this string.
567 * @param str Source string.
569 * The contents of @a str are moved into this string (without copying).
570 * @a str is a valid, but unspecified string.
573 operator=(basic_string
&& __str
)
581 * @brief Set value to string constructed from initializer %list.
582 * @param l std::initializer_list.
585 operator=(initializer_list
<_CharT
> __l
)
587 this->assign(__l
.begin(), __l
.size());
590 #endif // __GXX_EXPERIMENTAL_CXX0X__
594 * Returns a read/write iterator that points to the first character in
595 * the %string. Unshares the string.
601 return iterator(_M_data());
605 * Returns a read-only (constant) iterator that points to the first
606 * character in the %string.
610 { return const_iterator(_M_data()); }
613 * Returns a read/write iterator that points one past the last
614 * character in the %string. Unshares the string.
620 return iterator(_M_data() + this->size());
624 * Returns a read-only (constant) iterator that points one past the
625 * last character in the %string.
629 { return const_iterator(_M_data() + this->size()); }
632 * Returns a read/write reverse iterator that points to the last
633 * character in the %string. Iteration is done in reverse element
634 * order. Unshares the string.
638 { return reverse_iterator(this->end()); }
641 * Returns a read-only (constant) reverse iterator that points
642 * to the last character in the %string. Iteration is done in
643 * reverse element order.
645 const_reverse_iterator
647 { return const_reverse_iterator(this->end()); }
650 * Returns a read/write reverse iterator that points to one before the
651 * first character in the %string. Iteration is done in reverse
652 * element order. Unshares the string.
656 { return reverse_iterator(this->begin()); }
659 * Returns a read-only (constant) reverse iterator that points
660 * to one before the first character in the %string. Iteration
661 * is done in reverse element order.
663 const_reverse_iterator
665 { return const_reverse_iterator(this->begin()); }
667 #ifdef __GXX_EXPERIMENTAL_CXX0X__
669 * Returns a read-only (constant) iterator that points to the first
670 * character in the %string.
674 { return const_iterator(this->_M_data()); }
677 * Returns a read-only (constant) iterator that points one past the
678 * last character in the %string.
682 { return const_iterator(this->_M_data() + this->size()); }
685 * Returns a read-only (constant) reverse iterator that points
686 * to the last character in the %string. Iteration is done in
687 * reverse element order.
689 const_reverse_iterator
691 { return const_reverse_iterator(this->end()); }
694 * Returns a read-only (constant) reverse iterator that points
695 * to one before the first character in the %string. Iteration
696 * is done in reverse element order.
698 const_reverse_iterator
700 { return const_reverse_iterator(this->begin()); }
705 /// Returns the number of characters in the string, not including any
706 /// null-termination.
709 { return _M_rep()->_M_length
; }
711 /// Returns the number of characters in the string, not including any
712 /// null-termination.
715 { return _M_rep()->_M_length
; }
717 /// Returns the size() of the largest possible %string.
720 { return _Rep::_S_max_size
; }
723 * @brief Resizes the %string to the specified number of characters.
724 * @param n Number of characters the %string should contain.
725 * @param c Character to fill any new elements.
727 * This function will %resize the %string to the specified
728 * number of characters. If the number is smaller than the
729 * %string's current size the %string is truncated, otherwise
730 * the %string is extended and new elements are %set to @a c.
733 resize(size_type __n
, _CharT __c
);
736 * @brief Resizes the %string to the specified number of characters.
737 * @param n Number of characters the %string should contain.
739 * This function will resize the %string to the specified length. If
740 * the new size is smaller than the %string's current size the %string
741 * is truncated, otherwise the %string is extended and new characters
742 * are default-constructed. For basic types such as char, this means
746 resize(size_type __n
)
747 { this->resize(__n
, _CharT()); }
749 #ifdef __GXX_EXPERIMENTAL_CXX0X__
750 /// A non-binding request to reduce capacity() to size().
762 * Returns the total number of characters that the %string can hold
763 * before needing to allocate more memory.
767 { return _M_rep()->_M_capacity
; }
770 * @brief Attempt to preallocate enough memory for specified number of
772 * @param res_arg Number of characters required.
773 * @throw std::length_error If @a res_arg exceeds @c max_size().
775 * This function attempts to reserve enough memory for the
776 * %string to hold the specified number of characters. If the
777 * number requested is more than max_size(), length_error is
780 * The advantage of this function is that if optimal code is a
781 * necessity and the user can determine the string length that will be
782 * required, the user can reserve the memory in %advance, and thus
783 * prevent a possible reallocation of memory and copying of %string
787 reserve(size_type __res_arg
= 0);
790 * Erases the string, making it empty.
794 { _M_mutate(0, this->size(), 0); }
797 * Returns true if the %string is empty. Equivalent to
798 * <code>*this == ""</code>.
802 { return this->size() == 0; }
806 * @brief Subscript access to the data contained in the %string.
807 * @param pos The index of the character to access.
808 * @return Read-only (constant) reference to the character.
810 * This operator allows for easy, array-style, data access.
811 * Note that data access with this operator is unchecked and
812 * out_of_range lookups are not defined. (For checked lookups
816 operator[] (size_type __pos
) const
818 _GLIBCXX_DEBUG_ASSERT(__pos
<= size());
819 return _M_data()[__pos
];
823 * @brief Subscript access to the data contained in the %string.
824 * @param pos The index of the character to access.
825 * @return Read/write reference to the character.
827 * This operator allows for easy, array-style, data access.
828 * Note that data access with this operator is unchecked and
829 * out_of_range lookups are not defined. (For checked lookups
830 * see at().) Unshares the string.
833 operator[](size_type __pos
)
835 // allow pos == size() as v3 extension:
836 _GLIBCXX_DEBUG_ASSERT(__pos
<= size());
837 // but be strict in pedantic mode:
838 _GLIBCXX_DEBUG_PEDASSERT(__pos
< size());
840 return _M_data()[__pos
];
844 * @brief Provides access to the data contained in the %string.
845 * @param n The index of the character to access.
846 * @return Read-only (const) reference to the character.
847 * @throw std::out_of_range If @a n is an invalid index.
849 * This function provides for safer data access. The parameter is
850 * first checked that it is in the range of the string. The function
851 * throws out_of_range if the check fails.
854 at(size_type __n
) const
856 if (__n
>= this->size())
857 __throw_out_of_range(__N("basic_string::at"));
858 return _M_data()[__n
];
861 #ifdef __GXX_EXPERIMENTAL_CXX0X__
863 * Returns a read/write reference to the data at the first
864 * element of the %string.
868 { return operator[](0); }
871 * Returns a read-only (constant) reference to the data at the first
872 * element of the %string.
876 { return operator[](0); }
879 * Returns a read/write reference to the data at the last
880 * element of the %string.
884 { return operator[](this->size() - 1); }
887 * Returns a read-only (constant) reference to the data at the
888 * last element of the %string.
892 { return operator[](this->size() - 1); }
896 * @brief Provides access to the data contained in the %string.
897 * @param n The index of the character to access.
898 * @return Read/write reference to the character.
899 * @throw std::out_of_range If @a n is an invalid index.
901 * This function provides for safer data access. The parameter is
902 * first checked that it is in the range of the string. The function
903 * throws out_of_range if the check fails. Success results in
904 * unsharing the string.
910 __throw_out_of_range(__N("basic_string::at"));
912 return _M_data()[__n
];
917 * @brief Append a string to this string.
918 * @param str The string to append.
919 * @return Reference to this string.
922 operator+=(const basic_string
& __str
)
923 { return this->append(__str
); }
926 * @brief Append a C string.
927 * @param s The C string to append.
928 * @return Reference to this string.
931 operator+=(const _CharT
* __s
)
932 { return this->append(__s
); }
935 * @brief Append a character.
936 * @param c The character to append.
937 * @return Reference to this string.
940 operator+=(_CharT __c
)
942 this->push_back(__c
);
946 #ifdef __GXX_EXPERIMENTAL_CXX0X__
948 * @brief Append an initializer_list of characters.
949 * @param l The initializer_list of characters to be appended.
950 * @return Reference to this string.
953 operator+=(initializer_list
<_CharT
> __l
)
954 { return this->append(__l
.begin(), __l
.size()); }
955 #endif // __GXX_EXPERIMENTAL_CXX0X__
958 * @brief Append a string to this string.
959 * @param str The string to append.
960 * @return Reference to this string.
963 append(const basic_string
& __str
);
966 * @brief Append a substring.
967 * @param str The string to append.
968 * @param pos Index of the first character of str to append.
969 * @param n The number of characters to append.
970 * @return Reference to this string.
971 * @throw std::out_of_range if @a pos is not a valid index.
973 * This function appends @a n characters from @a str starting at @a pos
974 * to this string. If @a n is is larger than the number of available
975 * characters in @a str, the remainder of @a str is appended.
978 append(const basic_string
& __str
, size_type __pos
, size_type __n
);
981 * @brief Append a C substring.
982 * @param s The C string to append.
983 * @param n The number of characters to append.
984 * @return Reference to this string.
987 append(const _CharT
* __s
, size_type __n
);
990 * @brief Append a C string.
991 * @param s The C string to append.
992 * @return Reference to this string.
995 append(const _CharT
* __s
)
997 __glibcxx_requires_string(__s
);
998 return this->append(__s
, traits_type::length(__s
));
1002 * @brief Append multiple characters.
1003 * @param n The number of characters to append.
1004 * @param c The character to use.
1005 * @return Reference to this string.
1007 * Appends n copies of c to this string.
1010 append(size_type __n
, _CharT __c
);
1012 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1014 * @brief Append an initializer_list of characters.
1015 * @param l The initializer_list of characters to append.
1016 * @return Reference to this string.
1019 append(initializer_list
<_CharT
> __l
)
1020 { return this->append(__l
.begin(), __l
.size()); }
1021 #endif // __GXX_EXPERIMENTAL_CXX0X__
1024 * @brief Append a range of characters.
1025 * @param first Iterator referencing the first character to append.
1026 * @param last Iterator marking the end of the range.
1027 * @return Reference to this string.
1029 * Appends characters in the range [first,last) to this string.
1031 template<class _InputIterator
>
1033 append(_InputIterator __first
, _InputIterator __last
)
1034 { return this->replace(_M_iend(), _M_iend(), __first
, __last
); }
1037 * @brief Append a single character.
1038 * @param c Character to append.
1041 push_back(_CharT __c
)
1043 const size_type __len
= 1 + this->size();
1044 if (__len
> this->capacity() || _M_rep()->_M_is_shared())
1045 this->reserve(__len
);
1046 traits_type::assign(_M_data()[this->size()], __c
);
1047 _M_rep()->_M_set_length_and_sharable(__len
);
1051 * @brief Set value to contents of another string.
1052 * @param str Source string to use.
1053 * @return Reference to this string.
1056 assign(const basic_string
& __str
);
1058 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1060 * @brief Set value to contents of another string.
1061 * @param str Source string to use.
1062 * @return Reference to this string.
1064 * This function sets this string to the exact contents of @a str.
1065 * @a str is a valid, but unspecified string.
1068 assign(basic_string
&& __str
)
1073 #endif // __GXX_EXPERIMENTAL_CXX0X__
1076 * @brief Set value to a substring of a string.
1077 * @param str The string to use.
1078 * @param pos Index of the first character of str.
1079 * @param n Number of characters to use.
1080 * @return Reference to this string.
1081 * @throw std::out_of_range if @a pos is not a valid index.
1083 * This function sets this string to the substring of @a str consisting
1084 * of @a n characters at @a pos. If @a n is is larger than the number
1085 * of available characters in @a str, the remainder of @a str is used.
1088 assign(const basic_string
& __str
, size_type __pos
, size_type __n
)
1089 { return this->assign(__str
._M_data()
1090 + __str
._M_check(__pos
, "basic_string::assign"),
1091 __str
._M_limit(__pos
, __n
)); }
1094 * @brief Set value to a C substring.
1095 * @param s The C string to use.
1096 * @param n Number of characters to use.
1097 * @return Reference to this string.
1099 * This function sets the value of this string to the first @a n
1100 * characters of @a s. If @a n is is larger than the number of
1101 * available characters in @a s, the remainder of @a s is used.
1104 assign(const _CharT
* __s
, size_type __n
);
1107 * @brief Set value to contents of a C string.
1108 * @param s The C string to use.
1109 * @return Reference to this string.
1111 * This function sets the value of this string to the value of @a s.
1112 * The data is copied, so there is no dependence on @a s once the
1116 assign(const _CharT
* __s
)
1118 __glibcxx_requires_string(__s
);
1119 return this->assign(__s
, traits_type::length(__s
));
1123 * @brief Set value to multiple characters.
1124 * @param n Length of the resulting string.
1125 * @param c The character to use.
1126 * @return Reference to this string.
1128 * This function sets the value of this string to @a n copies of
1132 assign(size_type __n
, _CharT __c
)
1133 { return _M_replace_aux(size_type(0), this->size(), __n
, __c
); }
1136 * @brief Set value to a range of characters.
1137 * @param first Iterator referencing the first character to append.
1138 * @param last Iterator marking the end of the range.
1139 * @return Reference to this string.
1141 * Sets value of string to characters in the range [first,last).
1143 template<class _InputIterator
>
1145 assign(_InputIterator __first
, _InputIterator __last
)
1146 { return this->replace(_M_ibegin(), _M_iend(), __first
, __last
); }
1148 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1150 * @brief Set value to an initializer_list of characters.
1151 * @param l The initializer_list of characters to assign.
1152 * @return Reference to this string.
1155 assign(initializer_list
<_CharT
> __l
)
1156 { return this->assign(__l
.begin(), __l
.size()); }
1157 #endif // __GXX_EXPERIMENTAL_CXX0X__
1160 * @brief Insert multiple characters.
1161 * @param p Iterator referencing location in string to insert at.
1162 * @param n Number of characters to insert
1163 * @param c The character to insert.
1164 * @throw std::length_error If new length exceeds @c max_size().
1166 * Inserts @a n copies of character @a c starting at the position
1167 * referenced by iterator @a p. If adding characters causes the length
1168 * to exceed max_size(), length_error is thrown. The value of the
1169 * string doesn't change if an error is thrown.
1172 insert(iterator __p
, size_type __n
, _CharT __c
)
1173 { this->replace(__p
, __p
, __n
, __c
); }
1176 * @brief Insert a range of characters.
1177 * @param p Iterator referencing location in string to insert at.
1178 * @param beg Start of range.
1179 * @param end End of range.
1180 * @throw std::length_error If new length exceeds @c max_size().
1182 * Inserts characters in range [beg,end). If adding characters causes
1183 * the length to exceed max_size(), length_error is thrown. The value
1184 * of the string doesn't change if an error is thrown.
1186 template<class _InputIterator
>
1188 insert(iterator __p
, _InputIterator __beg
, _InputIterator __end
)
1189 { this->replace(__p
, __p
, __beg
, __end
); }
1191 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1193 * @brief Insert an initializer_list of characters.
1194 * @param p Iterator referencing location in string to insert at.
1195 * @param l The initializer_list of characters to insert.
1196 * @throw std::length_error If new length exceeds @c max_size().
1199 insert(iterator __p
, initializer_list
<_CharT
> __l
)
1201 _GLIBCXX_DEBUG_PEDASSERT(__p
>= _M_ibegin() && __p
<= _M_iend());
1202 this->insert(__p
- _M_ibegin(), __l
.begin(), __l
.size());
1204 #endif // __GXX_EXPERIMENTAL_CXX0X__
1207 * @brief Insert value of a string.
1208 * @param pos1 Iterator referencing location in string to insert at.
1209 * @param str The string to insert.
1210 * @return Reference to this string.
1211 * @throw std::length_error If new length exceeds @c max_size().
1213 * Inserts value of @a str starting at @a pos1. If adding characters
1214 * causes the length to exceed max_size(), length_error is thrown. The
1215 * value of the string doesn't change if an error is thrown.
1218 insert(size_type __pos1
, const basic_string
& __str
)
1219 { return this->insert(__pos1
, __str
, size_type(0), __str
.size()); }
1222 * @brief Insert a substring.
1223 * @param pos1 Iterator referencing location in string to insert at.
1224 * @param str The string to insert.
1225 * @param pos2 Start of characters in str to insert.
1226 * @param n Number of characters to insert.
1227 * @return Reference to this string.
1228 * @throw std::length_error If new length exceeds @c max_size().
1229 * @throw std::out_of_range If @a pos1 > size() or
1230 * @a pos2 > @a str.size().
1232 * Starting at @a pos1, insert @a n character of @a str beginning with
1233 * @a pos2. If adding characters causes the length to exceed
1234 * max_size(), length_error is thrown. If @a pos1 is beyond the end of
1235 * this string or @a pos2 is beyond the end of @a str, out_of_range is
1236 * thrown. The value of the string doesn't change if an error is
1240 insert(size_type __pos1
, const basic_string
& __str
,
1241 size_type __pos2
, size_type __n
)
1242 { return this->insert(__pos1
, __str
._M_data()
1243 + __str
._M_check(__pos2
, "basic_string::insert"),
1244 __str
._M_limit(__pos2
, __n
)); }
1247 * @brief Insert a C substring.
1248 * @param pos Iterator referencing location in string to insert at.
1249 * @param s The C string to insert.
1250 * @param n The number of characters to insert.
1251 * @return Reference to this string.
1252 * @throw std::length_error If new length exceeds @c max_size().
1253 * @throw std::out_of_range If @a pos is beyond the end of this
1256 * Inserts the first @a n characters of @a s starting at @a pos. If
1257 * adding characters causes the length to exceed max_size(),
1258 * length_error is thrown. If @a pos is beyond end(), out_of_range is
1259 * thrown. The value of the string doesn't change if an error is
1263 insert(size_type __pos
, const _CharT
* __s
, size_type __n
);
1266 * @brief Insert a C string.
1267 * @param pos Iterator referencing location in string to insert at.
1268 * @param s The C string to insert.
1269 * @return Reference to this string.
1270 * @throw std::length_error If new length exceeds @c max_size().
1271 * @throw std::out_of_range If @a pos is beyond the end of this
1274 * Inserts the first @a n characters of @a s starting at @a pos. If
1275 * adding characters causes the length to exceed max_size(),
1276 * length_error is thrown. If @a pos is beyond end(), out_of_range is
1277 * thrown. The value of the string doesn't change if an error is
1281 insert(size_type __pos
, const _CharT
* __s
)
1283 __glibcxx_requires_string(__s
);
1284 return this->insert(__pos
, __s
, traits_type::length(__s
));
1288 * @brief Insert multiple characters.
1289 * @param pos Index in string to insert at.
1290 * @param n Number of characters to insert
1291 * @param c The character to insert.
1292 * @return Reference to this string.
1293 * @throw std::length_error If new length exceeds @c max_size().
1294 * @throw std::out_of_range If @a pos is beyond the end of this
1297 * Inserts @a n copies of character @a c starting at index @a pos. If
1298 * adding characters causes the length to exceed max_size(),
1299 * length_error is thrown. If @a pos > length(), out_of_range is
1300 * thrown. The value of the string doesn't change if an error is
1304 insert(size_type __pos
, size_type __n
, _CharT __c
)
1305 { return _M_replace_aux(_M_check(__pos
, "basic_string::insert"),
1306 size_type(0), __n
, __c
); }
1309 * @brief Insert one character.
1310 * @param p Iterator referencing position in string to insert at.
1311 * @param c The character to insert.
1312 * @return Iterator referencing newly inserted char.
1313 * @throw std::length_error If new length exceeds @c max_size().
1315 * Inserts character @a c at position referenced by @a p. If adding
1316 * character causes the length to exceed max_size(), length_error is
1317 * thrown. If @a p is beyond end of string, out_of_range is thrown.
1318 * The value of the string doesn't change if an error is thrown.
1321 insert(iterator __p
, _CharT __c
)
1323 _GLIBCXX_DEBUG_PEDASSERT(__p
>= _M_ibegin() && __p
<= _M_iend());
1324 const size_type __pos
= __p
- _M_ibegin();
1325 _M_replace_aux(__pos
, size_type(0), size_type(1), __c
);
1326 _M_rep()->_M_set_leaked();
1327 return iterator(_M_data() + __pos
);
1331 * @brief Remove characters.
1332 * @param pos Index of first character to remove (default 0).
1333 * @param n Number of characters to remove (default remainder).
1334 * @return Reference to this string.
1335 * @throw std::out_of_range If @a pos is beyond the end of this
1338 * Removes @a n characters from this string starting at @a pos. The
1339 * length of the string is reduced by @a n. If there are < @a n
1340 * characters to remove, the remainder of the string is truncated. If
1341 * @a p is beyond end of string, out_of_range is thrown. The value of
1342 * the string doesn't change if an error is thrown.
1345 erase(size_type __pos
= 0, size_type __n
= npos
)
1347 _M_mutate(_M_check(__pos
, "basic_string::erase"),
1348 _M_limit(__pos
, __n
), size_type(0));
1353 * @brief Remove one character.
1354 * @param position Iterator referencing the character to remove.
1355 * @return iterator referencing same location after removal.
1357 * Removes the character at @a position from this string. The value
1358 * of the string doesn't change if an error is thrown.
1361 erase(iterator __position
)
1363 _GLIBCXX_DEBUG_PEDASSERT(__position
>= _M_ibegin()
1364 && __position
< _M_iend());
1365 const size_type __pos
= __position
- _M_ibegin();
1366 _M_mutate(__pos
, size_type(1), size_type(0));
1367 _M_rep()->_M_set_leaked();
1368 return iterator(_M_data() + __pos
);
1372 * @brief Remove a range of characters.
1373 * @param first Iterator referencing the first character to remove.
1374 * @param last Iterator referencing the end of the range.
1375 * @return Iterator referencing location of first after removal.
1377 * Removes the characters in the range [first,last) from this string.
1378 * The value of the string doesn't change if an error is thrown.
1381 erase(iterator __first
, iterator __last
);
1384 * @brief Replace characters with value from another string.
1385 * @param pos Index of first character to replace.
1386 * @param n Number of characters to be replaced.
1387 * @param str String to insert.
1388 * @return Reference to this string.
1389 * @throw std::out_of_range If @a pos is beyond the end of this
1391 * @throw std::length_error If new length exceeds @c max_size().
1393 * Removes the characters in the range [pos,pos+n) from this string.
1394 * In place, the value of @a str is inserted. If @a pos is beyond end
1395 * of string, out_of_range is thrown. If the length of the result
1396 * exceeds max_size(), length_error is thrown. The value of the string
1397 * doesn't change if an error is thrown.
1400 replace(size_type __pos
, size_type __n
, const basic_string
& __str
)
1401 { return this->replace(__pos
, __n
, __str
._M_data(), __str
.size()); }
1404 * @brief Replace characters with value from another string.
1405 * @param pos1 Index of first character to replace.
1406 * @param n1 Number of characters to be replaced.
1407 * @param str String to insert.
1408 * @param pos2 Index of first character of str to use.
1409 * @param n2 Number of characters from str to use.
1410 * @return Reference to this string.
1411 * @throw std::out_of_range If @a pos1 > size() or @a pos2 >
1413 * @throw std::length_error If new length exceeds @c max_size().
1415 * Removes the characters in the range [pos1,pos1 + n) from this
1416 * string. In place, the value of @a str is inserted. If @a pos is
1417 * beyond end of string, out_of_range is thrown. If the length of the
1418 * result exceeds max_size(), length_error is thrown. The value of the
1419 * string doesn't change if an error is thrown.
1422 replace(size_type __pos1
, size_type __n1
, const basic_string
& __str
,
1423 size_type __pos2
, size_type __n2
)
1424 { return this->replace(__pos1
, __n1
, __str
._M_data()
1425 + __str
._M_check(__pos2
, "basic_string::replace"),
1426 __str
._M_limit(__pos2
, __n2
)); }
1429 * @brief Replace characters with value of a C substring.
1430 * @param pos Index of first character to replace.
1431 * @param n1 Number of characters to be replaced.
1432 * @param s C string to insert.
1433 * @param n2 Number of characters from @a s to use.
1434 * @return Reference to this string.
1435 * @throw std::out_of_range If @a pos1 > size().
1436 * @throw std::length_error If new length exceeds @c max_size().
1438 * Removes the characters in the range [pos,pos + n1) from this string.
1439 * In place, the first @a n2 characters of @a s are inserted, or all
1440 * of @a s if @a n2 is too large. If @a pos is beyond end of string,
1441 * out_of_range is thrown. If the length of result exceeds max_size(),
1442 * length_error is thrown. The value of the string doesn't change if
1443 * an error is thrown.
1446 replace(size_type __pos
, size_type __n1
, const _CharT
* __s
,
1450 * @brief Replace characters with value of a C string.
1451 * @param pos Index of first character to replace.
1452 * @param n1 Number of characters to be replaced.
1453 * @param s C string to insert.
1454 * @return Reference to this string.
1455 * @throw std::out_of_range If @a pos > size().
1456 * @throw std::length_error If new length exceeds @c max_size().
1458 * Removes the characters in the range [pos,pos + n1) from this string.
1459 * In place, the characters of @a s are inserted. If @a pos is beyond
1460 * end of string, out_of_range is thrown. If the length of result
1461 * exceeds max_size(), length_error is thrown. The value of the string
1462 * doesn't change if an error is thrown.
1465 replace(size_type __pos
, size_type __n1
, const _CharT
* __s
)
1467 __glibcxx_requires_string(__s
);
1468 return this->replace(__pos
, __n1
, __s
, traits_type::length(__s
));
1472 * @brief Replace characters with multiple characters.
1473 * @param pos Index of first character to replace.
1474 * @param n1 Number of characters to be replaced.
1475 * @param n2 Number of characters to insert.
1476 * @param c Character to insert.
1477 * @return Reference to this string.
1478 * @throw std::out_of_range If @a pos > size().
1479 * @throw std::length_error If new length exceeds @c max_size().
1481 * Removes the characters in the range [pos,pos + n1) from this string.
1482 * In place, @a n2 copies of @a c are inserted. If @a pos is beyond
1483 * end of string, out_of_range is thrown. If the length of result
1484 * exceeds max_size(), length_error is thrown. The value of the string
1485 * doesn't change if an error is thrown.
1488 replace(size_type __pos
, size_type __n1
, size_type __n2
, _CharT __c
)
1489 { return _M_replace_aux(_M_check(__pos
, "basic_string::replace"),
1490 _M_limit(__pos
, __n1
), __n2
, __c
); }
1493 * @brief Replace range of characters with string.
1494 * @param i1 Iterator referencing start of range to replace.
1495 * @param i2 Iterator referencing end of range to replace.
1496 * @param str String value to insert.
1497 * @return Reference to this string.
1498 * @throw std::length_error If new length exceeds @c max_size().
1500 * Removes the characters in the range [i1,i2). In place, the value of
1501 * @a str is inserted. If the length of result exceeds max_size(),
1502 * length_error is thrown. The value of the string doesn't change if
1503 * an error is thrown.
1506 replace(iterator __i1
, iterator __i2
, const basic_string
& __str
)
1507 { return this->replace(__i1
, __i2
, __str
._M_data(), __str
.size()); }
1510 * @brief Replace range of characters with C substring.
1511 * @param i1 Iterator referencing start of range to replace.
1512 * @param i2 Iterator referencing end of range to replace.
1513 * @param s C string value to insert.
1514 * @param n Number of characters from s 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, the first @a
1519 * n characters of @a s are inserted. If the length of result exceeds
1520 * max_size(), length_error is thrown. The value of the string doesn't
1521 * change if an error is thrown.
1524 replace(iterator __i1
, iterator __i2
, const _CharT
* __s
, size_type __n
)
1526 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1527 && __i2
<= _M_iend());
1528 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
, __s
, __n
);
1532 * @brief Replace range of characters with C string.
1533 * @param i1 Iterator referencing start of range to replace.
1534 * @param i2 Iterator referencing end of range to replace.
1535 * @param s C string value to insert.
1536 * @return Reference to this string.
1537 * @throw std::length_error If new length exceeds @c max_size().
1539 * Removes the characters in the range [i1,i2). In place, the
1540 * characters of @a s are inserted. If the length of result exceeds
1541 * max_size(), length_error is thrown. The value of the string doesn't
1542 * change if an error is thrown.
1545 replace(iterator __i1
, iterator __i2
, const _CharT
* __s
)
1547 __glibcxx_requires_string(__s
);
1548 return this->replace(__i1
, __i2
, __s
, traits_type::length(__s
));
1552 * @brief Replace range of characters with multiple characters
1553 * @param i1 Iterator referencing start of range to replace.
1554 * @param i2 Iterator referencing end of range to replace.
1555 * @param n Number of characters to insert.
1556 * @param c Character to insert.
1557 * @return Reference to this string.
1558 * @throw std::length_error If new length exceeds @c max_size().
1560 * Removes the characters in the range [i1,i2). In place, @a n copies
1561 * of @a c are inserted. If the length of result exceeds max_size(),
1562 * length_error is thrown. The value of the string doesn't change if
1563 * an error is thrown.
1566 replace(iterator __i1
, iterator __i2
, size_type __n
, _CharT __c
)
1568 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1569 && __i2
<= _M_iend());
1570 return _M_replace_aux(__i1
- _M_ibegin(), __i2
- __i1
, __n
, __c
);
1574 * @brief Replace range of characters with range.
1575 * @param i1 Iterator referencing start of range to replace.
1576 * @param i2 Iterator referencing end of range to replace.
1577 * @param k1 Iterator referencing start of range to insert.
1578 * @param k2 Iterator referencing end of range to insert.
1579 * @return Reference to this string.
1580 * @throw std::length_error If new length exceeds @c max_size().
1582 * Removes the characters in the range [i1,i2). In place, characters
1583 * in the range [k1,k2) are inserted. If the length of result exceeds
1584 * max_size(), length_error is thrown. The value of the string doesn't
1585 * change if an error is thrown.
1587 template<class _InputIterator
>
1589 replace(iterator __i1
, iterator __i2
,
1590 _InputIterator __k1
, _InputIterator __k2
)
1592 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1593 && __i2
<= _M_iend());
1594 __glibcxx_requires_valid_range(__k1
, __k2
);
1595 typedef typename
std::__is_integer
<_InputIterator
>::__type _Integral
;
1596 return _M_replace_dispatch(__i1
, __i2
, __k1
, __k2
, _Integral());
1599 // Specializations for the common case of pointer and iterator:
1600 // useful to avoid the overhead of temporary buffering in _M_replace.
1602 replace(iterator __i1
, iterator __i2
, _CharT
* __k1
, _CharT
* __k2
)
1604 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1605 && __i2
<= _M_iend());
1606 __glibcxx_requires_valid_range(__k1
, __k2
);
1607 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1612 replace(iterator __i1
, iterator __i2
,
1613 const _CharT
* __k1
, const _CharT
* __k2
)
1615 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1616 && __i2
<= _M_iend());
1617 __glibcxx_requires_valid_range(__k1
, __k2
);
1618 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1623 replace(iterator __i1
, iterator __i2
, iterator __k1
, iterator __k2
)
1625 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1626 && __i2
<= _M_iend());
1627 __glibcxx_requires_valid_range(__k1
, __k2
);
1628 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1629 __k1
.base(), __k2
- __k1
);
1633 replace(iterator __i1
, iterator __i2
,
1634 const_iterator __k1
, const_iterator __k2
)
1636 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1637 && __i2
<= _M_iend());
1638 __glibcxx_requires_valid_range(__k1
, __k2
);
1639 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1640 __k1
.base(), __k2
- __k1
);
1643 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1645 * @brief Replace range of characters with initializer_list.
1646 * @param i1 Iterator referencing start of range to replace.
1647 * @param i2 Iterator referencing end of range to replace.
1648 * @param l The initializer_list of characters to insert.
1649 * @return Reference to this string.
1650 * @throw std::length_error If new length exceeds @c max_size().
1652 * Removes the characters in the range [i1,i2). In place, characters
1653 * in the range [k1,k2) are inserted. If the length of result exceeds
1654 * max_size(), length_error is thrown. The value of the string doesn't
1655 * change if an error is thrown.
1657 basic_string
& replace(iterator __i1
, iterator __i2
,
1658 initializer_list
<_CharT
> __l
)
1659 { return this->replace(__i1
, __i2
, __l
.begin(), __l
.end()); }
1660 #endif // __GXX_EXPERIMENTAL_CXX0X__
1663 template<class _Integer
>
1665 _M_replace_dispatch(iterator __i1
, iterator __i2
, _Integer __n
,
1666 _Integer __val
, __true_type
)
1667 { return _M_replace_aux(__i1
- _M_ibegin(), __i2
- __i1
, __n
, __val
); }
1669 template<class _InputIterator
>
1671 _M_replace_dispatch(iterator __i1
, iterator __i2
, _InputIterator __k1
,
1672 _InputIterator __k2
, __false_type
);
1675 _M_replace_aux(size_type __pos1
, size_type __n1
, size_type __n2
,
1679 _M_replace_safe(size_type __pos1
, size_type __n1
, const _CharT
* __s
,
1682 // _S_construct_aux is used to implement the 21.3.1 para 15 which
1683 // requires special behaviour if _InIter is an integral type
1684 template<class _InIterator
>
1686 _S_construct_aux(_InIterator __beg
, _InIterator __end
,
1687 const _Alloc
& __a
, __false_type
)
1689 typedef typename iterator_traits
<_InIterator
>::iterator_category _Tag
;
1690 return _S_construct(__beg
, __end
, __a
, _Tag());
1693 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1694 // 438. Ambiguity in the "do the right thing" clause
1695 template<class _Integer
>
1697 _S_construct_aux(_Integer __beg
, _Integer __end
,
1698 const _Alloc
& __a
, __true_type
)
1699 { return _S_construct_aux_2(static_cast<size_type
>(__beg
),
1703 _S_construct_aux_2(size_type __req
, _CharT __c
, const _Alloc
& __a
)
1704 { return _S_construct(__req
, __c
, __a
); }
1706 template<class _InIterator
>
1708 _S_construct(_InIterator __beg
, _InIterator __end
, const _Alloc
& __a
)
1710 typedef typename
std::__is_integer
<_InIterator
>::__type _Integral
;
1711 return _S_construct_aux(__beg
, __end
, __a
, _Integral());
1714 // For Input Iterators, used in istreambuf_iterators, etc.
1715 template<class _InIterator
>
1717 _S_construct(_InIterator __beg
, _InIterator __end
, const _Alloc
& __a
,
1718 input_iterator_tag
);
1720 // For forward_iterators up to random_access_iterators, used for
1721 // string::iterator, _CharT*, etc.
1722 template<class _FwdIterator
>
1724 _S_construct(_FwdIterator __beg
, _FwdIterator __end
, const _Alloc
& __a
,
1725 forward_iterator_tag
);
1728 _S_construct(size_type __req
, _CharT __c
, const _Alloc
& __a
);
1733 * @brief Copy substring into C string.
1734 * @param s C string to copy value into.
1735 * @param n Number of characters to copy.
1736 * @param pos Index of first character to copy.
1737 * @return Number of characters actually copied
1738 * @throw std::out_of_range If pos > size().
1740 * Copies up to @a n characters starting at @a pos into the C string @a
1741 * s. If @a pos is %greater than size(), out_of_range is thrown.
1744 copy(_CharT
* __s
, size_type __n
, size_type __pos
= 0) const;
1747 * @brief Swap contents with another string.
1748 * @param s String to swap with.
1750 * Exchanges the contents of this string with that of @a s in constant
1754 swap(basic_string
& __s
);
1756 // String operations:
1758 * @brief Return const pointer to null-terminated contents.
1760 * This is a handle to internal data. Do not modify or dire things may
1765 { return _M_data(); }
1768 * @brief Return const pointer to contents.
1770 * This is a handle to internal data. Do not modify or dire things may
1775 { return _M_data(); }
1778 * @brief Return copy of allocator used to construct this string.
1781 get_allocator() const
1782 { return _M_dataplus
; }
1785 * @brief Find position of a C substring.
1786 * @param s C string to locate.
1787 * @param pos Index of character to search from.
1788 * @param n Number of characters from @a s to search for.
1789 * @return Index of start of first occurrence.
1791 * Starting from @a pos, searches forward for the first @a n characters
1792 * in @a s within this string. If found, returns the index where it
1793 * begins. If not found, returns npos.
1796 find(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
1799 * @brief Find position of a string.
1800 * @param str String to locate.
1801 * @param pos Index of character to search from (default 0).
1802 * @return Index of start of first occurrence.
1804 * Starting from @a pos, searches forward for value of @a str within
1805 * this string. If found, returns the index where it begins. If not
1806 * found, returns npos.
1809 find(const basic_string
& __str
, size_type __pos
= 0) const
1810 { return this->find(__str
.data(), __pos
, __str
.size()); }
1813 * @brief Find position of a C string.
1814 * @param s C string to locate.
1815 * @param pos Index of character to search from (default 0).
1816 * @return Index of start of first occurrence.
1818 * Starting from @a pos, searches forward for the value of @a s within
1819 * this string. If found, returns the index where it begins. If not
1820 * found, returns npos.
1823 find(const _CharT
* __s
, size_type __pos
= 0) const
1825 __glibcxx_requires_string(__s
);
1826 return this->find(__s
, __pos
, traits_type::length(__s
));
1830 * @brief Find position of a character.
1831 * @param c Character to locate.
1832 * @param pos Index of character to search from (default 0).
1833 * @return Index of first occurrence.
1835 * Starting from @a pos, searches forward for @a c within this string.
1836 * If found, returns the index where it was found. If not found,
1840 find(_CharT __c
, size_type __pos
= 0) const;
1843 * @brief Find last position of a string.
1844 * @param str String to locate.
1845 * @param pos Index of character to search back from (default end).
1846 * @return Index of start of last occurrence.
1848 * Starting from @a pos, searches backward for value of @a str within
1849 * this string. If found, returns the index where it begins. If not
1850 * found, returns npos.
1853 rfind(const basic_string
& __str
, size_type __pos
= npos
) const
1854 { return this->rfind(__str
.data(), __pos
, __str
.size()); }
1857 * @brief Find last position of a C substring.
1858 * @param s C string to locate.
1859 * @param pos Index of character to search back from.
1860 * @param n Number of characters from s to search for.
1861 * @return Index of start of last occurrence.
1863 * Starting from @a pos, searches backward for the first @a n
1864 * characters in @a s within this string. If found, returns the index
1865 * where it begins. If not found, returns npos.
1868 rfind(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
1871 * @brief Find last position of a C string.
1872 * @param s C string to locate.
1873 * @param pos Index of character to start search at (default end).
1874 * @return Index of start of last occurrence.
1876 * Starting from @a pos, searches backward for the value of @a s within
1877 * this string. If found, returns the index where it begins. If not
1878 * found, returns npos.
1881 rfind(const _CharT
* __s
, size_type __pos
= npos
) const
1883 __glibcxx_requires_string(__s
);
1884 return this->rfind(__s
, __pos
, traits_type::length(__s
));
1888 * @brief Find last position of a character.
1889 * @param c Character to locate.
1890 * @param pos Index of character to search back from (default end).
1891 * @return Index of last occurrence.
1893 * Starting from @a pos, searches backward for @a c within this string.
1894 * If found, returns the index where it was found. If not found,
1898 rfind(_CharT __c
, size_type __pos
= npos
) const;
1901 * @brief Find position of a character of string.
1902 * @param str String containing characters to locate.
1903 * @param pos Index of character to search from (default 0).
1904 * @return Index of first occurrence.
1906 * Starting from @a pos, searches forward for one of the characters of
1907 * @a str within this string. If found, returns the index where it was
1908 * found. If not found, returns npos.
1911 find_first_of(const basic_string
& __str
, size_type __pos
= 0) const
1912 { return this->find_first_of(__str
.data(), __pos
, __str
.size()); }
1915 * @brief Find position of a character of C substring.
1916 * @param s String containing characters to locate.
1917 * @param pos Index of character to search from.
1918 * @param n Number of characters from s to search for.
1919 * @return Index of first occurrence.
1921 * Starting from @a pos, searches forward for one of the first @a n
1922 * characters of @a s within this string. If found, returns the index
1923 * where it was found. If not found, returns npos.
1926 find_first_of(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
1929 * @brief Find position of a character of C string.
1930 * @param s String containing characters to locate.
1931 * @param pos Index of character to search from (default 0).
1932 * @return Index of first occurrence.
1934 * Starting from @a pos, searches forward for one of the characters of
1935 * @a s within this string. If found, returns the index where it was
1936 * found. If not found, returns npos.
1939 find_first_of(const _CharT
* __s
, size_type __pos
= 0) const
1941 __glibcxx_requires_string(__s
);
1942 return this->find_first_of(__s
, __pos
, traits_type::length(__s
));
1946 * @brief Find position of a character.
1947 * @param c Character to locate.
1948 * @param pos Index of character to search from (default 0).
1949 * @return Index of first occurrence.
1951 * Starting from @a pos, searches forward for the character @a c within
1952 * this string. If found, returns the index where it was found. If
1953 * not found, returns npos.
1955 * Note: equivalent to find(c, pos).
1958 find_first_of(_CharT __c
, size_type __pos
= 0) const
1959 { return this->find(__c
, __pos
); }
1962 * @brief Find last position of a character of string.
1963 * @param str String containing characters to locate.
1964 * @param pos Index of character to search back from (default end).
1965 * @return Index of last occurrence.
1967 * Starting from @a pos, searches backward for one of the characters of
1968 * @a str within this string. If found, returns the index where it was
1969 * found. If not found, returns npos.
1972 find_last_of(const basic_string
& __str
, size_type __pos
= npos
) const
1973 { return this->find_last_of(__str
.data(), __pos
, __str
.size()); }
1976 * @brief Find last position of a character of C substring.
1977 * @param s C string containing characters to locate.
1978 * @param pos Index of character to search back from.
1979 * @param n Number of characters from s to search for.
1980 * @return Index of last occurrence.
1982 * Starting from @a pos, searches backward for one of the first @a n
1983 * characters of @a s within this string. If found, returns the index
1984 * where it was found. If not found, returns npos.
1987 find_last_of(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
1990 * @brief Find last position of a character of C string.
1991 * @param s C string containing characters to locate.
1992 * @param pos Index of character to search back from (default end).
1993 * @return Index of last occurrence.
1995 * Starting from @a pos, searches backward for one of the characters of
1996 * @a s within this string. If found, returns the index where it was
1997 * found. If not found, returns npos.
2000 find_last_of(const _CharT
* __s
, size_type __pos
= npos
) const
2002 __glibcxx_requires_string(__s
);
2003 return this->find_last_of(__s
, __pos
, traits_type::length(__s
));
2007 * @brief Find last position of a character.
2008 * @param c Character to locate.
2009 * @param pos Index of character to search back from (default end).
2010 * @return Index of last occurrence.
2012 * Starting from @a pos, searches backward for @a c within this string.
2013 * If found, returns the index where it was found. If not found,
2016 * Note: equivalent to rfind(c, pos).
2019 find_last_of(_CharT __c
, size_type __pos
= npos
) const
2020 { return this->rfind(__c
, __pos
); }
2023 * @brief Find position of a character not in string.
2024 * @param str String containing characters to avoid.
2025 * @param pos Index of character to search from (default 0).
2026 * @return Index of first occurrence.
2028 * Starting from @a pos, searches forward for a character not contained
2029 * in @a str within this string. If found, returns the index where it
2030 * was found. If not found, returns npos.
2033 find_first_not_of(const basic_string
& __str
, size_type __pos
= 0) const
2034 { return this->find_first_not_of(__str
.data(), __pos
, __str
.size()); }
2037 * @brief Find position of a character not in C substring.
2038 * @param s C string containing characters to avoid.
2039 * @param pos Index of character to search from.
2040 * @param n Number of characters from s to consider.
2041 * @return Index of first occurrence.
2043 * Starting from @a pos, searches forward for a character not contained
2044 * in the first @a n characters of @a s within this string. If found,
2045 * returns the index where it was found. If not found, returns npos.
2048 find_first_not_of(const _CharT
* __s
, size_type __pos
,
2049 size_type __n
) const;
2052 * @brief Find position of a character not in C string.
2053 * @param s C string containing characters to avoid.
2054 * @param pos Index of character to search from (default 0).
2055 * @return Index of first occurrence.
2057 * Starting from @a pos, searches forward for a character not contained
2058 * in @a s within this string. If found, returns the index where it
2059 * was found. If not found, returns npos.
2062 find_first_not_of(const _CharT
* __s
, size_type __pos
= 0) const
2064 __glibcxx_requires_string(__s
);
2065 return this->find_first_not_of(__s
, __pos
, traits_type::length(__s
));
2069 * @brief Find position of a different character.
2070 * @param c Character to avoid.
2071 * @param pos Index of character to search from (default 0).
2072 * @return Index of first occurrence.
2074 * Starting from @a pos, searches forward for a character other than @a c
2075 * within this string. If found, returns the index where it was found.
2076 * If not found, returns npos.
2079 find_first_not_of(_CharT __c
, size_type __pos
= 0) const;
2082 * @brief Find last position of a character not in string.
2083 * @param str String containing characters to avoid.
2084 * @param pos Index of character to search back from (default end).
2085 * @return Index of last occurrence.
2087 * Starting from @a pos, searches backward for a character not
2088 * contained in @a str within this string. If found, returns the index
2089 * where it was found. If not found, returns npos.
2092 find_last_not_of(const basic_string
& __str
, size_type __pos
= npos
) const
2093 { return this->find_last_not_of(__str
.data(), __pos
, __str
.size()); }
2096 * @brief Find last position of a character not in C substring.
2097 * @param s C string containing characters to avoid.
2098 * @param pos Index of character to search back from.
2099 * @param n Number of characters from s to consider.
2100 * @return Index of last occurrence.
2102 * Starting from @a pos, searches backward for a character not
2103 * contained in the first @a n characters of @a s within this string.
2104 * If found, returns the index where it was found. If not found,
2108 find_last_not_of(const _CharT
* __s
, size_type __pos
,
2109 size_type __n
) const;
2111 * @brief Find last position of a character not in C string.
2112 * @param s C string containing characters to avoid.
2113 * @param pos Index of character to search back from (default end).
2114 * @return Index of last occurrence.
2116 * Starting from @a pos, searches backward for a character not
2117 * contained in @a s within this string. If found, returns the index
2118 * where it was found. If not found, returns npos.
2121 find_last_not_of(const _CharT
* __s
, size_type __pos
= npos
) const
2123 __glibcxx_requires_string(__s
);
2124 return this->find_last_not_of(__s
, __pos
, traits_type::length(__s
));
2128 * @brief Find last position of a different character.
2129 * @param c Character to avoid.
2130 * @param pos Index of character to search back from (default end).
2131 * @return Index of last occurrence.
2133 * Starting from @a pos, searches backward for a character other than
2134 * @a c within this string. If found, returns the index where it was
2135 * found. If not found, returns npos.
2138 find_last_not_of(_CharT __c
, size_type __pos
= npos
) const;
2141 * @brief Get a substring.
2142 * @param pos Index of first character (default 0).
2143 * @param n Number of characters in substring (default remainder).
2144 * @return The new string.
2145 * @throw std::out_of_range If pos > size().
2147 * Construct and return a new string using the @a n characters starting
2148 * at @a pos. If the string is too short, use the remainder of the
2149 * characters. If @a pos is beyond the end of the string, out_of_range
2153 substr(size_type __pos
= 0, size_type __n
= npos
) const
2154 { return basic_string(*this,
2155 _M_check(__pos
, "basic_string::substr"), __n
); }
2158 * @brief Compare to a string.
2159 * @param str String to compare against.
2160 * @return Integer < 0, 0, or > 0.
2162 * Returns an integer < 0 if this string is ordered before @a str, 0 if
2163 * their values are equivalent, or > 0 if this string is ordered after
2164 * @a str. Determines the effective length rlen of the strings to
2165 * compare as the smallest of size() and str.size(). The function
2166 * then compares the two strings by calling traits::compare(data(),
2167 * str.data(),rlen). If the result of the comparison is nonzero returns
2168 * it, otherwise the shorter one is ordered first.
2171 compare(const basic_string
& __str
) const
2173 const size_type __size
= this->size();
2174 const size_type __osize
= __str
.size();
2175 const size_type __len
= std::min(__size
, __osize
);
2177 int __r
= traits_type::compare(_M_data(), __str
.data(), __len
);
2179 __r
= _S_compare(__size
, __osize
);
2184 * @brief Compare substring to a string.
2185 * @param pos Index of first character of substring.
2186 * @param n Number of characters in substring.
2187 * @param str String to compare against.
2188 * @return Integer < 0, 0, or > 0.
2190 * Form the substring of this string from the @a n characters starting
2191 * at @a pos. Returns an integer < 0 if the substring is ordered
2192 * before @a str, 0 if their values are equivalent, or > 0 if the
2193 * substring is ordered after @a str. Determines the effective length
2194 * rlen of the strings to compare as the smallest of the length of the
2195 * substring and @a str.size(). The function then compares the two
2196 * strings by calling traits::compare(substring.data(),str.data(),rlen).
2197 * If the result of the comparison is nonzero returns it, otherwise the
2198 * shorter one is ordered first.
2201 compare(size_type __pos
, size_type __n
, const basic_string
& __str
) const;
2204 * @brief Compare substring to a substring.
2205 * @param pos1 Index of first character of substring.
2206 * @param n1 Number of characters in substring.
2207 * @param str String to compare against.
2208 * @param pos2 Index of first character of substring of str.
2209 * @param n2 Number of characters in substring of str.
2210 * @return Integer < 0, 0, or > 0.
2212 * Form the substring of this string from the @a n1 characters starting
2213 * at @a pos1. Form the substring of @a str from the @a n2 characters
2214 * starting at @a pos2. Returns an integer < 0 if this substring is
2215 * ordered before the substring of @a str, 0 if their values are
2216 * equivalent, or > 0 if this substring is ordered after the substring
2217 * of @a str. Determines the effective length rlen of the strings
2218 * to compare as the smallest of the lengths of the substrings. The
2219 * function then compares the two strings by calling
2220 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
2221 * If the result of the comparison is nonzero returns it, otherwise the
2222 * shorter one is ordered first.
2225 compare(size_type __pos1
, size_type __n1
, const basic_string
& __str
,
2226 size_type __pos2
, size_type __n2
) const;
2229 * @brief Compare to a C string.
2230 * @param s C string to compare against.
2231 * @return Integer < 0, 0, or > 0.
2233 * Returns an integer < 0 if this string is ordered before @a s, 0 if
2234 * their values are equivalent, or > 0 if this string is ordered after
2235 * @a s. Determines the effective length rlen of the strings to
2236 * compare as the smallest of size() and the length of a string
2237 * constructed from @a s. The function then compares the two strings
2238 * by calling traits::compare(data(),s,rlen). If the result of the
2239 * comparison is nonzero returns it, otherwise the shorter one is
2243 compare(const _CharT
* __s
) const;
2245 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2246 // 5 String::compare specification questionable
2248 * @brief Compare substring to a C string.
2249 * @param pos Index of first character of substring.
2250 * @param n1 Number of characters in substring.
2251 * @param s C string to compare against.
2252 * @return Integer < 0, 0, or > 0.
2254 * Form the substring of this string from the @a n1 characters starting
2255 * at @a pos. Returns an integer < 0 if the substring is ordered
2256 * before @a s, 0 if their values are equivalent, or > 0 if the
2257 * substring is ordered after @a s. Determines the effective length
2258 * rlen of the strings to compare as the smallest of the length of the
2259 * substring and the length of a string constructed from @a s. The
2260 * function then compares the two string by calling
2261 * traits::compare(substring.data(),s,rlen). If the result of the
2262 * comparison is nonzero returns it, otherwise the shorter one is
2266 compare(size_type __pos
, size_type __n1
, const _CharT
* __s
) const;
2269 * @brief Compare substring against a character %array.
2270 * @param pos1 Index of first character of substring.
2271 * @param n1 Number of characters in substring.
2272 * @param s character %array to compare against.
2273 * @param n2 Number of characters of s.
2274 * @return Integer < 0, 0, or > 0.
2276 * Form the substring of this string from the @a n1 characters starting
2277 * at @a pos1. Form a string from the first @a n2 characters of @a s.
2278 * Returns an integer < 0 if this substring is ordered before the string
2279 * from @a s, 0 if their values are equivalent, or > 0 if this substring
2280 * is ordered after the string from @a s. Determines the effective
2281 * length rlen of the strings to compare as the smallest of the length
2282 * of the substring and @a n2. The function then compares the two
2283 * strings by calling traits::compare(substring.data(),s,rlen). If the
2284 * result of the comparison is nonzero returns it, otherwise the shorter
2285 * one is ordered first.
2287 * NB: s must have at least n2 characters, '\\0' has
2288 * no special meaning.
2291 compare(size_type __pos
, size_type __n1
, const _CharT
* __s
,
2292 size_type __n2
) const;
2297 * @brief Concatenate two strings.
2298 * @param lhs First string.
2299 * @param rhs Last string.
2300 * @return New string with value of @a lhs followed by @a rhs.
2302 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2303 basic_string
<_CharT
, _Traits
, _Alloc
>
2304 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2305 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2307 basic_string
<_CharT
, _Traits
, _Alloc
> __str(__lhs
);
2308 __str
.append(__rhs
);
2313 * @brief Concatenate C string and string.
2314 * @param lhs First string.
2315 * @param rhs Last string.
2316 * @return New string with value of @a lhs followed by @a rhs.
2318 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2319 basic_string
<_CharT
,_Traits
,_Alloc
>
2320 operator+(const _CharT
* __lhs
,
2321 const basic_string
<_CharT
,_Traits
,_Alloc
>& __rhs
);
2324 * @brief Concatenate character and string.
2325 * @param lhs First string.
2326 * @param rhs Last string.
2327 * @return New string with @a lhs followed by @a rhs.
2329 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2330 basic_string
<_CharT
,_Traits
,_Alloc
>
2331 operator+(_CharT __lhs
, const basic_string
<_CharT
,_Traits
,_Alloc
>& __rhs
);
2334 * @brief Concatenate string and C string.
2335 * @param lhs First string.
2336 * @param rhs Last string.
2337 * @return New string with @a lhs followed by @a rhs.
2339 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2340 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2341 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2342 const _CharT
* __rhs
)
2344 basic_string
<_CharT
, _Traits
, _Alloc
> __str(__lhs
);
2345 __str
.append(__rhs
);
2350 * @brief Concatenate string and character.
2351 * @param lhs First string.
2352 * @param rhs Last string.
2353 * @return New string with @a lhs followed by @a rhs.
2355 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2356 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2357 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
, _CharT __rhs
)
2359 typedef basic_string
<_CharT
, _Traits
, _Alloc
> __string_type
;
2360 typedef typename
__string_type::size_type __size_type
;
2361 __string_type
__str(__lhs
);
2362 __str
.append(__size_type(1), __rhs
);
2366 #ifdef __GXX_EXPERIMENTAL_CXX0X__
2367 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2368 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2369 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
2370 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2371 { return std::move(__lhs
.append(__rhs
)); }
2373 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2374 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2375 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2376 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
2377 { return std::move(__rhs
.insert(0, __lhs
)); }
2379 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2380 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2381 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
2382 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
2384 const auto __size
= __lhs
.size() + __rhs
.size();
2385 const bool __cond
= (__size
> __lhs
.capacity()
2386 && __size
<= __rhs
.capacity());
2387 return __cond
? std::move(__rhs
.insert(0, __lhs
))
2388 : std::move(__lhs
.append(__rhs
));
2391 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2392 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2393 operator+(const _CharT
* __lhs
,
2394 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
2395 { return std::move(__rhs
.insert(0, __lhs
)); }
2397 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2398 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2399 operator+(_CharT __lhs
,
2400 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
2401 { return std::move(__rhs
.insert(0, 1, __lhs
)); }
2403 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2404 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2405 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
2406 const _CharT
* __rhs
)
2407 { return std::move(__lhs
.append(__rhs
)); }
2409 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2410 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2411 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
2413 { return std::move(__lhs
.append(1, __rhs
)); }
2418 * @brief Test equivalence of two strings.
2419 * @param lhs First string.
2420 * @param rhs Second string.
2421 * @return True if @a lhs.compare(@a rhs) == 0. False otherwise.
2423 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2425 operator==(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2426 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2427 { return __lhs
.compare(__rhs
) == 0; }
2429 template<typename _CharT
>
2431 typename
__gnu_cxx::__enable_if
<__is_char
<_CharT
>::__value
, bool>::__type
2432 operator==(const basic_string
<_CharT
>& __lhs
,
2433 const basic_string
<_CharT
>& __rhs
)
2434 { return (__lhs
.size() == __rhs
.size()
2435 && !std::char_traits
<_CharT
>::compare(__lhs
.data(), __rhs
.data(),
2439 * @brief Test equivalence of C string and string.
2440 * @param lhs C string.
2441 * @param rhs String.
2442 * @return True if @a rhs.compare(@a lhs) == 0. False otherwise.
2444 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2446 operator==(const _CharT
* __lhs
,
2447 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2448 { return __rhs
.compare(__lhs
) == 0; }
2451 * @brief Test equivalence of string and C string.
2452 * @param lhs String.
2453 * @param rhs C string.
2454 * @return True if @a lhs.compare(@a rhs) == 0. False otherwise.
2456 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2458 operator==(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2459 const _CharT
* __rhs
)
2460 { return __lhs
.compare(__rhs
) == 0; }
2464 * @brief Test difference of two strings.
2465 * @param lhs First string.
2466 * @param rhs Second string.
2467 * @return True if @a lhs.compare(@a rhs) != 0. False otherwise.
2469 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2471 operator!=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2472 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2473 { return !(__lhs
== __rhs
); }
2476 * @brief Test difference of C string and string.
2477 * @param lhs C string.
2478 * @param rhs String.
2479 * @return True if @a rhs.compare(@a lhs) != 0. False otherwise.
2481 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2483 operator!=(const _CharT
* __lhs
,
2484 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2485 { return !(__lhs
== __rhs
); }
2488 * @brief Test difference of string and C string.
2489 * @param lhs String.
2490 * @param rhs C string.
2491 * @return True if @a lhs.compare(@a rhs) != 0. False otherwise.
2493 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2495 operator!=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2496 const _CharT
* __rhs
)
2497 { return !(__lhs
== __rhs
); }
2501 * @brief Test if string precedes string.
2502 * @param lhs First string.
2503 * @param rhs Second string.
2504 * @return True if @a lhs precedes @a rhs. False otherwise.
2506 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2508 operator<(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2509 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2510 { return __lhs
.compare(__rhs
) < 0; }
2513 * @brief Test if string precedes C string.
2514 * @param lhs String.
2515 * @param rhs C string.
2516 * @return True if @a lhs precedes @a rhs. False otherwise.
2518 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2520 operator<(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2521 const _CharT
* __rhs
)
2522 { return __lhs
.compare(__rhs
) < 0; }
2525 * @brief Test if C string precedes string.
2526 * @param lhs C string.
2527 * @param rhs String.
2528 * @return True if @a lhs precedes @a rhs. False otherwise.
2530 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2532 operator<(const _CharT
* __lhs
,
2533 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2534 { return __rhs
.compare(__lhs
) > 0; }
2538 * @brief Test if string follows string.
2539 * @param lhs First string.
2540 * @param rhs Second string.
2541 * @return True if @a lhs follows @a rhs. False otherwise.
2543 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2545 operator>(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2546 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2547 { return __lhs
.compare(__rhs
) > 0; }
2550 * @brief Test if string follows C string.
2551 * @param lhs String.
2552 * @param rhs C string.
2553 * @return True if @a lhs follows @a rhs. False otherwise.
2555 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2557 operator>(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2558 const _CharT
* __rhs
)
2559 { return __lhs
.compare(__rhs
) > 0; }
2562 * @brief Test if C string follows string.
2563 * @param lhs C string.
2564 * @param rhs String.
2565 * @return True if @a lhs follows @a rhs. False otherwise.
2567 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2569 operator>(const _CharT
* __lhs
,
2570 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2571 { return __rhs
.compare(__lhs
) < 0; }
2575 * @brief Test if string doesn't follow string.
2576 * @param lhs First string.
2577 * @param rhs Second string.
2578 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2580 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2582 operator<=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2583 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2584 { return __lhs
.compare(__rhs
) <= 0; }
2587 * @brief Test if string doesn't follow C string.
2588 * @param lhs String.
2589 * @param rhs C string.
2590 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2592 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2594 operator<=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2595 const _CharT
* __rhs
)
2596 { return __lhs
.compare(__rhs
) <= 0; }
2599 * @brief Test if C string doesn't follow string.
2600 * @param lhs C string.
2601 * @param rhs String.
2602 * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2604 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2606 operator<=(const _CharT
* __lhs
,
2607 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2608 { return __rhs
.compare(__lhs
) >= 0; }
2612 * @brief Test if string doesn't precede string.
2613 * @param lhs First string.
2614 * @param rhs Second string.
2615 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2617 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2619 operator>=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2620 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2621 { return __lhs
.compare(__rhs
) >= 0; }
2624 * @brief Test if string doesn't precede C string.
2625 * @param lhs String.
2626 * @param rhs C string.
2627 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2629 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2631 operator>=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2632 const _CharT
* __rhs
)
2633 { return __lhs
.compare(__rhs
) >= 0; }
2636 * @brief Test if C string doesn't precede string.
2637 * @param lhs C string.
2638 * @param rhs String.
2639 * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2641 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2643 operator>=(const _CharT
* __lhs
,
2644 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2645 { return __rhs
.compare(__lhs
) <= 0; }
2648 * @brief Swap contents of two strings.
2649 * @param lhs First string.
2650 * @param rhs Second string.
2652 * Exchanges the contents of @a lhs and @a rhs in constant time.
2654 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2656 swap(basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2657 basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2658 { __lhs
.swap(__rhs
); }
2661 * @brief Read stream into a string.
2662 * @param is Input stream.
2663 * @param str Buffer to store into.
2664 * @return Reference to the input stream.
2666 * Stores characters from @a is into @a str until whitespace is found, the
2667 * end of the stream is encountered, or str.max_size() is reached. If
2668 * is.width() is non-zero, that is the limit on the number of characters
2669 * stored into @a str. Any previous contents of @a str are erased.
2671 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2672 basic_istream
<_CharT
, _Traits
>&
2673 operator>>(basic_istream
<_CharT
, _Traits
>& __is
,
2674 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
);
2677 basic_istream
<char>&
2678 operator>>(basic_istream
<char>& __is
, basic_string
<char>& __str
);
2681 * @brief Write string to a stream.
2682 * @param os Output stream.
2683 * @param str String to write out.
2684 * @return Reference to the output stream.
2686 * Output characters of @a str into os following the same rules as for
2687 * writing a C string.
2689 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2690 inline basic_ostream
<_CharT
, _Traits
>&
2691 operator<<(basic_ostream
<_CharT
, _Traits
>& __os
,
2692 const basic_string
<_CharT
, _Traits
, _Alloc
>& __str
)
2694 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2695 // 586. string inserter not a formatted function
2696 return __ostream_insert(__os
, __str
.data(), __str
.size());
2700 * @brief Read a line from stream into a string.
2701 * @param is Input stream.
2702 * @param str Buffer to store into.
2703 * @param delim Character marking end of line.
2704 * @return Reference to the input stream.
2706 * Stores characters from @a is into @a str until @a delim is found, the
2707 * end of the stream is encountered, or str.max_size() is reached. If
2708 * is.width() is non-zero, that is the limit on the number of characters
2709 * stored into @a str. Any previous contents of @a str are erased. If @a
2710 * delim was encountered, it is extracted but not stored into @a str.
2712 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2713 basic_istream
<_CharT
, _Traits
>&
2714 getline(basic_istream
<_CharT
, _Traits
>& __is
,
2715 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
, _CharT __delim
);
2718 * @brief Read a line from stream into a string.
2719 * @param is Input stream.
2720 * @param str Buffer to store into.
2721 * @return Reference to the input stream.
2723 * Stores characters from is into @a str until '\n' is
2724 * found, the end of the stream is encountered, or str.max_size()
2725 * is reached. If is.width() is non-zero, that is the limit on the
2726 * number of characters stored into @a str. Any previous contents
2727 * of @a str are erased. If end of line was encountered, it is
2728 * extracted but not stored into @a str.
2730 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2731 inline basic_istream
<_CharT
, _Traits
>&
2732 getline(basic_istream
<_CharT
, _Traits
>& __is
,
2733 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
)
2734 { return getline(__is
, __str
, __is
.widen('\n')); }
2737 basic_istream
<char>&
2738 getline(basic_istream
<char>& __in
, basic_string
<char>& __str
,
2741 #ifdef _GLIBCXX_USE_WCHAR_T
2743 basic_istream
<wchar_t>&
2744 getline(basic_istream
<wchar_t>& __in
, basic_string
<wchar_t>& __str
,
2748 _GLIBCXX_END_NAMESPACE
2750 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99) \
2751 && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
2753 #include <ext/string_conversions.h>
2755 _GLIBCXX_BEGIN_NAMESPACE(std
)
2757 // 21.4 Numeric Conversions [string.conversions].
2759 stoi(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
2760 { return __gnu_cxx::__stoa
<long, int>(&std::strtol
, "stoi", __str
.c_str(),
2764 stol(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
2765 { return __gnu_cxx::__stoa(&std::strtol
, "stol", __str
.c_str(),
2768 inline unsigned long
2769 stoul(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
2770 { return __gnu_cxx::__stoa(&std::strtoul
, "stoul", __str
.c_str(),
2774 stoll(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
2775 { return __gnu_cxx::__stoa(&std::strtoll
, "stoll", __str
.c_str(),
2778 inline unsigned long long
2779 stoull(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
2780 { return __gnu_cxx::__stoa(&std::strtoull
, "stoull", __str
.c_str(),
2783 // NB: strtof vs strtod.
2785 stof(const string
& __str
, size_t* __idx
= 0)
2786 { return __gnu_cxx::__stoa(&std::strtof
, "stof", __str
.c_str(), __idx
); }
2789 stod(const string
& __str
, size_t* __idx
= 0)
2790 { return __gnu_cxx::__stoa(&std::strtod
, "stod", __str
.c_str(), __idx
); }
2793 stold(const string
& __str
, size_t* __idx
= 0)
2794 { return __gnu_cxx::__stoa(&std::strtold
, "stold", __str
.c_str(), __idx
); }
2796 // NB: (v)snprintf vs sprintf.
2800 to_string(int __val
)
2801 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, 4 * sizeof(int),
2805 to_string(unsigned __val
)
2806 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
2807 4 * sizeof(unsigned),
2811 to_string(long __val
)
2812 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, 4 * sizeof(long),
2816 to_string(unsigned long __val
)
2817 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
2818 4 * sizeof(unsigned long),
2822 to_string(long long __val
)
2823 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
2824 4 * sizeof(long long),
2828 to_string(unsigned long long __val
)
2829 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
2830 4 * sizeof(unsigned long long),
2834 to_string(float __val
)
2837 __gnu_cxx::__numeric_traits
<float>::__max_exponent10
+ 20;
2838 return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, __n
,
2843 to_string(double __val
)
2846 __gnu_cxx::__numeric_traits
<double>::__max_exponent10
+ 20;
2847 return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, __n
,
2852 to_string(long double __val
)
2855 __gnu_cxx::__numeric_traits
<long double>::__max_exponent10
+ 20;
2856 return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, __n
,
2860 #ifdef _GLIBCXX_USE_WCHAR_T
2862 stoi(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
2863 { return __gnu_cxx::__stoa
<long, int>(&std::wcstol
, "stoi", __str
.c_str(),
2867 stol(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
2868 { return __gnu_cxx::__stoa(&std::wcstol
, "stol", __str
.c_str(),
2871 inline unsigned long
2872 stoul(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
2873 { return __gnu_cxx::__stoa(&std::wcstoul
, "stoul", __str
.c_str(),
2877 stoll(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
2878 { return __gnu_cxx::__stoa(&std::wcstoll
, "stoll", __str
.c_str(),
2881 inline unsigned long long
2882 stoull(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
2883 { return __gnu_cxx::__stoa(&std::wcstoull
, "stoull", __str
.c_str(),
2886 // NB: wcstof vs wcstod.
2888 stof(const wstring
& __str
, size_t* __idx
= 0)
2889 { return __gnu_cxx::__stoa(&std::wcstof
, "stof", __str
.c_str(), __idx
); }
2892 stod(const wstring
& __str
, size_t* __idx
= 0)
2893 { return __gnu_cxx::__stoa(&std::wcstod
, "stod", __str
.c_str(), __idx
); }
2896 stold(const wstring
& __str
, size_t* __idx
= 0)
2897 { return __gnu_cxx::__stoa(&std::wcstold
, "stold", __str
.c_str(), __idx
); }
2901 to_wstring(int __val
)
2902 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, 4 * sizeof(int),
2906 to_wstring(unsigned __val
)
2907 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
2908 4 * sizeof(unsigned),
2912 to_wstring(long __val
)
2913 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, 4 * sizeof(long),
2917 to_wstring(unsigned long __val
)
2918 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
2919 4 * sizeof(unsigned long),
2923 to_wstring(long long __val
)
2924 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
2925 4 * sizeof(long long),
2929 to_wstring(unsigned long long __val
)
2930 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
2931 4 * sizeof(unsigned long long),
2935 to_wstring(float __val
)
2938 __gnu_cxx::__numeric_traits
<float>::__max_exponent10
+ 20;
2939 return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, __n
,
2944 to_wstring(double __val
)
2947 __gnu_cxx::__numeric_traits
<double>::__max_exponent10
+ 20;
2948 return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, __n
,
2953 to_wstring(long double __val
)
2956 __gnu_cxx::__numeric_traits
<long double>::__max_exponent10
+ 20;
2957 return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, __n
,
2962 _GLIBCXX_END_NAMESPACE
2964 #endif /* __GXX_EXPERIMENTAL_CXX0X__ && _GLIBCXX_USE_C99 ... */
2966 #ifdef __GXX_EXPERIMENTAL_CXX0X__
2968 #include <bits/functional_hash.h>
2970 _GLIBCXX_BEGIN_NAMESPACE(std
)
2974 #ifndef _GLIBCXX_COMPATIBILITY_CXX0X
2975 /// std::hash specialization for string.
2978 : public __hash_base
<size_t, string
>
2981 operator()(const string
& __s
) const
2982 { return std::_Hash_impl::hash(__s
.data(), __s
.length()); }
2985 #ifdef _GLIBCXX_USE_WCHAR_T
2986 /// std::hash specialization for wstring.
2988 struct hash
<wstring
>
2989 : public __hash_base
<size_t, wstring
>
2992 operator()(const wstring
& __s
) const
2993 { return std::_Hash_impl::hash(__s
.data(),
2994 __s
.length() * sizeof(wchar_t)); }
2997 #endif /* _GLIBCXX_COMPATIBILITY_CXX0X */
2999 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
3000 /// std::hash specialization for u16string.
3002 struct hash
<u16string
>
3003 : public __hash_base
<size_t, u16string
>
3006 operator()(const u16string
& __s
) const
3007 { return std::_Hash_impl::hash(__s
.data(),
3008 __s
.length() * sizeof(char16_t
)); }
3011 /// std::hash specialization for u32string.
3013 struct hash
<u32string
>
3014 : public __hash_base
<size_t, u32string
>
3017 operator()(const u32string
& __s
) const
3018 { return std::_Hash_impl::hash(__s
.data(),
3019 __s
.length() * sizeof(char32_t
)); }
3023 _GLIBCXX_END_NAMESPACE
3025 #endif /* __GXX_EXPERIMENTAL_CXX0X__ */
3027 #endif /* _BASIC_STRING_H */