1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | #ifndef _BASIC_STRING_H |
35 | #define _BASIC_STRING_H 1 |
36 | |
37 | #pragma GCC system_header |
38 | |
39 | #include <ext/atomicity.h> |
40 | #include <ext/alloc_traits.h> |
41 | #include <debug/debug.h> |
42 | |
43 | #if __cplusplus >= 201103L |
44 | #include <initializer_list> |
45 | #endif |
46 | |
47 | #if __cplusplus > 201402L |
48 | # include <string_view> |
49 | #endif |
50 | |
51 | |
52 | namespace std _GLIBCXX_VISIBILITY(default) |
53 | { |
54 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
55 | |
56 | #if _GLIBCXX_USE_CXX11_ABI |
57 | _GLIBCXX_BEGIN_NAMESPACE_CXX11 |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | template<typename _CharT, typename _Traits, typename _Alloc> |
77 | class basic_string |
78 | { |
79 | typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template |
80 | rebind<_CharT>::other _Char_alloc_type; |
81 | typedef __gnu_cxx::__alloc_traits<_Char_alloc_type> _Alloc_traits; |
82 | |
83 | |
84 | public: |
85 | typedef _Traits traits_type; |
86 | typedef typename _Traits::char_type value_type; |
87 | typedef _Char_alloc_type allocator_type; |
88 | typedef typename _Alloc_traits::size_type size_type; |
89 | typedef typename _Alloc_traits::difference_type difference_type; |
90 | typedef typename _Alloc_traits::reference reference; |
91 | typedef typename _Alloc_traits::const_reference const_reference; |
92 | typedef typename _Alloc_traits::pointer pointer; |
93 | typedef typename _Alloc_traits::const_pointer const_pointer; |
94 | typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator; |
95 | typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string> |
96 | const_iterator; |
97 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
98 | typedef std::reverse_iterator<iterator> reverse_iterator; |
99 | |
100 | |
101 | static const size_type npos = static_cast<size_type>(-1); |
102 | |
103 | private: |
104 | |
105 | #if __cplusplus < 201103L |
106 | typedef iterator __const_iterator; |
107 | #else |
108 | typedef const_iterator __const_iterator; |
109 | #endif |
110 | |
111 | #if __cplusplus > 201402L |
112 | |
113 | typedef basic_string_view<_CharT, _Traits> __sv_type; |
114 | |
115 | template<typename _Tp, typename _Res> |
116 | using _If_sv = enable_if_t< |
117 | __and_<is_convertible<const _Tp&, __sv_type>, |
118 | __not_<is_convertible<const _Tp*, const basic_string*>>, |
119 | __not_<is_convertible<const _Tp&, const _CharT*>>>::value, |
120 | _Res>; |
121 | |
122 | |
123 | static __sv_type |
124 | _S_to_string_view(__sv_type __svt) noexcept |
125 | { return __svt; } |
126 | |
127 | |
128 | |
129 | |
130 | |
131 | struct __sv_wrapper |
132 | { |
133 | explicit __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { } |
134 | __sv_type _M_sv; |
135 | }; |
136 | #endif |
137 | |
138 | |
139 | struct _Alloc_hider : allocator_type |
140 | { |
141 | #if __cplusplus < 201103L |
142 | _Alloc_hider(pointer __dat, const _Alloc& __a = _Alloc()) |
143 | : allocator_type(__a), _M_p(__dat) { } |
144 | #else |
145 | _Alloc_hider(pointer __dat, const _Alloc& __a) |
146 | : allocator_type(__a), _M_p(__dat) { } |
147 | |
148 | _Alloc_hider(pointer __dat, _Alloc&& __a = _Alloc()) |
149 | : allocator_type(std::move(__a)), _M_p(__dat) { } |
150 | #endif |
151 | |
152 | pointer _M_p; |
153 | }; |
154 | |
155 | _Alloc_hider _M_dataplus; |
156 | size_type _M_string_length; |
157 | |
158 | enum { _S_local_capacity = 15 / sizeof(_CharT) }; |
159 | |
160 | union |
161 | { |
162 | _CharT _M_local_buf[_S_local_capacity + 1]; |
163 | size_type _M_allocated_capacity; |
164 | }; |
165 | |
166 | void |
167 | _M_data(pointer __p) |
168 | { _M_dataplus._M_p = __p; } |
169 | |
170 | void |
171 | _M_length(size_type __length) |
172 | { _M_string_length = __length; } |
173 | |
174 | pointer |
175 | _M_data() const |
176 | { return _M_dataplus._M_p; } |
177 | |
178 | pointer |
179 | _M_local_data() |
180 | { |
181 | #if __cplusplus >= 201103L |
182 | return std::pointer_traits<pointer>::pointer_to(*_M_local_buf); |
183 | #else |
184 | return pointer(_M_local_buf); |
185 | #endif |
186 | } |
187 | |
188 | const_pointer |
189 | _M_local_data() const |
190 | { |
191 | #if __cplusplus >= 201103L |
192 | return std::pointer_traits<const_pointer>::pointer_to(*_M_local_buf); |
193 | #else |
194 | return const_pointer(_M_local_buf); |
195 | #endif |
196 | } |
197 | |
198 | void |
199 | _M_capacity(size_type __capacity) |
200 | { _M_allocated_capacity = __capacity; } |
201 | |
202 | void |
203 | _M_set_length(size_type __n) |
204 | { |
205 | _M_length(__n); |
206 | traits_type::assign(_M_data()[__n], _CharT()); |
207 | } |
208 | |
209 | bool |
210 | _M_is_local() const |
211 | { return _M_data() == _M_local_data(); } |
212 | |
213 | |
214 | pointer |
215 | _M_create(size_type&, size_type); |
216 | |
217 | void |
218 | _M_dispose() |
219 | { |
220 | if (!_M_is_local()) |
221 | _M_destroy(_M_allocated_capacity); |
222 | } |
223 | |
224 | void |
225 | _M_destroy(size_type __size) throw() |
226 | { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); } |
227 | |
228 | |
229 | |
230 | template<typename _InIterator> |
231 | void |
232 | _M_construct_aux(_InIterator __beg, _InIterator __end, |
233 | std::__false_type) |
234 | { |
235 | typedef typename iterator_traits<_InIterator>::iterator_category _Tag; |
236 | _M_construct(__beg, __end, _Tag()); |
237 | } |
238 | |
239 | |
240 | |
241 | template<typename _Integer> |
242 | void |
243 | _M_construct_aux(_Integer __beg, _Integer __end, std::__true_type) |
244 | { _M_construct_aux_2(static_cast<size_type>(__beg), __end); } |
245 | |
246 | void |
247 | _M_construct_aux_2(size_type __req, _CharT __c) |
248 | { _M_construct(__req, __c); } |
249 | |
250 | template<typename _InIterator> |
251 | void |
252 | _M_construct(_InIterator __beg, _InIterator __end) |
253 | { |
254 | typedef typename std::__is_integer<_InIterator>::__type _Integral; |
255 | _M_construct_aux(__beg, __end, _Integral()); |
256 | } |
257 | |
258 | |
259 | template<typename _InIterator> |
260 | void |
261 | _M_construct(_InIterator __beg, _InIterator __end, |
262 | std::input_iterator_tag); |
263 | |
264 | |
265 | |
266 | template<typename _FwdIterator> |
267 | void |
268 | _M_construct(_FwdIterator __beg, _FwdIterator __end, |
269 | std::forward_iterator_tag); |
270 | |
271 | void |
272 | _M_construct(size_type __req, _CharT __c); |
273 | |
274 | allocator_type& |
275 | _M_get_allocator() |
276 | { return _M_dataplus; } |
277 | |
278 | const allocator_type& |
279 | _M_get_allocator() const |
280 | { return _M_dataplus; } |
281 | |
282 | private: |
283 | |
284 | #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST |
285 | |
286 | |
287 | template<typename _Tp, bool _Requires = |
288 | !__are_same<_Tp, _CharT*>::__value |
289 | && !__are_same<_Tp, const _CharT*>::__value |
290 | && !__are_same<_Tp, iterator>::__value |
291 | && !__are_same<_Tp, const_iterator>::__value> |
292 | struct __enable_if_not_native_iterator |
293 | { typedef basic_string& __type; }; |
294 | template<typename _Tp> |
295 | struct __enable_if_not_native_iterator<_Tp, false> { }; |
296 | #endif |
297 | |
298 | size_type |
299 | _M_check(size_type __pos, const char* __s) const |
300 | { |
301 | if (__pos > this->size()) |
302 | __throw_out_of_range_fmt( " "this->size() (which is %zu)")" file_link="../../../x86_64-linux-gnu/c++/7/bits/c++config.h.html#595" macro="true">__N("%s: __pos (which is %zu) > " |
303 | " "this->size() (which is %zu)")" file_link="../../../x86_64-linux-gnu/c++/7/bits/c++config.h.html#595" macro="true"> "this->size() (which is %zu)"), |
304 | __s, __pos, this->size()); |
305 | return __pos; |
306 | } |
307 | |
308 | void |
309 | _M_check_length(size_type __n1, size_type __n2, const char* __s) const |
310 | { |
311 | if (this->max_size() - (this->size() - __n1) < __n2) |
312 | __throw_length_error(__N(__s)); |
313 | } |
314 | |
315 | |
316 | |
317 | size_type |
318 | _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT |
319 | { |
320 | const bool __testoff = __off < this->size() - __pos; |
321 | return __testoff ? __off : this->size() - __pos; |
322 | } |
323 | |
324 | |
325 | bool |
326 | _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT |
327 | { |
328 | return (less<const _CharT*>()(__s, _M_data()) |
329 | || less<const _CharT*>()(_M_data() + this->size(), __s)); |
330 | } |
331 | |
332 | |
333 | |
334 | static void |
335 | _S_copy(_CharT* __d, const _CharT* __s, size_type __n) |
336 | { |
337 | if (__n == 1) |
338 | traits_type::assign(*__d, *__s); |
339 | else |
340 | traits_type::copy(__d, __s, __n); |
341 | } |
342 | |
343 | static void |
344 | _S_move(_CharT* __d, const _CharT* __s, size_type __n) |
345 | { |
346 | if (__n == 1) |
347 | traits_type::assign(*__d, *__s); |
348 | else |
349 | traits_type::move(__d, __s, __n); |
350 | } |
351 | |
352 | static void |
353 | _S_assign(_CharT* __d, size_type __n, _CharT __c) |
354 | { |
355 | if (__n == 1) |
356 | traits_type::assign(*__d, __c); |
357 | else |
358 | traits_type::assign(__d, __n, __c); |
359 | } |
360 | |
361 | |
362 | |
363 | template<class _Iterator> |
364 | static void |
365 | _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2) |
366 | { |
367 | for (; __k1 != __k2; ++__k1, (void)++__p) |
368 | traits_type::assign(*__p, *__k1); |
369 | } |
370 | |
371 | static void |
372 | _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT |
373 | { _S_copy_chars(__p, __k1.base(), __k2.base()); } |
374 | |
375 | static void |
376 | _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2) |
377 | _GLIBCXX_NOEXCEPT |
378 | { _S_copy_chars(__p, __k1.base(), __k2.base()); } |
379 | |
380 | static void |
381 | _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT |
382 | { _S_copy(__p, __k1, __k2 - __k1); } |
383 | |
384 | static void |
385 | _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2) |
386 | _GLIBCXX_NOEXCEPT |
387 | { _S_copy(__p, __k1, __k2 - __k1); } |
388 | |
389 | static int |
390 | _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT |
391 | { |
392 | const difference_type __d = difference_type(__n1 - __n2); |
393 | |
394 | if (__d > __gnu_cxx::__numeric_traits<int>::__max) |
395 | return __gnu_cxx::__numeric_traits<int>::__max; |
396 | else if (__d < __gnu_cxx::__numeric_traits<int>::__min) |
397 | return __gnu_cxx::__numeric_traits<int>::__min; |
398 | else |
399 | return int(__d); |
400 | } |
401 | |
402 | void |
403 | _M_assign(const basic_string&); |
404 | |
405 | void |
406 | _M_mutate(size_type __pos, size_type __len1, const _CharT* __s, |
407 | size_type __len2); |
408 | |
409 | void |
410 | _M_erase(size_type __pos, size_type __n); |
411 | |
412 | public: |
413 | |
414 | |
415 | |
416 | |
417 | |
418 | |
419 | |
420 | basic_string() |
421 | _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value) |
422 | : _M_dataplus(_M_local_data()) |
423 | { _M_set_length(0); } |
424 | |
425 | |
426 | |
427 | |
428 | explicit |
429 | basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT |
430 | : _M_dataplus(_M_local_data(), __a) |
431 | { _M_set_length(0); } |
432 | |
433 | |
434 | |
435 | |
436 | |
437 | basic_string(const basic_string& __str) |
438 | : _M_dataplus(_M_local_data(), |
439 | _Alloc_traits::_S_select_on_copy(__str._M_get_allocator())) |
440 | { _M_construct(__str._M_data(), __str._M_data() + __str.length()); } |
441 | |
442 | |
443 | |
444 | |
445 | |
446 | |
447 | |
448 | |
449 | |
450 | basic_string(const basic_string& __str, size_type __pos, |
451 | const _Alloc& __a = _Alloc()) |
452 | : _M_dataplus(_M_local_data(), __a) |
453 | { |
454 | const _CharT* __start = __str._M_data() |
455 | + __str._M_check(__pos, "basic_string::basic_string"); |
456 | _M_construct(__start, __start + __str._M_limit(__pos, npos)); |
457 | } |
458 | |
459 | |
460 | |
461 | |
462 | |
463 | |
464 | |
465 | basic_string(const basic_string& __str, size_type __pos, |
466 | size_type __n) |
467 | : _M_dataplus(_M_local_data()) |
468 | { |
469 | const _CharT* __start = __str._M_data() |
470 | + __str._M_check(__pos, "basic_string::basic_string"); |
471 | _M_construct(__start, __start + __str._M_limit(__pos, __n)); |
472 | } |
473 | |
474 | |
475 | |
476 | |
477 | |
478 | |
479 | |
480 | |
481 | basic_string(const basic_string& __str, size_type __pos, |
482 | size_type __n, const _Alloc& __a) |
483 | : _M_dataplus(_M_local_data(), __a) |
484 | { |
485 | const _CharT* __start |
486 | = __str._M_data() + __str._M_check(__pos, "string::string"); |
487 | _M_construct(__start, __start + __str._M_limit(__pos, __n)); |
488 | } |
489 | |
490 | |
491 | |
492 | |
493 | |
494 | |
495 | |
496 | |
497 | |
498 | |
499 | basic_string(const _CharT* __s, size_type __n, |
500 | const _Alloc& __a = _Alloc()) |
501 | : _M_dataplus(_M_local_data(), __a) |
502 | { _M_construct(__s, __s + __n); } |
503 | |
504 | |
505 | |
506 | |
507 | |
508 | |
509 | basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()) |
510 | : _M_dataplus(_M_local_data(), __a) |
511 | { _M_construct(__s, __s ? __s + traits_type::length(__s) : __s+npos); } |
512 | |
513 | |
514 | |
515 | |
516 | |
517 | |
518 | |
519 | basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()) |
520 | : _M_dataplus(_M_local_data(), __a) |
521 | { _M_construct(__n, __c); } |
522 | |
523 | #if __cplusplus >= 201103L |
524 | |
525 | |
526 | |
527 | |
528 | |
529 | |
530 | |
531 | basic_string(basic_string&& __str) noexcept |
532 | : _M_dataplus(_M_local_data(), std::move(__str._M_get_allocator())) |
533 | { |
534 | if (__str._M_is_local()) |
535 | { |
536 | traits_type::copy(_M_local_buf, __str._M_local_buf, |
537 | _S_local_capacity + 1); |
538 | } |
539 | else |
540 | { |
541 | _M_data(__str._M_data()); |
542 | _M_capacity(__str._M_allocated_capacity); |
543 | } |
544 | |
545 | |
546 | |
547 | |
548 | _M_length(__str.length()); |
549 | __str._M_data(__str._M_local_data()); |
550 | __str._M_set_length(0); |
551 | } |
552 | |
553 | |
554 | |
555 | |
556 | |
557 | |
558 | basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc()) |
559 | : _M_dataplus(_M_local_data(), __a) |
560 | { _M_construct(__l.begin(), __l.end()); } |
561 | |
562 | basic_string(const basic_string& __str, const _Alloc& __a) |
563 | : _M_dataplus(_M_local_data(), __a) |
564 | { _M_construct(__str.begin(), __str.end()); } |
565 | |
566 | basic_string(basic_string&& __str, const _Alloc& __a) |
567 | noexcept(_Alloc_traits::_S_always_equal()) |
568 | : _M_dataplus(_M_local_data(), __a) |
569 | { |
570 | if (__str._M_is_local()) |
571 | { |
572 | traits_type::copy(_M_local_buf, __str._M_local_buf, |
573 | _S_local_capacity + 1); |
574 | _M_length(__str.length()); |
575 | __str._M_set_length(0); |
576 | } |
577 | else if (_Alloc_traits::_S_always_equal() |
578 | || __str.get_allocator() == __a) |
579 | { |
580 | _M_data(__str._M_data()); |
581 | _M_length(__str.length()); |
582 | _M_capacity(__str._M_allocated_capacity); |
583 | __str._M_data(__str._M_local_buf); |
584 | __str._M_set_length(0); |
585 | } |
586 | else |
587 | _M_construct(__str.begin(), __str.end()); |
588 | } |
589 | |
590 | #endif |
591 | |
592 | |
593 | |
594 | |
595 | |
596 | |
597 | |
598 | #if __cplusplus >= 201103L |
599 | template<typename _InputIterator, |
600 | typename = std::_RequireInputIter<_InputIterator>> |
601 | #else |
602 | template<typename _InputIterator> |
603 | #endif |
604 | basic_string(_InputIterator __beg, _InputIterator __end, |
605 | const _Alloc& __a = _Alloc()) |
606 | : _M_dataplus(_M_local_data(), __a) |
607 | { _M_construct(__beg, __end); } |
608 | |
609 | #if __cplusplus > 201402L |
610 | |
611 | |
612 | |
613 | |
614 | |
615 | |
616 | |
617 | template<typename _Tp, typename = _If_sv<_Tp, void>> |
618 | basic_string(const _Tp& __t, size_type __pos, size_type __n, |
619 | const _Alloc& __a = _Alloc()) |
620 | : basic_string(_S_to_string_view(__t).substr(__pos, __n), __a) { } |
621 | |
622 | |
623 | |
624 | |
625 | |
626 | |
627 | template<typename _Tp, typename = _If_sv<_Tp, void>> |
628 | explicit |
629 | basic_string(const _Tp& __t, const _Alloc& __a = _Alloc()) |
630 | : basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { } |
631 | |
632 | |
633 | |
634 | |
635 | |
636 | |
637 | |
638 | explicit |
639 | basic_string(__sv_wrapper __svw, const _Alloc& __a) |
640 | : basic_string(__svw._M_sv.data(), __svw._M_sv.size(), __a) { } |
641 | #endif |
642 | |
643 | |
644 | |
645 | |
646 | ~basic_string() |
647 | { _M_dispose(); } |
648 | |
649 | |
650 | |
651 | |
652 | |
653 | basic_string& |
654 | operator=(const basic_string& __str) |
655 | { |
656 | #if __cplusplus >= 201103L |
657 | if (_Alloc_traits::_S_propagate_on_copy_assign()) |
658 | { |
659 | if (!_Alloc_traits::_S_always_equal() && !_M_is_local() |
660 | && _M_get_allocator() != __str._M_get_allocator()) |
661 | { |
662 | |
663 | |
664 | if (__str.size() <= _S_local_capacity) |
665 | { |
666 | _M_destroy(_M_allocated_capacity); |
667 | _M_data(_M_local_data()); |
668 | _M_set_length(0); |
669 | } |
670 | else |
671 | { |
672 | const auto __len = __str.size(); |
673 | auto __alloc = __str._M_get_allocator(); |
674 | |
675 | auto __ptr = _Alloc_traits::allocate(__alloc, __len + 1); |
676 | _M_destroy(_M_allocated_capacity); |
677 | _M_data(__ptr); |
678 | _M_capacity(__len); |
679 | _M_set_length(__len); |
680 | } |
681 | } |
682 | std::__alloc_on_copy(_M_get_allocator(), __str._M_get_allocator()); |
683 | } |
684 | #endif |
685 | return this->assign(__str); |
686 | } |
687 | |
688 | |
689 | |
690 | |
691 | |
692 | basic_string& |
693 | operator=(const _CharT* __s) |
694 | { return this->assign(__s); } |
695 | |
696 | |
697 | |
698 | |
699 | |
700 | |
701 | |
702 | |
703 | basic_string& |
704 | operator=(_CharT __c) |
705 | { |
706 | this->assign(1, __c); |
707 | return *this; |
708 | } |
709 | |
710 | #if __cplusplus >= 201103L |
711 | |
712 | |
713 | |
714 | |
715 | |
716 | |
717 | |
718 | |
719 | |
720 | |
721 | basic_string& |
722 | operator=(basic_string&& __str) |
723 | noexcept(_Alloc_traits::_S_nothrow_move()) |
724 | { |
725 | if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign() |
726 | && !_Alloc_traits::_S_always_equal() |
727 | && _M_get_allocator() != __str._M_get_allocator()) |
728 | { |
729 | |
730 | _M_destroy(_M_allocated_capacity); |
731 | _M_data(_M_local_data()); |
732 | _M_set_length(0); |
733 | } |
734 | |
735 | std::__alloc_on_move(_M_get_allocator(), __str._M_get_allocator()); |
736 | |
737 | if (__str._M_is_local()) |
738 | { |
739 | |
740 | if (__str.size()) |
741 | this->_S_copy(_M_data(), __str._M_data(), __str.size()); |
742 | _M_set_length(__str.size()); |
743 | } |
744 | else if (_Alloc_traits::_S_propagate_on_move_assign() |
745 | || _Alloc_traits::_S_always_equal() |
746 | || _M_get_allocator() == __str._M_get_allocator()) |
747 | { |
748 | |
749 | pointer __data = nullptr; |
750 | size_type __capacity; |
751 | if (!_M_is_local()) |
752 | { |
753 | if (_Alloc_traits::_S_always_equal()) |
754 | { |
755 | |
756 | __data = _M_data(); |
757 | __capacity = _M_allocated_capacity; |
758 | } |
759 | else |
760 | _M_destroy(_M_allocated_capacity); |
761 | } |
762 | |
763 | _M_data(__str._M_data()); |
764 | _M_length(__str.length()); |
765 | _M_capacity(__str._M_allocated_capacity); |
766 | if (__data) |
767 | { |
768 | __str._M_data(__data); |
769 | __str._M_capacity(__capacity); |
770 | } |
771 | else |
772 | __str._M_data(__str._M_local_buf); |
773 | } |
774 | else |
775 | assign(__str); |
776 | __str.clear(); |
777 | return *this; |
778 | } |
779 | |
780 | |
781 | |
782 | |
783 | |
784 | basic_string& |
785 | operator=(initializer_list<_CharT> __l) |
786 | { |
787 | this->assign(__l.begin(), __l.size()); |
788 | return *this; |
789 | } |
790 | #endif |
791 | |
792 | #if __cplusplus > 201402L |
793 | |
794 | |
795 | |
796 | |
797 | template<typename _Tp> |
798 | _If_sv<_Tp, basic_string&> |
799 | operator=(const _Tp& __svt) |
800 | { return this->assign(__svt); } |
801 | |
802 | |
803 | |
804 | |
805 | |
806 | operator __sv_type() const noexcept |
807 | { return __sv_type(data(), size()); } |
808 | #endif |
809 | |
810 | |
811 | |
812 | |
813 | |
814 | |
815 | iterator |
816 | begin() _GLIBCXX_NOEXCEPT |
817 | { return iterator(_M_data()); } |
818 | |
819 | |
820 | |
821 | |
822 | |
823 | const_iterator |
824 | begin() const _GLIBCXX_NOEXCEPT |
825 | { return const_iterator(_M_data()); } |
826 | |
827 | |
828 | |
829 | |
830 | |
831 | iterator |
832 | end() _GLIBCXX_NOEXCEPT |
833 | { return iterator(_M_data() + this->size()); } |
834 | |
835 | |
836 | |
837 | |
838 | |
839 | const_iterator |
840 | end() const _GLIBCXX_NOEXCEPT |
841 | { return const_iterator(_M_data() + this->size()); } |
842 | |
843 | |
844 | |
845 | |
846 | |
847 | |
848 | reverse_iterator |
849 | rbegin() _GLIBCXX_NOEXCEPT |
850 | { return reverse_iterator(this->end()); } |
851 | |
852 | |
853 | |
854 | |
855 | |
856 | |
857 | const_reverse_iterator |
858 | rbegin() const _GLIBCXX_NOEXCEPT |
859 | { return const_reverse_iterator(this->end()); } |
860 | |
861 | |
862 | |
863 | |
864 | |
865 | |
866 | reverse_iterator |
867 | rend() _GLIBCXX_NOEXCEPT |
868 | { return reverse_iterator(this->begin()); } |
869 | |
870 | |
871 | |
872 | |
873 | |
874 | |
875 | const_reverse_iterator |
876 | rend() const _GLIBCXX_NOEXCEPT |
877 | { return const_reverse_iterator(this->begin()); } |
878 | |
879 | #if __cplusplus >= 201103L |
880 | |
881 | |
882 | |
883 | |
884 | const_iterator |
885 | cbegin() const noexcept |
886 | { return const_iterator(this->_M_data()); } |
887 | |
888 | |
889 | |
890 | |
891 | |
892 | const_iterator |
893 | cend() const noexcept |
894 | { return const_iterator(this->_M_data() + this->size()); } |
895 | |
896 | |
897 | |
898 | |
899 | |
900 | |
901 | const_reverse_iterator |
902 | crbegin() const noexcept |
903 | { return const_reverse_iterator(this->end()); } |
904 | |
905 | |
906 | |
907 | |
908 | |
909 | |
910 | const_reverse_iterator |
911 | crend() const noexcept |
912 | { return const_reverse_iterator(this->begin()); } |
913 | #endif |
914 | |
915 | public: |
916 | |
917 | |
918 | |
919 | size_type |
920 | size() const _GLIBCXX_NOEXCEPT |
921 | { return _M_string_length; } |
922 | |
923 | |
924 | |
925 | size_type |
926 | length() const _GLIBCXX_NOEXCEPT |
927 | { return _M_string_length; } |
928 | |
929 | |
930 | size_type |
931 | max_size() const _GLIBCXX_NOEXCEPT |
932 | { return (_Alloc_traits::max_size(_M_get_allocator()) - 1) / 2; } |
933 | |
934 | |
935 | |
936 | |
937 | |
938 | |
939 | |
940 | |
941 | |
942 | |
943 | |
944 | void |
945 | resize(size_type __n, _CharT __c); |
946 | |
947 | |
948 | |
949 | |
950 | |
951 | |
952 | |
953 | |
954 | |
955 | |
956 | |
957 | void |
958 | resize(size_type __n) |
959 | { this->resize(__n, _CharT()); } |
960 | |
961 | #if __cplusplus >= 201103L |
962 | |
963 | void |
964 | shrink_to_fit() noexcept |
965 | { |
966 | #if __cpp_exceptions |
967 | if (capacity() > size()) |
968 | { |
969 | try |
970 | { reserve(0); } |
971 | catch(...) |
972 | { } |
973 | } |
974 | #endif |
975 | } |
976 | #endif |
977 | |
978 | |
979 | |
980 | |
981 | |
982 | size_type |
983 | capacity() const _GLIBCXX_NOEXCEPT |
984 | { |
985 | return _M_is_local() ? size_type(_S_local_capacity) |
986 | : _M_allocated_capacity; |
987 | } |
988 | |
989 | |
990 | |
991 | |
992 | |
993 | |
994 | |
995 | |
996 | |
997 | |
998 | |
999 | |
1000 | |
1001 | |
1002 | |
1003 | |
1004 | |
1005 | |
1006 | void |
1007 | reserve(size_type __res_arg = 0); |
1008 | |
1009 | |
1010 | |
1011 | |
1012 | void |
1013 | clear() _GLIBCXX_NOEXCEPT |
1014 | { _M_set_length(0); } |
1015 | |
1016 | |
1017 | |
1018 | |
1019 | |
1020 | bool |
1021 | empty() const _GLIBCXX_NOEXCEPT |
1022 | { return this->size() == 0; } |
1023 | |
1024 | |
1025 | |
1026 | |
1027 | |
1028 | |
1029 | |
1030 | |
1031 | |
1032 | |
1033 | |
1034 | |
1035 | const_reference |
1036 | operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT |
1037 | { |
1038 | __glibcxx_assert(__pos <= size()); |
1039 | return _M_data()[__pos]; |
1040 | } |
1041 | |
1042 | |
1043 | |
1044 | |
1045 | |
1046 | |
1047 | |
1048 | |
1049 | |
1050 | |
1051 | |
1052 | reference |
1053 | operator[](size_type __pos) |
1054 | { |
1055 | |
1056 | |
1057 | __glibcxx_assert(__pos <= size()); |
1058 | |
1059 | _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos < size()); |
1060 | return _M_data()[__pos]; |
1061 | } |
1062 | |
1063 | |
1064 | |
1065 | |
1066 | |
1067 | |
1068 | |
1069 | |
1070 | |
1071 | |
1072 | |
1073 | const_reference |
1074 | at(size_type __n) const |
1075 | { |
1076 | if (__n >= this->size()) |
1077 | __throw_out_of_range_fmt(= this->size() " "(which is %zu)")" file_link="../../../x86_64-linux-gnu/c++/7/bits/c++config.h.html#595" macro="true">__N("basic_string::at: __n " |
1078 | = this->size() " "(which is %zu)")" file_link="../../../x86_64-linux-gnu/c++/7/bits/c++config.h.html#595" macro="true"> "(which is %zu) >= this->size() " |
1079 | = this->size() " "(which is %zu)")" file_link="../../../x86_64-linux-gnu/c++/7/bits/c++config.h.html#595" macro="true"> "(which is %zu)"), |
1080 | __n, this->size()); |
1081 | return _M_data()[__n]; |
1082 | } |
1083 | |
1084 | |
1085 | |
1086 | |
1087 | |
1088 | |
1089 | |
1090 | |
1091 | |
1092 | |
1093 | |
1094 | reference |
1095 | at(size_type __n) |
1096 | { |
1097 | if (__n >= size()) |
1098 | __throw_out_of_range_fmt(= this->size() " "(which is %zu)")" file_link="../../../x86_64-linux-gnu/c++/7/bits/c++config.h.html#595" macro="true">__N("basic_string::at: __n " |
1099 | = this->size() " "(which is %zu)")" file_link="../../../x86_64-linux-gnu/c++/7/bits/c++config.h.html#595" macro="true"> "(which is %zu) >= this->size() " |
1100 | = this->size() " "(which is %zu)")" file_link="../../../x86_64-linux-gnu/c++/7/bits/c++config.h.html#595" macro="true"> "(which is %zu)"), |
1101 | __n, this->size()); |
1102 | return _M_data()[__n]; |
1103 | } |
1104 | |
1105 | #if __cplusplus >= 201103L |
1106 | |
1107 | |
1108 | |
1109 | |
1110 | reference |
1111 | front() noexcept |
1112 | { |
1113 | __glibcxx_assert(!empty()); |
1114 | return operator[](0); |
1115 | } |
1116 | |
1117 | |
1118 | |
1119 | |
1120 | |
1121 | const_reference |
1122 | front() const noexcept |
1123 | { |
1124 | __glibcxx_assert(!empty()); |
1125 | return operator[](0); |
1126 | } |
1127 | |
1128 | |
1129 | |
1130 | |
1131 | |
1132 | reference |
1133 | back() noexcept |
1134 | { |
1135 | __glibcxx_assert(!empty()); |
1136 | return operator[](this->size() - 1); |
1137 | } |
1138 | |
1139 | |
1140 | |
1141 | |
1142 | |
1143 | const_reference |
1144 | back() const noexcept |
1145 | { |
1146 | __glibcxx_assert(!empty()); |
1147 | return operator[](this->size() - 1); |
1148 | } |
1149 | #endif |
1150 | |
1151 | |
1152 | |
1153 | |
1154 | |
1155 | |
1156 | |
1157 | basic_string& |
1158 | operator+=(const basic_string& __str) |
1159 | { return this->append(__str); } |
1160 | |
1161 | |
1162 | |
1163 | |
1164 | |
1165 | |
1166 | basic_string& |
1167 | operator+=(const _CharT* __s) |
1168 | { return this->append(__s); } |
1169 | |
1170 | |
1171 | |
1172 | |
1173 | |
1174 | |
1175 | basic_string& |
1176 | operator+=(_CharT __c) |
1177 | { |
1178 | this->push_back(__c); |
1179 | return *this; |
1180 | } |
1181 | |
1182 | #if __cplusplus >= 201103L |
1183 | |
1184 | |
1185 | |
1186 | |
1187 | |
1188 | basic_string& |
1189 | operator+=(initializer_list<_CharT> __l) |
1190 | { return this->append(__l.begin(), __l.size()); } |
1191 | #endif |
1192 | |
1193 | #if __cplusplus > 201402L |
1194 | |
1195 | |
1196 | |
1197 | |
1198 | |
1199 | template<typename _Tp> |
1200 | _If_sv<_Tp, basic_string&> |
1201 | operator+=(const _Tp& __svt) |
1202 | { return this->append(__svt); } |
1203 | #endif |
1204 | |
1205 | |
1206 | |
1207 | |
1208 | |
1209 | |
1210 | basic_string& |
1211 | append(const basic_string& __str) |
1212 | { return _M_append(__str._M_data(), __str.size()); } |
1213 | |
1214 | |
1215 | |
1216 | |
1217 | |
1218 | |
1219 | |
1220 | |
1221 | |
1222 | |
1223 | |
1224 | |
1225 | |
1226 | |
1227 | basic_string& |
1228 | append(const basic_string& __str, size_type __pos, size_type __n = npos) |
1229 | { return _M_append(__str._M_data() |
1230 | + __str._M_check(__pos, "basic_string::append"), |
1231 | __str._M_limit(__pos, __n)); } |
1232 | |
1233 | |
1234 | |
1235 | |
1236 | |
1237 | |
1238 | |
1239 | basic_string& |
1240 | append(const _CharT* __s, size_type __n) |
1241 | { |
1242 | __glibcxx_requires_string_len(__s, __n); |
1243 | _M_check_length(size_type(0), __n, "basic_string::append"); |
1244 | return _M_append(__s, __n); |
1245 | } |
1246 | |
1247 | |
1248 | |
1249 | |
1250 | |
1251 | |
1252 | basic_string& |
1253 | append(const _CharT* __s) |
1254 | { |
1255 | __glibcxx_requires_string(__s); |
1256 | const size_type __n = traits_type::length(__s); |
1257 | _M_check_length(size_type(0), __n, "basic_string::append"); |
1258 | return _M_append(__s, __n); |
1259 | } |
1260 | |
1261 | |
1262 | |
1263 | |
1264 | |
1265 | |
1266 | |
1267 | |
1268 | |
1269 | basic_string& |
1270 | append(size_type __n, _CharT __c) |
1271 | { return _M_replace_aux(this->size(), size_type(0), __n, __c); } |
1272 | |
1273 | #if __cplusplus >= 201103L |
1274 | |
1275 | |
1276 | |
1277 | |
1278 | |
1279 | basic_string& |
1280 | append(initializer_list<_CharT> __l) |
1281 | { return this->append(__l.begin(), __l.size()); } |
1282 | #endif |
1283 | |
1284 | |
1285 | |
1286 | |
1287 | |
1288 | |
1289 | |
1290 | |
1291 | |
1292 | #if __cplusplus >= 201103L |
1293 | template<class _InputIterator, |
1294 | typename = std::_RequireInputIter<_InputIterator>> |
1295 | #else |
1296 | template<class _InputIterator> |
1297 | #endif |
1298 | basic_string& |
1299 | append(_InputIterator __first, _InputIterator __last) |
1300 | { return this->replace(end(), end(), __first, __last); } |
1301 | |
1302 | #if __cplusplus > 201402L |
1303 | |
1304 | |
1305 | |
1306 | |
1307 | |
1308 | template<typename _Tp> |
1309 | _If_sv<_Tp, basic_string&> |
1310 | append(const _Tp& __svt) |
1311 | { |
1312 | __sv_type __sv = __svt; |
1313 | return this->append(__sv.data(), __sv.size()); |
1314 | } |
1315 | |
1316 | |
1317 | |
1318 | |
1319 | |
1320 | |
1321 | |
1322 | |
1323 | template<typename _Tp> |
1324 | _If_sv<_Tp, basic_string&> |
1325 | append(const _Tp& __svt, size_type __pos, size_type __n = npos) |
1326 | { |
1327 | __sv_type __sv = __svt; |
1328 | return _M_append(__sv.data() |
1329 | + __sv._M_check(__pos, "basic_string::append"), |
1330 | __sv._M_limit(__pos, __n)); |
1331 | } |
1332 | #endif |
1333 | |
1334 | |
1335 | |
1336 | |
1337 | |
1338 | void |
1339 | push_back(_CharT __c) |
1340 | { |
1341 | const size_type __size = this->size(); |
1342 | if (__size + 1 > this->capacity()) |
1343 | this->_M_mutate(__size, size_type(0), 0, size_type(1)); |
1344 | traits_type::assign(this->_M_data()[__size], __c); |
1345 | this->_M_set_length(__size + 1); |
1346 | } |
1347 | |
1348 | |
1349 | |
1350 | |
1351 | |
1352 | |
1353 | basic_string& |
1354 | assign(const basic_string& __str) |
1355 | { |
1356 | this->_M_assign(__str); |
1357 | return *this; |
1358 | } |
1359 | |
1360 | #if __cplusplus >= 201103L |
1361 | |
1362 | |
1363 | |
1364 | |
1365 | |
1366 | |
1367 | |
1368 | |
1369 | basic_string& |
1370 | assign(basic_string&& __str) |
1371 | noexcept(_Alloc_traits::_S_nothrow_move()) |
1372 | { |
1373 | |
1374 | |
1375 | return *this = std::move(__str); |
1376 | } |
1377 | #endif |
1378 | |
1379 | |
1380 | |
1381 | |
1382 | |
1383 | |
1384 | |
1385 | |
1386 | |
1387 | |
1388 | |
1389 | |
1390 | |
1391 | |
1392 | basic_string& |
1393 | assign(const basic_string& __str, size_type __pos, size_type __n = npos) |
1394 | { return _M_replace(size_type(0), this->size(), __str._M_data() |
1395 | + __str._M_check(__pos, "basic_string::assign"), |
1396 | __str._M_limit(__pos, __n)); } |
1397 | |
1398 | |
1399 | |
1400 | |
1401 | |
1402 | |
1403 | |
1404 | |
1405 | |
1406 | |
1407 | |
1408 | basic_string& |
1409 | assign(const _CharT* __s, size_type __n) |
1410 | { |
1411 | __glibcxx_requires_string_len(__s, __n); |
1412 | return _M_replace(size_type(0), this->size(), __s, __n); |
1413 | } |
1414 | |
1415 | |
1416 | |
1417 | |
1418 | |
1419 | |
1420 | |
1421 | |
1422 | |
1423 | |
1424 | basic_string& |
1425 | assign(const _CharT* __s) |
1426 | { |
1427 | __glibcxx_requires_string(__s); |
1428 | return _M_replace(size_type(0), this->size(), __s, |
1429 | traits_type::length(__s)); |
1430 | } |
1431 | |
1432 | |
1433 | |
1434 | |
1435 | |
1436 | |
1437 | |
1438 | |
1439 | |
1440 | |
1441 | basic_string& |
1442 | assign(size_type __n, _CharT __c) |
1443 | { return _M_replace_aux(size_type(0), this->size(), __n, __c); } |
1444 | |
1445 | |
1446 | |
1447 | |
1448 | |
1449 | |
1450 | |
1451 | |
1452 | |
1453 | #if __cplusplus >= 201103L |
1454 | template<class _InputIterator, |
1455 | typename = std::_RequireInputIter<_InputIterator>> |
1456 | #else |
1457 | template<class _InputIterator> |
1458 | #endif |
1459 | basic_string& |
1460 | assign(_InputIterator __first, _InputIterator __last) |
1461 | { return this->replace(begin(), end(), __first, __last); } |
1462 | |
1463 | #if __cplusplus >= 201103L |
1464 | |
1465 | |
1466 | |
1467 | |
1468 | |
1469 | basic_string& |
1470 | assign(initializer_list<_CharT> __l) |
1471 | { return this->assign(__l.begin(), __l.size()); } |
1472 | #endif |
1473 | |
1474 | #if __cplusplus > 201402L |
1475 | |
1476 | |
1477 | |
1478 | |
1479 | |
1480 | template<typename _Tp> |
1481 | _If_sv<_Tp, basic_string&> |
1482 | assign(const _Tp& __svt) |
1483 | { |
1484 | __sv_type __sv = __svt; |
1485 | return this->assign(__sv.data(), __sv.size()); |
1486 | } |
1487 | |
1488 | |
1489 | |
1490 | |
1491 | |
1492 | |
1493 | |
1494 | |
1495 | template<typename _Tp> |
1496 | _If_sv<_Tp, basic_string&> |
1497 | assign(const _Tp& __svt, size_type __pos, size_type __n = npos) |
1498 | { |
1499 | __sv_type __sv = __svt; |
1500 | return _M_replace(size_type(0), this->size(), __sv.data() |
1501 | + __sv._M_check(__pos, "basic_string::assign"), |
1502 | __sv._M_limit(__pos, __n)); |
1503 | } |
1504 | #endif |
1505 | |
1506 | #if __cplusplus >= 201103L |
1507 | |
1508 | |
1509 | |
1510 | |
1511 | |
1512 | |
1513 | |
1514 | |
1515 | |
1516 | |
1517 | |
1518 | |
1519 | |
1520 | |
1521 | |
1522 | iterator |
1523 | insert(const_iterator __p, size_type __n, _CharT __c) |
1524 | { |
1525 | _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); |
1526 | const size_type __pos = __p - begin(); |
1527 | this->replace(__p, __p, __n, __c); |
1528 | return iterator(this->_M_data() + __pos); |
1529 | } |
1530 | #else |
1531 | |
1532 | |
1533 | |
1534 | |
1535 | |
1536 | |
1537 | |
1538 | |
1539 | |
1540 | |
1541 | |
1542 | |
1543 | |
1544 | void |
1545 | insert(iterator __p, size_type __n, _CharT __c) |
1546 | { this->replace(__p, __p, __n, __c); } |
1547 | #endif |
1548 | |
1549 | #if __cplusplus >= 201103L |
1550 | |
1551 | |
1552 | |
1553 | |
1554 | |
1555 | |
1556 | |
1557 | |
1558 | |
1559 | |
1560 | |
1561 | |
1562 | |
1563 | |
1564 | template<class _InputIterator, |
1565 | typename = std::_RequireInputIter<_InputIterator>> |
1566 | iterator |
1567 | insert(const_iterator __p, _InputIterator __beg, _InputIterator __end) |
1568 | { |
1569 | _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); |
1570 | const size_type __pos = __p - begin(); |
1571 | this->replace(__p, __p, __beg, __end); |
1572 | return iterator(this->_M_data() + __pos); |
1573 | } |
1574 | #else |
1575 | |
1576 | |
1577 | |
1578 | |
1579 | |
1580 | |
1581 | |
1582 | |
1583 | |
1584 | |
1585 | |
1586 | |
1587 | template<class _InputIterator> |
1588 | void |
1589 | insert(iterator __p, _InputIterator __beg, _InputIterator __end) |
1590 | { this->replace(__p, __p, __beg, __end); } |
1591 | #endif |
1592 | |
1593 | #if __cplusplus >= 201103L |
1594 | |
1595 | |
1596 | |
1597 | |
1598 | |
1599 | |
1600 | void |
1601 | insert(iterator __p, initializer_list<_CharT> __l) |
1602 | { |
1603 | _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); |
1604 | this->insert(__p - begin(), __l.begin(), __l.size()); |
1605 | } |
1606 | #endif |
1607 | |
1608 | |
1609 | |
1610 | |
1611 | |
1612 | |
1613 | |
1614 | |
1615 | |
1616 | |
1617 | |
1618 | |
1619 | |
1620 | basic_string& |
1621 | insert(size_type __pos1, const basic_string& __str) |
1622 | { return this->replace(__pos1, size_type(0), |
1623 | __str._M_data(), __str.size()); } |
1624 | |
1625 | |
1626 | |
1627 | |
1628 | |
1629 | |
1630 | |
1631 | |
1632 | |
1633 | |
1634 | |
1635 | |
1636 | |
1637 | |
1638 | |
1639 | |
1640 | |
1641 | |
1642 | |
1643 | basic_string& |
1644 | insert(size_type __pos1, const basic_string& __str, |
1645 | size_type __pos2, size_type __n = npos) |
1646 | { return this->replace(__pos1, size_type(0), __str._M_data() |
1647 | + __str._M_check(__pos2, "basic_string::insert"), |
1648 | __str._M_limit(__pos2, __n)); } |
1649 | |
1650 | |
1651 | |
1652 | |
1653 | |
1654 | |
1655 | |
1656 | |
1657 | |
1658 | |
1659 | |
1660 | |
1661 | |
1662 | |
1663 | |
1664 | |
1665 | |
1666 | basic_string& |
1667 | insert(size_type __pos, const _CharT* __s, size_type __n) |
1668 | { return this->replace(__pos, size_type(0), __s, __n); } |
1669 | |
1670 | |
1671 | |
1672 | |
1673 | |
1674 | |
1675 | |
1676 | |
1677 | |
1678 | |
1679 | |
1680 | |
1681 | |
1682 | |
1683 | |
1684 | |
1685 | basic_string& |
1686 | insert(size_type __pos, const _CharT* __s) |
1687 | { |
1688 | __glibcxx_requires_string(__s); |
1689 | return this->replace(__pos, size_type(0), __s, |
1690 | traits_type::length(__s)); |
1691 | } |
1692 | |
1693 | |
1694 | |
1695 | |
1696 | |
1697 | |
1698 | |
1699 | |
1700 | |
1701 | |
1702 | |
1703 | |
1704 | |
1705 | |
1706 | |
1707 | |
1708 | |
1709 | basic_string& |
1710 | insert(size_type __pos, size_type __n, _CharT __c) |
1711 | { return _M_replace_aux(_M_check(__pos, "basic_string::insert"), |
1712 | size_type(0), __n, __c); } |
1713 | |
1714 | |
1715 | |
1716 | |
1717 | |
1718 | |
1719 | |
1720 | |
1721 | |
1722 | |
1723 | |
1724 | |
1725 | |
1726 | |
1727 | iterator |
1728 | insert(__const_iterator __p, _CharT __c) |
1729 | { |
1730 | _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); |
1731 | const size_type __pos = __p - begin(); |
1732 | _M_replace_aux(__pos, size_type(0), size_type(1), __c); |
1733 | return iterator(_M_data() + __pos); |
1734 | } |
1735 | |
1736 | #if __cplusplus > 201402L |
1737 | |
1738 | |
1739 | |
1740 | |
1741 | |
1742 | |
1743 | template<typename _Tp> |
1744 | _If_sv<_Tp, basic_string&> |
1745 | insert(size_type __pos, const _Tp& __svt) |
1746 | { |
1747 | __sv_type __sv = __svt; |
1748 | return this->insert(__pos, __sv.data(), __sv.size()); |
1749 | } |
1750 | |
1751 | |
1752 | |
1753 | |
1754 | |
1755 | |
1756 | |
1757 | |
1758 | |
1759 | |
1760 | template<typename _Tp> |
1761 | _If_sv<_Tp, basic_string&> |
1762 | insert(size_type __pos1, const _Tp& __svt, |
1763 | size_type __pos2, size_type __n = npos) |
1764 | { |
1765 | __sv_type __sv = __svt; |
1766 | return this->replace(__pos1, size_type(0), __sv.data() |
1767 | + __sv._M_check(__pos2, "basic_string::insert"), |
1768 | __sv._M_limit(__pos2, __n)); |
1769 | } |
1770 | #endif |
1771 | |
1772 | |
1773 | |
1774 | |
1775 | |
1776 | |
1777 | |
1778 | |
1779 | |
1780 | |
1781 | |
1782 | |
1783 | |
1784 | |
1785 | |
1786 | |
1787 | basic_string& |
1788 | erase(size_type __pos = 0, size_type __n = npos) |
1789 | { |
1790 | _M_check(__pos, "basic_string::erase"); |
1791 | if (__n == npos) |
1792 | this->_M_set_length(__pos); |
1793 | else if (__n != 0) |
1794 | this->_M_erase(__pos, _M_limit(__pos, __n)); |
1795 | return *this; |
1796 | } |
1797 | |
1798 | |
1799 | |
1800 | |
1801 | |
1802 | |
1803 | |
1804 | |
1805 | |
1806 | iterator |
1807 | erase(__const_iterator __position) |
1808 | { |
1809 | _GLIBCXX_DEBUG_PEDASSERT(__position >= begin() |
1810 | && __position < end()); |
1811 | const size_type __pos = __position - begin(); |
1812 | this->_M_erase(__pos, size_type(1)); |
1813 | return iterator(_M_data() + __pos); |
1814 | } |
1815 | |
1816 | |
1817 | |
1818 | |
1819 | |
1820 | |
1821 | |
1822 | |
1823 | |
1824 | |
1825 | iterator |
1826 | erase(__const_iterator __first, __const_iterator __last) |
1827 | { |
1828 | _GLIBCXX_DEBUG_PEDASSERT(__first >= begin() && __first <= __last |
1829 | && __last <= end()); |
1830 | const size_type __pos = __first - begin(); |
1831 | if (__last == end()) |
1832 | this->_M_set_length(__pos); |
1833 | else |
1834 | this->_M_erase(__pos, __last - __first); |
1835 | return iterator(this->_M_data() + __pos); |
1836 | } |
1837 | |
1838 | #if __cplusplus >= 201103L |
1839 | |
1840 | |
1841 | |
1842 | |
1843 | |
1844 | void |
1845 | pop_back() noexcept |
1846 | { |
1847 | __glibcxx_assert(!empty()); |
1848 | _M_erase(size() - 1, 1); |
1849 | } |
1850 | #endif |
1851 | |
1852 | |
1853 | |
1854 | |
1855 | |
1856 | |
1857 | |
1858 | |
1859 | |
1860 | |
1861 | |
1862 | |
1863 | |
1864 | |
1865 | |
1866 | |
1867 | |
1868 | |
1869 | basic_string& |
1870 | replace(size_type __pos, size_type __n, const basic_string& __str) |
1871 | { return this->replace(__pos, __n, __str._M_data(), __str.size()); } |
1872 | |
1873 | |
1874 | |
1875 | |
1876 | |
1877 | |
1878 | |
1879 | |
1880 | |
1881 | |
1882 | |
1883 | |
1884 | |
1885 | |
1886 | |
1887 | |
1888 | |
1889 | |
1890 | |
1891 | basic_string& |
1892 | replace(size_type __pos1, size_type __n1, const basic_string& __str, |
1893 | size_type __pos2, size_type __n2 = npos) |
1894 | { return this->replace(__pos1, __n1, __str._M_data() |
1895 | + __str._M_check(__pos2, "basic_string::replace"), |
1896 | __str._M_limit(__pos2, __n2)); } |
1897 | |
1898 | |
1899 | |
1900 | |
1901 | |
1902 | |
1903 | |
1904 | |
1905 | |
1906 | |
1907 | |
1908 | |
1909 | |
1910 | |
1911 | |
1912 | |
1913 | |
1914 | |
1915 | |
1916 | basic_string& |
1917 | replace(size_type __pos, size_type __n1, const _CharT* __s, |
1918 | size_type __n2) |
1919 | { |
1920 | __glibcxx_requires_string_len(__s, __n2); |
1921 | return _M_replace(_M_check(__pos, "basic_string::replace"), |
1922 | _M_limit(__pos, __n1), __s, __n2); |
1923 | } |
1924 | |
1925 | |
1926 | |
1927 | |
1928 | |
1929 | |
1930 | |
1931 | |
1932 | |
1933 | |
1934 | |
1935 | |
1936 | |
1937 | |
1938 | |
1939 | |
1940 | |
1941 | basic_string& |
1942 | replace(size_type __pos, size_type __n1, const _CharT* __s) |
1943 | { |
1944 | __glibcxx_requires_string(__s); |
1945 | return this->replace(__pos, __n1, __s, traits_type::length(__s)); |
1946 | } |
1947 | |
1948 | |
1949 | |
1950 | |
1951 | |
1952 | |
1953 | |
1954 | |
1955 | |
1956 | |
1957 | |
1958 | |
1959 | |
1960 | |
1961 | |
1962 | |
1963 | |
1964 | |
1965 | basic_string& |
1966 | replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) |
1967 | { return _M_replace_aux(_M_check(__pos, "basic_string::replace"), |
1968 | _M_limit(__pos, __n1), __n2, __c); } |
1969 | |
1970 | |
1971 | |
1972 | |
1973 | |
1974 | |
1975 | |
1976 | |
1977 | |
1978 | |
1979 | |
1980 | |
1981 | |
1982 | |
1983 | basic_string& |
1984 | replace(__const_iterator __i1, __const_iterator __i2, |
1985 | const basic_string& __str) |
1986 | { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } |
1987 | |
1988 | |
1989 | |
1990 | |
1991 | |
1992 | |
1993 | |
1994 | |
1995 | |
1996 | |
1997 | |
1998 | |
1999 | |
2000 | |
2001 | |
2002 | |
2003 | basic_string& |
2004 | replace(__const_iterator __i1, __const_iterator __i2, |
2005 | const _CharT* __s, size_type __n) |
2006 | { |
2007 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
2008 | && __i2 <= end()); |
2009 | return this->replace(__i1 - begin(), __i2 - __i1, __s, __n); |
2010 | } |
2011 | |
2012 | |
2013 | |
2014 | |
2015 | |
2016 | |
2017 | |
2018 | |
2019 | |
2020 | |
2021 | |
2022 | |
2023 | |
2024 | |
2025 | basic_string& |
2026 | replace(__const_iterator __i1, __const_iterator __i2, const _CharT* __s) |
2027 | { |
2028 | __glibcxx_requires_string(__s); |
2029 | return this->replace(__i1, __i2, __s, traits_type::length(__s)); |
2030 | } |
2031 | |
2032 | |
2033 | |
2034 | |
2035 | |
2036 | |
2037 | |
2038 | |
2039 | |
2040 | |
2041 | |
2042 | |
2043 | |
2044 | |
2045 | |
2046 | basic_string& |
2047 | replace(__const_iterator __i1, __const_iterator __i2, size_type __n, |
2048 | _CharT __c) |
2049 | { |
2050 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
2051 | && __i2 <= end()); |
2052 | return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __c); |
2053 | } |
2054 | |
2055 | |
2056 | |
2057 | |
2058 | |
2059 | |
2060 | |
2061 | |
2062 | |
2063 | |
2064 | |
2065 | |
2066 | |
2067 | |
2068 | |
2069 | |
2070 | #if __cplusplus >= 201103L |
2071 | template<class _InputIterator, |
2072 | typename = std::_RequireInputIter<_InputIterator>> |
2073 | basic_string& |
2074 | replace(const_iterator __i1, const_iterator __i2, |
2075 | _InputIterator __k1, _InputIterator __k2) |
2076 | { |
2077 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
2078 | && __i2 <= end()); |
2079 | __glibcxx_requires_valid_range(__k1, __k2); |
2080 | return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, |
2081 | std::__false_type()); |
2082 | } |
2083 | #else |
2084 | template<class _InputIterator> |
2085 | #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST |
2086 | typename __enable_if_not_native_iterator<_InputIterator>::__type |
2087 | #else |
2088 | basic_string& |
2089 | #endif |
2090 | replace(iterator __i1, iterator __i2, |
2091 | _InputIterator __k1, _InputIterator __k2) |
2092 | { |
2093 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
2094 | && __i2 <= end()); |
2095 | __glibcxx_requires_valid_range(__k1, __k2); |
2096 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; |
2097 | return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); |
2098 | } |
2099 | #endif |
2100 | |
2101 | |
2102 | |
2103 | basic_string& |
2104 | replace(__const_iterator __i1, __const_iterator __i2, |
2105 | _CharT* __k1, _CharT* __k2) |
2106 | { |
2107 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
2108 | && __i2 <= end()); |
2109 | __glibcxx_requires_valid_range(__k1, __k2); |
2110 | return this->replace(__i1 - begin(), __i2 - __i1, |
2111 | __k1, __k2 - __k1); |
2112 | } |
2113 | |
2114 | basic_string& |
2115 | replace(__const_iterator __i1, __const_iterator __i2, |
2116 | const _CharT* __k1, const _CharT* __k2) |
2117 | { |
2118 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
2119 | && __i2 <= end()); |
2120 | __glibcxx_requires_valid_range(__k1, __k2); |
2121 | return this->replace(__i1 - begin(), __i2 - __i1, |
2122 | __k1, __k2 - __k1); |
2123 | } |
2124 | |
2125 | basic_string& |
2126 | replace(__const_iterator __i1, __const_iterator __i2, |
2127 | iterator __k1, iterator __k2) |
2128 | { |
2129 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
2130 | && __i2 <= end()); |
2131 | __glibcxx_requires_valid_range(__k1, __k2); |
2132 | return this->replace(__i1 - begin(), __i2 - __i1, |
2133 | __k1.base(), __k2 - __k1); |
2134 | } |
2135 | |
2136 | basic_string& |
2137 | replace(__const_iterator __i1, __const_iterator __i2, |
2138 | const_iterator __k1, const_iterator __k2) |
2139 | { |
2140 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
2141 | && __i2 <= end()); |
2142 | __glibcxx_requires_valid_range(__k1, __k2); |
2143 | return this->replace(__i1 - begin(), __i2 - __i1, |
2144 | __k1.base(), __k2 - __k1); |
2145 | } |
2146 | |
2147 | #if __cplusplus >= 201103L |
2148 | |
2149 | |
2150 | |
2151 | |
2152 | |
2153 | |
2154 | |
2155 | |
2156 | |
2157 | |
2158 | |
2159 | |
2160 | |
2161 | |
2162 | basic_string& replace(const_iterator __i1, const_iterator __i2, |
2163 | initializer_list<_CharT> __l) |
2164 | { return this->replace(__i1, __i2, __l.begin(), __l.size()); } |
2165 | #endif |
2166 | |
2167 | #if __cplusplus > 201402L |
2168 | |
2169 | |
2170 | |
2171 | |
2172 | |
2173 | |
2174 | |
2175 | template<typename _Tp> |
2176 | _If_sv<_Tp, basic_string&> |
2177 | replace(size_type __pos, size_type __n, const _Tp& __svt) |
2178 | { |
2179 | __sv_type __sv = __svt; |
2180 | return this->replace(__pos, __n, __sv.data(), __sv.size()); |
2181 | } |
2182 | |
2183 | |
2184 | |
2185 | |
2186 | |
2187 | |
2188 | |
2189 | |
2190 | |
2191 | |
2192 | template<typename _Tp> |
2193 | _If_sv<_Tp, basic_string&> |
2194 | replace(size_type __pos1, size_type __n1, const _Tp& __svt, |
2195 | size_type __pos2, size_type __n2 = npos) |
2196 | { |
2197 | __sv_type __sv = __svt; |
2198 | return this->replace(__pos1, __n1, __sv.data() |
2199 | + __sv._M_check(__pos2, "basic_string::replace"), |
2200 | __sv._M_limit(__pos2, __n2)); |
2201 | } |
2202 | |
2203 | |
2204 | |
2205 | |
2206 | |
2207 | |
2208 | |
2209 | |
2210 | |
2211 | |
2212 | template<typename _Tp> |
2213 | _If_sv<_Tp, basic_string&> |
2214 | replace(const_iterator __i1, const_iterator __i2, const _Tp& __svt) |
2215 | { |
2216 | __sv_type __sv = __svt; |
2217 | return this->replace(__i1 - begin(), __i2 - __i1, __sv); |
2218 | } |
2219 | #endif |
2220 | |
2221 | private: |
2222 | template<class _Integer> |
2223 | basic_string& |
2224 | _M_replace_dispatch(const_iterator __i1, const_iterator __i2, |
2225 | _Integer __n, _Integer __val, __true_type) |
2226 | { return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __val); } |
2227 | |
2228 | template<class _InputIterator> |
2229 | basic_string& |
2230 | _M_replace_dispatch(const_iterator __i1, const_iterator __i2, |
2231 | _InputIterator __k1, _InputIterator __k2, |
2232 | __false_type); |
2233 | |
2234 | basic_string& |
2235 | _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, |
2236 | _CharT __c); |
2237 | |
2238 | basic_string& |
2239 | _M_replace(size_type __pos, size_type __len1, const _CharT* __s, |
2240 | const size_type __len2); |
2241 | |
2242 | basic_string& |
2243 | _M_append(const _CharT* __s, size_type __n); |
2244 | |
2245 | public: |
2246 | |
2247 | |
2248 | |
2249 | |
2250 | |
2251 | |
2252 | |
2253 | |
2254 | |
2255 | |
2256 | |
2257 | |
2258 | |
2259 | size_type |
2260 | copy(_CharT* __s, size_type __n, size_type __pos = 0) const; |
2261 | |
2262 | |
2263 | |
2264 | |
2265 | |
2266 | |
2267 | |
2268 | |
2269 | void |
2270 | swap(basic_string& __s) _GLIBCXX_NOEXCEPT; |
2271 | |
2272 | |
2273 | |
2274 | |
2275 | |
2276 | |
2277 | |
2278 | |
2279 | const _CharT* |
2280 | c_str() const _GLIBCXX_NOEXCEPT |
2281 | { return _M_data(); } |
2282 | |
2283 | |
2284 | |
2285 | |
2286 | |
2287 | |
2288 | |
2289 | |
2290 | |
2291 | const _CharT* |
2292 | data() const _GLIBCXX_NOEXCEPT |
2293 | { return _M_data(); } |
2294 | |
2295 | #if __cplusplus > 201402L |
2296 | |
2297 | |
2298 | |
2299 | |
2300 | |
2301 | |
2302 | _CharT* |
2303 | data() noexcept |
2304 | { return _M_data(); } |
2305 | #endif |
2306 | |
2307 | |
2308 | |
2309 | |
2310 | allocator_type |
2311 | get_allocator() const _GLIBCXX_NOEXCEPT |
2312 | { return _M_get_allocator(); } |
2313 | |
2314 | |
2315 | |
2316 | |
2317 | |
2318 | |
2319 | |
2320 | |
2321 | |
2322 | |
2323 | |
2324 | |
2325 | |
2326 | size_type |
2327 | find(const _CharT* __s, size_type __pos, size_type __n) const |
2328 | _GLIBCXX_NOEXCEPT; |
2329 | |
2330 | |
2331 | |
2332 | |
2333 | |
2334 | |
2335 | |
2336 | |
2337 | |
2338 | |
2339 | |
2340 | size_type |
2341 | find(const basic_string& __str, size_type __pos = 0) const |
2342 | _GLIBCXX_NOEXCEPT |
2343 | { return this->find(__str.data(), __pos, __str.size()); } |
2344 | |
2345 | #if __cplusplus > 201402L |
2346 | |
2347 | |
2348 | |
2349 | |
2350 | |
2351 | |
2352 | template<typename _Tp> |
2353 | _If_sv<_Tp, size_type> |
2354 | find(const _Tp& __svt, size_type __pos = 0) const |
2355 | noexcept(is_same<_Tp, __sv_type>::value) |
2356 | { |
2357 | __sv_type __sv = __svt; |
2358 | return this->find(__sv.data(), __pos, __sv.size()); |
2359 | } |
2360 | #endif |
2361 | |
2362 | |
2363 | |
2364 | |
2365 | |
2366 | |
2367 | |
2368 | |
2369 | |
2370 | |
2371 | |
2372 | size_type |
2373 | find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT |
2374 | { |
2375 | __glibcxx_requires_string(__s); |
2376 | return this->find(__s, __pos, traits_type::length(__s)); |
2377 | } |
2378 | |
2379 | |
2380 | |
2381 | |
2382 | |
2383 | |
2384 | |
2385 | |
2386 | |
2387 | |
2388 | |
2389 | size_type |
2390 | find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT; |
2391 | |
2392 | |
2393 | |
2394 | |
2395 | |
2396 | |
2397 | |
2398 | |
2399 | |
2400 | |
2401 | |
2402 | size_type |
2403 | rfind(const basic_string& __str, size_type __pos = npos) const |
2404 | _GLIBCXX_NOEXCEPT |
2405 | { return this->rfind(__str.data(), __pos, __str.size()); } |
2406 | |
2407 | #if __cplusplus > 201402L |
2408 | |
2409 | |
2410 | |
2411 | |
2412 | |
2413 | |
2414 | template<typename _Tp> |
2415 | _If_sv<_Tp, size_type> |
2416 | rfind(const _Tp& __svt, size_type __pos = npos) const |
2417 | noexcept(is_same<_Tp, __sv_type>::value) |
2418 | { |
2419 | __sv_type __sv = __svt; |
2420 | return this->rfind(__sv.data(), __pos, __sv.size()); |
2421 | } |
2422 | #endif |
2423 | |
2424 | |
2425 | |
2426 | |
2427 | |
2428 | |
2429 | |
2430 | |
2431 | |
2432 | |
2433 | |
2434 | |
2435 | |
2436 | size_type |
2437 | rfind(const _CharT* __s, size_type __pos, size_type __n) const |
2438 | _GLIBCXX_NOEXCEPT; |
2439 | |
2440 | |
2441 | |
2442 | |
2443 | |
2444 | |
2445 | |
2446 | |
2447 | |
2448 | |
2449 | |
2450 | size_type |
2451 | rfind(const _CharT* __s, size_type __pos = npos) const |
2452 | { |
2453 | __glibcxx_requires_string(__s); |
2454 | return this->rfind(__s, __pos, traits_type::length(__s)); |
2455 | } |
2456 | |
2457 | |
2458 | |
2459 | |
2460 | |
2461 | |
2462 | |
2463 | |
2464 | |
2465 | |
2466 | |
2467 | size_type |
2468 | rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT; |
2469 | |
2470 | |
2471 | |
2472 | |
2473 | |
2474 | |
2475 | |
2476 | |
2477 | |
2478 | |
2479 | |
2480 | |
2481 | size_type |
2482 | find_first_of(const basic_string& __str, size_type __pos = 0) const |
2483 | _GLIBCXX_NOEXCEPT |
2484 | { return this->find_first_of(__str.data(), __pos, __str.size()); } |
2485 | |
2486 | #if __cplusplus > 201402L |
2487 | |
2488 | |
2489 | |
2490 | |
2491 | |
2492 | |
2493 | |
2494 | template<typename _Tp> |
2495 | _If_sv<_Tp, size_type> |
2496 | find_first_of(const _Tp& __svt, size_type __pos = 0) const |
2497 | noexcept(is_same<_Tp, __sv_type>::value) |
2498 | { |
2499 | __sv_type __sv = __svt; |
2500 | return this->find_first_of(__sv.data(), __pos, __sv.size()); |
2501 | } |
2502 | #endif |
2503 | |
2504 | |
2505 | |
2506 | |
2507 | |
2508 | |
2509 | |
2510 | |
2511 | |
2512 | |
2513 | |
2514 | |
2515 | |
2516 | size_type |
2517 | find_first_of(const _CharT* __s, size_type __pos, size_type __n) const |
2518 | _GLIBCXX_NOEXCEPT; |
2519 | |
2520 | |
2521 | |
2522 | |
2523 | |
2524 | |
2525 | |
2526 | |
2527 | |
2528 | |
2529 | |
2530 | size_type |
2531 | find_first_of(const _CharT* __s, size_type __pos = 0) const |
2532 | _GLIBCXX_NOEXCEPT |
2533 | { |
2534 | __glibcxx_requires_string(__s); |
2535 | return this->find_first_of(__s, __pos, traits_type::length(__s)); |
2536 | } |
2537 | |
2538 | |
2539 | |
2540 | |
2541 | |
2542 | |
2543 | |
2544 | |
2545 | |
2546 | |
2547 | |
2548 | |
2549 | |
2550 | size_type |
2551 | find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT |
2552 | { return this->find(__c, __pos); } |
2553 | |
2554 | |
2555 | |
2556 | |
2557 | |
2558 | |
2559 | |
2560 | |
2561 | |
2562 | |
2563 | |
2564 | |
2565 | size_type |
2566 | find_last_of(const basic_string& __str, size_type __pos = npos) const |
2567 | _GLIBCXX_NOEXCEPT |
2568 | { return this->find_last_of(__str.data(), __pos, __str.size()); } |
2569 | |
2570 | #if __cplusplus > 201402L |
2571 | |
2572 | |
2573 | |
2574 | |
2575 | |
2576 | |
2577 | |
2578 | template<typename _Tp> |
2579 | _If_sv<_Tp, size_type> |
2580 | find_last_of(const _Tp& __svt, size_type __pos = npos) const |
2581 | noexcept(is_same<_Tp, __sv_type>::value) |
2582 | { |
2583 | __sv_type __sv = __svt; |
2584 | return this->find_last_of(__sv.data(), __pos, __sv.size()); |
2585 | } |
2586 | #endif |
2587 | |
2588 | |
2589 | |
2590 | |
2591 | |
2592 | |
2593 | |
2594 | |
2595 | |
2596 | |
2597 | |
2598 | |
2599 | |
2600 | size_type |
2601 | find_last_of(const _CharT* __s, size_type __pos, size_type __n) const |
2602 | _GLIBCXX_NOEXCEPT; |
2603 | |
2604 | |
2605 | |
2606 | |
2607 | |
2608 | |
2609 | |
2610 | |
2611 | |
2612 | |
2613 | |
2614 | size_type |
2615 | find_last_of(const _CharT* __s, size_type __pos = npos) const |
2616 | _GLIBCXX_NOEXCEPT |
2617 | { |
2618 | __glibcxx_requires_string(__s); |
2619 | return this->find_last_of(__s, __pos, traits_type::length(__s)); |
2620 | } |
2621 | |
2622 | |
2623 | |
2624 | |
2625 | |
2626 | |
2627 | |
2628 | |
2629 | |
2630 | |
2631 | |
2632 | |
2633 | |
2634 | size_type |
2635 | find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT |
2636 | { return this->rfind(__c, __pos); } |
2637 | |
2638 | |
2639 | |
2640 | |
2641 | |
2642 | |
2643 | |
2644 | |
2645 | |
2646 | |
2647 | |
2648 | size_type |
2649 | find_first_not_of(const basic_string& __str, size_type __pos = 0) const |
2650 | _GLIBCXX_NOEXCEPT |
2651 | { return this->find_first_not_of(__str.data(), __pos, __str.size()); } |
2652 | |
2653 | #if __cplusplus > 201402L |
2654 | |
2655 | |
2656 | |
2657 | |
2658 | |
2659 | |
2660 | |
2661 | template<typename _Tp> |
2662 | _If_sv<_Tp, size_type> |
2663 | find_first_not_of(const _Tp& __svt, size_type __pos = 0) const |
2664 | noexcept(is_same<_Tp, __sv_type>::value) |
2665 | { |
2666 | __sv_type __sv = __svt; |
2667 | return this->find_first_not_of(__sv.data(), __pos, __sv.size()); |
2668 | } |
2669 | #endif |
2670 | |
2671 | |
2672 | |
2673 | |
2674 | |
2675 | |
2676 | |
2677 | |
2678 | |
2679 | |
2680 | |
2681 | |
2682 | |
2683 | size_type |
2684 | find_first_not_of(const _CharT* __s, size_type __pos, |
2685 | size_type __n) const _GLIBCXX_NOEXCEPT; |
2686 | |
2687 | |
2688 | |
2689 | |
2690 | |
2691 | |
2692 | |
2693 | |
2694 | |
2695 | |
2696 | |
2697 | size_type |
2698 | find_first_not_of(const _CharT* __s, size_type __pos = 0) const |
2699 | _GLIBCXX_NOEXCEPT |
2700 | { |
2701 | __glibcxx_requires_string(__s); |
2702 | return this->find_first_not_of(__s, __pos, traits_type::length(__s)); |
2703 | } |
2704 | |
2705 | |
2706 | |
2707 | |
2708 | |
2709 | |
2710 | |
2711 | |
2712 | |
2713 | |
2714 | |
2715 | size_type |
2716 | find_first_not_of(_CharT __c, size_type __pos = 0) const |
2717 | _GLIBCXX_NOEXCEPT; |
2718 | |
2719 | |
2720 | |
2721 | |
2722 | |
2723 | |
2724 | |
2725 | |
2726 | |
2727 | |
2728 | |
2729 | |
2730 | size_type |
2731 | find_last_not_of(const basic_string& __str, size_type __pos = npos) const |
2732 | _GLIBCXX_NOEXCEPT |
2733 | { return this->find_last_not_of(__str.data(), __pos, __str.size()); } |
2734 | |
2735 | #if __cplusplus > 201402L |
2736 | |
2737 | |
2738 | |
2739 | |
2740 | |
2741 | |
2742 | |
2743 | template<typename _Tp> |
2744 | _If_sv<_Tp, size_type> |
2745 | find_last_not_of(const _Tp& __svt, size_type __pos = npos) const |
2746 | noexcept(is_same<_Tp, __sv_type>::value) |
2747 | { |
2748 | __sv_type __sv = __svt; |
2749 | return this->find_last_not_of(__sv.data(), __pos, __sv.size()); |
2750 | } |
2751 | #endif |
2752 | |
2753 | |
2754 | |
2755 | |
2756 | |
2757 | |
2758 | |
2759 | |
2760 | |
2761 | |
2762 | |
2763 | |
2764 | |
2765 | size_type |
2766 | find_last_not_of(const _CharT* __s, size_type __pos, |
2767 | size_type __n) const _GLIBCXX_NOEXCEPT; |
2768 | |
2769 | |
2770 | |
2771 | |
2772 | |
2773 | |
2774 | |
2775 | |
2776 | |
2777 | |
2778 | |
2779 | size_type |
2780 | find_last_not_of(const _CharT* __s, size_type __pos = npos) const |
2781 | _GLIBCXX_NOEXCEPT |
2782 | { |
2783 | __glibcxx_requires_string(__s); |
2784 | return this->find_last_not_of(__s, __pos, traits_type::length(__s)); |
2785 | } |
2786 | |
2787 | |
2788 | |
2789 | |
2790 | |
2791 | |
2792 | |
2793 | |
2794 | |
2795 | |
2796 | |
2797 | size_type |
2798 | find_last_not_of(_CharT __c, size_type __pos = npos) const |
2799 | _GLIBCXX_NOEXCEPT; |
2800 | |
2801 | |
2802 | |
2803 | |
2804 | |
2805 | |
2806 | |
2807 | |
2808 | |
2809 | |
2810 | |
2811 | |
2812 | |
2813 | basic_string |
2814 | substr(size_type __pos = 0, size_type __n = npos) const |
2815 | { return basic_string(*this, |
2816 | _M_check(__pos, "basic_string::substr"), __n); } |
2817 | |
2818 | |
2819 | |
2820 | |
2821 | |
2822 | |
2823 | |
2824 | |
2825 | |
2826 | |
2827 | |
2828 | |
2829 | |
2830 | |
2831 | |
2832 | int |
2833 | compare(const basic_string& __str) const |
2834 | { |
2835 | const size_type __size = this->size(); |
2836 | const size_type __osize = __str.size(); |
2837 | const size_type __len = std::min(__size, __osize); |
2838 | |
2839 | int __r = traits_type::compare(_M_data(), __str.data(), __len); |
2840 | if (!__r) |
2841 | __r = _S_compare(__size, __osize); |
2842 | return __r; |
2843 | } |
2844 | |
2845 | #if __cplusplus > 201402L |
2846 | |
2847 | |
2848 | |
2849 | |
2850 | |
2851 | template<typename _Tp> |
2852 | _If_sv<_Tp, int> |
2853 | compare(const _Tp& __svt) const |
2854 | noexcept(is_same<_Tp, __sv_type>::value) |
2855 | { |
2856 | __sv_type __sv = __svt; |
2857 | const size_type __size = this->size(); |
2858 | const size_type __osize = __sv.size(); |
2859 | const size_type __len = std::min(__size, __osize); |
2860 | |
2861 | int __r = traits_type::compare(_M_data(), __sv.data(), __len); |
2862 | if (!__r) |
2863 | __r = _S_compare(__size, __osize); |
2864 | return __r; |
2865 | } |
2866 | |
2867 | |
2868 | |
2869 | |
2870 | |
2871 | |
2872 | |
2873 | |
2874 | |
2875 | template<typename _Tp> |
2876 | _If_sv<_Tp, int> |
2877 | compare(size_type __pos, size_type __n, const _Tp& __svt) const |
2878 | noexcept(is_same<_Tp, __sv_type>::value) |
2879 | { |
2880 | __sv_type __sv = __svt; |
2881 | return __sv_type(*this).substr(__pos, __n).compare(__sv); |
2882 | } |
2883 | |
2884 | |
2885 | |
2886 | |
2887 | |
2888 | |
2889 | |
2890 | |
2891 | |
2892 | |
2893 | |
2894 | template<typename _Tp> |
2895 | _If_sv<_Tp, int> |
2896 | compare(size_type __pos1, size_type __n1, const _Tp& __svt, |
2897 | size_type __pos2, size_type __n2 = npos) const |
2898 | noexcept(is_same<_Tp, __sv_type>::value) |
2899 | { |
2900 | __sv_type __sv = __svt; |
2901 | return __sv_type(*this) |
2902 | .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); |
2903 | } |
2904 | #endif |
2905 | |
2906 | |
2907 | |
2908 | |
2909 | |
2910 | |
2911 | |
2912 | |
2913 | |
2914 | |
2915 | |
2916 | |
2917 | |
2918 | |
2919 | |
2920 | |
2921 | |
2922 | |
2923 | |
2924 | |
2925 | int |
2926 | compare(size_type __pos, size_type __n, const basic_string& __str) const; |
2927 | |
2928 | |
2929 | |
2930 | |
2931 | |
2932 | |
2933 | |
2934 | |
2935 | |
2936 | |
2937 | |
2938 | |
2939 | |
2940 | |
2941 | |
2942 | |
2943 | |
2944 | |
2945 | |
2946 | |
2947 | |
2948 | |
2949 | |
2950 | |
2951 | int |
2952 | compare(size_type __pos1, size_type __n1, const basic_string& __str, |
2953 | size_type __pos2, size_type __n2 = npos) const; |
2954 | |
2955 | |
2956 | |
2957 | |
2958 | |
2959 | |
2960 | |
2961 | |
2962 | |
2963 | |
2964 | |
2965 | |
2966 | |
2967 | |
2968 | |
2969 | int |
2970 | compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT; |
2971 | |
2972 | |
2973 | |
2974 | |
2975 | |
2976 | |
2977 | |
2978 | |
2979 | |
2980 | |
2981 | |
2982 | |
2983 | |
2984 | |
2985 | |
2986 | |
2987 | |
2988 | |
2989 | |
2990 | |
2991 | |
2992 | |
2993 | int |
2994 | compare(size_type __pos, size_type __n1, const _CharT* __s) const; |
2995 | |
2996 | |
2997 | |
2998 | |
2999 | |
3000 | |
3001 | |
3002 | |
3003 | |
3004 | |
3005 | |
3006 | |
3007 | |
3008 | |
3009 | |
3010 | |
3011 | |
3012 | |
3013 | |
3014 | |
3015 | |
3016 | |
3017 | |
3018 | |
3019 | |
3020 | int |
3021 | compare(size_type __pos, size_type __n1, const _CharT* __s, |
3022 | size_type __n2) const; |
3023 | |
3024 | |
3025 | template<typename, typename, typename> friend class basic_stringbuf; |
3026 | }; |
3027 | _GLIBCXX_END_NAMESPACE_CXX11 |
3028 | #else |
3029 | |
3030 | |
3031 | |
3032 | |
3033 | |
3034 | |
3035 | |
3036 | |
3037 | |
3038 | |
3039 | |
3040 | |
3041 | |
3042 | |
3043 | |
3044 | |
3045 | |
3046 | |
3047 | |
3048 | |
3049 | |
3050 | |
3051 | |
3052 | |
3053 | |
3054 | |
3055 | |
3056 | |
3057 | |
3058 | |
3059 | |
3060 | |
3061 | |
3062 | |
3063 | |
3064 | |
3065 | |
3066 | |
3067 | |
3068 | |
3069 | |
3070 | |
3071 | |
3072 | |
3073 | |
3074 | |
3075 | |
3076 | |
3077 | |
3078 | |
3079 | |
3080 | |
3081 | |
3082 | |
3083 | |
3084 | |
3085 | |
3086 | |
3087 | |
3088 | |
3089 | |
3090 | |
3091 | |
3092 | |
3093 | template<typename _CharT, typename _Traits, typename _Alloc> |
3094 | class basic_string |
3095 | { |
3096 | typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type; |
3097 | |
3098 | |
3099 | public: |
3100 | typedef _Traits traits_type; |
3101 | typedef typename _Traits::char_type value_type; |
3102 | typedef _Alloc allocator_type; |
3103 | typedef typename _CharT_alloc_type::size_type size_type; |
3104 | typedef typename _CharT_alloc_type::difference_type difference_type; |
3105 | typedef typename _CharT_alloc_type::reference reference; |
3106 | typedef typename _CharT_alloc_type::const_reference const_reference; |
3107 | typedef typename _CharT_alloc_type::pointer pointer; |
3108 | typedef typename _CharT_alloc_type::const_pointer const_pointer; |
3109 | typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator; |
3110 | typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string> |
3111 | const_iterator; |
3112 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
3113 | typedef std::reverse_iterator<iterator> reverse_iterator; |
3114 | |
3115 | private: |
3116 | |
3117 | |
3118 | |
3119 | |
3120 | |
3121 | |
3122 | |
3123 | |
3124 | |
3125 | |
3126 | |
3127 | |
3128 | |
3129 | |
3130 | struct _Rep_base |
3131 | { |
3132 | size_type _M_length; |
3133 | size_type _M_capacity; |
3134 | _Atomic_word _M_refcount; |
3135 | }; |
3136 | |
3137 | struct _Rep : _Rep_base |
3138 | { |
3139 | |
3140 | typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc; |
3141 | |
3142 | |
3143 | |
3144 | |
3145 | |
3146 | |
3147 | |
3148 | |
3149 | |
3150 | |
3151 | |
3152 | |
3153 | |
3154 | |
3155 | static const size_type _S_max_size; |
3156 | static const _CharT _S_terminal; |
3157 | |
3158 | |
3159 | |
3160 | static size_type _S_empty_rep_storage[]; |
3161 | |
3162 | static _Rep& |
3163 | _S_empty_rep() _GLIBCXX_NOEXCEPT |
3164 | { |
3165 | |
3166 | |
3167 | |
3168 | void* __p = reinterpret_cast<void*>(&_S_empty_rep_storage); |
3169 | return *reinterpret_cast<_Rep*>(__p); |
3170 | } |
3171 | |
3172 | bool |
3173 | _M_is_leaked() const _GLIBCXX_NOEXCEPT |
3174 | { |
3175 | #if defined(__GTHREADS) |
3176 | |
3177 | |
3178 | |
3179 | |
3180 | return __atomic_load_n(&this->_M_refcount, __ATOMIC_RELAXED) < 0; |
3181 | #else |
3182 | return this->_M_refcount < 0; |
3183 | #endif |
3184 | } |
3185 | |
3186 | bool |
3187 | _M_is_shared() const _GLIBCXX_NOEXCEPT |
3188 | { |
3189 | #if defined(__GTHREADS) |
3190 | |
3191 | |
3192 | |
3193 | |
3194 | |
3195 | return __atomic_load_n(&this->_M_refcount, __ATOMIC_ACQUIRE) > 0; |
3196 | #else |
3197 | return this->_M_refcount > 0; |
3198 | #endif |
3199 | } |
3200 | |
3201 | void |
3202 | _M_set_leaked() _GLIBCXX_NOEXCEPT |
3203 | { this->_M_refcount = -1; } |
3204 | |
3205 | void |
3206 | _M_set_sharable() _GLIBCXX_NOEXCEPT |
3207 | { this->_M_refcount = 0; } |
3208 | |
3209 | void |
3210 | _M_set_length_and_sharable(size_type __n) _GLIBCXX_NOEXCEPT |
3211 | { |
3212 | #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 |
3213 | if (__builtin_expect(this != &_S_empty_rep(), false)) |
3214 | #endif |
3215 | { |
3216 | this->_M_set_sharable(); |
3217 | this->_M_length = __n; |
3218 | traits_type::assign(this->_M_refdata()[__n], _S_terminal); |
3219 | |
3220 | |
3221 | } |
3222 | } |
3223 | |
3224 | _CharT* |
3225 | _M_refdata() throw() |
3226 | { return reinterpret_cast<_CharT*>(this + 1); } |
3227 | |
3228 | _CharT* |
3229 | _M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2) |
3230 | { |
3231 | return (!_M_is_leaked() && __alloc1 == __alloc2) |
3232 | ? _M_refcopy() : _M_clone(__alloc1); |
3233 | } |
3234 | |
3235 | |
3236 | static _Rep* |
3237 | _S_create(size_type, size_type, const _Alloc&); |
3238 | |
3239 | void |
3240 | _M_dispose(const _Alloc& __a) _GLIBCXX_NOEXCEPT |
3241 | { |
3242 | #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 |
3243 | if (__builtin_expect(this != &_S_empty_rep(), false)) |
3244 | #endif |
3245 | { |
3246 | |
3247 | _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount); |
3248 | |
3249 | |
3250 | |
3251 | |
3252 | |
3253 | |
3254 | |
3255 | |
3256 | if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount, |
3257 | -1) <= 0) |
3258 | { |
3259 | _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount); |
3260 | _M_destroy(__a); |
3261 | } |
3262 | } |
3263 | } |
3264 | |
3265 | void |
3266 | _M_destroy(const _Alloc&) throw(); |
3267 | |
3268 | _CharT* |
3269 | _M_refcopy() throw() |
3270 | { |
3271 | #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 |
3272 | if (__builtin_expect(this != &_S_empty_rep(), false)) |
3273 | #endif |
3274 | __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1); |
3275 | return _M_refdata(); |
3276 | } |
3277 | |
3278 | _CharT* |
3279 | _M_clone(const _Alloc&, size_type __res = 0); |
3280 | }; |
3281 | |
3282 | |
3283 | struct _Alloc_hider : _Alloc |
3284 | { |
3285 | _Alloc_hider(_CharT* __dat, const _Alloc& __a) _GLIBCXX_NOEXCEPT |
3286 | : _Alloc(__a), _M_p(__dat) { } |
3287 | |
3288 | _CharT* _M_p; |
3289 | }; |
3290 | |
3291 | public: |
3292 | |
3293 | |
3294 | |
3295 | |
3296 | static const size_type npos = static_cast<size_type>(-1); |
3297 | |
3298 | private: |
3299 | |
3300 | mutable _Alloc_hider _M_dataplus; |
3301 | |
3302 | _CharT* |
3303 | _M_data() const _GLIBCXX_NOEXCEPT |
3304 | { return _M_dataplus._M_p; } |
3305 | |
3306 | _CharT* |
3307 | _M_data(_CharT* __p) _GLIBCXX_NOEXCEPT |
3308 | { return (_M_dataplus._M_p = __p); } |
3309 | |
3310 | _Rep* |
3311 | _M_rep() const _GLIBCXX_NOEXCEPT |
3312 | { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); } |
3313 | |
3314 | |
3315 | |
3316 | iterator |
3317 | _M_ibegin() const _GLIBCXX_NOEXCEPT |
3318 | { return iterator(_M_data()); } |
3319 | |
3320 | iterator |
3321 | _M_iend() const _GLIBCXX_NOEXCEPT |
3322 | { return iterator(_M_data() + this->size()); } |
3323 | |
3324 | void |
3325 | _M_leak() |
3326 | { |
3327 | if (!_M_rep()->_M_is_leaked()) |
3328 | _M_leak_hard(); |
3329 | } |
3330 | |
3331 | size_type |
3332 | _M_check(size_type __pos, const char* __s) const |
3333 | { |
3334 | if (__pos > this->size()) |
3335 | __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > " |
3336 | "this->size() (which is %zu)"), |
3337 | __s, __pos, this->size()); |
3338 | return __pos; |
3339 | } |
3340 | |
3341 | void |
3342 | _M_check_length(size_type __n1, size_type __n2, const char* __s) const |
3343 | { |
3344 | if (this->max_size() - (this->size() - __n1) < __n2) |
3345 | __throw_length_error(__N(__s)); |
3346 | } |
3347 | |
3348 | |
3349 | size_type |
3350 | _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT |
3351 | { |
3352 | const bool __testoff = __off < this->size() - __pos; |
3353 | return __testoff ? __off : this->size() - __pos; |
3354 | } |
3355 | |
3356 | |
3357 | bool |
3358 | _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT |
3359 | { |
3360 | return (less<const _CharT*>()(__s, _M_data()) |
3361 | || less<const _CharT*>()(_M_data() + this->size(), __s)); |
3362 | } |
3363 | |
3364 | |
3365 | |
3366 | static void |
3367 | _M_copy(_CharT* __d, const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT |
3368 | { |
3369 | if (__n == 1) |
3370 | traits_type::assign(*__d, *__s); |
3371 | else |
3372 | traits_type::copy(__d, __s, __n); |
3373 | } |
3374 | |
3375 | static void |
3376 | _M_move(_CharT* __d, const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT |
3377 | { |
3378 | if (__n == 1) |
3379 | traits_type::assign(*__d, *__s); |
3380 | else |
3381 | traits_type::move(__d, __s, __n); |
3382 | } |
3383 | |
3384 | static void |
3385 | _M_assign(_CharT* __d, size_type __n, _CharT __c) _GLIBCXX_NOEXCEPT |
3386 | { |
3387 | if (__n == 1) |
3388 | traits_type::assign(*__d, __c); |
3389 | else |
3390 | traits_type::assign(__d, __n, __c); |
3391 | } |
3392 | |
3393 | |
3394 | |
3395 | template<class _Iterator> |
3396 | static void |
3397 | _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2) |
3398 | { |
3399 | for (; __k1 != __k2; ++__k1, (void)++__p) |
3400 | traits_type::assign(*__p, *__k1); |
3401 | } |
3402 | |
3403 | static void |
3404 | _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT |
3405 | { _S_copy_chars(__p, __k1.base(), __k2.base()); } |
3406 | |
3407 | static void |
3408 | _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2) |
3409 | _GLIBCXX_NOEXCEPT |
3410 | { _S_copy_chars(__p, __k1.base(), __k2.base()); } |
3411 | |
3412 | static void |
3413 | _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT |
3414 | { _M_copy(__p, __k1, __k2 - __k1); } |
3415 | |
3416 | static void |
3417 | _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2) |
3418 | _GLIBCXX_NOEXCEPT |
3419 | { _M_copy(__p, __k1, __k2 - __k1); } |
3420 | |
3421 | static int |
3422 | _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT |
3423 | { |
3424 | const difference_type __d = difference_type(__n1 - __n2); |
3425 | |
3426 | if (__d > __gnu_cxx::__numeric_traits<int>::__max) |
3427 | return __gnu_cxx::__numeric_traits<int>::__max; |
3428 | else if (__d < __gnu_cxx::__numeric_traits<int>::__min) |
3429 | return __gnu_cxx::__numeric_traits<int>::__min; |
3430 | else |
3431 | return int(__d); |
3432 | } |
3433 | |
3434 | void |
3435 | _M_mutate(size_type __pos, size_type __len1, size_type __len2); |
3436 | |
3437 | void |
3438 | _M_leak_hard(); |
3439 | |
3440 | static _Rep& |
3441 | _S_empty_rep() _GLIBCXX_NOEXCEPT |
3442 | { return _Rep::_S_empty_rep(); } |
3443 | |
3444 | #if __cplusplus > 201402L |
3445 | |
3446 | typedef basic_string_view<_CharT, _Traits> __sv_type; |
3447 | |
3448 | template<typename _Tp, typename _Res> |
3449 | using _If_sv = enable_if_t< |
3450 | __and_<is_convertible<const _Tp&, __sv_type>, |
3451 | __not_<is_convertible<const _Tp*, const basic_string*>>, |
3452 | __not_<is_convertible<const _Tp&, const _CharT*>>>::value, |
3453 | _Res>; |
3454 | |
3455 | |
3456 | static __sv_type |
3457 | _S_to_string_view(__sv_type __svt) noexcept |
3458 | { return __svt; } |
3459 | |
3460 | |
3461 | |
3462 | |
3463 | |
3464 | struct __sv_wrapper |
3465 | { |
3466 | explicit __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { } |
3467 | __sv_type _M_sv; |
3468 | }; |
3469 | #endif |
3470 | |
3471 | public: |
3472 | |
3473 | |
3474 | |
3475 | |
3476 | |
3477 | |
3478 | |
3479 | basic_string() |
3480 | #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 |
3481 | : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { } |
3482 | #else |
3483 | : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()){ } |
3484 | #endif |
3485 | |
3486 | |
3487 | |
3488 | |
3489 | explicit |
3490 | basic_string(const _Alloc& __a); |
3491 | |
3492 | |
3493 | |
3494 | |
3495 | |
3496 | |
3497 | basic_string(const basic_string& __str); |
3498 | |
3499 | |
3500 | |
3501 | |
3502 | |
3503 | |
3504 | |
3505 | |
3506 | |
3507 | basic_string(const basic_string& __str, size_type __pos, |
3508 | const _Alloc& __a = _Alloc()); |
3509 | |
3510 | |
3511 | |
3512 | |
3513 | |
3514 | |
3515 | |
3516 | basic_string(const basic_string& __str, size_type __pos, |
3517 | size_type __n); |
3518 | |
3519 | |
3520 | |
3521 | |
3522 | |
3523 | |
3524 | |
3525 | basic_string(const basic_string& __str, size_type __pos, |
3526 | size_type __n, const _Alloc& __a); |
3527 | |
3528 | |
3529 | |
3530 | |
3531 | |
3532 | |
3533 | |
3534 | |
3535 | |
3536 | |
3537 | basic_string(const _CharT* __s, size_type __n, |
3538 | const _Alloc& __a = _Alloc()); |
3539 | |
3540 | |
3541 | |
3542 | |
3543 | |
3544 | basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()); |
3545 | |
3546 | |
3547 | |
3548 | |
3549 | |
3550 | |
3551 | basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()); |
3552 | |
3553 | #if __cplusplus >= 201103L |
3554 | |
3555 | |
3556 | |
3557 | |
3558 | |
3559 | |
3560 | |
3561 | basic_string(basic_string&& __str) |
3562 | #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 |
3563 | noexcept |
3564 | #endif |
3565 | : _M_dataplus(__str._M_dataplus) |
3566 | { |
3567 | #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 |
3568 | __str._M_data(_S_empty_rep()._M_refdata()); |
3569 | #else |
3570 | __str._M_data(_S_construct(size_type(), _CharT(), get_allocator())); |
3571 | #endif |
3572 | } |
3573 | |
3574 | |
3575 | |
3576 | |
3577 | |
3578 | |
3579 | basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc()); |
3580 | #endif |
3581 | |
3582 | |
3583 | |
3584 | |
3585 | |
3586 | |
3587 | |
3588 | template<class _InputIterator> |
3589 | basic_string(_InputIterator __beg, _InputIterator __end, |
3590 | const _Alloc& __a = _Alloc()); |
3591 | |
3592 | #if __cplusplus > 201402L |
3593 | |
3594 | |
3595 | |
3596 | |
3597 | |
3598 | |
3599 | |
3600 | template<typename _Tp, typename = _If_sv<_Tp, void>> |
3601 | basic_string(const _Tp& __t, size_type __pos, size_type __n, |
3602 | const _Alloc& __a = _Alloc()) |
3603 | : basic_string(_S_to_string_view(__t).substr(__pos, __n), __a) { } |
3604 | |
3605 | |
3606 | |
3607 | |
3608 | |
3609 | |
3610 | template<typename _Tp, typename = _If_sv<_Tp, void>> |
3611 | explicit |
3612 | basic_string(const _Tp& __t, const _Alloc& __a = _Alloc()) |
3613 | : basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { } |
3614 | |
3615 | |
3616 | |
3617 | |
3618 | |
3619 | |
3620 | |
3621 | explicit |
3622 | basic_string(__sv_wrapper __svw, const _Alloc& __a) |
3623 | : basic_string(__svw._M_sv.data(), __svw._M_sv.size(), __a) { } |
3624 | #endif |
3625 | |
3626 | |
3627 | |
3628 | |
3629 | ~basic_string() _GLIBCXX_NOEXCEPT |
3630 | { _M_rep()->_M_dispose(this->get_allocator()); } |
3631 | |
3632 | |
3633 | |
3634 | |
3635 | |
3636 | basic_string& |
3637 | operator=(const basic_string& __str) |
3638 | { return this->assign(__str); } |
3639 | |
3640 | |
3641 | |
3642 | |
3643 | |
3644 | basic_string& |
3645 | operator=(const _CharT* __s) |
3646 | { return this->assign(__s); } |
3647 | |
3648 | |
3649 | |
3650 | |
3651 | |
3652 | |
3653 | |
3654 | |
3655 | basic_string& |
3656 | operator=(_CharT __c) |
3657 | { |
3658 | this->assign(1, __c); |
3659 | return *this; |
3660 | } |
3661 | |
3662 | #if __cplusplus >= 201103L |
3663 | |
3664 | |
3665 | |
3666 | |
3667 | |
3668 | |
3669 | |
3670 | |
3671 | basic_string& |
3672 | operator=(basic_string&& __str) |
3673 | { |
3674 | |
3675 | this->swap(__str); |
3676 | return *this; |
3677 | } |
3678 | |
3679 | |
3680 | |
3681 | |
3682 | |
3683 | basic_string& |
3684 | operator=(initializer_list<_CharT> __l) |
3685 | { |
3686 | this->assign(__l.begin(), __l.size()); |
3687 | return *this; |
3688 | } |
3689 | #endif |
3690 | |
3691 | #if __cplusplus > 201402L |
3692 | |
3693 | |
3694 | |
3695 | |
3696 | template<typename _Tp> |
3697 | _If_sv<_Tp, basic_string&> |
3698 | operator=(const _Tp& __svt) |
3699 | { return this->assign(__svt); } |
3700 | |
3701 | |
3702 | |
3703 | |
3704 | |
3705 | operator __sv_type() const noexcept |
3706 | { return __sv_type(data(), size()); } |
3707 | #endif |
3708 | |
3709 | |
3710 | |
3711 | |
3712 | |
3713 | |
3714 | iterator |
3715 | begin() |
3716 | { |
3717 | _M_leak(); |
3718 | return iterator(_M_data()); |
3719 | } |
3720 | |
3721 | |
3722 | |
3723 | |
3724 | |
3725 | const_iterator |
3726 | begin() const _GLIBCXX_NOEXCEPT |
3727 | { return const_iterator(_M_data()); } |
3728 | |
3729 | |
3730 | |
3731 | |
3732 | |
3733 | iterator |
3734 | end() |
3735 | { |
3736 | _M_leak(); |
3737 | return iterator(_M_data() + this->size()); |
3738 | } |
3739 | |
3740 | |
3741 | |
3742 | |
3743 | |
3744 | const_iterator |
3745 | end() const _GLIBCXX_NOEXCEPT |
3746 | { return const_iterator(_M_data() + this->size()); } |
3747 | |
3748 | |
3749 | |
3750 | |
3751 | |
3752 | |
3753 | reverse_iterator |
3754 | rbegin() |
3755 | { return reverse_iterator(this->end()); } |
3756 | |
3757 | |
3758 | |
3759 | |
3760 | |
3761 | |
3762 | const_reverse_iterator |
3763 | rbegin() const _GLIBCXX_NOEXCEPT |
3764 | { return const_reverse_iterator(this->end()); } |
3765 | |
3766 | |
3767 | |
3768 | |
3769 | |
3770 | |
3771 | reverse_iterator |
3772 | rend() |
3773 | { return reverse_iterator(this->begin()); } |
3774 | |
3775 | |
3776 | |
3777 | |
3778 | |
3779 | |
3780 | const_reverse_iterator |
3781 | rend() const _GLIBCXX_NOEXCEPT |
3782 | { return const_reverse_iterator(this->begin()); } |
3783 | |
3784 | #if __cplusplus >= 201103L |
3785 | |
3786 | |
3787 | |
3788 | |
3789 | const_iterator |
3790 | cbegin() const noexcept |
3791 | { return const_iterator(this->_M_data()); } |
3792 | |
3793 | |
3794 | |
3795 | |
3796 | |
3797 | const_iterator |
3798 | cend() const noexcept |
3799 | { return const_iterator(this->_M_data() + this->size()); } |
3800 | |
3801 | |
3802 | |
3803 | |
3804 | |
3805 | |
3806 | const_reverse_iterator |
3807 | crbegin() const noexcept |
3808 | { return const_reverse_iterator(this->end()); } |
3809 | |
3810 | |
3811 | |
3812 | |
3813 | |
3814 | |
3815 | const_reverse_iterator |
3816 | crend() const noexcept |
3817 | { return const_reverse_iterator(this->begin()); } |
3818 | #endif |
3819 | |
3820 | public: |
3821 | |
3822 | |
3823 | |
3824 | size_type |
3825 | size() const _GLIBCXX_NOEXCEPT |
3826 | { return _M_rep()->_M_length; } |
3827 | |
3828 | |
3829 | |
3830 | size_type |
3831 | length() const _GLIBCXX_NOEXCEPT |
3832 | { return _M_rep()->_M_length; } |
3833 | |
3834 | |
3835 | size_type |
3836 | max_size() const _GLIBCXX_NOEXCEPT |
3837 | { return _Rep::_S_max_size; } |
3838 | |
3839 | |
3840 | |
3841 | |
3842 | |
3843 | |
3844 | |
3845 | |
3846 | |
3847 | |
3848 | |
3849 | void |
3850 | resize(size_type __n, _CharT __c); |
3851 | |
3852 | |
3853 | |
3854 | |
3855 | |
3856 | |
3857 | |
3858 | |
3859 | |
3860 | |
3861 | |
3862 | void |
3863 | resize(size_type __n) |
3864 | { this->resize(__n, _CharT()); } |
3865 | |
3866 | #if __cplusplus >= 201103L |
3867 | |
3868 | void |
3869 | shrink_to_fit() _GLIBCXX_NOEXCEPT |
3870 | { |
3871 | #if __cpp_exceptions |
3872 | if (capacity() > size()) |
3873 | { |
3874 | try |
3875 | { reserve(0); } |
3876 | catch(...) |
3877 | { } |
3878 | } |
3879 | #endif |
3880 | } |
3881 | #endif |
3882 | |
3883 | |
3884 | |
3885 | |
3886 | |
3887 | size_type |
3888 | capacity() const _GLIBCXX_NOEXCEPT |
3889 | { return _M_rep()->_M_capacity; } |
3890 | |
3891 | |
3892 | |
3893 | |
3894 | |
3895 | |
3896 | |
3897 | |
3898 | |
3899 | |
3900 | |
3901 | |
3902 | |
3903 | |
3904 | |
3905 | |
3906 | |
3907 | |
3908 | void |
3909 | reserve(size_type __res_arg = 0); |
3910 | |
3911 | |
3912 | |
3913 | |
3914 | #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 |
3915 | void |
3916 | clear() _GLIBCXX_NOEXCEPT |
3917 | { |
3918 | if (_M_rep()->_M_is_shared()) |
3919 | { |
3920 | _M_rep()->_M_dispose(this->get_allocator()); |
3921 | _M_data(_S_empty_rep()._M_refdata()); |
3922 | } |
3923 | else |
3924 | _M_rep()->_M_set_length_and_sharable(0); |
3925 | } |
3926 | #else |
3927 | |
3928 | void |
3929 | clear() |
3930 | { _M_mutate(0, this->size(), 0); } |
3931 | #endif |
3932 | |
3933 | |
3934 | |
3935 | |
3936 | |
3937 | bool |
3938 | empty() const _GLIBCXX_NOEXCEPT |
3939 | { return this->size() == 0; } |
3940 | |
3941 | |
3942 | |
3943 | |
3944 | |
3945 | |
3946 | |
3947 | |
3948 | |
3949 | |
3950 | |
3951 | |
3952 | const_reference |
3953 | operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT |
3954 | { |
3955 | __glibcxx_assert(__pos <= size()); |
3956 | return _M_data()[__pos]; |
3957 | } |
3958 | |
3959 | |
3960 | |
3961 | |
3962 | |
3963 | |
3964 | |
3965 | |
3966 | |
3967 | |
3968 | |
3969 | reference |
3970 | operator[](size_type __pos) |
3971 | { |
3972 | |
3973 | |
3974 | __glibcxx_assert(__pos <= size()); |
3975 | |
3976 | _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos < size()); |
3977 | _M_leak(); |
3978 | return _M_data()[__pos]; |
3979 | } |
3980 | |
3981 | |
3982 | |
3983 | |
3984 | |
3985 | |
3986 | |
3987 | |
3988 | |
3989 | |
3990 | |
3991 | const_reference |
3992 | at(size_type __n) const |
3993 | { |
3994 | if (__n >= this->size()) |
3995 | __throw_out_of_range_fmt(__N("basic_string::at: __n " |
3996 | "(which is %zu) >= this->size() " |
3997 | "(which is %zu)"), |
3998 | __n, this->size()); |
3999 | return _M_data()[__n]; |
4000 | } |
4001 | |
4002 | |
4003 | |
4004 | |
4005 | |
4006 | |
4007 | |
4008 | |
4009 | |
4010 | |
4011 | |
4012 | |
4013 | reference |
4014 | at(size_type __n) |
4015 | { |
4016 | if (__n >= size()) |
4017 | __throw_out_of_range_fmt(__N("basic_string::at: __n " |
4018 | "(which is %zu) >= this->size() " |
4019 | "(which is %zu)"), |
4020 | __n, this->size()); |
4021 | _M_leak(); |
4022 | return _M_data()[__n]; |
4023 | } |
4024 | |
4025 | #if __cplusplus >= 201103L |
4026 | |
4027 | |
4028 | |
4029 | |
4030 | reference |
4031 | front() |
4032 | { |
4033 | __glibcxx_assert(!empty()); |
4034 | return operator[](0); |
4035 | } |
4036 | |
4037 | |
4038 | |
4039 | |
4040 | |
4041 | const_reference |
4042 | front() const noexcept |
4043 | { |
4044 | __glibcxx_assert(!empty()); |
4045 | return operator[](0); |
4046 | } |
4047 | |
4048 | |
4049 | |
4050 | |
4051 | |
4052 | reference |
4053 | back() |
4054 | { |
4055 | __glibcxx_assert(!empty()); |
4056 | return operator[](this->size() - 1); |
4057 | } |
4058 | |
4059 | |
4060 | |
4061 | |
4062 | |
4063 | const_reference |
4064 | back() const noexcept |
4065 | { |
4066 | __glibcxx_assert(!empty()); |
4067 | return operator[](this->size() - 1); |
4068 | } |
4069 | #endif |
4070 | |
4071 | |
4072 | |
4073 | |
4074 | |
4075 | |
4076 | |
4077 | basic_string& |
4078 | operator+=(const basic_string& __str) |
4079 | { return this->append(__str); } |
4080 | |
4081 | |
4082 | |
4083 | |
4084 | |
4085 | |
4086 | basic_string& |
4087 | operator+=(const _CharT* __s) |
4088 | { return this->append(__s); } |
4089 | |
4090 | |
4091 | |
4092 | |
4093 | |
4094 | |
4095 | basic_string& |
4096 | operator+=(_CharT __c) |
4097 | { |
4098 | this->push_back(__c); |
4099 | return *this; |
4100 | } |
4101 | |
4102 | #if __cplusplus >= 201103L |
4103 | |
4104 | |
4105 | |
4106 | |
4107 | |
4108 | basic_string& |
4109 | operator+=(initializer_list<_CharT> __l) |
4110 | { return this->append(__l.begin(), __l.size()); } |
4111 | #endif |
4112 | |
4113 | #if __cplusplus > 201402L |
4114 | |
4115 | |
4116 | |
4117 | |
4118 | |
4119 | template<typename _Tp> |
4120 | _If_sv<_Tp, basic_string&> |
4121 | operator+=(const _Tp& __svt) |
4122 | { return this->append(__svt); } |
4123 | #endif |
4124 | |
4125 | |
4126 | |
4127 | |
4128 | |
4129 | |
4130 | basic_string& |
4131 | append(const basic_string& __str); |
4132 | |
4133 | |
4134 | |
4135 | |
4136 | |
4137 | |
4138 | |
4139 | |
4140 | |
4141 | |
4142 | |
4143 | |
4144 | |
4145 | |
4146 | basic_string& |
4147 | append(const basic_string& __str, size_type __pos, size_type __n = npos); |
4148 | |
4149 | |
4150 | |
4151 | |
4152 | |
4153 | |
4154 | |
4155 | basic_string& |
4156 | append(const _CharT* __s, size_type __n); |
4157 | |
4158 | |
4159 | |
4160 | |
4161 | |
4162 | |
4163 | basic_string& |
4164 | append(const _CharT* __s) |
4165 | { |
4166 | __glibcxx_requires_string(__s); |
4167 | return this->append(__s, traits_type::length(__s)); |
4168 | } |
4169 | |
4170 | |
4171 | |
4172 | |
4173 | |
4174 | |
4175 | |
4176 | |
4177 | |
4178 | basic_string& |
4179 | append(size_type __n, _CharT __c); |
4180 | |
4181 | #if __cplusplus >= 201103L |
4182 | |
4183 | |
4184 | |
4185 | |
4186 | |
4187 | basic_string& |
4188 | append(initializer_list<_CharT> __l) |
4189 | { return this->append(__l.begin(), __l.size()); } |
4190 | #endif |
4191 | |
4192 | |
4193 | |
4194 | |
4195 | |
4196 | |
4197 | |
4198 | |
4199 | |
4200 | template<class _InputIterator> |
4201 | basic_string& |
4202 | append(_InputIterator __first, _InputIterator __last) |
4203 | { return this->replace(_M_iend(), _M_iend(), __first, __last); } |
4204 | |
4205 | #if __cplusplus > 201402L |
4206 | |
4207 | |
4208 | |
4209 | |
4210 | |
4211 | template<typename _Tp> |
4212 | _If_sv<_Tp, basic_string&> |
4213 | append(const _Tp& __svt) |
4214 | { |
4215 | __sv_type __sv = __svt; |
4216 | return this->append(__sv.data(), __sv.size()); |
4217 | } |
4218 | |
4219 | |
4220 | |
4221 | |
4222 | |
4223 | |
4224 | |
4225 | |
4226 | |
4227 | template<typename _Tp> |
4228 | _If_sv<_Tp, basic_string&> |
4229 | append(const _Tp& __svt, size_type __pos, size_type __n = npos) |
4230 | { |
4231 | __sv_type __sv = __svt; |
4232 | return append(__sv.data() |
4233 | + __sv._M_check(__pos, "basic_string::append"), |
4234 | __sv._M_limit(__pos, __n)); |
4235 | } |
4236 | #endif |
4237 | |
4238 | |
4239 | |
4240 | |
4241 | |
4242 | void |
4243 | push_back(_CharT __c) |
4244 | { |
4245 | const size_type __len = 1 + this->size(); |
4246 | if (__len > this->capacity() || _M_rep()->_M_is_shared()) |
4247 | this->reserve(__len); |
4248 | traits_type::assign(_M_data()[this->size()], __c); |
4249 | _M_rep()->_M_set_length_and_sharable(__len); |
4250 | } |
4251 | |
4252 | |
4253 | |
4254 | |
4255 | |
4256 | |
4257 | basic_string& |
4258 | assign(const basic_string& __str); |
4259 | |
4260 | #if __cplusplus >= 201103L |
4261 | |
4262 | |
4263 | |
4264 | |
4265 | |
4266 | |
4267 | |
4268 | |
4269 | |
4270 | basic_string& |
4271 | assign(basic_string&& __str) |
4272 | { |
4273 | this->swap(__str); |
4274 | return *this; |
4275 | } |
4276 | #endif |
4277 | |
4278 | |
4279 | |
4280 | |
4281 | |
4282 | |
4283 | |
4284 | |
4285 | |
4286 | |
4287 | |
4288 | |
4289 | |
4290 | |
4291 | basic_string& |
4292 | assign(const basic_string& __str, size_type __pos, size_type __n = npos) |
4293 | { return this->assign(__str._M_data() |
4294 | + __str._M_check(__pos, "basic_string::assign"), |
4295 | __str._M_limit(__pos, __n)); } |
4296 | |
4297 | |
4298 | |
4299 | |
4300 | |
4301 | |
4302 | |
4303 | |
4304 | |
4305 | |
4306 | |
4307 | basic_string& |
4308 | assign(const _CharT* __s, size_type __n); |
4309 | |
4310 | |
4311 | |
4312 | |
4313 | |
4314 | |
4315 | |
4316 | |
4317 | |
4318 | |
4319 | basic_string& |
4320 | assign(const _CharT* __s) |
4321 | { |
4322 | __glibcxx_requires_string(__s); |
4323 | return this->assign(__s, traits_type::length(__s)); |
4324 | } |
4325 | |
4326 | |
4327 | |
4328 | |
4329 | |
4330 | |
4331 | |
4332 | |
4333 | |
4334 | |
4335 | basic_string& |
4336 | assign(size_type __n, _CharT __c) |
4337 | { return _M_replace_aux(size_type(0), this->size(), __n, __c); } |
4338 | |
4339 | |
4340 | |
4341 | |
4342 | |
4343 | |
4344 | |
4345 | |
4346 | |
4347 | template<class _InputIterator> |
4348 | basic_string& |
4349 | assign(_InputIterator __first, _InputIterator __last) |
4350 | { return this->replace(_M_ibegin(), _M_iend(), __first, __last); } |
4351 | |
4352 | #if __cplusplus >= 201103L |
4353 | |
4354 | |
4355 | |
4356 | |
4357 | |
4358 | basic_string& |
4359 | assign(initializer_list<_CharT> __l) |
4360 | { return this->assign(__l.begin(), __l.size()); } |
4361 | #endif |
4362 | |
4363 | #if __cplusplus > 201402L |
4364 | |
4365 | |
4366 | |
4367 | |
4368 | |
4369 | template<typename _Tp> |
4370 | _If_sv<_Tp, basic_string&> |
4371 | assign(const _Tp& __svt) |
4372 | { |
4373 | __sv_type __sv = __svt; |
4374 | return this->assign(__sv.data(), __sv.size()); |
4375 | } |
4376 | |
4377 | |
4378 | |
4379 | |
4380 | |
4381 | |
4382 | |
4383 | |
4384 | template<typename _Tp> |
4385 | _If_sv<_Tp, basic_string&> |
4386 | assign(const _Tp& __svt, size_type __pos, size_type __n = npos) |
4387 | { |
4388 | __sv_type __sv = __svt; |
4389 | return assign(__sv.data() |
4390 | + __sv._M_check(__pos, "basic_string::assign"), |
4391 | __sv._M_limit(__pos, __n)); |
4392 | } |
4393 | #endif |
4394 | |
4395 | |
4396 | |
4397 | |
4398 | |
4399 | |
4400 | |
4401 | |
4402 | |
4403 | |
4404 | |
4405 | |
4406 | |
4407 | |
4408 | void |
4409 | insert(iterator __p, size_type __n, _CharT __c) |
4410 | { this->replace(__p, __p, __n, __c); } |
4411 | |
4412 | |
4413 | |
4414 | |
4415 | |
4416 | |
4417 | |
4418 | |
4419 | |
4420 | |
4421 | |
4422 | |
4423 | |
4424 | template<class _InputIterator> |
4425 | void |
4426 | insert(iterator __p, _InputIterator __beg, _InputIterator __end) |
4427 | { this->replace(__p, __p, __beg, __end); } |
4428 | |
4429 | #if __cplusplus >= 201103L |
4430 | |
4431 | |
4432 | |
4433 | |
4434 | |
4435 | |
4436 | void |
4437 | insert(iterator __p, initializer_list<_CharT> __l) |
4438 | { |
4439 | _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); |
4440 | this->insert(__p - _M_ibegin(), __l.begin(), __l.size()); |
4441 | } |
4442 | #endif |
4443 | |
4444 | |
4445 | |
4446 | |
4447 | |
4448 | |
4449 | |
4450 | |
4451 | |
4452 | |
4453 | |
4454 | |
4455 | |
4456 | basic_string& |
4457 | insert(size_type __pos1, const basic_string& __str) |
4458 | { return this->insert(__pos1, __str, size_type(0), __str.size()); } |
4459 | |
4460 | |
4461 | |
4462 | |
4463 | |
4464 | |
4465 | |
4466 | |
4467 | |
4468 | |
4469 | |
4470 | |
4471 | |
4472 | |
4473 | |
4474 | |
4475 | |
4476 | |
4477 | |
4478 | basic_string& |
4479 | insert(size_type __pos1, const basic_string& __str, |
4480 | size_type __pos2, size_type __n = npos) |
4481 | { return this->insert(__pos1, __str._M_data() |
4482 | + __str._M_check(__pos2, "basic_string::insert"), |
4483 | __str._M_limit(__pos2, __n)); } |
4484 | |
4485 | |
4486 | |
4487 | |
4488 | |
4489 | |
4490 | |
4491 | |
4492 | |
4493 | |
4494 | |
4495 | |
4496 | |
4497 | |
4498 | |
4499 | |
4500 | |
4501 | basic_string& |
4502 | insert(size_type __pos, const _CharT* __s, size_type __n); |
4503 | |
4504 | |
4505 | |
4506 | |
4507 | |
4508 | |
4509 | |
4510 | |
4511 | |
4512 | |
4513 | |
4514 | |
4515 | |
4516 | |
4517 | |
4518 | |
4519 | basic_string& |
4520 | insert(size_type __pos, const _CharT* __s) |
4521 | { |
4522 | __glibcxx_requires_string(__s); |
4523 | return this->insert(__pos, __s, traits_type::length(__s)); |
4524 | } |
4525 | |
4526 | |
4527 | |
4528 | |
4529 | |
4530 | |
4531 | |
4532 | |
4533 | |
4534 | |
4535 | |
4536 | |
4537 | |
4538 | |
4539 | |
4540 | |
4541 | |
4542 | basic_string& |
4543 | insert(size_type __pos, size_type __n, _CharT __c) |
4544 | { return _M_replace_aux(_M_check(__pos, "basic_string::insert"), |
4545 | size_type(0), __n, __c); } |
4546 | |
4547 | |
4548 | |
4549 | |
4550 | |
4551 | |
4552 | |
4553 | |
4554 | |
4555 | |
4556 | |
4557 | |
4558 | |
4559 | |
4560 | iterator |
4561 | insert(iterator __p, _CharT __c) |
4562 | { |
4563 | _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); |
4564 | const size_type __pos = __p - _M_ibegin(); |
4565 | _M_replace_aux(__pos, size_type(0), size_type(1), __c); |
4566 | _M_rep()->_M_set_leaked(); |
4567 | return iterator(_M_data() + __pos); |
4568 | } |
4569 | |
4570 | #if __cplusplus > 201402L |
4571 | |
4572 | |
4573 | |
4574 | |
4575 | |
4576 | |
4577 | template<typename _Tp> |
4578 | _If_sv<_Tp, basic_string&> |
4579 | insert(size_type __pos, const _Tp& __svt) |
4580 | { |
4581 | __sv_type __sv = __svt; |
4582 | return this->insert(__pos, __sv.data(), __sv.size()); |
4583 | } |
4584 | |
4585 | |
4586 | |
4587 | |
4588 | |
4589 | |
4590 | |
4591 | |
4592 | |
4593 | |
4594 | template<typename _Tp> |
4595 | _If_sv<_Tp, basic_string&> |
4596 | insert(size_type __pos1, const _Tp& __svt, |
4597 | size_type __pos2, size_type __n = npos) |
4598 | { |
4599 | __sv_type __sv = __svt; |
4600 | return this->replace(__pos1, size_type(0), __sv.data() |
4601 | + __sv._M_check(__pos2, "basic_string::insert"), |
4602 | __sv._M_limit(__pos2, __n)); |
4603 | } |
4604 | #endif |
4605 | |
4606 | |
4607 | |
4608 | |
4609 | |
4610 | |
4611 | |
4612 | |
4613 | |
4614 | |
4615 | |
4616 | |
4617 | |
4618 | |
4619 | |
4620 | |
4621 | basic_string& |
4622 | erase(size_type __pos = 0, size_type __n = npos) |
4623 | { |
4624 | _M_mutate(_M_check(__pos, "basic_string::erase"), |
4625 | _M_limit(__pos, __n), size_type(0)); |
4626 | return *this; |
4627 | } |
4628 | |
4629 | |
4630 | |
4631 | |
4632 | |
4633 | |
4634 | |
4635 | |
4636 | |
4637 | iterator |
4638 | erase(iterator __position) |
4639 | { |
4640 | _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin() |
4641 | && __position < _M_iend()); |
4642 | const size_type __pos = __position - _M_ibegin(); |
4643 | _M_mutate(__pos, size_type(1), size_type(0)); |
4644 | _M_rep()->_M_set_leaked(); |
4645 | return iterator(_M_data() + __pos); |
4646 | } |
4647 | |
4648 | |
4649 | |
4650 | |
4651 | |
4652 | |
4653 | |
4654 | |
4655 | |
4656 | |
4657 | iterator |
4658 | erase(iterator __first, iterator __last); |
4659 | |
4660 | #if __cplusplus >= 201103L |
4661 | |
4662 | |
4663 | |
4664 | |
4665 | |
4666 | void |
4667 | pop_back() |
4668 | { |
4669 | __glibcxx_assert(!empty()); |
4670 | erase(size() - 1, 1); |
4671 | } |
4672 | #endif |
4673 | |
4674 | |
4675 | |
4676 | |
4677 | |
4678 | |
4679 | |
4680 | |
4681 | |
4682 | |
4683 | |
4684 | |
4685 | |
4686 | |
4687 | |
4688 | |
4689 | |
4690 | |
4691 | basic_string& |
4692 | replace(size_type __pos, size_type __n, const basic_string& __str) |
4693 | { return this->replace(__pos, __n, __str._M_data(), __str.size()); } |
4694 | |
4695 | |
4696 | |
4697 | |
4698 | |
4699 | |
4700 | |
4701 | |
4702 | |
4703 | |
4704 | |
4705 | |
4706 | |
4707 | |
4708 | |
4709 | |
4710 | |
4711 | |
4712 | |
4713 | basic_string& |
4714 | replace(size_type __pos1, size_type __n1, const basic_string& __str, |
4715 | size_type __pos2, size_type __n2 = npos) |
4716 | { return this->replace(__pos1, __n1, __str._M_data() |
4717 | + __str._M_check(__pos2, "basic_string::replace"), |
4718 | __str._M_limit(__pos2, __n2)); } |
4719 | |
4720 | |
4721 | |
4722 | |
4723 | |
4724 | |
4725 | |
4726 | |
4727 | |
4728 | |
4729 | |
4730 | |
4731 | |
4732 | |
4733 | |
4734 | |
4735 | |
4736 | |
4737 | |
4738 | basic_string& |
4739 | replace(size_type __pos, size_type __n1, const _CharT* __s, |
4740 | size_type __n2); |
4741 | |
4742 | |
4743 | |
4744 | |
4745 | |
4746 | |
4747 | |
4748 | |
4749 | |
4750 | |
4751 | |
4752 | |
4753 | |
4754 | |
4755 | |
4756 | |
4757 | |
4758 | basic_string& |
4759 | replace(size_type __pos, size_type __n1, const _CharT* __s) |
4760 | { |
4761 | __glibcxx_requires_string(__s); |
4762 | return this->replace(__pos, __n1, __s, traits_type::length(__s)); |
4763 | } |
4764 | |
4765 | |
4766 | |
4767 | |
4768 | |
4769 | |
4770 | |
4771 | |
4772 | |
4773 | |
4774 | |
4775 | |
4776 | |
4777 | |
4778 | |
4779 | |
4780 | |
4781 | |
4782 | basic_string& |
4783 | replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) |
4784 | { return _M_replace_aux(_M_check(__pos, "basic_string::replace"), |
4785 | _M_limit(__pos, __n1), __n2, __c); } |
4786 | |
4787 | |
4788 | |
4789 | |
4790 | |
4791 | |
4792 | |
4793 | |
4794 | |
4795 | |
4796 | |
4797 | |
4798 | |
4799 | |
4800 | basic_string& |
4801 | replace(iterator __i1, iterator __i2, const basic_string& __str) |
4802 | { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } |
4803 | |
4804 | |
4805 | |
4806 | |
4807 | |
4808 | |
4809 | |
4810 | |
4811 | |
4812 | |
4813 | |
4814 | |
4815 | |
4816 | |
4817 | |
4818 | |
4819 | basic_string& |
4820 | replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) |
4821 | { |
4822 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 |
4823 | && __i2 <= _M_iend()); |
4824 | return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n); |
4825 | } |
4826 | |
4827 | |
4828 | |
4829 | |
4830 | |
4831 | |
4832 | |
4833 | |
4834 | |
4835 | |
4836 | |
4837 | |
4838 | |
4839 | |
4840 | basic_string& |
4841 | replace(iterator __i1, iterator __i2, const _CharT* __s) |
4842 | { |
4843 | __glibcxx_requires_string(__s); |
4844 | return this->replace(__i1, __i2, __s, traits_type::length(__s)); |
4845 | } |
4846 | |
4847 | |
4848 | |
4849 | |
4850 | |
4851 | |
4852 | |
4853 | |
4854 | |
4855 | |
4856 | |
4857 | |
4858 | |
4859 | |
4860 | |
4861 | basic_string& |
4862 | replace(iterator __i1, iterator __i2, size_type __n, _CharT __c) |
4863 | { |
4864 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 |
4865 | && __i2 <= _M_iend()); |
4866 | return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c); |
4867 | } |
4868 | |
4869 | |
4870 | |
4871 | |
4872 | |
4873 | |
4874 | |
4875 | |
4876 | |
4877 | |
4878 | |
4879 | |
4880 | |
4881 | |
4882 | |
4883 | |
4884 | template<class _InputIterator> |
4885 | basic_string& |
4886 | replace(iterator __i1, iterator __i2, |
4887 | _InputIterator __k1, _InputIterator __k2) |
4888 | { |
4889 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 |
4890 | && __i2 <= _M_iend()); |
4891 | __glibcxx_requires_valid_range(__k1, __k2); |
4892 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; |
4893 | return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); |
4894 | } |
4895 | |
4896 | |
4897 | |
4898 | basic_string& |
4899 | replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2) |
4900 | { |
4901 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 |
4902 | && __i2 <= _M_iend()); |
4903 | __glibcxx_requires_valid_range(__k1, __k2); |
4904 | return this->replace(__i1 - _M_ibegin(), __i2 - __i1, |
4905 | __k1, __k2 - __k1); |
4906 | } |
4907 | |
4908 | basic_string& |
4909 | replace(iterator __i1, iterator __i2, |
4910 | const _CharT* __k1, const _CharT* __k2) |
4911 | { |
4912 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 |
4913 | && __i2 <= _M_iend()); |
4914 | __glibcxx_requires_valid_range(__k1, __k2); |
4915 | return this->replace(__i1 - _M_ibegin(), __i2 - __i1, |
4916 | __k1, __k2 - __k1); |
4917 | } |
4918 | |
4919 | basic_string& |
4920 | replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2) |
4921 | { |
4922 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 |
4923 | && __i2 <= _M_iend()); |
4924 | __glibcxx_requires_valid_range(__k1, __k2); |
4925 | return this->replace(__i1 - _M_ibegin(), __i2 - __i1, |
4926 | __k1.base(), __k2 - __k1); |
4927 | } |
4928 | |
4929 | basic_string& |
4930 | replace(iterator __i1, iterator __i2, |
4931 | const_iterator __k1, const_iterator __k2) |
4932 | { |
4933 | _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 |
4934 | && __i2 <= _M_iend()); |
4935 | __glibcxx_requires_valid_range(__k1, __k2); |
4936 | return this->replace(__i1 - _M_ibegin(), __i2 - __i1, |
4937 | __k1.base(), __k2 - __k1); |
4938 | } |
4939 | |
4940 | #if __cplusplus >= 201103L |
4941 | |
4942 | |
4943 | |
4944 | |
4945 | |
4946 | |
4947 | |
4948 | |
4949 | |
4950 | |
4951 | |
4952 | |
4953 | |
4954 | |
4955 | basic_string& replace(iterator __i1, iterator __i2, |
4956 | initializer_list<_CharT> __l) |
4957 | { return this->replace(__i1, __i2, __l.begin(), __l.end()); } |
4958 | #endif |
4959 | |
4960 | #if __cplusplus > 201402L |
4961 | |
4962 | |
4963 | |
4964 | |
4965 | |
4966 | |
4967 | |
4968 | template<typename _Tp> |
4969 | _If_sv<_Tp, basic_string&> |
4970 | replace(size_type __pos, size_type __n, const _Tp& __svt) |
4971 | { |
4972 | __sv_type __sv = __svt; |
4973 | return this->replace(__pos, __n, __sv.data(), __sv.size()); |
4974 | } |
4975 | |
4976 | |
4977 | |
4978 | |
4979 | |
4980 | |
4981 | |
4982 | |
4983 | |
4984 | |
4985 | template<typename _Tp> |
4986 | _If_sv<_Tp, basic_string&> |
4987 | replace(size_type __pos1, size_type __n1, const _Tp& __svt, |
4988 | size_type __pos2, size_type __n2 = npos) |
4989 | { |
4990 | __sv_type __sv = __svt; |
4991 | return this->replace(__pos1, __n1, |
4992 | __sv.data() + __sv._M_check(__pos2, "basic_string::replace"), |
4993 | __sv._M_limit(__pos2, __n2)); |
4994 | } |
4995 | |
4996 | |
4997 | |
4998 | |
4999 | |
5000 | |
5001 | |
5002 | |
5003 | |
5004 | |
5005 | template<typename _Tp> |
5006 | _If_sv<_Tp, basic_string&> |
5007 | replace(const_iterator __i1, const_iterator __i2, const _Tp& __svt) |
5008 | { |
5009 | __sv_type __sv = __svt; |
5010 | return this->replace(__i1 - begin(), __i2 - __i1, __sv); |
5011 | } |
5012 | #endif |
5013 | |
5014 | private: |
5015 | template<class _Integer> |
5016 | basic_string& |
5017 | _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n, |
5018 | _Integer __val, __true_type) |
5019 | { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); } |
5020 | |
5021 | template<class _InputIterator> |
5022 | basic_string& |
5023 | _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1, |
5024 | _InputIterator __k2, __false_type); |
5025 | |
5026 | basic_string& |
5027 | _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, |
5028 | _CharT __c); |
5029 | |
5030 | basic_string& |
5031 | _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s, |
5032 | size_type __n2); |
5033 | |
5034 | |
5035 | |
5036 | template<class _InIterator> |
5037 | static _CharT* |
5038 | _S_construct_aux(_InIterator __beg, _InIterator __end, |
5039 | const _Alloc& __a, __false_type) |
5040 | { |
5041 | typedef typename iterator_traits<_InIterator>::iterator_category _Tag; |
5042 | return _S_construct(__beg, __end, __a, _Tag()); |
5043 | } |
5044 | |
5045 | |
5046 | |
5047 | template<class _Integer> |
5048 | static _CharT* |
5049 | _S_construct_aux(_Integer __beg, _Integer __end, |
5050 | const _Alloc& __a, __true_type) |
5051 | { return _S_construct_aux_2(static_cast<size_type>(__beg), |
5052 | __end, __a); } |
5053 | |
5054 | static _CharT* |
5055 | _S_construct_aux_2(size_type __req, _CharT __c, const _Alloc& __a) |
5056 | { return _S_construct(__req, __c, __a); } |
5057 | |
5058 | template<class _InIterator> |
5059 | static _CharT* |
5060 | _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a) |
5061 | { |
5062 | typedef typename std::__is_integer<_InIterator>::__type _Integral; |
5063 | return _S_construct_aux(__beg, __end, __a, _Integral()); |
5064 | } |
5065 | |
5066 | |
5067 | template<class _InIterator> |
5068 | static _CharT* |
5069 | _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, |
5070 | input_iterator_tag); |
5071 | |
5072 | |
5073 | |
5074 | template<class _FwdIterator> |
5075 | static _CharT* |
5076 | _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a, |
5077 | forward_iterator_tag); |
5078 | |
5079 | static _CharT* |
5080 | _S_construct(size_type __req, _CharT __c, const _Alloc& __a); |
5081 | |
5082 | public: |
5083 | |
5084 | |
5085 | |
5086 | |
5087 | |
5088 | |
5089 | |
5090 | |
5091 | |
5092 | |
5093 | |
5094 | |
5095 | |
5096 | size_type |
5097 | copy(_CharT* __s, size_type __n, size_type __pos = 0) const; |
5098 | |
5099 | |
5100 | |
5101 | |
5102 | |
5103 | |
5104 | |
5105 | |
5106 | |
5107 | void |
5108 | swap(basic_string& __s); |
5109 | |
5110 | |
5111 | |
5112 | |
5113 | |
5114 | |
5115 | |
5116 | |
5117 | const _CharT* |
5118 | c_str() const _GLIBCXX_NOEXCEPT |
5119 | { return _M_data(); } |
5120 | |
5121 | |
5122 | |
5123 | |
5124 | |
5125 | |
5126 | |
5127 | |
5128 | |
5129 | const _CharT* |
5130 | data() const _GLIBCXX_NOEXCEPT |
5131 | { return _M_data(); } |
5132 | |
5133 | #if __cplusplus > 201402L |
5134 | |
5135 | |
5136 | |
5137 | |
5138 | |
5139 | |
5140 | _CharT* |
5141 | data() noexcept |
5142 | { |
5143 | _M_leak(); |
5144 | return _M_data(); |
5145 | } |
5146 | #endif |
5147 | |
5148 | |
5149 | |
5150 | |
5151 | allocator_type |
5152 | get_allocator() const _GLIBCXX_NOEXCEPT |
5153 | { return _M_dataplus; } |
5154 | |
5155 | |
5156 | |
5157 | |
5158 | |
5159 | |
5160 | |
5161 | |
5162 | |
5163 | |
5164 | |
5165 | |
5166 | |
5167 | size_type |
5168 | find(const _CharT* __s, size_type __pos, size_type __n) const |
5169 | _GLIBCXX_NOEXCEPT; |
5170 | |
5171 | |
5172 | |
5173 | |
5174 | |
5175 | |
5176 | |
5177 | |
5178 | |
5179 | |
5180 | |
5181 | size_type |
5182 | find(const basic_string& __str, size_type __pos = 0) const |
5183 | _GLIBCXX_NOEXCEPT |
5184 | { return this->find(__str.data(), __pos, __str.size()); } |
5185 | |
5186 | |
5187 | |
5188 | |
5189 | |
5190 | |
5191 | |
5192 | |
5193 | |
5194 | |
5195 | |
5196 | size_type |
5197 | find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT |
5198 | { |
5199 | __glibcxx_requires_string(__s); |
5200 | return this->find(__s, __pos, traits_type::length(__s)); |
5201 | } |
5202 | |
5203 | |
5204 | |
5205 | |
5206 | |
5207 | |
5208 | |
5209 | |
5210 | |
5211 | |
5212 | |
5213 | size_type |
5214 | find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT; |
5215 | |
5216 | #if __cplusplus > 201402L |
5217 | |
5218 | |
5219 | |
5220 | |
5221 | |
5222 | |
5223 | template<typename _Tp> |
5224 | _If_sv<_Tp, size_type> |
5225 | find(const _Tp& __svt, size_type __pos = 0) const |
5226 | noexcept(is_same<_Tp, __sv_type>::value) |
5227 | { |
5228 | __sv_type __sv = __svt; |
5229 | return this->find(__sv.data(), __pos, __sv.size()); |
5230 | } |
5231 | #endif |
5232 | |
5233 | |
5234 | |
5235 | |
5236 | |
5237 | |
5238 | |
5239 | |
5240 | |
5241 | |
5242 | |
5243 | size_type |
5244 | rfind(const basic_string& __str, size_type __pos = npos) const |
5245 | _GLIBCXX_NOEXCEPT |
5246 | { return this->rfind(__str.data(), __pos, __str.size()); } |
5247 | |
5248 | |
5249 | |
5250 | |
5251 | |
5252 | |
5253 | |
5254 | |
5255 | |
5256 | |
5257 | |
5258 | |
5259 | |
5260 | size_type |
5261 | rfind(const _CharT* __s, size_type __pos, size_type __n) const |
5262 | _GLIBCXX_NOEXCEPT; |
5263 | |
5264 | |
5265 | |
5266 | |
5267 | |
5268 | |
5269 | |
5270 | |
5271 | |
5272 | |
5273 | |
5274 | size_type |
5275 | rfind(const _CharT* __s, size_type __pos = npos) const _GLIBCXX_NOEXCEPT |
5276 | { |
5277 | __glibcxx_requires_string(__s); |
5278 | return this->rfind(__s, __pos, traits_type::length(__s)); |
5279 | } |
5280 | |
5281 | |
5282 | |
5283 | |
5284 | |
5285 | |
5286 | |
5287 | |
5288 | |
5289 | |
5290 | |
5291 | size_type |
5292 | rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT; |
5293 | |
5294 | #if __cplusplus > 201402L |
5295 | |
5296 | |
5297 | |
5298 | |
5299 | |
5300 | |
5301 | template<typename _Tp> |
5302 | _If_sv<_Tp, size_type> |
5303 | rfind(const _Tp& __svt, size_type __pos = npos) const |
5304 | noexcept(is_same<_Tp, __sv_type>::value) |
5305 | { |
5306 | __sv_type __sv = __svt; |
5307 | return this->rfind(__sv.data(), __pos, __sv.size()); |
5308 | } |
5309 | #endif |
5310 | |
5311 | |
5312 | |
5313 | |
5314 | |
5315 | |
5316 | |
5317 | |
5318 | |
5319 | |
5320 | |
5321 | |
5322 | size_type |
5323 | find_first_of(const basic_string& __str, size_type __pos = 0) const |
5324 | _GLIBCXX_NOEXCEPT |
5325 | { return this->find_first_of(__str.data(), __pos, __str.size()); } |
5326 | |
5327 | |
5328 | |
5329 | |
5330 | |
5331 | |
5332 | |
5333 | |
5334 | |
5335 | |
5336 | |
5337 | |
5338 | |
5339 | size_type |
5340 | find_first_of(const _CharT* __s, size_type __pos, size_type __n) const |
5341 | _GLIBCXX_NOEXCEPT; |
5342 | |
5343 | |
5344 | |
5345 | |
5346 | |
5347 | |
5348 | |
5349 | |
5350 | |
5351 | |
5352 | |
5353 | size_type |
5354 | find_first_of(const _CharT* __s, size_type __pos = 0) const |
5355 | _GLIBCXX_NOEXCEPT |
5356 | { |
5357 | __glibcxx_requires_string(__s); |
5358 | return this->find_first_of(__s, __pos, traits_type::length(__s)); |
5359 | } |
5360 | |
5361 | |
5362 | |
5363 | |
5364 | |
5365 | |
5366 | |
5367 | |
5368 | |
5369 | |
5370 | |
5371 | |
5372 | |
5373 | size_type |
5374 | find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT |
5375 | { return this->find(__c, __pos); } |
5376 | |
5377 | #if __cplusplus > 201402L |
5378 | |
5379 | |
5380 | |
5381 | |
5382 | |
5383 | |
5384 | |
5385 | template<typename _Tp> |
5386 | _If_sv<_Tp, size_type> |
5387 | find_first_of(const _Tp& __svt, size_type __pos = 0) const |
5388 | noexcept(is_same<_Tp, __sv_type>::value) |
5389 | { |
5390 | __sv_type __sv = __svt; |
5391 | return this->find_first_of(__sv.data(), __pos, __sv.size()); |
5392 | } |
5393 | #endif |
5394 | |
5395 | |
5396 | |
5397 | |
5398 | |
5399 | |
5400 | |
5401 | |
5402 | |
5403 | |
5404 | |
5405 | |
5406 | size_type |
5407 | find_last_of(const basic_string& __str, size_type __pos = npos) const |
5408 | _GLIBCXX_NOEXCEPT |
5409 | { return this->find_last_of(__str.data(), __pos, __str.size()); } |
5410 | |
5411 | |
5412 | |
5413 | |
5414 | |
5415 | |
5416 | |
5417 | |
5418 | |
5419 | |
5420 | |
5421 | |
5422 | |
5423 | size_type |
5424 | find_last_of(const _CharT* __s, size_type __pos, size_type __n) const |
5425 | _GLIBCXX_NOEXCEPT; |
5426 | |
5427 | |
5428 | |
5429 | |
5430 | |
5431 | |
5432 | |
5433 | |
5434 | |
5435 | |
5436 | |
5437 | size_type |
5438 | find_last_of(const _CharT* __s, size_type __pos = npos) const |
5439 | _GLIBCXX_NOEXCEPT |
5440 | { |
5441 | __glibcxx_requires_string(__s); |
5442 | return this->find_last_of(__s, __pos, traits_type::length(__s)); |
5443 | } |
5444 | |
5445 | |
5446 | |
5447 | |
5448 | |
5449 | |
5450 | |
5451 | |
5452 | |
5453 | |
5454 | |
5455 | |
5456 | |
5457 | size_type |
5458 | find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT |
5459 | { return this->rfind(__c, __pos); } |
5460 | |
5461 | #if __cplusplus > 201402L |
5462 | |
5463 | |
5464 | |
5465 | |
5466 | |
5467 | |
5468 | |
5469 | template<typename _Tp> |
5470 | _If_sv<_Tp, size_type> |
5471 | find_last_of(const _Tp& __svt, size_type __pos = npos) const |
5472 | noexcept(is_same<_Tp, __sv_type>::value) |
5473 | { |
5474 | __sv_type __sv = __svt; |
5475 | return this->find_last_of(__sv.data(), __pos, __sv.size()); |
5476 | } |
5477 | #endif |
5478 | |
5479 | |
5480 | |
5481 | |
5482 | |
5483 | |
5484 | |
5485 | |
5486 | |
5487 | |
5488 | |
5489 | size_type |
5490 | find_first_not_of(const basic_string& __str, size_type __pos = 0) const |
5491 | _GLIBCXX_NOEXCEPT |
5492 | { return this->find_first_not_of(__str.data(), __pos, __str.size()); } |
5493 | |
5494 | |
5495 | |
5496 | |
5497 | |
5498 | |
5499 | |
5500 | |
5501 | |
5502 | |
5503 | |
5504 | |
5505 | |
5506 | size_type |
5507 | find_first_not_of(const _CharT* __s, size_type __pos, |
5508 | size_type __n) const _GLIBCXX_NOEXCEPT; |
5509 | |
5510 | |
5511 | |
5512 | |
5513 | |
5514 | |
5515 | |
5516 | |
5517 | |
5518 | |
5519 | |
5520 | size_type |
5521 | find_first_not_of(const _CharT* __s, size_type __pos = 0) const |
5522 | _GLIBCXX_NOEXCEPT |
5523 | { |
5524 | __glibcxx_requires_string(__s); |
5525 | return this->find_first_not_of(__s, __pos, traits_type::length(__s)); |
5526 | } |
5527 | |
5528 | |
5529 | |
5530 | |
5531 | |
5532 | |
5533 | |
5534 | |
5535 | |
5536 | |
5537 | |
5538 | size_type |
5539 | find_first_not_of(_CharT __c, size_type __pos = 0) const |
5540 | _GLIBCXX_NOEXCEPT; |
5541 | |
5542 | #if __cplusplus > 201402L |
5543 | |
5544 | |
5545 | |
5546 | |
5547 | |
5548 | |
5549 | |
5550 | template<typename _Tp> |
5551 | _If_sv<_Tp, size_type> |
5552 | find_first_not_of(const _Tp& __svt, size_type __pos = 0) const |
5553 | noexcept(is_same<_Tp, __sv_type>::value) |
5554 | { |
5555 | __sv_type __sv = __svt; |
5556 | return this->find_first_not_of(__sv.data(), __pos, __sv.size()); |
5557 | } |
5558 | #endif |
5559 | |
5560 | |
5561 | |
5562 | |
5563 | |
5564 | |
5565 | |
5566 | |
5567 | |
5568 | |
5569 | |
5570 | |
5571 | size_type |
5572 | find_last_not_of(const basic_string& __str, size_type __pos = npos) const |
5573 | _GLIBCXX_NOEXCEPT |
5574 | { return this->find_last_not_of(__str.data(), __pos, __str.size()); } |
5575 | |
5576 | |
5577 | |
5578 | |
5579 | |
5580 | |
5581 | |
5582 | |
5583 | |
5584 | |
5585 | |
5586 | |
5587 | |
5588 | size_type |
5589 | find_last_not_of(const _CharT* __s, size_type __pos, |
5590 | size_type __n) const _GLIBCXX_NOEXCEPT; |
5591 | |
5592 | |
5593 | |
5594 | |
5595 | |
5596 | |
5597 | |
5598 | |
5599 | |
5600 | |
5601 | |
5602 | size_type |
5603 | find_last_not_of(const _CharT* __s, size_type __pos = npos) const |
5604 | _GLIBCXX_NOEXCEPT |
5605 | { |
5606 | __glibcxx_requires_string(__s); |
5607 | return this->find_last_not_of(__s, __pos, traits_type::length(__s)); |
5608 | } |
5609 | |
5610 | |
5611 | |
5612 | |
5613 | |
5614 | |
5615 | |
5616 | |
5617 | |
5618 | |
5619 | |
5620 | size_type |
5621 | find_last_not_of(_CharT __c, size_type __pos = npos) const |
5622 | _GLIBCXX_NOEXCEPT; |
5623 | |
5624 | #if __cplusplus > 201402L |
5625 | |
5626 | |
5627 | |
5628 | |
5629 | |
5630 | |
5631 | |
5632 | template<typename _Tp> |
5633 | _If_sv<_Tp, size_type> |
5634 | find_last_not_of(const _Tp& __svt, size_type __pos = npos) const |
5635 | noexcept(is_same<_Tp, __sv_type>::value) |
5636 | { |
5637 | __sv_type __sv = __svt; |
5638 | return this->find_last_not_of(__sv.data(), __pos, __sv.size()); |
5639 | } |
5640 | #endif |
5641 | |
5642 | |
5643 | |
5644 | |
5645 | |
5646 | |
5647 | |
5648 | |
5649 | |
5650 | |
5651 | |
5652 | |
5653 | |
5654 | basic_string |
5655 | substr(size_type __pos = 0, size_type __n = npos) const |
5656 | { return basic_string(*this, |
5657 | _M_check(__pos, "basic_string::substr"), __n); } |
5658 | |
5659 | |
5660 | |
5661 | |
5662 | |
5663 | |
5664 | |
5665 | |
5666 | |
5667 | |
5668 | |
5669 | |
5670 | |
5671 | |
5672 | |
5673 | int |
5674 | compare(const basic_string& __str) const |
5675 | { |
5676 | const size_type __size = this->size(); |
5677 | const size_type __osize = __str.size(); |
5678 | const size_type __len = std::min(__size, __osize); |
5679 | |
5680 | int __r = traits_type::compare(_M_data(), __str.data(), __len); |
5681 | if (!__r) |
5682 | __r = _S_compare(__size, __osize); |
5683 | return __r; |
5684 | } |
5685 | |
5686 | #if __cplusplus > 201402L |
5687 | |
5688 | |
5689 | |
5690 | |
5691 | |
5692 | template<typename _Tp> |
5693 | _If_sv<_Tp, int> |
5694 | compare(const _Tp& __svt) const |
5695 | noexcept(is_same<_Tp, __sv_type>::value) |
5696 | { |
5697 | __sv_type __sv = __svt; |
5698 | const size_type __size = this->size(); |
5699 | const size_type __osize = __sv.size(); |
5700 | const size_type __len = std::min(__size, __osize); |
5701 | |
5702 | int __r = traits_type::compare(_M_data(), __sv.data(), __len); |
5703 | if (!__r) |
5704 | __r = _S_compare(__size, __osize); |
5705 | return __r; |
5706 | } |
5707 | |
5708 | |
5709 | |
5710 | |
5711 | |
5712 | |
5713 | |
5714 | |
5715 | |
5716 | template<typename _Tp> |
5717 | _If_sv<_Tp, int> |
5718 | compare(size_type __pos, size_type __n, const _Tp& __svt) const |
5719 | noexcept(is_same<_Tp, __sv_type>::value) |
5720 | { |
5721 | __sv_type __sv = __svt; |
5722 | return __sv_type(*this).substr(__pos, __n).compare(__sv); |
5723 | } |
5724 | |
5725 | |
5726 | |
5727 | |
5728 | |
5729 | |
5730 | |
5731 | |
5732 | |
5733 | |
5734 | |
5735 | template<typename _Tp> |
5736 | _If_sv<_Tp, int> |
5737 | compare(size_type __pos1, size_type __n1, const _Tp& __svt, |
5738 | size_type __pos2, size_type __n2 = npos) const |
5739 | noexcept(is_same<_Tp, __sv_type>::value) |
5740 | { |
5741 | __sv_type __sv = __svt; |
5742 | return __sv_type(*this) |
5743 | .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); |
5744 | } |
5745 | #endif |
5746 | |
5747 | |
5748 | |
5749 | |
5750 | |
5751 | |
5752 | |
5753 | |
5754 | |
5755 | |
5756 | |
5757 | |
5758 | |
5759 | |
5760 | |
5761 | |
5762 | |
5763 | |
5764 | |
5765 | |
5766 | int |
5767 | compare(size_type __pos, size_type __n, const basic_string& __str) const; |
5768 | |
5769 | |
5770 | |
5771 | |
5772 | |
5773 | |
5774 | |
5775 | |
5776 | |
5777 | |
5778 | |
5779 | |
5780 | |
5781 | |
5782 | |
5783 | |
5784 | |
5785 | |
5786 | |
5787 | |
5788 | |
5789 | |
5790 | |
5791 | |
5792 | int |
5793 | compare(size_type __pos1, size_type __n1, const basic_string& __str, |
5794 | size_type __pos2, size_type __n2 = npos) const; |
5795 | |
5796 | |
5797 | |
5798 | |
5799 | |
5800 | |
5801 | |
5802 | |
5803 | |
5804 | |
5805 | |
5806 | |
5807 | |
5808 | |
5809 | |
5810 | int |
5811 | compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT; |
5812 | |
5813 | |
5814 | |
5815 | |
5816 | |
5817 | |
5818 | |
5819 | |
5820 | |
5821 | |
5822 | |
5823 | |
5824 | |
5825 | |
5826 | |
5827 | |
5828 | |
5829 | |
5830 | |
5831 | |
5832 | |
5833 | |
5834 | int |
5835 | compare(size_type __pos, size_type __n1, const _CharT* __s) const; |
5836 | |
5837 | |
5838 | |
5839 | |
5840 | |
5841 | |
5842 | |
5843 | |
5844 | |
5845 | |
5846 | |
5847 | |
5848 | |
5849 | |
5850 | |
5851 | |
5852 | |
5853 | |
5854 | |
5855 | |
5856 | |
5857 | |
5858 | |
5859 | |
5860 | |
5861 | int |
5862 | compare(size_type __pos, size_type __n1, const _CharT* __s, |
5863 | size_type __n2) const; |
5864 | |
5865 | # ifdef _GLIBCXX_TM_TS_INTERNAL |
5866 | friend void |
5867 | ::_txnal_cow_string_C1_for_exceptions(void* that, const char* s, |
5868 | void* exc); |
5869 | friend const char* |
5870 | ::_txnal_cow_string_c_str(const void *that); |
5871 | friend void |
5872 | ::_txnal_cow_string_D1(void *that); |
5873 | friend void |
5874 | ::_txnal_cow_string_D1_commit(void *that); |
5875 | # endif |
5876 | }; |
5877 | #endif |
5878 | |
5879 | |
5880 | |
5881 | |
5882 | |
5883 | |
5884 | |
5885 | |
5886 | template<typename _CharT, typename _Traits, typename _Alloc> |
5887 | basic_string<_CharT, _Traits, _Alloc> |
5888 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
5889 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
5890 | { |
5891 | basic_string<_CharT, _Traits, _Alloc> __str(__lhs); |
5892 | __str.append(__rhs); |
5893 | return __str; |
5894 | } |
5895 | |
5896 | |
5897 | |
5898 | |
5899 | |
5900 | |
5901 | |
5902 | template<typename _CharT, typename _Traits, typename _Alloc> |
5903 | basic_string<_CharT,_Traits,_Alloc> |
5904 | operator+(const _CharT* __lhs, |
5905 | const basic_string<_CharT,_Traits,_Alloc>& __rhs); |
5906 | |
5907 | |
5908 | |
5909 | |
5910 | |
5911 | |
5912 | |
5913 | template<typename _CharT, typename _Traits, typename _Alloc> |
5914 | basic_string<_CharT,_Traits,_Alloc> |
5915 | operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs); |
5916 | |
5917 | |
5918 | |
5919 | |
5920 | |
5921 | |
5922 | |
5923 | template<typename _CharT, typename _Traits, typename _Alloc> |
5924 | inline basic_string<_CharT, _Traits, _Alloc> |
5925 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
5926 | const _CharT* __rhs) |
5927 | { |
5928 | basic_string<_CharT, _Traits, _Alloc> __str(__lhs); |
5929 | __str.append(__rhs); |
5930 | return __str; |
5931 | } |
5932 | |
5933 | |
5934 | |
5935 | |
5936 | |
5937 | |
5938 | |
5939 | template<typename _CharT, typename _Traits, typename _Alloc> |
5940 | inline basic_string<_CharT, _Traits, _Alloc> |
5941 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs) |
5942 | { |
5943 | typedef basic_string<_CharT, _Traits, _Alloc> __string_type; |
5944 | typedef typename __string_type::size_type __size_type; |
5945 | __string_type __str(__lhs); |
5946 | __str.append(__size_type(1), __rhs); |
5947 | return __str; |
5948 | } |
5949 | |
5950 | #if __cplusplus >= 201103L |
5951 | template<typename _CharT, typename _Traits, typename _Alloc> |
5952 | inline basic_string<_CharT, _Traits, _Alloc> |
5953 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
5954 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
5955 | { return std::move(__lhs.append(__rhs)); } |
5956 | |
5957 | template<typename _CharT, typename _Traits, typename _Alloc> |
5958 | inline basic_string<_CharT, _Traits, _Alloc> |
5959 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
5960 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
5961 | { return std::move(__rhs.insert(0, __lhs)); } |
5962 | |
5963 | template<typename _CharT, typename _Traits, typename _Alloc> |
5964 | inline basic_string<_CharT, _Traits, _Alloc> |
5965 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
5966 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
5967 | { |
5968 | const auto __size = __lhs.size() + __rhs.size(); |
5969 | const bool __cond = (__size > __lhs.capacity() |
5970 | && __size <= __rhs.capacity()); |
5971 | return __cond ? std::move(__rhs.insert(0, __lhs)) |
5972 | : std::move(__lhs.append(__rhs)); |
5973 | } |
5974 | |
5975 | template<typename _CharT, typename _Traits, typename _Alloc> |
5976 | inline basic_string<_CharT, _Traits, _Alloc> |
5977 | operator+(const _CharT* __lhs, |
5978 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
5979 | { return std::move(__rhs.insert(0, __lhs)); } |
5980 | |
5981 | template<typename _CharT, typename _Traits, typename _Alloc> |
5982 | inline basic_string<_CharT, _Traits, _Alloc> |
5983 | operator+(_CharT __lhs, |
5984 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
5985 | { return std::move(__rhs.insert(0, 1, __lhs)); } |
5986 | |
5987 | template<typename _CharT, typename _Traits, typename _Alloc> |
5988 | inline basic_string<_CharT, _Traits, _Alloc> |
5989 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
5990 | const _CharT* __rhs) |
5991 | { return std::move(__lhs.append(__rhs)); } |
5992 | |
5993 | template<typename _CharT, typename _Traits, typename _Alloc> |
5994 | inline basic_string<_CharT, _Traits, _Alloc> |
5995 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
5996 | _CharT __rhs) |
5997 | { return std::move(__lhs.append(1, __rhs)); } |
5998 | #endif |
5999 | |
6000 | |
6001 | |
6002 | |
6003 | |
6004 | |
6005 | |
6006 | |
6007 | template<typename _CharT, typename _Traits, typename _Alloc> |
6008 | inline bool |
6009 | operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
6010 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
6011 | _GLIBCXX_NOEXCEPT |
6012 | { return __lhs.compare(__rhs) == 0; } |
6013 | |
6014 | template<typename _CharT> |
6015 | inline |
6016 | typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, bool>::__type |
6017 | operator==(const basic_string<_CharT>& __lhs, |
6018 | const basic_string<_CharT>& __rhs) _GLIBCXX_NOEXCEPT |
6019 | { return (__lhs.size() == __rhs.size() |
6020 | && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(), |
6021 | __lhs.size())); } |
6022 | |
6023 | |
6024 | |
6025 | |
6026 | |
6027 | |
6028 | |
6029 | template<typename _CharT, typename _Traits, typename _Alloc> |
6030 | inline bool |
6031 | operator==(const _CharT* __lhs, |
6032 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
6033 | { return __rhs.compare(__lhs) == 0; } |
6034 | |
6035 | |
6036 | |
6037 | |
6038 | |
6039 | |
6040 | |
6041 | template<typename _CharT, typename _Traits, typename _Alloc> |
6042 | inline bool |
6043 | operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
6044 | const _CharT* __rhs) |
6045 | { return __lhs.compare(__rhs) == 0; } |
6046 | |
6047 | |
6048 | |
6049 | |
6050 | |
6051 | |
6052 | |
6053 | |
6054 | template<typename _CharT, typename _Traits, typename _Alloc> |
6055 | inline bool |
6056 | operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
6057 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
6058 | _GLIBCXX_NOEXCEPT |
6059 | { return !(__lhs == __rhs); } |
6060 | |
6061 | |
6062 | |
6063 | |
6064 | |
6065 | |
6066 | |
6067 | template<typename _CharT, typename _Traits, typename _Alloc> |
6068 | inline bool |
6069 | operator!=(const _CharT* __lhs, |
6070 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
6071 | { return !(__lhs == __rhs); } |
6072 | |
6073 | |
6074 | |
6075 | |
6076 | |
6077 | |
6078 | |
6079 | template<typename _CharT, typename _Traits, typename _Alloc> |
6080 | inline bool |
6081 | operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
6082 | const _CharT* __rhs) |
6083 | { return !(__lhs == __rhs); } |
6084 | |
6085 | |
6086 | |
6087 | |
6088 | |
6089 | |
6090 | |
6091 | |
6092 | template<typename _CharT, typename _Traits, typename _Alloc> |
6093 | inline bool |
6094 | operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
6095 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
6096 | _GLIBCXX_NOEXCEPT |
6097 | { return __lhs.compare(__rhs) < 0; } |
6098 | |
6099 | |
6100 | |
6101 | |
6102 | |
6103 | |
6104 | |
6105 | template<typename _CharT, typename _Traits, typename _Alloc> |
6106 | inline bool |
6107 | operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
6108 | const _CharT* __rhs) |
6109 | { return __lhs.compare(__rhs) < 0; } |
6110 | |
6111 | |
6112 | |
6113 | |
6114 | |
6115 | |
6116 | |
6117 | template<typename _CharT, typename _Traits, typename _Alloc> |
6118 | inline bool |
6119 | operator<(const _CharT* __lhs, |
6120 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
6121 | { return __rhs.compare(__lhs) > 0; } |
6122 | |
6123 | |
6124 | |
6125 | |
6126 | |
6127 | |
6128 | |
6129 | |
6130 | template<typename _CharT, typename _Traits, typename _Alloc> |
6131 | inline bool |
6132 | operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
6133 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
6134 | _GLIBCXX_NOEXCEPT |
6135 | { return __lhs.compare(__rhs) > 0; } |
6136 | |
6137 | |
6138 | |
6139 | |
6140 | |
6141 | |
6142 | |
6143 | template<typename _CharT, typename _Traits, typename _Alloc> |
6144 | inline bool |
6145 | operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
6146 | const _CharT* __rhs) |
6147 | { return __lhs.compare(__rhs) > 0; } |
6148 | |
6149 | |
6150 | |
6151 | |
6152 | |
6153 | |
6154 | |
6155 | template<typename _CharT, typename _Traits, typename _Alloc> |
6156 | inline bool |
6157 | operator>(const _CharT* __lhs, |
6158 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
6159 | { return __rhs.compare(__lhs) < 0; } |
6160 | |
6161 | |
6162 | |
6163 | |
6164 | |
6165 | |
6166 | |
6167 | |
6168 | template<typename _CharT, typename _Traits, typename _Alloc> |
6169 | inline bool |
6170 | operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
6171 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
6172 | _GLIBCXX_NOEXCEPT |
6173 | { return __lhs.compare(__rhs) <= 0; } |
6174 | |
6175 | |
6176 | |
6177 | |
6178 | |
6179 | |
6180 | |
6181 | template<typename _CharT, typename _Traits, typename _Alloc> |
6182 | inline bool |
6183 | operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
6184 | const _CharT* __rhs) |
6185 | { return __lhs.compare(__rhs) <= 0; } |
6186 | |
6187 | |
6188 | |
6189 | |
6190 | |
6191 | |
6192 | |
6193 | template<typename _CharT, typename _Traits, typename _Alloc> |
6194 | inline bool |
6195 | operator<=(const _CharT* __lhs, |
6196 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
6197 | { return __rhs.compare(__lhs) >= 0; } |
6198 | |
6199 | |
6200 | |
6201 | |
6202 | |
6203 | |
6204 | |
6205 | |
6206 | template<typename _CharT, typename _Traits, typename _Alloc> |
6207 | inline bool |
6208 | operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
6209 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
6210 | _GLIBCXX_NOEXCEPT |
6211 | { return __lhs.compare(__rhs) >= 0; } |
6212 | |
6213 | |
6214 | |
6215 | |
6216 | |
6217 | |
6218 | |
6219 | template<typename _CharT, typename _Traits, typename _Alloc> |
6220 | inline bool |
6221 | operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
6222 | const _CharT* __rhs) |
6223 | { return __lhs.compare(__rhs) >= 0; } |
6224 | |
6225 | |
6226 | |
6227 | |
6228 | |
6229 | |
6230 | |
6231 | template<typename _CharT, typename _Traits, typename _Alloc> |
6232 | inline bool |
6233 | operator>=(const _CharT* __lhs, |
6234 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
6235 | { return __rhs.compare(__lhs) <= 0; } |
6236 | |
6237 | |
6238 | |
6239 | |
6240 | |
6241 | |
6242 | |
6243 | |
6244 | template<typename _CharT, typename _Traits, typename _Alloc> |
6245 | inline void |
6246 | swap(basic_string<_CharT, _Traits, _Alloc>& __lhs, |
6247 | basic_string<_CharT, _Traits, _Alloc>& __rhs) |
6248 | _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs))) |
6249 | { __lhs.swap(__rhs); } |
6250 | |
6251 | |
6252 | |
6253 | |
6254 | |
6255 | |
6256 | |
6257 | |
6258 | |
6259 | |
6260 | |
6261 | |
6262 | |
6263 | |
6264 | template<typename _CharT, typename _Traits, typename _Alloc> |
6265 | basic_istream<_CharT, _Traits>& |
6266 | operator>>(basic_istream<_CharT, _Traits>& __is, |
6267 | basic_string<_CharT, _Traits, _Alloc>& __str); |
6268 | |
6269 | template<> |
6270 | basic_istream<char>& |
6271 | operator>>(basic_istream<char>& __is, basic_string<char>& __str); |
6272 | |
6273 | |
6274 | |
6275 | |
6276 | |
6277 | |
6278 | |
6279 | |
6280 | |
6281 | |
6282 | template<typename _CharT, typename _Traits, typename _Alloc> |
6283 | inline basic_ostream<_CharT, _Traits>& |
6284 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
6285 | const basic_string<_CharT, _Traits, _Alloc>& __str) |
6286 | { |
6287 | |
6288 | |
6289 | return __ostream_insert(__os, __str.data(), __str.size()); |
6290 | } |
6291 | |
6292 | |
6293 | |
6294 | |
6295 | |
6296 | |
6297 | |
6298 | |
6299 | |
6300 | |
6301 | |
6302 | |
6303 | |
6304 | |
6305 | template<typename _CharT, typename _Traits, typename _Alloc> |
6306 | basic_istream<_CharT, _Traits>& |
6307 | getline(basic_istream<_CharT, _Traits>& __is, |
6308 | basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim); |
6309 | |
6310 | |
6311 | |
6312 | |
6313 | |
6314 | |
6315 | |
6316 | |
6317 | |
6318 | |
6319 | |
6320 | |
6321 | |
6322 | template<typename _CharT, typename _Traits, typename _Alloc> |
6323 | inline basic_istream<_CharT, _Traits>& |
6324 | getline(basic_istream<_CharT, _Traits>& __is, |
6325 | basic_string<_CharT, _Traits, _Alloc>& __str) |
6326 | { return std::getline(__is, __str, __is.widen('\n')); } |
6327 | |
6328 | #if __cplusplus >= 201103L |
6329 | |
6330 | template<typename _CharT, typename _Traits, typename _Alloc> |
6331 | inline basic_istream<_CharT, _Traits>& |
6332 | getline(basic_istream<_CharT, _Traits>&& __is, |
6333 | basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim) |
6334 | { return std::getline(__is, __str, __delim); } |
6335 | |
6336 | |
6337 | template<typename _CharT, typename _Traits, typename _Alloc> |
6338 | inline basic_istream<_CharT, _Traits>& |
6339 | getline(basic_istream<_CharT, _Traits>&& __is, |
6340 | basic_string<_CharT, _Traits, _Alloc>& __str) |
6341 | { return std::getline(__is, __str); } |
6342 | #endif |
6343 | |
6344 | template<> |
6345 | basic_istream<char>& |
6346 | getline(basic_istream<char>& __in, basic_string<char>& __str, |
6347 | char __delim); |
6348 | |
6349 | #ifdef _GLIBCXX_USE_WCHAR_T |
6350 | template<> |
6351 | basic_istream<wchar_t>& |
6352 | getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str, |
6353 | wchar_t __delim); |
6354 | #endif |
6355 | |
6356 | _GLIBCXX_END_NAMESPACE_VERSION |
6357 | } |
6358 | |
6359 | #if __cplusplus >= 201103L |
6360 | |
6361 | #include <ext/string_conversions.h> |
6362 | |
6363 | namespace std _GLIBCXX_VISIBILITY(default) |
6364 | { |
6365 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
6366 | _GLIBCXX_BEGIN_NAMESPACE_CXX11 |
6367 | |
6368 | #if _GLIBCXX_USE_C99_STDLIB |
6369 | |
6370 | inline int |
6371 | stoi(const string& __str, size_t* __idx = 0, int __base = 10) |
6372 | { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(), |
6373 | __idx, __base); } |
6374 | |
6375 | inline long |
6376 | stol(const string& __str, size_t* __idx = 0, int __base = 10) |
6377 | { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(), |
6378 | __idx, __base); } |
6379 | |
6380 | inline unsigned long |
6381 | stoul(const string& __str, size_t* __idx = 0, int __base = 10) |
6382 | { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(), |
6383 | __idx, __base); } |
6384 | |
6385 | inline long long |
6386 | stoll(const string& __str, size_t* __idx = 0, int __base = 10) |
6387 | { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(), |
6388 | __idx, __base); } |
6389 | |
6390 | inline unsigned long long |
6391 | stoull(const string& __str, size_t* __idx = 0, int __base = 10) |
6392 | { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(), |
6393 | __idx, __base); } |
6394 | |
6395 | |
6396 | inline float |
6397 | stof(const string& __str, size_t* __idx = 0) |
6398 | { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } |
6399 | |
6400 | inline double |
6401 | stod(const string& __str, size_t* __idx = 0) |
6402 | { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } |
6403 | |
6404 | inline long double |
6405 | stold(const string& __str, size_t* __idx = 0) |
6406 | { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } |
6407 | #endif |
6408 | |
6409 | #if _GLIBCXX_USE_C99_STDIO |
6410 | |
6411 | |
6412 | |
6413 | inline string |
6414 | to_string(int __val) |
6415 | { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(int), |
6416 | "%d", __val); } |
6417 | |
6418 | inline string |
6419 | to_string(unsigned __val) |
6420 | { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, |
6421 | 4 * sizeof(unsigned), |
6422 | "%u", __val); } |
6423 | |
6424 | inline string |
6425 | to_string(long __val) |
6426 | { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(long), |
6427 | "%ld", __val); } |
6428 | |
6429 | inline string |
6430 | to_string(unsigned long __val) |
6431 | { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, |
6432 | 4 * sizeof(unsigned long), |
6433 | "%lu", __val); } |
6434 | |
6435 | inline string |
6436 | to_string(long long __val) |
6437 | { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, |
6438 | 4 * sizeof(long long), |
6439 | "%lld", __val); } |
6440 | |
6441 | inline string |
6442 | to_string(unsigned long long __val) |
6443 | { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, |
6444 | 4 * sizeof(unsigned long long), |
6445 | "%llu", __val); } |
6446 | |
6447 | inline string |
6448 | to_string(float __val) |
6449 | { |
6450 | const int __n = |
6451 | __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20; |
6452 | return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, |
6453 | "%f", __val); |
6454 | } |
6455 | |
6456 | inline string |
6457 | to_string(double __val) |
6458 | { |
6459 | const int __n = |
6460 | __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20; |
6461 | return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, |
6462 | "%f", __val); |
6463 | } |
6464 | |
6465 | inline string |
6466 | to_string(long double __val) |
6467 | { |
6468 | const int __n = |
6469 | __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20; |
6470 | return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, |
6471 | "%Lf", __val); |
6472 | } |
6473 | #endif |
6474 | |
6475 | #if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR |
6476 | inline int |
6477 | stoi(const wstring& __str, size_t* __idx = 0, int __base = 10) |
6478 | { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(), |
6479 | __idx, __base); } |
6480 | |
6481 | inline long |
6482 | stol(const wstring& __str, size_t* __idx = 0, int __base = 10) |
6483 | { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(), |
6484 | __idx, __base); } |
6485 | |
6486 | inline unsigned long |
6487 | stoul(const wstring& __str, size_t* __idx = 0, int __base = 10) |
6488 | { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(), |
6489 | __idx, __base); } |
6490 | |
6491 | inline long long |
6492 | stoll(const wstring& __str, size_t* __idx = 0, int __base = 10) |
6493 | { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(), |
6494 | __idx, __base); } |
6495 | |
6496 | inline unsigned long long |
6497 | stoull(const wstring& __str, size_t* __idx = 0, int __base = 10) |
6498 | { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(), |
6499 | __idx, __base); } |
6500 | |
6501 | |
6502 | inline float |
6503 | stof(const wstring& __str, size_t* __idx = 0) |
6504 | { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); } |
6505 | |
6506 | inline double |
6507 | stod(const wstring& __str, size_t* __idx = 0) |
6508 | { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); } |
6509 | |
6510 | inline long double |
6511 | stold(const wstring& __str, size_t* __idx = 0) |
6512 | { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); } |
6513 | |
6514 | #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF |
6515 | |
6516 | inline wstring |
6517 | to_wstring(int __val) |
6518 | { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(int), |
6519 | L"%d", __val); } |
6520 | |
6521 | inline wstring |
6522 | to_wstring(unsigned __val) |
6523 | { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, |
6524 | 4 * sizeof(unsigned), |
6525 | L"%u", __val); } |
6526 | |
6527 | inline wstring |
6528 | to_wstring(long __val) |
6529 | { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(long), |
6530 | L"%ld", __val); } |
6531 | |
6532 | inline wstring |
6533 | to_wstring(unsigned long __val) |
6534 | { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, |
6535 | 4 * sizeof(unsigned long), |
6536 | L"%lu", __val); } |
6537 | |
6538 | inline wstring |
6539 | to_wstring(long long __val) |
6540 | { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, |
6541 | 4 * sizeof(long long), |
6542 | L"%lld", __val); } |
6543 | |
6544 | inline wstring |
6545 | to_wstring(unsigned long long __val) |
6546 | { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, |
6547 | 4 * sizeof(unsigned long long), |
6548 | L"%llu", __val); } |
6549 | |
6550 | inline wstring |
6551 | to_wstring(float __val) |
6552 | { |
6553 | const int __n = |
6554 | __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20; |
6555 | return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n, |
6556 | L"%f", __val); |
6557 | } |
6558 | |
6559 | inline wstring |
6560 | to_wstring(double __val) |
6561 | { |
6562 | const int __n = |
6563 | __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20; |
6564 | return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n, |
6565 | L"%f", __val); |
6566 | } |
6567 | |
6568 | inline wstring |
6569 | to_wstring(long double __val) |
6570 | { |
6571 | const int __n = |
6572 | __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20; |
6573 | return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n, |
6574 | L"%Lf", __val); |
6575 | } |
6576 | #endif |
6577 | #endif |
6578 | |
6579 | _GLIBCXX_END_NAMESPACE_CXX11 |
6580 | _GLIBCXX_END_NAMESPACE_VERSION |
6581 | } |
6582 | |
6583 | #endif |
6584 | |
6585 | #if __cplusplus >= 201103L |
6586 | |
6587 | #include <bits/functional_hash.h> |
6588 | |
6589 | namespace std _GLIBCXX_VISIBILITY(default) |
6590 | { |
6591 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
6592 | |
6593 | |
6594 | |
6595 | #ifndef _GLIBCXX_COMPATIBILITY_CXX0X |
6596 | |
6597 | template<> |
6598 | struct hash<string> |
6599 | : public __hash_base<size_t, string> |
6600 | { |
6601 | size_t |
6602 | operator()(const string& __s) const noexcept |
6603 | { return std::_Hash_impl::hash(__s.data(), __s.length()); } |
6604 | }; |
6605 | |
6606 | template<> |
6607 | struct __is_fast_hash<hash<string>> : std::false_type |
6608 | { }; |
6609 | |
6610 | #ifdef _GLIBCXX_USE_WCHAR_T |
6611 | |
6612 | template<> |
6613 | struct hash<wstring> |
6614 | : public __hash_base<size_t, wstring> |
6615 | { |
6616 | size_t |
6617 | operator()(const wstring& __s) const noexcept |
6618 | { return std::_Hash_impl::hash(__s.data(), |
6619 | __s.length() * sizeof(wchar_t)); } |
6620 | }; |
6621 | |
6622 | template<> |
6623 | struct __is_fast_hash<hash<wstring>> : std::false_type |
6624 | { }; |
6625 | #endif |
6626 | #endif |
6627 | |
6628 | #ifdef _GLIBCXX_USE_C99_STDINT_TR1 |
6629 | |
6630 | template<> |
6631 | struct hash<u16string> |
6632 | : public __hash_base<size_t, u16string> |
6633 | { |
6634 | size_t |
6635 | operator()(const u16string& __s) const noexcept |
6636 | { return std::_Hash_impl::hash(__s.data(), |
6637 | __s.length() * sizeof(char16_t)); } |
6638 | }; |
6639 | |
6640 | template<> |
6641 | struct __is_fast_hash<hash<u16string>> : std::false_type |
6642 | { }; |
6643 | |
6644 | |
6645 | template<> |
6646 | struct hash<u32string> |
6647 | : public __hash_base<size_t, u32string> |
6648 | { |
6649 | size_t |
6650 | operator()(const u32string& __s) const noexcept |
6651 | { return std::_Hash_impl::hash(__s.data(), |
6652 | __s.length() * sizeof(char32_t)); } |
6653 | }; |
6654 | |
6655 | template<> |
6656 | struct __is_fast_hash<hash<u32string>> : std::false_type |
6657 | { }; |
6658 | #endif |
6659 | |
6660 | _GLIBCXX_END_NAMESPACE_VERSION |
6661 | |
6662 | #if __cplusplus > 201103L |
6663 | |
6664 | #define __cpp_lib_string_udls 201304 |
6665 | |
6666 | inline namespace literals |
6667 | { |
6668 | inline namespace string_literals |
6669 | { |
6670 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
6671 | |
6672 | _GLIBCXX_DEFAULT_ABI_TAG |
6673 | inline basic_string<char> |
6674 | operator""s(const char* __str, size_t __len) |
6675 | { return basic_string<char>{__str, __len}; } |
6676 | |
6677 | #ifdef _GLIBCXX_USE_WCHAR_T |
6678 | _GLIBCXX_DEFAULT_ABI_TAG |
6679 | inline basic_string<wchar_t> |
6680 | operator""s(const wchar_t* __str, size_t __len) |
6681 | { return basic_string<wchar_t>{__str, __len}; } |
6682 | #endif |
6683 | |
6684 | #ifdef _GLIBCXX_USE_C99_STDINT_TR1 |
6685 | _GLIBCXX_DEFAULT_ABI_TAG |
6686 | inline basic_string<char16_t> |
6687 | operator""s(const char16_t* __str, size_t __len) |
6688 | { return basic_string<char16_t>{__str, __len}; } |
6689 | |
6690 | _GLIBCXX_DEFAULT_ABI_TAG |
6691 | inline basic_string<char32_t> |
6692 | operator""s(const char32_t* __str, size_t __len) |
6693 | { return basic_string<char32_t>{__str, __len}; } |
6694 | #endif |
6695 | |
6696 | _GLIBCXX_END_NAMESPACE_VERSION |
6697 | } |
6698 | } |
6699 | |
6700 | #endif |
6701 | |
6702 | } |
6703 | |
6704 | #endif |
6705 | |
6706 | #endif |
6707 | |