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