1 // Components for manipulating sequences of characters -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 // 2006, 2007, 2008, 2009, 2010, 2011
5 // Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // Under Section 7 of GPL version 3, you are granted additional
19 // permissions described in the GCC Runtime Library Exception, version
20 // 3.1, as published by the Free Software Foundation.
22 // You should have received a copy of the GNU General Public License and
23 // a copy of the GCC Runtime Library Exception along with this program;
24 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 // <http://www.gnu.org/licenses/>.
27 /** @file bits/basic_string.h
28 * This is an internal header file, included by other library headers.
29 * Do not attempt to use it directly. @headername{string}
33 // ISO C++ 14882: 21 Strings library
36 #ifndef _BASIC_STRING_H
37 #define _BASIC_STRING_H 1
39 #pragma GCC system_header
41 #include <ext/atomicity.h>
42 #include <debug/debug.h>
43 #if __cplusplus >= 201103L
44 #include <initializer_list>
47 namespace std
_GLIBCXX_VISIBILITY(default)
49 _GLIBCXX_BEGIN_NAMESPACE_VERSION
52 * @class basic_string basic_string.h <string>
53 * @brief Managing sequences of characters and character-like objects.
58 * @tparam _CharT Type of character
59 * @tparam _Traits Traits for character type, defaults to
60 * char_traits<_CharT>.
61 * @tparam _Alloc Allocator type, defaults to allocator<_CharT>.
63 * Meets the requirements of a <a href="tables.html#65">container</a>, a
64 * <a href="tables.html#66">reversible container</a>, and a
65 * <a href="tables.html#67">sequence</a>. Of the
66 * <a href="tables.html#68">optional sequence requirements</a>, only
67 * @c push_back, @c at, and @c %array access are supported.
72 * Documentation? What's that?
73 * Nathan Myers <ncm@cantrip.org>.
75 * A string looks like this:
80 * [basic_string<char_type>] _M_capacity
81 * _M_dataplus _M_refcount
82 * _M_p ----------------> unnamed array of char_type
85 * Where the _M_p points to the first character in the string, and
86 * you cast it to a pointer-to-_Rep and subtract 1 to get a
87 * pointer to the header.
89 * This approach has the enormous advantage that a string object
90 * requires only one allocation. All the ugliness is confined
91 * within a single %pair of inline functions, which each compile to
92 * a single @a add instruction: _Rep::_M_data(), and
93 * string::_M_rep(); and the allocation function which gets a
94 * block of raw bytes and with room enough and constructs a _Rep
95 * object at the front.
97 * The reason you want _M_data pointing to the character %array and
98 * not the _Rep is so that the debugger can see the string
99 * contents. (Probably we should add a non-inline member to get
100 * the _Rep for the debugger to use, so users can check the actual
103 * Note that the _Rep object is a POD so that you can have a
104 * static <em>empty string</em> _Rep object already @a constructed before
105 * static constructors have run. The reference-count encoding is
106 * chosen so that a 0 indicates one reference, so you never try to
107 * destroy the empty-string _Rep object.
109 * All but the last paragraph is considered pretty conventional
110 * for a C++ string implementation.
112 // 21.3 Template class basic_string
113 template<typename _CharT
, typename _Traits
, typename _Alloc
>
116 typedef typename
_Alloc::template rebind
<_CharT
>::other _CharT_alloc_type
;
120 typedef _Traits traits_type
;
121 typedef typename
_Traits::char_type value_type
;
122 typedef _Alloc allocator_type
;
123 typedef typename
_CharT_alloc_type::size_type size_type
;
124 typedef typename
_CharT_alloc_type::difference_type difference_type
;
125 typedef typename
_CharT_alloc_type::reference reference
;
126 typedef typename
_CharT_alloc_type::const_reference const_reference
;
127 typedef typename
_CharT_alloc_type::pointer pointer
;
128 typedef typename
_CharT_alloc_type::const_pointer const_pointer
;
129 typedef __gnu_cxx::__normal_iterator
<pointer
, basic_string
> iterator
;
130 typedef __gnu_cxx::__normal_iterator
<const_pointer
, basic_string
>
132 typedef std::reverse_iterator
<const_iterator
> const_reverse_iterator
;
133 typedef std::reverse_iterator
<iterator
> reverse_iterator
;
136 // _Rep: string representation
138 // 1. String really contains _M_length + 1 characters: due to 21.3.4
139 // must be kept null-terminated.
140 // 2. _M_capacity >= _M_length
141 // Allocated memory is always (_M_capacity + 1) * sizeof(_CharT).
142 // 3. _M_refcount has three states:
143 // -1: leaked, one reference, no ref-copies allowed, non-const.
144 // 0: one reference, non-const.
145 // n>0: n + 1 references, operations require a lock, const.
146 // 4. All fields==0 is an empty string, given the extra storage
147 // beyond-the-end for a null terminator; thus, the shared
148 // empty string representation needs no constructor.
153 size_type _M_capacity
;
154 _Atomic_word _M_refcount
;
157 struct _Rep
: _Rep_base
160 typedef typename
_Alloc::template rebind
<char>::other _Raw_bytes_alloc
;
162 // (Public) Data members:
164 // The maximum number of individual char_type elements of an
165 // individual string is determined by _S_max_size. This is the
166 // value that will be returned by max_size(). (Whereas npos
167 // is the maximum number of bytes the allocator can allocate.)
168 // If one was to divvy up the theoretical largest size string,
169 // with a terminating character and m _CharT elements, it'd
171 // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
173 // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
174 // In addition, this implementation quarters this amount.
175 static const size_type _S_max_size
;
176 static const _CharT _S_terminal
;
178 // The following storage is init'd to 0 by the linker, resulting
179 // (carefully) in an empty string with one reference.
180 static size_type _S_empty_rep_storage
[];
185 // NB: Mild hack to avoid strict-aliasing warnings. Note that
186 // _S_empty_rep_storage is never modified and the punning should
187 // be reasonably safe in this case.
188 void* __p
= reinterpret_cast<void*>(&_S_empty_rep_storage
);
189 return *reinterpret_cast<_Rep
*>(__p
);
194 { return this->_M_refcount
< 0; }
198 { return this->_M_refcount
> 0; }
202 { this->_M_refcount
= -1; }
206 { this->_M_refcount
= 0; }
209 _M_set_length_and_sharable(size_type __n
)
211 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
212 if (__builtin_expect(this != &_S_empty_rep(), false))
215 this->_M_set_sharable(); // One reference.
216 this->_M_length
= __n
;
217 traits_type::assign(this->_M_refdata()[__n
], _S_terminal
);
218 // grrr. (per 21.3.4)
219 // You cannot leave those LWG people alone for a second.
225 { return reinterpret_cast<_CharT
*>(this + 1); }
228 _M_grab(const _Alloc
& __alloc1
, const _Alloc
& __alloc2
)
230 return (!_M_is_leaked() && __alloc1
== __alloc2
)
231 ? _M_refcopy() : _M_clone(__alloc1
);
236 _S_create(size_type
, size_type
, const _Alloc
&);
239 _M_dispose(const _Alloc
& __a
)
241 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
242 if (__builtin_expect(this != &_S_empty_rep(), false))
245 // Be race-detector-friendly. For more info see bits/c++config.
246 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount
);
247 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount
,
250 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount
);
257 _M_destroy(const _Alloc
&) throw();
262 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
263 if (__builtin_expect(this != &_S_empty_rep(), false))
265 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount
, 1);
270 _M_clone(const _Alloc
&, size_type __res
= 0);
273 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
274 struct _Alloc_hider
: _Alloc
276 _Alloc_hider(_CharT
* __dat
, const _Alloc
& __a
)
277 : _Alloc(__a
), _M_p(__dat
) { }
279 _CharT
* _M_p
; // The actual data.
283 // Data Members (public):
284 // NB: This is an unsigned type, and thus represents the maximum
285 // size that the allocator can hold.
286 /// Value returned by various member functions when they fail.
287 static const size_type npos
= static_cast<size_type
>(-1);
290 // Data Members (private):
291 mutable _Alloc_hider _M_dataplus
;
295 { return _M_dataplus
._M_p
; }
299 { return (_M_dataplus
._M_p
= __p
); }
303 { return &((reinterpret_cast<_Rep
*> (_M_data()))[-1]); }
305 // For the internal use we have functions similar to `begin'/`end'
306 // but they do not call _M_leak.
309 { return iterator(_M_data()); }
313 { return iterator(_M_data() + this->size()); }
316 _M_leak() // for use in begin() & non-const op[]
318 if (!_M_rep()->_M_is_leaked())
323 _M_check(size_type __pos
, const char* __s
) const
325 if (__pos
> this->size())
326 __throw_out_of_range(__N(__s
));
331 _M_check_length(size_type __n1
, size_type __n2
, const char* __s
) const
333 if (this->max_size() - (this->size() - __n1
) < __n2
)
334 __throw_length_error(__N(__s
));
337 // NB: _M_limit doesn't check for a bad __pos value.
339 _M_limit(size_type __pos
, size_type __off
) const
341 const bool __testoff
= __off
< this->size() - __pos
;
342 return __testoff
? __off
: this->size() - __pos
;
345 // True if _Rep and source do not overlap.
347 _M_disjunct(const _CharT
* __s
) const
349 return (less
<const _CharT
*>()(__s
, _M_data())
350 || less
<const _CharT
*>()(_M_data() + this->size(), __s
));
353 // When __n = 1 way faster than the general multichar
354 // traits_type::copy/move/assign.
356 _M_copy(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
359 traits_type::assign(*__d
, *__s
);
361 traits_type::copy(__d
, __s
, __n
);
365 _M_move(_CharT
* __d
, const _CharT
* __s
, size_type __n
)
368 traits_type::assign(*__d
, *__s
);
370 traits_type::move(__d
, __s
, __n
);
374 _M_assign(_CharT
* __d
, size_type __n
, _CharT __c
)
377 traits_type::assign(*__d
, __c
);
379 traits_type::assign(__d
, __n
, __c
);
382 // _S_copy_chars is a separate template to permit specialization
383 // to optimize for the common case of pointers as iterators.
384 template<class _Iterator
>
386 _S_copy_chars(_CharT
* __p
, _Iterator __k1
, _Iterator __k2
)
388 for (; __k1
!= __k2
; ++__k1
, ++__p
)
389 traits_type::assign(*__p
, *__k1
); // These types are off.
393 _S_copy_chars(_CharT
* __p
, iterator __k1
, iterator __k2
)
394 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
397 _S_copy_chars(_CharT
* __p
, const_iterator __k1
, const_iterator __k2
)
398 { _S_copy_chars(__p
, __k1
.base(), __k2
.base()); }
401 _S_copy_chars(_CharT
* __p
, _CharT
* __k1
, _CharT
* __k2
)
402 { _M_copy(__p
, __k1
, __k2
- __k1
); }
405 _S_copy_chars(_CharT
* __p
, const _CharT
* __k1
, const _CharT
* __k2
)
406 { _M_copy(__p
, __k1
, __k2
- __k1
); }
409 _S_compare(size_type __n1
, size_type __n2
)
411 const difference_type __d
= difference_type(__n1
- __n2
);
413 if (__d
> __gnu_cxx::__numeric_traits
<int>::__max
)
414 return __gnu_cxx::__numeric_traits
<int>::__max
;
415 else if (__d
< __gnu_cxx::__numeric_traits
<int>::__min
)
416 return __gnu_cxx::__numeric_traits
<int>::__min
;
422 _M_mutate(size_type __pos
, size_type __len1
, size_type __len2
);
429 { return _Rep::_S_empty_rep(); }
432 // Construct/copy/destroy:
433 // NB: We overload ctors in some cases instead of using default
434 // arguments, per 17.4.4.4 para. 2 item 2.
437 * @brief Default constructor creates an empty string.
440 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
441 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
443 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()){ }
447 * @brief Construct an empty string using allocator @a a.
450 basic_string(const _Alloc
& __a
);
452 // NB: per LWG issue 42, semantics different from IS:
454 * @brief Construct string with copy of value of @a str.
455 * @param __str Source string.
457 basic_string(const basic_string
& __str
);
459 * @brief Construct string as copy of a substring.
460 * @param __str Source string.
461 * @param __pos Index of first character to copy from.
462 * @param __n Number of characters to copy (default remainder).
464 basic_string(const basic_string
& __str
, size_type __pos
,
465 size_type __n
= npos
);
467 * @brief Construct string as copy of a substring.
468 * @param __str Source string.
469 * @param __pos Index of first character to copy from.
470 * @param __n Number of characters to copy.
471 * @param __a Allocator to use.
473 basic_string(const basic_string
& __str
, size_type __pos
,
474 size_type __n
, const _Alloc
& __a
);
477 * @brief Construct string initialized by a character %array.
478 * @param __s Source character %array.
479 * @param __n Number of characters to copy.
480 * @param __a Allocator to use (default is default allocator).
482 * NB: @a __s must have at least @a __n characters, '\\0'
483 * has no special meaning.
485 basic_string(const _CharT
* __s
, size_type __n
,
486 const _Alloc
& __a
= _Alloc());
488 * @brief Construct string as copy of a C string.
489 * @param __s Source C string.
490 * @param __a Allocator to use (default is default allocator).
492 basic_string(const _CharT
* __s
, const _Alloc
& __a
= _Alloc());
494 * @brief Construct string as multiple characters.
495 * @param __n Number of characters.
496 * @param __c Character to use.
497 * @param __a Allocator to use (default is default allocator).
499 basic_string(size_type __n
, _CharT __c
, const _Alloc
& __a
= _Alloc());
501 #if __cplusplus >= 201103L
503 * @brief Move construct string.
504 * @param __str Source string.
506 * The newly-created string contains the exact contents of @a __str.
507 * @a __str is a valid, but unspecified string.
509 basic_string(basic_string
&& __str
) noexcept
510 : _M_dataplus(__str
._M_dataplus
)
512 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
513 __str
._M_data(_S_empty_rep()._M_refdata());
515 __str
._M_data(_S_construct(size_type(), _CharT(), get_allocator()));
520 * @brief Construct string from an initializer %list.
521 * @param __l std::initializer_list of characters.
522 * @param __a Allocator to use (default is default allocator).
524 basic_string(initializer_list
<_CharT
> __l
, const _Alloc
& __a
= _Alloc());
528 * @brief Construct string as copy of a range.
529 * @param __beg Start of range.
530 * @param __end End of range.
531 * @param __a Allocator to use (default is default allocator).
533 template<class _InputIterator
>
534 basic_string(_InputIterator __beg
, _InputIterator __end
,
535 const _Alloc
& __a
= _Alloc());
538 * @brief Destroy the string instance.
540 ~basic_string() _GLIBCXX_NOEXCEPT
541 { _M_rep()->_M_dispose(this->get_allocator()); }
544 * @brief Assign the value of @a str to this string.
545 * @param __str Source string.
548 operator=(const basic_string
& __str
)
549 { return this->assign(__str
); }
552 * @brief Copy contents of @a s into this string.
553 * @param __s Source null-terminated string.
556 operator=(const _CharT
* __s
)
557 { return this->assign(__s
); }
560 * @brief Set value to string of length 1.
561 * @param __c Source character.
563 * Assigning to a character makes this string length 1 and
564 * (*this)[0] == @a c.
567 operator=(_CharT __c
)
569 this->assign(1, __c
);
573 #if __cplusplus >= 201103L
575 * @brief Move assign the value of @a str to this string.
576 * @param __str Source string.
578 * The contents of @a str are moved into this string (without copying).
579 * @a str is a valid, but unspecified string.
582 operator=(basic_string
&& __str
)
590 * @brief Set value to string constructed from initializer %list.
591 * @param __l std::initializer_list.
594 operator=(initializer_list
<_CharT
> __l
)
596 this->assign(__l
.begin(), __l
.size());
603 * Returns a read/write iterator that points to the first character in
604 * the %string. Unshares the string.
607 begin() _GLIBCXX_NOEXCEPT
610 return iterator(_M_data());
614 * Returns a read-only (constant) iterator that points to the first
615 * character in the %string.
618 begin() const _GLIBCXX_NOEXCEPT
619 { return const_iterator(_M_data()); }
622 * Returns a read/write iterator that points one past the last
623 * character in the %string. Unshares the string.
626 end() _GLIBCXX_NOEXCEPT
629 return iterator(_M_data() + this->size());
633 * Returns a read-only (constant) iterator that points one past the
634 * last character in the %string.
637 end() const _GLIBCXX_NOEXCEPT
638 { return const_iterator(_M_data() + this->size()); }
641 * Returns a read/write reverse iterator that points to the last
642 * character in the %string. Iteration is done in reverse element
643 * order. Unshares the string.
646 rbegin() _GLIBCXX_NOEXCEPT
647 { return reverse_iterator(this->end()); }
650 * Returns a read-only (constant) reverse iterator that points
651 * to the last character in the %string. Iteration is done in
652 * reverse element order.
654 const_reverse_iterator
655 rbegin() const _GLIBCXX_NOEXCEPT
656 { return const_reverse_iterator(this->end()); }
659 * Returns a read/write reverse iterator that points to one before the
660 * first character in the %string. Iteration is done in reverse
661 * element order. Unshares the string.
664 rend() _GLIBCXX_NOEXCEPT
665 { return reverse_iterator(this->begin()); }
668 * Returns a read-only (constant) reverse iterator that points
669 * to one before the first character in the %string. Iteration
670 * is done in reverse element order.
672 const_reverse_iterator
673 rend() const _GLIBCXX_NOEXCEPT
674 { return const_reverse_iterator(this->begin()); }
676 #if __cplusplus >= 201103L
678 * Returns a read-only (constant) iterator that points to the first
679 * character in the %string.
682 cbegin() const noexcept
683 { return const_iterator(this->_M_data()); }
686 * Returns a read-only (constant) iterator that points one past the
687 * last character in the %string.
690 cend() const noexcept
691 { return const_iterator(this->_M_data() + this->size()); }
694 * Returns a read-only (constant) reverse iterator that points
695 * to the last character in the %string. Iteration is done in
696 * reverse element order.
698 const_reverse_iterator
699 crbegin() const noexcept
700 { return const_reverse_iterator(this->end()); }
703 * Returns a read-only (constant) reverse iterator that points
704 * to one before the first character in the %string. Iteration
705 * is done in reverse element order.
707 const_reverse_iterator
708 crend() const noexcept
709 { return const_reverse_iterator(this->begin()); }
714 /// Returns the number of characters in the string, not including any
715 /// null-termination.
717 size() const _GLIBCXX_NOEXCEPT
718 { return _M_rep()->_M_length
; }
720 /// Returns the number of characters in the string, not including any
721 /// null-termination.
723 length() const _GLIBCXX_NOEXCEPT
724 { return _M_rep()->_M_length
; }
726 /// Returns the size() of the largest possible %string.
728 max_size() const _GLIBCXX_NOEXCEPT
729 { return _Rep::_S_max_size
; }
732 * @brief Resizes the %string to the specified number of characters.
733 * @param __n Number of characters the %string should contain.
734 * @param __c Character to fill any new elements.
736 * This function will %resize the %string to the specified
737 * number of characters. If the number is smaller than the
738 * %string's current size the %string is truncated, otherwise
739 * the %string is extended and new elements are %set to @a __c.
742 resize(size_type __n
, _CharT __c
);
745 * @brief Resizes the %string to the specified number of characters.
746 * @param __n Number of characters the %string should contain.
748 * This function will resize the %string to the specified length. If
749 * the new size is smaller than the %string's current size the %string
750 * is truncated, otherwise the %string is extended and new characters
751 * are default-constructed. For basic types such as char, this means
755 resize(size_type __n
)
756 { this->resize(__n
, _CharT()); }
758 #if __cplusplus >= 201103L
759 /// A non-binding request to reduce capacity() to size().
763 if (capacity() > size())
774 * Returns the total number of characters that the %string can hold
775 * before needing to allocate more memory.
778 capacity() const _GLIBCXX_NOEXCEPT
779 { return _M_rep()->_M_capacity
; }
782 * @brief Attempt to preallocate enough memory for specified number of
784 * @param __res_arg Number of characters required.
785 * @throw std::length_error If @a __res_arg exceeds @c max_size().
787 * This function attempts to reserve enough memory for the
788 * %string to hold the specified number of characters. If the
789 * number requested is more than max_size(), length_error is
792 * The advantage of this function is that if optimal code is a
793 * necessity and the user can determine the string length that will be
794 * required, the user can reserve the memory in %advance, and thus
795 * prevent a possible reallocation of memory and copying of %string
799 reserve(size_type __res_arg
= 0);
802 * Erases the string, making it empty.
805 clear() _GLIBCXX_NOEXCEPT
806 { _M_mutate(0, this->size(), 0); }
809 * Returns true if the %string is empty. Equivalent to
810 * <code>*this == ""</code>.
813 empty() const _GLIBCXX_NOEXCEPT
814 { return this->size() == 0; }
818 * @brief Subscript access to the data contained in the %string.
819 * @param __pos The index of the character to access.
820 * @return Read-only (constant) reference to the character.
822 * This operator allows for easy, array-style, data access.
823 * Note that data access with this operator is unchecked and
824 * out_of_range lookups are not defined. (For checked lookups
828 operator[] (size_type __pos
) const
830 _GLIBCXX_DEBUG_ASSERT(__pos
<= size());
831 return _M_data()[__pos
];
835 * @brief Subscript access to the data contained in the %string.
836 * @param __pos The index of the character to access.
837 * @return Read/write reference to the character.
839 * This operator allows for easy, array-style, data access.
840 * Note that data access with this operator is unchecked and
841 * out_of_range lookups are not defined. (For checked lookups
842 * see at().) Unshares the string.
845 operator[](size_type __pos
)
847 // allow pos == size() as v3 extension:
848 _GLIBCXX_DEBUG_ASSERT(__pos
<= size());
849 // but be strict in pedantic mode:
850 _GLIBCXX_DEBUG_PEDASSERT(__pos
< size());
852 return _M_data()[__pos
];
856 * @brief Provides access to the data contained in the %string.
857 * @param __n The index of the character to access.
858 * @return Read-only (const) reference to the character.
859 * @throw std::out_of_range If @a n is an invalid index.
861 * This function provides for safer data access. The parameter is
862 * first checked that it is in the range of the string. The function
863 * throws out_of_range if the check fails.
866 at(size_type __n
) const
868 if (__n
>= this->size())
869 __throw_out_of_range(__N("basic_string::at"));
870 return _M_data()[__n
];
874 * @brief Provides access to the data contained in the %string.
875 * @param __n The index of the character to access.
876 * @return Read/write reference to the character.
877 * @throw std::out_of_range If @a n is an invalid index.
879 * This function provides for safer data access. The parameter is
880 * first checked that it is in the range of the string. The function
881 * throws out_of_range if the check fails. Success results in
882 * unsharing the string.
888 __throw_out_of_range(__N("basic_string::at"));
890 return _M_data()[__n
];
893 #if __cplusplus >= 201103L
895 * Returns a read/write reference to the data at the first
896 * element of the %string.
900 { return operator[](0); }
903 * Returns a read-only (constant) reference to the data at the first
904 * element of the %string.
908 { return operator[](0); }
911 * Returns a read/write reference to the data at the last
912 * element of the %string.
916 { return operator[](this->size() - 1); }
919 * Returns a read-only (constant) reference to the data at the
920 * last element of the %string.
924 { return operator[](this->size() - 1); }
929 * @brief Append a string to this string.
930 * @param __str The string to append.
931 * @return Reference to this string.
934 operator+=(const basic_string
& __str
)
935 { return this->append(__str
); }
938 * @brief Append a C string.
939 * @param __s The C string to append.
940 * @return Reference to this string.
943 operator+=(const _CharT
* __s
)
944 { return this->append(__s
); }
947 * @brief Append a character.
948 * @param __c The character to append.
949 * @return Reference to this string.
952 operator+=(_CharT __c
)
954 this->push_back(__c
);
958 #if __cplusplus >= 201103L
960 * @brief Append an initializer_list of characters.
961 * @param __l The initializer_list of characters to be appended.
962 * @return Reference to this string.
965 operator+=(initializer_list
<_CharT
> __l
)
966 { return this->append(__l
.begin(), __l
.size()); }
970 * @brief Append a string to this string.
971 * @param __str The string to append.
972 * @return Reference to this string.
975 append(const basic_string
& __str
);
978 * @brief Append a substring.
979 * @param __str The string to append.
980 * @param __pos Index of the first character of str to append.
981 * @param __n The number of characters to append.
982 * @return Reference to this string.
983 * @throw std::out_of_range if @a __pos is not a valid index.
985 * This function appends @a __n characters from @a __str
986 * starting at @a __pos to this string. If @a __n is is larger
987 * than the number of available characters in @a __str, the
988 * remainder of @a __str is appended.
991 append(const basic_string
& __str
, size_type __pos
, size_type __n
);
994 * @brief Append a C substring.
995 * @param __s The C string to append.
996 * @param __n The number of characters to append.
997 * @return Reference to this string.
1000 append(const _CharT
* __s
, size_type __n
);
1003 * @brief Append a C string.
1004 * @param __s The C string to append.
1005 * @return Reference to this string.
1008 append(const _CharT
* __s
)
1010 __glibcxx_requires_string(__s
);
1011 return this->append(__s
, traits_type::length(__s
));
1015 * @brief Append multiple characters.
1016 * @param __n The number of characters to append.
1017 * @param __c The character to use.
1018 * @return Reference to this string.
1020 * Appends __n copies of __c to this string.
1023 append(size_type __n
, _CharT __c
);
1025 #if __cplusplus >= 201103L
1027 * @brief Append an initializer_list of characters.
1028 * @param __l The initializer_list of characters to append.
1029 * @return Reference to this string.
1032 append(initializer_list
<_CharT
> __l
)
1033 { return this->append(__l
.begin(), __l
.size()); }
1037 * @brief Append a range of characters.
1038 * @param __first Iterator referencing the first character to append.
1039 * @param __last Iterator marking the end of the range.
1040 * @return Reference to this string.
1042 * Appends characters in the range [__first,__last) to this string.
1044 template<class _InputIterator
>
1046 append(_InputIterator __first
, _InputIterator __last
)
1047 { return this->replace(_M_iend(), _M_iend(), __first
, __last
); }
1050 * @brief Append a single character.
1051 * @param __c Character to append.
1054 push_back(_CharT __c
)
1056 const size_type __len
= 1 + this->size();
1057 if (__len
> this->capacity() || _M_rep()->_M_is_shared())
1058 this->reserve(__len
);
1059 traits_type::assign(_M_data()[this->size()], __c
);
1060 _M_rep()->_M_set_length_and_sharable(__len
);
1064 * @brief Set value to contents of another string.
1065 * @param __str Source string to use.
1066 * @return Reference to this string.
1069 assign(const basic_string
& __str
);
1071 #if __cplusplus >= 201103L
1073 * @brief Set value to contents of another string.
1074 * @param __str Source string to use.
1075 * @return Reference to this string.
1077 * This function sets this string to the exact contents of @a __str.
1078 * @a __str is a valid, but unspecified string.
1081 assign(basic_string
&& __str
)
1089 * @brief Set value to a substring of a string.
1090 * @param __str The string to use.
1091 * @param __pos Index of the first character of str.
1092 * @param __n Number of characters to use.
1093 * @return Reference to this string.
1094 * @throw std::out_of_range if @a pos is not a valid index.
1096 * This function sets this string to the substring of @a __str
1097 * consisting of @a __n characters at @a __pos. If @a __n is
1098 * is larger than the number of available characters in @a
1099 * __str, the remainder of @a __str is used.
1102 assign(const basic_string
& __str
, size_type __pos
, size_type __n
)
1103 { return this->assign(__str
._M_data()
1104 + __str
._M_check(__pos
, "basic_string::assign"),
1105 __str
._M_limit(__pos
, __n
)); }
1108 * @brief Set value to a C substring.
1109 * @param __s The C string to use.
1110 * @param __n Number of characters to use.
1111 * @return Reference to this string.
1113 * This function sets the value of this string to the first @a __n
1114 * characters of @a __s. If @a __n is is larger than the number of
1115 * available characters in @a __s, the remainder of @a __s is used.
1118 assign(const _CharT
* __s
, size_type __n
);
1121 * @brief Set value to contents of a C string.
1122 * @param __s The C string to use.
1123 * @return Reference to this string.
1125 * This function sets the value of this string to the value of @a __s.
1126 * The data is copied, so there is no dependence on @a __s once the
1130 assign(const _CharT
* __s
)
1132 __glibcxx_requires_string(__s
);
1133 return this->assign(__s
, traits_type::length(__s
));
1137 * @brief Set value to multiple characters.
1138 * @param __n Length of the resulting string.
1139 * @param __c The character to use.
1140 * @return Reference to this string.
1142 * This function sets the value of this string to @a __n copies of
1146 assign(size_type __n
, _CharT __c
)
1147 { return _M_replace_aux(size_type(0), this->size(), __n
, __c
); }
1150 * @brief Set value to a range of characters.
1151 * @param __first Iterator referencing the first character to append.
1152 * @param __last Iterator marking the end of the range.
1153 * @return Reference to this string.
1155 * Sets value of string to characters in the range [__first,__last).
1157 template<class _InputIterator
>
1159 assign(_InputIterator __first
, _InputIterator __last
)
1160 { return this->replace(_M_ibegin(), _M_iend(), __first
, __last
); }
1162 #if __cplusplus >= 201103L
1164 * @brief Set value to an initializer_list of characters.
1165 * @param __l The initializer_list of characters to assign.
1166 * @return Reference to this string.
1169 assign(initializer_list
<_CharT
> __l
)
1170 { return this->assign(__l
.begin(), __l
.size()); }
1174 * @brief Insert multiple characters.
1175 * @param __p Iterator referencing location in string to insert at.
1176 * @param __n Number of characters to insert
1177 * @param __c The character to insert.
1178 * @throw std::length_error If new length exceeds @c max_size().
1180 * Inserts @a __n copies of character @a __c starting at the
1181 * position referenced by iterator @a __p. If adding
1182 * characters causes the length to exceed max_size(),
1183 * length_error is thrown. The value of the string doesn't
1184 * change if an error is thrown.
1187 insert(iterator __p
, size_type __n
, _CharT __c
)
1188 { this->replace(__p
, __p
, __n
, __c
); }
1191 * @brief Insert a range of characters.
1192 * @param __p Iterator referencing location in string to insert at.
1193 * @param __beg Start of range.
1194 * @param __end End of range.
1195 * @throw std::length_error If new length exceeds @c max_size().
1197 * Inserts characters in range [__beg,__end). If adding
1198 * characters causes the length to exceed max_size(),
1199 * length_error is thrown. The value of the string doesn't
1200 * change if an error is thrown.
1202 template<class _InputIterator
>
1204 insert(iterator __p
, _InputIterator __beg
, _InputIterator __end
)
1205 { this->replace(__p
, __p
, __beg
, __end
); }
1207 #if __cplusplus >= 201103L
1209 * @brief Insert an initializer_list of characters.
1210 * @param __p Iterator referencing location in string to insert at.
1211 * @param __l The initializer_list of characters to insert.
1212 * @throw std::length_error If new length exceeds @c max_size().
1215 insert(iterator __p
, initializer_list
<_CharT
> __l
)
1217 _GLIBCXX_DEBUG_PEDASSERT(__p
>= _M_ibegin() && __p
<= _M_iend());
1218 this->insert(__p
- _M_ibegin(), __l
.begin(), __l
.size());
1223 * @brief Insert value of a string.
1224 * @param __pos1 Iterator referencing location in string to insert at.
1225 * @param __str The string to insert.
1226 * @return Reference to this string.
1227 * @throw std::length_error If new length exceeds @c max_size().
1229 * Inserts value of @a __str starting at @a __pos1. If adding
1230 * characters causes the length to exceed max_size(),
1231 * length_error is thrown. The value of the string doesn't
1232 * change if an error is thrown.
1235 insert(size_type __pos1
, const basic_string
& __str
)
1236 { return this->insert(__pos1
, __str
, size_type(0), __str
.size()); }
1239 * @brief Insert a substring.
1240 * @param __pos1 Iterator referencing location in string to insert at.
1241 * @param __str The string to insert.
1242 * @param __pos2 Start of characters in str to insert.
1243 * @param __n Number of characters to insert.
1244 * @return Reference to this string.
1245 * @throw std::length_error If new length exceeds @c max_size().
1246 * @throw std::out_of_range If @a pos1 > size() or
1247 * @a __pos2 > @a str.size().
1249 * Starting at @a pos1, insert @a __n character of @a __str
1250 * beginning with @a __pos2. If adding characters causes the
1251 * length to exceed max_size(), length_error is thrown. If @a
1252 * __pos1 is beyond the end of this string or @a __pos2 is
1253 * beyond the end of @a __str, out_of_range is thrown. The
1254 * value of the string doesn't change if an error is thrown.
1257 insert(size_type __pos1
, const basic_string
& __str
,
1258 size_type __pos2
, size_type __n
)
1259 { return this->insert(__pos1
, __str
._M_data()
1260 + __str
._M_check(__pos2
, "basic_string::insert"),
1261 __str
._M_limit(__pos2
, __n
)); }
1264 * @brief Insert a C substring.
1265 * @param __pos Iterator referencing location in string to insert at.
1266 * @param __s The C string to insert.
1267 * @param __n The number of characters to insert.
1268 * @return Reference to this string.
1269 * @throw std::length_error If new length exceeds @c max_size().
1270 * @throw std::out_of_range If @a __pos is beyond the end of this
1273 * Inserts the first @a __n characters of @a __s starting at @a
1274 * __pos. If adding characters causes the length to exceed
1275 * max_size(), length_error is thrown. If @a __pos is beyond
1276 * end(), out_of_range is thrown. The value of the string
1277 * doesn't change if an error is thrown.
1280 insert(size_type __pos
, const _CharT
* __s
, size_type __n
);
1283 * @brief Insert a C string.
1284 * @param __pos Iterator referencing location in string to insert at.
1285 * @param __s The C string to insert.
1286 * @return Reference to this string.
1287 * @throw std::length_error If new length exceeds @c max_size().
1288 * @throw std::out_of_range If @a pos is beyond the end of this
1291 * Inserts the first @a n characters of @a __s starting at @a __pos. If
1292 * adding characters causes the length to exceed max_size(),
1293 * length_error is thrown. If @a __pos is beyond end(), out_of_range is
1294 * thrown. The value of the string doesn't change if an error is
1298 insert(size_type __pos
, const _CharT
* __s
)
1300 __glibcxx_requires_string(__s
);
1301 return this->insert(__pos
, __s
, traits_type::length(__s
));
1305 * @brief Insert multiple characters.
1306 * @param __pos Index in string to insert at.
1307 * @param __n Number of characters to insert
1308 * @param __c The character to insert.
1309 * @return Reference to this string.
1310 * @throw std::length_error If new length exceeds @c max_size().
1311 * @throw std::out_of_range If @a __pos is beyond the end of this
1314 * Inserts @a __n copies of character @a __c starting at index
1315 * @a __pos. If adding characters causes the length to exceed
1316 * max_size(), length_error is thrown. If @a __pos > length(),
1317 * out_of_range is thrown. The value of the string doesn't
1318 * change if an error is thrown.
1321 insert(size_type __pos
, size_type __n
, _CharT __c
)
1322 { return _M_replace_aux(_M_check(__pos
, "basic_string::insert"),
1323 size_type(0), __n
, __c
); }
1326 * @brief Insert one character.
1327 * @param __p Iterator referencing position in string to insert at.
1328 * @param __c The character to insert.
1329 * @return Iterator referencing newly inserted char.
1330 * @throw std::length_error If new length exceeds @c max_size().
1332 * Inserts character @a __c at position referenced by @a __p.
1333 * If adding character causes the length to exceed max_size(),
1334 * length_error is thrown. If @a __p is beyond end of string,
1335 * out_of_range is thrown. The value of the string doesn't
1336 * change if an error is thrown.
1339 insert(iterator __p
, _CharT __c
)
1341 _GLIBCXX_DEBUG_PEDASSERT(__p
>= _M_ibegin() && __p
<= _M_iend());
1342 const size_type __pos
= __p
- _M_ibegin();
1343 _M_replace_aux(__pos
, size_type(0), size_type(1), __c
);
1344 _M_rep()->_M_set_leaked();
1345 return iterator(_M_data() + __pos
);
1349 * @brief Remove characters.
1350 * @param __pos Index of first character to remove (default 0).
1351 * @param __n Number of characters to remove (default remainder).
1352 * @return Reference to this string.
1353 * @throw std::out_of_range If @a pos is beyond the end of this
1356 * Removes @a __n characters from this string starting at @a
1357 * __pos. The length of the string is reduced by @a __n. If
1358 * there are < @a __n characters to remove, the remainder of
1359 * the string is truncated. If @a __p is beyond end of string,
1360 * out_of_range is thrown. The value of the string doesn't
1361 * change if an error is thrown.
1364 erase(size_type __pos
= 0, size_type __n
= npos
)
1366 _M_mutate(_M_check(__pos
, "basic_string::erase"),
1367 _M_limit(__pos
, __n
), size_type(0));
1372 * @brief Remove one character.
1373 * @param __position Iterator referencing the character to remove.
1374 * @return iterator referencing same location after removal.
1376 * Removes the character at @a __position from this string. The value
1377 * of the string doesn't change if an error is thrown.
1380 erase(iterator __position
)
1382 _GLIBCXX_DEBUG_PEDASSERT(__position
>= _M_ibegin()
1383 && __position
< _M_iend());
1384 const size_type __pos
= __position
- _M_ibegin();
1385 _M_mutate(__pos
, size_type(1), size_type(0));
1386 _M_rep()->_M_set_leaked();
1387 return iterator(_M_data() + __pos
);
1391 * @brief Remove a range of characters.
1392 * @param __first Iterator referencing the first character to remove.
1393 * @param __last Iterator referencing the end of the range.
1394 * @return Iterator referencing location of first after removal.
1396 * Removes the characters in the range [first,last) from this string.
1397 * The value of the string doesn't change if an error is thrown.
1400 erase(iterator __first
, iterator __last
);
1402 #if __cplusplus >= 201103L
1404 * @brief Remove the last character.
1406 * The string must be non-empty.
1410 { erase(size()-1, 1); }
1414 * @brief Replace characters with value from another string.
1415 * @param __pos Index of first character to replace.
1416 * @param __n Number of characters to be replaced.
1417 * @param __str String to insert.
1418 * @return Reference to this string.
1419 * @throw std::out_of_range If @a pos is beyond the end of this
1421 * @throw std::length_error If new length exceeds @c max_size().
1423 * Removes the characters in the range [__pos,__pos+__n) from
1424 * this string. In place, the value of @a __str is inserted.
1425 * If @a __pos is beyond end of string, out_of_range is thrown.
1426 * If the length of the result exceeds max_size(), length_error
1427 * is thrown. The value of the string doesn't change if an
1431 replace(size_type __pos
, size_type __n
, const basic_string
& __str
)
1432 { return this->replace(__pos
, __n
, __str
._M_data(), __str
.size()); }
1435 * @brief Replace characters with value from another string.
1436 * @param __pos1 Index of first character to replace.
1437 * @param __n1 Number of characters to be replaced.
1438 * @param __str String to insert.
1439 * @param __pos2 Index of first character of str to use.
1440 * @param __n2 Number of characters from str to use.
1441 * @return Reference to this string.
1442 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
1444 * @throw std::length_error If new length exceeds @c max_size().
1446 * Removes the characters in the range [__pos1,__pos1 + n) from this
1447 * string. In place, the value of @a __str is inserted. If @a __pos is
1448 * beyond end of string, out_of_range is thrown. If the length of the
1449 * result exceeds max_size(), length_error is thrown. The value of the
1450 * string doesn't change if an error is thrown.
1453 replace(size_type __pos1
, size_type __n1
, const basic_string
& __str
,
1454 size_type __pos2
, size_type __n2
)
1455 { return this->replace(__pos1
, __n1
, __str
._M_data()
1456 + __str
._M_check(__pos2
, "basic_string::replace"),
1457 __str
._M_limit(__pos2
, __n2
)); }
1460 * @brief Replace characters with value of a C substring.
1461 * @param __pos Index of first character to replace.
1462 * @param __n1 Number of characters to be replaced.
1463 * @param __s C string to insert.
1464 * @param __n2 Number of characters from @a s to use.
1465 * @return Reference to this string.
1466 * @throw std::out_of_range If @a pos1 > size().
1467 * @throw std::length_error If new length exceeds @c max_size().
1469 * Removes the characters in the range [__pos,__pos + __n1)
1470 * from this string. In place, the first @a __n2 characters of
1471 * @a __s are inserted, or all of @a __s if @a __n2 is too large. If
1472 * @a __pos is beyond end of string, out_of_range is thrown. If
1473 * the length of result exceeds max_size(), length_error is
1474 * thrown. The value of the string doesn't change if an error
1478 replace(size_type __pos
, size_type __n1
, const _CharT
* __s
,
1482 * @brief Replace characters with value of a C string.
1483 * @param __pos Index of first character to replace.
1484 * @param __n1 Number of characters to be replaced.
1485 * @param __s C string to insert.
1486 * @return Reference to this string.
1487 * @throw std::out_of_range If @a pos > size().
1488 * @throw std::length_error If new length exceeds @c max_size().
1490 * Removes the characters in the range [__pos,__pos + __n1)
1491 * from this string. In place, the characters of @a __s are
1492 * inserted. If @a __pos is beyond end of string, out_of_range
1493 * is thrown. If the length of result exceeds max_size(),
1494 * length_error is thrown. The value of the string doesn't
1495 * change if an error is thrown.
1498 replace(size_type __pos
, size_type __n1
, const _CharT
* __s
)
1500 __glibcxx_requires_string(__s
);
1501 return this->replace(__pos
, __n1
, __s
, traits_type::length(__s
));
1505 * @brief Replace characters with multiple characters.
1506 * @param __pos Index of first character to replace.
1507 * @param __n1 Number of characters to be replaced.
1508 * @param __n2 Number of characters to insert.
1509 * @param __c Character to insert.
1510 * @return Reference to this string.
1511 * @throw std::out_of_range If @a __pos > size().
1512 * @throw std::length_error If new length exceeds @c max_size().
1514 * Removes the characters in the range [pos,pos + n1) from this
1515 * string. In place, @a __n2 copies of @a __c are inserted.
1516 * If @a __pos is beyond end of string, out_of_range is thrown.
1517 * If the length of result exceeds max_size(), length_error is
1518 * thrown. The value of the string doesn't change if an error
1522 replace(size_type __pos
, size_type __n1
, size_type __n2
, _CharT __c
)
1523 { return _M_replace_aux(_M_check(__pos
, "basic_string::replace"),
1524 _M_limit(__pos
, __n1
), __n2
, __c
); }
1527 * @brief Replace range of characters with string.
1528 * @param __i1 Iterator referencing start of range to replace.
1529 * @param __i2 Iterator referencing end of range to replace.
1530 * @param __str String value to insert.
1531 * @return Reference to this string.
1532 * @throw std::length_error If new length exceeds @c max_size().
1534 * Removes the characters in the range [__i1,__i2). In place,
1535 * the value of @a __str is inserted. If the length of result
1536 * exceeds max_size(), length_error is thrown. The value of
1537 * the string doesn't change if an error is thrown.
1540 replace(iterator __i1
, iterator __i2
, const basic_string
& __str
)
1541 { return this->replace(__i1
, __i2
, __str
._M_data(), __str
.size()); }
1544 * @brief Replace range of characters with C substring.
1545 * @param __i1 Iterator referencing start of range to replace.
1546 * @param __i2 Iterator referencing end of range to replace.
1547 * @param __s C string value to insert.
1548 * @param __n Number of characters from s to insert.
1549 * @return Reference to this string.
1550 * @throw std::length_error If new length exceeds @c max_size().
1552 * Removes the characters in the range [__i1,__i2). In place,
1553 * the first @a __n characters of @a __s are inserted. If the
1554 * length of result exceeds max_size(), length_error is thrown.
1555 * The value of the string doesn't change if an error is
1559 replace(iterator __i1
, iterator __i2
, const _CharT
* __s
, size_type __n
)
1561 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1562 && __i2
<= _M_iend());
1563 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
, __s
, __n
);
1567 * @brief Replace range of characters with C string.
1568 * @param __i1 Iterator referencing start of range to replace.
1569 * @param __i2 Iterator referencing end of range to replace.
1570 * @param __s C string value to insert.
1571 * @return Reference to this string.
1572 * @throw std::length_error If new length exceeds @c max_size().
1574 * Removes the characters in the range [__i1,__i2). In place,
1575 * the characters of @a __s are inserted. If the length of
1576 * result exceeds max_size(), length_error is thrown. The
1577 * value of the string doesn't change if an error is thrown.
1580 replace(iterator __i1
, iterator __i2
, const _CharT
* __s
)
1582 __glibcxx_requires_string(__s
);
1583 return this->replace(__i1
, __i2
, __s
, traits_type::length(__s
));
1587 * @brief Replace range of characters with multiple characters
1588 * @param __i1 Iterator referencing start of range to replace.
1589 * @param __i2 Iterator referencing end of range to replace.
1590 * @param __n Number of characters to insert.
1591 * @param __c Character to insert.
1592 * @return Reference to this string.
1593 * @throw std::length_error If new length exceeds @c max_size().
1595 * Removes the characters in the range [__i1,__i2). In place,
1596 * @a __n copies of @a __c are inserted. If the length of
1597 * result exceeds max_size(), length_error is thrown. The
1598 * value of the string doesn't change if an error is thrown.
1601 replace(iterator __i1
, iterator __i2
, size_type __n
, _CharT __c
)
1603 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1604 && __i2
<= _M_iend());
1605 return _M_replace_aux(__i1
- _M_ibegin(), __i2
- __i1
, __n
, __c
);
1609 * @brief Replace range of characters with range.
1610 * @param __i1 Iterator referencing start of range to replace.
1611 * @param __i2 Iterator referencing end of range to replace.
1612 * @param __k1 Iterator referencing start of range to insert.
1613 * @param __k2 Iterator referencing end of range to insert.
1614 * @return Reference to this string.
1615 * @throw std::length_error If new length exceeds @c max_size().
1617 * Removes the characters in the range [__i1,__i2). In place,
1618 * characters in the range [__k1,__k2) are inserted. If the
1619 * length of result exceeds max_size(), length_error is thrown.
1620 * The value of the string doesn't change if an error is
1623 template<class _InputIterator
>
1625 replace(iterator __i1
, iterator __i2
,
1626 _InputIterator __k1
, _InputIterator __k2
)
1628 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1629 && __i2
<= _M_iend());
1630 __glibcxx_requires_valid_range(__k1
, __k2
);
1631 typedef typename
std::__is_integer
<_InputIterator
>::__type _Integral
;
1632 return _M_replace_dispatch(__i1
, __i2
, __k1
, __k2
, _Integral());
1635 // Specializations for the common case of pointer and iterator:
1636 // useful to avoid the overhead of temporary buffering in _M_replace.
1638 replace(iterator __i1
, iterator __i2
, _CharT
* __k1
, _CharT
* __k2
)
1640 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1641 && __i2
<= _M_iend());
1642 __glibcxx_requires_valid_range(__k1
, __k2
);
1643 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1648 replace(iterator __i1
, iterator __i2
,
1649 const _CharT
* __k1
, const _CharT
* __k2
)
1651 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1652 && __i2
<= _M_iend());
1653 __glibcxx_requires_valid_range(__k1
, __k2
);
1654 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1659 replace(iterator __i1
, iterator __i2
, iterator __k1
, iterator __k2
)
1661 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1662 && __i2
<= _M_iend());
1663 __glibcxx_requires_valid_range(__k1
, __k2
);
1664 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1665 __k1
.base(), __k2
- __k1
);
1669 replace(iterator __i1
, iterator __i2
,
1670 const_iterator __k1
, const_iterator __k2
)
1672 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1
&& __i1
<= __i2
1673 && __i2
<= _M_iend());
1674 __glibcxx_requires_valid_range(__k1
, __k2
);
1675 return this->replace(__i1
- _M_ibegin(), __i2
- __i1
,
1676 __k1
.base(), __k2
- __k1
);
1679 #if __cplusplus >= 201103L
1681 * @brief Replace range of characters with initializer_list.
1682 * @param __i1 Iterator referencing start of range to replace.
1683 * @param __i2 Iterator referencing end of range to replace.
1684 * @param __l The initializer_list of characters to insert.
1685 * @return Reference to this string.
1686 * @throw std::length_error If new length exceeds @c max_size().
1688 * Removes the characters in the range [__i1,__i2). In place,
1689 * characters in the range [__k1,__k2) are inserted. If the
1690 * length of result exceeds max_size(), length_error is thrown.
1691 * The value of the string doesn't change if an error is
1694 basic_string
& replace(iterator __i1
, iterator __i2
,
1695 initializer_list
<_CharT
> __l
)
1696 { return this->replace(__i1
, __i2
, __l
.begin(), __l
.end()); }
1700 template<class _Integer
>
1702 _M_replace_dispatch(iterator __i1
, iterator __i2
, _Integer __n
,
1703 _Integer __val
, __true_type
)
1704 { return _M_replace_aux(__i1
- _M_ibegin(), __i2
- __i1
, __n
, __val
); }
1706 template<class _InputIterator
>
1708 _M_replace_dispatch(iterator __i1
, iterator __i2
, _InputIterator __k1
,
1709 _InputIterator __k2
, __false_type
);
1712 _M_replace_aux(size_type __pos1
, size_type __n1
, size_type __n2
,
1716 _M_replace_safe(size_type __pos1
, size_type __n1
, const _CharT
* __s
,
1719 // _S_construct_aux is used to implement the 21.3.1 para 15 which
1720 // requires special behaviour if _InIter is an integral type
1721 template<class _InIterator
>
1723 _S_construct_aux(_InIterator __beg
, _InIterator __end
,
1724 const _Alloc
& __a
, __false_type
)
1726 typedef typename iterator_traits
<_InIterator
>::iterator_category _Tag
;
1727 return _S_construct(__beg
, __end
, __a
, _Tag());
1730 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1731 // 438. Ambiguity in the "do the right thing" clause
1732 template<class _Integer
>
1734 _S_construct_aux(_Integer __beg
, _Integer __end
,
1735 const _Alloc
& __a
, __true_type
)
1736 { return _S_construct_aux_2(static_cast<size_type
>(__beg
),
1740 _S_construct_aux_2(size_type __req
, _CharT __c
, const _Alloc
& __a
)
1741 { return _S_construct(__req
, __c
, __a
); }
1743 template<class _InIterator
>
1745 _S_construct(_InIterator __beg
, _InIterator __end
, const _Alloc
& __a
)
1747 typedef typename
std::__is_integer
<_InIterator
>::__type _Integral
;
1748 return _S_construct_aux(__beg
, __end
, __a
, _Integral());
1751 // For Input Iterators, used in istreambuf_iterators, etc.
1752 template<class _InIterator
>
1754 _S_construct(_InIterator __beg
, _InIterator __end
, const _Alloc
& __a
,
1755 input_iterator_tag
);
1757 // For forward_iterators up to random_access_iterators, used for
1758 // string::iterator, _CharT*, etc.
1759 template<class _FwdIterator
>
1761 _S_construct(_FwdIterator __beg
, _FwdIterator __end
, const _Alloc
& __a
,
1762 forward_iterator_tag
);
1765 _S_construct(size_type __req
, _CharT __c
, const _Alloc
& __a
);
1770 * @brief Copy substring into C string.
1771 * @param __s C string to copy value into.
1772 * @param __n Number of characters to copy.
1773 * @param __pos Index of first character to copy.
1774 * @return Number of characters actually copied
1775 * @throw std::out_of_range If __pos > size().
1777 * Copies up to @a __n characters starting at @a __pos into the
1778 * C string @a __s. If @a __pos is %greater than size(),
1779 * out_of_range is thrown.
1782 copy(_CharT
* __s
, size_type __n
, size_type __pos
= 0) const;
1785 * @brief Swap contents with another string.
1786 * @param __s String to swap with.
1788 * Exchanges the contents of this string with that of @a __s in constant
1792 swap(basic_string
& __s
);
1794 // String operations:
1796 * @brief Return const pointer to null-terminated contents.
1798 * This is a handle to internal data. Do not modify or dire things may
1802 c_str() const _GLIBCXX_NOEXCEPT
1803 { return _M_data(); }
1806 * @brief Return const pointer to contents.
1808 * This is a handle to internal data. Do not modify or dire things may
1812 data() const _GLIBCXX_NOEXCEPT
1813 { return _M_data(); }
1816 * @brief Return copy of allocator used to construct this string.
1819 get_allocator() const _GLIBCXX_NOEXCEPT
1820 { return _M_dataplus
; }
1823 * @brief Find position of a C substring.
1824 * @param __s C string to locate.
1825 * @param __pos Index of character to search from.
1826 * @param __n Number of characters from @a s to search for.
1827 * @return Index of start of first occurrence.
1829 * Starting from @a __pos, searches forward for the first @a
1830 * __n characters in @a __s within this string. If found,
1831 * returns the index where it begins. If not found, returns
1835 find(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
1838 * @brief Find position of a string.
1839 * @param __str String to locate.
1840 * @param __pos Index of character to search from (default 0).
1841 * @return Index of start of first occurrence.
1843 * Starting from @a __pos, searches forward for value of @a __str within
1844 * this string. If found, returns the index where it begins. If not
1845 * found, returns npos.
1848 find(const basic_string
& __str
, size_type __pos
= 0) const
1850 { return this->find(__str
.data(), __pos
, __str
.size()); }
1853 * @brief Find position of a C string.
1854 * @param __s C string to locate.
1855 * @param __pos Index of character to search from (default 0).
1856 * @return Index of start of first occurrence.
1858 * Starting from @a __pos, searches forward for the value of @a
1859 * __s within this string. If found, returns the index where
1860 * it begins. If not found, returns npos.
1863 find(const _CharT
* __s
, size_type __pos
= 0) const
1865 __glibcxx_requires_string(__s
);
1866 return this->find(__s
, __pos
, traits_type::length(__s
));
1870 * @brief Find position of a character.
1871 * @param __c Character to locate.
1872 * @param __pos Index of character to search from (default 0).
1873 * @return Index of first occurrence.
1875 * Starting from @a __pos, searches forward for @a __c within
1876 * this string. If found, returns the index where it was
1877 * found. If not found, returns npos.
1880 find(_CharT __c
, size_type __pos
= 0) const _GLIBCXX_NOEXCEPT
;
1883 * @brief Find last position of a string.
1884 * @param __str String to locate.
1885 * @param __pos Index of character to search back from (default end).
1886 * @return Index of start of last occurrence.
1888 * Starting from @a __pos, searches backward for value of @a
1889 * __str within this string. If found, returns the index where
1890 * it begins. If not found, returns npos.
1893 rfind(const basic_string
& __str
, size_type __pos
= npos
) const
1895 { return this->rfind(__str
.data(), __pos
, __str
.size()); }
1898 * @brief Find last position of a C substring.
1899 * @param __s C string to locate.
1900 * @param __pos Index of character to search back from.
1901 * @param __n Number of characters from s to search for.
1902 * @return Index of start of last occurrence.
1904 * Starting from @a __pos, searches backward for the first @a
1905 * __n characters in @a __s within this string. If found,
1906 * returns the index where it begins. If not found, returns
1910 rfind(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
1913 * @brief Find last position of a C string.
1914 * @param __s C string to locate.
1915 * @param __pos Index of character to start search at (default end).
1916 * @return Index of start of last occurrence.
1918 * Starting from @a __pos, searches backward for the value of
1919 * @a __s within this string. If found, returns the index
1920 * where it begins. If not found, returns npos.
1923 rfind(const _CharT
* __s
, size_type __pos
= npos
) const
1925 __glibcxx_requires_string(__s
);
1926 return this->rfind(__s
, __pos
, traits_type::length(__s
));
1930 * @brief Find last position of a character.
1931 * @param __c Character to locate.
1932 * @param __pos Index of character to search back from (default end).
1933 * @return Index of last occurrence.
1935 * Starting from @a __pos, searches backward for @a __c within
1936 * this string. If found, returns the index where it was
1937 * found. If not found, returns npos.
1940 rfind(_CharT __c
, size_type __pos
= npos
) const _GLIBCXX_NOEXCEPT
;
1943 * @brief Find position of a character of string.
1944 * @param __str String containing characters to locate.
1945 * @param __pos Index of character to search from (default 0).
1946 * @return Index of first occurrence.
1948 * Starting from @a __pos, searches forward for one of the
1949 * characters of @a __str within this string. If found,
1950 * returns the index where it was found. If not found, returns
1954 find_first_of(const basic_string
& __str
, size_type __pos
= 0) const
1956 { return this->find_first_of(__str
.data(), __pos
, __str
.size()); }
1959 * @brief Find position of a character of C substring.
1960 * @param __s String containing characters to locate.
1961 * @param __pos Index of character to search from.
1962 * @param __n Number of characters from s to search for.
1963 * @return Index of first occurrence.
1965 * Starting from @a __pos, searches forward for one of the
1966 * first @a __n characters of @a __s within this string. If
1967 * found, returns the index where it was found. If not found,
1971 find_first_of(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
1974 * @brief Find position of a character of C string.
1975 * @param __s String containing characters to locate.
1976 * @param __pos Index of character to search from (default 0).
1977 * @return Index of first occurrence.
1979 * Starting from @a __pos, searches forward for one of the
1980 * characters of @a __s within this string. If found, returns
1981 * the index where it was found. If not found, returns npos.
1984 find_first_of(const _CharT
* __s
, size_type __pos
= 0) const
1986 __glibcxx_requires_string(__s
);
1987 return this->find_first_of(__s
, __pos
, traits_type::length(__s
));
1991 * @brief Find position of a character.
1992 * @param __c Character to locate.
1993 * @param __pos Index of character to search from (default 0).
1994 * @return Index of first occurrence.
1996 * Starting from @a __pos, searches forward for the character
1997 * @a __c within this string. If found, returns the index
1998 * where it was found. If not found, returns npos.
2000 * Note: equivalent to find(__c, __pos).
2003 find_first_of(_CharT __c
, size_type __pos
= 0) const _GLIBCXX_NOEXCEPT
2004 { return this->find(__c
, __pos
); }
2007 * @brief Find last position of a character of string.
2008 * @param __str String containing characters 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 one of the
2013 * characters of @a __str within this string. If found,
2014 * returns the index where it was found. If not found, returns
2018 find_last_of(const basic_string
& __str
, size_type __pos
= npos
) const
2020 { return this->find_last_of(__str
.data(), __pos
, __str
.size()); }
2023 * @brief Find last position of a character of C substring.
2024 * @param __s C string containing characters to locate.
2025 * @param __pos Index of character to search back from.
2026 * @param __n Number of characters from s to search for.
2027 * @return Index of last occurrence.
2029 * Starting from @a __pos, searches backward for one of the
2030 * first @a __n characters of @a __s within this string. If
2031 * found, returns the index where it was found. If not found,
2035 find_last_of(const _CharT
* __s
, size_type __pos
, size_type __n
) const;
2038 * @brief Find last position of a character of C string.
2039 * @param __s C string containing characters to locate.
2040 * @param __pos Index of character to search back from (default end).
2041 * @return Index of last occurrence.
2043 * Starting from @a __pos, searches backward for one of the
2044 * characters of @a __s within this string. If found, returns
2045 * the index where it was found. If not found, returns npos.
2048 find_last_of(const _CharT
* __s
, size_type __pos
= npos
) const
2050 __glibcxx_requires_string(__s
);
2051 return this->find_last_of(__s
, __pos
, traits_type::length(__s
));
2055 * @brief Find last position of a character.
2056 * @param __c Character to locate.
2057 * @param __pos Index of character to search back from (default end).
2058 * @return Index of last occurrence.
2060 * Starting from @a __pos, searches backward for @a __c within
2061 * this string. If found, returns the index where it was
2062 * found. If not found, returns npos.
2064 * Note: equivalent to rfind(__c, __pos).
2067 find_last_of(_CharT __c
, size_type __pos
= npos
) const _GLIBCXX_NOEXCEPT
2068 { return this->rfind(__c
, __pos
); }
2071 * @brief Find position of a character not in string.
2072 * @param __str String containing characters to avoid.
2073 * @param __pos Index of character to search from (default 0).
2074 * @return Index of first occurrence.
2076 * Starting from @a __pos, searches forward for a character not contained
2077 * in @a __str within this string. If found, returns the index where it
2078 * was found. If not found, returns npos.
2081 find_first_not_of(const basic_string
& __str
, size_type __pos
= 0) const
2083 { return this->find_first_not_of(__str
.data(), __pos
, __str
.size()); }
2086 * @brief Find position of a character not in C substring.
2087 * @param __s C string containing characters to avoid.
2088 * @param __pos Index of character to search from.
2089 * @param __n Number of characters from __s to consider.
2090 * @return Index of first occurrence.
2092 * Starting from @a __pos, searches forward for a character not
2093 * contained in the first @a __n characters of @a __s within
2094 * this string. If found, returns the index where it was
2095 * found. If not found, returns npos.
2098 find_first_not_of(const _CharT
* __s
, size_type __pos
,
2099 size_type __n
) const;
2102 * @brief Find position of a character not in C string.
2103 * @param __s C string containing characters to avoid.
2104 * @param __pos Index of character to search from (default 0).
2105 * @return Index of first occurrence.
2107 * Starting from @a __pos, searches forward for a character not
2108 * contained in @a __s within this string. If found, returns
2109 * the index where it was found. If not found, returns npos.
2112 find_first_not_of(const _CharT
* __s
, size_type __pos
= 0) const
2114 __glibcxx_requires_string(__s
);
2115 return this->find_first_not_of(__s
, __pos
, traits_type::length(__s
));
2119 * @brief Find position of a different character.
2120 * @param __c Character to avoid.
2121 * @param __pos Index of character to search from (default 0).
2122 * @return Index of first occurrence.
2124 * Starting from @a __pos, searches forward for a character
2125 * other than @a __c within this string. If found, returns the
2126 * index where it was found. If not found, returns npos.
2129 find_first_not_of(_CharT __c
, size_type __pos
= 0) const
2133 * @brief Find last position of a character not in string.
2134 * @param __str String containing characters to avoid.
2135 * @param __pos Index of character to search back from (default end).
2136 * @return Index of last occurrence.
2138 * Starting from @a __pos, searches backward for a character
2139 * not contained in @a __str within this string. If found,
2140 * returns the index where it was found. If not found, returns
2144 find_last_not_of(const basic_string
& __str
, size_type __pos
= npos
) const
2146 { return this->find_last_not_of(__str
.data(), __pos
, __str
.size()); }
2149 * @brief Find last position of a character not in C substring.
2150 * @param __s C string containing characters to avoid.
2151 * @param __pos Index of character to search back from.
2152 * @param __n Number of characters from s to consider.
2153 * @return Index of last occurrence.
2155 * Starting from @a __pos, searches backward for a character not
2156 * contained in the first @a __n characters of @a __s within this string.
2157 * If found, returns the index where it was found. If not found,
2161 find_last_not_of(const _CharT
* __s
, size_type __pos
,
2162 size_type __n
) const;
2164 * @brief Find last position of a character not in C string.
2165 * @param __s C string containing characters to avoid.
2166 * @param __pos Index of character to search back from (default end).
2167 * @return Index of last occurrence.
2169 * Starting from @a __pos, searches backward for a character
2170 * not contained in @a __s within this string. If found,
2171 * returns the index where it was found. If not found, returns
2175 find_last_not_of(const _CharT
* __s
, size_type __pos
= npos
) const
2177 __glibcxx_requires_string(__s
);
2178 return this->find_last_not_of(__s
, __pos
, traits_type::length(__s
));
2182 * @brief Find last position of a different character.
2183 * @param __c Character to avoid.
2184 * @param __pos Index of character to search back from (default end).
2185 * @return Index of last occurrence.
2187 * Starting from @a __pos, searches backward for a character other than
2188 * @a __c within this string. If found, returns the index where it was
2189 * found. If not found, returns npos.
2192 find_last_not_of(_CharT __c
, size_type __pos
= npos
) const
2196 * @brief Get a substring.
2197 * @param __pos Index of first character (default 0).
2198 * @param __n Number of characters in substring (default remainder).
2199 * @return The new string.
2200 * @throw std::out_of_range If __pos > size().
2202 * Construct and return a new string using the @a __n
2203 * characters starting at @a __pos. If the string is too
2204 * short, use the remainder of the characters. If @a __pos is
2205 * beyond the end of the string, out_of_range is thrown.
2208 substr(size_type __pos
= 0, size_type __n
= npos
) const
2209 { return basic_string(*this,
2210 _M_check(__pos
, "basic_string::substr"), __n
); }
2213 * @brief Compare to a string.
2214 * @param __str String to compare against.
2215 * @return Integer < 0, 0, or > 0.
2217 * Returns an integer < 0 if this string is ordered before @a
2218 * __str, 0 if their values are equivalent, or > 0 if this
2219 * string is ordered after @a __str. Determines the effective
2220 * length rlen of the strings to compare as the smallest of
2221 * size() and str.size(). The function then compares the two
2222 * strings by calling traits::compare(data(), str.data(),rlen).
2223 * If the result of the comparison is nonzero returns it,
2224 * otherwise the shorter one is ordered first.
2227 compare(const basic_string
& __str
) const
2229 const size_type __size
= this->size();
2230 const size_type __osize
= __str
.size();
2231 const size_type __len
= std::min(__size
, __osize
);
2233 int __r
= traits_type::compare(_M_data(), __str
.data(), __len
);
2235 __r
= _S_compare(__size
, __osize
);
2240 * @brief Compare substring to a string.
2241 * @param __pos Index of first character of substring.
2242 * @param __n Number of characters in substring.
2243 * @param __str String to compare against.
2244 * @return Integer < 0, 0, or > 0.
2246 * Form the substring of this string from the @a __n characters
2247 * starting at @a __pos. Returns an integer < 0 if the
2248 * substring is ordered before @a __str, 0 if their values are
2249 * equivalent, or > 0 if the substring is ordered after @a
2250 * __str. Determines the effective length rlen of the strings
2251 * to compare as the smallest of the length of the substring
2252 * and @a __str.size(). The function then compares the two
2253 * strings by calling
2254 * traits::compare(substring.data(),str.data(),rlen). If the
2255 * result of the comparison is nonzero returns it, otherwise
2256 * the shorter one is ordered first.
2259 compare(size_type __pos
, size_type __n
, const basic_string
& __str
) const;
2262 * @brief Compare substring to a substring.
2263 * @param __pos1 Index of first character of substring.
2264 * @param __n1 Number of characters in substring.
2265 * @param __str String to compare against.
2266 * @param __pos2 Index of first character of substring of str.
2267 * @param __n2 Number of characters in substring of str.
2268 * @return Integer < 0, 0, or > 0.
2270 * Form the substring of this string from the @a __n1
2271 * characters starting at @a __pos1. Form the substring of @a
2272 * __str from the @a __n2 characters starting at @a __pos2.
2273 * Returns an integer < 0 if this substring is ordered before
2274 * the substring of @a __str, 0 if their values are equivalent,
2275 * or > 0 if this substring is ordered after the substring of
2276 * @a __str. Determines the effective length rlen of the
2277 * strings to compare as the smallest of the lengths of the
2278 * substrings. The function then compares the two strings by
2280 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
2281 * If the result of the comparison is nonzero returns it,
2282 * otherwise the shorter one is ordered first.
2285 compare(size_type __pos1
, size_type __n1
, const basic_string
& __str
,
2286 size_type __pos2
, size_type __n2
) const;
2289 * @brief Compare to a C string.
2290 * @param __s C string to compare against.
2291 * @return Integer < 0, 0, or > 0.
2293 * Returns an integer < 0 if this string is ordered before @a __s, 0 if
2294 * their values are equivalent, or > 0 if this string is ordered after
2295 * @a __s. Determines the effective length rlen of the strings to
2296 * compare as the smallest of size() and the length of a string
2297 * constructed from @a __s. The function then compares the two strings
2298 * by calling traits::compare(data(),s,rlen). If the result of the
2299 * comparison is nonzero returns it, otherwise the shorter one is
2303 compare(const _CharT
* __s
) const;
2305 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2306 // 5 String::compare specification questionable
2308 * @brief Compare substring to a C string.
2309 * @param __pos Index of first character of substring.
2310 * @param __n1 Number of characters in substring.
2311 * @param __s C string to compare against.
2312 * @return Integer < 0, 0, or > 0.
2314 * Form the substring of this string from the @a __n1
2315 * characters starting at @a pos. Returns an integer < 0 if
2316 * the substring is ordered before @a __s, 0 if their values
2317 * are equivalent, or > 0 if the substring is ordered after @a
2318 * __s. Determines the effective length rlen of the strings to
2319 * compare as the smallest of the length of the substring and
2320 * the length of a string constructed from @a __s. The
2321 * function then compares the two string by calling
2322 * traits::compare(substring.data(),__s,rlen). If the result of
2323 * the comparison is nonzero returns it, otherwise the shorter
2324 * one is ordered first.
2327 compare(size_type __pos
, size_type __n1
, const _CharT
* __s
) const;
2330 * @brief Compare substring against a character %array.
2331 * @param __pos Index of first character of substring.
2332 * @param __n1 Number of characters in substring.
2333 * @param __s character %array to compare against.
2334 * @param __n2 Number of characters of s.
2335 * @return Integer < 0, 0, or > 0.
2337 * Form the substring of this string from the @a __n1
2338 * characters starting at @a __pos. Form a string from the
2339 * first @a __n2 characters of @a __s. Returns an integer < 0
2340 * if this substring is ordered before the string from @a __s,
2341 * 0 if their values are equivalent, or > 0 if this substring
2342 * is ordered after the string from @a __s. Determines the
2343 * effective length rlen of the strings to compare as the
2344 * smallest of the length of the substring and @a __n2. The
2345 * function then compares the two strings by calling
2346 * traits::compare(substring.data(),s,rlen). If the result of
2347 * the comparison is nonzero returns it, otherwise the shorter
2348 * one is ordered first.
2350 * NB: s must have at least n2 characters, '\\0' has
2351 * no special meaning.
2354 compare(size_type __pos
, size_type __n1
, const _CharT
* __s
,
2355 size_type __n2
) const;
2360 * @brief Concatenate two strings.
2361 * @param __lhs First string.
2362 * @param __rhs Last string.
2363 * @return New string with value of @a __lhs followed by @a __rhs.
2365 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2366 basic_string
<_CharT
, _Traits
, _Alloc
>
2367 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2368 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2370 basic_string
<_CharT
, _Traits
, _Alloc
> __str(__lhs
);
2371 __str
.append(__rhs
);
2376 * @brief Concatenate C string and string.
2377 * @param __lhs First string.
2378 * @param __rhs Last string.
2379 * @return New string with value of @a __lhs followed by @a __rhs.
2381 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2382 basic_string
<_CharT
,_Traits
,_Alloc
>
2383 operator+(const _CharT
* __lhs
,
2384 const basic_string
<_CharT
,_Traits
,_Alloc
>& __rhs
);
2387 * @brief Concatenate character and string.
2388 * @param __lhs First string.
2389 * @param __rhs Last string.
2390 * @return New string with @a __lhs followed by @a __rhs.
2392 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2393 basic_string
<_CharT
,_Traits
,_Alloc
>
2394 operator+(_CharT __lhs
, const basic_string
<_CharT
,_Traits
,_Alloc
>& __rhs
);
2397 * @brief Concatenate string and C string.
2398 * @param __lhs First string.
2399 * @param __rhs Last string.
2400 * @return New string with @a __lhs followed by @a __rhs.
2402 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2403 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2404 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2405 const _CharT
* __rhs
)
2407 basic_string
<_CharT
, _Traits
, _Alloc
> __str(__lhs
);
2408 __str
.append(__rhs
);
2413 * @brief Concatenate string and character.
2414 * @param __lhs First string.
2415 * @param __rhs Last string.
2416 * @return New string with @a __lhs followed by @a __rhs.
2418 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2419 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2420 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
, _CharT __rhs
)
2422 typedef basic_string
<_CharT
, _Traits
, _Alloc
> __string_type
;
2423 typedef typename
__string_type::size_type __size_type
;
2424 __string_type
__str(__lhs
);
2425 __str
.append(__size_type(1), __rhs
);
2429 #if __cplusplus >= 201103L
2430 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2431 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2432 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
2433 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2434 { return std::move(__lhs
.append(__rhs
)); }
2436 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2437 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2438 operator+(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2439 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
2440 { return std::move(__rhs
.insert(0, __lhs
)); }
2442 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2443 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2444 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
2445 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
2447 const auto __size
= __lhs
.size() + __rhs
.size();
2448 const bool __cond
= (__size
> __lhs
.capacity()
2449 && __size
<= __rhs
.capacity());
2450 return __cond
? std::move(__rhs
.insert(0, __lhs
))
2451 : std::move(__lhs
.append(__rhs
));
2454 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2455 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2456 operator+(const _CharT
* __lhs
,
2457 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
2458 { return std::move(__rhs
.insert(0, __lhs
)); }
2460 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2461 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2462 operator+(_CharT __lhs
,
2463 basic_string
<_CharT
, _Traits
, _Alloc
>&& __rhs
)
2464 { return std::move(__rhs
.insert(0, 1, __lhs
)); }
2466 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2467 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2468 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
2469 const _CharT
* __rhs
)
2470 { return std::move(__lhs
.append(__rhs
)); }
2472 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2473 inline basic_string
<_CharT
, _Traits
, _Alloc
>
2474 operator+(basic_string
<_CharT
, _Traits
, _Alloc
>&& __lhs
,
2476 { return std::move(__lhs
.append(1, __rhs
)); }
2481 * @brief Test equivalence of two strings.
2482 * @param __lhs First string.
2483 * @param __rhs Second string.
2484 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2486 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2488 operator==(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2489 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2490 { return __lhs
.compare(__rhs
) == 0; }
2492 template<typename _CharT
>
2494 typename
__gnu_cxx::__enable_if
<__is_char
<_CharT
>::__value
, bool>::__type
2495 operator==(const basic_string
<_CharT
>& __lhs
,
2496 const basic_string
<_CharT
>& __rhs
)
2497 { return (__lhs
.size() == __rhs
.size()
2498 && !std::char_traits
<_CharT
>::compare(__lhs
.data(), __rhs
.data(),
2502 * @brief Test equivalence of C string and string.
2503 * @param __lhs C string.
2504 * @param __rhs String.
2505 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
2507 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2509 operator==(const _CharT
* __lhs
,
2510 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2511 { return __rhs
.compare(__lhs
) == 0; }
2514 * @brief Test equivalence of string and C string.
2515 * @param __lhs String.
2516 * @param __rhs C string.
2517 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2519 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2521 operator==(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2522 const _CharT
* __rhs
)
2523 { return __lhs
.compare(__rhs
) == 0; }
2527 * @brief Test difference of two strings.
2528 * @param __lhs First string.
2529 * @param __rhs Second string.
2530 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2532 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2534 operator!=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2535 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2536 { return !(__lhs
== __rhs
); }
2539 * @brief Test difference of C string and string.
2540 * @param __lhs C string.
2541 * @param __rhs String.
2542 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
2544 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2546 operator!=(const _CharT
* __lhs
,
2547 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2548 { return !(__lhs
== __rhs
); }
2551 * @brief Test difference of string and C string.
2552 * @param __lhs String.
2553 * @param __rhs C string.
2554 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2556 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2558 operator!=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2559 const _CharT
* __rhs
)
2560 { return !(__lhs
== __rhs
); }
2564 * @brief Test if string precedes string.
2565 * @param __lhs First string.
2566 * @param __rhs Second string.
2567 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2569 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2571 operator<(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2572 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2573 { return __lhs
.compare(__rhs
) < 0; }
2576 * @brief Test if string precedes C string.
2577 * @param __lhs String.
2578 * @param __rhs C string.
2579 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2581 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2583 operator<(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2584 const _CharT
* __rhs
)
2585 { return __lhs
.compare(__rhs
) < 0; }
2588 * @brief Test if C string precedes string.
2589 * @param __lhs C string.
2590 * @param __rhs String.
2591 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2593 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2595 operator<(const _CharT
* __lhs
,
2596 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2597 { return __rhs
.compare(__lhs
) > 0; }
2601 * @brief Test if string follows string.
2602 * @param __lhs First string.
2603 * @param __rhs Second string.
2604 * @return True if @a __lhs follows @a __rhs. False otherwise.
2606 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2608 operator>(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2609 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2610 { return __lhs
.compare(__rhs
) > 0; }
2613 * @brief Test if string follows C string.
2614 * @param __lhs String.
2615 * @param __rhs C string.
2616 * @return True if @a __lhs follows @a __rhs. False otherwise.
2618 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2620 operator>(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2621 const _CharT
* __rhs
)
2622 { return __lhs
.compare(__rhs
) > 0; }
2625 * @brief Test if C string follows string.
2626 * @param __lhs C string.
2627 * @param __rhs String.
2628 * @return True if @a __lhs follows @a __rhs. False otherwise.
2630 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2632 operator>(const _CharT
* __lhs
,
2633 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2634 { return __rhs
.compare(__lhs
) < 0; }
2638 * @brief Test if string doesn't follow string.
2639 * @param __lhs First string.
2640 * @param __rhs Second string.
2641 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2643 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2645 operator<=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2646 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2647 { return __lhs
.compare(__rhs
) <= 0; }
2650 * @brief Test if string doesn't follow C string.
2651 * @param __lhs String.
2652 * @param __rhs C string.
2653 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2655 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2657 operator<=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2658 const _CharT
* __rhs
)
2659 { return __lhs
.compare(__rhs
) <= 0; }
2662 * @brief Test if C string doesn't follow string.
2663 * @param __lhs C string.
2664 * @param __rhs String.
2665 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2667 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2669 operator<=(const _CharT
* __lhs
,
2670 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2671 { return __rhs
.compare(__lhs
) >= 0; }
2675 * @brief Test if string doesn't precede string.
2676 * @param __lhs First string.
2677 * @param __rhs Second string.
2678 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2680 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2682 operator>=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2683 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2684 { return __lhs
.compare(__rhs
) >= 0; }
2687 * @brief Test if string doesn't precede C string.
2688 * @param __lhs String.
2689 * @param __rhs C string.
2690 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2692 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2694 operator>=(const basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2695 const _CharT
* __rhs
)
2696 { return __lhs
.compare(__rhs
) >= 0; }
2699 * @brief Test if C string doesn't precede string.
2700 * @param __lhs C string.
2701 * @param __rhs String.
2702 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2704 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2706 operator>=(const _CharT
* __lhs
,
2707 const basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2708 { return __rhs
.compare(__lhs
) <= 0; }
2711 * @brief Swap contents of two strings.
2712 * @param __lhs First string.
2713 * @param __rhs Second string.
2715 * Exchanges the contents of @a __lhs and @a __rhs in constant time.
2717 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2719 swap(basic_string
<_CharT
, _Traits
, _Alloc
>& __lhs
,
2720 basic_string
<_CharT
, _Traits
, _Alloc
>& __rhs
)
2721 { __lhs
.swap(__rhs
); }
2724 * @brief Read stream into a string.
2725 * @param __is Input stream.
2726 * @param __str Buffer to store into.
2727 * @return Reference to the input stream.
2729 * Stores characters from @a __is into @a __str until whitespace is
2730 * found, the end of the stream is encountered, or str.max_size()
2731 * is reached. If is.width() is non-zero, that is the limit on the
2732 * number of characters stored into @a __str. Any previous
2733 * contents of @a __str are erased.
2735 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2736 basic_istream
<_CharT
, _Traits
>&
2737 operator>>(basic_istream
<_CharT
, _Traits
>& __is
,
2738 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
);
2741 basic_istream
<char>&
2742 operator>>(basic_istream
<char>& __is
, basic_string
<char>& __str
);
2745 * @brief Write string to a stream.
2746 * @param __os Output stream.
2747 * @param __str String to write out.
2748 * @return Reference to the output stream.
2750 * Output characters of @a __str into os following the same rules as for
2751 * writing a C string.
2753 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2754 inline basic_ostream
<_CharT
, _Traits
>&
2755 operator<<(basic_ostream
<_CharT
, _Traits
>& __os
,
2756 const basic_string
<_CharT
, _Traits
, _Alloc
>& __str
)
2758 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2759 // 586. string inserter not a formatted function
2760 return __ostream_insert(__os
, __str
.data(), __str
.size());
2764 * @brief Read a line from stream into a string.
2765 * @param __is Input stream.
2766 * @param __str Buffer to store into.
2767 * @param __delim Character marking end of line.
2768 * @return Reference to the input stream.
2770 * Stores characters from @a __is into @a __str until @a __delim is
2771 * found, the end of the stream is encountered, or str.max_size()
2772 * is reached. If is.width() is non-zero, that is the limit on the
2773 * number of characters stored into @a __str. Any previous
2774 * contents of @a __str are erased. If @a __delim was encountered,
2775 * it is extracted but not stored into @a __str.
2777 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2778 basic_istream
<_CharT
, _Traits
>&
2779 getline(basic_istream
<_CharT
, _Traits
>& __is
,
2780 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
, _CharT __delim
);
2783 * @brief Read a line from stream into a string.
2784 * @param __is Input stream.
2785 * @param __str Buffer to store into.
2786 * @return Reference to the input stream.
2788 * Stores characters from is into @a __str until '\n' is
2789 * found, the end of the stream is encountered, or str.max_size()
2790 * is reached. If __is.width() is non-zero, that is the limit on
2791 * the number of characters stored into @a __str. Any previous
2792 * contents of @a __str are erased. If end of line was
2793 * encountered, it is extracted but not stored into @a __str.
2795 template<typename _CharT
, typename _Traits
, typename _Alloc
>
2796 inline basic_istream
<_CharT
, _Traits
>&
2797 getline(basic_istream
<_CharT
, _Traits
>& __is
,
2798 basic_string
<_CharT
, _Traits
, _Alloc
>& __str
)
2799 { return getline(__is
, __str
, __is
.widen('\n')); }
2802 basic_istream
<char>&
2803 getline(basic_istream
<char>& __in
, basic_string
<char>& __str
,
2806 #ifdef _GLIBCXX_USE_WCHAR_T
2808 basic_istream
<wchar_t>&
2809 getline(basic_istream
<wchar_t>& __in
, basic_string
<wchar_t>& __str
,
2813 _GLIBCXX_END_NAMESPACE_VERSION
2816 #if ((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \
2817 && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
2819 #include <ext/string_conversions.h>
2821 namespace std
_GLIBCXX_VISIBILITY(default)
2823 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2825 // 21.4 Numeric Conversions [string.conversions].
2827 stoi(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
2828 { return __gnu_cxx::__stoa
<long, int>(&std::strtol
, "stoi", __str
.c_str(),
2832 stol(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
2833 { return __gnu_cxx::__stoa(&std::strtol
, "stol", __str
.c_str(),
2836 inline unsigned long
2837 stoul(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
2838 { return __gnu_cxx::__stoa(&std::strtoul
, "stoul", __str
.c_str(),
2842 stoll(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
2843 { return __gnu_cxx::__stoa(&std::strtoll
, "stoll", __str
.c_str(),
2846 inline unsigned long long
2847 stoull(const string
& __str
, size_t* __idx
= 0, int __base
= 10)
2848 { return __gnu_cxx::__stoa(&std::strtoull
, "stoull", __str
.c_str(),
2851 // NB: strtof vs strtod.
2853 stof(const string
& __str
, size_t* __idx
= 0)
2854 { return __gnu_cxx::__stoa(&std::strtof
, "stof", __str
.c_str(), __idx
); }
2857 stod(const string
& __str
, size_t* __idx
= 0)
2858 { return __gnu_cxx::__stoa(&std::strtod
, "stod", __str
.c_str(), __idx
); }
2861 stold(const string
& __str
, size_t* __idx
= 0)
2862 { return __gnu_cxx::__stoa(&std::strtold
, "stold", __str
.c_str(), __idx
); }
2864 // NB: (v)snprintf vs sprintf.
2868 to_string(int __val
)
2869 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, 4 * sizeof(int),
2873 to_string(unsigned __val
)
2874 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
2875 4 * sizeof(unsigned),
2879 to_string(long __val
)
2880 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, 4 * sizeof(long),
2884 to_string(unsigned long __val
)
2885 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
2886 4 * sizeof(unsigned long),
2890 to_string(long long __val
)
2891 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
2892 4 * sizeof(long long),
2896 to_string(unsigned long long __val
)
2897 { return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
,
2898 4 * sizeof(unsigned long long),
2902 to_string(float __val
)
2905 __gnu_cxx::__numeric_traits
<float>::__max_exponent10
+ 20;
2906 return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, __n
,
2911 to_string(double __val
)
2914 __gnu_cxx::__numeric_traits
<double>::__max_exponent10
+ 20;
2915 return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, __n
,
2920 to_string(long double __val
)
2923 __gnu_cxx::__numeric_traits
<long double>::__max_exponent10
+ 20;
2924 return __gnu_cxx::__to_xstring
<string
>(&std::vsnprintf
, __n
,
2928 #ifdef _GLIBCXX_USE_WCHAR_T
2930 stoi(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
2931 { return __gnu_cxx::__stoa
<long, int>(&std::wcstol
, "stoi", __str
.c_str(),
2935 stol(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
2936 { return __gnu_cxx::__stoa(&std::wcstol
, "stol", __str
.c_str(),
2939 inline unsigned long
2940 stoul(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
2941 { return __gnu_cxx::__stoa(&std::wcstoul
, "stoul", __str
.c_str(),
2945 stoll(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
2946 { return __gnu_cxx::__stoa(&std::wcstoll
, "stoll", __str
.c_str(),
2949 inline unsigned long long
2950 stoull(const wstring
& __str
, size_t* __idx
= 0, int __base
= 10)
2951 { return __gnu_cxx::__stoa(&std::wcstoull
, "stoull", __str
.c_str(),
2954 // NB: wcstof vs wcstod.
2956 stof(const wstring
& __str
, size_t* __idx
= 0)
2957 { return __gnu_cxx::__stoa(&std::wcstof
, "stof", __str
.c_str(), __idx
); }
2960 stod(const wstring
& __str
, size_t* __idx
= 0)
2961 { return __gnu_cxx::__stoa(&std::wcstod
, "stod", __str
.c_str(), __idx
); }
2964 stold(const wstring
& __str
, size_t* __idx
= 0)
2965 { return __gnu_cxx::__stoa(&std::wcstold
, "stold", __str
.c_str(), __idx
); }
2969 to_wstring(int __val
)
2970 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, 4 * sizeof(int),
2974 to_wstring(unsigned __val
)
2975 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
2976 4 * sizeof(unsigned),
2980 to_wstring(long __val
)
2981 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, 4 * sizeof(long),
2985 to_wstring(unsigned long __val
)
2986 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
2987 4 * sizeof(unsigned long),
2991 to_wstring(long long __val
)
2992 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
2993 4 * sizeof(long long),
2997 to_wstring(unsigned long long __val
)
2998 { return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
,
2999 4 * sizeof(unsigned long long),
3003 to_wstring(float __val
)
3006 __gnu_cxx::__numeric_traits
<float>::__max_exponent10
+ 20;
3007 return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, __n
,
3012 to_wstring(double __val
)
3015 __gnu_cxx::__numeric_traits
<double>::__max_exponent10
+ 20;
3016 return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, __n
,
3021 to_wstring(long double __val
)
3024 __gnu_cxx::__numeric_traits
<long double>::__max_exponent10
+ 20;
3025 return __gnu_cxx::__to_xstring
<wstring
>(&std::vswprintf
, __n
,
3030 _GLIBCXX_END_NAMESPACE_VERSION
3033 #endif /* C++11 && _GLIBCXX_USE_C99 ... */
3035 #if __cplusplus >= 201103L
3037 #include <bits/functional_hash.h>
3039 namespace std
_GLIBCXX_VISIBILITY(default)
3041 _GLIBCXX_BEGIN_NAMESPACE_VERSION
3045 #ifndef _GLIBCXX_COMPATIBILITY_CXX0X
3046 /// std::hash specialization for string.
3049 : public __hash_base
<size_t, string
>
3052 operator()(const string
& __s
) const noexcept
3053 { return std::_Hash_impl::hash(__s
.data(), __s
.length()); }
3056 #ifdef _GLIBCXX_USE_WCHAR_T
3057 /// std::hash specialization for wstring.
3059 struct hash
<wstring
>
3060 : public __hash_base
<size_t, wstring
>
3063 operator()(const wstring
& __s
) const noexcept
3064 { return std::_Hash_impl::hash(__s
.data(),
3065 __s
.length() * sizeof(wchar_t)); }
3068 #endif /* _GLIBCXX_COMPATIBILITY_CXX0X */
3070 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
3071 /// std::hash specialization for u16string.
3073 struct hash
<u16string
>
3074 : public __hash_base
<size_t, u16string
>
3077 operator()(const u16string
& __s
) const noexcept
3078 { return std::_Hash_impl::hash(__s
.data(),
3079 __s
.length() * sizeof(char16_t
)); }
3082 /// std::hash specialization for u32string.
3084 struct hash
<u32string
>
3085 : public __hash_base
<size_t, u32string
>
3088 operator()(const u32string
& __s
) const noexcept
3089 { return std::_Hash_impl::hash(__s
.data(),
3090 __s
.length() * sizeof(char32_t
)); }
3094 _GLIBCXX_END_NAMESPACE_VERSION
3099 #endif /* _BASIC_STRING_H */