1 // Debugging string implementation -*- C++ -*-
3 // Copyright (C) 2003-2013 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
33 #include <debug/safe_sequence.h>
34 #include <debug/safe_iterator.h>
38 /// Class std::basic_string with safety/checking/debug instrumentation.
39 template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
40 typename _Allocator = std::allocator<_CharT> >
42 : public std::basic_string<_CharT, _Traits, _Allocator>,
43 public __gnu_debug::_Safe_sequence<basic_string<_CharT, _Traits,
46 typedef std::basic_string<_CharT, _Traits, _Allocator> _Base;
47 typedef __gnu_debug::_Safe_sequence<basic_string> _Safe_base;
51 typedef _Traits traits_type;
52 typedef typename _Traits::char_type value_type;
53 typedef _Allocator allocator_type;
54 typedef typename _Base::size_type size_type;
55 typedef typename _Base::difference_type difference_type;
56 typedef typename _Base::reference reference;
57 typedef typename _Base::const_reference const_reference;
58 typedef typename _Base::pointer pointer;
59 typedef typename _Base::const_pointer const_pointer;
61 typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, basic_string>
63 typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator,
64 basic_string> const_iterator;
66 typedef std::reverse_iterator<iterator> reverse_iterator;
67 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
71 // 21.3.1 construct/copy/destroy:
72 explicit basic_string(const _Allocator& __a = _Allocator())
76 // Provides conversion from a release-mode string to a debug-mode string
77 basic_string(const _Base& __base) : _Base(__base) { }
79 // _GLIBCXX_RESOLVE_LIB_DEFECTS
80 // 42. string ctors specify wrong default allocator
81 basic_string(const basic_string& __str)
82 : _Base(__str, 0, _Base::npos, __str.get_allocator())
85 // _GLIBCXX_RESOLVE_LIB_DEFECTS
86 // 42. string ctors specify wrong default allocator
87 basic_string(const basic_string& __str, size_type __pos,
88 size_type __n = _Base::npos,
89 const _Allocator& __a = _Allocator())
90 : _Base(__str, __pos, __n, __a)
93 basic_string(const _CharT* __s, size_type __n,
94 const _Allocator& __a = _Allocator())
95 : _Base(__gnu_debug::__check_string(__s, __n), __n, __a)
98 basic_string(const _CharT* __s, const _Allocator& __a = _Allocator())
99 : _Base(__gnu_debug::__check_string(__s), __a)
100 { this->assign(__s); }
102 basic_string(size_type __n, _CharT __c,
103 const _Allocator& __a = _Allocator())
104 : _Base(__n, __c, __a)
107 template<typename _InputIterator>
108 basic_string(_InputIterator __begin, _InputIterator __end,
109 const _Allocator& __a = _Allocator())
110 : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__begin,
112 __gnu_debug::__base(__end), __a)
115 #if __cplusplus >= 201103L
116 basic_string(basic_string&& __str) noexcept
117 : _Base(std::move(__str))
120 basic_string(std::initializer_list<_CharT> __l,
121 const _Allocator& __a = _Allocator())
126 ~basic_string() _GLIBCXX_NOEXCEPT { }
129 operator=(const basic_string& __str)
131 *static_cast<_Base*>(this) = __str;
132 this->_M_invalidate_all();
137 operator=(const _CharT* __s)
139 __glibcxx_check_string(__s);
140 *static_cast<_Base*>(this) = __s;
141 this->_M_invalidate_all();
146 operator=(_CharT __c)
148 *static_cast<_Base*>(this) = __c;
149 this->_M_invalidate_all();
153 #if __cplusplus >= 201103L
155 operator=(basic_string&& __str)
157 __glibcxx_check_self_move_assign(__str);
158 *static_cast<_Base*>(this) = std::move(__str);
159 this->_M_invalidate_all();
164 operator=(std::initializer_list<_CharT> __l)
166 *static_cast<_Base*>(this) = __l;
167 this->_M_invalidate_all();
174 begin() _GLIBCXX_NOEXCEPT
175 { return iterator(_Base::begin(), this); }
178 begin() const _GLIBCXX_NOEXCEPT
179 { return const_iterator(_Base::begin(), this); }
182 end() _GLIBCXX_NOEXCEPT
183 { return iterator(_Base::end(), this); }
186 end() const _GLIBCXX_NOEXCEPT
187 { return const_iterator(_Base::end(), this); }
190 rbegin() _GLIBCXX_NOEXCEPT
191 { return reverse_iterator(end()); }
193 const_reverse_iterator
194 rbegin() const _GLIBCXX_NOEXCEPT
195 { return const_reverse_iterator(end()); }
198 rend() _GLIBCXX_NOEXCEPT
199 { return reverse_iterator(begin()); }
201 const_reverse_iterator
202 rend() const _GLIBCXX_NOEXCEPT
203 { return const_reverse_iterator(begin()); }
205 #if __cplusplus >= 201103L
207 cbegin() const noexcept
208 { return const_iterator(_Base::begin(), this); }
211 cend() const noexcept
212 { return const_iterator(_Base::end(), this); }
214 const_reverse_iterator
215 crbegin() const noexcept
216 { return const_reverse_iterator(end()); }
218 const_reverse_iterator
219 crend() const noexcept
220 { return const_reverse_iterator(begin()); }
226 using _Base::max_size;
229 resize(size_type __n, _CharT __c)
231 _Base::resize(__n, __c);
232 this->_M_invalidate_all();
236 resize(size_type __n)
237 { this->resize(__n, _CharT()); }
239 #if __cplusplus >= 201103L
243 if (capacity() > size())
248 this->_M_invalidate_all();
256 using _Base::capacity;
257 using _Base::reserve;
260 clear() _GLIBCXX_NOEXCEPT
263 this->_M_invalidate_all();
268 // 21.3.4 element access:
270 operator[](size_type __pos) const
272 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
273 _M_message(__gnu_debug::__msg_subscript_oob)
274 ._M_sequence(*this, "this")
275 ._M_integer(__pos, "__pos")
276 ._M_integer(this->size(), "size"));
277 return _M_base()[__pos];
281 operator[](size_type __pos)
283 #ifdef _GLIBCXX_DEBUG_PEDANTIC
284 __glibcxx_check_subscript(__pos);
286 // as an extension v3 allows s[s.size()] when s is non-const.
287 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
288 _M_message(__gnu_debug::__msg_subscript_oob)
289 ._M_sequence(*this, "this")
290 ._M_integer(__pos, "__pos")
291 ._M_integer(this->size(), "size"));
293 return _M_base()[__pos];
298 #if __cplusplus >= 201103L
305 operator+=(const basic_string& __str)
308 this->_M_invalidate_all();
313 operator+=(const _CharT* __s)
315 __glibcxx_check_string(__s);
317 this->_M_invalidate_all();
322 operator+=(_CharT __c)
325 this->_M_invalidate_all();
329 #if __cplusplus >= 201103L
331 operator+=(std::initializer_list<_CharT> __l)
334 this->_M_invalidate_all();
340 append(const basic_string& __str)
342 _Base::append(__str);
343 this->_M_invalidate_all();
348 append(const basic_string& __str, size_type __pos, size_type __n)
350 _Base::append(__str, __pos, __n);
351 this->_M_invalidate_all();
356 append(const _CharT* __s, size_type __n)
358 __glibcxx_check_string_len(__s, __n);
359 _Base::append(__s, __n);
360 this->_M_invalidate_all();
365 append(const _CharT* __s)
367 __glibcxx_check_string(__s);
369 this->_M_invalidate_all();
374 append(size_type __n, _CharT __c)
376 _Base::append(__n, __c);
377 this->_M_invalidate_all();
381 template<typename _InputIterator>
383 append(_InputIterator __first, _InputIterator __last)
385 __glibcxx_check_valid_range(__first, __last);
386 _Base::append(__gnu_debug::__base(__first),
387 __gnu_debug::__base(__last));
388 this->_M_invalidate_all();
392 // _GLIBCXX_RESOLVE_LIB_DEFECTS
393 // 7. string clause minor problems
395 push_back(_CharT __c)
397 _Base::push_back(__c);
398 this->_M_invalidate_all();
402 assign(const basic_string& __x)
405 this->_M_invalidate_all();
409 #if __cplusplus >= 201103L
411 assign(basic_string&& __x)
413 _Base::assign(std::move(__x));
414 this->_M_invalidate_all();
420 assign(const basic_string& __str, size_type __pos, size_type __n)
422 _Base::assign(__str, __pos, __n);
423 this->_M_invalidate_all();
428 assign(const _CharT* __s, size_type __n)
430 __glibcxx_check_string_len(__s, __n);
431 _Base::assign(__s, __n);
432 this->_M_invalidate_all();
437 assign(const _CharT* __s)
439 __glibcxx_check_string(__s);
441 this->_M_invalidate_all();
446 assign(size_type __n, _CharT __c)
448 _Base::assign(__n, __c);
449 this->_M_invalidate_all();
453 template<typename _InputIterator>
455 assign(_InputIterator __first, _InputIterator __last)
457 __glibcxx_check_valid_range(__first, __last);
458 _Base::assign(__gnu_debug::__base(__first),
459 __gnu_debug::__base(__last));
460 this->_M_invalidate_all();
464 #if __cplusplus >= 201103L
466 assign(std::initializer_list<_CharT> __l)
469 this->_M_invalidate_all();
475 insert(size_type __pos1, const basic_string& __str)
477 _Base::insert(__pos1, __str);
478 this->_M_invalidate_all();
483 insert(size_type __pos1, const basic_string& __str,
484 size_type __pos2, size_type __n)
486 _Base::insert(__pos1, __str, __pos2, __n);
487 this->_M_invalidate_all();
492 insert(size_type __pos, const _CharT* __s, size_type __n)
494 __glibcxx_check_string(__s);
495 _Base::insert(__pos, __s, __n);
496 this->_M_invalidate_all();
501 insert(size_type __pos, const _CharT* __s)
503 __glibcxx_check_string(__s);
504 _Base::insert(__pos, __s);
505 this->_M_invalidate_all();
510 insert(size_type __pos, size_type __n, _CharT __c)
512 _Base::insert(__pos, __n, __c);
513 this->_M_invalidate_all();
518 insert(iterator __p, _CharT __c)
520 __glibcxx_check_insert(__p);
521 typename _Base::iterator __res = _Base::insert(__p.base(), __c);
522 this->_M_invalidate_all();
523 return iterator(__res, this);
527 insert(iterator __p, size_type __n, _CharT __c)
529 __glibcxx_check_insert(__p);
530 _Base::insert(__p.base(), __n, __c);
531 this->_M_invalidate_all();
534 template<typename _InputIterator>
536 insert(iterator __p, _InputIterator __first, _InputIterator __last)
538 __glibcxx_check_insert_range(__p, __first, __last);
539 _Base::insert(__p.base(), __gnu_debug::__base(__first),
540 __gnu_debug::__base(__last));
541 this->_M_invalidate_all();
544 #if __cplusplus >= 201103L
546 insert(iterator __p, std::initializer_list<_CharT> __l)
548 __glibcxx_check_insert(__p);
549 _Base::insert(__p.base(), __l);
550 this->_M_invalidate_all();
555 erase(size_type __pos = 0, size_type __n = _Base::npos)
557 _Base::erase(__pos, __n);
558 this->_M_invalidate_all();
563 erase(iterator __position)
565 __glibcxx_check_erase(__position);
566 typename _Base::iterator __res = _Base::erase(__position.base());
567 this->_M_invalidate_all();
568 return iterator(__res, this);
572 erase(iterator __first, iterator __last)
574 // _GLIBCXX_RESOLVE_LIB_DEFECTS
575 // 151. can't currently clear() empty container
576 __glibcxx_check_erase_range(__first, __last);
577 typename _Base::iterator __res = _Base::erase(__first.base(),
579 this->_M_invalidate_all();
580 return iterator(__res, this);
583 #if __cplusplus >= 201103L
587 __glibcxx_check_nonempty();
589 this->_M_invalidate_all();
594 replace(size_type __pos1, size_type __n1, const basic_string& __str)
596 _Base::replace(__pos1, __n1, __str);
597 this->_M_invalidate_all();
602 replace(size_type __pos1, size_type __n1, const basic_string& __str,
603 size_type __pos2, size_type __n2)
605 _Base::replace(__pos1, __n1, __str, __pos2, __n2);
606 this->_M_invalidate_all();
611 replace(size_type __pos, size_type __n1, const _CharT* __s,
614 __glibcxx_check_string_len(__s, __n2);
615 _Base::replace(__pos, __n1, __s, __n2);
616 this->_M_invalidate_all();
621 replace(size_type __pos, size_type __n1, const _CharT* __s)
623 __glibcxx_check_string(__s);
624 _Base::replace(__pos, __n1, __s);
625 this->_M_invalidate_all();
630 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
632 _Base::replace(__pos, __n1, __n2, __c);
633 this->_M_invalidate_all();
638 replace(iterator __i1, iterator __i2, const basic_string& __str)
640 __glibcxx_check_erase_range(__i1, __i2);
641 _Base::replace(__i1.base(), __i2.base(), __str);
642 this->_M_invalidate_all();
647 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
649 __glibcxx_check_erase_range(__i1, __i2);
650 __glibcxx_check_string_len(__s, __n);
651 _Base::replace(__i1.base(), __i2.base(), __s, __n);
652 this->_M_invalidate_all();
657 replace(iterator __i1, iterator __i2, const _CharT* __s)
659 __glibcxx_check_erase_range(__i1, __i2);
660 __glibcxx_check_string(__s);
661 _Base::replace(__i1.base(), __i2.base(), __s);
662 this->_M_invalidate_all();
667 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
669 __glibcxx_check_erase_range(__i1, __i2);
670 _Base::replace(__i1.base(), __i2.base(), __n, __c);
671 this->_M_invalidate_all();
675 template<typename _InputIterator>
677 replace(iterator __i1, iterator __i2,
678 _InputIterator __j1, _InputIterator __j2)
680 __glibcxx_check_erase_range(__i1, __i2);
681 __glibcxx_check_valid_range(__j1, __j2);
682 _Base::replace(__i1.base(), __i2.base(), __j1, __j2);
683 this->_M_invalidate_all();
687 #if __cplusplus >= 201103L
688 basic_string& replace(iterator __i1, iterator __i2,
689 std::initializer_list<_CharT> __l)
691 __glibcxx_check_erase_range(__i1, __i2);
692 _Base::replace(__i1.base(), __i2.base(), __l);
693 this->_M_invalidate_all();
699 copy(_CharT* __s, size_type __n, size_type __pos = 0) const
701 __glibcxx_check_string_len(__s, __n);
702 return _Base::copy(__s, __n, __pos);
706 swap(basic_string<_CharT,_Traits,_Allocator>& __x)
710 this->_M_invalidate_all();
711 __x._M_invalidate_all();
714 // 21.3.6 string operations:
716 c_str() const _GLIBCXX_NOEXCEPT
718 const _CharT* __res = _Base::c_str();
719 this->_M_invalidate_all();
724 data() const _GLIBCXX_NOEXCEPT
726 const _CharT* __res = _Base::data();
727 this->_M_invalidate_all();
731 using _Base::get_allocator;
734 find(const basic_string& __str, size_type __pos = 0) const
736 { return _Base::find(__str, __pos); }
739 find(const _CharT* __s, size_type __pos, size_type __n) const
741 __glibcxx_check_string(__s);
742 return _Base::find(__s, __pos, __n);
746 find(const _CharT* __s, size_type __pos = 0) const
748 __glibcxx_check_string(__s);
749 return _Base::find(__s, __pos);
753 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
754 { return _Base::find(__c, __pos); }
757 rfind(const basic_string& __str, size_type __pos = _Base::npos) const
759 { return _Base::rfind(__str, __pos); }
762 rfind(const _CharT* __s, size_type __pos, size_type __n) const
764 __glibcxx_check_string_len(__s, __n);
765 return _Base::rfind(__s, __pos, __n);
769 rfind(const _CharT* __s, size_type __pos = _Base::npos) const
771 __glibcxx_check_string(__s);
772 return _Base::rfind(__s, __pos);
776 rfind(_CharT __c, size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
777 { return _Base::rfind(__c, __pos); }
780 find_first_of(const basic_string& __str, size_type __pos = 0) const
782 { return _Base::find_first_of(__str, __pos); }
785 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
787 __glibcxx_check_string(__s);
788 return _Base::find_first_of(__s, __pos, __n);
792 find_first_of(const _CharT* __s, size_type __pos = 0) const
794 __glibcxx_check_string(__s);
795 return _Base::find_first_of(__s, __pos);
799 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
800 { return _Base::find_first_of(__c, __pos); }
803 find_last_of(const basic_string& __str,
804 size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
805 { return _Base::find_last_of(__str, __pos); }
808 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
810 __glibcxx_check_string(__s);
811 return _Base::find_last_of(__s, __pos, __n);
815 find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const
817 __glibcxx_check_string(__s);
818 return _Base::find_last_of(__s, __pos);
822 find_last_of(_CharT __c, size_type __pos = _Base::npos) const
824 { return _Base::find_last_of(__c, __pos); }
827 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
829 { return _Base::find_first_not_of(__str, __pos); }
832 find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
834 __glibcxx_check_string_len(__s, __n);
835 return _Base::find_first_not_of(__s, __pos, __n);
839 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
841 __glibcxx_check_string(__s);
842 return _Base::find_first_not_of(__s, __pos);
846 find_first_not_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
847 { return _Base::find_first_not_of(__c, __pos); }
850 find_last_not_of(const basic_string& __str,
851 size_type __pos = _Base::npos) const
853 { return _Base::find_last_not_of(__str, __pos); }
856 find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
858 __glibcxx_check_string(__s);
859 return _Base::find_last_not_of(__s, __pos, __n);
863 find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const
865 __glibcxx_check_string(__s);
866 return _Base::find_last_not_of(__s, __pos);
870 find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const
872 { return _Base::find_last_not_of(__c, __pos); }
875 substr(size_type __pos = 0, size_type __n = _Base::npos) const
876 { return basic_string(_Base::substr(__pos, __n)); }
879 compare(const basic_string& __str) const
880 { return _Base::compare(__str); }
883 compare(size_type __pos1, size_type __n1,
884 const basic_string& __str) const
885 { return _Base::compare(__pos1, __n1, __str); }
888 compare(size_type __pos1, size_type __n1, const basic_string& __str,
889 size_type __pos2, size_type __n2) const
890 { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); }
893 compare(const _CharT* __s) const
895 __glibcxx_check_string(__s);
896 return _Base::compare(__s);
899 // _GLIBCXX_RESOLVE_LIB_DEFECTS
900 // 5. string::compare specification questionable
902 compare(size_type __pos1, size_type __n1, const _CharT* __s) const
904 __glibcxx_check_string(__s);
905 return _Base::compare(__pos1, __n1, __s);
908 // _GLIBCXX_RESOLVE_LIB_DEFECTS
909 // 5. string::compare specification questionable
911 compare(size_type __pos1, size_type __n1,const _CharT* __s,
912 size_type __n2) const
914 __glibcxx_check_string_len(__s, __n2);
915 return _Base::compare(__pos1, __n1, __s, __n2);
919 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
922 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
924 using _Safe_base::_M_invalidate_all;
927 template<typename _CharT, typename _Traits, typename _Allocator>
928 inline basic_string<_CharT,_Traits,_Allocator>
929 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
930 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
931 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
933 template<typename _CharT, typename _Traits, typename _Allocator>
934 inline basic_string<_CharT,_Traits,_Allocator>
935 operator+(const _CharT* __lhs,
936 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
938 __glibcxx_check_string(__lhs);
939 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
942 template<typename _CharT, typename _Traits, typename _Allocator>
943 inline basic_string<_CharT,_Traits,_Allocator>
944 operator+(_CharT __lhs,
945 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
946 { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
948 template<typename _CharT, typename _Traits, typename _Allocator>
949 inline basic_string<_CharT,_Traits,_Allocator>
950 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
953 __glibcxx_check_string(__rhs);
954 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
957 template<typename _CharT, typename _Traits, typename _Allocator>
958 inline basic_string<_CharT,_Traits,_Allocator>
959 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
961 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
963 template<typename _CharT, typename _Traits, typename _Allocator>
965 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
966 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
967 { return __lhs._M_base() == __rhs._M_base(); }
969 template<typename _CharT, typename _Traits, typename _Allocator>
971 operator==(const _CharT* __lhs,
972 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
974 __glibcxx_check_string(__lhs);
975 return __lhs == __rhs._M_base();
978 template<typename _CharT, typename _Traits, typename _Allocator>
980 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
983 __glibcxx_check_string(__rhs);
984 return __lhs._M_base() == __rhs;
987 template<typename _CharT, typename _Traits, typename _Allocator>
989 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
990 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
991 { return __lhs._M_base() != __rhs._M_base(); }
993 template<typename _CharT, typename _Traits, typename _Allocator>
995 operator!=(const _CharT* __lhs,
996 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
998 __glibcxx_check_string(__lhs);
999 return __lhs != __rhs._M_base();
1002 template<typename _CharT, typename _Traits, typename _Allocator>
1004 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1005 const _CharT* __rhs)
1007 __glibcxx_check_string(__rhs);
1008 return __lhs._M_base() != __rhs;
1011 template<typename _CharT, typename _Traits, typename _Allocator>
1013 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1014 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1015 { return __lhs._M_base() < __rhs._M_base(); }
1017 template<typename _CharT, typename _Traits, typename _Allocator>
1019 operator<(const _CharT* __lhs,
1020 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1022 __glibcxx_check_string(__lhs);
1023 return __lhs < __rhs._M_base();
1026 template<typename _CharT, typename _Traits, typename _Allocator>
1028 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1029 const _CharT* __rhs)
1031 __glibcxx_check_string(__rhs);
1032 return __lhs._M_base() < __rhs;
1035 template<typename _CharT, typename _Traits, typename _Allocator>
1037 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1038 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1039 { return __lhs._M_base() <= __rhs._M_base(); }
1041 template<typename _CharT, typename _Traits, typename _Allocator>
1043 operator<=(const _CharT* __lhs,
1044 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1046 __glibcxx_check_string(__lhs);
1047 return __lhs <= __rhs._M_base();
1050 template<typename _CharT, typename _Traits, typename _Allocator>
1052 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1053 const _CharT* __rhs)
1055 __glibcxx_check_string(__rhs);
1056 return __lhs._M_base() <= __rhs;
1059 template<typename _CharT, typename _Traits, typename _Allocator>
1061 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1062 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1063 { return __lhs._M_base() >= __rhs._M_base(); }
1065 template<typename _CharT, typename _Traits, typename _Allocator>
1067 operator>=(const _CharT* __lhs,
1068 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1070 __glibcxx_check_string(__lhs);
1071 return __lhs >= __rhs._M_base();
1074 template<typename _CharT, typename _Traits, typename _Allocator>
1076 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1077 const _CharT* __rhs)
1079 __glibcxx_check_string(__rhs);
1080 return __lhs._M_base() >= __rhs;
1083 template<typename _CharT, typename _Traits, typename _Allocator>
1085 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1086 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1087 { return __lhs._M_base() > __rhs._M_base(); }
1089 template<typename _CharT, typename _Traits, typename _Allocator>
1091 operator>(const _CharT* __lhs,
1092 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1094 __glibcxx_check_string(__lhs);
1095 return __lhs > __rhs._M_base();
1098 template<typename _CharT, typename _Traits, typename _Allocator>
1100 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1101 const _CharT* __rhs)
1103 __glibcxx_check_string(__rhs);
1104 return __lhs._M_base() > __rhs;
1108 template<typename _CharT, typename _Traits, typename _Allocator>
1110 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1111 basic_string<_CharT,_Traits,_Allocator>& __rhs)
1112 { __lhs.swap(__rhs); }
1114 template<typename _CharT, typename _Traits, typename _Allocator>
1115 std::basic_ostream<_CharT, _Traits>&
1116 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1117 const basic_string<_CharT, _Traits, _Allocator>& __str)
1118 { return __os << __str._M_base(); }
1120 template<typename _CharT, typename _Traits, typename _Allocator>
1121 std::basic_istream<_CharT,_Traits>&
1122 operator>>(std::basic_istream<_CharT,_Traits>& __is,
1123 basic_string<_CharT,_Traits,_Allocator>& __str)
1125 std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base();
1126 __str._M_invalidate_all();
1130 template<typename _CharT, typename _Traits, typename _Allocator>
1131 std::basic_istream<_CharT,_Traits>&
1132 getline(std::basic_istream<_CharT,_Traits>& __is,
1133 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1135 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1138 __str._M_invalidate_all();
1142 template<typename _CharT, typename _Traits, typename _Allocator>
1143 std::basic_istream<_CharT,_Traits>&
1144 getline(std::basic_istream<_CharT,_Traits>& __is,
1145 basic_string<_CharT,_Traits,_Allocator>& __str)
1147 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1149 __str._M_invalidate_all();
1153 typedef basic_string<char> string;
1155 #ifdef _GLIBCXX_USE_WCHAR_T
1156 typedef basic_string<wchar_t> wstring;
1159 template<typename _CharT, typename _Traits, typename _Allocator>
1160 struct _Insert_range_from_self_is_safe<
1161 __gnu_debug::basic_string<_CharT, _Traits, _Allocator> >
1162 { enum { __value = 1 }; };
1164 } // namespace __gnu_debug