libstdc++
vstring.h
Go to the documentation of this file.
1 // Versatile string -*- C++ -*-
2 
3 // Copyright (C) 2005-2025 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 #ifdef _GLIBCXX_SYSHDR
33 #pragma GCC system_header
34 #endif
35 
36 #include <bits/requires_hosted.h> // GNU extensions are currently omitted
37 
38 #if __cplusplus >= 201103L
39 #include <initializer_list>
40 #endif
41 
42 #include <ext/vstring_util.h>
43 #include <ext/rc_string_base.h>
44 #include <ext/sso_string_base.h>
45 #include <bits/stl_algobase.h> // std::min
46 
47 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
48 {
49 _GLIBCXX_BEGIN_NAMESPACE_VERSION
50 
51  /**
52  * @class __versa_string vstring.h
53  * @brief Template class __versa_string.
54  * @ingroup extensions
55  *
56  * Data structure managing sequences of characters and
57  * character-like objects.
58  */
59  template<typename _CharT, typename _Traits, typename _Alloc,
60  template <typename, typename, typename> class _Base>
62  : private _Base<_CharT, _Traits, _Alloc>
63  {
64  typedef _Base<_CharT, _Traits, _Alloc> __vstring_base;
65  typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type;
67 
68  // Types:
69  public:
70  typedef _Traits traits_type;
71  typedef typename _Traits::char_type value_type;
72  typedef _Alloc allocator_type;
73  typedef typename _CharT_alloc_type::size_type size_type;
74  typedef typename _CharT_alloc_type::difference_type difference_type;
75  typedef value_type& reference;
76  typedef const value_type& const_reference;
77  typedef typename _CharT_alloc_traits::pointer pointer;
78  typedef typename _CharT_alloc_traits::const_pointer const_pointer;
79  typedef __gnu_cxx::__normal_iterator<pointer, __versa_string> iterator;
80  typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
81  const_iterator;
84 
85  // Data Member (public):
86  /// Value returned by various member functions when they fail.
87  static const size_type npos = static_cast<size_type>(-1);
88 
89  private:
90  size_type
91  _M_check(size_type __pos, const char* __s) const
92  {
93  if (__pos > this->size())
94  std::__throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
95  "this->size() (which is %zu)"),
96  __s, __pos, this->size());
97  return __pos;
98  }
99 
100  void
101  _M_check_length(size_type __n1, size_type __n2, const char* __s) const
102  {
103  if (this->max_size() - (this->size() - __n1) < __n2)
104  std::__throw_length_error(__N(__s));
105  }
106 
107  // NB: _M_limit doesn't check for a bad __pos value.
108  size_type
109  _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT
110  {
111  const bool __testoff = __off < this->size() - __pos;
112  return __testoff ? __off : this->size() - __pos;
113  }
114 
115  // True if _Rep and source do not overlap.
116  bool
117  _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT
118  {
119  return (std::less<const _CharT*>()(__s, this->_M_data())
120  || std::less<const _CharT*>()(this->_M_data()
121  + this->size(), __s));
122  }
123 
124  // For the internal use we have functions similar to `begin'/`end'
125  // but they do not call _M_leak.
126  iterator
127  _M_ibegin() const _GLIBCXX_NOEXCEPT
128  { return iterator(this->_M_data()); }
129 
130  iterator
131  _M_iend() const _GLIBCXX_NOEXCEPT
132  { return iterator(this->_M_data() + this->_M_length()); }
133 
134  public:
135  // Construct/copy/destroy:
136  // NB: We overload ctors in some cases instead of using default
137  // arguments, per 17.4.4.4 para. 2 item 2.
138 
139  /**
140  * @brief Construct an empty string using allocator @a a.
141  */
142  explicit
143  __versa_string(const _Alloc& __a = _Alloc()) _GLIBCXX_NOEXCEPT
144  : __vstring_base(__a) { }
145 
146  // NB: per LWG issue 42, semantics different from IS:
147  /**
148  * @brief Construct string with copy of value of @a __str.
149  * @param __str Source string.
150  */
152  : __vstring_base(__str) { }
153 
154 #if __cplusplus >= 201103L
155  /**
156  * @brief String move constructor.
157  * @param __str Source string.
158  *
159  * The newly-constructed %string contains the exact contents of
160  * @a __str. The contents of @a __str are a valid, but unspecified
161  * string.
162  */
163  __versa_string(__versa_string&& __str) noexcept
164  : __vstring_base(std::move(__str)) { }
165 
166  /**
167  * @brief Construct string from an initializer list.
168  * @param __l std::initializer_list of characters.
169  * @param __a Allocator to use (default is default allocator).
170  */
172  const _Alloc& __a = _Alloc())
173  : __vstring_base(__l.begin(), __l.end(), __a) { }
174 #endif
175 
176  /**
177  * @brief Construct string as copy of a substring.
178  * @param __str Source string.
179  * @param __pos Index of first character to copy from.
180  * @param __n Number of characters to copy (default remainder).
181  */
182  __versa_string(const __versa_string& __str, size_type __pos,
183  size_type __n = npos)
184  : __vstring_base(__str._M_data()
185  + __str._M_check(__pos,
186  "__versa_string::__versa_string"),
187  __str._M_data() + __str._M_limit(__pos, __n)
188  + __pos, _Alloc()) { }
189 
190  /**
191  * @brief Construct string as copy of a substring.
192  * @param __str Source string.
193  * @param __pos Index of first character to copy from.
194  * @param __n Number of characters to copy.
195  * @param __a Allocator to use.
196  */
197  __versa_string(const __versa_string& __str, size_type __pos,
198  size_type __n, const _Alloc& __a)
199  : __vstring_base(__str._M_data()
200  + __str._M_check(__pos,
201  "__versa_string::__versa_string"),
202  __str._M_data() + __str._M_limit(__pos, __n)
203  + __pos, __a) { }
204 
205  /**
206  * @brief Construct string initialized by a character array.
207  * @param __s Source character array.
208  * @param __n Number of characters to copy.
209  * @param __a Allocator to use (default is default allocator).
210  *
211  * NB: @a __s must have at least @a __n characters, '\\0' has no special
212  * meaning.
213  */
214  __versa_string(const _CharT* __s, size_type __n,
215  const _Alloc& __a = _Alloc())
216  : __vstring_base(__s, __s + __n, __a) { }
217 
218  /**
219  * @brief Construct string as copy of a C string.
220  * @param __s Source C string.
221  * @param __a Allocator to use (default is default allocator).
222  */
223  __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc())
224  : __vstring_base(__s, __s ? __s + traits_type::length(__s) :
225  __s + npos, __a) { }
226 
227  /**
228  * @brief Construct string as multiple characters.
229  * @param __n Number of characters.
230  * @param __c Character to use.
231  * @param __a Allocator to use (default is default allocator).
232  */
233  __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
234  : __vstring_base(__n, __c, __a) { }
235 
236  /**
237  * @brief Construct string as copy of a range.
238  * @param __beg Start of range.
239  * @param __end End of range.
240  * @param __a Allocator to use (default is default allocator).
241  */
242 #if __cplusplus >= 201103L
243  template<class _InputIterator,
244  typename = std::_RequireInputIter<_InputIterator>>
245 #else
246  template<class _InputIterator>
247 #endif
248  __versa_string(_InputIterator __beg, _InputIterator __end,
249  const _Alloc& __a = _Alloc())
250  : __vstring_base(__beg, __end, __a) { }
251 
252  /**
253  * @brief Destroy the string instance.
254  */
255  ~__versa_string() _GLIBCXX_NOEXCEPT { }
256 
257  /**
258  * @brief Assign the value of @a str to this string.
259  * @param __str Source string.
260  */
262  operator=(const __versa_string& __str)
263  { return this->assign(__str); }
264 
265 #if __cplusplus >= 201103L
266  /**
267  * @brief String move assignment operator.
268  * @param __str Source string.
269  *
270  * The contents of @a __str are moved into this string (without
271  * copying). @a __str is a valid, but unspecified string.
272  */
274  operator=(__versa_string&& __str) noexcept
275  {
276  // NB: DR 1204.
277  this->swap(__str);
278  return *this;
279  }
280 
281  /**
282  * @brief Set value to string constructed from initializer list.
283  * @param __l std::initializer_list.
284  */
287  {
288  this->assign(__l.begin(), __l.end());
289  return *this;
290  }
291 #endif
292 
293  /**
294  * @brief Copy contents of @a __s into this string.
295  * @param __s Source null-terminated string.
296  */
298  operator=(const _CharT* __s)
299  { return this->assign(__s); }
300 
301  /**
302  * @brief Set value to string of length 1.
303  * @param __c Source character.
304  *
305  * Assigning to a character makes this string length 1 and
306  * (*this)[0] == @a __c.
307  */
309  operator=(_CharT __c)
310  {
311  this->assign(1, __c);
312  return *this;
313  }
314 
315  // Iterators:
316  /**
317  * Returns a read/write iterator that points to the first character in
318  * the %string. Unshares the string.
319  */
320  iterator
321  begin() _GLIBCXX_NOEXCEPT
322  {
323  this->_M_leak();
324  return iterator(this->_M_data());
325  }
326 
327  /**
328  * Returns a read-only (constant) iterator that points to the first
329  * character in the %string.
330  */
331  const_iterator
332  begin() const _GLIBCXX_NOEXCEPT
333  { return const_iterator(this->_M_data()); }
334 
335  /**
336  * Returns a read/write iterator that points one past the last
337  * character in the %string. Unshares the string.
338  */
339  iterator
340  end() _GLIBCXX_NOEXCEPT
341  {
342  this->_M_leak();
343  return iterator(this->_M_data() + this->size());
344  }
345 
346  /**
347  * Returns a read-only (constant) iterator that points one past the
348  * last character in the %string.
349  */
350  const_iterator
351  end() const _GLIBCXX_NOEXCEPT
352  { return const_iterator(this->_M_data() + this->size()); }
353 
354  /**
355  * Returns a read/write reverse iterator that points to the last
356  * character in the %string. Iteration is done in reverse element
357  * order. Unshares the string.
358  */
359  reverse_iterator
360  rbegin() _GLIBCXX_NOEXCEPT
361  { return reverse_iterator(this->end()); }
362 
363  /**
364  * Returns a read-only (constant) reverse iterator that points
365  * to the last character in the %string. Iteration is done in
366  * reverse element order.
367  */
368  const_reverse_iterator
369  rbegin() const _GLIBCXX_NOEXCEPT
370  { return const_reverse_iterator(this->end()); }
371 
372  /**
373  * Returns a read/write reverse iterator that points to one before the
374  * first character in the %string. Iteration is done in reverse
375  * element order. Unshares the string.
376  */
377  reverse_iterator
378  rend() _GLIBCXX_NOEXCEPT
379  { return reverse_iterator(this->begin()); }
380 
381  /**
382  * Returns a read-only (constant) reverse iterator that points
383  * to one before the first character in the %string. Iteration
384  * is done in reverse element order.
385  */
386  const_reverse_iterator
387  rend() const _GLIBCXX_NOEXCEPT
388  { return const_reverse_iterator(this->begin()); }
389 
390 #if __cplusplus >= 201103L
391  /**
392  * Returns a read-only (constant) iterator that points to the first
393  * character in the %string.
394  */
395  const_iterator
396  cbegin() const noexcept
397  { return const_iterator(this->_M_data()); }
398 
399  /**
400  * Returns a read-only (constant) iterator that points one past the
401  * last character in the %string.
402  */
403  const_iterator
404  cend() const noexcept
405  { return const_iterator(this->_M_data() + this->size()); }
406 
407  /**
408  * Returns a read-only (constant) reverse iterator that points
409  * to the last character in the %string. Iteration is done in
410  * reverse element order.
411  */
412  const_reverse_iterator
413  crbegin() const noexcept
414  { return const_reverse_iterator(this->end()); }
415 
416  /**
417  * Returns a read-only (constant) reverse iterator that points
418  * to one before the first character in the %string. Iteration
419  * is done in reverse element order.
420  */
421  const_reverse_iterator
422  crend() const noexcept
423  { return const_reverse_iterator(this->begin()); }
424 #endif
425 
426  public:
427  // Capacity:
428  /// Returns the number of characters in the string, not including any
429  /// null-termination.
430  size_type
431  size() const _GLIBCXX_NOEXCEPT
432  { return this->_M_length(); }
433 
434  /// Returns the number of characters in the string, not including any
435  /// null-termination.
436  size_type
437  length() const _GLIBCXX_NOEXCEPT
438  { return this->_M_length(); }
439 
440  /// Returns the size() of the largest possible %string.
441  size_type
442  max_size() const _GLIBCXX_NOEXCEPT
443  { return this->_M_max_size(); }
444 
445  /**
446  * @brief Resizes the %string to the specified number of characters.
447  * @param __n Number of characters the %string should contain.
448  * @param __c Character to fill any new elements.
449  *
450  * This function will %resize the %string to the specified
451  * number of characters. If the number is smaller than the
452  * %string's current size the %string is truncated, otherwise
453  * the %string is extended and new elements are set to @a __c.
454  */
455  void
456  resize(size_type __n, _CharT __c);
457 
458  /**
459  * @brief Resizes the %string to the specified number of characters.
460  * @param __n Number of characters the %string should contain.
461  *
462  * This function will resize the %string to the specified
463  * length. If the new size is smaller than the %string's
464  * current size the %string is truncated, otherwise the %string
465  * is extended and new characters are default-constructed. For
466  * basic types such as char, this means setting them to 0.
467  */
468  void
469  resize(size_type __n)
470  { this->resize(__n, _CharT()); }
471 
472 #if __cplusplus >= 201103L
473  /// A non-binding request to reduce capacity() to size().
474  void
475  shrink_to_fit() noexcept
476  {
477  if (capacity() > size())
478  {
479  __try
480  { this->reserve(0); }
481  __catch(...)
482  { }
483  }
484  }
485 #endif
486 
487  /**
488  * Returns the total number of characters that the %string can
489  * hold before needing to allocate more memory.
490  */
491  size_type
492  capacity() const _GLIBCXX_NOEXCEPT
493  { return this->_M_capacity(); }
494 
495  /**
496  * @brief Attempt to preallocate enough memory for specified number of
497  * characters.
498  * @param __res_arg Number of characters required.
499  * @throw std::length_error If @a __res_arg exceeds @c max_size().
500  *
501  * This function attempts to reserve enough memory for the
502  * %string to hold the specified number of characters. If the
503  * number requested is more than max_size(), length_error is
504  * thrown.
505  *
506  * The advantage of this function is that if optimal code is a
507  * necessity and the user can determine the string length that
508  * will be required, the user can reserve the memory in
509  * %advance, and thus prevent a possible reallocation of memory
510  * and copying of %string data.
511  */
512  void
513  reserve(size_type __res_arg = 0)
514  { this->_M_reserve(__res_arg); }
515 
516  /**
517  * Erases the string, making it empty.
518  */
519  void
520  clear() _GLIBCXX_NOEXCEPT
521  { this->_M_clear(); }
522 
523  /**
524  * Returns true if the %string is empty. Equivalent to
525  * <code>*this == ""</code>.
526  */
527  _GLIBCXX_NODISCARD bool
528  empty() const _GLIBCXX_NOEXCEPT
529  { return this->size() == 0; }
530 
531  // Element access:
532  /**
533  * @brief Subscript access to the data contained in the %string.
534  * @param __pos The index of the character to access.
535  * @return Read-only (constant) reference to the character.
536  *
537  * This operator allows for easy, array-style, data access.
538  * Note that data access with this operator is unchecked and
539  * out_of_range lookups are not defined. (For checked lookups
540  * see at().)
541  */
542  const_reference
543  operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT
544  {
545  __glibcxx_assert(__pos <= this->size());
546  return this->_M_data()[__pos];
547  }
548 
549  /**
550  * @brief Subscript access to the data contained in the %string.
551  * @param __pos The index of the character to access.
552  * @return Read/write reference to the character.
553  *
554  * This operator allows for easy, array-style, data access.
555  * Note that data access with this operator is unchecked and
556  * out_of_range lookups are not defined. (For checked lookups
557  * see at().) Unshares the string.
558  */
559  reference
560  operator[](size_type __pos) _GLIBCXX_NOEXCEPT
561  {
562  // Allow pos == size() both in C++98 mode, as v3 extension,
563  // and in C++11 mode.
564  __glibcxx_assert(__pos <= this->size());
565  // In pedantic mode be strict in C++98 mode.
566  _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L
567  || __pos < this->size());
568  this->_M_leak();
569  return this->_M_data()[__pos];
570  }
571 
572  /**
573  * @brief Provides access to the data contained in the %string.
574  * @param __n The index of the character to access.
575  * @return Read-only (const) reference to the character.
576  * @throw std::out_of_range If @a __n is an invalid index.
577  *
578  * This function provides for safer data access. The parameter
579  * is first checked that it is in the range of the string. The
580  * function throws out_of_range if the check fails.
581  */
582  const_reference
583  at(size_type __n) const
584  {
585  if (__n >= this->size())
586  std::__throw_out_of_range_fmt(__N("__versa_string::at: __n "
587  "(which is %zu) >= this->size() "
588  "(which is %zu)"),
589  __n, this->size());
590  return this->_M_data()[__n];
591  }
592 
593  /**
594  * @brief Provides access to the data contained in the %string.
595  * @param __n The index of the character to access.
596  * @return Read/write reference to the character.
597  * @throw std::out_of_range If @a __n is an invalid index.
598  *
599  * This function provides for safer data access. The parameter
600  * is first checked that it is in the range of the string. The
601  * function throws out_of_range if the check fails. Success
602  * results in unsharing the string.
603  */
604  reference
605  at(size_type __n)
606  {
607  if (__n >= this->size())
608  std::__throw_out_of_range_fmt(__N("__versa_string::at: __n "
609  "(which is %zu) >= this->size() "
610  "(which is %zu)"),
611  __n, this->size());
612  this->_M_leak();
613  return this->_M_data()[__n];
614  }
615 
616 #if __cplusplus >= 201103L
617  /**
618  * Returns a read/write reference to the data at the first
619  * element of the %string.
620  */
621  reference
622  front() noexcept
623  { return operator[](0); }
624 
625  /**
626  * Returns a read-only (constant) reference to the data at the first
627  * element of the %string.
628  */
629  const_reference
630  front() const noexcept
631  { return operator[](0); }
632 
633  /**
634  * Returns a read/write reference to the data at the last
635  * element of the %string.
636  */
637  reference
638  back() noexcept
639  { return operator[](this->size() - 1); }
640 
641  /**
642  * Returns a read-only (constant) reference to the data at the
643  * last element of the %string.
644  */
645  const_reference
646  back() const noexcept
647  { return operator[](this->size() - 1); }
648 #endif
649 
650  // Modifiers:
651  /**
652  * @brief Append a string to this string.
653  * @param __str The string to append.
654  * @return Reference to this string.
655  */
658  { return this->append(__str); }
659 
660  /**
661  * @brief Append a C string.
662  * @param __s The C string to append.
663  * @return Reference to this string.
664  */
666  operator+=(const _CharT* __s)
667  { return this->append(__s); }
668 
669  /**
670  * @brief Append a character.
671  * @param __c The character to append.
672  * @return Reference to this string.
673  */
675  operator+=(_CharT __c)
676  {
677  this->push_back(__c);
678  return *this;
679  }
680 
681 #if __cplusplus >= 201103L
682  /**
683  * @brief Append an initializer_list of characters.
684  * @param __l The initializer_list of characters to be appended.
685  * @return Reference to this string.
686  */
689  { return this->append(__l.begin(), __l.end()); }
690 #endif // C++11
691 
692  /**
693  * @brief Append a string to this string.
694  * @param __str The string to append.
695  * @return Reference to this string.
696  */
698  append(const __versa_string& __str)
699  { return _M_append(__str._M_data(), __str.size()); }
700 
701  /**
702  * @brief Append a substring.
703  * @param __str The string to append.
704  * @param __pos Index of the first character of str to append.
705  * @param __n The number of characters to append.
706  * @return Reference to this string.
707  * @throw std::out_of_range if @a pos is not a valid index.
708  *
709  * This function appends @a __n characters from @a __str
710  * starting at @a __pos to this string. If @a __n is is larger
711  * than the number of available characters in @a __str, the
712  * remainder of @a __str is appended.
713  */
715  append(const __versa_string& __str, size_type __pos, size_type __n)
716  { return _M_append(__str._M_data()
717  + __str._M_check(__pos, "__versa_string::append"),
718  __str._M_limit(__pos, __n)); }
719 
720  /**
721  * @brief Append a C substring.
722  * @param __s The C string to append.
723  * @param __n The number of characters to append.
724  * @return Reference to this string.
725  */
727  append(const _CharT* __s, size_type __n)
728  {
729  __glibcxx_requires_string_len(__s, __n);
730  _M_check_length(size_type(0), __n, "__versa_string::append");
731  return _M_append(__s, __n);
732  }
733 
734  /**
735  * @brief Append a C string.
736  * @param __s The C string to append.
737  * @return Reference to this string.
738  */
740  append(const _CharT* __s)
741  {
742  __glibcxx_requires_string(__s);
743  const size_type __n = traits_type::length(__s);
744  _M_check_length(size_type(0), __n, "__versa_string::append");
745  return _M_append(__s, __n);
746  }
747 
748  /**
749  * @brief Append multiple characters.
750  * @param __n The number of characters to append.
751  * @param __c The character to use.
752  * @return Reference to this string.
753  *
754  * Appends n copies of c to this string.
755  */
757  append(size_type __n, _CharT __c)
758  { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
759 
760 #if __cplusplus >= 201103L
761  /**
762  * @brief Append an initializer_list of characters.
763  * @param __l The initializer_list of characters to append.
764  * @return Reference to this string.
765  */
768  { return this->append(__l.begin(), __l.end()); }
769 #endif // C++11
770 
771  /**
772  * @brief Append a range of characters.
773  * @param __first Iterator referencing the first character to append.
774  * @param __last Iterator marking the end of the range.
775  * @return Reference to this string.
776  *
777  * Appends characters in the range [first,last) to this string.
778  */
779 #if __cplusplus >= 201103L
780  template<class _InputIterator,
781  typename = std::_RequireInputIter<_InputIterator>>
782 #else
783  template<class _InputIterator>
784 #endif
786  append(_InputIterator __first, _InputIterator __last)
787  { return this->replace(_M_iend(), _M_iend(), __first, __last); }
788 
789  /**
790  * @brief Append a single character.
791  * @param __c Character to append.
792  */
793  void
794  push_back(_CharT __c)
795  {
796  const size_type __size = this->size();
797  if (__size + 1 > this->capacity() || this->_M_is_shared())
798  this->_M_mutate(__size, size_type(0), 0, size_type(1));
799  traits_type::assign(this->_M_data()[__size], __c);
800  this->_M_set_length(__size + 1);
801  }
802 
803  /**
804  * @brief Set value to contents of another string.
805  * @param __str Source string to use.
806  * @return Reference to this string.
807  */
809  assign(const __versa_string& __str)
810  {
811  this->_M_assign(__str);
812  return *this;
813  }
814 
815 #if __cplusplus >= 201103L
816  /**
817  * @brief Set value to contents of another string.
818  * @param __str Source string to use.
819  * @return Reference to this string.
820  *
821  * This function sets this string to the exact contents of @a __str.
822  * @a __str is a valid, but unspecified string.
823  */
825  assign(__versa_string&& __str) noexcept
826  {
827  this->swap(__str);
828  return *this;
829  }
830 #endif // C++11
831 
832  /**
833  * @brief Set value to a substring of a string.
834  * @param __str The string to use.
835  * @param __pos Index of the first character of str.
836  * @param __n Number of characters to use.
837  * @return Reference to this string.
838  * @throw std::out_of_range if @a __pos is not a valid index.
839  *
840  * This function sets this string to the substring of @a __str
841  * consisting of @a __n characters at @a __pos. If @a __n is
842  * is larger than the number of available characters in @a
843  * __str, the remainder of @a __str is used.
844  */
846  assign(const __versa_string& __str, size_type __pos, size_type __n)
847  { return _M_replace(size_type(0), this->size(), __str._M_data()
848  + __str._M_check(__pos, "__versa_string::assign"),
849  __str._M_limit(__pos, __n)); }
850 
851  /**
852  * @brief Set value to a C substring.
853  * @param __s The C string to use.
854  * @param __n Number of characters to use.
855  * @return Reference to this string.
856  *
857  * This function sets the value of this string to the first @a
858  * __n characters of @a __s. If @a __n is is larger than the
859  * number of available characters in @a __s, the remainder of
860  * @a __s is used.
861  */
863  assign(const _CharT* __s, size_type __n)
864  {
865  __glibcxx_requires_string_len(__s, __n);
866  return _M_replace(size_type(0), this->size(), __s, __n);
867  }
868 
869  /**
870  * @brief Set value to contents of a C string.
871  * @param __s The C string to use.
872  * @return Reference to this string.
873  *
874  * This function sets the value of this string to the value of
875  * @a __s. The data is copied, so there is no dependence on @a
876  * __s once the function returns.
877  */
879  assign(const _CharT* __s)
880  {
881  __glibcxx_requires_string(__s);
882  return _M_replace(size_type(0), this->size(), __s,
883  traits_type::length(__s));
884  }
885 
886  /**
887  * @brief Set value to multiple characters.
888  * @param __n Length of the resulting string.
889  * @param __c The character to use.
890  * @return Reference to this string.
891  *
892  * This function sets the value of this string to @a __n copies of
893  * character @a __c.
894  */
896  assign(size_type __n, _CharT __c)
897  { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
898 
899  /**
900  * @brief Set value to a range of characters.
901  * @param __first Iterator referencing the first character to append.
902  * @param __last Iterator marking the end of the range.
903  * @return Reference to this string.
904  *
905  * Sets value of string to characters in the range
906  * [first,last).
907  */
908 #if __cplusplus >= 201103L
909  template<class _InputIterator,
910  typename = std::_RequireInputIter<_InputIterator>>
911 #else
912  template<class _InputIterator>
913 #endif
915  assign(_InputIterator __first, _InputIterator __last)
916  { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
917 
918 #if __cplusplus >= 201103L
919  /**
920  * @brief Set value to an initializer_list of characters.
921  * @param __l The initializer_list of characters to assign.
922  * @return Reference to this string.
923  */
926  { return this->assign(__l.begin(), __l.end()); }
927 #endif // C++11
928 
929 #if __cplusplus >= 201103L
930  /**
931  * @brief Insert multiple characters.
932  * @param __p Const_iterator referencing location in string to
933  * insert at.
934  * @param __n Number of characters to insert
935  * @param __c The character to insert.
936  * @return Iterator referencing the first inserted char.
937  * @throw std::length_error If new length exceeds @c max_size().
938  *
939  * Inserts @a __n copies of character @a __c starting at the
940  * position referenced by iterator @a __p. If adding
941  * characters causes the length to exceed max_size(),
942  * length_error is thrown. The value of the string doesn't
943  * change if an error is thrown.
944  */
945  iterator
946  insert(const_iterator __p, size_type __n, _CharT __c)
947  {
948  _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
949  const size_type __pos = __p - _M_ibegin();
950  this->replace(__p, __p, __n, __c);
951  return iterator(this->_M_data() + __pos);
952  }
953 #else
954  /**
955  * @brief Insert multiple characters.
956  * @param __p Iterator referencing location in string to insert at.
957  * @param __n Number of characters to insert
958  * @param __c The character to insert.
959  * @throw std::length_error If new length exceeds @c max_size().
960  *
961  * Inserts @a __n copies of character @a __c starting at the
962  * position referenced by iterator @a __p. If adding
963  * characters causes the length to exceed max_size(),
964  * length_error is thrown. The value of the string doesn't
965  * change if an error is thrown.
966  */
967  void
968  insert(iterator __p, size_type __n, _CharT __c)
969  { this->replace(__p, __p, __n, __c); }
970 #endif
971 
972 #if __cplusplus >= 201103L
973  /**
974  * @brief Insert a range of characters.
975  * @param __p Const_iterator referencing location in string to
976  * insert at.
977  * @param __beg Start of range.
978  * @param __end End of range.
979  * @return Iterator referencing the first inserted char.
980  * @throw std::length_error If new length exceeds @c max_size().
981  *
982  * Inserts characters in range [beg,end). If adding characters
983  * causes the length to exceed max_size(), length_error is
984  * thrown. The value of the string doesn't change if an error
985  * is thrown.
986  */
987  template<class _InputIterator,
988  typename = std::_RequireInputIter<_InputIterator>>
989  iterator
990  insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
991  {
992  _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
993  const size_type __pos = __p - _M_ibegin();
994  this->replace(__p, __p, __beg, __end);
995  return iterator(this->_M_data() + __pos);
996  }
997 #else
998  /**
999  * @brief Insert a range of characters.
1000  * @param __p Iterator referencing location in string to insert at.
1001  * @param __beg Start of range.
1002  * @param __end End of range.
1003  * @throw std::length_error If new length exceeds @c max_size().
1004  *
1005  * Inserts characters in range [beg,end). If adding characters
1006  * causes the length to exceed max_size(), length_error is
1007  * thrown. The value of the string doesn't change if an error
1008  * is thrown.
1009  */
1010  template<class _InputIterator>
1011  void
1012  insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1013  { this->replace(__p, __p, __beg, __end); }
1014 #endif
1015 
1016 #if __cplusplus >= 201103L
1017  /**
1018  * @brief Insert an initializer_list of characters.
1019  * @param __p Const_iterator referencing location in string to
1020  * insert at.
1021  * @param __l The initializer_list of characters to insert.
1022  * @return Iterator referencing the first inserted char.
1023  * @throw std::length_error If new length exceeds @c max_size().
1024  */
1025  iterator
1026  insert(const_iterator __p, std::initializer_list<_CharT> __l)
1027  { return this->insert(__p, __l.begin(), __l.end()); }
1028 #endif // C++11
1029 
1030  /**
1031  * @brief Insert value of a string.
1032  * @param __pos1 Iterator referencing location in string to insert at.
1033  * @param __str The string to insert.
1034  * @return Reference to this string.
1035  * @throw std::length_error If new length exceeds @c max_size().
1036  *
1037  * Inserts value of @a __str starting at @a __pos1. If adding
1038  * characters causes the length to exceed max_size(),
1039  * length_error is thrown. The value of the string doesn't
1040  * change if an error is thrown.
1041  */
1043  insert(size_type __pos1, const __versa_string& __str)
1044  { return this->replace(__pos1, size_type(0),
1045  __str._M_data(), __str.size()); }
1046 
1047  /**
1048  * @brief Insert a substring.
1049  * @param __pos1 Iterator referencing location in string to insert at.
1050  * @param __str The string to insert.
1051  * @param __pos2 Start of characters in str to insert.
1052  * @param __n Number of characters to insert.
1053  * @return Reference to this string.
1054  * @throw std::length_error If new length exceeds @c max_size().
1055  * @throw std::out_of_range If @a __pos1 > size() or
1056  * @a __pos2 > @a __str.size().
1057  *
1058  * Starting at @a __pos1, insert @a __n character of @a __str
1059  * beginning with @a __pos2. If adding characters causes the
1060  * length to exceed max_size(), length_error is thrown. If @a
1061  * __pos1 is beyond the end of this string or @a __pos2 is
1062  * beyond the end of @a __str, out_of_range is thrown. The
1063  * value of the string doesn't change if an error is thrown.
1064  */
1066  insert(size_type __pos1, const __versa_string& __str,
1067  size_type __pos2, size_type __n)
1068  { return this->replace(__pos1, size_type(0), __str._M_data()
1069  + __str._M_check(__pos2, "__versa_string::insert"),
1070  __str._M_limit(__pos2, __n)); }
1071 
1072  /**
1073  * @brief Insert a C substring.
1074  * @param __pos Iterator referencing location in string to insert at.
1075  * @param __s The C string to insert.
1076  * @param __n The number of characters to insert.
1077  * @return Reference to this string.
1078  * @throw std::length_error If new length exceeds @c max_size().
1079  * @throw std::out_of_range If @a __pos is beyond the end of this
1080  * string.
1081  *
1082  * Inserts the first @a __n characters of @a __s starting at @a
1083  * __pos. If adding characters causes the length to exceed
1084  * max_size(), length_error is thrown. If @a __pos is beyond
1085  * end(), out_of_range is thrown. The value of the string
1086  * doesn't change if an error is thrown.
1087  */
1089  insert(size_type __pos, const _CharT* __s, size_type __n)
1090  { return this->replace(__pos, size_type(0), __s, __n); }
1091 
1092  /**
1093  * @brief Insert a C string.
1094  * @param __pos Iterator referencing location in string to insert at.
1095  * @param __s The C string to insert.
1096  * @return Reference to this string.
1097  * @throw std::length_error If new length exceeds @c max_size().
1098  * @throw std::out_of_range If @a __pos is beyond the end of this
1099  * string.
1100  *
1101  * Inserts the first @a __n characters of @a __s starting at @a
1102  * __pos. If adding characters causes the length to exceed
1103  * max_size(), length_error is thrown. If @a __pos is beyond
1104  * end(), out_of_range is thrown. The value of the string
1105  * doesn't change if an error is thrown.
1106  */
1108  insert(size_type __pos, const _CharT* __s)
1109  {
1110  __glibcxx_requires_string(__s);
1111  return this->replace(__pos, size_type(0), __s,
1112  traits_type::length(__s));
1113  }
1114 
1115  /**
1116  * @brief Insert multiple characters.
1117  * @param __pos Index in string to insert at.
1118  * @param __n Number of characters to insert
1119  * @param __c The character to insert.
1120  * @return Reference to this string.
1121  * @throw std::length_error If new length exceeds @c max_size().
1122  * @throw std::out_of_range If @a __pos is beyond the end of this
1123  * string.
1124  *
1125  * Inserts @a __n copies of character @a __c starting at index
1126  * @a __pos. If adding characters causes the length to exceed
1127  * max_size(), length_error is thrown. If @a __pos > length(),
1128  * out_of_range is thrown. The value of the string doesn't
1129  * change if an error is thrown.
1130  */
1132  insert(size_type __pos, size_type __n, _CharT __c)
1133  { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
1134  size_type(0), __n, __c); }
1135 
1136  /**
1137  * @brief Insert one character.
1138  * @param __p Iterator referencing position in string to insert at.
1139  * @param __c The character to insert.
1140  * @return Iterator referencing newly inserted char.
1141  * @throw std::length_error If new length exceeds @c max_size().
1142  *
1143  * Inserts character @a __c at position referenced by @a __p.
1144  * If adding character causes the length to exceed max_size(),
1145  * length_error is thrown. If @a __p is beyond end of string,
1146  * out_of_range is thrown. The value of the string doesn't
1147  * change if an error is thrown.
1148  */
1149  iterator
1150 #if __cplusplus >= 201103L
1151  insert(const_iterator __p, _CharT __c)
1152 #else
1153  insert(iterator __p, _CharT __c)
1154 #endif
1155  {
1156  _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1157  const size_type __pos = __p - _M_ibegin();
1158  _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1159  this->_M_set_leaked();
1160  return iterator(this->_M_data() + __pos);
1161  }
1162 
1163  /**
1164  * @brief Remove characters.
1165  * @param __pos Index of first character to remove (default 0).
1166  * @param __n Number of characters to remove (default remainder).
1167  * @return Reference to this string.
1168  * @throw std::out_of_range If @a __pos is beyond the end of this
1169  * string.
1170  *
1171  * Removes @a __n characters from this string starting at @a
1172  * __pos. The length of the string is reduced by @a __n. If
1173  * there are < @a __n characters to remove, the remainder of
1174  * the string is truncated. If @a __p is beyond end of string,
1175  * out_of_range is thrown. The value of the string doesn't
1176  * change if an error is thrown.
1177  */
1179  erase(size_type __pos = 0, size_type __n = npos)
1180  {
1181  this->_M_erase(_M_check(__pos, "__versa_string::erase"),
1182  _M_limit(__pos, __n));
1183  return *this;
1184  }
1185 
1186  /**
1187  * @brief Remove one character.
1188  * @param __position Iterator referencing the character to remove.
1189  * @return iterator referencing same location after removal.
1190  *
1191  * Removes the character at @a __position from this string. The
1192  * value of the string doesn't change if an error is thrown.
1193  */
1194  iterator
1195 #if __cplusplus >= 201103L
1196  erase(const_iterator __position)
1197 #else
1198  erase(iterator __position)
1199 #endif
1200  {
1201  _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1202  && __position < _M_iend());
1203  const size_type __pos = __position - _M_ibegin();
1204  this->_M_erase(__pos, size_type(1));
1205  this->_M_set_leaked();
1206  return iterator(this->_M_data() + __pos);
1207  }
1208 
1209  /**
1210  * @brief Remove a range of characters.
1211  * @param __first Iterator referencing the first character to remove.
1212  * @param __last Iterator referencing the end of the range.
1213  * @return Iterator referencing location of first after removal.
1214  *
1215  * Removes the characters in the range [first,last) from this
1216  * string. The value of the string doesn't change if an error
1217  * is thrown.
1218  */
1219  iterator
1220 #if __cplusplus >= 201103L
1221  erase(const_iterator __first, const_iterator __last)
1222 #else
1223  erase(iterator __first, iterator __last)
1224 #endif
1225  {
1226  _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1227  && __last <= _M_iend());
1228  const size_type __pos = __first - _M_ibegin();
1229  this->_M_erase(__pos, __last - __first);
1230  this->_M_set_leaked();
1231  return iterator(this->_M_data() + __pos);
1232  }
1233 
1234 #if __cplusplus >= 201103L
1235  /**
1236  * @brief Remove the last character.
1237  *
1238  * The string must be non-empty.
1239  */
1240  void
1242  { this->_M_erase(size()-1, 1); }
1243 #endif // C++11
1244 
1245  /**
1246  * @brief Replace characters with value from another string.
1247  * @param __pos Index of first character to replace.
1248  * @param __n Number of characters to be replaced.
1249  * @param __str String to insert.
1250  * @return Reference to this string.
1251  * @throw std::out_of_range If @a __pos is beyond the end of this
1252  * string.
1253  * @throw std::length_error If new length exceeds @c max_size().
1254  *
1255  * Removes the characters in the range [pos,pos+n) from this
1256  * string. In place, the value of @a __str is inserted. If @a
1257  * __pos is beyond end of string, out_of_range is thrown. If
1258  * the length of the result exceeds max_size(), length_error is
1259  * thrown. The value of the string doesn't change if an error
1260  * is thrown.
1261  */
1263  replace(size_type __pos, size_type __n, const __versa_string& __str)
1264  { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1265 
1266  /**
1267  * @brief Replace characters with value from another string.
1268  * @param __pos1 Index of first character to replace.
1269  * @param __n1 Number of characters to be replaced.
1270  * @param __str String to insert.
1271  * @param __pos2 Index of first character of str to use.
1272  * @param __n2 Number of characters from str to use.
1273  * @return Reference to this string.
1274  * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
1275  * str.size().
1276  * @throw std::length_error If new length exceeds @c max_size().
1277  *
1278  * Removes the characters in the range [pos1,pos1 + n) from
1279  * this string. In place, the value of @a __str is inserted.
1280  * If @a __pos is beyond end of string, out_of_range is thrown.
1281  * If the length of the result exceeds max_size(), length_error
1282  * is thrown. The value of the string doesn't change if an
1283  * error is thrown.
1284  */
1286  replace(size_type __pos1, size_type __n1, const __versa_string& __str,
1287  size_type __pos2, size_type __n2)
1288  {
1289  return this->replace(__pos1, __n1, __str._M_data()
1290  + __str._M_check(__pos2,
1291  "__versa_string::replace"),
1292  __str._M_limit(__pos2, __n2));
1293  }
1294 
1295  /**
1296  * @brief Replace characters with value of a C substring.
1297  * @param __pos Index of first character to replace.
1298  * @param __n1 Number of characters to be replaced.
1299  * @param __s C string to insert.
1300  * @param __n2 Number of characters from @a __s to use.
1301  * @return Reference to this string.
1302  * @throw std::out_of_range If @a __pos1 > size().
1303  * @throw std::length_error If new length exceeds @c max_size().
1304  *
1305  * Removes the characters in the range [pos,pos + n1) from this
1306  * string. In place, the first @a __n2 characters of @a __s
1307  * are inserted, or all of @a __s if @a __n2 is too large. If
1308  * @a __pos is beyond end of string, out_of_range is thrown.
1309  * If the length of result exceeds max_size(), length_error is
1310  * thrown. The value of the string doesn't change if an error
1311  * is thrown.
1312  */
1314  replace(size_type __pos, size_type __n1, const _CharT* __s,
1315  size_type __n2)
1316  {
1317  __glibcxx_requires_string_len(__s, __n2);
1318  return _M_replace(_M_check(__pos, "__versa_string::replace"),
1319  _M_limit(__pos, __n1), __s, __n2);
1320  }
1321 
1322  /**
1323  * @brief Replace characters with value of a C string.
1324  * @param __pos Index of first character to replace.
1325  * @param __n1 Number of characters to be replaced.
1326  * @param __s C string to insert.
1327  * @return Reference to this string.
1328  * @throw std::out_of_range If @a __pos > size().
1329  * @throw std::length_error If new length exceeds @c max_size().
1330  *
1331  * Removes the characters in the range [pos,pos + n1) from this
1332  * string. In place, the characters of @a __s are inserted. If
1333  * @a pos is beyond end of string, out_of_range is thrown. If
1334  * the length of result exceeds max_size(), length_error is thrown.
1335  * The value of the string doesn't change if an error is thrown.
1336  */
1338  replace(size_type __pos, size_type __n1, const _CharT* __s)
1339  {
1340  __glibcxx_requires_string(__s);
1341  return this->replace(__pos, __n1, __s, traits_type::length(__s));
1342  }
1343 
1344  /**
1345  * @brief Replace characters with multiple characters.
1346  * @param __pos Index of first character to replace.
1347  * @param __n1 Number of characters to be replaced.
1348  * @param __n2 Number of characters to insert.
1349  * @param __c Character to insert.
1350  * @return Reference to this string.
1351  * @throw std::out_of_range If @a __pos > size().
1352  * @throw std::length_error If new length exceeds @c max_size().
1353  *
1354  * Removes the characters in the range [pos,pos + n1) from this
1355  * string. In place, @a __n2 copies of @a __c are inserted.
1356  * If @a __pos is beyond end of string, out_of_range is thrown.
1357  * If the length of result exceeds max_size(), length_error is
1358  * thrown. The value of the string doesn't change if an error
1359  * is thrown.
1360  */
1362  replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1363  { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
1364  _M_limit(__pos, __n1), __n2, __c); }
1365 
1366  /**
1367  * @brief Replace range of characters with string.
1368  * @param __i1 Iterator referencing start of range to replace.
1369  * @param __i2 Iterator referencing end of range to replace.
1370  * @param __str String value to insert.
1371  * @return Reference to this string.
1372  * @throw std::length_error If new length exceeds @c max_size().
1373  *
1374  * Removes the characters in the range [i1,i2). In place, the
1375  * value of @a __str is inserted. If the length of result
1376  * exceeds max_size(), length_error is thrown. The value of
1377  * the string doesn't change if an error is thrown.
1378  */
1380 #if __cplusplus >= 201103L
1381  replace(const_iterator __i1, const_iterator __i2,
1382  const __versa_string& __str)
1383 #else
1384  replace(iterator __i1, iterator __i2, const __versa_string& __str)
1385 #endif
1386  { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1387 
1388  /**
1389  * @brief Replace range of characters with C substring.
1390  * @param __i1 Iterator referencing start of range to replace.
1391  * @param __i2 Iterator referencing end of range to replace.
1392  * @param __s C string value to insert.
1393  * @param __n Number of characters from s to insert.
1394  * @return Reference to this string.
1395  * @throw std::length_error If new length exceeds @c max_size().
1396  *
1397  * Removes the characters in the range [i1,i2). In place, the
1398  * first @a n characters of @a __s are inserted. If the length
1399  * of result exceeds max_size(), length_error is thrown. The
1400  * value of the string doesn't change if an error is thrown.
1401  */
1403 #if __cplusplus >= 201103L
1404  replace(const_iterator __i1, const_iterator __i2,
1405  const _CharT* __s, size_type __n)
1406 #else
1407  replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1408 #endif
1409  {
1410  _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1411  && __i2 <= _M_iend());
1412  return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1413  }
1414 
1415  /**
1416  * @brief Replace range of characters with C string.
1417  * @param __i1 Iterator referencing start of range to replace.
1418  * @param __i2 Iterator referencing end of range to replace.
1419  * @param __s C string value to insert.
1420  * @return Reference to this string.
1421  * @throw std::length_error If new length exceeds @c max_size().
1422  *
1423  * Removes the characters in the range [i1,i2). In place, the
1424  * characters of @a __s are inserted. If the length of result
1425  * exceeds max_size(), length_error is thrown. The value of
1426  * the string doesn't change if an error is thrown.
1427  */
1429 #if __cplusplus >= 201103L
1430  replace(const_iterator __i1, const_iterator __i2, const _CharT* __s)
1431 #else
1432  replace(iterator __i1, iterator __i2, const _CharT* __s)
1433 #endif
1434  {
1435  __glibcxx_requires_string(__s);
1436  return this->replace(__i1, __i2, __s, traits_type::length(__s));
1437  }
1438 
1439  /**
1440  * @brief Replace range of characters with multiple characters
1441  * @param __i1 Iterator referencing start of range to replace.
1442  * @param __i2 Iterator referencing end of range to replace.
1443  * @param __n Number of characters to insert.
1444  * @param __c Character to insert.
1445  * @return Reference to this string.
1446  * @throw std::length_error If new length exceeds @c max_size().
1447  *
1448  * Removes the characters in the range [i1,i2). In place, @a
1449  * __n copies of @a __c are inserted. If the length of result
1450  * exceeds max_size(), length_error is thrown. The value of
1451  * the string doesn't change if an error is thrown.
1452  */
1454 #if __cplusplus >= 201103L
1455  replace(const_iterator __i1, const_iterator __i2, size_type __n,
1456  _CharT __c)
1457 #else
1458  replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1459 #endif
1460  {
1461  _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1462  && __i2 <= _M_iend());
1463  return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1464  }
1465 
1466  /**
1467  * @brief Replace range of characters with range.
1468  * @param __i1 Iterator referencing start of range to replace.
1469  * @param __i2 Iterator referencing end of range to replace.
1470  * @param __k1 Iterator referencing start of range to insert.
1471  * @param __k2 Iterator referencing end of range to insert.
1472  * @return Reference to this string.
1473  * @throw std::length_error If new length exceeds @c max_size().
1474  *
1475  * Removes the characters in the range [i1,i2). In place,
1476  * characters in the range [k1,k2) are inserted. If the length
1477  * of result exceeds max_size(), length_error is thrown. The
1478  * value of the string doesn't change if an error is thrown.
1479  */
1480 #if __cplusplus >= 201103L
1481  template<class _InputIterator,
1482  typename = std::_RequireInputIter<_InputIterator>>
1484  replace(const_iterator __i1, const_iterator __i2,
1485  _InputIterator __k1, _InputIterator __k2)
1486  {
1487  _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1488  && __i2 <= _M_iend());
1489  __glibcxx_requires_valid_range(__k1, __k2);
1490  return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
1491  std::__false_type());
1492  }
1493 #else
1494  template<class _InputIterator>
1496  replace(iterator __i1, iterator __i2,
1497  _InputIterator __k1, _InputIterator __k2)
1498  {
1499  _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1500  && __i2 <= _M_iend());
1501  __glibcxx_requires_valid_range(__k1, __k2);
1502  typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1503  return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1504  }
1505 #endif
1506 
1507  // Specializations for the common case of pointer and iterator:
1508  // useful to avoid the overhead of temporary buffering in _M_replace.
1510 #if __cplusplus >= 201103L
1511  replace(const_iterator __i1, const_iterator __i2,
1512  _CharT* __k1, _CharT* __k2)
1513 #else
1514  replace(iterator __i1, iterator __i2,
1515  _CharT* __k1, _CharT* __k2)
1516 #endif
1517  {
1518  _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1519  && __i2 <= _M_iend());
1520  __glibcxx_requires_valid_range(__k1, __k2);
1521  return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1522  __k1, __k2 - __k1);
1523  }
1524 
1526 #if __cplusplus >= 201103L
1527  replace(const_iterator __i1, const_iterator __i2,
1528  const _CharT* __k1, const _CharT* __k2)
1529 #else
1530  replace(iterator __i1, iterator __i2,
1531  const _CharT* __k1, const _CharT* __k2)
1532 #endif
1533  {
1534  _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1535  && __i2 <= _M_iend());
1536  __glibcxx_requires_valid_range(__k1, __k2);
1537  return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1538  __k1, __k2 - __k1);
1539  }
1540 
1542 #if __cplusplus >= 201103L
1543  replace(const_iterator __i1, const_iterator __i2,
1544  iterator __k1, iterator __k2)
1545 #else
1546  replace(iterator __i1, iterator __i2,
1547  iterator __k1, iterator __k2)
1548 #endif
1549  {
1550  _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1551  && __i2 <= _M_iend());
1552  __glibcxx_requires_valid_range(__k1, __k2);
1553  return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1554  __k1.base(), __k2 - __k1);
1555  }
1556 
1558 #if __cplusplus >= 201103L
1559  replace(const_iterator __i1, const_iterator __i2,
1560  const_iterator __k1, const_iterator __k2)
1561 #else
1562  replace(iterator __i1, iterator __i2,
1563  const_iterator __k1, const_iterator __k2)
1564 #endif
1565  {
1566  _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1567  && __i2 <= _M_iend());
1568  __glibcxx_requires_valid_range(__k1, __k2);
1569  return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1570  __k1.base(), __k2 - __k1);
1571  }
1572 
1573 #if __cplusplus >= 201103L
1574  /**
1575  * @brief Replace range of characters with initializer_list.
1576  * @param __i1 Iterator referencing start of range to replace.
1577  * @param __i2 Iterator referencing end of range to replace.
1578  * @param __l The initializer_list of characters to insert.
1579  * @return Reference to this string.
1580  * @throw std::length_error If new length exceeds @c max_size().
1581  *
1582  * Removes the characters in the range [i1,i2). In place,
1583  * characters in the range [k1,k2) are inserted. If the length
1584  * of result exceeds max_size(), length_error is thrown. The
1585  * value of the string doesn't change if an error is thrown.
1586  */
1588  replace(const_iterator __i1, const_iterator __i2,
1590  { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
1591 #endif // C++11
1592 
1593  private:
1594  template<class _Integer>
1596  _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
1597  _Integer __n, _Integer __val, std::__true_type)
1598  { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1599 
1600  template<class _InputIterator>
1602  _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
1603  _InputIterator __k1, _InputIterator __k2,
1604  std::__false_type);
1605 
1607  _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1608  _CharT __c);
1609 
1611  _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
1612  const size_type __len2);
1613 
1615  _M_append(const _CharT* __s, size_type __n);
1616 
1617  public:
1618 
1619  /**
1620  * @brief Copy substring into C string.
1621  * @param __s C string to copy value into.
1622  * @param __n Number of characters to copy.
1623  * @param __pos Index of first character to copy.
1624  * @return Number of characters actually copied
1625  * @throw std::out_of_range If pos > size().
1626  *
1627  * Copies up to @a __n characters starting at @a __pos into the
1628  * C string @a s. If @a __pos is greater than size(),
1629  * out_of_range is thrown.
1630  */
1631  size_type
1632  copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1633 
1634  /**
1635  * @brief Swap contents with another string.
1636  * @param __s String to swap with.
1637  *
1638  * Exchanges the contents of this string with that of @a __s in
1639  * constant time.
1640  */
1641  void
1642  swap(__versa_string& __s) _GLIBCXX_NOEXCEPT
1643  { this->_M_swap(__s); }
1644 
1645  // String operations:
1646  /**
1647  * @brief Return const pointer to null-terminated contents.
1648  *
1649  * This is a handle to internal data. Do not modify or dire things may
1650  * happen.
1651  */
1652  const _CharT*
1653  c_str() const _GLIBCXX_NOEXCEPT
1654  { return this->_M_data(); }
1655 
1656  /**
1657  * @brief Return const pointer to contents.
1658  *
1659  * This is a handle to internal data. Do not modify or dire things may
1660  * happen.
1661  */
1662  const _CharT*
1663  data() const _GLIBCXX_NOEXCEPT
1664  { return this->_M_data(); }
1665 
1666  /**
1667  * @brief Return copy of allocator used to construct this string.
1668  */
1669  allocator_type
1670  get_allocator() const _GLIBCXX_NOEXCEPT
1671  { return allocator_type(this->_M_get_allocator()); }
1672 
1673  /**
1674  * @brief Find position of a C substring.
1675  * @param __s C string to locate.
1676  * @param __pos Index of character to search from.
1677  * @param __n Number of characters from @a __s to search for.
1678  * @return Index of start of first occurrence.
1679  *
1680  * Starting from @a __pos, searches forward for the first @a
1681  * __n characters in @a __s within this string. If found,
1682  * returns the index where it begins. If not found, returns
1683  * npos.
1684  */
1685  size_type
1686  find(const _CharT* __s, size_type __pos, size_type __n) const;
1687 
1688  /**
1689  * @brief Find position of a string.
1690  * @param __str String to locate.
1691  * @param __pos Index of character to search from (default 0).
1692  * @return Index of start of first occurrence.
1693  *
1694  * Starting from @a __pos, searches forward for value of @a
1695  * __str within this string. If found, returns the index where
1696  * it begins. If not found, returns npos.
1697  */
1698  size_type
1699  find(const __versa_string& __str, size_type __pos = 0) const
1700  _GLIBCXX_NOEXCEPT
1701  { return this->find(__str.data(), __pos, __str.size()); }
1702 
1703  /**
1704  * @brief Find position of a C string.
1705  * @param __s C string to locate.
1706  * @param __pos Index of character to search from (default 0).
1707  * @return Index of start of first occurrence.
1708  *
1709  * Starting from @a __pos, searches forward for the value of @a
1710  * __s within this string. If found, returns the index where
1711  * it begins. If not found, returns npos.
1712  */
1713  size_type
1714  find(const _CharT* __s, size_type __pos = 0) const
1715  {
1716  __glibcxx_requires_string(__s);
1717  return this->find(__s, __pos, traits_type::length(__s));
1718  }
1719 
1720  /**
1721  * @brief Find position of a character.
1722  * @param __c Character to locate.
1723  * @param __pos Index of character to search from (default 0).
1724  * @return Index of first occurrence.
1725  *
1726  * Starting from @a __pos, searches forward for @a __c within
1727  * this string. If found, returns the index where it was
1728  * found. If not found, returns npos.
1729  */
1730  size_type
1731  find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
1732 
1733  /**
1734  * @brief Find last position of a string.
1735  * @param __str String to locate.
1736  * @param __pos Index of character to search back from (default end).
1737  * @return Index of start of last occurrence.
1738  *
1739  * Starting from @a __pos, searches backward for value of @a
1740  * __str within this string. If found, returns the index where
1741  * it begins. If not found, returns npos.
1742  */
1743  size_type
1744  rfind(const __versa_string& __str, size_type __pos = npos) const
1745  _GLIBCXX_NOEXCEPT
1746  { return this->rfind(__str.data(), __pos, __str.size()); }
1747 
1748  /**
1749  * @brief Find last position of a C substring.
1750  * @param __s C string to locate.
1751  * @param __pos Index of character to search back from.
1752  * @param __n Number of characters from s to search for.
1753  * @return Index of start of last occurrence.
1754  *
1755  * Starting from @a __pos, searches backward for the first @a
1756  * __n characters in @a __s within this string. If found,
1757  * returns the index where it begins. If not found, returns
1758  * npos.
1759  */
1760  size_type
1761  rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1762 
1763  /**
1764  * @brief Find last position of a C string.
1765  * @param __s C string to locate.
1766  * @param __pos Index of character to start search at (default end).
1767  * @return Index of start of last occurrence.
1768  *
1769  * Starting from @a __pos, searches backward for the value of
1770  * @a __s within this string. If found, returns the index
1771  * where it begins. If not found, returns npos.
1772  */
1773  size_type
1774  rfind(const _CharT* __s, size_type __pos = npos) const
1775  {
1776  __glibcxx_requires_string(__s);
1777  return this->rfind(__s, __pos, traits_type::length(__s));
1778  }
1779 
1780  /**
1781  * @brief Find last position of a character.
1782  * @param __c Character to locate.
1783  * @param __pos Index of character to search back from (default end).
1784  * @return Index of last occurrence.
1785  *
1786  * Starting from @a __pos, searches backward for @a __c within
1787  * this string. If found, returns the index where it was
1788  * found. If not found, returns npos.
1789  */
1790  size_type
1791  rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
1792 
1793  /**
1794  * @brief Find position of a character of string.
1795  * @param __str String containing characters to locate.
1796  * @param __pos Index of character to search from (default 0).
1797  * @return Index of first occurrence.
1798  *
1799  * Starting from @a __pos, searches forward for one of the characters of
1800  * @a __str within this string. If found, returns the index where it was
1801  * found. If not found, returns npos.
1802  */
1803  size_type
1804  find_first_of(const __versa_string& __str, size_type __pos = 0) const
1805  _GLIBCXX_NOEXCEPT
1806  { return this->find_first_of(__str.data(), __pos, __str.size()); }
1807 
1808  /**
1809  * @brief Find position of a character of C substring.
1810  * @param __s String containing characters to locate.
1811  * @param __pos Index of character to search from.
1812  * @param __n Number of characters from s to search for.
1813  * @return Index of first occurrence.
1814  *
1815  * Starting from @a __pos, searches forward for one of the
1816  * first @a __n characters of @a __s within this string. If
1817  * found, returns the index where it was found. If not found,
1818  * returns npos.
1819  */
1820  size_type
1821  find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1822 
1823  /**
1824  * @brief Find position of a character of C string.
1825  * @param __s String containing characters to locate.
1826  * @param __pos Index of character to search from (default 0).
1827  * @return Index of first occurrence.
1828  *
1829  * Starting from @a __pos, searches forward for one of the
1830  * characters of @a __s within this string. If found, returns
1831  * the index where it was found. If not found, returns npos.
1832  */
1833  size_type
1834  find_first_of(const _CharT* __s, size_type __pos = 0) const
1835  {
1836  __glibcxx_requires_string(__s);
1837  return this->find_first_of(__s, __pos, traits_type::length(__s));
1838  }
1839 
1840  /**
1841  * @brief Find position of a character.
1842  * @param __c Character to locate.
1843  * @param __pos Index of character to search from (default 0).
1844  * @return Index of first occurrence.
1845  *
1846  * Starting from @a __pos, searches forward for the character
1847  * @a __c within this string. If found, returns the index
1848  * where it was found. If not found, returns npos.
1849  *
1850  * Note: equivalent to find(c, pos).
1851  */
1852  size_type
1853  find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
1854  { return this->find(__c, __pos); }
1855 
1856  /**
1857  * @brief Find last position of a character of string.
1858  * @param __str String containing characters to locate.
1859  * @param __pos Index of character to search back from (default end).
1860  * @return Index of last occurrence.
1861  *
1862  * Starting from @a __pos, searches backward for one of the
1863  * characters of @a __str within this string. If found,
1864  * returns the index where it was found. If not found, returns
1865  * npos.
1866  */
1867  size_type
1868  find_last_of(const __versa_string& __str, size_type __pos = npos) const
1869  _GLIBCXX_NOEXCEPT
1870  { return this->find_last_of(__str.data(), __pos, __str.size()); }
1871 
1872  /**
1873  * @brief Find last position of a character of C substring.
1874  * @param __s C string containing characters to locate.
1875  * @param __pos Index of character to search back from.
1876  * @param __n Number of characters from s to search for.
1877  * @return Index of last occurrence.
1878  *
1879  * Starting from @a __pos, searches backward for one of the
1880  * first @a __n characters of @a __s within this string. If
1881  * found, returns the index where it was found. If not found,
1882  * returns npos.
1883  */
1884  size_type
1885  find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1886 
1887  /**
1888  * @brief Find last position of a character of C string.
1889  * @param __s C string containing characters to locate.
1890  * @param __pos Index of character to search back from (default end).
1891  * @return Index of last occurrence.
1892  *
1893  * Starting from @a __pos, searches backward for one of the
1894  * characters of @a __s within this string. If found, returns
1895  * the index where it was found. If not found, returns npos.
1896  */
1897  size_type
1898  find_last_of(const _CharT* __s, size_type __pos = npos) const
1899  {
1900  __glibcxx_requires_string(__s);
1901  return this->find_last_of(__s, __pos, traits_type::length(__s));
1902  }
1903 
1904  /**
1905  * @brief Find last position of a character.
1906  * @param __c Character to locate.
1907  * @param __pos Index of character to search back from (default end).
1908  * @return Index of last occurrence.
1909  *
1910  * Starting from @a __pos, searches backward for @a __c within
1911  * this string. If found, returns the index where it was
1912  * found. If not found, returns npos.
1913  *
1914  * Note: equivalent to rfind(c, pos).
1915  */
1916  size_type
1917  find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1918  { return this->rfind(__c, __pos); }
1919 
1920  /**
1921  * @brief Find position of a character not in string.
1922  * @param __str String containing characters to avoid.
1923  * @param __pos Index of character to search from (default 0).
1924  * @return Index of first occurrence.
1925  *
1926  * Starting from @a __pos, searches forward for a character not
1927  * contained in @a __str within this string. If found, returns
1928  * the index where it was found. If not found, returns npos.
1929  */
1930  size_type
1931  find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
1932  _GLIBCXX_NOEXCEPT
1933  { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1934 
1935  /**
1936  * @brief Find position of a character not in C substring.
1937  * @param __s C string containing characters to avoid.
1938  * @param __pos Index of character to search from.
1939  * @param __n Number of characters from s to consider.
1940  * @return Index of first occurrence.
1941  *
1942  * Starting from @a __pos, searches forward for a character not
1943  * contained in the first @a __n characters of @a __s within
1944  * this string. If found, returns the index where it was
1945  * found. If not found, returns npos.
1946  */
1947  size_type
1948  find_first_not_of(const _CharT* __s, size_type __pos,
1949  size_type __n) const;
1950 
1951  /**
1952  * @brief Find position of a character not in C string.
1953  * @param __s C string containing characters to avoid.
1954  * @param __pos Index of character to search from (default 0).
1955  * @return Index of first occurrence.
1956  *
1957  * Starting from @a __pos, searches forward for a character not
1958  * contained in @a __s within this string. If found, returns
1959  * the index where it was found. If not found, returns npos.
1960  */
1961  size_type
1962  find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1963  {
1964  __glibcxx_requires_string(__s);
1965  return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1966  }
1967 
1968  /**
1969  * @brief Find position of a different character.
1970  * @param __c Character to avoid.
1971  * @param __pos Index of character to search from (default 0).
1972  * @return Index of first occurrence.
1973  *
1974  * Starting from @a __pos, searches forward for a character
1975  * other than @a __c within this string. If found, returns the
1976  * index where it was found. If not found, returns npos.
1977  */
1978  size_type
1979  find_first_not_of(_CharT __c, size_type __pos = 0) const
1980  _GLIBCXX_NOEXCEPT;
1981 
1982  /**
1983  * @brief Find last position of a character not in string.
1984  * @param __str String containing characters to avoid.
1985  * @param __pos Index of character to search back from (default end).
1986  * @return Index of last occurrence.
1987  *
1988  * Starting from @a __pos, searches backward for a character
1989  * not contained in @a __str within this string. If found,
1990  * returns the index where it was found. If not found, returns
1991  * npos.
1992  */
1993  size_type
1995  size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1996  { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1997 
1998  /**
1999  * @brief Find last position of a character not in C substring.
2000  * @param __s C string containing characters to avoid.
2001  * @param __pos Index of character to search back from.
2002  * @param __n Number of characters from s to consider.
2003  * @return Index of last occurrence.
2004  *
2005  * Starting from @a __pos, searches backward for a character
2006  * not contained in the first @a __n characters of @a __s
2007  * within this string. If found, returns the index where it
2008  * was found. If not found, returns npos.
2009  */
2010  size_type
2011  find_last_not_of(const _CharT* __s, size_type __pos,
2012  size_type __n) const;
2013  /**
2014  * @brief Find last position of a character not in C string.
2015  * @param __s C string containing characters to avoid.
2016  * @param __pos Index of character to search back from (default end).
2017  * @return Index of last occurrence.
2018  *
2019  * Starting from @a __pos, searches backward for a character
2020  * not contained in @a __s within this string. If found,
2021  * returns the index where it was found. If not found, returns
2022  * npos.
2023  */
2024  size_type
2025  find_last_not_of(const _CharT* __s, size_type __pos = npos) const
2026  {
2027  __glibcxx_requires_string(__s);
2028  return this->find_last_not_of(__s, __pos, traits_type::length(__s));
2029  }
2030 
2031  /**
2032  * @brief Find last position of a different character.
2033  * @param __c Character to avoid.
2034  * @param __pos Index of character to search back from (default end).
2035  * @return Index of last occurrence.
2036  *
2037  * Starting from @a __pos, searches backward for a character
2038  * other than @a __c within this string. If found, returns the
2039  * index where it was found. If not found, returns npos.
2040  */
2041  size_type
2042  find_last_not_of(_CharT __c, size_type __pos = npos) const
2043  _GLIBCXX_NOEXCEPT;
2044 
2045  /**
2046  * @brief Get a substring.
2047  * @param __pos Index of first character (default 0).
2048  * @param __n Number of characters in substring (default remainder).
2049  * @return The new string.
2050  * @throw std::out_of_range If pos > size().
2051  *
2052  * Construct and return a new string using the @a __n
2053  * characters starting at @a __pos. If the string is too
2054  * short, use the remainder of the characters. If @a __pos is
2055  * beyond the end of the string, out_of_range is thrown.
2056  */
2058  substr(size_type __pos = 0, size_type __n = npos) const
2059  {
2060  return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
2061  __n);
2062  }
2063 
2064  /**
2065  * @brief Compare to a string.
2066  * @param __str String to compare against.
2067  * @return Integer < 0, 0, or > 0.
2068  *
2069  * Returns an integer < 0 if this string is ordered before @a
2070  * __str, 0 if their values are equivalent, or > 0 if this
2071  * string is ordered after @a __str. Determines the effective
2072  * length rlen of the strings to compare as the smallest of
2073  * size() and str.size(). The function then compares the two
2074  * strings by calling traits::compare(data(), str.data(),rlen).
2075  * If the result of the comparison is nonzero returns it,
2076  * otherwise the shorter one is ordered first.
2077  */
2078  int
2079  compare(const __versa_string& __str) const
2080  {
2081  if (this->_M_compare(__str))
2082  return 0;
2083 
2084  const size_type __size = this->size();
2085  const size_type __osize = __str.size();
2086  const size_type __len = std::min(__size, __osize);
2087 
2088  int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
2089  if (!__r)
2090  __r = this->_S_compare(__size, __osize);
2091  return __r;
2092  }
2093 
2094  /**
2095  * @brief Compare substring to a string.
2096  * @param __pos Index of first character of substring.
2097  * @param __n Number of characters in substring.
2098  * @param __str String to compare against.
2099  * @return Integer < 0, 0, or > 0.
2100  *
2101  * Form the substring of this string from the @a __n characters
2102  * starting at @a __pos. Returns an integer < 0 if the
2103  * substring is ordered before @a __str, 0 if their values are
2104  * equivalent, or > 0 if the substring is ordered after @a
2105  * __str. Determines the effective length rlen of the strings
2106  * to compare as the smallest of the length of the substring
2107  * and @a __str.size(). The function then compares the two
2108  * strings by calling
2109  * traits::compare(substring.data(),str.data(),rlen). If the
2110  * result of the comparison is nonzero returns it, otherwise
2111  * the shorter one is ordered first.
2112  */
2113  int
2114  compare(size_type __pos, size_type __n,
2115  const __versa_string& __str) const;
2116 
2117  /**
2118  * @brief Compare substring to a substring.
2119  * @param __pos1 Index of first character of substring.
2120  * @param __n1 Number of characters in substring.
2121  * @param __str String to compare against.
2122  * @param __pos2 Index of first character of substring of str.
2123  * @param __n2 Number of characters in substring of str.
2124  * @return Integer < 0, 0, or > 0.
2125  *
2126  * Form the substring of this string from the @a __n1
2127  * characters starting at @a __pos1. Form the substring of @a
2128  * __str from the @a __n2 characters starting at @a __pos2.
2129  * Returns an integer < 0 if this substring is ordered before
2130  * the substring of @a __str, 0 if their values are equivalent,
2131  * or > 0 if this substring is ordered after the substring of
2132  * @a __str. Determines the effective length rlen of the
2133  * strings to compare as the smallest of the lengths of the
2134  * substrings. The function then compares the two strings by
2135  * calling
2136  * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
2137  * If the result of the comparison is nonzero returns it,
2138  * otherwise the shorter one is ordered first.
2139  */
2140  int
2141  compare(size_type __pos1, size_type __n1, const __versa_string& __str,
2142  size_type __pos2, size_type __n2) const;
2143 
2144  /**
2145  * @brief Compare to a C string.
2146  * @param __s C string to compare against.
2147  * @return Integer < 0, 0, or > 0.
2148  *
2149  * Returns an integer < 0 if this string is ordered before @a
2150  * __s, 0 if their values are equivalent, or > 0 if this string
2151  * is ordered after @a __s. Determines the effective length
2152  * rlen of the strings to compare as the smallest of size() and
2153  * the length of a string constructed from @a __s. The
2154  * function then compares the two strings by calling
2155  * traits::compare(data(),s,rlen). If the result of the
2156  * comparison is nonzero returns it, otherwise the shorter one
2157  * is ordered first.
2158  */
2159  int
2160  compare(const _CharT* __s) const;
2161 
2162  // _GLIBCXX_RESOLVE_LIB_DEFECTS
2163  // 5 String::compare specification questionable
2164  /**
2165  * @brief Compare substring to a C string.
2166  * @param __pos Index of first character of substring.
2167  * @param __n1 Number of characters in substring.
2168  * @param __s C string to compare against.
2169  * @return Integer < 0, 0, or > 0.
2170  *
2171  * Form the substring of this string from the @a __n1
2172  * characters starting at @a __pos. Returns an integer < 0 if
2173  * the substring is ordered before @a __s, 0 if their values
2174  * are equivalent, or > 0 if the substring is ordered after @a
2175  * __s. Determines the effective length rlen of the strings to
2176  * compare as the smallest of the length of the substring and
2177  * the length of a string constructed from @a __s. The
2178  * function then compares the two string by calling
2179  * traits::compare(substring.data(),s,rlen). If the result of
2180  * the comparison is nonzero returns it, otherwise the shorter
2181  * one is ordered first.
2182  */
2183  int
2184  compare(size_type __pos, size_type __n1, const _CharT* __s) const;
2185 
2186  /**
2187  * @brief Compare substring against a character array.
2188  * @param __pos Index of first character of substring.
2189  * @param __n1 Number of characters in substring.
2190  * @param __s character array to compare against.
2191  * @param __n2 Number of characters of s.
2192  * @return Integer < 0, 0, or > 0.
2193  *
2194  * Form the substring of this string from the @a __n1
2195  * characters starting at @a __pos. Form a string from the
2196  * first @a __n2 characters of @a __s. Returns an integer < 0
2197  * if this substring is ordered before the string from @a __s,
2198  * 0 if their values are equivalent, or > 0 if this substring
2199  * is ordered after the string from @a __s. Determines the
2200  * effective length rlen of the strings to compare as the
2201  * smallest of the length of the substring and @a __n2. The
2202  * function then compares the two strings by calling
2203  * traits::compare(substring.data(),__s,rlen). If the result of
2204  * the comparison is nonzero returns it, otherwise the shorter
2205  * one is ordered first.
2206  *
2207  * NB: __s must have at least n2 characters, <em>\\0</em> has no special
2208  * meaning.
2209  */
2210  int
2211  compare(size_type __pos, size_type __n1, const _CharT* __s,
2212  size_type __n2) const;
2213  };
2214 
2215  // operator+
2216  /**
2217  * @brief Concatenate two strings.
2218  * @param __lhs First string.
2219  * @param __rhs Last string.
2220  * @return New string with value of @a __lhs followed by @a __rhs.
2221  */
2222  template<typename _CharT, typename _Traits, typename _Alloc,
2223  template <typename, typename, typename> class _Base>
2224  __versa_string<_CharT, _Traits, _Alloc, _Base>
2225  operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2226  const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2227 
2228  /**
2229  * @brief Concatenate C string and string.
2230  * @param __lhs First string.
2231  * @param __rhs Last string.
2232  * @return New string with value of @a __lhs followed by @a __rhs.
2233  */
2234  template<typename _CharT, typename _Traits, typename _Alloc,
2235  template <typename, typename, typename> class _Base>
2236  __versa_string<_CharT, _Traits, _Alloc, _Base>
2237  operator+(const _CharT* __lhs,
2238  const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2239 
2240  /**
2241  * @brief Concatenate character and string.
2242  * @param __lhs First string.
2243  * @param __rhs Last string.
2244  * @return New string with @a __lhs followed by @a __rhs.
2245  */
2246  template<typename _CharT, typename _Traits, typename _Alloc,
2247  template <typename, typename, typename> class _Base>
2248  __versa_string<_CharT, _Traits, _Alloc, _Base>
2249  operator+(_CharT __lhs,
2250  const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2251 
2252  /**
2253  * @brief Concatenate string and C string.
2254  * @param __lhs First string.
2255  * @param __rhs Last string.
2256  * @return New string with @a __lhs followed by @a __rhs.
2257  */
2258  template<typename _CharT, typename _Traits, typename _Alloc,
2259  template <typename, typename, typename> class _Base>
2260  __versa_string<_CharT, _Traits, _Alloc, _Base>
2261  operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2262  const _CharT* __rhs);
2263 
2264  /**
2265  * @brief Concatenate string and character.
2266  * @param __lhs First string.
2267  * @param __rhs Last string.
2268  * @return New string with @a __lhs followed by @a __rhs.
2269  */
2270  template<typename _CharT, typename _Traits, typename _Alloc,
2271  template <typename, typename, typename> class _Base>
2272  __versa_string<_CharT, _Traits, _Alloc, _Base>
2273  operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2274  _CharT __rhs);
2275 
2276 #if __cplusplus >= 201103L
2277  template<typename _CharT, typename _Traits, typename _Alloc,
2278  template <typename, typename, typename> class _Base>
2279  inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2280  operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2281  const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2282  { return std::move(__lhs.append(__rhs)); }
2283 
2284  template<typename _CharT, typename _Traits, typename _Alloc,
2285  template <typename, typename, typename> class _Base>
2286  inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2287  operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2288  __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2289  { return std::move(__rhs.insert(0, __lhs)); }
2290 
2291  template<typename _CharT, typename _Traits, typename _Alloc,
2292  template <typename, typename, typename> class _Base>
2293  inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2294  operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2295  __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2296  {
2297  const auto __size = __lhs.size() + __rhs.size();
2298  const bool __cond = (__size > __lhs.capacity()
2299  && __size <= __rhs.capacity());
2300  return __cond ? std::move(__rhs.insert(0, __lhs))
2301  : std::move(__lhs.append(__rhs));
2302  }
2303 
2304  template<typename _CharT, typename _Traits, typename _Alloc,
2305  template <typename, typename, typename> class _Base>
2306  inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2307  operator+(const _CharT* __lhs,
2308  __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2309  { return std::move(__rhs.insert(0, __lhs)); }
2310 
2311  template<typename _CharT, typename _Traits, typename _Alloc,
2312  template <typename, typename, typename> class _Base>
2313  inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2314  operator+(_CharT __lhs,
2315  __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2316  { return std::move(__rhs.insert(0, 1, __lhs)); }
2317 
2318  template<typename _CharT, typename _Traits, typename _Alloc,
2319  template <typename, typename, typename> class _Base>
2320  inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2321  operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2322  const _CharT* __rhs)
2323  { return std::move(__lhs.append(__rhs)); }
2324 
2325  template<typename _CharT, typename _Traits, typename _Alloc,
2326  template <typename, typename, typename> class _Base>
2327  inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2328  operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2329  _CharT __rhs)
2330  { return std::move(__lhs.append(1, __rhs)); }
2331 #endif
2332 
2333  // operator ==
2334  /**
2335  * @brief Test equivalence of two strings.
2336  * @param __lhs First string.
2337  * @param __rhs Second string.
2338  * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2339  */
2340  template<typename _CharT, typename _Traits, typename _Alloc,
2341  template <typename, typename, typename> class _Base>
2342  inline bool
2345  {
2346  return __lhs.size() == __rhs.size()
2347  && !_Traits::compare(__lhs.data(), __rhs.data(), __lhs.size());
2348  }
2349 
2350  /**
2351  * @brief Test equivalence of string and C string.
2352  * @param __lhs String.
2353  * @param __rhs C string.
2354  * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2355  */
2356  template<typename _CharT, typename _Traits, typename _Alloc,
2357  template <typename, typename, typename> class _Base>
2358  inline bool
2360  const _CharT* __rhs)
2361  {
2362  return __lhs.size() == _Traits::length(__rhs)
2363  && !_Traits::compare(__lhs.data(), __rhs, __lhs.size());
2364  }
2365 
2366  /**
2367  * @brief Test equivalence of C string and string.
2368  * @param __lhs C string.
2369  * @param __rhs String.
2370  * @return True if @a __rhs.compare(@a __lhs) == 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 _CharT* __lhs,
2377  { return __rhs == __lhs; }
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
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,
2404  { return !(__rhs == __lhs); }
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
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,
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,
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
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
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,
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,
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,
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
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
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,
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
2591  { __lhs.swap(__rhs); }
2592 
2593 _GLIBCXX_END_NAMESPACE_VERSION
2594 } // namespace
2595 
2596 namespace 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>&
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>
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,
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>&
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 
2688 namespace __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 
2910 namespace 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  /// std::hash specialization for __wvstring.
2925  template<>
2926  struct hash<__gnu_cxx::__wvstring>
2927  : public __hash_base<size_t, __gnu_cxx::__wvstring>
2928  {
2929  size_t
2930  operator()(const __gnu_cxx::__wvstring& __s) const noexcept
2931  { return std::_Hash_impl::hash(__s.data(),
2932  __s.length() * sizeof(wchar_t)); }
2933  };
2934 
2935  /// std::hash specialization for __u16vstring.
2936  template<>
2937  struct hash<__gnu_cxx::__u16vstring>
2938  : public __hash_base<size_t, __gnu_cxx::__u16vstring>
2939  {
2940  size_t
2941  operator()(const __gnu_cxx::__u16vstring& __s) const noexcept
2942  { return std::_Hash_impl::hash(__s.data(),
2943  __s.length() * sizeof(char16_t)); }
2944  };
2945 
2946  /// std::hash specialization for __u32vstring.
2947  template<>
2948  struct hash<__gnu_cxx::__u32vstring>
2949  : public __hash_base<size_t, __gnu_cxx::__u32vstring>
2950  {
2951  size_t
2952  operator()(const __gnu_cxx::__u32vstring& __s) const noexcept
2953  { return std::_Hash_impl::hash(__s.data(),
2954  __s.length() * sizeof(char32_t)); }
2955  };
2956 
2957 _GLIBCXX_END_NAMESPACE_VERSION
2958 } // namespace
2959 
2960 #endif // C++11
2961 
2962 #include <ext/vstring.tcc>
2963 
2964 #endif /* _VSTRING_H */
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
Definition: complex:374
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition: move.h:138
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
Definition: stl_algobase.h:234
ISO C++ entities toplevel namespace is std.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
Definition: bitset:1602
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
Definition: bitset:1692
basic_istream< _CharT, _Traits > & getline(basic_istream< _CharT, _Traits > &__is, basic_string< _CharT, _Traits, _Alloc > &__str, _CharT __delim)
Read a line from stream into a string.
GNU extensions for public use.
constexpr _Iterator __base(_Iterator __it)
initializer_list
char_type widen(char __c) const
Widens characters.
Definition: basic_ios.h:464
Template class basic_istream.
Definition: istream:63
Template class basic_ostream.
Definition: ostream.h:67
Primary class template hash.
One of the comparison functors.
Definition: stl_function.h:401
Uniform interface to C++98 and C++11 allocators.
Template class __versa_string.
Definition: vstring.h:63
__versa_string & operator=(const _CharT *__s)
Copy contents of __s into this string.
Definition: vstring.h:298
void swap(__versa_string &__s) noexcept
Swap contents with another string.
Definition: vstring.h:1642
reverse_iterator rend() noexcept
Definition: vstring.h:378
iterator begin() noexcept
Definition: vstring.h:321
iterator end() noexcept
Definition: vstring.h:340
__versa_string & assign(_InputIterator __first, _InputIterator __last)
Set value to a range of characters.
Definition: vstring.h:915
iterator insert(const_iterator __p, _CharT __c)
Insert one character.
Definition: vstring.h:1151
size_type find_last_of(const _CharT *__s, size_type __pos=npos) const
Find last position of a character of C string.
Definition: vstring.h:1898
size_type find_last_of(const __versa_string &__str, size_type __pos=npos) const noexcept
Find last position of a character of string.
Definition: vstring.h:1868
__versa_string & operator+=(std::initializer_list< _CharT > __l)
Append an initializer_list of characters.
Definition: vstring.h:688
size_type find_first_not_of(const __versa_string &__str, size_type __pos=0) const noexcept
Find position of a character not in string.
Definition: vstring.h:1931
size_type find(const _CharT *__s, size_type __pos, size_type __n) const
Find position of a C substring.
Definition: vstring.tcc:274
const_reference at(size_type __n) const
Provides access to the data contained in the string.
Definition: vstring.h:583
size_type find_first_of(_CharT __c, size_type __pos=0) const noexcept
Find position of a character.
Definition: vstring.h:1853
__versa_string & replace(size_type __pos1, size_type __n1, const __versa_string &__str, size_type __pos2, size_type __n2)
Replace characters with value from another string.
Definition: vstring.h:1286
__versa_string & replace(const_iterator __i1, const_iterator __i2, const __versa_string &__str)
Replace range of characters with string.
Definition: vstring.h:1381
const_reference front() const noexcept
Definition: vstring.h:630
__versa_string & insert(size_type __pos, size_type __n, _CharT __c)
Insert multiple characters.
Definition: vstring.h:1132
__versa_string & assign(const __versa_string &__str)
Set value to contents of another string.
Definition: vstring.h:809
__versa_string & assign(__versa_string &&__str) noexcept
Set value to contents of another string.
Definition: vstring.h:825
__versa_string & replace(size_type __pos, size_type __n1, const _CharT *__s, size_type __n2)
Replace characters with value of a C substring.
Definition: vstring.h:1314
__versa_string & insert(size_type __pos1, const __versa_string &__str)
Insert value of a string.
Definition: vstring.h:1043
__versa_string & append(size_type __n, _CharT __c)
Append multiple characters.
Definition: vstring.h:757
size_type find_last_not_of(const __versa_string &__str, size_type __pos=npos) const noexcept
Find last position of a character not in string.
Definition: vstring.h:1994
__versa_string & operator=(__versa_string &&__str) noexcept
String move assignment operator.
Definition: vstring.h:274
const_iterator cend() const noexcept
Definition: vstring.h:404
__versa_string & replace(const_iterator __i1, const_iterator __i2, const _CharT *__s, size_type __n)
Replace range of characters with C substring.
Definition: vstring.h:1404
__versa_string & operator+=(const __versa_string &__str)
Append a string to this string.
Definition: vstring.h:657
const _CharT * data() const noexcept
Return const pointer to contents.
Definition: vstring.h:1663
__versa_string & append(std::initializer_list< _CharT > __l)
Append an initializer_list of characters.
Definition: vstring.h:767
size_type find_first_of(const __versa_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
Definition: vstring.h:1804
__versa_string(_InputIterator __beg, _InputIterator __end, const _Alloc &__a=_Alloc())
Construct string as copy of a range.
Definition: vstring.h:248
__versa_string(const _Alloc &__a=_Alloc()) noexcept
Construct an empty string using allocator a.
Definition: vstring.h:143
__versa_string & insert(size_type __pos1, const __versa_string &__str, size_type __pos2, size_type __n)
Insert a substring.
Definition: vstring.h:1066
size_type find(const __versa_string &__str, size_type __pos=0) const noexcept
Find position of a string.
Definition: vstring.h:1699
const_reverse_iterator rbegin() const noexcept
Definition: vstring.h:369
size_type find_last_not_of(const _CharT *__s, size_type __pos=npos) const
Find last position of a character not in C string.
Definition: vstring.h:2025
__versa_string(std::initializer_list< _CharT > __l, const _Alloc &__a=_Alloc())
Construct string from an initializer list.
Definition: vstring.h:171
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
Definition: vstring.tcc:54
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
Definition: vstring.h:1653
allocator_type get_allocator() const noexcept
Return copy of allocator used to construct this string.
Definition: vstring.h:1670
iterator erase(const_iterator __position)
Remove one character.
Definition: vstring.h:1196
size_type capacity() const noexcept
Definition: vstring.h:492
__versa_string & operator+=(const _CharT *__s)
Append a C string.
Definition: vstring.h:666
__versa_string & operator=(const __versa_string &__str)
Assign the value of str to this string.
Definition: vstring.h:262
iterator insert(const_iterator __p, std::initializer_list< _CharT > __l)
Insert an initializer_list of characters.
Definition: vstring.h:1026
__versa_string & assign(const _CharT *__s, size_type __n)
Set value to a C substring.
Definition: vstring.h:863
~__versa_string() noexcept
Destroy the string instance.
Definition: vstring.h:255
static const size_type npos
Value returned by various member functions when they fail.
Definition: vstring.h:87
reference back() noexcept
Definition: vstring.h:638
__versa_string & insert(size_type __pos, const _CharT *__s, size_type __n)
Insert a C substring.
Definition: vstring.h:1089
size_type find_first_not_of(const _CharT *__s, size_type __pos=0) const
Find position of a character not in C string.
Definition: vstring.h:1962
reference at(size_type __n)
Provides access to the data contained in the string.
Definition: vstring.h:605
iterator erase(const_iterator __first, const_iterator __last)
Remove a range of characters.
Definition: vstring.h:1221
__versa_string(__versa_string &&__str) noexcept
String move constructor.
Definition: vstring.h:163
size_type length() const noexcept
Returns the number of characters in the string, not including any null-termination.
Definition: vstring.h:437
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
Definition: vstring.h:431
__versa_string & append(const __versa_string &__str)
Append a string to this string.
Definition: vstring.h:698
int compare(const __versa_string &__str) const
Compare to a string.
Definition: vstring.h:2079
void shrink_to_fit() noexcept
A non-binding request to reduce capacity() to size().
Definition: vstring.h:475
__versa_string & replace(const_iterator __i1, const_iterator __i2, _InputIterator __k1, _InputIterator __k2)
Replace range of characters with range.
Definition: vstring.h:1484
__versa_string(size_type __n, _CharT __c, const _Alloc &__a=_Alloc())
Construct string as multiple characters.
Definition: vstring.h:233
__versa_string & insert(size_type __pos, const _CharT *__s)
Insert a C string.
Definition: vstring.h:1108
__versa_string & replace(const_iterator __i1, const_iterator __i2, std::initializer_list< _CharT > __l)
Replace range of characters with initializer_list.
Definition: vstring.h:1588
bool empty() const noexcept
Definition: vstring.h:528
reference operator[](size_type __pos) noexcept
Subscript access to the data contained in the string.
Definition: vstring.h:560
__versa_string(const _CharT *__s, size_type __n, const _Alloc &__a=_Alloc())
Construct string initialized by a character array.
Definition: vstring.h:214
iterator insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
Insert a range of characters.
Definition: vstring.h:990
__versa_string & append(_InputIterator __first, _InputIterator __last)
Append a range of characters.
Definition: vstring.h:786
__versa_string & assign(const _CharT *__s)
Set value to contents of a C string.
Definition: vstring.h:879
__versa_string & operator=(_CharT __c)
Set value to string of length 1.
Definition: vstring.h:309
const_reference back() const noexcept
Definition: vstring.h:646
__versa_string & operator=(std::initializer_list< _CharT > __l)
Set value to string constructed from initializer list.
Definition: vstring.h:286
void resize(size_type __n)
Resizes the string to the specified number of characters.
Definition: vstring.h:469
const_reverse_iterator crbegin() const noexcept
Definition: vstring.h:413
__versa_string & replace(const_iterator __i1, const_iterator __i2, const _CharT *__s)
Replace range of characters with C string.
Definition: vstring.h:1430
const_iterator begin() const noexcept
Definition: vstring.h:332
const_reverse_iterator rend() const noexcept
Definition: vstring.h:387
__versa_string & replace(size_type __pos, size_type __n, const __versa_string &__str)
Replace characters with value from another string.
Definition: vstring.h:1263
const_reference operator[](size_type __pos) const noexcept
Subscript access to the data contained in the string.
Definition: vstring.h:543
__versa_string & assign(std::initializer_list< _CharT > __l)
Set value to an initializer_list of characters.
Definition: vstring.h:925
__versa_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
Definition: vstring.h:2058
__versa_string & assign(const __versa_string &__str, size_type __pos, size_type __n)
Set value to a substring of a string.
Definition: vstring.h:846
void clear() noexcept
Definition: vstring.h:520
__versa_string(const _CharT *__s, const _Alloc &__a=_Alloc())
Construct string as copy of a C string.
Definition: vstring.h:223
__versa_string(const __versa_string &__str, size_type __pos, size_type __n=npos)
Construct string as copy of a substring.
Definition: vstring.h:182
__versa_string(const __versa_string &__str, size_type __pos, size_type __n, const _Alloc &__a)
Construct string as copy of a substring.
Definition: vstring.h:197
__versa_string & operator+=(_CharT __c)
Append a character.
Definition: vstring.h:675
size_type max_size() const noexcept
Returns the size() of the largest possible string.
Definition: vstring.h:442
const_iterator end() const noexcept
Definition: vstring.h:351
__versa_string & replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
Replace characters with multiple characters.
Definition: vstring.h:1362
const_iterator cbegin() const noexcept
Definition: vstring.h:396
__versa_string & assign(size_type __n, _CharT __c)
Set value to multiple characters.
Definition: vstring.h:896
size_type rfind(const _CharT *__s, size_type __pos=npos) const
Find last position of a C string.
Definition: vstring.h:1774
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C string.
Definition: vstring.tcc:259
__versa_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
Definition: vstring.h:1179
size_type find_first_of(const _CharT *__s, size_type __pos=0) const
Find position of a character of C string.
Definition: vstring.h:1834
iterator insert(const_iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
Definition: vstring.h:946
void push_back(_CharT __c)
Append a single character.
Definition: vstring.h:794
size_type find_last_of(_CharT __c, size_type __pos=npos) const noexcept
Find last position of a character.
Definition: vstring.h:1917
__versa_string & replace(size_type __pos, size_type __n1, const _CharT *__s)
Replace characters with value of a C string.
Definition: vstring.h:1338
__versa_string & append(const __versa_string &__str, size_type __pos, size_type __n)
Append a substring.
Definition: vstring.h:715
reference front() noexcept
Definition: vstring.h:622
__versa_string & append(const _CharT *__s)
Append a C string.
Definition: vstring.h:740
__versa_string(const __versa_string &__str)
Construct string with copy of value of __str.
Definition: vstring.h:151
__versa_string & append(const _CharT *__s, size_type __n)
Append a C substring.
Definition: vstring.h:727
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
Definition: vstring.h:513
size_type rfind(const __versa_string &__str, size_type __pos=npos) const noexcept
Find last position of a string.
Definition: vstring.h:1744
const_reverse_iterator crend() const noexcept
Definition: vstring.h:422
__versa_string & replace(const_iterator __i1, const_iterator __i2, size_type __n, _CharT __c)
Replace range of characters with multiple characters.
Definition: vstring.h:1455
void pop_back()
Remove the last character.
Definition: vstring.h:1241
reverse_iterator rbegin() noexcept
Definition: vstring.h:360
size_type find(const _CharT *__s, size_type __pos=0) const
Find position of a C string.
Definition: vstring.h:1714