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