xref: /dflybsd-src/contrib/gcc-8.0/libstdc++-v3/include/ext/vstring.h (revision 95059079af47f9a66a175f374f2da1a5020e3255)
138fd1498Szrj // Versatile string -*- C++ -*-
238fd1498Szrj 
338fd1498Szrj // Copyright (C) 2005-2018 Free Software Foundation, Inc.
438fd1498Szrj //
538fd1498Szrj // This file is part of the GNU ISO C++ Library.  This library is free
638fd1498Szrj // software; you can redistribute it and/or modify it under the
738fd1498Szrj // terms of the GNU General Public License as published by the
838fd1498Szrj // Free Software Foundation; either version 3, or (at your option)
938fd1498Szrj // any later version.
1038fd1498Szrj 
1138fd1498Szrj // This library is distributed in the hope that it will be useful,
1238fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
1338fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1438fd1498Szrj // GNU General Public License for more details.
1538fd1498Szrj 
1638fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional
1738fd1498Szrj // permissions described in the GCC Runtime Library Exception, version
1838fd1498Szrj // 3.1, as published by the Free Software Foundation.
1938fd1498Szrj 
2038fd1498Szrj // You should have received a copy of the GNU General Public License and
2138fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program;
2238fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
2338fd1498Szrj // <http://www.gnu.org/licenses/>.
2438fd1498Szrj 
2538fd1498Szrj /** @file ext/vstring.h
2638fd1498Szrj  *  This file is a GNU extension to the Standard C++ Library.
2738fd1498Szrj  */
2838fd1498Szrj 
2938fd1498Szrj #ifndef _VSTRING_H
3038fd1498Szrj #define _VSTRING_H 1
3138fd1498Szrj 
3238fd1498Szrj #pragma GCC system_header
3338fd1498Szrj 
3438fd1498Szrj #if __cplusplus >= 201103L
3538fd1498Szrj #include <initializer_list>
3638fd1498Szrj #endif
3738fd1498Szrj 
3838fd1498Szrj #include <ext/vstring_util.h>
3938fd1498Szrj #include <ext/rc_string_base.h>
4038fd1498Szrj #include <ext/sso_string_base.h>
4138fd1498Szrj 
_GLIBCXX_VISIBILITY(default)4238fd1498Szrj namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
4338fd1498Szrj {
4438fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
4538fd1498Szrj 
4638fd1498Szrj   /**
4738fd1498Szrj    *  @class __versa_string vstring.h
4838fd1498Szrj    *  @brief  Template class __versa_string.
4938fd1498Szrj    *  @ingroup extensions
5038fd1498Szrj    *
5138fd1498Szrj    *  Data structure managing sequences of characters and
5238fd1498Szrj    *  character-like objects.
5338fd1498Szrj    */
5438fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
5538fd1498Szrj 	   template <typename, typename, typename> class _Base>
5638fd1498Szrj     class __versa_string
5738fd1498Szrj     : private _Base<_CharT, _Traits, _Alloc>
5838fd1498Szrj     {
5938fd1498Szrj       typedef _Base<_CharT, _Traits, _Alloc>                __vstring_base;
6038fd1498Szrj       typedef typename __vstring_base::_CharT_alloc_type    _CharT_alloc_type;
6138fd1498Szrj 
6238fd1498Szrj       // Types:
6338fd1498Szrj     public:
6438fd1498Szrj       typedef _Traits					    traits_type;
6538fd1498Szrj       typedef typename _Traits::char_type		    value_type;
6638fd1498Szrj       typedef _Alloc					    allocator_type;
6738fd1498Szrj       typedef typename _CharT_alloc_type::size_type	    size_type;
6838fd1498Szrj       typedef typename _CharT_alloc_type::difference_type   difference_type;
6938fd1498Szrj       typedef value_type&               	            reference;
7038fd1498Szrj       typedef const value_type&                             const_reference;
7138fd1498Szrj       typedef typename _CharT_alloc_type::pointer	    pointer;
7238fd1498Szrj       typedef typename _CharT_alloc_type::const_pointer	    const_pointer;
7338fd1498Szrj       typedef __gnu_cxx::__normal_iterator<pointer, __versa_string>  iterator;
7438fd1498Szrj       typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
7538fd1498Szrj                                                             const_iterator;
7638fd1498Szrj       typedef std::reverse_iterator<const_iterator>	const_reverse_iterator;
7738fd1498Szrj       typedef std::reverse_iterator<iterator>		    reverse_iterator;
7838fd1498Szrj 
7938fd1498Szrj       // Data Member (public):
8038fd1498Szrj       ///  Value returned by various member functions when they fail.
8138fd1498Szrj       static const size_type	npos = static_cast<size_type>(-1);
8238fd1498Szrj 
8338fd1498Szrj     private:
8438fd1498Szrj       size_type
8538fd1498Szrj       _M_check(size_type __pos, const char* __s) const
8638fd1498Szrj       {
8738fd1498Szrj 	if (__pos > this->size())
8838fd1498Szrj 	  std::__throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
8938fd1498Szrj 					    "this->size() (which is %zu)"),
9038fd1498Szrj 					__s, __pos, this->size());
9138fd1498Szrj 	return __pos;
9238fd1498Szrj       }
9338fd1498Szrj 
9438fd1498Szrj       void
9538fd1498Szrj       _M_check_length(size_type __n1, size_type __n2, const char* __s) const
9638fd1498Szrj       {
9738fd1498Szrj 	if (this->max_size() - (this->size() - __n1) < __n2)
9838fd1498Szrj 	  std::__throw_length_error(__N(__s));
9938fd1498Szrj       }
10038fd1498Szrj 
10138fd1498Szrj       // NB: _M_limit doesn't check for a bad __pos value.
10238fd1498Szrj       size_type
10338fd1498Szrj       _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT
10438fd1498Szrj       {
10538fd1498Szrj 	const bool __testoff =  __off < this->size() - __pos;
10638fd1498Szrj 	return __testoff ? __off : this->size() - __pos;
10738fd1498Szrj       }
10838fd1498Szrj 
10938fd1498Szrj       // True if _Rep and source do not overlap.
11038fd1498Szrj       bool
11138fd1498Szrj       _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT
11238fd1498Szrj       {
11338fd1498Szrj 	return (std::less<const _CharT*>()(__s, this->_M_data())
11438fd1498Szrj 		|| std::less<const _CharT*>()(this->_M_data()
11538fd1498Szrj 					      + this->size(), __s));
11638fd1498Szrj       }
11738fd1498Szrj 
11838fd1498Szrj       // For the internal use we have functions similar to `begin'/`end'
11938fd1498Szrj       // but they do not call _M_leak.
12038fd1498Szrj       iterator
12138fd1498Szrj       _M_ibegin() const _GLIBCXX_NOEXCEPT
12238fd1498Szrj       { return iterator(this->_M_data()); }
12338fd1498Szrj 
12438fd1498Szrj       iterator
12538fd1498Szrj       _M_iend() const _GLIBCXX_NOEXCEPT
12638fd1498Szrj       { return iterator(this->_M_data() + this->_M_length()); }
12738fd1498Szrj 
12838fd1498Szrj     public:
12938fd1498Szrj       // Construct/copy/destroy:
13038fd1498Szrj       // NB: We overload ctors in some cases instead of using default
13138fd1498Szrj       // arguments, per 17.4.4.4 para. 2 item 2.
13238fd1498Szrj 
13338fd1498Szrj       /**
13438fd1498Szrj        *  @brief  Construct an empty string using allocator @a a.
13538fd1498Szrj        */
13638fd1498Szrj       explicit
13738fd1498Szrj       __versa_string(const _Alloc& __a = _Alloc()) _GLIBCXX_NOEXCEPT
13838fd1498Szrj       : __vstring_base(__a) { }
13938fd1498Szrj 
14038fd1498Szrj       // NB: per LWG issue 42, semantics different from IS:
14138fd1498Szrj       /**
14238fd1498Szrj        *  @brief  Construct string with copy of value of @a __str.
14338fd1498Szrj        *  @param  __str  Source string.
14438fd1498Szrj        */
14538fd1498Szrj       __versa_string(const __versa_string& __str)
14638fd1498Szrj       : __vstring_base(__str) { }
14738fd1498Szrj 
14838fd1498Szrj #if __cplusplus >= 201103L
14938fd1498Szrj       /**
15038fd1498Szrj        *  @brief  String move constructor.
15138fd1498Szrj        *  @param  __str  Source string.
15238fd1498Szrj        *
15338fd1498Szrj        *  The newly-constructed %string contains the exact contents of
15438fd1498Szrj        *  @a __str.  The contents of @a __str are a valid, but unspecified
15538fd1498Szrj        *  string.
15638fd1498Szrj        */
15738fd1498Szrj       __versa_string(__versa_string&& __str) noexcept
15838fd1498Szrj       : __vstring_base(std::move(__str)) { }
15938fd1498Szrj 
16038fd1498Szrj       /**
16138fd1498Szrj        *  @brief  Construct string from an initializer list.
16238fd1498Szrj        *  @param  __l  std::initializer_list of characters.
16338fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
16438fd1498Szrj        */
16538fd1498Szrj       __versa_string(std::initializer_list<_CharT> __l,
16638fd1498Szrj 		     const _Alloc& __a = _Alloc())
16738fd1498Szrj       : __vstring_base(__l.begin(), __l.end(), __a) { }
16838fd1498Szrj #endif
16938fd1498Szrj 
17038fd1498Szrj       /**
17138fd1498Szrj        *  @brief  Construct string as copy of a substring.
17238fd1498Szrj        *  @param  __str  Source string.
17338fd1498Szrj        *  @param  __pos  Index of first character to copy from.
17438fd1498Szrj        *  @param  __n  Number of characters to copy (default remainder).
17538fd1498Szrj        */
17638fd1498Szrj       __versa_string(const __versa_string& __str, size_type __pos,
17738fd1498Szrj 		     size_type __n = npos)
17838fd1498Szrj       : __vstring_base(__str._M_data()
17938fd1498Szrj 		       + __str._M_check(__pos,
18038fd1498Szrj 					"__versa_string::__versa_string"),
18138fd1498Szrj 		       __str._M_data() + __str._M_limit(__pos, __n)
18238fd1498Szrj 		       + __pos, _Alloc()) { }
18338fd1498Szrj 
18438fd1498Szrj       /**
18538fd1498Szrj        *  @brief  Construct string as copy of a substring.
18638fd1498Szrj        *  @param  __str  Source string.
18738fd1498Szrj        *  @param  __pos  Index of first character to copy from.
18838fd1498Szrj        *  @param  __n  Number of characters to copy.
18938fd1498Szrj        *  @param  __a  Allocator to use.
19038fd1498Szrj        */
19138fd1498Szrj       __versa_string(const __versa_string& __str, size_type __pos,
19238fd1498Szrj 		     size_type __n, const _Alloc& __a)
19338fd1498Szrj       : __vstring_base(__str._M_data()
19438fd1498Szrj 		       + __str._M_check(__pos,
19538fd1498Szrj 					"__versa_string::__versa_string"),
19638fd1498Szrj 		       __str._M_data() + __str._M_limit(__pos, __n)
19738fd1498Szrj 		       + __pos, __a) { }
19838fd1498Szrj 
19938fd1498Szrj       /**
20038fd1498Szrj        *  @brief  Construct string initialized by a character array.
20138fd1498Szrj        *  @param  __s  Source character array.
20238fd1498Szrj        *  @param  __n  Number of characters to copy.
20338fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
20438fd1498Szrj        *
20538fd1498Szrj        *  NB: @a __s must have at least @a __n characters, '\\0' has no special
20638fd1498Szrj        *  meaning.
20738fd1498Szrj        */
20838fd1498Szrj       __versa_string(const _CharT* __s, size_type __n,
20938fd1498Szrj 		     const _Alloc& __a = _Alloc())
21038fd1498Szrj       : __vstring_base(__s, __s + __n, __a) { }
21138fd1498Szrj 
21238fd1498Szrj       /**
21338fd1498Szrj        *  @brief  Construct string as copy of a C string.
21438fd1498Szrj        *  @param  __s  Source C string.
21538fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
21638fd1498Szrj        */
21738fd1498Szrj       __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc())
21838fd1498Szrj       : __vstring_base(__s, __s ? __s + traits_type::length(__s) :
21938fd1498Szrj 		       __s + npos, __a) { }
22038fd1498Szrj 
22138fd1498Szrj       /**
22238fd1498Szrj        *  @brief  Construct string as multiple characters.
22338fd1498Szrj        *  @param  __n  Number of characters.
22438fd1498Szrj        *  @param  __c  Character to use.
22538fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
22638fd1498Szrj        */
22738fd1498Szrj       __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
22838fd1498Szrj       : __vstring_base(__n, __c, __a) { }
22938fd1498Szrj 
23038fd1498Szrj       /**
23138fd1498Szrj        *  @brief  Construct string as copy of a range.
23238fd1498Szrj        *  @param  __beg  Start of range.
23338fd1498Szrj        *  @param  __end  End of range.
23438fd1498Szrj        *  @param  __a  Allocator to use (default is default allocator).
23538fd1498Szrj        */
23638fd1498Szrj #if __cplusplus >= 201103L
23738fd1498Szrj       template<class _InputIterator,
23838fd1498Szrj 	       typename = std::_RequireInputIter<_InputIterator>>
23938fd1498Szrj #else
24038fd1498Szrj       template<class _InputIterator>
24138fd1498Szrj #endif
24238fd1498Szrj         __versa_string(_InputIterator __beg, _InputIterator __end,
24338fd1498Szrj 		       const _Alloc& __a = _Alloc())
24438fd1498Szrj 	: __vstring_base(__beg, __end, __a) { }
24538fd1498Szrj 
24638fd1498Szrj       /**
24738fd1498Szrj        *  @brief  Destroy the string instance.
24838fd1498Szrj        */
24938fd1498Szrj       ~__versa_string() _GLIBCXX_NOEXCEPT { }
25038fd1498Szrj 
25138fd1498Szrj       /**
25238fd1498Szrj        *  @brief  Assign the value of @a str to this string.
25338fd1498Szrj        *  @param  __str  Source string.
25438fd1498Szrj        */
25538fd1498Szrj       __versa_string&
25638fd1498Szrj       operator=(const __versa_string& __str)
25738fd1498Szrj       { return this->assign(__str); }
25838fd1498Szrj 
25938fd1498Szrj #if __cplusplus >= 201103L
26038fd1498Szrj       /**
26138fd1498Szrj        *  @brief  String move assignment operator.
26238fd1498Szrj        *  @param  __str  Source string.
26338fd1498Szrj        *
26438fd1498Szrj        *  The contents of @a __str are moved into this string (without
26538fd1498Szrj        *  copying).  @a __str is a valid, but unspecified string.
26638fd1498Szrj        */
26738fd1498Szrj       __versa_string&
26838fd1498Szrj       operator=(__versa_string&& __str) noexcept
26938fd1498Szrj       {
27038fd1498Szrj 	// NB: DR 1204.
27138fd1498Szrj 	this->swap(__str);
27238fd1498Szrj 	return *this;
27338fd1498Szrj       }
27438fd1498Szrj 
27538fd1498Szrj       /**
27638fd1498Szrj        *  @brief  Set value to string constructed from initializer list.
27738fd1498Szrj        *  @param  __l  std::initializer_list.
27838fd1498Szrj        */
27938fd1498Szrj       __versa_string&
28038fd1498Szrj       operator=(std::initializer_list<_CharT> __l)
28138fd1498Szrj       {
28238fd1498Szrj 	this->assign(__l.begin(), __l.end());
28338fd1498Szrj 	return *this;
28438fd1498Szrj       }
28538fd1498Szrj #endif
28638fd1498Szrj 
28738fd1498Szrj       /**
28838fd1498Szrj        *  @brief  Copy contents of @a __s into this string.
28938fd1498Szrj        *  @param  __s  Source null-terminated string.
29038fd1498Szrj        */
29138fd1498Szrj       __versa_string&
29238fd1498Szrj       operator=(const _CharT* __s)
29338fd1498Szrj       { return this->assign(__s); }
29438fd1498Szrj 
29538fd1498Szrj       /**
29638fd1498Szrj        *  @brief  Set value to string of length 1.
29738fd1498Szrj        *  @param  __c  Source character.
29838fd1498Szrj        *
29938fd1498Szrj        *  Assigning to a character makes this string length 1 and
30038fd1498Szrj        *  (*this)[0] == @a __c.
30138fd1498Szrj        */
30238fd1498Szrj       __versa_string&
30338fd1498Szrj       operator=(_CharT __c)
30438fd1498Szrj       {
30538fd1498Szrj 	this->assign(1, __c);
30638fd1498Szrj 	return *this;
30738fd1498Szrj       }
30838fd1498Szrj 
30938fd1498Szrj       // Iterators:
31038fd1498Szrj       /**
31138fd1498Szrj        *  Returns a read/write iterator that points to the first character in
31238fd1498Szrj        *  the %string.  Unshares the string.
31338fd1498Szrj        */
31438fd1498Szrj       iterator
31538fd1498Szrj       begin() _GLIBCXX_NOEXCEPT
31638fd1498Szrj       {
31738fd1498Szrj 	this->_M_leak();
31838fd1498Szrj 	return iterator(this->_M_data());
31938fd1498Szrj       }
32038fd1498Szrj 
32138fd1498Szrj       /**
32238fd1498Szrj        *  Returns a read-only (constant) iterator that points to the first
32338fd1498Szrj        *  character in the %string.
32438fd1498Szrj        */
32538fd1498Szrj       const_iterator
32638fd1498Szrj       begin() const _GLIBCXX_NOEXCEPT
32738fd1498Szrj       { return const_iterator(this->_M_data()); }
32838fd1498Szrj 
32938fd1498Szrj       /**
33038fd1498Szrj        *  Returns a read/write iterator that points one past the last
33138fd1498Szrj        *  character in the %string.  Unshares the string.
33238fd1498Szrj        */
33338fd1498Szrj       iterator
33438fd1498Szrj       end() _GLIBCXX_NOEXCEPT
33538fd1498Szrj       {
33638fd1498Szrj 	this->_M_leak();
33738fd1498Szrj 	return iterator(this->_M_data() + this->size());
33838fd1498Szrj       }
33938fd1498Szrj 
34038fd1498Szrj       /**
34138fd1498Szrj        *  Returns a read-only (constant) iterator that points one past the
34238fd1498Szrj        *  last character in the %string.
34338fd1498Szrj        */
34438fd1498Szrj       const_iterator
34538fd1498Szrj       end() const _GLIBCXX_NOEXCEPT
34638fd1498Szrj       { return const_iterator(this->_M_data() + this->size()); }
34738fd1498Szrj 
34838fd1498Szrj       /**
34938fd1498Szrj        *  Returns a read/write reverse iterator that points to the last
35038fd1498Szrj        *  character in the %string.  Iteration is done in reverse element
35138fd1498Szrj        *  order.  Unshares the string.
35238fd1498Szrj        */
35338fd1498Szrj       reverse_iterator
35438fd1498Szrj       rbegin() _GLIBCXX_NOEXCEPT
35538fd1498Szrj       { return reverse_iterator(this->end()); }
35638fd1498Szrj 
35738fd1498Szrj       /**
35838fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points
35938fd1498Szrj        *  to the last character in the %string.  Iteration is done in
36038fd1498Szrj        *  reverse element order.
36138fd1498Szrj        */
36238fd1498Szrj       const_reverse_iterator
36338fd1498Szrj       rbegin() const _GLIBCXX_NOEXCEPT
36438fd1498Szrj       { return const_reverse_iterator(this->end()); }
36538fd1498Szrj 
36638fd1498Szrj       /**
36738fd1498Szrj        *  Returns a read/write reverse iterator that points to one before the
36838fd1498Szrj        *  first character in the %string.  Iteration is done in reverse
36938fd1498Szrj        *  element order.  Unshares the string.
37038fd1498Szrj        */
37138fd1498Szrj       reverse_iterator
37238fd1498Szrj       rend() _GLIBCXX_NOEXCEPT
37338fd1498Szrj       { return reverse_iterator(this->begin()); }
37438fd1498Szrj 
37538fd1498Szrj       /**
37638fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points
37738fd1498Szrj        *  to one before the first character in the %string.  Iteration
37838fd1498Szrj        *  is done in reverse element order.
37938fd1498Szrj        */
38038fd1498Szrj       const_reverse_iterator
38138fd1498Szrj       rend() const _GLIBCXX_NOEXCEPT
38238fd1498Szrj       { return const_reverse_iterator(this->begin()); }
38338fd1498Szrj 
38438fd1498Szrj #if __cplusplus >= 201103L
38538fd1498Szrj       /**
38638fd1498Szrj        *  Returns a read-only (constant) iterator that points to the first
38738fd1498Szrj        *  character in the %string.
38838fd1498Szrj        */
38938fd1498Szrj       const_iterator
39038fd1498Szrj       cbegin() const noexcept
39138fd1498Szrj       { return const_iterator(this->_M_data()); }
39238fd1498Szrj 
39338fd1498Szrj       /**
39438fd1498Szrj        *  Returns a read-only (constant) iterator that points one past the
39538fd1498Szrj        *  last character in the %string.
39638fd1498Szrj        */
39738fd1498Szrj       const_iterator
39838fd1498Szrj       cend() const noexcept
39938fd1498Szrj       { return const_iterator(this->_M_data() + this->size()); }
40038fd1498Szrj 
40138fd1498Szrj       /**
40238fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points
40338fd1498Szrj        *  to the last character in the %string.  Iteration is done in
40438fd1498Szrj        *  reverse element order.
40538fd1498Szrj        */
40638fd1498Szrj       const_reverse_iterator
40738fd1498Szrj       crbegin() const noexcept
40838fd1498Szrj       { return const_reverse_iterator(this->end()); }
40938fd1498Szrj 
41038fd1498Szrj       /**
41138fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points
41238fd1498Szrj        *  to one before the first character in the %string.  Iteration
41338fd1498Szrj        *  is done in reverse element order.
41438fd1498Szrj        */
41538fd1498Szrj       const_reverse_iterator
41638fd1498Szrj       crend() const noexcept
41738fd1498Szrj       { return const_reverse_iterator(this->begin()); }
41838fd1498Szrj #endif
41938fd1498Szrj 
42038fd1498Szrj     public:
42138fd1498Szrj       // Capacity:
42238fd1498Szrj       ///  Returns the number of characters in the string, not including any
42338fd1498Szrj       ///  null-termination.
42438fd1498Szrj       size_type
42538fd1498Szrj       size() const _GLIBCXX_NOEXCEPT
42638fd1498Szrj       { return this->_M_length(); }
42738fd1498Szrj 
42838fd1498Szrj       ///  Returns the number of characters in the string, not including any
42938fd1498Szrj       ///  null-termination.
43038fd1498Szrj       size_type
43138fd1498Szrj       length() const _GLIBCXX_NOEXCEPT
43238fd1498Szrj       { return this->_M_length(); }
43338fd1498Szrj 
43438fd1498Szrj       /// Returns the size() of the largest possible %string.
43538fd1498Szrj       size_type
43638fd1498Szrj       max_size() const _GLIBCXX_NOEXCEPT
43738fd1498Szrj       { return this->_M_max_size(); }
43838fd1498Szrj 
43938fd1498Szrj       /**
44038fd1498Szrj        *  @brief  Resizes the %string to the specified number of characters.
44138fd1498Szrj        *  @param  __n  Number of characters the %string should contain.
44238fd1498Szrj        *  @param  __c  Character to fill any new elements.
44338fd1498Szrj        *
44438fd1498Szrj        *  This function will %resize the %string to the specified
44538fd1498Szrj        *  number of characters.  If the number is smaller than the
44638fd1498Szrj        *  %string's current size the %string is truncated, otherwise
44738fd1498Szrj        *  the %string is extended and new elements are set to @a __c.
44838fd1498Szrj        */
44938fd1498Szrj       void
45038fd1498Szrj       resize(size_type __n, _CharT __c);
45138fd1498Szrj 
45238fd1498Szrj       /**
45338fd1498Szrj        *  @brief  Resizes the %string to the specified number of characters.
45438fd1498Szrj        *  @param  __n  Number of characters the %string should contain.
45538fd1498Szrj        *
45638fd1498Szrj        *  This function will resize the %string to the specified
45738fd1498Szrj        *  length.  If the new size is smaller than the %string's
45838fd1498Szrj        *  current size the %string is truncated, otherwise the %string
45938fd1498Szrj        *  is extended and new characters are default-constructed.  For
46038fd1498Szrj        *  basic types such as char, this means setting them to 0.
46138fd1498Szrj        */
46238fd1498Szrj       void
46338fd1498Szrj       resize(size_type __n)
46438fd1498Szrj       { this->resize(__n, _CharT()); }
46538fd1498Szrj 
46638fd1498Szrj #if __cplusplus >= 201103L
46738fd1498Szrj       /// A non-binding request to reduce capacity() to size().
46838fd1498Szrj       void
46938fd1498Szrj       shrink_to_fit() noexcept
47038fd1498Szrj       {
47138fd1498Szrj 	if (capacity() > size())
47238fd1498Szrj 	  {
47338fd1498Szrj 	    __try
47438fd1498Szrj 	      { this->reserve(0); }
47538fd1498Szrj 	    __catch(...)
47638fd1498Szrj 	      { }
47738fd1498Szrj 	  }
47838fd1498Szrj       }
47938fd1498Szrj #endif
48038fd1498Szrj 
48138fd1498Szrj       /**
48238fd1498Szrj        *  Returns the total number of characters that the %string can
48338fd1498Szrj        *  hold before needing to allocate more memory.
48438fd1498Szrj        */
48538fd1498Szrj       size_type
48638fd1498Szrj       capacity() const _GLIBCXX_NOEXCEPT
48738fd1498Szrj       { return this->_M_capacity(); }
48838fd1498Szrj 
48938fd1498Szrj       /**
49038fd1498Szrj        *  @brief  Attempt to preallocate enough memory for specified number of
49138fd1498Szrj        *          characters.
49238fd1498Szrj        *  @param  __res_arg  Number of characters required.
49338fd1498Szrj        *  @throw  std::length_error  If @a __res_arg exceeds @c max_size().
49438fd1498Szrj        *
49538fd1498Szrj        *  This function attempts to reserve enough memory for the
49638fd1498Szrj        *  %string to hold the specified number of characters.  If the
49738fd1498Szrj        *  number requested is more than max_size(), length_error is
49838fd1498Szrj        *  thrown.
49938fd1498Szrj        *
50038fd1498Szrj        *  The advantage of this function is that if optimal code is a
50138fd1498Szrj        *  necessity and the user can determine the string length that
50238fd1498Szrj        *  will be required, the user can reserve the memory in
50338fd1498Szrj        *  %advance, and thus prevent a possible reallocation of memory
50438fd1498Szrj        *  and copying of %string data.
50538fd1498Szrj        */
50638fd1498Szrj       void
50738fd1498Szrj       reserve(size_type __res_arg = 0)
50838fd1498Szrj       { this->_M_reserve(__res_arg); }
50938fd1498Szrj 
51038fd1498Szrj       /**
51138fd1498Szrj        *  Erases the string, making it empty.
51238fd1498Szrj        */
51338fd1498Szrj       void
51438fd1498Szrj       clear() _GLIBCXX_NOEXCEPT
51538fd1498Szrj       { this->_M_clear(); }
51638fd1498Szrj 
51738fd1498Szrj       /**
51838fd1498Szrj        *  Returns true if the %string is empty.  Equivalent to
51938fd1498Szrj        *  <code>*this == ""</code>.
52038fd1498Szrj        */
52138fd1498Szrj       bool
52238fd1498Szrj       empty() const _GLIBCXX_NOEXCEPT
52338fd1498Szrj       { return this->size() == 0; }
52438fd1498Szrj 
52538fd1498Szrj       // Element access:
52638fd1498Szrj       /**
52738fd1498Szrj        *  @brief  Subscript access to the data contained in the %string.
52838fd1498Szrj        *  @param  __pos  The index of the character to access.
52938fd1498Szrj        *  @return  Read-only (constant) reference to the character.
53038fd1498Szrj        *
53138fd1498Szrj        *  This operator allows for easy, array-style, data access.
53238fd1498Szrj        *  Note that data access with this operator is unchecked and
53338fd1498Szrj        *  out_of_range lookups are not defined. (For checked lookups
53438fd1498Szrj        *  see at().)
53538fd1498Szrj        */
53638fd1498Szrj       const_reference
53738fd1498Szrj       operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT
53838fd1498Szrj       {
53938fd1498Szrj 	__glibcxx_assert(__pos <= this->size());
54038fd1498Szrj 	return this->_M_data()[__pos];
54138fd1498Szrj       }
54238fd1498Szrj 
54338fd1498Szrj       /**
54438fd1498Szrj        *  @brief  Subscript access to the data contained in the %string.
54538fd1498Szrj        *  @param  __pos  The index of the character to access.
54638fd1498Szrj        *  @return  Read/write reference to the character.
54738fd1498Szrj        *
54838fd1498Szrj        *  This operator allows for easy, array-style, data access.
54938fd1498Szrj        *  Note that data access with this operator is unchecked and
55038fd1498Szrj        *  out_of_range lookups are not defined. (For checked lookups
55138fd1498Szrj        *  see at().)  Unshares the string.
55238fd1498Szrj        */
55338fd1498Szrj       reference
55438fd1498Szrj       operator[](size_type __pos) _GLIBCXX_NOEXCEPT
55538fd1498Szrj       {
55638fd1498Szrj         // Allow pos == size() both in C++98 mode, as v3 extension,
55738fd1498Szrj 	// and in C++11 mode.
55838fd1498Szrj 	__glibcxx_assert(__pos <= this->size());
55938fd1498Szrj         // In pedantic mode be strict in C++98 mode.
56038fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L
56138fd1498Szrj 				 || __pos < this->size());
56238fd1498Szrj 	this->_M_leak();
56338fd1498Szrj 	return this->_M_data()[__pos];
56438fd1498Szrj       }
56538fd1498Szrj 
56638fd1498Szrj       /**
56738fd1498Szrj        *  @brief  Provides access to the data contained in the %string.
56838fd1498Szrj        *  @param __n The index of the character to access.
56938fd1498Szrj        *  @return  Read-only (const) reference to the character.
57038fd1498Szrj        *  @throw  std::out_of_range  If @a __n is an invalid index.
57138fd1498Szrj        *
57238fd1498Szrj        *  This function provides for safer data access.  The parameter
57338fd1498Szrj        *  is first checked that it is in the range of the string.  The
57438fd1498Szrj        *  function throws out_of_range if the check fails.
57538fd1498Szrj        */
57638fd1498Szrj       const_reference
57738fd1498Szrj       at(size_type __n) const
57838fd1498Szrj       {
57938fd1498Szrj 	if (__n >= this->size())
58038fd1498Szrj 	  std::__throw_out_of_range_fmt(__N("__versa_string::at: __n "
58138fd1498Szrj 					    "(which is %zu) >= this->size() "
58238fd1498Szrj 					    "(which is %zu)"),
58338fd1498Szrj 					__n, this->size());
58438fd1498Szrj 	return this->_M_data()[__n];
58538fd1498Szrj       }
58638fd1498Szrj 
58738fd1498Szrj       /**
58838fd1498Szrj        *  @brief  Provides access to the data contained in the %string.
58938fd1498Szrj        *  @param __n The index of the character to access.
59038fd1498Szrj        *  @return  Read/write reference to the character.
59138fd1498Szrj        *  @throw  std::out_of_range  If @a __n is an invalid index.
59238fd1498Szrj        *
59338fd1498Szrj        *  This function provides for safer data access.  The parameter
59438fd1498Szrj        *  is first checked that it is in the range of the string.  The
59538fd1498Szrj        *  function throws out_of_range if the check fails.  Success
59638fd1498Szrj        *  results in unsharing the string.
59738fd1498Szrj        */
59838fd1498Szrj       reference
59938fd1498Szrj       at(size_type __n)
60038fd1498Szrj       {
60138fd1498Szrj 	if (__n >= this->size())
60238fd1498Szrj 	  std::__throw_out_of_range_fmt(__N("__versa_string::at: __n "
60338fd1498Szrj 					    "(which is %zu) >= this->size() "
60438fd1498Szrj 					    "(which is %zu)"),
60538fd1498Szrj 					__n, this->size());
60638fd1498Szrj 	this->_M_leak();
60738fd1498Szrj 	return this->_M_data()[__n];
60838fd1498Szrj       }
60938fd1498Szrj 
61038fd1498Szrj #if __cplusplus >= 201103L
61138fd1498Szrj       /**
61238fd1498Szrj        *  Returns a read/write reference to the data at the first
61338fd1498Szrj        *  element of the %string.
61438fd1498Szrj        */
61538fd1498Szrj       reference
61638fd1498Szrj       front() noexcept
61738fd1498Szrj       { return operator[](0); }
61838fd1498Szrj 
61938fd1498Szrj       /**
62038fd1498Szrj        *  Returns a read-only (constant) reference to the data at the first
62138fd1498Szrj        *  element of the %string.
62238fd1498Szrj        */
62338fd1498Szrj       const_reference
62438fd1498Szrj       front() const noexcept
62538fd1498Szrj       { return operator[](0); }
62638fd1498Szrj 
62738fd1498Szrj       /**
62838fd1498Szrj        *  Returns a read/write reference to the data at the last
62938fd1498Szrj        *  element of the %string.
63038fd1498Szrj        */
63138fd1498Szrj       reference
63238fd1498Szrj       back() noexcept
63338fd1498Szrj       { return operator[](this->size() - 1); }
63438fd1498Szrj 
63538fd1498Szrj       /**
63638fd1498Szrj        *  Returns a read-only (constant) reference to the data at the
63738fd1498Szrj        *  last element of the %string.
63838fd1498Szrj        */
63938fd1498Szrj       const_reference
64038fd1498Szrj       back() const noexcept
64138fd1498Szrj       { return operator[](this->size() - 1); }
64238fd1498Szrj #endif
64338fd1498Szrj 
64438fd1498Szrj       // Modifiers:
64538fd1498Szrj       /**
64638fd1498Szrj        *  @brief  Append a string to this string.
64738fd1498Szrj        *  @param __str  The string to append.
64838fd1498Szrj        *  @return  Reference to this string.
64938fd1498Szrj        */
65038fd1498Szrj       __versa_string&
65138fd1498Szrj       operator+=(const __versa_string& __str)
65238fd1498Szrj       { return this->append(__str); }
65338fd1498Szrj 
65438fd1498Szrj       /**
65538fd1498Szrj        *  @brief  Append a C string.
65638fd1498Szrj        *  @param __s  The C string to append.
65738fd1498Szrj        *  @return  Reference to this string.
65838fd1498Szrj        */
65938fd1498Szrj       __versa_string&
66038fd1498Szrj       operator+=(const _CharT* __s)
66138fd1498Szrj       { return this->append(__s); }
66238fd1498Szrj 
66338fd1498Szrj       /**
66438fd1498Szrj        *  @brief  Append a character.
66538fd1498Szrj        *  @param __c  The character to append.
66638fd1498Szrj        *  @return  Reference to this string.
66738fd1498Szrj        */
66838fd1498Szrj       __versa_string&
66938fd1498Szrj       operator+=(_CharT __c)
67038fd1498Szrj       {
67138fd1498Szrj 	this->push_back(__c);
67238fd1498Szrj 	return *this;
67338fd1498Szrj       }
67438fd1498Szrj 
67538fd1498Szrj #if __cplusplus >= 201103L
67638fd1498Szrj       /**
67738fd1498Szrj        *  @brief  Append an initializer_list of characters.
67838fd1498Szrj        *  @param __l  The initializer_list of characters to be appended.
67938fd1498Szrj        *  @return  Reference to this string.
68038fd1498Szrj        */
68138fd1498Szrj       __versa_string&
68238fd1498Szrj       operator+=(std::initializer_list<_CharT> __l)
68338fd1498Szrj       { return this->append(__l.begin(), __l.end()); }
68438fd1498Szrj #endif // C++11
68538fd1498Szrj 
68638fd1498Szrj       /**
68738fd1498Szrj        *  @brief  Append a string to this string.
68838fd1498Szrj        *  @param __str  The string to append.
68938fd1498Szrj        *  @return  Reference to this string.
69038fd1498Szrj        */
69138fd1498Szrj       __versa_string&
69238fd1498Szrj       append(const __versa_string& __str)
69338fd1498Szrj       { return _M_append(__str._M_data(), __str.size()); }
69438fd1498Szrj 
69538fd1498Szrj       /**
69638fd1498Szrj        *  @brief  Append a substring.
69738fd1498Szrj        *  @param __str  The string to append.
69838fd1498Szrj        *  @param __pos  Index of the first character of str to append.
69938fd1498Szrj        *  @param __n  The number of characters to append.
70038fd1498Szrj        *  @return  Reference to this string.
70138fd1498Szrj        *  @throw  std::out_of_range if @a pos is not a valid index.
70238fd1498Szrj        *
70338fd1498Szrj        *  This function appends @a __n characters from @a __str
70438fd1498Szrj        *  starting at @a __pos to this string.  If @a __n is is larger
70538fd1498Szrj        *  than the number of available characters in @a __str, the
70638fd1498Szrj        *  remainder of @a __str is appended.
70738fd1498Szrj        */
70838fd1498Szrj       __versa_string&
70938fd1498Szrj       append(const __versa_string& __str, size_type __pos, size_type __n)
71038fd1498Szrj       { return _M_append(__str._M_data()
71138fd1498Szrj 			 + __str._M_check(__pos, "__versa_string::append"),
71238fd1498Szrj 			 __str._M_limit(__pos, __n)); }
71338fd1498Szrj 
71438fd1498Szrj       /**
71538fd1498Szrj        *  @brief  Append a C substring.
71638fd1498Szrj        *  @param __s  The C string to append.
71738fd1498Szrj        *  @param __n  The number of characters to append.
71838fd1498Szrj        *  @return  Reference to this string.
71938fd1498Szrj        */
72038fd1498Szrj       __versa_string&
72138fd1498Szrj       append(const _CharT* __s, size_type __n)
72238fd1498Szrj       {
72338fd1498Szrj 	__glibcxx_requires_string_len(__s, __n);
72438fd1498Szrj 	_M_check_length(size_type(0), __n, "__versa_string::append");
72538fd1498Szrj 	return _M_append(__s, __n);
72638fd1498Szrj       }
72738fd1498Szrj 
72838fd1498Szrj       /**
72938fd1498Szrj        *  @brief  Append a C string.
73038fd1498Szrj        *  @param __s  The C string to append.
73138fd1498Szrj        *  @return  Reference to this string.
73238fd1498Szrj        */
73338fd1498Szrj       __versa_string&
73438fd1498Szrj       append(const _CharT* __s)
73538fd1498Szrj       {
73638fd1498Szrj 	__glibcxx_requires_string(__s);
73738fd1498Szrj 	const size_type __n = traits_type::length(__s);
73838fd1498Szrj 	_M_check_length(size_type(0), __n, "__versa_string::append");
73938fd1498Szrj 	return _M_append(__s, __n);
74038fd1498Szrj       }
74138fd1498Szrj 
74238fd1498Szrj       /**
74338fd1498Szrj        *  @brief  Append multiple characters.
74438fd1498Szrj        *  @param __n  The number of characters to append.
74538fd1498Szrj        *  @param __c  The character to use.
74638fd1498Szrj        *  @return  Reference to this string.
74738fd1498Szrj        *
74838fd1498Szrj        *  Appends n copies of c to this string.
74938fd1498Szrj        */
75038fd1498Szrj       __versa_string&
75138fd1498Szrj       append(size_type __n, _CharT __c)
75238fd1498Szrj       { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
75338fd1498Szrj 
75438fd1498Szrj #if __cplusplus >= 201103L
75538fd1498Szrj       /**
75638fd1498Szrj        *  @brief  Append an initializer_list of characters.
75738fd1498Szrj        *  @param __l  The initializer_list of characters to append.
75838fd1498Szrj        *  @return  Reference to this string.
75938fd1498Szrj        */
76038fd1498Szrj       __versa_string&
76138fd1498Szrj       append(std::initializer_list<_CharT> __l)
76238fd1498Szrj       { return this->append(__l.begin(), __l.end()); }
76338fd1498Szrj #endif // C++11
76438fd1498Szrj 
76538fd1498Szrj       /**
76638fd1498Szrj        *  @brief  Append a range of characters.
76738fd1498Szrj        *  @param __first  Iterator referencing the first character to append.
76838fd1498Szrj        *  @param __last  Iterator marking the end of the range.
76938fd1498Szrj        *  @return  Reference to this string.
77038fd1498Szrj        *
77138fd1498Szrj        *  Appends characters in the range [first,last) to this string.
77238fd1498Szrj        */
77338fd1498Szrj #if __cplusplus >= 201103L
77438fd1498Szrj       template<class _InputIterator,
77538fd1498Szrj 	       typename = std::_RequireInputIter<_InputIterator>>
77638fd1498Szrj #else
77738fd1498Szrj       template<class _InputIterator>
77838fd1498Szrj #endif
77938fd1498Szrj         __versa_string&
78038fd1498Szrj         append(_InputIterator __first, _InputIterator __last)
78138fd1498Szrj         { return this->replace(_M_iend(), _M_iend(), __first, __last); }
78238fd1498Szrj 
78338fd1498Szrj       /**
78438fd1498Szrj        *  @brief  Append a single character.
78538fd1498Szrj        *  @param __c  Character to append.
78638fd1498Szrj        */
78738fd1498Szrj       void
78838fd1498Szrj       push_back(_CharT __c)
78938fd1498Szrj       {
79038fd1498Szrj 	const size_type __size = this->size();
79138fd1498Szrj 	if (__size + 1 > this->capacity() || this->_M_is_shared())
79238fd1498Szrj 	  this->_M_mutate(__size, size_type(0), 0, size_type(1));
79338fd1498Szrj 	traits_type::assign(this->_M_data()[__size], __c);
79438fd1498Szrj 	this->_M_set_length(__size + 1);
79538fd1498Szrj       }
79638fd1498Szrj 
79738fd1498Szrj       /**
79838fd1498Szrj        *  @brief  Set value to contents of another string.
79938fd1498Szrj        *  @param  __str  Source string to use.
80038fd1498Szrj        *  @return  Reference to this string.
80138fd1498Szrj        */
80238fd1498Szrj       __versa_string&
80338fd1498Szrj       assign(const __versa_string& __str)
80438fd1498Szrj       {
80538fd1498Szrj 	this->_M_assign(__str);
80638fd1498Szrj 	return *this;
80738fd1498Szrj       }
80838fd1498Szrj 
80938fd1498Szrj #if __cplusplus >= 201103L
81038fd1498Szrj       /**
81138fd1498Szrj        *  @brief  Set value to contents of another string.
81238fd1498Szrj        *  @param  __str  Source string to use.
81338fd1498Szrj        *  @return  Reference to this string.
81438fd1498Szrj        *
81538fd1498Szrj        *  This function sets this string to the exact contents of @a __str.
81638fd1498Szrj        *  @a __str is a valid, but unspecified string.
81738fd1498Szrj        */
81838fd1498Szrj       __versa_string&
81938fd1498Szrj       assign(__versa_string&& __str) noexcept
82038fd1498Szrj       {
82138fd1498Szrj 	this->swap(__str);
82238fd1498Szrj 	return *this;
82338fd1498Szrj       }
82438fd1498Szrj #endif // C++11
82538fd1498Szrj 
82638fd1498Szrj       /**
82738fd1498Szrj        *  @brief  Set value to a substring of a string.
82838fd1498Szrj        *  @param __str  The string to use.
82938fd1498Szrj        *  @param __pos  Index of the first character of str.
83038fd1498Szrj        *  @param __n  Number of characters to use.
83138fd1498Szrj        *  @return  Reference to this string.
83238fd1498Szrj        *  @throw  std::out_of_range if @a __pos is not a valid index.
83338fd1498Szrj        *
83438fd1498Szrj        *  This function sets this string to the substring of @a __str
83538fd1498Szrj        *  consisting of @a __n characters at @a __pos.  If @a __n is
83638fd1498Szrj        *  is larger than the number of available characters in @a
83738fd1498Szrj        *  __str, the remainder of @a __str is used.
83838fd1498Szrj        */
83938fd1498Szrj       __versa_string&
84038fd1498Szrj       assign(const __versa_string& __str, size_type __pos, size_type __n)
84138fd1498Szrj       { return _M_replace(size_type(0), this->size(), __str._M_data()
84238fd1498Szrj 			  + __str._M_check(__pos, "__versa_string::assign"),
84338fd1498Szrj 			  __str._M_limit(__pos, __n)); }
84438fd1498Szrj 
84538fd1498Szrj       /**
84638fd1498Szrj        *  @brief  Set value to a C substring.
84738fd1498Szrj        *  @param __s  The C string to use.
84838fd1498Szrj        *  @param __n  Number of characters to use.
84938fd1498Szrj        *  @return  Reference to this string.
85038fd1498Szrj        *
85138fd1498Szrj        *  This function sets the value of this string to the first @a
85238fd1498Szrj        *  __n characters of @a __s.  If @a __n is is larger than the
85338fd1498Szrj        *  number of available characters in @a __s, the remainder of
85438fd1498Szrj        *  @a __s is used.
85538fd1498Szrj        */
85638fd1498Szrj       __versa_string&
85738fd1498Szrj       assign(const _CharT* __s, size_type __n)
85838fd1498Szrj       {
85938fd1498Szrj 	__glibcxx_requires_string_len(__s, __n);
86038fd1498Szrj 	return _M_replace(size_type(0), this->size(), __s, __n);
86138fd1498Szrj       }
86238fd1498Szrj 
86338fd1498Szrj       /**
86438fd1498Szrj        *  @brief  Set value to contents of a C string.
86538fd1498Szrj        *  @param __s  The C string to use.
86638fd1498Szrj        *  @return  Reference to this string.
86738fd1498Szrj        *
86838fd1498Szrj        *  This function sets the value of this string to the value of
86938fd1498Szrj        *  @a __s.  The data is copied, so there is no dependence on @a
87038fd1498Szrj        *  __s once the function returns.
87138fd1498Szrj        */
87238fd1498Szrj       __versa_string&
87338fd1498Szrj       assign(const _CharT* __s)
87438fd1498Szrj       {
87538fd1498Szrj 	__glibcxx_requires_string(__s);
87638fd1498Szrj 	return _M_replace(size_type(0), this->size(), __s,
87738fd1498Szrj 			  traits_type::length(__s));
87838fd1498Szrj       }
87938fd1498Szrj 
88038fd1498Szrj       /**
88138fd1498Szrj        *  @brief  Set value to multiple characters.
88238fd1498Szrj        *  @param __n  Length of the resulting string.
88338fd1498Szrj        *  @param __c  The character to use.
88438fd1498Szrj        *  @return  Reference to this string.
88538fd1498Szrj        *
88638fd1498Szrj        *  This function sets the value of this string to @a __n copies of
88738fd1498Szrj        *  character @a __c.
88838fd1498Szrj        */
88938fd1498Szrj       __versa_string&
89038fd1498Szrj       assign(size_type __n, _CharT __c)
89138fd1498Szrj       { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
89238fd1498Szrj 
89338fd1498Szrj       /**
89438fd1498Szrj        *  @brief  Set value to a range of characters.
89538fd1498Szrj        *  @param __first  Iterator referencing the first character to append.
89638fd1498Szrj        *  @param __last  Iterator marking the end of the range.
89738fd1498Szrj        *  @return  Reference to this string.
89838fd1498Szrj        *
89938fd1498Szrj        *  Sets value of string to characters in the range
90038fd1498Szrj        *  [first,last).
90138fd1498Szrj       */
90238fd1498Szrj #if __cplusplus >= 201103L
90338fd1498Szrj       template<class _InputIterator,
90438fd1498Szrj 	       typename = std::_RequireInputIter<_InputIterator>>
90538fd1498Szrj #else
90638fd1498Szrj       template<class _InputIterator>
90738fd1498Szrj #endif
90838fd1498Szrj         __versa_string&
90938fd1498Szrj         assign(_InputIterator __first, _InputIterator __last)
91038fd1498Szrj         { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
91138fd1498Szrj 
91238fd1498Szrj #if __cplusplus >= 201103L
91338fd1498Szrj       /**
91438fd1498Szrj        *  @brief  Set value to an initializer_list of characters.
91538fd1498Szrj        *  @param __l  The initializer_list of characters to assign.
91638fd1498Szrj        *  @return  Reference to this string.
91738fd1498Szrj        */
91838fd1498Szrj       __versa_string&
91938fd1498Szrj       assign(std::initializer_list<_CharT> __l)
92038fd1498Szrj       { return this->assign(__l.begin(), __l.end()); }
92138fd1498Szrj #endif // C++11
92238fd1498Szrj 
92338fd1498Szrj #if __cplusplus >= 201103L
92438fd1498Szrj       /**
92538fd1498Szrj        *  @brief  Insert multiple characters.
92638fd1498Szrj        *  @param __p  Const_iterator referencing location in string to
92738fd1498Szrj        *              insert at.
92838fd1498Szrj        *  @param __n  Number of characters to insert
92938fd1498Szrj        *  @param __c  The character to insert.
93038fd1498Szrj        *  @return  Iterator referencing the first inserted char.
93138fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
93238fd1498Szrj        *
93338fd1498Szrj        *  Inserts @a __n copies of character @a __c starting at the
93438fd1498Szrj        *  position referenced by iterator @a __p.  If adding
93538fd1498Szrj        *  characters causes the length to exceed max_size(),
93638fd1498Szrj        *  length_error is thrown.  The value of the string doesn't
93738fd1498Szrj        *  change if an error is thrown.
93838fd1498Szrj       */
93938fd1498Szrj       iterator
94038fd1498Szrj       insert(const_iterator __p, size_type __n, _CharT __c)
94138fd1498Szrj       {
94238fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
94338fd1498Szrj 	const size_type __pos = __p - _M_ibegin();
94438fd1498Szrj 	this->replace(__p, __p, __n, __c);
94538fd1498Szrj 	return iterator(this->_M_data() + __pos);
94638fd1498Szrj       }
94738fd1498Szrj #else
94838fd1498Szrj       /**
94938fd1498Szrj        *  @brief  Insert multiple characters.
95038fd1498Szrj        *  @param __p  Iterator referencing location in string to insert at.
95138fd1498Szrj        *  @param __n  Number of characters to insert
95238fd1498Szrj        *  @param __c  The character to insert.
95338fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
95438fd1498Szrj        *
95538fd1498Szrj        *  Inserts @a __n copies of character @a __c starting at the
95638fd1498Szrj        *  position referenced by iterator @a __p.  If adding
95738fd1498Szrj        *  characters causes the length to exceed max_size(),
95838fd1498Szrj        *  length_error is thrown.  The value of the string doesn't
95938fd1498Szrj        *  change if an error is thrown.
96038fd1498Szrj       */
96138fd1498Szrj       void
96238fd1498Szrj       insert(iterator __p, size_type __n, _CharT __c)
96338fd1498Szrj       {	this->replace(__p, __p, __n, __c);  }
96438fd1498Szrj #endif
96538fd1498Szrj 
96638fd1498Szrj #if __cplusplus >= 201103L
96738fd1498Szrj       /**
96838fd1498Szrj        *  @brief  Insert a range of characters.
96938fd1498Szrj        *  @param __p  Const_iterator referencing location in string to
97038fd1498Szrj        *              insert at.
97138fd1498Szrj        *  @param __beg  Start of range.
97238fd1498Szrj        *  @param __end  End of range.
97338fd1498Szrj        *  @return  Iterator referencing the first inserted char.
97438fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
97538fd1498Szrj        *
97638fd1498Szrj        *  Inserts characters in range [beg,end).  If adding characters
97738fd1498Szrj        *  causes the length to exceed max_size(), length_error is
97838fd1498Szrj        *  thrown.  The value of the string doesn't change if an error
97938fd1498Szrj        *  is thrown.
98038fd1498Szrj       */
98138fd1498Szrj       template<class _InputIterator,
98238fd1498Szrj 	       typename = std::_RequireInputIter<_InputIterator>>
98338fd1498Szrj 	iterator
98438fd1498Szrj         insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
98538fd1498Szrj         {
98638fd1498Szrj 	  _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
98738fd1498Szrj 	  const size_type __pos = __p - _M_ibegin();
98838fd1498Szrj 	  this->replace(__p, __p, __beg, __end);
98938fd1498Szrj 	  return iterator(this->_M_data() + __pos);
99038fd1498Szrj 	}
99138fd1498Szrj #else
99238fd1498Szrj       /**
99338fd1498Szrj        *  @brief  Insert a range of characters.
99438fd1498Szrj        *  @param __p  Iterator referencing location in string to insert at.
99538fd1498Szrj        *  @param __beg  Start of range.
99638fd1498Szrj        *  @param __end  End of range.
99738fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
99838fd1498Szrj        *
99938fd1498Szrj        *  Inserts characters in range [beg,end).  If adding characters
100038fd1498Szrj        *  causes the length to exceed max_size(), length_error is
100138fd1498Szrj        *  thrown.  The value of the string doesn't change if an error
100238fd1498Szrj        *  is thrown.
100338fd1498Szrj       */
100438fd1498Szrj       template<class _InputIterator>
100538fd1498Szrj         void
100638fd1498Szrj         insert(iterator __p, _InputIterator __beg, _InputIterator __end)
100738fd1498Szrj         { this->replace(__p, __p, __beg, __end); }
100838fd1498Szrj #endif
100938fd1498Szrj 
101038fd1498Szrj #if __cplusplus >= 201103L
101138fd1498Szrj       /**
101238fd1498Szrj        *  @brief  Insert an initializer_list of characters.
101338fd1498Szrj        *  @param __p  Const_iterator referencing location in string to
101438fd1498Szrj        *              insert at.
101538fd1498Szrj        *  @param __l  The initializer_list of characters to insert.
101638fd1498Szrj        *  @return  Iterator referencing the first inserted char.
101738fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
101838fd1498Szrj        */
101938fd1498Szrj       iterator
102038fd1498Szrj       insert(const_iterator __p, std::initializer_list<_CharT> __l)
102138fd1498Szrj       { return this->insert(__p, __l.begin(), __l.end()); }
102238fd1498Szrj #endif // C++11
102338fd1498Szrj 
102438fd1498Szrj       /**
102538fd1498Szrj        *  @brief  Insert value of a string.
102638fd1498Szrj        *  @param __pos1  Iterator referencing location in string to insert at.
102738fd1498Szrj        *  @param __str  The string to insert.
102838fd1498Szrj        *  @return  Reference to this string.
102938fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
103038fd1498Szrj        *
103138fd1498Szrj        *  Inserts value of @a __str starting at @a __pos1.  If adding
103238fd1498Szrj        *  characters causes the length to exceed max_size(),
103338fd1498Szrj        *  length_error is thrown.  The value of the string doesn't
103438fd1498Szrj        *  change if an error is thrown.
103538fd1498Szrj       */
103638fd1498Szrj       __versa_string&
103738fd1498Szrj       insert(size_type __pos1, const __versa_string& __str)
103838fd1498Szrj       { return this->replace(__pos1, size_type(0),
103938fd1498Szrj 			     __str._M_data(), __str.size()); }
104038fd1498Szrj 
104138fd1498Szrj       /**
104238fd1498Szrj        *  @brief  Insert a substring.
104338fd1498Szrj        *  @param __pos1  Iterator referencing location in string to insert at.
104438fd1498Szrj        *  @param __str  The string to insert.
104538fd1498Szrj        *  @param __pos2  Start of characters in str to insert.
104638fd1498Szrj        *  @param __n  Number of characters to insert.
104738fd1498Szrj        *  @return  Reference to this string.
104838fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
104938fd1498Szrj        *  @throw  std::out_of_range  If @a __pos1 > size() or
105038fd1498Szrj        *  @a __pos2 > @a __str.size().
105138fd1498Szrj        *
105238fd1498Szrj        *  Starting at @a __pos1, insert @a __n character of @a __str
105338fd1498Szrj        *  beginning with @a __pos2.  If adding characters causes the
105438fd1498Szrj        *  length to exceed max_size(), length_error is thrown.  If @a
105538fd1498Szrj        *  __pos1 is beyond the end of this string or @a __pos2 is
105638fd1498Szrj        *  beyond the end of @a __str, out_of_range is thrown.  The
105738fd1498Szrj        *  value of the string doesn't change if an error is thrown.
105838fd1498Szrj       */
105938fd1498Szrj       __versa_string&
106038fd1498Szrj       insert(size_type __pos1, const __versa_string& __str,
106138fd1498Szrj 	     size_type __pos2, size_type __n)
106238fd1498Szrj       { return this->replace(__pos1, size_type(0), __str._M_data()
106338fd1498Szrj 			     + __str._M_check(__pos2, "__versa_string::insert"),
106438fd1498Szrj 			     __str._M_limit(__pos2, __n)); }
106538fd1498Szrj 
106638fd1498Szrj       /**
106738fd1498Szrj        *  @brief  Insert a C substring.
106838fd1498Szrj        *  @param __pos  Iterator referencing location in string to insert at.
106938fd1498Szrj        *  @param __s  The C string to insert.
107038fd1498Szrj        *  @param __n  The number of characters to insert.
107138fd1498Szrj        *  @return  Reference to this string.
107238fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
107338fd1498Szrj        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
107438fd1498Szrj        *  string.
107538fd1498Szrj        *
107638fd1498Szrj        *  Inserts the first @a __n characters of @a __s starting at @a
107738fd1498Szrj        *  __pos.  If adding characters causes the length to exceed
107838fd1498Szrj        *  max_size(), length_error is thrown.  If @a __pos is beyond
107938fd1498Szrj        *  end(), out_of_range is thrown.  The value of the string
108038fd1498Szrj        *  doesn't change if an error is thrown.
108138fd1498Szrj       */
108238fd1498Szrj       __versa_string&
108338fd1498Szrj       insert(size_type __pos, const _CharT* __s, size_type __n)
108438fd1498Szrj       { return this->replace(__pos, size_type(0), __s, __n); }
108538fd1498Szrj 
108638fd1498Szrj       /**
108738fd1498Szrj        *  @brief  Insert a C string.
108838fd1498Szrj        *  @param __pos  Iterator referencing location in string to insert at.
108938fd1498Szrj        *  @param __s  The C string to insert.
109038fd1498Szrj        *  @return  Reference to this string.
109138fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
109238fd1498Szrj        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
109338fd1498Szrj        *  string.
109438fd1498Szrj        *
109538fd1498Szrj        *  Inserts the first @a __n characters of @a __s starting at @a
109638fd1498Szrj        *  __pos.  If adding characters causes the length to exceed
109738fd1498Szrj        *  max_size(), length_error is thrown.  If @a __pos is beyond
109838fd1498Szrj        *  end(), out_of_range is thrown.  The value of the string
109938fd1498Szrj        *  doesn't change if an error is thrown.
110038fd1498Szrj       */
110138fd1498Szrj       __versa_string&
110238fd1498Szrj       insert(size_type __pos, const _CharT* __s)
110338fd1498Szrj       {
110438fd1498Szrj 	__glibcxx_requires_string(__s);
110538fd1498Szrj 	return this->replace(__pos, size_type(0), __s,
110638fd1498Szrj 			     traits_type::length(__s));
110738fd1498Szrj       }
110838fd1498Szrj 
110938fd1498Szrj       /**
111038fd1498Szrj        *  @brief  Insert multiple characters.
111138fd1498Szrj        *  @param __pos  Index in string to insert at.
111238fd1498Szrj        *  @param __n  Number of characters to insert
111338fd1498Szrj        *  @param __c  The character to insert.
111438fd1498Szrj        *  @return  Reference to this string.
111538fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
111638fd1498Szrj        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
111738fd1498Szrj        *  string.
111838fd1498Szrj        *
111938fd1498Szrj        *  Inserts @a __n copies of character @a __c starting at index
112038fd1498Szrj        *  @a __pos.  If adding characters causes the length to exceed
112138fd1498Szrj        *  max_size(), length_error is thrown.  If @a __pos > length(),
112238fd1498Szrj        *  out_of_range is thrown.  The value of the string doesn't
112338fd1498Szrj        *  change if an error is thrown.
112438fd1498Szrj       */
112538fd1498Szrj       __versa_string&
112638fd1498Szrj       insert(size_type __pos, size_type __n, _CharT __c)
112738fd1498Szrj       { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
112838fd1498Szrj 			      size_type(0), __n, __c); }
112938fd1498Szrj 
113038fd1498Szrj       /**
113138fd1498Szrj        *  @brief  Insert one character.
113238fd1498Szrj        *  @param __p  Iterator referencing position in string to insert at.
113338fd1498Szrj        *  @param __c  The character to insert.
113438fd1498Szrj        *  @return  Iterator referencing newly inserted char.
113538fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
113638fd1498Szrj        *
113738fd1498Szrj        *  Inserts character @a __c at position referenced by @a __p.
113838fd1498Szrj        *  If adding character causes the length to exceed max_size(),
113938fd1498Szrj        *  length_error is thrown.  If @a __p is beyond end of string,
114038fd1498Szrj        *  out_of_range is thrown.  The value of the string doesn't
114138fd1498Szrj        *  change if an error is thrown.
114238fd1498Szrj       */
114338fd1498Szrj       iterator
114438fd1498Szrj #if __cplusplus >= 201103L
114538fd1498Szrj       insert(const_iterator __p, _CharT __c)
114638fd1498Szrj #else
114738fd1498Szrj       insert(iterator __p, _CharT __c)
114838fd1498Szrj #endif
114938fd1498Szrj       {
115038fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
115138fd1498Szrj 	const size_type __pos = __p - _M_ibegin();
115238fd1498Szrj 	_M_replace_aux(__pos, size_type(0), size_type(1), __c);
115338fd1498Szrj 	this->_M_set_leaked();
115438fd1498Szrj 	return iterator(this->_M_data() + __pos);
115538fd1498Szrj       }
115638fd1498Szrj 
115738fd1498Szrj       /**
115838fd1498Szrj        *  @brief  Remove characters.
115938fd1498Szrj        *  @param __pos  Index of first character to remove (default 0).
116038fd1498Szrj        *  @param __n  Number of characters to remove (default remainder).
116138fd1498Szrj        *  @return  Reference to this string.
116238fd1498Szrj        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
116338fd1498Szrj        *  string.
116438fd1498Szrj        *
116538fd1498Szrj        *  Removes @a __n characters from this string starting at @a
116638fd1498Szrj        *  __pos.  The length of the string is reduced by @a __n.  If
116738fd1498Szrj        *  there are < @a __n characters to remove, the remainder of
116838fd1498Szrj        *  the string is truncated.  If @a __p is beyond end of string,
116938fd1498Szrj        *  out_of_range is thrown.  The value of the string doesn't
117038fd1498Szrj        *  change if an error is thrown.
117138fd1498Szrj       */
117238fd1498Szrj       __versa_string&
117338fd1498Szrj       erase(size_type __pos = 0, size_type __n = npos)
117438fd1498Szrj       {
117538fd1498Szrj 	this->_M_erase(_M_check(__pos, "__versa_string::erase"),
117638fd1498Szrj 		       _M_limit(__pos, __n));
117738fd1498Szrj 	return *this;
117838fd1498Szrj       }
117938fd1498Szrj 
118038fd1498Szrj       /**
118138fd1498Szrj        *  @brief  Remove one character.
118238fd1498Szrj        *  @param __position  Iterator referencing the character to remove.
118338fd1498Szrj        *  @return  iterator referencing same location after removal.
118438fd1498Szrj        *
118538fd1498Szrj        *  Removes the character at @a __position from this string. The
118638fd1498Szrj        *  value of the string doesn't change if an error is thrown.
118738fd1498Szrj       */
118838fd1498Szrj       iterator
118938fd1498Szrj #if __cplusplus >= 201103L
119038fd1498Szrj       erase(const_iterator __position)
119138fd1498Szrj #else
119238fd1498Szrj       erase(iterator __position)
119338fd1498Szrj #endif
119438fd1498Szrj       {
119538fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
119638fd1498Szrj 				 && __position < _M_iend());
119738fd1498Szrj 	const size_type __pos = __position - _M_ibegin();
119838fd1498Szrj 	this->_M_erase(__pos, size_type(1));
119938fd1498Szrj 	this->_M_set_leaked();
120038fd1498Szrj 	return iterator(this->_M_data() + __pos);
120138fd1498Szrj       }
120238fd1498Szrj 
120338fd1498Szrj       /**
120438fd1498Szrj        *  @brief  Remove a range of characters.
120538fd1498Szrj        *  @param __first  Iterator referencing the first character to remove.
120638fd1498Szrj        *  @param __last  Iterator referencing the end of the range.
120738fd1498Szrj        *  @return  Iterator referencing location of first after removal.
120838fd1498Szrj        *
120938fd1498Szrj        *  Removes the characters in the range [first,last) from this
121038fd1498Szrj        *  string.  The value of the string doesn't change if an error
121138fd1498Szrj        *  is thrown.
121238fd1498Szrj       */
121338fd1498Szrj       iterator
121438fd1498Szrj #if __cplusplus >= 201103L
121538fd1498Szrj       erase(const_iterator __first, const_iterator __last)
121638fd1498Szrj #else
121738fd1498Szrj       erase(iterator __first, iterator __last)
121838fd1498Szrj #endif
121938fd1498Szrj       {
122038fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
122138fd1498Szrj 				 && __last <= _M_iend());
122238fd1498Szrj         const size_type __pos = __first - _M_ibegin();
122338fd1498Szrj 	this->_M_erase(__pos, __last - __first);
122438fd1498Szrj 	this->_M_set_leaked();
122538fd1498Szrj 	return iterator(this->_M_data() + __pos);
122638fd1498Szrj       }
122738fd1498Szrj 
122838fd1498Szrj #if __cplusplus >= 201103L
122938fd1498Szrj       /**
123038fd1498Szrj        *  @brief  Remove the last character.
123138fd1498Szrj        *
123238fd1498Szrj        *  The string must be non-empty.
123338fd1498Szrj        */
123438fd1498Szrj       void
123538fd1498Szrj       pop_back()
123638fd1498Szrj       { this->_M_erase(size()-1, 1); }
123738fd1498Szrj #endif // C++11
123838fd1498Szrj 
123938fd1498Szrj       /**
124038fd1498Szrj        *  @brief  Replace characters with value from another string.
124138fd1498Szrj        *  @param __pos  Index of first character to replace.
124238fd1498Szrj        *  @param __n  Number of characters to be replaced.
124338fd1498Szrj        *  @param __str  String to insert.
124438fd1498Szrj        *  @return  Reference to this string.
124538fd1498Szrj        *  @throw  std::out_of_range  If @a __pos is beyond the end of this
124638fd1498Szrj        *  string.
124738fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
124838fd1498Szrj        *
124938fd1498Szrj        *  Removes the characters in the range [pos,pos+n) from this
125038fd1498Szrj        *  string.  In place, the value of @a __str is inserted.  If @a
125138fd1498Szrj        *  __pos is beyond end of string, out_of_range is thrown.  If
125238fd1498Szrj        *  the length of the result exceeds max_size(), length_error is
125338fd1498Szrj        *  thrown.  The value of the string doesn't change if an error
125438fd1498Szrj        *  is thrown.
125538fd1498Szrj       */
125638fd1498Szrj       __versa_string&
125738fd1498Szrj       replace(size_type __pos, size_type __n, const __versa_string& __str)
125838fd1498Szrj       { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
125938fd1498Szrj 
126038fd1498Szrj       /**
126138fd1498Szrj        *  @brief  Replace characters with value from another string.
126238fd1498Szrj        *  @param __pos1  Index of first character to replace.
126338fd1498Szrj        *  @param __n1  Number of characters to be replaced.
126438fd1498Szrj        *  @param __str  String to insert.
126538fd1498Szrj        *  @param __pos2  Index of first character of str to use.
126638fd1498Szrj        *  @param __n2  Number of characters from str to use.
126738fd1498Szrj        *  @return  Reference to this string.
126838fd1498Szrj        *  @throw  std::out_of_range  If @a __pos1 > size() or @a __pos2 >
126938fd1498Szrj        *  str.size().
127038fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
127138fd1498Szrj        *
127238fd1498Szrj        *  Removes the characters in the range [pos1,pos1 + n) from
127338fd1498Szrj        *  this string.  In place, the value of @a __str is inserted.
127438fd1498Szrj        *  If @a __pos is beyond end of string, out_of_range is thrown.
127538fd1498Szrj        *  If the length of the result exceeds max_size(), length_error
127638fd1498Szrj        *  is thrown.  The value of the string doesn't change if an
127738fd1498Szrj        *  error is thrown.
127838fd1498Szrj       */
127938fd1498Szrj       __versa_string&
128038fd1498Szrj       replace(size_type __pos1, size_type __n1, const __versa_string& __str,
128138fd1498Szrj 	      size_type __pos2, size_type __n2)
128238fd1498Szrj       {
128338fd1498Szrj 	return this->replace(__pos1, __n1, __str._M_data()
128438fd1498Szrj 			     + __str._M_check(__pos2,
128538fd1498Szrj 					      "__versa_string::replace"),
128638fd1498Szrj 			     __str._M_limit(__pos2, __n2));
128738fd1498Szrj       }
128838fd1498Szrj 
128938fd1498Szrj       /**
129038fd1498Szrj        *  @brief  Replace characters with value of a C substring.
129138fd1498Szrj        *  @param __pos  Index of first character to replace.
129238fd1498Szrj        *  @param __n1  Number of characters to be replaced.
129338fd1498Szrj        *  @param __s  C string to insert.
129438fd1498Szrj        *  @param __n2  Number of characters from @a __s to use.
129538fd1498Szrj        *  @return  Reference to this string.
129638fd1498Szrj        *  @throw  std::out_of_range  If @a __pos1 > size().
129738fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
129838fd1498Szrj        *
129938fd1498Szrj        *  Removes the characters in the range [pos,pos + n1) from this
130038fd1498Szrj        *  string.  In place, the first @a __n2 characters of @a __s
130138fd1498Szrj        *  are inserted, or all of @a __s if @a __n2 is too large.  If
130238fd1498Szrj        *  @a __pos is beyond end of string, out_of_range is thrown.
130338fd1498Szrj        *  If the length of result exceeds max_size(), length_error is
130438fd1498Szrj        *  thrown.  The value of the string doesn't change if an error
130538fd1498Szrj        *  is thrown.
130638fd1498Szrj       */
130738fd1498Szrj       __versa_string&
130838fd1498Szrj       replace(size_type __pos, size_type __n1, const _CharT* __s,
130938fd1498Szrj 	      size_type __n2)
131038fd1498Szrj       {
131138fd1498Szrj 	__glibcxx_requires_string_len(__s, __n2);
131238fd1498Szrj 	return _M_replace(_M_check(__pos, "__versa_string::replace"),
131338fd1498Szrj 			  _M_limit(__pos, __n1), __s, __n2);
131438fd1498Szrj       }
131538fd1498Szrj 
131638fd1498Szrj       /**
131738fd1498Szrj        *  @brief  Replace characters with value of a C string.
131838fd1498Szrj        *  @param __pos  Index of first character to replace.
131938fd1498Szrj        *  @param __n1  Number of characters to be replaced.
132038fd1498Szrj        *  @param __s  C string to insert.
132138fd1498Szrj        *  @return  Reference to this string.
132238fd1498Szrj        *  @throw  std::out_of_range  If @a __pos > size().
132338fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
132438fd1498Szrj        *
132538fd1498Szrj        *  Removes the characters in the range [pos,pos + n1) from this
132638fd1498Szrj        *  string.  In place, the characters of @a __s are inserted.  If
132738fd1498Szrj        *  @a pos is beyond end of string, out_of_range is thrown.  If
132838fd1498Szrj        *  the length of result exceeds max_size(), length_error is thrown.
132938fd1498Szrj        *  The value of the string doesn't change if an error is thrown.
133038fd1498Szrj       */
133138fd1498Szrj       __versa_string&
133238fd1498Szrj       replace(size_type __pos, size_type __n1, const _CharT* __s)
133338fd1498Szrj       {
133438fd1498Szrj 	__glibcxx_requires_string(__s);
133538fd1498Szrj 	return this->replace(__pos, __n1, __s, traits_type::length(__s));
133638fd1498Szrj       }
133738fd1498Szrj 
133838fd1498Szrj       /**
133938fd1498Szrj        *  @brief  Replace characters with multiple characters.
134038fd1498Szrj        *  @param __pos  Index of first character to replace.
134138fd1498Szrj        *  @param __n1  Number of characters to be replaced.
134238fd1498Szrj        *  @param __n2  Number of characters to insert.
134338fd1498Szrj        *  @param __c  Character to insert.
134438fd1498Szrj        *  @return  Reference to this string.
134538fd1498Szrj        *  @throw  std::out_of_range  If @a __pos > size().
134638fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
134738fd1498Szrj        *
134838fd1498Szrj        *  Removes the characters in the range [pos,pos + n1) from this
134938fd1498Szrj        *  string.  In place, @a __n2 copies of @a __c are inserted.
135038fd1498Szrj        *  If @a __pos is beyond end of string, out_of_range is thrown.
135138fd1498Szrj        *  If the length of result exceeds max_size(), length_error is
135238fd1498Szrj        *  thrown.  The value of the string doesn't change if an error
135338fd1498Szrj        *  is thrown.
135438fd1498Szrj       */
135538fd1498Szrj       __versa_string&
135638fd1498Szrj       replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
135738fd1498Szrj       { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
135838fd1498Szrj 			      _M_limit(__pos, __n1), __n2, __c); }
135938fd1498Szrj 
136038fd1498Szrj       /**
136138fd1498Szrj        *  @brief  Replace range of characters with string.
136238fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
136338fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
136438fd1498Szrj        *  @param __str  String value to insert.
136538fd1498Szrj        *  @return  Reference to this string.
136638fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
136738fd1498Szrj        *
136838fd1498Szrj        *  Removes the characters in the range [i1,i2).  In place, the
136938fd1498Szrj        *  value of @a __str is inserted.  If the length of result
137038fd1498Szrj        *  exceeds max_size(), length_error is thrown.  The value of
137138fd1498Szrj        *  the string doesn't change if an error is thrown.
137238fd1498Szrj       */
137338fd1498Szrj       __versa_string&
137438fd1498Szrj #if __cplusplus >= 201103L
137538fd1498Szrj       replace(const_iterator __i1, const_iterator __i2,
137638fd1498Szrj 	      const __versa_string& __str)
137738fd1498Szrj #else
137838fd1498Szrj       replace(iterator __i1, iterator __i2, const __versa_string& __str)
137938fd1498Szrj #endif
138038fd1498Szrj       { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
138138fd1498Szrj 
138238fd1498Szrj       /**
138338fd1498Szrj        *  @brief  Replace range of characters with C substring.
138438fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
138538fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
138638fd1498Szrj        *  @param __s  C string value to insert.
138738fd1498Szrj        *  @param __n  Number of characters from s to insert.
138838fd1498Szrj        *  @return  Reference to this string.
138938fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
139038fd1498Szrj        *
139138fd1498Szrj        *  Removes the characters in the range [i1,i2).  In place, the
139238fd1498Szrj        *  first @a n characters of @a __s are inserted.  If the length
139338fd1498Szrj        *  of result exceeds max_size(), length_error is thrown.  The
139438fd1498Szrj        *  value of the string doesn't change if an error is thrown.
139538fd1498Szrj       */
139638fd1498Szrj       __versa_string&
139738fd1498Szrj #if __cplusplus >= 201103L
139838fd1498Szrj       replace(const_iterator __i1, const_iterator __i2,
139938fd1498Szrj 	      const _CharT* __s, size_type __n)
140038fd1498Szrj #else
140138fd1498Szrj       replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
140238fd1498Szrj #endif
140338fd1498Szrj       {
140438fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
140538fd1498Szrj 				 && __i2 <= _M_iend());
140638fd1498Szrj 	return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
140738fd1498Szrj       }
140838fd1498Szrj 
140938fd1498Szrj       /**
141038fd1498Szrj        *  @brief  Replace range of characters with C string.
141138fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
141238fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
141338fd1498Szrj        *  @param __s  C string value to insert.
141438fd1498Szrj        *  @return  Reference to this string.
141538fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
141638fd1498Szrj        *
141738fd1498Szrj        *  Removes the characters in the range [i1,i2).  In place, the
141838fd1498Szrj        *  characters of @a __s are inserted.  If the length of result
141938fd1498Szrj        *  exceeds max_size(), length_error is thrown.  The value of
142038fd1498Szrj        *  the string doesn't change if an error is thrown.
142138fd1498Szrj       */
142238fd1498Szrj       __versa_string&
142338fd1498Szrj #if __cplusplus >= 201103L
142438fd1498Szrj       replace(const_iterator __i1, const_iterator __i2, const _CharT* __s)
142538fd1498Szrj #else
142638fd1498Szrj       replace(iterator __i1, iterator __i2, const _CharT* __s)
142738fd1498Szrj #endif
142838fd1498Szrj       {
142938fd1498Szrj 	__glibcxx_requires_string(__s);
143038fd1498Szrj 	return this->replace(__i1, __i2, __s, traits_type::length(__s));
143138fd1498Szrj       }
143238fd1498Szrj 
143338fd1498Szrj       /**
143438fd1498Szrj        *  @brief  Replace range of characters with multiple characters
143538fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
143638fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
143738fd1498Szrj        *  @param __n  Number of characters to insert.
143838fd1498Szrj        *  @param __c  Character to insert.
143938fd1498Szrj        *  @return  Reference to this string.
144038fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
144138fd1498Szrj        *
144238fd1498Szrj        *  Removes the characters in the range [i1,i2).  In place, @a
144338fd1498Szrj        *  __n copies of @a __c are inserted.  If the length of result
144438fd1498Szrj        *  exceeds max_size(), length_error is thrown.  The value of
144538fd1498Szrj        *  the string doesn't change if an error is thrown.
144638fd1498Szrj       */
144738fd1498Szrj       __versa_string&
144838fd1498Szrj #if __cplusplus >= 201103L
144938fd1498Szrj       replace(const_iterator __i1, const_iterator __i2, size_type __n,
145038fd1498Szrj 	      _CharT __c)
145138fd1498Szrj #else
145238fd1498Szrj       replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
145338fd1498Szrj #endif
145438fd1498Szrj       {
145538fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
145638fd1498Szrj 				 && __i2 <= _M_iend());
145738fd1498Szrj 	return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
145838fd1498Szrj       }
145938fd1498Szrj 
146038fd1498Szrj       /**
146138fd1498Szrj        *  @brief  Replace range of characters with range.
146238fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
146338fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
146438fd1498Szrj        *  @param __k1  Iterator referencing start of range to insert.
146538fd1498Szrj        *  @param __k2  Iterator referencing end of range to insert.
146638fd1498Szrj        *  @return  Reference to this string.
146738fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
146838fd1498Szrj        *
146938fd1498Szrj        *  Removes the characters in the range [i1,i2).  In place,
147038fd1498Szrj        *  characters in the range [k1,k2) are inserted.  If the length
147138fd1498Szrj        *  of result exceeds max_size(), length_error is thrown.  The
147238fd1498Szrj        *  value of the string doesn't change if an error is thrown.
147338fd1498Szrj       */
147438fd1498Szrj #if __cplusplus >= 201103L
147538fd1498Szrj       template<class _InputIterator,
147638fd1498Szrj 	       typename = std::_RequireInputIter<_InputIterator>>
147738fd1498Szrj         __versa_string&
147838fd1498Szrj         replace(const_iterator __i1, const_iterator __i2,
147938fd1498Szrj 		_InputIterator __k1, _InputIterator __k2)
148038fd1498Szrj         {
148138fd1498Szrj 	  _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
148238fd1498Szrj 				   && __i2 <= _M_iend());
148338fd1498Szrj 	  __glibcxx_requires_valid_range(__k1, __k2);
148438fd1498Szrj 	  return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
148538fd1498Szrj 					   std::__false_type());
148638fd1498Szrj 	}
148738fd1498Szrj #else
148838fd1498Szrj       template<class _InputIterator>
148938fd1498Szrj         __versa_string&
149038fd1498Szrj         replace(iterator __i1, iterator __i2,
149138fd1498Szrj 		_InputIterator __k1, _InputIterator __k2)
149238fd1498Szrj         {
149338fd1498Szrj 	  _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
149438fd1498Szrj 				   && __i2 <= _M_iend());
149538fd1498Szrj 	  __glibcxx_requires_valid_range(__k1, __k2);
149638fd1498Szrj 	  typedef typename std::__is_integer<_InputIterator>::__type _Integral;
149738fd1498Szrj 	  return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
149838fd1498Szrj 	}
149938fd1498Szrj #endif
150038fd1498Szrj 
150138fd1498Szrj       // Specializations for the common case of pointer and iterator:
150238fd1498Szrj       // useful to avoid the overhead of temporary buffering in _M_replace.
150338fd1498Szrj       __versa_string&
150438fd1498Szrj #if __cplusplus >= 201103L
150538fd1498Szrj       replace(const_iterator __i1, const_iterator __i2,
150638fd1498Szrj 	      _CharT* __k1, _CharT* __k2)
150738fd1498Szrj #else
150838fd1498Szrj       replace(iterator __i1, iterator __i2,
150938fd1498Szrj 	      _CharT* __k1, _CharT* __k2)
151038fd1498Szrj #endif
151138fd1498Szrj       {
151238fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
151338fd1498Szrj 				 && __i2 <= _M_iend());
151438fd1498Szrj 	__glibcxx_requires_valid_range(__k1, __k2);
151538fd1498Szrj 	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
151638fd1498Szrj 			     __k1, __k2 - __k1);
151738fd1498Szrj       }
151838fd1498Szrj 
151938fd1498Szrj       __versa_string&
152038fd1498Szrj #if __cplusplus >= 201103L
152138fd1498Szrj       replace(const_iterator __i1, const_iterator __i2,
152238fd1498Szrj 	      const _CharT* __k1, const _CharT* __k2)
152338fd1498Szrj #else
152438fd1498Szrj       replace(iterator __i1, iterator __i2,
152538fd1498Szrj 	      const _CharT* __k1, const _CharT* __k2)
152638fd1498Szrj #endif
152738fd1498Szrj       {
152838fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
152938fd1498Szrj 				 && __i2 <= _M_iend());
153038fd1498Szrj 	__glibcxx_requires_valid_range(__k1, __k2);
153138fd1498Szrj 	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
153238fd1498Szrj 			     __k1, __k2 - __k1);
153338fd1498Szrj       }
153438fd1498Szrj 
153538fd1498Szrj       __versa_string&
153638fd1498Szrj #if __cplusplus >= 201103L
153738fd1498Szrj       replace(const_iterator __i1, const_iterator __i2,
153838fd1498Szrj 	      iterator __k1, iterator __k2)
153938fd1498Szrj #else
154038fd1498Szrj       replace(iterator __i1, iterator __i2,
154138fd1498Szrj 	      iterator __k1, iterator __k2)
154238fd1498Szrj #endif
154338fd1498Szrj       {
154438fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
154538fd1498Szrj 				 && __i2 <= _M_iend());
154638fd1498Szrj 	__glibcxx_requires_valid_range(__k1, __k2);
154738fd1498Szrj 	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
154838fd1498Szrj 			     __k1.base(), __k2 - __k1);
154938fd1498Szrj       }
155038fd1498Szrj 
155138fd1498Szrj       __versa_string&
155238fd1498Szrj #if __cplusplus >= 201103L
155338fd1498Szrj       replace(const_iterator __i1, const_iterator __i2,
155438fd1498Szrj 	      const_iterator __k1, const_iterator __k2)
155538fd1498Szrj #else
155638fd1498Szrj       replace(iterator __i1, iterator __i2,
155738fd1498Szrj 	      const_iterator __k1, const_iterator __k2)
155838fd1498Szrj #endif
155938fd1498Szrj       {
156038fd1498Szrj 	_GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
156138fd1498Szrj 				 && __i2 <= _M_iend());
156238fd1498Szrj 	__glibcxx_requires_valid_range(__k1, __k2);
156338fd1498Szrj 	return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
156438fd1498Szrj 			     __k1.base(), __k2 - __k1);
156538fd1498Szrj       }
156638fd1498Szrj 
156738fd1498Szrj #if __cplusplus >= 201103L
156838fd1498Szrj       /**
156938fd1498Szrj        *  @brief  Replace range of characters with initializer_list.
157038fd1498Szrj        *  @param __i1  Iterator referencing start of range to replace.
157138fd1498Szrj        *  @param __i2  Iterator referencing end of range to replace.
157238fd1498Szrj        *  @param __l  The initializer_list of characters to insert.
157338fd1498Szrj        *  @return  Reference to this string.
157438fd1498Szrj        *  @throw  std::length_error  If new length exceeds @c max_size().
157538fd1498Szrj        *
157638fd1498Szrj        *  Removes the characters in the range [i1,i2).  In place,
157738fd1498Szrj        *  characters in the range [k1,k2) are inserted.  If the length
157838fd1498Szrj        *  of result exceeds max_size(), length_error is thrown.  The
157938fd1498Szrj        *  value of the string doesn't change if an error is thrown.
158038fd1498Szrj       */
158138fd1498Szrj       __versa_string&
158238fd1498Szrj       replace(const_iterator __i1, const_iterator __i2,
158338fd1498Szrj 	      std::initializer_list<_CharT> __l)
158438fd1498Szrj       { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
158538fd1498Szrj #endif // C++11
158638fd1498Szrj 
158738fd1498Szrj     private:
158838fd1498Szrj       template<class _Integer>
158938fd1498Szrj 	__versa_string&
159038fd1498Szrj 	_M_replace_dispatch(const_iterator __i1, const_iterator __i2,
159138fd1498Szrj 			    _Integer __n, _Integer __val, std::__true_type)
159238fd1498Szrj         { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
159338fd1498Szrj 
159438fd1498Szrj       template<class _InputIterator>
159538fd1498Szrj 	__versa_string&
159638fd1498Szrj 	_M_replace_dispatch(const_iterator __i1, const_iterator __i2,
159738fd1498Szrj 			    _InputIterator __k1, _InputIterator __k2,
159838fd1498Szrj 			    std::__false_type);
159938fd1498Szrj 
160038fd1498Szrj       __versa_string&
160138fd1498Szrj       _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
160238fd1498Szrj 		     _CharT __c);
160338fd1498Szrj 
160438fd1498Szrj       __versa_string&
160538fd1498Szrj       _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
160638fd1498Szrj 		 const size_type __len2);
160738fd1498Szrj 
160838fd1498Szrj       __versa_string&
160938fd1498Szrj       _M_append(const _CharT* __s, size_type __n);
161038fd1498Szrj 
161138fd1498Szrj     public:
161238fd1498Szrj 
161338fd1498Szrj       /**
161438fd1498Szrj        *  @brief  Copy substring into C string.
161538fd1498Szrj        *  @param __s  C string to copy value into.
161638fd1498Szrj        *  @param __n  Number of characters to copy.
161738fd1498Szrj        *  @param __pos  Index of first character to copy.
161838fd1498Szrj        *  @return  Number of characters actually copied
161938fd1498Szrj        *  @throw  std::out_of_range  If pos > size().
162038fd1498Szrj        *
162138fd1498Szrj        *  Copies up to @a __n characters starting at @a __pos into the
162238fd1498Szrj        *  C string @a s.  If @a __pos is greater than size(),
162338fd1498Szrj        *  out_of_range is thrown.
162438fd1498Szrj       */
162538fd1498Szrj       size_type
162638fd1498Szrj       copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
162738fd1498Szrj 
162838fd1498Szrj       /**
162938fd1498Szrj        *  @brief  Swap contents with another string.
163038fd1498Szrj        *  @param __s  String to swap with.
163138fd1498Szrj        *
163238fd1498Szrj        *  Exchanges the contents of this string with that of @a __s in
163338fd1498Szrj        *  constant time.
163438fd1498Szrj       */
163538fd1498Szrj       void
163638fd1498Szrj       swap(__versa_string& __s) _GLIBCXX_NOEXCEPT
163738fd1498Szrj       { this->_M_swap(__s); }
163838fd1498Szrj 
163938fd1498Szrj       // String operations:
164038fd1498Szrj       /**
164138fd1498Szrj        *  @brief  Return const pointer to null-terminated contents.
164238fd1498Szrj        *
164338fd1498Szrj        *  This is a handle to internal data.  Do not modify or dire things may
164438fd1498Szrj        *  happen.
164538fd1498Szrj       */
164638fd1498Szrj       const _CharT*
164738fd1498Szrj       c_str() const _GLIBCXX_NOEXCEPT
164838fd1498Szrj       { return this->_M_data(); }
164938fd1498Szrj 
165038fd1498Szrj       /**
165138fd1498Szrj        *  @brief  Return const pointer to contents.
165238fd1498Szrj        *
165338fd1498Szrj        *  This is a handle to internal data.  Do not modify or dire things may
165438fd1498Szrj        *  happen.
165538fd1498Szrj       */
165638fd1498Szrj       const _CharT*
165738fd1498Szrj       data() const _GLIBCXX_NOEXCEPT
165838fd1498Szrj       { return this->_M_data(); }
165938fd1498Szrj 
166038fd1498Szrj       /**
166138fd1498Szrj        *  @brief  Return copy of allocator used to construct this string.
166238fd1498Szrj       */
166338fd1498Szrj       allocator_type
166438fd1498Szrj       get_allocator() const _GLIBCXX_NOEXCEPT
166538fd1498Szrj       { return allocator_type(this->_M_get_allocator()); }
166638fd1498Szrj 
166738fd1498Szrj       /**
166838fd1498Szrj        *  @brief  Find position of a C substring.
166938fd1498Szrj        *  @param __s  C string to locate.
167038fd1498Szrj        *  @param __pos  Index of character to search from.
167138fd1498Szrj        *  @param __n  Number of characters from @a __s to search for.
167238fd1498Szrj        *  @return  Index of start of first occurrence.
167338fd1498Szrj        *
167438fd1498Szrj        *  Starting from @a __pos, searches forward for the first @a
167538fd1498Szrj        *  __n characters in @a __s within this string.  If found,
167638fd1498Szrj        *  returns the index where it begins.  If not found, returns
167738fd1498Szrj        *  npos.
167838fd1498Szrj       */
167938fd1498Szrj       size_type
168038fd1498Szrj       find(const _CharT* __s, size_type __pos, size_type __n) const;
168138fd1498Szrj 
168238fd1498Szrj       /**
168338fd1498Szrj        *  @brief  Find position of a string.
168438fd1498Szrj        *  @param __str  String to locate.
168538fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
168638fd1498Szrj        *  @return  Index of start of first occurrence.
168738fd1498Szrj        *
168838fd1498Szrj        *  Starting from @a __pos, searches forward for value of @a
168938fd1498Szrj        *  __str within this string.  If found, returns the index where
169038fd1498Szrj        *  it begins.  If not found, returns npos.
169138fd1498Szrj       */
169238fd1498Szrj       size_type
169338fd1498Szrj       find(const __versa_string& __str, size_type __pos = 0) const
169438fd1498Szrj 	_GLIBCXX_NOEXCEPT
169538fd1498Szrj       { return this->find(__str.data(), __pos, __str.size()); }
169638fd1498Szrj 
169738fd1498Szrj       /**
169838fd1498Szrj        *  @brief  Find position of a C string.
169938fd1498Szrj        *  @param __s  C string to locate.
170038fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
170138fd1498Szrj        *  @return  Index of start of first occurrence.
170238fd1498Szrj        *
170338fd1498Szrj        *  Starting from @a __pos, searches forward for the value of @a
170438fd1498Szrj        *  __s within this string.  If found, returns the index where
170538fd1498Szrj        *  it begins.  If not found, returns npos.
170638fd1498Szrj       */
170738fd1498Szrj       size_type
170838fd1498Szrj       find(const _CharT* __s, size_type __pos = 0) const
170938fd1498Szrj       {
171038fd1498Szrj 	__glibcxx_requires_string(__s);
171138fd1498Szrj 	return this->find(__s, __pos, traits_type::length(__s));
171238fd1498Szrj       }
171338fd1498Szrj 
171438fd1498Szrj       /**
171538fd1498Szrj        *  @brief  Find position of a character.
171638fd1498Szrj        *  @param __c  Character to locate.
171738fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
171838fd1498Szrj        *  @return  Index of first occurrence.
171938fd1498Szrj        *
172038fd1498Szrj        *  Starting from @a __pos, searches forward for @a __c within
172138fd1498Szrj        *  this string.  If found, returns the index where it was
172238fd1498Szrj        *  found.  If not found, returns npos.
172338fd1498Szrj       */
172438fd1498Szrj       size_type
172538fd1498Szrj       find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
172638fd1498Szrj 
172738fd1498Szrj       /**
172838fd1498Szrj        *  @brief  Find last position of a string.
172938fd1498Szrj        *  @param __str  String to locate.
173038fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
173138fd1498Szrj        *  @return  Index of start of last occurrence.
173238fd1498Szrj        *
173338fd1498Szrj        *  Starting from @a __pos, searches backward for value of @a
173438fd1498Szrj        *  __str within this string.  If found, returns the index where
173538fd1498Szrj        *  it begins.  If not found, returns npos.
173638fd1498Szrj       */
173738fd1498Szrj       size_type
173838fd1498Szrj       rfind(const __versa_string& __str, size_type __pos = npos) const
173938fd1498Szrj 	_GLIBCXX_NOEXCEPT
174038fd1498Szrj       { return this->rfind(__str.data(), __pos, __str.size()); }
174138fd1498Szrj 
174238fd1498Szrj       /**
174338fd1498Szrj        *  @brief  Find last position of a C substring.
174438fd1498Szrj        *  @param __s  C string to locate.
174538fd1498Szrj        *  @param __pos  Index of character to search back from.
174638fd1498Szrj        *  @param __n  Number of characters from s to search for.
174738fd1498Szrj        *  @return  Index of start of last occurrence.
174838fd1498Szrj        *
174938fd1498Szrj        *  Starting from @a __pos, searches backward for the first @a
175038fd1498Szrj        *  __n characters in @a __s within this string.  If found,
175138fd1498Szrj        *  returns the index where it begins.  If not found, returns
175238fd1498Szrj        *  npos.
175338fd1498Szrj       */
175438fd1498Szrj       size_type
175538fd1498Szrj       rfind(const _CharT* __s, size_type __pos, size_type __n) const;
175638fd1498Szrj 
175738fd1498Szrj       /**
175838fd1498Szrj        *  @brief  Find last position of a C string.
175938fd1498Szrj        *  @param __s  C string to locate.
176038fd1498Szrj        *  @param __pos  Index of character to start search at (default end).
176138fd1498Szrj        *  @return  Index of start of  last occurrence.
176238fd1498Szrj        *
176338fd1498Szrj        *  Starting from @a __pos, searches backward for the value of
176438fd1498Szrj        *  @a __s within this string.  If found, returns the index
176538fd1498Szrj        *  where it begins.  If not found, returns npos.
176638fd1498Szrj       */
176738fd1498Szrj       size_type
176838fd1498Szrj       rfind(const _CharT* __s, size_type __pos = npos) const
176938fd1498Szrj       {
177038fd1498Szrj 	__glibcxx_requires_string(__s);
177138fd1498Szrj 	return this->rfind(__s, __pos, traits_type::length(__s));
177238fd1498Szrj       }
177338fd1498Szrj 
177438fd1498Szrj       /**
177538fd1498Szrj        *  @brief  Find last position of a character.
177638fd1498Szrj        *  @param __c  Character to locate.
177738fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
177838fd1498Szrj        *  @return  Index of last occurrence.
177938fd1498Szrj        *
178038fd1498Szrj        *  Starting from @a __pos, searches backward for @a __c within
178138fd1498Szrj        *  this string.  If found, returns the index where it was
178238fd1498Szrj        *  found.  If not found, returns npos.
178338fd1498Szrj       */
178438fd1498Szrj       size_type
178538fd1498Szrj       rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
178638fd1498Szrj 
178738fd1498Szrj       /**
178838fd1498Szrj        *  @brief  Find position of a character of string.
178938fd1498Szrj        *  @param __str  String containing characters to locate.
179038fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
179138fd1498Szrj        *  @return  Index of first occurrence.
179238fd1498Szrj        *
179338fd1498Szrj        *  Starting from @a __pos, searches forward for one of the characters of
179438fd1498Szrj        *  @a __str within this string.  If found, returns the index where it was
179538fd1498Szrj        *  found.  If not found, returns npos.
179638fd1498Szrj       */
179738fd1498Szrj       size_type
179838fd1498Szrj       find_first_of(const __versa_string& __str, size_type __pos = 0) const
179938fd1498Szrj 	_GLIBCXX_NOEXCEPT
180038fd1498Szrj       { return this->find_first_of(__str.data(), __pos, __str.size()); }
180138fd1498Szrj 
180238fd1498Szrj       /**
180338fd1498Szrj        *  @brief  Find position of a character of C substring.
180438fd1498Szrj        *  @param __s  String containing characters to locate.
180538fd1498Szrj        *  @param __pos  Index of character to search from.
180638fd1498Szrj        *  @param __n  Number of characters from s to search for.
180738fd1498Szrj        *  @return  Index of first occurrence.
180838fd1498Szrj        *
180938fd1498Szrj        *  Starting from @a __pos, searches forward for one of the
181038fd1498Szrj        *  first @a __n characters of @a __s within this string.  If
181138fd1498Szrj        *  found, returns the index where it was found.  If not found,
181238fd1498Szrj        *  returns npos.
181338fd1498Szrj       */
181438fd1498Szrj       size_type
181538fd1498Szrj       find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
181638fd1498Szrj 
181738fd1498Szrj       /**
181838fd1498Szrj        *  @brief  Find position of a character of C string.
181938fd1498Szrj        *  @param __s  String containing characters to locate.
182038fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
182138fd1498Szrj        *  @return  Index of first occurrence.
182238fd1498Szrj        *
182338fd1498Szrj        *  Starting from @a __pos, searches forward for one of the
182438fd1498Szrj        *  characters of @a __s within this string.  If found, returns
182538fd1498Szrj        *  the index where it was found.  If not found, returns npos.
182638fd1498Szrj       */
182738fd1498Szrj       size_type
182838fd1498Szrj       find_first_of(const _CharT* __s, size_type __pos = 0) const
182938fd1498Szrj       {
183038fd1498Szrj 	__glibcxx_requires_string(__s);
183138fd1498Szrj 	return this->find_first_of(__s, __pos, traits_type::length(__s));
183238fd1498Szrj       }
183338fd1498Szrj 
183438fd1498Szrj       /**
183538fd1498Szrj        *  @brief  Find position of a character.
183638fd1498Szrj        *  @param __c  Character to locate.
183738fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
183838fd1498Szrj        *  @return  Index of first occurrence.
183938fd1498Szrj        *
184038fd1498Szrj        *  Starting from @a __pos, searches forward for the character
184138fd1498Szrj        *  @a __c within this string.  If found, returns the index
184238fd1498Szrj        *  where it was found.  If not found, returns npos.
184338fd1498Szrj        *
184438fd1498Szrj        *  Note: equivalent to find(c, pos).
184538fd1498Szrj       */
184638fd1498Szrj       size_type
184738fd1498Szrj       find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
184838fd1498Szrj       { return this->find(__c, __pos); }
184938fd1498Szrj 
185038fd1498Szrj       /**
185138fd1498Szrj        *  @brief  Find last position of a character of string.
185238fd1498Szrj        *  @param __str  String containing characters to locate.
185338fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
185438fd1498Szrj        *  @return  Index of last occurrence.
185538fd1498Szrj        *
185638fd1498Szrj        *  Starting from @a __pos, searches backward for one of the
185738fd1498Szrj        *  characters of @a __str within this string.  If found,
185838fd1498Szrj        *  returns the index where it was found.  If not found, returns
185938fd1498Szrj        *  npos.
186038fd1498Szrj       */
186138fd1498Szrj       size_type
186238fd1498Szrj       find_last_of(const __versa_string& __str, size_type __pos = npos) const
186338fd1498Szrj 	_GLIBCXX_NOEXCEPT
186438fd1498Szrj       { return this->find_last_of(__str.data(), __pos, __str.size()); }
186538fd1498Szrj 
186638fd1498Szrj       /**
186738fd1498Szrj        *  @brief  Find last position of a character of C substring.
186838fd1498Szrj        *  @param __s  C string containing characters to locate.
186938fd1498Szrj        *  @param __pos  Index of character to search back from.
187038fd1498Szrj        *  @param __n  Number of characters from s to search for.
187138fd1498Szrj        *  @return  Index of last occurrence.
187238fd1498Szrj        *
187338fd1498Szrj        *  Starting from @a __pos, searches backward for one of the
187438fd1498Szrj        *  first @a __n characters of @a __s within this string.  If
187538fd1498Szrj        *  found, returns the index where it was found.  If not found,
187638fd1498Szrj        *  returns npos.
187738fd1498Szrj       */
187838fd1498Szrj       size_type
187938fd1498Szrj       find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
188038fd1498Szrj 
188138fd1498Szrj       /**
188238fd1498Szrj        *  @brief  Find last position of a character of C string.
188338fd1498Szrj        *  @param __s  C string containing characters to locate.
188438fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
188538fd1498Szrj        *  @return  Index of last occurrence.
188638fd1498Szrj        *
188738fd1498Szrj        *  Starting from @a __pos, searches backward for one of the
188838fd1498Szrj        *  characters of @a __s within this string.  If found, returns
188938fd1498Szrj        *  the index where it was found.  If not found, returns npos.
189038fd1498Szrj       */
189138fd1498Szrj       size_type
189238fd1498Szrj       find_last_of(const _CharT* __s, size_type __pos = npos) const
189338fd1498Szrj       {
189438fd1498Szrj 	__glibcxx_requires_string(__s);
189538fd1498Szrj 	return this->find_last_of(__s, __pos, traits_type::length(__s));
189638fd1498Szrj       }
189738fd1498Szrj 
189838fd1498Szrj       /**
189938fd1498Szrj        *  @brief  Find last position of a character.
190038fd1498Szrj        *  @param __c  Character to locate.
190138fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
190238fd1498Szrj        *  @return  Index of last occurrence.
190338fd1498Szrj        *
190438fd1498Szrj        *  Starting from @a __pos, searches backward for @a __c within
190538fd1498Szrj        *  this string.  If found, returns the index where it was
190638fd1498Szrj        *  found.  If not found, returns npos.
190738fd1498Szrj        *
190838fd1498Szrj        *  Note: equivalent to rfind(c, pos).
190938fd1498Szrj       */
191038fd1498Szrj       size_type
191138fd1498Szrj       find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
191238fd1498Szrj       { return this->rfind(__c, __pos); }
191338fd1498Szrj 
191438fd1498Szrj       /**
191538fd1498Szrj        *  @brief  Find position of a character not in string.
191638fd1498Szrj        *  @param __str  String containing characters to avoid.
191738fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
191838fd1498Szrj        *  @return  Index of first occurrence.
191938fd1498Szrj        *
192038fd1498Szrj        *  Starting from @a __pos, searches forward for a character not
192138fd1498Szrj        *  contained in @a __str within this string.  If found, returns
192238fd1498Szrj        *  the index where it was found.  If not found, returns npos.
192338fd1498Szrj       */
192438fd1498Szrj       size_type
192538fd1498Szrj       find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
192638fd1498Szrj 	_GLIBCXX_NOEXCEPT
192738fd1498Szrj       { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
192838fd1498Szrj 
192938fd1498Szrj       /**
193038fd1498Szrj        *  @brief  Find position of a character not in C substring.
193138fd1498Szrj        *  @param __s  C string containing characters to avoid.
193238fd1498Szrj        *  @param __pos  Index of character to search from.
193338fd1498Szrj        *  @param __n  Number of characters from s to consider.
193438fd1498Szrj        *  @return  Index of first occurrence.
193538fd1498Szrj        *
193638fd1498Szrj        *  Starting from @a __pos, searches forward for a character not
193738fd1498Szrj        *  contained in the first @a __n characters of @a __s within
193838fd1498Szrj        *  this string.  If found, returns the index where it was
193938fd1498Szrj        *  found.  If not found, returns npos.
194038fd1498Szrj       */
194138fd1498Szrj       size_type
194238fd1498Szrj       find_first_not_of(const _CharT* __s, size_type __pos,
194338fd1498Szrj 			size_type __n) const;
194438fd1498Szrj 
194538fd1498Szrj       /**
194638fd1498Szrj        *  @brief  Find position of a character not in C string.
194738fd1498Szrj        *  @param __s  C string containing characters to avoid.
194838fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
194938fd1498Szrj        *  @return  Index of first occurrence.
195038fd1498Szrj        *
195138fd1498Szrj        *  Starting from @a __pos, searches forward for a character not
195238fd1498Szrj        *  contained in @a __s within this string.  If found, returns
195338fd1498Szrj        *  the index where it was found.  If not found, returns npos.
195438fd1498Szrj       */
195538fd1498Szrj       size_type
195638fd1498Szrj       find_first_not_of(const _CharT* __s, size_type __pos = 0) const
195738fd1498Szrj       {
195838fd1498Szrj 	__glibcxx_requires_string(__s);
195938fd1498Szrj 	return this->find_first_not_of(__s, __pos, traits_type::length(__s));
196038fd1498Szrj       }
196138fd1498Szrj 
196238fd1498Szrj       /**
196338fd1498Szrj        *  @brief  Find position of a different character.
196438fd1498Szrj        *  @param __c  Character to avoid.
196538fd1498Szrj        *  @param __pos  Index of character to search from (default 0).
196638fd1498Szrj        *  @return  Index of first occurrence.
196738fd1498Szrj        *
196838fd1498Szrj        *  Starting from @a __pos, searches forward for a character
196938fd1498Szrj        *  other than @a __c within this string.  If found, returns the
197038fd1498Szrj        *  index where it was found.  If not found, returns npos.
197138fd1498Szrj       */
197238fd1498Szrj       size_type
197338fd1498Szrj       find_first_not_of(_CharT __c, size_type __pos = 0) const
197438fd1498Szrj 	_GLIBCXX_NOEXCEPT;
197538fd1498Szrj 
197638fd1498Szrj       /**
197738fd1498Szrj        *  @brief  Find last position of a character not in string.
197838fd1498Szrj        *  @param __str  String containing characters to avoid.
197938fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
198038fd1498Szrj        *  @return  Index of last occurrence.
198138fd1498Szrj        *
198238fd1498Szrj        *  Starting from @a __pos, searches backward for a character
198338fd1498Szrj        *  not contained in @a __str within this string.  If found,
198438fd1498Szrj        *  returns the index where it was found.  If not found, returns
198538fd1498Szrj        *  npos.
198638fd1498Szrj       */
198738fd1498Szrj       size_type
198838fd1498Szrj       find_last_not_of(const __versa_string& __str,
198938fd1498Szrj 		       size_type __pos = npos) const _GLIBCXX_NOEXCEPT
199038fd1498Szrj       { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
199138fd1498Szrj 
199238fd1498Szrj       /**
199338fd1498Szrj        *  @brief  Find last position of a character not in C substring.
199438fd1498Szrj        *  @param __s  C string containing characters to avoid.
199538fd1498Szrj        *  @param __pos  Index of character to search back from.
199638fd1498Szrj        *  @param __n  Number of characters from s to consider.
199738fd1498Szrj        *  @return  Index of last occurrence.
199838fd1498Szrj        *
199938fd1498Szrj        *  Starting from @a __pos, searches backward for a character
200038fd1498Szrj        *  not contained in the first @a __n characters of @a __s
200138fd1498Szrj        *  within this string.  If found, returns the index where it
200238fd1498Szrj        *  was found.  If not found, returns npos.
200338fd1498Szrj       */
200438fd1498Szrj       size_type
200538fd1498Szrj       find_last_not_of(const _CharT* __s, size_type __pos,
200638fd1498Szrj 		       size_type __n) const;
200738fd1498Szrj       /**
200838fd1498Szrj        *  @brief  Find last position of a character not in C string.
200938fd1498Szrj        *  @param __s  C string containing characters to avoid.
201038fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
201138fd1498Szrj        *  @return  Index of last occurrence.
201238fd1498Szrj        *
201338fd1498Szrj        *  Starting from @a __pos, searches backward for a character
201438fd1498Szrj        *  not contained in @a __s within this string.  If found,
201538fd1498Szrj        *  returns the index where it was found.  If not found, returns
201638fd1498Szrj        *  npos.
201738fd1498Szrj       */
201838fd1498Szrj       size_type
201938fd1498Szrj       find_last_not_of(const _CharT* __s, size_type __pos = npos) const
202038fd1498Szrj       {
202138fd1498Szrj 	__glibcxx_requires_string(__s);
202238fd1498Szrj 	return this->find_last_not_of(__s, __pos, traits_type::length(__s));
202338fd1498Szrj       }
202438fd1498Szrj 
202538fd1498Szrj       /**
202638fd1498Szrj        *  @brief  Find last position of a different character.
202738fd1498Szrj        *  @param __c  Character to avoid.
202838fd1498Szrj        *  @param __pos  Index of character to search back from (default end).
202938fd1498Szrj        *  @return  Index of last occurrence.
203038fd1498Szrj        *
203138fd1498Szrj        *  Starting from @a __pos, searches backward for a character
203238fd1498Szrj        *  other than @a __c within this string.  If found, returns the
203338fd1498Szrj        *  index where it was found.  If not found, returns npos.
203438fd1498Szrj       */
203538fd1498Szrj       size_type
203638fd1498Szrj       find_last_not_of(_CharT __c, size_type __pos = npos) const
203738fd1498Szrj 	_GLIBCXX_NOEXCEPT;
203838fd1498Szrj 
203938fd1498Szrj       /**
204038fd1498Szrj        *  @brief  Get a substring.
204138fd1498Szrj        *  @param __pos  Index of first character (default 0).
204238fd1498Szrj        *  @param __n  Number of characters in substring (default remainder).
204338fd1498Szrj        *  @return  The new string.
204438fd1498Szrj        *  @throw  std::out_of_range  If pos > size().
204538fd1498Szrj        *
204638fd1498Szrj        *  Construct and return a new string using the @a __n
204738fd1498Szrj        *  characters starting at @a __pos.  If the string is too
204838fd1498Szrj        *  short, use the remainder of the characters.  If @a __pos is
204938fd1498Szrj        *  beyond the end of the string, out_of_range is thrown.
205038fd1498Szrj       */
205138fd1498Szrj       __versa_string
205238fd1498Szrj       substr(size_type __pos = 0, size_type __n = npos) const
205338fd1498Szrj       {
205438fd1498Szrj 	return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
205538fd1498Szrj 			      __n);
205638fd1498Szrj       }
205738fd1498Szrj 
205838fd1498Szrj       /**
205938fd1498Szrj        *  @brief  Compare to a string.
206038fd1498Szrj        *  @param __str  String to compare against.
206138fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
206238fd1498Szrj        *
206338fd1498Szrj        *  Returns an integer < 0 if this string is ordered before @a
206438fd1498Szrj        *  __str, 0 if their values are equivalent, or > 0 if this
206538fd1498Szrj        *  string is ordered after @a __str.  Determines the effective
206638fd1498Szrj        *  length rlen of the strings to compare as the smallest of
206738fd1498Szrj        *  size() and str.size().  The function then compares the two
206838fd1498Szrj        *  strings by calling traits::compare(data(), str.data(),rlen).
206938fd1498Szrj        *  If the result of the comparison is nonzero returns it,
207038fd1498Szrj        *  otherwise the shorter one is ordered first.
207138fd1498Szrj       */
207238fd1498Szrj       int
207338fd1498Szrj       compare(const __versa_string& __str) const
207438fd1498Szrj       {
207538fd1498Szrj 	if (this->_M_compare(__str))
207638fd1498Szrj 	  return 0;
207738fd1498Szrj 
207838fd1498Szrj 	const size_type __size = this->size();
207938fd1498Szrj 	const size_type __osize = __str.size();
208038fd1498Szrj 	const size_type __len = std::min(__size, __osize);
208138fd1498Szrj 
208238fd1498Szrj 	int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
208338fd1498Szrj 	if (!__r)
208438fd1498Szrj 	  __r = this->_S_compare(__size, __osize);
208538fd1498Szrj 	return __r;
208638fd1498Szrj       }
208738fd1498Szrj 
208838fd1498Szrj       /**
208938fd1498Szrj        *  @brief  Compare substring to a string.
209038fd1498Szrj        *  @param __pos  Index of first character of substring.
209138fd1498Szrj        *  @param __n  Number of characters in substring.
209238fd1498Szrj        *  @param __str  String to compare against.
209338fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
209438fd1498Szrj        *
209538fd1498Szrj        *  Form the substring of this string from the @a __n characters
209638fd1498Szrj        *  starting at @a __pos.  Returns an integer < 0 if the
209738fd1498Szrj        *  substring is ordered before @a __str, 0 if their values are
209838fd1498Szrj        *  equivalent, or > 0 if the substring is ordered after @a
209938fd1498Szrj        *  __str.  Determines the effective length rlen of the strings
210038fd1498Szrj        *  to compare as the smallest of the length of the substring
210138fd1498Szrj        *  and @a __str.size().  The function then compares the two
210238fd1498Szrj        *  strings by calling
210338fd1498Szrj        *  traits::compare(substring.data(),str.data(),rlen).  If the
210438fd1498Szrj        *  result of the comparison is nonzero returns it, otherwise
210538fd1498Szrj        *  the shorter one is ordered first.
210638fd1498Szrj       */
210738fd1498Szrj       int
210838fd1498Szrj       compare(size_type __pos, size_type __n,
210938fd1498Szrj 	      const __versa_string& __str) const;
211038fd1498Szrj 
211138fd1498Szrj       /**
211238fd1498Szrj        *  @brief  Compare substring to a substring.
211338fd1498Szrj        *  @param __pos1  Index of first character of substring.
211438fd1498Szrj        *  @param __n1  Number of characters in substring.
211538fd1498Szrj        *  @param __str  String to compare against.
211638fd1498Szrj        *  @param __pos2  Index of first character of substring of str.
211738fd1498Szrj        *  @param __n2  Number of characters in substring of str.
211838fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
211938fd1498Szrj        *
212038fd1498Szrj        *  Form the substring of this string from the @a __n1
212138fd1498Szrj        *  characters starting at @a __pos1.  Form the substring of @a
212238fd1498Szrj        *  __str from the @a __n2 characters starting at @a __pos2.
212338fd1498Szrj        *  Returns an integer < 0 if this substring is ordered before
212438fd1498Szrj        *  the substring of @a __str, 0 if their values are equivalent,
212538fd1498Szrj        *  or > 0 if this substring is ordered after the substring of
212638fd1498Szrj        *  @a __str.  Determines the effective length rlen of the
212738fd1498Szrj        *  strings to compare as the smallest of the lengths of the
212838fd1498Szrj        *  substrings.  The function then compares the two strings by
212938fd1498Szrj        *  calling
213038fd1498Szrj        *  traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
213138fd1498Szrj        *  If the result of the comparison is nonzero returns it,
213238fd1498Szrj        *  otherwise the shorter one is ordered first.
213338fd1498Szrj       */
213438fd1498Szrj       int
213538fd1498Szrj       compare(size_type __pos1, size_type __n1, const __versa_string& __str,
213638fd1498Szrj 	      size_type __pos2, size_type __n2) const;
213738fd1498Szrj 
213838fd1498Szrj       /**
213938fd1498Szrj        *  @brief  Compare to a C string.
214038fd1498Szrj        *  @param __s  C string to compare against.
214138fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
214238fd1498Szrj        *
214338fd1498Szrj        *  Returns an integer < 0 if this string is ordered before @a
214438fd1498Szrj        *  __s, 0 if their values are equivalent, or > 0 if this string
214538fd1498Szrj        *  is ordered after @a __s.  Determines the effective length
214638fd1498Szrj        *  rlen of the strings to compare as the smallest of size() and
214738fd1498Szrj        *  the length of a string constructed from @a __s.  The
214838fd1498Szrj        *  function then compares the two strings by calling
214938fd1498Szrj        *  traits::compare(data(),s,rlen).  If the result of the
215038fd1498Szrj        *  comparison is nonzero returns it, otherwise the shorter one
215138fd1498Szrj        *  is ordered first.
215238fd1498Szrj       */
215338fd1498Szrj       int
215438fd1498Szrj       compare(const _CharT* __s) const;
215538fd1498Szrj 
215638fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
215738fd1498Szrj       // 5 String::compare specification questionable
215838fd1498Szrj       /**
215938fd1498Szrj        *  @brief  Compare substring to a C string.
216038fd1498Szrj        *  @param __pos  Index of first character of substring.
216138fd1498Szrj        *  @param __n1  Number of characters in substring.
216238fd1498Szrj        *  @param __s  C string to compare against.
216338fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
216438fd1498Szrj        *
216538fd1498Szrj        *  Form the substring of this string from the @a __n1
216638fd1498Szrj        *  characters starting at @a __pos.  Returns an integer < 0 if
216738fd1498Szrj        *  the substring is ordered before @a __s, 0 if their values
216838fd1498Szrj        *  are equivalent, or > 0 if the substring is ordered after @a
216938fd1498Szrj        *  __s.  Determines the effective length rlen of the strings to
217038fd1498Szrj        *  compare as the smallest of the length of the substring and
217138fd1498Szrj        *  the length of a string constructed from @a __s.  The
217238fd1498Szrj        *  function then compares the two string by calling
217338fd1498Szrj        *  traits::compare(substring.data(),s,rlen).  If the result of
217438fd1498Szrj        *  the comparison is nonzero returns it, otherwise the shorter
217538fd1498Szrj        *  one is ordered first.
217638fd1498Szrj       */
217738fd1498Szrj       int
217838fd1498Szrj       compare(size_type __pos, size_type __n1, const _CharT* __s) const;
217938fd1498Szrj 
218038fd1498Szrj       /**
218138fd1498Szrj        *  @brief  Compare substring against a character array.
218238fd1498Szrj        *  @param __pos  Index of first character of substring.
218338fd1498Szrj        *  @param __n1  Number of characters in substring.
218438fd1498Szrj        *  @param __s  character array to compare against.
218538fd1498Szrj        *  @param __n2  Number of characters of s.
218638fd1498Szrj        *  @return  Integer < 0, 0, or > 0.
218738fd1498Szrj        *
218838fd1498Szrj        *  Form the substring of this string from the @a __n1
218938fd1498Szrj        *  characters starting at @a __pos.  Form a string from the
219038fd1498Szrj        *  first @a __n2 characters of @a __s.  Returns an integer < 0
219138fd1498Szrj        *  if this substring is ordered before the string from @a __s,
219238fd1498Szrj        *  0 if their values are equivalent, or > 0 if this substring
219338fd1498Szrj        *  is ordered after the string from @a __s.  Determines the
219438fd1498Szrj        *  effective length rlen of the strings to compare as the
219538fd1498Szrj        *  smallest of the length of the substring and @a __n2.  The
219638fd1498Szrj        *  function then compares the two strings by calling
219738fd1498Szrj        *  traits::compare(substring.data(),__s,rlen).  If the result of
219838fd1498Szrj        *  the comparison is nonzero returns it, otherwise the shorter
219938fd1498Szrj        *  one is ordered first.
220038fd1498Szrj        *
220138fd1498Szrj        *  NB: __s must have at least n2 characters, <em>\\0</em> has no special
220238fd1498Szrj        *  meaning.
220338fd1498Szrj       */
220438fd1498Szrj       int
220538fd1498Szrj       compare(size_type __pos, size_type __n1, const _CharT* __s,
220638fd1498Szrj 	      size_type __n2) const;
220738fd1498Szrj     };
220838fd1498Szrj 
220938fd1498Szrj   // operator+
221038fd1498Szrj   /**
221138fd1498Szrj    *  @brief  Concatenate two strings.
221238fd1498Szrj    *  @param __lhs  First string.
221338fd1498Szrj    *  @param __rhs  Last string.
221438fd1498Szrj    *  @return  New string with value of @a __lhs followed by @a __rhs.
221538fd1498Szrj    */
221638fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
221738fd1498Szrj 	   template <typename, typename, typename> class _Base>
221838fd1498Szrj     __versa_string<_CharT, _Traits, _Alloc, _Base>
221938fd1498Szrj     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
222038fd1498Szrj 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
222138fd1498Szrj 
222238fd1498Szrj   /**
222338fd1498Szrj    *  @brief  Concatenate C string and string.
222438fd1498Szrj    *  @param __lhs  First string.
222538fd1498Szrj    *  @param __rhs  Last string.
222638fd1498Szrj    *  @return  New string with value of @a __lhs followed by @a __rhs.
222738fd1498Szrj    */
222838fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
222938fd1498Szrj 	   template <typename, typename, typename> class _Base>
223038fd1498Szrj     __versa_string<_CharT, _Traits, _Alloc, _Base>
223138fd1498Szrj     operator+(const _CharT* __lhs,
223238fd1498Szrj 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
223338fd1498Szrj 
223438fd1498Szrj   /**
223538fd1498Szrj    *  @brief  Concatenate character and string.
223638fd1498Szrj    *  @param __lhs  First string.
223738fd1498Szrj    *  @param __rhs  Last string.
223838fd1498Szrj    *  @return  New string with @a __lhs followed by @a __rhs.
223938fd1498Szrj    */
224038fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
224138fd1498Szrj 	   template <typename, typename, typename> class _Base>
224238fd1498Szrj     __versa_string<_CharT, _Traits, _Alloc, _Base>
224338fd1498Szrj     operator+(_CharT __lhs,
224438fd1498Szrj 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
224538fd1498Szrj 
224638fd1498Szrj   /**
224738fd1498Szrj    *  @brief  Concatenate string and C string.
224838fd1498Szrj    *  @param __lhs  First string.
224938fd1498Szrj    *  @param __rhs  Last string.
225038fd1498Szrj    *  @return  New string with @a __lhs followed by @a __rhs.
225138fd1498Szrj    */
225238fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
225338fd1498Szrj 	   template <typename, typename, typename> class _Base>
225438fd1498Szrj     __versa_string<_CharT, _Traits, _Alloc, _Base>
225538fd1498Szrj     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
225638fd1498Szrj 	      const _CharT* __rhs);
225738fd1498Szrj 
225838fd1498Szrj   /**
225938fd1498Szrj    *  @brief  Concatenate string and character.
226038fd1498Szrj    *  @param __lhs  First string.
226138fd1498Szrj    *  @param __rhs  Last string.
226238fd1498Szrj    *  @return  New string with @a __lhs followed by @a __rhs.
226338fd1498Szrj    */
226438fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
226538fd1498Szrj 	   template <typename, typename, typename> class _Base>
226638fd1498Szrj     __versa_string<_CharT, _Traits, _Alloc, _Base>
226738fd1498Szrj     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
226838fd1498Szrj 	      _CharT __rhs);
226938fd1498Szrj 
227038fd1498Szrj #if __cplusplus >= 201103L
227138fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
227238fd1498Szrj 	   template <typename, typename, typename> class _Base>
227338fd1498Szrj     inline __versa_string<_CharT, _Traits, _Alloc, _Base>
227438fd1498Szrj     operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
227538fd1498Szrj 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
227638fd1498Szrj     { return std::move(__lhs.append(__rhs)); }
227738fd1498Szrj 
227838fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
227938fd1498Szrj 	   template <typename, typename, typename> class _Base>
228038fd1498Szrj     inline __versa_string<_CharT, _Traits, _Alloc, _Base>
228138fd1498Szrj     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
228238fd1498Szrj 	      __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
228338fd1498Szrj     { return std::move(__rhs.insert(0, __lhs)); }
228438fd1498Szrj 
228538fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
228638fd1498Szrj 	   template <typename, typename, typename> class _Base>
228738fd1498Szrj     inline __versa_string<_CharT, _Traits, _Alloc, _Base>
228838fd1498Szrj     operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
228938fd1498Szrj 	      __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
229038fd1498Szrj     {
229138fd1498Szrj       const auto __size = __lhs.size() + __rhs.size();
229238fd1498Szrj       const bool __cond = (__size > __lhs.capacity()
229338fd1498Szrj 			   && __size <= __rhs.capacity());
229438fd1498Szrj       return __cond ? std::move(__rhs.insert(0, __lhs))
229538fd1498Szrj 	            : std::move(__lhs.append(__rhs));
229638fd1498Szrj     }
229738fd1498Szrj 
229838fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
229938fd1498Szrj 	   template <typename, typename, typename> class _Base>
230038fd1498Szrj     inline __versa_string<_CharT, _Traits, _Alloc, _Base>
230138fd1498Szrj     operator+(const _CharT* __lhs,
230238fd1498Szrj 	      __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
230338fd1498Szrj     { return std::move(__rhs.insert(0, __lhs)); }
230438fd1498Szrj 
230538fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
230638fd1498Szrj 	   template <typename, typename, typename> class _Base>
230738fd1498Szrj     inline __versa_string<_CharT, _Traits, _Alloc, _Base>
230838fd1498Szrj     operator+(_CharT __lhs,
230938fd1498Szrj 	      __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
231038fd1498Szrj     { return std::move(__rhs.insert(0, 1, __lhs)); }
231138fd1498Szrj 
231238fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
231338fd1498Szrj 	   template <typename, typename, typename> class _Base>
231438fd1498Szrj     inline __versa_string<_CharT, _Traits, _Alloc, _Base>
231538fd1498Szrj     operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
231638fd1498Szrj 	      const _CharT* __rhs)
231738fd1498Szrj     { return std::move(__lhs.append(__rhs)); }
231838fd1498Szrj 
231938fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
232038fd1498Szrj 	   template <typename, typename, typename> class _Base>
232138fd1498Szrj     inline __versa_string<_CharT, _Traits, _Alloc, _Base>
232238fd1498Szrj     operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
232338fd1498Szrj 	      _CharT __rhs)
232438fd1498Szrj     { return std::move(__lhs.append(1, __rhs)); }
232538fd1498Szrj #endif
232638fd1498Szrj 
232738fd1498Szrj   // operator ==
232838fd1498Szrj   /**
232938fd1498Szrj    *  @brief  Test equivalence of two strings.
233038fd1498Szrj    *  @param __lhs  First string.
233138fd1498Szrj    *  @param __rhs  Second string.
233238fd1498Szrj    *  @return  True if @a __lhs.compare(@a __rhs) == 0.  False otherwise.
233338fd1498Szrj    */
233438fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
233538fd1498Szrj 	   template <typename, typename, typename> class _Base>
233638fd1498Szrj     inline bool
233738fd1498Szrj     operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
233838fd1498Szrj 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
233938fd1498Szrj     { return __lhs.compare(__rhs) == 0; }
234038fd1498Szrj 
234138fd1498Szrj   template<typename _CharT,
234238fd1498Szrj 	   template <typename, typename, typename> class _Base>
234338fd1498Szrj     inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type
234438fd1498Szrj     operator==(const __versa_string<_CharT, std::char_traits<_CharT>,
234538fd1498Szrj 	       std::allocator<_CharT>, _Base>& __lhs,
234638fd1498Szrj 	       const __versa_string<_CharT, std::char_traits<_CharT>,
234738fd1498Szrj 	       std::allocator<_CharT>, _Base>& __rhs)
234838fd1498Szrj     { return (__lhs.size() == __rhs.size()
234938fd1498Szrj 	      && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
235038fd1498Szrj 						    __lhs.size())); }
235138fd1498Szrj 
235238fd1498Szrj   /**
235338fd1498Szrj    *  @brief  Test equivalence of C string and string.
235438fd1498Szrj    *  @param __lhs  C string.
235538fd1498Szrj    *  @param __rhs  String.
235638fd1498Szrj    *  @return  True if @a __rhs.compare(@a __lhs) == 0.  False otherwise.
235738fd1498Szrj    */
235838fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
235938fd1498Szrj 	   template <typename, typename, typename> class _Base>
236038fd1498Szrj     inline bool
236138fd1498Szrj     operator==(const _CharT* __lhs,
236238fd1498Szrj 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
236338fd1498Szrj     { return __rhs.compare(__lhs) == 0; }
236438fd1498Szrj 
236538fd1498Szrj   /**
236638fd1498Szrj    *  @brief  Test equivalence of string and C string.
236738fd1498Szrj    *  @param __lhs  String.
236838fd1498Szrj    *  @param __rhs  C string.
236938fd1498Szrj    *  @return  True if @a __lhs.compare(@a __rhs) == 0.  False otherwise.
237038fd1498Szrj    */
237138fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
237238fd1498Szrj 	   template <typename, typename, typename> class _Base>
237338fd1498Szrj     inline bool
237438fd1498Szrj     operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
237538fd1498Szrj 	       const _CharT* __rhs)
237638fd1498Szrj     { return __lhs.compare(__rhs) == 0; }
237738fd1498Szrj 
237838fd1498Szrj   // operator !=
237938fd1498Szrj   /**
238038fd1498Szrj    *  @brief  Test difference of two strings.
238138fd1498Szrj    *  @param __lhs  First string.
238238fd1498Szrj    *  @param __rhs  Second string.
238338fd1498Szrj    *  @return  True if @a __lhs.compare(@a __rhs) != 0.  False otherwise.
238438fd1498Szrj    */
238538fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
238638fd1498Szrj 	   template <typename, typename, typename> class _Base>
238738fd1498Szrj     inline bool
238838fd1498Szrj     operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
238938fd1498Szrj 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
239038fd1498Szrj     { return !(__lhs == __rhs); }
239138fd1498Szrj 
239238fd1498Szrj   /**
239338fd1498Szrj    *  @brief  Test difference of C string and string.
239438fd1498Szrj    *  @param __lhs  C string.
239538fd1498Szrj    *  @param __rhs  String.
239638fd1498Szrj    *  @return  True if @a __rhs.compare(@a __lhs) != 0.  False otherwise.
239738fd1498Szrj    */
239838fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
239938fd1498Szrj 	   template <typename, typename, typename> class _Base>
240038fd1498Szrj     inline bool
240138fd1498Szrj     operator!=(const _CharT* __lhs,
240238fd1498Szrj 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
240338fd1498Szrj     { return !(__lhs == __rhs); }
240438fd1498Szrj 
240538fd1498Szrj   /**
240638fd1498Szrj    *  @brief  Test difference of string and C string.
240738fd1498Szrj    *  @param __lhs  String.
240838fd1498Szrj    *  @param __rhs  C string.
240938fd1498Szrj    *  @return  True if @a __lhs.compare(@a __rhs) != 0.  False otherwise.
241038fd1498Szrj    */
241138fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
241238fd1498Szrj 	   template <typename, typename, typename> class _Base>
241338fd1498Szrj     inline bool
241438fd1498Szrj     operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
241538fd1498Szrj 	       const _CharT* __rhs)
241638fd1498Szrj     { return !(__lhs == __rhs); }
241738fd1498Szrj 
241838fd1498Szrj   // operator <
241938fd1498Szrj   /**
242038fd1498Szrj    *  @brief  Test if string precedes string.
242138fd1498Szrj    *  @param __lhs  First string.
242238fd1498Szrj    *  @param __rhs  Second string.
242338fd1498Szrj    *  @return  True if @a __lhs precedes @a __rhs.  False otherwise.
242438fd1498Szrj    */
242538fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
242638fd1498Szrj 	   template <typename, typename, typename> class _Base>
242738fd1498Szrj     inline bool
242838fd1498Szrj     operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
242938fd1498Szrj 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
243038fd1498Szrj     { return __lhs.compare(__rhs) < 0; }
243138fd1498Szrj 
243238fd1498Szrj   /**
243338fd1498Szrj    *  @brief  Test if string precedes C string.
243438fd1498Szrj    *  @param __lhs  String.
243538fd1498Szrj    *  @param __rhs  C string.
243638fd1498Szrj    *  @return  True if @a __lhs precedes @a __rhs.  False otherwise.
243738fd1498Szrj    */
243838fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
243938fd1498Szrj 	   template <typename, typename, typename> class _Base>
244038fd1498Szrj     inline bool
244138fd1498Szrj     operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
244238fd1498Szrj 	      const _CharT* __rhs)
244338fd1498Szrj     { return __lhs.compare(__rhs) < 0; }
244438fd1498Szrj 
244538fd1498Szrj   /**
244638fd1498Szrj    *  @brief  Test if C string precedes string.
244738fd1498Szrj    *  @param __lhs  C string.
244838fd1498Szrj    *  @param __rhs  String.
244938fd1498Szrj    *  @return  True if @a __lhs precedes @a __rhs.  False otherwise.
245038fd1498Szrj    */
245138fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
245238fd1498Szrj 	   template <typename, typename, typename> class _Base>
245338fd1498Szrj     inline bool
245438fd1498Szrj     operator<(const _CharT* __lhs,
245538fd1498Szrj 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
245638fd1498Szrj     { return __rhs.compare(__lhs) > 0; }
245738fd1498Szrj 
245838fd1498Szrj   // operator >
245938fd1498Szrj   /**
246038fd1498Szrj    *  @brief  Test if string follows string.
246138fd1498Szrj    *  @param __lhs  First string.
246238fd1498Szrj    *  @param __rhs  Second string.
246338fd1498Szrj    *  @return  True if @a __lhs follows @a __rhs.  False otherwise.
246438fd1498Szrj    */
246538fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
246638fd1498Szrj 	   template <typename, typename, typename> class _Base>
246738fd1498Szrj     inline bool
246838fd1498Szrj     operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
246938fd1498Szrj 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
247038fd1498Szrj     { return __lhs.compare(__rhs) > 0; }
247138fd1498Szrj 
247238fd1498Szrj   /**
247338fd1498Szrj    *  @brief  Test if string follows C string.
247438fd1498Szrj    *  @param __lhs  String.
247538fd1498Szrj    *  @param __rhs  C string.
247638fd1498Szrj    *  @return  True if @a __lhs follows @a __rhs.  False otherwise.
247738fd1498Szrj    */
247838fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
247938fd1498Szrj 	   template <typename, typename, typename> class _Base>
248038fd1498Szrj     inline bool
248138fd1498Szrj     operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
248238fd1498Szrj 	      const _CharT* __rhs)
248338fd1498Szrj     { return __lhs.compare(__rhs) > 0; }
248438fd1498Szrj 
248538fd1498Szrj   /**
248638fd1498Szrj    *  @brief  Test if C string follows string.
248738fd1498Szrj    *  @param __lhs  C string.
248838fd1498Szrj    *  @param __rhs  String.
248938fd1498Szrj    *  @return  True if @a __lhs follows @a __rhs.  False otherwise.
249038fd1498Szrj    */
249138fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
249238fd1498Szrj 	   template <typename, typename, typename> class _Base>
249338fd1498Szrj     inline bool
249438fd1498Szrj     operator>(const _CharT* __lhs,
249538fd1498Szrj 	      const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
249638fd1498Szrj     { return __rhs.compare(__lhs) < 0; }
249738fd1498Szrj 
249838fd1498Szrj   // operator <=
249938fd1498Szrj   /**
250038fd1498Szrj    *  @brief  Test if string doesn't follow string.
250138fd1498Szrj    *  @param __lhs  First string.
250238fd1498Szrj    *  @param __rhs  Second string.
250338fd1498Szrj    *  @return  True if @a __lhs doesn't follow @a __rhs.  False otherwise.
250438fd1498Szrj    */
250538fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
250638fd1498Szrj 	   template <typename, typename, typename> class _Base>
250738fd1498Szrj     inline bool
250838fd1498Szrj     operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
250938fd1498Szrj 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
251038fd1498Szrj     { return __lhs.compare(__rhs) <= 0; }
251138fd1498Szrj 
251238fd1498Szrj   /**
251338fd1498Szrj    *  @brief  Test if string doesn't follow C string.
251438fd1498Szrj    *  @param __lhs  String.
251538fd1498Szrj    *  @param __rhs  C string.
251638fd1498Szrj    *  @return  True if @a __lhs doesn't follow @a __rhs.  False otherwise.
251738fd1498Szrj    */
251838fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
251938fd1498Szrj 	   template <typename, typename, typename> class _Base>
252038fd1498Szrj     inline bool
252138fd1498Szrj     operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
252238fd1498Szrj 	       const _CharT* __rhs)
252338fd1498Szrj     { return __lhs.compare(__rhs) <= 0; }
252438fd1498Szrj 
252538fd1498Szrj   /**
252638fd1498Szrj    *  @brief  Test if C string doesn't follow string.
252738fd1498Szrj    *  @param __lhs  C string.
252838fd1498Szrj    *  @param __rhs  String.
252938fd1498Szrj    *  @return  True if @a __lhs doesn't follow @a __rhs.  False otherwise.
253038fd1498Szrj    */
253138fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
253238fd1498Szrj 	   template <typename, typename, typename> class _Base>
253338fd1498Szrj     inline bool
253438fd1498Szrj     operator<=(const _CharT* __lhs,
253538fd1498Szrj 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
253638fd1498Szrj     { return __rhs.compare(__lhs) >= 0; }
253738fd1498Szrj 
253838fd1498Szrj   // operator >=
253938fd1498Szrj   /**
254038fd1498Szrj    *  @brief  Test if string doesn't precede string.
254138fd1498Szrj    *  @param __lhs  First string.
254238fd1498Szrj    *  @param __rhs  Second string.
254338fd1498Szrj    *  @return  True if @a __lhs doesn't precede @a __rhs.  False otherwise.
254438fd1498Szrj    */
254538fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
254638fd1498Szrj 	   template <typename, typename, typename> class _Base>
254738fd1498Szrj     inline bool
254838fd1498Szrj     operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
254938fd1498Szrj 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
255038fd1498Szrj     { return __lhs.compare(__rhs) >= 0; }
255138fd1498Szrj 
255238fd1498Szrj   /**
255338fd1498Szrj    *  @brief  Test if string doesn't precede C string.
255438fd1498Szrj    *  @param __lhs  String.
255538fd1498Szrj    *  @param __rhs  C string.
255638fd1498Szrj    *  @return  True if @a __lhs doesn't precede @a __rhs.  False otherwise.
255738fd1498Szrj    */
255838fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
255938fd1498Szrj 	   template <typename, typename, typename> class _Base>
256038fd1498Szrj     inline bool
256138fd1498Szrj     operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
256238fd1498Szrj 	       const _CharT* __rhs)
256338fd1498Szrj     { return __lhs.compare(__rhs) >= 0; }
256438fd1498Szrj 
256538fd1498Szrj   /**
256638fd1498Szrj    *  @brief  Test if C string doesn't precede string.
256738fd1498Szrj    *  @param __lhs  C string.
256838fd1498Szrj    *  @param __rhs  String.
256938fd1498Szrj    *  @return  True if @a __lhs doesn't precede @a __rhs.  False otherwise.
257038fd1498Szrj    */
257138fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
257238fd1498Szrj 	   template <typename, typename, typename> class _Base>
257338fd1498Szrj     inline bool
257438fd1498Szrj     operator>=(const _CharT* __lhs,
257538fd1498Szrj 	       const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
257638fd1498Szrj     { return __rhs.compare(__lhs) <= 0; }
257738fd1498Szrj 
257838fd1498Szrj   /**
257938fd1498Szrj    *  @brief  Swap contents of two strings.
258038fd1498Szrj    *  @param __lhs  First string.
258138fd1498Szrj    *  @param __rhs  Second string.
258238fd1498Szrj    *
258338fd1498Szrj    *  Exchanges the contents of @a __lhs and @a __rhs in constant time.
258438fd1498Szrj    */
258538fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
258638fd1498Szrj 	   template <typename, typename, typename> class _Base>
258738fd1498Szrj     inline void
258838fd1498Szrj     swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
258938fd1498Szrj 	 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
259038fd1498Szrj     { __lhs.swap(__rhs); }
259138fd1498Szrj 
259238fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
259338fd1498Szrj } // namespace
259438fd1498Szrj 
_GLIBCXX_VISIBILITY(default)259538fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default)
259638fd1498Szrj {
259738fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
259838fd1498Szrj 
259938fd1498Szrj   /**
260038fd1498Szrj    *  @brief  Read stream into a string.
260138fd1498Szrj    *  @param __is  Input stream.
260238fd1498Szrj    *  @param __str  Buffer to store into.
260338fd1498Szrj    *  @return  Reference to the input stream.
260438fd1498Szrj    *
260538fd1498Szrj    *  Stores characters from @a __is into @a __str until whitespace is
260638fd1498Szrj    *  found, the end of the stream is encountered, or str.max_size()
260738fd1498Szrj    *  is reached.  If is.width() is non-zero, that is the limit on the
260838fd1498Szrj    *  number of characters stored into @a __str.  Any previous
260938fd1498Szrj    *  contents of @a __str are erased.
261038fd1498Szrj    */
261138fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
261238fd1498Szrj            template <typename, typename, typename> class _Base>
261338fd1498Szrj     basic_istream<_CharT, _Traits>&
261438fd1498Szrj     operator>>(basic_istream<_CharT, _Traits>& __is,
261538fd1498Szrj 	       __gnu_cxx::__versa_string<_CharT, _Traits,
261638fd1498Szrj 	                                 _Alloc, _Base>& __str);
261738fd1498Szrj 
261838fd1498Szrj   /**
261938fd1498Szrj    *  @brief  Write string to a stream.
262038fd1498Szrj    *  @param __os  Output stream.
262138fd1498Szrj    *  @param __str  String to write out.
262238fd1498Szrj    *  @return  Reference to the output stream.
262338fd1498Szrj    *
262438fd1498Szrj    *  Output characters of @a __str into os following the same rules as for
262538fd1498Szrj    *  writing a C string.
262638fd1498Szrj    */
262738fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
262838fd1498Szrj 	   template <typename, typename, typename> class _Base>
262938fd1498Szrj     inline basic_ostream<_CharT, _Traits>&
263038fd1498Szrj     operator<<(basic_ostream<_CharT, _Traits>& __os,
263138fd1498Szrj 	       const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc,
263238fd1498Szrj 	       _Base>& __str)
263338fd1498Szrj     {
263438fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
263538fd1498Szrj       // 586. string inserter not a formatted function
263638fd1498Szrj       return __ostream_insert(__os, __str.data(), __str.size());
263738fd1498Szrj     }
263838fd1498Szrj 
263938fd1498Szrj   /**
264038fd1498Szrj    *  @brief  Read a line from stream into a string.
264138fd1498Szrj    *  @param __is  Input stream.
264238fd1498Szrj    *  @param __str  Buffer to store into.
264338fd1498Szrj    *  @param __delim  Character marking end of line.
264438fd1498Szrj    *  @return  Reference to the input stream.
264538fd1498Szrj    *
264638fd1498Szrj    *  Stores characters from @a __is into @a __str until @a __delim is
264738fd1498Szrj    *  found, the end of the stream is encountered, or str.max_size()
264838fd1498Szrj    *  is reached.  If is.width() is non-zero, that is the limit on the
264938fd1498Szrj    *  number of characters stored into @a __str.  Any previous
265038fd1498Szrj    *  contents of @a __str are erased.  If @a delim was encountered,
265138fd1498Szrj    *  it is extracted but not stored into @a __str.
265238fd1498Szrj    */
265338fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
265438fd1498Szrj            template <typename, typename, typename> class _Base>
265538fd1498Szrj     basic_istream<_CharT, _Traits>&
265638fd1498Szrj     getline(basic_istream<_CharT, _Traits>& __is,
265738fd1498Szrj 	    __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
265838fd1498Szrj 	    _CharT __delim);
265938fd1498Szrj 
266038fd1498Szrj   /**
266138fd1498Szrj    *  @brief  Read a line from stream into a string.
266238fd1498Szrj    *  @param __is  Input stream.
266338fd1498Szrj    *  @param __str  Buffer to store into.
266438fd1498Szrj    *  @return  Reference to the input stream.
266538fd1498Szrj    *
266638fd1498Szrj    *  Stores characters from is into @a __str until &apos;\n&apos; is
266738fd1498Szrj    *  found, the end of the stream is encountered, or str.max_size()
266838fd1498Szrj    *  is reached.  If is.width() is non-zero, that is the limit on the
266938fd1498Szrj    *  number of characters stored into @a __str.  Any previous
267038fd1498Szrj    *  contents of @a __str are erased.  If end of line was
267138fd1498Szrj    *  encountered, it is extracted but not stored into @a __str.
267238fd1498Szrj    */
267338fd1498Szrj   template<typename _CharT, typename _Traits, typename _Alloc,
267438fd1498Szrj            template <typename, typename, typename> class _Base>
267538fd1498Szrj     inline basic_istream<_CharT, _Traits>&
267638fd1498Szrj     getline(basic_istream<_CharT, _Traits>& __is,
267738fd1498Szrj 	    __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
267838fd1498Szrj     { return getline(__is, __str, __is.widen('\n')); }
267938fd1498Szrj 
268038fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
268138fd1498Szrj } // namespace
268238fd1498Szrj 
268338fd1498Szrj #if __cplusplus >= 201103L
268438fd1498Szrj 
268538fd1498Szrj #include <ext/string_conversions.h>
268638fd1498Szrj 
_GLIBCXX_VISIBILITY(default)268738fd1498Szrj namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
268838fd1498Szrj {
268938fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
269038fd1498Szrj 
269138fd1498Szrj #if _GLIBCXX_USE_C99_STDLIB
269238fd1498Szrj   // 21.4 Numeric Conversions [string.conversions].
269338fd1498Szrj   inline int
269438fd1498Szrj   stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
269538fd1498Szrj   { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
269638fd1498Szrj 					__idx, __base); }
269738fd1498Szrj 
269838fd1498Szrj   inline long
269938fd1498Szrj   stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
270038fd1498Szrj   { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
270138fd1498Szrj 			     __idx, __base); }
270238fd1498Szrj 
270338fd1498Szrj   inline unsigned long
270438fd1498Szrj   stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
270538fd1498Szrj   { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
270638fd1498Szrj 			     __idx, __base); }
270738fd1498Szrj 
270838fd1498Szrj   inline long long
270938fd1498Szrj   stoll(const __vstring& __str, std::size_t* __idx = 0,	int __base = 10)
271038fd1498Szrj   { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
271138fd1498Szrj 			     __idx, __base); }
271238fd1498Szrj 
271338fd1498Szrj   inline unsigned long long
271438fd1498Szrj   stoull(const __vstring& __str, std::size_t* __idx, int __base = 10)
271538fd1498Szrj   { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
271638fd1498Szrj 			     __idx, __base); }
271738fd1498Szrj 
271838fd1498Szrj   // NB: strtof vs strtod.
271938fd1498Szrj   inline float
272038fd1498Szrj   stof(const __vstring& __str, std::size_t* __idx = 0)
272138fd1498Szrj   { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
272238fd1498Szrj 
272338fd1498Szrj   inline double
272438fd1498Szrj   stod(const __vstring& __str, std::size_t* __idx = 0)
272538fd1498Szrj   { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
272638fd1498Szrj 
272738fd1498Szrj   inline long double
272838fd1498Szrj   stold(const __vstring& __str, std::size_t* __idx = 0)
272938fd1498Szrj   { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
273038fd1498Szrj #endif // _GLIBCXX_USE_C99_STDLIB
273138fd1498Szrj 
273238fd1498Szrj #if _GLIBCXX_USE_C99_STDIO
273338fd1498Szrj   // NB: (v)snprintf vs sprintf.
273438fd1498Szrj 
273538fd1498Szrj   // DR 1261.
273638fd1498Szrj   inline __vstring
273738fd1498Szrj   to_string(int __val)
273838fd1498Szrj   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
273938fd1498Szrj 					      "%d", __val); }
274038fd1498Szrj 
274138fd1498Szrj   inline __vstring
274238fd1498Szrj   to_string(unsigned __val)
274338fd1498Szrj   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
274438fd1498Szrj 					      4 * sizeof(unsigned),
274538fd1498Szrj 					      "%u", __val); }
274638fd1498Szrj 
274738fd1498Szrj   inline __vstring
274838fd1498Szrj   to_string(long __val)
274938fd1498Szrj   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
275038fd1498Szrj 					      4 * sizeof(long),
275138fd1498Szrj 					      "%ld", __val); }
275238fd1498Szrj 
275338fd1498Szrj   inline __vstring
275438fd1498Szrj   to_string(unsigned long __val)
275538fd1498Szrj   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
275638fd1498Szrj 					      4 * sizeof(unsigned long),
275738fd1498Szrj 					      "%lu", __val); }
275838fd1498Szrj 
275938fd1498Szrj 
276038fd1498Szrj   inline __vstring
276138fd1498Szrj   to_string(long long __val)
276238fd1498Szrj   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
276338fd1498Szrj 					      4 * sizeof(long long),
276438fd1498Szrj 					      "%lld", __val); }
276538fd1498Szrj 
276638fd1498Szrj   inline __vstring
276738fd1498Szrj   to_string(unsigned long long __val)
276838fd1498Szrj   { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
276938fd1498Szrj 					      4 * sizeof(unsigned long long),
277038fd1498Szrj 					      "%llu", __val); }
277138fd1498Szrj 
277238fd1498Szrj   inline __vstring
277338fd1498Szrj   to_string(float __val)
277438fd1498Szrj   {
277538fd1498Szrj     const int __n = __numeric_traits<float>::__max_exponent10 + 20;
277638fd1498Szrj     return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
277738fd1498Szrj 					      "%f", __val);
277838fd1498Szrj   }
277938fd1498Szrj 
278038fd1498Szrj   inline __vstring
278138fd1498Szrj   to_string(double __val)
278238fd1498Szrj   {
278338fd1498Szrj     const int __n = __numeric_traits<double>::__max_exponent10 + 20;
278438fd1498Szrj     return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
278538fd1498Szrj 					      "%f", __val);
278638fd1498Szrj   }
278738fd1498Szrj 
278838fd1498Szrj   inline __vstring
278938fd1498Szrj   to_string(long double __val)
279038fd1498Szrj   {
279138fd1498Szrj     const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
279238fd1498Szrj     return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
279338fd1498Szrj 					      "%Lf", __val);
279438fd1498Szrj   }
279538fd1498Szrj #endif // _GLIBCXX_USE_C99_STDIO
279638fd1498Szrj 
279738fd1498Szrj #if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR
279838fd1498Szrj   inline int
279938fd1498Szrj   stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
280038fd1498Szrj   { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
280138fd1498Szrj 					__idx, __base); }
280238fd1498Szrj 
280338fd1498Szrj   inline long
280438fd1498Szrj   stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
280538fd1498Szrj   { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
280638fd1498Szrj 			     __idx, __base); }
280738fd1498Szrj 
280838fd1498Szrj   inline unsigned long
280938fd1498Szrj   stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
281038fd1498Szrj   { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
281138fd1498Szrj 			     __idx, __base); }
281238fd1498Szrj 
281338fd1498Szrj   inline long long
281438fd1498Szrj   stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
281538fd1498Szrj   { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
281638fd1498Szrj 			     __idx, __base); }
281738fd1498Szrj 
281838fd1498Szrj   inline unsigned long long
281938fd1498Szrj   stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
282038fd1498Szrj   { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
282138fd1498Szrj 			     __idx, __base); }
282238fd1498Szrj 
282338fd1498Szrj   // NB: wcstof vs wcstod.
282438fd1498Szrj   inline float
282538fd1498Szrj   stof(const __wvstring& __str, std::size_t* __idx = 0)
282638fd1498Szrj   { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
282738fd1498Szrj 
282838fd1498Szrj   inline double
282938fd1498Szrj   stod(const __wvstring& __str, std::size_t* __idx = 0)
283038fd1498Szrj   { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
283138fd1498Szrj 
283238fd1498Szrj   inline long double
283338fd1498Szrj   stold(const __wvstring& __str, std::size_t* __idx = 0)
283438fd1498Szrj   { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
283538fd1498Szrj 
283638fd1498Szrj #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
283738fd1498Szrj   // DR 1261.
283838fd1498Szrj   inline __wvstring
283938fd1498Szrj   to_wstring(int __val)
284038fd1498Szrj   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
284138fd1498Szrj 					       4 * sizeof(int),
284238fd1498Szrj 					       L"%d", __val); }
284338fd1498Szrj 
284438fd1498Szrj   inline __wvstring
284538fd1498Szrj   to_wstring(unsigned __val)
284638fd1498Szrj   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
284738fd1498Szrj 					       4 * sizeof(unsigned),
284838fd1498Szrj 					       L"%u", __val); }
284938fd1498Szrj 
285038fd1498Szrj   inline __wvstring
285138fd1498Szrj   to_wstring(long __val)
285238fd1498Szrj   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
285338fd1498Szrj 					       4 * sizeof(long),
285438fd1498Szrj 					       L"%ld", __val); }
285538fd1498Szrj 
285638fd1498Szrj   inline __wvstring
285738fd1498Szrj   to_wstring(unsigned long __val)
285838fd1498Szrj   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
285938fd1498Szrj 					       4 * sizeof(unsigned long),
286038fd1498Szrj 					       L"%lu", __val); }
286138fd1498Szrj 
286238fd1498Szrj   inline __wvstring
286338fd1498Szrj   to_wstring(long long __val)
286438fd1498Szrj   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
286538fd1498Szrj 					       4 * sizeof(long long),
286638fd1498Szrj 					       L"%lld", __val); }
286738fd1498Szrj 
286838fd1498Szrj   inline __wvstring
286938fd1498Szrj   to_wstring(unsigned long long __val)
287038fd1498Szrj   { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
287138fd1498Szrj 					       4 * sizeof(unsigned long long),
287238fd1498Szrj 					       L"%llu", __val); }
287338fd1498Szrj 
287438fd1498Szrj   inline __wvstring
287538fd1498Szrj   to_wstring(float __val)
287638fd1498Szrj   {
287738fd1498Szrj     const int __n = __numeric_traits<float>::__max_exponent10 + 20;
287838fd1498Szrj     return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
287938fd1498Szrj 					       L"%f", __val);
288038fd1498Szrj   }
288138fd1498Szrj 
288238fd1498Szrj   inline __wvstring
288338fd1498Szrj   to_wstring(double __val)
288438fd1498Szrj   {
288538fd1498Szrj     const int __n = __numeric_traits<double>::__max_exponent10 + 20;
288638fd1498Szrj     return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
288738fd1498Szrj 					       L"%f", __val);
288838fd1498Szrj   }
288938fd1498Szrj 
289038fd1498Szrj   inline __wvstring
289138fd1498Szrj   to_wstring(long double __val)
289238fd1498Szrj   {
289338fd1498Szrj     const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
289438fd1498Szrj     return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
289538fd1498Szrj 					       L"%Lf", __val);
289638fd1498Szrj   }
289738fd1498Szrj #endif // _GLIBCXX_HAVE_BROKEN_VSWPRINTF
289838fd1498Szrj #endif // _GLIBCXX_USE_WCHAR_T && _GLIBCXX_USE_C99_WCHAR
289938fd1498Szrj 
290038fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
290138fd1498Szrj } // namespace
290238fd1498Szrj 
290338fd1498Szrj #endif
290438fd1498Szrj 
290538fd1498Szrj #if __cplusplus >= 201103L
290638fd1498Szrj 
290738fd1498Szrj #include <bits/functional_hash.h>
290838fd1498Szrj 
_GLIBCXX_VISIBILITY(default)290938fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default)
291038fd1498Szrj {
291138fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
291238fd1498Szrj 
291338fd1498Szrj   /// std::hash specialization for __vstring.
291438fd1498Szrj   template<>
291538fd1498Szrj     struct hash<__gnu_cxx::__vstring>
291638fd1498Szrj     : public __hash_base<size_t, __gnu_cxx::__vstring>
291738fd1498Szrj     {
291838fd1498Szrj       size_t
291938fd1498Szrj       operator()(const __gnu_cxx::__vstring& __s) const noexcept
292038fd1498Szrj       { return std::_Hash_impl::hash(__s.data(), __s.length()); }
292138fd1498Szrj     };
292238fd1498Szrj 
292338fd1498Szrj #ifdef _GLIBCXX_USE_WCHAR_T
292438fd1498Szrj   /// std::hash specialization for __wvstring.
292538fd1498Szrj   template<>
292638fd1498Szrj     struct hash<__gnu_cxx::__wvstring>
292738fd1498Szrj     : public __hash_base<size_t, __gnu_cxx::__wvstring>
292838fd1498Szrj     {
292938fd1498Szrj       size_t
293038fd1498Szrj       operator()(const __gnu_cxx::__wvstring& __s) const noexcept
293138fd1498Szrj       { return std::_Hash_impl::hash(__s.data(),
293238fd1498Szrj                                      __s.length() * sizeof(wchar_t)); }
293338fd1498Szrj     };
293438fd1498Szrj #endif
293538fd1498Szrj 
293638fd1498Szrj #ifdef _GLIBCXX_USE_C99_STDINT_TR1
293738fd1498Szrj   /// std::hash specialization for __u16vstring.
293838fd1498Szrj   template<>
293938fd1498Szrj     struct hash<__gnu_cxx::__u16vstring>
294038fd1498Szrj     : public __hash_base<size_t, __gnu_cxx::__u16vstring>
294138fd1498Szrj     {
294238fd1498Szrj       size_t
294338fd1498Szrj       operator()(const __gnu_cxx::__u16vstring& __s) const noexcept
294438fd1498Szrj       { return std::_Hash_impl::hash(__s.data(),
294538fd1498Szrj                                      __s.length() * sizeof(char16_t)); }
294638fd1498Szrj     };
294738fd1498Szrj 
294838fd1498Szrj   /// std::hash specialization for __u32vstring.
294938fd1498Szrj   template<>
295038fd1498Szrj     struct hash<__gnu_cxx::__u32vstring>
295138fd1498Szrj     : public __hash_base<size_t, __gnu_cxx::__u32vstring>
295238fd1498Szrj     {
295338fd1498Szrj       size_t
295438fd1498Szrj       operator()(const __gnu_cxx::__u32vstring& __s) const noexcept
295538fd1498Szrj       { return std::_Hash_impl::hash(__s.data(),
295638fd1498Szrj                                      __s.length() * sizeof(char32_t)); }
295738fd1498Szrj     };
295838fd1498Szrj #endif
295938fd1498Szrj 
296038fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
296138fd1498Szrj } // namespace
296238fd1498Szrj 
296338fd1498Szrj #endif // C++11
296438fd1498Szrj 
2965*58e805e6Szrj #include <ext/vstring.tcc>
296638fd1498Szrj 
296738fd1498Szrj #endif /* _VSTRING_H */
2968