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