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