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(
142 __glibcxx_check_valid_constructor_range(__begin, __end)),
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(const_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(const_iterator __p, size_type __n, _CharT __c)
558 __glibcxx_check_insert(__p);
559 typename _Base::iterator __res = _Base::insert(__p.base(), __n, __c);
560 this->_M_invalidate_all();
561 return iterator(__res, this);
564 template<typename _InputIterator>
566 insert(const_iterator __p, _InputIterator __first, _InputIterator __last)
568 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
569 __glibcxx_check_insert_range2(__p, __first, __last, __dist);
571 typename _Base::iterator __res;
572 if (__dist.second >= __dp_sign)
573 __res = _Base::insert(__p.base(), __gnu_debug::__unsafe(__first),
574 __gnu_debug::__unsafe(__last));
576 __res = _Base::insert(__p.base(), __first, __last);
577 this->_M_invalidate_all();
578 return iterator(__res, this);
581 #if __cplusplus >= 201103L
583 insert(const_iterator __p, std::initializer_list<_CharT> __l)
585 __glibcxx_check_insert(__p);
586 const auto __res = _Base::insert(__p.base(), __l);
587 this->_M_invalidate_all();
588 return iterator(__res, this);
593 erase(size_type __pos = 0, size_type __n = _Base::npos)
595 _Base::erase(__pos, __n);
596 this->_M_invalidate_all();
601 erase(iterator __position)
603 __glibcxx_check_erase(__position);
604 typename _Base::iterator __res = _Base::erase(__position.base());
605 this->_M_invalidate_all();
606 return iterator(__res, this);
610 erase(iterator __first, iterator __last)
612 // _GLIBCXX_RESOLVE_LIB_DEFECTS
613 // 151. can't currently clear() empty container
614 __glibcxx_check_erase_range(__first, __last);
615 typename _Base::iterator __res = _Base::erase(__first.base(),
617 this->_M_invalidate_all();
618 return iterator(__res, this);
621 #if __cplusplus >= 201103L
623 pop_back() // noexcept
625 __glibcxx_check_nonempty();
627 this->_M_invalidate_all();
632 replace(size_type __pos1, size_type __n1, const basic_string& __str)
634 _Base::replace(__pos1, __n1, __str);
635 this->_M_invalidate_all();
640 replace(size_type __pos1, size_type __n1, const basic_string& __str,
641 size_type __pos2, size_type __n2)
643 _Base::replace(__pos1, __n1, __str, __pos2, __n2);
644 this->_M_invalidate_all();
649 replace(size_type __pos, size_type __n1, const _CharT* __s,
652 __glibcxx_check_string_len(__s, __n2);
653 _Base::replace(__pos, __n1, __s, __n2);
654 this->_M_invalidate_all();
659 replace(size_type __pos, size_type __n1, const _CharT* __s)
661 __glibcxx_check_string(__s);
662 _Base::replace(__pos, __n1, __s);
663 this->_M_invalidate_all();
668 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
670 _Base::replace(__pos, __n1, __n2, __c);
671 this->_M_invalidate_all();
676 replace(iterator __i1, iterator __i2, const basic_string& __str)
678 __glibcxx_check_erase_range(__i1, __i2);
679 _Base::replace(__i1.base(), __i2.base(), __str);
680 this->_M_invalidate_all();
685 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
687 __glibcxx_check_erase_range(__i1, __i2);
688 __glibcxx_check_string_len(__s, __n);
689 _Base::replace(__i1.base(), __i2.base(), __s, __n);
690 this->_M_invalidate_all();
695 replace(iterator __i1, iterator __i2, const _CharT* __s)
697 __glibcxx_check_erase_range(__i1, __i2);
698 __glibcxx_check_string(__s);
699 _Base::replace(__i1.base(), __i2.base(), __s);
700 this->_M_invalidate_all();
705 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
707 __glibcxx_check_erase_range(__i1, __i2);
708 _Base::replace(__i1.base(), __i2.base(), __n, __c);
709 this->_M_invalidate_all();
713 template<typename _InputIterator>
715 replace(iterator __i1, iterator __i2,
716 _InputIterator __j1, _InputIterator __j2)
718 __glibcxx_check_erase_range(__i1, __i2);
720 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
721 __glibcxx_check_valid_range2(__j1, __j2, __dist);
723 if (__dist.second >= __dp_sign)
724 _Base::replace(__i1.base(), __i2.base(),
725 __gnu_debug::__unsafe(__j1),
726 __gnu_debug::__unsafe(__j2));
728 _Base::replace(__i1.base(), __i2.base(), __j1, __j2);
730 this->_M_invalidate_all();
734 #if __cplusplus >= 201103L
735 basic_string& replace(iterator __i1, iterator __i2,
736 std::initializer_list<_CharT> __l)
738 __glibcxx_check_erase_range(__i1, __i2);
739 _Base::replace(__i1.base(), __i2.base(), __l);
740 this->_M_invalidate_all();
746 copy(_CharT* __s, size_type __n, size_type __pos = 0) const
748 __glibcxx_check_string_len(__s, __n);
749 return _Base::copy(__s, __n, __pos);
753 swap(basic_string& __x)
754 _GLIBCXX_NOEXCEPT_IF(std::__is_nothrow_swappable<_Base>::value)
760 // 21.3.6 string operations:
762 c_str() const _GLIBCXX_NOEXCEPT
764 const _CharT* __res = _Base::c_str();
765 this->_M_invalidate_all();
770 data() const _GLIBCXX_NOEXCEPT
772 const _CharT* __res = _Base::data();
773 this->_M_invalidate_all();
777 using _Base::get_allocator;
780 find(const basic_string& __str, size_type __pos = 0) const
782 { return _Base::find(__str, __pos); }
785 find(const _CharT* __s, size_type __pos, size_type __n) const
787 __glibcxx_check_string(__s);
788 return _Base::find(__s, __pos, __n);
792 find(const _CharT* __s, size_type __pos = 0) const
794 __glibcxx_check_string(__s);
795 return _Base::find(__s, __pos);
799 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
800 { return _Base::find(__c, __pos); }
803 rfind(const basic_string& __str, size_type __pos = _Base::npos) const
805 { return _Base::rfind(__str, __pos); }
808 rfind(const _CharT* __s, size_type __pos, size_type __n) const
810 __glibcxx_check_string_len(__s, __n);
811 return _Base::rfind(__s, __pos, __n);
815 rfind(const _CharT* __s, size_type __pos = _Base::npos) const
817 __glibcxx_check_string(__s);
818 return _Base::rfind(__s, __pos);
822 rfind(_CharT __c, size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
823 { return _Base::rfind(__c, __pos); }
826 find_first_of(const basic_string& __str, size_type __pos = 0) const
828 { return _Base::find_first_of(__str, __pos); }
831 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
833 __glibcxx_check_string(__s);
834 return _Base::find_first_of(__s, __pos, __n);
838 find_first_of(const _CharT* __s, size_type __pos = 0) const
840 __glibcxx_check_string(__s);
841 return _Base::find_first_of(__s, __pos);
845 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
846 { return _Base::find_first_of(__c, __pos); }
849 find_last_of(const basic_string& __str,
850 size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
851 { return _Base::find_last_of(__str, __pos); }
854 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
856 __glibcxx_check_string(__s);
857 return _Base::find_last_of(__s, __pos, __n);
861 find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const
863 __glibcxx_check_string(__s);
864 return _Base::find_last_of(__s, __pos);
868 find_last_of(_CharT __c, size_type __pos = _Base::npos) const
870 { return _Base::find_last_of(__c, __pos); }
873 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
875 { return _Base::find_first_not_of(__str, __pos); }
878 find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
880 __glibcxx_check_string_len(__s, __n);
881 return _Base::find_first_not_of(__s, __pos, __n);
885 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
887 __glibcxx_check_string(__s);
888 return _Base::find_first_not_of(__s, __pos);
892 find_first_not_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
893 { return _Base::find_first_not_of(__c, __pos); }
896 find_last_not_of(const basic_string& __str,
897 size_type __pos = _Base::npos) const
899 { return _Base::find_last_not_of(__str, __pos); }
902 find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
904 __glibcxx_check_string(__s);
905 return _Base::find_last_not_of(__s, __pos, __n);
909 find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const
911 __glibcxx_check_string(__s);
912 return _Base::find_last_not_of(__s, __pos);
916 find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const
918 { return _Base::find_last_not_of(__c, __pos); }
921 substr(size_type __pos = 0, size_type __n = _Base::npos) const
922 { return basic_string(_Base::substr(__pos, __n)); }
925 compare(const basic_string& __str) const
926 { return _Base::compare(__str); }
929 compare(size_type __pos1, size_type __n1,
930 const basic_string& __str) const
931 { return _Base::compare(__pos1, __n1, __str); }
934 compare(size_type __pos1, size_type __n1, const basic_string& __str,
935 size_type __pos2, size_type __n2) const
936 { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); }
939 compare(const _CharT* __s) const
941 __glibcxx_check_string(__s);
942 return _Base::compare(__s);
945 // _GLIBCXX_RESOLVE_LIB_DEFECTS
946 // 5. string::compare specification questionable
948 compare(size_type __pos1, size_type __n1, const _CharT* __s) const
950 __glibcxx_check_string(__s);
951 return _Base::compare(__pos1, __n1, __s);
954 // _GLIBCXX_RESOLVE_LIB_DEFECTS
955 // 5. string::compare specification questionable
957 compare(size_type __pos1, size_type __n1,const _CharT* __s,
958 size_type __n2) const
960 __glibcxx_check_string_len(__s, __n2);
961 return _Base::compare(__pos1, __n1, __s, __n2);
965 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
968 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
970 using _Safe::_M_invalidate_all;
973 template<typename _CharT, typename _Traits, typename _Allocator>
974 inline basic_string<_CharT,_Traits,_Allocator>
975 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
976 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
977 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
979 template<typename _CharT, typename _Traits, typename _Allocator>
980 inline basic_string<_CharT,_Traits,_Allocator>
981 operator+(const _CharT* __lhs,
982 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
984 __glibcxx_check_string(__lhs);
985 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
988 template<typename _CharT, typename _Traits, typename _Allocator>
989 inline basic_string<_CharT,_Traits,_Allocator>
990 operator+(_CharT __lhs,
991 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
992 { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
994 template<typename _CharT, typename _Traits, typename _Allocator>
995 inline basic_string<_CharT,_Traits,_Allocator>
996 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
999 __glibcxx_check_string(__rhs);
1000 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
1003 template<typename _CharT, typename _Traits, typename _Allocator>
1004 inline basic_string<_CharT,_Traits,_Allocator>
1005 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1007 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
1009 template<typename _CharT, typename _Traits, typename _Allocator>
1011 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1012 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1013 { return __lhs._M_base() == __rhs._M_base(); }
1015 template<typename _CharT, typename _Traits, typename _Allocator>
1017 operator==(const _CharT* __lhs,
1018 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1020 __glibcxx_check_string(__lhs);
1021 return __lhs == __rhs._M_base();
1024 template<typename _CharT, typename _Traits, typename _Allocator>
1026 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1027 const _CharT* __rhs)
1029 __glibcxx_check_string(__rhs);
1030 return __lhs._M_base() == __rhs;
1033 template<typename _CharT, typename _Traits, typename _Allocator>
1035 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1036 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1037 { return __lhs._M_base() != __rhs._M_base(); }
1039 template<typename _CharT, typename _Traits, typename _Allocator>
1041 operator!=(const _CharT* __lhs,
1042 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1044 __glibcxx_check_string(__lhs);
1045 return __lhs != __rhs._M_base();
1048 template<typename _CharT, typename _Traits, typename _Allocator>
1050 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1051 const _CharT* __rhs)
1053 __glibcxx_check_string(__rhs);
1054 return __lhs._M_base() != __rhs;
1057 template<typename _CharT, typename _Traits, typename _Allocator>
1059 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1060 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1061 { return __lhs._M_base() < __rhs._M_base(); }
1063 template<typename _CharT, typename _Traits, typename _Allocator>
1065 operator<(const _CharT* __lhs,
1066 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1068 __glibcxx_check_string(__lhs);
1069 return __lhs < __rhs._M_base();
1072 template<typename _CharT, typename _Traits, typename _Allocator>
1074 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1075 const _CharT* __rhs)
1077 __glibcxx_check_string(__rhs);
1078 return __lhs._M_base() < __rhs;
1081 template<typename _CharT, typename _Traits, typename _Allocator>
1083 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1084 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1085 { return __lhs._M_base() <= __rhs._M_base(); }
1087 template<typename _CharT, typename _Traits, typename _Allocator>
1089 operator<=(const _CharT* __lhs,
1090 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1092 __glibcxx_check_string(__lhs);
1093 return __lhs <= __rhs._M_base();
1096 template<typename _CharT, typename _Traits, typename _Allocator>
1098 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1099 const _CharT* __rhs)
1101 __glibcxx_check_string(__rhs);
1102 return __lhs._M_base() <= __rhs;
1105 template<typename _CharT, typename _Traits, typename _Allocator>
1107 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1108 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1109 { return __lhs._M_base() >= __rhs._M_base(); }
1111 template<typename _CharT, typename _Traits, typename _Allocator>
1113 operator>=(const _CharT* __lhs,
1114 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1116 __glibcxx_check_string(__lhs);
1117 return __lhs >= __rhs._M_base();
1120 template<typename _CharT, typename _Traits, typename _Allocator>
1122 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1123 const _CharT* __rhs)
1125 __glibcxx_check_string(__rhs);
1126 return __lhs._M_base() >= __rhs;
1129 template<typename _CharT, typename _Traits, typename _Allocator>
1131 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1132 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1133 { return __lhs._M_base() > __rhs._M_base(); }
1135 template<typename _CharT, typename _Traits, typename _Allocator>
1137 operator>(const _CharT* __lhs,
1138 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1140 __glibcxx_check_string(__lhs);
1141 return __lhs > __rhs._M_base();
1144 template<typename _CharT, typename _Traits, typename _Allocator>
1146 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1147 const _CharT* __rhs)
1149 __glibcxx_check_string(__rhs);
1150 return __lhs._M_base() > __rhs;
1154 template<typename _CharT, typename _Traits, typename _Allocator>
1156 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1157 basic_string<_CharT,_Traits,_Allocator>& __rhs)
1158 { __lhs.swap(__rhs); }
1160 template<typename _CharT, typename _Traits, typename _Allocator>
1161 std::basic_ostream<_CharT, _Traits>&
1162 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1163 const basic_string<_CharT, _Traits, _Allocator>& __str)
1164 { return __os << __str._M_base(); }
1166 template<typename _CharT, typename _Traits, typename _Allocator>
1167 std::basic_istream<_CharT,_Traits>&
1168 operator>>(std::basic_istream<_CharT,_Traits>& __is,
1169 basic_string<_CharT,_Traits,_Allocator>& __str)
1171 std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base();
1172 __str._M_invalidate_all();
1176 template<typename _CharT, typename _Traits, typename _Allocator>
1177 std::basic_istream<_CharT,_Traits>&
1178 getline(std::basic_istream<_CharT,_Traits>& __is,
1179 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1181 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1184 __str._M_invalidate_all();
1188 template<typename _CharT, typename _Traits, typename _Allocator>
1189 std::basic_istream<_CharT,_Traits>&
1190 getline(std::basic_istream<_CharT,_Traits>& __is,
1191 basic_string<_CharT,_Traits,_Allocator>& __str)
1193 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1195 __str._M_invalidate_all();
1199 typedef basic_string<char> string;
1201 #ifdef _GLIBCXX_USE_WCHAR_T
1202 typedef basic_string<wchar_t> wstring;
1205 template<typename _CharT, typename _Traits, typename _Allocator>
1206 struct _Insert_range_from_self_is_safe<
1207 __gnu_debug::basic_string<_CharT, _Traits, _Allocator> >
1208 { enum { __value = 1 }; };
1210 } // namespace __gnu_debug