Remove outermost loop parameter.
[official-gcc/graphite-test-results.git] / libstdc++-v3 / include / debug / string
blobfe31ffb99ed3b2fca97bc17af49318da04eb6fa3
1 // Debugging string implementation -*- C++ -*-
3 // Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24 // <http://www.gnu.org/licenses/>.
26 /** @file debug/string
27  *  This file is a GNU debug extension to the Standard C++ Library.
28  */
30 #ifndef _GLIBCXX_DEBUG_STRING
31 #define _GLIBCXX_DEBUG_STRING 1
33 #include <string>
34 #include <debug/safe_sequence.h>
35 #include <debug/safe_iterator.h>
37 namespace __gnu_debug
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> >
42     class basic_string
43     : public std::basic_string<_CharT, _Traits, _Allocator>,
44       public __gnu_debug::_Safe_sequence<basic_string<_CharT, _Traits,
45                                                       _Allocator> >
46     {
47       typedef std::basic_string<_CharT, _Traits, _Allocator> _Base;
48       typedef __gnu_debug::_Safe_sequence<basic_string>     _Safe_base;
50   public:
51     // types:
52     typedef _Traits                                    traits_type;
53     typedef typename _Traits::char_type                value_type;
54     typedef _Allocator                                 allocator_type;
55     typedef typename _Base::size_type                  size_type;
56     typedef typename _Base::difference_type            difference_type;
57     typedef typename _Base::reference                  reference;
58     typedef typename _Base::const_reference            const_reference;
59     typedef typename _Base::pointer                    pointer;
60     typedef typename _Base::const_pointer              const_pointer;
62     typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, basic_string>
63                                                        iterator;
64     typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator,
65                                          basic_string> const_iterator;
67     typedef std::reverse_iterator<iterator>            reverse_iterator;
68     typedef std::reverse_iterator<const_iterator>      const_reverse_iterator;
70     using _Base::npos;
72     // 21.3.1 construct/copy/destroy:
73     explicit basic_string(const _Allocator& __a = _Allocator())
74     : _Base(__a)
75     { }
77     // Provides conversion from a release-mode string to a debug-mode string
78     basic_string(const _Base& __base) : _Base(__base), _Safe_base() { }
80     // _GLIBCXX_RESOLVE_LIB_DEFECTS
81     // 42. string ctors specify wrong default allocator
82     basic_string(const basic_string& __str)
83     : _Base(__str, 0, _Base::npos, __str.get_allocator()), _Safe_base()
84     { }
86     // _GLIBCXX_RESOLVE_LIB_DEFECTS
87     // 42. string ctors specify wrong default allocator
88     basic_string(const basic_string& __str, size_type __pos,
89                    size_type __n = _Base::npos,
90                    const _Allocator& __a = _Allocator())
91     : _Base(__str, __pos, __n, __a)
92     { }
94     basic_string(const _CharT* __s, size_type __n,
95                    const _Allocator& __a = _Allocator())
96     : _Base(__gnu_debug::__check_string(__s, __n), __n, __a)
97     { }
99     basic_string(const _CharT* __s, const _Allocator& __a = _Allocator())
100     : _Base(__gnu_debug::__check_string(__s), __a)
101     { this->assign(__s); }
103     basic_string(size_type __n, _CharT __c,
104                    const _Allocator& __a = _Allocator())
105     : _Base(__n, __c, __a)
106     { }
108     template<typename _InputIterator>
109       basic_string(_InputIterator __begin, _InputIterator __end,
110                      const _Allocator& __a = _Allocator())
111       : _Base(__gnu_debug::__check_valid_range(__begin, __end), __end, __a)
112       { }
114 #ifdef __GXX_EXPERIMENTAL_CXX0X__
115     basic_string(basic_string&& __str)
116     : _Base(std::forward<_Base>(__str))
117     { }
119     basic_string(std::initializer_list<_CharT> __l,
120                  const _Allocator& __a = _Allocator())
121     : _Base(__l, __a)
122     { }
123 #endif // __GXX_EXPERIMENTAL_CXX0X__
125     ~basic_string() { }
127     basic_string&
128     operator=(const basic_string& __str)
129     {
130       *static_cast<_Base*>(this) = __str;
131       this->_M_invalidate_all();
132       return *this;
133     }
135     basic_string&
136     operator=(const _CharT* __s)
137     {
138       __glibcxx_check_string(__s);
139       *static_cast<_Base*>(this) = __s;
140       this->_M_invalidate_all();
141       return *this;
142     }
144     basic_string&
145     operator=(_CharT __c)
146     {
147       *static_cast<_Base*>(this) = __c;
148       this->_M_invalidate_all();
149       return *this;
150     }
152 #ifdef __GXX_EXPERIMENTAL_CXX0X__
153     basic_string&
154     operator=(basic_string&& __str)
155     {
156       *static_cast<_Base*>(this) = std::forward<_Base>(__str);
157       this->_M_invalidate_all();
158       return *this;
159     }
161     basic_string&
162     operator=(std::initializer_list<_CharT> __l)
163     {
164       *static_cast<_Base*>(this) = __l;
165       this->_M_invalidate_all();
166       return *this;
167     }
168 #endif // __GXX_EXPERIMENTAL_CXX0X__
170     // 21.3.2 iterators:
171     iterator
172     begin()
173     { return iterator(_Base::begin(), this); }
175     const_iterator
176     begin() const
177     { return const_iterator(_Base::begin(), this); }
179     iterator
180     end()
181     { return iterator(_Base::end(), this); }
183     const_iterator
184     end() const
185     { return const_iterator(_Base::end(), this); }
187     reverse_iterator
188     rbegin()
189     { return reverse_iterator(end()); }
191     const_reverse_iterator
192     rbegin() const
193     { return const_reverse_iterator(end()); }
195     reverse_iterator
196     rend()
197     { return reverse_iterator(begin()); }
199     const_reverse_iterator
200     rend() const
201     { return const_reverse_iterator(begin()); }
203     // 21.3.3 capacity:
204     using _Base::size;
205     using _Base::length;
206     using _Base::max_size;
208     void
209     resize(size_type __n, _CharT __c)
210     {
211       _Base::resize(__n, __c);
212       this->_M_invalidate_all();
213     }
215     void
216     resize(size_type __n)
217     { this->resize(__n, _CharT()); }
219 #ifdef __GXX_EXPERIMENTAL_CXX0X__
220     using _Base::shrink_to_fit;
221 #endif
223     using _Base::capacity;
224     using _Base::reserve;
226     void
227     clear()
228     {
229       _Base::clear();
230       this->_M_invalidate_all();
231     }
233     using _Base::empty;
235     // 21.3.4 element access:
236     const_reference
237     operator[](size_type __pos) const
238     {
239       _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
240                             _M_message(__gnu_debug::__msg_subscript_oob)
241                             ._M_sequence(*this, "this")
242                             ._M_integer(__pos, "__pos")
243                             ._M_integer(this->size(), "size"));
244       return _M_base()[__pos];
245     }
247     reference
248     operator[](size_type __pos)
249     {
250 #ifdef _GLIBCXX_DEBUG_PEDANTIC
251       __glibcxx_check_subscript(__pos);
252 #else
253       // as an extension v3 allows s[s.size()] when s is non-const.
254       _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
255                             _M_message(__gnu_debug::__msg_subscript_oob)
256                             ._M_sequence(*this, "this")
257                             ._M_integer(__pos, "__pos")
258                             ._M_integer(this->size(), "size"));
259 #endif
260       return _M_base()[__pos];
261     }
263     using _Base::at;
265 #ifdef __GXX_EXPERIMENTAL_CXX0X__
266     using _Base::front;
267     using _Base::back;
268 #endif
270     // 21.3.5 modifiers:
271     basic_string&
272     operator+=(const basic_string& __str)
273     {
274       _M_base() += __str;
275       this->_M_invalidate_all();
276       return *this;
277     }
279     basic_string&
280     operator+=(const _CharT* __s)
281     {
282       __glibcxx_check_string(__s);
283       _M_base() += __s;
284       this->_M_invalidate_all();
285       return *this;
286     }
288     basic_string&
289     operator+=(_CharT __c)
290     {
291       _M_base() += __c;
292       this->_M_invalidate_all();
293       return *this;
294     }
296 #ifdef __GXX_EXPERIMENTAL_CXX0X__
297     basic_string&
298     operator+=(std::initializer_list<_CharT> __l)
299     {
300       _M_base() += __l;
301       this->_M_invalidate_all();
302       return *this;
303     }
304 #endif // __GXX_EXPERIMENTAL_CXX0X__
306     basic_string&
307     append(const basic_string& __str)
308     {
309       _Base::append(__str);
310       this->_M_invalidate_all();
311       return *this;
312     }
314     basic_string&
315     append(const basic_string& __str, size_type __pos, size_type __n)
316     {
317       _Base::append(__str, __pos, __n);
318       this->_M_invalidate_all();
319       return *this;
320     }
322     basic_string&
323     append(const _CharT* __s, size_type __n)
324     {
325       __glibcxx_check_string_len(__s, __n);
326       _Base::append(__s, __n);
327       this->_M_invalidate_all();
328       return *this;
329     }
331     basic_string&
332     append(const _CharT* __s)
333     {
334       __glibcxx_check_string(__s);
335       _Base::append(__s);
336       this->_M_invalidate_all();
337       return *this;
338     }
340     basic_string&
341     append(size_type __n, _CharT __c)
342     {
343       _Base::append(__n, __c);
344       this->_M_invalidate_all();
345       return *this;
346     }
348     template<typename _InputIterator>
349       basic_string&
350       append(_InputIterator __first, _InputIterator __last)
351       {
352         __glibcxx_check_valid_range(__first, __last);
353         _Base::append(__first, __last);
354         this->_M_invalidate_all();
355         return *this;
356       }
358     // _GLIBCXX_RESOLVE_LIB_DEFECTS
359     // 7. string clause minor problems
360     void
361     push_back(_CharT __c)
362     {
363       _Base::push_back(__c);
364       this->_M_invalidate_all();
365     }
367     basic_string&
368     assign(const basic_string& __x)
369     {
370       _Base::assign(__x);
371       this->_M_invalidate_all();
372       return *this;
373     }
375 #ifdef __GXX_EXPERIMENTAL_CXX0X__
376     basic_string&
377     assign(basic_string&& __x)
378     {
379       _Base::assign(std::forward<_Base>(__x));
380       this->_M_invalidate_all();
381       return *this;
382     }
383 #endif // __GXX_EXPERIMENTAL_CXX0X__
385     basic_string&
386     assign(const basic_string& __str, size_type __pos, size_type __n)
387     {
388       _Base::assign(__str, __pos, __n);
389       this->_M_invalidate_all();
390       return *this;
391     }
393     basic_string&
394     assign(const _CharT* __s, size_type __n)
395     {
396       __glibcxx_check_string_len(__s, __n);
397       _Base::assign(__s, __n);
398       this->_M_invalidate_all();
399       return *this;
400     }
402     basic_string&
403     assign(const _CharT* __s)
404     {
405       __glibcxx_check_string(__s);
406       _Base::assign(__s);
407       this->_M_invalidate_all();
408       return *this;
409     }
411     basic_string&
412     assign(size_type __n, _CharT __c)
413     {
414       _Base::assign(__n, __c);
415       this->_M_invalidate_all();
416       return *this;
417     }
419     template<typename _InputIterator>
420       basic_string&
421       assign(_InputIterator __first, _InputIterator __last)
422       {
423         __glibcxx_check_valid_range(__first, __last);
424         _Base::assign(__first, __last);
425         this->_M_invalidate_all();
426         return *this;
427       }
429 #ifdef __GXX_EXPERIMENTAL_CXX0X__
430     basic_string&
431     assign(std::initializer_list<_CharT> __l)
432     {
433       _Base::assign(__l);
434       this->_M_invalidate_all();
435       return *this;
436     }
437 #endif // __GXX_EXPERIMENTAL_CXX0X__
439     basic_string&
440     insert(size_type __pos1, const basic_string& __str)
441     {
442       _Base::insert(__pos1, __str);
443       this->_M_invalidate_all();
444       return *this;
445     }
447     basic_string&
448     insert(size_type __pos1, const basic_string& __str,
449            size_type __pos2, size_type __n)
450     {
451       _Base::insert(__pos1, __str, __pos2, __n);
452       this->_M_invalidate_all();
453       return *this;
454     }
456     basic_string&
457     insert(size_type __pos, const _CharT* __s, size_type __n)
458     {
459       __glibcxx_check_string(__s);
460       _Base::insert(__pos, __s, __n);
461       this->_M_invalidate_all();
462       return *this;
463     }
465     basic_string&
466     insert(size_type __pos, const _CharT* __s)
467     {
468       __glibcxx_check_string(__s);
469       _Base::insert(__pos, __s);
470       this->_M_invalidate_all();
471       return *this;
472     }
474     basic_string&
475     insert(size_type __pos, size_type __n, _CharT __c)
476     {
477       _Base::insert(__pos, __n, __c);
478       this->_M_invalidate_all();
479       return *this;
480     }
482     iterator
483     insert(iterator __p, _CharT __c)
484     {
485       __glibcxx_check_insert(__p);
486       typename _Base::iterator __res = _Base::insert(__p.base(), __c);
487       this->_M_invalidate_all();
488       return iterator(__res, this);
489     }
491     void
492     insert(iterator __p, size_type __n, _CharT __c)
493     {
494       __glibcxx_check_insert(__p);
495       _Base::insert(__p.base(), __n, __c);
496       this->_M_invalidate_all();
497     }
499     template<typename _InputIterator>
500       void
501       insert(iterator __p, _InputIterator __first, _InputIterator __last)
502       {
503         __glibcxx_check_insert_range(__p, __first, __last);
504         _Base::insert(__p.base(), __first, __last);
505         this->_M_invalidate_all();
506       }
508 #ifdef __GXX_EXPERIMENTAL_CXX0X__
509     void
510     insert(iterator __p, std::initializer_list<_CharT> __l)
511     {
512       _Base::insert(__p, __l);
513       this->_M_invalidate_all();
514     }
515 #endif // __GXX_EXPERIMENTAL_CXX0X__
517     basic_string&
518     erase(size_type __pos = 0, size_type __n = _Base::npos)
519     {
520       _Base::erase(__pos, __n);
521       this->_M_invalidate_all();
522       return *this;
523     }
525     iterator
526     erase(iterator __position)
527     {
528       __glibcxx_check_erase(__position);
529       typename _Base::iterator __res = _Base::erase(__position.base());
530       this->_M_invalidate_all();
531       return iterator(__res, this);
532     }
534     iterator
535     erase(iterator __first, iterator __last)
536     {
537       // _GLIBCXX_RESOLVE_LIB_DEFECTS
538       // 151. can't currently clear() empty container
539       __glibcxx_check_erase_range(__first, __last);
540       typename _Base::iterator __res = _Base::erase(__first.base(),
541                                                        __last.base());
542       this->_M_invalidate_all();
543       return iterator(__res, this);
544     }
546     basic_string&
547     replace(size_type __pos1, size_type __n1, const basic_string& __str)
548     {
549       _Base::replace(__pos1, __n1, __str);
550       this->_M_invalidate_all();
551       return *this;
552     }
554     basic_string&
555     replace(size_type __pos1, size_type __n1, const basic_string& __str,
556             size_type __pos2, size_type __n2)
557     {
558       _Base::replace(__pos1, __n1, __str, __pos2, __n2);
559       this->_M_invalidate_all();
560       return *this;
561     }
563     basic_string&
564     replace(size_type __pos, size_type __n1, const _CharT* __s,
565             size_type __n2)
566     {
567       __glibcxx_check_string_len(__s, __n2);
568       _Base::replace(__pos, __n1, __s, __n2);
569       this->_M_invalidate_all();
570       return *this;
571     }
573     basic_string&
574     replace(size_type __pos, size_type __n1, const _CharT* __s)
575     {
576       __glibcxx_check_string(__s);
577       _Base::replace(__pos, __n1, __s);
578       this->_M_invalidate_all();
579       return *this;
580     }
582     basic_string&
583     replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
584     {
585       _Base::replace(__pos, __n1, __n2, __c);
586       this->_M_invalidate_all();
587       return *this;
588     }
590     basic_string&
591     replace(iterator __i1, iterator __i2, const basic_string& __str)
592     {
593       __glibcxx_check_erase_range(__i1, __i2);
594       _Base::replace(__i1.base(), __i2.base(), __str);
595       this->_M_invalidate_all();
596       return *this;
597     }
599     basic_string&
600     replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
601     {
602       __glibcxx_check_erase_range(__i1, __i2);
603       __glibcxx_check_string_len(__s, __n);
604       _Base::replace(__i1.base(), __i2.base(), __s, __n);
605       this->_M_invalidate_all();
606       return *this;
607     }
609     basic_string&
610     replace(iterator __i1, iterator __i2, const _CharT* __s)
611     {
612       __glibcxx_check_erase_range(__i1, __i2);
613       __glibcxx_check_string(__s);
614       _Base::replace(__i1.base(), __i2.base(), __s);
615       this->_M_invalidate_all();
616       return *this;
617     }
619     basic_string&
620     replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
621     {
622       __glibcxx_check_erase_range(__i1, __i2);
623       _Base::replace(__i1.base(), __i2.base(), __n, __c);
624       this->_M_invalidate_all();
625       return *this;
626     }
628     template<typename _InputIterator>
629       basic_string&
630       replace(iterator __i1, iterator __i2,
631               _InputIterator __j1, _InputIterator __j2)
632       {
633         __glibcxx_check_erase_range(__i1, __i2);
634         __glibcxx_check_valid_range(__j1, __j2);
635         _Base::replace(__i1.base(), __i2.base(), __j1, __j2);
636         this->_M_invalidate_all();
637         return *this;
638       }
640 #ifdef __GXX_EXPERIMENTAL_CXX0X__
641       basic_string& replace(iterator __i1, iterator __i2,
642                             std::initializer_list<_CharT> __l)
643       {
644         __glibcxx_check_erase_range(__i1, __i2);
645         _Base::replace(__i1.base(), __i2.base(), __l);
646         this->_M_invalidate_all();
647         return *this;
648       }
649 #endif // __GXX_EXPERIMENTAL_CXX0X__
651     size_type
652     copy(_CharT* __s, size_type __n, size_type __pos = 0) const
653     {
654       __glibcxx_check_string_len(__s, __n);
655       return _Base::copy(__s, __n, __pos);
656     }
658     void
659     swap(basic_string<_CharT,_Traits,_Allocator>& __x)
660     {
661       _Base::swap(__x);
662       this->_M_swap(__x);
663       this->_M_invalidate_all();
664       __x._M_invalidate_all();
665     }
667     // 21.3.6 string operations:
668     const _CharT*
669     c_str() const
670     {
671       const _CharT* __res = _Base::c_str();
672       this->_M_invalidate_all();
673       return __res;
674     }
676     const _CharT*
677     data() const
678     {
679       const _CharT* __res = _Base::data();
680       this->_M_invalidate_all();
681       return __res;
682     }
684     using _Base::get_allocator;
686     size_type
687     find(const basic_string& __str, size_type __pos = 0) const
688     { return _Base::find(__str, __pos); }
690     size_type
691     find(const _CharT* __s, size_type __pos, size_type __n) const
692     {
693       __glibcxx_check_string(__s);
694       return _Base::find(__s, __pos, __n);
695     }
697     size_type
698     find(const _CharT* __s, size_type __pos = 0) const
699     {
700       __glibcxx_check_string(__s);
701       return _Base::find(__s, __pos);
702     }
704     size_type
705     find(_CharT __c, size_type __pos = 0) const
706     { return _Base::find(__c, __pos); }
708     size_type
709     rfind(const basic_string& __str, size_type __pos = _Base::npos) const
710     { return _Base::rfind(__str, __pos); }
712     size_type
713     rfind(const _CharT* __s, size_type __pos, size_type __n) const
714     {
715       __glibcxx_check_string_len(__s, __n);
716       return _Base::rfind(__s, __pos, __n);
717     }
719     size_type
720     rfind(const _CharT* __s, size_type __pos = _Base::npos) const
721     {
722       __glibcxx_check_string(__s);
723       return _Base::rfind(__s, __pos);
724     }
726     size_type
727     rfind(_CharT __c, size_type __pos = _Base::npos) const
728     { return _Base::rfind(__c, __pos); }
730     size_type
731     find_first_of(const basic_string& __str, size_type __pos = 0) const
732     { return _Base::find_first_of(__str, __pos); }
734     size_type
735     find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
736     {
737       __glibcxx_check_string(__s);
738       return _Base::find_first_of(__s, __pos, __n);
739     }
741     size_type
742     find_first_of(const _CharT* __s, size_type __pos = 0) const
743     {
744       __glibcxx_check_string(__s);
745       return _Base::find_first_of(__s, __pos);
746     }
748     size_type
749     find_first_of(_CharT __c, size_type __pos = 0) const
750     { return _Base::find_first_of(__c, __pos); }
752     size_type
753     find_last_of(const basic_string& __str, 
754                  size_type __pos = _Base::npos) const
755     { return _Base::find_last_of(__str, __pos); }
757     size_type
758     find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
759     {
760       __glibcxx_check_string(__s);
761       return _Base::find_last_of(__s, __pos, __n);
762     }
764     size_type
765     find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const
766     {
767       __glibcxx_check_string(__s);
768       return _Base::find_last_of(__s, __pos);
769     }
771     size_type
772     find_last_of(_CharT __c, size_type __pos = _Base::npos) const
773     { return _Base::find_last_of(__c, __pos); }
775     size_type
776     find_first_not_of(const basic_string& __str, size_type __pos = 0) const
777     { return _Base::find_first_not_of(__str, __pos); }
779     size_type
780     find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
781     {
782       __glibcxx_check_string_len(__s, __n);
783       return _Base::find_first_not_of(__s, __pos, __n);
784     }
786     size_type
787     find_first_not_of(const _CharT* __s, size_type __pos = 0) const
788     {
789       __glibcxx_check_string(__s);
790       return _Base::find_first_not_of(__s, __pos);
791     }
793     size_type
794     find_first_not_of(_CharT __c, size_type __pos = 0) const
795     { return _Base::find_first_not_of(__c, __pos); }
797     size_type
798     find_last_not_of(const basic_string& __str,
799                                   size_type __pos = _Base::npos) const
800     { return _Base::find_last_not_of(__str, __pos); }
802     size_type
803     find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
804     {
805       __glibcxx_check_string(__s);
806       return _Base::find_last_not_of(__s, __pos, __n);
807     }
809     size_type
810     find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const
811     {
812       __glibcxx_check_string(__s);
813       return _Base::find_last_not_of(__s, __pos);
814     }
816     size_type
817     find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const
818     { return _Base::find_last_not_of(__c, __pos); }
820     basic_string
821     substr(size_type __pos = 0, size_type __n = _Base::npos) const
822     { return basic_string(_Base::substr(__pos, __n)); }
824     int
825     compare(const basic_string& __str) const
826     { return _Base::compare(__str); }
828     int
829     compare(size_type __pos1, size_type __n1,
830                   const basic_string& __str) const
831     { return _Base::compare(__pos1, __n1, __str); }
833     int
834     compare(size_type __pos1, size_type __n1, const basic_string& __str,
835               size_type __pos2, size_type __n2) const
836     { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); }
838     int
839     compare(const _CharT* __s) const
840     {
841       __glibcxx_check_string(__s);
842       return _Base::compare(__s);
843     }
845     //  _GLIBCXX_RESOLVE_LIB_DEFECTS
846     //  5. string::compare specification questionable
847     int
848     compare(size_type __pos1, size_type __n1, const _CharT* __s) const
849     {
850       __glibcxx_check_string(__s);
851       return _Base::compare(__pos1, __n1, __s);
852     }
854     //  _GLIBCXX_RESOLVE_LIB_DEFECTS
855     //  5. string::compare specification questionable
856     int
857     compare(size_type __pos1, size_type __n1,const _CharT* __s,
858               size_type __n2) const
859     {
860       __glibcxx_check_string_len(__s, __n2);
861       return _Base::compare(__pos1, __n1, __s, __n2);
862     }
864     _Base&
865     _M_base() { return *this; }
867     const _Base&
868     _M_base() const { return *this; }
870     using _Safe_base::_M_invalidate_all;
871   };
873   template<typename _CharT, typename _Traits, typename _Allocator>
874     inline basic_string<_CharT,_Traits,_Allocator>
875     operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
876               const basic_string<_CharT,_Traits,_Allocator>& __rhs)
877     { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
879   template<typename _CharT, typename _Traits, typename _Allocator>
880     inline basic_string<_CharT,_Traits,_Allocator>
881     operator+(const _CharT* __lhs,
882               const basic_string<_CharT,_Traits,_Allocator>& __rhs)
883     {
884       __glibcxx_check_string(__lhs);
885       return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
886     }
888   template<typename _CharT, typename _Traits, typename _Allocator>
889     inline basic_string<_CharT,_Traits,_Allocator>
890     operator+(_CharT __lhs,
891               const basic_string<_CharT,_Traits,_Allocator>& __rhs)
892     { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
894   template<typename _CharT, typename _Traits, typename _Allocator>
895     inline basic_string<_CharT,_Traits,_Allocator>
896     operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
897               const _CharT* __rhs)
898     {
899       __glibcxx_check_string(__rhs);
900       return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
901     }
903   template<typename _CharT, typename _Traits, typename _Allocator>
904     inline basic_string<_CharT,_Traits,_Allocator>
905     operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
906               _CharT __rhs)
907     { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
909   template<typename _CharT, typename _Traits, typename _Allocator>
910     inline bool
911     operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
912                const basic_string<_CharT,_Traits,_Allocator>& __rhs)
913     { return __lhs._M_base() == __rhs._M_base(); }
915   template<typename _CharT, typename _Traits, typename _Allocator>
916     inline bool
917     operator==(const _CharT* __lhs,
918                const basic_string<_CharT,_Traits,_Allocator>& __rhs)
919     {
920       __glibcxx_check_string(__lhs);
921       return __lhs == __rhs._M_base();
922     }
924   template<typename _CharT, typename _Traits, typename _Allocator>
925     inline bool
926     operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
927                const _CharT* __rhs)
928     {
929       __glibcxx_check_string(__rhs);
930       return __lhs._M_base() == __rhs;
931     }
933   template<typename _CharT, typename _Traits, typename _Allocator>
934     inline bool
935     operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
936                const basic_string<_CharT,_Traits,_Allocator>& __rhs)
937     { return __lhs._M_base() != __rhs._M_base(); }
939   template<typename _CharT, typename _Traits, typename _Allocator>
940     inline bool
941     operator!=(const _CharT* __lhs,
942                const basic_string<_CharT,_Traits,_Allocator>& __rhs)
943     {
944       __glibcxx_check_string(__lhs);
945       return __lhs != __rhs._M_base();
946     }
948   template<typename _CharT, typename _Traits, typename _Allocator>
949     inline bool
950     operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
951                const _CharT* __rhs)
952     {
953       __glibcxx_check_string(__rhs);
954       return __lhs._M_base() != __rhs;
955     }
957   template<typename _CharT, typename _Traits, typename _Allocator>
958     inline bool
959     operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
960               const basic_string<_CharT,_Traits,_Allocator>& __rhs)
961     { return __lhs._M_base() < __rhs._M_base(); }
963   template<typename _CharT, typename _Traits, typename _Allocator>
964     inline bool
965     operator<(const _CharT* __lhs,
966               const basic_string<_CharT,_Traits,_Allocator>& __rhs)
967     {
968       __glibcxx_check_string(__lhs);
969       return __lhs < __rhs._M_base();
970     }
972   template<typename _CharT, typename _Traits, typename _Allocator>
973     inline bool
974     operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
975               const _CharT* __rhs)
976     {
977       __glibcxx_check_string(__rhs);
978       return __lhs._M_base() < __rhs;
979     }
981   template<typename _CharT, typename _Traits, typename _Allocator>
982     inline bool
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>
988     inline bool
989     operator<=(const _CharT* __lhs,
990                const basic_string<_CharT,_Traits,_Allocator>& __rhs)
991     {
992       __glibcxx_check_string(__lhs);
993       return __lhs <= __rhs._M_base();
994     }
996   template<typename _CharT, typename _Traits, typename _Allocator>
997     inline bool
998     operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
999                const _CharT* __rhs)
1000     {
1001       __glibcxx_check_string(__rhs);
1002       return __lhs._M_base() <= __rhs;
1003     }
1005   template<typename _CharT, typename _Traits, typename _Allocator>
1006     inline bool
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>
1012     inline bool
1013     operator>=(const _CharT* __lhs,
1014                const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1015     {
1016       __glibcxx_check_string(__lhs);
1017       return __lhs >= __rhs._M_base();
1018     }
1020   template<typename _CharT, typename _Traits, typename _Allocator>
1021     inline bool
1022     operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1023                const _CharT* __rhs)
1024     {
1025       __glibcxx_check_string(__rhs);
1026       return __lhs._M_base() >= __rhs;
1027     }
1029   template<typename _CharT, typename _Traits, typename _Allocator>
1030     inline bool
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>
1036     inline bool
1037     operator>(const _CharT* __lhs,
1038               const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1039     {
1040       __glibcxx_check_string(__lhs);
1041       return __lhs > __rhs._M_base();
1042     }
1044   template<typename _CharT, typename _Traits, typename _Allocator>
1045     inline bool
1046     operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1047               const _CharT* __rhs)
1048     {
1049       __glibcxx_check_string(__rhs);
1050       return __lhs._M_base() > __rhs;
1051     }
1053   // 21.3.7.8:
1054   template<typename _CharT, typename _Traits, typename _Allocator>
1055     inline void
1056     swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1057          basic_string<_CharT,_Traits,_Allocator>& __rhs)
1058     { __lhs.swap(__rhs); }
1060   template<typename _CharT, typename _Traits, typename _Allocator>
1061     std::basic_ostream<_CharT, _Traits>&
1062     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1063                const basic_string<_CharT, _Traits, _Allocator>& __str)
1064     { return __os << __str._M_base(); }
1066   template<typename _CharT, typename _Traits, typename _Allocator>
1067     std::basic_istream<_CharT,_Traits>&
1068     operator>>(std::basic_istream<_CharT,_Traits>& __is,
1069                basic_string<_CharT,_Traits,_Allocator>& __str)
1070     {
1071       std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base();
1072       __str._M_invalidate_all();
1073       return __res;
1074     }
1076   template<typename _CharT, typename _Traits, typename _Allocator>
1077     std::basic_istream<_CharT,_Traits>&
1078     getline(std::basic_istream<_CharT,_Traits>& __is,
1079             basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1080     {
1081       std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1082                                                           __str._M_base(),
1083                                                         __delim);
1084       __str._M_invalidate_all();
1085       return __res;
1086     }
1088   template<typename _CharT, typename _Traits, typename _Allocator>
1089     std::basic_istream<_CharT,_Traits>&
1090     getline(std::basic_istream<_CharT,_Traits>& __is,
1091             basic_string<_CharT,_Traits,_Allocator>& __str)
1092     {
1093       std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1094                                                           __str._M_base());
1095       __str._M_invalidate_all();
1096       return __res;
1097     }
1099   typedef basic_string<char>    string;
1101 #ifdef _GLIBCXX_USE_WCHAR_T
1102   typedef basic_string<wchar_t> wstring;
1103 #endif
1105 } // namespace __gnu_debug
1107 #endif