1 // Debugging string implementation -*- C++ -*-
3 // Copyright (C) 2003-2022 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file debug/string
26 * This file is a GNU debug extension to the Standard C++ Library.
29 #ifndef _GLIBCXX_DEBUG_STRING
30 #define _GLIBCXX_DEBUG_STRING 1
32 #pragma GCC system_header
35 #include <debug/safe_sequence.h>
36 #include <debug/safe_container.h>
37 #include <debug/safe_iterator.h>
39 #define _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(_Cond,_File,_Line,_Func) \
41 __gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func) \
42 ._M_message(#_Cond)._M_error()
44 #if _GLIBCXX_USE_CXX11_ABI && __cplusplus >= 201103
45 # define _GLIBCXX_INSERT_RETURNS_ITERATOR 1
46 # define _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(expr) expr
48 # define _GLIBCXX_INSERT_RETURNS_ITERATOR 0
49 # define _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(expr)
54 /** Checks that __s is non-NULL or __n == 0, and then returns __s. */
55 template<typename _CharT, typename _Integer>
57 __check_string(const _CharT* __s,
58 _Integer __n __attribute__((__unused__)),
59 const char* __file __attribute__((__unused__)),
60 unsigned int __line __attribute__((__unused__)),
61 const char* __function __attribute__((__unused__)))
63 #ifdef _GLIBCXX_DEBUG_PEDANTIC
64 _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(__s != 0 || __n == 0,
65 __file, __line, __function);
70 /** Checks that __s is non-NULL and then returns __s. */
71 template<typename _CharT>
73 __check_string(const _CharT* __s,
74 const char* __file __attribute__((__unused__)),
75 unsigned int __line __attribute__((__unused__)),
76 const char* __function __attribute__((__unused__)))
78 #ifdef _GLIBCXX_DEBUG_PEDANTIC
79 _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(__s != 0,
80 __file, __line, __function);
85 #define __glibcxx_check_string_n_constructor(_Str, _Size) \
86 __check_string(_Str, _Size, __FILE__, __LINE__, __PRETTY_FUNCTION__)
88 #define __glibcxx_check_string_constructor(_Str) \
89 __check_string(_Str, __FILE__, __LINE__, __PRETTY_FUNCTION__)
91 /// Class std::basic_string with safety/checking/debug instrumentation.
92 template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
93 typename _Allocator = std::allocator<_CharT> >
95 : public __gnu_debug::_Safe_container<
96 basic_string<_CharT, _Traits, _Allocator>,
97 _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>,
98 public std::basic_string<_CharT, _Traits, _Allocator>
100 typedef std::basic_string<_CharT, _Traits, _Allocator> _Base;
101 typedef __gnu_debug::_Safe_container<
102 basic_string, _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>
105 template<typename _ItT, typename _SeqT, typename _CatT>
106 friend class ::__gnu_debug::_Safe_iterator;
108 // type used for positions in insert, erase etc.
109 typedef __gnu_debug::_Safe_iterator<
110 typename _Base::__const_iterator, basic_string> __const_iterator;
114 typedef _Traits traits_type;
115 typedef typename _Traits::char_type value_type;
116 typedef _Allocator allocator_type;
117 typedef typename _Base::size_type size_type;
118 typedef typename _Base::difference_type difference_type;
119 typedef typename _Base::reference reference;
120 typedef typename _Base::const_reference const_reference;
121 typedef typename _Base::pointer pointer;
122 typedef typename _Base::const_pointer const_pointer;
124 typedef __gnu_debug::_Safe_iterator<
125 typename _Base::iterator, basic_string> iterator;
126 typedef __gnu_debug::_Safe_iterator<
127 typename _Base::const_iterator, basic_string> const_iterator;
129 typedef std::reverse_iterator<iterator> reverse_iterator;
130 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
134 // 21.3.1 construct/copy/destroy:
137 basic_string(const _Allocator& __a) _GLIBCXX_NOEXCEPT
140 #if __cplusplus < 201103L
141 basic_string() : _Base() { }
143 basic_string(const basic_string& __str)
148 basic_string() = default;
149 basic_string(const basic_string&) = default;
150 basic_string(basic_string&&) = default;
152 basic_string(std::initializer_list<_CharT> __l,
153 const _Allocator& __a = _Allocator())
157 basic_string(const basic_string& __s, const _Allocator& __a)
158 : _Base(__s, __a) { }
160 basic_string(basic_string&& __s, const _Allocator& __a)
162 std::is_nothrow_constructible<_Base, _Base, const _Allocator&>::value )
163 : _Safe(std::move(__s), __a),
164 _Base(std::move(__s), __a)
167 ~basic_string() = default;
169 // Provides conversion from a normal-mode string to a debug-mode string
170 basic_string(_Base&& __base) noexcept
171 : _Base(std::move(__base)) { }
174 // Provides conversion from a normal-mode string to a debug-mode string
175 basic_string(const _Base& __base)
178 // _GLIBCXX_RESOLVE_LIB_DEFECTS
179 // 42. string ctors specify wrong default allocator
180 basic_string(const basic_string& __str, size_type __pos,
181 size_type __n = _Base::npos,
182 const _Allocator& __a = _Allocator())
183 : _Base(__str, __pos, __n, __a) { }
185 basic_string(const _CharT* __s, size_type __n,
186 const _Allocator& __a = _Allocator())
187 : _Base(__glibcxx_check_string_n_constructor(__s, __n), __n, __a) { }
189 basic_string(const _CharT* __s, const _Allocator& __a = _Allocator())
190 : _Base(__glibcxx_check_string_constructor(__s), __a)
193 basic_string(size_type __n, _CharT __c,
194 const _Allocator& __a = _Allocator())
195 : _Base(__n, __c, __a) { }
197 template<typename _InputIterator>
198 basic_string(_InputIterator __begin, _InputIterator __end,
199 const _Allocator& __a = _Allocator())
200 : _Base(__gnu_debug::__base(
201 __glibcxx_check_valid_constructor_range(__begin, __end)),
202 __gnu_debug::__base(__end), __a) { }
204 #if __cplusplus >= 201103L
206 operator=(const basic_string&) = default;
209 operator=(basic_string&&) = default;
213 operator=(const _CharT* __s)
215 __glibcxx_check_string(__s);
216 _Base::operator=(__s);
217 this->_M_invalidate_all();
222 operator=(_CharT __c)
224 _Base::operator=(__c);
225 this->_M_invalidate_all();
229 #if __cplusplus >= 201103L
231 operator=(std::initializer_list<_CharT> __l)
233 _Base::operator=(__l);
234 this->_M_invalidate_all();
241 begin() // _GLIBCXX_NOEXCEPT
242 { return iterator(_Base::begin(), this); }
245 begin() const _GLIBCXX_NOEXCEPT
246 { return const_iterator(_Base::begin(), this); }
249 end() // _GLIBCXX_NOEXCEPT
250 { return iterator(_Base::end(), this); }
253 end() const _GLIBCXX_NOEXCEPT
254 { return const_iterator(_Base::end(), this); }
257 rbegin() // _GLIBCXX_NOEXCEPT
258 { return reverse_iterator(end()); }
260 const_reverse_iterator
261 rbegin() const _GLIBCXX_NOEXCEPT
262 { return const_reverse_iterator(end()); }
265 rend() // _GLIBCXX_NOEXCEPT
266 { return reverse_iterator(begin()); }
268 const_reverse_iterator
269 rend() const _GLIBCXX_NOEXCEPT
270 { return const_reverse_iterator(begin()); }
272 #if __cplusplus >= 201103L
274 cbegin() const noexcept
275 { return const_iterator(_Base::begin(), this); }
278 cend() const noexcept
279 { return const_iterator(_Base::end(), this); }
281 const_reverse_iterator
282 crbegin() const noexcept
283 { return const_reverse_iterator(end()); }
285 const_reverse_iterator
286 crend() const noexcept
287 { return const_reverse_iterator(begin()); }
293 using _Base::max_size;
296 resize(size_type __n, _CharT __c)
298 _Base::resize(__n, __c);
299 this->_M_invalidate_all();
303 resize(size_type __n)
304 { this->resize(__n, _CharT()); }
306 #if __cplusplus >= 201103L
308 shrink_to_fit() noexcept
310 if (capacity() > size())
315 this->_M_invalidate_all();
323 using _Base::capacity;
324 using _Base::reserve;
327 clear() // _GLIBCXX_NOEXCEPT
330 this->_M_invalidate_all();
335 // 21.3.4 element access:
337 operator[](size_type __pos) const _GLIBCXX_NOEXCEPT
339 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
340 _M_message(__gnu_debug::__msg_subscript_oob)
341 ._M_sequence(*this, "this")
342 ._M_integer(__pos, "__pos")
343 ._M_integer(this->size(), "size"));
344 return _Base::operator[](__pos);
348 operator[](size_type __pos) // _GLIBCXX_NOEXCEPT
350 #if __cplusplus < 201103L && defined(_GLIBCXX_DEBUG_PEDANTIC)
351 __glibcxx_check_subscript(__pos);
353 // as an extension v3 allows s[s.size()] when s is non-const.
354 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
355 _M_message(__gnu_debug::__msg_subscript_oob)
356 ._M_sequence(*this, "this")
357 ._M_integer(__pos, "__pos")
358 ._M_integer(this->size(), "size"));
360 return _Base::operator[](__pos);
365 #if __cplusplus >= 201103L
372 operator+=(const basic_string& __str)
374 _Base::operator+=(__str);
375 this->_M_invalidate_all();
380 operator+=(const _CharT* __s)
382 __glibcxx_check_string(__s);
383 _Base::operator+=(__s);
384 this->_M_invalidate_all();
389 operator+=(_CharT __c)
391 _Base::operator+=(__c);
392 this->_M_invalidate_all();
396 #if __cplusplus >= 201103L
398 operator+=(std::initializer_list<_CharT> __l)
400 _Base::operator+=(__l);
401 this->_M_invalidate_all();
407 append(const basic_string& __str)
409 _Base::append(__str);
410 this->_M_invalidate_all();
415 append(const basic_string& __str, size_type __pos, size_type __n)
417 _Base::append(__str, __pos, __n);
418 this->_M_invalidate_all();
423 append(const _CharT* __s, size_type __n)
425 __glibcxx_check_string_len(__s, __n);
426 _Base::append(__s, __n);
427 this->_M_invalidate_all();
432 append(const _CharT* __s)
434 __glibcxx_check_string(__s);
436 this->_M_invalidate_all();
441 append(size_type __n, _CharT __c)
443 _Base::append(__n, __c);
444 this->_M_invalidate_all();
448 template<typename _InputIterator>
450 append(_InputIterator __first, _InputIterator __last)
452 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
453 __glibcxx_check_valid_range2(__first, __last, __dist);
455 if (__dist.second >= __dp_sign)
456 _Base::append(__gnu_debug::__unsafe(__first),
457 __gnu_debug::__unsafe(__last));
459 _Base::append(__first, __last);
461 this->_M_invalidate_all();
465 // _GLIBCXX_RESOLVE_LIB_DEFECTS
466 // 7. string clause minor problems
468 push_back(_CharT __c)
470 _Base::push_back(__c);
471 this->_M_invalidate_all();
475 assign(const basic_string& __x)
478 this->_M_invalidate_all();
482 #if __cplusplus >= 201103L
484 assign(basic_string&& __x)
485 noexcept(noexcept(std::declval<_Base&>().assign(std::move(__x))))
487 _Base::assign(std::move(__x));
488 this->_M_invalidate_all();
494 assign(const basic_string& __str, size_type __pos, size_type __n)
496 _Base::assign(__str, __pos, __n);
497 this->_M_invalidate_all();
502 assign(const _CharT* __s, size_type __n)
504 __glibcxx_check_string_len(__s, __n);
505 _Base::assign(__s, __n);
506 this->_M_invalidate_all();
511 assign(const _CharT* __s)
513 __glibcxx_check_string(__s);
515 this->_M_invalidate_all();
520 assign(size_type __n, _CharT __c)
522 _Base::assign(__n, __c);
523 this->_M_invalidate_all();
527 template<typename _InputIterator>
529 assign(_InputIterator __first, _InputIterator __last)
531 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
532 __glibcxx_check_valid_range2(__first, __last, __dist);
534 if (__dist.second >= __dp_sign)
535 _Base::assign(__gnu_debug::__unsafe(__first),
536 __gnu_debug::__unsafe(__last));
538 _Base::assign(__first, __last);
540 this->_M_invalidate_all();
544 #if __cplusplus >= 201103L
546 assign(std::initializer_list<_CharT> __l)
549 this->_M_invalidate_all();
555 insert(size_type __pos1, const basic_string& __str)
557 _Base::insert(__pos1, __str);
558 this->_M_invalidate_all();
563 insert(size_type __pos1, const basic_string& __str,
564 size_type __pos2, size_type __n)
566 _Base::insert(__pos1, __str, __pos2, __n);
567 this->_M_invalidate_all();
572 insert(size_type __pos, const _CharT* __s, size_type __n)
574 __glibcxx_check_string(__s);
575 _Base::insert(__pos, __s, __n);
576 this->_M_invalidate_all();
581 insert(size_type __pos, const _CharT* __s)
583 __glibcxx_check_string(__s);
584 _Base::insert(__pos, __s);
585 this->_M_invalidate_all();
590 insert(size_type __pos, size_type __n, _CharT __c)
592 _Base::insert(__pos, __n, __c);
593 this->_M_invalidate_all();
598 insert(__const_iterator __p, _CharT __c)
600 __glibcxx_check_insert(__p);
601 typename _Base::iterator __res = _Base::insert(__p.base(), __c);
602 this->_M_invalidate_all();
603 return iterator(__res, this);
606 #if __cplusplus >= 201103L
608 insert(const_iterator __p, size_type __n, _CharT __c)
610 __glibcxx_check_insert(__p);
611 #if _GLIBCXX_USE_CXX11_ABI
612 typename _Base::iterator __res = _Base::insert(__p.base(), __n, __c);
614 const size_type __offset = __p.base() - _Base::cbegin();
615 _Base::insert(_Base::begin() + __offset, __n, __c);
616 typename _Base::iterator __res = _Base::begin() + __offset;
618 this->_M_invalidate_all();
619 return iterator(__res, this);
623 insert(iterator __p, size_type __n, _CharT __c)
625 __glibcxx_check_insert(__p);
626 _Base::insert(__p.base(), __n, __c);
627 this->_M_invalidate_all();
631 template<typename _InputIterator>
633 insert(__const_iterator __p,
634 _InputIterator __first, _InputIterator __last)
636 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
637 __glibcxx_check_insert_range(__p, __first, __last, __dist);
639 typename _Base::iterator __res;
640 #if ! _GLIBCXX_INSERT_RETURNS_ITERATOR
641 const size_type __offset = __p.base() - _Base::begin();
643 if (__dist.second >= __dp_sign)
645 _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(__res =)
646 _Base::insert(__p.base(), __gnu_debug::__unsafe(__first),
647 __gnu_debug::__unsafe(__last));
651 _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(__res =)
652 _Base::insert(__p.base(), __first, __last);
655 #if ! _GLIBCXX_INSERT_RETURNS_ITERATOR
656 __res = _Base::begin() + __offset;
658 this->_M_invalidate_all();
659 return iterator(__res, this);
662 #if __cplusplus >= 201103L
664 insert(const_iterator __p, std::initializer_list<_CharT> __l)
666 __glibcxx_check_insert(__p);
667 #if _GLIBCXX_USE_CXX11_ABI
668 const auto __res = _Base::insert(__p.base(), __l);
670 const size_type __offset = __p.base() - _Base::cbegin();
671 _Base::insert(_Base::begin() + __offset, __l);
672 auto __res = _Base::begin() + __offset;
674 this->_M_invalidate_all();
675 return iterator(__res, this);
680 erase(size_type __pos = 0, size_type __n = _Base::npos)
682 _Base::erase(__pos, __n);
683 this->_M_invalidate_all();
688 erase(__const_iterator __position)
690 __glibcxx_check_erase(__position);
691 typename _Base::iterator __res = _Base::erase(__position.base());
692 this->_M_invalidate_all();
693 return iterator(__res, this);
697 erase(__const_iterator __first, __const_iterator __last)
699 // _GLIBCXX_RESOLVE_LIB_DEFECTS
700 // 151. can't currently clear() empty container
701 __glibcxx_check_erase_range(__first, __last);
702 typename _Base::iterator __res = _Base::erase(__first.base(),
704 this->_M_invalidate_all();
705 return iterator(__res, this);
708 #if __cplusplus >= 201103L
710 pop_back() // noexcept
712 __glibcxx_check_nonempty();
714 this->_M_invalidate_all();
719 replace(size_type __pos1, size_type __n1, const basic_string& __str)
721 _Base::replace(__pos1, __n1, __str);
722 this->_M_invalidate_all();
727 replace(size_type __pos1, size_type __n1, const basic_string& __str,
728 size_type __pos2, size_type __n2)
730 _Base::replace(__pos1, __n1, __str, __pos2, __n2);
731 this->_M_invalidate_all();
736 replace(size_type __pos, size_type __n1, const _CharT* __s,
739 __glibcxx_check_string_len(__s, __n2);
740 _Base::replace(__pos, __n1, __s, __n2);
741 this->_M_invalidate_all();
746 replace(size_type __pos, size_type __n1, const _CharT* __s)
748 __glibcxx_check_string(__s);
749 _Base::replace(__pos, __n1, __s);
750 this->_M_invalidate_all();
755 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
757 _Base::replace(__pos, __n1, __n2, __c);
758 this->_M_invalidate_all();
763 replace(__const_iterator __i1, __const_iterator __i2,
764 const basic_string& __str)
766 __glibcxx_check_erase_range(__i1, __i2);
767 _Base::replace(__i1.base(), __i2.base(), __str);
768 this->_M_invalidate_all();
773 replace(__const_iterator __i1, __const_iterator __i2,
774 const _CharT* __s, size_type __n)
776 __glibcxx_check_erase_range(__i1, __i2);
777 __glibcxx_check_string_len(__s, __n);
778 _Base::replace(__i1.base(), __i2.base(), __s, __n);
779 this->_M_invalidate_all();
784 replace(__const_iterator __i1, __const_iterator __i2,
787 __glibcxx_check_erase_range(__i1, __i2);
788 __glibcxx_check_string(__s);
789 _Base::replace(__i1.base(), __i2.base(), __s);
790 this->_M_invalidate_all();
795 replace(__const_iterator __i1, __const_iterator __i2,
796 size_type __n, _CharT __c)
798 __glibcxx_check_erase_range(__i1, __i2);
799 _Base::replace(__i1.base(), __i2.base(), __n, __c);
800 this->_M_invalidate_all();
804 template<typename _InputIterator>
806 replace(__const_iterator __i1, __const_iterator __i2,
807 _InputIterator __j1, _InputIterator __j2)
809 __glibcxx_check_erase_range(__i1, __i2);
811 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
812 __glibcxx_check_valid_range2(__j1, __j2, __dist);
814 if (__dist.second >= __dp_sign)
815 _Base::replace(__i1.base(), __i2.base(),
816 __gnu_debug::__unsafe(__j1),
817 __gnu_debug::__unsafe(__j2));
819 _Base::replace(__i1.base(), __i2.base(), __j1, __j2);
821 this->_M_invalidate_all();
825 #if __cplusplus >= 201103L
827 replace(__const_iterator __i1, __const_iterator __i2,
828 std::initializer_list<_CharT> __l)
830 __glibcxx_check_erase_range(__i1, __i2);
831 _Base::replace(__i1.base(), __i2.base(), __l);
832 this->_M_invalidate_all();
838 copy(_CharT* __s, size_type __n, size_type __pos = 0) const
840 __glibcxx_check_string_len(__s, __n);
841 return _Base::copy(__s, __n, __pos);
845 swap(basic_string& __x)
846 _GLIBCXX_NOEXCEPT_IF(std::__is_nothrow_swappable<_Base>::value)
852 // 21.3.6 string operations:
854 c_str() const _GLIBCXX_NOEXCEPT
856 const _CharT* __res = _Base::c_str();
857 this->_M_invalidate_all();
862 data() const _GLIBCXX_NOEXCEPT
864 const _CharT* __res = _Base::data();
865 this->_M_invalidate_all();
869 using _Base::get_allocator;
872 find(const basic_string& __str, size_type __pos = 0) const
874 { return _Base::find(__str, __pos); }
877 find(const _CharT* __s, size_type __pos, size_type __n) const
879 __glibcxx_check_string(__s);
880 return _Base::find(__s, __pos, __n);
884 find(const _CharT* __s, size_type __pos = 0) const
886 __glibcxx_check_string(__s);
887 return _Base::find(__s, __pos);
891 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
892 { return _Base::find(__c, __pos); }
895 rfind(const basic_string& __str, size_type __pos = _Base::npos) const
897 { return _Base::rfind(__str, __pos); }
900 rfind(const _CharT* __s, size_type __pos, size_type __n) const
902 __glibcxx_check_string_len(__s, __n);
903 return _Base::rfind(__s, __pos, __n);
907 rfind(const _CharT* __s, size_type __pos = _Base::npos) const
909 __glibcxx_check_string(__s);
910 return _Base::rfind(__s, __pos);
914 rfind(_CharT __c, size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
915 { return _Base::rfind(__c, __pos); }
918 find_first_of(const basic_string& __str, size_type __pos = 0) const
920 { return _Base::find_first_of(__str, __pos); }
923 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
925 __glibcxx_check_string(__s);
926 return _Base::find_first_of(__s, __pos, __n);
930 find_first_of(const _CharT* __s, size_type __pos = 0) const
932 __glibcxx_check_string(__s);
933 return _Base::find_first_of(__s, __pos);
937 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
938 { return _Base::find_first_of(__c, __pos); }
941 find_last_of(const basic_string& __str,
942 size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
943 { return _Base::find_last_of(__str, __pos); }
946 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
948 __glibcxx_check_string(__s);
949 return _Base::find_last_of(__s, __pos, __n);
953 find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const
955 __glibcxx_check_string(__s);
956 return _Base::find_last_of(__s, __pos);
960 find_last_of(_CharT __c, size_type __pos = _Base::npos) const
962 { return _Base::find_last_of(__c, __pos); }
965 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
967 { return _Base::find_first_not_of(__str, __pos); }
970 find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
972 __glibcxx_check_string_len(__s, __n);
973 return _Base::find_first_not_of(__s, __pos, __n);
977 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
979 __glibcxx_check_string(__s);
980 return _Base::find_first_not_of(__s, __pos);
984 find_first_not_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
985 { return _Base::find_first_not_of(__c, __pos); }
988 find_last_not_of(const basic_string& __str,
989 size_type __pos = _Base::npos) const
991 { return _Base::find_last_not_of(__str, __pos); }
994 find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
996 __glibcxx_check_string(__s);
997 return _Base::find_last_not_of(__s, __pos, __n);
1001 find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const
1003 __glibcxx_check_string(__s);
1004 return _Base::find_last_not_of(__s, __pos);
1008 find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const
1010 { return _Base::find_last_not_of(__c, __pos); }
1013 substr(size_type __pos = 0, size_type __n = _Base::npos) const
1014 { return basic_string(_Base::substr(__pos, __n)); }
1017 compare(const basic_string& __str) const
1018 { return _Base::compare(__str); }
1021 compare(size_type __pos1, size_type __n1,
1022 const basic_string& __str) const
1023 { return _Base::compare(__pos1, __n1, __str); }
1026 compare(size_type __pos1, size_type __n1, const basic_string& __str,
1027 size_type __pos2, size_type __n2) const
1028 { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); }
1031 compare(const _CharT* __s) const
1033 __glibcxx_check_string(__s);
1034 return _Base::compare(__s);
1037 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1038 // 5. string::compare specification questionable
1040 compare(size_type __pos1, size_type __n1, const _CharT* __s) const
1042 __glibcxx_check_string(__s);
1043 return _Base::compare(__pos1, __n1, __s);
1046 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1047 // 5. string::compare specification questionable
1049 compare(size_type __pos1, size_type __n1,const _CharT* __s,
1050 size_type __n2) const
1052 __glibcxx_check_string_len(__s, __n2);
1053 return _Base::compare(__pos1, __n1, __s, __n2);
1057 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
1060 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
1062 using _Safe::_M_invalidate_all;
1065 template<typename _CharT, typename _Traits, typename _Allocator>
1066 inline basic_string<_CharT,_Traits,_Allocator>
1067 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1068 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1069 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
1071 template<typename _CharT, typename _Traits, typename _Allocator>
1072 inline basic_string<_CharT,_Traits,_Allocator>
1073 operator+(const _CharT* __lhs,
1074 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1076 __glibcxx_check_string(__lhs);
1077 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
1080 template<typename _CharT, typename _Traits, typename _Allocator>
1081 inline basic_string<_CharT,_Traits,_Allocator>
1082 operator+(_CharT __lhs,
1083 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1084 { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
1086 template<typename _CharT, typename _Traits, typename _Allocator>
1087 inline basic_string<_CharT,_Traits,_Allocator>
1088 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1089 const _CharT* __rhs)
1091 __glibcxx_check_string(__rhs);
1092 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
1095 template<typename _CharT, typename _Traits, typename _Allocator>
1096 inline basic_string<_CharT,_Traits,_Allocator>
1097 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1099 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
1101 template<typename _CharT, typename _Traits, typename _Allocator>
1103 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1104 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1105 { return __lhs._M_base() == __rhs._M_base(); }
1107 template<typename _CharT, typename _Traits, typename _Allocator>
1109 operator==(const _CharT* __lhs,
1110 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1112 __glibcxx_check_string(__lhs);
1113 return __lhs == __rhs._M_base();
1116 template<typename _CharT, typename _Traits, typename _Allocator>
1118 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1119 const _CharT* __rhs)
1121 __glibcxx_check_string(__rhs);
1122 return __lhs._M_base() == __rhs;
1125 template<typename _CharT, typename _Traits, typename _Allocator>
1127 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1128 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1129 { return __lhs._M_base() != __rhs._M_base(); }
1131 template<typename _CharT, typename _Traits, typename _Allocator>
1133 operator!=(const _CharT* __lhs,
1134 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1136 __glibcxx_check_string(__lhs);
1137 return __lhs != __rhs._M_base();
1140 template<typename _CharT, typename _Traits, typename _Allocator>
1142 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1143 const _CharT* __rhs)
1145 __glibcxx_check_string(__rhs);
1146 return __lhs._M_base() != __rhs;
1149 template<typename _CharT, typename _Traits, typename _Allocator>
1151 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1152 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1153 { return __lhs._M_base() < __rhs._M_base(); }
1155 template<typename _CharT, typename _Traits, typename _Allocator>
1157 operator<(const _CharT* __lhs,
1158 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1160 __glibcxx_check_string(__lhs);
1161 return __lhs < __rhs._M_base();
1164 template<typename _CharT, typename _Traits, typename _Allocator>
1166 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1167 const _CharT* __rhs)
1169 __glibcxx_check_string(__rhs);
1170 return __lhs._M_base() < __rhs;
1173 template<typename _CharT, typename _Traits, typename _Allocator>
1175 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1176 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1177 { return __lhs._M_base() <= __rhs._M_base(); }
1179 template<typename _CharT, typename _Traits, typename _Allocator>
1181 operator<=(const _CharT* __lhs,
1182 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1184 __glibcxx_check_string(__lhs);
1185 return __lhs <= __rhs._M_base();
1188 template<typename _CharT, typename _Traits, typename _Allocator>
1190 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1191 const _CharT* __rhs)
1193 __glibcxx_check_string(__rhs);
1194 return __lhs._M_base() <= __rhs;
1197 template<typename _CharT, typename _Traits, typename _Allocator>
1199 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1200 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1201 { return __lhs._M_base() >= __rhs._M_base(); }
1203 template<typename _CharT, typename _Traits, typename _Allocator>
1205 operator>=(const _CharT* __lhs,
1206 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1208 __glibcxx_check_string(__lhs);
1209 return __lhs >= __rhs._M_base();
1212 template<typename _CharT, typename _Traits, typename _Allocator>
1214 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1215 const _CharT* __rhs)
1217 __glibcxx_check_string(__rhs);
1218 return __lhs._M_base() >= __rhs;
1221 template<typename _CharT, typename _Traits, typename _Allocator>
1223 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1224 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1225 { return __lhs._M_base() > __rhs._M_base(); }
1227 template<typename _CharT, typename _Traits, typename _Allocator>
1229 operator>(const _CharT* __lhs,
1230 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1232 __glibcxx_check_string(__lhs);
1233 return __lhs > __rhs._M_base();
1236 template<typename _CharT, typename _Traits, typename _Allocator>
1238 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1239 const _CharT* __rhs)
1241 __glibcxx_check_string(__rhs);
1242 return __lhs._M_base() > __rhs;
1246 template<typename _CharT, typename _Traits, typename _Allocator>
1248 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1249 basic_string<_CharT,_Traits,_Allocator>& __rhs)
1250 { __lhs.swap(__rhs); }
1252 template<typename _CharT, typename _Traits, typename _Allocator>
1253 std::basic_ostream<_CharT, _Traits>&
1254 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1255 const basic_string<_CharT, _Traits, _Allocator>& __str)
1256 { return __os << __str._M_base(); }
1258 template<typename _CharT, typename _Traits, typename _Allocator>
1259 std::basic_istream<_CharT,_Traits>&
1260 operator>>(std::basic_istream<_CharT,_Traits>& __is,
1261 basic_string<_CharT,_Traits,_Allocator>& __str)
1263 std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base();
1264 __str._M_invalidate_all();
1268 template<typename _CharT, typename _Traits, typename _Allocator>
1269 std::basic_istream<_CharT,_Traits>&
1270 getline(std::basic_istream<_CharT,_Traits>& __is,
1271 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1273 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1276 __str._M_invalidate_all();
1280 template<typename _CharT, typename _Traits, typename _Allocator>
1281 std::basic_istream<_CharT,_Traits>&
1282 getline(std::basic_istream<_CharT,_Traits>& __is,
1283 basic_string<_CharT,_Traits,_Allocator>& __str)
1285 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1287 __str._M_invalidate_all();
1291 typedef basic_string<char> string;
1293 typedef basic_string<wchar_t> wstring;
1295 #ifdef _GLIBCXX_USE_CHAR8_T
1296 /// A string of @c char8_t
1297 typedef basic_string<char8_t> u8string;
1300 #if __cplusplus >= 201103L
1301 /// A string of @c char16_t
1302 typedef basic_string<char16_t> u16string;
1304 /// A string of @c char32_t
1305 typedef basic_string<char32_t> u32string;
1308 template<typename _CharT, typename _Traits, typename _Allocator>
1309 struct _Insert_range_from_self_is_safe<
1310 __gnu_debug::basic_string<_CharT, _Traits, _Allocator> >
1311 { enum { __value = 1 }; };
1313 } // namespace __gnu_debug
1315 #if __cplusplus >= 201103L
1316 namespace std _GLIBCXX_VISIBILITY(default)
1318 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1320 /// std::hash specialization for __gnu_debug::basic_string.
1321 template<typename _CharT>
1322 struct hash<__gnu_debug::basic_string<_CharT>>
1323 : public hash<std::basic_string<_CharT>>
1326 template<typename _CharT>
1327 struct __is_fast_hash<hash<__gnu_debug::basic_string<_CharT>>>
1328 : __is_fast_hash<hash<std::basic_string<_CharT>>>
1331 _GLIBCXX_END_NAMESPACE_VERSION
1335 #undef _GLIBCXX_INSERT_RETURNS_ITERATOR
1336 #undef _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY