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, false>,
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, false> _Safe;
54 typedef _Traits traits_type;
55 typedef typename _Traits::char_type value_type;
56 typedef _Allocator allocator_type;
57 typedef typename _Base::size_type size_type;
58 typedef typename _Base::difference_type difference_type;
59 typedef typename _Base::reference reference;
60 typedef typename _Base::const_reference const_reference;
61 typedef typename _Base::pointer pointer;
62 typedef typename _Base::const_pointer const_pointer;
64 typedef __gnu_debug::_Safe_iterator<
65 typename _Base::iterator, basic_string> iterator;
66 typedef __gnu_debug::_Safe_iterator<
67 typename _Base::const_iterator, basic_string> const_iterator;
69 typedef std::reverse_iterator<iterator> reverse_iterator;
70 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
74 // 21.3.1 construct/copy/destroy:
75 explicit basic_string(const _Allocator& __a = _Allocator())
79 #if __cplusplus < 201103L
80 basic_string(const basic_string& __str)
85 basic_string(const basic_string&) = default;
86 basic_string(basic_string&&) = default;
88 basic_string(std::initializer_list<_CharT> __l,
89 const _Allocator& __a = _Allocator())
93 ~basic_string() = default;
96 // Provides conversion from a normal-mode string to a debug-mode string
97 basic_string(const _Base& __base)
100 // _GLIBCXX_RESOLVE_LIB_DEFECTS
101 // 42. string ctors specify wrong default allocator
102 basic_string(const basic_string& __str, size_type __pos,
103 size_type __n = _Base::npos,
104 const _Allocator& __a = _Allocator())
105 : _Base(__str, __pos, __n, __a) { }
107 basic_string(const _CharT* __s, size_type __n,
108 const _Allocator& __a = _Allocator())
109 : _Base(__gnu_debug::__check_string(__s, __n), __n, __a) { }
111 basic_string(const _CharT* __s, const _Allocator& __a = _Allocator())
112 : _Base(__gnu_debug::__check_string(__s), __a)
113 { this->assign(__s); }
115 basic_string(size_type __n, _CharT __c,
116 const _Allocator& __a = _Allocator())
117 : _Base(__n, __c, __a) { }
119 template<typename _InputIterator>
120 basic_string(_InputIterator __begin, _InputIterator __end,
121 const _Allocator& __a = _Allocator())
122 : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__begin,
124 __gnu_debug::__base(__end), __a) { }
126 #if __cplusplus < 201103L
128 operator=(const basic_string& __str)
130 this->_M_safe() = __str;
136 operator=(const basic_string&) = default;
139 operator=(basic_string&&) = default;
143 operator=(const _CharT* __s)
145 __glibcxx_check_string(__s);
147 this->_M_invalidate_all();
152 operator=(_CharT __c)
155 this->_M_invalidate_all();
159 #if __cplusplus >= 201103L
161 operator=(std::initializer_list<_CharT> __l)
164 this->_M_invalidate_all();
171 begin() // _GLIBCXX_NOEXCEPT
172 { return iterator(_Base::begin(), this); }
175 begin() const _GLIBCXX_NOEXCEPT
176 { return const_iterator(_Base::begin(), this); }
179 end() // _GLIBCXX_NOEXCEPT
180 { return iterator(_Base::end(), this); }
183 end() const _GLIBCXX_NOEXCEPT
184 { return const_iterator(_Base::end(), this); }
187 rbegin() // _GLIBCXX_NOEXCEPT
188 { return reverse_iterator(end()); }
190 const_reverse_iterator
191 rbegin() const _GLIBCXX_NOEXCEPT
192 { return const_reverse_iterator(end()); }
195 rend() // _GLIBCXX_NOEXCEPT
196 { return reverse_iterator(begin()); }
198 const_reverse_iterator
199 rend() const _GLIBCXX_NOEXCEPT
200 { return const_reverse_iterator(begin()); }
202 #if __cplusplus >= 201103L
204 cbegin() const noexcept
205 { return const_iterator(_Base::begin(), this); }
208 cend() const noexcept
209 { return const_iterator(_Base::end(), this); }
211 const_reverse_iterator
212 crbegin() const noexcept
213 { return const_reverse_iterator(end()); }
215 const_reverse_iterator
216 crend() const noexcept
217 { return const_reverse_iterator(begin()); }
223 using _Base::max_size;
226 resize(size_type __n, _CharT __c)
228 _Base::resize(__n, __c);
229 this->_M_invalidate_all();
233 resize(size_type __n)
234 { this->resize(__n, _CharT()); }
236 #if __cplusplus >= 201103L
238 shrink_to_fit() noexcept
240 if (capacity() > size())
245 this->_M_invalidate_all();
253 using _Base::capacity;
254 using _Base::reserve;
257 clear() // _GLIBCXX_NOEXCEPT
260 this->_M_invalidate_all();
265 // 21.3.4 element access:
267 operator[](size_type __pos) const _GLIBCXX_NOEXCEPT
269 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
270 _M_message(__gnu_debug::__msg_subscript_oob)
271 ._M_sequence(*this, "this")
272 ._M_integer(__pos, "__pos")
273 ._M_integer(this->size(), "size"));
274 return _M_base()[__pos];
278 operator[](size_type __pos) // _GLIBCXX_NOEXCEPT
280 #ifdef _GLIBCXX_DEBUG_PEDANTIC
281 __glibcxx_check_subscript(__pos);
283 // as an extension v3 allows s[s.size()] when s is non-const.
284 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
285 _M_message(__gnu_debug::__msg_subscript_oob)
286 ._M_sequence(*this, "this")
287 ._M_integer(__pos, "__pos")
288 ._M_integer(this->size(), "size"));
290 return _M_base()[__pos];
295 #if __cplusplus >= 201103L
302 operator+=(const basic_string& __str)
305 this->_M_invalidate_all();
310 operator+=(const _CharT* __s)
312 __glibcxx_check_string(__s);
314 this->_M_invalidate_all();
319 operator+=(_CharT __c)
322 this->_M_invalidate_all();
326 #if __cplusplus >= 201103L
328 operator+=(std::initializer_list<_CharT> __l)
331 this->_M_invalidate_all();
337 append(const basic_string& __str)
339 _Base::append(__str);
340 this->_M_invalidate_all();
345 append(const basic_string& __str, size_type __pos, size_type __n)
347 _Base::append(__str, __pos, __n);
348 this->_M_invalidate_all();
353 append(const _CharT* __s, size_type __n)
355 __glibcxx_check_string_len(__s, __n);
356 _Base::append(__s, __n);
357 this->_M_invalidate_all();
362 append(const _CharT* __s)
364 __glibcxx_check_string(__s);
366 this->_M_invalidate_all();
371 append(size_type __n, _CharT __c)
373 _Base::append(__n, __c);
374 this->_M_invalidate_all();
378 template<typename _InputIterator>
380 append(_InputIterator __first, _InputIterator __last)
382 __glibcxx_check_valid_range(__first, __last);
383 _Base::append(__gnu_debug::__base(__first),
384 __gnu_debug::__base(__last));
385 this->_M_invalidate_all();
389 // _GLIBCXX_RESOLVE_LIB_DEFECTS
390 // 7. string clause minor problems
392 push_back(_CharT __c)
394 _Base::push_back(__c);
395 this->_M_invalidate_all();
399 assign(const basic_string& __x)
402 this->_M_invalidate_all();
406 #if __cplusplus >= 201103L
408 assign(basic_string&& __x)
410 _Base::assign(std::move(__x));
411 this->_M_invalidate_all();
417 assign(const basic_string& __str, size_type __pos, size_type __n)
419 _Base::assign(__str, __pos, __n);
420 this->_M_invalidate_all();
425 assign(const _CharT* __s, size_type __n)
427 __glibcxx_check_string_len(__s, __n);
428 _Base::assign(__s, __n);
429 this->_M_invalidate_all();
434 assign(const _CharT* __s)
436 __glibcxx_check_string(__s);
438 this->_M_invalidate_all();
443 assign(size_type __n, _CharT __c)
445 _Base::assign(__n, __c);
446 this->_M_invalidate_all();
450 template<typename _InputIterator>
452 assign(_InputIterator __first, _InputIterator __last)
454 __glibcxx_check_valid_range(__first, __last);
455 _Base::assign(__gnu_debug::__base(__first),
456 __gnu_debug::__base(__last));
457 this->_M_invalidate_all();
461 #if __cplusplus >= 201103L
463 assign(std::initializer_list<_CharT> __l)
466 this->_M_invalidate_all();
472 insert(size_type __pos1, const basic_string& __str)
474 _Base::insert(__pos1, __str);
475 this->_M_invalidate_all();
480 insert(size_type __pos1, const basic_string& __str,
481 size_type __pos2, size_type __n)
483 _Base::insert(__pos1, __str, __pos2, __n);
484 this->_M_invalidate_all();
489 insert(size_type __pos, const _CharT* __s, size_type __n)
491 __glibcxx_check_string(__s);
492 _Base::insert(__pos, __s, __n);
493 this->_M_invalidate_all();
498 insert(size_type __pos, const _CharT* __s)
500 __glibcxx_check_string(__s);
501 _Base::insert(__pos, __s);
502 this->_M_invalidate_all();
507 insert(size_type __pos, size_type __n, _CharT __c)
509 _Base::insert(__pos, __n, __c);
510 this->_M_invalidate_all();
515 insert(iterator __p, _CharT __c)
517 __glibcxx_check_insert(__p);
518 typename _Base::iterator __res = _Base::insert(__p.base(), __c);
519 this->_M_invalidate_all();
520 return iterator(__res, this);
524 insert(iterator __p, size_type __n, _CharT __c)
526 __glibcxx_check_insert(__p);
527 _Base::insert(__p.base(), __n, __c);
528 this->_M_invalidate_all();
531 template<typename _InputIterator>
533 insert(iterator __p, _InputIterator __first, _InputIterator __last)
535 __glibcxx_check_insert_range(__p, __first, __last);
536 _Base::insert(__p.base(), __gnu_debug::__base(__first),
537 __gnu_debug::__base(__last));
538 this->_M_invalidate_all();
541 #if __cplusplus >= 201103L
543 insert(iterator __p, std::initializer_list<_CharT> __l)
545 __glibcxx_check_insert(__p);
546 _Base::insert(__p.base(), __l);
547 this->_M_invalidate_all();
552 erase(size_type __pos = 0, size_type __n = _Base::npos)
554 _Base::erase(__pos, __n);
555 this->_M_invalidate_all();
560 erase(iterator __position)
562 __glibcxx_check_erase(__position);
563 typename _Base::iterator __res = _Base::erase(__position.base());
564 this->_M_invalidate_all();
565 return iterator(__res, this);
569 erase(iterator __first, iterator __last)
571 // _GLIBCXX_RESOLVE_LIB_DEFECTS
572 // 151. can't currently clear() empty container
573 __glibcxx_check_erase_range(__first, __last);
574 typename _Base::iterator __res = _Base::erase(__first.base(),
576 this->_M_invalidate_all();
577 return iterator(__res, this);
580 #if __cplusplus >= 201103L
582 pop_back() // noexcept
584 __glibcxx_check_nonempty();
586 this->_M_invalidate_all();
591 replace(size_type __pos1, size_type __n1, const basic_string& __str)
593 _Base::replace(__pos1, __n1, __str);
594 this->_M_invalidate_all();
599 replace(size_type __pos1, size_type __n1, const basic_string& __str,
600 size_type __pos2, size_type __n2)
602 _Base::replace(__pos1, __n1, __str, __pos2, __n2);
603 this->_M_invalidate_all();
608 replace(size_type __pos, size_type __n1, const _CharT* __s,
611 __glibcxx_check_string_len(__s, __n2);
612 _Base::replace(__pos, __n1, __s, __n2);
613 this->_M_invalidate_all();
618 replace(size_type __pos, size_type __n1, const _CharT* __s)
620 __glibcxx_check_string(__s);
621 _Base::replace(__pos, __n1, __s);
622 this->_M_invalidate_all();
627 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
629 _Base::replace(__pos, __n1, __n2, __c);
630 this->_M_invalidate_all();
635 replace(iterator __i1, iterator __i2, const basic_string& __str)
637 __glibcxx_check_erase_range(__i1, __i2);
638 _Base::replace(__i1.base(), __i2.base(), __str);
639 this->_M_invalidate_all();
644 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
646 __glibcxx_check_erase_range(__i1, __i2);
647 __glibcxx_check_string_len(__s, __n);
648 _Base::replace(__i1.base(), __i2.base(), __s, __n);
649 this->_M_invalidate_all();
654 replace(iterator __i1, iterator __i2, const _CharT* __s)
656 __glibcxx_check_erase_range(__i1, __i2);
657 __glibcxx_check_string(__s);
658 _Base::replace(__i1.base(), __i2.base(), __s);
659 this->_M_invalidate_all();
664 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
666 __glibcxx_check_erase_range(__i1, __i2);
667 _Base::replace(__i1.base(), __i2.base(), __n, __c);
668 this->_M_invalidate_all();
672 template<typename _InputIterator>
674 replace(iterator __i1, iterator __i2,
675 _InputIterator __j1, _InputIterator __j2)
677 __glibcxx_check_erase_range(__i1, __i2);
678 __glibcxx_check_valid_range(__j1, __j2);
679 _Base::replace(__i1.base(), __i2.base(), __j1, __j2);
680 this->_M_invalidate_all();
684 #if __cplusplus >= 201103L
685 basic_string& replace(iterator __i1, iterator __i2,
686 std::initializer_list<_CharT> __l)
688 __glibcxx_check_erase_range(__i1, __i2);
689 _Base::replace(__i1.base(), __i2.base(), __l);
690 this->_M_invalidate_all();
696 copy(_CharT* __s, size_type __n, size_type __pos = 0) const
698 __glibcxx_check_string_len(__s, __n);
699 return _Base::copy(__s, __n, __pos);
703 swap(basic_string& __x)
709 // 21.3.6 string operations:
711 c_str() const _GLIBCXX_NOEXCEPT
713 const _CharT* __res = _Base::c_str();
714 this->_M_invalidate_all();
719 data() const _GLIBCXX_NOEXCEPT
721 const _CharT* __res = _Base::data();
722 this->_M_invalidate_all();
726 using _Base::get_allocator;
729 find(const basic_string& __str, size_type __pos = 0) const
731 { return _Base::find(__str, __pos); }
734 find(const _CharT* __s, size_type __pos, size_type __n) const
736 __glibcxx_check_string(__s);
737 return _Base::find(__s, __pos, __n);
741 find(const _CharT* __s, size_type __pos = 0) const
743 __glibcxx_check_string(__s);
744 return _Base::find(__s, __pos);
748 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
749 { return _Base::find(__c, __pos); }
752 rfind(const basic_string& __str, size_type __pos = _Base::npos) const
754 { return _Base::rfind(__str, __pos); }
757 rfind(const _CharT* __s, size_type __pos, size_type __n) const
759 __glibcxx_check_string_len(__s, __n);
760 return _Base::rfind(__s, __pos, __n);
764 rfind(const _CharT* __s, size_type __pos = _Base::npos) const
766 __glibcxx_check_string(__s);
767 return _Base::rfind(__s, __pos);
771 rfind(_CharT __c, size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
772 { return _Base::rfind(__c, __pos); }
775 find_first_of(const basic_string& __str, size_type __pos = 0) const
777 { return _Base::find_first_of(__str, __pos); }
780 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
782 __glibcxx_check_string(__s);
783 return _Base::find_first_of(__s, __pos, __n);
787 find_first_of(const _CharT* __s, size_type __pos = 0) const
789 __glibcxx_check_string(__s);
790 return _Base::find_first_of(__s, __pos);
794 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
795 { return _Base::find_first_of(__c, __pos); }
798 find_last_of(const basic_string& __str,
799 size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
800 { return _Base::find_last_of(__str, __pos); }
803 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
805 __glibcxx_check_string(__s);
806 return _Base::find_last_of(__s, __pos, __n);
810 find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const
812 __glibcxx_check_string(__s);
813 return _Base::find_last_of(__s, __pos);
817 find_last_of(_CharT __c, size_type __pos = _Base::npos) const
819 { return _Base::find_last_of(__c, __pos); }
822 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
824 { return _Base::find_first_not_of(__str, __pos); }
827 find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
829 __glibcxx_check_string_len(__s, __n);
830 return _Base::find_first_not_of(__s, __pos, __n);
834 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
836 __glibcxx_check_string(__s);
837 return _Base::find_first_not_of(__s, __pos);
841 find_first_not_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
842 { return _Base::find_first_not_of(__c, __pos); }
845 find_last_not_of(const basic_string& __str,
846 size_type __pos = _Base::npos) const
848 { return _Base::find_last_not_of(__str, __pos); }
851 find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
853 __glibcxx_check_string(__s);
854 return _Base::find_last_not_of(__s, __pos, __n);
858 find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const
860 __glibcxx_check_string(__s);
861 return _Base::find_last_not_of(__s, __pos);
865 find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const
867 { return _Base::find_last_not_of(__c, __pos); }
870 substr(size_type __pos = 0, size_type __n = _Base::npos) const
871 { return basic_string(_Base::substr(__pos, __n)); }
874 compare(const basic_string& __str) const
875 { return _Base::compare(__str); }
878 compare(size_type __pos1, size_type __n1,
879 const basic_string& __str) const
880 { return _Base::compare(__pos1, __n1, __str); }
883 compare(size_type __pos1, size_type __n1, const basic_string& __str,
884 size_type __pos2, size_type __n2) const
885 { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); }
888 compare(const _CharT* __s) const
890 __glibcxx_check_string(__s);
891 return _Base::compare(__s);
894 // _GLIBCXX_RESOLVE_LIB_DEFECTS
895 // 5. string::compare specification questionable
897 compare(size_type __pos1, size_type __n1, const _CharT* __s) const
899 __glibcxx_check_string(__s);
900 return _Base::compare(__pos1, __n1, __s);
903 // _GLIBCXX_RESOLVE_LIB_DEFECTS
904 // 5. string::compare specification questionable
906 compare(size_type __pos1, size_type __n1,const _CharT* __s,
907 size_type __n2) const
909 __glibcxx_check_string_len(__s, __n2);
910 return _Base::compare(__pos1, __n1, __s, __n2);
914 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
917 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
919 using _Safe::_M_invalidate_all;
922 template<typename _CharT, typename _Traits, typename _Allocator>
923 inline basic_string<_CharT,_Traits,_Allocator>
924 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
925 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
926 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
928 template<typename _CharT, typename _Traits, typename _Allocator>
929 inline basic_string<_CharT,_Traits,_Allocator>
930 operator+(const _CharT* __lhs,
931 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
933 __glibcxx_check_string(__lhs);
934 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
937 template<typename _CharT, typename _Traits, typename _Allocator>
938 inline basic_string<_CharT,_Traits,_Allocator>
939 operator+(_CharT __lhs,
940 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
941 { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
943 template<typename _CharT, typename _Traits, typename _Allocator>
944 inline basic_string<_CharT,_Traits,_Allocator>
945 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
948 __glibcxx_check_string(__rhs);
949 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
952 template<typename _CharT, typename _Traits, typename _Allocator>
953 inline basic_string<_CharT,_Traits,_Allocator>
954 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
956 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
958 template<typename _CharT, typename _Traits, typename _Allocator>
960 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
961 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
962 { return __lhs._M_base() == __rhs._M_base(); }
964 template<typename _CharT, typename _Traits, typename _Allocator>
966 operator==(const _CharT* __lhs,
967 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
969 __glibcxx_check_string(__lhs);
970 return __lhs == __rhs._M_base();
973 template<typename _CharT, typename _Traits, typename _Allocator>
975 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
978 __glibcxx_check_string(__rhs);
979 return __lhs._M_base() == __rhs;
982 template<typename _CharT, typename _Traits, typename _Allocator>
984 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
985 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
986 { return __lhs._M_base() != __rhs._M_base(); }
988 template<typename _CharT, typename _Traits, typename _Allocator>
990 operator!=(const _CharT* __lhs,
991 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
993 __glibcxx_check_string(__lhs);
994 return __lhs != __rhs._M_base();
997 template<typename _CharT, typename _Traits, typename _Allocator>
999 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1000 const _CharT* __rhs)
1002 __glibcxx_check_string(__rhs);
1003 return __lhs._M_base() != __rhs;
1006 template<typename _CharT, typename _Traits, typename _Allocator>
1008 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1009 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1010 { return __lhs._M_base() < __rhs._M_base(); }
1012 template<typename _CharT, typename _Traits, typename _Allocator>
1014 operator<(const _CharT* __lhs,
1015 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1017 __glibcxx_check_string(__lhs);
1018 return __lhs < __rhs._M_base();
1021 template<typename _CharT, typename _Traits, typename _Allocator>
1023 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1024 const _CharT* __rhs)
1026 __glibcxx_check_string(__rhs);
1027 return __lhs._M_base() < __rhs;
1030 template<typename _CharT, typename _Traits, typename _Allocator>
1032 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1033 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1034 { return __lhs._M_base() <= __rhs._M_base(); }
1036 template<typename _CharT, typename _Traits, typename _Allocator>
1038 operator<=(const _CharT* __lhs,
1039 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1041 __glibcxx_check_string(__lhs);
1042 return __lhs <= __rhs._M_base();
1045 template<typename _CharT, typename _Traits, typename _Allocator>
1047 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1048 const _CharT* __rhs)
1050 __glibcxx_check_string(__rhs);
1051 return __lhs._M_base() <= __rhs;
1054 template<typename _CharT, typename _Traits, typename _Allocator>
1056 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1057 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1058 { return __lhs._M_base() >= __rhs._M_base(); }
1060 template<typename _CharT, typename _Traits, typename _Allocator>
1062 operator>=(const _CharT* __lhs,
1063 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1065 __glibcxx_check_string(__lhs);
1066 return __lhs >= __rhs._M_base();
1069 template<typename _CharT, typename _Traits, typename _Allocator>
1071 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1072 const _CharT* __rhs)
1074 __glibcxx_check_string(__rhs);
1075 return __lhs._M_base() >= __rhs;
1078 template<typename _CharT, typename _Traits, typename _Allocator>
1080 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1081 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1082 { return __lhs._M_base() > __rhs._M_base(); }
1084 template<typename _CharT, typename _Traits, typename _Allocator>
1086 operator>(const _CharT* __lhs,
1087 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1089 __glibcxx_check_string(__lhs);
1090 return __lhs > __rhs._M_base();
1093 template<typename _CharT, typename _Traits, typename _Allocator>
1095 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1096 const _CharT* __rhs)
1098 __glibcxx_check_string(__rhs);
1099 return __lhs._M_base() > __rhs;
1103 template<typename _CharT, typename _Traits, typename _Allocator>
1105 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1106 basic_string<_CharT,_Traits,_Allocator>& __rhs)
1107 { __lhs.swap(__rhs); }
1109 template<typename _CharT, typename _Traits, typename _Allocator>
1110 std::basic_ostream<_CharT, _Traits>&
1111 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1112 const basic_string<_CharT, _Traits, _Allocator>& __str)
1113 { return __os << __str._M_base(); }
1115 template<typename _CharT, typename _Traits, typename _Allocator>
1116 std::basic_istream<_CharT,_Traits>&
1117 operator>>(std::basic_istream<_CharT,_Traits>& __is,
1118 basic_string<_CharT,_Traits,_Allocator>& __str)
1120 std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base();
1121 __str._M_invalidate_all();
1125 template<typename _CharT, typename _Traits, typename _Allocator>
1126 std::basic_istream<_CharT,_Traits>&
1127 getline(std::basic_istream<_CharT,_Traits>& __is,
1128 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1130 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1133 __str._M_invalidate_all();
1137 template<typename _CharT, typename _Traits, typename _Allocator>
1138 std::basic_istream<_CharT,_Traits>&
1139 getline(std::basic_istream<_CharT,_Traits>& __is,
1140 basic_string<_CharT,_Traits,_Allocator>& __str)
1142 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1144 __str._M_invalidate_all();
1148 typedef basic_string<char> string;
1150 #ifdef _GLIBCXX_USE_WCHAR_T
1151 typedef basic_string<wchar_t> wstring;
1154 template<typename _CharT, typename _Traits, typename _Allocator>
1155 struct _Insert_range_from_self_is_safe<
1156 __gnu_debug::basic_string<_CharT, _Traits, _Allocator> >
1157 { enum { __value = 1 }; };
1159 } // namespace __gnu_debug