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