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