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