OSDN Git Service

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