1 // Debugging string implementation -*- C++ -*-
3 // Copyright (C) 2003-2018 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>
41 /// Class std::basic_string with safety/checking/debug instrumentation.
42 template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
43 typename _Allocator = std::allocator<_CharT> >
45 : public __gnu_debug::_Safe_container<
46 basic_string<_CharT, _Traits, _Allocator>,
47 _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>,
48 public std::basic_string<_CharT, _Traits, _Allocator>
50 typedef std::basic_string<_CharT, _Traits, _Allocator> _Base;
51 typedef __gnu_debug::_Safe_container<
52 basic_string, _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>
57 typedef _Traits traits_type;
58 typedef typename _Traits::char_type value_type;
59 typedef _Allocator allocator_type;
60 typedef typename _Base::size_type size_type;
61 typedef typename _Base::difference_type difference_type;
62 typedef typename _Base::reference reference;
63 typedef typename _Base::const_reference const_reference;
64 typedef typename _Base::pointer pointer;
65 typedef typename _Base::const_pointer const_pointer;
67 typedef __gnu_debug::_Safe_iterator<
68 typename _Base::iterator, basic_string> iterator;
69 typedef __gnu_debug::_Safe_iterator<
70 typename _Base::const_iterator, basic_string> const_iterator;
72 typedef std::reverse_iterator<iterator> reverse_iterator;
73 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
78 _GLIBCXX_NOEXCEPT_IF(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 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
402 __glibcxx_check_valid_range2(__first, __last, __dist);
404 if (__dist.second >= __dp_sign)
405 _Base::append(__gnu_debug::__unsafe(__first),
406 __gnu_debug::__unsafe(__last));
408 _Base::append(__first, __last);
410 this->_M_invalidate_all();
414 // _GLIBCXX_RESOLVE_LIB_DEFECTS
415 // 7. string clause minor problems
417 push_back(_CharT __c)
419 _Base::push_back(__c);
420 this->_M_invalidate_all();
424 assign(const basic_string& __x)
427 this->_M_invalidate_all();
431 #if __cplusplus >= 201103L
433 assign(basic_string&& __x)
434 noexcept(noexcept(std::declval<_Base&>().assign(std::move(__x))))
436 _Base::assign(std::move(__x));
437 this->_M_invalidate_all();
443 assign(const basic_string& __str, size_type __pos, size_type __n)
445 _Base::assign(__str, __pos, __n);
446 this->_M_invalidate_all();
451 assign(const _CharT* __s, size_type __n)
453 __glibcxx_check_string_len(__s, __n);
454 _Base::assign(__s, __n);
455 this->_M_invalidate_all();
460 assign(const _CharT* __s)
462 __glibcxx_check_string(__s);
464 this->_M_invalidate_all();
469 assign(size_type __n, _CharT __c)
471 _Base::assign(__n, __c);
472 this->_M_invalidate_all();
476 template<typename _InputIterator>
478 assign(_InputIterator __first, _InputIterator __last)
480 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
481 __glibcxx_check_valid_range2(__first, __last, __dist);
483 if (__dist.second >= __dp_sign)
484 _Base::assign(__gnu_debug::__unsafe(__first),
485 __gnu_debug::__unsafe(__last));
487 _Base::assign(__first, __last);
489 this->_M_invalidate_all();
493 #if __cplusplus >= 201103L
495 assign(std::initializer_list<_CharT> __l)
498 this->_M_invalidate_all();
504 insert(size_type __pos1, const basic_string& __str)
506 _Base::insert(__pos1, __str);
507 this->_M_invalidate_all();
512 insert(size_type __pos1, const basic_string& __str,
513 size_type __pos2, size_type __n)
515 _Base::insert(__pos1, __str, __pos2, __n);
516 this->_M_invalidate_all();
521 insert(size_type __pos, const _CharT* __s, size_type __n)
523 __glibcxx_check_string(__s);
524 _Base::insert(__pos, __s, __n);
525 this->_M_invalidate_all();
530 insert(size_type __pos, const _CharT* __s)
532 __glibcxx_check_string(__s);
533 _Base::insert(__pos, __s);
534 this->_M_invalidate_all();
539 insert(size_type __pos, size_type __n, _CharT __c)
541 _Base::insert(__pos, __n, __c);
542 this->_M_invalidate_all();
547 insert(iterator __p, _CharT __c)
549 __glibcxx_check_insert(__p);
550 typename _Base::iterator __res = _Base::insert(__p.base(), __c);
551 this->_M_invalidate_all();
552 return iterator(__res, this);
556 insert(iterator __p, size_type __n, _CharT __c)
558 __glibcxx_check_insert(__p);
559 _Base::insert(__p.base(), __n, __c);
560 this->_M_invalidate_all();
563 template<typename _InputIterator>
565 insert(iterator __p, _InputIterator __first, _InputIterator __last)
567 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
568 __glibcxx_check_insert_range(__p, __first, __last, __dist);
570 if (__dist.second >= __dp_sign)
571 _Base::insert(__p.base(), __gnu_debug::__unsafe(__first),
572 __gnu_debug::__unsafe(__last));
574 _Base::insert(__p.base(), __first, __last);
576 this->_M_invalidate_all();
579 #if __cplusplus >= 201103L
581 insert(iterator __p, std::initializer_list<_CharT> __l)
583 __glibcxx_check_insert(__p);
584 _Base::insert(__p.base(), __l);
585 this->_M_invalidate_all();
590 erase(size_type __pos = 0, size_type __n = _Base::npos)
592 _Base::erase(__pos, __n);
593 this->_M_invalidate_all();
598 erase(iterator __position)
600 __glibcxx_check_erase(__position);
601 typename _Base::iterator __res = _Base::erase(__position.base());
602 this->_M_invalidate_all();
603 return iterator(__res, this);
607 erase(iterator __first, iterator __last)
609 // _GLIBCXX_RESOLVE_LIB_DEFECTS
610 // 151. can't currently clear() empty container
611 __glibcxx_check_erase_range(__first, __last);
612 typename _Base::iterator __res = _Base::erase(__first.base(),
614 this->_M_invalidate_all();
615 return iterator(__res, this);
618 #if __cplusplus >= 201103L
620 pop_back() // noexcept
622 __glibcxx_check_nonempty();
624 this->_M_invalidate_all();
629 replace(size_type __pos1, size_type __n1, const basic_string& __str)
631 _Base::replace(__pos1, __n1, __str);
632 this->_M_invalidate_all();
637 replace(size_type __pos1, size_type __n1, const basic_string& __str,
638 size_type __pos2, size_type __n2)
640 _Base::replace(__pos1, __n1, __str, __pos2, __n2);
641 this->_M_invalidate_all();
646 replace(size_type __pos, size_type __n1, const _CharT* __s,
649 __glibcxx_check_string_len(__s, __n2);
650 _Base::replace(__pos, __n1, __s, __n2);
651 this->_M_invalidate_all();
656 replace(size_type __pos, size_type __n1, const _CharT* __s)
658 __glibcxx_check_string(__s);
659 _Base::replace(__pos, __n1, __s);
660 this->_M_invalidate_all();
665 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
667 _Base::replace(__pos, __n1, __n2, __c);
668 this->_M_invalidate_all();
673 replace(iterator __i1, iterator __i2, const basic_string& __str)
675 __glibcxx_check_erase_range(__i1, __i2);
676 _Base::replace(__i1.base(), __i2.base(), __str);
677 this->_M_invalidate_all();
682 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
684 __glibcxx_check_erase_range(__i1, __i2);
685 __glibcxx_check_string_len(__s, __n);
686 _Base::replace(__i1.base(), __i2.base(), __s, __n);
687 this->_M_invalidate_all();
692 replace(iterator __i1, iterator __i2, const _CharT* __s)
694 __glibcxx_check_erase_range(__i1, __i2);
695 __glibcxx_check_string(__s);
696 _Base::replace(__i1.base(), __i2.base(), __s);
697 this->_M_invalidate_all();
702 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
704 __glibcxx_check_erase_range(__i1, __i2);
705 _Base::replace(__i1.base(), __i2.base(), __n, __c);
706 this->_M_invalidate_all();
710 template<typename _InputIterator>
712 replace(iterator __i1, iterator __i2,
713 _InputIterator __j1, _InputIterator __j2)
715 __glibcxx_check_erase_range(__i1, __i2);
717 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
718 __glibcxx_check_valid_range2(__j1, __j2, __dist);
720 if (__dist.second >= __dp_sign)
721 _Base::replace(__i1.base(), __i2.base(),
722 __gnu_debug::__unsafe(__j1),
723 __gnu_debug::__unsafe(__j2));
725 _Base::replace(__i1.base(), __i2.base(), __j1, __j2);
727 this->_M_invalidate_all();
731 #if __cplusplus >= 201103L
732 basic_string& replace(iterator __i1, iterator __i2,
733 std::initializer_list<_CharT> __l)
735 __glibcxx_check_erase_range(__i1, __i2);
736 _Base::replace(__i1.base(), __i2.base(), __l);
737 this->_M_invalidate_all();
743 copy(_CharT* __s, size_type __n, size_type __pos = 0) const
745 __glibcxx_check_string_len(__s, __n);
746 return _Base::copy(__s, __n, __pos);
750 swap(basic_string& __x)
751 _GLIBCXX_NOEXCEPT_IF(std::__is_nothrow_swappable<_Base>::value)
757 // 21.3.6 string operations:
759 c_str() const _GLIBCXX_NOEXCEPT
761 const _CharT* __res = _Base::c_str();
762 this->_M_invalidate_all();
767 data() const _GLIBCXX_NOEXCEPT
769 const _CharT* __res = _Base::data();
770 this->_M_invalidate_all();
774 using _Base::get_allocator;
777 find(const basic_string& __str, size_type __pos = 0) const
779 { return _Base::find(__str, __pos); }
782 find(const _CharT* __s, size_type __pos, size_type __n) const
784 __glibcxx_check_string(__s);
785 return _Base::find(__s, __pos, __n);
789 find(const _CharT* __s, size_type __pos = 0) const
791 __glibcxx_check_string(__s);
792 return _Base::find(__s, __pos);
796 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
797 { return _Base::find(__c, __pos); }
800 rfind(const basic_string& __str, size_type __pos = _Base::npos) const
802 { return _Base::rfind(__str, __pos); }
805 rfind(const _CharT* __s, size_type __pos, size_type __n) const
807 __glibcxx_check_string_len(__s, __n);
808 return _Base::rfind(__s, __pos, __n);
812 rfind(const _CharT* __s, size_type __pos = _Base::npos) const
814 __glibcxx_check_string(__s);
815 return _Base::rfind(__s, __pos);
819 rfind(_CharT __c, size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
820 { return _Base::rfind(__c, __pos); }
823 find_first_of(const basic_string& __str, size_type __pos = 0) const
825 { return _Base::find_first_of(__str, __pos); }
828 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
830 __glibcxx_check_string(__s);
831 return _Base::find_first_of(__s, __pos, __n);
835 find_first_of(const _CharT* __s, size_type __pos = 0) const
837 __glibcxx_check_string(__s);
838 return _Base::find_first_of(__s, __pos);
842 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
843 { return _Base::find_first_of(__c, __pos); }
846 find_last_of(const basic_string& __str,
847 size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
848 { return _Base::find_last_of(__str, __pos); }
851 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
853 __glibcxx_check_string(__s);
854 return _Base::find_last_of(__s, __pos, __n);
858 find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const
860 __glibcxx_check_string(__s);
861 return _Base::find_last_of(__s, __pos);
865 find_last_of(_CharT __c, size_type __pos = _Base::npos) const
867 { return _Base::find_last_of(__c, __pos); }
870 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
872 { return _Base::find_first_not_of(__str, __pos); }
875 find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
877 __glibcxx_check_string_len(__s, __n);
878 return _Base::find_first_not_of(__s, __pos, __n);
882 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
884 __glibcxx_check_string(__s);
885 return _Base::find_first_not_of(__s, __pos);
889 find_first_not_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
890 { return _Base::find_first_not_of(__c, __pos); }
893 find_last_not_of(const basic_string& __str,
894 size_type __pos = _Base::npos) const
896 { return _Base::find_last_not_of(__str, __pos); }
899 find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
901 __glibcxx_check_string(__s);
902 return _Base::find_last_not_of(__s, __pos, __n);
906 find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const
908 __glibcxx_check_string(__s);
909 return _Base::find_last_not_of(__s, __pos);
913 find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const
915 { return _Base::find_last_not_of(__c, __pos); }
918 substr(size_type __pos = 0, size_type __n = _Base::npos) const
919 { return basic_string(_Base::substr(__pos, __n)); }
922 compare(const basic_string& __str) const
923 { return _Base::compare(__str); }
926 compare(size_type __pos1, size_type __n1,
927 const basic_string& __str) const
928 { return _Base::compare(__pos1, __n1, __str); }
931 compare(size_type __pos1, size_type __n1, const basic_string& __str,
932 size_type __pos2, size_type __n2) const
933 { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); }
936 compare(const _CharT* __s) const
938 __glibcxx_check_string(__s);
939 return _Base::compare(__s);
942 // _GLIBCXX_RESOLVE_LIB_DEFECTS
943 // 5. string::compare specification questionable
945 compare(size_type __pos1, size_type __n1, const _CharT* __s) const
947 __glibcxx_check_string(__s);
948 return _Base::compare(__pos1, __n1, __s);
951 // _GLIBCXX_RESOLVE_LIB_DEFECTS
952 // 5. string::compare specification questionable
954 compare(size_type __pos1, size_type __n1,const _CharT* __s,
955 size_type __n2) const
957 __glibcxx_check_string_len(__s, __n2);
958 return _Base::compare(__pos1, __n1, __s, __n2);
962 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
965 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
967 using _Safe::_M_invalidate_all;
970 template<typename _CharT, typename _Traits, typename _Allocator>
971 inline basic_string<_CharT,_Traits,_Allocator>
972 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
973 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
974 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
976 template<typename _CharT, typename _Traits, typename _Allocator>
977 inline basic_string<_CharT,_Traits,_Allocator>
978 operator+(const _CharT* __lhs,
979 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
981 __glibcxx_check_string(__lhs);
982 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
985 template<typename _CharT, typename _Traits, typename _Allocator>
986 inline basic_string<_CharT,_Traits,_Allocator>
987 operator+(_CharT __lhs,
988 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
989 { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
991 template<typename _CharT, typename _Traits, typename _Allocator>
992 inline basic_string<_CharT,_Traits,_Allocator>
993 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
996 __glibcxx_check_string(__rhs);
997 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
1000 template<typename _CharT, typename _Traits, typename _Allocator>
1001 inline basic_string<_CharT,_Traits,_Allocator>
1002 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1004 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __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;
1102 template<typename _CharT, typename _Traits, typename _Allocator>
1104 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1105 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1106 { return __lhs._M_base() >= __rhs._M_base(); }
1108 template<typename _CharT, typename _Traits, typename _Allocator>
1110 operator>=(const _CharT* __lhs,
1111 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1113 __glibcxx_check_string(__lhs);
1114 return __lhs >= __rhs._M_base();
1117 template<typename _CharT, typename _Traits, typename _Allocator>
1119 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1120 const _CharT* __rhs)
1122 __glibcxx_check_string(__rhs);
1123 return __lhs._M_base() >= __rhs;
1126 template<typename _CharT, typename _Traits, typename _Allocator>
1128 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1129 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1130 { return __lhs._M_base() > __rhs._M_base(); }
1132 template<typename _CharT, typename _Traits, typename _Allocator>
1134 operator>(const _CharT* __lhs,
1135 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1137 __glibcxx_check_string(__lhs);
1138 return __lhs > __rhs._M_base();
1141 template<typename _CharT, typename _Traits, typename _Allocator>
1143 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1144 const _CharT* __rhs)
1146 __glibcxx_check_string(__rhs);
1147 return __lhs._M_base() > __rhs;
1151 template<typename _CharT, typename _Traits, typename _Allocator>
1153 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1154 basic_string<_CharT,_Traits,_Allocator>& __rhs)
1155 { __lhs.swap(__rhs); }
1157 template<typename _CharT, typename _Traits, typename _Allocator>
1158 std::basic_ostream<_CharT, _Traits>&
1159 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1160 const basic_string<_CharT, _Traits, _Allocator>& __str)
1161 { return __os << __str._M_base(); }
1163 template<typename _CharT, typename _Traits, typename _Allocator>
1164 std::basic_istream<_CharT,_Traits>&
1165 operator>>(std::basic_istream<_CharT,_Traits>& __is,
1166 basic_string<_CharT,_Traits,_Allocator>& __str)
1168 std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base();
1169 __str._M_invalidate_all();
1173 template<typename _CharT, typename _Traits, typename _Allocator>
1174 std::basic_istream<_CharT,_Traits>&
1175 getline(std::basic_istream<_CharT,_Traits>& __is,
1176 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1178 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1181 __str._M_invalidate_all();
1185 template<typename _CharT, typename _Traits, typename _Allocator>
1186 std::basic_istream<_CharT,_Traits>&
1187 getline(std::basic_istream<_CharT,_Traits>& __is,
1188 basic_string<_CharT,_Traits,_Allocator>& __str)
1190 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1192 __str._M_invalidate_all();
1196 typedef basic_string<char> string;
1198 #ifdef _GLIBCXX_USE_WCHAR_T
1199 typedef basic_string<wchar_t> wstring;
1202 template<typename _CharT, typename _Traits, typename _Allocator>
1203 struct _Insert_range_from_self_is_safe<
1204 __gnu_debug::basic_string<_CharT, _Traits, _Allocator> >
1205 { enum { __value = 1 }; };
1207 } // namespace __gnu_debug