OSDN Git Service

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