blob: 786735f970f8ee7a24f4d8f1497cf67c8e64d766 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- string -----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_STRING
12#define _LIBCPP_STRING
13
14/*
15 string synopsis
16
17namespace std
18{
19
20template <class stateT>
21class fpos
22{
23private:
24 stateT st;
25public:
26 fpos(streamoff = streamoff());
27
28 operator streamoff() const;
29
30 stateT state() const;
31 void state(stateT);
32
33 fpos& operator+=(streamoff);
34 fpos operator+ (streamoff) const;
35 fpos& operator-=(streamoff);
36 fpos operator- (streamoff) const;
37};
38
39template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
40
41template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
42template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
43
44template <class charT>
45struct char_traits
46{
47 typedef charT char_type;
48 typedef ... int_type;
49 typedef streamoff off_type;
50 typedef streampos pos_type;
51 typedef mbstate_t state_type;
52
Howard Hinnanta6119a82011-05-29 19:57:12 +000053 static void assign(char_type& c1, const char_type& c2) noexcept;
Howard Hinnant03d71812012-07-20 19:09:12 +000054 static constexpr bool eq(char_type c1, char_type c2) noexcept;
55 static constexpr bool lt(char_type c1, char_type c2) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056
57 static int compare(const char_type* s1, const char_type* s2, size_t n);
58 static size_t length(const char_type* s);
59 static const char_type* find(const char_type* s, size_t n, const char_type& a);
60 static char_type* move(char_type* s1, const char_type* s2, size_t n);
61 static char_type* copy(char_type* s1, const char_type* s2, size_t n);
62 static char_type* assign(char_type* s, size_t n, char_type a);
63
Howard Hinnant03d71812012-07-20 19:09:12 +000064 static constexpr int_type not_eof(int_type c) noexcept;
65 static constexpr char_type to_char_type(int_type c) noexcept;
66 static constexpr int_type to_int_type(char_type c) noexcept;
67 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
68 static constexpr int_type eof() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000069};
70
71template <> struct char_traits<char>;
72template <> struct char_traits<wchar_t>;
73
Howard Hinnant324bb032010-08-22 00:02:43 +000074template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000075class basic_string
76{
Howard Hinnant324bb032010-08-22 00:02:43 +000077public:
78// types:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000079 typedef traits traits_type;
80 typedef typename traits_type::char_type value_type;
81 typedef Allocator allocator_type;
82 typedef typename allocator_type::size_type size_type;
83 typedef typename allocator_type::difference_type difference_type;
84 typedef typename allocator_type::reference reference;
85 typedef typename allocator_type::const_reference const_reference;
86 typedef typename allocator_type::pointer pointer;
87 typedef typename allocator_type::const_pointer const_pointer;
88 typedef implementation-defined iterator;
89 typedef implementation-defined const_iterator;
90 typedef std::reverse_iterator<iterator> reverse_iterator;
91 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
92
93 static const size_type npos = -1;
94
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000095 basic_string()
96 noexcept(is_nothrow_default_constructible<allocator_type>::value);
97 explicit basic_string(const allocator_type& a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000098 basic_string(const basic_string& str);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000099 basic_string(basic_string&& str)
100 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000101 basic_string(const basic_string& str, size_type pos,
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000102 const allocator_type& a = allocator_type());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000103 basic_string(const basic_string& str, size_type pos, size_type n,
104 const Allocator& a = Allocator());
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000105 basic_string(const value_type* s, const allocator_type& a = allocator_type());
106 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000107 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
108 template<class InputIterator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000109 basic_string(InputIterator begin, InputIterator end,
110 const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000111 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
112 basic_string(const basic_string&, const Allocator&);
113 basic_string(basic_string&&, const Allocator&);
114
115 ~basic_string();
116
117 basic_string& operator=(const basic_string& str);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000118 basic_string& operator=(basic_string&& str)
119 noexcept(
Marshall Clowaf961ed2015-08-18 18:57:00 +0000120 allocator_type::propagate_on_container_move_assignment::value ||
121 allocator_type::is_always_equal::value ); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000122 basic_string& operator=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000123 basic_string& operator=(value_type c);
124 basic_string& operator=(initializer_list<value_type>);
125
Howard Hinnanta6119a82011-05-29 19:57:12 +0000126 iterator begin() noexcept;
127 const_iterator begin() const noexcept;
128 iterator end() noexcept;
129 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000130
Howard Hinnanta6119a82011-05-29 19:57:12 +0000131 reverse_iterator rbegin() noexcept;
132 const_reverse_iterator rbegin() const noexcept;
133 reverse_iterator rend() noexcept;
134 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000135
Howard Hinnanta6119a82011-05-29 19:57:12 +0000136 const_iterator cbegin() const noexcept;
137 const_iterator cend() const noexcept;
138 const_reverse_iterator crbegin() const noexcept;
139 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000140
Howard Hinnanta6119a82011-05-29 19:57:12 +0000141 size_type size() const noexcept;
142 size_type length() const noexcept;
143 size_type max_size() const noexcept;
144 size_type capacity() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000145
146 void resize(size_type n, value_type c);
147 void resize(size_type n);
148
149 void reserve(size_type res_arg = 0);
150 void shrink_to_fit();
Howard Hinnanta6119a82011-05-29 19:57:12 +0000151 void clear() noexcept;
152 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000153
154 const_reference operator[](size_type pos) const;
155 reference operator[](size_type pos);
156
157 const_reference at(size_type n) const;
158 reference at(size_type n);
159
160 basic_string& operator+=(const basic_string& str);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000161 basic_string& operator+=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000162 basic_string& operator+=(value_type c);
163 basic_string& operator+=(initializer_list<value_type>);
164
165 basic_string& append(const basic_string& str);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000166 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000167 basic_string& append(const value_type* s, size_type n);
168 basic_string& append(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000169 basic_string& append(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000170 template<class InputIterator>
171 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000172 basic_string& append(initializer_list<value_type>);
173
174 void push_back(value_type c);
175 void pop_back();
176 reference front();
177 const_reference front() const;
178 reference back();
179 const_reference back() const;
180
181 basic_string& assign(const basic_string& str);
Howard Hinnanta6119a82011-05-29 19:57:12 +0000182 basic_string& assign(basic_string&& str);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000183 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000184 basic_string& assign(const value_type* s, size_type n);
185 basic_string& assign(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000186 basic_string& assign(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000187 template<class InputIterator>
188 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000189 basic_string& assign(initializer_list<value_type>);
190
191 basic_string& insert(size_type pos1, const basic_string& str);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000192 basic_string& insert(size_type pos1, const basic_string& str,
193 size_type pos2, size_type n);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000194 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000195 basic_string& insert(size_type pos, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000196 basic_string& insert(size_type pos, size_type n, value_type c);
197 iterator insert(const_iterator p, value_type c);
198 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000199 template<class InputIterator>
200 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000201 iterator insert(const_iterator p, initializer_list<value_type>);
202
203 basic_string& erase(size_type pos = 0, size_type n = npos);
204 iterator erase(const_iterator position);
205 iterator erase(const_iterator first, const_iterator last);
206
207 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000208 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000209 size_type pos2, size_type n2=npos); // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000210 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
211 basic_string& replace(size_type pos, size_type n1, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000212 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000213 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000214 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
215 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000216 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000217 template<class InputIterator>
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000218 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
219 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000220
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000221 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000222 basic_string substr(size_type pos = 0, size_type n = npos) const;
223
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000224 void swap(basic_string& str)
Marshall Clow7d914d12015-07-13 20:04:56 +0000225 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
226 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000227
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000228 const value_type* c_str() const noexcept;
229 const value_type* data() const noexcept;
Marshall Clowf532a702016-03-08 15:44:30 +0000230 value_type* data() noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000231
Howard Hinnanta6119a82011-05-29 19:57:12 +0000232 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000233
Howard Hinnanta6119a82011-05-29 19:57:12 +0000234 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000235 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
236 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000237 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000238
Howard Hinnanta6119a82011-05-29 19:57:12 +0000239 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000240 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
241 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000242 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000243
Howard Hinnanta6119a82011-05-29 19:57:12 +0000244 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000245 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
246 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000247 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000248
Howard Hinnanta6119a82011-05-29 19:57:12 +0000249 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000250 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
251 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000252 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000253
Howard Hinnanta6119a82011-05-29 19:57:12 +0000254 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000255 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
256 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000257 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258
Howard Hinnanta6119a82011-05-29 19:57:12 +0000259 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000260 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
261 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000262 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000263
Howard Hinnanta6119a82011-05-29 19:57:12 +0000264 int compare(const basic_string& str) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000265 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000266 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000267 size_type pos2, size_type n2=npos) const; // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000268 int compare(const value_type* s) const noexcept;
269 int compare(size_type pos1, size_type n1, const value_type* s) const;
270 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000271
272 bool __invariants() const;
273};
274
275template<class charT, class traits, class Allocator>
276basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000277operator+(const basic_string<charT, traits, Allocator>& lhs,
278 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000279
280template<class charT, class traits, class Allocator>
281basic_string<charT, traits, Allocator>
282operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
283
284template<class charT, class traits, class Allocator>
285basic_string<charT, traits, Allocator>
286operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
287
288template<class charT, class traits, class Allocator>
289basic_string<charT, traits, Allocator>
290operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
291
292template<class charT, class traits, class Allocator>
293basic_string<charT, traits, Allocator>
294operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
295
296template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000297bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000298 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000299
300template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000301bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000302
303template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000304bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305
Howard Hinnant324bb032010-08-22 00:02:43 +0000306template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000307bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000308 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000309
310template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000311bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000312
313template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000314bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000315
316template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000317bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000318 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000319
320template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000321bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000322
323template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000324bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000325
326template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000327bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000328 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000329
330template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000331bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000332
333template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000334bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000335
336template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000337bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000338 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000339
340template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000341bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000342
343template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000344bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345
346template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000347bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000348 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000349
350template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000351bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000352
353template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000354bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355
356template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000357void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000358 basic_string<charT, traits, Allocator>& rhs)
359 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000360
361template<class charT, class traits, class Allocator>
362basic_istream<charT, traits>&
363operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
364
365template<class charT, class traits, class Allocator>
366basic_ostream<charT, traits>&
367operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
368
369template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000370basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000371getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
372 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000373
374template<class charT, class traits, class Allocator>
375basic_istream<charT, traits>&
376getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
377
378typedef basic_string<char> string;
379typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000380typedef basic_string<char16_t> u16string;
381typedef basic_string<char32_t> u32string;
382
383int stoi (const string& str, size_t* idx = 0, int base = 10);
384long stol (const string& str, size_t* idx = 0, int base = 10);
385unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
386long long stoll (const string& str, size_t* idx = 0, int base = 10);
387unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
388
389float stof (const string& str, size_t* idx = 0);
390double stod (const string& str, size_t* idx = 0);
391long double stold(const string& str, size_t* idx = 0);
392
393string to_string(int val);
394string to_string(unsigned val);
395string to_string(long val);
396string to_string(unsigned long val);
397string to_string(long long val);
398string to_string(unsigned long long val);
399string to_string(float val);
400string to_string(double val);
401string to_string(long double val);
402
403int stoi (const wstring& str, size_t* idx = 0, int base = 10);
404long stol (const wstring& str, size_t* idx = 0, int base = 10);
405unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
406long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
407unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
408
409float stof (const wstring& str, size_t* idx = 0);
410double stod (const wstring& str, size_t* idx = 0);
411long double stold(const wstring& str, size_t* idx = 0);
412
413wstring to_wstring(int val);
414wstring to_wstring(unsigned val);
415wstring to_wstring(long val);
416wstring to_wstring(unsigned long val);
417wstring to_wstring(long long val);
418wstring to_wstring(unsigned long long val);
419wstring to_wstring(float val);
420wstring to_wstring(double val);
421wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422
423template <> struct hash<string>;
424template <> struct hash<u16string>;
425template <> struct hash<u32string>;
426template <> struct hash<wstring>;
427
Marshall Clow15234322013-07-23 17:05:24 +0000428basic_string<char> operator "" s( const char *str, size_t len ); // C++14
429basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
430basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
431basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
432
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433} // std
434
435*/
436
437#include <__config>
438#include <iosfwd>
439#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000440#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000441#include <cwchar>
442#include <algorithm>
443#include <iterator>
444#include <utility>
445#include <memory>
446#include <stdexcept>
447#include <type_traits>
448#include <initializer_list>
449#include <__functional_base>
450#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
451#include <cstdint>
452#endif
Howard Hinnant499cea12013-08-23 17:37:05 +0000453#if defined(_LIBCPP_NO_EXCEPTIONS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000454#include <cassert>
455#endif
456
Howard Hinnant66c6f972011-11-29 16:45:27 +0000457#include <__undef_min_max>
458
Eric Fiselierb9536102014-08-10 23:53:08 +0000459#include <__debug>
460
Howard Hinnant08e17472011-10-17 20:05:10 +0000461#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000463#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000464
465_LIBCPP_BEGIN_NAMESPACE_STD
466
467// fpos
468
469template <class _StateT>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000470class _LIBCPP_TYPE_VIS_ONLY fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000471{
472private:
473 _StateT __st_;
474 streamoff __off_;
475public:
476 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
477
478 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
479
480 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
481 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
482
483 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
484 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
485 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
486 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
487};
488
489template <class _StateT>
490inline _LIBCPP_INLINE_VISIBILITY
491streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
492 {return streamoff(__x) - streamoff(__y);}
493
494template <class _StateT>
495inline _LIBCPP_INLINE_VISIBILITY
496bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
497 {return streamoff(__x) == streamoff(__y);}
498
499template <class _StateT>
500inline _LIBCPP_INLINE_VISIBILITY
501bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
502 {return streamoff(__x) != streamoff(__y);}
503
504// char_traits
505
506template <class _CharT>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000507struct _LIBCPP_TYPE_VIS_ONLY char_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000508{
509 typedef _CharT char_type;
510 typedef int int_type;
511 typedef streamoff off_type;
512 typedef streampos pos_type;
513 typedef mbstate_t state_type;
514
Dan Albert6d9505a2014-09-17 16:34:29 +0000515 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000516 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000517 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000518 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000519 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000520 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521
522 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524 static size_t length(const char_type* __s);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000526 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
527 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000531 static char_type* assign(char_type* __s, size_t __n, char_type __a);
532
Dan Albert6d9505a2014-09-17 16:34:29 +0000533 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000535 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000536 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000537 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000538 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000539 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000541 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000542 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000543};
544
545template <class _CharT>
546int
547char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
548{
549 for (; __n; --__n, ++__s1, ++__s2)
550 {
551 if (lt(*__s1, *__s2))
552 return -1;
553 if (lt(*__s2, *__s1))
554 return 1;
555 }
556 return 0;
557}
558
559template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000560inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000561size_t
562char_traits<_CharT>::length(const char_type* __s)
563{
564 size_t __len = 0;
565 for (; !eq(*__s, char_type(0)); ++__s)
566 ++__len;
567 return __len;
568}
569
570template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000571inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572const _CharT*
573char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
574{
575 for (; __n; --__n)
576 {
577 if (eq(*__s, __a))
578 return __s;
579 ++__s;
580 }
581 return 0;
582}
583
584template <class _CharT>
585_CharT*
586char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
587{
588 char_type* __r = __s1;
589 if (__s1 < __s2)
590 {
591 for (; __n; --__n, ++__s1, ++__s2)
592 assign(*__s1, *__s2);
593 }
594 else if (__s2 < __s1)
595 {
596 __s1 += __n;
597 __s2 += __n;
598 for (; __n; --__n)
599 assign(*--__s1, *--__s2);
600 }
601 return __r;
602}
603
604template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000605inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606_CharT*
607char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
608{
Howard Hinnant499cea12013-08-23 17:37:05 +0000609 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000610 char_type* __r = __s1;
611 for (; __n; --__n, ++__s1, ++__s2)
612 assign(*__s1, *__s2);
613 return __r;
614}
615
616template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000617inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000618_CharT*
619char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
620{
621 char_type* __r = __s;
622 for (; __n; --__n, ++__s)
623 assign(*__s, __a);
624 return __r;
625}
626
627// char_traits<char>
628
629template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000630struct _LIBCPP_TYPE_VIS_ONLY char_traits<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000631{
632 typedef char char_type;
633 typedef int int_type;
634 typedef streamoff off_type;
635 typedef streampos pos_type;
636 typedef mbstate_t state_type;
637
Dan Albert6d9505a2014-09-17 16:34:29 +0000638 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000639 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000640 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000641 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000642 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643 {return (unsigned char)__c1 < (unsigned char)__c2;}
644
Dan Albert6d9505a2014-09-17 16:34:29 +0000645 static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clowf2e36ef2015-02-12 23:34:52 +0000646 {return __n == 0 ? 0 : memcmp(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000647 static inline size_t length(const char_type* __s) {return strlen(__s);}
648 static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000649 {return __n == 0 ? NULL : (const char_type*) memchr(__s, to_int_type(__a), __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000650 static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000651 {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000652 static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnant499cea12013-08-23 17:37:05 +0000653 {
654 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Marshall Clow6bcbced2015-02-13 16:04:42 +0000655 return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +0000656 }
Dan Albert6d9505a2014-09-17 16:34:29 +0000657 static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000658 {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659
Dan Albert6d9505a2014-09-17 16:34:29 +0000660 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000662 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000663 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000664 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000665 {return int_type((unsigned char)__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000666 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000668 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000669 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670};
671
672// char_traits<wchar_t>
673
674template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000675struct _LIBCPP_TYPE_VIS_ONLY char_traits<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676{
677 typedef wchar_t char_type;
678 typedef wint_t int_type;
679 typedef streamoff off_type;
680 typedef streampos pos_type;
681 typedef mbstate_t state_type;
682
Dan Albert6d9505a2014-09-17 16:34:29 +0000683 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000684 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000685 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000686 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000687 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000688 {return __c1 < __c2;}
689
Dan Albert6d9505a2014-09-17 16:34:29 +0000690 static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clowf2e36ef2015-02-12 23:34:52 +0000691 {return __n == 0 ? 0 : wmemcmp(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000692 static inline size_t length(const char_type* __s)
Howard Hinnanta6119a82011-05-29 19:57:12 +0000693 {return wcslen(__s);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000694 static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000695 {return __n == 0 ? NULL : (const char_type*)wmemchr(__s, __a, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000696 static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000697 {return __n == 0 ? __s1 : (char_type*)wmemmove(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000698 static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnant499cea12013-08-23 17:37:05 +0000699 {
700 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Marshall Clow6bcbced2015-02-13 16:04:42 +0000701 return __n == 0 ? __s1 : (char_type*)wmemcpy(__s1, __s2, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +0000702 }
Dan Albert6d9505a2014-09-17 16:34:29 +0000703 static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000704 {return __n == 0 ? __s : (char_type*)wmemset(__s, __a, __n);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705
Dan Albert6d9505a2014-09-17 16:34:29 +0000706 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000708 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000709 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000710 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000711 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000712 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000714 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000715 {return int_type(WEOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000716};
717
718#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
719
720template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000721struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000722{
723 typedef char16_t char_type;
724 typedef uint_least16_t int_type;
725 typedef streamoff off_type;
726 typedef u16streampos pos_type;
727 typedef mbstate_t state_type;
728
Dan Albert6d9505a2014-09-17 16:34:29 +0000729 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000730 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000731 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000732 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000733 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000734 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000735
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000737 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000738 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000739 static size_t length(const char_type* __s);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000740 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000741 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747 static char_type* assign(char_type* __s, size_t __n, char_type __a);
748
Dan Albert6d9505a2014-09-17 16:34:29 +0000749 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000750 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000751 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000752 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000753 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000754 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000755 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000756 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000757 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Marshall Clow9a3c6892015-08-04 01:38:34 +0000758 {return int_type(0xFFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000759};
760
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000761inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000762int
763char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
764{
765 for (; __n; --__n, ++__s1, ++__s2)
766 {
767 if (lt(*__s1, *__s2))
768 return -1;
769 if (lt(*__s2, *__s1))
770 return 1;
771 }
772 return 0;
773}
774
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000775inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000776size_t
777char_traits<char16_t>::length(const char_type* __s)
778{
779 size_t __len = 0;
780 for (; !eq(*__s, char_type(0)); ++__s)
781 ++__len;
782 return __len;
783}
784
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000785inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000786const char16_t*
787char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
788{
789 for (; __n; --__n)
790 {
791 if (eq(*__s, __a))
792 return __s;
793 ++__s;
794 }
795 return 0;
796}
797
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000798inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000799char16_t*
800char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
801{
802 char_type* __r = __s1;
803 if (__s1 < __s2)
804 {
805 for (; __n; --__n, ++__s1, ++__s2)
806 assign(*__s1, *__s2);
807 }
808 else if (__s2 < __s1)
809 {
810 __s1 += __n;
811 __s2 += __n;
812 for (; __n; --__n)
813 assign(*--__s1, *--__s2);
814 }
815 return __r;
816}
817
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000818inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819char16_t*
820char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
821{
Howard Hinnant499cea12013-08-23 17:37:05 +0000822 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000823 char_type* __r = __s1;
824 for (; __n; --__n, ++__s1, ++__s2)
825 assign(*__s1, *__s2);
826 return __r;
827}
828
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000829inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000830char16_t*
831char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
832{
833 char_type* __r = __s;
834 for (; __n; --__n, ++__s)
835 assign(*__s, __a);
836 return __r;
837}
838
839template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000840struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841{
842 typedef char32_t char_type;
843 typedef uint_least32_t int_type;
844 typedef streamoff off_type;
845 typedef u32streampos pos_type;
846 typedef mbstate_t state_type;
847
Dan Albert6d9505a2014-09-17 16:34:29 +0000848 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000849 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000850 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000851 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000852 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000853 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000854
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000855 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000856 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000858 static size_t length(const char_type* __s);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000859 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000860 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000864 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866 static char_type* assign(char_type* __s, size_t __n, char_type __a);
867
Dan Albert6d9505a2014-09-17 16:34:29 +0000868 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000869 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000870 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000871 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000872 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000873 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000874 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000876 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000877 {return int_type(0xFFFFFFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878};
879
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000880inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000881int
882char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
883{
884 for (; __n; --__n, ++__s1, ++__s2)
885 {
886 if (lt(*__s1, *__s2))
887 return -1;
888 if (lt(*__s2, *__s1))
889 return 1;
890 }
891 return 0;
892}
893
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000894inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000895size_t
896char_traits<char32_t>::length(const char_type* __s)
897{
898 size_t __len = 0;
899 for (; !eq(*__s, char_type(0)); ++__s)
900 ++__len;
901 return __len;
902}
903
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000904inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905const char32_t*
906char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
907{
908 for (; __n; --__n)
909 {
910 if (eq(*__s, __a))
911 return __s;
912 ++__s;
913 }
914 return 0;
915}
916
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000917inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000918char32_t*
919char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
920{
921 char_type* __r = __s1;
922 if (__s1 < __s2)
923 {
924 for (; __n; --__n, ++__s1, ++__s2)
925 assign(*__s1, *__s2);
926 }
927 else if (__s2 < __s1)
928 {
929 __s1 += __n;
930 __s2 += __n;
931 for (; __n; --__n)
932 assign(*--__s1, *--__s2);
933 }
934 return __r;
935}
936
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000937inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938char32_t*
939char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
940{
Howard Hinnant499cea12013-08-23 17:37:05 +0000941 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000942 char_type* __r = __s1;
943 for (; __n; --__n, ++__s1, ++__s2)
944 assign(*__s1, *__s2);
945 return __r;
946}
947
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000948inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000949char32_t*
950char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
951{
952 char_type* __r = __s;
953 for (; __n; --__n, ++__s)
954 assign(*__s, __a);
955 return __r;
956}
957
Howard Hinnant324bb032010-08-22 00:02:43 +0000958#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000959
Marshall Clowb671fc92013-12-09 16:00:28 +0000960// helper fns for basic_string
961
Marshall Clow37025e12014-06-10 18:51:55 +0000962// __str_find
Marshall Clowb671fc92013-12-09 16:00:28 +0000963template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Eric Fiselier566bcb42016-04-21 22:54:21 +0000964inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +0000965__str_find(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +0000966 _CharT __c, _SizeT __pos) _NOEXCEPT
967{
968 if (__pos >= __sz)
969 return __npos;
970 const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);
971 if (__r == 0)
972 return __npos;
973 return static_cast<_SizeT>(__r - __p);
974}
975
976template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Eric Fiselier566bcb42016-04-21 22:54:21 +0000977inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +0000978__str_find(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +0000979 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
980{
981 if (__pos > __sz || __sz - __pos < __n)
982 return __npos;
983 if (__n == 0)
984 return __pos;
Marshall Clow360f3192014-06-02 02:22:49 +0000985 const _CharT* __r =
Marshall Clow37025e12014-06-10 18:51:55 +0000986 _VSTD::__search(__p + __pos, __p + __sz,
987 __s, __s + __n, _Traits::eq,
Marshall Clowf6d6b512016-03-08 15:12:52 +0000988 random_access_iterator_tag(), random_access_iterator_tag()).first;
Marshall Clow360f3192014-06-02 02:22:49 +0000989 if (__r == __p + __sz)
990 return __npos;
991 return static_cast<_SizeT>(__r - __p);
992}
993
994
Marshall Clow37025e12014-06-10 18:51:55 +0000995// __str_rfind
Marshall Clow360f3192014-06-02 02:22:49 +0000996
997template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Eric Fiselier566bcb42016-04-21 22:54:21 +0000998inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +0000999__str_rfind(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001000 _CharT __c, _SizeT __pos) _NOEXCEPT
1001{
1002 if (__sz < 1)
Marshall Clowd5549cc2014-07-17 15:32:20 +00001003 return __npos;
1004 if (__pos < __sz)
1005 ++__pos;
1006 else
1007 __pos = __sz;
1008 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1009 {
1010 if (_Traits::eq(*--__ps, __c))
1011 return static_cast<_SizeT>(__ps - __p);
1012 }
Marshall Clow360f3192014-06-02 02:22:49 +00001013 return __npos;
1014}
1015
1016template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Eric Fiselier566bcb42016-04-21 22:54:21 +00001017inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001018__str_rfind(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001019 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1020{
1021 __pos = _VSTD::min(__pos, __sz);
1022 if (__n < __sz - __pos)
1023 __pos += __n;
1024 else
1025 __pos = __sz;
Marshall Clow37025e12014-06-10 18:51:55 +00001026 const _CharT* __r = _VSTD::__find_end(
1027 __p, __p + __pos, __s, __s + __n, _Traits::eq,
1028 random_access_iterator_tag(), random_access_iterator_tag());
Marshall Clow360f3192014-06-02 02:22:49 +00001029 if (__n > 0 && __r == __p + __pos)
1030 return __npos;
1031 return static_cast<_SizeT>(__r - __p);
1032}
1033
Marshall Clow37025e12014-06-10 18:51:55 +00001034// __str_find_first_of
Marshall Clow360f3192014-06-02 02:22:49 +00001035template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Eric Fiselier566bcb42016-04-21 22:54:21 +00001036inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001037__str_find_first_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001038 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001039{
1040 if (__pos >= __sz || __n == 0)
1041 return __npos;
Marshall Clow37025e12014-06-10 18:51:55 +00001042 const _CharT* __r = _VSTD::__find_first_of_ce
Marshall Clowb671fc92013-12-09 16:00:28 +00001043 (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
1044 if (__r == __p + __sz)
1045 return __npos;
1046 return static_cast<_SizeT>(__r - __p);
1047}
1048
Marshall Clow360f3192014-06-02 02:22:49 +00001049
Marshall Clow37025e12014-06-10 18:51:55 +00001050// __str_find_last_of
Marshall Clowb671fc92013-12-09 16:00:28 +00001051template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Eric Fiselier566bcb42016-04-21 22:54:21 +00001052inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001053__str_find_last_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001054 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001055 {
1056 if (__n != 0)
1057 {
1058 if (__pos < __sz)
1059 ++__pos;
1060 else
1061 __pos = __sz;
1062 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1063 {
1064 const _CharT* __r = _Traits::find(__s, __n, *--__ps);
1065 if (__r)
1066 return static_cast<_SizeT>(__ps - __p);
1067 }
1068 }
1069 return __npos;
1070}
1071
1072
Marshall Clow37025e12014-06-10 18:51:55 +00001073// __str_find_first_not_of
Marshall Clowb671fc92013-12-09 16:00:28 +00001074template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Eric Fiselier566bcb42016-04-21 22:54:21 +00001075inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001076__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001077 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001078{
1079 if (__pos < __sz)
1080 {
1081 const _CharT* __pe = __p + __sz;
1082 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1083 if (_Traits::find(__s, __n, *__ps) == 0)
1084 return static_cast<_SizeT>(__ps - __p);
1085 }
1086 return __npos;
1087}
1088
1089
1090template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Eric Fiselier566bcb42016-04-21 22:54:21 +00001091inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001092__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001093 _CharT __c, _SizeT __pos) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001094{
1095 if (__pos < __sz)
1096 {
1097 const _CharT* __pe = __p + __sz;
1098 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1099 if (!_Traits::eq(*__ps, __c))
1100 return static_cast<_SizeT>(__ps - __p);
1101 }
1102 return __npos;
1103}
1104
1105
Marshall Clow37025e12014-06-10 18:51:55 +00001106// __str_find_last_not_of
Marshall Clowb671fc92013-12-09 16:00:28 +00001107template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Eric Fiselier566bcb42016-04-21 22:54:21 +00001108inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001109__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001110 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001111{
1112 if (__pos < __sz)
1113 ++__pos;
1114 else
1115 __pos = __sz;
1116 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1117 if (_Traits::find(__s, __n, *--__ps) == 0)
1118 return static_cast<_SizeT>(__ps - __p);
1119 return __npos;
1120}
1121
1122
1123template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Eric Fiselier566bcb42016-04-21 22:54:21 +00001124inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001125__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001126 _CharT __c, _SizeT __pos) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001127{
1128 if (__pos < __sz)
1129 ++__pos;
1130 else
1131 __pos = __sz;
1132 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1133 if (!_Traits::eq(*--__ps, __c))
1134 return static_cast<_SizeT>(__ps - __p);
1135 return __npos;
1136}
1137
1138template<class _Ptr>
1139size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
1140{
1141 typedef typename iterator_traits<_Ptr>::value_type value_type;
1142 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
1143}
1144
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001145// basic_string
1146
1147template<class _CharT, class _Traits, class _Allocator>
1148basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001149operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
1150 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001151
1152template<class _CharT, class _Traits, class _Allocator>
1153basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001154operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155
1156template<class _CharT, class _Traits, class _Allocator>
1157basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001158operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001159
1160template<class _CharT, class _Traits, class _Allocator>
1161basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001162operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163
1164template<class _CharT, class _Traits, class _Allocator>
1165basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001166operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001167
1168template <bool>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001169class _LIBCPP_TYPE_VIS_ONLY __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001170{
1171protected:
1172 void __throw_length_error() const;
1173 void __throw_out_of_range() const;
1174};
1175
1176template <bool __b>
1177void
1178__basic_string_common<__b>::__throw_length_error() const
1179{
1180#ifndef _LIBCPP_NO_EXCEPTIONS
1181 throw length_error("basic_string");
1182#else
1183 assert(!"basic_string length_error");
1184#endif
1185}
1186
1187template <bool __b>
1188void
1189__basic_string_common<__b>::__throw_out_of_range() const
1190{
1191#ifndef _LIBCPP_NO_EXCEPTIONS
1192 throw out_of_range("basic_string");
1193#else
1194 assert(!"basic_string out_of_range");
1195#endif
1196}
1197
Howard Hinnante9df0a52013-08-01 18:17:34 +00001198#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +00001199#pragma warning( push )
1200#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34 +00001201#endif // _LIBCPP_MSVC
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001202_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34 +00001203#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +00001204#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34 +00001205#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001206
Marshall Clowdf9db312016-01-13 21:54:34 +00001207#ifdef _LIBCPP_NO_EXCEPTIONS
1208template <class _Iter>
1209struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
1210#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
1211template <class _Iter>
1212struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
1213#else
1214template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
1215struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
1216 noexcept(++(declval<_Iter&>())) &&
1217 is_nothrow_assignable<_Iter&, _Iter>::value &&
1218 noexcept(declval<_Iter>() == declval<_Iter>()) &&
1219 noexcept(*declval<_Iter>())
1220)) {};
1221
1222template <class _Iter>
1223struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
1224#endif
1225
1226
1227template <class _Iter>
1228struct __libcpp_string_gets_noexcept_iterator
1229 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
1230
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001231#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001232
1233template <class _CharT, size_t = sizeof(_CharT)>
1234struct __padding
1235{
1236 unsigned char __xx[sizeof(_CharT)-1];
1237};
1238
1239template <class _CharT>
1240struct __padding<_CharT, 1>
1241{
1242};
1243
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001244#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001245
Howard Hinnant324bb032010-08-22 00:02:43 +00001246template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001247class _LIBCPP_TYPE_VIS_ONLY basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001248 : private __basic_string_common<true>
1249{
1250public:
1251 typedef basic_string __self;
1252 typedef _Traits traits_type;
1253 typedef typename traits_type::char_type value_type;
1254 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001255 typedef allocator_traits<allocator_type> __alloc_traits;
1256 typedef typename __alloc_traits::size_type size_type;
1257 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001258 typedef value_type& reference;
1259 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001260 typedef typename __alloc_traits::pointer pointer;
1261 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001262
Howard Hinnant499cea12013-08-23 17:37:05 +00001263 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
1264 static_assert((is_same<_CharT, value_type>::value),
1265 "traits_type::char_type must be the same type as CharT");
1266 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1267 "Allocator::value_type must be same type as value_type");
1268#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269 typedef pointer iterator;
1270 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001271#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001272 typedef __wrap_iter<pointer> iterator;
1273 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001274#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001275 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1276 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001277
1278private:
Howard Hinnant15467182013-04-30 21:44:48 +00001279
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001280#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001281
1282 struct __long
1283 {
1284 pointer __data_;
1285 size_type __size_;
1286 size_type __cap_;
1287 };
1288
1289#if _LIBCPP_BIG_ENDIAN
1290 enum {__short_mask = 0x01};
1291 enum {__long_mask = 0x1ul};
1292#else // _LIBCPP_BIG_ENDIAN
1293 enum {__short_mask = 0x80};
1294 enum {__long_mask = ~(size_type(~0) >> 1)};
1295#endif // _LIBCPP_BIG_ENDIAN
1296
1297 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1298 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1299
1300 struct __short
1301 {
1302 value_type __data_[__min_cap];
1303 struct
1304 : __padding<value_type>
1305 {
1306 unsigned char __size_;
1307 };
1308 };
1309
1310#else
1311
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001312 struct __long
1313 {
1314 size_type __cap_;
1315 size_type __size_;
1316 pointer __data_;
1317 };
1318
1319#if _LIBCPP_BIG_ENDIAN
1320 enum {__short_mask = 0x80};
1321 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43 +00001322#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001323 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04 +00001324 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43 +00001325#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001326
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001327 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1328 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1329
1330 struct __short
1331 {
1332 union
1333 {
1334 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +00001335 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001336 };
1337 value_type __data_[__min_cap];
1338 };
1339
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001340#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001341
Howard Hinnant499cea12013-08-23 17:37:05 +00001342 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343
Howard Hinnant499cea12013-08-23 17:37:05 +00001344 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345
1346 struct __raw
1347 {
1348 size_type __words[__n_words];
1349 };
1350
1351 struct __rep
1352 {
1353 union
1354 {
1355 __long __l;
1356 __short __s;
1357 __raw __r;
1358 };
1359 };
1360
1361 __compressed_pair<__rep, allocator_type> __r_;
1362
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001363public:
1364 static const size_type npos = -1;
1365
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001366 _LIBCPP_INLINE_VISIBILITY basic_string()
1367 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +00001368
1369 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
1370#if _LIBCPP_STD_VER <= 14
1371 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
1372#else
1373 _NOEXCEPT;
1374#endif
1375
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001376 basic_string(const basic_string& __str);
1377 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +00001378
Howard Hinnant73d21a42010-09-04 23:28:19 +00001379#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59 +00001380 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001381 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001382#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001383 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +00001384#else
1385 _NOEXCEPT;
1386#endif
1387
Howard Hinnant9f193f22011-01-26 00:06:59 +00001388 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001389 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001390#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001391 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001392 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001393 basic_string(const value_type* __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001395 basic_string(const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001396 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001397 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001398 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001399 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001400 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001401 basic_string(size_type __n, value_type __c, const allocator_type& __a);
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001402 basic_string(const basic_string& __str, size_type __pos, size_type __n,
1403 const allocator_type& __a = allocator_type());
1404 _LIBCPP_INLINE_VISIBILITY
1405 basic_string(const basic_string& __str, size_type __pos,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001406 const allocator_type& __a = allocator_type());
1407 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001409 basic_string(_InputIterator __first, _InputIterator __last);
1410 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001411 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001412 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001413#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001414 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001415 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001416 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001417 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001418#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001419
1420 ~basic_string();
1421
Howard Hinnante32b5e22010-11-17 17:55:08 +00001422 basic_string& operator=(const basic_string& __str);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001423#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001425 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001426 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001427#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001428 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001429 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02 +00001430#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001431 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001432 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001433#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001434
Howard Hinnant499cea12013-08-23 17:37:05 +00001435#if _LIBCPP_DEBUG_LEVEL >= 2
1436 _LIBCPP_INLINE_VISIBILITY
1437 iterator begin() _NOEXCEPT
1438 {return iterator(this, __get_pointer());}
1439 _LIBCPP_INLINE_VISIBILITY
1440 const_iterator begin() const _NOEXCEPT
1441 {return const_iterator(this, __get_pointer());}
1442 _LIBCPP_INLINE_VISIBILITY
1443 iterator end() _NOEXCEPT
1444 {return iterator(this, __get_pointer() + size());}
1445 _LIBCPP_INLINE_VISIBILITY
1446 const_iterator end() const _NOEXCEPT
1447 {return const_iterator(this, __get_pointer() + size());}
1448#else
Howard Hinnanta6119a82011-05-29 19:57:12 +00001449 _LIBCPP_INLINE_VISIBILITY
1450 iterator begin() _NOEXCEPT
1451 {return iterator(__get_pointer());}
1452 _LIBCPP_INLINE_VISIBILITY
1453 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001454 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001455 _LIBCPP_INLINE_VISIBILITY
1456 iterator end() _NOEXCEPT
1457 {return iterator(__get_pointer() + size());}
1458 _LIBCPP_INLINE_VISIBILITY
1459 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001460 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +00001461#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +00001462 _LIBCPP_INLINE_VISIBILITY
1463 reverse_iterator rbegin() _NOEXCEPT
1464 {return reverse_iterator(end());}
1465 _LIBCPP_INLINE_VISIBILITY
1466 const_reverse_iterator rbegin() const _NOEXCEPT
1467 {return const_reverse_iterator(end());}
1468 _LIBCPP_INLINE_VISIBILITY
1469 reverse_iterator rend() _NOEXCEPT
1470 {return reverse_iterator(begin());}
1471 _LIBCPP_INLINE_VISIBILITY
1472 const_reverse_iterator rend() const _NOEXCEPT
1473 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001474
Howard Hinnanta6119a82011-05-29 19:57:12 +00001475 _LIBCPP_INLINE_VISIBILITY
1476 const_iterator cbegin() const _NOEXCEPT
1477 {return begin();}
1478 _LIBCPP_INLINE_VISIBILITY
1479 const_iterator cend() const _NOEXCEPT
1480 {return end();}
1481 _LIBCPP_INLINE_VISIBILITY
1482 const_reverse_iterator crbegin() const _NOEXCEPT
1483 {return rbegin();}
1484 _LIBCPP_INLINE_VISIBILITY
1485 const_reverse_iterator crend() const _NOEXCEPT
1486 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001487
Howard Hinnanta6119a82011-05-29 19:57:12 +00001488 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001489 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001490 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
1491 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
1492 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001493 {return (__is_long() ? __get_long_cap()
1494 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001495
1496 void resize(size_type __n, value_type __c);
1497 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
1498
1499 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001501 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001502 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001503 void clear() _NOEXCEPT;
1504 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001505
1506 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
1507 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
1508
1509 const_reference at(size_type __n) const;
1510 reference at(size_type __n);
1511
1512 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001513 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001514 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00001515#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001516 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02 +00001517#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001520 basic_string& append(const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001521 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001522 basic_string& append(const value_type* __s, size_type __n);
1523 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001524 basic_string& append(size_type __n, value_type __c);
1525 template<class _InputIterator>
1526 typename enable_if
1527 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001528 __is_exactly_input_iterator<_InputIterator>::value
1529 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001530 basic_string&
1531 >::type
1532 append(_InputIterator __first, _InputIterator __last);
1533 template<class _ForwardIterator>
1534 typename enable_if
1535 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001536 __is_forward_iterator<_ForwardIterator>::value
1537 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001538 basic_string&
1539 >::type
1540 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001541#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001543 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001544#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001545
1546 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001549 _LIBCPP_INLINE_VISIBILITY reference front();
1550 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1551 _LIBCPP_INLINE_VISIBILITY reference back();
1552 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001553
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001554 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29 +00001555 basic_string& assign(const basic_string& __str) { return *this = __str; }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001556#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1557 _LIBCPP_INLINE_VISIBILITY
1558 basic_string& assign(basic_string&& str)
Marshall Clow7ed093b2015-10-05 16:17:34 +00001559 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +00001560 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001561#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +00001562 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001563 basic_string& assign(const value_type* __s, size_type __n);
1564 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001565 basic_string& assign(size_type __n, value_type __c);
1566 template<class _InputIterator>
1567 typename enable_if
1568 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001569 __is_exactly_input_iterator<_InputIterator>::value
1570 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001571 basic_string&
1572 >::type
1573 assign(_InputIterator __first, _InputIterator __last);
1574 template<class _ForwardIterator>
1575 typename enable_if
1576 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001577 __is_forward_iterator<_ForwardIterator>::value
1578 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001579 basic_string&
1580 >::type
1581 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001582#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001584 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001585#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001586
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001588 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001589 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001590 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1591 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001592 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1593 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001595 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1596 template<class _InputIterator>
1597 typename enable_if
1598 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001599 __is_exactly_input_iterator<_InputIterator>::value
1600 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001601 iterator
1602 >::type
1603 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1604 template<class _ForwardIterator>
1605 typename enable_if
1606 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001607 __is_forward_iterator<_ForwardIterator>::value
1608 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001609 iterator
1610 >::type
1611 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001612#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001614 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1615 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001616#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001617
1618 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001620 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001622 iterator erase(const_iterator __first, const_iterator __last);
1623
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001625 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001626 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001627 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1628 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001629 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001631 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001632 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001633 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001635 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001637 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001638 template<class _InputIterator>
1639 typename enable_if
1640 <
1641 __is_input_iterator<_InputIterator>::value,
1642 basic_string&
1643 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001644 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:02 +00001645#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001647 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001648 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001649#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001650
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001651 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001653 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1654
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001656 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001657#if _LIBCPP_STD_VER >= 14
1658 _NOEXCEPT;
1659#else
1660 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1661 __is_nothrow_swappable<allocator_type>::value);
1662#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001663
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001665 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001666 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001667 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Marshall Clowf532a702016-03-08 15:44:30 +00001668#if _LIBCPP_STD_VER > 14
1669 _LIBCPP_INLINE_VISIBILITY
1670 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1671#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001672
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001674 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001675
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001677 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001678 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001679 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001680 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001681 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001682
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001683 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001684 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001685 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001686 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001687 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001688 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001689
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001691 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001692 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001694 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001696 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001697
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001698 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001699 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001700 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001702 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001704 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001705
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001707 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001708 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001710 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001711 _LIBCPP_INLINE_VISIBILITY
1712 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1713
1714 _LIBCPP_INLINE_VISIBILITY
1715 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001716 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001717 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001718 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001719 _LIBCPP_INLINE_VISIBILITY
1720 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1721
1722 _LIBCPP_INLINE_VISIBILITY
1723 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001725 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001726 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001727 int compare(const value_type* __s) const _NOEXCEPT;
1728 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1729 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001730
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001731 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001732
1733 _LIBCPP_INLINE_VISIBILITY
1734 bool __is_long() const _NOEXCEPT
1735 {return bool(__r_.first().__s.__size_ & __short_mask);}
1736
Howard Hinnant499cea12013-08-23 17:37:05 +00001737#if _LIBCPP_DEBUG_LEVEL >= 2
1738
1739 bool __dereferenceable(const const_iterator* __i) const;
1740 bool __decrementable(const const_iterator* __i) const;
1741 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1742 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1743
1744#endif // _LIBCPP_DEBUG_LEVEL >= 2
1745
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001746private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001747 _LIBCPP_INLINE_VISIBILITY
1748 allocator_type& __alloc() _NOEXCEPT
1749 {return __r_.second();}
1750 _LIBCPP_INLINE_VISIBILITY
1751 const allocator_type& __alloc() const _NOEXCEPT
1752 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001753
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001754#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001755
Howard Hinnanta6119a82011-05-29 19:57:12 +00001756 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001757 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001758# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001759 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001760# else
1761 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1762# endif
1763
Howard Hinnanta6119a82011-05-29 19:57:12 +00001764 _LIBCPP_INLINE_VISIBILITY
1765 size_type __get_short_size() const _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001766# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001767 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001768# else
1769 {return __r_.first().__s.__size_;}
1770# endif
1771
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001772#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001773
1774 _LIBCPP_INLINE_VISIBILITY
1775 void __set_short_size(size_type __s) _NOEXCEPT
1776# if _LIBCPP_BIG_ENDIAN
1777 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1778# else
1779 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1780# endif
1781
1782 _LIBCPP_INLINE_VISIBILITY
1783 size_type __get_short_size() const _NOEXCEPT
1784# if _LIBCPP_BIG_ENDIAN
1785 {return __r_.first().__s.__size_;}
1786# else
1787 {return __r_.first().__s.__size_ >> 1;}
1788# endif
1789
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001790#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001791
Howard Hinnanta6119a82011-05-29 19:57:12 +00001792 _LIBCPP_INLINE_VISIBILITY
1793 void __set_long_size(size_type __s) _NOEXCEPT
1794 {__r_.first().__l.__size_ = __s;}
1795 _LIBCPP_INLINE_VISIBILITY
1796 size_type __get_long_size() const _NOEXCEPT
1797 {return __r_.first().__l.__size_;}
1798 _LIBCPP_INLINE_VISIBILITY
1799 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001800 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1801
Howard Hinnanta6119a82011-05-29 19:57:12 +00001802 _LIBCPP_INLINE_VISIBILITY
1803 void __set_long_cap(size_type __s) _NOEXCEPT
1804 {__r_.first().__l.__cap_ = __long_mask | __s;}
1805 _LIBCPP_INLINE_VISIBILITY
1806 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001807 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001808
Howard Hinnanta6119a82011-05-29 19:57:12 +00001809 _LIBCPP_INLINE_VISIBILITY
1810 void __set_long_pointer(pointer __p) _NOEXCEPT
1811 {__r_.first().__l.__data_ = __p;}
1812 _LIBCPP_INLINE_VISIBILITY
1813 pointer __get_long_pointer() _NOEXCEPT
1814 {return __r_.first().__l.__data_;}
1815 _LIBCPP_INLINE_VISIBILITY
1816 const_pointer __get_long_pointer() const _NOEXCEPT
1817 {return __r_.first().__l.__data_;}
1818 _LIBCPP_INLINE_VISIBILITY
1819 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001820 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001821 _LIBCPP_INLINE_VISIBILITY
1822 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001823 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001824 _LIBCPP_INLINE_VISIBILITY
1825 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001826 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001827 _LIBCPP_INLINE_VISIBILITY
1828 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001829 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1830
Howard Hinnanta6119a82011-05-29 19:57:12 +00001831 _LIBCPP_INLINE_VISIBILITY
1832 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001833 {
1834 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1835 for (unsigned __i = 0; __i < __n_words; ++__i)
1836 __a[__i] = 0;
1837 }
1838
1839 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001841 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001842 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001843 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001844 static _LIBCPP_INLINE_VISIBILITY
1845 size_type __recommend(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001846 {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
Howard Hinnant7f764502013-08-14 18:00:20 +00001847 __align_it<sizeof(value_type) < __alignment ?
Howard Hinnanta6119a82011-05-29 19:57:12 +00001848 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001849
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001850 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1851 void __init(const value_type* __s, size_type __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001852 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001853
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001854 template <class _InputIterator>
1855 typename enable_if
1856 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001857 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001858 void
1859 >::type
1860 __init(_InputIterator __first, _InputIterator __last);
1861
1862 template <class _ForwardIterator>
1863 typename enable_if
1864 <
1865 __is_forward_iterator<_ForwardIterator>::value,
1866 void
1867 >::type
1868 __init(_ForwardIterator __first, _ForwardIterator __last);
1869
1870 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001871 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001872 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1873 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001874 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001875
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001877 void __erase_to_end(size_type __pos);
1878
Howard Hinnante32b5e22010-11-17 17:55:08 +00001879 _LIBCPP_INLINE_VISIBILITY
1880 void __copy_assign_alloc(const basic_string& __str)
1881 {__copy_assign_alloc(__str, integral_constant<bool,
1882 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1883
1884 _LIBCPP_INLINE_VISIBILITY
1885 void __copy_assign_alloc(const basic_string& __str, true_type)
1886 {
1887 if (__alloc() != __str.__alloc())
1888 {
1889 clear();
1890 shrink_to_fit();
1891 }
1892 __alloc() = __str.__alloc();
1893 }
1894
1895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001896 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001897 {}
1898
1899#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001900 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001901 void __move_assign(basic_string& __str, false_type)
1902 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001904 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001905#if _LIBCPP_STD_VER > 14
1906 _NOEXCEPT;
1907#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001908 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001909#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001910#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001911
1912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001913 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001914 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001915 _NOEXCEPT_(
1916 !__alloc_traits::propagate_on_container_move_assignment::value ||
1917 is_nothrow_move_assignable<allocator_type>::value)
1918 {__move_assign_alloc(__str, integral_constant<bool,
1919 __alloc_traits::propagate_on_container_move_assignment::value>());}
1920
1921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001922 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001923 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1924 {
1925 __alloc() = _VSTD::move(__c.__alloc());
1926 }
1927
1928 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001929 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001930 _NOEXCEPT
1931 {}
1932
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001933 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1934 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935
1936 friend basic_string operator+<>(const basic_string&, const basic_string&);
1937 friend basic_string operator+<>(const value_type*, const basic_string&);
1938 friend basic_string operator+<>(value_type, const basic_string&);
1939 friend basic_string operator+<>(const basic_string&, const value_type*);
1940 friend basic_string operator+<>(const basic_string&, value_type);
1941};
1942
1943template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001944inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001945void
1946basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1947{
Howard Hinnant499cea12013-08-23 17:37:05 +00001948#if _LIBCPP_DEBUG_LEVEL >= 2
1949 __get_db()->__invalidate_all(this);
1950#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001951}
1952
1953template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001954inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001955void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001956basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001957#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001958 __pos
1959#endif
1960 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001961{
Howard Hinnant499cea12013-08-23 17:37:05 +00001962#if _LIBCPP_DEBUG_LEVEL >= 2
1963 __c_node* __c = __get_db()->__find_c_and_lock(this);
1964 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001965 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001966 const_pointer __new_last = __get_pointer() + __pos;
1967 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001968 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001969 --__p;
1970 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1971 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001972 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001973 (*__p)->__c_ = nullptr;
1974 if (--__c->end_ != __p)
1975 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001976 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001977 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001978 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001979 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001980#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001981}
1982
1983template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001984inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001985basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001986 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001987{
Howard Hinnant499cea12013-08-23 17:37:05 +00001988#if _LIBCPP_DEBUG_LEVEL >= 2
1989 __get_db()->__insert_c(this);
1990#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001991 __zero();
1992}
1993
1994template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001995inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001996basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001997#if _LIBCPP_STD_VER <= 14
1998 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1999#else
2000 _NOEXCEPT
2001#endif
2002: __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002003{
Howard Hinnant499cea12013-08-23 17:37:05 +00002004#if _LIBCPP_DEBUG_LEVEL >= 2
2005 __get_db()->__insert_c(this);
2006#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002007 __zero();
2008}
2009
2010template <class _CharT, class _Traits, class _Allocator>
2011void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002012basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002013{
2014 if (__reserve > max_size())
2015 this->__throw_length_error();
2016 pointer __p;
2017 if (__reserve < __min_cap)
2018 {
2019 __set_short_size(__sz);
2020 __p = __get_short_pointer();
2021 }
2022 else
2023 {
2024 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002025 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002026 __set_long_pointer(__p);
2027 __set_long_cap(__cap+1);
2028 __set_long_size(__sz);
2029 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002030 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002031 traits_type::assign(__p[__sz], value_type());
2032}
2033
2034template <class _CharT, class _Traits, class _Allocator>
2035void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002036basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002037{
2038 if (__sz > max_size())
2039 this->__throw_length_error();
2040 pointer __p;
2041 if (__sz < __min_cap)
2042 {
2043 __set_short_size(__sz);
2044 __p = __get_short_pointer();
2045 }
2046 else
2047 {
2048 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002049 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002050 __set_long_pointer(__p);
2051 __set_long_cap(__cap+1);
2052 __set_long_size(__sz);
2053 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002054 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002055 traits_type::assign(__p[__sz], value_type());
2056}
2057
2058template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002059inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002060basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002061{
Howard Hinnant499cea12013-08-23 17:37:05 +00002062 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002063 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00002064#if _LIBCPP_DEBUG_LEVEL >= 2
2065 __get_db()->__insert_c(this);
2066#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002067}
2068
2069template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002070inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002071basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002072 : __r_(__a)
2073{
Howard Hinnant499cea12013-08-23 17:37:05 +00002074 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002075 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00002076#if _LIBCPP_DEBUG_LEVEL >= 2
2077 __get_db()->__insert_c(this);
2078#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002079}
2080
2081template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002082inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002083basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002084{
Howard Hinnant499cea12013-08-23 17:37:05 +00002085 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002086 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00002087#if _LIBCPP_DEBUG_LEVEL >= 2
2088 __get_db()->__insert_c(this);
2089#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002090}
2091
2092template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002093inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002094basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095 : __r_(__a)
2096{
Howard Hinnant499cea12013-08-23 17:37:05 +00002097 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002098 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00002099#if _LIBCPP_DEBUG_LEVEL >= 2
2100 __get_db()->__insert_c(this);
2101#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002102}
2103
2104template <class _CharT, class _Traits, class _Allocator>
2105basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002106 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002107{
2108 if (!__str.__is_long())
2109 __r_.first().__r = __str.__r_.first().__r;
2110 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002111 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00002112#if _LIBCPP_DEBUG_LEVEL >= 2
2113 __get_db()->__insert_c(this);
2114#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002115}
2116
2117template <class _CharT, class _Traits, class _Allocator>
2118basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
2119 : __r_(__a)
2120{
2121 if (!__str.__is_long())
2122 __r_.first().__r = __str.__r_.first().__r;
2123 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002124 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00002125#if _LIBCPP_DEBUG_LEVEL >= 2
2126 __get_db()->__insert_c(this);
2127#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002128}
2129
Howard Hinnant73d21a42010-09-04 23:28:19 +00002130#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002131
2132template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002133inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002134basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00002135#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002136 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00002137#else
2138 _NOEXCEPT
2139#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00002140 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002141{
2142 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00002143#if _LIBCPP_DEBUG_LEVEL >= 2
2144 __get_db()->__insert_c(this);
2145 if (__is_long())
2146 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002147#endif
2148}
2149
2150template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002151inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002152basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002153 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002154{
Marshall Clowd5549cc2014-07-17 15:32:20 +00002155 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002156 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00002157 else
2158 {
2159 __r_.first().__r = __str.__r_.first().__r;
2160 __str.__zero();
2161 }
Howard Hinnant499cea12013-08-23 17:37:05 +00002162#if _LIBCPP_DEBUG_LEVEL >= 2
2163 __get_db()->__insert_c(this);
2164 if (__is_long())
2165 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002166#endif
2167}
2168
Howard Hinnant73d21a42010-09-04 23:28:19 +00002169#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002170
2171template <class _CharT, class _Traits, class _Allocator>
2172void
2173basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
2174{
2175 if (__n > max_size())
2176 this->__throw_length_error();
2177 pointer __p;
2178 if (__n < __min_cap)
2179 {
2180 __set_short_size(__n);
2181 __p = __get_short_pointer();
2182 }
2183 else
2184 {
2185 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002186 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002187 __set_long_pointer(__p);
2188 __set_long_cap(__cap+1);
2189 __set_long_size(__n);
2190 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002191 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002192 traits_type::assign(__p[__n], value_type());
2193}
2194
2195template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002196inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002197basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
2198{
2199 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00002200#if _LIBCPP_DEBUG_LEVEL >= 2
2201 __get_db()->__insert_c(this);
2202#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002203}
2204
2205template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002206inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002207basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
2208 : __r_(__a)
2209{
2210 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00002211#if _LIBCPP_DEBUG_LEVEL >= 2
2212 __get_db()->__insert_c(this);
2213#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002214}
2215
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002216template <class _CharT, class _Traits, class _Allocator>
2217basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
2218 const allocator_type& __a)
2219 : __r_(__a)
2220{
2221 size_type __str_sz = __str.size();
2222 if (__pos > __str_sz)
2223 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002224 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00002225#if _LIBCPP_DEBUG_LEVEL >= 2
2226 __get_db()->__insert_c(this);
2227#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002228}
2229
2230template <class _CharT, class _Traits, class _Allocator>
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00002231inline _LIBCPP_INLINE_VISIBILITY
2232basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
2233 const allocator_type& __a)
2234 : __r_(__a)
2235{
2236 size_type __str_sz = __str.size();
2237 if (__pos > __str_sz)
2238 this->__throw_out_of_range();
2239 __init(__str.data() + __pos, __str_sz - __pos);
2240#if _LIBCPP_DEBUG_LEVEL >= 2
2241 __get_db()->__insert_c(this);
2242#endif
2243}
2244
2245template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002246template <class _InputIterator>
2247typename enable_if
2248<
Marshall Clowdf9db312016-01-13 21:54:34 +00002249 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002250 void
2251>::type
2252basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2253{
2254 __zero();
2255#ifndef _LIBCPP_NO_EXCEPTIONS
2256 try
2257 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002258#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002259 for (; __first != __last; ++__first)
2260 push_back(*__first);
2261#ifndef _LIBCPP_NO_EXCEPTIONS
2262 }
2263 catch (...)
2264 {
2265 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002266 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002267 throw;
2268 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002269#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002270}
2271
2272template <class _CharT, class _Traits, class _Allocator>
2273template <class _ForwardIterator>
2274typename enable_if
2275<
2276 __is_forward_iterator<_ForwardIterator>::value,
2277 void
2278>::type
2279basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2280{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002281 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002282 if (__sz > max_size())
2283 this->__throw_length_error();
2284 pointer __p;
2285 if (__sz < __min_cap)
2286 {
2287 __set_short_size(__sz);
2288 __p = __get_short_pointer();
2289 }
2290 else
2291 {
2292 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002293 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002294 __set_long_pointer(__p);
2295 __set_long_cap(__cap+1);
2296 __set_long_size(__sz);
2297 }
Eric Fiselierb9919752014-10-27 19:28:20 +00002298 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002299 traits_type::assign(*__p, *__first);
2300 traits_type::assign(*__p, value_type());
2301}
2302
2303template <class _CharT, class _Traits, class _Allocator>
2304template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002305inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002306basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2307{
2308 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002309#if _LIBCPP_DEBUG_LEVEL >= 2
2310 __get_db()->__insert_c(this);
2311#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002312}
2313
2314template <class _CharT, class _Traits, class _Allocator>
2315template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002316inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002317basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2318 const allocator_type& __a)
2319 : __r_(__a)
2320{
2321 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002322#if _LIBCPP_DEBUG_LEVEL >= 2
2323 __get_db()->__insert_c(this);
2324#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002325}
2326
Howard Hinnante3e32912011-08-12 21:56:02 +00002327#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2328
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002329template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002330inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002331basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
2332{
2333 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002334#if _LIBCPP_DEBUG_LEVEL >= 2
2335 __get_db()->__insert_c(this);
2336#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002337}
2338
2339template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002340inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002341basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
2342 : __r_(__a)
2343{
2344 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002345#if _LIBCPP_DEBUG_LEVEL >= 2
2346 __get_db()->__insert_c(this);
2347#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002348}
2349
Howard Hinnante3e32912011-08-12 21:56:02 +00002350#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2351
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002352template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002353basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2354{
Howard Hinnant499cea12013-08-23 17:37:05 +00002355#if _LIBCPP_DEBUG_LEVEL >= 2
2356 __get_db()->__erase_c(this);
2357#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002358 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002359 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002360}
2361
2362template <class _CharT, class _Traits, class _Allocator>
2363void
2364basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2365 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002366 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002367{
2368 size_type __ms = max_size();
2369 if (__delta_cap > __ms - __old_cap - 1)
2370 this->__throw_length_error();
2371 pointer __old_p = __get_pointer();
2372 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002373 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002374 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002375 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002376 __invalidate_all_iterators();
2377 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002378 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2379 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002380 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002381 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002382 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2383 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002384 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2385 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002386 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002387 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002388 __set_long_pointer(__p);
2389 __set_long_cap(__cap+1);
2390 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2391 __set_long_size(__old_sz);
2392 traits_type::assign(__p[__old_sz], value_type());
2393}
2394
2395template <class _CharT, class _Traits, class _Allocator>
2396void
2397basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2398 size_type __n_copy, size_type __n_del, size_type __n_add)
2399{
2400 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00002401 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002402 this->__throw_length_error();
2403 pointer __old_p = __get_pointer();
2404 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002405 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002406 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002407 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002408 __invalidate_all_iterators();
2409 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002410 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2411 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002412 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2413 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002414 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2415 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2416 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002417 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002418 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002419 __set_long_pointer(__p);
2420 __set_long_cap(__cap+1);
2421}
2422
2423// assign
2424
2425template <class _CharT, class _Traits, class _Allocator>
2426basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002427basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002428{
Alp Tokerec34c482014-05-15 11:27:39 +00002429 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002430 size_type __cap = capacity();
2431 if (__cap >= __n)
2432 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002433 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002434 traits_type::move(__p, __s, __n);
2435 traits_type::assign(__p[__n], value_type());
2436 __set_size(__n);
2437 __invalidate_iterators_past(__n);
2438 }
2439 else
2440 {
2441 size_type __sz = size();
2442 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2443 }
2444 return *this;
2445}
2446
2447template <class _CharT, class _Traits, class _Allocator>
2448basic_string<_CharT, _Traits, _Allocator>&
2449basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2450{
2451 size_type __cap = capacity();
2452 if (__cap < __n)
2453 {
2454 size_type __sz = size();
2455 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2456 }
2457 else
2458 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002459 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002460 traits_type::assign(__p, __n, __c);
2461 traits_type::assign(__p[__n], value_type());
2462 __set_size(__n);
2463 return *this;
2464}
2465
2466template <class _CharT, class _Traits, class _Allocator>
2467basic_string<_CharT, _Traits, _Allocator>&
2468basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2469{
2470 pointer __p;
2471 if (__is_long())
2472 {
2473 __p = __get_long_pointer();
2474 __set_long_size(1);
2475 }
2476 else
2477 {
2478 __p = __get_short_pointer();
2479 __set_short_size(1);
2480 }
2481 traits_type::assign(*__p, __c);
2482 traits_type::assign(*++__p, value_type());
2483 __invalidate_iterators_past(1);
2484 return *this;
2485}
2486
2487template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002488basic_string<_CharT, _Traits, _Allocator>&
2489basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2490{
2491 if (this != &__str)
2492 {
2493 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00002494 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00002495 }
2496 return *this;
2497}
2498
2499#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2500
2501template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002502inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002503void
2504basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002505 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002506{
2507 if (__alloc() != __str.__alloc())
2508 assign(__str);
2509 else
2510 __move_assign(__str, true_type());
2511}
2512
2513template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002514inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002515void
2516basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002517#if _LIBCPP_STD_VER > 14
2518 _NOEXCEPT
2519#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002520 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002521#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002522{
2523 clear();
2524 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002525 __r_.first() = __str.__r_.first();
2526 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002527 __str.__zero();
2528}
2529
2530template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002531inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002532basic_string<_CharT, _Traits, _Allocator>&
2533basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002534 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002535{
2536 __move_assign(__str, integral_constant<bool,
2537 __alloc_traits::propagate_on_container_move_assignment::value>());
2538 return *this;
2539}
2540
2541#endif
2542
2543template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002544template<class _InputIterator>
2545typename enable_if
2546<
Marshall Clowdf9db312016-01-13 21:54:34 +00002547 __is_exactly_input_iterator <_InputIterator>::value
2548 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002549 basic_string<_CharT, _Traits, _Allocator>&
2550>::type
2551basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2552{
Marshall Clowdf9db312016-01-13 21:54:34 +00002553 basic_string __temp(__first, __last, __alloc());
2554 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002555 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002556}
2557
2558template <class _CharT, class _Traits, class _Allocator>
2559template<class _ForwardIterator>
2560typename enable_if
2561<
Marshall Clowdf9db312016-01-13 21:54:34 +00002562 __is_forward_iterator<_ForwardIterator>::value
2563 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002564 basic_string<_CharT, _Traits, _Allocator>&
2565>::type
2566basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2567{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002568 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002569 size_type __cap = capacity();
2570 if (__cap < __n)
2571 {
2572 size_type __sz = size();
2573 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2574 }
2575 else
2576 __invalidate_iterators_past(__n);
2577 pointer __p = __get_pointer();
2578 for (; __first != __last; ++__first, ++__p)
2579 traits_type::assign(*__p, *__first);
2580 traits_type::assign(*__p, value_type());
2581 __set_size(__n);
2582 return *this;
2583}
2584
2585template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002586basic_string<_CharT, _Traits, _Allocator>&
2587basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2588{
2589 size_type __sz = __str.size();
2590 if (__pos > __sz)
2591 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002592 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002593}
2594
2595template <class _CharT, class _Traits, class _Allocator>
2596basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002597basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002598{
Alp Tokerec34c482014-05-15 11:27:39 +00002599 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002600 return assign(__s, traits_type::length(__s));
2601}
2602
2603// append
2604
2605template <class _CharT, class _Traits, class _Allocator>
2606basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002607basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002608{
Alp Tokerec34c482014-05-15 11:27:39 +00002609 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002610 size_type __cap = capacity();
2611 size_type __sz = size();
2612 if (__cap - __sz >= __n)
2613 {
2614 if (__n)
2615 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002616 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002617 traits_type::copy(__p + __sz, __s, __n);
2618 __sz += __n;
2619 __set_size(__sz);
2620 traits_type::assign(__p[__sz], value_type());
2621 }
2622 }
2623 else
2624 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2625 return *this;
2626}
2627
2628template <class _CharT, class _Traits, class _Allocator>
2629basic_string<_CharT, _Traits, _Allocator>&
2630basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2631{
2632 if (__n)
2633 {
2634 size_type __cap = capacity();
2635 size_type __sz = size();
2636 if (__cap - __sz < __n)
2637 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2638 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002639 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002640 __sz += __n;
2641 __set_size(__sz);
2642 traits_type::assign(__p[__sz], value_type());
2643 }
2644 return *this;
2645}
2646
2647template <class _CharT, class _Traits, class _Allocator>
2648void
2649basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2650{
Howard Hinnant15467182013-04-30 21:44:48 +00002651 bool __is_short = !__is_long();
2652 size_type __cap;
2653 size_type __sz;
2654 if (__is_short)
2655 {
2656 __cap = __min_cap - 1;
2657 __sz = __get_short_size();
2658 }
2659 else
2660 {
2661 __cap = __get_long_cap() - 1;
2662 __sz = __get_long_size();
2663 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002664 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002665 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002666 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002667 __is_short = !__is_long();
2668 }
2669 pointer __p;
2670 if (__is_short)
2671 {
2672 __p = __get_short_pointer() + __sz;
2673 __set_short_size(__sz+1);
2674 }
2675 else
2676 {
2677 __p = __get_long_pointer() + __sz;
2678 __set_long_size(__sz+1);
2679 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002680 traits_type::assign(*__p, __c);
2681 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002682}
2683
2684template <class _CharT, class _Traits, class _Allocator>
2685template<class _InputIterator>
2686typename enable_if
2687<
Marshall Clowdf9db312016-01-13 21:54:34 +00002688 __is_exactly_input_iterator<_InputIterator>::value
2689 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002690 basic_string<_CharT, _Traits, _Allocator>&
2691>::type
2692basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2693{
Marshall Clowdf9db312016-01-13 21:54:34 +00002694 basic_string __temp (__first, __last, __alloc());
2695 append(__temp.data(), __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002696 return *this;
2697}
2698
2699template <class _CharT, class _Traits, class _Allocator>
2700template<class _ForwardIterator>
2701typename enable_if
2702<
Marshall Clowdf9db312016-01-13 21:54:34 +00002703 __is_forward_iterator<_ForwardIterator>::value
2704 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002705 basic_string<_CharT, _Traits, _Allocator>&
2706>::type
2707basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2708{
2709 size_type __sz = size();
2710 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002711 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002712 if (__n)
2713 {
2714 if (__cap - __sz < __n)
2715 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2716 pointer __p = __get_pointer() + __sz;
2717 for (; __first != __last; ++__p, ++__first)
2718 traits_type::assign(*__p, *__first);
2719 traits_type::assign(*__p, value_type());
2720 __set_size(__sz + __n);
2721 }
2722 return *this;
2723}
2724
2725template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002726inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002727basic_string<_CharT, _Traits, _Allocator>&
2728basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2729{
2730 return append(__str.data(), __str.size());
2731}
2732
2733template <class _CharT, class _Traits, class _Allocator>
2734basic_string<_CharT, _Traits, _Allocator>&
2735basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2736{
2737 size_type __sz = __str.size();
2738 if (__pos > __sz)
2739 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002740 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002741}
2742
2743template <class _CharT, class _Traits, class _Allocator>
2744basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002745basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002746{
Alp Tokerec34c482014-05-15 11:27:39 +00002747 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002748 return append(__s, traits_type::length(__s));
2749}
2750
2751// insert
2752
2753template <class _CharT, class _Traits, class _Allocator>
2754basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002755basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002756{
Alp Tokerec34c482014-05-15 11:27:39 +00002757 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002758 size_type __sz = size();
2759 if (__pos > __sz)
2760 this->__throw_out_of_range();
2761 size_type __cap = capacity();
2762 if (__cap - __sz >= __n)
2763 {
2764 if (__n)
2765 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002766 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002767 size_type __n_move = __sz - __pos;
2768 if (__n_move != 0)
2769 {
2770 if (__p + __pos <= __s && __s < __p + __sz)
2771 __s += __n;
2772 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2773 }
2774 traits_type::move(__p + __pos, __s, __n);
2775 __sz += __n;
2776 __set_size(__sz);
2777 traits_type::assign(__p[__sz], value_type());
2778 }
2779 }
2780 else
2781 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2782 return *this;
2783}
2784
2785template <class _CharT, class _Traits, class _Allocator>
2786basic_string<_CharT, _Traits, _Allocator>&
2787basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2788{
2789 size_type __sz = size();
2790 if (__pos > __sz)
2791 this->__throw_out_of_range();
2792 if (__n)
2793 {
2794 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002795 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002796 if (__cap - __sz >= __n)
2797 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002798 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002799 size_type __n_move = __sz - __pos;
2800 if (__n_move != 0)
2801 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2802 }
2803 else
2804 {
2805 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002806 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002807 }
2808 traits_type::assign(__p + __pos, __n, __c);
2809 __sz += __n;
2810 __set_size(__sz);
2811 traits_type::assign(__p[__sz], value_type());
2812 }
2813 return *this;
2814}
2815
2816template <class _CharT, class _Traits, class _Allocator>
2817template<class _InputIterator>
2818typename enable_if
2819<
Marshall Clowdf9db312016-01-13 21:54:34 +00002820 __is_exactly_input_iterator<_InputIterator>::value
2821 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2822 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002823>::type
2824basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2825{
Howard Hinnant499cea12013-08-23 17:37:05 +00002826#if _LIBCPP_DEBUG_LEVEL >= 2
2827 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2828 "string::insert(iterator, range) called with an iterator not"
2829 " referring to this string");
2830#endif
Marshall Clowdf9db312016-01-13 21:54:34 +00002831 basic_string __temp(__first, __last, __alloc());
2832 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002833}
2834
2835template <class _CharT, class _Traits, class _Allocator>
2836template<class _ForwardIterator>
2837typename enable_if
2838<
Marshall Clowdf9db312016-01-13 21:54:34 +00002839 __is_forward_iterator<_ForwardIterator>::value
2840 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002841 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2842>::type
2843basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2844{
Howard Hinnant499cea12013-08-23 17:37:05 +00002845#if _LIBCPP_DEBUG_LEVEL >= 2
2846 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2847 "string::insert(iterator, range) called with an iterator not"
2848 " referring to this string");
2849#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002850 size_type __ip = static_cast<size_type>(__pos - begin());
2851 size_type __sz = size();
2852 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002853 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002854 if (__n)
2855 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002856 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002857 if (__cap - __sz >= __n)
2858 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002859 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002860 size_type __n_move = __sz - __ip;
2861 if (__n_move != 0)
2862 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2863 }
2864 else
2865 {
2866 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002867 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002868 }
2869 __sz += __n;
2870 __set_size(__sz);
2871 traits_type::assign(__p[__sz], value_type());
2872 for (__p += __ip; __first != __last; ++__p, ++__first)
2873 traits_type::assign(*__p, *__first);
2874 }
2875 return begin() + __ip;
2876}
2877
2878template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002879inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002880basic_string<_CharT, _Traits, _Allocator>&
2881basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2882{
2883 return insert(__pos1, __str.data(), __str.size());
2884}
2885
2886template <class _CharT, class _Traits, class _Allocator>
2887basic_string<_CharT, _Traits, _Allocator>&
2888basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2889 size_type __pos2, size_type __n)
2890{
2891 size_type __str_sz = __str.size();
2892 if (__pos2 > __str_sz)
2893 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002894 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002895}
2896
2897template <class _CharT, class _Traits, class _Allocator>
2898basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002899basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002900{
Alp Tokerec34c482014-05-15 11:27:39 +00002901 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002902 return insert(__pos, __s, traits_type::length(__s));
2903}
2904
2905template <class _CharT, class _Traits, class _Allocator>
2906typename basic_string<_CharT, _Traits, _Allocator>::iterator
2907basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2908{
2909 size_type __ip = static_cast<size_type>(__pos - begin());
2910 size_type __sz = size();
2911 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002912 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002913 if (__cap == __sz)
2914 {
2915 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002916 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002917 }
2918 else
2919 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002920 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002921 size_type __n_move = __sz - __ip;
2922 if (__n_move != 0)
2923 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2924 }
2925 traits_type::assign(__p[__ip], __c);
2926 traits_type::assign(__p[++__sz], value_type());
2927 __set_size(__sz);
2928 return begin() + static_cast<difference_type>(__ip);
2929}
2930
2931template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002932inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002933typename basic_string<_CharT, _Traits, _Allocator>::iterator
2934basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2935{
Howard Hinnant499cea12013-08-23 17:37:05 +00002936#if _LIBCPP_DEBUG_LEVEL >= 2
2937 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2938 "string::insert(iterator, n, value) called with an iterator not"
2939 " referring to this string");
2940#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002941 difference_type __p = __pos - begin();
2942 insert(static_cast<size_type>(__p), __n, __c);
2943 return begin() + __p;
2944}
2945
2946// replace
2947
2948template <class _CharT, class _Traits, class _Allocator>
2949basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002950basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002951{
Alp Tokerec34c482014-05-15 11:27:39 +00002952 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002953 size_type __sz = size();
2954 if (__pos > __sz)
2955 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002956 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002957 size_type __cap = capacity();
2958 if (__cap - __sz + __n1 >= __n2)
2959 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002960 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002961 if (__n1 != __n2)
2962 {
2963 size_type __n_move = __sz - __pos - __n1;
2964 if (__n_move != 0)
2965 {
2966 if (__n1 > __n2)
2967 {
2968 traits_type::move(__p + __pos, __s, __n2);
2969 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2970 goto __finish;
2971 }
2972 if (__p + __pos < __s && __s < __p + __sz)
2973 {
2974 if (__p + __pos + __n1 <= __s)
2975 __s += __n2 - __n1;
2976 else // __p + __pos < __s < __p + __pos + __n1
2977 {
2978 traits_type::move(__p + __pos, __s, __n1);
2979 __pos += __n1;
2980 __s += __n2;
2981 __n2 -= __n1;
2982 __n1 = 0;
2983 }
2984 }
2985 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2986 }
2987 }
2988 traits_type::move(__p + __pos, __s, __n2);
2989__finish:
2990 __sz += __n2 - __n1;
2991 __set_size(__sz);
2992 __invalidate_iterators_past(__sz);
2993 traits_type::assign(__p[__sz], value_type());
2994 }
2995 else
2996 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2997 return *this;
2998}
2999
3000template <class _CharT, class _Traits, class _Allocator>
3001basic_string<_CharT, _Traits, _Allocator>&
3002basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
3003{
3004 size_type __sz = size();
3005 if (__pos > __sz)
3006 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003007 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003008 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003009 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003010 if (__cap - __sz + __n1 >= __n2)
3011 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003012 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003013 if (__n1 != __n2)
3014 {
3015 size_type __n_move = __sz - __pos - __n1;
3016 if (__n_move != 0)
3017 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
3018 }
3019 }
3020 else
3021 {
3022 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003023 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003024 }
3025 traits_type::assign(__p + __pos, __n2, __c);
3026 __sz += __n2 - __n1;
3027 __set_size(__sz);
3028 __invalidate_iterators_past(__sz);
3029 traits_type::assign(__p[__sz], value_type());
3030 return *this;
3031}
3032
3033template <class _CharT, class _Traits, class _Allocator>
3034template<class _InputIterator>
3035typename enable_if
3036<
3037 __is_input_iterator<_InputIterator>::value,
3038 basic_string<_CharT, _Traits, _Allocator>&
3039>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003040basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003041 _InputIterator __j1, _InputIterator __j2)
3042{
Marshall Clowdf9db312016-01-13 21:54:34 +00003043 basic_string __temp(__j1, __j2, __alloc());
3044 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003045}
3046
3047template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003048inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003049basic_string<_CharT, _Traits, _Allocator>&
3050basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
3051{
3052 return replace(__pos1, __n1, __str.data(), __str.size());
3053}
3054
3055template <class _CharT, class _Traits, class _Allocator>
3056basic_string<_CharT, _Traits, _Allocator>&
3057basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
3058 size_type __pos2, size_type __n2)
3059{
3060 size_type __str_sz = __str.size();
3061 if (__pos2 > __str_sz)
3062 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003063 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003064}
3065
3066template <class _CharT, class _Traits, class _Allocator>
3067basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003068basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003069{
Alp Tokerec34c482014-05-15 11:27:39 +00003070 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003071 return replace(__pos, __n1, __s, traits_type::length(__s));
3072}
3073
3074template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003075inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003076basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003077basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003078{
3079 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
3080 __str.data(), __str.size());
3081}
3082
3083template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003084inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003085basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003086basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003087{
3088 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
3089}
3090
3091template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003092inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003093basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003094basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003095{
3096 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
3097}
3098
3099template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003100inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003101basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003102basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003103{
3104 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
3105}
3106
3107// erase
3108
3109template <class _CharT, class _Traits, class _Allocator>
3110basic_string<_CharT, _Traits, _Allocator>&
3111basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
3112{
3113 size_type __sz = size();
3114 if (__pos > __sz)
3115 this->__throw_out_of_range();
3116 if (__n)
3117 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003118 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00003119 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003120 size_type __n_move = __sz - __pos - __n;
3121 if (__n_move != 0)
3122 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3123 __sz -= __n;
3124 __set_size(__sz);
3125 __invalidate_iterators_past(__sz);
3126 traits_type::assign(__p[__sz], value_type());
3127 }
3128 return *this;
3129}
3130
3131template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003132inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003133typename basic_string<_CharT, _Traits, _Allocator>::iterator
3134basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3135{
Howard Hinnant499cea12013-08-23 17:37:05 +00003136#if _LIBCPP_DEBUG_LEVEL >= 2
3137 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3138 "string::erase(iterator) called with an iterator not"
3139 " referring to this string");
3140#endif
3141 _LIBCPP_ASSERT(__pos != end(),
3142 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003143 iterator __b = begin();
3144 size_type __r = static_cast<size_type>(__pos - __b);
3145 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00003146 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003147}
3148
3149template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003150inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003151typename basic_string<_CharT, _Traits, _Allocator>::iterator
3152basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3153{
Howard Hinnant499cea12013-08-23 17:37:05 +00003154#if _LIBCPP_DEBUG_LEVEL >= 2
3155 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3156 "string::erase(iterator, iterator) called with an iterator not"
3157 " referring to this string");
3158#endif
3159 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003160 iterator __b = begin();
3161 size_type __r = static_cast<size_type>(__first - __b);
3162 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00003163 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003164}
3165
3166template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003167inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003168void
3169basic_string<_CharT, _Traits, _Allocator>::pop_back()
3170{
Howard Hinnant499cea12013-08-23 17:37:05 +00003171 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003172 size_type __sz;
3173 if (__is_long())
3174 {
3175 __sz = __get_long_size() - 1;
3176 __set_long_size(__sz);
3177 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3178 }
3179 else
3180 {
3181 __sz = __get_short_size() - 1;
3182 __set_short_size(__sz);
3183 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3184 }
3185 __invalidate_iterators_past(__sz);
3186}
3187
3188template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003189inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003190void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003191basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003192{
3193 __invalidate_all_iterators();
3194 if (__is_long())
3195 {
3196 traits_type::assign(*__get_long_pointer(), value_type());
3197 __set_long_size(0);
3198 }
3199 else
3200 {
3201 traits_type::assign(*__get_short_pointer(), value_type());
3202 __set_short_size(0);
3203 }
3204}
3205
3206template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003207inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003208void
3209basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3210{
3211 if (__is_long())
3212 {
3213 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3214 __set_long_size(__pos);
3215 }
3216 else
3217 {
3218 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3219 __set_short_size(__pos);
3220 }
3221 __invalidate_iterators_past(__pos);
3222}
3223
3224template <class _CharT, class _Traits, class _Allocator>
3225void
3226basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3227{
3228 size_type __sz = size();
3229 if (__n > __sz)
3230 append(__n - __sz, __c);
3231 else
3232 __erase_to_end(__n);
3233}
3234
3235template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003236inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003237typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003238basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003239{
Howard Hinnante32b5e22010-11-17 17:55:08 +00003240 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003241#if _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00003242 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003243#else
Marshall Clow09f85502013-10-31 17:23:08 +00003244 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003245#endif
3246}
3247
3248template <class _CharT, class _Traits, class _Allocator>
3249void
3250basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3251{
3252 if (__res_arg > max_size())
3253 this->__throw_length_error();
3254 size_type __cap = capacity();
3255 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003256 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003257 __res_arg = __recommend(__res_arg);
3258 if (__res_arg != __cap)
3259 {
3260 pointer __new_data, __p;
3261 bool __was_long, __now_long;
3262 if (__res_arg == __min_cap - 1)
3263 {
3264 __was_long = true;
3265 __now_long = false;
3266 __new_data = __get_short_pointer();
3267 __p = __get_long_pointer();
3268 }
3269 else
3270 {
3271 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003272 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003273 else
3274 {
3275 #ifndef _LIBCPP_NO_EXCEPTIONS
3276 try
3277 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003278 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00003279 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003280 #ifndef _LIBCPP_NO_EXCEPTIONS
3281 }
3282 catch (...)
3283 {
3284 return;
3285 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003286 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003287 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003288 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003289 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003290 }
3291 __now_long = true;
3292 __was_long = __is_long();
3293 __p = __get_pointer();
3294 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003295 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3296 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003297 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003298 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003299 if (__now_long)
3300 {
3301 __set_long_cap(__res_arg+1);
3302 __set_long_size(__sz);
3303 __set_long_pointer(__new_data);
3304 }
3305 else
3306 __set_short_size(__sz);
3307 __invalidate_all_iterators();
3308 }
3309}
3310
3311template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003312inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003313typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3314basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
3315{
Howard Hinnant499cea12013-08-23 17:37:05 +00003316 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003317 return *(data() + __pos);
3318}
3319
3320template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003321inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003322typename basic_string<_CharT, _Traits, _Allocator>::reference
3323basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
3324{
Howard Hinnant499cea12013-08-23 17:37:05 +00003325 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003326 return *(__get_pointer() + __pos);
3327}
3328
3329template <class _CharT, class _Traits, class _Allocator>
3330typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3331basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3332{
3333 if (__n >= size())
3334 this->__throw_out_of_range();
3335 return (*this)[__n];
3336}
3337
3338template <class _CharT, class _Traits, class _Allocator>
3339typename basic_string<_CharT, _Traits, _Allocator>::reference
3340basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3341{
3342 if (__n >= size())
3343 this->__throw_out_of_range();
3344 return (*this)[__n];
3345}
3346
3347template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003348inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003349typename basic_string<_CharT, _Traits, _Allocator>::reference
3350basic_string<_CharT, _Traits, _Allocator>::front()
3351{
Howard Hinnant499cea12013-08-23 17:37:05 +00003352 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003353 return *__get_pointer();
3354}
3355
3356template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003357inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003358typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3359basic_string<_CharT, _Traits, _Allocator>::front() const
3360{
Howard Hinnant499cea12013-08-23 17:37:05 +00003361 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003362 return *data();
3363}
3364
3365template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003366inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003367typename basic_string<_CharT, _Traits, _Allocator>::reference
3368basic_string<_CharT, _Traits, _Allocator>::back()
3369{
Howard Hinnant499cea12013-08-23 17:37:05 +00003370 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003371 return *(__get_pointer() + size() - 1);
3372}
3373
3374template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003375inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003376typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3377basic_string<_CharT, _Traits, _Allocator>::back() const
3378{
Howard Hinnant499cea12013-08-23 17:37:05 +00003379 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003380 return *(data() + size() - 1);
3381}
3382
3383template <class _CharT, class _Traits, class _Allocator>
3384typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003385basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003386{
3387 size_type __sz = size();
3388 if (__pos > __sz)
3389 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003390 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003391 traits_type::copy(__s, data() + __pos, __rlen);
3392 return __rlen;
3393}
3394
3395template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003396inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003397basic_string<_CharT, _Traits, _Allocator>
3398basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3399{
3400 return basic_string(*this, __pos, __n, __alloc());
3401}
3402
3403template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003404inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003405void
3406basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00003407#if _LIBCPP_STD_VER >= 14
3408 _NOEXCEPT
3409#else
3410 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3411 __is_nothrow_swappable<allocator_type>::value)
3412#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003413{
Howard Hinnant499cea12013-08-23 17:37:05 +00003414#if _LIBCPP_DEBUG_LEVEL >= 2
3415 if (!__is_long())
3416 __get_db()->__invalidate_all(this);
3417 if (!__str.__is_long())
3418 __get_db()->__invalidate_all(&__str);
3419 __get_db()->swap(this, &__str);
3420#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00003421 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00003422 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003423}
3424
3425// find
3426
3427template <class _Traits>
3428struct _LIBCPP_HIDDEN __traits_eq
3429{
3430 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003431 _LIBCPP_INLINE_VISIBILITY
3432 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3433 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003434};
3435
3436template<class _CharT, class _Traits, class _Allocator>
3437typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003438basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003439 size_type __pos,
3440 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003441{
Alp Tokerec34c482014-05-15 11:27:39 +00003442 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003443 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003444 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003445}
3446
3447template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003448inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003449typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003450basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3451 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003452{
Marshall Clow37025e12014-06-10 18:51:55 +00003453 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003454 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003455}
3456
3457template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003458inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003459typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003460basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003461 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003462{
Alp Tokerec34c482014-05-15 11:27:39 +00003463 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003464 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003465 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003466}
3467
3468template<class _CharT, class _Traits, class _Allocator>
3469typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003470basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3471 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003472{
Marshall Clow37025e12014-06-10 18:51:55 +00003473 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003474 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003475}
3476
3477// rfind
3478
3479template<class _CharT, class _Traits, class _Allocator>
3480typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003481basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003482 size_type __pos,
3483 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003484{
Alp Tokerec34c482014-05-15 11:27:39 +00003485 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003486 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003487 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003488}
3489
3490template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003491inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003492typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003493basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3494 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003495{
Marshall Clow37025e12014-06-10 18:51:55 +00003496 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003497 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003498}
3499
3500template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003501inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003502typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003503basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003504 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003505{
Alp Tokerec34c482014-05-15 11:27:39 +00003506 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003507 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003508 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003509}
3510
3511template<class _CharT, class _Traits, class _Allocator>
3512typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003513basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3514 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003515{
Marshall Clow37025e12014-06-10 18:51:55 +00003516 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003517 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003518}
3519
3520// find_first_of
3521
3522template<class _CharT, class _Traits, class _Allocator>
3523typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003524basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003525 size_type __pos,
3526 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003527{
Alp Tokerec34c482014-05-15 11:27:39 +00003528 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003529 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003530 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003531}
3532
3533template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003534inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003535typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003536basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3537 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003538{
Marshall Clow37025e12014-06-10 18:51:55 +00003539 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003540 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003541}
3542
3543template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003544inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003545typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003546basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003547 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003548{
Alp Tokerec34c482014-05-15 11:27:39 +00003549 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003550 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003551 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003552}
3553
3554template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003555inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003556typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003557basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3558 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003559{
3560 return find(__c, __pos);
3561}
3562
3563// find_last_of
3564
3565template<class _CharT, class _Traits, class _Allocator>
3566typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003567basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003568 size_type __pos,
3569 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003570{
Alp Tokerec34c482014-05-15 11:27:39 +00003571 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003572 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003573 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003574}
3575
3576template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003577inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003578typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003579basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3580 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003581{
Marshall Clow37025e12014-06-10 18:51:55 +00003582 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003583 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003584}
3585
3586template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003587inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003588typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003589basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003590 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003591{
Alp Tokerec34c482014-05-15 11:27:39 +00003592 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003593 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003594 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003595}
3596
3597template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003598inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003599typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003600basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3601 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003602{
3603 return rfind(__c, __pos);
3604}
3605
3606// find_first_not_of
3607
3608template<class _CharT, class _Traits, class _Allocator>
3609typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003610basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003611 size_type __pos,
3612 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003613{
Alp Tokerec34c482014-05-15 11:27:39 +00003614 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003615 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003616 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003617}
3618
3619template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003620inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003621typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003622basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3623 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003624{
Marshall Clow37025e12014-06-10 18:51:55 +00003625 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003626 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003627}
3628
3629template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003630inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003631typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003632basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003633 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003634{
Alp Tokerec34c482014-05-15 11:27:39 +00003635 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003636 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003637 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003638}
3639
3640template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003641inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003642typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003643basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3644 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003645{
Marshall Clow37025e12014-06-10 18:51:55 +00003646 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003647 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003648}
3649
3650// find_last_not_of
3651
3652template<class _CharT, class _Traits, class _Allocator>
3653typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003654basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003655 size_type __pos,
3656 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003657{
Alp Tokerec34c482014-05-15 11:27:39 +00003658 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003659 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003660 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003661}
3662
3663template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003664inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003665typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003666basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3667 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003668{
Marshall Clow37025e12014-06-10 18:51:55 +00003669 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003670 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003671}
3672
3673template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003674inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003675typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003676basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003677 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003678{
Alp Tokerec34c482014-05-15 11:27:39 +00003679 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003680 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003681 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003682}
3683
3684template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003685inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003686typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003687basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3688 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003689{
Marshall Clow37025e12014-06-10 18:51:55 +00003690 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003691 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003692}
3693
3694// compare
3695
3696template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003697inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003698int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003699basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003700{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003701 size_t __lhs_sz = size();
3702 size_t __rhs_sz = __str.size();
3703 int __result = traits_type::compare(data(), __str.data(),
3704 _VSTD::min(__lhs_sz, __rhs_sz));
3705 if (__result != 0)
3706 return __result;
3707 if (__lhs_sz < __rhs_sz)
3708 return -1;
3709 if (__lhs_sz > __rhs_sz)
3710 return 1;
3711 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003712}
3713
3714template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003715inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003716int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003717basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3718 size_type __n1,
3719 const basic_string& __str) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003720{
3721 return compare(__pos1, __n1, __str.data(), __str.size());
3722}
3723
3724template <class _CharT, class _Traits, class _Allocator>
3725int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003726basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3727 size_type __n1,
3728 const basic_string& __str,
3729 size_type __pos2,
3730 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003731{
3732 size_type __sz = __str.size();
3733 if (__pos2 > __sz)
3734 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003735 return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003736 __sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003737}
3738
3739template <class _CharT, class _Traits, class _Allocator>
3740int
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003741basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003742{
Alp Tokerec34c482014-05-15 11:27:39 +00003743 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003744 return compare(0, npos, __s, traits_type::length(__s));
3745}
3746
3747template <class _CharT, class _Traits, class _Allocator>
3748int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003749basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3750 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003751 const value_type* __s) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003752{
Alp Tokerec34c482014-05-15 11:27:39 +00003753 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003754 return compare(__pos1, __n1, __s, traits_type::length(__s));
3755}
3756
3757template <class _CharT, class _Traits, class _Allocator>
3758int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003759basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3760 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003761 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003762 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003763{
Alp Tokerec34c482014-05-15 11:27:39 +00003764 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003765 size_type __sz = size();
3766 if (__pos1 > __sz || __n2 == npos)
3767 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003768 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3769 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003770 if (__r == 0)
3771 {
3772 if (__rlen < __n2)
3773 __r = -1;
3774 else if (__rlen > __n2)
3775 __r = 1;
3776 }
3777 return __r;
3778}
3779
3780// __invariants
3781
3782template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003783inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003784bool
3785basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3786{
3787 if (size() > capacity())
3788 return false;
3789 if (capacity() < __min_cap - 1)
3790 return false;
3791 if (data() == 0)
3792 return false;
3793 if (data()[size()] != value_type(0))
3794 return false;
3795 return true;
3796}
3797
3798// operator==
3799
3800template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003801inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003802bool
3803operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003804 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003805{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003806 size_t __lhs_sz = __lhs.size();
3807 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3808 __rhs.data(),
3809 __lhs_sz) == 0;
3810}
3811
3812template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003813inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003814bool
3815operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3816 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3817{
3818 size_t __lhs_sz = __lhs.size();
3819 if (__lhs_sz != __rhs.size())
3820 return false;
3821 const char* __lp = __lhs.data();
3822 const char* __rp = __rhs.data();
3823 if (__lhs.__is_long())
3824 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3825 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3826 if (*__lp != *__rp)
3827 return false;
3828 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003829}
3830
3831template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003832inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003833bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003834operator==(const _CharT* __lhs,
3835 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003836{
Eric Fiselier4f241822015-08-28 03:02:37 +00003837 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3838 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3839 size_t __lhs_len = _Traits::length(__lhs);
3840 if (__lhs_len != __rhs.size()) return false;
3841 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003842}
3843
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003844template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003845inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003846bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003847operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3848 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003849{
Eric Fiselier4f241822015-08-28 03:02:37 +00003850 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3851 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3852 size_t __rhs_len = _Traits::length(__rhs);
3853 if (__rhs_len != __lhs.size()) return false;
3854 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003855}
3856
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003857// operator!=
3858
Howard Hinnant324bb032010-08-22 00:02:43 +00003859template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003860inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003861bool
3862operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003863 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003864{
3865 return !(__lhs == __rhs);
3866}
3867
3868template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003869inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003870bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003871operator!=(const _CharT* __lhs,
3872 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003873{
3874 return !(__lhs == __rhs);
3875}
3876
3877template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003878inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003879bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003880operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3881 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003882{
3883 return !(__lhs == __rhs);
3884}
3885
3886// operator<
3887
3888template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003889inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003890bool
3891operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003892 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003893{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003894 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003895}
3896
3897template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003898inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003899bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003900operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3901 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003902{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003903 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003904}
3905
3906template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003907inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003908bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003909operator< (const _CharT* __lhs,
3910 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003911{
3912 return __rhs.compare(__lhs) > 0;
3913}
3914
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003915// operator>
3916
3917template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003918inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003919bool
3920operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003921 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003922{
3923 return __rhs < __lhs;
3924}
3925
3926template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003927inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003928bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003929operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3930 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003931{
3932 return __rhs < __lhs;
3933}
3934
3935template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003936inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003937bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003938operator> (const _CharT* __lhs,
3939 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003940{
3941 return __rhs < __lhs;
3942}
3943
3944// operator<=
3945
3946template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003947inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003948bool
3949operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003950 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003951{
3952 return !(__rhs < __lhs);
3953}
3954
3955template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003956inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003957bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003958operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3959 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003960{
3961 return !(__rhs < __lhs);
3962}
3963
3964template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003965inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003966bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003967operator<=(const _CharT* __lhs,
3968 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003969{
3970 return !(__rhs < __lhs);
3971}
3972
3973// operator>=
3974
3975template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003976inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003977bool
3978operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003979 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003980{
3981 return !(__lhs < __rhs);
3982}
3983
3984template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003985inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003986bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003987operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3988 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003989{
3990 return !(__lhs < __rhs);
3991}
3992
3993template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003994inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003995bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003996operator>=(const _CharT* __lhs,
3997 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003998{
3999 return !(__lhs < __rhs);
4000}
4001
4002// operator +
4003
4004template<class _CharT, class _Traits, class _Allocator>
4005basic_string<_CharT, _Traits, _Allocator>
4006operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4007 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4008{
4009 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4010 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4011 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4012 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4013 __r.append(__rhs.data(), __rhs_sz);
4014 return __r;
4015}
4016
4017template<class _CharT, class _Traits, class _Allocator>
4018basic_string<_CharT, _Traits, _Allocator>
4019operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4020{
4021 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4022 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4023 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4024 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4025 __r.append(__rhs.data(), __rhs_sz);
4026 return __r;
4027}
4028
4029template<class _CharT, class _Traits, class _Allocator>
4030basic_string<_CharT, _Traits, _Allocator>
4031operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4032{
4033 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4034 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4035 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4036 __r.append(__rhs.data(), __rhs_sz);
4037 return __r;
4038}
4039
4040template<class _CharT, class _Traits, class _Allocator>
4041basic_string<_CharT, _Traits, _Allocator>
4042operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4043{
4044 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4045 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4046 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4047 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4048 __r.append(__rhs, __rhs_sz);
4049 return __r;
4050}
4051
4052template<class _CharT, class _Traits, class _Allocator>
4053basic_string<_CharT, _Traits, _Allocator>
4054operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4055{
4056 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4057 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4058 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4059 __r.push_back(__rhs);
4060 return __r;
4061}
4062
Howard Hinnant73d21a42010-09-04 23:28:19 +00004063#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004064
4065template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004066inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004067basic_string<_CharT, _Traits, _Allocator>
4068operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4069{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004070 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004071}
4072
4073template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004074inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004075basic_string<_CharT, _Traits, _Allocator>
4076operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4077{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004078 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004079}
4080
4081template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004082inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004083basic_string<_CharT, _Traits, _Allocator>
4084operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4085{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004086 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004087}
4088
4089template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004090inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004091basic_string<_CharT, _Traits, _Allocator>
4092operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4093{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004094 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004095}
4096
4097template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004098inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004099basic_string<_CharT, _Traits, _Allocator>
4100operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4101{
4102 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004103 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004104}
4105
4106template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004107inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004108basic_string<_CharT, _Traits, _Allocator>
4109operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4110{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004111 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004112}
4113
4114template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004115inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004116basic_string<_CharT, _Traits, _Allocator>
4117operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4118{
4119 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004120 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004121}
4122
Howard Hinnant73d21a42010-09-04 23:28:19 +00004123#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004124
4125// swap
4126
4127template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004128inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004129void
Howard Hinnanta6119a82011-05-29 19:57:12 +00004130swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00004131 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4132 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004133{
4134 __lhs.swap(__rhs);
4135}
4136
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004137#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
4138
4139typedef basic_string<char16_t> u16string;
4140typedef basic_string<char32_t> u32string;
4141
Howard Hinnant324bb032010-08-22 00:02:43 +00004142#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004143
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004144_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4145_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4146_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4147_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4148_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004149
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004150_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4151_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4152_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004153
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004154_LIBCPP_FUNC_VIS string to_string(int __val);
4155_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4156_LIBCPP_FUNC_VIS string to_string(long __val);
4157_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4158_LIBCPP_FUNC_VIS string to_string(long long __val);
4159_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4160_LIBCPP_FUNC_VIS string to_string(float __val);
4161_LIBCPP_FUNC_VIS string to_string(double __val);
4162_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004163
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004164_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4165_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4166_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4167_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4168_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004169
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004170_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4171_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4172_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004173
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004174_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4175_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4176_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4177_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4178_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4179_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4180_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4181_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4182_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004183
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004184template<class _CharT, class _Traits, class _Allocator>
4185 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4186 basic_string<_CharT, _Traits, _Allocator>::npos;
4187
4188template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004189struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004190 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4191{
4192 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004193 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004194};
4195
4196template<class _CharT, class _Traits, class _Allocator>
4197size_t
4198hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004199 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004200{
Sean Huntaffd9e52011-07-29 23:31:56 +00004201 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004202}
4203
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004204template<class _CharT, class _Traits, class _Allocator>
4205basic_ostream<_CharT, _Traits>&
4206operator<<(basic_ostream<_CharT, _Traits>& __os,
4207 const basic_string<_CharT, _Traits, _Allocator>& __str);
4208
4209template<class _CharT, class _Traits, class _Allocator>
4210basic_istream<_CharT, _Traits>&
4211operator>>(basic_istream<_CharT, _Traits>& __is,
4212 basic_string<_CharT, _Traits, _Allocator>& __str);
4213
4214template<class _CharT, class _Traits, class _Allocator>
4215basic_istream<_CharT, _Traits>&
4216getline(basic_istream<_CharT, _Traits>& __is,
4217 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4218
4219template<class _CharT, class _Traits, class _Allocator>
4220inline _LIBCPP_INLINE_VISIBILITY
4221basic_istream<_CharT, _Traits>&
4222getline(basic_istream<_CharT, _Traits>& __is,
4223 basic_string<_CharT, _Traits, _Allocator>& __str);
4224
4225#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4226
4227template<class _CharT, class _Traits, class _Allocator>
4228inline _LIBCPP_INLINE_VISIBILITY
4229basic_istream<_CharT, _Traits>&
4230getline(basic_istream<_CharT, _Traits>&& __is,
4231 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4232
4233template<class _CharT, class _Traits, class _Allocator>
4234inline _LIBCPP_INLINE_VISIBILITY
4235basic_istream<_CharT, _Traits>&
4236getline(basic_istream<_CharT, _Traits>&& __is,
4237 basic_string<_CharT, _Traits, _Allocator>& __str);
4238
4239#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4240
Howard Hinnant499cea12013-08-23 17:37:05 +00004241#if _LIBCPP_DEBUG_LEVEL >= 2
4242
4243template<class _CharT, class _Traits, class _Allocator>
4244bool
4245basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4246{
4247 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4248 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4249}
4250
4251template<class _CharT, class _Traits, class _Allocator>
4252bool
4253basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4254{
4255 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4256 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4257}
4258
4259template<class _CharT, class _Traits, class _Allocator>
4260bool
4261basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4262{
4263 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4264 return this->data() <= __p && __p <= this->data() + this->size();
4265}
4266
4267template<class _CharT, class _Traits, class _Allocator>
4268bool
4269basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4270{
4271 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4272 return this->data() <= __p && __p < this->data() + this->size();
4273}
4274
4275#endif // _LIBCPP_DEBUG_LEVEL >= 2
4276
Marshall Clow15234322013-07-23 17:05:24 +00004277#if _LIBCPP_STD_VER > 11
4278// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004279inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004280{
4281 inline namespace string_literals
4282 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004283 inline _LIBCPP_INLINE_VISIBILITY
4284 basic_string<char> operator "" s( const char *__str, size_t __len )
4285 {
4286 return basic_string<char> (__str, __len);
4287 }
Marshall Clow15234322013-07-23 17:05:24 +00004288
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004289 inline _LIBCPP_INLINE_VISIBILITY
4290 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4291 {
4292 return basic_string<wchar_t> (__str, __len);
4293 }
Marshall Clow15234322013-07-23 17:05:24 +00004294
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004295 inline _LIBCPP_INLINE_VISIBILITY
4296 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4297 {
4298 return basic_string<char16_t> (__str, __len);
4299 }
Marshall Clow15234322013-07-23 17:05:24 +00004300
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004301 inline _LIBCPP_INLINE_VISIBILITY
4302 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4303 {
4304 return basic_string<char32_t> (__str, __len);
4305 }
Marshall Clow15234322013-07-23 17:05:24 +00004306 }
4307}
4308#endif
4309
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004310_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>)
4311_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>)
Howard Hinnant499cea12013-08-23 17:37:05 +00004312_LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004313
4314_LIBCPP_END_NAMESPACE_STD
4315
4316#endif // _LIBCPP_STRING