OSDN Git Service

2010-11-27 François Dumont <francois.cppdevs@free.fr>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / debug / string
1 // Debugging string implementation -*- C++ -*-
2
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.
11
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.
16
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.
20
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/>.
25
26 /** @file debug/string
27  *  This file is a GNU debug extension to the Standard C++ Library.
28  */
29
30 #ifndef _GLIBCXX_DEBUG_STRING
31 #define _GLIBCXX_DEBUG_STRING 1
32
33 #include <string>
34 #include <debug/safe_sequence.h>
35 #include <debug/safe_iterator.h>
36
37 namespace __gnu_debug
38 {
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;
49
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;
61
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;
66
67     typedef std::reverse_iterator<iterator>            reverse_iterator;
68     typedef std::reverse_iterator<const_iterator>      const_reverse_iterator;
69
70     using _Base::npos;
71
72     // 21.3.1 construct/copy/destroy:
73     explicit basic_string(const _Allocator& __a = _Allocator())
74     : _Base(__a)
75     { }
76
77     // Provides conversion from a release-mode string to a debug-mode string
78     basic_string(const _Base& __base) : _Base(__base), _Safe_base() { }
79
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     { }
85
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     { }
93
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     { }
98
99     basic_string(const _CharT* __s, const _Allocator& __a = _Allocator())
100     : _Base(__gnu_debug::__check_string(__s), __a)
101     { this->assign(__s); }
102
103     basic_string(size_type __n, _CharT __c,
104                    const _Allocator& __a = _Allocator())
105     : _Base(__n, __c, __a)
106     { }
107
108     template<typename _InputIterator>
109       basic_string(_InputIterator __begin, _InputIterator __end,
110                    const _Allocator& __a = _Allocator())
111       : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__begin,
112                                                                    __end)),
113               __gnu_debug::__base(__end), __a)
114       { }
115
116 #ifdef __GXX_EXPERIMENTAL_CXX0X__
117     basic_string(basic_string&& __str)
118     : _Base(std::move(__str))
119     { }
120
121     basic_string(std::initializer_list<_CharT> __l,
122                  const _Allocator& __a = _Allocator())
123     : _Base(__l, __a)
124     { }
125 #endif // __GXX_EXPERIMENTAL_CXX0X__
126
127     ~basic_string() { }
128
129     basic_string&
130     operator=(const basic_string& __str)
131     {
132       *static_cast<_Base*>(this) = __str;
133       this->_M_invalidate_all();
134       return *this;
135     }
136
137     basic_string&
138     operator=(const _CharT* __s)
139     {
140       __glibcxx_check_string(__s);
141       *static_cast<_Base*>(this) = __s;
142       this->_M_invalidate_all();
143       return *this;
144     }
145
146     basic_string&
147     operator=(_CharT __c)
148     {
149       *static_cast<_Base*>(this) = __c;
150       this->_M_invalidate_all();
151       return *this;
152     }
153
154 #ifdef __GXX_EXPERIMENTAL_CXX0X__
155     basic_string&
156     operator=(basic_string&& __str)
157     {
158       *static_cast<_Base*>(this) = std::move(__str);
159       this->_M_invalidate_all();
160       return *this;
161     }
162
163     basic_string&
164     operator=(std::initializer_list<_CharT> __l)
165     {
166       *static_cast<_Base*>(this) = __l;
167       this->_M_invalidate_all();
168       return *this;
169     }
170 #endif // __GXX_EXPERIMENTAL_CXX0X__
171
172     // 21.3.2 iterators:
173     iterator
174     begin()
175     { return iterator(_Base::begin(), this); }
176
177     const_iterator
178     begin() const
179     { return const_iterator(_Base::begin(), this); }
180
181     iterator
182     end()
183     { return iterator(_Base::end(), this); }
184
185     const_iterator
186     end() const
187     { return const_iterator(_Base::end(), this); }
188
189     reverse_iterator
190     rbegin()
191     { return reverse_iterator(end()); }
192
193     const_reverse_iterator
194     rbegin() const
195     { return const_reverse_iterator(end()); }
196
197     reverse_iterator
198     rend()
199     { return reverse_iterator(begin()); }
200
201     const_reverse_iterator
202     rend() const
203     { return const_reverse_iterator(begin()); }
204
205     // 21.3.3 capacity:
206     using _Base::size;
207     using _Base::length;
208     using _Base::max_size;
209
210     void
211     resize(size_type __n, _CharT __c)
212     {
213       _Base::resize(__n, __c);
214       this->_M_invalidate_all();
215     }
216
217     void
218     resize(size_type __n)
219     { this->resize(__n, _CharT()); }
220
221 #ifdef __GXX_EXPERIMENTAL_CXX0X__
222     using _Base::shrink_to_fit;
223 #endif
224
225     using _Base::capacity;
226     using _Base::reserve;
227
228     void
229     clear()
230     {
231       _Base::clear();
232       this->_M_invalidate_all();
233     }
234
235     using _Base::empty;
236
237     // 21.3.4 element access:
238     const_reference
239     operator[](size_type __pos) const
240     {
241       _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
242                             _M_message(__gnu_debug::__msg_subscript_oob)
243                             ._M_sequence(*this, "this")
244                             ._M_integer(__pos, "__pos")
245                             ._M_integer(this->size(), "size"));
246       return _M_base()[__pos];
247     }
248
249     reference
250     operator[](size_type __pos)
251     {
252 #ifdef _GLIBCXX_DEBUG_PEDANTIC
253       __glibcxx_check_subscript(__pos);
254 #else
255       // as an extension v3 allows s[s.size()] when s is non-const.
256       _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
257                             _M_message(__gnu_debug::__msg_subscript_oob)
258                             ._M_sequence(*this, "this")
259                             ._M_integer(__pos, "__pos")
260                             ._M_integer(this->size(), "size"));
261 #endif
262       return _M_base()[__pos];
263     }
264
265     using _Base::at;
266
267 #ifdef __GXX_EXPERIMENTAL_CXX0X__
268     using _Base::front;
269     using _Base::back;
270 #endif
271
272     // 21.3.5 modifiers:
273     basic_string&
274     operator+=(const basic_string& __str)
275     {
276       _M_base() += __str;
277       this->_M_invalidate_all();
278       return *this;
279     }
280
281     basic_string&
282     operator+=(const _CharT* __s)
283     {
284       __glibcxx_check_string(__s);
285       _M_base() += __s;
286       this->_M_invalidate_all();
287       return *this;
288     }
289
290     basic_string&
291     operator+=(_CharT __c)
292     {
293       _M_base() += __c;
294       this->_M_invalidate_all();
295       return *this;
296     }
297
298 #ifdef __GXX_EXPERIMENTAL_CXX0X__
299     basic_string&
300     operator+=(std::initializer_list<_CharT> __l)
301     {
302       _M_base() += __l;
303       this->_M_invalidate_all();
304       return *this;
305     }
306 #endif // __GXX_EXPERIMENTAL_CXX0X__
307
308     basic_string&
309     append(const basic_string& __str)
310     {
311       _Base::append(__str);
312       this->_M_invalidate_all();
313       return *this;
314     }
315
316     basic_string&
317     append(const basic_string& __str, size_type __pos, size_type __n)
318     {
319       _Base::append(__str, __pos, __n);
320       this->_M_invalidate_all();
321       return *this;
322     }
323
324     basic_string&
325     append(const _CharT* __s, size_type __n)
326     {
327       __glibcxx_check_string_len(__s, __n);
328       _Base::append(__s, __n);
329       this->_M_invalidate_all();
330       return *this;
331     }
332
333     basic_string&
334     append(const _CharT* __s)
335     {
336       __glibcxx_check_string(__s);
337       _Base::append(__s);
338       this->_M_invalidate_all();
339       return *this;
340     }
341
342     basic_string&
343     append(size_type __n, _CharT __c)
344     {
345       _Base::append(__n, __c);
346       this->_M_invalidate_all();
347       return *this;
348     }
349
350     template<typename _InputIterator>
351       basic_string&
352       append(_InputIterator __first, _InputIterator __last)
353       {
354         __glibcxx_check_valid_range(__first, __last);
355         _Base::append(__gnu_debug::__base(__first),
356                       __gnu_debug::__base(__last));
357         this->_M_invalidate_all();
358         return *this;
359       }
360
361     // _GLIBCXX_RESOLVE_LIB_DEFECTS
362     // 7. string clause minor problems
363     void
364     push_back(_CharT __c)
365     {
366       _Base::push_back(__c);
367       this->_M_invalidate_all();
368     }
369
370     basic_string&
371     assign(const basic_string& __x)
372     {
373       _Base::assign(__x);
374       this->_M_invalidate_all();
375       return *this;
376     }
377
378 #ifdef __GXX_EXPERIMENTAL_CXX0X__
379     basic_string&
380     assign(basic_string&& __x)
381     {
382       _Base::assign(std::move(__x));
383       this->_M_invalidate_all();
384       return *this;
385     }
386 #endif // __GXX_EXPERIMENTAL_CXX0X__
387
388     basic_string&
389     assign(const basic_string& __str, size_type __pos, size_type __n)
390     {
391       _Base::assign(__str, __pos, __n);
392       this->_M_invalidate_all();
393       return *this;
394     }
395
396     basic_string&
397     assign(const _CharT* __s, size_type __n)
398     {
399       __glibcxx_check_string_len(__s, __n);
400       _Base::assign(__s, __n);
401       this->_M_invalidate_all();
402       return *this;
403     }
404
405     basic_string&
406     assign(const _CharT* __s)
407     {
408       __glibcxx_check_string(__s);
409       _Base::assign(__s);
410       this->_M_invalidate_all();
411       return *this;
412     }
413
414     basic_string&
415     assign(size_type __n, _CharT __c)
416     {
417       _Base::assign(__n, __c);
418       this->_M_invalidate_all();
419       return *this;
420     }
421
422     template<typename _InputIterator>
423       basic_string&
424       assign(_InputIterator __first, _InputIterator __last)
425       {
426         __glibcxx_check_valid_range(__first, __last);
427         _Base::assign(__gnu_debug::__base(__first),
428                       __gnu_debug::__base(__last));
429         this->_M_invalidate_all();
430         return *this;
431       }
432
433 #ifdef __GXX_EXPERIMENTAL_CXX0X__
434     basic_string&
435     assign(std::initializer_list<_CharT> __l)
436     {
437       _Base::assign(__l);
438       this->_M_invalidate_all();
439       return *this;
440     }
441 #endif // __GXX_EXPERIMENTAL_CXX0X__
442
443     basic_string&
444     insert(size_type __pos1, const basic_string& __str)
445     {
446       _Base::insert(__pos1, __str);
447       this->_M_invalidate_all();
448       return *this;
449     }
450
451     basic_string&
452     insert(size_type __pos1, const basic_string& __str,
453            size_type __pos2, size_type __n)
454     {
455       _Base::insert(__pos1, __str, __pos2, __n);
456       this->_M_invalidate_all();
457       return *this;
458     }
459
460     basic_string&
461     insert(size_type __pos, const _CharT* __s, size_type __n)
462     {
463       __glibcxx_check_string(__s);
464       _Base::insert(__pos, __s, __n);
465       this->_M_invalidate_all();
466       return *this;
467     }
468
469     basic_string&
470     insert(size_type __pos, const _CharT* __s)
471     {
472       __glibcxx_check_string(__s);
473       _Base::insert(__pos, __s);
474       this->_M_invalidate_all();
475       return *this;
476     }
477
478     basic_string&
479     insert(size_type __pos, size_type __n, _CharT __c)
480     {
481       _Base::insert(__pos, __n, __c);
482       this->_M_invalidate_all();
483       return *this;
484     }
485
486     iterator
487     insert(iterator __p, _CharT __c)
488     {
489       __glibcxx_check_insert(__p);
490       typename _Base::iterator __res = _Base::insert(__p.base(), __c);
491       this->_M_invalidate_all();
492       return iterator(__res, this);
493     }
494
495     void
496     insert(iterator __p, size_type __n, _CharT __c)
497     {
498       __glibcxx_check_insert(__p);
499       _Base::insert(__p.base(), __n, __c);
500       this->_M_invalidate_all();
501     }
502
503     template<typename _InputIterator>
504       void
505       insert(iterator __p, _InputIterator __first, _InputIterator __last)
506       {
507         __glibcxx_check_insert_range(__p, __first, __last);
508         _Base::insert(__p.base(), __gnu_debug::__base(__first),
509                                   __gnu_debug::__base(__last));
510         this->_M_invalidate_all();
511       }
512
513 #ifdef __GXX_EXPERIMENTAL_CXX0X__
514     void
515     insert(iterator __p, std::initializer_list<_CharT> __l)
516     {
517       _Base::insert(__p, __l);
518       this->_M_invalidate_all();
519     }
520 #endif // __GXX_EXPERIMENTAL_CXX0X__
521
522     basic_string&
523     erase(size_type __pos = 0, size_type __n = _Base::npos)
524     {
525       _Base::erase(__pos, __n);
526       this->_M_invalidate_all();
527       return *this;
528     }
529
530     iterator
531     erase(iterator __position)
532     {
533       __glibcxx_check_erase(__position);
534       typename _Base::iterator __res = _Base::erase(__position.base());
535       this->_M_invalidate_all();
536       return iterator(__res, this);
537     }
538
539     iterator
540     erase(iterator __first, iterator __last)
541     {
542       // _GLIBCXX_RESOLVE_LIB_DEFECTS
543       // 151. can't currently clear() empty container
544       __glibcxx_check_erase_range(__first, __last);
545       typename _Base::iterator __res = _Base::erase(__first.base(),
546                                                        __last.base());
547       this->_M_invalidate_all();
548       return iterator(__res, this);
549     }
550
551     basic_string&
552     replace(size_type __pos1, size_type __n1, const basic_string& __str)
553     {
554       _Base::replace(__pos1, __n1, __str);
555       this->_M_invalidate_all();
556       return *this;
557     }
558
559     basic_string&
560     replace(size_type __pos1, size_type __n1, const basic_string& __str,
561             size_type __pos2, size_type __n2)
562     {
563       _Base::replace(__pos1, __n1, __str, __pos2, __n2);
564       this->_M_invalidate_all();
565       return *this;
566     }
567
568     basic_string&
569     replace(size_type __pos, size_type __n1, const _CharT* __s,
570             size_type __n2)
571     {
572       __glibcxx_check_string_len(__s, __n2);
573       _Base::replace(__pos, __n1, __s, __n2);
574       this->_M_invalidate_all();
575       return *this;
576     }
577
578     basic_string&
579     replace(size_type __pos, size_type __n1, const _CharT* __s)
580     {
581       __glibcxx_check_string(__s);
582       _Base::replace(__pos, __n1, __s);
583       this->_M_invalidate_all();
584       return *this;
585     }
586
587     basic_string&
588     replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
589     {
590       _Base::replace(__pos, __n1, __n2, __c);
591       this->_M_invalidate_all();
592       return *this;
593     }
594
595     basic_string&
596     replace(iterator __i1, iterator __i2, const basic_string& __str)
597     {
598       __glibcxx_check_erase_range(__i1, __i2);
599       _Base::replace(__i1.base(), __i2.base(), __str);
600       this->_M_invalidate_all();
601       return *this;
602     }
603
604     basic_string&
605     replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
606     {
607       __glibcxx_check_erase_range(__i1, __i2);
608       __glibcxx_check_string_len(__s, __n);
609       _Base::replace(__i1.base(), __i2.base(), __s, __n);
610       this->_M_invalidate_all();
611       return *this;
612     }
613
614     basic_string&
615     replace(iterator __i1, iterator __i2, const _CharT* __s)
616     {
617       __glibcxx_check_erase_range(__i1, __i2);
618       __glibcxx_check_string(__s);
619       _Base::replace(__i1.base(), __i2.base(), __s);
620       this->_M_invalidate_all();
621       return *this;
622     }
623
624     basic_string&
625     replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
626     {
627       __glibcxx_check_erase_range(__i1, __i2);
628       _Base::replace(__i1.base(), __i2.base(), __n, __c);
629       this->_M_invalidate_all();
630       return *this;
631     }
632
633     template<typename _InputIterator>
634       basic_string&
635       replace(iterator __i1, iterator __i2,
636               _InputIterator __j1, _InputIterator __j2)
637       {
638         __glibcxx_check_erase_range(__i1, __i2);
639         __glibcxx_check_valid_range(__j1, __j2);
640         _Base::replace(__i1.base(), __i2.base(), __j1, __j2);
641         this->_M_invalidate_all();
642         return *this;
643       }
644
645 #ifdef __GXX_EXPERIMENTAL_CXX0X__
646       basic_string& replace(iterator __i1, iterator __i2,
647                             std::initializer_list<_CharT> __l)
648       {
649         __glibcxx_check_erase_range(__i1, __i2);
650         _Base::replace(__i1.base(), __i2.base(), __l);
651         this->_M_invalidate_all();
652         return *this;
653       }
654 #endif // __GXX_EXPERIMENTAL_CXX0X__
655
656     size_type
657     copy(_CharT* __s, size_type __n, size_type __pos = 0) const
658     {
659       __glibcxx_check_string_len(__s, __n);
660       return _Base::copy(__s, __n, __pos);
661     }
662
663     void
664     swap(basic_string<_CharT,_Traits,_Allocator>& __x)
665     {
666       _Base::swap(__x);
667       this->_M_swap(__x);
668       this->_M_invalidate_all();
669       __x._M_invalidate_all();
670     }
671
672     // 21.3.6 string operations:
673     const _CharT*
674     c_str() const
675     {
676       const _CharT* __res = _Base::c_str();
677       this->_M_invalidate_all();
678       return __res;
679     }
680
681     const _CharT*
682     data() const
683     {
684       const _CharT* __res = _Base::data();
685       this->_M_invalidate_all();
686       return __res;
687     }
688
689     using _Base::get_allocator;
690
691     size_type
692     find(const basic_string& __str, size_type __pos = 0) const
693     { return _Base::find(__str, __pos); }
694
695     size_type
696     find(const _CharT* __s, size_type __pos, size_type __n) const
697     {
698       __glibcxx_check_string(__s);
699       return _Base::find(__s, __pos, __n);
700     }
701
702     size_type
703     find(const _CharT* __s, size_type __pos = 0) const
704     {
705       __glibcxx_check_string(__s);
706       return _Base::find(__s, __pos);
707     }
708
709     size_type
710     find(_CharT __c, size_type __pos = 0) const
711     { return _Base::find(__c, __pos); }
712
713     size_type
714     rfind(const basic_string& __str, size_type __pos = _Base::npos) const
715     { return _Base::rfind(__str, __pos); }
716
717     size_type
718     rfind(const _CharT* __s, size_type __pos, size_type __n) const
719     {
720       __glibcxx_check_string_len(__s, __n);
721       return _Base::rfind(__s, __pos, __n);
722     }
723
724     size_type
725     rfind(const _CharT* __s, size_type __pos = _Base::npos) const
726     {
727       __glibcxx_check_string(__s);
728       return _Base::rfind(__s, __pos);
729     }
730
731     size_type
732     rfind(_CharT __c, size_type __pos = _Base::npos) const
733     { return _Base::rfind(__c, __pos); }
734
735     size_type
736     find_first_of(const basic_string& __str, size_type __pos = 0) const
737     { return _Base::find_first_of(__str, __pos); }
738
739     size_type
740     find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
741     {
742       __glibcxx_check_string(__s);
743       return _Base::find_first_of(__s, __pos, __n);
744     }
745
746     size_type
747     find_first_of(const _CharT* __s, size_type __pos = 0) const
748     {
749       __glibcxx_check_string(__s);
750       return _Base::find_first_of(__s, __pos);
751     }
752
753     size_type
754     find_first_of(_CharT __c, size_type __pos = 0) const
755     { return _Base::find_first_of(__c, __pos); }
756
757     size_type
758     find_last_of(const basic_string& __str, 
759                  size_type __pos = _Base::npos) const
760     { return _Base::find_last_of(__str, __pos); }
761
762     size_type
763     find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
764     {
765       __glibcxx_check_string(__s);
766       return _Base::find_last_of(__s, __pos, __n);
767     }
768
769     size_type
770     find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const
771     {
772       __glibcxx_check_string(__s);
773       return _Base::find_last_of(__s, __pos);
774     }
775
776     size_type
777     find_last_of(_CharT __c, size_type __pos = _Base::npos) const
778     { return _Base::find_last_of(__c, __pos); }
779
780     size_type
781     find_first_not_of(const basic_string& __str, size_type __pos = 0) const
782     { return _Base::find_first_not_of(__str, __pos); }
783
784     size_type
785     find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
786     {
787       __glibcxx_check_string_len(__s, __n);
788       return _Base::find_first_not_of(__s, __pos, __n);
789     }
790
791     size_type
792     find_first_not_of(const _CharT* __s, size_type __pos = 0) const
793     {
794       __glibcxx_check_string(__s);
795       return _Base::find_first_not_of(__s, __pos);
796     }
797
798     size_type
799     find_first_not_of(_CharT __c, size_type __pos = 0) const
800     { return _Base::find_first_not_of(__c, __pos); }
801
802     size_type
803     find_last_not_of(const basic_string& __str,
804                                   size_type __pos = _Base::npos) const
805     { return _Base::find_last_not_of(__str, __pos); }
806
807     size_type
808     find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
809     {
810       __glibcxx_check_string(__s);
811       return _Base::find_last_not_of(__s, __pos, __n);
812     }
813
814     size_type
815     find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const
816     {
817       __glibcxx_check_string(__s);
818       return _Base::find_last_not_of(__s, __pos);
819     }
820
821     size_type
822     find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const
823     { return _Base::find_last_not_of(__c, __pos); }
824
825     basic_string
826     substr(size_type __pos = 0, size_type __n = _Base::npos) const
827     { return basic_string(_Base::substr(__pos, __n)); }
828
829     int
830     compare(const basic_string& __str) const
831     { return _Base::compare(__str); }
832
833     int
834     compare(size_type __pos1, size_type __n1,
835                   const basic_string& __str) const
836     { return _Base::compare(__pos1, __n1, __str); }
837
838     int
839     compare(size_type __pos1, size_type __n1, const basic_string& __str,
840               size_type __pos2, size_type __n2) const
841     { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); }
842
843     int
844     compare(const _CharT* __s) const
845     {
846       __glibcxx_check_string(__s);
847       return _Base::compare(__s);
848     }
849
850     //  _GLIBCXX_RESOLVE_LIB_DEFECTS
851     //  5. string::compare specification questionable
852     int
853     compare(size_type __pos1, size_type __n1, const _CharT* __s) const
854     {
855       __glibcxx_check_string(__s);
856       return _Base::compare(__pos1, __n1, __s);
857     }
858
859     //  _GLIBCXX_RESOLVE_LIB_DEFECTS
860     //  5. string::compare specification questionable
861     int
862     compare(size_type __pos1, size_type __n1,const _CharT* __s,
863               size_type __n2) const
864     {
865       __glibcxx_check_string_len(__s, __n2);
866       return _Base::compare(__pos1, __n1, __s, __n2);
867     }
868
869     _Base&
870     _M_base() { return *this; }
871
872     const _Base&
873     _M_base() const { return *this; }
874
875     using _Safe_base::_M_invalidate_all;
876   };
877
878   template<typename _CharT, typename _Traits, typename _Allocator>
879     inline basic_string<_CharT,_Traits,_Allocator>
880     operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
881               const basic_string<_CharT,_Traits,_Allocator>& __rhs)
882     { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
883
884   template<typename _CharT, typename _Traits, typename _Allocator>
885     inline basic_string<_CharT,_Traits,_Allocator>
886     operator+(const _CharT* __lhs,
887               const basic_string<_CharT,_Traits,_Allocator>& __rhs)
888     {
889       __glibcxx_check_string(__lhs);
890       return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
891     }
892
893   template<typename _CharT, typename _Traits, typename _Allocator>
894     inline basic_string<_CharT,_Traits,_Allocator>
895     operator+(_CharT __lhs,
896               const basic_string<_CharT,_Traits,_Allocator>& __rhs)
897     { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
898
899   template<typename _CharT, typename _Traits, typename _Allocator>
900     inline basic_string<_CharT,_Traits,_Allocator>
901     operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
902               const _CharT* __rhs)
903     {
904       __glibcxx_check_string(__rhs);
905       return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
906     }
907
908   template<typename _CharT, typename _Traits, typename _Allocator>
909     inline basic_string<_CharT,_Traits,_Allocator>
910     operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
911               _CharT __rhs)
912     { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
913
914   template<typename _CharT, typename _Traits, typename _Allocator>
915     inline bool
916     operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
917                const basic_string<_CharT,_Traits,_Allocator>& __rhs)
918     { return __lhs._M_base() == __rhs._M_base(); }
919
920   template<typename _CharT, typename _Traits, typename _Allocator>
921     inline bool
922     operator==(const _CharT* __lhs,
923                const basic_string<_CharT,_Traits,_Allocator>& __rhs)
924     {
925       __glibcxx_check_string(__lhs);
926       return __lhs == __rhs._M_base();
927     }
928
929   template<typename _CharT, typename _Traits, typename _Allocator>
930     inline bool
931     operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
932                const _CharT* __rhs)
933     {
934       __glibcxx_check_string(__rhs);
935       return __lhs._M_base() == __rhs;
936     }
937
938   template<typename _CharT, typename _Traits, typename _Allocator>
939     inline bool
940     operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
941                const basic_string<_CharT,_Traits,_Allocator>& __rhs)
942     { return __lhs._M_base() != __rhs._M_base(); }
943
944   template<typename _CharT, typename _Traits, typename _Allocator>
945     inline bool
946     operator!=(const _CharT* __lhs,
947                const basic_string<_CharT,_Traits,_Allocator>& __rhs)
948     {
949       __glibcxx_check_string(__lhs);
950       return __lhs != __rhs._M_base();
951     }
952
953   template<typename _CharT, typename _Traits, typename _Allocator>
954     inline bool
955     operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
956                const _CharT* __rhs)
957     {
958       __glibcxx_check_string(__rhs);
959       return __lhs._M_base() != __rhs;
960     }
961
962   template<typename _CharT, typename _Traits, typename _Allocator>
963     inline bool
964     operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
965               const basic_string<_CharT,_Traits,_Allocator>& __rhs)
966     { return __lhs._M_base() < __rhs._M_base(); }
967
968   template<typename _CharT, typename _Traits, typename _Allocator>
969     inline bool
970     operator<(const _CharT* __lhs,
971               const basic_string<_CharT,_Traits,_Allocator>& __rhs)
972     {
973       __glibcxx_check_string(__lhs);
974       return __lhs < __rhs._M_base();
975     }
976
977   template<typename _CharT, typename _Traits, typename _Allocator>
978     inline bool
979     operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
980               const _CharT* __rhs)
981     {
982       __glibcxx_check_string(__rhs);
983       return __lhs._M_base() < __rhs;
984     }
985
986   template<typename _CharT, typename _Traits, typename _Allocator>
987     inline bool
988     operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
989                const basic_string<_CharT,_Traits,_Allocator>& __rhs)
990     { return __lhs._M_base() <= __rhs._M_base(); }
991
992   template<typename _CharT, typename _Traits, typename _Allocator>
993     inline bool
994     operator<=(const _CharT* __lhs,
995                const basic_string<_CharT,_Traits,_Allocator>& __rhs)
996     {
997       __glibcxx_check_string(__lhs);
998       return __lhs <= __rhs._M_base();
999     }
1000
1001   template<typename _CharT, typename _Traits, typename _Allocator>
1002     inline bool
1003     operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1004                const _CharT* __rhs)
1005     {
1006       __glibcxx_check_string(__rhs);
1007       return __lhs._M_base() <= __rhs;
1008     }
1009
1010   template<typename _CharT, typename _Traits, typename _Allocator>
1011     inline bool
1012     operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1013                const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1014     { return __lhs._M_base() >= __rhs._M_base(); }
1015
1016   template<typename _CharT, typename _Traits, typename _Allocator>
1017     inline bool
1018     operator>=(const _CharT* __lhs,
1019                const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1020     {
1021       __glibcxx_check_string(__lhs);
1022       return __lhs >= __rhs._M_base();
1023     }
1024
1025   template<typename _CharT, typename _Traits, typename _Allocator>
1026     inline bool
1027     operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1028                const _CharT* __rhs)
1029     {
1030       __glibcxx_check_string(__rhs);
1031       return __lhs._M_base() >= __rhs;
1032     }
1033
1034   template<typename _CharT, typename _Traits, typename _Allocator>
1035     inline bool
1036     operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1037               const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1038     { return __lhs._M_base() > __rhs._M_base(); }
1039
1040   template<typename _CharT, typename _Traits, typename _Allocator>
1041     inline bool
1042     operator>(const _CharT* __lhs,
1043               const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1044     {
1045       __glibcxx_check_string(__lhs);
1046       return __lhs > __rhs._M_base();
1047     }
1048
1049   template<typename _CharT, typename _Traits, typename _Allocator>
1050     inline bool
1051     operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1052               const _CharT* __rhs)
1053     {
1054       __glibcxx_check_string(__rhs);
1055       return __lhs._M_base() > __rhs;
1056     }
1057
1058   // 21.3.7.8:
1059   template<typename _CharT, typename _Traits, typename _Allocator>
1060     inline void
1061     swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1062          basic_string<_CharT,_Traits,_Allocator>& __rhs)
1063     { __lhs.swap(__rhs); }
1064
1065   template<typename _CharT, typename _Traits, typename _Allocator>
1066     std::basic_ostream<_CharT, _Traits>&
1067     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1068                const basic_string<_CharT, _Traits, _Allocator>& __str)
1069     { return __os << __str._M_base(); }
1070
1071   template<typename _CharT, typename _Traits, typename _Allocator>
1072     std::basic_istream<_CharT,_Traits>&
1073     operator>>(std::basic_istream<_CharT,_Traits>& __is,
1074                basic_string<_CharT,_Traits,_Allocator>& __str)
1075     {
1076       std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base();
1077       __str._M_invalidate_all();
1078       return __res;
1079     }
1080
1081   template<typename _CharT, typename _Traits, typename _Allocator>
1082     std::basic_istream<_CharT,_Traits>&
1083     getline(std::basic_istream<_CharT,_Traits>& __is,
1084             basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1085     {
1086       std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1087                                                           __str._M_base(),
1088                                                         __delim);
1089       __str._M_invalidate_all();
1090       return __res;
1091     }
1092
1093   template<typename _CharT, typename _Traits, typename _Allocator>
1094     std::basic_istream<_CharT,_Traits>&
1095     getline(std::basic_istream<_CharT,_Traits>& __is,
1096             basic_string<_CharT,_Traits,_Allocator>& __str)
1097     {
1098       std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1099                                                           __str._M_base());
1100       __str._M_invalidate_all();
1101       return __res;
1102     }
1103
1104   typedef basic_string<char>    string;
1105
1106 #ifdef _GLIBCXX_USE_WCHAR_T
1107   typedef basic_string<wchar_t> wstring;
1108 #endif
1109
1110 } // namespace __gnu_debug
1111
1112 #endif