OSDN Git Service

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