blob: 8a0ac844470ce12000be64674fba8acd7a7f64c9 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- string -----------------------------------===//
3//
Chandler Carruth7642bb12019-01-19 08:50:56 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_STRING
11#define _LIBCPP_STRING
12
13/*
14 string synopsis
15
16namespace std
17{
18
19template <class stateT>
20class fpos
21{
22private:
23 stateT st;
24public:
25 fpos(streamoff = streamoff());
26
27 operator streamoff() const;
28
29 stateT state() const;
30 void state(stateT);
31
32 fpos& operator+=(streamoff);
33 fpos operator+ (streamoff) const;
34 fpos& operator-=(streamoff);
35 fpos operator- (streamoff) const;
36};
37
38template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
39
40template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
41template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
42
43template <class charT>
44struct char_traits
45{
46 typedef charT char_type;
47 typedef ... int_type;
48 typedef streamoff off_type;
49 typedef streampos pos_type;
50 typedef mbstate_t state_type;
51
Howard Hinnantaeb17d82011-05-29 19:57:12 +000052 static void assign(char_type& c1, const char_type& c2) noexcept;
Howard Hinnant270c00e2012-07-20 19:09:12 +000053 static constexpr bool eq(char_type c1, char_type c2) noexcept;
54 static constexpr bool lt(char_type c1, char_type c2) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000055
56 static int compare(const char_type* s1, const char_type* s2, size_t n);
57 static size_t length(const char_type* s);
58 static const char_type* find(const char_type* s, size_t n, const char_type& a);
59 static char_type* move(char_type* s1, const char_type* s2, size_t n);
60 static char_type* copy(char_type* s1, const char_type* s2, size_t n);
61 static char_type* assign(char_type* s, size_t n, char_type a);
62
Howard Hinnant270c00e2012-07-20 19:09:12 +000063 static constexpr int_type not_eof(int_type c) noexcept;
64 static constexpr char_type to_char_type(int_type c) noexcept;
65 static constexpr int_type to_int_type(char_type c) noexcept;
66 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
67 static constexpr int_type eof() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000068};
69
70template <> struct char_traits<char>;
71template <> struct char_traits<wchar_t>;
72
Howard Hinnant3b6579a2010-08-22 00:02:43 +000073template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
Howard Hinnantc51e1022010-05-11 19:42:16 +000074class basic_string
75{
Howard Hinnant3b6579a2010-08-22 00:02:43 +000076public:
77// types:
Howard Hinnantc51e1022010-05-11 19:42:16 +000078 typedef traits traits_type;
79 typedef typename traits_type::char_type value_type;
80 typedef Allocator allocator_type;
81 typedef typename allocator_type::size_type size_type;
82 typedef typename allocator_type::difference_type difference_type;
83 typedef typename allocator_type::reference reference;
84 typedef typename allocator_type::const_reference const_reference;
85 typedef typename allocator_type::pointer pointer;
86 typedef typename allocator_type::const_pointer const_pointer;
87 typedef implementation-defined iterator;
88 typedef implementation-defined const_iterator;
89 typedef std::reverse_iterator<iterator> reverse_iterator;
90 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
91
92 static const size_type npos = -1;
93
Howard Hinnant3e276872011-06-03 18:40:47 +000094 basic_string()
95 noexcept(is_nothrow_default_constructible<allocator_type>::value);
96 explicit basic_string(const allocator_type& a);
Howard Hinnantc51e1022010-05-11 19:42:16 +000097 basic_string(const basic_string& str);
Howard Hinnant3e276872011-06-03 18:40:47 +000098 basic_string(basic_string&& str)
99 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow83445802016-04-07 18:13:41 +0000100 basic_string(const basic_string& str, size_type pos,
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000101 const allocator_type& a = allocator_type());
Marshall Clow83445802016-04-07 18:13:41 +0000102 basic_string(const basic_string& str, size_type pos, size_type n,
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000103 const Allocator& a = Allocator());
Marshall Clow78dbe462016-11-14 18:22:19 +0000104 template<class T>
105 basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
Marshall Clowe46031a2018-07-02 18:41:15 +0000106 template <class T>
107 explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17
Howard Hinnantd17880b2013-06-28 16:59:19 +0000108 basic_string(const value_type* s, const allocator_type& a = allocator_type());
109 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000110 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
111 template<class InputIterator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000112 basic_string(InputIterator begin, InputIterator end,
113 const allocator_type& a = allocator_type());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000114 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
115 basic_string(const basic_string&, const Allocator&);
116 basic_string(basic_string&&, const Allocator&);
117
118 ~basic_string();
119
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000120 operator basic_string_view<charT, traits>() const noexcept;
121
Howard Hinnantc51e1022010-05-11 19:42:16 +0000122 basic_string& operator=(const basic_string& str);
Marshall Clowe46031a2018-07-02 18:41:15 +0000123 template <class T>
124 basic_string& operator=(const T& t); // C++17
Howard Hinnant3e276872011-06-03 18:40:47 +0000125 basic_string& operator=(basic_string&& str)
126 noexcept(
Marshall Clow2fe8a8d2015-08-18 18:57:00 +0000127 allocator_type::propagate_on_container_move_assignment::value ||
128 allocator_type::is_always_equal::value ); // C++17
Howard Hinnantd17880b2013-06-28 16:59:19 +0000129 basic_string& operator=(const value_type* s);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000130 basic_string& operator=(value_type c);
131 basic_string& operator=(initializer_list<value_type>);
132
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000133 iterator begin() noexcept;
134 const_iterator begin() const noexcept;
135 iterator end() noexcept;
136 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000137
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000138 reverse_iterator rbegin() noexcept;
139 const_reverse_iterator rbegin() const noexcept;
140 reverse_iterator rend() noexcept;
141 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000142
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000143 const_iterator cbegin() const noexcept;
144 const_iterator cend() const noexcept;
145 const_reverse_iterator crbegin() const noexcept;
146 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000147
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000148 size_type size() const noexcept;
149 size_type length() const noexcept;
150 size_type max_size() const noexcept;
151 size_type capacity() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000152
153 void resize(size_type n, value_type c);
154 void resize(size_type n);
155
156 void reserve(size_type res_arg = 0);
157 void shrink_to_fit();
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000158 void clear() noexcept;
159 bool empty() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000160
161 const_reference operator[](size_type pos) const;
162 reference operator[](size_type pos);
163
164 const_reference at(size_type n) const;
165 reference at(size_type n);
166
167 basic_string& operator+=(const basic_string& str);
Marshall Clowe46031a2018-07-02 18:41:15 +0000168 template <class T>
169 basic_string& operator+=(const T& t); // C++17
Howard Hinnantd17880b2013-06-28 16:59:19 +0000170 basic_string& operator+=(const value_type* s);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000171 basic_string& operator+=(value_type c);
172 basic_string& operator+=(initializer_list<value_type>);
173
174 basic_string& append(const basic_string& str);
Marshall Clowe46031a2018-07-02 18:41:15 +0000175 template <class T>
176 basic_string& append(const T& t); // C++17
Marshall Clow8db7fb02014-03-04 19:17:19 +0000177 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
Marshall Clow82513342016-09-24 22:45:42 +0000178 template <class T>
179 basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnantd17880b2013-06-28 16:59:19 +0000180 basic_string& append(const value_type* s, size_type n);
181 basic_string& append(const value_type* s);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182 basic_string& append(size_type n, value_type c);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000183 template<class InputIterator>
184 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185 basic_string& append(initializer_list<value_type>);
186
187 void push_back(value_type c);
188 void pop_back();
189 reference front();
190 const_reference front() const;
191 reference back();
192 const_reference back() const;
193
194 basic_string& assign(const basic_string& str);
Marshall Clowe46031a2018-07-02 18:41:15 +0000195 template <class T>
196 basic_string& assign(const T& t); // C++17
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000197 basic_string& assign(basic_string&& str);
Marshall Clow8db7fb02014-03-04 19:17:19 +0000198 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
Marshall Clow82513342016-09-24 22:45:42 +0000199 template <class T>
200 basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnantd17880b2013-06-28 16:59:19 +0000201 basic_string& assign(const value_type* s, size_type n);
202 basic_string& assign(const value_type* s);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000203 basic_string& assign(size_type n, value_type c);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000204 template<class InputIterator>
205 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000206 basic_string& assign(initializer_list<value_type>);
207
208 basic_string& insert(size_type pos1, const basic_string& str);
Marshall Clowe46031a2018-07-02 18:41:15 +0000209 template <class T>
210 basic_string& insert(size_type pos1, const T& t);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000211 basic_string& insert(size_type pos1, const basic_string& str,
212 size_type pos2, size_type n);
Marshall Clow82513342016-09-24 22:45:42 +0000213 template <class T>
214 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
Marshall Clow8db7fb02014-03-04 19:17:19 +0000215 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
Howard Hinnantd17880b2013-06-28 16:59:19 +0000216 basic_string& insert(size_type pos, const value_type* s);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000217 basic_string& insert(size_type pos, size_type n, value_type c);
218 iterator insert(const_iterator p, value_type c);
219 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000220 template<class InputIterator>
221 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000222 iterator insert(const_iterator p, initializer_list<value_type>);
223
224 basic_string& erase(size_type pos = 0, size_type n = npos);
225 iterator erase(const_iterator position);
226 iterator erase(const_iterator first, const_iterator last);
227
228 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Marshall Clowe46031a2018-07-02 18:41:15 +0000229 template <class T>
230 basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000231 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Marshall Clow8db7fb02014-03-04 19:17:19 +0000232 size_type pos2, size_type n2=npos); // C++14
Marshall Clow82513342016-09-24 22:45:42 +0000233 template <class T>
234 basic_string& replace(size_type pos1, size_type n1, const T& t,
235 size_type pos2, size_type n); // C++17
Howard Hinnantd17880b2013-06-28 16:59:19 +0000236 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
237 basic_string& replace(size_type pos, size_type n1, const value_type* s);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000238 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant990d6e82010-11-17 21:11:40 +0000239 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Marshall Clowe46031a2018-07-02 18:41:15 +0000240 template <class T>
241 basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17
Howard Hinnantd17880b2013-06-28 16:59:19 +0000242 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
243 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
Howard Hinnant990d6e82010-11-17 21:11:40 +0000244 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000245 template<class InputIterator>
Howard Hinnant990d6e82010-11-17 21:11:40 +0000246 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
247 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000248
Howard Hinnantd17880b2013-06-28 16:59:19 +0000249 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250 basic_string substr(size_type pos = 0, size_type n = npos) const;
251
Howard Hinnant3e276872011-06-03 18:40:47 +0000252 void swap(basic_string& str)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000253 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
254 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000255
Howard Hinnantd17880b2013-06-28 16:59:19 +0000256 const value_type* c_str() const noexcept;
257 const value_type* data() const noexcept;
Marshall Clowd3c22392016-03-08 15:44:30 +0000258 value_type* data() noexcept; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000259
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000260 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000261
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000262 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clowe46031a2018-07-02 18:41:15 +0000263 template <class T>
264 size_type find(const T& t, size_type pos = 0) const; // C++17
Howard Hinnantd17880b2013-06-28 16:59:19 +0000265 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
266 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000267 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000269 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clowe46031a2018-07-02 18:41:15 +0000270 template <class T>
271 size_type rfind(const T& t, size_type pos = npos) const; // C++17
Howard Hinnantd17880b2013-06-28 16:59:19 +0000272 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
273 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000274 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000276 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clowe46031a2018-07-02 18:41:15 +0000277 template <class T>
278 size_type find_first_of(const T& t, size_type pos = 0) const; // C++17
Howard Hinnantd17880b2013-06-28 16:59:19 +0000279 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
280 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000281 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000283 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clowe46031a2018-07-02 18:41:15 +0000284 template <class T>
285 size_type find_last_of(const T& t, size_type pos = npos) const noexcept; // C++17
Howard Hinnantd17880b2013-06-28 16:59:19 +0000286 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
287 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000288 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000290 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clowe46031a2018-07-02 18:41:15 +0000291 template <class T>
292 size_type find_first_not_of(const T& t, size_type pos = 0) const; // C++17
Howard Hinnantd17880b2013-06-28 16:59:19 +0000293 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
294 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000295 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000297 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clowe46031a2018-07-02 18:41:15 +0000298 template <class T>
299 size_type find_last_not_of(const T& t, size_type pos = npos) const; // C++17
Howard Hinnantd17880b2013-06-28 16:59:19 +0000300 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
301 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000302 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000303
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000304 int compare(const basic_string& str) const noexcept;
Marshall Clowe46031a2018-07-02 18:41:15 +0000305 template <class T>
306 int compare(const T& t) const noexcept; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000307 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Marshall Clowe46031a2018-07-02 18:41:15 +0000308 template <class T>
309 int compare(size_type pos1, size_type n1, const T& t) const; // C++17
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000310 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clow8db7fb02014-03-04 19:17:19 +0000311 size_type pos2, size_type n2=npos) const; // C++14
Marshall Clow82513342016-09-24 22:45:42 +0000312 template <class T>
313 int compare(size_type pos1, size_type n1, const T& t,
314 size_type pos2, size_type n2=npos) const; // C++17
Howard Hinnantd17880b2013-06-28 16:59:19 +0000315 int compare(const value_type* s) const noexcept;
316 int compare(size_type pos1, size_type n1, const value_type* s) const;
317 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000318
Marshall Clow18c293b2017-12-04 20:11:38 +0000319 bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
320 bool starts_with(charT c) const noexcept; // C++2a
321 bool starts_with(const charT* s) const; // C++2a
322 bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
323 bool ends_with(charT c) const noexcept; // C++2a
324 bool ends_with(const charT* s) const; // C++2a
325
Howard Hinnantc51e1022010-05-11 19:42:16 +0000326 bool __invariants() const;
327};
328
Marshall Clowa0563332018-02-08 06:34:03 +0000329template<class InputIterator,
330 class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
331basic_string(InputIterator, InputIterator, Allocator = Allocator())
332 -> basic_string<typename iterator_traits<InputIterator>::value_type,
333 char_traits<typename iterator_traits<InputIterator>::value_type>,
334 Allocator>; // C++17
335
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336template<class charT, class traits, class Allocator>
337basic_string<charT, traits, Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000338operator+(const basic_string<charT, traits, Allocator>& lhs,
339 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000340
341template<class charT, class traits, class Allocator>
342basic_string<charT, traits, Allocator>
343operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
344
345template<class charT, class traits, class Allocator>
346basic_string<charT, traits, Allocator>
347operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
348
349template<class charT, class traits, class Allocator>
350basic_string<charT, traits, Allocator>
351operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
352
353template<class charT, class traits, class Allocator>
354basic_string<charT, traits, Allocator>
355operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
356
357template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000358bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000359 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360
361template<class charT, class traits, class Allocator>
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000362bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000363
364template<class charT, class traits, class Allocator>
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000365bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000367template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000368bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000369 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370
371template<class charT, class traits, class Allocator>
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000372bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000373
374template<class charT, class traits, class Allocator>
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000375bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000376
377template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000378bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000379 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000380
381template<class charT, class traits, class Allocator>
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000382bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000383
384template<class charT, class traits, class Allocator>
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000385bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000386
387template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000388bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000389 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000390
391template<class charT, class traits, class Allocator>
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000392bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000393
394template<class charT, class traits, class Allocator>
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000395bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000396
397template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000398bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000399 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000400
401template<class charT, class traits, class Allocator>
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000402bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000403
404template<class charT, class traits, class Allocator>
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000405bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000406
407template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000408bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000409 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000410
411template<class charT, class traits, class Allocator>
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000412bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413
414template<class charT, class traits, class Allocator>
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000415bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416
417template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000418void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant3e276872011-06-03 18:40:47 +0000419 basic_string<charT, traits, Allocator>& rhs)
420 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000421
422template<class charT, class traits, class Allocator>
423basic_istream<charT, traits>&
424operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
425
426template<class charT, class traits, class Allocator>
427basic_ostream<charT, traits>&
428operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
429
430template<class charT, class traits, class Allocator>
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000431basic_istream<charT, traits>&
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000432getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
433 charT delim);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434
435template<class charT, class traits, class Allocator>
436basic_istream<charT, traits>&
437getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
438
Marshall Clow29b53f22018-12-14 18:49:35 +0000439template<class charT, class traits, class Allocator, class U>
440void erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20
441template<class charT, class traits, class Allocator, class Predicate>
442void erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20
443
Howard Hinnantc51e1022010-05-11 19:42:16 +0000444typedef basic_string<char> string;
445typedef basic_string<wchar_t> wstring;
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000446typedef basic_string<char16_t> u16string;
447typedef basic_string<char32_t> u32string;
448
449int stoi (const string& str, size_t* idx = 0, int base = 10);
450long stol (const string& str, size_t* idx = 0, int base = 10);
451unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
452long long stoll (const string& str, size_t* idx = 0, int base = 10);
453unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
454
455float stof (const string& str, size_t* idx = 0);
456double stod (const string& str, size_t* idx = 0);
457long double stold(const string& str, size_t* idx = 0);
458
459string to_string(int val);
460string to_string(unsigned val);
461string to_string(long val);
462string to_string(unsigned long val);
463string to_string(long long val);
464string to_string(unsigned long long val);
465string to_string(float val);
466string to_string(double val);
467string to_string(long double val);
468
469int stoi (const wstring& str, size_t* idx = 0, int base = 10);
470long stol (const wstring& str, size_t* idx = 0, int base = 10);
471unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
472long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
473unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
474
475float stof (const wstring& str, size_t* idx = 0);
476double stod (const wstring& str, size_t* idx = 0);
477long double stold(const wstring& str, size_t* idx = 0);
478
479wstring to_wstring(int val);
480wstring to_wstring(unsigned val);
481wstring to_wstring(long val);
482wstring to_wstring(unsigned long val);
483wstring to_wstring(long long val);
484wstring to_wstring(unsigned long long val);
485wstring to_wstring(float val);
486wstring to_wstring(double val);
487wstring to_wstring(long double val);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488
489template <> struct hash<string>;
490template <> struct hash<u16string>;
491template <> struct hash<u32string>;
492template <> struct hash<wstring>;
493
Marshall Clowcba751f2013-07-23 17:05:24 +0000494basic_string<char> operator "" s( const char *str, size_t len ); // C++14
495basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
496basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
497basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
498
Howard Hinnantc51e1022010-05-11 19:42:16 +0000499} // std
500
501*/
502
503#include <__config>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000504#include <string_view>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505#include <iosfwd>
506#include <cstring>
Howard Hinnant155c2af2010-05-24 17:49:41 +0000507#include <cstdio> // For EOF.
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508#include <cwchar>
509#include <algorithm>
510#include <iterator>
511#include <utility>
512#include <memory>
513#include <stdexcept>
514#include <type_traits>
515#include <initializer_list>
516#include <__functional_base>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000517#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
519#include <cstdint>
520#endif
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000521
Eric Fiselier14b6de92014-08-10 23:53:08 +0000522#include <__debug>
523
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000524#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000525#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000526#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000527
Eric Fiselierf4433a32017-05-31 22:07:49 +0000528_LIBCPP_PUSH_MACROS
529#include <__undef_macros>
530
531
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532_LIBCPP_BEGIN_NAMESPACE_STD
533
534// fpos
535
536template <class _StateT>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000537class _LIBCPP_TEMPLATE_VIS fpos
Howard Hinnantc51e1022010-05-11 19:42:16 +0000538{
539private:
540 _StateT __st_;
541 streamoff __off_;
542public:
543 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
544
545 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
546
547 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
548 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
549
550 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
551 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
552 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
553 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
554};
555
556template <class _StateT>
557inline _LIBCPP_INLINE_VISIBILITY
558streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
559 {return streamoff(__x) - streamoff(__y);}
560
561template <class _StateT>
562inline _LIBCPP_INLINE_VISIBILITY
563bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
564 {return streamoff(__x) == streamoff(__y);}
565
566template <class _StateT>
567inline _LIBCPP_INLINE_VISIBILITY
568bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
569 {return streamoff(__x) != streamoff(__y);}
570
Howard Hinnantc51e1022010-05-11 19:42:16 +0000571// basic_string
572
573template<class _CharT, class _Traits, class _Allocator>
574basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant944510a2011-06-14 19:58:17 +0000575operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
576 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577
578template<class _CharT, class _Traits, class _Allocator>
579basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant944510a2011-06-14 19:58:17 +0000580operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000581
582template<class _CharT, class _Traits, class _Allocator>
583basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant944510a2011-06-14 19:58:17 +0000584operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000585
586template<class _CharT, class _Traits, class _Allocator>
Louis Dionne8f8d95d2018-11-21 17:31:55 +0000587inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant944510a2011-06-14 19:58:17 +0000589operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590
591template<class _CharT, class _Traits, class _Allocator>
592basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant944510a2011-06-14 19:58:17 +0000593operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594
Shoaib Meenaiea363712017-07-29 02:54:41 +0000595_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
596
Howard Hinnantc51e1022010-05-11 19:42:16 +0000597template <bool>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000598class _LIBCPP_TEMPLATE_VIS __basic_string_common
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599{
600protected:
Marshall Clow8fea1612016-08-25 15:09:01 +0000601 _LIBCPP_NORETURN void __throw_length_error() const;
602 _LIBCPP_NORETURN void __throw_out_of_range() const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000603};
604
605template <bool __b>
606void
607__basic_string_common<__b>::__throw_length_error() const
608{
Marshall Clow8fea1612016-08-25 15:09:01 +0000609 _VSTD::__throw_length_error("basic_string");
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610}
611
612template <bool __b>
613void
614__basic_string_common<__b>::__throw_out_of_range() const
615{
Marshall Clow8fea1612016-08-25 15:09:01 +0000616 _VSTD::__throw_out_of_range("basic_string");
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617}
618
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000619_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000620
Marshall Clow039b2f02016-01-13 21:54:34 +0000621#ifdef _LIBCPP_NO_EXCEPTIONS
622template <class _Iter>
623struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
624#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
625template <class _Iter>
626struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
627#else
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500628template <class _Iter, bool = __is_cpp17_forward_iterator<_Iter>::value>
Marshall Clow039b2f02016-01-13 21:54:34 +0000629struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
Louis Dionne173f29e2019-05-29 16:01:36 +0000630 noexcept(++(declval<_Iter&>())) &&
631 is_nothrow_assignable<_Iter&, _Iter>::value &&
632 noexcept(declval<_Iter>() == declval<_Iter>()) &&
Marshall Clow039b2f02016-01-13 21:54:34 +0000633 noexcept(*declval<_Iter>())
634)) {};
635
Louis Dionne173f29e2019-05-29 16:01:36 +0000636template <class _Iter>
Marshall Clow039b2f02016-01-13 21:54:34 +0000637struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
638#endif
639
640
641template <class _Iter>
642struct __libcpp_string_gets_noexcept_iterator
643 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
644
Marshall Clow82513342016-09-24 22:45:42 +0000645template <class _CharT, class _Traits, class _Tp>
646struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
Marshall Clowb7db4972017-11-15 20:02:27 +0000647 ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
Marshall Clow82513342016-09-24 22:45:42 +0000648 !is_convertible<const _Tp&, const _CharT*>::value)) {};
649
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000650#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +0000651
652template <class _CharT, size_t = sizeof(_CharT)>
653struct __padding
654{
655 unsigned char __xx[sizeof(_CharT)-1];
656};
657
658template <class _CharT>
659struct __padding<_CharT, 1>
660{
661};
662
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000663#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +0000664
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000665template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000666class _LIBCPP_TEMPLATE_VIS basic_string
Howard Hinnantc51e1022010-05-11 19:42:16 +0000667 : private __basic_string_common<true>
668{
669public:
670 typedef basic_string __self;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000671 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672 typedef _Traits traits_type;
Marshall Clowa3a74e02017-03-15 18:41:11 +0000673 typedef _CharT value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674 typedef _Allocator allocator_type;
Howard Hinnantea8f7e12010-11-17 17:55:08 +0000675 typedef allocator_traits<allocator_type> __alloc_traits;
676 typedef typename __alloc_traits::size_type size_type;
677 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant3e276872011-06-03 18:40:47 +0000678 typedef value_type& reference;
679 typedef const value_type& const_reference;
Howard Hinnantea8f7e12010-11-17 17:55:08 +0000680 typedef typename __alloc_traits::pointer pointer;
681 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000682
Marshall Clow79f33542018-03-21 00:36:05 +0000683 static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
684 static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
685 static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
686 static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
Howard Hinnant8ea98242013-08-23 17:37:05 +0000687 "traits_type::char_type must be the same type as CharT");
Marshall Clow79f33542018-03-21 00:36:05 +0000688 static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
Howard Hinnant8ea98242013-08-23 17:37:05 +0000689 "Allocator::value_type must be same type as value_type");
Marshall Clowe46031a2018-07-02 18:41:15 +0000690
Howard Hinnant8ea98242013-08-23 17:37:05 +0000691#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692 typedef pointer iterator;
693 typedef const_pointer const_iterator;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000694#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695 typedef __wrap_iter<pointer> iterator;
696 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000697#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000698 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
699 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000700
701private:
Howard Hinnant68bf1812013-04-30 21:44:48 +0000702
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000703#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +0000704
705 struct __long
706 {
707 pointer __data_;
708 size_type __size_;
709 size_type __cap_;
710 };
711
Eric Fiseliere9cc5922017-10-17 13:16:01 +0000712#ifdef _LIBCPP_BIG_ENDIAN
Ben Craig4b6f5f12017-07-12 01:45:13 +0000713 static const size_type __short_mask = 0x01;
714 static const size_type __long_mask = 0x1ul;
Howard Hinnant68bf1812013-04-30 21:44:48 +0000715#else // _LIBCPP_BIG_ENDIAN
Ben Craig4b6f5f12017-07-12 01:45:13 +0000716 static const size_type __short_mask = 0x80;
717 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant68bf1812013-04-30 21:44:48 +0000718#endif // _LIBCPP_BIG_ENDIAN
719
720 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
721 (sizeof(__long) - 1)/sizeof(value_type) : 2};
722
723 struct __short
724 {
725 value_type __data_[__min_cap];
726 struct
727 : __padding<value_type>
728 {
729 unsigned char __size_;
730 };
731 };
732
733#else
734
Howard Hinnantc51e1022010-05-11 19:42:16 +0000735 struct __long
736 {
737 size_type __cap_;
738 size_type __size_;
739 pointer __data_;
740 };
741
Eric Fiseliere9cc5922017-10-17 13:16:01 +0000742#ifdef _LIBCPP_BIG_ENDIAN
Ben Craig4b6f5f12017-07-12 01:45:13 +0000743 static const size_type __short_mask = 0x80;
744 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000745#else // _LIBCPP_BIG_ENDIAN
Ben Craig4b6f5f12017-07-12 01:45:13 +0000746 static const size_type __short_mask = 0x01;
747 static const size_type __long_mask = 0x1ul;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000748#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantc51e1022010-05-11 19:42:16 +0000749
Howard Hinnantc51e1022010-05-11 19:42:16 +0000750 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
751 (sizeof(__long) - 1)/sizeof(value_type) : 2};
752
753 struct __short
754 {
755 union
756 {
757 unsigned char __size_;
Howard Hinnant49e145e2012-10-30 19:06:59 +0000758 value_type __lx;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000759 };
760 value_type __data_[__min_cap];
761 };
762
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000763#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +0000764
Howard Hinnant8ea98242013-08-23 17:37:05 +0000765 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000766
Howard Hinnant8ea98242013-08-23 17:37:05 +0000767 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000768
769 struct __raw
770 {
771 size_type __words[__n_words];
772 };
773
774 struct __rep
775 {
776 union
777 {
778 __long __l;
779 __short __s;
780 __raw __r;
781 };
782 };
783
784 __compressed_pair<__rep, allocator_type> __r_;
785
Howard Hinnantc51e1022010-05-11 19:42:16 +0000786public:
787 static const size_type npos = -1;
788
Howard Hinnant3e276872011-06-03 18:40:47 +0000789 _LIBCPP_INLINE_VISIBILITY basic_string()
790 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clowa80abc72015-06-03 19:56:43 +0000791
792 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
793#if _LIBCPP_STD_VER <= 14
794 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
795#else
796 _NOEXCEPT;
797#endif
798
Howard Hinnantc51e1022010-05-11 19:42:16 +0000799 basic_string(const basic_string& __str);
800 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clowa80abc72015-06-03 19:56:43 +0000801
Eric Fiselierfc92be82017-04-19 00:28:44 +0000802#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantebb0edf2011-01-26 00:06:59 +0000803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e276872011-06-03 18:40:47 +0000804 basic_string(basic_string&& __str)
Marshall Clowa80abc72015-06-03 19:56:43 +0000805#if _LIBCPP_STD_VER <= 14
Howard Hinnant3e276872011-06-03 18:40:47 +0000806 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clowa80abc72015-06-03 19:56:43 +0000807#else
808 _NOEXCEPT;
809#endif
810
Howard Hinnantebb0edf2011-01-26 00:06:59 +0000811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000812 basic_string(basic_string&& __str, const allocator_type& __a);
Eric Fiselierfc92be82017-04-19 00:28:44 +0000813#endif // _LIBCPP_CXX03_LANG
Marshall Clowe46031a2018-07-02 18:41:15 +0000814
815 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
Eric Fiseliera8567862018-07-17 05:48:48 +0000816 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5169d1c2019-12-16 19:03:23 -0500817 basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) {
Eric Fiseliera8567862018-07-17 05:48:48 +0000818 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
819 __init(__s, traits_type::length(__s));
820# if _LIBCPP_DEBUG_LEVEL >= 2
821 __get_db()->__insert_c(this);
822# endif
823 }
Marshall Clowe46031a2018-07-02 18:41:15 +0000824
825 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
826 _LIBCPP_INLINE_VISIBILITY
827 basic_string(const _CharT* __s, const _Allocator& __a);
828
Howard Hinnantcf823322010-12-17 14:46:43 +0000829 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier812882b2017-02-17 01:17:10 +0000830 basic_string(const _CharT* __s, size_type __n);
Howard Hinnantcf823322010-12-17 14:46:43 +0000831 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier812882b2017-02-17 01:17:10 +0000832 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
Howard Hinnantcf823322010-12-17 14:46:43 +0000833 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier812882b2017-02-17 01:17:10 +0000834 basic_string(size_type __n, _CharT __c);
Marshall Clowe46031a2018-07-02 18:41:15 +0000835
836 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
837 _LIBCPP_INLINE_VISIBILITY
838 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
839
Marshall Clow83445802016-04-07 18:13:41 +0000840 basic_string(const basic_string& __str, size_type __pos, size_type __n,
Eric Fiselier812882b2017-02-17 01:17:10 +0000841 const _Allocator& __a = _Allocator());
Marshall Clow83445802016-04-07 18:13:41 +0000842 _LIBCPP_INLINE_VISIBILITY
843 basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier812882b2017-02-17 01:17:10 +0000844 const _Allocator& __a = _Allocator());
Marshall Clowe46031a2018-07-02 18:41:15 +0000845
846 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
Shoaib Meenai69c57412017-03-02 03:02:50 +0000847 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselier812882b2017-02-17 01:17:10 +0000848 basic_string(const _Tp& __t, size_type __pos, size_type __n,
Marshall Clowe46031a2018-07-02 18:41:15 +0000849 const allocator_type& __a = allocator_type());
850
851 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
852 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
853 explicit basic_string(const _Tp& __t);
854
855 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
856 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
857 explicit basic_string(const _Tp& __t, const allocator_type& __a);
858
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500859 template<class _InputIterator, class = typename enable_if<__is_cpp17_input_iterator<_InputIterator>::value>::type>
Howard Hinnantcf823322010-12-17 14:46:43 +0000860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000861 basic_string(_InputIterator __first, _InputIterator __last);
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500862 template<class _InputIterator, class = typename enable_if<__is_cpp17_input_iterator<_InputIterator>::value>::type>
Howard Hinnantcf823322010-12-17 14:46:43 +0000863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000864 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Eric Fiselierfc92be82017-04-19 00:28:44 +0000865#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantcf823322010-12-17 14:46:43 +0000866 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier812882b2017-02-17 01:17:10 +0000867 basic_string(initializer_list<_CharT> __il);
Howard Hinnantcf823322010-12-17 14:46:43 +0000868 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier812882b2017-02-17 01:17:10 +0000869 basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
Eric Fiselierfc92be82017-04-19 00:28:44 +0000870#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871
Eric Fiselierd9a702a2016-10-31 03:42:50 +0000872 inline ~basic_string();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000873
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000874 _LIBCPP_INLINE_VISIBILITY
875 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
876
Howard Hinnantea8f7e12010-11-17 17:55:08 +0000877 basic_string& operator=(const basic_string& __str);
Eric Fiselier5ec13b12017-01-23 21:24:58 +0000878
Marshall Clowe46031a2018-07-02 18:41:15 +0000879 template <class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
880 basic_string& operator=(const _Tp& __t)
881 {__self_view __sv = __t; return assign(__sv);}
882
Eric Fiselierfc92be82017-04-19 00:28:44 +0000883#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantcf823322010-12-17 14:46:43 +0000884 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e276872011-06-03 18:40:47 +0000885 basic_string& operator=(basic_string&& __str)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +0000886 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Eric Fiselierfc92be82017-04-19 00:28:44 +0000887 _LIBCPP_INLINE_VISIBILITY
888 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000889#endif
Howard Hinnantd17880b2013-06-28 16:59:19 +0000890 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000891 basic_string& operator=(value_type __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000892
Howard Hinnant8ea98242013-08-23 17:37:05 +0000893#if _LIBCPP_DEBUG_LEVEL >= 2
894 _LIBCPP_INLINE_VISIBILITY
895 iterator begin() _NOEXCEPT
896 {return iterator(this, __get_pointer());}
897 _LIBCPP_INLINE_VISIBILITY
898 const_iterator begin() const _NOEXCEPT
899 {return const_iterator(this, __get_pointer());}
900 _LIBCPP_INLINE_VISIBILITY
901 iterator end() _NOEXCEPT
902 {return iterator(this, __get_pointer() + size());}
903 _LIBCPP_INLINE_VISIBILITY
904 const_iterator end() const _NOEXCEPT
905 {return const_iterator(this, __get_pointer() + size());}
906#else
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000907 _LIBCPP_INLINE_VISIBILITY
908 iterator begin() _NOEXCEPT
909 {return iterator(__get_pointer());}
910 _LIBCPP_INLINE_VISIBILITY
911 const_iterator begin() const _NOEXCEPT
Howard Hinnantd17880b2013-06-28 16:59:19 +0000912 {return const_iterator(__get_pointer());}
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000913 _LIBCPP_INLINE_VISIBILITY
914 iterator end() _NOEXCEPT
915 {return iterator(__get_pointer() + size());}
916 _LIBCPP_INLINE_VISIBILITY
917 const_iterator end() const _NOEXCEPT
Howard Hinnantd17880b2013-06-28 16:59:19 +0000918 {return const_iterator(__get_pointer() + size());}
Howard Hinnant8ea98242013-08-23 17:37:05 +0000919#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000920 _LIBCPP_INLINE_VISIBILITY
921 reverse_iterator rbegin() _NOEXCEPT
922 {return reverse_iterator(end());}
923 _LIBCPP_INLINE_VISIBILITY
924 const_reverse_iterator rbegin() const _NOEXCEPT
925 {return const_reverse_iterator(end());}
926 _LIBCPP_INLINE_VISIBILITY
927 reverse_iterator rend() _NOEXCEPT
928 {return reverse_iterator(begin());}
929 _LIBCPP_INLINE_VISIBILITY
930 const_reverse_iterator rend() const _NOEXCEPT
931 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000932
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000933 _LIBCPP_INLINE_VISIBILITY
934 const_iterator cbegin() const _NOEXCEPT
935 {return begin();}
936 _LIBCPP_INLINE_VISIBILITY
937 const_iterator cend() const _NOEXCEPT
938 {return end();}
939 _LIBCPP_INLINE_VISIBILITY
940 const_reverse_iterator crbegin() const _NOEXCEPT
941 {return rbegin();}
942 _LIBCPP_INLINE_VISIBILITY
943 const_reverse_iterator crend() const _NOEXCEPT
944 {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000945
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000946 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000947 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000948 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
949 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
950 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiselier8599fcc2015-08-28 07:02:42 +0000951 {return (__is_long() ? __get_long_cap()
952 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000953
954 void resize(size_type __n, value_type __c);
955 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
956
Marshall Clow6ae12a82018-11-28 18:18:34 +0000957 void reserve(size_type __res_arg);
Eric Fiselier451d5582018-11-26 20:15:38 +0000958 _LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n);
959
Marshall Clow6ae12a82018-11-28 18:18:34 +0000960 _LIBCPP_INLINE_VISIBILITY
961 void reserve() _NOEXCEPT {reserve(0);}
Howard Hinnant186dca82010-09-23 17:31:07 +0000962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e276872011-06-03 18:40:47 +0000963 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnantcf823322010-12-17 14:46:43 +0000964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000965 void clear() _NOEXCEPT;
Marshall Clowb7db4972017-11-15 20:02:27 +0000966 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
967 bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000968
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000969 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
970 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000971
972 const_reference at(size_type __n) const;
973 reference at(size_type __n);
974
975 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clowe46031a2018-07-02 18:41:15 +0000976
977 template <class _Tp>
978 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
979 typename enable_if
980 <
981 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
982 basic_string&
983 >::type
984 operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);}
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000985 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000986 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Eric Fiselierfc92be82017-04-19 00:28:44 +0000987#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000988 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Eric Fiselierfc92be82017-04-19 00:28:44 +0000989#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000990
Howard Hinnantcf823322010-12-17 14:46:43 +0000991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992 basic_string& append(const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +0000993
994 template <class _Tp>
995 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
996 typename enable_if
997 <
998 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
999 basic_string&
1000 >::type
1001 append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
Marshall Clow8db7fb02014-03-04 19:17:19 +00001002 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clowe46031a2018-07-02 18:41:15 +00001003
Marshall Clow62953962016-10-03 23:40:48 +00001004 template <class _Tp>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001005 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1006 typename enable_if
Marshall Clow82513342016-09-24 22:45:42 +00001007 <
1008 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1009 basic_string&
1010 >::type
1011 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Howard Hinnantd17880b2013-06-28 16:59:19 +00001012 basic_string& append(const value_type* __s, size_type __n);
1013 basic_string& append(const value_type* __s);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014 basic_string& append(size_type __n, value_type __c);
Eric Fiselier451d5582018-11-26 20:15:38 +00001015
1016 _LIBCPP_INLINE_VISIBILITY
1017 void __append_default_init(size_type __n);
1018
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00001019 template <class _ForwardIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001020 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1021 basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001022 template<class _InputIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001023 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1024 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +00001025 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001026 __is_exactly_cpp17_input_iterator<_InputIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00001027 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001028 basic_string&
1029 >::type
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00001030 _LIBCPP_INLINE_VISIBILITY
1031 append(_InputIterator __first, _InputIterator __last) {
1032 const basic_string __temp (__first, __last, __alloc());
1033 append(__temp.data(), __temp.size());
1034 return *this;
1035 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001036 template<class _ForwardIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001037 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1038 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +00001039 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001040 __is_cpp17_forward_iterator<_ForwardIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00001041 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001042 basic_string&
1043 >::type
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00001044 _LIBCPP_INLINE_VISIBILITY
1045 append(_ForwardIterator __first, _ForwardIterator __last) {
1046 return __append_forward_unsafe(__first, __last);
1047 }
1048
Eric Fiselierfc92be82017-04-19 00:28:44 +00001049#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant186dca82010-09-23 17:31:07 +00001050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Eric Fiselierfc92be82017-04-19 00:28:44 +00001052#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053
1054 void push_back(value_type __c);
Howard Hinnantcf823322010-12-17 14:46:43 +00001055 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001056 void pop_back();
Marshall Clow05cf6692019-03-19 03:30:07 +00001057 _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT;
1058 _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT;
1059 _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT;
1060 _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001061
Marshall Clowe46031a2018-07-02 18:41:15 +00001062 template <class _Tp>
1063 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1064 typename enable_if
1065 <
1066 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1067 basic_string&
1068 >::type
1069 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001070 _LIBCPP_INLINE_VISIBILITY
Marshall Clow95d5e9a2016-03-09 18:08:29 +00001071 basic_string& assign(const basic_string& __str) { return *this = __str; }
Eric Fiselierfc92be82017-04-19 00:28:44 +00001072#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001073 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001074 basic_string& assign(basic_string&& __str)
Marshall Clow5aa9e942015-10-05 16:17:34 +00001075 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001076 {*this = _VSTD::move(__str); return *this;}
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001077#endif
Marshall Clow8db7fb02014-03-04 19:17:19 +00001078 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow62953962016-10-03 23:40:48 +00001079 template <class _Tp>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001080 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1081 typename enable_if
Marshall Clow82513342016-09-24 22:45:42 +00001082 <
1083 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1084 basic_string&
1085 >::type
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001086 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
Howard Hinnantd17880b2013-06-28 16:59:19 +00001087 basic_string& assign(const value_type* __s, size_type __n);
1088 basic_string& assign(const value_type* __s);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001089 basic_string& assign(size_type __n, value_type __c);
1090 template<class _InputIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001091 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1092 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +00001093 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001094 __is_exactly_cpp17_input_iterator<_InputIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00001095 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001096 basic_string&
1097 >::type
1098 assign(_InputIterator __first, _InputIterator __last);
1099 template<class _ForwardIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001100 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1101 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +00001102 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001103 __is_cpp17_forward_iterator<_ForwardIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00001104 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001105 basic_string&
1106 >::type
1107 assign(_ForwardIterator __first, _ForwardIterator __last);
Eric Fiselierfc92be82017-04-19 00:28:44 +00001108#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant186dca82010-09-23 17:31:07 +00001109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001110 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Eric Fiselierfc92be82017-04-19 00:28:44 +00001111#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001112
Howard Hinnantcf823322010-12-17 14:46:43 +00001113 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001114 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +00001115
1116 template <class _Tp>
1117 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1118 typename enable_if
1119 <
1120 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1121 basic_string&
1122 >::type
1123 insert(size_type __pos1, const _Tp& __t)
1124 { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
1125
Marshall Clow82513342016-09-24 22:45:42 +00001126 template <class _Tp>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001127 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1128 typename enable_if
Marshall Clow82513342016-09-24 22:45:42 +00001129 <
1130 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1131 basic_string&
1132 >::type
1133 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Marshall Clow8db7fb02014-03-04 19:17:19 +00001134 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnantd17880b2013-06-28 16:59:19 +00001135 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1136 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001137 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1138 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnantcf823322010-12-17 14:46:43 +00001139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1141 template<class _InputIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001142 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1143 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001145 __is_exactly_cpp17_input_iterator<_InputIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00001146 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001147 iterator
1148 >::type
1149 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1150 template<class _ForwardIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001151 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1152 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +00001153 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001154 __is_cpp17_forward_iterator<_ForwardIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00001155 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001156 iterator
1157 >::type
1158 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Eric Fiselierfc92be82017-04-19 00:28:44 +00001159#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant186dca82010-09-23 17:31:07 +00001160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001161 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1162 {return insert(__pos, __il.begin(), __il.end());}
Eric Fiselierfc92be82017-04-19 00:28:44 +00001163#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001164
1165 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnantcf823322010-12-17 14:46:43 +00001166 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001167 iterator erase(const_iterator __pos);
Howard Hinnantcf823322010-12-17 14:46:43 +00001168 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001169 iterator erase(const_iterator __first, const_iterator __last);
1170
Howard Hinnantcf823322010-12-17 14:46:43 +00001171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +00001173
1174 template <class _Tp>
1175 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1176 typename enable_if
1177 <
1178 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1179 basic_string&
1180 >::type
1181 replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); }
Marshall Clow8db7fb02014-03-04 19:17:19 +00001182 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
Marshall Clow82513342016-09-24 22:45:42 +00001183 template <class _Tp>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001184 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1185 typename enable_if
Marshall Clow82513342016-09-24 22:45:42 +00001186 <
1187 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1188 basic_string&
1189 >::type
1190 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Howard Hinnantd17880b2013-06-28 16:59:19 +00001191 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1192 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001193 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnantcf823322010-12-17 14:46:43 +00001194 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant990d6e82010-11-17 21:11:40 +00001195 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +00001196
1197 template <class _Tp>
1198 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1199 typename enable_if
1200 <
1201 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1202 basic_string&
1203 >::type
1204 replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
1205
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001206 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001207 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnantcf823322010-12-17 14:46:43 +00001208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001209 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnantcf823322010-12-17 14:46:43 +00001210 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant990d6e82010-11-17 21:11:40 +00001211 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001212 template<class _InputIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001213 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1214 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +00001215 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001216 __is_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001217 basic_string&
1218 >::type
Howard Hinnant990d6e82010-11-17 21:11:40 +00001219 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Eric Fiselierfc92be82017-04-19 00:28:44 +00001220#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant186dca82010-09-23 17:31:07 +00001221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant990d6e82010-11-17 21:11:40 +00001222 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001223 {return replace(__i1, __i2, __il.begin(), __il.end());}
Eric Fiselierfc92be82017-04-19 00:28:44 +00001224#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001225
Howard Hinnantd17880b2013-06-28 16:59:19 +00001226 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnantcf823322010-12-17 14:46:43 +00001227 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001228 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1229
Howard Hinnantcf823322010-12-17 14:46:43 +00001230 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e276872011-06-03 18:40:47 +00001231 void swap(basic_string& __str)
Marshall Clow8982dcd2015-07-13 20:04:56 +00001232#if _LIBCPP_STD_VER >= 14
Eric Fiselier873b8d32019-03-18 21:50:12 +00001233 _NOEXCEPT;
Marshall Clow8982dcd2015-07-13 20:04:56 +00001234#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001235 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow8982dcd2015-07-13 20:04:56 +00001236 __is_nothrow_swappable<allocator_type>::value);
1237#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001238
Howard Hinnantcf823322010-12-17 14:46:43 +00001239 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001240 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnantcf823322010-12-17 14:46:43 +00001241 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001242 const value_type* data() const _NOEXCEPT {return _VSTD::__to_address(__get_pointer());}
Eric Fiselier4ee2a892017-11-20 20:23:27 +00001243#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
Marshall Clowd3c22392016-03-08 15:44:30 +00001244 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001245 value_type* data() _NOEXCEPT {return _VSTD::__to_address(__get_pointer());}
Marshall Clowd3c22392016-03-08 15:44:30 +00001246#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001247
Howard Hinnantcf823322010-12-17 14:46:43 +00001248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001249 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001250
Howard Hinnantcf823322010-12-17 14:46:43 +00001251 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001252 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001253
1254 template <class _Tp>
1255 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1256 typename enable_if
1257 <
1258 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1259 size_type
1260 >::type
1261 find(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnantd17880b2013-06-28 16:59:19 +00001262 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnantcf823322010-12-17 14:46:43 +00001263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001264 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001265 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001266
Howard Hinnantcf823322010-12-17 14:46:43 +00001267 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001268 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001269
1270 template <class _Tp>
1271 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1272 typename enable_if
1273 <
1274 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1275 size_type
1276 >::type
1277 rfind(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnantd17880b2013-06-28 16:59:19 +00001278 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnantcf823322010-12-17 14:46:43 +00001279 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001280 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001281 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001282
Howard Hinnantcf823322010-12-17 14:46:43 +00001283 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001284 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001285
1286 template <class _Tp>
1287 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1288 typename enable_if
1289 <
1290 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1291 size_type
1292 >::type
1293 find_first_of(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnantd17880b2013-06-28 16:59:19 +00001294 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnantcf823322010-12-17 14:46:43 +00001295 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001296 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantcf823322010-12-17 14:46:43 +00001297 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001298 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001299
Howard Hinnantcf823322010-12-17 14:46:43 +00001300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001301 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001302
1303 template <class _Tp>
1304 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1305 typename enable_if
1306 <
1307 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1308 size_type
1309 >::type
1310 find_last_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnantd17880b2013-06-28 16:59:19 +00001311 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnantcf823322010-12-17 14:46:43 +00001312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001313 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantcf823322010-12-17 14:46:43 +00001314 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001315 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001316
Howard Hinnantcf823322010-12-17 14:46:43 +00001317 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001318 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001319
1320 template <class _Tp>
1321 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1322 typename enable_if
1323 <
1324 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1325 size_type
1326 >::type
1327 find_first_not_of(const _Tp &__t, size_type __pos = 0) const;
Howard Hinnantd17880b2013-06-28 16:59:19 +00001328 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001330 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001331 _LIBCPP_INLINE_VISIBILITY
1332 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1333
1334 _LIBCPP_INLINE_VISIBILITY
1335 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001336
1337 template <class _Tp>
1338 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1339 typename enable_if
1340 <
1341 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1342 size_type
1343 >::type
1344 find_last_not_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnantd17880b2013-06-28 16:59:19 +00001345 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001346 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001347 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001348 _LIBCPP_INLINE_VISIBILITY
1349 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1350
1351 _LIBCPP_INLINE_VISIBILITY
1352 int compare(const basic_string& __str) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001353
1354 template <class _Tp>
1355 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1356 typename enable_if
1357 <
1358 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1359 int
1360 >::type
1361 compare(const _Tp &__t) const;
1362
1363 template <class _Tp>
1364 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1365 typename enable_if
1366 <
1367 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1368 int
1369 >::type
1370 compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
1371
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001372 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001373 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clow8db7fb02014-03-04 19:17:19 +00001374 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
Marshall Clowe46031a2018-07-02 18:41:15 +00001375
Marshall Clow82513342016-09-24 22:45:42 +00001376 template <class _Tp>
Eric Fiselier7d4aa5c2016-10-14 05:29:46 +00001377 inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow82513342016-09-24 22:45:42 +00001378 typename enable_if
1379 <
1380 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1381 int
1382 >::type
1383 compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
Howard Hinnantd17880b2013-06-28 16:59:19 +00001384 int compare(const value_type* __s) const _NOEXCEPT;
1385 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1386 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001387
Marshall Clow18c293b2017-12-04 20:11:38 +00001388#if _LIBCPP_STD_VER > 17
1389 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1390 bool starts_with(__self_view __sv) const _NOEXCEPT
1391 { return __self_view(data(), size()).starts_with(__sv); }
1392
1393 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1394 bool starts_with(value_type __c) const _NOEXCEPT
1395 { return !empty() && _Traits::eq(front(), __c); }
1396
1397 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1398 bool starts_with(const value_type* __s) const _NOEXCEPT
1399 { return starts_with(__self_view(__s)); }
1400
1401 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1402 bool ends_with(__self_view __sv) const _NOEXCEPT
1403 { return __self_view(data(), size()).ends_with( __sv); }
1404
1405 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1406 bool ends_with(value_type __c) const _NOEXCEPT
1407 { return !empty() && _Traits::eq(back(), __c); }
1408
1409 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1410 bool ends_with(const value_type* __s) const _NOEXCEPT
1411 { return ends_with(__self_view(__s)); }
1412#endif
1413
Howard Hinnantcf823322010-12-17 14:46:43 +00001414 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnantaaeb1132013-04-22 23:55:13 +00001415
Marshall Clowe60a7182018-05-29 17:04:37 +00001416 _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT;
Marshall Clow851b9ec2019-05-20 21:56:51 +00001417
Howard Hinnantaaeb1132013-04-22 23:55:13 +00001418 _LIBCPP_INLINE_VISIBILITY
1419 bool __is_long() const _NOEXCEPT
1420 {return bool(__r_.first().__s.__size_ & __short_mask);}
1421
Howard Hinnant8ea98242013-08-23 17:37:05 +00001422#if _LIBCPP_DEBUG_LEVEL >= 2
1423
1424 bool __dereferenceable(const const_iterator* __i) const;
1425 bool __decrementable(const const_iterator* __i) const;
1426 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1427 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1428
1429#endif // _LIBCPP_DEBUG_LEVEL >= 2
1430
Howard Hinnantc51e1022010-05-11 19:42:16 +00001431private:
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001432 _LIBCPP_INLINE_VISIBILITY
1433 allocator_type& __alloc() _NOEXCEPT
1434 {return __r_.second();}
1435 _LIBCPP_INLINE_VISIBILITY
1436 const allocator_type& __alloc() const _NOEXCEPT
1437 {return __r_.second();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001438
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +00001439#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +00001440
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001442 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiseliere9cc5922017-10-17 13:16:01 +00001443# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant68bf1812013-04-30 21:44:48 +00001445# else
1446 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1447# endif
1448
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001449 _LIBCPP_INLINE_VISIBILITY
1450 size_type __get_short_size() const _NOEXCEPT
Eric Fiseliere9cc5922017-10-17 13:16:01 +00001451# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantc51e1022010-05-11 19:42:16 +00001452 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant68bf1812013-04-30 21:44:48 +00001453# else
1454 {return __r_.first().__s.__size_;}
1455# endif
1456
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +00001457#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +00001458
1459 _LIBCPP_INLINE_VISIBILITY
1460 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiseliere9cc5922017-10-17 13:16:01 +00001461# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant68bf1812013-04-30 21:44:48 +00001462 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1463# else
1464 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1465# endif
1466
1467 _LIBCPP_INLINE_VISIBILITY
1468 size_type __get_short_size() const _NOEXCEPT
Eric Fiseliere9cc5922017-10-17 13:16:01 +00001469# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant68bf1812013-04-30 21:44:48 +00001470 {return __r_.first().__s.__size_;}
1471# else
1472 {return __r_.first().__s.__size_ >> 1;}
1473# endif
1474
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +00001475#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +00001476
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001477 _LIBCPP_INLINE_VISIBILITY
1478 void __set_long_size(size_type __s) _NOEXCEPT
1479 {__r_.first().__l.__size_ = __s;}
1480 _LIBCPP_INLINE_VISIBILITY
1481 size_type __get_long_size() const _NOEXCEPT
1482 {return __r_.first().__l.__size_;}
1483 _LIBCPP_INLINE_VISIBILITY
1484 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001485 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1486
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001487 _LIBCPP_INLINE_VISIBILITY
1488 void __set_long_cap(size_type __s) _NOEXCEPT
1489 {__r_.first().__l.__cap_ = __long_mask | __s;}
1490 _LIBCPP_INLINE_VISIBILITY
1491 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnant28b24882011-12-01 20:21:04 +00001492 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001493
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001494 _LIBCPP_INLINE_VISIBILITY
1495 void __set_long_pointer(pointer __p) _NOEXCEPT
1496 {__r_.first().__l.__data_ = __p;}
1497 _LIBCPP_INLINE_VISIBILITY
1498 pointer __get_long_pointer() _NOEXCEPT
1499 {return __r_.first().__l.__data_;}
1500 _LIBCPP_INLINE_VISIBILITY
1501 const_pointer __get_long_pointer() const _NOEXCEPT
1502 {return __r_.first().__l.__data_;}
1503 _LIBCPP_INLINE_VISIBILITY
1504 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnantd17880b2013-06-28 16:59:19 +00001505 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001506 _LIBCPP_INLINE_VISIBILITY
1507 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnantd17880b2013-06-28 16:59:19 +00001508 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001509 _LIBCPP_INLINE_VISIBILITY
1510 pointer __get_pointer() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001511 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001512 _LIBCPP_INLINE_VISIBILITY
1513 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001514 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1515
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001516 _LIBCPP_INLINE_VISIBILITY
1517 void __zero() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001518 {
1519 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1520 for (unsigned __i = 0; __i < __n_words; ++__i)
1521 __a[__i] = 0;
1522 }
1523
1524 template <size_type __a> static
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantea382952013-08-14 18:00:20 +00001526 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiselier8599fcc2015-08-28 07:02:42 +00001527 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001528 enum {__alignment = 16};
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001529 static _LIBCPP_INLINE_VISIBILITY
1530 size_type __recommend(size_type __s) _NOEXCEPT
Marshall Clow80584522018-02-07 21:30:17 +00001531 {
1532 if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
1533 size_type __guess = __align_it<sizeof(value_type) < __alignment ?
1534 __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
1535 if (__guess == __min_cap) ++__guess;
1536 return __guess;
1537 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001538
Duncan P. N. Exon Smitheb584632017-04-01 03:20:48 +00001539 inline
Howard Hinnantd17880b2013-06-28 16:59:19 +00001540 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Duncan P. N. Exon Smitheb584632017-04-01 03:20:48 +00001541 inline
Howard Hinnantd17880b2013-06-28 16:59:19 +00001542 void __init(const value_type* __s, size_type __sz);
Duncan P. N. Exon Smitheb584632017-04-01 03:20:48 +00001543 inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001544 void __init(size_type __n, value_type __c);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001545
Howard Hinnantc51e1022010-05-11 19:42:16 +00001546 template <class _InputIterator>
Duncan P. N. Exon Smitheb584632017-04-01 03:20:48 +00001547 inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001548 typename enable_if
1549 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001550 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001551 void
1552 >::type
1553 __init(_InputIterator __first, _InputIterator __last);
1554
1555 template <class _ForwardIterator>
Duncan P. N. Exon Smitheb584632017-04-01 03:20:48 +00001556 inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001557 typename enable_if
1558 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001559 __is_cpp17_forward_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001560 void
1561 >::type
1562 __init(_ForwardIterator __first, _ForwardIterator __last);
1563
1564 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001565 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001566 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1567 size_type __n_copy, size_type __n_del,
Howard Hinnantd17880b2013-06-28 16:59:19 +00001568 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001569
Howard Hinnantcf823322010-12-17 14:46:43 +00001570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001571 void __erase_to_end(size_type __pos);
1572
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001573 _LIBCPP_INLINE_VISIBILITY
1574 void __copy_assign_alloc(const basic_string& __str)
1575 {__copy_assign_alloc(__str, integral_constant<bool,
1576 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1577
1578 _LIBCPP_INLINE_VISIBILITY
1579 void __copy_assign_alloc(const basic_string& __str, true_type)
1580 {
Marshall Clowf258c202017-01-31 03:40:52 +00001581 if (__alloc() == __str.__alloc())
1582 __alloc() = __str.__alloc();
1583 else
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001584 {
Marshall Clowf258c202017-01-31 03:40:52 +00001585 if (!__str.__is_long())
1586 {
Vedant Kumar55e007e2018-03-08 21:15:26 +00001587 __clear_and_shrink();
Marshall Clowf258c202017-01-31 03:40:52 +00001588 __alloc() = __str.__alloc();
1589 }
1590 else
1591 {
1592 allocator_type __a = __str.__alloc();
1593 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
Vedant Kumar55e007e2018-03-08 21:15:26 +00001594 __clear_and_shrink();
Marshall Clowf258c202017-01-31 03:40:52 +00001595 __alloc() = _VSTD::move(__a);
1596 __set_long_pointer(__p);
1597 __set_long_cap(__str.__get_long_cap());
1598 __set_long_size(__str.size());
1599 }
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001600 }
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001601 }
1602
1603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant28b24882011-12-01 20:21:04 +00001604 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001605 {}
1606
Eric Fiselierfc92be82017-04-19 00:28:44 +00001607#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantcf823322010-12-17 14:46:43 +00001608 _LIBCPP_INLINE_VISIBILITY
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00001609 void __move_assign(basic_string& __str, false_type)
1610 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnantcf823322010-12-17 14:46:43 +00001611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e276872011-06-03 18:40:47 +00001612 void __move_assign(basic_string& __str, true_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00001613#if _LIBCPP_STD_VER > 14
1614 _NOEXCEPT;
1615#else
Howard Hinnant3e276872011-06-03 18:40:47 +00001616 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001617#endif
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00001618#endif
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001619
1620 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001621 void
Howard Hinnantc2734962011-09-02 20:42:31 +00001622 __move_assign_alloc(basic_string& __str)
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001623 _NOEXCEPT_(
1624 !__alloc_traits::propagate_on_container_move_assignment::value ||
1625 is_nothrow_move_assignable<allocator_type>::value)
1626 {__move_assign_alloc(__str, integral_constant<bool,
1627 __alloc_traits::propagate_on_container_move_assignment::value>());}
1628
1629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc2734962011-09-02 20:42:31 +00001630 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001631 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1632 {
1633 __alloc() = _VSTD::move(__c.__alloc());
1634 }
1635
1636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant28b24882011-12-01 20:21:04 +00001637 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001638 _NOEXCEPT
1639 {}
1640
Howard Hinnantcf823322010-12-17 14:46:43 +00001641 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1642 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001643
1644 friend basic_string operator+<>(const basic_string&, const basic_string&);
1645 friend basic_string operator+<>(const value_type*, const basic_string&);
1646 friend basic_string operator+<>(value_type, const basic_string&);
1647 friend basic_string operator+<>(const basic_string&, const value_type*);
1648 friend basic_string operator+<>(const basic_string&, value_type);
1649};
1650
Marshall Clowa0563332018-02-08 06:34:03 +00001651#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1652template<class _InputIterator,
1653 class _CharT = typename iterator_traits<_InputIterator>::value_type,
1654 class _Allocator = allocator<_CharT>,
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001655 class = typename enable_if<__is_cpp17_input_iterator<_InputIterator>::value, void>::type,
Marshall Clowa0563332018-02-08 06:34:03 +00001656 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1657 >
1658basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
1659 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
Marshall Clowe46031a2018-07-02 18:41:15 +00001660
1661template<class _CharT,
1662 class _Traits,
1663 class _Allocator = allocator<_CharT>,
1664 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1665 >
1666explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
1667 -> basic_string<_CharT, _Traits, _Allocator>;
1668
1669template<class _CharT,
1670 class _Traits,
1671 class _Allocator = allocator<_CharT>,
1672 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type,
1673 class _Sz = typename allocator_traits<_Allocator>::size_type
1674 >
1675basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
1676 -> basic_string<_CharT, _Traits, _Allocator>;
Marshall Clowa0563332018-02-08 06:34:03 +00001677#endif
1678
Marshall Clow851b9ec2019-05-20 21:56:51 +00001679
Howard Hinnantc51e1022010-05-11 19:42:16 +00001680template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001681inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001682void
1683basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1684{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001685#if _LIBCPP_DEBUG_LEVEL >= 2
1686 __get_db()->__invalidate_all(this);
1687#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantc51e1022010-05-11 19:42:16 +00001688}
1689
1690template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001691inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001692void
Howard Hinnant28b24882011-12-01 20:21:04 +00001693basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant8ea98242013-08-23 17:37:05 +00001694#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant28b24882011-12-01 20:21:04 +00001695 __pos
1696#endif
1697 )
Howard Hinnantc51e1022010-05-11 19:42:16 +00001698{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001699#if _LIBCPP_DEBUG_LEVEL >= 2
1700 __c_node* __c = __get_db()->__find_c_and_lock(this);
1701 if (__c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001702 {
Howard Hinnant8ea98242013-08-23 17:37:05 +00001703 const_pointer __new_last = __get_pointer() + __pos;
1704 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantc51e1022010-05-11 19:42:16 +00001705 {
Howard Hinnant8ea98242013-08-23 17:37:05 +00001706 --__p;
1707 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1708 if (__i->base() > __new_last)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001709 {
Howard Hinnant8ea98242013-08-23 17:37:05 +00001710 (*__p)->__c_ = nullptr;
1711 if (--__c->end_ != __p)
1712 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001713 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001714 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001715 __get_db()->unlock();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001716 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001717#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantc51e1022010-05-11 19:42:16 +00001718}
1719
1720template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001721inline
Howard Hinnant3e276872011-06-03 18:40:47 +00001722basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowe546cbb2015-06-04 02:05:41 +00001723 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001724 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001725{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001726#if _LIBCPP_DEBUG_LEVEL >= 2
1727 __get_db()->__insert_c(this);
1728#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001729 __zero();
1730}
1731
1732template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001733inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001734basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiseliere012bf22015-07-18 20:40:46 +00001735#if _LIBCPP_STD_VER <= 14
1736 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1737#else
1738 _NOEXCEPT
1739#endif
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001740: __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001741{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001742#if _LIBCPP_DEBUG_LEVEL >= 2
1743 __get_db()->__insert_c(this);
1744#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001745 __zero();
1746}
1747
1748template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier815ed732016-09-16 00:00:48 +00001749void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1750 size_type __sz,
1751 size_type __reserve)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001752{
1753 if (__reserve > max_size())
1754 this->__throw_length_error();
1755 pointer __p;
1756 if (__reserve < __min_cap)
1757 {
1758 __set_short_size(__sz);
1759 __p = __get_short_pointer();
1760 }
1761 else
1762 {
1763 size_type __cap = __recommend(__reserve);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001764 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001765 __set_long_pointer(__p);
1766 __set_long_cap(__cap+1);
1767 __set_long_size(__sz);
1768 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001769 traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001770 traits_type::assign(__p[__sz], value_type());
1771}
1772
1773template <class _CharT, class _Traits, class _Allocator>
1774void
Howard Hinnantd17880b2013-06-28 16:59:19 +00001775basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001776{
1777 if (__sz > max_size())
1778 this->__throw_length_error();
1779 pointer __p;
1780 if (__sz < __min_cap)
1781 {
1782 __set_short_size(__sz);
1783 __p = __get_short_pointer();
1784 }
1785 else
1786 {
1787 size_type __cap = __recommend(__sz);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001788 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001789 __set_long_pointer(__p);
1790 __set_long_cap(__cap+1);
1791 __set_long_size(__sz);
1792 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001793 traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001794 traits_type::assign(__p[__sz], value_type());
1795}
1796
1797template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00001798template <class>
Eric Fiselier812882b2017-02-17 01:17:10 +00001799basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001800 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001801{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001802 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001803 __init(__s, traits_type::length(__s));
Howard Hinnant8ea98242013-08-23 17:37:05 +00001804#if _LIBCPP_DEBUG_LEVEL >= 2
1805 __get_db()->__insert_c(this);
1806#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001807}
1808
1809template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001810inline
Eric Fiselier812882b2017-02-17 01:17:10 +00001811basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001812 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001813{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001814 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001815 __init(__s, __n);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001816#if _LIBCPP_DEBUG_LEVEL >= 2
1817 __get_db()->__insert_c(this);
1818#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001819}
1820
1821template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001822inline
Eric Fiselier812882b2017-02-17 01:17:10 +00001823basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001824 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001825{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001826 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001827 __init(__s, __n);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001828#if _LIBCPP_DEBUG_LEVEL >= 2
1829 __get_db()->__insert_c(this);
1830#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001831}
1832
1833template <class _CharT, class _Traits, class _Allocator>
1834basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001835 : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001836{
1837 if (!__str.__is_long())
1838 __r_.first().__r = __str.__r_.first().__r;
1839 else
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001840 __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant8ea98242013-08-23 17:37:05 +00001841#if _LIBCPP_DEBUG_LEVEL >= 2
1842 __get_db()->__insert_c(this);
1843#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001844}
1845
1846template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier812882b2017-02-17 01:17:10 +00001847basic_string<_CharT, _Traits, _Allocator>::basic_string(
1848 const basic_string& __str, const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001849 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001850{
1851 if (!__str.__is_long())
1852 __r_.first().__r = __str.__r_.first().__r;
1853 else
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001854 __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant8ea98242013-08-23 17:37:05 +00001855#if _LIBCPP_DEBUG_LEVEL >= 2
1856 __get_db()->__insert_c(this);
1857#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001858}
1859
Eric Fiselierfc92be82017-04-19 00:28:44 +00001860#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001861
1862template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001863inline
Howard Hinnant3e276872011-06-03 18:40:47 +00001864basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clowa80abc72015-06-03 19:56:43 +00001865#if _LIBCPP_STD_VER <= 14
Howard Hinnant3e276872011-06-03 18:40:47 +00001866 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clowa80abc72015-06-03 19:56:43 +00001867#else
1868 _NOEXCEPT
1869#endif
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001870 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001871{
1872 __str.__zero();
Howard Hinnant8ea98242013-08-23 17:37:05 +00001873#if _LIBCPP_DEBUG_LEVEL >= 2
1874 __get_db()->__insert_c(this);
1875 if (__is_long())
1876 __get_db()->swap(this, &__str);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001877#endif
1878}
1879
1880template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001881inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001882basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001883 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001884{
Marshall Clowd2d24692014-07-17 15:32:20 +00001885 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001886 __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd2d24692014-07-17 15:32:20 +00001887 else
1888 {
1889 __r_.first().__r = __str.__r_.first().__r;
1890 __str.__zero();
1891 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001892#if _LIBCPP_DEBUG_LEVEL >= 2
1893 __get_db()->__insert_c(this);
1894 if (__is_long())
1895 __get_db()->swap(this, &__str);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001896#endif
1897}
1898
Eric Fiselierfc92be82017-04-19 00:28:44 +00001899#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001900
1901template <class _CharT, class _Traits, class _Allocator>
1902void
1903basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1904{
1905 if (__n > max_size())
1906 this->__throw_length_error();
1907 pointer __p;
1908 if (__n < __min_cap)
1909 {
1910 __set_short_size(__n);
1911 __p = __get_short_pointer();
1912 }
1913 else
1914 {
1915 size_type __cap = __recommend(__n);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001916 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001917 __set_long_pointer(__p);
1918 __set_long_cap(__cap+1);
1919 __set_long_size(__n);
1920 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001921 traits_type::assign(_VSTD::__to_address(__p), __n, __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001922 traits_type::assign(__p[__n], value_type());
1923}
1924
1925template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001926inline
Eric Fiselier812882b2017-02-17 01:17:10 +00001927basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001928 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001929{
1930 __init(__n, __c);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001931#if _LIBCPP_DEBUG_LEVEL >= 2
1932 __get_db()->__insert_c(this);
1933#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001934}
1935
1936template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00001937template <class>
Eric Fiselier812882b2017-02-17 01:17:10 +00001938basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001939 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001940{
1941 __init(__n, __c);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001942#if _LIBCPP_DEBUG_LEVEL >= 2
1943 __get_db()->__insert_c(this);
1944#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001945}
1946
Howard Hinnantc51e1022010-05-11 19:42:16 +00001947template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier812882b2017-02-17 01:17:10 +00001948basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1949 size_type __pos, size_type __n,
1950 const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001951 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001952{
1953 size_type __str_sz = __str.size();
1954 if (__pos > __str_sz)
1955 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001956 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant8ea98242013-08-23 17:37:05 +00001957#if _LIBCPP_DEBUG_LEVEL >= 2
1958 __get_db()->__insert_c(this);
1959#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001960}
1961
1962template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001963inline
Marshall Clow83445802016-04-07 18:13:41 +00001964basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier812882b2017-02-17 01:17:10 +00001965 const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001966 : __r_(__default_init_tag(), __a)
Marshall Clow83445802016-04-07 18:13:41 +00001967{
1968 size_type __str_sz = __str.size();
1969 if (__pos > __str_sz)
1970 this->__throw_out_of_range();
1971 __init(__str.data() + __pos, __str_sz - __pos);
1972#if _LIBCPP_DEBUG_LEVEL >= 2
1973 __get_db()->__insert_c(this);
1974#endif
1975}
1976
1977template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00001978template <class _Tp, class>
Marshall Clow78dbe462016-11-14 18:22:19 +00001979basic_string<_CharT, _Traits, _Allocator>::basic_string(
Marshall Clowe46031a2018-07-02 18:41:15 +00001980 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001981 : __r_(__default_init_tag(), __a)
Marshall Clow78dbe462016-11-14 18:22:19 +00001982{
Marshall Clowe46031a2018-07-02 18:41:15 +00001983 __self_view __sv0 = __t;
1984 __self_view __sv = __sv0.substr(__pos, __n);
Marshall Clow78dbe462016-11-14 18:22:19 +00001985 __init(__sv.data(), __sv.size());
1986#if _LIBCPP_DEBUG_LEVEL >= 2
1987 __get_db()->__insert_c(this);
Eric Fiselier812882b2017-02-17 01:17:10 +00001988#endif
Marshall Clow78dbe462016-11-14 18:22:19 +00001989}
1990
1991template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00001992template <class _Tp, class>
1993basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001994 : __r_(__default_init_tag(), __default_init_tag())
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001995{
Marshall Clowe46031a2018-07-02 18:41:15 +00001996 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001997 __init(__sv.data(), __sv.size());
1998#if _LIBCPP_DEBUG_LEVEL >= 2
1999 __get_db()->__insert_c(this);
2000#endif
2001}
2002
2003template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002004template <class _Tp, class>
2005basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002006 : __r_(__default_init_tag(), __a)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002007{
Marshall Clowe46031a2018-07-02 18:41:15 +00002008 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002009 __init(__sv.data(), __sv.size());
2010#if _LIBCPP_DEBUG_LEVEL >= 2
2011 __get_db()->__insert_c(this);
2012#endif
2013}
2014
2015template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002016template <class _InputIterator>
2017typename enable_if
2018<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002019 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002020 void
2021>::type
2022basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2023{
2024 __zero();
2025#ifndef _LIBCPP_NO_EXCEPTIONS
2026 try
2027 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002028#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002029 for (; __first != __last; ++__first)
2030 push_back(*__first);
2031#ifndef _LIBCPP_NO_EXCEPTIONS
2032 }
2033 catch (...)
2034 {
2035 if (__is_long())
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002036 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002037 throw;
2038 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002039#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002040}
2041
2042template <class _CharT, class _Traits, class _Allocator>
2043template <class _ForwardIterator>
2044typename enable_if
2045<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002046 __is_cpp17_forward_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002047 void
2048>::type
2049basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2050{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002051 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002052 if (__sz > max_size())
2053 this->__throw_length_error();
2054 pointer __p;
2055 if (__sz < __min_cap)
2056 {
2057 __set_short_size(__sz);
2058 __p = __get_short_pointer();
2059 }
2060 else
2061 {
2062 size_type __cap = __recommend(__sz);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002063 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002064 __set_long_pointer(__p);
2065 __set_long_cap(__cap+1);
2066 __set_long_size(__sz);
2067 }
Eric Fiseliera09a3b42014-10-27 19:28:20 +00002068 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002069 traits_type::assign(*__p, *__first);
2070 traits_type::assign(*__p, value_type());
2071}
2072
2073template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierc0f566d2019-03-14 12:31:10 +00002074template<class _InputIterator, class>
Eric Fiselierbea70602018-11-26 22:51:35 +00002075inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002076basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002077 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00002078{
2079 __init(__first, __last);
Howard Hinnant8ea98242013-08-23 17:37:05 +00002080#if _LIBCPP_DEBUG_LEVEL >= 2
2081 __get_db()->__insert_c(this);
2082#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002083}
2084
2085template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierc0f566d2019-03-14 12:31:10 +00002086template<class _InputIterator, class>
Eric Fiselierbea70602018-11-26 22:51:35 +00002087inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002088basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2089 const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002090 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002091{
2092 __init(__first, __last);
Howard Hinnant8ea98242013-08-23 17:37:05 +00002093#if _LIBCPP_DEBUG_LEVEL >= 2
2094 __get_db()->__insert_c(this);
2095#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002096}
2097
Eric Fiselierfc92be82017-04-19 00:28:44 +00002098#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant33711792011-08-12 21:56:02 +00002099
Howard Hinnantc51e1022010-05-11 19:42:16 +00002100template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002101inline
Eric Fiselier812882b2017-02-17 01:17:10 +00002102basic_string<_CharT, _Traits, _Allocator>::basic_string(
2103 initializer_list<_CharT> __il)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002104 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00002105{
2106 __init(__il.begin(), __il.end());
Howard Hinnant8ea98242013-08-23 17:37:05 +00002107#if _LIBCPP_DEBUG_LEVEL >= 2
2108 __get_db()->__insert_c(this);
2109#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002110}
2111
2112template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002113inline
Eric Fiselier9d355982017-04-12 23:45:53 +00002114
Eric Fiselier812882b2017-02-17 01:17:10 +00002115basic_string<_CharT, _Traits, _Allocator>::basic_string(
2116 initializer_list<_CharT> __il, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002117 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002118{
2119 __init(__il.begin(), __il.end());
Howard Hinnant8ea98242013-08-23 17:37:05 +00002120#if _LIBCPP_DEBUG_LEVEL >= 2
2121 __get_db()->__insert_c(this);
2122#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002123}
2124
Eric Fiselierfc92be82017-04-19 00:28:44 +00002125#endif // _LIBCPP_CXX03_LANG
Howard Hinnant33711792011-08-12 21:56:02 +00002126
Howard Hinnantc51e1022010-05-11 19:42:16 +00002127template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002128basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2129{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002130#if _LIBCPP_DEBUG_LEVEL >= 2
2131 __get_db()->__erase_c(this);
2132#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002133 if (__is_long())
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002134 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002135}
2136
2137template <class _CharT, class _Traits, class _Allocator>
2138void
2139basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2140 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnantd17880b2013-06-28 16:59:19 +00002141 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002142{
2143 size_type __ms = max_size();
2144 if (__delta_cap > __ms - __old_cap - 1)
2145 this->__throw_length_error();
2146 pointer __old_p = __get_pointer();
2147 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002148 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantc51e1022010-05-11 19:42:16 +00002149 __ms - 1;
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002150 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002151 __invalidate_all_iterators();
2152 if (__n_copy != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002153 traits_type::copy(_VSTD::__to_address(__p),
2154 _VSTD::__to_address(__old_p), __n_copy);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002155 if (__n_add != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002156 traits_type::copy(_VSTD::__to_address(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002157 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2158 if (__sec_cp_sz != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002159 traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2160 _VSTD::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002161 if (__old_cap+1 != __min_cap)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002162 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002163 __set_long_pointer(__p);
2164 __set_long_cap(__cap+1);
2165 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2166 __set_long_size(__old_sz);
2167 traits_type::assign(__p[__old_sz], value_type());
2168}
2169
2170template <class _CharT, class _Traits, class _Allocator>
2171void
2172basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2173 size_type __n_copy, size_type __n_del, size_type __n_add)
2174{
2175 size_type __ms = max_size();
Marshall Clow2267c5d2013-11-06 14:24:38 +00002176 if (__delta_cap > __ms - __old_cap)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002177 this->__throw_length_error();
2178 pointer __old_p = __get_pointer();
2179 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002180 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantc51e1022010-05-11 19:42:16 +00002181 __ms - 1;
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002182 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002183 __invalidate_all_iterators();
2184 if (__n_copy != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002185 traits_type::copy(_VSTD::__to_address(__p),
2186 _VSTD::__to_address(__old_p), __n_copy);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002187 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2188 if (__sec_cp_sz != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002189 traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2190 _VSTD::__to_address(__old_p) + __n_copy + __n_del,
Howard Hinnantd17880b2013-06-28 16:59:19 +00002191 __sec_cp_sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002192 if (__old_cap+1 != __min_cap)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002193 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002194 __set_long_pointer(__p);
2195 __set_long_cap(__cap+1);
2196}
2197
2198// assign
2199
2200template <class _CharT, class _Traits, class _Allocator>
2201basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002202basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002203{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002204 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002205 size_type __cap = capacity();
2206 if (__cap >= __n)
2207 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002208 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002209 traits_type::move(__p, __s, __n);
2210 traits_type::assign(__p[__n], value_type());
2211 __set_size(__n);
2212 __invalidate_iterators_past(__n);
2213 }
2214 else
2215 {
2216 size_type __sz = size();
2217 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2218 }
2219 return *this;
2220}
2221
2222template <class _CharT, class _Traits, class _Allocator>
2223basic_string<_CharT, _Traits, _Allocator>&
2224basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2225{
2226 size_type __cap = capacity();
2227 if (__cap < __n)
2228 {
2229 size_type __sz = size();
2230 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2231 }
2232 else
2233 __invalidate_iterators_past(__n);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002234 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002235 traits_type::assign(__p, __n, __c);
2236 traits_type::assign(__p[__n], value_type());
2237 __set_size(__n);
2238 return *this;
2239}
2240
2241template <class _CharT, class _Traits, class _Allocator>
2242basic_string<_CharT, _Traits, _Allocator>&
2243basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2244{
2245 pointer __p;
2246 if (__is_long())
2247 {
2248 __p = __get_long_pointer();
2249 __set_long_size(1);
2250 }
2251 else
2252 {
2253 __p = __get_short_pointer();
2254 __set_short_size(1);
2255 }
2256 traits_type::assign(*__p, __c);
2257 traits_type::assign(*++__p, value_type());
2258 __invalidate_iterators_past(1);
2259 return *this;
2260}
2261
2262template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002263basic_string<_CharT, _Traits, _Allocator>&
2264basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2265{
2266 if (this != &__str)
2267 {
2268 __copy_assign_alloc(__str);
Eric Fiselierbac2d652019-10-09 03:07:02 +00002269 return assign(__str.data(), __str.size());
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002270 }
2271 return *this;
2272}
2273
Eric Fiselierfc92be82017-04-19 00:28:44 +00002274#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002275
2276template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002277inline
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002278void
2279basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002280 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002281{
2282 if (__alloc() != __str.__alloc())
2283 assign(__str);
2284 else
2285 __move_assign(__str, true_type());
2286}
2287
2288template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002289inline
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002290void
2291basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002292#if _LIBCPP_STD_VER > 14
2293 _NOEXCEPT
2294#else
Howard Hinnant3e276872011-06-03 18:40:47 +00002295 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002296#endif
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002297{
marshall2ed41622019-11-27 07:13:00 -08002298 if (__is_long()) {
2299 __alloc_traits::deallocate(__alloc(), __get_long_pointer(),
2300 __get_long_cap());
2301#if _LIBCPP_STD_VER <= 14
2302 if (!is_nothrow_move_assignable<allocator_type>::value) {
2303 __set_short_size(0);
2304 traits_type::assign(__get_short_pointer()[0], value_type());
2305 }
2306#endif
2307 }
2308 __move_assign_alloc(__str);
2309 __r_.first() = __str.__r_.first();
2310 __str.__set_short_size(0);
2311 traits_type::assign(__str.__get_short_pointer()[0], value_type());
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002312}
2313
2314template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002315inline
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002316basic_string<_CharT, _Traits, _Allocator>&
2317basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002318 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002319{
2320 __move_assign(__str, integral_constant<bool,
2321 __alloc_traits::propagate_on_container_move_assignment::value>());
2322 return *this;
2323}
2324
2325#endif
2326
2327template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002328template<class _InputIterator>
2329typename enable_if
2330<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002331 __is_exactly_cpp17_input_iterator <_InputIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002332 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002333 basic_string<_CharT, _Traits, _Allocator>&
2334>::type
2335basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2336{
Marshall Clow958362f2016-09-05 01:54:30 +00002337 const basic_string __temp(__first, __last, __alloc());
Marshall Clow039b2f02016-01-13 21:54:34 +00002338 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002339 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002340}
2341
2342template <class _CharT, class _Traits, class _Allocator>
2343template<class _ForwardIterator>
2344typename enable_if
2345<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002346 __is_cpp17_forward_iterator<_ForwardIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002347 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002348 basic_string<_CharT, _Traits, _Allocator>&
2349>::type
2350basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2351{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002352 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002353 size_type __cap = capacity();
2354 if (__cap < __n)
2355 {
2356 size_type __sz = size();
2357 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2358 }
2359 else
2360 __invalidate_iterators_past(__n);
2361 pointer __p = __get_pointer();
2362 for (; __first != __last; ++__first, ++__p)
2363 traits_type::assign(*__p, *__first);
2364 traits_type::assign(*__p, value_type());
2365 __set_size(__n);
2366 return *this;
2367}
2368
2369template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002370basic_string<_CharT, _Traits, _Allocator>&
2371basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2372{
2373 size_type __sz = __str.size();
2374 if (__pos > __sz)
2375 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002376 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002377}
2378
2379template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00002380template <class _Tp>
2381typename enable_if
2382<
2383 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00002384 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow82513342016-09-24 22:45:42 +00002385>::type
2386basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002387{
Marshall Clow82513342016-09-24 22:45:42 +00002388 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002389 size_type __sz = __sv.size();
2390 if (__pos > __sz)
2391 this->__throw_out_of_range();
2392 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2393}
2394
2395
2396template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002397basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002398basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002399{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002400 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002401 return assign(__s, traits_type::length(__s));
2402}
2403
2404// append
2405
2406template <class _CharT, class _Traits, class _Allocator>
2407basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002408basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002409{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002410 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002411 size_type __cap = capacity();
2412 size_type __sz = size();
2413 if (__cap - __sz >= __n)
2414 {
2415 if (__n)
2416 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002417 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002418 traits_type::copy(__p + __sz, __s, __n);
2419 __sz += __n;
2420 __set_size(__sz);
2421 traits_type::assign(__p[__sz], value_type());
2422 }
2423 }
2424 else
2425 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2426 return *this;
2427}
2428
2429template <class _CharT, class _Traits, class _Allocator>
2430basic_string<_CharT, _Traits, _Allocator>&
2431basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2432{
2433 if (__n)
2434 {
2435 size_type __cap = capacity();
2436 size_type __sz = size();
2437 if (__cap - __sz < __n)
2438 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2439 pointer __p = __get_pointer();
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002440 traits_type::assign(_VSTD::__to_address(__p) + __sz, __n, __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002441 __sz += __n;
2442 __set_size(__sz);
2443 traits_type::assign(__p[__sz], value_type());
2444 }
2445 return *this;
2446}
2447
2448template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier451d5582018-11-26 20:15:38 +00002449inline void
2450basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
2451{
2452 if (__n)
2453 {
2454 size_type __cap = capacity();
2455 size_type __sz = size();
2456 if (__cap - __sz < __n)
2457 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2458 pointer __p = __get_pointer();
2459 __sz += __n;
2460 __set_size(__sz);
2461 traits_type::assign(__p[__sz], value_type());
2462 }
2463}
2464
2465template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002466void
2467basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2468{
Howard Hinnant68bf1812013-04-30 21:44:48 +00002469 bool __is_short = !__is_long();
2470 size_type __cap;
2471 size_type __sz;
2472 if (__is_short)
2473 {
2474 __cap = __min_cap - 1;
2475 __sz = __get_short_size();
2476 }
2477 else
2478 {
2479 __cap = __get_long_cap() - 1;
2480 __sz = __get_long_size();
2481 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002482 if (__sz == __cap)
Howard Hinnant68bf1812013-04-30 21:44:48 +00002483 {
Howard Hinnantc51e1022010-05-11 19:42:16 +00002484 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant68bf1812013-04-30 21:44:48 +00002485 __is_short = !__is_long();
2486 }
2487 pointer __p;
2488 if (__is_short)
2489 {
2490 __p = __get_short_pointer() + __sz;
2491 __set_short_size(__sz+1);
2492 }
2493 else
2494 {
2495 __p = __get_long_pointer() + __sz;
2496 __set_long_size(__sz+1);
2497 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002498 traits_type::assign(*__p, __c);
2499 traits_type::assign(*++__p, value_type());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002500}
2501
Marshall Clow6ebbf662016-09-07 03:32:06 +00002502template <class _Tp>
Marshall Clow958362f2016-09-05 01:54:30 +00002503bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2504{
2505 return __first <= __p && __p < __last;
2506}
2507
Marshall Clow6ebbf662016-09-07 03:32:06 +00002508template <class _Tp1, class _Tp2>
Eric Fiselier6003c772016-12-23 23:37:52 +00002509bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
Marshall Clow6ebbf662016-09-07 03:32:06 +00002510{
2511 return false;
2512}
2513
Howard Hinnantc51e1022010-05-11 19:42:16 +00002514template <class _CharT, class _Traits, class _Allocator>
2515template<class _ForwardIterator>
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00002516basic_string<_CharT, _Traits, _Allocator>&
2517basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2518 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002519{
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002520 static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00002521 "function requires a ForwardIterator");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002522 size_type __sz = size();
2523 size_type __cap = capacity();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002524 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002525 if (__n)
2526 {
Eric Fiselier96866b52017-04-15 06:49:02 +00002527 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2528 _CharRef __tmp_ref = *__first;
2529 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
Marshall Clow958362f2016-09-05 01:54:30 +00002530 {
2531 const basic_string __temp (__first, __last, __alloc());
2532 append(__temp.data(), __temp.size());
2533 }
Louis Dionne173f29e2019-05-29 16:01:36 +00002534 else
Marshall Clow958362f2016-09-05 01:54:30 +00002535 {
2536 if (__cap - __sz < __n)
2537 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2538 pointer __p = __get_pointer() + __sz;
2539 for (; __first != __last; ++__p, ++__first)
2540 traits_type::assign(*__p, *__first);
2541 traits_type::assign(*__p, value_type());
2542 __set_size(__sz + __n);
2543 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002544 }
2545 return *this;
2546}
2547
2548template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002549inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002550basic_string<_CharT, _Traits, _Allocator>&
2551basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2552{
2553 return append(__str.data(), __str.size());
2554}
2555
2556template <class _CharT, class _Traits, class _Allocator>
2557basic_string<_CharT, _Traits, _Allocator>&
2558basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2559{
2560 size_type __sz = __str.size();
2561 if (__pos > __sz)
2562 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002563 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002564}
2565
2566template <class _CharT, class _Traits, class _Allocator>
Marshall Clow62953962016-10-03 23:40:48 +00002567template <class _Tp>
Marshall Clow82513342016-09-24 22:45:42 +00002568 typename enable_if
2569 <
2570 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2571 basic_string<_CharT, _Traits, _Allocator>&
2572 >::type
2573basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002574{
Marshall Clow82513342016-09-24 22:45:42 +00002575 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002576 size_type __sz = __sv.size();
2577 if (__pos > __sz)
2578 this->__throw_out_of_range();
2579 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2580}
2581
2582template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002583basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002584basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002585{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002586 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002587 return append(__s, traits_type::length(__s));
2588}
2589
2590// insert
2591
2592template <class _CharT, class _Traits, class _Allocator>
2593basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002594basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002595{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002596 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002597 size_type __sz = size();
2598 if (__pos > __sz)
2599 this->__throw_out_of_range();
2600 size_type __cap = capacity();
2601 if (__cap - __sz >= __n)
2602 {
2603 if (__n)
2604 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002605 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002606 size_type __n_move = __sz - __pos;
2607 if (__n_move != 0)
2608 {
2609 if (__p + __pos <= __s && __s < __p + __sz)
2610 __s += __n;
2611 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2612 }
2613 traits_type::move(__p + __pos, __s, __n);
2614 __sz += __n;
2615 __set_size(__sz);
2616 traits_type::assign(__p[__sz], value_type());
2617 }
2618 }
2619 else
2620 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2621 return *this;
2622}
2623
2624template <class _CharT, class _Traits, class _Allocator>
2625basic_string<_CharT, _Traits, _Allocator>&
2626basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2627{
2628 size_type __sz = size();
2629 if (__pos > __sz)
2630 this->__throw_out_of_range();
2631 if (__n)
2632 {
2633 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002634 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002635 if (__cap - __sz >= __n)
2636 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002637 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002638 size_type __n_move = __sz - __pos;
2639 if (__n_move != 0)
2640 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2641 }
2642 else
2643 {
2644 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002645 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002646 }
2647 traits_type::assign(__p + __pos, __n, __c);
2648 __sz += __n;
2649 __set_size(__sz);
2650 traits_type::assign(__p[__sz], value_type());
2651 }
2652 return *this;
2653}
2654
2655template <class _CharT, class _Traits, class _Allocator>
2656template<class _InputIterator>
2657typename enable_if
2658<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002659 __is_exactly_cpp17_input_iterator<_InputIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002660 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2661 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00002662>::type
2663basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2664{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002665#if _LIBCPP_DEBUG_LEVEL >= 2
2666 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2667 "string::insert(iterator, range) called with an iterator not"
2668 " referring to this string");
2669#endif
Marshall Clow958362f2016-09-05 01:54:30 +00002670 const basic_string __temp(__first, __last, __alloc());
Marshall Clow039b2f02016-01-13 21:54:34 +00002671 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002672}
2673
2674template <class _CharT, class _Traits, class _Allocator>
2675template<class _ForwardIterator>
2676typename enable_if
2677<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002678 __is_cpp17_forward_iterator<_ForwardIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002679 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002680 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2681>::type
2682basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2683{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002684#if _LIBCPP_DEBUG_LEVEL >= 2
2685 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2686 "string::insert(iterator, range) called with an iterator not"
2687 " referring to this string");
2688#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002689 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002690 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002691 if (__n)
2692 {
Eric Fiselier96866b52017-04-15 06:49:02 +00002693 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2694 _CharRef __tmp_char = *__first;
2695 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
Marshall Clow958362f2016-09-05 01:54:30 +00002696 {
2697 const basic_string __temp(__first, __last, __alloc());
2698 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2699 }
2700
2701 size_type __sz = size();
2702 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002703 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002704 if (__cap - __sz >= __n)
2705 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002706 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002707 size_type __n_move = __sz - __ip;
2708 if (__n_move != 0)
2709 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2710 }
2711 else
2712 {
2713 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002714 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002715 }
2716 __sz += __n;
2717 __set_size(__sz);
2718 traits_type::assign(__p[__sz], value_type());
2719 for (__p += __ip; __first != __last; ++__p, ++__first)
2720 traits_type::assign(*__p, *__first);
2721 }
2722 return begin() + __ip;
2723}
2724
2725template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002726inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002727basic_string<_CharT, _Traits, _Allocator>&
2728basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2729{
2730 return insert(__pos1, __str.data(), __str.size());
2731}
2732
2733template <class _CharT, class _Traits, class _Allocator>
2734basic_string<_CharT, _Traits, _Allocator>&
2735basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2736 size_type __pos2, size_type __n)
2737{
2738 size_type __str_sz = __str.size();
2739 if (__pos2 > __str_sz)
2740 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002741 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002742}
2743
2744template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00002745template <class _Tp>
2746typename enable_if
2747<
2748 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00002749 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow82513342016-09-24 22:45:42 +00002750>::type
2751basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002752 size_type __pos2, size_type __n)
2753{
Marshall Clow82513342016-09-24 22:45:42 +00002754 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002755 size_type __str_sz = __sv.size();
2756 if (__pos2 > __str_sz)
2757 this->__throw_out_of_range();
2758 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2759}
2760
2761template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002762basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002763basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002764{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002765 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002766 return insert(__pos, __s, traits_type::length(__s));
2767}
2768
2769template <class _CharT, class _Traits, class _Allocator>
2770typename basic_string<_CharT, _Traits, _Allocator>::iterator
2771basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2772{
2773 size_type __ip = static_cast<size_type>(__pos - begin());
2774 size_type __sz = size();
2775 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002776 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002777 if (__cap == __sz)
2778 {
2779 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002780 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002781 }
2782 else
2783 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002784 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002785 size_type __n_move = __sz - __ip;
2786 if (__n_move != 0)
2787 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2788 }
2789 traits_type::assign(__p[__ip], __c);
2790 traits_type::assign(__p[++__sz], value_type());
2791 __set_size(__sz);
2792 return begin() + static_cast<difference_type>(__ip);
2793}
2794
2795template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002796inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002797typename basic_string<_CharT, _Traits, _Allocator>::iterator
2798basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2799{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002800#if _LIBCPP_DEBUG_LEVEL >= 2
2801 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2802 "string::insert(iterator, n, value) called with an iterator not"
2803 " referring to this string");
2804#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002805 difference_type __p = __pos - begin();
2806 insert(static_cast<size_type>(__p), __n, __c);
2807 return begin() + __p;
2808}
2809
2810// replace
2811
2812template <class _CharT, class _Traits, class _Allocator>
2813basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002814basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
Eric Fiseliere5b21842017-03-09 01:54:13 +00002815 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantc51e1022010-05-11 19:42:16 +00002816{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002817 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002818 size_type __sz = size();
2819 if (__pos > __sz)
2820 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002821 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002822 size_type __cap = capacity();
2823 if (__cap - __sz + __n1 >= __n2)
2824 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002825 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002826 if (__n1 != __n2)
2827 {
2828 size_type __n_move = __sz - __pos - __n1;
2829 if (__n_move != 0)
2830 {
2831 if (__n1 > __n2)
2832 {
2833 traits_type::move(__p + __pos, __s, __n2);
2834 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2835 goto __finish;
2836 }
2837 if (__p + __pos < __s && __s < __p + __sz)
2838 {
2839 if (__p + __pos + __n1 <= __s)
2840 __s += __n2 - __n1;
2841 else // __p + __pos < __s < __p + __pos + __n1
2842 {
2843 traits_type::move(__p + __pos, __s, __n1);
2844 __pos += __n1;
2845 __s += __n2;
2846 __n2 -= __n1;
2847 __n1 = 0;
2848 }
2849 }
2850 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2851 }
2852 }
2853 traits_type::move(__p + __pos, __s, __n2);
2854__finish:
Eric Fiseliere5b21842017-03-09 01:54:13 +00002855// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
2856// but this is a safe operation, so we disable the check.
Howard Hinnantc51e1022010-05-11 19:42:16 +00002857 __sz += __n2 - __n1;
2858 __set_size(__sz);
2859 __invalidate_iterators_past(__sz);
2860 traits_type::assign(__p[__sz], value_type());
2861 }
2862 else
2863 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2864 return *this;
2865}
2866
2867template <class _CharT, class _Traits, class _Allocator>
2868basic_string<_CharT, _Traits, _Allocator>&
2869basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
Eric Fiseliere5b21842017-03-09 01:54:13 +00002870 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantc51e1022010-05-11 19:42:16 +00002871{
2872 size_type __sz = size();
2873 if (__pos > __sz)
2874 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002875 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002876 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002877 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002878 if (__cap - __sz + __n1 >= __n2)
2879 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002880 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002881 if (__n1 != __n2)
2882 {
2883 size_type __n_move = __sz - __pos - __n1;
2884 if (__n_move != 0)
2885 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2886 }
2887 }
2888 else
2889 {
2890 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002891 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002892 }
2893 traits_type::assign(__p + __pos, __n2, __c);
2894 __sz += __n2 - __n1;
2895 __set_size(__sz);
2896 __invalidate_iterators_past(__sz);
2897 traits_type::assign(__p[__sz], value_type());
2898 return *this;
2899}
2900
2901template <class _CharT, class _Traits, class _Allocator>
2902template<class _InputIterator>
2903typename enable_if
2904<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002905 __is_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002906 basic_string<_CharT, _Traits, _Allocator>&
2907>::type
Howard Hinnant990d6e82010-11-17 21:11:40 +00002908basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002909 _InputIterator __j1, _InputIterator __j2)
2910{
Marshall Clow958362f2016-09-05 01:54:30 +00002911 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clow039b2f02016-01-13 21:54:34 +00002912 return this->replace(__i1, __i2, __temp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002913}
2914
2915template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002916inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002917basic_string<_CharT, _Traits, _Allocator>&
2918basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2919{
2920 return replace(__pos1, __n1, __str.data(), __str.size());
2921}
2922
2923template <class _CharT, class _Traits, class _Allocator>
2924basic_string<_CharT, _Traits, _Allocator>&
2925basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2926 size_type __pos2, size_type __n2)
2927{
2928 size_type __str_sz = __str.size();
2929 if (__pos2 > __str_sz)
2930 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002931 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002932}
2933
2934template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00002935template <class _Tp>
2936typename enable_if
2937<
Marshall Clowb7db4972017-11-15 20:02:27 +00002938 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2939 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow82513342016-09-24 22:45:42 +00002940>::type
2941basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002942 size_type __pos2, size_type __n2)
2943{
Marshall Clow82513342016-09-24 22:45:42 +00002944 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002945 size_type __str_sz = __sv.size();
2946 if (__pos2 > __str_sz)
2947 this->__throw_out_of_range();
2948 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2949}
2950
2951template <class _CharT, class _Traits, class _Allocator>
2952basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002953basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002954{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002955 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002956 return replace(__pos, __n1, __s, traits_type::length(__s));
2957}
2958
2959template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002960inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002961basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant990d6e82010-11-17 21:11:40 +00002962basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002963{
2964 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2965 __str.data(), __str.size());
2966}
2967
2968template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002969inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002970basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002971basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002972{
2973 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2974}
2975
2976template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002977inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002978basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002979basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002980{
2981 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2982}
2983
2984template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002985inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002986basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant990d6e82010-11-17 21:11:40 +00002987basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002988{
2989 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2990}
2991
2992// erase
2993
2994template <class _CharT, class _Traits, class _Allocator>
2995basic_string<_CharT, _Traits, _Allocator>&
2996basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2997{
2998 size_type __sz = size();
2999 if (__pos > __sz)
3000 this->__throw_out_of_range();
3001 if (__n)
3002 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05003003 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003004 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003005 size_type __n_move = __sz - __pos - __n;
3006 if (__n_move != 0)
3007 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3008 __sz -= __n;
3009 __set_size(__sz);
3010 __invalidate_iterators_past(__sz);
3011 traits_type::assign(__p[__sz], value_type());
3012 }
3013 return *this;
3014}
3015
3016template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003017inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003018typename basic_string<_CharT, _Traits, _Allocator>::iterator
3019basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3020{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003021#if _LIBCPP_DEBUG_LEVEL >= 2
3022 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3023 "string::erase(iterator) called with an iterator not"
3024 " referring to this string");
3025#endif
3026 _LIBCPP_ASSERT(__pos != end(),
3027 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003028 iterator __b = begin();
3029 size_type __r = static_cast<size_type>(__pos - __b);
3030 erase(__r, 1);
Howard Hinnant28b24882011-12-01 20:21:04 +00003031 return __b + static_cast<difference_type>(__r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003032}
3033
3034template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003035inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003036typename basic_string<_CharT, _Traits, _Allocator>::iterator
3037basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3038{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003039#if _LIBCPP_DEBUG_LEVEL >= 2
3040 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3041 "string::erase(iterator, iterator) called with an iterator not"
3042 " referring to this string");
3043#endif
3044 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003045 iterator __b = begin();
3046 size_type __r = static_cast<size_type>(__first - __b);
3047 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnant28b24882011-12-01 20:21:04 +00003048 return __b + static_cast<difference_type>(__r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003049}
3050
3051template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003052inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003053void
3054basic_string<_CharT, _Traits, _Allocator>::pop_back()
3055{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003056 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003057 size_type __sz;
3058 if (__is_long())
3059 {
3060 __sz = __get_long_size() - 1;
3061 __set_long_size(__sz);
3062 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3063 }
3064 else
3065 {
3066 __sz = __get_short_size() - 1;
3067 __set_short_size(__sz);
3068 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3069 }
3070 __invalidate_iterators_past(__sz);
3071}
3072
3073template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003074inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003075void
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003076basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003077{
3078 __invalidate_all_iterators();
3079 if (__is_long())
3080 {
3081 traits_type::assign(*__get_long_pointer(), value_type());
3082 __set_long_size(0);
3083 }
3084 else
3085 {
3086 traits_type::assign(*__get_short_pointer(), value_type());
3087 __set_short_size(0);
3088 }
3089}
3090
3091template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003092inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003093void
3094basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3095{
3096 if (__is_long())
3097 {
3098 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3099 __set_long_size(__pos);
3100 }
3101 else
3102 {
3103 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3104 __set_short_size(__pos);
3105 }
3106 __invalidate_iterators_past(__pos);
3107}
3108
3109template <class _CharT, class _Traits, class _Allocator>
3110void
3111basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3112{
3113 size_type __sz = size();
3114 if (__n > __sz)
3115 append(__n - __sz, __c);
3116 else
3117 __erase_to_end(__n);
3118}
3119
3120template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier451d5582018-11-26 20:15:38 +00003121inline void
3122basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
3123{
3124 size_type __sz = size();
3125 if (__n > __sz) {
3126 __append_default_init(__n - __sz);
3127 } else
3128 __erase_to_end(__n);
3129}
3130
3131template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003132inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003133typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003134basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003135{
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003136 size_type __m = __alloc_traits::max_size(__alloc());
Eric Fiseliere9cc5922017-10-17 13:16:01 +00003137#ifdef _LIBCPP_BIG_ENDIAN
Marshall Clow6dd6cb72013-10-31 17:23:08 +00003138 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003139#else
Marshall Clow6dd6cb72013-10-31 17:23:08 +00003140 return __m - __alignment;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003141#endif
3142}
3143
3144template <class _CharT, class _Traits, class _Allocator>
3145void
3146basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3147{
3148 if (__res_arg > max_size())
3149 this->__throw_length_error();
3150 size_type __cap = capacity();
3151 size_type __sz = size();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003152 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003153 __res_arg = __recommend(__res_arg);
3154 if (__res_arg != __cap)
3155 {
3156 pointer __new_data, __p;
3157 bool __was_long, __now_long;
3158 if (__res_arg == __min_cap - 1)
3159 {
3160 __was_long = true;
3161 __now_long = false;
3162 __new_data = __get_short_pointer();
3163 __p = __get_long_pointer();
3164 }
3165 else
3166 {
3167 if (__res_arg > __cap)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003168 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003169 else
3170 {
3171 #ifndef _LIBCPP_NO_EXCEPTIONS
3172 try
3173 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003174 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003175 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003176 #ifndef _LIBCPP_NO_EXCEPTIONS
3177 }
3178 catch (...)
3179 {
3180 return;
3181 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003182 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantd17880b2013-06-28 16:59:19 +00003183 if (__new_data == nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003184 return;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003185 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00003186 }
3187 __now_long = true;
3188 __was_long = __is_long();
3189 __p = __get_pointer();
3190 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05003191 traits_type::copy(_VSTD::__to_address(__new_data),
3192 _VSTD::__to_address(__p), size()+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003193 if (__was_long)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003194 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003195 if (__now_long)
3196 {
3197 __set_long_cap(__res_arg+1);
3198 __set_long_size(__sz);
3199 __set_long_pointer(__new_data);
3200 }
3201 else
3202 __set_short_size(__sz);
3203 __invalidate_all_iterators();
3204 }
3205}
3206
3207template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003208inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003209typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003210basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003211{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003212 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003213 return *(data() + __pos);
3214}
3215
3216template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003217inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003218typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003219basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003220{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003221 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003222 return *(__get_pointer() + __pos);
3223}
3224
3225template <class _CharT, class _Traits, class _Allocator>
3226typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3227basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3228{
3229 if (__n >= size())
3230 this->__throw_out_of_range();
3231 return (*this)[__n];
3232}
3233
3234template <class _CharT, class _Traits, class _Allocator>
3235typename basic_string<_CharT, _Traits, _Allocator>::reference
3236basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3237{
3238 if (__n >= size())
3239 this->__throw_out_of_range();
3240 return (*this)[__n];
3241}
3242
3243template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003244inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003245typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003246basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003247{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003248 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003249 return *__get_pointer();
3250}
3251
3252template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003253inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003254typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003255basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003256{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003257 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003258 return *data();
3259}
3260
3261template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003262inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003263typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003264basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003265{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003266 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003267 return *(__get_pointer() + size() - 1);
3268}
3269
3270template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003271inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003272typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003273basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003274{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003275 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003276 return *(data() + size() - 1);
3277}
3278
3279template <class _CharT, class _Traits, class _Allocator>
3280typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003281basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003282{
3283 size_type __sz = size();
3284 if (__pos > __sz)
3285 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003286 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003287 traits_type::copy(__s, data() + __pos, __rlen);
3288 return __rlen;
3289}
3290
3291template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003292inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003293basic_string<_CharT, _Traits, _Allocator>
3294basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3295{
3296 return basic_string(*this, __pos, __n, __alloc());
3297}
3298
3299template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003300inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003301void
3302basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow8982dcd2015-07-13 20:04:56 +00003303#if _LIBCPP_STD_VER >= 14
Eric Fiselier873b8d32019-03-18 21:50:12 +00003304 _NOEXCEPT
Marshall Clow8982dcd2015-07-13 20:04:56 +00003305#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00003306 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow8982dcd2015-07-13 20:04:56 +00003307 __is_nothrow_swappable<allocator_type>::value)
3308#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003309{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003310#if _LIBCPP_DEBUG_LEVEL >= 2
3311 if (!__is_long())
3312 __get_db()->__invalidate_all(this);
3313 if (!__str.__is_long())
3314 __get_db()->__invalidate_all(&__str);
3315 __get_db()->swap(this, &__str);
3316#endif
Eric Fiselier9bf691f2016-12-28 05:53:01 +00003317 _LIBCPP_ASSERT(
3318 __alloc_traits::propagate_on_container_swap::value ||
3319 __alloc_traits::is_always_equal::value ||
3320 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003321 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow8982dcd2015-07-13 20:04:56 +00003322 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003323}
3324
3325// find
3326
3327template <class _Traits>
3328struct _LIBCPP_HIDDEN __traits_eq
3329{
3330 typedef typename _Traits::char_type char_type;
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003331 _LIBCPP_INLINE_VISIBILITY
3332 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3333 {return _Traits::eq(__x, __y);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003334};
3335
3336template<class _CharT, class _Traits, class _Allocator>
3337typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003338basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003339 size_type __pos,
3340 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003341{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003342 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003343 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003344 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003345}
3346
3347template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003348inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003349typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003350basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3351 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003352{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003353 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003354 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003355}
3356
3357template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003358template <class _Tp>
3359typename enable_if
3360<
3361 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3362 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3363>::type
3364basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
3365 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003366{
Marshall Clowe46031a2018-07-02 18:41:15 +00003367 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003368 return __str_find<value_type, size_type, traits_type, npos>
3369 (data(), size(), __sv.data(), __pos, __sv.size());
3370}
3371
3372template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003373inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003374typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003375basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003376 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003377{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003378 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003379 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003380 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003381}
3382
3383template<class _CharT, class _Traits, class _Allocator>
3384typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003385basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3386 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003387{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003388 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003389 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003390}
3391
3392// rfind
3393
3394template<class _CharT, class _Traits, class _Allocator>
3395typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003396basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003397 size_type __pos,
3398 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003399{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003400 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003401 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003402 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003403}
3404
3405template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003406inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003407typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003408basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3409 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003410{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003411 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003412 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003413}
3414
3415template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003416template <class _Tp>
3417typename enable_if
3418<
3419 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3420 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3421>::type
3422basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
3423 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003424{
Marshall Clowe46031a2018-07-02 18:41:15 +00003425 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003426 return __str_rfind<value_type, size_type, traits_type, npos>
3427 (data(), size(), __sv.data(), __pos, __sv.size());
3428}
3429
3430template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003431inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003432typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003433basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003434 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003435{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003436 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003437 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003438 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003439}
3440
3441template<class _CharT, class _Traits, class _Allocator>
3442typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003443basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3444 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003445{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003446 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003447 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003448}
3449
3450// find_first_of
3451
3452template<class _CharT, class _Traits, class _Allocator>
3453typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003454basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003455 size_type __pos,
3456 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003457{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003458 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003459 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003460 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003461}
3462
3463template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003464inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003465typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003466basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3467 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003468{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003469 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003470 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003471}
3472
3473template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003474template <class _Tp>
3475typename enable_if
3476<
3477 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3478 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3479>::type
3480basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
3481 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003482{
Marshall Clowe46031a2018-07-02 18:41:15 +00003483 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003484 return __str_find_first_of<value_type, size_type, traits_type, npos>
3485 (data(), size(), __sv.data(), __pos, __sv.size());
3486}
3487
3488template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003489inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003490typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003491basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003492 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003493{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003494 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003495 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003496 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003497}
3498
3499template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003500inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003501typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003502basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3503 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003504{
3505 return find(__c, __pos);
3506}
3507
3508// find_last_of
3509
3510template<class _CharT, class _Traits, class _Allocator>
3511typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003512basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003513 size_type __pos,
3514 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003515{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003516 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003517 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003518 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003519}
3520
3521template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003522inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003523typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003524basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3525 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003526{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003527 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003528 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003529}
3530
3531template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003532template <class _Tp>
3533typename enable_if
3534<
3535 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3536 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3537>::type
3538basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
3539 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003540{
Marshall Clowe46031a2018-07-02 18:41:15 +00003541 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003542 return __str_find_last_of<value_type, size_type, traits_type, npos>
3543 (data(), size(), __sv.data(), __pos, __sv.size());
3544}
3545
3546template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003547inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003548typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003549basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003550 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003551{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003552 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003553 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003554 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003555}
3556
3557template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003558inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003559typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003560basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3561 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003562{
3563 return rfind(__c, __pos);
3564}
3565
3566// find_first_not_of
3567
3568template<class _CharT, class _Traits, class _Allocator>
3569typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003570basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003571 size_type __pos,
3572 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003573{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003574 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003575 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003576 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003577}
3578
3579template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003580inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003581typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003582basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3583 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003584{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003585 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003586 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003587}
3588
3589template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003590template <class _Tp>
3591typename enable_if
3592<
3593 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3594 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3595>::type
3596basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
3597 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003598{
Marshall Clowe46031a2018-07-02 18:41:15 +00003599 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003600 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3601 (data(), size(), __sv.data(), __pos, __sv.size());
3602}
3603
3604template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003605inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003606typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003607basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003608 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003609{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003610 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003611 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003612 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003613}
3614
3615template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003616inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003617typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003618basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3619 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003620{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003621 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003622 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003623}
3624
3625// find_last_not_of
3626
3627template<class _CharT, class _Traits, class _Allocator>
3628typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003629basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003630 size_type __pos,
3631 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003632{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003633 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003634 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003635 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003636}
3637
3638template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003639inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003640typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003641basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3642 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003643{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003644 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003645 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003646}
3647
3648template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003649template <class _Tp>
3650typename enable_if
3651<
3652 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3653 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3654>::type
3655basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
3656 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003657{
Marshall Clowe46031a2018-07-02 18:41:15 +00003658 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003659 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3660 (data(), size(), __sv.data(), __pos, __sv.size());
3661}
3662
3663template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003664inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003665typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003666basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003667 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003668{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003669 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003670 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003671 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003672}
3673
3674template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003675inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003676typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003677basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3678 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003679{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003680 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003681 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003682}
3683
3684// compare
3685
3686template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003687template <class _Tp>
3688typename enable_if
3689<
3690 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3691 int
3692>::type
3693basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003694{
Marshall Clowe46031a2018-07-02 18:41:15 +00003695 __self_view __sv = __t;
Howard Hinnantb0485532011-07-24 21:45:06 +00003696 size_t __lhs_sz = size();
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003697 size_t __rhs_sz = __sv.size();
3698 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantb0485532011-07-24 21:45:06 +00003699 _VSTD::min(__lhs_sz, __rhs_sz));
3700 if (__result != 0)
3701 return __result;
3702 if (__lhs_sz < __rhs_sz)
3703 return -1;
3704 if (__lhs_sz > __rhs_sz)
3705 return 1;
3706 return 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003707}
3708
3709template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003710inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003711int
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003712basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003713{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003714 return compare(__self_view(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003715}
3716
3717template <class _CharT, class _Traits, class _Allocator>
3718int
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003719basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3720 size_type __n1,
Howard Hinnantd17880b2013-06-28 16:59:19 +00003721 const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003722 size_type __n2) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003723{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003724 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003725 size_type __sz = size();
3726 if (__pos1 > __sz || __n2 == npos)
3727 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003728 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3729 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003730 if (__r == 0)
3731 {
3732 if (__rlen < __n2)
3733 __r = -1;
3734 else if (__rlen > __n2)
3735 __r = 1;
3736 }
3737 return __r;
3738}
3739
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003740template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003741template <class _Tp>
3742typename enable_if
3743<
3744 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3745 int
3746>::type
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003747basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3748 size_type __n1,
Marshall Clowe46031a2018-07-02 18:41:15 +00003749 const _Tp& __t) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003750{
Marshall Clowe46031a2018-07-02 18:41:15 +00003751 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003752 return compare(__pos1, __n1, __sv.data(), __sv.size());
3753}
3754
3755template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003756inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003757int
3758basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3759 size_type __n1,
3760 const basic_string& __str) const
3761{
3762 return compare(__pos1, __n1, __str.data(), __str.size());
3763}
3764
3765template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00003766template <class _Tp>
3767typename enable_if
3768<
Marshall Clowb7db4972017-11-15 20:02:27 +00003769 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3770 int
Marshall Clow82513342016-09-24 22:45:42 +00003771>::type
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003772basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3773 size_type __n1,
Marshall Clow82513342016-09-24 22:45:42 +00003774 const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003775 size_type __pos2,
3776 size_type __n2) const
3777{
Marshall Clow82513342016-09-24 22:45:42 +00003778 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003779 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3780}
3781
3782template <class _CharT, class _Traits, class _Allocator>
3783int
3784basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3785 size_type __n1,
3786 const basic_string& __str,
3787 size_type __pos2,
3788 size_type __n2) const
3789{
3790 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3791}
3792
3793template <class _CharT, class _Traits, class _Allocator>
3794int
3795basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3796{
3797 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3798 return compare(0, npos, __s, traits_type::length(__s));
3799}
3800
3801template <class _CharT, class _Traits, class _Allocator>
3802int
3803basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3804 size_type __n1,
3805 const value_type* __s) const
3806{
3807 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3808 return compare(__pos1, __n1, __s, traits_type::length(__s));
3809}
3810
Howard Hinnantc51e1022010-05-11 19:42:16 +00003811// __invariants
3812
3813template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003814inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003815bool
3816basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3817{
3818 if (size() > capacity())
3819 return false;
3820 if (capacity() < __min_cap - 1)
3821 return false;
3822 if (data() == 0)
3823 return false;
3824 if (data()[size()] != value_type(0))
3825 return false;
3826 return true;
3827}
3828
Vedant Kumar55e007e2018-03-08 21:15:26 +00003829// __clear_and_shrink
3830
3831template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003832inline
Louis Dionne173f29e2019-05-29 16:01:36 +00003833void
Marshall Clowe60a7182018-05-29 17:04:37 +00003834basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
Vedant Kumar55e007e2018-03-08 21:15:26 +00003835{
3836 clear();
3837 if(__is_long())
3838 {
3839 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
3840 __set_long_cap(0);
3841 __set_short_size(0);
3842 }
Louis Dionne173f29e2019-05-29 16:01:36 +00003843}
Vedant Kumar55e007e2018-03-08 21:15:26 +00003844
Howard Hinnantc51e1022010-05-11 19:42:16 +00003845// operator==
3846
3847template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003848inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003849bool
3850operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003851 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003852{
Howard Hinnantaaeb1132013-04-22 23:55:13 +00003853 size_t __lhs_sz = __lhs.size();
3854 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3855 __rhs.data(),
3856 __lhs_sz) == 0;
3857}
3858
3859template<class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003860inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaaeb1132013-04-22 23:55:13 +00003861bool
3862operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3863 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3864{
3865 size_t __lhs_sz = __lhs.size();
3866 if (__lhs_sz != __rhs.size())
3867 return false;
3868 const char* __lp = __lhs.data();
3869 const char* __rp = __rhs.data();
3870 if (__lhs.__is_long())
3871 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3872 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3873 if (*__lp != *__rp)
3874 return false;
3875 return true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003876}
3877
3878template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003879inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003880bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003881operator==(const _CharT* __lhs,
3882 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003883{
Eric Fiselier0cafa3f2015-08-28 03:02:37 +00003884 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3885 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3886 size_t __lhs_len = _Traits::length(__lhs);
3887 if (__lhs_len != __rhs.size()) return false;
3888 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003889}
3890
Howard Hinnantc51e1022010-05-11 19:42:16 +00003891template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003892inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003893bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003894operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3895 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003896{
Eric Fiselier0cafa3f2015-08-28 03:02:37 +00003897 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3898 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3899 size_t __rhs_len = _Traits::length(__rhs);
3900 if (__rhs_len != __lhs.size()) return false;
3901 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003902}
3903
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003904template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003905inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003906bool
3907operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003908 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003909{
3910 return !(__lhs == __rhs);
3911}
3912
3913template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003914inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003915bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003916operator!=(const _CharT* __lhs,
3917 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003918{
3919 return !(__lhs == __rhs);
3920}
3921
3922template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003923inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003924bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003925operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3926 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003927{
3928 return !(__lhs == __rhs);
3929}
3930
3931// operator<
3932
3933template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003934inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003935bool
3936operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003937 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003938{
Howard Hinnanta2660c12011-07-24 15:07:21 +00003939 return __lhs.compare(__rhs) < 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003940}
3941
3942template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003943inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003944bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003945operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3946 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003947{
Howard Hinnanta2660c12011-07-24 15:07:21 +00003948 return __lhs.compare(__rhs) < 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003949}
3950
3951template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003952inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003953bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003954operator< (const _CharT* __lhs,
3955 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003956{
3957 return __rhs.compare(__lhs) > 0;
3958}
3959
Howard Hinnantc51e1022010-05-11 19:42:16 +00003960// operator>
3961
3962template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003963inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003964bool
3965operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003966 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003967{
3968 return __rhs < __lhs;
3969}
3970
3971template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003972inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003973bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003974operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3975 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003976{
3977 return __rhs < __lhs;
3978}
3979
3980template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003981inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003982bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003983operator> (const _CharT* __lhs,
3984 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003985{
3986 return __rhs < __lhs;
3987}
3988
3989// operator<=
3990
3991template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003992inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003993bool
3994operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003995 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003996{
3997 return !(__rhs < __lhs);
3998}
3999
4000template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004001inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004002bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004003operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4004 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004005{
4006 return !(__rhs < __lhs);
4007}
4008
4009template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004010inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004011bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004012operator<=(const _CharT* __lhs,
4013 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004014{
4015 return !(__rhs < __lhs);
4016}
4017
4018// operator>=
4019
4020template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004021inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004022bool
4023operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004024 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004025{
4026 return !(__lhs < __rhs);
4027}
4028
4029template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004030inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004031bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004032operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4033 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004034{
4035 return !(__lhs < __rhs);
4036}
4037
4038template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004039inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004040bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004041operator>=(const _CharT* __lhs,
4042 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004043{
4044 return !(__lhs < __rhs);
4045}
4046
4047// operator +
4048
4049template<class _CharT, class _Traits, class _Allocator>
4050basic_string<_CharT, _Traits, _Allocator>
4051operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4052 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4053{
4054 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4055 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4056 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4057 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4058 __r.append(__rhs.data(), __rhs_sz);
4059 return __r;
4060}
4061
4062template<class _CharT, class _Traits, class _Allocator>
4063basic_string<_CharT, _Traits, _Allocator>
4064operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4065{
4066 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4067 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4068 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4069 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4070 __r.append(__rhs.data(), __rhs_sz);
4071 return __r;
4072}
4073
4074template<class _CharT, class _Traits, class _Allocator>
4075basic_string<_CharT, _Traits, _Allocator>
4076operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4077{
4078 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4079 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4080 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4081 __r.append(__rhs.data(), __rhs_sz);
4082 return __r;
4083}
4084
4085template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00004086inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004087basic_string<_CharT, _Traits, _Allocator>
4088operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4089{
4090 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4091 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4092 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4093 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4094 __r.append(__rhs, __rhs_sz);
4095 return __r;
4096}
4097
4098template<class _CharT, class _Traits, class _Allocator>
4099basic_string<_CharT, _Traits, _Allocator>
4100operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4101{
4102 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4103 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4104 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4105 __r.push_back(__rhs);
4106 return __r;
4107}
4108
Eric Fiselierfc92be82017-04-19 00:28:44 +00004109#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00004110
4111template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004112inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004113basic_string<_CharT, _Traits, _Allocator>
4114operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4115{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004116 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004117}
4118
4119template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004120inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004121basic_string<_CharT, _Traits, _Allocator>
4122operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4123{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004124 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004125}
4126
4127template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004128inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004129basic_string<_CharT, _Traits, _Allocator>
4130operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4131{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004132 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004133}
4134
4135template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004136inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004137basic_string<_CharT, _Traits, _Allocator>
4138operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4139{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004140 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004141}
4142
4143template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004144inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004145basic_string<_CharT, _Traits, _Allocator>
4146operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4147{
4148 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004149 return _VSTD::move(__rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004150}
4151
4152template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004153inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004154basic_string<_CharT, _Traits, _Allocator>
4155operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4156{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004157 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004158}
4159
4160template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004161inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004162basic_string<_CharT, _Traits, _Allocator>
4163operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4164{
4165 __lhs.push_back(__rhs);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004166 return _VSTD::move(__lhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004167}
4168
Eric Fiselierfc92be82017-04-19 00:28:44 +00004169#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00004170
4171// swap
4172
4173template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004174inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004175void
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004176swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant3e276872011-06-03 18:40:47 +00004177 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4178 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00004179{
4180 __lhs.swap(__rhs);
4181}
4182
Marshall Clow8732fed2018-12-11 04:35:44 +00004183#ifndef _LIBCPP_NO_HAS_CHAR8_T
4184typedef basic_string<char8_t> u8string;
4185#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00004186
Marshall Clow8732fed2018-12-11 04:35:44 +00004187#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004188typedef basic_string<char16_t> u16string;
4189typedef basic_string<char32_t> u32string;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004190#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004191
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004192_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4193_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4194_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4195_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4196_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004197
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004198_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4199_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4200_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004201
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004202_LIBCPP_FUNC_VIS string to_string(int __val);
4203_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4204_LIBCPP_FUNC_VIS string to_string(long __val);
4205_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4206_LIBCPP_FUNC_VIS string to_string(long long __val);
4207_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4208_LIBCPP_FUNC_VIS string to_string(float __val);
4209_LIBCPP_FUNC_VIS string to_string(double __val);
4210_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004211
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004212_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4213_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4214_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4215_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4216_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004217
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004218_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4219_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4220_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004221
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004222_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4223_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4224_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4225_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4226_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4227_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4228_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4229_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4230_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004231
Howard Hinnantc51e1022010-05-11 19:42:16 +00004232template<class _CharT, class _Traits, class _Allocator>
4233 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4234 basic_string<_CharT, _Traits, _Allocator>::npos;
4235
Marshall Clow851b9ec2019-05-20 21:56:51 +00004236template <class _CharT, class _Allocator>
4237struct _LIBCPP_TEMPLATE_VIS
4238 hash<basic_string<_CharT, char_traits<_CharT>, _Allocator> >
4239 : public unary_function<
4240 basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004241{
4242 size_t
Marshall Clow851b9ec2019-05-20 21:56:51 +00004243 operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT
4244 { return __do_string_hash(__val.data(), __val.data() + __val.size()); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00004245};
4246
Howard Hinnantc51e1022010-05-11 19:42:16 +00004247
Howard Hinnantdc095972011-07-18 15:51:59 +00004248template<class _CharT, class _Traits, class _Allocator>
4249basic_ostream<_CharT, _Traits>&
4250operator<<(basic_ostream<_CharT, _Traits>& __os,
4251 const basic_string<_CharT, _Traits, _Allocator>& __str);
4252
4253template<class _CharT, class _Traits, class _Allocator>
4254basic_istream<_CharT, _Traits>&
4255operator>>(basic_istream<_CharT, _Traits>& __is,
4256 basic_string<_CharT, _Traits, _Allocator>& __str);
4257
4258template<class _CharT, class _Traits, class _Allocator>
4259basic_istream<_CharT, _Traits>&
4260getline(basic_istream<_CharT, _Traits>& __is,
4261 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4262
4263template<class _CharT, class _Traits, class _Allocator>
4264inline _LIBCPP_INLINE_VISIBILITY
4265basic_istream<_CharT, _Traits>&
4266getline(basic_istream<_CharT, _Traits>& __is,
4267 basic_string<_CharT, _Traits, _Allocator>& __str);
4268
Eric Fiselierfc92be82017-04-19 00:28:44 +00004269#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantdc095972011-07-18 15:51:59 +00004270
4271template<class _CharT, class _Traits, class _Allocator>
4272inline _LIBCPP_INLINE_VISIBILITY
4273basic_istream<_CharT, _Traits>&
4274getline(basic_istream<_CharT, _Traits>&& __is,
4275 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4276
4277template<class _CharT, class _Traits, class _Allocator>
4278inline _LIBCPP_INLINE_VISIBILITY
4279basic_istream<_CharT, _Traits>&
4280getline(basic_istream<_CharT, _Traits>&& __is,
4281 basic_string<_CharT, _Traits, _Allocator>& __str);
4282
Eric Fiselierfc92be82017-04-19 00:28:44 +00004283#endif // _LIBCPP_CXX03_LANG
Howard Hinnantdc095972011-07-18 15:51:59 +00004284
Marshall Clow29b53f22018-12-14 18:49:35 +00004285#if _LIBCPP_STD_VER > 17
4286template<class _CharT, class _Traits, class _Allocator, class _Up>
4287inline _LIBCPP_INLINE_VISIBILITY
4288void erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v)
4289{ __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end()); }
4290
4291template<class _CharT, class _Traits, class _Allocator, class _Predicate>
4292inline _LIBCPP_INLINE_VISIBILITY
4293void erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, _Predicate __pred)
4294{ __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred), __str.end()); }
4295#endif
4296
Howard Hinnant8ea98242013-08-23 17:37:05 +00004297#if _LIBCPP_DEBUG_LEVEL >= 2
4298
4299template<class _CharT, class _Traits, class _Allocator>
4300bool
4301basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4302{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004303 return this->data() <= _VSTD::__to_address(__i->base()) &&
4304 _VSTD::__to_address(__i->base()) < this->data() + this->size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004305}
4306
4307template<class _CharT, class _Traits, class _Allocator>
4308bool
4309basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4310{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004311 return this->data() < _VSTD::__to_address(__i->base()) &&
4312 _VSTD::__to_address(__i->base()) <= this->data() + this->size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004313}
4314
4315template<class _CharT, class _Traits, class _Allocator>
4316bool
4317basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4318{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004319 const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
Howard Hinnant8ea98242013-08-23 17:37:05 +00004320 return this->data() <= __p && __p <= this->data() + this->size();
4321}
4322
4323template<class _CharT, class _Traits, class _Allocator>
4324bool
4325basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4326{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004327 const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
Howard Hinnant8ea98242013-08-23 17:37:05 +00004328 return this->data() <= __p && __p < this->data() + this->size();
4329}
4330
4331#endif // _LIBCPP_DEBUG_LEVEL >= 2
4332
Oliver Stannard998c5a02020-01-13 13:54:04 +00004333_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
4334_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Shoaib Meenai6eb5f112017-06-29 02:52:46 +00004335
Louis Dionne173f29e2019-05-29 16:01:36 +00004336#if _LIBCPP_STD_VER > 11
Marshall Clowcba751f2013-07-23 17:05:24 +00004337// Literal suffixes for basic_string [basic.string.literals]
Marshall Clowac868372013-10-05 21:18:32 +00004338inline namespace literals
Marshall Clowcba751f2013-07-23 17:05:24 +00004339{
4340 inline namespace string_literals
4341 {
Howard Hinnant5c167562013-08-07 19:39:48 +00004342 inline _LIBCPP_INLINE_VISIBILITY
4343 basic_string<char> operator "" s( const char *__str, size_t __len )
4344 {
4345 return basic_string<char> (__str, __len);
4346 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004347
Howard Hinnant5c167562013-08-07 19:39:48 +00004348 inline _LIBCPP_INLINE_VISIBILITY
4349 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4350 {
4351 return basic_string<wchar_t> (__str, __len);
4352 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004353
Marshall Clow8732fed2018-12-11 04:35:44 +00004354#ifndef _LIBCPP_NO_HAS_CHAR8_T
4355 inline _LIBCPP_INLINE_VISIBILITY
4356 basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPT
4357 {
4358 return basic_string<char8_t> (__str, __len);
4359 }
4360#endif
4361
Howard Hinnant5c167562013-08-07 19:39:48 +00004362 inline _LIBCPP_INLINE_VISIBILITY
4363 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4364 {
4365 return basic_string<char16_t> (__str, __len);
4366 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004367
Howard Hinnant5c167562013-08-07 19:39:48 +00004368 inline _LIBCPP_INLINE_VISIBILITY
4369 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4370 {
4371 return basic_string<char32_t> (__str, __len);
4372 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004373 }
4374}
4375#endif
4376
Howard Hinnantc51e1022010-05-11 19:42:16 +00004377_LIBCPP_END_NAMESPACE_STD
4378
Eric Fiselierf4433a32017-05-31 22:07:49 +00004379_LIBCPP_POP_MACROS
4380
Howard Hinnantc51e1022010-05-11 19:42:16 +00004381#endif // _LIBCPP_STRING