]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/debug/string
aa611b2d4a9b7c5bd6076b15b7b76d57feb497e1
[thirdparty/gcc.git] / libstdc++-v3 / include / debug / string
1 // Debugging string implementation -*- C++ -*-
2
3 // Copyright (C) 2003-2018 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24
25 /** @file debug/string
26 * This file is a GNU debug extension to the Standard C++ Library.
27 */
28
29 #ifndef _GLIBCXX_DEBUG_STRING
30 #define _GLIBCXX_DEBUG_STRING 1
31
32 #pragma GCC system_header
33
34 #include <string>
35 #include <debug/safe_sequence.h>
36 #include <debug/safe_container.h>
37 #include <debug/safe_iterator.h>
38
39 namespace __gnu_debug
40 {
41 /// Class std::basic_string with safety/checking/debug instrumentation.
42 template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
43 typename _Allocator = std::allocator<_CharT> >
44 class basic_string
45 : public __gnu_debug::_Safe_container<
46 basic_string<_CharT, _Traits, _Allocator>,
47 _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>,
48 public std::basic_string<_CharT, _Traits, _Allocator>
49 {
50 typedef std::basic_string<_CharT, _Traits, _Allocator> _Base;
51 typedef __gnu_debug::_Safe_container<
52 basic_string, _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>
53 _Safe;
54
55 public:
56 // types:
57 typedef _Traits traits_type;
58 typedef typename _Traits::char_type value_type;
59 typedef _Allocator allocator_type;
60 typedef typename _Base::size_type size_type;
61 typedef typename _Base::difference_type difference_type;
62 typedef typename _Base::reference reference;
63 typedef typename _Base::const_reference const_reference;
64 typedef typename _Base::pointer pointer;
65 typedef typename _Base::const_pointer const_pointer;
66
67 typedef __gnu_debug::_Safe_iterator<
68 typename _Base::iterator, basic_string> iterator;
69 typedef __gnu_debug::_Safe_iterator<
70 typename _Base::const_iterator, basic_string> const_iterator;
71
72 typedef std::reverse_iterator<iterator> reverse_iterator;
73 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
74
75 using _Base::npos;
76
77 basic_string()
78 _GLIBCXX_NOEXCEPT_IF(std::is_nothrow_default_constructible<_Base>::value)
79 : _Base() { }
80
81 // 21.3.1 construct/copy/destroy:
82 explicit
83 basic_string(const _Allocator& __a) _GLIBCXX_NOEXCEPT
84 : _Base(__a) { }
85
86 #if __cplusplus < 201103L
87 basic_string(const basic_string& __str)
88 : _Base(__str) { }
89
90 ~basic_string() { }
91 #else
92 basic_string(const basic_string&) = default;
93 basic_string(basic_string&&) = default;
94
95 basic_string(std::initializer_list<_CharT> __l,
96 const _Allocator& __a = _Allocator())
97 : _Base(__l, __a)
98 { }
99
100 #if _GLIBCXX_USE_CXX11_ABI
101 basic_string(const basic_string& __s, const _Allocator& __a)
102 : _Base(__s, __a) { }
103
104 basic_string(basic_string&& __s, const _Allocator& __a)
105 : _Base(std::move(__s), __a) { }
106 #endif
107
108 ~basic_string() = default;
109
110 // Provides conversion from a normal-mode string to a debug-mode string
111 basic_string(_Base&& __base) noexcept
112 : _Base(std::move(__base)) { }
113 #endif // C++11
114
115 // Provides conversion from a normal-mode string to a debug-mode string
116 basic_string(const _Base& __base)
117 : _Base(__base) { }
118
119 // _GLIBCXX_RESOLVE_LIB_DEFECTS
120 // 42. string ctors specify wrong default allocator
121 basic_string(const basic_string& __str, size_type __pos,
122 size_type __n = _Base::npos,
123 const _Allocator& __a = _Allocator())
124 : _Base(__str, __pos, __n, __a) { }
125
126 basic_string(const _CharT* __s, size_type __n,
127 const _Allocator& __a = _Allocator())
128 : _Base(__gnu_debug::__check_string(__s, __n), __n, __a) { }
129
130 basic_string(const _CharT* __s, const _Allocator& __a = _Allocator())
131 : _Base(__gnu_debug::__check_string(__s), __a)
132 { this->assign(__s); }
133
134 basic_string(size_type __n, _CharT __c,
135 const _Allocator& __a = _Allocator())
136 : _Base(__n, __c, __a) { }
137
138 template<typename _InputIterator>
139 basic_string(_InputIterator __begin, _InputIterator __end,
140 const _Allocator& __a = _Allocator())
141 : _Base(__gnu_debug::__base(
142 __glibcxx_check_valid_constructor_range(__begin, __end)),
143 __gnu_debug::__base(__end), __a) { }
144
145 #if __cplusplus < 201103L
146 basic_string&
147 operator=(const basic_string& __str)
148 {
149 this->_M_safe() = __str;
150 _M_base() = __str;
151 return *this;
152 }
153 #else
154 basic_string&
155 operator=(const basic_string&) = default;
156
157 basic_string&
158 operator=(basic_string&&) = default;
159 #endif
160
161 basic_string&
162 operator=(const _CharT* __s)
163 {
164 __glibcxx_check_string(__s);
165 _M_base() = __s;
166 this->_M_invalidate_all();
167 return *this;
168 }
169
170 basic_string&
171 operator=(_CharT __c)
172 {
173 _M_base() = __c;
174 this->_M_invalidate_all();
175 return *this;
176 }
177
178 #if __cplusplus >= 201103L
179 basic_string&
180 operator=(std::initializer_list<_CharT> __l)
181 {
182 _M_base() = __l;
183 this->_M_invalidate_all();
184 return *this;
185 }
186 #endif // C++11
187
188 // 21.3.2 iterators:
189 iterator
190 begin() // _GLIBCXX_NOEXCEPT
191 { return iterator(_Base::begin(), this); }
192
193 const_iterator
194 begin() const _GLIBCXX_NOEXCEPT
195 { return const_iterator(_Base::begin(), this); }
196
197 iterator
198 end() // _GLIBCXX_NOEXCEPT
199 { return iterator(_Base::end(), this); }
200
201 const_iterator
202 end() const _GLIBCXX_NOEXCEPT
203 { return const_iterator(_Base::end(), this); }
204
205 reverse_iterator
206 rbegin() // _GLIBCXX_NOEXCEPT
207 { return reverse_iterator(end()); }
208
209 const_reverse_iterator
210 rbegin() const _GLIBCXX_NOEXCEPT
211 { return const_reverse_iterator(end()); }
212
213 reverse_iterator
214 rend() // _GLIBCXX_NOEXCEPT
215 { return reverse_iterator(begin()); }
216
217 const_reverse_iterator
218 rend() const _GLIBCXX_NOEXCEPT
219 { return const_reverse_iterator(begin()); }
220
221 #if __cplusplus >= 201103L
222 const_iterator
223 cbegin() const noexcept
224 { return const_iterator(_Base::begin(), this); }
225
226 const_iterator
227 cend() const noexcept
228 { return const_iterator(_Base::end(), this); }
229
230 const_reverse_iterator
231 crbegin() const noexcept
232 { return const_reverse_iterator(end()); }
233
234 const_reverse_iterator
235 crend() const noexcept
236 { return const_reverse_iterator(begin()); }
237 #endif
238
239 // 21.3.3 capacity:
240 using _Base::size;
241 using _Base::length;
242 using _Base::max_size;
243
244 void
245 resize(size_type __n, _CharT __c)
246 {
247 _Base::resize(__n, __c);
248 this->_M_invalidate_all();
249 }
250
251 void
252 resize(size_type __n)
253 { this->resize(__n, _CharT()); }
254
255 #if __cplusplus >= 201103L
256 void
257 shrink_to_fit() noexcept
258 {
259 if (capacity() > size())
260 {
261 __try
262 {
263 reserve(0);
264 this->_M_invalidate_all();
265 }
266 __catch(...)
267 { }
268 }
269 }
270 #endif
271
272 using _Base::capacity;
273 using _Base::reserve;
274
275 void
276 clear() // _GLIBCXX_NOEXCEPT
277 {
278 _Base::clear();
279 this->_M_invalidate_all();
280 }
281
282 using _Base::empty;
283
284 // 21.3.4 element access:
285 const_reference
286 operator[](size_type __pos) const _GLIBCXX_NOEXCEPT
287 {
288 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
289 _M_message(__gnu_debug::__msg_subscript_oob)
290 ._M_sequence(*this, "this")
291 ._M_integer(__pos, "__pos")
292 ._M_integer(this->size(), "size"));
293 return _M_base()[__pos];
294 }
295
296 reference
297 operator[](size_type __pos) // _GLIBCXX_NOEXCEPT
298 {
299 #if __cplusplus < 201103L && defined(_GLIBCXX_DEBUG_PEDANTIC)
300 __glibcxx_check_subscript(__pos);
301 #else
302 // as an extension v3 allows s[s.size()] when s is non-const.
303 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
304 _M_message(__gnu_debug::__msg_subscript_oob)
305 ._M_sequence(*this, "this")
306 ._M_integer(__pos, "__pos")
307 ._M_integer(this->size(), "size"));
308 #endif
309 return _M_base()[__pos];
310 }
311
312 using _Base::at;
313
314 #if __cplusplus >= 201103L
315 using _Base::front;
316 using _Base::back;
317 #endif
318
319 // 21.3.5 modifiers:
320 basic_string&
321 operator+=(const basic_string& __str)
322 {
323 _M_base() += __str;
324 this->_M_invalidate_all();
325 return *this;
326 }
327
328 basic_string&
329 operator+=(const _CharT* __s)
330 {
331 __glibcxx_check_string(__s);
332 _M_base() += __s;
333 this->_M_invalidate_all();
334 return *this;
335 }
336
337 basic_string&
338 operator+=(_CharT __c)
339 {
340 _M_base() += __c;
341 this->_M_invalidate_all();
342 return *this;
343 }
344
345 #if __cplusplus >= 201103L
346 basic_string&
347 operator+=(std::initializer_list<_CharT> __l)
348 {
349 _M_base() += __l;
350 this->_M_invalidate_all();
351 return *this;
352 }
353 #endif // C++11
354
355 basic_string&
356 append(const basic_string& __str)
357 {
358 _Base::append(__str);
359 this->_M_invalidate_all();
360 return *this;
361 }
362
363 basic_string&
364 append(const basic_string& __str, size_type __pos, size_type __n)
365 {
366 _Base::append(__str, __pos, __n);
367 this->_M_invalidate_all();
368 return *this;
369 }
370
371 basic_string&
372 append(const _CharT* __s, size_type __n)
373 {
374 __glibcxx_check_string_len(__s, __n);
375 _Base::append(__s, __n);
376 this->_M_invalidate_all();
377 return *this;
378 }
379
380 basic_string&
381 append(const _CharT* __s)
382 {
383 __glibcxx_check_string(__s);
384 _Base::append(__s);
385 this->_M_invalidate_all();
386 return *this;
387 }
388
389 basic_string&
390 append(size_type __n, _CharT __c)
391 {
392 _Base::append(__n, __c);
393 this->_M_invalidate_all();
394 return *this;
395 }
396
397 template<typename _InputIterator>
398 basic_string&
399 append(_InputIterator __first, _InputIterator __last)
400 {
401 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
402 __glibcxx_check_valid_range2(__first, __last, __dist);
403
404 if (__dist.second >= __dp_sign)
405 _Base::append(__gnu_debug::__unsafe(__first),
406 __gnu_debug::__unsafe(__last));
407 else
408 _Base::append(__first, __last);
409
410 this->_M_invalidate_all();
411 return *this;
412 }
413
414 // _GLIBCXX_RESOLVE_LIB_DEFECTS
415 // 7. string clause minor problems
416 void
417 push_back(_CharT __c)
418 {
419 _Base::push_back(__c);
420 this->_M_invalidate_all();
421 }
422
423 basic_string&
424 assign(const basic_string& __x)
425 {
426 _Base::assign(__x);
427 this->_M_invalidate_all();
428 return *this;
429 }
430
431 #if __cplusplus >= 201103L
432 basic_string&
433 assign(basic_string&& __x)
434 noexcept(noexcept(std::declval<_Base&>().assign(std::move(__x))))
435 {
436 _Base::assign(std::move(__x));
437 this->_M_invalidate_all();
438 return *this;
439 }
440 #endif // C++11
441
442 basic_string&
443 assign(const basic_string& __str, size_type __pos, size_type __n)
444 {
445 _Base::assign(__str, __pos, __n);
446 this->_M_invalidate_all();
447 return *this;
448 }
449
450 basic_string&
451 assign(const _CharT* __s, size_type __n)
452 {
453 __glibcxx_check_string_len(__s, __n);
454 _Base::assign(__s, __n);
455 this->_M_invalidate_all();
456 return *this;
457 }
458
459 basic_string&
460 assign(const _CharT* __s)
461 {
462 __glibcxx_check_string(__s);
463 _Base::assign(__s);
464 this->_M_invalidate_all();
465 return *this;
466 }
467
468 basic_string&
469 assign(size_type __n, _CharT __c)
470 {
471 _Base::assign(__n, __c);
472 this->_M_invalidate_all();
473 return *this;
474 }
475
476 template<typename _InputIterator>
477 basic_string&
478 assign(_InputIterator __first, _InputIterator __last)
479 {
480 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
481 __glibcxx_check_valid_range2(__first, __last, __dist);
482
483 if (__dist.second >= __dp_sign)
484 _Base::assign(__gnu_debug::__unsafe(__first),
485 __gnu_debug::__unsafe(__last));
486 else
487 _Base::assign(__first, __last);
488
489 this->_M_invalidate_all();
490 return *this;
491 }
492
493 #if __cplusplus >= 201103L
494 basic_string&
495 assign(std::initializer_list<_CharT> __l)
496 {
497 _Base::assign(__l);
498 this->_M_invalidate_all();
499 return *this;
500 }
501 #endif // C++11
502
503 basic_string&
504 insert(size_type __pos1, const basic_string& __str)
505 {
506 _Base::insert(__pos1, __str);
507 this->_M_invalidate_all();
508 return *this;
509 }
510
511 basic_string&
512 insert(size_type __pos1, const basic_string& __str,
513 size_type __pos2, size_type __n)
514 {
515 _Base::insert(__pos1, __str, __pos2, __n);
516 this->_M_invalidate_all();
517 return *this;
518 }
519
520 basic_string&
521 insert(size_type __pos, const _CharT* __s, size_type __n)
522 {
523 __glibcxx_check_string(__s);
524 _Base::insert(__pos, __s, __n);
525 this->_M_invalidate_all();
526 return *this;
527 }
528
529 basic_string&
530 insert(size_type __pos, const _CharT* __s)
531 {
532 __glibcxx_check_string(__s);
533 _Base::insert(__pos, __s);
534 this->_M_invalidate_all();
535 return *this;
536 }
537
538 basic_string&
539 insert(size_type __pos, size_type __n, _CharT __c)
540 {
541 _Base::insert(__pos, __n, __c);
542 this->_M_invalidate_all();
543 return *this;
544 }
545
546 iterator
547 insert(const_iterator __p, _CharT __c)
548 {
549 __glibcxx_check_insert(__p);
550 typename _Base::iterator __res = _Base::insert(__p.base(), __c);
551 this->_M_invalidate_all();
552 return iterator(__res, this);
553 }
554
555 iterator
556 insert(const_iterator __p, size_type __n, _CharT __c)
557 {
558 __glibcxx_check_insert(__p);
559 typename _Base::iterator __res = _Base::insert(__p.base(), __n, __c);
560 this->_M_invalidate_all();
561 return iterator(__res, this);
562 }
563
564 template<typename _InputIterator>
565 iterator
566 insert(const_iterator __p, _InputIterator __first, _InputIterator __last)
567 {
568 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
569 __glibcxx_check_insert_range2(__p, __first, __last, __dist);
570
571 typename _Base::iterator __res;
572 if (__dist.second >= __dp_sign)
573 __res = _Base::insert(__p.base(), __gnu_debug::__unsafe(__first),
574 __gnu_debug::__unsafe(__last));
575 else
576 __res = _Base::insert(__p.base(), __first, __last);
577 this->_M_invalidate_all();
578 return iterator(__res, this);
579 }
580
581 #if __cplusplus >= 201103L
582 iterator
583 insert(const_iterator __p, std::initializer_list<_CharT> __l)
584 {
585 __glibcxx_check_insert(__p);
586 const auto __res = _Base::insert(__p.base(), __l);
587 this->_M_invalidate_all();
588 return iterator(__res, this);
589 }
590 #endif // C++11
591
592 basic_string&
593 erase(size_type __pos = 0, size_type __n = _Base::npos)
594 {
595 _Base::erase(__pos, __n);
596 this->_M_invalidate_all();
597 return *this;
598 }
599
600 iterator
601 erase(iterator __position)
602 {
603 __glibcxx_check_erase(__position);
604 typename _Base::iterator __res = _Base::erase(__position.base());
605 this->_M_invalidate_all();
606 return iterator(__res, this);
607 }
608
609 iterator
610 erase(iterator __first, iterator __last)
611 {
612 // _GLIBCXX_RESOLVE_LIB_DEFECTS
613 // 151. can't currently clear() empty container
614 __glibcxx_check_erase_range(__first, __last);
615 typename _Base::iterator __res = _Base::erase(__first.base(),
616 __last.base());
617 this->_M_invalidate_all();
618 return iterator(__res, this);
619 }
620
621 #if __cplusplus >= 201103L
622 void
623 pop_back() // noexcept
624 {
625 __glibcxx_check_nonempty();
626 _Base::pop_back();
627 this->_M_invalidate_all();
628 }
629 #endif // C++11
630
631 basic_string&
632 replace(size_type __pos1, size_type __n1, const basic_string& __str)
633 {
634 _Base::replace(__pos1, __n1, __str);
635 this->_M_invalidate_all();
636 return *this;
637 }
638
639 basic_string&
640 replace(size_type __pos1, size_type __n1, const basic_string& __str,
641 size_type __pos2, size_type __n2)
642 {
643 _Base::replace(__pos1, __n1, __str, __pos2, __n2);
644 this->_M_invalidate_all();
645 return *this;
646 }
647
648 basic_string&
649 replace(size_type __pos, size_type __n1, const _CharT* __s,
650 size_type __n2)
651 {
652 __glibcxx_check_string_len(__s, __n2);
653 _Base::replace(__pos, __n1, __s, __n2);
654 this->_M_invalidate_all();
655 return *this;
656 }
657
658 basic_string&
659 replace(size_type __pos, size_type __n1, const _CharT* __s)
660 {
661 __glibcxx_check_string(__s);
662 _Base::replace(__pos, __n1, __s);
663 this->_M_invalidate_all();
664 return *this;
665 }
666
667 basic_string&
668 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
669 {
670 _Base::replace(__pos, __n1, __n2, __c);
671 this->_M_invalidate_all();
672 return *this;
673 }
674
675 basic_string&
676 replace(iterator __i1, iterator __i2, const basic_string& __str)
677 {
678 __glibcxx_check_erase_range(__i1, __i2);
679 _Base::replace(__i1.base(), __i2.base(), __str);
680 this->_M_invalidate_all();
681 return *this;
682 }
683
684 basic_string&
685 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
686 {
687 __glibcxx_check_erase_range(__i1, __i2);
688 __glibcxx_check_string_len(__s, __n);
689 _Base::replace(__i1.base(), __i2.base(), __s, __n);
690 this->_M_invalidate_all();
691 return *this;
692 }
693
694 basic_string&
695 replace(iterator __i1, iterator __i2, const _CharT* __s)
696 {
697 __glibcxx_check_erase_range(__i1, __i2);
698 __glibcxx_check_string(__s);
699 _Base::replace(__i1.base(), __i2.base(), __s);
700 this->_M_invalidate_all();
701 return *this;
702 }
703
704 basic_string&
705 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
706 {
707 __glibcxx_check_erase_range(__i1, __i2);
708 _Base::replace(__i1.base(), __i2.base(), __n, __c);
709 this->_M_invalidate_all();
710 return *this;
711 }
712
713 template<typename _InputIterator>
714 basic_string&
715 replace(iterator __i1, iterator __i2,
716 _InputIterator __j1, _InputIterator __j2)
717 {
718 __glibcxx_check_erase_range(__i1, __i2);
719
720 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
721 __glibcxx_check_valid_range2(__j1, __j2, __dist);
722
723 if (__dist.second >= __dp_sign)
724 _Base::replace(__i1.base(), __i2.base(),
725 __gnu_debug::__unsafe(__j1),
726 __gnu_debug::__unsafe(__j2));
727 else
728 _Base::replace(__i1.base(), __i2.base(), __j1, __j2);
729
730 this->_M_invalidate_all();
731 return *this;
732 }
733
734 #if __cplusplus >= 201103L
735 basic_string& replace(iterator __i1, iterator __i2,
736 std::initializer_list<_CharT> __l)
737 {
738 __glibcxx_check_erase_range(__i1, __i2);
739 _Base::replace(__i1.base(), __i2.base(), __l);
740 this->_M_invalidate_all();
741 return *this;
742 }
743 #endif // C++11
744
745 size_type
746 copy(_CharT* __s, size_type __n, size_type __pos = 0) const
747 {
748 __glibcxx_check_string_len(__s, __n);
749 return _Base::copy(__s, __n, __pos);
750 }
751
752 void
753 swap(basic_string& __x)
754 _GLIBCXX_NOEXCEPT_IF(std::__is_nothrow_swappable<_Base>::value)
755 {
756 _Safe::_M_swap(__x);
757 _Base::swap(__x);
758 }
759
760 // 21.3.6 string operations:
761 const _CharT*
762 c_str() const _GLIBCXX_NOEXCEPT
763 {
764 const _CharT* __res = _Base::c_str();
765 this->_M_invalidate_all();
766 return __res;
767 }
768
769 const _CharT*
770 data() const _GLIBCXX_NOEXCEPT
771 {
772 const _CharT* __res = _Base::data();
773 this->_M_invalidate_all();
774 return __res;
775 }
776
777 using _Base::get_allocator;
778
779 size_type
780 find(const basic_string& __str, size_type __pos = 0) const
781 _GLIBCXX_NOEXCEPT
782 { return _Base::find(__str, __pos); }
783
784 size_type
785 find(const _CharT* __s, size_type __pos, size_type __n) const
786 {
787 __glibcxx_check_string(__s);
788 return _Base::find(__s, __pos, __n);
789 }
790
791 size_type
792 find(const _CharT* __s, size_type __pos = 0) const
793 {
794 __glibcxx_check_string(__s);
795 return _Base::find(__s, __pos);
796 }
797
798 size_type
799 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
800 { return _Base::find(__c, __pos); }
801
802 size_type
803 rfind(const basic_string& __str, size_type __pos = _Base::npos) const
804 _GLIBCXX_NOEXCEPT
805 { return _Base::rfind(__str, __pos); }
806
807 size_type
808 rfind(const _CharT* __s, size_type __pos, size_type __n) const
809 {
810 __glibcxx_check_string_len(__s, __n);
811 return _Base::rfind(__s, __pos, __n);
812 }
813
814 size_type
815 rfind(const _CharT* __s, size_type __pos = _Base::npos) const
816 {
817 __glibcxx_check_string(__s);
818 return _Base::rfind(__s, __pos);
819 }
820
821 size_type
822 rfind(_CharT __c, size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
823 { return _Base::rfind(__c, __pos); }
824
825 size_type
826 find_first_of(const basic_string& __str, size_type __pos = 0) const
827 _GLIBCXX_NOEXCEPT
828 { return _Base::find_first_of(__str, __pos); }
829
830 size_type
831 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
832 {
833 __glibcxx_check_string(__s);
834 return _Base::find_first_of(__s, __pos, __n);
835 }
836
837 size_type
838 find_first_of(const _CharT* __s, size_type __pos = 0) const
839 {
840 __glibcxx_check_string(__s);
841 return _Base::find_first_of(__s, __pos);
842 }
843
844 size_type
845 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
846 { return _Base::find_first_of(__c, __pos); }
847
848 size_type
849 find_last_of(const basic_string& __str,
850 size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
851 { return _Base::find_last_of(__str, __pos); }
852
853 size_type
854 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
855 {
856 __glibcxx_check_string(__s);
857 return _Base::find_last_of(__s, __pos, __n);
858 }
859
860 size_type
861 find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const
862 {
863 __glibcxx_check_string(__s);
864 return _Base::find_last_of(__s, __pos);
865 }
866
867 size_type
868 find_last_of(_CharT __c, size_type __pos = _Base::npos) const
869 _GLIBCXX_NOEXCEPT
870 { return _Base::find_last_of(__c, __pos); }
871
872 size_type
873 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
874 _GLIBCXX_NOEXCEPT
875 { return _Base::find_first_not_of(__str, __pos); }
876
877 size_type
878 find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
879 {
880 __glibcxx_check_string_len(__s, __n);
881 return _Base::find_first_not_of(__s, __pos, __n);
882 }
883
884 size_type
885 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
886 {
887 __glibcxx_check_string(__s);
888 return _Base::find_first_not_of(__s, __pos);
889 }
890
891 size_type
892 find_first_not_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
893 { return _Base::find_first_not_of(__c, __pos); }
894
895 size_type
896 find_last_not_of(const basic_string& __str,
897 size_type __pos = _Base::npos) const
898 _GLIBCXX_NOEXCEPT
899 { return _Base::find_last_not_of(__str, __pos); }
900
901 size_type
902 find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
903 {
904 __glibcxx_check_string(__s);
905 return _Base::find_last_not_of(__s, __pos, __n);
906 }
907
908 size_type
909 find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const
910 {
911 __glibcxx_check_string(__s);
912 return _Base::find_last_not_of(__s, __pos);
913 }
914
915 size_type
916 find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const
917 _GLIBCXX_NOEXCEPT
918 { return _Base::find_last_not_of(__c, __pos); }
919
920 basic_string
921 substr(size_type __pos = 0, size_type __n = _Base::npos) const
922 { return basic_string(_Base::substr(__pos, __n)); }
923
924 int
925 compare(const basic_string& __str) const
926 { return _Base::compare(__str); }
927
928 int
929 compare(size_type __pos1, size_type __n1,
930 const basic_string& __str) const
931 { return _Base::compare(__pos1, __n1, __str); }
932
933 int
934 compare(size_type __pos1, size_type __n1, const basic_string& __str,
935 size_type __pos2, size_type __n2) const
936 { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); }
937
938 int
939 compare(const _CharT* __s) const
940 {
941 __glibcxx_check_string(__s);
942 return _Base::compare(__s);
943 }
944
945 // _GLIBCXX_RESOLVE_LIB_DEFECTS
946 // 5. string::compare specification questionable
947 int
948 compare(size_type __pos1, size_type __n1, const _CharT* __s) const
949 {
950 __glibcxx_check_string(__s);
951 return _Base::compare(__pos1, __n1, __s);
952 }
953
954 // _GLIBCXX_RESOLVE_LIB_DEFECTS
955 // 5. string::compare specification questionable
956 int
957 compare(size_type __pos1, size_type __n1,const _CharT* __s,
958 size_type __n2) const
959 {
960 __glibcxx_check_string_len(__s, __n2);
961 return _Base::compare(__pos1, __n1, __s, __n2);
962 }
963
964 _Base&
965 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
966
967 const _Base&
968 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
969
970 using _Safe::_M_invalidate_all;
971 };
972
973 template<typename _CharT, typename _Traits, typename _Allocator>
974 inline basic_string<_CharT,_Traits,_Allocator>
975 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
976 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
977 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
978
979 template<typename _CharT, typename _Traits, typename _Allocator>
980 inline basic_string<_CharT,_Traits,_Allocator>
981 operator+(const _CharT* __lhs,
982 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
983 {
984 __glibcxx_check_string(__lhs);
985 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
986 }
987
988 template<typename _CharT, typename _Traits, typename _Allocator>
989 inline basic_string<_CharT,_Traits,_Allocator>
990 operator+(_CharT __lhs,
991 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
992 { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
993
994 template<typename _CharT, typename _Traits, typename _Allocator>
995 inline basic_string<_CharT,_Traits,_Allocator>
996 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
997 const _CharT* __rhs)
998 {
999 __glibcxx_check_string(__rhs);
1000 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
1001 }
1002
1003 template<typename _CharT, typename _Traits, typename _Allocator>
1004 inline basic_string<_CharT,_Traits,_Allocator>
1005 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1006 _CharT __rhs)
1007 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
1008
1009 template<typename _CharT, typename _Traits, typename _Allocator>
1010 inline bool
1011 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1012 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1013 { return __lhs._M_base() == __rhs._M_base(); }
1014
1015 template<typename _CharT, typename _Traits, typename _Allocator>
1016 inline bool
1017 operator==(const _CharT* __lhs,
1018 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1019 {
1020 __glibcxx_check_string(__lhs);
1021 return __lhs == __rhs._M_base();
1022 }
1023
1024 template<typename _CharT, typename _Traits, typename _Allocator>
1025 inline bool
1026 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1027 const _CharT* __rhs)
1028 {
1029 __glibcxx_check_string(__rhs);
1030 return __lhs._M_base() == __rhs;
1031 }
1032
1033 template<typename _CharT, typename _Traits, typename _Allocator>
1034 inline bool
1035 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1036 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1037 { return __lhs._M_base() != __rhs._M_base(); }
1038
1039 template<typename _CharT, typename _Traits, typename _Allocator>
1040 inline bool
1041 operator!=(const _CharT* __lhs,
1042 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1043 {
1044 __glibcxx_check_string(__lhs);
1045 return __lhs != __rhs._M_base();
1046 }
1047
1048 template<typename _CharT, typename _Traits, typename _Allocator>
1049 inline bool
1050 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1051 const _CharT* __rhs)
1052 {
1053 __glibcxx_check_string(__rhs);
1054 return __lhs._M_base() != __rhs;
1055 }
1056
1057 template<typename _CharT, typename _Traits, typename _Allocator>
1058 inline bool
1059 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1060 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1061 { return __lhs._M_base() < __rhs._M_base(); }
1062
1063 template<typename _CharT, typename _Traits, typename _Allocator>
1064 inline bool
1065 operator<(const _CharT* __lhs,
1066 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1067 {
1068 __glibcxx_check_string(__lhs);
1069 return __lhs < __rhs._M_base();
1070 }
1071
1072 template<typename _CharT, typename _Traits, typename _Allocator>
1073 inline bool
1074 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1075 const _CharT* __rhs)
1076 {
1077 __glibcxx_check_string(__rhs);
1078 return __lhs._M_base() < __rhs;
1079 }
1080
1081 template<typename _CharT, typename _Traits, typename _Allocator>
1082 inline bool
1083 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1084 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1085 { return __lhs._M_base() <= __rhs._M_base(); }
1086
1087 template<typename _CharT, typename _Traits, typename _Allocator>
1088 inline bool
1089 operator<=(const _CharT* __lhs,
1090 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1091 {
1092 __glibcxx_check_string(__lhs);
1093 return __lhs <= __rhs._M_base();
1094 }
1095
1096 template<typename _CharT, typename _Traits, typename _Allocator>
1097 inline bool
1098 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1099 const _CharT* __rhs)
1100 {
1101 __glibcxx_check_string(__rhs);
1102 return __lhs._M_base() <= __rhs;
1103 }
1104
1105 template<typename _CharT, typename _Traits, typename _Allocator>
1106 inline bool
1107 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1108 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1109 { return __lhs._M_base() >= __rhs._M_base(); }
1110
1111 template<typename _CharT, typename _Traits, typename _Allocator>
1112 inline bool
1113 operator>=(const _CharT* __lhs,
1114 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1115 {
1116 __glibcxx_check_string(__lhs);
1117 return __lhs >= __rhs._M_base();
1118 }
1119
1120 template<typename _CharT, typename _Traits, typename _Allocator>
1121 inline bool
1122 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1123 const _CharT* __rhs)
1124 {
1125 __glibcxx_check_string(__rhs);
1126 return __lhs._M_base() >= __rhs;
1127 }
1128
1129 template<typename _CharT, typename _Traits, typename _Allocator>
1130 inline bool
1131 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1132 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1133 { return __lhs._M_base() > __rhs._M_base(); }
1134
1135 template<typename _CharT, typename _Traits, typename _Allocator>
1136 inline bool
1137 operator>(const _CharT* __lhs,
1138 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1139 {
1140 __glibcxx_check_string(__lhs);
1141 return __lhs > __rhs._M_base();
1142 }
1143
1144 template<typename _CharT, typename _Traits, typename _Allocator>
1145 inline bool
1146 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1147 const _CharT* __rhs)
1148 {
1149 __glibcxx_check_string(__rhs);
1150 return __lhs._M_base() > __rhs;
1151 }
1152
1153 // 21.3.7.8:
1154 template<typename _CharT, typename _Traits, typename _Allocator>
1155 inline void
1156 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1157 basic_string<_CharT,_Traits,_Allocator>& __rhs)
1158 { __lhs.swap(__rhs); }
1159
1160 template<typename _CharT, typename _Traits, typename _Allocator>
1161 std::basic_ostream<_CharT, _Traits>&
1162 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1163 const basic_string<_CharT, _Traits, _Allocator>& __str)
1164 { return __os << __str._M_base(); }
1165
1166 template<typename _CharT, typename _Traits, typename _Allocator>
1167 std::basic_istream<_CharT,_Traits>&
1168 operator>>(std::basic_istream<_CharT,_Traits>& __is,
1169 basic_string<_CharT,_Traits,_Allocator>& __str)
1170 {
1171 std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base();
1172 __str._M_invalidate_all();
1173 return __res;
1174 }
1175
1176 template<typename _CharT, typename _Traits, typename _Allocator>
1177 std::basic_istream<_CharT,_Traits>&
1178 getline(std::basic_istream<_CharT,_Traits>& __is,
1179 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1180 {
1181 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1182 __str._M_base(),
1183 __delim);
1184 __str._M_invalidate_all();
1185 return __res;
1186 }
1187
1188 template<typename _CharT, typename _Traits, typename _Allocator>
1189 std::basic_istream<_CharT,_Traits>&
1190 getline(std::basic_istream<_CharT,_Traits>& __is,
1191 basic_string<_CharT,_Traits,_Allocator>& __str)
1192 {
1193 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1194 __str._M_base());
1195 __str._M_invalidate_all();
1196 return __res;
1197 }
1198
1199 typedef basic_string<char> string;
1200
1201 #ifdef _GLIBCXX_USE_WCHAR_T
1202 typedef basic_string<wchar_t> wstring;
1203 #endif
1204
1205 template<typename _CharT, typename _Traits, typename _Allocator>
1206 struct _Insert_range_from_self_is_safe<
1207 __gnu_debug::basic_string<_CharT, _Traits, _Allocator> >
1208 { enum { __value = 1 }; };
1209
1210 } // namespace __gnu_debug
1211
1212 #endif