string revision 1.1 1 1.1 joerg // -*- C++ -*-
2 1.1 joerg //===--------------------------- string -----------------------------------===//
3 1.1 joerg //
4 1.1 joerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 1.1 joerg // See https://llvm.org/LICENSE.txt for license information.
6 1.1 joerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 1.1 joerg //
8 1.1 joerg //===----------------------------------------------------------------------===//
9 1.1 joerg
10 1.1 joerg #ifndef _LIBCPP_STRING
11 1.1 joerg #define _LIBCPP_STRING
12 1.1 joerg
13 1.1 joerg /*
14 1.1 joerg string synopsis
15 1.1 joerg
16 1.1 joerg namespace std
17 1.1 joerg {
18 1.1 joerg
19 1.1 joerg template <class stateT>
20 1.1 joerg class fpos
21 1.1 joerg {
22 1.1 joerg private:
23 1.1 joerg stateT st;
24 1.1 joerg public:
25 1.1 joerg fpos(streamoff = streamoff());
26 1.1 joerg
27 1.1 joerg operator streamoff() const;
28 1.1 joerg
29 1.1 joerg stateT state() const;
30 1.1 joerg void state(stateT);
31 1.1 joerg
32 1.1 joerg fpos& operator+=(streamoff);
33 1.1 joerg fpos operator+ (streamoff) const;
34 1.1 joerg fpos& operator-=(streamoff);
35 1.1 joerg fpos operator- (streamoff) const;
36 1.1 joerg };
37 1.1 joerg
38 1.1 joerg template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
39 1.1 joerg
40 1.1 joerg template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
41 1.1 joerg template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
42 1.1 joerg
43 1.1 joerg template <class charT>
44 1.1 joerg struct char_traits
45 1.1 joerg {
46 1.1 joerg typedef charT char_type;
47 1.1 joerg typedef ... int_type;
48 1.1 joerg typedef streamoff off_type;
49 1.1 joerg typedef streampos pos_type;
50 1.1 joerg typedef mbstate_t state_type;
51 1.1 joerg
52 1.1 joerg static void assign(char_type& c1, const char_type& c2) noexcept;
53 1.1 joerg static constexpr bool eq(char_type c1, char_type c2) noexcept;
54 1.1 joerg static constexpr bool lt(char_type c1, char_type c2) noexcept;
55 1.1 joerg
56 1.1 joerg static int compare(const char_type* s1, const char_type* s2, size_t n);
57 1.1 joerg static size_t length(const char_type* s);
58 1.1 joerg static const char_type* find(const char_type* s, size_t n, const char_type& a);
59 1.1 joerg static char_type* move(char_type* s1, const char_type* s2, size_t n);
60 1.1 joerg static char_type* copy(char_type* s1, const char_type* s2, size_t n);
61 1.1 joerg static char_type* assign(char_type* s, size_t n, char_type a);
62 1.1 joerg
63 1.1 joerg static constexpr int_type not_eof(int_type c) noexcept;
64 1.1 joerg static constexpr char_type to_char_type(int_type c) noexcept;
65 1.1 joerg static constexpr int_type to_int_type(char_type c) noexcept;
66 1.1 joerg static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
67 1.1 joerg static constexpr int_type eof() noexcept;
68 1.1 joerg };
69 1.1 joerg
70 1.1 joerg template <> struct char_traits<char>;
71 1.1 joerg template <> struct char_traits<wchar_t>;
72 1.1 joerg template <> struct char_traits<char8_t>; // C++20
73 1.1 joerg template <> struct char_traits<char16_t>;
74 1.1 joerg template <> struct char_traits<char32_t>;
75 1.1 joerg
76 1.1 joerg template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
77 1.1 joerg class basic_string
78 1.1 joerg {
79 1.1 joerg public:
80 1.1 joerg // types:
81 1.1 joerg typedef traits traits_type;
82 1.1 joerg typedef typename traits_type::char_type value_type;
83 1.1 joerg typedef Allocator allocator_type;
84 1.1 joerg typedef typename allocator_type::size_type size_type;
85 1.1 joerg typedef typename allocator_type::difference_type difference_type;
86 1.1 joerg typedef typename allocator_type::reference reference;
87 1.1 joerg typedef typename allocator_type::const_reference const_reference;
88 1.1 joerg typedef typename allocator_type::pointer pointer;
89 1.1 joerg typedef typename allocator_type::const_pointer const_pointer;
90 1.1 joerg typedef implementation-defined iterator;
91 1.1 joerg typedef implementation-defined const_iterator;
92 1.1 joerg typedef std::reverse_iterator<iterator> reverse_iterator;
93 1.1 joerg typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
94 1.1 joerg
95 1.1 joerg static const size_type npos = -1;
96 1.1 joerg
97 1.1 joerg basic_string()
98 1.1 joerg noexcept(is_nothrow_default_constructible<allocator_type>::value);
99 1.1 joerg explicit basic_string(const allocator_type& a);
100 1.1 joerg basic_string(const basic_string& str);
101 1.1 joerg basic_string(basic_string&& str)
102 1.1 joerg noexcept(is_nothrow_move_constructible<allocator_type>::value);
103 1.1 joerg basic_string(const basic_string& str, size_type pos,
104 1.1 joerg const allocator_type& a = allocator_type());
105 1.1 joerg basic_string(const basic_string& str, size_type pos, size_type n,
106 1.1 joerg const Allocator& a = Allocator());
107 1.1 joerg template<class T>
108 1.1 joerg basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
109 1.1 joerg template <class T>
110 1.1 joerg explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17
111 1.1 joerg basic_string(const value_type* s, const allocator_type& a = allocator_type());
112 1.1 joerg basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
113 1.1 joerg basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
114 1.1 joerg template<class InputIterator>
115 1.1 joerg basic_string(InputIterator begin, InputIterator end,
116 1.1 joerg const allocator_type& a = allocator_type());
117 1.1 joerg basic_string(initializer_list<value_type>, const Allocator& = Allocator());
118 1.1 joerg basic_string(const basic_string&, const Allocator&);
119 1.1 joerg basic_string(basic_string&&, const Allocator&);
120 1.1 joerg
121 1.1 joerg ~basic_string();
122 1.1 joerg
123 1.1 joerg operator basic_string_view<charT, traits>() const noexcept;
124 1.1 joerg
125 1.1 joerg basic_string& operator=(const basic_string& str);
126 1.1 joerg template <class T>
127 1.1 joerg basic_string& operator=(const T& t); // C++17
128 1.1 joerg basic_string& operator=(basic_string&& str)
129 1.1 joerg noexcept(
130 1.1 joerg allocator_type::propagate_on_container_move_assignment::value ||
131 1.1 joerg allocator_type::is_always_equal::value ); // C++17
132 1.1 joerg basic_string& operator=(const value_type* s);
133 1.1 joerg basic_string& operator=(value_type c);
134 1.1 joerg basic_string& operator=(initializer_list<value_type>);
135 1.1 joerg
136 1.1 joerg iterator begin() noexcept;
137 1.1 joerg const_iterator begin() const noexcept;
138 1.1 joerg iterator end() noexcept;
139 1.1 joerg const_iterator end() const noexcept;
140 1.1 joerg
141 1.1 joerg reverse_iterator rbegin() noexcept;
142 1.1 joerg const_reverse_iterator rbegin() const noexcept;
143 1.1 joerg reverse_iterator rend() noexcept;
144 1.1 joerg const_reverse_iterator rend() const noexcept;
145 1.1 joerg
146 1.1 joerg const_iterator cbegin() const noexcept;
147 1.1 joerg const_iterator cend() const noexcept;
148 1.1 joerg const_reverse_iterator crbegin() const noexcept;
149 1.1 joerg const_reverse_iterator crend() const noexcept;
150 1.1 joerg
151 1.1 joerg size_type size() const noexcept;
152 1.1 joerg size_type length() const noexcept;
153 1.1 joerg size_type max_size() const noexcept;
154 1.1 joerg size_type capacity() const noexcept;
155 1.1 joerg
156 1.1 joerg void resize(size_type n, value_type c);
157 1.1 joerg void resize(size_type n);
158 1.1 joerg
159 1.1 joerg void reserve(size_type res_arg);
160 1.1 joerg void reserve(); // deprecated in C++20
161 1.1 joerg void shrink_to_fit();
162 1.1 joerg void clear() noexcept;
163 1.1 joerg bool empty() const noexcept;
164 1.1 joerg
165 1.1 joerg const_reference operator[](size_type pos) const;
166 1.1 joerg reference operator[](size_type pos);
167 1.1 joerg
168 1.1 joerg const_reference at(size_type n) const;
169 1.1 joerg reference at(size_type n);
170 1.1 joerg
171 1.1 joerg basic_string& operator+=(const basic_string& str);
172 1.1 joerg template <class T>
173 1.1 joerg basic_string& operator+=(const T& t); // C++17
174 1.1 joerg basic_string& operator+=(const value_type* s);
175 1.1 joerg basic_string& operator+=(value_type c);
176 1.1 joerg basic_string& operator+=(initializer_list<value_type>);
177 1.1 joerg
178 1.1 joerg basic_string& append(const basic_string& str);
179 1.1 joerg template <class T>
180 1.1 joerg basic_string& append(const T& t); // C++17
181 1.1 joerg basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
182 1.1 joerg template <class T>
183 1.1 joerg basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
184 1.1 joerg basic_string& append(const value_type* s, size_type n);
185 1.1 joerg basic_string& append(const value_type* s);
186 1.1 joerg basic_string& append(size_type n, value_type c);
187 1.1 joerg template<class InputIterator>
188 1.1 joerg basic_string& append(InputIterator first, InputIterator last);
189 1.1 joerg basic_string& append(initializer_list<value_type>);
190 1.1 joerg
191 1.1 joerg void push_back(value_type c);
192 1.1 joerg void pop_back();
193 1.1 joerg reference front();
194 1.1 joerg const_reference front() const;
195 1.1 joerg reference back();
196 1.1 joerg const_reference back() const;
197 1.1 joerg
198 1.1 joerg basic_string& assign(const basic_string& str);
199 1.1 joerg template <class T>
200 1.1 joerg basic_string& assign(const T& t); // C++17
201 1.1 joerg basic_string& assign(basic_string&& str);
202 1.1 joerg basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
203 1.1 joerg template <class T>
204 1.1 joerg basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
205 1.1 joerg basic_string& assign(const value_type* s, size_type n);
206 1.1 joerg basic_string& assign(const value_type* s);
207 1.1 joerg basic_string& assign(size_type n, value_type c);
208 1.1 joerg template<class InputIterator>
209 1.1 joerg basic_string& assign(InputIterator first, InputIterator last);
210 1.1 joerg basic_string& assign(initializer_list<value_type>);
211 1.1 joerg
212 1.1 joerg basic_string& insert(size_type pos1, const basic_string& str);
213 1.1 joerg template <class T>
214 1.1 joerg basic_string& insert(size_type pos1, const T& t);
215 1.1 joerg basic_string& insert(size_type pos1, const basic_string& str,
216 1.1 joerg size_type pos2, size_type n);
217 1.1 joerg template <class T>
218 1.1 joerg basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
219 1.1 joerg basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
220 1.1 joerg basic_string& insert(size_type pos, const value_type* s);
221 1.1 joerg basic_string& insert(size_type pos, size_type n, value_type c);
222 1.1 joerg iterator insert(const_iterator p, value_type c);
223 1.1 joerg iterator insert(const_iterator p, size_type n, value_type c);
224 1.1 joerg template<class InputIterator>
225 1.1 joerg iterator insert(const_iterator p, InputIterator first, InputIterator last);
226 1.1 joerg iterator insert(const_iterator p, initializer_list<value_type>);
227 1.1 joerg
228 1.1 joerg basic_string& erase(size_type pos = 0, size_type n = npos);
229 1.1 joerg iterator erase(const_iterator position);
230 1.1 joerg iterator erase(const_iterator first, const_iterator last);
231 1.1 joerg
232 1.1 joerg basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
233 1.1 joerg template <class T>
234 1.1 joerg basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17
235 1.1 joerg basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
236 1.1 joerg size_type pos2, size_type n2=npos); // C++14
237 1.1 joerg template <class T>
238 1.1 joerg basic_string& replace(size_type pos1, size_type n1, const T& t,
239 1.1 joerg size_type pos2, size_type n); // C++17
240 1.1 joerg basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
241 1.1 joerg basic_string& replace(size_type pos, size_type n1, const value_type* s);
242 1.1 joerg basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
243 1.1 joerg basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
244 1.1 joerg template <class T>
245 1.1 joerg basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17
246 1.1 joerg basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
247 1.1 joerg basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
248 1.1 joerg basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
249 1.1 joerg template<class InputIterator>
250 1.1 joerg basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
251 1.1 joerg basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
252 1.1 joerg
253 1.1 joerg size_type copy(value_type* s, size_type n, size_type pos = 0) const;
254 1.1 joerg basic_string substr(size_type pos = 0, size_type n = npos) const;
255 1.1 joerg
256 1.1 joerg void swap(basic_string& str)
257 1.1 joerg noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
258 1.1 joerg allocator_traits<allocator_type>::is_always_equal::value); // C++17
259 1.1 joerg
260 1.1 joerg const value_type* c_str() const noexcept;
261 1.1 joerg const value_type* data() const noexcept;
262 1.1 joerg value_type* data() noexcept; // C++17
263 1.1 joerg
264 1.1 joerg allocator_type get_allocator() const noexcept;
265 1.1 joerg
266 1.1 joerg size_type find(const basic_string& str, size_type pos = 0) const noexcept;
267 1.1 joerg template <class T>
268 1.1 joerg size_type find(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension
269 1.1 joerg size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
270 1.1 joerg size_type find(const value_type* s, size_type pos = 0) const noexcept;
271 1.1 joerg size_type find(value_type c, size_type pos = 0) const noexcept;
272 1.1 joerg
273 1.1 joerg size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
274 1.1 joerg template <class T>
275 1.1 joerg size_type rfind(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension
276 1.1 joerg size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
277 1.1 joerg size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
278 1.1 joerg size_type rfind(value_type c, size_type pos = npos) const noexcept;
279 1.1 joerg
280 1.1 joerg size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
281 1.1 joerg template <class T>
282 1.1 joerg size_type find_first_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension
283 1.1 joerg size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
284 1.1 joerg size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
285 1.1 joerg size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
286 1.1 joerg
287 1.1 joerg size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
288 1.1 joerg template <class T>
289 1.1 joerg size_type find_last_of(const T& t, size_type pos = npos) const noexcept noexcept; // C++17, noexcept as an extension
290 1.1 joerg size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
291 1.1 joerg size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
292 1.1 joerg size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
293 1.1 joerg
294 1.1 joerg size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
295 1.1 joerg template <class T>
296 1.1 joerg size_type find_first_not_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension
297 1.1 joerg size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
298 1.1 joerg size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
299 1.1 joerg size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
300 1.1 joerg
301 1.1 joerg size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
302 1.1 joerg template <class T>
303 1.1 joerg size_type find_last_not_of(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension
304 1.1 joerg size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
305 1.1 joerg size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
306 1.1 joerg size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
307 1.1 joerg
308 1.1 joerg int compare(const basic_string& str) const noexcept;
309 1.1 joerg template <class T>
310 1.1 joerg int compare(const T& t) const noexcept; // C++17, noexcept as an extension
311 1.1 joerg int compare(size_type pos1, size_type n1, const basic_string& str) const;
312 1.1 joerg template <class T>
313 1.1 joerg int compare(size_type pos1, size_type n1, const T& t) const; // C++17
314 1.1 joerg int compare(size_type pos1, size_type n1, const basic_string& str,
315 1.1 joerg size_type pos2, size_type n2=npos) const; // C++14
316 1.1 joerg template <class T>
317 1.1 joerg int compare(size_type pos1, size_type n1, const T& t,
318 1.1 joerg size_type pos2, size_type n2=npos) const; // C++17
319 1.1 joerg int compare(const value_type* s) const noexcept;
320 1.1 joerg int compare(size_type pos1, size_type n1, const value_type* s) const;
321 1.1 joerg int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
322 1.1 joerg
323 1.1 joerg bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++20
324 1.1 joerg bool starts_with(charT c) const noexcept; // C++20
325 1.1 joerg bool starts_with(const charT* s) const; // C++20
326 1.1 joerg bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++20
327 1.1 joerg bool ends_with(charT c) const noexcept; // C++20
328 1.1 joerg bool ends_with(const charT* s) const; // C++20
329 1.1 joerg
330 1.1 joerg constexpr bool contains(basic_string_view<charT, traits> sv) const noexcept; // C++2b
331 1.1 joerg constexpr bool contains(charT c) const noexcept; // C++2b
332 1.1 joerg constexpr bool contains(const charT* s) const; // C++2b
333 1.1 joerg
334 1.1 joerg bool __invariants() const;
335 1.1 joerg };
336 1.1 joerg
337 1.1 joerg template<class InputIterator,
338 1.1 joerg class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
339 1.1 joerg basic_string(InputIterator, InputIterator, Allocator = Allocator())
340 1.1 joerg -> basic_string<typename iterator_traits<InputIterator>::value_type,
341 1.1 joerg char_traits<typename iterator_traits<InputIterator>::value_type>,
342 1.1 joerg Allocator>; // C++17
343 1.1 joerg
344 1.1 joerg template<class charT, class traits, class Allocator>
345 1.1 joerg basic_string<charT, traits, Allocator>
346 1.1 joerg operator+(const basic_string<charT, traits, Allocator>& lhs,
347 1.1 joerg const basic_string<charT, traits, Allocator>& rhs);
348 1.1 joerg
349 1.1 joerg template<class charT, class traits, class Allocator>
350 1.1 joerg basic_string<charT, traits, Allocator>
351 1.1 joerg operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
352 1.1 joerg
353 1.1 joerg template<class charT, class traits, class Allocator>
354 1.1 joerg basic_string<charT, traits, Allocator>
355 1.1 joerg operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
356 1.1 joerg
357 1.1 joerg template<class charT, class traits, class Allocator>
358 1.1 joerg basic_string<charT, traits, Allocator>
359 1.1 joerg operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
360 1.1 joerg
361 1.1 joerg template<class charT, class traits, class Allocator>
362 1.1 joerg basic_string<charT, traits, Allocator>
363 1.1 joerg operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
364 1.1 joerg
365 1.1 joerg template<class charT, class traits, class Allocator>
366 1.1 joerg bool operator==(const basic_string<charT, traits, Allocator>& lhs,
367 1.1 joerg const basic_string<charT, traits, Allocator>& rhs) noexcept;
368 1.1 joerg
369 1.1 joerg template<class charT, class traits, class Allocator>
370 1.1 joerg bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
371 1.1 joerg
372 1.1 joerg template<class charT, class traits, class Allocator>
373 1.1 joerg bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
374 1.1 joerg
375 1.1 joerg template<class charT, class traits, class Allocator>
376 1.1 joerg bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
377 1.1 joerg const basic_string<charT, traits, Allocator>& rhs) noexcept;
378 1.1 joerg
379 1.1 joerg template<class charT, class traits, class Allocator>
380 1.1 joerg bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
381 1.1 joerg
382 1.1 joerg template<class charT, class traits, class Allocator>
383 1.1 joerg bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
384 1.1 joerg
385 1.1 joerg template<class charT, class traits, class Allocator>
386 1.1 joerg bool operator< (const basic_string<charT, traits, Allocator>& lhs,
387 1.1 joerg const basic_string<charT, traits, Allocator>& rhs) noexcept;
388 1.1 joerg
389 1.1 joerg template<class charT, class traits, class Allocator>
390 1.1 joerg bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
391 1.1 joerg
392 1.1 joerg template<class charT, class traits, class Allocator>
393 1.1 joerg bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
394 1.1 joerg
395 1.1 joerg template<class charT, class traits, class Allocator>
396 1.1 joerg bool operator> (const basic_string<charT, traits, Allocator>& lhs,
397 1.1 joerg const basic_string<charT, traits, Allocator>& rhs) noexcept;
398 1.1 joerg
399 1.1 joerg template<class charT, class traits, class Allocator>
400 1.1 joerg bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
401 1.1 joerg
402 1.1 joerg template<class charT, class traits, class Allocator>
403 1.1 joerg bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
404 1.1 joerg
405 1.1 joerg template<class charT, class traits, class Allocator>
406 1.1 joerg bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
407 1.1 joerg const basic_string<charT, traits, Allocator>& rhs) noexcept;
408 1.1 joerg
409 1.1 joerg template<class charT, class traits, class Allocator>
410 1.1 joerg bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
411 1.1 joerg
412 1.1 joerg template<class charT, class traits, class Allocator>
413 1.1 joerg bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
414 1.1 joerg
415 1.1 joerg template<class charT, class traits, class Allocator>
416 1.1 joerg bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
417 1.1 joerg const basic_string<charT, traits, Allocator>& rhs) noexcept;
418 1.1 joerg
419 1.1 joerg template<class charT, class traits, class Allocator>
420 1.1 joerg bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
421 1.1 joerg
422 1.1 joerg template<class charT, class traits, class Allocator>
423 1.1 joerg bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
424 1.1 joerg
425 1.1 joerg template<class charT, class traits, class Allocator>
426 1.1 joerg void swap(basic_string<charT, traits, Allocator>& lhs,
427 1.1 joerg basic_string<charT, traits, Allocator>& rhs)
428 1.1 joerg noexcept(noexcept(lhs.swap(rhs)));
429 1.1 joerg
430 1.1 joerg template<class charT, class traits, class Allocator>
431 1.1 joerg basic_istream<charT, traits>&
432 1.1 joerg operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
433 1.1 joerg
434 1.1 joerg template<class charT, class traits, class Allocator>
435 1.1 joerg basic_ostream<charT, traits>&
436 1.1 joerg operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
437 1.1 joerg
438 1.1 joerg template<class charT, class traits, class Allocator>
439 1.1 joerg basic_istream<charT, traits>&
440 1.1 joerg getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
441 1.1 joerg charT delim);
442 1.1 joerg
443 1.1 joerg template<class charT, class traits, class Allocator>
444 1.1 joerg basic_istream<charT, traits>&
445 1.1 joerg getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
446 1.1 joerg
447 1.1 joerg template<class charT, class traits, class Allocator, class U>
448 1.1 joerg typename basic_string<charT, traits, Allocator>::size_type
449 1.1 joerg erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20
450 1.1 joerg template<class charT, class traits, class Allocator, class Predicate>
451 1.1 joerg typename basic_string<charT, traits, Allocator>::size_type
452 1.1 joerg erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20
453 1.1 joerg
454 1.1 joerg typedef basic_string<char> string;
455 1.1 joerg typedef basic_string<wchar_t> wstring;
456 1.1 joerg typedef basic_string<char8_t> u8string; // C++20
457 1.1 joerg typedef basic_string<char16_t> u16string;
458 1.1 joerg typedef basic_string<char32_t> u32string;
459 1.1 joerg
460 1.1 joerg int stoi (const string& str, size_t* idx = nullptr, int base = 10);
461 1.1 joerg long stol (const string& str, size_t* idx = nullptr, int base = 10);
462 1.1 joerg unsigned long stoul (const string& str, size_t* idx = nullptr, int base = 10);
463 1.1 joerg long long stoll (const string& str, size_t* idx = nullptr, int base = 10);
464 1.1 joerg unsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 10);
465 1.1 joerg
466 1.1 joerg float stof (const string& str, size_t* idx = nullptr);
467 1.1 joerg double stod (const string& str, size_t* idx = nullptr);
468 1.1 joerg long double stold(const string& str, size_t* idx = nullptr);
469 1.1 joerg
470 1.1 joerg string to_string(int val);
471 1.1 joerg string to_string(unsigned val);
472 1.1 joerg string to_string(long val);
473 1.1 joerg string to_string(unsigned long val);
474 1.1 joerg string to_string(long long val);
475 1.1 joerg string to_string(unsigned long long val);
476 1.1 joerg string to_string(float val);
477 1.1 joerg string to_string(double val);
478 1.1 joerg string to_string(long double val);
479 1.1 joerg
480 1.1 joerg int stoi (const wstring& str, size_t* idx = nullptr, int base = 10);
481 1.1 joerg long stol (const wstring& str, size_t* idx = nullptr, int base = 10);
482 1.1 joerg unsigned long stoul (const wstring& str, size_t* idx = nullptr, int base = 10);
483 1.1 joerg long long stoll (const wstring& str, size_t* idx = nullptr, int base = 10);
484 1.1 joerg unsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base = 10);
485 1.1 joerg
486 1.1 joerg float stof (const wstring& str, size_t* idx = nullptr);
487 1.1 joerg double stod (const wstring& str, size_t* idx = nullptr);
488 1.1 joerg long double stold(const wstring& str, size_t* idx = nullptr);
489 1.1 joerg
490 1.1 joerg wstring to_wstring(int val);
491 1.1 joerg wstring to_wstring(unsigned val);
492 1.1 joerg wstring to_wstring(long val);
493 1.1 joerg wstring to_wstring(unsigned long val);
494 1.1 joerg wstring to_wstring(long long val);
495 1.1 joerg wstring to_wstring(unsigned long long val);
496 1.1 joerg wstring to_wstring(float val);
497 1.1 joerg wstring to_wstring(double val);
498 1.1 joerg wstring to_wstring(long double val);
499 1.1 joerg
500 1.1 joerg template <> struct hash<string>;
501 1.1 joerg template <> struct hash<u8string>; // C++20
502 1.1 joerg template <> struct hash<u16string>;
503 1.1 joerg template <> struct hash<u32string>;
504 1.1 joerg template <> struct hash<wstring>;
505 1.1 joerg
506 1.1 joerg basic_string<char> operator "" s( const char *str, size_t len ); // C++14
507 1.1 joerg basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
508 1.1 joerg basic_string<char8_t> operator "" s( const char8_t *str, size_t len ); // C++20
509 1.1 joerg basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
510 1.1 joerg basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
511 1.1 joerg
512 1.1 joerg } // std
513 1.1 joerg
514 1.1 joerg */
515 1.1 joerg
516 1.1 joerg #include <__config>
517 1.1 joerg #include <compare>
518 1.1 joerg #include <string_view>
519 1.1 joerg #include <iosfwd>
520 1.1 joerg #include <cstring>
521 1.1 joerg #include <cstdio> // For EOF.
522 1.1 joerg #include <cwchar>
523 1.1 joerg #include <algorithm>
524 1.1 joerg #include <iterator>
525 1.1 joerg #include <utility>
526 1.1 joerg #include <memory>
527 1.1 joerg #include <stdexcept>
528 1.1 joerg #include <type_traits>
529 1.1 joerg #include <initializer_list>
530 1.1 joerg #include <__functional_base>
531 1.1 joerg #include <version>
532 1.1 joerg #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
533 1.1 joerg #include <cstdint>
534 1.1 joerg #endif
535 1.1 joerg
536 1.1 joerg #include <__debug>
537 1.1 joerg
538 1.1 joerg #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
539 1.1 joerg #pragma GCC system_header
540 1.1 joerg #endif
541 1.1 joerg
542 1.1 joerg _LIBCPP_PUSH_MACROS
543 1.1 joerg #include <__undef_macros>
544 1.1 joerg
545 1.1 joerg
546 1.1 joerg _LIBCPP_BEGIN_NAMESPACE_STD
547 1.1 joerg
548 1.1 joerg // fpos
549 1.1 joerg
550 1.1 joerg template <class _StateT>
551 1.1 joerg class _LIBCPP_TEMPLATE_VIS fpos
552 1.1 joerg {
553 1.1 joerg private:
554 1.1 joerg _StateT __st_;
555 1.1 joerg streamoff __off_;
556 1.1 joerg public:
557 1.1 joerg _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
558 1.1 joerg
559 1.1 joerg _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
560 1.1 joerg
561 1.1 joerg _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
562 1.1 joerg _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
563 1.1 joerg
564 1.1 joerg _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
565 1.1 joerg _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
566 1.1 joerg _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
567 1.1 joerg _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
568 1.1 joerg };
569 1.1 joerg
570 1.1 joerg template <class _StateT>
571 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
572 1.1 joerg streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
573 1.1 joerg {return streamoff(__x) - streamoff(__y);}
574 1.1 joerg
575 1.1 joerg template <class _StateT>
576 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
577 1.1 joerg bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
578 1.1 joerg {return streamoff(__x) == streamoff(__y);}
579 1.1 joerg
580 1.1 joerg template <class _StateT>
581 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
582 1.1 joerg bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
583 1.1 joerg {return streamoff(__x) != streamoff(__y);}
584 1.1 joerg
585 1.1 joerg // basic_string
586 1.1 joerg
587 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
588 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
589 1.1 joerg operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
590 1.1 joerg const basic_string<_CharT, _Traits, _Allocator>& __y);
591 1.1 joerg
592 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
593 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
594 1.1 joerg operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
595 1.1 joerg
596 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
597 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
598 1.1 joerg operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
599 1.1 joerg
600 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
601 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
602 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
603 1.1 joerg operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
604 1.1 joerg
605 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
606 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
607 1.1 joerg operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
608 1.1 joerg
609 1.1 joerg _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
610 1.1 joerg
611 1.1 joerg template <bool>
612 1.1 joerg class _LIBCPP_TEMPLATE_VIS __basic_string_common
613 1.1 joerg {
614 1.1 joerg protected:
615 1.1 joerg _LIBCPP_NORETURN void __throw_length_error() const;
616 1.1 joerg _LIBCPP_NORETURN void __throw_out_of_range() const;
617 1.1 joerg };
618 1.1 joerg
619 1.1 joerg template <bool __b>
620 1.1 joerg void
621 1.1 joerg __basic_string_common<__b>::__throw_length_error() const
622 1.1 joerg {
623 1.1 joerg _VSTD::__throw_length_error("basic_string");
624 1.1 joerg }
625 1.1 joerg
626 1.1 joerg template <bool __b>
627 1.1 joerg void
628 1.1 joerg __basic_string_common<__b>::__throw_out_of_range() const
629 1.1 joerg {
630 1.1 joerg _VSTD::__throw_out_of_range("basic_string");
631 1.1 joerg }
632 1.1 joerg
633 1.1 joerg _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
634 1.1 joerg
635 1.1 joerg template <class _Iter>
636 1.1 joerg struct __string_is_trivial_iterator : public false_type {};
637 1.1 joerg
638 1.1 joerg template <class _Tp>
639 1.1 joerg struct __string_is_trivial_iterator<_Tp*>
640 1.1 joerg : public is_arithmetic<_Tp> {};
641 1.1 joerg
642 1.1 joerg template <class _Iter>
643 1.1 joerg struct __string_is_trivial_iterator<__wrap_iter<_Iter> >
644 1.1 joerg : public __string_is_trivial_iterator<_Iter> {};
645 1.1 joerg
646 1.1 joerg template <class _CharT, class _Traits, class _Tp>
647 1.1 joerg struct __can_be_converted_to_string_view : public _BoolConstant<
648 1.1 joerg is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
649 1.1 joerg !is_convertible<const _Tp&, const _CharT*>::value
650 1.1 joerg > {};
651 1.1 joerg
652 1.1 joerg #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
653 1.1 joerg
654 1.1 joerg template <class _CharT, size_t = sizeof(_CharT)>
655 1.1 joerg struct __padding
656 1.1 joerg {
657 1.1 joerg unsigned char __xx[sizeof(_CharT)-1];
658 1.1 joerg };
659 1.1 joerg
660 1.1 joerg template <class _CharT>
661 1.1 joerg struct __padding<_CharT, 1>
662 1.1 joerg {
663 1.1 joerg };
664 1.1 joerg
665 1.1 joerg #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
666 1.1 joerg
667 1.1 joerg #ifndef _LIBCPP_HAS_NO_CHAR8_T
668 1.1 joerg typedef basic_string<char8_t> u8string;
669 1.1 joerg #endif
670 1.1 joerg
671 1.1 joerg #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
672 1.1 joerg typedef basic_string<char16_t> u16string;
673 1.1 joerg typedef basic_string<char32_t> u32string;
674 1.1 joerg #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
675 1.1 joerg
676 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
677 1.1 joerg class
678 1.1 joerg _LIBCPP_TEMPLATE_VIS
679 1.1 joerg #ifndef _LIBCPP_HAS_NO_CHAR8_T
680 1.1 joerg _LIBCPP_PREFERRED_NAME(u8string)
681 1.1 joerg #endif
682 1.1 joerg #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
683 1.1 joerg _LIBCPP_PREFERRED_NAME(u16string)
684 1.1 joerg _LIBCPP_PREFERRED_NAME(u32string)
685 1.1 joerg #endif
686 1.1 joerg basic_string
687 1.1 joerg : private __basic_string_common<true>
688 1.1 joerg {
689 1.1 joerg public:
690 1.1 joerg typedef basic_string __self;
691 1.1 joerg typedef basic_string_view<_CharT, _Traits> __self_view;
692 1.1 joerg typedef _Traits traits_type;
693 1.1 joerg typedef _CharT value_type;
694 1.1 joerg typedef _Allocator allocator_type;
695 1.1 joerg typedef allocator_traits<allocator_type> __alloc_traits;
696 1.1 joerg typedef typename __alloc_traits::size_type size_type;
697 1.1 joerg typedef typename __alloc_traits::difference_type difference_type;
698 1.1 joerg typedef value_type& reference;
699 1.1 joerg typedef const value_type& const_reference;
700 1.1 joerg typedef typename __alloc_traits::pointer pointer;
701 1.1 joerg typedef typename __alloc_traits::const_pointer const_pointer;
702 1.1 joerg
703 1.1 joerg static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
704 1.1 joerg static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
705 1.1 joerg static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
706 1.1 joerg static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
707 1.1 joerg "traits_type::char_type must be the same type as CharT");
708 1.1 joerg static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
709 1.1 joerg "Allocator::value_type must be same type as value_type");
710 1.1 joerg
711 1.1 joerg typedef __wrap_iter<pointer> iterator;
712 1.1 joerg typedef __wrap_iter<const_pointer> const_iterator;
713 1.1 joerg typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
714 1.1 joerg typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
715 1.1 joerg
716 1.1 joerg private:
717 1.1 joerg
718 1.1 joerg #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
719 1.1 joerg
720 1.1 joerg struct __long
721 1.1 joerg {
722 1.1 joerg pointer __data_;
723 1.1 joerg size_type __size_;
724 1.1 joerg size_type __cap_;
725 1.1 joerg };
726 1.1 joerg
727 1.1 joerg #ifdef _LIBCPP_BIG_ENDIAN
728 1.1 joerg static const size_type __short_mask = 0x01;
729 1.1 joerg static const size_type __long_mask = 0x1ul;
730 1.1 joerg #else // _LIBCPP_BIG_ENDIAN
731 1.1 joerg static const size_type __short_mask = 0x80;
732 1.1 joerg static const size_type __long_mask = ~(size_type(~0) >> 1);
733 1.1 joerg #endif // _LIBCPP_BIG_ENDIAN
734 1.1 joerg
735 1.1 joerg enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
736 1.1 joerg (sizeof(__long) - 1)/sizeof(value_type) : 2};
737 1.1 joerg
738 1.1 joerg struct __short
739 1.1 joerg {
740 1.1 joerg value_type __data_[__min_cap];
741 1.1 joerg struct
742 1.1 joerg : __padding<value_type>
743 1.1 joerg {
744 1.1 joerg unsigned char __size_;
745 1.1 joerg };
746 1.1 joerg };
747 1.1 joerg
748 1.1 joerg #else
749 1.1 joerg
750 1.1 joerg struct __long
751 1.1 joerg {
752 1.1 joerg size_type __cap_;
753 1.1 joerg size_type __size_;
754 1.1 joerg pointer __data_;
755 1.1 joerg };
756 1.1 joerg
757 1.1 joerg #ifdef _LIBCPP_BIG_ENDIAN
758 1.1 joerg static const size_type __short_mask = 0x80;
759 1.1 joerg static const size_type __long_mask = ~(size_type(~0) >> 1);
760 1.1 joerg #else // _LIBCPP_BIG_ENDIAN
761 1.1 joerg static const size_type __short_mask = 0x01;
762 1.1 joerg static const size_type __long_mask = 0x1ul;
763 1.1 joerg #endif // _LIBCPP_BIG_ENDIAN
764 1.1 joerg
765 1.1 joerg enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
766 1.1 joerg (sizeof(__long) - 1)/sizeof(value_type) : 2};
767 1.1 joerg
768 1.1 joerg struct __short
769 1.1 joerg {
770 1.1 joerg union
771 1.1 joerg {
772 1.1 joerg unsigned char __size_;
773 1.1 joerg value_type __lx;
774 1.1 joerg };
775 1.1 joerg value_type __data_[__min_cap];
776 1.1 joerg };
777 1.1 joerg
778 1.1 joerg #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
779 1.1 joerg
780 1.1 joerg union __ulx{__long __lx; __short __lxx;};
781 1.1 joerg
782 1.1 joerg enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
783 1.1 joerg
784 1.1 joerg struct __raw
785 1.1 joerg {
786 1.1 joerg size_type __words[__n_words];
787 1.1 joerg };
788 1.1 joerg
789 1.1 joerg struct __rep
790 1.1 joerg {
791 1.1 joerg union
792 1.1 joerg {
793 1.1 joerg __long __l;
794 1.1 joerg __short __s;
795 1.1 joerg __raw __r;
796 1.1 joerg };
797 1.1 joerg };
798 1.1 joerg
799 1.1 joerg __compressed_pair<__rep, allocator_type> __r_;
800 1.1 joerg
801 1.1 joerg public:
802 1.1 joerg _LIBCPP_TEMPLATE_DATA_VIS
803 1.1 joerg static const size_type npos = -1;
804 1.1 joerg
805 1.1 joerg _LIBCPP_INLINE_VISIBILITY basic_string()
806 1.1 joerg _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
807 1.1 joerg
808 1.1 joerg _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
809 1.1 joerg #if _LIBCPP_STD_VER <= 14
810 1.1 joerg _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
811 1.1 joerg #else
812 1.1 joerg _NOEXCEPT;
813 1.1 joerg #endif
814 1.1 joerg
815 1.1 joerg basic_string(const basic_string& __str);
816 1.1 joerg basic_string(const basic_string& __str, const allocator_type& __a);
817 1.1 joerg
818 1.1 joerg #ifndef _LIBCPP_CXX03_LANG
819 1.1 joerg _LIBCPP_INLINE_VISIBILITY
820 1.1 joerg basic_string(basic_string&& __str)
821 1.1 joerg #if _LIBCPP_STD_VER <= 14
822 1.1 joerg _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
823 1.1 joerg #else
824 1.1 joerg _NOEXCEPT;
825 1.1 joerg #endif
826 1.1 joerg
827 1.1 joerg _LIBCPP_INLINE_VISIBILITY
828 1.1 joerg basic_string(basic_string&& __str, const allocator_type& __a);
829 1.1 joerg #endif // _LIBCPP_CXX03_LANG
830 1.1 joerg
831 1.1 joerg template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
832 1.1 joerg _LIBCPP_INLINE_VISIBILITY
833 1.1 joerg basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) {
834 1.1 joerg _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
835 1.1 joerg __init(__s, traits_type::length(__s));
836 1.1 joerg # if _LIBCPP_DEBUG_LEVEL == 2
837 1.1 joerg __get_db()->__insert_c(this);
838 1.1 joerg # endif
839 1.1 joerg }
840 1.1 joerg
841 1.1 joerg template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
842 1.1 joerg _LIBCPP_INLINE_VISIBILITY
843 1.1 joerg basic_string(const _CharT* __s, const _Allocator& __a);
844 1.1 joerg
845 1.1 joerg _LIBCPP_INLINE_VISIBILITY
846 1.1 joerg basic_string(const _CharT* __s, size_type __n);
847 1.1 joerg _LIBCPP_INLINE_VISIBILITY
848 1.1 joerg basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
849 1.1 joerg _LIBCPP_INLINE_VISIBILITY
850 1.1 joerg basic_string(size_type __n, _CharT __c);
851 1.1 joerg
852 1.1 joerg template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
853 1.1 joerg _LIBCPP_INLINE_VISIBILITY
854 1.1 joerg basic_string(size_type __n, _CharT __c, const _Allocator& __a);
855 1.1 joerg
856 1.1 joerg basic_string(const basic_string& __str, size_type __pos, size_type __n,
857 1.1 joerg const _Allocator& __a = _Allocator());
858 1.1 joerg _LIBCPP_INLINE_VISIBILITY
859 1.1 joerg basic_string(const basic_string& __str, size_type __pos,
860 1.1 joerg const _Allocator& __a = _Allocator());
861 1.1 joerg
862 1.1 joerg template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
863 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
864 1.1 joerg basic_string(const _Tp& __t, size_type __pos, size_type __n,
865 1.1 joerg const allocator_type& __a = allocator_type());
866 1.1 joerg
867 1.1 joerg template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
868 1.1 joerg !__is_same_uncvref<_Tp, basic_string>::value> >
869 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
870 1.1 joerg explicit basic_string(const _Tp& __t);
871 1.1 joerg
872 1.1 joerg template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
873 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
874 1.1 joerg explicit basic_string(const _Tp& __t, const allocator_type& __a);
875 1.1 joerg
876 1.1 joerg template<class _InputIterator, class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value> >
877 1.1 joerg _LIBCPP_INLINE_VISIBILITY
878 1.1 joerg basic_string(_InputIterator __first, _InputIterator __last);
879 1.1 joerg template<class _InputIterator, class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value> >
880 1.1 joerg _LIBCPP_INLINE_VISIBILITY
881 1.1 joerg basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
882 1.1 joerg #ifndef _LIBCPP_CXX03_LANG
883 1.1 joerg _LIBCPP_INLINE_VISIBILITY
884 1.1 joerg basic_string(initializer_list<_CharT> __il);
885 1.1 joerg _LIBCPP_INLINE_VISIBILITY
886 1.1 joerg basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
887 1.1 joerg #endif // _LIBCPP_CXX03_LANG
888 1.1 joerg
889 1.1 joerg inline ~basic_string();
890 1.1 joerg
891 1.1 joerg _LIBCPP_INLINE_VISIBILITY
892 1.1 joerg operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
893 1.1 joerg
894 1.1 joerg basic_string& operator=(const basic_string& __str);
895 1.1 joerg
896 1.1 joerg template <class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
897 1.1 joerg basic_string& operator=(const _Tp& __t)
898 1.1 joerg {__self_view __sv = __t; return assign(__sv);}
899 1.1 joerg
900 1.1 joerg #ifndef _LIBCPP_CXX03_LANG
901 1.1 joerg _LIBCPP_INLINE_VISIBILITY
902 1.1 joerg basic_string& operator=(basic_string&& __str)
903 1.1 joerg _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
904 1.1 joerg _LIBCPP_INLINE_VISIBILITY
905 1.1 joerg basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
906 1.1 joerg #endif
907 1.1 joerg _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
908 1.1 joerg basic_string& operator=(value_type __c);
909 1.1 joerg
910 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
911 1.1 joerg _LIBCPP_INLINE_VISIBILITY
912 1.1 joerg iterator begin() _NOEXCEPT
913 1.1 joerg {return iterator(this, __get_pointer());}
914 1.1 joerg _LIBCPP_INLINE_VISIBILITY
915 1.1 joerg const_iterator begin() const _NOEXCEPT
916 1.1 joerg {return const_iterator(this, __get_pointer());}
917 1.1 joerg _LIBCPP_INLINE_VISIBILITY
918 1.1 joerg iterator end() _NOEXCEPT
919 1.1 joerg {return iterator(this, __get_pointer() + size());}
920 1.1 joerg _LIBCPP_INLINE_VISIBILITY
921 1.1 joerg const_iterator end() const _NOEXCEPT
922 1.1 joerg {return const_iterator(this, __get_pointer() + size());}
923 1.1 joerg #else
924 1.1 joerg _LIBCPP_INLINE_VISIBILITY
925 1.1 joerg iterator begin() _NOEXCEPT
926 1.1 joerg {return iterator(__get_pointer());}
927 1.1 joerg _LIBCPP_INLINE_VISIBILITY
928 1.1 joerg const_iterator begin() const _NOEXCEPT
929 1.1 joerg {return const_iterator(__get_pointer());}
930 1.1 joerg _LIBCPP_INLINE_VISIBILITY
931 1.1 joerg iterator end() _NOEXCEPT
932 1.1 joerg {return iterator(__get_pointer() + size());}
933 1.1 joerg _LIBCPP_INLINE_VISIBILITY
934 1.1 joerg const_iterator end() const _NOEXCEPT
935 1.1 joerg {return const_iterator(__get_pointer() + size());}
936 1.1 joerg #endif // _LIBCPP_DEBUG_LEVEL == 2
937 1.1 joerg _LIBCPP_INLINE_VISIBILITY
938 1.1 joerg reverse_iterator rbegin() _NOEXCEPT
939 1.1 joerg {return reverse_iterator(end());}
940 1.1 joerg _LIBCPP_INLINE_VISIBILITY
941 1.1 joerg const_reverse_iterator rbegin() const _NOEXCEPT
942 1.1 joerg {return const_reverse_iterator(end());}
943 1.1 joerg _LIBCPP_INLINE_VISIBILITY
944 1.1 joerg reverse_iterator rend() _NOEXCEPT
945 1.1 joerg {return reverse_iterator(begin());}
946 1.1 joerg _LIBCPP_INLINE_VISIBILITY
947 1.1 joerg const_reverse_iterator rend() const _NOEXCEPT
948 1.1 joerg {return const_reverse_iterator(begin());}
949 1.1 joerg
950 1.1 joerg _LIBCPP_INLINE_VISIBILITY
951 1.1 joerg const_iterator cbegin() const _NOEXCEPT
952 1.1 joerg {return begin();}
953 1.1 joerg _LIBCPP_INLINE_VISIBILITY
954 1.1 joerg const_iterator cend() const _NOEXCEPT
955 1.1 joerg {return end();}
956 1.1 joerg _LIBCPP_INLINE_VISIBILITY
957 1.1 joerg const_reverse_iterator crbegin() const _NOEXCEPT
958 1.1 joerg {return rbegin();}
959 1.1 joerg _LIBCPP_INLINE_VISIBILITY
960 1.1 joerg const_reverse_iterator crend() const _NOEXCEPT
961 1.1 joerg {return rend();}
962 1.1 joerg
963 1.1 joerg _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
964 1.1 joerg {return __is_long() ? __get_long_size() : __get_short_size();}
965 1.1 joerg _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
966 1.1 joerg _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
967 1.1 joerg _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
968 1.1 joerg {return (__is_long() ? __get_long_cap()
969 1.1 joerg : static_cast<size_type>(__min_cap)) - 1;}
970 1.1 joerg
971 1.1 joerg void resize(size_type __n, value_type __c);
972 1.1 joerg _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
973 1.1 joerg
974 1.1 joerg void reserve(size_type __requested_capacity);
975 1.1 joerg _LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n);
976 1.1 joerg
977 1.1 joerg _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_INLINE_VISIBILITY
978 1.1 joerg void reserve() _NOEXCEPT {shrink_to_fit();}
979 1.1 joerg _LIBCPP_INLINE_VISIBILITY
980 1.1 joerg void shrink_to_fit() _NOEXCEPT;
981 1.1 joerg _LIBCPP_INLINE_VISIBILITY
982 1.1 joerg void clear() _NOEXCEPT;
983 1.1 joerg _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
984 1.1 joerg bool empty() const _NOEXCEPT {return size() == 0;}
985 1.1 joerg
986 1.1 joerg _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
987 1.1 joerg _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
988 1.1 joerg
989 1.1 joerg const_reference at(size_type __n) const;
990 1.1 joerg reference at(size_type __n);
991 1.1 joerg
992 1.1 joerg _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
993 1.1 joerg
994 1.1 joerg template <class _Tp>
995 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
996 1.1 joerg _EnableIf
997 1.1 joerg <
998 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
999 1.1 joerg && !__is_same_uncvref<_Tp, basic_string >::value,
1000 1.1 joerg basic_string&
1001 1.1 joerg >
1002 1.1 joerg operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);}
1003 1.1 joerg _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
1004 1.1 joerg _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
1005 1.1 joerg #ifndef _LIBCPP_CXX03_LANG
1006 1.1 joerg _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
1007 1.1 joerg #endif // _LIBCPP_CXX03_LANG
1008 1.1 joerg
1009 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1010 1.1 joerg basic_string& append(const basic_string& __str);
1011 1.1 joerg
1012 1.1 joerg template <class _Tp>
1013 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1014 1.1 joerg _EnableIf<
1015 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1016 1.1 joerg && !__is_same_uncvref<_Tp, basic_string>::value,
1017 1.1 joerg basic_string&
1018 1.1 joerg >
1019 1.1 joerg append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
1020 1.1 joerg basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
1021 1.1 joerg
1022 1.1 joerg template <class _Tp>
1023 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1024 1.1 joerg _EnableIf
1025 1.1 joerg <
1026 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1027 1.1 joerg && !__is_same_uncvref<_Tp, basic_string>::value,
1028 1.1 joerg basic_string&
1029 1.1 joerg >
1030 1.1 joerg append(const _Tp& __t, size_type __pos, size_type __n=npos);
1031 1.1 joerg basic_string& append(const value_type* __s, size_type __n);
1032 1.1 joerg basic_string& append(const value_type* __s);
1033 1.1 joerg basic_string& append(size_type __n, value_type __c);
1034 1.1 joerg
1035 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1036 1.1 joerg void __append_default_init(size_type __n);
1037 1.1 joerg
1038 1.1 joerg template<class _InputIterator>
1039 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1040 1.1 joerg _EnableIf
1041 1.1 joerg <
1042 1.1 joerg __is_exactly_cpp17_input_iterator<_InputIterator>::value,
1043 1.1 joerg basic_string&
1044 1.1 joerg >
1045 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1046 1.1 joerg append(_InputIterator __first, _InputIterator __last) {
1047 1.1 joerg const basic_string __temp(__first, __last, __alloc());
1048 1.1 joerg append(__temp.data(), __temp.size());
1049 1.1 joerg return *this;
1050 1.1 joerg }
1051 1.1 joerg template<class _ForwardIterator>
1052 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1053 1.1 joerg _EnableIf
1054 1.1 joerg <
1055 1.1 joerg __is_cpp17_forward_iterator<_ForwardIterator>::value,
1056 1.1 joerg basic_string&
1057 1.1 joerg >
1058 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1059 1.1 joerg append(_ForwardIterator __first, _ForwardIterator __last);
1060 1.1 joerg
1061 1.1 joerg #ifndef _LIBCPP_CXX03_LANG
1062 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1063 1.1 joerg basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
1064 1.1 joerg #endif // _LIBCPP_CXX03_LANG
1065 1.1 joerg
1066 1.1 joerg void push_back(value_type __c);
1067 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1068 1.1 joerg void pop_back();
1069 1.1 joerg _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT;
1070 1.1 joerg _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT;
1071 1.1 joerg _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT;
1072 1.1 joerg _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT;
1073 1.1 joerg
1074 1.1 joerg template <class _Tp>
1075 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1076 1.1 joerg _EnableIf
1077 1.1 joerg <
1078 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1079 1.1 joerg basic_string&
1080 1.1 joerg >
1081 1.1 joerg assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
1082 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1083 1.1 joerg basic_string& assign(const basic_string& __str) { return *this = __str; }
1084 1.1 joerg #ifndef _LIBCPP_CXX03_LANG
1085 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1086 1.1 joerg basic_string& assign(basic_string&& __str)
1087 1.1 joerg _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
1088 1.1 joerg {*this = _VSTD::move(__str); return *this;}
1089 1.1 joerg #endif
1090 1.1 joerg basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
1091 1.1 joerg template <class _Tp>
1092 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1093 1.1 joerg _EnableIf
1094 1.1 joerg <
1095 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1096 1.1 joerg && !__is_same_uncvref<_Tp, basic_string>::value,
1097 1.1 joerg basic_string&
1098 1.1 joerg >
1099 1.1 joerg assign(const _Tp & __t, size_type __pos, size_type __n=npos);
1100 1.1 joerg basic_string& assign(const value_type* __s, size_type __n);
1101 1.1 joerg basic_string& assign(const value_type* __s);
1102 1.1 joerg basic_string& assign(size_type __n, value_type __c);
1103 1.1 joerg template<class _InputIterator>
1104 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1105 1.1 joerg _EnableIf
1106 1.1 joerg <
1107 1.1 joerg __is_exactly_cpp17_input_iterator<_InputIterator>::value,
1108 1.1 joerg basic_string&
1109 1.1 joerg >
1110 1.1 joerg assign(_InputIterator __first, _InputIterator __last);
1111 1.1 joerg template<class _ForwardIterator>
1112 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1113 1.1 joerg _EnableIf
1114 1.1 joerg <
1115 1.1 joerg __is_cpp17_forward_iterator<_ForwardIterator>::value,
1116 1.1 joerg basic_string&
1117 1.1 joerg >
1118 1.1 joerg assign(_ForwardIterator __first, _ForwardIterator __last);
1119 1.1 joerg #ifndef _LIBCPP_CXX03_LANG
1120 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1121 1.1 joerg basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
1122 1.1 joerg #endif // _LIBCPP_CXX03_LANG
1123 1.1 joerg
1124 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1125 1.1 joerg basic_string& insert(size_type __pos1, const basic_string& __str);
1126 1.1 joerg
1127 1.1 joerg template <class _Tp>
1128 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1129 1.1 joerg _EnableIf
1130 1.1 joerg <
1131 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1132 1.1 joerg basic_string&
1133 1.1 joerg >
1134 1.1 joerg insert(size_type __pos1, const _Tp& __t)
1135 1.1 joerg { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
1136 1.1 joerg
1137 1.1 joerg template <class _Tp>
1138 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1139 1.1 joerg _EnableIf
1140 1.1 joerg <
1141 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
1142 1.1 joerg basic_string&
1143 1.1 joerg >
1144 1.1 joerg insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
1145 1.1 joerg basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
1146 1.1 joerg basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1147 1.1 joerg basic_string& insert(size_type __pos, const value_type* __s);
1148 1.1 joerg basic_string& insert(size_type __pos, size_type __n, value_type __c);
1149 1.1 joerg iterator insert(const_iterator __pos, value_type __c);
1150 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1151 1.1 joerg iterator insert(const_iterator __pos, size_type __n, value_type __c);
1152 1.1 joerg template<class _InputIterator>
1153 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1154 1.1 joerg _EnableIf
1155 1.1 joerg <
1156 1.1 joerg __is_exactly_cpp17_input_iterator<_InputIterator>::value,
1157 1.1 joerg iterator
1158 1.1 joerg >
1159 1.1 joerg insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1160 1.1 joerg template<class _ForwardIterator>
1161 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1162 1.1 joerg _EnableIf
1163 1.1 joerg <
1164 1.1 joerg __is_cpp17_forward_iterator<_ForwardIterator>::value,
1165 1.1 joerg iterator
1166 1.1 joerg >
1167 1.1 joerg insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
1168 1.1 joerg #ifndef _LIBCPP_CXX03_LANG
1169 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1170 1.1 joerg iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1171 1.1 joerg {return insert(__pos, __il.begin(), __il.end());}
1172 1.1 joerg #endif // _LIBCPP_CXX03_LANG
1173 1.1 joerg
1174 1.1 joerg basic_string& erase(size_type __pos = 0, size_type __n = npos);
1175 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1176 1.1 joerg iterator erase(const_iterator __pos);
1177 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1178 1.1 joerg iterator erase(const_iterator __first, const_iterator __last);
1179 1.1 joerg
1180 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1181 1.1 joerg basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
1182 1.1 joerg
1183 1.1 joerg template <class _Tp>
1184 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1185 1.1 joerg _EnableIf
1186 1.1 joerg <
1187 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1188 1.1 joerg basic_string&
1189 1.1 joerg >
1190 1.1 joerg replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); }
1191 1.1 joerg basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
1192 1.1 joerg template <class _Tp>
1193 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1194 1.1 joerg _EnableIf
1195 1.1 joerg <
1196 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
1197 1.1 joerg basic_string&
1198 1.1 joerg >
1199 1.1 joerg replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
1200 1.1 joerg basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1201 1.1 joerg basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
1202 1.1 joerg basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
1203 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1204 1.1 joerg basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
1205 1.1 joerg
1206 1.1 joerg template <class _Tp>
1207 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1208 1.1 joerg _EnableIf
1209 1.1 joerg <
1210 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1211 1.1 joerg basic_string&
1212 1.1 joerg >
1213 1.1 joerg replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
1214 1.1 joerg
1215 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1216 1.1 joerg basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
1217 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1218 1.1 joerg basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
1219 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1220 1.1 joerg basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
1221 1.1 joerg template<class _InputIterator>
1222 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1223 1.1 joerg _EnableIf
1224 1.1 joerg <
1225 1.1 joerg __is_cpp17_input_iterator<_InputIterator>::value,
1226 1.1 joerg basic_string&
1227 1.1 joerg >
1228 1.1 joerg replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
1229 1.1 joerg #ifndef _LIBCPP_CXX03_LANG
1230 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1231 1.1 joerg basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
1232 1.1 joerg {return replace(__i1, __i2, __il.begin(), __il.end());}
1233 1.1 joerg #endif // _LIBCPP_CXX03_LANG
1234 1.1 joerg
1235 1.1 joerg size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
1236 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1237 1.1 joerg basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1238 1.1 joerg
1239 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1240 1.1 joerg void swap(basic_string& __str)
1241 1.1 joerg #if _LIBCPP_STD_VER >= 14
1242 1.1 joerg _NOEXCEPT;
1243 1.1 joerg #else
1244 1.1 joerg _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1245 1.1 joerg __is_nothrow_swappable<allocator_type>::value);
1246 1.1 joerg #endif
1247 1.1 joerg
1248 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1249 1.1 joerg const value_type* c_str() const _NOEXCEPT {return data();}
1250 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1251 1.1 joerg const value_type* data() const _NOEXCEPT {return _VSTD::__to_address(__get_pointer());}
1252 1.1 joerg #if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
1253 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1254 1.1 joerg value_type* data() _NOEXCEPT {return _VSTD::__to_address(__get_pointer());}
1255 1.1 joerg #endif
1256 1.1 joerg
1257 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1258 1.1 joerg allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
1259 1.1 joerg
1260 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1261 1.1 joerg size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1262 1.1 joerg
1263 1.1 joerg template <class _Tp>
1264 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1265 1.1 joerg _EnableIf
1266 1.1 joerg <
1267 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1268 1.1 joerg size_type
1269 1.1 joerg >
1270 1.1 joerg find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT;
1271 1.1 joerg size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1272 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1273 1.1 joerg size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1274 1.1 joerg size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1275 1.1 joerg
1276 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1277 1.1 joerg size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1278 1.1 joerg
1279 1.1 joerg template <class _Tp>
1280 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1281 1.1 joerg _EnableIf
1282 1.1 joerg <
1283 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1284 1.1 joerg size_type
1285 1.1 joerg >
1286 1.1 joerg rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
1287 1.1 joerg size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1288 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1289 1.1 joerg size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1290 1.1 joerg size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1291 1.1 joerg
1292 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1293 1.1 joerg size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1294 1.1 joerg
1295 1.1 joerg template <class _Tp>
1296 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1297 1.1 joerg _EnableIf
1298 1.1 joerg <
1299 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1300 1.1 joerg size_type
1301 1.1 joerg >
1302 1.1 joerg find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT;
1303 1.1 joerg size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1304 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1305 1.1 joerg size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1306 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1307 1.1 joerg size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1308 1.1 joerg
1309 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1310 1.1 joerg size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1311 1.1 joerg
1312 1.1 joerg template <class _Tp>
1313 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1314 1.1 joerg _EnableIf
1315 1.1 joerg <
1316 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1317 1.1 joerg size_type
1318 1.1 joerg >
1319 1.1 joerg find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
1320 1.1 joerg size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1321 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1322 1.1 joerg size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1323 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1324 1.1 joerg size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1325 1.1 joerg
1326 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1327 1.1 joerg size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1328 1.1 joerg
1329 1.1 joerg template <class _Tp>
1330 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1331 1.1 joerg _EnableIf
1332 1.1 joerg <
1333 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1334 1.1 joerg size_type
1335 1.1 joerg >
1336 1.1 joerg find_first_not_of(const _Tp &__t, size_type __pos = 0) const _NOEXCEPT;
1337 1.1 joerg size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1338 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1339 1.1 joerg size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1340 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1341 1.1 joerg size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1342 1.1 joerg
1343 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1344 1.1 joerg size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1345 1.1 joerg
1346 1.1 joerg template <class _Tp>
1347 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1348 1.1 joerg _EnableIf
1349 1.1 joerg <
1350 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1351 1.1 joerg size_type
1352 1.1 joerg >
1353 1.1 joerg find_last_not_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
1354 1.1 joerg size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1355 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1356 1.1 joerg size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1357 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1358 1.1 joerg size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1359 1.1 joerg
1360 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1361 1.1 joerg int compare(const basic_string& __str) const _NOEXCEPT;
1362 1.1 joerg
1363 1.1 joerg template <class _Tp>
1364 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1365 1.1 joerg _EnableIf
1366 1.1 joerg <
1367 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1368 1.1 joerg int
1369 1.1 joerg >
1370 1.1 joerg compare(const _Tp &__t) const _NOEXCEPT;
1371 1.1 joerg
1372 1.1 joerg template <class _Tp>
1373 1.1 joerg _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1374 1.1 joerg _EnableIf
1375 1.1 joerg <
1376 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1377 1.1 joerg int
1378 1.1 joerg >
1379 1.1 joerg compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
1380 1.1 joerg
1381 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1382 1.1 joerg int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
1383 1.1 joerg int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
1384 1.1 joerg
1385 1.1 joerg template <class _Tp>
1386 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
1387 1.1 joerg _EnableIf
1388 1.1 joerg <
1389 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
1390 1.1 joerg int
1391 1.1 joerg >
1392 1.1 joerg compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
1393 1.1 joerg int compare(const value_type* __s) const _NOEXCEPT;
1394 1.1 joerg int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1395 1.1 joerg int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
1396 1.1 joerg
1397 1.1 joerg #if _LIBCPP_STD_VER > 17
1398 1.1 joerg _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1399 1.1 joerg bool starts_with(__self_view __sv) const _NOEXCEPT
1400 1.1 joerg { return __self_view(data(), size()).starts_with(__sv); }
1401 1.1 joerg
1402 1.1 joerg _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1403 1.1 joerg bool starts_with(value_type __c) const _NOEXCEPT
1404 1.1 joerg { return !empty() && _Traits::eq(front(), __c); }
1405 1.1 joerg
1406 1.1 joerg _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1407 1.1 joerg bool starts_with(const value_type* __s) const _NOEXCEPT
1408 1.1 joerg { return starts_with(__self_view(__s)); }
1409 1.1 joerg
1410 1.1 joerg _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1411 1.1 joerg bool ends_with(__self_view __sv) const _NOEXCEPT
1412 1.1 joerg { return __self_view(data(), size()).ends_with( __sv); }
1413 1.1 joerg
1414 1.1 joerg _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1415 1.1 joerg bool ends_with(value_type __c) const _NOEXCEPT
1416 1.1 joerg { return !empty() && _Traits::eq(back(), __c); }
1417 1.1 joerg
1418 1.1 joerg _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1419 1.1 joerg bool ends_with(const value_type* __s) const _NOEXCEPT
1420 1.1 joerg { return ends_with(__self_view(__s)); }
1421 1.1 joerg #endif
1422 1.1 joerg
1423 1.1 joerg #if _LIBCPP_STD_VER > 20
1424 1.1 joerg constexpr _LIBCPP_INLINE_VISIBILITY
1425 1.1 joerg bool contains(__self_view __sv) const noexcept
1426 1.1 joerg { return __self_view(data(), size()).contains(__sv); }
1427 1.1 joerg
1428 1.1 joerg constexpr _LIBCPP_INLINE_VISIBILITY
1429 1.1 joerg bool contains(value_type __c) const noexcept
1430 1.1 joerg { return __self_view(data(), size()).contains(__c); }
1431 1.1 joerg
1432 1.1 joerg constexpr _LIBCPP_INLINE_VISIBILITY
1433 1.1 joerg bool contains(const value_type* __s) const
1434 1.1 joerg { return __self_view(data(), size()).contains(__s); }
1435 1.1 joerg #endif
1436 1.1 joerg
1437 1.1 joerg _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
1438 1.1 joerg
1439 1.1 joerg _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT;
1440 1.1 joerg
1441 1.1 joerg _LIBCPP_INLINE_VISIBILITY void __shrink_or_extend(size_type __target_capacity);
1442 1.1 joerg
1443 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1444 1.1 joerg bool __is_long() const _NOEXCEPT
1445 1.1 joerg {return bool(__r_.first().__s.__size_ & __short_mask);}
1446 1.1 joerg
1447 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
1448 1.1 joerg
1449 1.1 joerg bool __dereferenceable(const const_iterator* __i) const;
1450 1.1 joerg bool __decrementable(const const_iterator* __i) const;
1451 1.1 joerg bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1452 1.1 joerg bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1453 1.1 joerg
1454 1.1 joerg #endif // _LIBCPP_DEBUG_LEVEL == 2
1455 1.1 joerg
1456 1.1 joerg private:
1457 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1458 1.1 joerg allocator_type& __alloc() _NOEXCEPT
1459 1.1 joerg {return __r_.second();}
1460 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1461 1.1 joerg const allocator_type& __alloc() const _NOEXCEPT
1462 1.1 joerg {return __r_.second();}
1463 1.1 joerg
1464 1.1 joerg #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1465 1.1 joerg
1466 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1467 1.1 joerg void __set_short_size(size_type __s) _NOEXCEPT
1468 1.1 joerg # ifdef _LIBCPP_BIG_ENDIAN
1469 1.1 joerg {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1470 1.1 joerg # else
1471 1.1 joerg {__r_.first().__s.__size_ = (unsigned char)(__s);}
1472 1.1 joerg # endif
1473 1.1 joerg
1474 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1475 1.1 joerg size_type __get_short_size() const _NOEXCEPT
1476 1.1 joerg # ifdef _LIBCPP_BIG_ENDIAN
1477 1.1 joerg {return __r_.first().__s.__size_ >> 1;}
1478 1.1 joerg # else
1479 1.1 joerg {return __r_.first().__s.__size_;}
1480 1.1 joerg # endif
1481 1.1 joerg
1482 1.1 joerg #else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1483 1.1 joerg
1484 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1485 1.1 joerg void __set_short_size(size_type __s) _NOEXCEPT
1486 1.1 joerg # ifdef _LIBCPP_BIG_ENDIAN
1487 1.1 joerg {__r_.first().__s.__size_ = (unsigned char)(__s);}
1488 1.1 joerg # else
1489 1.1 joerg {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1490 1.1 joerg # endif
1491 1.1 joerg
1492 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1493 1.1 joerg size_type __get_short_size() const _NOEXCEPT
1494 1.1 joerg # ifdef _LIBCPP_BIG_ENDIAN
1495 1.1 joerg {return __r_.first().__s.__size_;}
1496 1.1 joerg # else
1497 1.1 joerg {return __r_.first().__s.__size_ >> 1;}
1498 1.1 joerg # endif
1499 1.1 joerg
1500 1.1 joerg #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1501 1.1 joerg
1502 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1503 1.1 joerg void __set_long_size(size_type __s) _NOEXCEPT
1504 1.1 joerg {__r_.first().__l.__size_ = __s;}
1505 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1506 1.1 joerg size_type __get_long_size() const _NOEXCEPT
1507 1.1 joerg {return __r_.first().__l.__size_;}
1508 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1509 1.1 joerg void __set_size(size_type __s) _NOEXCEPT
1510 1.1 joerg {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1511 1.1 joerg
1512 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1513 1.1 joerg void __set_long_cap(size_type __s) _NOEXCEPT
1514 1.1 joerg {__r_.first().__l.__cap_ = __long_mask | __s;}
1515 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1516 1.1 joerg size_type __get_long_cap() const _NOEXCEPT
1517 1.1 joerg {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
1518 1.1 joerg
1519 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1520 1.1 joerg void __set_long_pointer(pointer __p) _NOEXCEPT
1521 1.1 joerg {__r_.first().__l.__data_ = __p;}
1522 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1523 1.1 joerg pointer __get_long_pointer() _NOEXCEPT
1524 1.1 joerg {return __r_.first().__l.__data_;}
1525 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1526 1.1 joerg const_pointer __get_long_pointer() const _NOEXCEPT
1527 1.1 joerg {return __r_.first().__l.__data_;}
1528 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1529 1.1 joerg pointer __get_short_pointer() _NOEXCEPT
1530 1.1 joerg {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1531 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1532 1.1 joerg const_pointer __get_short_pointer() const _NOEXCEPT
1533 1.1 joerg {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1534 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1535 1.1 joerg pointer __get_pointer() _NOEXCEPT
1536 1.1 joerg {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1537 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1538 1.1 joerg const_pointer __get_pointer() const _NOEXCEPT
1539 1.1 joerg {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1540 1.1 joerg
1541 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1542 1.1 joerg void __zero() _NOEXCEPT
1543 1.1 joerg {
1544 1.1 joerg size_type (&__a)[__n_words] = __r_.first().__r.__words;
1545 1.1 joerg for (unsigned __i = 0; __i < __n_words; ++__i)
1546 1.1 joerg __a[__i] = 0;
1547 1.1 joerg }
1548 1.1 joerg
1549 1.1 joerg template <size_type __a> static
1550 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1551 1.1 joerg size_type __align_it(size_type __s) _NOEXCEPT
1552 1.1 joerg {return (__s + (__a-1)) & ~(__a-1);}
1553 1.1 joerg enum {__alignment = 16};
1554 1.1 joerg static _LIBCPP_INLINE_VISIBILITY
1555 1.1 joerg size_type __recommend(size_type __s) _NOEXCEPT
1556 1.1 joerg {
1557 1.1 joerg if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
1558 1.1 joerg size_type __guess = __align_it<sizeof(value_type) < __alignment ?
1559 1.1 joerg __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
1560 1.1 joerg if (__guess == __min_cap) ++__guess;
1561 1.1 joerg return __guess;
1562 1.1 joerg }
1563 1.1 joerg
1564 1.1 joerg inline
1565 1.1 joerg void __init(const value_type* __s, size_type __sz, size_type __reserve);
1566 1.1 joerg inline
1567 1.1 joerg void __init(const value_type* __s, size_type __sz);
1568 1.1 joerg inline
1569 1.1 joerg void __init(size_type __n, value_type __c);
1570 1.1 joerg
1571 1.1 joerg // Slow path for the (inlined) copy constructor for 'long' strings.
1572 1.1 joerg // Always externally instantiated and not inlined.
1573 1.1 joerg // Requires that __s is zero terminated.
1574 1.1 joerg // The main reason for this function to exist is because for unstable, we
1575 1.1 joerg // want to allow inlining of the copy constructor. However, we don't want
1576 1.1 joerg // to call the __init() functions as those are marked as inline which may
1577 1.1 joerg // result in over-aggressive inlining by the compiler, where our aim is
1578 1.1 joerg // to only inline the fast path code directly in the ctor.
1579 1.1 joerg void __init_copy_ctor_external(const value_type* __s, size_type __sz);
1580 1.1 joerg
1581 1.1 joerg template <class _InputIterator>
1582 1.1 joerg inline
1583 1.1 joerg _EnableIf
1584 1.1 joerg <
1585 1.1 joerg __is_exactly_cpp17_input_iterator<_InputIterator>::value
1586 1.1 joerg >
1587 1.1 joerg __init(_InputIterator __first, _InputIterator __last);
1588 1.1 joerg
1589 1.1 joerg template <class _ForwardIterator>
1590 1.1 joerg inline
1591 1.1 joerg _EnableIf
1592 1.1 joerg <
1593 1.1 joerg __is_cpp17_forward_iterator<_ForwardIterator>::value
1594 1.1 joerg >
1595 1.1 joerg __init(_ForwardIterator __first, _ForwardIterator __last);
1596 1.1 joerg
1597 1.1 joerg void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1598 1.1 joerg size_type __n_copy, size_type __n_del, size_type __n_add = 0);
1599 1.1 joerg void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1600 1.1 joerg size_type __n_copy, size_type __n_del,
1601 1.1 joerg size_type __n_add, const value_type* __p_new_stuff);
1602 1.1 joerg
1603 1.1 joerg // __assign_no_alias is invoked for assignment operations where we
1604 1.1 joerg // have proof that the input does not alias the current instance.
1605 1.1 joerg // For example, operator=(basic_string) performs a 'self' check.
1606 1.1 joerg template <bool __is_short>
1607 1.1 joerg basic_string& __assign_no_alias(const value_type* __s, size_type __n);
1608 1.1 joerg
1609 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1610 1.1 joerg void __erase_to_end(size_type __pos);
1611 1.1 joerg
1612 1.1 joerg // __erase_external_with_move is invoked for erase() invocations where
1613 1.1 joerg // `n ~= npos`, likely requiring memory moves on the string data.
1614 1.1 joerg void __erase_external_with_move(size_type __pos, size_type __n);
1615 1.1 joerg
1616 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1617 1.1 joerg void __copy_assign_alloc(const basic_string& __str)
1618 1.1 joerg {__copy_assign_alloc(__str, integral_constant<bool,
1619 1.1 joerg __alloc_traits::propagate_on_container_copy_assignment::value>());}
1620 1.1 joerg
1621 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1622 1.1 joerg void __copy_assign_alloc(const basic_string& __str, true_type)
1623 1.1 joerg {
1624 1.1 joerg if (__alloc() == __str.__alloc())
1625 1.1 joerg __alloc() = __str.__alloc();
1626 1.1 joerg else
1627 1.1 joerg {
1628 1.1 joerg if (!__str.__is_long())
1629 1.1 joerg {
1630 1.1 joerg __clear_and_shrink();
1631 1.1 joerg __alloc() = __str.__alloc();
1632 1.1 joerg }
1633 1.1 joerg else
1634 1.1 joerg {
1635 1.1 joerg allocator_type __a = __str.__alloc();
1636 1.1 joerg pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
1637 1.1 joerg __clear_and_shrink();
1638 1.1 joerg __alloc() = _VSTD::move(__a);
1639 1.1 joerg __set_long_pointer(__p);
1640 1.1 joerg __set_long_cap(__str.__get_long_cap());
1641 1.1 joerg __set_long_size(__str.size());
1642 1.1 joerg }
1643 1.1 joerg }
1644 1.1 joerg }
1645 1.1 joerg
1646 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1647 1.1 joerg void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
1648 1.1 joerg {}
1649 1.1 joerg
1650 1.1 joerg #ifndef _LIBCPP_CXX03_LANG
1651 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1652 1.1 joerg void __move_assign(basic_string& __str, false_type)
1653 1.1 joerg _NOEXCEPT_(__alloc_traits::is_always_equal::value);
1654 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1655 1.1 joerg void __move_assign(basic_string& __str, true_type)
1656 1.1 joerg #if _LIBCPP_STD_VER > 14
1657 1.1 joerg _NOEXCEPT;
1658 1.1 joerg #else
1659 1.1 joerg _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
1660 1.1 joerg #endif
1661 1.1 joerg #endif
1662 1.1 joerg
1663 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1664 1.1 joerg void
1665 1.1 joerg __move_assign_alloc(basic_string& __str)
1666 1.1 joerg _NOEXCEPT_(
1667 1.1 joerg !__alloc_traits::propagate_on_container_move_assignment::value ||
1668 1.1 joerg is_nothrow_move_assignable<allocator_type>::value)
1669 1.1 joerg {__move_assign_alloc(__str, integral_constant<bool,
1670 1.1 joerg __alloc_traits::propagate_on_container_move_assignment::value>());}
1671 1.1 joerg
1672 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1673 1.1 joerg void __move_assign_alloc(basic_string& __c, true_type)
1674 1.1 joerg _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1675 1.1 joerg {
1676 1.1 joerg __alloc() = _VSTD::move(__c.__alloc());
1677 1.1 joerg }
1678 1.1 joerg
1679 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1680 1.1 joerg void __move_assign_alloc(basic_string&, false_type)
1681 1.1 joerg _NOEXCEPT
1682 1.1 joerg {}
1683 1.1 joerg
1684 1.1 joerg basic_string& __assign_external(const value_type* __s);
1685 1.1 joerg basic_string& __assign_external(const value_type* __s, size_type __n);
1686 1.1 joerg
1687 1.1 joerg // Assigns the value in __s, guaranteed to be __n < __min_cap in length.
1688 1.1 joerg inline basic_string& __assign_short(const value_type* __s, size_type __n) {
1689 1.1 joerg pointer __p = __is_long()
1690 1.1 joerg ? (__set_long_size(__n), __get_long_pointer())
1691 1.1 joerg : (__set_short_size(__n), __get_short_pointer());
1692 1.1 joerg traits_type::move(_VSTD::__to_address(__p), __s, __n);
1693 1.1 joerg traits_type::assign(__p[__n], value_type());
1694 1.1 joerg return *this;
1695 1.1 joerg }
1696 1.1 joerg
1697 1.1 joerg _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1698 1.1 joerg _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
1699 1.1 joerg
1700 1.1 joerg template<class _Tp>
1701 1.1 joerg _LIBCPP_INLINE_VISIBILITY
1702 1.1 joerg bool __addr_in_range(_Tp&& __t) const {
1703 1.1 joerg const volatile void *__p = _VSTD::addressof(__t);
1704 1.1 joerg return data() <= __p && __p <= data() + size();
1705 1.1 joerg }
1706 1.1 joerg
1707 1.1 joerg friend basic_string operator+<>(const basic_string&, const basic_string&);
1708 1.1 joerg friend basic_string operator+<>(const value_type*, const basic_string&);
1709 1.1 joerg friend basic_string operator+<>(value_type, const basic_string&);
1710 1.1 joerg friend basic_string operator+<>(const basic_string&, const value_type*);
1711 1.1 joerg friend basic_string operator+<>(const basic_string&, value_type);
1712 1.1 joerg };
1713 1.1 joerg
1714 1.1 joerg // These declarations must appear before any functions are implicitly used
1715 1.1 joerg // so that they have the correct visibility specifier.
1716 1.1 joerg #ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
1717 1.1 joerg _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1718 1.1 joerg _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1719 1.1 joerg #else
1720 1.1 joerg _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1721 1.1 joerg _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1722 1.1 joerg #endif
1723 1.1 joerg
1724 1.1 joerg
1725 1.1 joerg #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1726 1.1 joerg template<class _InputIterator,
1727 1.1 joerg class _CharT = __iter_value_type<_InputIterator>,
1728 1.1 joerg class _Allocator = allocator<_CharT>,
1729 1.1 joerg class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value>,
1730 1.1 joerg class = _EnableIf<__is_allocator<_Allocator>::value>
1731 1.1 joerg >
1732 1.1 joerg basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
1733 1.1 joerg -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
1734 1.1 joerg
1735 1.1 joerg template<class _CharT,
1736 1.1 joerg class _Traits,
1737 1.1 joerg class _Allocator = allocator<_CharT>,
1738 1.1 joerg class = _EnableIf<__is_allocator<_Allocator>::value>
1739 1.1 joerg >
1740 1.1 joerg explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
1741 1.1 joerg -> basic_string<_CharT, _Traits, _Allocator>;
1742 1.1 joerg
1743 1.1 joerg template<class _CharT,
1744 1.1 joerg class _Traits,
1745 1.1 joerg class _Allocator = allocator<_CharT>,
1746 1.1 joerg class = _EnableIf<__is_allocator<_Allocator>::value>,
1747 1.1 joerg class _Sz = typename allocator_traits<_Allocator>::size_type
1748 1.1 joerg >
1749 1.1 joerg basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
1750 1.1 joerg -> basic_string<_CharT, _Traits, _Allocator>;
1751 1.1 joerg #endif
1752 1.1 joerg
1753 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
1754 1.1 joerg inline
1755 1.1 joerg void
1756 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1757 1.1 joerg {
1758 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
1759 1.1 joerg __get_db()->__invalidate_all(this);
1760 1.1 joerg #endif
1761 1.1 joerg }
1762 1.1 joerg
1763 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
1764 1.1 joerg inline
1765 1.1 joerg void
1766 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos)
1767 1.1 joerg {
1768 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
1769 1.1 joerg __c_node* __c = __get_db()->__find_c_and_lock(this);
1770 1.1 joerg if (__c)
1771 1.1 joerg {
1772 1.1 joerg const_pointer __new_last = __get_pointer() + __pos;
1773 1.1 joerg for (__i_node** __p = __c->end_; __p != __c->beg_; )
1774 1.1 joerg {
1775 1.1 joerg --__p;
1776 1.1 joerg const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1777 1.1 joerg if (__i->base() > __new_last)
1778 1.1 joerg {
1779 1.1 joerg (*__p)->__c_ = nullptr;
1780 1.1 joerg if (--__c->end_ != __p)
1781 1.1 joerg _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1782 1.1 joerg }
1783 1.1 joerg }
1784 1.1 joerg __get_db()->unlock();
1785 1.1 joerg }
1786 1.1 joerg #else
1787 1.1 joerg (void)__pos;
1788 1.1 joerg #endif // _LIBCPP_DEBUG_LEVEL == 2
1789 1.1 joerg }
1790 1.1 joerg
1791 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
1792 1.1 joerg inline
1793 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string()
1794 1.1 joerg _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1795 1.1 joerg : __r_(__default_init_tag(), __default_init_tag())
1796 1.1 joerg {
1797 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
1798 1.1 joerg __get_db()->__insert_c(this);
1799 1.1 joerg #endif
1800 1.1 joerg __zero();
1801 1.1 joerg }
1802 1.1 joerg
1803 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
1804 1.1 joerg inline
1805 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
1806 1.1 joerg #if _LIBCPP_STD_VER <= 14
1807 1.1 joerg _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1808 1.1 joerg #else
1809 1.1 joerg _NOEXCEPT
1810 1.1 joerg #endif
1811 1.1 joerg : __r_(__default_init_tag(), __a)
1812 1.1 joerg {
1813 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
1814 1.1 joerg __get_db()->__insert_c(this);
1815 1.1 joerg #endif
1816 1.1 joerg __zero();
1817 1.1 joerg }
1818 1.1 joerg
1819 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
1820 1.1 joerg void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1821 1.1 joerg size_type __sz,
1822 1.1 joerg size_type __reserve)
1823 1.1 joerg {
1824 1.1 joerg if (__reserve > max_size())
1825 1.1 joerg this->__throw_length_error();
1826 1.1 joerg pointer __p;
1827 1.1 joerg if (__reserve < __min_cap)
1828 1.1 joerg {
1829 1.1 joerg __set_short_size(__sz);
1830 1.1 joerg __p = __get_short_pointer();
1831 1.1 joerg }
1832 1.1 joerg else
1833 1.1 joerg {
1834 1.1 joerg size_type __cap = __recommend(__reserve);
1835 1.1 joerg __p = __alloc_traits::allocate(__alloc(), __cap+1);
1836 1.1 joerg __set_long_pointer(__p);
1837 1.1 joerg __set_long_cap(__cap+1);
1838 1.1 joerg __set_long_size(__sz);
1839 1.1 joerg }
1840 1.1 joerg traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
1841 1.1 joerg traits_type::assign(__p[__sz], value_type());
1842 1.1 joerg }
1843 1.1 joerg
1844 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
1845 1.1 joerg void
1846 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
1847 1.1 joerg {
1848 1.1 joerg if (__sz > max_size())
1849 1.1 joerg this->__throw_length_error();
1850 1.1 joerg pointer __p;
1851 1.1 joerg if (__sz < __min_cap)
1852 1.1 joerg {
1853 1.1 joerg __set_short_size(__sz);
1854 1.1 joerg __p = __get_short_pointer();
1855 1.1 joerg }
1856 1.1 joerg else
1857 1.1 joerg {
1858 1.1 joerg size_type __cap = __recommend(__sz);
1859 1.1 joerg __p = __alloc_traits::allocate(__alloc(), __cap+1);
1860 1.1 joerg __set_long_pointer(__p);
1861 1.1 joerg __set_long_cap(__cap+1);
1862 1.1 joerg __set_long_size(__sz);
1863 1.1 joerg }
1864 1.1 joerg traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
1865 1.1 joerg traits_type::assign(__p[__sz], value_type());
1866 1.1 joerg }
1867 1.1 joerg
1868 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
1869 1.1 joerg template <class>
1870 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
1871 1.1 joerg : __r_(__default_init_tag(), __a)
1872 1.1 joerg {
1873 1.1 joerg _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
1874 1.1 joerg __init(__s, traits_type::length(__s));
1875 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
1876 1.1 joerg __get_db()->__insert_c(this);
1877 1.1 joerg #endif
1878 1.1 joerg }
1879 1.1 joerg
1880 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
1881 1.1 joerg inline
1882 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
1883 1.1 joerg : __r_(__default_init_tag(), __default_init_tag())
1884 1.1 joerg {
1885 1.1 joerg _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
1886 1.1 joerg __init(__s, __n);
1887 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
1888 1.1 joerg __get_db()->__insert_c(this);
1889 1.1 joerg #endif
1890 1.1 joerg }
1891 1.1 joerg
1892 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
1893 1.1 joerg inline
1894 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
1895 1.1 joerg : __r_(__default_init_tag(), __a)
1896 1.1 joerg {
1897 1.1 joerg _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
1898 1.1 joerg __init(__s, __n);
1899 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
1900 1.1 joerg __get_db()->__insert_c(this);
1901 1.1 joerg #endif
1902 1.1 joerg }
1903 1.1 joerg
1904 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
1905 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
1906 1.1 joerg : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
1907 1.1 joerg {
1908 1.1 joerg if (!__str.__is_long())
1909 1.1 joerg __r_.first().__r = __str.__r_.first().__r;
1910 1.1 joerg else
1911 1.1 joerg __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
1912 1.1 joerg __str.__get_long_size());
1913 1.1 joerg
1914 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
1915 1.1 joerg __get_db()->__insert_c(this);
1916 1.1 joerg #endif
1917 1.1 joerg }
1918 1.1 joerg
1919 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
1920 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(
1921 1.1 joerg const basic_string& __str, const allocator_type& __a)
1922 1.1 joerg : __r_(__default_init_tag(), __a)
1923 1.1 joerg {
1924 1.1 joerg if (!__str.__is_long())
1925 1.1 joerg __r_.first().__r = __str.__r_.first().__r;
1926 1.1 joerg else
1927 1.1 joerg __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
1928 1.1 joerg __str.__get_long_size());
1929 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
1930 1.1 joerg __get_db()->__insert_c(this);
1931 1.1 joerg #endif
1932 1.1 joerg }
1933 1.1 joerg
1934 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
1935 1.1 joerg void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
1936 1.1 joerg const value_type* __s, size_type __sz) {
1937 1.1 joerg pointer __p;
1938 1.1 joerg if (__sz < __min_cap) {
1939 1.1 joerg __p = __get_short_pointer();
1940 1.1 joerg __set_short_size(__sz);
1941 1.1 joerg } else {
1942 1.1 joerg if (__sz > max_size())
1943 1.1 joerg this->__throw_length_error();
1944 1.1 joerg size_t __cap = __recommend(__sz);
1945 1.1 joerg __p = __alloc_traits::allocate(__alloc(), __cap + 1);
1946 1.1 joerg __set_long_pointer(__p);
1947 1.1 joerg __set_long_cap(__cap + 1);
1948 1.1 joerg __set_long_size(__sz);
1949 1.1 joerg }
1950 1.1 joerg traits_type::copy(_VSTD::__to_address(__p), __s, __sz + 1);
1951 1.1 joerg }
1952 1.1 joerg
1953 1.1 joerg #ifndef _LIBCPP_CXX03_LANG
1954 1.1 joerg
1955 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
1956 1.1 joerg inline
1957 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
1958 1.1 joerg #if _LIBCPP_STD_VER <= 14
1959 1.1 joerg _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1960 1.1 joerg #else
1961 1.1 joerg _NOEXCEPT
1962 1.1 joerg #endif
1963 1.1 joerg : __r_(_VSTD::move(__str.__r_))
1964 1.1 joerg {
1965 1.1 joerg __str.__zero();
1966 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
1967 1.1 joerg __get_db()->__insert_c(this);
1968 1.1 joerg if (__is_long())
1969 1.1 joerg __get_db()->swap(this, &__str);
1970 1.1 joerg #endif
1971 1.1 joerg }
1972 1.1 joerg
1973 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
1974 1.1 joerg inline
1975 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
1976 1.1 joerg : __r_(__default_init_tag(), __a)
1977 1.1 joerg {
1978 1.1 joerg if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
1979 1.1 joerg __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
1980 1.1 joerg else
1981 1.1 joerg {
1982 1.1 joerg __r_.first().__r = __str.__r_.first().__r;
1983 1.1 joerg __str.__zero();
1984 1.1 joerg }
1985 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
1986 1.1 joerg __get_db()->__insert_c(this);
1987 1.1 joerg if (__is_long())
1988 1.1 joerg __get_db()->swap(this, &__str);
1989 1.1 joerg #endif
1990 1.1 joerg }
1991 1.1 joerg
1992 1.1 joerg #endif // _LIBCPP_CXX03_LANG
1993 1.1 joerg
1994 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
1995 1.1 joerg void
1996 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1997 1.1 joerg {
1998 1.1 joerg if (__n > max_size())
1999 1.1 joerg this->__throw_length_error();
2000 1.1 joerg pointer __p;
2001 1.1 joerg if (__n < __min_cap)
2002 1.1 joerg {
2003 1.1 joerg __set_short_size(__n);
2004 1.1 joerg __p = __get_short_pointer();
2005 1.1 joerg }
2006 1.1 joerg else
2007 1.1 joerg {
2008 1.1 joerg size_type __cap = __recommend(__n);
2009 1.1 joerg __p = __alloc_traits::allocate(__alloc(), __cap+1);
2010 1.1 joerg __set_long_pointer(__p);
2011 1.1 joerg __set_long_cap(__cap+1);
2012 1.1 joerg __set_long_size(__n);
2013 1.1 joerg }
2014 1.1 joerg traits_type::assign(_VSTD::__to_address(__p), __n, __c);
2015 1.1 joerg traits_type::assign(__p[__n], value_type());
2016 1.1 joerg }
2017 1.1 joerg
2018 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2019 1.1 joerg inline
2020 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
2021 1.1 joerg : __r_(__default_init_tag(), __default_init_tag())
2022 1.1 joerg {
2023 1.1 joerg __init(__n, __c);
2024 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
2025 1.1 joerg __get_db()->__insert_c(this);
2026 1.1 joerg #endif
2027 1.1 joerg }
2028 1.1 joerg
2029 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2030 1.1 joerg template <class>
2031 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
2032 1.1 joerg : __r_(__default_init_tag(), __a)
2033 1.1 joerg {
2034 1.1 joerg __init(__n, __c);
2035 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
2036 1.1 joerg __get_db()->__insert_c(this);
2037 1.1 joerg #endif
2038 1.1 joerg }
2039 1.1 joerg
2040 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2041 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
2042 1.1 joerg size_type __pos, size_type __n,
2043 1.1 joerg const _Allocator& __a)
2044 1.1 joerg : __r_(__default_init_tag(), __a)
2045 1.1 joerg {
2046 1.1 joerg size_type __str_sz = __str.size();
2047 1.1 joerg if (__pos > __str_sz)
2048 1.1 joerg this->__throw_out_of_range();
2049 1.1 joerg __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
2050 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
2051 1.1 joerg __get_db()->__insert_c(this);
2052 1.1 joerg #endif
2053 1.1 joerg }
2054 1.1 joerg
2055 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2056 1.1 joerg inline
2057 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
2058 1.1 joerg const _Allocator& __a)
2059 1.1 joerg : __r_(__default_init_tag(), __a)
2060 1.1 joerg {
2061 1.1 joerg size_type __str_sz = __str.size();
2062 1.1 joerg if (__pos > __str_sz)
2063 1.1 joerg this->__throw_out_of_range();
2064 1.1 joerg __init(__str.data() + __pos, __str_sz - __pos);
2065 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
2066 1.1 joerg __get_db()->__insert_c(this);
2067 1.1 joerg #endif
2068 1.1 joerg }
2069 1.1 joerg
2070 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2071 1.1 joerg template <class _Tp, class>
2072 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(
2073 1.1 joerg const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
2074 1.1 joerg : __r_(__default_init_tag(), __a)
2075 1.1 joerg {
2076 1.1 joerg __self_view __sv0 = __t;
2077 1.1 joerg __self_view __sv = __sv0.substr(__pos, __n);
2078 1.1 joerg __init(__sv.data(), __sv.size());
2079 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
2080 1.1 joerg __get_db()->__insert_c(this);
2081 1.1 joerg #endif
2082 1.1 joerg }
2083 1.1 joerg
2084 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2085 1.1 joerg template <class _Tp, class>
2086 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
2087 1.1 joerg : __r_(__default_init_tag(), __default_init_tag())
2088 1.1 joerg {
2089 1.1 joerg __self_view __sv = __t;
2090 1.1 joerg __init(__sv.data(), __sv.size());
2091 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
2092 1.1 joerg __get_db()->__insert_c(this);
2093 1.1 joerg #endif
2094 1.1 joerg }
2095 1.1 joerg
2096 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2097 1.1 joerg template <class _Tp, class>
2098 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
2099 1.1 joerg : __r_(__default_init_tag(), __a)
2100 1.1 joerg {
2101 1.1 joerg __self_view __sv = __t;
2102 1.1 joerg __init(__sv.data(), __sv.size());
2103 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
2104 1.1 joerg __get_db()->__insert_c(this);
2105 1.1 joerg #endif
2106 1.1 joerg }
2107 1.1 joerg
2108 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2109 1.1 joerg template <class _InputIterator>
2110 1.1 joerg _EnableIf
2111 1.1 joerg <
2112 1.1 joerg __is_exactly_cpp17_input_iterator<_InputIterator>::value
2113 1.1 joerg >
2114 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2115 1.1 joerg {
2116 1.1 joerg __zero();
2117 1.1 joerg #ifndef _LIBCPP_NO_EXCEPTIONS
2118 1.1 joerg try
2119 1.1 joerg {
2120 1.1 joerg #endif // _LIBCPP_NO_EXCEPTIONS
2121 1.1 joerg for (; __first != __last; ++__first)
2122 1.1 joerg push_back(*__first);
2123 1.1 joerg #ifndef _LIBCPP_NO_EXCEPTIONS
2124 1.1 joerg }
2125 1.1 joerg catch (...)
2126 1.1 joerg {
2127 1.1 joerg if (__is_long())
2128 1.1 joerg __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2129 1.1 joerg throw;
2130 1.1 joerg }
2131 1.1 joerg #endif // _LIBCPP_NO_EXCEPTIONS
2132 1.1 joerg }
2133 1.1 joerg
2134 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2135 1.1 joerg template <class _ForwardIterator>
2136 1.1 joerg _EnableIf
2137 1.1 joerg <
2138 1.1 joerg __is_cpp17_forward_iterator<_ForwardIterator>::value
2139 1.1 joerg >
2140 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2141 1.1 joerg {
2142 1.1 joerg size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
2143 1.1 joerg if (__sz > max_size())
2144 1.1 joerg this->__throw_length_error();
2145 1.1 joerg pointer __p;
2146 1.1 joerg if (__sz < __min_cap)
2147 1.1 joerg {
2148 1.1 joerg __set_short_size(__sz);
2149 1.1 joerg __p = __get_short_pointer();
2150 1.1 joerg }
2151 1.1 joerg else
2152 1.1 joerg {
2153 1.1 joerg size_type __cap = __recommend(__sz);
2154 1.1 joerg __p = __alloc_traits::allocate(__alloc(), __cap+1);
2155 1.1 joerg __set_long_pointer(__p);
2156 1.1 joerg __set_long_cap(__cap+1);
2157 1.1 joerg __set_long_size(__sz);
2158 1.1 joerg }
2159 1.1 joerg
2160 1.1 joerg #ifndef _LIBCPP_NO_EXCEPTIONS
2161 1.1 joerg try
2162 1.1 joerg {
2163 1.1 joerg #endif // _LIBCPP_NO_EXCEPTIONS
2164 1.1 joerg for (; __first != __last; ++__first, (void) ++__p)
2165 1.1 joerg traits_type::assign(*__p, *__first);
2166 1.1 joerg traits_type::assign(*__p, value_type());
2167 1.1 joerg #ifndef _LIBCPP_NO_EXCEPTIONS
2168 1.1 joerg }
2169 1.1 joerg catch (...)
2170 1.1 joerg {
2171 1.1 joerg if (__is_long())
2172 1.1 joerg __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2173 1.1 joerg throw;
2174 1.1 joerg }
2175 1.1 joerg #endif // _LIBCPP_NO_EXCEPTIONS
2176 1.1 joerg }
2177 1.1 joerg
2178 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2179 1.1 joerg template<class _InputIterator, class>
2180 1.1 joerg inline
2181 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2182 1.1 joerg : __r_(__default_init_tag(), __default_init_tag())
2183 1.1 joerg {
2184 1.1 joerg __init(__first, __last);
2185 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
2186 1.1 joerg __get_db()->__insert_c(this);
2187 1.1 joerg #endif
2188 1.1 joerg }
2189 1.1 joerg
2190 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2191 1.1 joerg template<class _InputIterator, class>
2192 1.1 joerg inline
2193 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2194 1.1 joerg const allocator_type& __a)
2195 1.1 joerg : __r_(__default_init_tag(), __a)
2196 1.1 joerg {
2197 1.1 joerg __init(__first, __last);
2198 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
2199 1.1 joerg __get_db()->__insert_c(this);
2200 1.1 joerg #endif
2201 1.1 joerg }
2202 1.1 joerg
2203 1.1 joerg #ifndef _LIBCPP_CXX03_LANG
2204 1.1 joerg
2205 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2206 1.1 joerg inline
2207 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(
2208 1.1 joerg initializer_list<_CharT> __il)
2209 1.1 joerg : __r_(__default_init_tag(), __default_init_tag())
2210 1.1 joerg {
2211 1.1 joerg __init(__il.begin(), __il.end());
2212 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
2213 1.1 joerg __get_db()->__insert_c(this);
2214 1.1 joerg #endif
2215 1.1 joerg }
2216 1.1 joerg
2217 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2218 1.1 joerg inline
2219 1.1 joerg
2220 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::basic_string(
2221 1.1 joerg initializer_list<_CharT> __il, const _Allocator& __a)
2222 1.1 joerg : __r_(__default_init_tag(), __a)
2223 1.1 joerg {
2224 1.1 joerg __init(__il.begin(), __il.end());
2225 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
2226 1.1 joerg __get_db()->__insert_c(this);
2227 1.1 joerg #endif
2228 1.1 joerg }
2229 1.1 joerg
2230 1.1 joerg #endif // _LIBCPP_CXX03_LANG
2231 1.1 joerg
2232 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2233 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2234 1.1 joerg {
2235 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
2236 1.1 joerg __get_db()->__erase_c(this);
2237 1.1 joerg #endif
2238 1.1 joerg if (__is_long())
2239 1.1 joerg __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2240 1.1 joerg }
2241 1.1 joerg
2242 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2243 1.1 joerg void
2244 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2245 1.1 joerg (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2246 1.1 joerg size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
2247 1.1 joerg {
2248 1.1 joerg size_type __ms = max_size();
2249 1.1 joerg if (__delta_cap > __ms - __old_cap - 1)
2250 1.1 joerg this->__throw_length_error();
2251 1.1 joerg pointer __old_p = __get_pointer();
2252 1.1 joerg size_type __cap = __old_cap < __ms / 2 - __alignment ?
2253 1.1 joerg __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
2254 1.1 joerg __ms - 1;
2255 1.1 joerg pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
2256 1.1 joerg __invalidate_all_iterators();
2257 1.1 joerg if (__n_copy != 0)
2258 1.1 joerg traits_type::copy(_VSTD::__to_address(__p),
2259 1.1 joerg _VSTD::__to_address(__old_p), __n_copy);
2260 1.1 joerg if (__n_add != 0)
2261 1.1 joerg traits_type::copy(_VSTD::__to_address(__p) + __n_copy, __p_new_stuff, __n_add);
2262 1.1 joerg size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2263 1.1 joerg if (__sec_cp_sz != 0)
2264 1.1 joerg traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2265 1.1 joerg _VSTD::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz);
2266 1.1 joerg if (__old_cap+1 != __min_cap)
2267 1.1 joerg __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2268 1.1 joerg __set_long_pointer(__p);
2269 1.1 joerg __set_long_cap(__cap+1);
2270 1.1 joerg __old_sz = __n_copy + __n_add + __sec_cp_sz;
2271 1.1 joerg __set_long_size(__old_sz);
2272 1.1 joerg traits_type::assign(__p[__old_sz], value_type());
2273 1.1 joerg }
2274 1.1 joerg
2275 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2276 1.1 joerg void
2277 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2278 1.1 joerg size_type __n_copy, size_type __n_del, size_type __n_add)
2279 1.1 joerg {
2280 1.1 joerg size_type __ms = max_size();
2281 1.1 joerg if (__delta_cap > __ms - __old_cap)
2282 1.1 joerg this->__throw_length_error();
2283 1.1 joerg pointer __old_p = __get_pointer();
2284 1.1 joerg size_type __cap = __old_cap < __ms / 2 - __alignment ?
2285 1.1 joerg __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
2286 1.1 joerg __ms - 1;
2287 1.1 joerg pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
2288 1.1 joerg __invalidate_all_iterators();
2289 1.1 joerg if (__n_copy != 0)
2290 1.1 joerg traits_type::copy(_VSTD::__to_address(__p),
2291 1.1 joerg _VSTD::__to_address(__old_p), __n_copy);
2292 1.1 joerg size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2293 1.1 joerg if (__sec_cp_sz != 0)
2294 1.1 joerg traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2295 1.1 joerg _VSTD::__to_address(__old_p) + __n_copy + __n_del,
2296 1.1 joerg __sec_cp_sz);
2297 1.1 joerg if (__old_cap+1 != __min_cap)
2298 1.1 joerg __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2299 1.1 joerg __set_long_pointer(__p);
2300 1.1 joerg __set_long_cap(__cap+1);
2301 1.1 joerg }
2302 1.1 joerg
2303 1.1 joerg // assign
2304 1.1 joerg
2305 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2306 1.1 joerg template <bool __is_short>
2307 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2308 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(
2309 1.1 joerg const value_type* __s, size_type __n) {
2310 1.1 joerg size_type __cap = __is_short ? __min_cap : __get_long_cap();
2311 1.1 joerg if (__n < __cap) {
2312 1.1 joerg pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer();
2313 1.1 joerg __is_short ? __set_short_size(__n) : __set_long_size(__n);
2314 1.1 joerg traits_type::copy(_VSTD::__to_address(__p), __s, __n);
2315 1.1 joerg traits_type::assign(__p[__n], value_type());
2316 1.1 joerg __invalidate_iterators_past(__n);
2317 1.1 joerg } else {
2318 1.1 joerg size_type __sz = __is_short ? __get_short_size() : __get_long_size();
2319 1.1 joerg __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s);
2320 1.1 joerg }
2321 1.1 joerg return *this;
2322 1.1 joerg }
2323 1.1 joerg
2324 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2325 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2326 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__assign_external(
2327 1.1 joerg const value_type* __s, size_type __n) {
2328 1.1 joerg size_type __cap = capacity();
2329 1.1 joerg if (__cap >= __n) {
2330 1.1 joerg value_type* __p = _VSTD::__to_address(__get_pointer());
2331 1.1 joerg traits_type::move(__p, __s, __n);
2332 1.1 joerg traits_type::assign(__p[__n], value_type());
2333 1.1 joerg __set_size(__n);
2334 1.1 joerg __invalidate_iterators_past(__n);
2335 1.1 joerg } else {
2336 1.1 joerg size_type __sz = size();
2337 1.1 joerg __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2338 1.1 joerg }
2339 1.1 joerg return *this;
2340 1.1 joerg }
2341 1.1 joerg
2342 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2343 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2344 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
2345 1.1 joerg {
2346 1.1 joerg _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
2347 1.1 joerg return (_LIBCPP_BUILTIN_CONSTANT_P(__n) && __n < __min_cap)
2348 1.1 joerg ? __assign_short(__s, __n)
2349 1.1 joerg : __assign_external(__s, __n);
2350 1.1 joerg }
2351 1.1 joerg
2352 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2353 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2354 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2355 1.1 joerg {
2356 1.1 joerg size_type __cap = capacity();
2357 1.1 joerg if (__cap < __n)
2358 1.1 joerg {
2359 1.1 joerg size_type __sz = size();
2360 1.1 joerg __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2361 1.1 joerg }
2362 1.1 joerg value_type* __p = _VSTD::__to_address(__get_pointer());
2363 1.1 joerg traits_type::assign(__p, __n, __c);
2364 1.1 joerg traits_type::assign(__p[__n], value_type());
2365 1.1 joerg __set_size(__n);
2366 1.1 joerg __invalidate_iterators_past(__n);
2367 1.1 joerg return *this;
2368 1.1 joerg }
2369 1.1 joerg
2370 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2371 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2372 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2373 1.1 joerg {
2374 1.1 joerg pointer __p;
2375 1.1 joerg if (__is_long())
2376 1.1 joerg {
2377 1.1 joerg __p = __get_long_pointer();
2378 1.1 joerg __set_long_size(1);
2379 1.1 joerg }
2380 1.1 joerg else
2381 1.1 joerg {
2382 1.1 joerg __p = __get_short_pointer();
2383 1.1 joerg __set_short_size(1);
2384 1.1 joerg }
2385 1.1 joerg traits_type::assign(*__p, __c);
2386 1.1 joerg traits_type::assign(*++__p, value_type());
2387 1.1 joerg __invalidate_iterators_past(1);
2388 1.1 joerg return *this;
2389 1.1 joerg }
2390 1.1 joerg
2391 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2392 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2393 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2394 1.1 joerg {
2395 1.1 joerg if (this != &__str) {
2396 1.1 joerg __copy_assign_alloc(__str);
2397 1.1 joerg if (!__is_long()) {
2398 1.1 joerg if (!__str.__is_long()) {
2399 1.1 joerg __r_.first().__r = __str.__r_.first().__r;
2400 1.1 joerg } else {
2401 1.1 joerg return __assign_no_alias<true>(__str.data(), __str.size());
2402 1.1 joerg }
2403 1.1 joerg } else {
2404 1.1 joerg return __assign_no_alias<false>(__str.data(), __str.size());
2405 1.1 joerg }
2406 1.1 joerg }
2407 1.1 joerg return *this;
2408 1.1 joerg }
2409 1.1 joerg
2410 1.1 joerg #ifndef _LIBCPP_CXX03_LANG
2411 1.1 joerg
2412 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2413 1.1 joerg inline
2414 1.1 joerg void
2415 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2416 1.1 joerg _NOEXCEPT_(__alloc_traits::is_always_equal::value)
2417 1.1 joerg {
2418 1.1 joerg if (__alloc() != __str.__alloc())
2419 1.1 joerg assign(__str);
2420 1.1 joerg else
2421 1.1 joerg __move_assign(__str, true_type());
2422 1.1 joerg }
2423 1.1 joerg
2424 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2425 1.1 joerg inline
2426 1.1 joerg void
2427 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
2428 1.1 joerg #if _LIBCPP_STD_VER > 14
2429 1.1 joerg _NOEXCEPT
2430 1.1 joerg #else
2431 1.1 joerg _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2432 1.1 joerg #endif
2433 1.1 joerg {
2434 1.1 joerg if (__is_long()) {
2435 1.1 joerg __alloc_traits::deallocate(__alloc(), __get_long_pointer(),
2436 1.1 joerg __get_long_cap());
2437 1.1 joerg #if _LIBCPP_STD_VER <= 14
2438 1.1 joerg if (!is_nothrow_move_assignable<allocator_type>::value) {
2439 1.1 joerg __set_short_size(0);
2440 1.1 joerg traits_type::assign(__get_short_pointer()[0], value_type());
2441 1.1 joerg }
2442 1.1 joerg #endif
2443 1.1 joerg }
2444 1.1 joerg __move_assign_alloc(__str);
2445 1.1 joerg __r_.first() = __str.__r_.first();
2446 1.1 joerg __str.__set_short_size(0);
2447 1.1 joerg traits_type::assign(__str.__get_short_pointer()[0], value_type());
2448 1.1 joerg }
2449 1.1 joerg
2450 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2451 1.1 joerg inline
2452 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2453 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
2454 1.1 joerg _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
2455 1.1 joerg {
2456 1.1 joerg __move_assign(__str, integral_constant<bool,
2457 1.1 joerg __alloc_traits::propagate_on_container_move_assignment::value>());
2458 1.1 joerg return *this;
2459 1.1 joerg }
2460 1.1 joerg
2461 1.1 joerg #endif
2462 1.1 joerg
2463 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2464 1.1 joerg template<class _InputIterator>
2465 1.1 joerg _EnableIf
2466 1.1 joerg <
2467 1.1 joerg __is_exactly_cpp17_input_iterator<_InputIterator>::value,
2468 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2469 1.1 joerg >
2470 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2471 1.1 joerg {
2472 1.1 joerg const basic_string __temp(__first, __last, __alloc());
2473 1.1 joerg assign(__temp.data(), __temp.size());
2474 1.1 joerg return *this;
2475 1.1 joerg }
2476 1.1 joerg
2477 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2478 1.1 joerg template<class _ForwardIterator>
2479 1.1 joerg _EnableIf
2480 1.1 joerg <
2481 1.1 joerg __is_cpp17_forward_iterator<_ForwardIterator>::value,
2482 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2483 1.1 joerg >
2484 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2485 1.1 joerg {
2486 1.1 joerg size_type __cap = capacity();
2487 1.1 joerg size_type __n = __string_is_trivial_iterator<_ForwardIterator>::value ?
2488 1.1 joerg static_cast<size_type>(_VSTD::distance(__first, __last)) : 0;
2489 1.1 joerg
2490 1.1 joerg if (__string_is_trivial_iterator<_ForwardIterator>::value &&
2491 1.1 joerg (__cap >= __n || !__addr_in_range(*__first)))
2492 1.1 joerg {
2493 1.1 joerg if (__cap < __n)
2494 1.1 joerg {
2495 1.1 joerg size_type __sz = size();
2496 1.1 joerg __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2497 1.1 joerg }
2498 1.1 joerg pointer __p = __get_pointer();
2499 1.1 joerg for (; __first != __last; ++__first, ++__p)
2500 1.1 joerg traits_type::assign(*__p, *__first);
2501 1.1 joerg traits_type::assign(*__p, value_type());
2502 1.1 joerg __set_size(__n);
2503 1.1 joerg __invalidate_iterators_past(__n);
2504 1.1 joerg }
2505 1.1 joerg else
2506 1.1 joerg {
2507 1.1 joerg const basic_string __temp(__first, __last, __alloc());
2508 1.1 joerg assign(__temp.data(), __temp.size());
2509 1.1 joerg }
2510 1.1 joerg return *this;
2511 1.1 joerg }
2512 1.1 joerg
2513 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2514 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2515 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2516 1.1 joerg {
2517 1.1 joerg size_type __sz = __str.size();
2518 1.1 joerg if (__pos > __sz)
2519 1.1 joerg this->__throw_out_of_range();
2520 1.1 joerg return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2521 1.1 joerg }
2522 1.1 joerg
2523 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2524 1.1 joerg template <class _Tp>
2525 1.1 joerg _EnableIf
2526 1.1 joerg <
2527 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
2528 1.1 joerg && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
2529 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2530 1.1 joerg >
2531 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
2532 1.1 joerg {
2533 1.1 joerg __self_view __sv = __t;
2534 1.1 joerg size_type __sz = __sv.size();
2535 1.1 joerg if (__pos > __sz)
2536 1.1 joerg this->__throw_out_of_range();
2537 1.1 joerg return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2538 1.1 joerg }
2539 1.1 joerg
2540 1.1 joerg
2541 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2542 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2543 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) {
2544 1.1 joerg return __assign_external(__s, traits_type::length(__s));
2545 1.1 joerg }
2546 1.1 joerg
2547 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2548 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2549 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
2550 1.1 joerg {
2551 1.1 joerg _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
2552 1.1 joerg return _LIBCPP_BUILTIN_CONSTANT_P(*__s)
2553 1.1 joerg ? (traits_type::length(__s) < __min_cap
2554 1.1 joerg ? __assign_short(__s, traits_type::length(__s))
2555 1.1 joerg : __assign_external(__s, traits_type::length(__s)))
2556 1.1 joerg : __assign_external(__s);
2557 1.1 joerg }
2558 1.1 joerg // append
2559 1.1 joerg
2560 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2561 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2562 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
2563 1.1 joerg {
2564 1.1 joerg _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
2565 1.1 joerg size_type __cap = capacity();
2566 1.1 joerg size_type __sz = size();
2567 1.1 joerg if (__cap - __sz >= __n)
2568 1.1 joerg {
2569 1.1 joerg if (__n)
2570 1.1 joerg {
2571 1.1 joerg value_type* __p = _VSTD::__to_address(__get_pointer());
2572 1.1 joerg traits_type::copy(__p + __sz, __s, __n);
2573 1.1 joerg __sz += __n;
2574 1.1 joerg __set_size(__sz);
2575 1.1 joerg traits_type::assign(__p[__sz], value_type());
2576 1.1 joerg }
2577 1.1 joerg }
2578 1.1 joerg else
2579 1.1 joerg __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2580 1.1 joerg return *this;
2581 1.1 joerg }
2582 1.1 joerg
2583 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2584 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2585 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2586 1.1 joerg {
2587 1.1 joerg if (__n)
2588 1.1 joerg {
2589 1.1 joerg size_type __cap = capacity();
2590 1.1 joerg size_type __sz = size();
2591 1.1 joerg if (__cap - __sz < __n)
2592 1.1 joerg __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2593 1.1 joerg pointer __p = __get_pointer();
2594 1.1 joerg traits_type::assign(_VSTD::__to_address(__p) + __sz, __n, __c);
2595 1.1 joerg __sz += __n;
2596 1.1 joerg __set_size(__sz);
2597 1.1 joerg traits_type::assign(__p[__sz], value_type());
2598 1.1 joerg }
2599 1.1 joerg return *this;
2600 1.1 joerg }
2601 1.1 joerg
2602 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2603 1.1 joerg inline void
2604 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
2605 1.1 joerg {
2606 1.1 joerg if (__n)
2607 1.1 joerg {
2608 1.1 joerg size_type __cap = capacity();
2609 1.1 joerg size_type __sz = size();
2610 1.1 joerg if (__cap - __sz < __n)
2611 1.1 joerg __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2612 1.1 joerg pointer __p = __get_pointer();
2613 1.1 joerg __sz += __n;
2614 1.1 joerg __set_size(__sz);
2615 1.1 joerg traits_type::assign(__p[__sz], value_type());
2616 1.1 joerg }
2617 1.1 joerg }
2618 1.1 joerg
2619 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2620 1.1 joerg void
2621 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2622 1.1 joerg {
2623 1.1 joerg bool __is_short = !__is_long();
2624 1.1 joerg size_type __cap;
2625 1.1 joerg size_type __sz;
2626 1.1 joerg if (__is_short)
2627 1.1 joerg {
2628 1.1 joerg __cap = __min_cap - 1;
2629 1.1 joerg __sz = __get_short_size();
2630 1.1 joerg }
2631 1.1 joerg else
2632 1.1 joerg {
2633 1.1 joerg __cap = __get_long_cap() - 1;
2634 1.1 joerg __sz = __get_long_size();
2635 1.1 joerg }
2636 1.1 joerg if (__sz == __cap)
2637 1.1 joerg {
2638 1.1 joerg __grow_by(__cap, 1, __sz, __sz, 0);
2639 1.1 joerg __is_short = !__is_long();
2640 1.1 joerg }
2641 1.1 joerg pointer __p;
2642 1.1 joerg if (__is_short)
2643 1.1 joerg {
2644 1.1 joerg __p = __get_short_pointer() + __sz;
2645 1.1 joerg __set_short_size(__sz+1);
2646 1.1 joerg }
2647 1.1 joerg else
2648 1.1 joerg {
2649 1.1 joerg __p = __get_long_pointer() + __sz;
2650 1.1 joerg __set_long_size(__sz+1);
2651 1.1 joerg }
2652 1.1 joerg traits_type::assign(*__p, __c);
2653 1.1 joerg traits_type::assign(*++__p, value_type());
2654 1.1 joerg }
2655 1.1 joerg
2656 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2657 1.1 joerg template<class _ForwardIterator>
2658 1.1 joerg _EnableIf
2659 1.1 joerg <
2660 1.1 joerg __is_cpp17_forward_iterator<_ForwardIterator>::value,
2661 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2662 1.1 joerg >
2663 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::append(
2664 1.1 joerg _ForwardIterator __first, _ForwardIterator __last)
2665 1.1 joerg {
2666 1.1 joerg size_type __sz = size();
2667 1.1 joerg size_type __cap = capacity();
2668 1.1 joerg size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2669 1.1 joerg if (__n)
2670 1.1 joerg {
2671 1.1 joerg if (__string_is_trivial_iterator<_ForwardIterator>::value &&
2672 1.1 joerg !__addr_in_range(*__first))
2673 1.1 joerg {
2674 1.1 joerg if (__cap - __sz < __n)
2675 1.1 joerg __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2676 1.1 joerg pointer __p = __get_pointer() + __sz;
2677 1.1 joerg for (; __first != __last; ++__p, ++__first)
2678 1.1 joerg traits_type::assign(*__p, *__first);
2679 1.1 joerg traits_type::assign(*__p, value_type());
2680 1.1 joerg __set_size(__sz + __n);
2681 1.1 joerg }
2682 1.1 joerg else
2683 1.1 joerg {
2684 1.1 joerg const basic_string __temp(__first, __last, __alloc());
2685 1.1 joerg append(__temp.data(), __temp.size());
2686 1.1 joerg }
2687 1.1 joerg }
2688 1.1 joerg return *this;
2689 1.1 joerg }
2690 1.1 joerg
2691 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2692 1.1 joerg inline
2693 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2694 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2695 1.1 joerg {
2696 1.1 joerg return append(__str.data(), __str.size());
2697 1.1 joerg }
2698 1.1 joerg
2699 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2700 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2701 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2702 1.1 joerg {
2703 1.1 joerg size_type __sz = __str.size();
2704 1.1 joerg if (__pos > __sz)
2705 1.1 joerg this->__throw_out_of_range();
2706 1.1 joerg return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2707 1.1 joerg }
2708 1.1 joerg
2709 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2710 1.1 joerg template <class _Tp>
2711 1.1 joerg _EnableIf
2712 1.1 joerg <
2713 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
2714 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2715 1.1 joerg >
2716 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
2717 1.1 joerg {
2718 1.1 joerg __self_view __sv = __t;
2719 1.1 joerg size_type __sz = __sv.size();
2720 1.1 joerg if (__pos > __sz)
2721 1.1 joerg this->__throw_out_of_range();
2722 1.1 joerg return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2723 1.1 joerg }
2724 1.1 joerg
2725 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2726 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2727 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
2728 1.1 joerg {
2729 1.1 joerg _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
2730 1.1 joerg return append(__s, traits_type::length(__s));
2731 1.1 joerg }
2732 1.1 joerg
2733 1.1 joerg // insert
2734 1.1 joerg
2735 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2736 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2737 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
2738 1.1 joerg {
2739 1.1 joerg _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
2740 1.1 joerg size_type __sz = size();
2741 1.1 joerg if (__pos > __sz)
2742 1.1 joerg this->__throw_out_of_range();
2743 1.1 joerg size_type __cap = capacity();
2744 1.1 joerg if (__cap - __sz >= __n)
2745 1.1 joerg {
2746 1.1 joerg if (__n)
2747 1.1 joerg {
2748 1.1 joerg value_type* __p = _VSTD::__to_address(__get_pointer());
2749 1.1 joerg size_type __n_move = __sz - __pos;
2750 1.1 joerg if (__n_move != 0)
2751 1.1 joerg {
2752 1.1 joerg if (__p + __pos <= __s && __s < __p + __sz)
2753 1.1 joerg __s += __n;
2754 1.1 joerg traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2755 1.1 joerg }
2756 1.1 joerg traits_type::move(__p + __pos, __s, __n);
2757 1.1 joerg __sz += __n;
2758 1.1 joerg __set_size(__sz);
2759 1.1 joerg traits_type::assign(__p[__sz], value_type());
2760 1.1 joerg }
2761 1.1 joerg }
2762 1.1 joerg else
2763 1.1 joerg __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2764 1.1 joerg return *this;
2765 1.1 joerg }
2766 1.1 joerg
2767 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2768 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2769 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2770 1.1 joerg {
2771 1.1 joerg size_type __sz = size();
2772 1.1 joerg if (__pos > __sz)
2773 1.1 joerg this->__throw_out_of_range();
2774 1.1 joerg if (__n)
2775 1.1 joerg {
2776 1.1 joerg size_type __cap = capacity();
2777 1.1 joerg value_type* __p;
2778 1.1 joerg if (__cap - __sz >= __n)
2779 1.1 joerg {
2780 1.1 joerg __p = _VSTD::__to_address(__get_pointer());
2781 1.1 joerg size_type __n_move = __sz - __pos;
2782 1.1 joerg if (__n_move != 0)
2783 1.1 joerg traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2784 1.1 joerg }
2785 1.1 joerg else
2786 1.1 joerg {
2787 1.1 joerg __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
2788 1.1 joerg __p = _VSTD::__to_address(__get_long_pointer());
2789 1.1 joerg }
2790 1.1 joerg traits_type::assign(__p + __pos, __n, __c);
2791 1.1 joerg __sz += __n;
2792 1.1 joerg __set_size(__sz);
2793 1.1 joerg traits_type::assign(__p[__sz], value_type());
2794 1.1 joerg }
2795 1.1 joerg return *this;
2796 1.1 joerg }
2797 1.1 joerg
2798 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2799 1.1 joerg template<class _InputIterator>
2800 1.1 joerg _EnableIf
2801 1.1 joerg <
2802 1.1 joerg __is_exactly_cpp17_input_iterator<_InputIterator>::value,
2803 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::iterator
2804 1.1 joerg >
2805 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2806 1.1 joerg {
2807 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
2808 1.1 joerg _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2809 1.1 joerg "string::insert(iterator, range) called with an iterator not"
2810 1.1 joerg " referring to this string");
2811 1.1 joerg #endif
2812 1.1 joerg const basic_string __temp(__first, __last, __alloc());
2813 1.1 joerg return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2814 1.1 joerg }
2815 1.1 joerg
2816 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2817 1.1 joerg template<class _ForwardIterator>
2818 1.1 joerg _EnableIf
2819 1.1 joerg <
2820 1.1 joerg __is_cpp17_forward_iterator<_ForwardIterator>::value,
2821 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::iterator
2822 1.1 joerg >
2823 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2824 1.1 joerg {
2825 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
2826 1.1 joerg _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2827 1.1 joerg "string::insert(iterator, range) called with an iterator not"
2828 1.1 joerg " referring to this string");
2829 1.1 joerg #endif
2830 1.1 joerg size_type __ip = static_cast<size_type>(__pos - begin());
2831 1.1 joerg size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2832 1.1 joerg if (__n)
2833 1.1 joerg {
2834 1.1 joerg if (__string_is_trivial_iterator<_ForwardIterator>::value &&
2835 1.1 joerg !__addr_in_range(*__first))
2836 1.1 joerg {
2837 1.1 joerg size_type __sz = size();
2838 1.1 joerg size_type __cap = capacity();
2839 1.1 joerg value_type* __p;
2840 1.1 joerg if (__cap - __sz >= __n)
2841 1.1 joerg {
2842 1.1 joerg __p = _VSTD::__to_address(__get_pointer());
2843 1.1 joerg size_type __n_move = __sz - __ip;
2844 1.1 joerg if (__n_move != 0)
2845 1.1 joerg traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2846 1.1 joerg }
2847 1.1 joerg else
2848 1.1 joerg {
2849 1.1 joerg __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
2850 1.1 joerg __p = _VSTD::__to_address(__get_long_pointer());
2851 1.1 joerg }
2852 1.1 joerg __sz += __n;
2853 1.1 joerg __set_size(__sz);
2854 1.1 joerg traits_type::assign(__p[__sz], value_type());
2855 1.1 joerg for (__p += __ip; __first != __last; ++__p, ++__first)
2856 1.1 joerg traits_type::assign(*__p, *__first);
2857 1.1 joerg }
2858 1.1 joerg else
2859 1.1 joerg {
2860 1.1 joerg const basic_string __temp(__first, __last, __alloc());
2861 1.1 joerg return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2862 1.1 joerg }
2863 1.1 joerg }
2864 1.1 joerg return begin() + __ip;
2865 1.1 joerg }
2866 1.1 joerg
2867 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2868 1.1 joerg inline
2869 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2870 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2871 1.1 joerg {
2872 1.1 joerg return insert(__pos1, __str.data(), __str.size());
2873 1.1 joerg }
2874 1.1 joerg
2875 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2876 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2877 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2878 1.1 joerg size_type __pos2, size_type __n)
2879 1.1 joerg {
2880 1.1 joerg size_type __str_sz = __str.size();
2881 1.1 joerg if (__pos2 > __str_sz)
2882 1.1 joerg this->__throw_out_of_range();
2883 1.1 joerg return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2884 1.1 joerg }
2885 1.1 joerg
2886 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2887 1.1 joerg template <class _Tp>
2888 1.1 joerg _EnableIf
2889 1.1 joerg <
2890 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
2891 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2892 1.1 joerg >
2893 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
2894 1.1 joerg size_type __pos2, size_type __n)
2895 1.1 joerg {
2896 1.1 joerg __self_view __sv = __t;
2897 1.1 joerg size_type __str_sz = __sv.size();
2898 1.1 joerg if (__pos2 > __str_sz)
2899 1.1 joerg this->__throw_out_of_range();
2900 1.1 joerg return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2901 1.1 joerg }
2902 1.1 joerg
2903 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2904 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2905 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
2906 1.1 joerg {
2907 1.1 joerg _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
2908 1.1 joerg return insert(__pos, __s, traits_type::length(__s));
2909 1.1 joerg }
2910 1.1 joerg
2911 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2912 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::iterator
2913 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2914 1.1 joerg {
2915 1.1 joerg size_type __ip = static_cast<size_type>(__pos - begin());
2916 1.1 joerg size_type __sz = size();
2917 1.1 joerg size_type __cap = capacity();
2918 1.1 joerg value_type* __p;
2919 1.1 joerg if (__cap == __sz)
2920 1.1 joerg {
2921 1.1 joerg __grow_by(__cap, 1, __sz, __ip, 0, 1);
2922 1.1 joerg __p = _VSTD::__to_address(__get_long_pointer());
2923 1.1 joerg }
2924 1.1 joerg else
2925 1.1 joerg {
2926 1.1 joerg __p = _VSTD::__to_address(__get_pointer());
2927 1.1 joerg size_type __n_move = __sz - __ip;
2928 1.1 joerg if (__n_move != 0)
2929 1.1 joerg traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2930 1.1 joerg }
2931 1.1 joerg traits_type::assign(__p[__ip], __c);
2932 1.1 joerg traits_type::assign(__p[++__sz], value_type());
2933 1.1 joerg __set_size(__sz);
2934 1.1 joerg return begin() + static_cast<difference_type>(__ip);
2935 1.1 joerg }
2936 1.1 joerg
2937 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2938 1.1 joerg inline
2939 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::iterator
2940 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2941 1.1 joerg {
2942 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
2943 1.1 joerg _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2944 1.1 joerg "string::insert(iterator, n, value) called with an iterator not"
2945 1.1 joerg " referring to this string");
2946 1.1 joerg #endif
2947 1.1 joerg difference_type __p = __pos - begin();
2948 1.1 joerg insert(static_cast<size_type>(__p), __n, __c);
2949 1.1 joerg return begin() + __p;
2950 1.1 joerg }
2951 1.1 joerg
2952 1.1 joerg // replace
2953 1.1 joerg
2954 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
2955 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
2956 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
2957 1.1 joerg _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
2958 1.1 joerg {
2959 1.1 joerg _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
2960 1.1 joerg size_type __sz = size();
2961 1.1 joerg if (__pos > __sz)
2962 1.1 joerg this->__throw_out_of_range();
2963 1.1 joerg __n1 = _VSTD::min(__n1, __sz - __pos);
2964 1.1 joerg size_type __cap = capacity();
2965 1.1 joerg if (__cap - __sz + __n1 >= __n2)
2966 1.1 joerg {
2967 1.1 joerg value_type* __p = _VSTD::__to_address(__get_pointer());
2968 1.1 joerg if (__n1 != __n2)
2969 1.1 joerg {
2970 1.1 joerg size_type __n_move = __sz - __pos - __n1;
2971 1.1 joerg if (__n_move != 0)
2972 1.1 joerg {
2973 1.1 joerg if (__n1 > __n2)
2974 1.1 joerg {
2975 1.1 joerg traits_type::move(__p + __pos, __s, __n2);
2976 1.1 joerg traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2977 1.1 joerg goto __finish;
2978 1.1 joerg }
2979 1.1 joerg if (__p + __pos < __s && __s < __p + __sz)
2980 1.1 joerg {
2981 1.1 joerg if (__p + __pos + __n1 <= __s)
2982 1.1 joerg __s += __n2 - __n1;
2983 1.1 joerg else // __p + __pos < __s < __p + __pos + __n1
2984 1.1 joerg {
2985 1.1 joerg traits_type::move(__p + __pos, __s, __n1);
2986 1.1 joerg __pos += __n1;
2987 1.1 joerg __s += __n2;
2988 1.1 joerg __n2 -= __n1;
2989 1.1 joerg __n1 = 0;
2990 1.1 joerg }
2991 1.1 joerg }
2992 1.1 joerg traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2993 1.1 joerg }
2994 1.1 joerg }
2995 1.1 joerg traits_type::move(__p + __pos, __s, __n2);
2996 1.1 joerg __finish:
2997 1.1 joerg // __sz += __n2 - __n1; in this and the below function below can cause unsigned
2998 1.1 joerg // integer overflow, but this is a safe operation, so we disable the check.
2999 1.1 joerg __sz += __n2 - __n1;
3000 1.1 joerg __set_size(__sz);
3001 1.1 joerg __invalidate_iterators_past(__sz);
3002 1.1 joerg traits_type::assign(__p[__sz], value_type());
3003 1.1 joerg }
3004 1.1 joerg else
3005 1.1 joerg __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
3006 1.1 joerg return *this;
3007 1.1 joerg }
3008 1.1 joerg
3009 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3010 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
3011 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
3012 1.1 joerg _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
3013 1.1 joerg {
3014 1.1 joerg size_type __sz = size();
3015 1.1 joerg if (__pos > __sz)
3016 1.1 joerg this->__throw_out_of_range();
3017 1.1 joerg __n1 = _VSTD::min(__n1, __sz - __pos);
3018 1.1 joerg size_type __cap = capacity();
3019 1.1 joerg value_type* __p;
3020 1.1 joerg if (__cap - __sz + __n1 >= __n2)
3021 1.1 joerg {
3022 1.1 joerg __p = _VSTD::__to_address(__get_pointer());
3023 1.1 joerg if (__n1 != __n2)
3024 1.1 joerg {
3025 1.1 joerg size_type __n_move = __sz - __pos - __n1;
3026 1.1 joerg if (__n_move != 0)
3027 1.1 joerg traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
3028 1.1 joerg }
3029 1.1 joerg }
3030 1.1 joerg else
3031 1.1 joerg {
3032 1.1 joerg __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
3033 1.1 joerg __p = _VSTD::__to_address(__get_long_pointer());
3034 1.1 joerg }
3035 1.1 joerg traits_type::assign(__p + __pos, __n2, __c);
3036 1.1 joerg __sz += __n2 - __n1;
3037 1.1 joerg __set_size(__sz);
3038 1.1 joerg __invalidate_iterators_past(__sz);
3039 1.1 joerg traits_type::assign(__p[__sz], value_type());
3040 1.1 joerg return *this;
3041 1.1 joerg }
3042 1.1 joerg
3043 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3044 1.1 joerg template<class _InputIterator>
3045 1.1 joerg _EnableIf
3046 1.1 joerg <
3047 1.1 joerg __is_cpp17_input_iterator<_InputIterator>::value,
3048 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
3049 1.1 joerg >
3050 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
3051 1.1 joerg _InputIterator __j1, _InputIterator __j2)
3052 1.1 joerg {
3053 1.1 joerg const basic_string __temp(__j1, __j2, __alloc());
3054 1.1 joerg return this->replace(__i1, __i2, __temp);
3055 1.1 joerg }
3056 1.1 joerg
3057 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3058 1.1 joerg inline
3059 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
3060 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
3061 1.1 joerg {
3062 1.1 joerg return replace(__pos1, __n1, __str.data(), __str.size());
3063 1.1 joerg }
3064 1.1 joerg
3065 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3066 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
3067 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
3068 1.1 joerg size_type __pos2, size_type __n2)
3069 1.1 joerg {
3070 1.1 joerg size_type __str_sz = __str.size();
3071 1.1 joerg if (__pos2 > __str_sz)
3072 1.1 joerg this->__throw_out_of_range();
3073 1.1 joerg return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
3074 1.1 joerg }
3075 1.1 joerg
3076 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3077 1.1 joerg template <class _Tp>
3078 1.1 joerg _EnableIf
3079 1.1 joerg <
3080 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
3081 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
3082 1.1 joerg >
3083 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
3084 1.1 joerg size_type __pos2, size_type __n2)
3085 1.1 joerg {
3086 1.1 joerg __self_view __sv = __t;
3087 1.1 joerg size_type __str_sz = __sv.size();
3088 1.1 joerg if (__pos2 > __str_sz)
3089 1.1 joerg this->__throw_out_of_range();
3090 1.1 joerg return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
3091 1.1 joerg }
3092 1.1 joerg
3093 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3094 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
3095 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
3096 1.1 joerg {
3097 1.1 joerg _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
3098 1.1 joerg return replace(__pos, __n1, __s, traits_type::length(__s));
3099 1.1 joerg }
3100 1.1 joerg
3101 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3102 1.1 joerg inline
3103 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
3104 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
3105 1.1 joerg {
3106 1.1 joerg return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
3107 1.1 joerg __str.data(), __str.size());
3108 1.1 joerg }
3109 1.1 joerg
3110 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3111 1.1 joerg inline
3112 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
3113 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
3114 1.1 joerg {
3115 1.1 joerg return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
3116 1.1 joerg }
3117 1.1 joerg
3118 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3119 1.1 joerg inline
3120 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
3121 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
3122 1.1 joerg {
3123 1.1 joerg return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
3124 1.1 joerg }
3125 1.1 joerg
3126 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3127 1.1 joerg inline
3128 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
3129 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
3130 1.1 joerg {
3131 1.1 joerg return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
3132 1.1 joerg }
3133 1.1 joerg
3134 1.1 joerg // erase
3135 1.1 joerg
3136 1.1 joerg // 'externally instantiated' erase() implementation, called when __n != npos.
3137 1.1 joerg // Does not check __pos against size()
3138 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3139 1.1 joerg void
3140 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move(
3141 1.1 joerg size_type __pos, size_type __n)
3142 1.1 joerg {
3143 1.1 joerg if (__n)
3144 1.1 joerg {
3145 1.1 joerg size_type __sz = size();
3146 1.1 joerg value_type* __p = _VSTD::__to_address(__get_pointer());
3147 1.1 joerg __n = _VSTD::min(__n, __sz - __pos);
3148 1.1 joerg size_type __n_move = __sz - __pos - __n;
3149 1.1 joerg if (__n_move != 0)
3150 1.1 joerg traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3151 1.1 joerg __sz -= __n;
3152 1.1 joerg __set_size(__sz);
3153 1.1 joerg __invalidate_iterators_past(__sz);
3154 1.1 joerg traits_type::assign(__p[__sz], value_type());
3155 1.1 joerg }
3156 1.1 joerg }
3157 1.1 joerg
3158 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3159 1.1 joerg basic_string<_CharT, _Traits, _Allocator>&
3160 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos,
3161 1.1 joerg size_type __n) {
3162 1.1 joerg if (__pos > size()) this->__throw_out_of_range();
3163 1.1 joerg if (__n == npos) {
3164 1.1 joerg __erase_to_end(__pos);
3165 1.1 joerg } else {
3166 1.1 joerg __erase_external_with_move(__pos, __n);
3167 1.1 joerg }
3168 1.1 joerg return *this;
3169 1.1 joerg }
3170 1.1 joerg
3171 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3172 1.1 joerg inline
3173 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::iterator
3174 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3175 1.1 joerg {
3176 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
3177 1.1 joerg _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3178 1.1 joerg "string::erase(iterator) called with an iterator not"
3179 1.1 joerg " referring to this string");
3180 1.1 joerg #endif
3181 1.1 joerg _LIBCPP_ASSERT(__pos != end(),
3182 1.1 joerg "string::erase(iterator) called with a non-dereferenceable iterator");
3183 1.1 joerg iterator __b = begin();
3184 1.1 joerg size_type __r = static_cast<size_type>(__pos - __b);
3185 1.1 joerg erase(__r, 1);
3186 1.1 joerg return __b + static_cast<difference_type>(__r);
3187 1.1 joerg }
3188 1.1 joerg
3189 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3190 1.1 joerg inline
3191 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::iterator
3192 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3193 1.1 joerg {
3194 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
3195 1.1 joerg _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3196 1.1 joerg "string::erase(iterator, iterator) called with an iterator not"
3197 1.1 joerg " referring to this string");
3198 1.1 joerg #endif
3199 1.1 joerg _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
3200 1.1 joerg iterator __b = begin();
3201 1.1 joerg size_type __r = static_cast<size_type>(__first - __b);
3202 1.1 joerg erase(__r, static_cast<size_type>(__last - __first));
3203 1.1 joerg return __b + static_cast<difference_type>(__r);
3204 1.1 joerg }
3205 1.1 joerg
3206 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3207 1.1 joerg inline
3208 1.1 joerg void
3209 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::pop_back()
3210 1.1 joerg {
3211 1.1 joerg _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
3212 1.1 joerg size_type __sz;
3213 1.1 joerg if (__is_long())
3214 1.1 joerg {
3215 1.1 joerg __sz = __get_long_size() - 1;
3216 1.1 joerg __set_long_size(__sz);
3217 1.1 joerg traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3218 1.1 joerg }
3219 1.1 joerg else
3220 1.1 joerg {
3221 1.1 joerg __sz = __get_short_size() - 1;
3222 1.1 joerg __set_short_size(__sz);
3223 1.1 joerg traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3224 1.1 joerg }
3225 1.1 joerg __invalidate_iterators_past(__sz);
3226 1.1 joerg }
3227 1.1 joerg
3228 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3229 1.1 joerg inline
3230 1.1 joerg void
3231 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
3232 1.1 joerg {
3233 1.1 joerg __invalidate_all_iterators();
3234 1.1 joerg if (__is_long())
3235 1.1 joerg {
3236 1.1 joerg traits_type::assign(*__get_long_pointer(), value_type());
3237 1.1 joerg __set_long_size(0);
3238 1.1 joerg }
3239 1.1 joerg else
3240 1.1 joerg {
3241 1.1 joerg traits_type::assign(*__get_short_pointer(), value_type());
3242 1.1 joerg __set_short_size(0);
3243 1.1 joerg }
3244 1.1 joerg }
3245 1.1 joerg
3246 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3247 1.1 joerg inline
3248 1.1 joerg void
3249 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3250 1.1 joerg {
3251 1.1 joerg if (__is_long())
3252 1.1 joerg {
3253 1.1 joerg traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3254 1.1 joerg __set_long_size(__pos);
3255 1.1 joerg }
3256 1.1 joerg else
3257 1.1 joerg {
3258 1.1 joerg traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3259 1.1 joerg __set_short_size(__pos);
3260 1.1 joerg }
3261 1.1 joerg __invalidate_iterators_past(__pos);
3262 1.1 joerg }
3263 1.1 joerg
3264 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3265 1.1 joerg void
3266 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3267 1.1 joerg {
3268 1.1 joerg size_type __sz = size();
3269 1.1 joerg if (__n > __sz)
3270 1.1 joerg append(__n - __sz, __c);
3271 1.1 joerg else
3272 1.1 joerg __erase_to_end(__n);
3273 1.1 joerg }
3274 1.1 joerg
3275 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3276 1.1 joerg inline void
3277 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
3278 1.1 joerg {
3279 1.1 joerg size_type __sz = size();
3280 1.1 joerg if (__n > __sz) {
3281 1.1 joerg __append_default_init(__n - __sz);
3282 1.1 joerg } else
3283 1.1 joerg __erase_to_end(__n);
3284 1.1 joerg }
3285 1.1 joerg
3286 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3287 1.1 joerg inline
3288 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3289 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
3290 1.1 joerg {
3291 1.1 joerg size_type __m = __alloc_traits::max_size(__alloc());
3292 1.1 joerg #ifdef _LIBCPP_BIG_ENDIAN
3293 1.1 joerg return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
3294 1.1 joerg #else
3295 1.1 joerg return __m - __alignment;
3296 1.1 joerg #endif
3297 1.1 joerg }
3298 1.1 joerg
3299 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3300 1.1 joerg void
3301 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity)
3302 1.1 joerg {
3303 1.1 joerg if (__requested_capacity > max_size())
3304 1.1 joerg this->__throw_length_error();
3305 1.1 joerg
3306 1.1 joerg #if _LIBCPP_STD_VER > 17
3307 1.1 joerg // Reserve never shrinks as of C++20.
3308 1.1 joerg if (__requested_capacity <= capacity()) return;
3309 1.1 joerg #endif
3310 1.1 joerg
3311 1.1 joerg size_type __target_capacity = _VSTD::max(__requested_capacity, size());
3312 1.1 joerg __target_capacity = __recommend(__target_capacity);
3313 1.1 joerg if (__target_capacity == capacity()) return;
3314 1.1 joerg
3315 1.1 joerg __shrink_or_extend(__target_capacity);
3316 1.1 joerg }
3317 1.1 joerg
3318 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3319 1.1 joerg void
3320 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT
3321 1.1 joerg {
3322 1.1 joerg size_type __target_capacity = __recommend(size());
3323 1.1 joerg if (__target_capacity == capacity()) return;
3324 1.1 joerg
3325 1.1 joerg __shrink_or_extend(__target_capacity);
3326 1.1 joerg }
3327 1.1 joerg
3328 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3329 1.1 joerg void
3330 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity)
3331 1.1 joerg {
3332 1.1 joerg size_type __cap = capacity();
3333 1.1 joerg size_type __sz = size();
3334 1.1 joerg
3335 1.1 joerg pointer __new_data, __p;
3336 1.1 joerg bool __was_long, __now_long;
3337 1.1 joerg if (__target_capacity == __min_cap - 1)
3338 1.1 joerg {
3339 1.1 joerg __was_long = true;
3340 1.1 joerg __now_long = false;
3341 1.1 joerg __new_data = __get_short_pointer();
3342 1.1 joerg __p = __get_long_pointer();
3343 1.1 joerg }
3344 1.1 joerg else
3345 1.1 joerg {
3346 1.1 joerg if (__target_capacity > __cap)
3347 1.1 joerg __new_data = __alloc_traits::allocate(__alloc(), __target_capacity+1);
3348 1.1 joerg else
3349 1.1 joerg {
3350 1.1 joerg #ifndef _LIBCPP_NO_EXCEPTIONS
3351 1.1 joerg try
3352 1.1 joerg {
3353 1.1 joerg #endif // _LIBCPP_NO_EXCEPTIONS
3354 1.1 joerg __new_data = __alloc_traits::allocate(__alloc(), __target_capacity+1);
3355 1.1 joerg #ifndef _LIBCPP_NO_EXCEPTIONS
3356 1.1 joerg }
3357 1.1 joerg catch (...)
3358 1.1 joerg {
3359 1.1 joerg return;
3360 1.1 joerg }
3361 1.1 joerg #else // _LIBCPP_NO_EXCEPTIONS
3362 1.1 joerg if (__new_data == nullptr)
3363 1.1 joerg return;
3364 1.1 joerg #endif // _LIBCPP_NO_EXCEPTIONS
3365 1.1 joerg }
3366 1.1 joerg __now_long = true;
3367 1.1 joerg __was_long = __is_long();
3368 1.1 joerg __p = __get_pointer();
3369 1.1 joerg }
3370 1.1 joerg traits_type::copy(_VSTD::__to_address(__new_data),
3371 1.1 joerg _VSTD::__to_address(__p), size()+1);
3372 1.1 joerg if (__was_long)
3373 1.1 joerg __alloc_traits::deallocate(__alloc(), __p, __cap+1);
3374 1.1 joerg if (__now_long)
3375 1.1 joerg {
3376 1.1 joerg __set_long_cap(__target_capacity+1);
3377 1.1 joerg __set_long_size(__sz);
3378 1.1 joerg __set_long_pointer(__new_data);
3379 1.1 joerg }
3380 1.1 joerg else
3381 1.1 joerg __set_short_size(__sz);
3382 1.1 joerg __invalidate_all_iterators();
3383 1.1 joerg }
3384 1.1 joerg
3385 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3386 1.1 joerg inline
3387 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3388 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
3389 1.1 joerg {
3390 1.1 joerg _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
3391 1.1 joerg return *(data() + __pos);
3392 1.1 joerg }
3393 1.1 joerg
3394 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3395 1.1 joerg inline
3396 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::reference
3397 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
3398 1.1 joerg {
3399 1.1 joerg _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
3400 1.1 joerg return *(__get_pointer() + __pos);
3401 1.1 joerg }
3402 1.1 joerg
3403 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3404 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3405 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3406 1.1 joerg {
3407 1.1 joerg if (__n >= size())
3408 1.1 joerg this->__throw_out_of_range();
3409 1.1 joerg return (*this)[__n];
3410 1.1 joerg }
3411 1.1 joerg
3412 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3413 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::reference
3414 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3415 1.1 joerg {
3416 1.1 joerg if (__n >= size())
3417 1.1 joerg this->__throw_out_of_range();
3418 1.1 joerg return (*this)[__n];
3419 1.1 joerg }
3420 1.1 joerg
3421 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3422 1.1 joerg inline
3423 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::reference
3424 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT
3425 1.1 joerg {
3426 1.1 joerg _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
3427 1.1 joerg return *__get_pointer();
3428 1.1 joerg }
3429 1.1 joerg
3430 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3431 1.1 joerg inline
3432 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3433 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT
3434 1.1 joerg {
3435 1.1 joerg _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
3436 1.1 joerg return *data();
3437 1.1 joerg }
3438 1.1 joerg
3439 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3440 1.1 joerg inline
3441 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::reference
3442 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT
3443 1.1 joerg {
3444 1.1 joerg _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
3445 1.1 joerg return *(__get_pointer() + size() - 1);
3446 1.1 joerg }
3447 1.1 joerg
3448 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3449 1.1 joerg inline
3450 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3451 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT
3452 1.1 joerg {
3453 1.1 joerg _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
3454 1.1 joerg return *(data() + size() - 1);
3455 1.1 joerg }
3456 1.1 joerg
3457 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3458 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3459 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
3460 1.1 joerg {
3461 1.1 joerg size_type __sz = size();
3462 1.1 joerg if (__pos > __sz)
3463 1.1 joerg this->__throw_out_of_range();
3464 1.1 joerg size_type __rlen = _VSTD::min(__n, __sz - __pos);
3465 1.1 joerg traits_type::copy(__s, data() + __pos, __rlen);
3466 1.1 joerg return __rlen;
3467 1.1 joerg }
3468 1.1 joerg
3469 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3470 1.1 joerg inline
3471 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
3472 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3473 1.1 joerg {
3474 1.1 joerg return basic_string(*this, __pos, __n, __alloc());
3475 1.1 joerg }
3476 1.1 joerg
3477 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3478 1.1 joerg inline
3479 1.1 joerg void
3480 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
3481 1.1 joerg #if _LIBCPP_STD_VER >= 14
3482 1.1 joerg _NOEXCEPT
3483 1.1 joerg #else
3484 1.1 joerg _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3485 1.1 joerg __is_nothrow_swappable<allocator_type>::value)
3486 1.1 joerg #endif
3487 1.1 joerg {
3488 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
3489 1.1 joerg if (!__is_long())
3490 1.1 joerg __get_db()->__invalidate_all(this);
3491 1.1 joerg if (!__str.__is_long())
3492 1.1 joerg __get_db()->__invalidate_all(&__str);
3493 1.1 joerg __get_db()->swap(this, &__str);
3494 1.1 joerg #endif
3495 1.1 joerg _LIBCPP_ASSERT(
3496 1.1 joerg __alloc_traits::propagate_on_container_swap::value ||
3497 1.1 joerg __alloc_traits::is_always_equal::value ||
3498 1.1 joerg __alloc() == __str.__alloc(), "swapping non-equal allocators");
3499 1.1 joerg _VSTD::swap(__r_.first(), __str.__r_.first());
3500 1.1 joerg _VSTD::__swap_allocator(__alloc(), __str.__alloc());
3501 1.1 joerg }
3502 1.1 joerg
3503 1.1 joerg // find
3504 1.1 joerg
3505 1.1 joerg template <class _Traits>
3506 1.1 joerg struct _LIBCPP_HIDDEN __traits_eq
3507 1.1 joerg {
3508 1.1 joerg typedef typename _Traits::char_type char_type;
3509 1.1 joerg _LIBCPP_INLINE_VISIBILITY
3510 1.1 joerg bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3511 1.1 joerg {return _Traits::eq(__x, __y);}
3512 1.1 joerg };
3513 1.1 joerg
3514 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3515 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3516 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3517 1.1 joerg size_type __pos,
3518 1.1 joerg size_type __n) const _NOEXCEPT
3519 1.1 joerg {
3520 1.1 joerg _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
3521 1.1 joerg return __str_find<value_type, size_type, traits_type, npos>
3522 1.1 joerg (data(), size(), __s, __pos, __n);
3523 1.1 joerg }
3524 1.1 joerg
3525 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3526 1.1 joerg inline
3527 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3528 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3529 1.1 joerg size_type __pos) const _NOEXCEPT
3530 1.1 joerg {
3531 1.1 joerg return __str_find<value_type, size_type, traits_type, npos>
3532 1.1 joerg (data(), size(), __str.data(), __pos, __str.size());
3533 1.1 joerg }
3534 1.1 joerg
3535 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3536 1.1 joerg template <class _Tp>
3537 1.1 joerg _EnableIf
3538 1.1 joerg <
3539 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3540 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3541 1.1 joerg >
3542 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
3543 1.1 joerg size_type __pos) const _NOEXCEPT
3544 1.1 joerg {
3545 1.1 joerg __self_view __sv = __t;
3546 1.1 joerg return __str_find<value_type, size_type, traits_type, npos>
3547 1.1 joerg (data(), size(), __sv.data(), __pos, __sv.size());
3548 1.1 joerg }
3549 1.1 joerg
3550 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3551 1.1 joerg inline
3552 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3553 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3554 1.1 joerg size_type __pos) const _NOEXCEPT
3555 1.1 joerg {
3556 1.1 joerg _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
3557 1.1 joerg return __str_find<value_type, size_type, traits_type, npos>
3558 1.1 joerg (data(), size(), __s, __pos, traits_type::length(__s));
3559 1.1 joerg }
3560 1.1 joerg
3561 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3562 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3563 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3564 1.1 joerg size_type __pos) const _NOEXCEPT
3565 1.1 joerg {
3566 1.1 joerg return __str_find<value_type, size_type, traits_type, npos>
3567 1.1 joerg (data(), size(), __c, __pos);
3568 1.1 joerg }
3569 1.1 joerg
3570 1.1 joerg // rfind
3571 1.1 joerg
3572 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3573 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3574 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3575 1.1 joerg size_type __pos,
3576 1.1 joerg size_type __n) const _NOEXCEPT
3577 1.1 joerg {
3578 1.1 joerg _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
3579 1.1 joerg return __str_rfind<value_type, size_type, traits_type, npos>
3580 1.1 joerg (data(), size(), __s, __pos, __n);
3581 1.1 joerg }
3582 1.1 joerg
3583 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3584 1.1 joerg inline
3585 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3586 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3587 1.1 joerg size_type __pos) const _NOEXCEPT
3588 1.1 joerg {
3589 1.1 joerg return __str_rfind<value_type, size_type, traits_type, npos>
3590 1.1 joerg (data(), size(), __str.data(), __pos, __str.size());
3591 1.1 joerg }
3592 1.1 joerg
3593 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3594 1.1 joerg template <class _Tp>
3595 1.1 joerg _EnableIf
3596 1.1 joerg <
3597 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3598 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3599 1.1 joerg >
3600 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
3601 1.1 joerg size_type __pos) const _NOEXCEPT
3602 1.1 joerg {
3603 1.1 joerg __self_view __sv = __t;
3604 1.1 joerg return __str_rfind<value_type, size_type, traits_type, npos>
3605 1.1 joerg (data(), size(), __sv.data(), __pos, __sv.size());
3606 1.1 joerg }
3607 1.1 joerg
3608 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3609 1.1 joerg inline
3610 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3611 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3612 1.1 joerg size_type __pos) const _NOEXCEPT
3613 1.1 joerg {
3614 1.1 joerg _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
3615 1.1 joerg return __str_rfind<value_type, size_type, traits_type, npos>
3616 1.1 joerg (data(), size(), __s, __pos, traits_type::length(__s));
3617 1.1 joerg }
3618 1.1 joerg
3619 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3620 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3621 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3622 1.1 joerg size_type __pos) const _NOEXCEPT
3623 1.1 joerg {
3624 1.1 joerg return __str_rfind<value_type, size_type, traits_type, npos>
3625 1.1 joerg (data(), size(), __c, __pos);
3626 1.1 joerg }
3627 1.1 joerg
3628 1.1 joerg // find_first_of
3629 1.1 joerg
3630 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3631 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3632 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3633 1.1 joerg size_type __pos,
3634 1.1 joerg size_type __n) const _NOEXCEPT
3635 1.1 joerg {
3636 1.1 joerg _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
3637 1.1 joerg return __str_find_first_of<value_type, size_type, traits_type, npos>
3638 1.1 joerg (data(), size(), __s, __pos, __n);
3639 1.1 joerg }
3640 1.1 joerg
3641 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3642 1.1 joerg inline
3643 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3644 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3645 1.1 joerg size_type __pos) const _NOEXCEPT
3646 1.1 joerg {
3647 1.1 joerg return __str_find_first_of<value_type, size_type, traits_type, npos>
3648 1.1 joerg (data(), size(), __str.data(), __pos, __str.size());
3649 1.1 joerg }
3650 1.1 joerg
3651 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3652 1.1 joerg template <class _Tp>
3653 1.1 joerg _EnableIf
3654 1.1 joerg <
3655 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3656 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3657 1.1 joerg >
3658 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
3659 1.1 joerg size_type __pos) const _NOEXCEPT
3660 1.1 joerg {
3661 1.1 joerg __self_view __sv = __t;
3662 1.1 joerg return __str_find_first_of<value_type, size_type, traits_type, npos>
3663 1.1 joerg (data(), size(), __sv.data(), __pos, __sv.size());
3664 1.1 joerg }
3665 1.1 joerg
3666 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3667 1.1 joerg inline
3668 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3669 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3670 1.1 joerg size_type __pos) const _NOEXCEPT
3671 1.1 joerg {
3672 1.1 joerg _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
3673 1.1 joerg return __str_find_first_of<value_type, size_type, traits_type, npos>
3674 1.1 joerg (data(), size(), __s, __pos, traits_type::length(__s));
3675 1.1 joerg }
3676 1.1 joerg
3677 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3678 1.1 joerg inline
3679 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3680 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3681 1.1 joerg size_type __pos) const _NOEXCEPT
3682 1.1 joerg {
3683 1.1 joerg return find(__c, __pos);
3684 1.1 joerg }
3685 1.1 joerg
3686 1.1 joerg // find_last_of
3687 1.1 joerg
3688 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3689 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3690 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3691 1.1 joerg size_type __pos,
3692 1.1 joerg size_type __n) const _NOEXCEPT
3693 1.1 joerg {
3694 1.1 joerg _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
3695 1.1 joerg return __str_find_last_of<value_type, size_type, traits_type, npos>
3696 1.1 joerg (data(), size(), __s, __pos, __n);
3697 1.1 joerg }
3698 1.1 joerg
3699 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3700 1.1 joerg inline
3701 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3702 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3703 1.1 joerg size_type __pos) const _NOEXCEPT
3704 1.1 joerg {
3705 1.1 joerg return __str_find_last_of<value_type, size_type, traits_type, npos>
3706 1.1 joerg (data(), size(), __str.data(), __pos, __str.size());
3707 1.1 joerg }
3708 1.1 joerg
3709 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3710 1.1 joerg template <class _Tp>
3711 1.1 joerg _EnableIf
3712 1.1 joerg <
3713 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3714 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3715 1.1 joerg >
3716 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
3717 1.1 joerg size_type __pos) const _NOEXCEPT
3718 1.1 joerg {
3719 1.1 joerg __self_view __sv = __t;
3720 1.1 joerg return __str_find_last_of<value_type, size_type, traits_type, npos>
3721 1.1 joerg (data(), size(), __sv.data(), __pos, __sv.size());
3722 1.1 joerg }
3723 1.1 joerg
3724 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3725 1.1 joerg inline
3726 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3727 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3728 1.1 joerg size_type __pos) const _NOEXCEPT
3729 1.1 joerg {
3730 1.1 joerg _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
3731 1.1 joerg return __str_find_last_of<value_type, size_type, traits_type, npos>
3732 1.1 joerg (data(), size(), __s, __pos, traits_type::length(__s));
3733 1.1 joerg }
3734 1.1 joerg
3735 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3736 1.1 joerg inline
3737 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3738 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3739 1.1 joerg size_type __pos) const _NOEXCEPT
3740 1.1 joerg {
3741 1.1 joerg return rfind(__c, __pos);
3742 1.1 joerg }
3743 1.1 joerg
3744 1.1 joerg // find_first_not_of
3745 1.1 joerg
3746 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3747 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3748 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3749 1.1 joerg size_type __pos,
3750 1.1 joerg size_type __n) const _NOEXCEPT
3751 1.1 joerg {
3752 1.1 joerg _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
3753 1.1 joerg return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3754 1.1 joerg (data(), size(), __s, __pos, __n);
3755 1.1 joerg }
3756 1.1 joerg
3757 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3758 1.1 joerg inline
3759 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3760 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3761 1.1 joerg size_type __pos) const _NOEXCEPT
3762 1.1 joerg {
3763 1.1 joerg return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3764 1.1 joerg (data(), size(), __str.data(), __pos, __str.size());
3765 1.1 joerg }
3766 1.1 joerg
3767 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3768 1.1 joerg template <class _Tp>
3769 1.1 joerg _EnableIf
3770 1.1 joerg <
3771 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3772 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3773 1.1 joerg >
3774 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
3775 1.1 joerg size_type __pos) const _NOEXCEPT
3776 1.1 joerg {
3777 1.1 joerg __self_view __sv = __t;
3778 1.1 joerg return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3779 1.1 joerg (data(), size(), __sv.data(), __pos, __sv.size());
3780 1.1 joerg }
3781 1.1 joerg
3782 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3783 1.1 joerg inline
3784 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3785 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3786 1.1 joerg size_type __pos) const _NOEXCEPT
3787 1.1 joerg {
3788 1.1 joerg _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
3789 1.1 joerg return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3790 1.1 joerg (data(), size(), __s, __pos, traits_type::length(__s));
3791 1.1 joerg }
3792 1.1 joerg
3793 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3794 1.1 joerg inline
3795 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3796 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3797 1.1 joerg size_type __pos) const _NOEXCEPT
3798 1.1 joerg {
3799 1.1 joerg return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3800 1.1 joerg (data(), size(), __c, __pos);
3801 1.1 joerg }
3802 1.1 joerg
3803 1.1 joerg // find_last_not_of
3804 1.1 joerg
3805 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3806 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3807 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3808 1.1 joerg size_type __pos,
3809 1.1 joerg size_type __n) const _NOEXCEPT
3810 1.1 joerg {
3811 1.1 joerg _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
3812 1.1 joerg return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3813 1.1 joerg (data(), size(), __s, __pos, __n);
3814 1.1 joerg }
3815 1.1 joerg
3816 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3817 1.1 joerg inline
3818 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3819 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3820 1.1 joerg size_type __pos) const _NOEXCEPT
3821 1.1 joerg {
3822 1.1 joerg return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3823 1.1 joerg (data(), size(), __str.data(), __pos, __str.size());
3824 1.1 joerg }
3825 1.1 joerg
3826 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3827 1.1 joerg template <class _Tp>
3828 1.1 joerg _EnableIf
3829 1.1 joerg <
3830 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3831 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3832 1.1 joerg >
3833 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
3834 1.1 joerg size_type __pos) const _NOEXCEPT
3835 1.1 joerg {
3836 1.1 joerg __self_view __sv = __t;
3837 1.1 joerg return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3838 1.1 joerg (data(), size(), __sv.data(), __pos, __sv.size());
3839 1.1 joerg }
3840 1.1 joerg
3841 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3842 1.1 joerg inline
3843 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3844 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3845 1.1 joerg size_type __pos) const _NOEXCEPT
3846 1.1 joerg {
3847 1.1 joerg _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
3848 1.1 joerg return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3849 1.1 joerg (data(), size(), __s, __pos, traits_type::length(__s));
3850 1.1 joerg }
3851 1.1 joerg
3852 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3853 1.1 joerg inline
3854 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
3855 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3856 1.1 joerg size_type __pos) const _NOEXCEPT
3857 1.1 joerg {
3858 1.1 joerg return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3859 1.1 joerg (data(), size(), __c, __pos);
3860 1.1 joerg }
3861 1.1 joerg
3862 1.1 joerg // compare
3863 1.1 joerg
3864 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3865 1.1 joerg template <class _Tp>
3866 1.1 joerg _EnableIf
3867 1.1 joerg <
3868 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3869 1.1 joerg int
3870 1.1 joerg >
3871 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCEPT
3872 1.1 joerg {
3873 1.1 joerg __self_view __sv = __t;
3874 1.1 joerg size_t __lhs_sz = size();
3875 1.1 joerg size_t __rhs_sz = __sv.size();
3876 1.1 joerg int __result = traits_type::compare(data(), __sv.data(),
3877 1.1 joerg _VSTD::min(__lhs_sz, __rhs_sz));
3878 1.1 joerg if (__result != 0)
3879 1.1 joerg return __result;
3880 1.1 joerg if (__lhs_sz < __rhs_sz)
3881 1.1 joerg return -1;
3882 1.1 joerg if (__lhs_sz > __rhs_sz)
3883 1.1 joerg return 1;
3884 1.1 joerg return 0;
3885 1.1 joerg }
3886 1.1 joerg
3887 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3888 1.1 joerg inline
3889 1.1 joerg int
3890 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
3891 1.1 joerg {
3892 1.1 joerg return compare(__self_view(__str));
3893 1.1 joerg }
3894 1.1 joerg
3895 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3896 1.1 joerg int
3897 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3898 1.1 joerg size_type __n1,
3899 1.1 joerg const value_type* __s,
3900 1.1 joerg size_type __n2) const
3901 1.1 joerg {
3902 1.1 joerg _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
3903 1.1 joerg size_type __sz = size();
3904 1.1 joerg if (__pos1 > __sz || __n2 == npos)
3905 1.1 joerg this->__throw_out_of_range();
3906 1.1 joerg size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3907 1.1 joerg int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
3908 1.1 joerg if (__r == 0)
3909 1.1 joerg {
3910 1.1 joerg if (__rlen < __n2)
3911 1.1 joerg __r = -1;
3912 1.1 joerg else if (__rlen > __n2)
3913 1.1 joerg __r = 1;
3914 1.1 joerg }
3915 1.1 joerg return __r;
3916 1.1 joerg }
3917 1.1 joerg
3918 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3919 1.1 joerg template <class _Tp>
3920 1.1 joerg _EnableIf
3921 1.1 joerg <
3922 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3923 1.1 joerg int
3924 1.1 joerg >
3925 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3926 1.1 joerg size_type __n1,
3927 1.1 joerg const _Tp& __t) const
3928 1.1 joerg {
3929 1.1 joerg __self_view __sv = __t;
3930 1.1 joerg return compare(__pos1, __n1, __sv.data(), __sv.size());
3931 1.1 joerg }
3932 1.1 joerg
3933 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3934 1.1 joerg inline
3935 1.1 joerg int
3936 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3937 1.1 joerg size_type __n1,
3938 1.1 joerg const basic_string& __str) const
3939 1.1 joerg {
3940 1.1 joerg return compare(__pos1, __n1, __str.data(), __str.size());
3941 1.1 joerg }
3942 1.1 joerg
3943 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3944 1.1 joerg template <class _Tp>
3945 1.1 joerg _EnableIf
3946 1.1 joerg <
3947 1.1 joerg __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
3948 1.1 joerg && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
3949 1.1 joerg int
3950 1.1 joerg >
3951 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3952 1.1 joerg size_type __n1,
3953 1.1 joerg const _Tp& __t,
3954 1.1 joerg size_type __pos2,
3955 1.1 joerg size_type __n2) const
3956 1.1 joerg {
3957 1.1 joerg __self_view __sv = __t;
3958 1.1 joerg return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3959 1.1 joerg }
3960 1.1 joerg
3961 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3962 1.1 joerg int
3963 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3964 1.1 joerg size_type __n1,
3965 1.1 joerg const basic_string& __str,
3966 1.1 joerg size_type __pos2,
3967 1.1 joerg size_type __n2) const
3968 1.1 joerg {
3969 1.1 joerg return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3970 1.1 joerg }
3971 1.1 joerg
3972 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3973 1.1 joerg int
3974 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3975 1.1 joerg {
3976 1.1 joerg _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3977 1.1 joerg return compare(0, npos, __s, traits_type::length(__s));
3978 1.1 joerg }
3979 1.1 joerg
3980 1.1 joerg template <class _CharT, class _Traits, class _Allocator>
3981 1.1 joerg int
3982 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3983 1.1 joerg size_type __n1,
3984 1.1 joerg const value_type* __s) const
3985 1.1 joerg {
3986 1.1 joerg _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3987 1.1 joerg return compare(__pos1, __n1, __s, traits_type::length(__s));
3988 1.1 joerg }
3989 1.1 joerg
3990 1.1 joerg // __invariants
3991 1.1 joerg
3992 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
3993 1.1 joerg inline
3994 1.1 joerg bool
3995 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3996 1.1 joerg {
3997 1.1 joerg if (size() > capacity())
3998 1.1 joerg return false;
3999 1.1 joerg if (capacity() < __min_cap - 1)
4000 1.1 joerg return false;
4001 1.1 joerg if (data() == nullptr)
4002 1.1 joerg return false;
4003 1.1 joerg if (data()[size()] != value_type())
4004 1.1 joerg return false;
4005 1.1 joerg return true;
4006 1.1 joerg }
4007 1.1 joerg
4008 1.1 joerg // __clear_and_shrink
4009 1.1 joerg
4010 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4011 1.1 joerg inline
4012 1.1 joerg void
4013 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
4014 1.1 joerg {
4015 1.1 joerg clear();
4016 1.1 joerg if(__is_long())
4017 1.1 joerg {
4018 1.1 joerg __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
4019 1.1 joerg __set_long_cap(0);
4020 1.1 joerg __set_short_size(0);
4021 1.1 joerg traits_type::assign(*__get_short_pointer(), value_type());
4022 1.1 joerg }
4023 1.1 joerg }
4024 1.1 joerg
4025 1.1 joerg // operator==
4026 1.1 joerg
4027 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4028 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4029 1.1 joerg bool
4030 1.1 joerg operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4031 1.1 joerg const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
4032 1.1 joerg {
4033 1.1 joerg size_t __lhs_sz = __lhs.size();
4034 1.1 joerg return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
4035 1.1 joerg __rhs.data(),
4036 1.1 joerg __lhs_sz) == 0;
4037 1.1 joerg }
4038 1.1 joerg
4039 1.1 joerg template<class _Allocator>
4040 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4041 1.1 joerg bool
4042 1.1 joerg operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
4043 1.1 joerg const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
4044 1.1 joerg {
4045 1.1 joerg size_t __lhs_sz = __lhs.size();
4046 1.1 joerg if (__lhs_sz != __rhs.size())
4047 1.1 joerg return false;
4048 1.1 joerg const char* __lp = __lhs.data();
4049 1.1 joerg const char* __rp = __rhs.data();
4050 1.1 joerg if (__lhs.__is_long())
4051 1.1 joerg return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
4052 1.1 joerg for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
4053 1.1 joerg if (*__lp != *__rp)
4054 1.1 joerg return false;
4055 1.1 joerg return true;
4056 1.1 joerg }
4057 1.1 joerg
4058 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4059 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4060 1.1 joerg bool
4061 1.1 joerg operator==(const _CharT* __lhs,
4062 1.1 joerg const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
4063 1.1 joerg {
4064 1.1 joerg typedef basic_string<_CharT, _Traits, _Allocator> _String;
4065 1.1 joerg _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
4066 1.1 joerg size_t __lhs_len = _Traits::length(__lhs);
4067 1.1 joerg if (__lhs_len != __rhs.size()) return false;
4068 1.1 joerg return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
4069 1.1 joerg }
4070 1.1 joerg
4071 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4072 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4073 1.1 joerg bool
4074 1.1 joerg operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
4075 1.1 joerg const _CharT* __rhs) _NOEXCEPT
4076 1.1 joerg {
4077 1.1 joerg typedef basic_string<_CharT, _Traits, _Allocator> _String;
4078 1.1 joerg _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
4079 1.1 joerg size_t __rhs_len = _Traits::length(__rhs);
4080 1.1 joerg if (__rhs_len != __lhs.size()) return false;
4081 1.1 joerg return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
4082 1.1 joerg }
4083 1.1 joerg
4084 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4085 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4086 1.1 joerg bool
4087 1.1 joerg operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
4088 1.1 joerg const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
4089 1.1 joerg {
4090 1.1 joerg return !(__lhs == __rhs);
4091 1.1 joerg }
4092 1.1 joerg
4093 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4094 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4095 1.1 joerg bool
4096 1.1 joerg operator!=(const _CharT* __lhs,
4097 1.1 joerg const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
4098 1.1 joerg {
4099 1.1 joerg return !(__lhs == __rhs);
4100 1.1 joerg }
4101 1.1 joerg
4102 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4103 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4104 1.1 joerg bool
4105 1.1 joerg operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4106 1.1 joerg const _CharT* __rhs) _NOEXCEPT
4107 1.1 joerg {
4108 1.1 joerg return !(__lhs == __rhs);
4109 1.1 joerg }
4110 1.1 joerg
4111 1.1 joerg // operator<
4112 1.1 joerg
4113 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4114 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4115 1.1 joerg bool
4116 1.1 joerg operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4117 1.1 joerg const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
4118 1.1 joerg {
4119 1.1 joerg return __lhs.compare(__rhs) < 0;
4120 1.1 joerg }
4121 1.1 joerg
4122 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4123 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4124 1.1 joerg bool
4125 1.1 joerg operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4126 1.1 joerg const _CharT* __rhs) _NOEXCEPT
4127 1.1 joerg {
4128 1.1 joerg return __lhs.compare(__rhs) < 0;
4129 1.1 joerg }
4130 1.1 joerg
4131 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4132 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4133 1.1 joerg bool
4134 1.1 joerg operator< (const _CharT* __lhs,
4135 1.1 joerg const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
4136 1.1 joerg {
4137 1.1 joerg return __rhs.compare(__lhs) > 0;
4138 1.1 joerg }
4139 1.1 joerg
4140 1.1 joerg // operator>
4141 1.1 joerg
4142 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4143 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4144 1.1 joerg bool
4145 1.1 joerg operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4146 1.1 joerg const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
4147 1.1 joerg {
4148 1.1 joerg return __rhs < __lhs;
4149 1.1 joerg }
4150 1.1 joerg
4151 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4152 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4153 1.1 joerg bool
4154 1.1 joerg operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4155 1.1 joerg const _CharT* __rhs) _NOEXCEPT
4156 1.1 joerg {
4157 1.1 joerg return __rhs < __lhs;
4158 1.1 joerg }
4159 1.1 joerg
4160 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4161 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4162 1.1 joerg bool
4163 1.1 joerg operator> (const _CharT* __lhs,
4164 1.1 joerg const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
4165 1.1 joerg {
4166 1.1 joerg return __rhs < __lhs;
4167 1.1 joerg }
4168 1.1 joerg
4169 1.1 joerg // operator<=
4170 1.1 joerg
4171 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4172 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4173 1.1 joerg bool
4174 1.1 joerg operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4175 1.1 joerg const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
4176 1.1 joerg {
4177 1.1 joerg return !(__rhs < __lhs);
4178 1.1 joerg }
4179 1.1 joerg
4180 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4181 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4182 1.1 joerg bool
4183 1.1 joerg operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4184 1.1 joerg const _CharT* __rhs) _NOEXCEPT
4185 1.1 joerg {
4186 1.1 joerg return !(__rhs < __lhs);
4187 1.1 joerg }
4188 1.1 joerg
4189 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4190 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4191 1.1 joerg bool
4192 1.1 joerg operator<=(const _CharT* __lhs,
4193 1.1 joerg const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
4194 1.1 joerg {
4195 1.1 joerg return !(__rhs < __lhs);
4196 1.1 joerg }
4197 1.1 joerg
4198 1.1 joerg // operator>=
4199 1.1 joerg
4200 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4201 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4202 1.1 joerg bool
4203 1.1 joerg operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4204 1.1 joerg const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
4205 1.1 joerg {
4206 1.1 joerg return !(__lhs < __rhs);
4207 1.1 joerg }
4208 1.1 joerg
4209 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4210 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4211 1.1 joerg bool
4212 1.1 joerg operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4213 1.1 joerg const _CharT* __rhs) _NOEXCEPT
4214 1.1 joerg {
4215 1.1 joerg return !(__lhs < __rhs);
4216 1.1 joerg }
4217 1.1 joerg
4218 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4219 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4220 1.1 joerg bool
4221 1.1 joerg operator>=(const _CharT* __lhs,
4222 1.1 joerg const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
4223 1.1 joerg {
4224 1.1 joerg return !(__lhs < __rhs);
4225 1.1 joerg }
4226 1.1 joerg
4227 1.1 joerg // operator +
4228 1.1 joerg
4229 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4230 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
4231 1.1 joerg operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4232 1.1 joerg const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4233 1.1 joerg {
4234 1.1 joerg basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4235 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4236 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4237 1.1 joerg __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4238 1.1 joerg __r.append(__rhs.data(), __rhs_sz);
4239 1.1 joerg return __r;
4240 1.1 joerg }
4241 1.1 joerg
4242 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4243 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
4244 1.1 joerg operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4245 1.1 joerg {
4246 1.1 joerg basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4247 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4248 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4249 1.1 joerg __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4250 1.1 joerg __r.append(__rhs.data(), __rhs_sz);
4251 1.1 joerg return __r;
4252 1.1 joerg }
4253 1.1 joerg
4254 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4255 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
4256 1.1 joerg operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4257 1.1 joerg {
4258 1.1 joerg basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4259 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4260 1.1 joerg __r.__init(&__lhs, 1, 1 + __rhs_sz);
4261 1.1 joerg __r.append(__rhs.data(), __rhs_sz);
4262 1.1 joerg return __r;
4263 1.1 joerg }
4264 1.1 joerg
4265 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4266 1.1 joerg inline
4267 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
4268 1.1 joerg operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4269 1.1 joerg {
4270 1.1 joerg basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4271 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4272 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4273 1.1 joerg __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4274 1.1 joerg __r.append(__rhs, __rhs_sz);
4275 1.1 joerg return __r;
4276 1.1 joerg }
4277 1.1 joerg
4278 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4279 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
4280 1.1 joerg operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4281 1.1 joerg {
4282 1.1 joerg basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4283 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4284 1.1 joerg __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4285 1.1 joerg __r.push_back(__rhs);
4286 1.1 joerg return __r;
4287 1.1 joerg }
4288 1.1 joerg
4289 1.1 joerg #ifndef _LIBCPP_CXX03_LANG
4290 1.1 joerg
4291 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4292 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4293 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
4294 1.1 joerg operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4295 1.1 joerg {
4296 1.1 joerg return _VSTD::move(__lhs.append(__rhs));
4297 1.1 joerg }
4298 1.1 joerg
4299 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4300 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4301 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
4302 1.1 joerg operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4303 1.1 joerg {
4304 1.1 joerg return _VSTD::move(__rhs.insert(0, __lhs));
4305 1.1 joerg }
4306 1.1 joerg
4307 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4308 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4309 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
4310 1.1 joerg operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4311 1.1 joerg {
4312 1.1 joerg return _VSTD::move(__lhs.append(__rhs));
4313 1.1 joerg }
4314 1.1 joerg
4315 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4316 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4317 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
4318 1.1 joerg operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4319 1.1 joerg {
4320 1.1 joerg return _VSTD::move(__rhs.insert(0, __lhs));
4321 1.1 joerg }
4322 1.1 joerg
4323 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4324 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4325 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
4326 1.1 joerg operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4327 1.1 joerg {
4328 1.1 joerg __rhs.insert(__rhs.begin(), __lhs);
4329 1.1 joerg return _VSTD::move(__rhs);
4330 1.1 joerg }
4331 1.1 joerg
4332 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4333 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4334 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
4335 1.1 joerg operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4336 1.1 joerg {
4337 1.1 joerg return _VSTD::move(__lhs.append(__rhs));
4338 1.1 joerg }
4339 1.1 joerg
4340 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4341 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4342 1.1 joerg basic_string<_CharT, _Traits, _Allocator>
4343 1.1 joerg operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4344 1.1 joerg {
4345 1.1 joerg __lhs.push_back(__rhs);
4346 1.1 joerg return _VSTD::move(__lhs);
4347 1.1 joerg }
4348 1.1 joerg
4349 1.1 joerg #endif // _LIBCPP_CXX03_LANG
4350 1.1 joerg
4351 1.1 joerg // swap
4352 1.1 joerg
4353 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4354 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4355 1.1 joerg void
4356 1.1 joerg swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
4357 1.1 joerg basic_string<_CharT, _Traits, _Allocator>& __rhs)
4358 1.1 joerg _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
4359 1.1 joerg {
4360 1.1 joerg __lhs.swap(__rhs);
4361 1.1 joerg }
4362 1.1 joerg
4363 1.1 joerg _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = nullptr, int __base = 10);
4364 1.1 joerg _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = nullptr, int __base = 10);
4365 1.1 joerg _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = nullptr, int __base = 10);
4366 1.1 joerg _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = nullptr, int __base = 10);
4367 1.1 joerg _LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = nullptr, int __base = 10);
4368 1.1 joerg
4369 1.1 joerg _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = nullptr);
4370 1.1 joerg _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = nullptr);
4371 1.1 joerg _LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = nullptr);
4372 1.1 joerg
4373 1.1 joerg _LIBCPP_FUNC_VIS string to_string(int __val);
4374 1.1 joerg _LIBCPP_FUNC_VIS string to_string(unsigned __val);
4375 1.1 joerg _LIBCPP_FUNC_VIS string to_string(long __val);
4376 1.1 joerg _LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4377 1.1 joerg _LIBCPP_FUNC_VIS string to_string(long long __val);
4378 1.1 joerg _LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4379 1.1 joerg _LIBCPP_FUNC_VIS string to_string(float __val);
4380 1.1 joerg _LIBCPP_FUNC_VIS string to_string(double __val);
4381 1.1 joerg _LIBCPP_FUNC_VIS string to_string(long double __val);
4382 1.1 joerg
4383 1.1 joerg _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4384 1.1 joerg _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4385 1.1 joerg _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4386 1.1 joerg _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4387 1.1 joerg _LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4388 1.1 joerg
4389 1.1 joerg _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = nullptr);
4390 1.1 joerg _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = nullptr);
4391 1.1 joerg _LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = nullptr);
4392 1.1 joerg
4393 1.1 joerg _LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4394 1.1 joerg _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4395 1.1 joerg _LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4396 1.1 joerg _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4397 1.1 joerg _LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4398 1.1 joerg _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4399 1.1 joerg _LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4400 1.1 joerg _LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4401 1.1 joerg _LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
4402 1.1 joerg
4403 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4404 1.1 joerg _LIBCPP_TEMPLATE_DATA_VIS
4405 1.1 joerg const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4406 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::npos;
4407 1.1 joerg
4408 1.1 joerg template <class _CharT, class _Allocator>
4409 1.1 joerg struct _LIBCPP_TEMPLATE_VIS
4410 1.1 joerg hash<basic_string<_CharT, char_traits<_CharT>, _Allocator> >
4411 1.1 joerg : public unary_function<
4412 1.1 joerg basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t>
4413 1.1 joerg {
4414 1.1 joerg size_t
4415 1.1 joerg operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT
4416 1.1 joerg { return __do_string_hash(__val.data(), __val.data() + __val.size()); }
4417 1.1 joerg };
4418 1.1 joerg
4419 1.1 joerg
4420 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4421 1.1 joerg basic_ostream<_CharT, _Traits>&
4422 1.1 joerg operator<<(basic_ostream<_CharT, _Traits>& __os,
4423 1.1 joerg const basic_string<_CharT, _Traits, _Allocator>& __str);
4424 1.1 joerg
4425 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4426 1.1 joerg basic_istream<_CharT, _Traits>&
4427 1.1 joerg operator>>(basic_istream<_CharT, _Traits>& __is,
4428 1.1 joerg basic_string<_CharT, _Traits, _Allocator>& __str);
4429 1.1 joerg
4430 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4431 1.1 joerg basic_istream<_CharT, _Traits>&
4432 1.1 joerg getline(basic_istream<_CharT, _Traits>& __is,
4433 1.1 joerg basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4434 1.1 joerg
4435 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4436 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4437 1.1 joerg basic_istream<_CharT, _Traits>&
4438 1.1 joerg getline(basic_istream<_CharT, _Traits>& __is,
4439 1.1 joerg basic_string<_CharT, _Traits, _Allocator>& __str);
4440 1.1 joerg
4441 1.1 joerg #ifndef _LIBCPP_CXX03_LANG
4442 1.1 joerg
4443 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4444 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4445 1.1 joerg basic_istream<_CharT, _Traits>&
4446 1.1 joerg getline(basic_istream<_CharT, _Traits>&& __is,
4447 1.1 joerg basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4448 1.1 joerg
4449 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4450 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4451 1.1 joerg basic_istream<_CharT, _Traits>&
4452 1.1 joerg getline(basic_istream<_CharT, _Traits>&& __is,
4453 1.1 joerg basic_string<_CharT, _Traits, _Allocator>& __str);
4454 1.1 joerg
4455 1.1 joerg #endif // _LIBCPP_CXX03_LANG
4456 1.1 joerg
4457 1.1 joerg #if _LIBCPP_STD_VER > 17
4458 1.1 joerg template <class _CharT, class _Traits, class _Allocator, class _Up>
4459 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4460 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
4461 1.1 joerg erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) {
4462 1.1 joerg auto __old_size = __str.size();
4463 1.1 joerg __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end());
4464 1.1 joerg return __old_size - __str.size();
4465 1.1 joerg }
4466 1.1 joerg
4467 1.1 joerg template <class _CharT, class _Traits, class _Allocator, class _Predicate>
4468 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4469 1.1 joerg typename basic_string<_CharT, _Traits, _Allocator>::size_type
4470 1.1 joerg erase_if(basic_string<_CharT, _Traits, _Allocator>& __str,
4471 1.1 joerg _Predicate __pred) {
4472 1.1 joerg auto __old_size = __str.size();
4473 1.1 joerg __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred),
4474 1.1 joerg __str.end());
4475 1.1 joerg return __old_size - __str.size();
4476 1.1 joerg }
4477 1.1 joerg #endif
4478 1.1 joerg
4479 1.1 joerg #if _LIBCPP_DEBUG_LEVEL == 2
4480 1.1 joerg
4481 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4482 1.1 joerg bool
4483 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4484 1.1 joerg {
4485 1.1 joerg return this->data() <= _VSTD::__to_address(__i->base()) &&
4486 1.1 joerg _VSTD::__to_address(__i->base()) < this->data() + this->size();
4487 1.1 joerg }
4488 1.1 joerg
4489 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4490 1.1 joerg bool
4491 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4492 1.1 joerg {
4493 1.1 joerg return this->data() < _VSTD::__to_address(__i->base()) &&
4494 1.1 joerg _VSTD::__to_address(__i->base()) <= this->data() + this->size();
4495 1.1 joerg }
4496 1.1 joerg
4497 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4498 1.1 joerg bool
4499 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4500 1.1 joerg {
4501 1.1 joerg const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
4502 1.1 joerg return this->data() <= __p && __p <= this->data() + this->size();
4503 1.1 joerg }
4504 1.1 joerg
4505 1.1 joerg template<class _CharT, class _Traits, class _Allocator>
4506 1.1 joerg bool
4507 1.1 joerg basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4508 1.1 joerg {
4509 1.1 joerg const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
4510 1.1 joerg return this->data() <= __p && __p < this->data() + this->size();
4511 1.1 joerg }
4512 1.1 joerg
4513 1.1 joerg #endif // _LIBCPP_DEBUG_LEVEL == 2
4514 1.1 joerg
4515 1.1 joerg #if _LIBCPP_STD_VER > 11
4516 1.1 joerg // Literal suffixes for basic_string [basic.string.literals]
4517 1.1 joerg inline namespace literals
4518 1.1 joerg {
4519 1.1 joerg inline namespace string_literals
4520 1.1 joerg {
4521 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4522 1.1 joerg basic_string<char> operator "" s( const char *__str, size_t __len )
4523 1.1 joerg {
4524 1.1 joerg return basic_string<char> (__str, __len);
4525 1.1 joerg }
4526 1.1 joerg
4527 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4528 1.1 joerg basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4529 1.1 joerg {
4530 1.1 joerg return basic_string<wchar_t> (__str, __len);
4531 1.1 joerg }
4532 1.1 joerg
4533 1.1 joerg #ifndef _LIBCPP_HAS_NO_CHAR8_T
4534 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4535 1.1 joerg basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPT
4536 1.1 joerg {
4537 1.1 joerg return basic_string<char8_t> (__str, __len);
4538 1.1 joerg }
4539 1.1 joerg #endif
4540 1.1 joerg
4541 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4542 1.1 joerg basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4543 1.1 joerg {
4544 1.1 joerg return basic_string<char16_t> (__str, __len);
4545 1.1 joerg }
4546 1.1 joerg
4547 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY
4548 1.1 joerg basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4549 1.1 joerg {
4550 1.1 joerg return basic_string<char32_t> (__str, __len);
4551 1.1 joerg }
4552 1.1 joerg }
4553 1.1 joerg }
4554 1.1 joerg #endif
4555 1.1 joerg
4556 1.1 joerg _LIBCPP_END_NAMESPACE_STD
4557 1.1 joerg
4558 1.1 joerg _LIBCPP_POP_MACROS
4559 1.1 joerg
4560 1.1 joerg #endif // _LIBCPP_STRING
4561