source: Daodan/MSYS2/mingw32/include/c++/11.2.0/ext/vstring.h@ 1170

Last change on this file since 1170 was 1166, checked in by rossy, 3 years ago

Daodan: Replace MinGW build env with an up-to-date MSYS2 env

File size: 108.0 KB
RevLine 
[1166]1// Versatile string -*- C++ -*-
2
3// Copyright (C) 2005-2021 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/** @file ext/vstring.h
26 * This file is a GNU extension to the Standard C++ Library.
27 */
28
29#ifndef _VSTRING_H
30#define _VSTRING_H 1
31
32#pragma GCC system_header
33
34#if __cplusplus >= 201103L
35#include <initializer_list>
36#endif
37
38#include <ext/vstring_util.h>
39#include <ext/rc_string_base.h>
40#include <ext/sso_string_base.h>
41
42namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
43{
44_GLIBCXX_BEGIN_NAMESPACE_VERSION
45
46 /**
47 * @class __versa_string vstring.h
48 * @brief Template class __versa_string.
49 * @ingroup extensions
50 *
51 * Data structure managing sequences of characters and
52 * character-like objects.
53 */
54 template<typename _CharT, typename _Traits, typename _Alloc,
55 template <typename, typename, typename> class _Base>
56 class __versa_string
57 : private _Base<_CharT, _Traits, _Alloc>
58 {
59 typedef _Base<_CharT, _Traits, _Alloc> __vstring_base;
60 typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type;
61 typedef __alloc_traits<_CharT_alloc_type> _CharT_alloc_traits;
62
63 // Types:
64 public:
65 typedef _Traits traits_type;
66 typedef typename _Traits::char_type value_type;
67 typedef _Alloc allocator_type;
68 typedef typename _CharT_alloc_type::size_type size_type;
69 typedef typename _CharT_alloc_type::difference_type difference_type;
70 typedef value_type& reference;
71 typedef const value_type& const_reference;
72 typedef typename _CharT_alloc_traits::pointer pointer;
73 typedef typename _CharT_alloc_traits::const_pointer const_pointer;
74 typedef __gnu_cxx::__normal_iterator<pointer, __versa_string> iterator;
75 typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
76 const_iterator;
77 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
78 typedef std::reverse_iterator<iterator> reverse_iterator;
79
80 // Data Member (public):
81 /// Value returned by various member functions when they fail.
82 static const size_type npos = static_cast<size_type>(-1);
83
84 private:
85 size_type
86 _M_check(size_type __pos, const char* __s) const
87 {
88 if (__pos > this->size())
89 std::__throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
90 "this->size() (which is %zu)"),
91 __s, __pos, this->size());
92 return __pos;
93 }
94
95 void
96 _M_check_length(size_type __n1, size_type __n2, const char* __s) const
97 {
98 if (this->max_size() - (this->size() - __n1) < __n2)
99 std::__throw_length_error(__N(__s));
100 }
101
102 // NB: _M_limit doesn't check for a bad __pos value.
103 size_type
104 _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT
105 {
106 const bool __testoff = __off < this->size() - __pos;
107 return __testoff ? __off : this->size() - __pos;
108 }
109
110 // True if _Rep and source do not overlap.
111 bool
112 _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT
113 {
114 return (std::less<const _CharT*>()(__s, this->_M_data())
115 || std::less<const _CharT*>()(this->_M_data()
116 + this->size(), __s));
117 }
118
119 // For the internal use we have functions similar to `begin'/`end'
120 // but they do not call _M_leak.
121 iterator
122 _M_ibegin() const _GLIBCXX_NOEXCEPT
123 { return iterator(this->_M_data()); }
124
125 iterator
126 _M_iend() const _GLIBCXX_NOEXCEPT
127 { return iterator(this->_M_data() + this->_M_length()); }
128
129 public:
130 // Construct/copy/destroy:
131 // NB: We overload ctors in some cases instead of using default
132 // arguments, per 17.4.4.4 para. 2 item 2.
133
134 /**
135 * @brief Construct an empty string using allocator @a a.
136 */
137 explicit
138 __versa_string(const _Alloc& __a = _Alloc()) _GLIBCXX_NOEXCEPT
139 : __vstring_base(__a) { }
140
141 // NB: per LWG issue 42, semantics different from IS:
142 /**
143 * @brief Construct string with copy of value of @a __str.
144 * @param __str Source string.
145 */
146 __versa_string(const __versa_string& __str)
147 : __vstring_base(__str) { }
148
149#if __cplusplus >= 201103L
150 /**
151 * @brief String move constructor.
152 * @param __str Source string.
153 *
154 * The newly-constructed %string contains the exact contents of
155 * @a __str. The contents of @a __str are a valid, but unspecified
156 * string.
157 */
158 __versa_string(__versa_string&& __str) noexcept
159 : __vstring_base(std::move(__str)) { }
160
161 /**
162 * @brief Construct string from an initializer list.
163 * @param __l std::initializer_list of characters.
164 * @param __a Allocator to use (default is default allocator).
165 */
166 __versa_string(std::initializer_list<_CharT> __l,
167 const _Alloc& __a = _Alloc())
168 : __vstring_base(__l.begin(), __l.end(), __a) { }
169#endif
170
171 /**
172 * @brief Construct string as copy of a substring.
173 * @param __str Source string.
174 * @param __pos Index of first character to copy from.
175 * @param __n Number of characters to copy (default remainder).
176 */
177 __versa_string(const __versa_string& __str, size_type __pos,
178 size_type __n = npos)
179 : __vstring_base(__str._M_data()
180 + __str._M_check(__pos,
181 "__versa_string::__versa_string"),
182 __str._M_data() + __str._M_limit(__pos, __n)
183 + __pos, _Alloc()) { }
184
185 /**
186 * @brief Construct string as copy of a substring.
187 * @param __str Source string.
188 * @param __pos Index of first character to copy from.
189 * @param __n Number of characters to copy.
190 * @param __a Allocator to use.
191 */
192 __versa_string(const __versa_string& __str, size_type __pos,
193 size_type __n, const _Alloc& __a)
194 : __vstring_base(__str._M_data()
195 + __str._M_check(__pos,
196 "__versa_string::__versa_string"),
197 __str._M_data() + __str._M_limit(__pos, __n)
198 + __pos, __a) { }
199
200 /**
201 * @brief Construct string initialized by a character array.
202 * @param __s Source character array.
203 * @param __n Number of characters to copy.
204 * @param __a Allocator to use (default is default allocator).
205 *
206 * NB: @a __s must have at least @a __n characters, '\\0' has no special
207 * meaning.
208 */
209 __versa_string(const _CharT* __s, size_type __n,
210 const _Alloc& __a = _Alloc())
211 : __vstring_base(__s, __s + __n, __a) { }
212
213 /**
214 * @brief Construct string as copy of a C string.
215 * @param __s Source C string.
216 * @param __a Allocator to use (default is default allocator).
217 */
218 __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc())
219 : __vstring_base(__s, __s ? __s + traits_type::length(__s) :
220 __s + npos, __a) { }
221
222 /**
223 * @brief Construct string as multiple characters.
224 * @param __n Number of characters.
225 * @param __c Character to use.
226 * @param __a Allocator to use (default is default allocator).
227 */
228 __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
229 : __vstring_base(__n, __c, __a) { }
230
231 /**
232 * @brief Construct string as copy of a range.
233 * @param __beg Start of range.
234 * @param __end End of range.
235 * @param __a Allocator to use (default is default allocator).
236 */
237#if __cplusplus >= 201103L
238 template<class _InputIterator,
239 typename = std::_RequireInputIter<_InputIterator>>
240#else
241 template<class _InputIterator>
242#endif
243 __versa_string(_InputIterator __beg, _InputIterator __end,
244 const _Alloc& __a = _Alloc())
245 : __vstring_base(__beg, __end, __a) { }
246
247 /**
248 * @brief Destroy the string instance.
249 */
250 ~__versa_string() _GLIBCXX_NOEXCEPT { }
251
252 /**
253 * @brief Assign the value of @a str to this string.
254 * @param __str Source string.
255 */
256 __versa_string&
257 operator=(const __versa_string& __str)
258 { return this->assign(__str); }
259
260#if __cplusplus >= 201103L
261 /**
262 * @brief String move assignment operator.
263 * @param __str Source string.
264 *
265 * The contents of @a __str are moved into this string (without
266 * copying). @a __str is a valid, but unspecified string.
267 */
268 __versa_string&
269 operator=(__versa_string&& __str) noexcept
270 {
271 // NB: DR 1204.
272 this->swap(__str);
273 return *this;
274 }
275
276 /**
277 * @brief Set value to string constructed from initializer list.
278 * @param __l std::initializer_list.
279 */
280 __versa_string&
281 operator=(std::initializer_list<_CharT> __l)
282 {
283 this->assign(__l.begin(), __l.end());
284 return *this;
285 }
286#endif
287
288 /**
289 * @brief Copy contents of @a __s into this string.
290 * @param __s Source null-terminated string.
291 */
292 __versa_string&
293 operator=(const _CharT* __s)
294 { return this->assign(__s); }
295
296 /**
297 * @brief Set value to string of length 1.
298 * @param __c Source character.
299 *
300 * Assigning to a character makes this string length 1 and
301 * (*this)[0] == @a __c.
302 */
303 __versa_string&
304 operator=(_CharT __c)
305 {
306 this->assign(1, __c);
307 return *this;
308 }
309
310 // Iterators:
311 /**
312 * Returns a read/write iterator that points to the first character in
313 * the %string. Unshares the string.
314 */
315 iterator
316 begin() _GLIBCXX_NOEXCEPT
317 {
318 this->_M_leak();
319 return iterator(this->_M_data());
320 }
321
322 /**
323 * Returns a read-only (constant) iterator that points to the first
324 * character in the %string.
325 */
326 const_iterator
327 begin() const _GLIBCXX_NOEXCEPT
328 { return const_iterator(this->_M_data()); }
329
330 /**
331 * Returns a read/write iterator that points one past the last
332 * character in the %string. Unshares the string.
333 */
334 iterator
335 end() _GLIBCXX_NOEXCEPT
336 {
337 this->_M_leak();
338 return iterator(this->_M_data() + this->size());
339 }
340
341 /**
342 * Returns a read-only (constant) iterator that points one past the
343 * last character in the %string.
344 */
345 const_iterator
346 end() const _GLIBCXX_NOEXCEPT
347 { return const_iterator(this->_M_data() + this->size()); }
348
349 /**
350 * Returns a read/write reverse iterator that points to the last
351 * character in the %string. Iteration is done in reverse element
352 * order. Unshares the string.
353 */
354 reverse_iterator
355 rbegin() _GLIBCXX_NOEXCEPT
356 { return reverse_iterator(this->end()); }
357
358 /**
359 * Returns a read-only (constant) reverse iterator that points
360 * to the last character in the %string. Iteration is done in
361 * reverse element order.
362 */
363 const_reverse_iterator
364 rbegin() const _GLIBCXX_NOEXCEPT
365 { return const_reverse_iterator(this->end()); }
366
367 /**
368 * Returns a read/write reverse iterator that points to one before the
369 * first character in the %string. Iteration is done in reverse
370 * element order. Unshares the string.
371 */
372 reverse_iterator
373 rend() _GLIBCXX_NOEXCEPT
374 { return reverse_iterator(this->begin()); }
375
376 /**
377 * Returns a read-only (constant) reverse iterator that points
378 * to one before the first character in the %string. Iteration
379 * is done in reverse element order.
380 */
381 const_reverse_iterator
382 rend() const _GLIBCXX_NOEXCEPT
383 { return const_reverse_iterator(this->begin()); }
384
385#if __cplusplus >= 201103L
386 /**
387 * Returns a read-only (constant) iterator that points to the first
388 * character in the %string.
389 */
390 const_iterator
391 cbegin() const noexcept
392 { return const_iterator(this->_M_data()); }
393
394 /**
395 * Returns a read-only (constant) iterator that points one past the
396 * last character in the %string.
397 */
398 const_iterator
399 cend() const noexcept
400 { return const_iterator(this->_M_data() + this->size()); }
401
402 /**
403 * Returns a read-only (constant) reverse iterator that points
404 * to the last character in the %string. Iteration is done in
405 * reverse element order.
406 */
407 const_reverse_iterator
408 crbegin() const noexcept
409 { return const_reverse_iterator(this->end()); }
410
411 /**
412 * Returns a read-only (constant) reverse iterator that points
413 * to one before the first character in the %string. Iteration
414 * is done in reverse element order.
415 */
416 const_reverse_iterator
417 crend() const noexcept
418 { return const_reverse_iterator(this->begin()); }
419#endif
420
421 public:
422 // Capacity:
423 /// Returns the number of characters in the string, not including any
424 /// null-termination.
425 size_type
426 size() const _GLIBCXX_NOEXCEPT
427 { return this->_M_length(); }
428
429 /// Returns the number of characters in the string, not including any
430 /// null-termination.
431 size_type
432 length() const _GLIBCXX_NOEXCEPT
433 { return this->_M_length(); }
434
435 /// Returns the size() of the largest possible %string.
436 size_type
437 max_size() const _GLIBCXX_NOEXCEPT
438 { return this->_M_max_size(); }
439
440 /**
441 * @brief Resizes the %string to the specified number of characters.
442 * @param __n Number of characters the %string should contain.
443 * @param __c Character to fill any new elements.
444 *
445 * This function will %resize the %string to the specified
446 * number of characters. If the number is smaller than the
447 * %string's current size the %string is truncated, otherwise
448 * the %string is extended and new elements are set to @a __c.
449 */
450 void
451 resize(size_type __n, _CharT __c);
452
453 /**
454 * @brief Resizes the %string to the specified number of characters.
455 * @param __n Number of characters the %string should contain.
456 *
457 * This function will resize the %string to the specified
458 * length. If the new size is smaller than the %string's
459 * current size the %string is truncated, otherwise the %string
460 * is extended and new characters are default-constructed. For
461 * basic types such as char, this means setting them to 0.
462 */
463 void
464 resize(size_type __n)
465 { this->resize(__n, _CharT()); }
466
467#if __cplusplus >= 201103L
468 /// A non-binding request to reduce capacity() to size().
469 void
470 shrink_to_fit() noexcept
471 {
472 if (capacity() > size())
473 {
474 __try
475 { this->reserve(0); }
476 __catch(...)
477 { }
478 }
479 }
480#endif
481
482 /**
483 * Returns the total number of characters that the %string can
484 * hold before needing to allocate more memory.
485 */
486 size_type
487 capacity() const _GLIBCXX_NOEXCEPT
488 { return this->_M_capacity(); }
489
490 /**
491 * @brief Attempt to preallocate enough memory for specified number of
492 * characters.
493 * @param __res_arg Number of characters required.
494 * @throw std::length_error If @a __res_arg exceeds @c max_size().
495 *
496 * This function attempts to reserve enough memory for the
497 * %string to hold the specified number of characters. If the
498 * number requested is more than max_size(), length_error is
499 * thrown.
500 *
501 * The advantage of this function is that if optimal code is a
502 * necessity and the user can determine the string length that
503 * will be required, the user can reserve the memory in
504 * %advance, and thus prevent a possible reallocation of memory
505 * and copying of %string data.
506 */
507 void
508 reserve(size_type __res_arg = 0)
509 { this->_M_reserve(__res_arg); }
510
511 /**
512 * Erases the string, making it empty.
513 */
514 void
515 clear() _GLIBCXX_NOEXCEPT
516 { this->_M_clear(); }
517
518 /**
519 * Returns true if the %string is empty. Equivalent to
520 * <code>*this == ""</code>.
521 */
522 _GLIBCXX_NODISCARD bool
523 empty() const _GLIBCXX_NOEXCEPT
524 { return this->size() == 0; }
525
526 // Element access:
527 /**
528 * @brief Subscript access to the data contained in the %string.
529 * @param __pos The index of the character to access.
530 * @return Read-only (constant) reference to the character.
531 *
532 * This operator allows for easy, array-style, data access.
533 * Note that data access with this operator is unchecked and
534 * out_of_range lookups are not defined. (For checked lookups
535 * see at().)
536 */
537 const_reference
538 operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT
539 {
540 __glibcxx_assert(__pos <= this->size());
541 return this->_M_data()[__pos];
542 }
543
544 /**
545 * @brief Subscript access to the data contained in the %string.
546 * @param __pos The index of the character to access.
547 * @return Read/write reference to the character.
548 *
549 * This operator allows for easy, array-style, data access.
550 * Note that data access with this operator is unchecked and
551 * out_of_range lookups are not defined. (For checked lookups
552 * see at().) Unshares the string.
553 */
554 reference
555 operator[](size_type __pos) _GLIBCXX_NOEXCEPT
556 {
557 // Allow pos == size() both in C++98 mode, as v3 extension,
558 // and in C++11 mode.
559 __glibcxx_assert(__pos <= this->size());
560 // In pedantic mode be strict in C++98 mode.
561 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L
562 || __pos < this->size());
563 this->_M_leak();
564 return this->_M_data()[__pos];
565 }
566
567 /**
568 * @brief Provides access to the data contained in the %string.
569 * @param __n The index of the character to access.
570 * @return Read-only (const) reference to the character.
571 * @throw std::out_of_range If @a __n is an invalid index.
572 *
573 * This function provides for safer data access. The parameter
574 * is first checked that it is in the range of the string. The
575 * function throws out_of_range if the check fails.
576 */
577 const_reference
578 at(size_type __n) const
579 {
580 if (__n >= this->size())
581 std::__throw_out_of_range_fmt(__N("__versa_string::at: __n "
582 "(which is %zu) >= this->size() "
583 "(which is %zu)"),
584 __n, this->size());
585 return this->_M_data()[__n];
586 }
587
588 /**
589 * @brief Provides access to the data contained in the %string.
590 * @param __n The index of the character to access.
591 * @return Read/write reference to the character.
592 * @throw std::out_of_range If @a __n is an invalid index.
593 *
594 * This function provides for safer data access. The parameter
595 * is first checked that it is in the range of the string. The
596 * function throws out_of_range if the check fails. Success
597 * results in unsharing the string.
598 */
599 reference
600 at(size_type __n)
601 {
602 if (__n >= this->size())
603 std::__throw_out_of_range_fmt(__N("__versa_string::at: __n "
604 "(which is %zu) >= this->size() "
605 "(which is %zu)"),
606 __n, this->size());
607 this->_M_leak();
608 return this->_M_data()[__n];
609 }
610
611#if __cplusplus >= 201103L
612 /**
613 * Returns a read/write reference to the data at the first
614 * element of the %string.
615 */
616 reference
617 front() noexcept
618 { return operator[](0); }
619
620 /**
621 * Returns a read-only (constant) reference to the data at the first
622 * element of the %string.
623 */
624 const_reference
625 front() const noexcept
626 { return operator[](0); }
627
628 /**
629 * Returns a read/write reference to the data at the last
630 * element of the %string.
631 */
632 reference
633 back() noexcept
634 { return operator[](this->size() - 1); }
635
636 /**
637 * Returns a read-only (constant) reference to the data at the
638 * last element of the %string.
639 */
640 const_reference
641 back() const noexcept
642 { return operator[](this->size() - 1); }
643#endif
644
645 // Modifiers:
646 /**
647 * @brief Append a string to this string.
648 * @param __str The string to append.
649 * @return Reference to this string.
650 */
651 __versa_string&
652 operator+=(const __versa_string& __str)
653 { return this->append(__str); }
654
655 /**
656 * @brief Append a C string.
657 * @param __s The C string to append.
658 * @return Reference to this string.
659 */
660 __versa_string&
661 operator+=(const _CharT* __s)
662 { return this->append(__s); }
663
664 /**
665 * @brief Append a character.
666 * @param __c The character to append.
667 * @return Reference to this string.
668 */
669 __versa_string&
670 operator+=(_CharT __c)
671 {
672 this->push_back(__c);
673 return *this;
674 }
675
676#if __cplusplus >= 201103L
677 /**
678 * @brief Append an initializer_list of characters.
679 * @param __l The initializer_list of characters to be appended.
680 * @return Reference to this string.
681 */
682 __versa_string&
683 operator+=(std::initializer_list<_CharT> __l)
684 { return this->append(__l.begin(), __l.end()); }
685#endif // C++11
686
687 /**
688 * @brief Append a string to this string.
689 * @param __str The string to append.
690 * @return Reference to this string.
691 */
692 __versa_string&
693 append(const __versa_string& __str)
694 { return _M_append(__str._M_data(), __str.size()); }
695
696 /**
697 * @brief Append a substring.
698 * @param __str The string to append.
699 * @param __pos Index of the first character of str to append.
700 * @param __n The number of characters to append.
701 * @return Reference to this string.
702 * @throw std::out_of_range if @a pos is not a valid index.
703 *
704 * This function appends @a __n characters from @a __str
705 * starting at @a __pos to this string. If @a __n is is larger
706 * than the number of available characters in @a __str, the
707 * remainder of @a __str is appended.
708 */
709 __versa_string&
710 append(const __versa_string& __str, size_type __pos, size_type __n)
711 { return _M_append(__str._M_data()
712 + __str._M_check(__pos, "__versa_string::append"),
713 __str._M_limit(__pos, __n)); }
714
715 /**
716 * @brief Append a C substring.
717 * @param __s The C string to append.
718 * @param __n The number of characters to append.
719 * @return Reference to this string.
720 */
721 __versa_string&
722 append(const _CharT* __s, size_type __n)
723 {
724 __glibcxx_requires_string_len(__s, __n);
725 _M_check_length(size_type(0), __n, "__versa_string::append");
726 return _M_append(__s, __n);
727 }
728
729 /**
730 * @brief Append a C string.
731 * @param __s The C string to append.
732 * @return Reference to this string.
733 */
734 __versa_string&
735 append(const _CharT* __s)
736 {
737 __glibcxx_requires_string(__s);
738 const size_type __n = traits_type::length(__s);
739 _M_check_length(size_type(0), __n, "__versa_string::append");
740 return _M_append(__s, __n);
741 }
742
743 /**
744 * @brief Append multiple characters.
745 * @param __n The number of characters to append.
746 * @param __c The character to use.
747 * @return Reference to this string.
748 *
749 * Appends n copies of c to this string.
750 */
751 __versa_string&
752 append(size_type __n, _CharT __c)
753 { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
754
755#if __cplusplus >= 201103L
756 /**
757 * @brief Append an initializer_list of characters.
758 * @param __l The initializer_list of characters to append.
759 * @return Reference to this string.
760 */
761 __versa_string&
762 append(std::initializer_list<_CharT> __l)
763 { return this->append(__l.begin(), __l.end()); }
764#endif // C++11
765
766 /**
767 * @brief Append a range of characters.
768 * @param __first Iterator referencing the first character to append.
769 * @param __last Iterator marking the end of the range.
770 * @return Reference to this string.
771 *
772 * Appends characters in the range [first,last) to this string.
773 */
774#if __cplusplus >= 201103L
775 template<class _InputIterator,
776 typename = std::_RequireInputIter<_InputIterator>>
777#else
778 template<class _InputIterator>
779#endif
780 __versa_string&
781 append(_InputIterator __first, _InputIterator __last)
782 { return this->replace(_M_iend(), _M_iend(), __first, __last); }
783
784 /**
785 * @brief Append a single character.
786 * @param __c Character to append.
787 */
788 void
789 push_back(_CharT __c)
790 {
791 const size_type __size = this->size();
792 if (__size + 1 > this->capacity() || this->_M_is_shared())
793 this->_M_mutate(__size, size_type(0), 0, size_type(1));
794 traits_type::assign(this->_M_data()[__size], __c);
795 this->_M_set_length(__size + 1);
796 }
797
798 /**
799 * @brief Set value to contents of another string.
800 * @param __str Source string to use.
801 * @return Reference to this string.
802 */
803 __versa_string&
804 assign(const __versa_string& __str)
805 {
806 this->_M_assign(__str);
807 return *this;
808 }
809
810#if __cplusplus >= 201103L
811 /**
812 * @brief Set value to contents of another string.
813 * @param __str Source string to use.
814 * @return Reference to this string.
815 *
816 * This function sets this string to the exact contents of @a __str.
817 * @a __str is a valid, but unspecified string.
818 */
819 __versa_string&
820 assign(__versa_string&& __str) noexcept
821 {
822 this->swap(__str);
823 return *this;
824 }
825#endif // C++11
826
827 /**
828 * @brief Set value to a substring of a string.
829 * @param __str The string to use.
830 * @param __pos Index of the first character of str.
831 * @param __n Number of characters to use.
832 * @return Reference to this string.
833 * @throw std::out_of_range if @a __pos is not a valid index.
834 *
835 * This function sets this string to the substring of @a __str
836 * consisting of @a __n characters at @a __pos. If @a __n is
837 * is larger than the number of available characters in @a
838 * __str, the remainder of @a __str is used.
839 */
840 __versa_string&
841 assign(const __versa_string& __str, size_type __pos, size_type __n)
842 { return _M_replace(size_type(0), this->size(), __str._M_data()
843 + __str._M_check(__pos, "__versa_string::assign"),
844 __str._M_limit(__pos, __n)); }
845
846 /**
847 * @brief Set value to a C substring.
848 * @param __s The C string to use.
849 * @param __n Number of characters to use.
850 * @return Reference to this string.
851 *
852 * This function sets the value of this string to the first @a
853 * __n characters of @a __s. If @a __n is is larger than the
854 * number of available characters in @a __s, the remainder of
855 * @a __s is used.
856 */
857 __versa_string&
858 assign(const _CharT* __s, size_type __n)
859 {
860 __glibcxx_requires_string_len(__s, __n);
861 return _M_replace(size_type(0), this->size(), __s, __n);
862 }
863
864 /**
865 * @brief Set value to contents of a C string.
866 * @param __s The C string to use.
867 * @return Reference to this string.
868 *
869 * This function sets the value of this string to the value of
870 * @a __s. The data is copied, so there is no dependence on @a
871 * __s once the function returns.
872 */
873 __versa_string&
874 assign(const _CharT* __s)
875 {
876 __glibcxx_requires_string(__s);
877 return _M_replace(size_type(0), this->size(), __s,
878 traits_type::length(__s));
879 }
880
881 /**
882 * @brief Set value to multiple characters.
883 * @param __n Length of the resulting string.
884 * @param __c The character to use.
885 * @return Reference to this string.
886 *
887 * This function sets the value of this string to @a __n copies of
888 * character @a __c.
889 */
890 __versa_string&
891 assign(size_type __n, _CharT __c)
892 { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
893
894 /**
895 * @brief Set value to a range of characters.
896 * @param __first Iterator referencing the first character to append.
897 * @param __last Iterator marking the end of the range.
898 * @return Reference to this string.
899 *
900 * Sets value of string to characters in the range
901 * [first,last).
902 */
903#if __cplusplus >= 201103L
904 template<class _InputIterator,
905 typename = std::_RequireInputIter<_InputIterator>>
906#else
907 template<class _InputIterator>
908#endif
909 __versa_string&
910 assign(_InputIterator __first, _InputIterator __last)
911 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
912
913#if __cplusplus >= 201103L
914 /**
915 * @brief Set value to an initializer_list of characters.
916 * @param __l The initializer_list of characters to assign.
917 * @return Reference to this string.
918 */
919 __versa_string&
920 assign(std::initializer_list<_CharT> __l)
921 { return this->assign(__l.begin(), __l.end()); }
922#endif // C++11
923
924#if __cplusplus >= 201103L
925 /**
926 * @brief Insert multiple characters.
927 * @param __p Const_iterator referencing location in string to
928 * insert at.
929 * @param __n Number of characters to insert
930 * @param __c The character to insert.
931 * @return Iterator referencing the first inserted char.
932 * @throw std::length_error If new length exceeds @c max_size().
933 *
934 * Inserts @a __n copies of character @a __c starting at the
935 * position referenced by iterator @a __p. If adding
936 * characters causes the length to exceed max_size(),
937 * length_error is thrown. The value of the string doesn't
938 * change if an error is thrown.
939 */
940 iterator
941 insert(const_iterator __p, size_type __n, _CharT __c)
942 {
943 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
944 const size_type __pos = __p - _M_ibegin();
945 this->replace(__p, __p, __n, __c);
946 return iterator(this->_M_data() + __pos);
947 }
948#else
949 /**
950 * @brief Insert multiple characters.
951 * @param __p Iterator referencing location in string to insert at.
952 * @param __n Number of characters to insert
953 * @param __c The character to insert.
954 * @throw std::length_error If new length exceeds @c max_size().
955 *
956 * Inserts @a __n copies of character @a __c starting at the
957 * position referenced by iterator @a __p. If adding
958 * characters causes the length to exceed max_size(),
959 * length_error is thrown. The value of the string doesn't
960 * change if an error is thrown.
961 */
962 void
963 insert(iterator __p, size_type __n, _CharT __c)
964 { this->replace(__p, __p, __n, __c); }
965#endif
966
967#if __cplusplus >= 201103L
968 /**
969 * @brief Insert a range of characters.
970 * @param __p Const_iterator referencing location in string to
971 * insert at.
972 * @param __beg Start of range.
973 * @param __end End of range.
974 * @return Iterator referencing the first inserted char.
975 * @throw std::length_error If new length exceeds @c max_size().
976 *
977 * Inserts characters in range [beg,end). If adding characters
978 * causes the length to exceed max_size(), length_error is
979 * thrown. The value of the string doesn't change if an error
980 * is thrown.
981 */
982 template<class _InputIterator,
983 typename = std::_RequireInputIter<_InputIterator>>
984 iterator
985 insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
986 {
987 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
988 const size_type __pos = __p - _M_ibegin();
989 this->replace(__p, __p, __beg, __end);
990 return iterator(this->_M_data() + __pos);
991 }
992#else
993 /**
994 * @brief Insert a range of characters.
995 * @param __p Iterator referencing location in string to insert at.
996 * @param __beg Start of range.
997 * @param __end End of range.
998 * @throw std::length_error If new length exceeds @c max_size().
999 *
1000 * Inserts characters in range [beg,end). If adding characters
1001 * causes the length to exceed max_size(), length_error is
1002 * thrown. The value of the string doesn't change if an error
1003 * is thrown.
1004 */
1005 template<class _InputIterator>
1006 void
1007 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1008 { this->replace(__p, __p, __beg, __end); }
1009#endif
1010
1011#if __cplusplus >= 201103L
1012 /**
1013 * @brief Insert an initializer_list of characters.
1014 * @param __p Const_iterator referencing location in string to
1015 * insert at.
1016 * @param __l The initializer_list of characters to insert.
1017 * @return Iterator referencing the first inserted char.
1018 * @throw std::length_error If new length exceeds @c max_size().
1019 */
1020 iterator
1021 insert(const_iterator __p, std::initializer_list<_CharT> __l)
1022 { return this->insert(__p, __l.begin(), __l.end()); }
1023#endif // C++11
1024
1025 /**
1026 * @brief Insert value of a string.
1027 * @param __pos1 Iterator referencing location in string to insert at.
1028 * @param __str The string to insert.
1029 * @return Reference to this string.
1030 * @throw std::length_error If new length exceeds @c max_size().
1031 *
1032 * Inserts value of @a __str starting at @a __pos1. If adding
1033 * characters causes the length to exceed max_size(),
1034 * length_error is thrown. The value of the string doesn't
1035 * change if an error is thrown.
1036 */
1037 __versa_string&
1038 insert(size_type __pos1, const __versa_string& __str)
1039 { return this->replace(__pos1, size_type(0),
1040 __str._M_data(), __str.size()); }
1041
1042 /**
1043 * @brief Insert a substring.
1044 * @param __pos1 Iterator referencing location in string to insert at.
1045 * @param __str The string to insert.
1046 * @param __pos2 Start of characters in str to insert.
1047 * @param __n Number of characters to insert.
1048 * @return Reference to this string.
1049 * @throw std::length_error If new length exceeds @c max_size().
1050 * @throw std::out_of_range If @a __pos1 > size() or
1051 * @a __pos2 > @a __str.size().
1052 *
1053 * Starting at @a __pos1, insert @a __n character of @a __str
1054 * beginning with @a __pos2. If adding characters causes the
1055 * length to exceed max_size(), length_error is thrown. If @a
1056 * __pos1 is beyond the end of this string or @a __pos2 is
1057 * beyond the end of @a __str, out_of_range is thrown. The
1058 * value of the string doesn't change if an error is thrown.
1059 */
1060 __versa_string&
1061 insert(size_type __pos1, const __versa_string& __str,
1062 size_type __pos2, size_type __n)
1063 { return this->replace(__pos1, size_type(0), __str._M_data()
1064 + __str._M_check(__pos2, "__versa_string::insert"),
1065 __str._M_limit(__pos2, __n)); }
1066
1067 /**
1068 * @brief Insert a C substring.
1069 * @param __pos Iterator referencing location in string to insert at.
1070 * @param __s The C string to insert.
1071 * @param __n The number of characters to insert.
1072 * @return Reference to this string.
1073 * @throw std::length_error If new length exceeds @c max_size().
1074 * @throw std::out_of_range If @a __pos is beyond the end of this
1075 * string.
1076 *
1077 * Inserts the first @a __n characters of @a __s starting at @a
1078 * __pos. If adding characters causes the length to exceed
1079 * max_size(), length_error is thrown. If @a __pos is beyond
1080 * end(), out_of_range is thrown. The value of the string
1081 * doesn't change if an error is thrown.
1082 */
1083 __versa_string&
1084 insert(size_type __pos, const _CharT* __s, size_type __n)
1085 { return this->replace(__pos, size_type(0), __s, __n); }
1086
1087 /**
1088 * @brief Insert a C string.
1089 * @param __pos Iterator referencing location in string to insert at.
1090 * @param __s The C string to insert.
1091 * @return Reference to this string.
1092 * @throw std::length_error If new length exceeds @c max_size().
1093 * @throw std::out_of_range If @a __pos is beyond the end of this
1094 * string.
1095 *
1096 * Inserts the first @a __n characters of @a __s starting at @a
1097 * __pos. If adding characters causes the length to exceed
1098 * max_size(), length_error is thrown. If @a __pos is beyond
1099 * end(), out_of_range is thrown. The value of the string
1100 * doesn't change if an error is thrown.
1101 */
1102 __versa_string&
1103 insert(size_type __pos, const _CharT* __s)
1104 {
1105 __glibcxx_requires_string(__s);
1106 return this->replace(__pos, size_type(0), __s,
1107 traits_type::length(__s));
1108 }
1109
1110 /**
1111 * @brief Insert multiple characters.
1112 * @param __pos Index in string to insert at.
1113 * @param __n Number of characters to insert
1114 * @param __c The character to insert.
1115 * @return Reference to this string.
1116 * @throw std::length_error If new length exceeds @c max_size().
1117 * @throw std::out_of_range If @a __pos is beyond the end of this
1118 * string.
1119 *
1120 * Inserts @a __n copies of character @a __c starting at index
1121 * @a __pos. If adding characters causes the length to exceed
1122 * max_size(), length_error is thrown. If @a __pos > length(),
1123 * out_of_range is thrown. The value of the string doesn't
1124 * change if an error is thrown.
1125 */
1126 __versa_string&
1127 insert(size_type __pos, size_type __n, _CharT __c)
1128 { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
1129 size_type(0), __n, __c); }
1130
1131 /**
1132 * @brief Insert one character.
1133 * @param __p Iterator referencing position in string to insert at.
1134 * @param __c The character to insert.
1135 * @return Iterator referencing newly inserted char.
1136 * @throw std::length_error If new length exceeds @c max_size().
1137 *
1138 * Inserts character @a __c at position referenced by @a __p.
1139 * If adding character causes the length to exceed max_size(),
1140 * length_error is thrown. If @a __p is beyond end of string,
1141 * out_of_range is thrown. The value of the string doesn't
1142 * change if an error is thrown.
1143 */
1144 iterator
1145#if __cplusplus >= 201103L
1146 insert(const_iterator __p, _CharT __c)
1147#else
1148 insert(iterator __p, _CharT __c)
1149#endif
1150 {
1151 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1152 const size_type __pos = __p - _M_ibegin();
1153 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1154 this->_M_set_leaked();
1155 return iterator(this->_M_data() + __pos);
1156 }
1157
1158 /**
1159 * @brief Remove characters.
1160 * @param __pos Index of first character to remove (default 0).
1161 * @param __n Number of characters to remove (default remainder).
1162 * @return Reference to this string.
1163 * @throw std::out_of_range If @a __pos is beyond the end of this
1164 * string.
1165 *
1166 * Removes @a __n characters from this string starting at @a
1167 * __pos. The length of the string is reduced by @a __n. If
1168 * there are < @a __n characters to remove, the remainder of
1169 * the string is truncated. If @a __p is beyond end of string,
1170 * out_of_range is thrown. The value of the string doesn't
1171 * change if an error is thrown.
1172 */
1173 __versa_string&
1174 erase(size_type __pos = 0, size_type __n = npos)
1175 {
1176 this->_M_erase(_M_check(__pos, "__versa_string::erase"),
1177 _M_limit(__pos, __n));
1178 return *this;
1179 }
1180
1181 /**
1182 * @brief Remove one character.
1183 * @param __position Iterator referencing the character to remove.
1184 * @return iterator referencing same location after removal.
1185 *
1186 * Removes the character at @a __position from this string. The
1187 * value of the string doesn't change if an error is thrown.
1188 */
1189 iterator
1190#if __cplusplus >= 201103L
1191 erase(const_iterator __position)
1192#else
1193 erase(iterator __position)
1194#endif
1195 {
1196 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1197 && __position < _M_iend());
1198 const size_type __pos = __position - _M_ibegin();
1199 this->_M_erase(__pos, size_type(1));
1200 this->_M_set_leaked();
1201 return iterator(this->_M_data() + __pos);
1202 }
1203
1204 /**
1205 * @brief Remove a range of characters.
1206 * @param __first Iterator referencing the first character to remove.
1207 * @param __last Iterator referencing the end of the range.
1208 * @return Iterator referencing location of first after removal.
1209 *
1210 * Removes the characters in the range [first,last) from this
1211 * string. The value of the string doesn't change if an error
1212 * is thrown.
1213 */
1214 iterator
1215#if __cplusplus >= 201103L
1216 erase(const_iterator __first, const_iterator __last)
1217#else
1218 erase(iterator __first, iterator __last)
1219#endif
1220 {
1221 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1222 && __last <= _M_iend());
1223 const size_type __pos = __first - _M_ibegin();
1224 this->_M_erase(__pos, __last - __first);
1225 this->_M_set_leaked();
1226 return iterator(this->_M_data() + __pos);
1227 }
1228
1229#if __cplusplus >= 201103L
1230 /**
1231 * @brief Remove the last character.
1232 *
1233 * The string must be non-empty.
1234 */
1235 void
1236 pop_back()
1237 { this->_M_erase(size()-1, 1); }
1238#endif // C++11
1239
1240 /**
1241 * @brief Replace characters with value from another string.
1242 * @param __pos Index of first character to replace.
1243 * @param __n Number of characters to be replaced.
1244 * @param __str String to insert.
1245 * @return Reference to this string.
1246 * @throw std::out_of_range If @a __pos is beyond the end of this
1247 * string.
1248 * @throw std::length_error If new length exceeds @c max_size().
1249 *
1250 * Removes the characters in the range [pos,pos+n) from this
1251 * string. In place, the value of @a __str is inserted. If @a
1252 * __pos is beyond end of string, out_of_range is thrown. If
1253 * the length of the result exceeds max_size(), length_error is
1254 * thrown. The value of the string doesn't change if an error
1255 * is thrown.
1256 */
1257 __versa_string&
1258 replace(size_type __pos, size_type __n, const __versa_string& __str)
1259 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1260
1261 /**
1262 * @brief Replace characters with value from another string.
1263 * @param __pos1 Index of first character to replace.
1264 * @param __n1 Number of characters to be replaced.
1265 * @param __str String to insert.
1266 * @param __pos2 Index of first character of str to use.
1267 * @param __n2 Number of characters from str to use.
1268 * @return Reference to this string.
1269 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
1270 * str.size().
1271 * @throw std::length_error If new length exceeds @c max_size().
1272 *
1273 * Removes the characters in the range [pos1,pos1 + n) from
1274 * this string. In place, the value of @a __str is inserted.
1275 * If @a __pos is beyond end of string, out_of_range is thrown.
1276 * If the length of the result exceeds max_size(), length_error
1277 * is thrown. The value of the string doesn't change if an
1278 * error is thrown.
1279 */
1280 __versa_string&
1281 replace(size_type __pos1, size_type __n1, const __versa_string& __str,
1282 size_type __pos2, size_type __n2)
1283 {
1284 return this->replace(__pos1, __n1, __str._M_data()
1285 + __str._M_check(__pos2,
1286 "__versa_string::replace"),
1287 __str._M_limit(__pos2, __n2));
1288 }
1289
1290 /**
1291 * @brief Replace characters with value of a C substring.
1292 * @param __pos Index of first character to replace.
1293 * @param __n1 Number of characters to be replaced.
1294 * @param __s C string to insert.
1295 * @param __n2 Number of characters from @a __s to use.
1296 * @return Reference to this string.
1297 * @throw std::out_of_range If @a __pos1 > size().
1298 * @throw std::length_error If new length exceeds @c max_size().
1299 *
1300 * Removes the characters in the range [pos,pos + n1) from this
1301 * string. In place, the first @a __n2 characters of @a __s
1302 * are inserted, or all of @a __s if @a __n2 is too large. If
1303 * @a __pos is beyond end of string, out_of_range is thrown.
1304 * If the length of result exceeds max_size(), length_error is
1305 * thrown. The value of the string doesn't change if an error
1306 * is thrown.
1307 */
1308 __versa_string&
1309 replace(size_type __pos, size_type __n1, const _CharT* __s,
1310 size_type __n2)
1311 {
1312 __glibcxx_requires_string_len(__s, __n2);
1313 return _M_replace(_M_check(__pos, "__versa_string::replace"),
1314 _M_limit(__pos, __n1), __s, __n2);
1315 }
1316
1317 /**
1318 * @brief Replace characters with value of a C string.
1319 * @param __pos Index of first character to replace.
1320 * @param __n1 Number of characters to be replaced.
1321 * @param __s C string to insert.
1322 * @return Reference to this string.
1323 * @throw std::out_of_range If @a __pos > size().
1324 * @throw std::length_error If new length exceeds @c max_size().
1325 *
1326 * Removes the characters in the range [pos,pos + n1) from this
1327 * string. In place, the characters of @a __s are inserted. If
1328 * @a pos is beyond end of string, out_of_range is thrown. If
1329 * the length of result exceeds max_size(), length_error is thrown.
1330 * The value of the string doesn't change if an error is thrown.
1331 */
1332 __versa_string&
1333 replace(size_type __pos, size_type __n1, const _CharT* __s)
1334 {
1335 __glibcxx_requires_string(__s);
1336 return this->replace(__pos, __n1, __s, traits_type::length(__s));
1337 }
1338
1339 /**
1340 * @brief Replace characters with multiple characters.
1341 * @param __pos Index of first character to replace.
1342 * @param __n1 Number of characters to be replaced.
1343 * @param __n2 Number of characters to insert.
1344 * @param __c Character to insert.
1345 * @return Reference to this string.
1346 * @throw std::out_of_range If @a __pos > size().
1347 * @throw std::length_error If new length exceeds @c max_size().
1348 *
1349 * Removes the characters in the range [pos,pos + n1) from this
1350 * string. In place, @a __n2 copies of @a __c are inserted.
1351 * If @a __pos is beyond end of string, out_of_range is thrown.
1352 * If the length of result exceeds max_size(), length_error is
1353 * thrown. The value of the string doesn't change if an error
1354 * is thrown.
1355 */
1356 __versa_string&
1357 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1358 { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
1359 _M_limit(__pos, __n1), __n2, __c); }
1360
1361 /**
1362 * @brief Replace range of characters with string.
1363 * @param __i1 Iterator referencing start of range to replace.
1364 * @param __i2 Iterator referencing end of range to replace.
1365 * @param __str String value to insert.
1366 * @return Reference to this string.
1367 * @throw std::length_error If new length exceeds @c max_size().
1368 *
1369 * Removes the characters in the range [i1,i2). In place, the
1370 * value of @a __str is inserted. If the length of result
1371 * exceeds max_size(), length_error is thrown. The value of
1372 * the string doesn't change if an error is thrown.
1373 */
1374 __versa_string&
1375#if __cplusplus >= 201103L
1376 replace(const_iterator __i1, const_iterator __i2,
1377 const __versa_string& __str)
1378#else
1379 replace(iterator __i1, iterator __i2, const __versa_string& __str)
1380#endif
1381 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1382
1383 /**
1384 * @brief Replace range of characters with C substring.
1385 * @param __i1 Iterator referencing start of range to replace.
1386 * @param __i2 Iterator referencing end of range to replace.
1387 * @param __s C string value to insert.
1388 * @param __n Number of characters from s to insert.
1389 * @return Reference to this string.
1390 * @throw std::length_error If new length exceeds @c max_size().
1391 *
1392 * Removes the characters in the range [i1,i2). In place, the
1393 * first @a n characters of @a __s are inserted. If the length
1394 * of result exceeds max_size(), length_error is thrown. The
1395 * value of the string doesn't change if an error is thrown.
1396 */
1397 __versa_string&
1398#if __cplusplus >= 201103L
1399 replace(const_iterator __i1, const_iterator __i2,
1400 const _CharT* __s, size_type __n)
1401#else
1402 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1403#endif
1404 {
1405 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1406 && __i2 <= _M_iend());
1407 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1408 }
1409
1410 /**
1411 * @brief Replace range of characters with C string.
1412 * @param __i1 Iterator referencing start of range to replace.
1413 * @param __i2 Iterator referencing end of range to replace.
1414 * @param __s C string value to insert.
1415 * @return Reference to this string.
1416 * @throw std::length_error If new length exceeds @c max_size().
1417 *
1418 * Removes the characters in the range [i1,i2). In place, the
1419 * characters of @a __s are inserted. If the length of result
1420 * exceeds max_size(), length_error is thrown. The value of
1421 * the string doesn't change if an error is thrown.
1422 */
1423 __versa_string&
1424#if __cplusplus >= 201103L
1425 replace(const_iterator __i1, const_iterator __i2, const _CharT* __s)
1426#else
1427 replace(iterator __i1, iterator __i2, const _CharT* __s)
1428#endif
1429 {
1430 __glibcxx_requires_string(__s);
1431 return this->replace(__i1, __i2, __s, traits_type::length(__s));
1432 }
1433
1434 /**
1435 * @brief Replace range of characters with multiple characters
1436 * @param __i1 Iterator referencing start of range to replace.
1437 * @param __i2 Iterator referencing end of range to replace.
1438 * @param __n Number of characters to insert.
1439 * @param __c Character to insert.
1440 * @return Reference to this string.
1441 * @throw std::length_error If new length exceeds @c max_size().
1442 *
1443 * Removes the characters in the range [i1,i2). In place, @a
1444 * __n copies of @a __c are inserted. If the length of result
1445 * exceeds max_size(), length_error is thrown. The value of
1446 * the string doesn't change if an error is thrown.
1447 */
1448 __versa_string&
1449#if __cplusplus >= 201103L
1450 replace(const_iterator __i1, const_iterator __i2, size_type __n,
1451 _CharT __c)
1452#else
1453 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1454#endif
1455 {
1456 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1457 && __i2 <= _M_iend());
1458 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1459 }
1460
1461 /**
1462 * @brief Replace range of characters with range.
1463 * @param __i1 Iterator referencing start of range to replace.
1464 * @param __i2 Iterator referencing end of range to replace.
1465 * @param __k1 Iterator referencing start of range to insert.
1466 * @param __k2 Iterator referencing end of range to insert.
1467 * @return Reference to this string.
1468 * @throw std::length_error If new length exceeds @c max_size().
1469 *
1470 * Removes the characters in the range [i1,i2). In place,
1471 * characters in the range [k1,k2) are inserted. If the length
1472 * of result exceeds max_size(), length_error is thrown. The
1473 * value of the string doesn't change if an error is thrown.
1474 */
1475#if __cplusplus >= 201103L
1476 template<class _InputIterator,
1477 typename = std::_RequireInputIter<_InputIterator>>
1478 __versa_string&
1479 replace(const_iterator __i1, const_iterator __i2,
1480 _InputIterator __k1, _InputIterator __k2)
1481 {
1482 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1483 && __i2 <= _M_iend());
1484 __glibcxx_requires_valid_range(__k1, __k2);
1485 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
1486 std::__false_type());
1487 }
1488#else
1489 template<class _InputIterator>
1490 __versa_string&
1491 replace(iterator __i1, iterator __i2,
1492 _InputIterator __k1, _InputIterator __k2)
1493 {
1494 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1495 && __i2 <= _M_iend());
1496 __glibcxx_requires_valid_range(__k1, __k2);
1497 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1498 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1499 }
1500#endif
1501
1502 // Specializations for the common case of pointer and iterator:
1503 // useful to avoid the overhead of temporary buffering in _M_replace.
1504 __versa_string&
1505#if __cplusplus >= 201103L
1506 replace(const_iterator __i1, const_iterator __i2,
1507 _CharT* __k1, _CharT* __k2)
1508#else
1509 replace(iterator __i1, iterator __i2,
1510 _CharT* __k1, _CharT* __k2)
1511#endif
1512 {
1513 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1514 && __i2 <= _M_iend());
1515 __glibcxx_requires_valid_range(__k1, __k2);
1516 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1517 __k1, __k2 - __k1);
1518 }
1519
1520 __versa_string&
1521#if __cplusplus >= 201103L
1522 replace(const_iterator __i1, const_iterator __i2,
1523 const _CharT* __k1, const _CharT* __k2)
1524#else
1525 replace(iterator __i1, iterator __i2,
1526 const _CharT* __k1, const _CharT* __k2)
1527#endif
1528 {
1529 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1530 && __i2 <= _M_iend());
1531 __glibcxx_requires_valid_range(__k1, __k2);
1532 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1533 __k1, __k2 - __k1);
1534 }
1535
1536 __versa_string&
1537#if __cplusplus >= 201103L
1538 replace(const_iterator __i1, const_iterator __i2,
1539 iterator __k1, iterator __k2)
1540#else
1541 replace(iterator __i1, iterator __i2,
1542 iterator __k1, iterator __k2)
1543#endif
1544 {
1545 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1546 && __i2 <= _M_iend());
1547 __glibcxx_requires_valid_range(__k1, __k2);
1548 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1549 __k1.base(), __k2 - __k1);
1550 }
1551
1552 __versa_string&
1553#if __cplusplus >= 201103L
1554 replace(const_iterator __i1, const_iterator __i2,
1555 const_iterator __k1, const_iterator __k2)
1556#else
1557 replace(iterator __i1, iterator __i2,
1558 const_iterator __k1, const_iterator __k2)
1559#endif
1560 {
1561 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1562 && __i2 <= _M_iend());
1563 __glibcxx_requires_valid_range(__k1, __k2);
1564 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1565 __k1.base(), __k2 - __k1);
1566 }
1567
1568#if __cplusplus >= 201103L
1569 /**
1570 * @brief Replace range of characters with initializer_list.
1571 * @param __i1 Iterator referencing start of range to replace.
1572 * @param __i2 Iterator referencing end of range to replace.
1573 * @param __l The initializer_list of characters to insert.
1574 * @return Reference to this string.
1575 * @throw std::length_error If new length exceeds @c max_size().
1576 *
1577 * Removes the characters in the range [i1,i2). In place,
1578 * characters in the range [k1,k2) are inserted. If the length
1579 * of result exceeds max_size(), length_error is thrown. The
1580 * value of the string doesn't change if an error is thrown.
1581 */
1582 __versa_string&
1583 replace(const_iterator __i1, const_iterator __i2,
1584 std::initializer_list<_CharT> __l)
1585 { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
1586#endif // C++11
1587
1588 private:
1589 template<class _Integer>
1590 __versa_string&
1591 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
1592 _Integer __n, _Integer __val, std::__true_type)
1593 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1594
1595 template<class _InputIterator>
1596 __versa_string&
1597 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
1598 _InputIterator __k1, _InputIterator __k2,
1599 std::__false_type);
1600
1601 __versa_string&
1602 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1603 _CharT __c);
1604
1605 __versa_string&
1606 _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
1607 const size_type __len2);
1608
1609 __versa_string&
1610 _M_append(const _CharT* __s, size_type __n);
1611
1612 public:
1613
1614 /**
1615 * @brief Copy substring into C string.
1616 * @param __s C string to copy value into.
1617 * @param __n Number of characters to copy.
1618 * @param __pos Index of first character to copy.
1619 * @return Number of characters actually copied
1620 * @throw std::out_of_range If pos > size().
1621 *
1622 * Copies up to @a __n characters starting at @a __pos into the
1623 * C string @a s. If @a __pos is greater than size(),
1624 * out_of_range is thrown.
1625 */
1626 size_type
1627 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1628
1629 /**
1630 * @brief Swap contents with another string.
1631 * @param __s String to swap with.
1632 *
1633 * Exchanges the contents of this string with that of @a __s in
1634 * constant time.
1635 */
1636 void
1637 swap(__versa_string& __s) _GLIBCXX_NOEXCEPT
1638 { this->_M_swap(__s); }
1639
1640 // String operations:
1641 /**
1642 * @brief Return const pointer to null-terminated contents.
1643 *
1644 * This is a handle to internal data. Do not modify or dire things may
1645 * happen.
1646 */
1647 const _CharT*
1648 c_str() const _GLIBCXX_NOEXCEPT
1649 { return this->_M_data(); }
1650
1651 /**
1652 * @brief Return const pointer to contents.
1653 *
1654 * This is a handle to internal data. Do not modify or dire things may
1655 * happen.
1656 */
1657 const _CharT*
1658 data() const _GLIBCXX_NOEXCEPT
1659 { return this->_M_data(); }
1660
1661 /**
1662 * @brief Return copy of allocator used to construct this string.
1663 */
1664 allocator_type
1665 get_allocator() const _GLIBCXX_NOEXCEPT
1666 { return allocator_type(this->_M_get_allocator()); }
1667
1668 /**
1669 * @brief Find position of a C substring.
1670 * @param __s C string to locate.
1671 * @param __pos Index of character to search from.
1672 * @param __n Number of characters from @a __s to search for.
1673 * @return Index of start of first occurrence.
1674 *
1675 * Starting from @a __pos, searches forward for the first @a
1676 * __n characters in @a __s within this string. If found,
1677 * returns the index where it begins. If not found, returns
1678 * npos.
1679 */
1680 size_type
1681 find(const _CharT* __s, size_type __pos, size_type __n) const;
1682
1683 /**
1684 * @brief Find position of a string.
1685 * @param __str String to locate.
1686 * @param __pos Index of character to search from (default 0).
1687 * @return Index of start of first occurrence.
1688 *
1689 * Starting from @a __pos, searches forward for value of @a
1690 * __str within this string. If found, returns the index where
1691 * it begins. If not found, returns npos.
1692 */
1693 size_type
1694 find(const __versa_string& __str, size_type __pos = 0) const
1695 _GLIBCXX_NOEXCEPT
1696 { return this->find(__str.data(), __pos, __str.size()); }
1697
1698 /**
1699 * @brief Find position of a C string.
1700 * @param __s C string to locate.
1701 * @param __pos Index of character to search from (default 0).
1702 * @return Index of start of first occurrence.
1703 *
1704 * Starting from @a __pos, searches forward for the value of @a
1705 * __s within this string. If found, returns the index where
1706 * it begins. If not found, returns npos.
1707 */
1708 size_type
1709 find(const _CharT* __s, size_type __pos = 0) const
1710 {
1711 __glibcxx_requires_string(__s);
1712 return this->find(__s, __pos, traits_type::length(__s));
1713 }
1714
1715 /**
1716 * @brief Find position of a character.
1717 * @param __c Character to locate.
1718 * @param __pos Index of character to search from (default 0).
1719 * @return Index of first occurrence.
1720 *
1721 * Starting from @a __pos, searches forward for @a __c within
1722 * this string. If found, returns the index where it was
1723 * found. If not found, returns npos.
1724 */
1725 size_type
1726 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
1727
1728 /**
1729 * @brief Find last position of a string.
1730 * @param __str String to locate.
1731 * @param __pos Index of character to search back from (default end).
1732 * @return Index of start of last occurrence.
1733 *
1734 * Starting from @a __pos, searches backward for value of @a
1735 * __str within this string. If found, returns the index where
1736 * it begins. If not found, returns npos.
1737 */
1738 size_type
1739 rfind(const __versa_string& __str, size_type __pos = npos) const
1740 _GLIBCXX_NOEXCEPT
1741 { return this->rfind(__str.data(), __pos, __str.size()); }
1742
1743 /**
1744 * @brief Find last position of a C substring.
1745 * @param __s C string to locate.
1746 * @param __pos Index of character to search back from.
1747 * @param __n Number of characters from s to search for.
1748 * @return Index of start of last occurrence.
1749 *
1750 * Starting from @a __pos, searches backward for the first @a
1751 * __n characters in @a __s within this string. If found,
1752 * returns the index where it begins. If not found, returns
1753 * npos.
1754 */
1755 size_type
1756 rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1757
1758 /**
1759 * @brief Find last position of a C string.
1760 * @param __s C string to locate.
1761 * @param __pos Index of character to start search at (default end).
1762 * @return Index of start of last occurrence.
1763 *
1764 * Starting from @a __pos, searches backward for the value of
1765 * @a __s within this string. If found, returns the index
1766 * where it begins. If not found, returns npos.
1767 */
1768 size_type
1769 rfind(const _CharT* __s, size_type __pos = npos) const
1770 {
1771 __glibcxx_requires_string(__s);
1772 return this->rfind(__s, __pos, traits_type::length(__s));
1773 }
1774
1775 /**
1776 * @brief Find last position of a character.
1777 * @param __c Character to locate.
1778 * @param __pos Index of character to search back from (default end).
1779 * @return Index of last occurrence.
1780 *
1781 * Starting from @a __pos, searches backward for @a __c within
1782 * this string. If found, returns the index where it was
1783 * found. If not found, returns npos.
1784 */
1785 size_type
1786 rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
1787
1788 /**
1789 * @brief Find position of a character of string.
1790 * @param __str String containing characters to locate.
1791 * @param __pos Index of character to search from (default 0).
1792 * @return Index of first occurrence.
1793 *
1794 * Starting from @a __pos, searches forward for one of the characters of
1795 * @a __str within this string. If found, returns the index where it was
1796 * found. If not found, returns npos.
1797 */
1798 size_type
1799 find_first_of(const __versa_string& __str, size_type __pos = 0) const
1800 _GLIBCXX_NOEXCEPT
1801 { return this->find_first_of(__str.data(), __pos, __str.size()); }
1802
1803 /**
1804 * @brief Find position of a character of C substring.
1805 * @param __s String containing characters to locate.
1806 * @param __pos Index of character to search from.
1807 * @param __n Number of characters from s to search for.
1808 * @return Index of first occurrence.
1809 *
1810 * Starting from @a __pos, searches forward for one of the
1811 * first @a __n characters of @a __s within this string. If
1812 * found, returns the index where it was found. If not found,
1813 * returns npos.
1814 */
1815 size_type
1816 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1817
1818 /**
1819 * @brief Find position of a character of C string.
1820 * @param __s String containing characters to locate.
1821 * @param __pos Index of character to search from (default 0).
1822 * @return Index of first occurrence.
1823 *
1824 * Starting from @a __pos, searches forward for one of the
1825 * characters of @a __s within this string. If found, returns
1826 * the index where it was found. If not found, returns npos.
1827 */
1828 size_type
1829 find_first_of(const _CharT* __s, size_type __pos = 0) const
1830 {
1831 __glibcxx_requires_string(__s);
1832 return this->find_first_of(__s, __pos, traits_type::length(__s));
1833 }
1834
1835 /**
1836 * @brief Find position of a character.
1837 * @param __c Character to locate.
1838 * @param __pos Index of character to search from (default 0).
1839 * @return Index of first occurrence.
1840 *
1841 * Starting from @a __pos, searches forward for the character
1842 * @a __c within this string. If found, returns the index
1843 * where it was found. If not found, returns npos.
1844 *
1845 * Note: equivalent to find(c, pos).
1846 */
1847 size_type
1848 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
1849 { return this->find(__c, __pos); }
1850
1851 /**
1852 * @brief Find last position of a character of string.
1853 * @param __str String containing characters to locate.
1854 * @param __pos Index of character to search back from (default end).
1855 * @return Index of last occurrence.
1856 *
1857 * Starting from @a __pos, searches backward for one of the
1858 * characters of @a __str within this string. If found,
1859 * returns the index where it was found. If not found, returns
1860 * npos.
1861 */
1862 size_type
1863 find_last_of(const __versa_string& __str, size_type __pos = npos) const
1864 _GLIBCXX_NOEXCEPT
1865 { return this->find_last_of(__str.data(), __pos, __str.size()); }
1866
1867 /**
1868 * @brief Find last position of a character of C substring.
1869 * @param __s C string containing characters to locate.
1870 * @param __pos Index of character to search back from.
1871 * @param __n Number of characters from s to search for.
1872 * @return Index of last occurrence.
1873 *
1874 * Starting from @a __pos, searches backward for one of the
1875 * first @a __n characters of @a __s within this string. If
1876 * found, returns the index where it was found. If not found,
1877 * returns npos.
1878 */
1879 size_type
1880 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1881
1882 /**
1883 * @brief Find last position of a character of C string.
1884 * @param __s C string containing characters to locate.
1885 * @param __pos Index of character to search back from (default end).
1886 * @return Index of last occurrence.
1887 *
1888 * Starting from @a __pos, searches backward for one of the
1889 * characters of @a __s within this string. If found, returns
1890 * the index where it was found. If not found, returns npos.
1891 */
1892 size_type
1893 find_last_of(const _CharT* __s, size_type __pos = npos) const
1894 {
1895 __glibcxx_requires_string(__s);
1896 return this->find_last_of(__s, __pos, traits_type::length(__s));
1897 }
1898
1899 /**
1900 * @brief Find last position of a character.
1901 * @param __c Character to locate.
1902 * @param __pos Index of character to search back from (default end).
1903 * @return Index of last occurrence.
1904 *
1905 * Starting from @a __pos, searches backward for @a __c within
1906 * this string. If found, returns the index where it was
1907 * found. If not found, returns npos.
1908 *
1909 * Note: equivalent to rfind(c, pos).
1910 */
1911 size_type
1912 find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1913 { return this->rfind(__c, __pos); }
1914
1915 /**
1916 * @brief Find position of a character not in string.
1917 * @param __str String containing characters to avoid.
1918 * @param __pos Index of character to search from (default 0).
1919 * @return Index of first occurrence.
1920 *
1921 * Starting from @a __pos, searches forward for a character not
1922 * contained in @a __str within this string. If found, returns
1923 * the index where it was found. If not found, returns npos.
1924 */
1925 size_type
1926 find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
1927 _GLIBCXX_NOEXCEPT
1928 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1929
1930 /**
1931 * @brief Find position of a character not in C substring.
1932 * @param __s C string containing characters to avoid.
1933 * @param __pos Index of character to search from.
1934 * @param __n Number of characters from s to consider.
1935 * @return Index of first occurrence.
1936 *
1937 * Starting from @a __pos, searches forward for a character not
1938 * contained in the first @a __n characters of @a __s within
1939 * this string. If found, returns the index where it was
1940 * found. If not found, returns npos.
1941 */
1942 size_type
1943 find_first_not_of(const _CharT* __s, size_type __pos,
1944 size_type __n) const;
1945
1946 /**
1947 * @brief Find position of a character not in C string.
1948 * @param __s C string containing characters to avoid.
1949 * @param __pos Index of character to search from (default 0).
1950 * @return Index of first occurrence.
1951 *
1952 * Starting from @a __pos, searches forward for a character not
1953 * contained in @a __s within this string. If found, returns
1954 * the index where it was found. If not found, returns npos.
1955 */
1956 size_type
1957 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1958 {
1959 __glibcxx_requires_string(__s);
1960 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1961 }
1962
1963 /**
1964 * @brief Find position of a different character.
1965 * @param __c Character to avoid.
1966 * @param __pos Index of character to search from (default 0).
1967 * @return Index of first occurrence.
1968 *
1969 * Starting from @a __pos, searches forward for a character
1970 * other than @a __c within this string. If found, returns the
1971 * index where it was found. If not found, returns npos.
1972 */
1973 size_type
1974 find_first_not_of(_CharT __c, size_type __pos = 0) const
1975 _GLIBCXX_NOEXCEPT;
1976
1977 /**
1978 * @brief Find last position of a character not in string.
1979 * @param __str String containing characters to avoid.
1980 * @param __pos Index of character to search back from (default end).
1981 * @return Index of last occurrence.
1982 *
1983 * Starting from @a __pos, searches backward for a character
1984 * not contained in @a __str within this string. If found,
1985 * returns the index where it was found. If not found, returns
1986 * npos.
1987 */
1988 size_type
1989 find_last_not_of(const __versa_string& __str,
1990 size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1991 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1992
1993 /**
1994 * @brief Find last position of a character not in C substring.
1995 * @param __s C string containing characters to avoid.
1996 * @param __pos Index of character to search back from.
1997 * @param __n Number of characters from s to consider.
1998 * @return Index of last occurrence.
1999 *
2000 * Starting from @a __pos, searches backward for a character
2001 * not contained in the first @a __n characters of @a __s
2002 * within this string. If found, returns the index where it
2003 * was found. If not found, returns npos.
2004 */
2005 size_type
2006 find_last_not_of(const _CharT* __s, size_type __pos,
2007 size_type __n) const;
2008 /**
2009 * @brief Find last position of a character not in C string.
2010 * @param __s C string containing characters to avoid.
2011 * @param __pos Index of character to search back from (default end).
2012 * @return Index of last occurrence.
2013 *
2014 * Starting from @a __pos, searches backward for a character
2015 * not contained in @a __s within this string. If found,
2016 * returns the index where it was found. If not found, returns
2017 * npos.
2018 */
2019 size_type
2020 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
2021 {
2022 __glibcxx_requires_string(__s);
2023 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
2024 }
2025
2026 /**
2027 * @brief Find last position of a different character.
2028 * @param __c Character to avoid.
2029 * @param __pos Index of character to search back from (default end).
2030 * @return Index of last occurrence.
2031 *
2032 * Starting from @a __pos, searches backward for a character
2033 * other than @a __c within this string. If found, returns the
2034 * index where it was found. If not found, returns npos.
2035 */
2036 size_type
2037 find_last_not_of(_CharT __c, size_type __pos = npos) const
2038 _GLIBCXX_NOEXCEPT;
2039
2040 /**
2041 * @brief Get a substring.
2042 * @param __pos Index of first character (default 0).
2043 * @param __n Number of characters in substring (default remainder).
2044 * @return The new string.
2045 * @throw std::out_of_range If pos > size().
2046 *
2047 * Construct and return a new string using the @a __n
2048 * characters starting at @a __pos. If the string is too
2049 * short, use the remainder of the characters. If @a __pos is
2050 * beyond the end of the string, out_of_range is thrown.
2051 */
2052 __versa_string
2053 substr(size_type __pos = 0, size_type __n = npos) const
2054 {
2055 return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
2056 __n);
2057 }
2058
2059 /**
2060 * @brief Compare to a string.
2061 * @param __str String to compare against.
2062 * @return Integer < 0, 0, or > 0.
2063 *
2064 * Returns an integer < 0 if this string is ordered before @a
2065 * __str, 0 if their values are equivalent, or > 0 if this
2066 * string is ordered after @a __str. Determines the effective
2067 * length rlen of the strings to compare as the smallest of
2068 * size() and str.size(). The function then compares the two
2069 * strings by calling traits::compare(data(), str.data(),rlen).
2070 * If the result of the comparison is nonzero returns it,
2071 * otherwise the shorter one is ordered first.
2072 */
2073 int
2074 compare(const __versa_string& __str) const
2075 {
2076 if (this->_M_compare(__str))
2077 return 0;
2078
2079 const size_type __size = this->size();
2080 const size_type __osize = __str.size();
2081 const size_type __len = std::min(__size, __osize);
2082
2083 int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
2084 if (!__r)
2085 __r = this->_S_compare(__size, __osize);
2086 return __r;
2087 }
2088
2089 /**
2090 * @brief Compare substring to a string.
2091 * @param __pos Index of first character of substring.
2092 * @param __n Number of characters in substring.
2093 * @param __str String to compare against.
2094 * @return Integer < 0, 0, or > 0.
2095 *
2096 * Form the substring of this string from the @a __n characters
2097 * starting at @a __pos. Returns an integer < 0 if the
2098 * substring is ordered before @a __str, 0 if their values are
2099 * equivalent, or > 0 if the substring is ordered after @a
2100 * __str. Determines the effective length rlen of the strings
2101 * to compare as the smallest of the length of the substring
2102 * and @a __str.size(). The function then compares the two
2103 * strings by calling
2104 * traits::compare(substring.data(),str.data(),rlen). If the
2105 * result of the comparison is nonzero returns it, otherwise
2106 * the shorter one is ordered first.
2107 */
2108 int
2109 compare(size_type __pos, size_type __n,
2110 const __versa_string& __str) const;
2111
2112 /**
2113 * @brief Compare substring to a substring.
2114 * @param __pos1 Index of first character of substring.
2115 * @param __n1 Number of characters in substring.
2116 * @param __str String to compare against.
2117 * @param __pos2 Index of first character of substring of str.
2118 * @param __n2 Number of characters in substring of str.
2119 * @return Integer < 0, 0, or > 0.
2120 *
2121 * Form the substring of this string from the @a __n1
2122 * characters starting at @a __pos1. Form the substring of @a
2123 * __str from the @a __n2 characters starting at @a __pos2.
2124 * Returns an integer < 0 if this substring is ordered before
2125 * the substring of @a __str, 0 if their values are equivalent,
2126 * or > 0 if this substring is ordered after the substring of
2127 * @a __str. Determines the effective length rlen of the
2128 * strings to compare as the smallest of the lengths of the
2129 * substrings. The function then compares the two strings by
2130 * calling
2131 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
2132 * If the result of the comparison is nonzero returns it,
2133 * otherwise the shorter one is ordered first.
2134 */
2135 int
2136 compare(size_type __pos1, size_type __n1, const __versa_string& __str,
2137 size_type __pos2, size_type __n2) const;
2138
2139 /**
2140 * @brief Compare to a C string.
2141 * @param __s C string to compare against.
2142 * @return Integer < 0, 0, or > 0.
2143 *
2144 * Returns an integer < 0 if this string is ordered before @a
2145 * __s, 0 if their values are equivalent, or > 0 if this string
2146 * is ordered after @a __s. Determines the effective length
2147 * rlen of the strings to compare as the smallest of size() and
2148 * the length of a string constructed from @a __s. The
2149 * function then compares the two strings by calling
2150 * traits::compare(data(),s,rlen). If the result of the
2151 * comparison is nonzero returns it, otherwise the shorter one
2152 * is ordered first.
2153 */
2154 int
2155 compare(const _CharT* __s) const;
2156
2157 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2158 // 5 String::compare specification questionable
2159 /**
2160 * @brief Compare substring to a C string.
2161 * @param __pos Index of first character of substring.
2162 * @param __n1 Number of characters in substring.
2163 * @param __s C string to compare against.
2164 * @return Integer < 0, 0, or > 0.
2165 *
2166 * Form the substring of this string from the @a __n1
2167 * characters starting at @a __pos. Returns an integer < 0 if
2168 * the substring is ordered before @a __s, 0 if their values
2169 * are equivalent, or > 0 if the substring is ordered after @a
2170 * __s. Determines the effective length rlen of the strings to
2171 * compare as the smallest of the length of the substring and
2172 * the length of a string constructed from @a __s. The
2173 * function then compares the two string by calling
2174 * traits::compare(substring.data(),s,rlen). If the result of
2175 * the comparison is nonzero returns it, otherwise the shorter
2176 * one is ordered first.
2177 */
2178 int
2179 compare(size_type __pos, size_type __n1, const _CharT* __s) const;
2180
2181 /**
2182 * @brief Compare substring against a character array.
2183 * @param __pos Index of first character of substring.
2184 * @param __n1 Number of characters in substring.
2185 * @param __s character array to compare against.
2186 * @param __n2 Number of characters of s.
2187 * @return Integer < 0, 0, or > 0.
2188 *
2189 * Form the substring of this string from the @a __n1
2190 * characters starting at @a __pos. Form a string from the
2191 * first @a __n2 characters of @a __s. Returns an integer < 0
2192 * if this substring is ordered before the string from @a __s,
2193 * 0 if their values are equivalent, or > 0 if this substring
2194 * is ordered after the string from @a __s. Determines the
2195 * effective length rlen of the strings to compare as the
2196 * smallest of the length of the substring and @a __n2. The
2197 * function then compares the two strings by calling
2198 * traits::compare(substring.data(),__s,rlen). If the result of
2199 * the comparison is nonzero returns it, otherwise the shorter
2200 * one is ordered first.
2201 *
2202 * NB: __s must have at least n2 characters, <em>\\0</em> has no special
2203 * meaning.
2204 */
2205 int
2206 compare(size_type __pos, size_type __n1, const _CharT* __s,
2207 size_type __n2) const;
2208 };
2209
2210 // operator+
2211 /**
2212 * @brief Concatenate two strings.
2213 * @param __lhs First string.
2214 * @param __rhs Last string.
2215 * @return New string with value of @a __lhs followed by @a __rhs.
2216 */
2217 template<typename _CharT, typename _Traits, typename _Alloc,
2218 template <typename, typename, typename> class _Base>
2219 __versa_string<_CharT, _Traits, _Alloc, _Base>
2220 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2221 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2222
2223 /**
2224 * @brief Concatenate C string and string.
2225 * @param __lhs First string.
2226 * @param __rhs Last string.
2227 * @return New string with value of @a __lhs followed by @a __rhs.
2228 */
2229 template<typename _CharT, typename _Traits, typename _Alloc,
2230 template <typename, typename, typename> class _Base>
2231 __versa_string<_CharT, _Traits, _Alloc, _Base>
2232 operator+(const _CharT* __lhs,
2233 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2234
2235 /**
2236 * @brief Concatenate character and string.
2237 * @param __lhs First string.
2238 * @param __rhs Last string.
2239 * @return New string with @a __lhs followed by @a __rhs.
2240 */
2241 template<typename _CharT, typename _Traits, typename _Alloc,
2242 template <typename, typename, typename> class _Base>
2243 __versa_string<_CharT, _Traits, _Alloc, _Base>
2244 operator+(_CharT __lhs,
2245 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2246
2247 /**
2248 * @brief Concatenate string and C string.
2249 * @param __lhs First string.
2250 * @param __rhs Last string.
2251 * @return New string with @a __lhs followed by @a __rhs.
2252 */
2253 template<typename _CharT, typename _Traits, typename _Alloc,
2254 template <typename, typename, typename> class _Base>
2255 __versa_string<_CharT, _Traits, _Alloc, _Base>
2256 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2257 const _CharT* __rhs);
2258
2259 /**
2260 * @brief Concatenate string and character.
2261 * @param __lhs First string.
2262 * @param __rhs Last string.
2263 * @return New string with @a __lhs followed by @a __rhs.
2264 */
2265 template<typename _CharT, typename _Traits, typename _Alloc,
2266 template <typename, typename, typename> class _Base>
2267 __versa_string<_CharT, _Traits, _Alloc, _Base>
2268 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2269 _CharT __rhs);
2270
2271#if __cplusplus >= 201103L
2272 template<typename _CharT, typename _Traits, typename _Alloc,
2273 template <typename, typename, typename> class _Base>
2274 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2275 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2276 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2277 { return std::move(__lhs.append(__rhs)); }
2278
2279 template<typename _CharT, typename _Traits, typename _Alloc,
2280 template <typename, typename, typename> class _Base>
2281 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2282 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2283 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2284 { return std::move(__rhs.insert(0, __lhs)); }
2285
2286 template<typename _CharT, typename _Traits, typename _Alloc,
2287 template <typename, typename, typename> class _Base>
2288 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2289 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2290 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2291 {
2292 const auto __size = __lhs.size() + __rhs.size();
2293 const bool __cond = (__size > __lhs.capacity()
2294 && __size <= __rhs.capacity());
2295 return __cond ? std::move(__rhs.insert(0, __lhs))
2296 : std::move(__lhs.append(__rhs));
2297 }
2298
2299 template<typename _CharT, typename _Traits, typename _Alloc,
2300 template <typename, typename, typename> class _Base>
2301 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2302 operator+(const _CharT* __lhs,
2303 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2304 { return std::move(__rhs.insert(0, __lhs)); }
2305
2306 template<typename _CharT, typename _Traits, typename _Alloc,
2307 template <typename, typename, typename> class _Base>
2308 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2309 operator+(_CharT __lhs,
2310 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2311 { return std::move(__rhs.insert(0, 1, __lhs)); }
2312
2313 template<typename _CharT, typename _Traits, typename _Alloc,
2314 template <typename, typename, typename> class _Base>
2315 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2316 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2317 const _CharT* __rhs)
2318 { return std::move(__lhs.append(__rhs)); }
2319
2320 template<typename _CharT, typename _Traits, typename _Alloc,
2321 template <typename, typename, typename> class _Base>
2322 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2323 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2324 _CharT __rhs)
2325 { return std::move(__lhs.append(1, __rhs)); }
2326#endif
2327
2328 // operator ==
2329 /**
2330 * @brief Test equivalence of two strings.
2331 * @param __lhs First string.
2332 * @param __rhs Second string.
2333 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2334 */
2335 template<typename _CharT, typename _Traits, typename _Alloc,
2336 template <typename, typename, typename> class _Base>
2337 inline bool
2338 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2339 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2340 { return __lhs.compare(__rhs) == 0; }
2341
2342 template<typename _CharT,
2343 template <typename, typename, typename> class _Base>
2344 inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type
2345 operator==(const __versa_string<_CharT, std::char_traits<_CharT>,
2346 std::allocator<_CharT>, _Base>& __lhs,
2347 const __versa_string<_CharT, std::char_traits<_CharT>,
2348 std::allocator<_CharT>, _Base>& __rhs)
2349 { return (__lhs.size() == __rhs.size()
2350 && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
2351 __lhs.size())); }
2352
2353 /**
2354 * @brief Test equivalence of C string and string.
2355 * @param __lhs C string.
2356 * @param __rhs String.
2357 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
2358 */
2359 template<typename _CharT, typename _Traits, typename _Alloc,
2360 template <typename, typename, typename> class _Base>
2361 inline bool
2362 operator==(const _CharT* __lhs,
2363 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2364 { return __rhs.compare(__lhs) == 0; }
2365
2366 /**
2367 * @brief Test equivalence of string and C string.
2368 * @param __lhs String.
2369 * @param __rhs C string.
2370 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2371 */
2372 template<typename _CharT, typename _Traits, typename _Alloc,
2373 template <typename, typename, typename> class _Base>
2374 inline bool
2375 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2376 const _CharT* __rhs)
2377 { return __lhs.compare(__rhs) == 0; }
2378
2379 // operator !=
2380 /**
2381 * @brief Test difference of two strings.
2382 * @param __lhs First string.
2383 * @param __rhs Second string.
2384 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2385 */
2386 template<typename _CharT, typename _Traits, typename _Alloc,
2387 template <typename, typename, typename> class _Base>
2388 inline bool
2389 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2390 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2391 { return !(__lhs == __rhs); }
2392
2393 /**
2394 * @brief Test difference of C string and string.
2395 * @param __lhs C string.
2396 * @param __rhs String.
2397 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
2398 */
2399 template<typename _CharT, typename _Traits, typename _Alloc,
2400 template <typename, typename, typename> class _Base>
2401 inline bool
2402 operator!=(const _CharT* __lhs,
2403 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2404 { return !(__lhs == __rhs); }
2405
2406 /**
2407 * @brief Test difference of string and C string.
2408 * @param __lhs String.
2409 * @param __rhs C string.
2410 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2411 */
2412 template<typename _CharT, typename _Traits, typename _Alloc,
2413 template <typename, typename, typename> class _Base>
2414 inline bool
2415 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2416 const _CharT* __rhs)
2417 { return !(__lhs == __rhs); }
2418
2419 // operator <
2420 /**
2421 * @brief Test if string precedes string.
2422 * @param __lhs First string.
2423 * @param __rhs Second string.
2424 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2425 */
2426 template<typename _CharT, typename _Traits, typename _Alloc,
2427 template <typename, typename, typename> class _Base>
2428 inline bool
2429 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2430 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2431 { return __lhs.compare(__rhs) < 0; }
2432
2433 /**
2434 * @brief Test if string precedes C string.
2435 * @param __lhs String.
2436 * @param __rhs C string.
2437 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2438 */
2439 template<typename _CharT, typename _Traits, typename _Alloc,
2440 template <typename, typename, typename> class _Base>
2441 inline bool
2442 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2443 const _CharT* __rhs)
2444 { return __lhs.compare(__rhs) < 0; }
2445
2446 /**
2447 * @brief Test if C string precedes string.
2448 * @param __lhs C string.
2449 * @param __rhs String.
2450 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2451 */
2452 template<typename _CharT, typename _Traits, typename _Alloc,
2453 template <typename, typename, typename> class _Base>
2454 inline bool
2455 operator<(const _CharT* __lhs,
2456 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2457 { return __rhs.compare(__lhs) > 0; }
2458
2459 // operator >
2460 /**
2461 * @brief Test if string follows string.
2462 * @param __lhs First string.
2463 * @param __rhs Second string.
2464 * @return True if @a __lhs follows @a __rhs. False otherwise.
2465 */
2466 template<typename _CharT, typename _Traits, typename _Alloc,
2467 template <typename, typename, typename> class _Base>
2468 inline bool
2469 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2470 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2471 { return __lhs.compare(__rhs) > 0; }
2472
2473 /**
2474 * @brief Test if string follows C string.
2475 * @param __lhs String.
2476 * @param __rhs C string.
2477 * @return True if @a __lhs follows @a __rhs. False otherwise.
2478 */
2479 template<typename _CharT, typename _Traits, typename _Alloc,
2480 template <typename, typename, typename> class _Base>
2481 inline bool
2482 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2483 const _CharT* __rhs)
2484 { return __lhs.compare(__rhs) > 0; }
2485
2486 /**
2487 * @brief Test if C string follows string.
2488 * @param __lhs C string.
2489 * @param __rhs String.
2490 * @return True if @a __lhs follows @a __rhs. False otherwise.
2491 */
2492 template<typename _CharT, typename _Traits, typename _Alloc,
2493 template <typename, typename, typename> class _Base>
2494 inline bool
2495 operator>(const _CharT* __lhs,
2496 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2497 { return __rhs.compare(__lhs) < 0; }
2498
2499 // operator <=
2500 /**
2501 * @brief Test if string doesn't follow string.
2502 * @param __lhs First string.
2503 * @param __rhs Second string.
2504 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2505 */
2506 template<typename _CharT, typename _Traits, typename _Alloc,
2507 template <typename, typename, typename> class _Base>
2508 inline bool
2509 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2510 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2511 { return __lhs.compare(__rhs) <= 0; }
2512
2513 /**
2514 * @brief Test if string doesn't follow C string.
2515 * @param __lhs String.
2516 * @param __rhs C string.
2517 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2518 */
2519 template<typename _CharT, typename _Traits, typename _Alloc,
2520 template <typename, typename, typename> class _Base>
2521 inline bool
2522 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2523 const _CharT* __rhs)
2524 { return __lhs.compare(__rhs) <= 0; }
2525
2526 /**
2527 * @brief Test if C string doesn't follow string.
2528 * @param __lhs C string.
2529 * @param __rhs String.
2530 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2531 */
2532 template<typename _CharT, typename _Traits, typename _Alloc,
2533 template <typename, typename, typename> class _Base>
2534 inline bool
2535 operator<=(const _CharT* __lhs,
2536 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2537 { return __rhs.compare(__lhs) >= 0; }
2538
2539 // operator >=
2540 /**
2541 * @brief Test if string doesn't precede string.
2542 * @param __lhs First string.
2543 * @param __rhs Second string.
2544 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2545 */
2546 template<typename _CharT, typename _Traits, typename _Alloc,
2547 template <typename, typename, typename> class _Base>
2548 inline bool
2549 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2550 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2551 { return __lhs.compare(__rhs) >= 0; }
2552
2553 /**
2554 * @brief Test if string doesn't precede C string.
2555 * @param __lhs String.
2556 * @param __rhs C string.
2557 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2558 */
2559 template<typename _CharT, typename _Traits, typename _Alloc,
2560 template <typename, typename, typename> class _Base>
2561 inline bool
2562 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2563 const _CharT* __rhs)
2564 { return __lhs.compare(__rhs) >= 0; }
2565
2566 /**
2567 * @brief Test if C string doesn't precede string.
2568 * @param __lhs C string.
2569 * @param __rhs String.
2570 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2571 */
2572 template<typename _CharT, typename _Traits, typename _Alloc,
2573 template <typename, typename, typename> class _Base>
2574 inline bool
2575 operator>=(const _CharT* __lhs,
2576 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2577 { return __rhs.compare(__lhs) <= 0; }
2578
2579 /**
2580 * @brief Swap contents of two strings.
2581 * @param __lhs First string.
2582 * @param __rhs Second string.
2583 *
2584 * Exchanges the contents of @a __lhs and @a __rhs in constant time.
2585 */
2586 template<typename _CharT, typename _Traits, typename _Alloc,
2587 template <typename, typename, typename> class _Base>
2588 inline void
2589 swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2590 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2591 { __lhs.swap(__rhs); }
2592
2593_GLIBCXX_END_NAMESPACE_VERSION
2594} // namespace
2595
2596namespace std _GLIBCXX_VISIBILITY(default)
2597{
2598_GLIBCXX_BEGIN_NAMESPACE_VERSION
2599
2600 /**
2601 * @brief Read stream into a string.
2602 * @param __is Input stream.
2603 * @param __str Buffer to store into.
2604 * @return Reference to the input stream.
2605 *
2606 * Stores characters from @a __is into @a __str until whitespace is
2607 * found, the end of the stream is encountered, or str.max_size()
2608 * is reached. If is.width() is non-zero, that is the limit on the
2609 * number of characters stored into @a __str. Any previous
2610 * contents of @a __str are erased.
2611 */
2612 template<typename _CharT, typename _Traits, typename _Alloc,
2613 template <typename, typename, typename> class _Base>
2614 basic_istream<_CharT, _Traits>&
2615 operator>>(basic_istream<_CharT, _Traits>& __is,
2616 __gnu_cxx::__versa_string<_CharT, _Traits,
2617 _Alloc, _Base>& __str);
2618
2619 /**
2620 * @brief Write string to a stream.
2621 * @param __os Output stream.
2622 * @param __str String to write out.
2623 * @return Reference to the output stream.
2624 *
2625 * Output characters of @a __str into os following the same rules as for
2626 * writing a C string.
2627 */
2628 template<typename _CharT, typename _Traits, typename _Alloc,
2629 template <typename, typename, typename> class _Base>
2630 inline basic_ostream<_CharT, _Traits>&
2631 operator<<(basic_ostream<_CharT, _Traits>& __os,
2632 const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc,
2633 _Base>& __str)
2634 {
2635 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2636 // 586. string inserter not a formatted function
2637 return __ostream_insert(__os, __str.data(), __str.size());
2638 }
2639
2640 /**
2641 * @brief Read a line from stream into a string.
2642 * @param __is Input stream.
2643 * @param __str Buffer to store into.
2644 * @param __delim Character marking end of line.
2645 * @return Reference to the input stream.
2646 *
2647 * Stores characters from @a __is into @a __str until @a __delim is
2648 * found, the end of the stream is encountered, or str.max_size()
2649 * is reached. If is.width() is non-zero, that is the limit on the
2650 * number of characters stored into @a __str. Any previous
2651 * contents of @a __str are erased. If @a delim was encountered,
2652 * it is extracted but not stored into @a __str.
2653 */
2654 template<typename _CharT, typename _Traits, typename _Alloc,
2655 template <typename, typename, typename> class _Base>
2656 basic_istream<_CharT, _Traits>&
2657 getline(basic_istream<_CharT, _Traits>& __is,
2658 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
2659 _CharT __delim);
2660
2661 /**
2662 * @brief Read a line from stream into a string.
2663 * @param __is Input stream.
2664 * @param __str Buffer to store into.
2665 * @return Reference to the input stream.
2666 *
2667 * Stores characters from is into @a __str until &apos;\n&apos; is
2668 * found, the end of the stream is encountered, or str.max_size()
2669 * is reached. If is.width() is non-zero, that is the limit on the
2670 * number of characters stored into @a __str. Any previous
2671 * contents of @a __str are erased. If end of line was
2672 * encountered, it is extracted but not stored into @a __str.
2673 */
2674 template<typename _CharT, typename _Traits, typename _Alloc,
2675 template <typename, typename, typename> class _Base>
2676 inline basic_istream<_CharT, _Traits>&
2677 getline(basic_istream<_CharT, _Traits>& __is,
2678 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
2679 { return getline(__is, __str, __is.widen('\n')); }
2680
2681_GLIBCXX_END_NAMESPACE_VERSION
2682} // namespace
2683
2684#if __cplusplus >= 201103L
2685
2686#include <ext/string_conversions.h>
2687
2688namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
2689{
2690_GLIBCXX_BEGIN_NAMESPACE_VERSION
2691
2692#if _GLIBCXX_USE_C99_STDLIB
2693 // 21.4 Numeric Conversions [string.conversions].
2694 inline int
2695 stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2696 { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
2697 __idx, __base); }
2698
2699 inline long
2700 stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2701 { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
2702 __idx, __base); }
2703
2704 inline unsigned long
2705 stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2706 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
2707 __idx, __base); }
2708
2709 inline long long
2710 stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2711 { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
2712 __idx, __base); }
2713
2714 inline unsigned long long
2715 stoull(const __vstring& __str, std::size_t* __idx, int __base = 10)
2716 { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
2717 __idx, __base); }
2718
2719 // NB: strtof vs strtod.
2720 inline float
2721 stof(const __vstring& __str, std::size_t* __idx = 0)
2722 { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
2723
2724 inline double
2725 stod(const __vstring& __str, std::size_t* __idx = 0)
2726 { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
2727
2728 inline long double
2729 stold(const __vstring& __str, std::size_t* __idx = 0)
2730 { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
2731#endif // _GLIBCXX_USE_C99_STDLIB
2732
2733#if _GLIBCXX_USE_C99_STDIO
2734 // NB: (v)snprintf vs sprintf.
2735
2736 // DR 1261.
2737 inline __vstring
2738 to_string(int __val)
2739 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
2740 "%d", __val); }
2741
2742 inline __vstring
2743 to_string(unsigned __val)
2744 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2745 4 * sizeof(unsigned),
2746 "%u", __val); }
2747
2748 inline __vstring
2749 to_string(long __val)
2750 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2751 4 * sizeof(long),
2752 "%ld", __val); }
2753
2754 inline __vstring
2755 to_string(unsigned long __val)
2756 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2757 4 * sizeof(unsigned long),
2758 "%lu", __val); }
2759
2760
2761 inline __vstring
2762 to_string(long long __val)
2763 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2764 4 * sizeof(long long),
2765 "%lld", __val); }
2766
2767 inline __vstring
2768 to_string(unsigned long long __val)
2769 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2770 4 * sizeof(unsigned long long),
2771 "%llu", __val); }
2772
2773 inline __vstring
2774 to_string(float __val)
2775 {
2776 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2777 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2778 "%f", __val);
2779 }
2780
2781 inline __vstring
2782 to_string(double __val)
2783 {
2784 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2785 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2786 "%f", __val);
2787 }
2788
2789 inline __vstring
2790 to_string(long double __val)
2791 {
2792 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2793 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2794 "%Lf", __val);
2795 }
2796#endif // _GLIBCXX_USE_C99_STDIO
2797
2798#if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR
2799 inline int
2800 stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2801 { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
2802 __idx, __base); }
2803
2804 inline long
2805 stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2806 { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
2807 __idx, __base); }
2808
2809 inline unsigned long
2810 stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2811 { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
2812 __idx, __base); }
2813
2814 inline long long
2815 stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2816 { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
2817 __idx, __base); }
2818
2819 inline unsigned long long
2820 stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2821 { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
2822 __idx, __base); }
2823
2824 // NB: wcstof vs wcstod.
2825 inline float
2826 stof(const __wvstring& __str, std::size_t* __idx = 0)
2827 { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
2828
2829 inline double
2830 stod(const __wvstring& __str, std::size_t* __idx = 0)
2831 { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
2832
2833 inline long double
2834 stold(const __wvstring& __str, std::size_t* __idx = 0)
2835 { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
2836
2837#ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
2838 // DR 1261.
2839 inline __wvstring
2840 to_wstring(int __val)
2841 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2842 4 * sizeof(int),
2843 L"%d", __val); }
2844
2845 inline __wvstring
2846 to_wstring(unsigned __val)
2847 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2848 4 * sizeof(unsigned),
2849 L"%u", __val); }
2850
2851 inline __wvstring
2852 to_wstring(long __val)
2853 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2854 4 * sizeof(long),
2855 L"%ld", __val); }
2856
2857 inline __wvstring
2858 to_wstring(unsigned long __val)
2859 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2860 4 * sizeof(unsigned long),
2861 L"%lu", __val); }
2862
2863 inline __wvstring
2864 to_wstring(long long __val)
2865 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2866 4 * sizeof(long long),
2867 L"%lld", __val); }
2868
2869 inline __wvstring
2870 to_wstring(unsigned long long __val)
2871 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2872 4 * sizeof(unsigned long long),
2873 L"%llu", __val); }
2874
2875 inline __wvstring
2876 to_wstring(float __val)
2877 {
2878 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2879 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2880 L"%f", __val);
2881 }
2882
2883 inline __wvstring
2884 to_wstring(double __val)
2885 {
2886 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2887 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2888 L"%f", __val);
2889 }
2890
2891 inline __wvstring
2892 to_wstring(long double __val)
2893 {
2894 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2895 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2896 L"%Lf", __val);
2897 }
2898#endif // _GLIBCXX_HAVE_BROKEN_VSWPRINTF
2899#endif // _GLIBCXX_USE_WCHAR_T && _GLIBCXX_USE_C99_WCHAR
2900
2901_GLIBCXX_END_NAMESPACE_VERSION
2902} // namespace
2903
2904#endif
2905
2906#if __cplusplus >= 201103L
2907
2908#include <bits/functional_hash.h>
2909
2910namespace std _GLIBCXX_VISIBILITY(default)
2911{
2912_GLIBCXX_BEGIN_NAMESPACE_VERSION
2913
2914 /// std::hash specialization for __vstring.
2915 template<>
2916 struct hash<__gnu_cxx::__vstring>
2917 : public __hash_base<size_t, __gnu_cxx::__vstring>
2918 {
2919 size_t
2920 operator()(const __gnu_cxx::__vstring& __s) const noexcept
2921 { return std::_Hash_impl::hash(__s.data(), __s.length()); }
2922 };
2923
2924#ifdef _GLIBCXX_USE_WCHAR_T
2925 /// std::hash specialization for __wvstring.
2926 template<>
2927 struct hash<__gnu_cxx::__wvstring>
2928 : public __hash_base<size_t, __gnu_cxx::__wvstring>
2929 {
2930 size_t
2931 operator()(const __gnu_cxx::__wvstring& __s) const noexcept
2932 { return std::_Hash_impl::hash(__s.data(),
2933 __s.length() * sizeof(wchar_t)); }
2934 };
2935#endif
2936
2937 /// std::hash specialization for __u16vstring.
2938 template<>
2939 struct hash<__gnu_cxx::__u16vstring>
2940 : public __hash_base<size_t, __gnu_cxx::__u16vstring>
2941 {
2942 size_t
2943 operator()(const __gnu_cxx::__u16vstring& __s) const noexcept
2944 { return std::_Hash_impl::hash(__s.data(),
2945 __s.length() * sizeof(char16_t)); }
2946 };
2947
2948 /// std::hash specialization for __u32vstring.
2949 template<>
2950 struct hash<__gnu_cxx::__u32vstring>
2951 : public __hash_base<size_t, __gnu_cxx::__u32vstring>
2952 {
2953 size_t
2954 operator()(const __gnu_cxx::__u32vstring& __s) const noexcept
2955 { return std::_Hash_impl::hash(__s.data(),
2956 __s.length() * sizeof(char32_t)); }
2957 };
2958
2959_GLIBCXX_END_NAMESPACE_VERSION
2960} // namespace
2961
2962#endif // C++11
2963
2964#include <ext/vstring.tcc>
2965
2966#endif /* _VSTRING_H */
Note: See TracBrowser for help on using the repository browser.