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