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