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