1 // Debugging string implementation -*- C++ -*-
3 // Copyright (C) 2003-2015 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_container.h>
35 #include <debug/safe_iterator.h>
39 /// Class std::basic_string with safety/checking/debug instrumentation.
40 template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
41 typename _Allocator = std::allocator<_CharT> >
43 : public __gnu_debug::_Safe_container<
44 basic_string<_CharT, _Traits, _Allocator>,
45 _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>,
46 public std::basic_string<_CharT, _Traits, _Allocator>
48 typedef std::basic_string<_CharT, _Traits, _Allocator> _Base;
49 typedef __gnu_debug::_Safe_container<
50 basic_string, _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>
55 typedef _Traits traits_type;
56 typedef typename _Traits::char_type value_type;
57 typedef _Allocator allocator_type;
58 typedef typename _Base::size_type size_type;
59 typedef typename _Base::difference_type difference_type;
60 typedef typename _Base::reference reference;
61 typedef typename _Base::const_reference const_reference;
62 typedef typename _Base::pointer pointer;
63 typedef typename _Base::const_pointer const_pointer;
65 typedef __gnu_debug::_Safe_iterator<
66 typename _Base::iterator, basic_string> iterator;
67 typedef __gnu_debug::_Safe_iterator<
68 typename _Base::const_iterator, basic_string> const_iterator;
70 typedef std::reverse_iterator<iterator> reverse_iterator;
71 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
76 #if __cplusplus >= 201103L
77 noexcept(std::is_nothrow_default_constructible<_Base>::value)
81 // 21.3.1 construct/copy/destroy:
83 basic_string(const _Allocator& __a) _GLIBCXX_NOEXCEPT
86 #if __cplusplus < 201103L
87 basic_string(const basic_string& __str)
92 basic_string(const basic_string&) = default;
93 basic_string(basic_string&&) = default;
95 basic_string(std::initializer_list<_CharT> __l,
96 const _Allocator& __a = _Allocator())
100 #if _GLIBCXX_USE_CXX11_ABI
101 basic_string(const basic_string& __s, const _Allocator& __a)
102 : _Base(__s, __a) { }
104 basic_string(basic_string&& __s, const _Allocator& __a)
105 : _Base(std::move(__s), __a) { }
108 ~basic_string() = default;
110 // Provides conversion from a normal-mode string to a debug-mode string
111 basic_string(_Base&& __base) noexcept
112 : _Base(std::move(__base)) { }
115 // Provides conversion from a normal-mode string to a debug-mode string
116 basic_string(const _Base& __base)
119 // _GLIBCXX_RESOLVE_LIB_DEFECTS
120 // 42. string ctors specify wrong default allocator
121 basic_string(const basic_string& __str, size_type __pos,
122 size_type __n = _Base::npos,
123 const _Allocator& __a = _Allocator())
124 : _Base(__str, __pos, __n, __a) { }
126 basic_string(const _CharT* __s, size_type __n,
127 const _Allocator& __a = _Allocator())
128 : _Base(__gnu_debug::__check_string(__s, __n), __n, __a) { }
130 basic_string(const _CharT* __s, const _Allocator& __a = _Allocator())
131 : _Base(__gnu_debug::__check_string(__s), __a)
132 { this->assign(__s); }
134 basic_string(size_type __n, _CharT __c,
135 const _Allocator& __a = _Allocator())
136 : _Base(__n, __c, __a) { }
138 template<typename _InputIterator>
139 basic_string(_InputIterator __begin, _InputIterator __end,
140 const _Allocator& __a = _Allocator())
141 : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__begin,
143 __gnu_debug::__base(__end), __a) { }
145 #if __cplusplus < 201103L
147 operator=(const basic_string& __str)
149 this->_M_safe() = __str;
155 operator=(const basic_string&) = default;
158 operator=(basic_string&&) = default;
162 operator=(const _CharT* __s)
164 __glibcxx_check_string(__s);
166 this->_M_invalidate_all();
171 operator=(_CharT __c)
174 this->_M_invalidate_all();
178 #if __cplusplus >= 201103L
180 operator=(std::initializer_list<_CharT> __l)
183 this->_M_invalidate_all();
190 begin() // _GLIBCXX_NOEXCEPT
191 { return iterator(_Base::begin(), this); }
194 begin() const _GLIBCXX_NOEXCEPT
195 { return const_iterator(_Base::begin(), this); }
198 end() // _GLIBCXX_NOEXCEPT
199 { return iterator(_Base::end(), this); }
202 end() const _GLIBCXX_NOEXCEPT
203 { return const_iterator(_Base::end(), this); }
206 rbegin() // _GLIBCXX_NOEXCEPT
207 { return reverse_iterator(end()); }
209 const_reverse_iterator
210 rbegin() const _GLIBCXX_NOEXCEPT
211 { return const_reverse_iterator(end()); }
214 rend() // _GLIBCXX_NOEXCEPT
215 { return reverse_iterator(begin()); }
217 const_reverse_iterator
218 rend() const _GLIBCXX_NOEXCEPT
219 { return const_reverse_iterator(begin()); }
221 #if __cplusplus >= 201103L
223 cbegin() const noexcept
224 { return const_iterator(_Base::begin(), this); }
227 cend() const noexcept
228 { return const_iterator(_Base::end(), this); }
230 const_reverse_iterator
231 crbegin() const noexcept
232 { return const_reverse_iterator(end()); }
234 const_reverse_iterator
235 crend() const noexcept
236 { return const_reverse_iterator(begin()); }
242 using _Base::max_size;
245 resize(size_type __n, _CharT __c)
247 _Base::resize(__n, __c);
248 this->_M_invalidate_all();
252 resize(size_type __n)
253 { this->resize(__n, _CharT()); }
255 #if __cplusplus >= 201103L
257 shrink_to_fit() noexcept
259 if (capacity() > size())
264 this->_M_invalidate_all();
272 using _Base::capacity;
273 using _Base::reserve;
276 clear() // _GLIBCXX_NOEXCEPT
279 this->_M_invalidate_all();
284 // 21.3.4 element access:
286 operator[](size_type __pos) const _GLIBCXX_NOEXCEPT
288 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
289 _M_message(__gnu_debug::__msg_subscript_oob)
290 ._M_sequence(*this, "this")
291 ._M_integer(__pos, "__pos")
292 ._M_integer(this->size(), "size"));
293 return _M_base()[__pos];
297 operator[](size_type __pos) // _GLIBCXX_NOEXCEPT
299 #if __cplusplus < 201103L && defined(_GLIBCXX_DEBUG_PEDANTIC)
300 __glibcxx_check_subscript(__pos);
302 // as an extension v3 allows s[s.size()] when s is non-const.
303 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
304 _M_message(__gnu_debug::__msg_subscript_oob)
305 ._M_sequence(*this, "this")
306 ._M_integer(__pos, "__pos")
307 ._M_integer(this->size(), "size"));
309 return _M_base()[__pos];
314 #if __cplusplus >= 201103L
321 operator+=(const basic_string& __str)
324 this->_M_invalidate_all();
329 operator+=(const _CharT* __s)
331 __glibcxx_check_string(__s);
333 this->_M_invalidate_all();
338 operator+=(_CharT __c)
341 this->_M_invalidate_all();
345 #if __cplusplus >= 201103L
347 operator+=(std::initializer_list<_CharT> __l)
350 this->_M_invalidate_all();
356 append(const basic_string& __str)
358 _Base::append(__str);
359 this->_M_invalidate_all();
364 append(const basic_string& __str, size_type __pos, size_type __n)
366 _Base::append(__str, __pos, __n);
367 this->_M_invalidate_all();
372 append(const _CharT* __s, size_type __n)
374 __glibcxx_check_string_len(__s, __n);
375 _Base::append(__s, __n);
376 this->_M_invalidate_all();
381 append(const _CharT* __s)
383 __glibcxx_check_string(__s);
385 this->_M_invalidate_all();
390 append(size_type __n, _CharT __c)
392 _Base::append(__n, __c);
393 this->_M_invalidate_all();
397 template<typename _InputIterator>
399 append(_InputIterator __first, _InputIterator __last)
401 __glibcxx_check_valid_range(__first, __last);
402 _Base::append(__gnu_debug::__base(__first),
403 __gnu_debug::__base(__last));
404 this->_M_invalidate_all();
408 // _GLIBCXX_RESOLVE_LIB_DEFECTS
409 // 7. string clause minor problems
411 push_back(_CharT __c)
413 _Base::push_back(__c);
414 this->_M_invalidate_all();
418 assign(const basic_string& __x)
421 this->_M_invalidate_all();
425 #if __cplusplus >= 201103L
427 assign(basic_string&& __x)
428 noexcept(noexcept(std::declval<_Base&>().assign(std::move(__x))))
430 _Base::assign(std::move(__x));
431 this->_M_invalidate_all();
437 assign(const basic_string& __str, size_type __pos, size_type __n)
439 _Base::assign(__str, __pos, __n);
440 this->_M_invalidate_all();
445 assign(const _CharT* __s, size_type __n)
447 __glibcxx_check_string_len(__s, __n);
448 _Base::assign(__s, __n);
449 this->_M_invalidate_all();
454 assign(const _CharT* __s)
456 __glibcxx_check_string(__s);
458 this->_M_invalidate_all();
463 assign(size_type __n, _CharT __c)
465 _Base::assign(__n, __c);
466 this->_M_invalidate_all();
470 template<typename _InputIterator>
472 assign(_InputIterator __first, _InputIterator __last)
474 __glibcxx_check_valid_range(__first, __last);
475 _Base::assign(__gnu_debug::__base(__first),
476 __gnu_debug::__base(__last));
477 this->_M_invalidate_all();
481 #if __cplusplus >= 201103L
483 assign(std::initializer_list<_CharT> __l)
486 this->_M_invalidate_all();
492 insert(size_type __pos1, const basic_string& __str)
494 _Base::insert(__pos1, __str);
495 this->_M_invalidate_all();
500 insert(size_type __pos1, const basic_string& __str,
501 size_type __pos2, size_type __n)
503 _Base::insert(__pos1, __str, __pos2, __n);
504 this->_M_invalidate_all();
509 insert(size_type __pos, const _CharT* __s, size_type __n)
511 __glibcxx_check_string(__s);
512 _Base::insert(__pos, __s, __n);
513 this->_M_invalidate_all();
518 insert(size_type __pos, const _CharT* __s)
520 __glibcxx_check_string(__s);
521 _Base::insert(__pos, __s);
522 this->_M_invalidate_all();
527 insert(size_type __pos, size_type __n, _CharT __c)
529 _Base::insert(__pos, __n, __c);
530 this->_M_invalidate_all();
535 insert(iterator __p, _CharT __c)
537 __glibcxx_check_insert(__p);
538 typename _Base::iterator __res = _Base::insert(__p.base(), __c);
539 this->_M_invalidate_all();
540 return iterator(__res, this);
544 insert(iterator __p, size_type __n, _CharT __c)
546 __glibcxx_check_insert(__p);
547 _Base::insert(__p.base(), __n, __c);
548 this->_M_invalidate_all();
551 template<typename _InputIterator>
553 insert(iterator __p, _InputIterator __first, _InputIterator __last)
555 __glibcxx_check_insert_range(__p, __first, __last);
556 _Base::insert(__p.base(), __gnu_debug::__base(__first),
557 __gnu_debug::__base(__last));
558 this->_M_invalidate_all();
561 #if __cplusplus >= 201103L
563 insert(iterator __p, std::initializer_list<_CharT> __l)
565 __glibcxx_check_insert(__p);
566 _Base::insert(__p.base(), __l);
567 this->_M_invalidate_all();
572 erase(size_type __pos = 0, size_type __n = _Base::npos)
574 _Base::erase(__pos, __n);
575 this->_M_invalidate_all();
580 erase(iterator __position)
582 __glibcxx_check_erase(__position);
583 typename _Base::iterator __res = _Base::erase(__position.base());
584 this->_M_invalidate_all();
585 return iterator(__res, this);
589 erase(iterator __first, iterator __last)
591 // _GLIBCXX_RESOLVE_LIB_DEFECTS
592 // 151. can't currently clear() empty container
593 __glibcxx_check_erase_range(__first, __last);
594 typename _Base::iterator __res = _Base::erase(__first.base(),
596 this->_M_invalidate_all();
597 return iterator(__res, this);
600 #if __cplusplus >= 201103L
602 pop_back() // noexcept
604 __glibcxx_check_nonempty();
606 this->_M_invalidate_all();
611 replace(size_type __pos1, size_type __n1, const basic_string& __str)
613 _Base::replace(__pos1, __n1, __str);
614 this->_M_invalidate_all();
619 replace(size_type __pos1, size_type __n1, const basic_string& __str,
620 size_type __pos2, size_type __n2)
622 _Base::replace(__pos1, __n1, __str, __pos2, __n2);
623 this->_M_invalidate_all();
628 replace(size_type __pos, size_type __n1, const _CharT* __s,
631 __glibcxx_check_string_len(__s, __n2);
632 _Base::replace(__pos, __n1, __s, __n2);
633 this->_M_invalidate_all();
638 replace(size_type __pos, size_type __n1, const _CharT* __s)
640 __glibcxx_check_string(__s);
641 _Base::replace(__pos, __n1, __s);
642 this->_M_invalidate_all();
647 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
649 _Base::replace(__pos, __n1, __n2, __c);
650 this->_M_invalidate_all();
655 replace(iterator __i1, iterator __i2, const basic_string& __str)
657 __glibcxx_check_erase_range(__i1, __i2);
658 _Base::replace(__i1.base(), __i2.base(), __str);
659 this->_M_invalidate_all();
664 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
666 __glibcxx_check_erase_range(__i1, __i2);
667 __glibcxx_check_string_len(__s, __n);
668 _Base::replace(__i1.base(), __i2.base(), __s, __n);
669 this->_M_invalidate_all();
674 replace(iterator __i1, iterator __i2, const _CharT* __s)
676 __glibcxx_check_erase_range(__i1, __i2);
677 __glibcxx_check_string(__s);
678 _Base::replace(__i1.base(), __i2.base(), __s);
679 this->_M_invalidate_all();
684 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
686 __glibcxx_check_erase_range(__i1, __i2);
687 _Base::replace(__i1.base(), __i2.base(), __n, __c);
688 this->_M_invalidate_all();
692 template<typename _InputIterator>
694 replace(iterator __i1, iterator __i2,
695 _InputIterator __j1, _InputIterator __j2)
697 __glibcxx_check_erase_range(__i1, __i2);
698 __glibcxx_check_valid_range(__j1, __j2);
699 _Base::replace(__i1.base(), __i2.base(), __j1, __j2);
700 this->_M_invalidate_all();
704 #if __cplusplus >= 201103L
705 basic_string& replace(iterator __i1, iterator __i2,
706 std::initializer_list<_CharT> __l)
708 __glibcxx_check_erase_range(__i1, __i2);
709 _Base::replace(__i1.base(), __i2.base(), __l);
710 this->_M_invalidate_all();
716 copy(_CharT* __s, size_type __n, size_type __pos = 0) const
718 __glibcxx_check_string_len(__s, __n);
719 return _Base::copy(__s, __n, __pos);
723 swap(basic_string& __x)
724 #if _GLIBCXX_USE_CXX11_ABI
732 // 21.3.6 string operations:
734 c_str() const _GLIBCXX_NOEXCEPT
736 const _CharT* __res = _Base::c_str();
737 this->_M_invalidate_all();
742 data() const _GLIBCXX_NOEXCEPT
744 const _CharT* __res = _Base::data();
745 this->_M_invalidate_all();
749 using _Base::get_allocator;
752 find(const basic_string& __str, size_type __pos = 0) const
754 { return _Base::find(__str, __pos); }
757 find(const _CharT* __s, size_type __pos, size_type __n) const
759 __glibcxx_check_string(__s);
760 return _Base::find(__s, __pos, __n);
764 find(const _CharT* __s, size_type __pos = 0) const
766 __glibcxx_check_string(__s);
767 return _Base::find(__s, __pos);
771 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
772 { return _Base::find(__c, __pos); }
775 rfind(const basic_string& __str, size_type __pos = _Base::npos) const
777 { return _Base::rfind(__str, __pos); }
780 rfind(const _CharT* __s, size_type __pos, size_type __n) const
782 __glibcxx_check_string_len(__s, __n);
783 return _Base::rfind(__s, __pos, __n);
787 rfind(const _CharT* __s, size_type __pos = _Base::npos) const
789 __glibcxx_check_string(__s);
790 return _Base::rfind(__s, __pos);
794 rfind(_CharT __c, size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
795 { return _Base::rfind(__c, __pos); }
798 find_first_of(const basic_string& __str, size_type __pos = 0) const
800 { return _Base::find_first_of(__str, __pos); }
803 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
805 __glibcxx_check_string(__s);
806 return _Base::find_first_of(__s, __pos, __n);
810 find_first_of(const _CharT* __s, size_type __pos = 0) const
812 __glibcxx_check_string(__s);
813 return _Base::find_first_of(__s, __pos);
817 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
818 { return _Base::find_first_of(__c, __pos); }
821 find_last_of(const basic_string& __str,
822 size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
823 { return _Base::find_last_of(__str, __pos); }
826 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
828 __glibcxx_check_string(__s);
829 return _Base::find_last_of(__s, __pos, __n);
833 find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const
835 __glibcxx_check_string(__s);
836 return _Base::find_last_of(__s, __pos);
840 find_last_of(_CharT __c, size_type __pos = _Base::npos) const
842 { return _Base::find_last_of(__c, __pos); }
845 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
847 { return _Base::find_first_not_of(__str, __pos); }
850 find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
852 __glibcxx_check_string_len(__s, __n);
853 return _Base::find_first_not_of(__s, __pos, __n);
857 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
859 __glibcxx_check_string(__s);
860 return _Base::find_first_not_of(__s, __pos);
864 find_first_not_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
865 { return _Base::find_first_not_of(__c, __pos); }
868 find_last_not_of(const basic_string& __str,
869 size_type __pos = _Base::npos) const
871 { return _Base::find_last_not_of(__str, __pos); }
874 find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
876 __glibcxx_check_string(__s);
877 return _Base::find_last_not_of(__s, __pos, __n);
881 find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const
883 __glibcxx_check_string(__s);
884 return _Base::find_last_not_of(__s, __pos);
888 find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const
890 { return _Base::find_last_not_of(__c, __pos); }
893 substr(size_type __pos = 0, size_type __n = _Base::npos) const
894 { return basic_string(_Base::substr(__pos, __n)); }
897 compare(const basic_string& __str) const
898 { return _Base::compare(__str); }
901 compare(size_type __pos1, size_type __n1,
902 const basic_string& __str) const
903 { return _Base::compare(__pos1, __n1, __str); }
906 compare(size_type __pos1, size_type __n1, const basic_string& __str,
907 size_type __pos2, size_type __n2) const
908 { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); }
911 compare(const _CharT* __s) const
913 __glibcxx_check_string(__s);
914 return _Base::compare(__s);
917 // _GLIBCXX_RESOLVE_LIB_DEFECTS
918 // 5. string::compare specification questionable
920 compare(size_type __pos1, size_type __n1, const _CharT* __s) const
922 __glibcxx_check_string(__s);
923 return _Base::compare(__pos1, __n1, __s);
926 // _GLIBCXX_RESOLVE_LIB_DEFECTS
927 // 5. string::compare specification questionable
929 compare(size_type __pos1, size_type __n1,const _CharT* __s,
930 size_type __n2) const
932 __glibcxx_check_string_len(__s, __n2);
933 return _Base::compare(__pos1, __n1, __s, __n2);
937 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
940 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
942 using _Safe::_M_invalidate_all;
945 template<typename _CharT, typename _Traits, typename _Allocator>
946 inline basic_string<_CharT,_Traits,_Allocator>
947 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
948 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
949 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
951 template<typename _CharT, typename _Traits, typename _Allocator>
952 inline basic_string<_CharT,_Traits,_Allocator>
953 operator+(const _CharT* __lhs,
954 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
956 __glibcxx_check_string(__lhs);
957 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
960 template<typename _CharT, typename _Traits, typename _Allocator>
961 inline basic_string<_CharT,_Traits,_Allocator>
962 operator+(_CharT __lhs,
963 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
964 { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
966 template<typename _CharT, typename _Traits, typename _Allocator>
967 inline basic_string<_CharT,_Traits,_Allocator>
968 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
971 __glibcxx_check_string(__rhs);
972 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
975 template<typename _CharT, typename _Traits, typename _Allocator>
976 inline basic_string<_CharT,_Traits,_Allocator>
977 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
979 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
981 template<typename _CharT, typename _Traits, typename _Allocator>
983 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
984 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
985 { return __lhs._M_base() == __rhs._M_base(); }
987 template<typename _CharT, typename _Traits, typename _Allocator>
989 operator==(const _CharT* __lhs,
990 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
992 __glibcxx_check_string(__lhs);
993 return __lhs == __rhs._M_base();
996 template<typename _CharT, typename _Traits, typename _Allocator>
998 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1001 __glibcxx_check_string(__rhs);
1002 return __lhs._M_base() == __rhs;
1005 template<typename _CharT, typename _Traits, typename _Allocator>
1007 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1008 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1009 { return __lhs._M_base() != __rhs._M_base(); }
1011 template<typename _CharT, typename _Traits, typename _Allocator>
1013 operator!=(const _CharT* __lhs,
1014 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1016 __glibcxx_check_string(__lhs);
1017 return __lhs != __rhs._M_base();
1020 template<typename _CharT, typename _Traits, typename _Allocator>
1022 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1023 const _CharT* __rhs)
1025 __glibcxx_check_string(__rhs);
1026 return __lhs._M_base() != __rhs;
1029 template<typename _CharT, typename _Traits, typename _Allocator>
1031 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1032 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1033 { return __lhs._M_base() < __rhs._M_base(); }
1035 template<typename _CharT, typename _Traits, typename _Allocator>
1037 operator<(const _CharT* __lhs,
1038 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1040 __glibcxx_check_string(__lhs);
1041 return __lhs < __rhs._M_base();
1044 template<typename _CharT, typename _Traits, typename _Allocator>
1046 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1047 const _CharT* __rhs)
1049 __glibcxx_check_string(__rhs);
1050 return __lhs._M_base() < __rhs;
1053 template<typename _CharT, typename _Traits, typename _Allocator>
1055 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1056 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1057 { return __lhs._M_base() <= __rhs._M_base(); }
1059 template<typename _CharT, typename _Traits, typename _Allocator>
1061 operator<=(const _CharT* __lhs,
1062 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1064 __glibcxx_check_string(__lhs);
1065 return __lhs <= __rhs._M_base();
1068 template<typename _CharT, typename _Traits, typename _Allocator>
1070 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1071 const _CharT* __rhs)
1073 __glibcxx_check_string(__rhs);
1074 return __lhs._M_base() <= __rhs;
1077 template<typename _CharT, typename _Traits, typename _Allocator>
1079 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1080 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1081 { return __lhs._M_base() >= __rhs._M_base(); }
1083 template<typename _CharT, typename _Traits, typename _Allocator>
1085 operator>=(const _CharT* __lhs,
1086 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1088 __glibcxx_check_string(__lhs);
1089 return __lhs >= __rhs._M_base();
1092 template<typename _CharT, typename _Traits, typename _Allocator>
1094 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1095 const _CharT* __rhs)
1097 __glibcxx_check_string(__rhs);
1098 return __lhs._M_base() >= __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;
1126 template<typename _CharT, typename _Traits, typename _Allocator>
1128 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1129 basic_string<_CharT,_Traits,_Allocator>& __rhs)
1130 { __lhs.swap(__rhs); }
1132 template<typename _CharT, typename _Traits, typename _Allocator>
1133 std::basic_ostream<_CharT, _Traits>&
1134 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1135 const basic_string<_CharT, _Traits, _Allocator>& __str)
1136 { return __os << __str._M_base(); }
1138 template<typename _CharT, typename _Traits, typename _Allocator>
1139 std::basic_istream<_CharT,_Traits>&
1140 operator>>(std::basic_istream<_CharT,_Traits>& __is,
1141 basic_string<_CharT,_Traits,_Allocator>& __str)
1143 std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base();
1144 __str._M_invalidate_all();
1148 template<typename _CharT, typename _Traits, typename _Allocator>
1149 std::basic_istream<_CharT,_Traits>&
1150 getline(std::basic_istream<_CharT,_Traits>& __is,
1151 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1153 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1156 __str._M_invalidate_all();
1160 template<typename _CharT, typename _Traits, typename _Allocator>
1161 std::basic_istream<_CharT,_Traits>&
1162 getline(std::basic_istream<_CharT,_Traits>& __is,
1163 basic_string<_CharT,_Traits,_Allocator>& __str)
1165 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1167 __str._M_invalidate_all();
1171 typedef basic_string<char> string;
1173 #ifdef _GLIBCXX_USE_WCHAR_T
1174 typedef basic_string<wchar_t> wstring;
1177 template<typename _CharT, typename _Traits, typename _Allocator>
1178 struct _Insert_range_from_self_is_safe<
1179 __gnu_debug::basic_string<_CharT, _Traits, _Allocator> >
1180 { enum { __value = 1 }; };
1182 } // namespace __gnu_debug