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