blob: 4e0b21135a7e69144af15b5e703df00f751d4303 [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
817 basic_string(const _CharT* __s) {
818 _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)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001724{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001725#if _LIBCPP_DEBUG_LEVEL >= 2
1726 __get_db()->__insert_c(this);
1727#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001728 __zero();
1729}
1730
1731template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001732inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001733basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiseliere012bf22015-07-18 20:40:46 +00001734#if _LIBCPP_STD_VER <= 14
1735 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1736#else
1737 _NOEXCEPT
1738#endif
Eric Fiselier9d355982017-04-12 23:45:53 +00001739: __r_(__second_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001740{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001741#if _LIBCPP_DEBUG_LEVEL >= 2
1742 __get_db()->__insert_c(this);
1743#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001744 __zero();
1745}
1746
1747template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier815ed732016-09-16 00:00:48 +00001748void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1749 size_type __sz,
1750 size_type __reserve)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001751{
1752 if (__reserve > max_size())
1753 this->__throw_length_error();
1754 pointer __p;
1755 if (__reserve < __min_cap)
1756 {
1757 __set_short_size(__sz);
1758 __p = __get_short_pointer();
1759 }
1760 else
1761 {
1762 size_type __cap = __recommend(__reserve);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001763 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001764 __set_long_pointer(__p);
1765 __set_long_cap(__cap+1);
1766 __set_long_size(__sz);
1767 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001768 traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001769 traits_type::assign(__p[__sz], value_type());
1770}
1771
1772template <class _CharT, class _Traits, class _Allocator>
1773void
Howard Hinnantd17880b2013-06-28 16:59:19 +00001774basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001775{
1776 if (__sz > max_size())
1777 this->__throw_length_error();
1778 pointer __p;
1779 if (__sz < __min_cap)
1780 {
1781 __set_short_size(__sz);
1782 __p = __get_short_pointer();
1783 }
1784 else
1785 {
1786 size_type __cap = __recommend(__sz);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001787 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001788 __set_long_pointer(__p);
1789 __set_long_cap(__cap+1);
1790 __set_long_size(__sz);
1791 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001792 traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001793 traits_type::assign(__p[__sz], value_type());
1794}
1795
1796template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00001797template <class>
Eric Fiselier812882b2017-02-17 01:17:10 +00001798basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
Eric Fiselier9d355982017-04-12 23:45:53 +00001799 : __r_(__second_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001800{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001801 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001802 __init(__s, traits_type::length(__s));
Howard Hinnant8ea98242013-08-23 17:37:05 +00001803#if _LIBCPP_DEBUG_LEVEL >= 2
1804 __get_db()->__insert_c(this);
1805#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001806}
1807
1808template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001809inline
Eric Fiselier812882b2017-02-17 01:17:10 +00001810basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001811{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001812 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001813 __init(__s, __n);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001814#if _LIBCPP_DEBUG_LEVEL >= 2
1815 __get_db()->__insert_c(this);
1816#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001817}
1818
1819template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001820inline
Eric Fiselier812882b2017-02-17 01:17:10 +00001821basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
Eric Fiselier9d355982017-04-12 23:45:53 +00001822 : __r_(__second_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001823{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001824 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001825 __init(__s, __n);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001826#if _LIBCPP_DEBUG_LEVEL >= 2
1827 __get_db()->__insert_c(this);
1828#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001829}
1830
1831template <class _CharT, class _Traits, class _Allocator>
1832basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselier9d355982017-04-12 23:45:53 +00001833 : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001834{
1835 if (!__str.__is_long())
1836 __r_.first().__r = __str.__r_.first().__r;
1837 else
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001838 __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant8ea98242013-08-23 17:37:05 +00001839#if _LIBCPP_DEBUG_LEVEL >= 2
1840 __get_db()->__insert_c(this);
1841#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001842}
1843
1844template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier812882b2017-02-17 01:17:10 +00001845basic_string<_CharT, _Traits, _Allocator>::basic_string(
1846 const basic_string& __str, const allocator_type& __a)
Eric Fiselier9d355982017-04-12 23:45:53 +00001847 : __r_(__second_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001848{
1849 if (!__str.__is_long())
1850 __r_.first().__r = __str.__r_.first().__r;
1851 else
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001852 __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant8ea98242013-08-23 17:37:05 +00001853#if _LIBCPP_DEBUG_LEVEL >= 2
1854 __get_db()->__insert_c(this);
1855#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001856}
1857
Eric Fiselierfc92be82017-04-19 00:28:44 +00001858#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001859
1860template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001861inline
Howard Hinnant3e276872011-06-03 18:40:47 +00001862basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clowa80abc72015-06-03 19:56:43 +00001863#if _LIBCPP_STD_VER <= 14
Howard Hinnant3e276872011-06-03 18:40:47 +00001864 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clowa80abc72015-06-03 19:56:43 +00001865#else
1866 _NOEXCEPT
1867#endif
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001868 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001869{
1870 __str.__zero();
Howard Hinnant8ea98242013-08-23 17:37:05 +00001871#if _LIBCPP_DEBUG_LEVEL >= 2
1872 __get_db()->__insert_c(this);
1873 if (__is_long())
1874 __get_db()->swap(this, &__str);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001875#endif
1876}
1877
1878template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001879inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001880basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Eric Fiselier9d355982017-04-12 23:45:53 +00001881 : __r_(__second_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001882{
Marshall Clowd2d24692014-07-17 15:32:20 +00001883 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001884 __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd2d24692014-07-17 15:32:20 +00001885 else
1886 {
1887 __r_.first().__r = __str.__r_.first().__r;
1888 __str.__zero();
1889 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001890#if _LIBCPP_DEBUG_LEVEL >= 2
1891 __get_db()->__insert_c(this);
1892 if (__is_long())
1893 __get_db()->swap(this, &__str);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001894#endif
1895}
1896
Eric Fiselierfc92be82017-04-19 00:28:44 +00001897#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001898
1899template <class _CharT, class _Traits, class _Allocator>
1900void
1901basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1902{
1903 if (__n > max_size())
1904 this->__throw_length_error();
1905 pointer __p;
1906 if (__n < __min_cap)
1907 {
1908 __set_short_size(__n);
1909 __p = __get_short_pointer();
1910 }
1911 else
1912 {
1913 size_type __cap = __recommend(__n);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001914 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001915 __set_long_pointer(__p);
1916 __set_long_cap(__cap+1);
1917 __set_long_size(__n);
1918 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001919 traits_type::assign(_VSTD::__to_address(__p), __n, __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001920 traits_type::assign(__p[__n], value_type());
1921}
1922
1923template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001924inline
Eric Fiselier812882b2017-02-17 01:17:10 +00001925basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001926{
1927 __init(__n, __c);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001928#if _LIBCPP_DEBUG_LEVEL >= 2
1929 __get_db()->__insert_c(this);
1930#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001931}
1932
1933template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00001934template <class>
Eric Fiselier812882b2017-02-17 01:17:10 +00001935basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselier9d355982017-04-12 23:45:53 +00001936 : __r_(__second_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001937{
1938 __init(__n, __c);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001939#if _LIBCPP_DEBUG_LEVEL >= 2
1940 __get_db()->__insert_c(this);
1941#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001942}
1943
Howard Hinnantc51e1022010-05-11 19:42:16 +00001944template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier812882b2017-02-17 01:17:10 +00001945basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1946 size_type __pos, size_type __n,
1947 const _Allocator& __a)
Eric Fiselier9d355982017-04-12 23:45:53 +00001948 : __r_(__second_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001949{
1950 size_type __str_sz = __str.size();
1951 if (__pos > __str_sz)
1952 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001953 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant8ea98242013-08-23 17:37:05 +00001954#if _LIBCPP_DEBUG_LEVEL >= 2
1955 __get_db()->__insert_c(this);
1956#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001957}
1958
1959template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001960inline
Marshall Clow83445802016-04-07 18:13:41 +00001961basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier812882b2017-02-17 01:17:10 +00001962 const _Allocator& __a)
Eric Fiselier9d355982017-04-12 23:45:53 +00001963 : __r_(__second_tag(), __a)
Marshall Clow83445802016-04-07 18:13:41 +00001964{
1965 size_type __str_sz = __str.size();
1966 if (__pos > __str_sz)
1967 this->__throw_out_of_range();
1968 __init(__str.data() + __pos, __str_sz - __pos);
1969#if _LIBCPP_DEBUG_LEVEL >= 2
1970 __get_db()->__insert_c(this);
1971#endif
1972}
1973
1974template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00001975template <class _Tp, class>
Marshall Clow78dbe462016-11-14 18:22:19 +00001976basic_string<_CharT, _Traits, _Allocator>::basic_string(
Marshall Clowe46031a2018-07-02 18:41:15 +00001977 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
Eric Fiselier9d355982017-04-12 23:45:53 +00001978 : __r_(__second_tag(), __a)
Marshall Clow78dbe462016-11-14 18:22:19 +00001979{
Marshall Clowe46031a2018-07-02 18:41:15 +00001980 __self_view __sv0 = __t;
1981 __self_view __sv = __sv0.substr(__pos, __n);
Marshall Clow78dbe462016-11-14 18:22:19 +00001982 __init(__sv.data(), __sv.size());
1983#if _LIBCPP_DEBUG_LEVEL >= 2
1984 __get_db()->__insert_c(this);
Eric Fiselier812882b2017-02-17 01:17:10 +00001985#endif
Marshall Clow78dbe462016-11-14 18:22:19 +00001986}
1987
1988template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00001989template <class _Tp, class>
1990basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001991{
Marshall Clowe46031a2018-07-02 18:41:15 +00001992 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001993 __init(__sv.data(), __sv.size());
1994#if _LIBCPP_DEBUG_LEVEL >= 2
1995 __get_db()->__insert_c(this);
1996#endif
1997}
1998
1999template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002000template <class _Tp, class>
2001basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
Eric Fiselier9d355982017-04-12 23:45:53 +00002002 : __r_(__second_tag(), __a)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002003{
Marshall Clowe46031a2018-07-02 18:41:15 +00002004 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002005 __init(__sv.data(), __sv.size());
2006#if _LIBCPP_DEBUG_LEVEL >= 2
2007 __get_db()->__insert_c(this);
2008#endif
2009}
2010
2011template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002012template <class _InputIterator>
2013typename enable_if
2014<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002015 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002016 void
2017>::type
2018basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2019{
2020 __zero();
2021#ifndef _LIBCPP_NO_EXCEPTIONS
2022 try
2023 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002024#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002025 for (; __first != __last; ++__first)
2026 push_back(*__first);
2027#ifndef _LIBCPP_NO_EXCEPTIONS
2028 }
2029 catch (...)
2030 {
2031 if (__is_long())
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002032 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002033 throw;
2034 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002035#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002036}
2037
2038template <class _CharT, class _Traits, class _Allocator>
2039template <class _ForwardIterator>
2040typename enable_if
2041<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002042 __is_cpp17_forward_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002043 void
2044>::type
2045basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2046{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002047 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002048 if (__sz > max_size())
2049 this->__throw_length_error();
2050 pointer __p;
2051 if (__sz < __min_cap)
2052 {
2053 __set_short_size(__sz);
2054 __p = __get_short_pointer();
2055 }
2056 else
2057 {
2058 size_type __cap = __recommend(__sz);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002059 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002060 __set_long_pointer(__p);
2061 __set_long_cap(__cap+1);
2062 __set_long_size(__sz);
2063 }
Eric Fiseliera09a3b42014-10-27 19:28:20 +00002064 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002065 traits_type::assign(*__p, *__first);
2066 traits_type::assign(*__p, value_type());
2067}
2068
2069template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierc0f566d2019-03-14 12:31:10 +00002070template<class _InputIterator, class>
Eric Fiselierbea70602018-11-26 22:51:35 +00002071inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002072basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2073{
2074 __init(__first, __last);
Howard Hinnant8ea98242013-08-23 17:37:05 +00002075#if _LIBCPP_DEBUG_LEVEL >= 2
2076 __get_db()->__insert_c(this);
2077#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002078}
2079
2080template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierc0f566d2019-03-14 12:31:10 +00002081template<class _InputIterator, class>
Eric Fiselierbea70602018-11-26 22:51:35 +00002082inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002083basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2084 const allocator_type& __a)
Eric Fiselier9d355982017-04-12 23:45:53 +00002085 : __r_(__second_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002086{
2087 __init(__first, __last);
Howard Hinnant8ea98242013-08-23 17:37:05 +00002088#if _LIBCPP_DEBUG_LEVEL >= 2
2089 __get_db()->__insert_c(this);
2090#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002091}
2092
Eric Fiselierfc92be82017-04-19 00:28:44 +00002093#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant33711792011-08-12 21:56:02 +00002094
Howard Hinnantc51e1022010-05-11 19:42:16 +00002095template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002096inline
Eric Fiselier812882b2017-02-17 01:17:10 +00002097basic_string<_CharT, _Traits, _Allocator>::basic_string(
2098 initializer_list<_CharT> __il)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002099{
2100 __init(__il.begin(), __il.end());
Howard Hinnant8ea98242013-08-23 17:37:05 +00002101#if _LIBCPP_DEBUG_LEVEL >= 2
2102 __get_db()->__insert_c(this);
2103#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002104}
2105
2106template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002107inline
Eric Fiselier9d355982017-04-12 23:45:53 +00002108
Eric Fiselier812882b2017-02-17 01:17:10 +00002109basic_string<_CharT, _Traits, _Allocator>::basic_string(
2110 initializer_list<_CharT> __il, const _Allocator& __a)
Eric Fiselier9d355982017-04-12 23:45:53 +00002111 : __r_(__second_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002112{
2113 __init(__il.begin(), __il.end());
Howard Hinnant8ea98242013-08-23 17:37:05 +00002114#if _LIBCPP_DEBUG_LEVEL >= 2
2115 __get_db()->__insert_c(this);
2116#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002117}
2118
Eric Fiselierfc92be82017-04-19 00:28:44 +00002119#endif // _LIBCPP_CXX03_LANG
Howard Hinnant33711792011-08-12 21:56:02 +00002120
Howard Hinnantc51e1022010-05-11 19:42:16 +00002121template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002122basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2123{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002124#if _LIBCPP_DEBUG_LEVEL >= 2
2125 __get_db()->__erase_c(this);
2126#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002127 if (__is_long())
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002128 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002129}
2130
2131template <class _CharT, class _Traits, class _Allocator>
2132void
2133basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2134 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnantd17880b2013-06-28 16:59:19 +00002135 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 +00002136{
2137 size_type __ms = max_size();
2138 if (__delta_cap > __ms - __old_cap - 1)
2139 this->__throw_length_error();
2140 pointer __old_p = __get_pointer();
2141 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002142 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantc51e1022010-05-11 19:42:16 +00002143 __ms - 1;
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002144 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002145 __invalidate_all_iterators();
2146 if (__n_copy != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002147 traits_type::copy(_VSTD::__to_address(__p),
2148 _VSTD::__to_address(__old_p), __n_copy);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002149 if (__n_add != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002150 traits_type::copy(_VSTD::__to_address(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002151 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2152 if (__sec_cp_sz != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002153 traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2154 _VSTD::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002155 if (__old_cap+1 != __min_cap)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002156 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002157 __set_long_pointer(__p);
2158 __set_long_cap(__cap+1);
2159 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2160 __set_long_size(__old_sz);
2161 traits_type::assign(__p[__old_sz], value_type());
2162}
2163
2164template <class _CharT, class _Traits, class _Allocator>
2165void
2166basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2167 size_type __n_copy, size_type __n_del, size_type __n_add)
2168{
2169 size_type __ms = max_size();
Marshall Clow2267c5d2013-11-06 14:24:38 +00002170 if (__delta_cap > __ms - __old_cap)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002171 this->__throw_length_error();
2172 pointer __old_p = __get_pointer();
2173 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002174 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantc51e1022010-05-11 19:42:16 +00002175 __ms - 1;
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002176 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002177 __invalidate_all_iterators();
2178 if (__n_copy != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002179 traits_type::copy(_VSTD::__to_address(__p),
2180 _VSTD::__to_address(__old_p), __n_copy);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002181 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2182 if (__sec_cp_sz != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002183 traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2184 _VSTD::__to_address(__old_p) + __n_copy + __n_del,
Howard Hinnantd17880b2013-06-28 16:59:19 +00002185 __sec_cp_sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002186 if (__old_cap+1 != __min_cap)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002187 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002188 __set_long_pointer(__p);
2189 __set_long_cap(__cap+1);
2190}
2191
2192// assign
2193
2194template <class _CharT, class _Traits, class _Allocator>
2195basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002196basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002197{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002198 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002199 size_type __cap = capacity();
2200 if (__cap >= __n)
2201 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002202 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002203 traits_type::move(__p, __s, __n);
2204 traits_type::assign(__p[__n], value_type());
2205 __set_size(__n);
2206 __invalidate_iterators_past(__n);
2207 }
2208 else
2209 {
2210 size_type __sz = size();
2211 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2212 }
2213 return *this;
2214}
2215
2216template <class _CharT, class _Traits, class _Allocator>
2217basic_string<_CharT, _Traits, _Allocator>&
2218basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2219{
2220 size_type __cap = capacity();
2221 if (__cap < __n)
2222 {
2223 size_type __sz = size();
2224 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2225 }
2226 else
2227 __invalidate_iterators_past(__n);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002228 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002229 traits_type::assign(__p, __n, __c);
2230 traits_type::assign(__p[__n], value_type());
2231 __set_size(__n);
2232 return *this;
2233}
2234
2235template <class _CharT, class _Traits, class _Allocator>
2236basic_string<_CharT, _Traits, _Allocator>&
2237basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2238{
2239 pointer __p;
2240 if (__is_long())
2241 {
2242 __p = __get_long_pointer();
2243 __set_long_size(1);
2244 }
2245 else
2246 {
2247 __p = __get_short_pointer();
2248 __set_short_size(1);
2249 }
2250 traits_type::assign(*__p, __c);
2251 traits_type::assign(*++__p, value_type());
2252 __invalidate_iterators_past(1);
2253 return *this;
2254}
2255
2256template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002257basic_string<_CharT, _Traits, _Allocator>&
2258basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2259{
2260 if (this != &__str)
2261 {
2262 __copy_assign_alloc(__str);
Eric Fiselierbac2d652019-10-09 03:07:02 +00002263 return assign(__str.data(), __str.size());
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002264 }
2265 return *this;
2266}
2267
Eric Fiselierfc92be82017-04-19 00:28:44 +00002268#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002269
2270template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002271inline
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002272void
2273basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002274 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002275{
2276 if (__alloc() != __str.__alloc())
2277 assign(__str);
2278 else
2279 __move_assign(__str, true_type());
2280}
2281
2282template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002283inline
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002284void
2285basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002286#if _LIBCPP_STD_VER > 14
2287 _NOEXCEPT
2288#else
Howard Hinnant3e276872011-06-03 18:40:47 +00002289 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002290#endif
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002291{
marshall2ed41622019-11-27 07:13:00 -08002292 if (__is_long()) {
2293 __alloc_traits::deallocate(__alloc(), __get_long_pointer(),
2294 __get_long_cap());
2295#if _LIBCPP_STD_VER <= 14
2296 if (!is_nothrow_move_assignable<allocator_type>::value) {
2297 __set_short_size(0);
2298 traits_type::assign(__get_short_pointer()[0], value_type());
2299 }
2300#endif
2301 }
2302 __move_assign_alloc(__str);
2303 __r_.first() = __str.__r_.first();
2304 __str.__set_short_size(0);
2305 traits_type::assign(__str.__get_short_pointer()[0], value_type());
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002306}
2307
2308template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002309inline
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002310basic_string<_CharT, _Traits, _Allocator>&
2311basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002312 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002313{
2314 __move_assign(__str, integral_constant<bool,
2315 __alloc_traits::propagate_on_container_move_assignment::value>());
2316 return *this;
2317}
2318
2319#endif
2320
2321template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002322template<class _InputIterator>
2323typename enable_if
2324<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002325 __is_exactly_cpp17_input_iterator <_InputIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002326 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002327 basic_string<_CharT, _Traits, _Allocator>&
2328>::type
2329basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2330{
Marshall Clow958362f2016-09-05 01:54:30 +00002331 const basic_string __temp(__first, __last, __alloc());
Marshall Clow039b2f02016-01-13 21:54:34 +00002332 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002333 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002334}
2335
2336template <class _CharT, class _Traits, class _Allocator>
2337template<class _ForwardIterator>
2338typename enable_if
2339<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002340 __is_cpp17_forward_iterator<_ForwardIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002341 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002342 basic_string<_CharT, _Traits, _Allocator>&
2343>::type
2344basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2345{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002346 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002347 size_type __cap = capacity();
2348 if (__cap < __n)
2349 {
2350 size_type __sz = size();
2351 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2352 }
2353 else
2354 __invalidate_iterators_past(__n);
2355 pointer __p = __get_pointer();
2356 for (; __first != __last; ++__first, ++__p)
2357 traits_type::assign(*__p, *__first);
2358 traits_type::assign(*__p, value_type());
2359 __set_size(__n);
2360 return *this;
2361}
2362
2363template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002364basic_string<_CharT, _Traits, _Allocator>&
2365basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2366{
2367 size_type __sz = __str.size();
2368 if (__pos > __sz)
2369 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002370 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002371}
2372
2373template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00002374template <class _Tp>
2375typename enable_if
2376<
2377 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00002378 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow82513342016-09-24 22:45:42 +00002379>::type
2380basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002381{
Marshall Clow82513342016-09-24 22:45:42 +00002382 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002383 size_type __sz = __sv.size();
2384 if (__pos > __sz)
2385 this->__throw_out_of_range();
2386 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2387}
2388
2389
2390template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002391basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002392basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002393{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002394 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002395 return assign(__s, traits_type::length(__s));
2396}
2397
2398// append
2399
2400template <class _CharT, class _Traits, class _Allocator>
2401basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002402basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002403{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002404 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002405 size_type __cap = capacity();
2406 size_type __sz = size();
2407 if (__cap - __sz >= __n)
2408 {
2409 if (__n)
2410 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002411 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002412 traits_type::copy(__p + __sz, __s, __n);
2413 __sz += __n;
2414 __set_size(__sz);
2415 traits_type::assign(__p[__sz], value_type());
2416 }
2417 }
2418 else
2419 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2420 return *this;
2421}
2422
2423template <class _CharT, class _Traits, class _Allocator>
2424basic_string<_CharT, _Traits, _Allocator>&
2425basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2426{
2427 if (__n)
2428 {
2429 size_type __cap = capacity();
2430 size_type __sz = size();
2431 if (__cap - __sz < __n)
2432 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2433 pointer __p = __get_pointer();
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002434 traits_type::assign(_VSTD::__to_address(__p) + __sz, __n, __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002435 __sz += __n;
2436 __set_size(__sz);
2437 traits_type::assign(__p[__sz], value_type());
2438 }
2439 return *this;
2440}
2441
2442template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier451d5582018-11-26 20:15:38 +00002443inline void
2444basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
2445{
2446 if (__n)
2447 {
2448 size_type __cap = capacity();
2449 size_type __sz = size();
2450 if (__cap - __sz < __n)
2451 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2452 pointer __p = __get_pointer();
2453 __sz += __n;
2454 __set_size(__sz);
2455 traits_type::assign(__p[__sz], value_type());
2456 }
2457}
2458
2459template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002460void
2461basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2462{
Howard Hinnant68bf1812013-04-30 21:44:48 +00002463 bool __is_short = !__is_long();
2464 size_type __cap;
2465 size_type __sz;
2466 if (__is_short)
2467 {
2468 __cap = __min_cap - 1;
2469 __sz = __get_short_size();
2470 }
2471 else
2472 {
2473 __cap = __get_long_cap() - 1;
2474 __sz = __get_long_size();
2475 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002476 if (__sz == __cap)
Howard Hinnant68bf1812013-04-30 21:44:48 +00002477 {
Howard Hinnantc51e1022010-05-11 19:42:16 +00002478 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant68bf1812013-04-30 21:44:48 +00002479 __is_short = !__is_long();
2480 }
2481 pointer __p;
2482 if (__is_short)
2483 {
2484 __p = __get_short_pointer() + __sz;
2485 __set_short_size(__sz+1);
2486 }
2487 else
2488 {
2489 __p = __get_long_pointer() + __sz;
2490 __set_long_size(__sz+1);
2491 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002492 traits_type::assign(*__p, __c);
2493 traits_type::assign(*++__p, value_type());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002494}
2495
Marshall Clow6ebbf662016-09-07 03:32:06 +00002496template <class _Tp>
Marshall Clow958362f2016-09-05 01:54:30 +00002497bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2498{
2499 return __first <= __p && __p < __last;
2500}
2501
Marshall Clow6ebbf662016-09-07 03:32:06 +00002502template <class _Tp1, class _Tp2>
Eric Fiselier6003c772016-12-23 23:37:52 +00002503bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
Marshall Clow6ebbf662016-09-07 03:32:06 +00002504{
2505 return false;
2506}
2507
Howard Hinnantc51e1022010-05-11 19:42:16 +00002508template <class _CharT, class _Traits, class _Allocator>
2509template<class _ForwardIterator>
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00002510basic_string<_CharT, _Traits, _Allocator>&
2511basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2512 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002513{
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002514 static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00002515 "function requires a ForwardIterator");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002516 size_type __sz = size();
2517 size_type __cap = capacity();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002518 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002519 if (__n)
2520 {
Eric Fiselier96866b52017-04-15 06:49:02 +00002521 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2522 _CharRef __tmp_ref = *__first;
2523 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
Marshall Clow958362f2016-09-05 01:54:30 +00002524 {
2525 const basic_string __temp (__first, __last, __alloc());
2526 append(__temp.data(), __temp.size());
2527 }
Louis Dionne173f29e2019-05-29 16:01:36 +00002528 else
Marshall Clow958362f2016-09-05 01:54:30 +00002529 {
2530 if (__cap - __sz < __n)
2531 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2532 pointer __p = __get_pointer() + __sz;
2533 for (; __first != __last; ++__p, ++__first)
2534 traits_type::assign(*__p, *__first);
2535 traits_type::assign(*__p, value_type());
2536 __set_size(__sz + __n);
2537 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002538 }
2539 return *this;
2540}
2541
2542template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002543inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002544basic_string<_CharT, _Traits, _Allocator>&
2545basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2546{
2547 return append(__str.data(), __str.size());
2548}
2549
2550template <class _CharT, class _Traits, class _Allocator>
2551basic_string<_CharT, _Traits, _Allocator>&
2552basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2553{
2554 size_type __sz = __str.size();
2555 if (__pos > __sz)
2556 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002557 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002558}
2559
2560template <class _CharT, class _Traits, class _Allocator>
Marshall Clow62953962016-10-03 23:40:48 +00002561template <class _Tp>
Marshall Clow82513342016-09-24 22:45:42 +00002562 typename enable_if
2563 <
2564 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2565 basic_string<_CharT, _Traits, _Allocator>&
2566 >::type
2567basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002568{
Marshall Clow82513342016-09-24 22:45:42 +00002569 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002570 size_type __sz = __sv.size();
2571 if (__pos > __sz)
2572 this->__throw_out_of_range();
2573 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2574}
2575
2576template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002577basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002578basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002579{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002580 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002581 return append(__s, traits_type::length(__s));
2582}
2583
2584// insert
2585
2586template <class _CharT, class _Traits, class _Allocator>
2587basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002588basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002589{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002590 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002591 size_type __sz = size();
2592 if (__pos > __sz)
2593 this->__throw_out_of_range();
2594 size_type __cap = capacity();
2595 if (__cap - __sz >= __n)
2596 {
2597 if (__n)
2598 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002599 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002600 size_type __n_move = __sz - __pos;
2601 if (__n_move != 0)
2602 {
2603 if (__p + __pos <= __s && __s < __p + __sz)
2604 __s += __n;
2605 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2606 }
2607 traits_type::move(__p + __pos, __s, __n);
2608 __sz += __n;
2609 __set_size(__sz);
2610 traits_type::assign(__p[__sz], value_type());
2611 }
2612 }
2613 else
2614 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2615 return *this;
2616}
2617
2618template <class _CharT, class _Traits, class _Allocator>
2619basic_string<_CharT, _Traits, _Allocator>&
2620basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2621{
2622 size_type __sz = size();
2623 if (__pos > __sz)
2624 this->__throw_out_of_range();
2625 if (__n)
2626 {
2627 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002628 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002629 if (__cap - __sz >= __n)
2630 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002631 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002632 size_type __n_move = __sz - __pos;
2633 if (__n_move != 0)
2634 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2635 }
2636 else
2637 {
2638 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002639 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002640 }
2641 traits_type::assign(__p + __pos, __n, __c);
2642 __sz += __n;
2643 __set_size(__sz);
2644 traits_type::assign(__p[__sz], value_type());
2645 }
2646 return *this;
2647}
2648
2649template <class _CharT, class _Traits, class _Allocator>
2650template<class _InputIterator>
2651typename enable_if
2652<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002653 __is_exactly_cpp17_input_iterator<_InputIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002654 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2655 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00002656>::type
2657basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2658{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002659#if _LIBCPP_DEBUG_LEVEL >= 2
2660 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2661 "string::insert(iterator, range) called with an iterator not"
2662 " referring to this string");
2663#endif
Marshall Clow958362f2016-09-05 01:54:30 +00002664 const basic_string __temp(__first, __last, __alloc());
Marshall Clow039b2f02016-01-13 21:54:34 +00002665 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002666}
2667
2668template <class _CharT, class _Traits, class _Allocator>
2669template<class _ForwardIterator>
2670typename enable_if
2671<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002672 __is_cpp17_forward_iterator<_ForwardIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002673 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002674 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2675>::type
2676basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2677{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002678#if _LIBCPP_DEBUG_LEVEL >= 2
2679 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2680 "string::insert(iterator, range) called with an iterator not"
2681 " referring to this string");
2682#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002683 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002684 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002685 if (__n)
2686 {
Eric Fiselier96866b52017-04-15 06:49:02 +00002687 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2688 _CharRef __tmp_char = *__first;
2689 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
Marshall Clow958362f2016-09-05 01:54:30 +00002690 {
2691 const basic_string __temp(__first, __last, __alloc());
2692 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2693 }
2694
2695 size_type __sz = size();
2696 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002697 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002698 if (__cap - __sz >= __n)
2699 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002700 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002701 size_type __n_move = __sz - __ip;
2702 if (__n_move != 0)
2703 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2704 }
2705 else
2706 {
2707 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002708 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002709 }
2710 __sz += __n;
2711 __set_size(__sz);
2712 traits_type::assign(__p[__sz], value_type());
2713 for (__p += __ip; __first != __last; ++__p, ++__first)
2714 traits_type::assign(*__p, *__first);
2715 }
2716 return begin() + __ip;
2717}
2718
2719template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002720inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002721basic_string<_CharT, _Traits, _Allocator>&
2722basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2723{
2724 return insert(__pos1, __str.data(), __str.size());
2725}
2726
2727template <class _CharT, class _Traits, class _Allocator>
2728basic_string<_CharT, _Traits, _Allocator>&
2729basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2730 size_type __pos2, size_type __n)
2731{
2732 size_type __str_sz = __str.size();
2733 if (__pos2 > __str_sz)
2734 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002735 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002736}
2737
2738template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00002739template <class _Tp>
2740typename enable_if
2741<
2742 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00002743 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow82513342016-09-24 22:45:42 +00002744>::type
2745basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002746 size_type __pos2, size_type __n)
2747{
Marshall Clow82513342016-09-24 22:45:42 +00002748 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002749 size_type __str_sz = __sv.size();
2750 if (__pos2 > __str_sz)
2751 this->__throw_out_of_range();
2752 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2753}
2754
2755template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002756basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002757basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002758{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002759 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002760 return insert(__pos, __s, traits_type::length(__s));
2761}
2762
2763template <class _CharT, class _Traits, class _Allocator>
2764typename basic_string<_CharT, _Traits, _Allocator>::iterator
2765basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2766{
2767 size_type __ip = static_cast<size_type>(__pos - begin());
2768 size_type __sz = size();
2769 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002770 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002771 if (__cap == __sz)
2772 {
2773 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002774 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002775 }
2776 else
2777 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002778 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002779 size_type __n_move = __sz - __ip;
2780 if (__n_move != 0)
2781 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2782 }
2783 traits_type::assign(__p[__ip], __c);
2784 traits_type::assign(__p[++__sz], value_type());
2785 __set_size(__sz);
2786 return begin() + static_cast<difference_type>(__ip);
2787}
2788
2789template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002790inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002791typename basic_string<_CharT, _Traits, _Allocator>::iterator
2792basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2793{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002794#if _LIBCPP_DEBUG_LEVEL >= 2
2795 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2796 "string::insert(iterator, n, value) called with an iterator not"
2797 " referring to this string");
2798#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002799 difference_type __p = __pos - begin();
2800 insert(static_cast<size_type>(__p), __n, __c);
2801 return begin() + __p;
2802}
2803
2804// replace
2805
2806template <class _CharT, class _Traits, class _Allocator>
2807basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002808basic_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 +00002809 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantc51e1022010-05-11 19:42:16 +00002810{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002811 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002812 size_type __sz = size();
2813 if (__pos > __sz)
2814 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002815 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002816 size_type __cap = capacity();
2817 if (__cap - __sz + __n1 >= __n2)
2818 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002819 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002820 if (__n1 != __n2)
2821 {
2822 size_type __n_move = __sz - __pos - __n1;
2823 if (__n_move != 0)
2824 {
2825 if (__n1 > __n2)
2826 {
2827 traits_type::move(__p + __pos, __s, __n2);
2828 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2829 goto __finish;
2830 }
2831 if (__p + __pos < __s && __s < __p + __sz)
2832 {
2833 if (__p + __pos + __n1 <= __s)
2834 __s += __n2 - __n1;
2835 else // __p + __pos < __s < __p + __pos + __n1
2836 {
2837 traits_type::move(__p + __pos, __s, __n1);
2838 __pos += __n1;
2839 __s += __n2;
2840 __n2 -= __n1;
2841 __n1 = 0;
2842 }
2843 }
2844 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2845 }
2846 }
2847 traits_type::move(__p + __pos, __s, __n2);
2848__finish:
Eric Fiseliere5b21842017-03-09 01:54:13 +00002849// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
2850// but this is a safe operation, so we disable the check.
Howard Hinnantc51e1022010-05-11 19:42:16 +00002851 __sz += __n2 - __n1;
2852 __set_size(__sz);
2853 __invalidate_iterators_past(__sz);
2854 traits_type::assign(__p[__sz], value_type());
2855 }
2856 else
2857 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2858 return *this;
2859}
2860
2861template <class _CharT, class _Traits, class _Allocator>
2862basic_string<_CharT, _Traits, _Allocator>&
2863basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
Eric Fiseliere5b21842017-03-09 01:54:13 +00002864 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantc51e1022010-05-11 19:42:16 +00002865{
2866 size_type __sz = size();
2867 if (__pos > __sz)
2868 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002869 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002870 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002871 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002872 if (__cap - __sz + __n1 >= __n2)
2873 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002874 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002875 if (__n1 != __n2)
2876 {
2877 size_type __n_move = __sz - __pos - __n1;
2878 if (__n_move != 0)
2879 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2880 }
2881 }
2882 else
2883 {
2884 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002885 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002886 }
2887 traits_type::assign(__p + __pos, __n2, __c);
2888 __sz += __n2 - __n1;
2889 __set_size(__sz);
2890 __invalidate_iterators_past(__sz);
2891 traits_type::assign(__p[__sz], value_type());
2892 return *this;
2893}
2894
2895template <class _CharT, class _Traits, class _Allocator>
2896template<class _InputIterator>
2897typename enable_if
2898<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002899 __is_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002900 basic_string<_CharT, _Traits, _Allocator>&
2901>::type
Howard Hinnant990d6e82010-11-17 21:11:40 +00002902basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002903 _InputIterator __j1, _InputIterator __j2)
2904{
Marshall Clow958362f2016-09-05 01:54:30 +00002905 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clow039b2f02016-01-13 21:54:34 +00002906 return this->replace(__i1, __i2, __temp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002907}
2908
2909template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002910inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002911basic_string<_CharT, _Traits, _Allocator>&
2912basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2913{
2914 return replace(__pos1, __n1, __str.data(), __str.size());
2915}
2916
2917template <class _CharT, class _Traits, class _Allocator>
2918basic_string<_CharT, _Traits, _Allocator>&
2919basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2920 size_type __pos2, size_type __n2)
2921{
2922 size_type __str_sz = __str.size();
2923 if (__pos2 > __str_sz)
2924 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002925 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002926}
2927
2928template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00002929template <class _Tp>
2930typename enable_if
2931<
Marshall Clowb7db4972017-11-15 20:02:27 +00002932 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2933 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow82513342016-09-24 22:45:42 +00002934>::type
2935basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002936 size_type __pos2, size_type __n2)
2937{
Marshall Clow82513342016-09-24 22:45:42 +00002938 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002939 size_type __str_sz = __sv.size();
2940 if (__pos2 > __str_sz)
2941 this->__throw_out_of_range();
2942 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2943}
2944
2945template <class _CharT, class _Traits, class _Allocator>
2946basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002947basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002948{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002949 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002950 return replace(__pos, __n1, __s, traits_type::length(__s));
2951}
2952
2953template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002954inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002955basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant990d6e82010-11-17 21:11:40 +00002956basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002957{
2958 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2959 __str.data(), __str.size());
2960}
2961
2962template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002963inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002964basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002965basic_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 +00002966{
2967 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2968}
2969
2970template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002971inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002972basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002973basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002974{
2975 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2976}
2977
2978template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002979inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002980basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant990d6e82010-11-17 21:11:40 +00002981basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002982{
2983 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2984}
2985
2986// erase
2987
2988template <class _CharT, class _Traits, class _Allocator>
2989basic_string<_CharT, _Traits, _Allocator>&
2990basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2991{
2992 size_type __sz = size();
2993 if (__pos > __sz)
2994 this->__throw_out_of_range();
2995 if (__n)
2996 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002997 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002998 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002999 size_type __n_move = __sz - __pos - __n;
3000 if (__n_move != 0)
3001 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3002 __sz -= __n;
3003 __set_size(__sz);
3004 __invalidate_iterators_past(__sz);
3005 traits_type::assign(__p[__sz], value_type());
3006 }
3007 return *this;
3008}
3009
3010template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003011inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003012typename basic_string<_CharT, _Traits, _Allocator>::iterator
3013basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3014{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003015#if _LIBCPP_DEBUG_LEVEL >= 2
3016 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3017 "string::erase(iterator) called with an iterator not"
3018 " referring to this string");
3019#endif
3020 _LIBCPP_ASSERT(__pos != end(),
3021 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003022 iterator __b = begin();
3023 size_type __r = static_cast<size_type>(__pos - __b);
3024 erase(__r, 1);
Howard Hinnant28b24882011-12-01 20:21:04 +00003025 return __b + static_cast<difference_type>(__r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003026}
3027
3028template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003029inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003030typename basic_string<_CharT, _Traits, _Allocator>::iterator
3031basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3032{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003033#if _LIBCPP_DEBUG_LEVEL >= 2
3034 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3035 "string::erase(iterator, iterator) called with an iterator not"
3036 " referring to this string");
3037#endif
3038 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003039 iterator __b = begin();
3040 size_type __r = static_cast<size_type>(__first - __b);
3041 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnant28b24882011-12-01 20:21:04 +00003042 return __b + static_cast<difference_type>(__r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003043}
3044
3045template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003046inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003047void
3048basic_string<_CharT, _Traits, _Allocator>::pop_back()
3049{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003050 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003051 size_type __sz;
3052 if (__is_long())
3053 {
3054 __sz = __get_long_size() - 1;
3055 __set_long_size(__sz);
3056 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3057 }
3058 else
3059 {
3060 __sz = __get_short_size() - 1;
3061 __set_short_size(__sz);
3062 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3063 }
3064 __invalidate_iterators_past(__sz);
3065}
3066
3067template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003068inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003069void
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003070basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003071{
3072 __invalidate_all_iterators();
3073 if (__is_long())
3074 {
3075 traits_type::assign(*__get_long_pointer(), value_type());
3076 __set_long_size(0);
3077 }
3078 else
3079 {
3080 traits_type::assign(*__get_short_pointer(), value_type());
3081 __set_short_size(0);
3082 }
3083}
3084
3085template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003086inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003087void
3088basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3089{
3090 if (__is_long())
3091 {
3092 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3093 __set_long_size(__pos);
3094 }
3095 else
3096 {
3097 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3098 __set_short_size(__pos);
3099 }
3100 __invalidate_iterators_past(__pos);
3101}
3102
3103template <class _CharT, class _Traits, class _Allocator>
3104void
3105basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3106{
3107 size_type __sz = size();
3108 if (__n > __sz)
3109 append(__n - __sz, __c);
3110 else
3111 __erase_to_end(__n);
3112}
3113
3114template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier451d5582018-11-26 20:15:38 +00003115inline void
3116basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
3117{
3118 size_type __sz = size();
3119 if (__n > __sz) {
3120 __append_default_init(__n - __sz);
3121 } else
3122 __erase_to_end(__n);
3123}
3124
3125template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003126inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003127typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003128basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003129{
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003130 size_type __m = __alloc_traits::max_size(__alloc());
Eric Fiseliere9cc5922017-10-17 13:16:01 +00003131#ifdef _LIBCPP_BIG_ENDIAN
Marshall Clow6dd6cb72013-10-31 17:23:08 +00003132 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003133#else
Marshall Clow6dd6cb72013-10-31 17:23:08 +00003134 return __m - __alignment;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003135#endif
3136}
3137
3138template <class _CharT, class _Traits, class _Allocator>
3139void
3140basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3141{
3142 if (__res_arg > max_size())
3143 this->__throw_length_error();
3144 size_type __cap = capacity();
3145 size_type __sz = size();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003146 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003147 __res_arg = __recommend(__res_arg);
3148 if (__res_arg != __cap)
3149 {
3150 pointer __new_data, __p;
3151 bool __was_long, __now_long;
3152 if (__res_arg == __min_cap - 1)
3153 {
3154 __was_long = true;
3155 __now_long = false;
3156 __new_data = __get_short_pointer();
3157 __p = __get_long_pointer();
3158 }
3159 else
3160 {
3161 if (__res_arg > __cap)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003162 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003163 else
3164 {
3165 #ifndef _LIBCPP_NO_EXCEPTIONS
3166 try
3167 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003168 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003169 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003170 #ifndef _LIBCPP_NO_EXCEPTIONS
3171 }
3172 catch (...)
3173 {
3174 return;
3175 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003176 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantd17880b2013-06-28 16:59:19 +00003177 if (__new_data == nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003178 return;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003179 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00003180 }
3181 __now_long = true;
3182 __was_long = __is_long();
3183 __p = __get_pointer();
3184 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05003185 traits_type::copy(_VSTD::__to_address(__new_data),
3186 _VSTD::__to_address(__p), size()+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003187 if (__was_long)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003188 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003189 if (__now_long)
3190 {
3191 __set_long_cap(__res_arg+1);
3192 __set_long_size(__sz);
3193 __set_long_pointer(__new_data);
3194 }
3195 else
3196 __set_short_size(__sz);
3197 __invalidate_all_iterators();
3198 }
3199}
3200
3201template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003202inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003203typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003204basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003205{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003206 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003207 return *(data() + __pos);
3208}
3209
3210template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003211inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003212typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003213basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003214{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003215 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003216 return *(__get_pointer() + __pos);
3217}
3218
3219template <class _CharT, class _Traits, class _Allocator>
3220typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3221basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3222{
3223 if (__n >= size())
3224 this->__throw_out_of_range();
3225 return (*this)[__n];
3226}
3227
3228template <class _CharT, class _Traits, class _Allocator>
3229typename basic_string<_CharT, _Traits, _Allocator>::reference
3230basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3231{
3232 if (__n >= size())
3233 this->__throw_out_of_range();
3234 return (*this)[__n];
3235}
3236
3237template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003238inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003239typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003240basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003241{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003242 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003243 return *__get_pointer();
3244}
3245
3246template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003247inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003248typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003249basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003250{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003251 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003252 return *data();
3253}
3254
3255template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003256inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003257typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003258basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003259{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003260 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003261 return *(__get_pointer() + size() - 1);
3262}
3263
3264template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003265inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003266typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003267basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003268{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003269 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003270 return *(data() + size() - 1);
3271}
3272
3273template <class _CharT, class _Traits, class _Allocator>
3274typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003275basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003276{
3277 size_type __sz = size();
3278 if (__pos > __sz)
3279 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003280 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003281 traits_type::copy(__s, data() + __pos, __rlen);
3282 return __rlen;
3283}
3284
3285template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003286inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003287basic_string<_CharT, _Traits, _Allocator>
3288basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3289{
3290 return basic_string(*this, __pos, __n, __alloc());
3291}
3292
3293template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003294inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003295void
3296basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow8982dcd2015-07-13 20:04:56 +00003297#if _LIBCPP_STD_VER >= 14
Eric Fiselier873b8d32019-03-18 21:50:12 +00003298 _NOEXCEPT
Marshall Clow8982dcd2015-07-13 20:04:56 +00003299#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00003300 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow8982dcd2015-07-13 20:04:56 +00003301 __is_nothrow_swappable<allocator_type>::value)
3302#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003303{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003304#if _LIBCPP_DEBUG_LEVEL >= 2
3305 if (!__is_long())
3306 __get_db()->__invalidate_all(this);
3307 if (!__str.__is_long())
3308 __get_db()->__invalidate_all(&__str);
3309 __get_db()->swap(this, &__str);
3310#endif
Eric Fiselier9bf691f2016-12-28 05:53:01 +00003311 _LIBCPP_ASSERT(
3312 __alloc_traits::propagate_on_container_swap::value ||
3313 __alloc_traits::is_always_equal::value ||
3314 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003315 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow8982dcd2015-07-13 20:04:56 +00003316 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003317}
3318
3319// find
3320
3321template <class _Traits>
3322struct _LIBCPP_HIDDEN __traits_eq
3323{
3324 typedef typename _Traits::char_type char_type;
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003325 _LIBCPP_INLINE_VISIBILITY
3326 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3327 {return _Traits::eq(__x, __y);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003328};
3329
3330template<class _CharT, class _Traits, class _Allocator>
3331typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003332basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003333 size_type __pos,
3334 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003335{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003336 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003337 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003338 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003339}
3340
3341template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003342inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003343typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003344basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3345 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003346{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003347 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003348 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003349}
3350
3351template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003352template <class _Tp>
3353typename enable_if
3354<
3355 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3356 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3357>::type
3358basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
3359 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003360{
Marshall Clowe46031a2018-07-02 18:41:15 +00003361 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003362 return __str_find<value_type, size_type, traits_type, npos>
3363 (data(), size(), __sv.data(), __pos, __sv.size());
3364}
3365
3366template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003367inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003368typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003369basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003370 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003371{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003372 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003373 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003374 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003375}
3376
3377template<class _CharT, class _Traits, class _Allocator>
3378typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003379basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3380 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003381{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003382 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003383 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003384}
3385
3386// rfind
3387
3388template<class _CharT, class _Traits, class _Allocator>
3389typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003390basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003391 size_type __pos,
3392 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003393{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003394 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003395 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003396 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003397}
3398
3399template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003400inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003401typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003402basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3403 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003404{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003405 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003406 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003407}
3408
3409template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003410template <class _Tp>
3411typename enable_if
3412<
3413 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3414 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3415>::type
3416basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
3417 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003418{
Marshall Clowe46031a2018-07-02 18:41:15 +00003419 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003420 return __str_rfind<value_type, size_type, traits_type, npos>
3421 (data(), size(), __sv.data(), __pos, __sv.size());
3422}
3423
3424template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003425inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003426typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003427basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003428 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003429{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003430 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003431 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003432 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003433}
3434
3435template<class _CharT, class _Traits, class _Allocator>
3436typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003437basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3438 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003439{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003440 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003441 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003442}
3443
3444// find_first_of
3445
3446template<class _CharT, class _Traits, class _Allocator>
3447typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003448basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003449 size_type __pos,
3450 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003451{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003452 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003453 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003454 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003455}
3456
3457template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003458inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003459typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003460basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3461 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003462{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003463 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003464 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003465}
3466
3467template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003468template <class _Tp>
3469typename enable_if
3470<
3471 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3472 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3473>::type
3474basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
3475 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003476{
Marshall Clowe46031a2018-07-02 18:41:15 +00003477 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003478 return __str_find_first_of<value_type, size_type, traits_type, npos>
3479 (data(), size(), __sv.data(), __pos, __sv.size());
3480}
3481
3482template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003483inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003484typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003485basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003486 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003487{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003488 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003489 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003490 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003491}
3492
3493template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003494inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003495typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003496basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3497 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003498{
3499 return find(__c, __pos);
3500}
3501
3502// find_last_of
3503
3504template<class _CharT, class _Traits, class _Allocator>
3505typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003506basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003507 size_type __pos,
3508 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003509{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003510 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003511 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003512 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003513}
3514
3515template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003516inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003517typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003518basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3519 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003520{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003521 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003522 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003523}
3524
3525template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003526template <class _Tp>
3527typename enable_if
3528<
3529 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3530 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3531>::type
3532basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
3533 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003534{
Marshall Clowe46031a2018-07-02 18:41:15 +00003535 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003536 return __str_find_last_of<value_type, size_type, traits_type, npos>
3537 (data(), size(), __sv.data(), __pos, __sv.size());
3538}
3539
3540template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003541inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003542typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003543basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003544 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003545{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003546 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003547 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003548 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003549}
3550
3551template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003552inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003553typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003554basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3555 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003556{
3557 return rfind(__c, __pos);
3558}
3559
3560// find_first_not_of
3561
3562template<class _CharT, class _Traits, class _Allocator>
3563typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003564basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003565 size_type __pos,
3566 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003567{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003568 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003569 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003570 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003571}
3572
3573template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003574inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003575typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003576basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3577 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003578{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003579 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003580 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003581}
3582
3583template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003584template <class _Tp>
3585typename enable_if
3586<
3587 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3588 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3589>::type
3590basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
3591 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003592{
Marshall Clowe46031a2018-07-02 18:41:15 +00003593 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003594 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3595 (data(), size(), __sv.data(), __pos, __sv.size());
3596}
3597
3598template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003599inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003600typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003601basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003602 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003603{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003604 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003605 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003606 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003607}
3608
3609template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003610inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003611typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003612basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3613 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003614{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003615 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003616 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003617}
3618
3619// find_last_not_of
3620
3621template<class _CharT, class _Traits, class _Allocator>
3622typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003623basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003624 size_type __pos,
3625 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003626{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003627 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003628 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003629 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003630}
3631
3632template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003633inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003634typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003635basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3636 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003637{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003638 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003639 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003640}
3641
3642template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003643template <class _Tp>
3644typename enable_if
3645<
3646 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3647 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3648>::type
3649basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
3650 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003651{
Marshall Clowe46031a2018-07-02 18:41:15 +00003652 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003653 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3654 (data(), size(), __sv.data(), __pos, __sv.size());
3655}
3656
3657template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003658inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003659typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003660basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003661 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003662{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003663 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003664 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003665 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003666}
3667
3668template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003669inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003670typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003671basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3672 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003673{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003674 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003675 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003676}
3677
3678// compare
3679
3680template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003681template <class _Tp>
3682typename enable_if
3683<
3684 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3685 int
3686>::type
3687basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003688{
Marshall Clowe46031a2018-07-02 18:41:15 +00003689 __self_view __sv = __t;
Howard Hinnantb0485532011-07-24 21:45:06 +00003690 size_t __lhs_sz = size();
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003691 size_t __rhs_sz = __sv.size();
3692 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantb0485532011-07-24 21:45:06 +00003693 _VSTD::min(__lhs_sz, __rhs_sz));
3694 if (__result != 0)
3695 return __result;
3696 if (__lhs_sz < __rhs_sz)
3697 return -1;
3698 if (__lhs_sz > __rhs_sz)
3699 return 1;
3700 return 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003701}
3702
3703template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003704inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003705int
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003706basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003707{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003708 return compare(__self_view(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003709}
3710
3711template <class _CharT, class _Traits, class _Allocator>
3712int
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003713basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3714 size_type __n1,
Howard Hinnantd17880b2013-06-28 16:59:19 +00003715 const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003716 size_type __n2) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003717{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003718 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003719 size_type __sz = size();
3720 if (__pos1 > __sz || __n2 == npos)
3721 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003722 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3723 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003724 if (__r == 0)
3725 {
3726 if (__rlen < __n2)
3727 __r = -1;
3728 else if (__rlen > __n2)
3729 __r = 1;
3730 }
3731 return __r;
3732}
3733
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003734template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003735template <class _Tp>
3736typename enable_if
3737<
3738 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3739 int
3740>::type
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003741basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3742 size_type __n1,
Marshall Clowe46031a2018-07-02 18:41:15 +00003743 const _Tp& __t) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003744{
Marshall Clowe46031a2018-07-02 18:41:15 +00003745 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003746 return compare(__pos1, __n1, __sv.data(), __sv.size());
3747}
3748
3749template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003750inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003751int
3752basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3753 size_type __n1,
3754 const basic_string& __str) const
3755{
3756 return compare(__pos1, __n1, __str.data(), __str.size());
3757}
3758
3759template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00003760template <class _Tp>
3761typename enable_if
3762<
Marshall Clowb7db4972017-11-15 20:02:27 +00003763 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3764 int
Marshall Clow82513342016-09-24 22:45:42 +00003765>::type
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003766basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3767 size_type __n1,
Marshall Clow82513342016-09-24 22:45:42 +00003768 const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003769 size_type __pos2,
3770 size_type __n2) const
3771{
Marshall Clow82513342016-09-24 22:45:42 +00003772 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003773 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3774}
3775
3776template <class _CharT, class _Traits, class _Allocator>
3777int
3778basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3779 size_type __n1,
3780 const basic_string& __str,
3781 size_type __pos2,
3782 size_type __n2) const
3783{
3784 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3785}
3786
3787template <class _CharT, class _Traits, class _Allocator>
3788int
3789basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3790{
3791 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3792 return compare(0, npos, __s, traits_type::length(__s));
3793}
3794
3795template <class _CharT, class _Traits, class _Allocator>
3796int
3797basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3798 size_type __n1,
3799 const value_type* __s) const
3800{
3801 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3802 return compare(__pos1, __n1, __s, traits_type::length(__s));
3803}
3804
Howard Hinnantc51e1022010-05-11 19:42:16 +00003805// __invariants
3806
3807template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003808inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003809bool
3810basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3811{
3812 if (size() > capacity())
3813 return false;
3814 if (capacity() < __min_cap - 1)
3815 return false;
3816 if (data() == 0)
3817 return false;
3818 if (data()[size()] != value_type(0))
3819 return false;
3820 return true;
3821}
3822
Vedant Kumar55e007e2018-03-08 21:15:26 +00003823// __clear_and_shrink
3824
3825template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003826inline
Louis Dionne173f29e2019-05-29 16:01:36 +00003827void
Marshall Clowe60a7182018-05-29 17:04:37 +00003828basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
Vedant Kumar55e007e2018-03-08 21:15:26 +00003829{
3830 clear();
3831 if(__is_long())
3832 {
3833 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
3834 __set_long_cap(0);
3835 __set_short_size(0);
3836 }
Louis Dionne173f29e2019-05-29 16:01:36 +00003837}
Vedant Kumar55e007e2018-03-08 21:15:26 +00003838
Howard Hinnantc51e1022010-05-11 19:42:16 +00003839// operator==
3840
3841template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003842inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003843bool
3844operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003845 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003846{
Howard Hinnantaaeb1132013-04-22 23:55:13 +00003847 size_t __lhs_sz = __lhs.size();
3848 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3849 __rhs.data(),
3850 __lhs_sz) == 0;
3851}
3852
3853template<class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003854inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaaeb1132013-04-22 23:55:13 +00003855bool
3856operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3857 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3858{
3859 size_t __lhs_sz = __lhs.size();
3860 if (__lhs_sz != __rhs.size())
3861 return false;
3862 const char* __lp = __lhs.data();
3863 const char* __rp = __rhs.data();
3864 if (__lhs.__is_long())
3865 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3866 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3867 if (*__lp != *__rp)
3868 return false;
3869 return true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003870}
3871
3872template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003873inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003874bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003875operator==(const _CharT* __lhs,
3876 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003877{
Eric Fiselier0cafa3f2015-08-28 03:02:37 +00003878 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3879 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3880 size_t __lhs_len = _Traits::length(__lhs);
3881 if (__lhs_len != __rhs.size()) return false;
3882 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003883}
3884
Howard Hinnantc51e1022010-05-11 19:42:16 +00003885template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003886inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003887bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003888operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3889 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003890{
Eric Fiselier0cafa3f2015-08-28 03:02:37 +00003891 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3892 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3893 size_t __rhs_len = _Traits::length(__rhs);
3894 if (__rhs_len != __lhs.size()) return false;
3895 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003896}
3897
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003898template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003899inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003900bool
3901operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003902 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003903{
3904 return !(__lhs == __rhs);
3905}
3906
3907template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003908inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003909bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003910operator!=(const _CharT* __lhs,
3911 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003912{
3913 return !(__lhs == __rhs);
3914}
3915
3916template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003917inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003918bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003919operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3920 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003921{
3922 return !(__lhs == __rhs);
3923}
3924
3925// operator<
3926
3927template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003928inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003929bool
3930operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003931 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003932{
Howard Hinnanta2660c12011-07-24 15:07:21 +00003933 return __lhs.compare(__rhs) < 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003934}
3935
3936template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003937inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003938bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003939operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3940 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003941{
Howard Hinnanta2660c12011-07-24 15:07:21 +00003942 return __lhs.compare(__rhs) < 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003943}
3944
3945template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003946inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003947bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003948operator< (const _CharT* __lhs,
3949 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003950{
3951 return __rhs.compare(__lhs) > 0;
3952}
3953
Howard Hinnantc51e1022010-05-11 19:42:16 +00003954// operator>
3955
3956template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003957inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003958bool
3959operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003960 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003961{
3962 return __rhs < __lhs;
3963}
3964
3965template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003966inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003967bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003968operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3969 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003970{
3971 return __rhs < __lhs;
3972}
3973
3974template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003975inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003976bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003977operator> (const _CharT* __lhs,
3978 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003979{
3980 return __rhs < __lhs;
3981}
3982
3983// operator<=
3984
3985template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003986inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003987bool
3988operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003989 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003990{
3991 return !(__rhs < __lhs);
3992}
3993
3994template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003995inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003996bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003997operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3998 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003999{
4000 return !(__rhs < __lhs);
4001}
4002
4003template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004004inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004005bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004006operator<=(const _CharT* __lhs,
4007 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004008{
4009 return !(__rhs < __lhs);
4010}
4011
4012// operator>=
4013
4014template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004015inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004016bool
4017operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004018 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004019{
4020 return !(__lhs < __rhs);
4021}
4022
4023template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004024inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004025bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004026operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4027 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004028{
4029 return !(__lhs < __rhs);
4030}
4031
4032template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004033inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004034bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004035operator>=(const _CharT* __lhs,
4036 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004037{
4038 return !(__lhs < __rhs);
4039}
4040
4041// operator +
4042
4043template<class _CharT, class _Traits, class _Allocator>
4044basic_string<_CharT, _Traits, _Allocator>
4045operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4046 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4047{
4048 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4049 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4050 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4051 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4052 __r.append(__rhs.data(), __rhs_sz);
4053 return __r;
4054}
4055
4056template<class _CharT, class _Traits, class _Allocator>
4057basic_string<_CharT, _Traits, _Allocator>
4058operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4059{
4060 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4061 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4062 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4063 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4064 __r.append(__rhs.data(), __rhs_sz);
4065 return __r;
4066}
4067
4068template<class _CharT, class _Traits, class _Allocator>
4069basic_string<_CharT, _Traits, _Allocator>
4070operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4071{
4072 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4073 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4074 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4075 __r.append(__rhs.data(), __rhs_sz);
4076 return __r;
4077}
4078
4079template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00004080inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004081basic_string<_CharT, _Traits, _Allocator>
4082operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4083{
4084 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4085 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4086 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4087 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4088 __r.append(__rhs, __rhs_sz);
4089 return __r;
4090}
4091
4092template<class _CharT, class _Traits, class _Allocator>
4093basic_string<_CharT, _Traits, _Allocator>
4094operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4095{
4096 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4097 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4098 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4099 __r.push_back(__rhs);
4100 return __r;
4101}
4102
Eric Fiselierfc92be82017-04-19 00:28:44 +00004103#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00004104
4105template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004106inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004107basic_string<_CharT, _Traits, _Allocator>
4108operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4109{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004110 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004111}
4112
4113template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004114inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004115basic_string<_CharT, _Traits, _Allocator>
4116operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4117{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004118 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004119}
4120
4121template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004122inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004123basic_string<_CharT, _Traits, _Allocator>
4124operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4125{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004126 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004127}
4128
4129template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004130inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004131basic_string<_CharT, _Traits, _Allocator>
4132operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4133{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004134 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004135}
4136
4137template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004138inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004139basic_string<_CharT, _Traits, _Allocator>
4140operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4141{
4142 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004143 return _VSTD::move(__rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004144}
4145
4146template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004147inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004148basic_string<_CharT, _Traits, _Allocator>
4149operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4150{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004151 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004152}
4153
4154template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004155inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004156basic_string<_CharT, _Traits, _Allocator>
4157operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4158{
4159 __lhs.push_back(__rhs);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004160 return _VSTD::move(__lhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004161}
4162
Eric Fiselierfc92be82017-04-19 00:28:44 +00004163#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00004164
4165// swap
4166
4167template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004168inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004169void
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004170swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant3e276872011-06-03 18:40:47 +00004171 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4172 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00004173{
4174 __lhs.swap(__rhs);
4175}
4176
Marshall Clow8732fed2018-12-11 04:35:44 +00004177#ifndef _LIBCPP_NO_HAS_CHAR8_T
4178typedef basic_string<char8_t> u8string;
4179#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00004180
Marshall Clow8732fed2018-12-11 04:35:44 +00004181#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004182typedef basic_string<char16_t> u16string;
4183typedef basic_string<char32_t> u32string;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004184#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004185
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004186_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4187_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4188_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4189_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4190_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004191
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004192_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4193_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4194_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004195
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004196_LIBCPP_FUNC_VIS string to_string(int __val);
4197_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4198_LIBCPP_FUNC_VIS string to_string(long __val);
4199_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4200_LIBCPP_FUNC_VIS string to_string(long long __val);
4201_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4202_LIBCPP_FUNC_VIS string to_string(float __val);
4203_LIBCPP_FUNC_VIS string to_string(double __val);
4204_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004205
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004206_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4207_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4208_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4209_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4210_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004211
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004212_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4213_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4214_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004215
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004216_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4217_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4218_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4219_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4220_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4221_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4222_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4223_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4224_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004225
Howard Hinnantc51e1022010-05-11 19:42:16 +00004226template<class _CharT, class _Traits, class _Allocator>
4227 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4228 basic_string<_CharT, _Traits, _Allocator>::npos;
4229
Marshall Clow851b9ec2019-05-20 21:56:51 +00004230template <class _CharT, class _Allocator>
4231struct _LIBCPP_TEMPLATE_VIS
4232 hash<basic_string<_CharT, char_traits<_CharT>, _Allocator> >
4233 : public unary_function<
4234 basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004235{
4236 size_t
Marshall Clow851b9ec2019-05-20 21:56:51 +00004237 operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT
4238 { return __do_string_hash(__val.data(), __val.data() + __val.size()); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00004239};
4240
Howard Hinnantc51e1022010-05-11 19:42:16 +00004241
Howard Hinnantdc095972011-07-18 15:51:59 +00004242template<class _CharT, class _Traits, class _Allocator>
4243basic_ostream<_CharT, _Traits>&
4244operator<<(basic_ostream<_CharT, _Traits>& __os,
4245 const basic_string<_CharT, _Traits, _Allocator>& __str);
4246
4247template<class _CharT, class _Traits, class _Allocator>
4248basic_istream<_CharT, _Traits>&
4249operator>>(basic_istream<_CharT, _Traits>& __is,
4250 basic_string<_CharT, _Traits, _Allocator>& __str);
4251
4252template<class _CharT, class _Traits, class _Allocator>
4253basic_istream<_CharT, _Traits>&
4254getline(basic_istream<_CharT, _Traits>& __is,
4255 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4256
4257template<class _CharT, class _Traits, class _Allocator>
4258inline _LIBCPP_INLINE_VISIBILITY
4259basic_istream<_CharT, _Traits>&
4260getline(basic_istream<_CharT, _Traits>& __is,
4261 basic_string<_CharT, _Traits, _Allocator>& __str);
4262
Eric Fiselierfc92be82017-04-19 00:28:44 +00004263#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantdc095972011-07-18 15:51:59 +00004264
4265template<class _CharT, class _Traits, class _Allocator>
4266inline _LIBCPP_INLINE_VISIBILITY
4267basic_istream<_CharT, _Traits>&
4268getline(basic_istream<_CharT, _Traits>&& __is,
4269 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4270
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);
4276
Eric Fiselierfc92be82017-04-19 00:28:44 +00004277#endif // _LIBCPP_CXX03_LANG
Howard Hinnantdc095972011-07-18 15:51:59 +00004278
Marshall Clow29b53f22018-12-14 18:49:35 +00004279#if _LIBCPP_STD_VER > 17
4280template<class _CharT, class _Traits, class _Allocator, class _Up>
4281inline _LIBCPP_INLINE_VISIBILITY
4282void erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v)
4283{ __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end()); }
4284
4285template<class _CharT, class _Traits, class _Allocator, class _Predicate>
4286inline _LIBCPP_INLINE_VISIBILITY
4287void erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, _Predicate __pred)
4288{ __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred), __str.end()); }
4289#endif
4290
Howard Hinnant8ea98242013-08-23 17:37:05 +00004291#if _LIBCPP_DEBUG_LEVEL >= 2
4292
4293template<class _CharT, class _Traits, class _Allocator>
4294bool
4295basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4296{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004297 return this->data() <= _VSTD::__to_address(__i->base()) &&
4298 _VSTD::__to_address(__i->base()) < this->data() + this->size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004299}
4300
4301template<class _CharT, class _Traits, class _Allocator>
4302bool
4303basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4304{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004305 return this->data() < _VSTD::__to_address(__i->base()) &&
4306 _VSTD::__to_address(__i->base()) <= this->data() + this->size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004307}
4308
4309template<class _CharT, class _Traits, class _Allocator>
4310bool
4311basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4312{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004313 const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
Howard Hinnant8ea98242013-08-23 17:37:05 +00004314 return this->data() <= __p && __p <= this->data() + this->size();
4315}
4316
4317template<class _CharT, class _Traits, class _Allocator>
4318bool
4319basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4320{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004321 const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
Howard Hinnant8ea98242013-08-23 17:37:05 +00004322 return this->data() <= __p && __p < this->data() + this->size();
4323}
4324
4325#endif // _LIBCPP_DEBUG_LEVEL >= 2
4326
Shoaib Meenai6eb5f112017-06-29 02:52:46 +00004327_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
4328_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Shoaib Meenai6eb5f112017-06-29 02:52:46 +00004329
Louis Dionne173f29e2019-05-29 16:01:36 +00004330#if _LIBCPP_STD_VER > 11
Marshall Clowcba751f2013-07-23 17:05:24 +00004331// Literal suffixes for basic_string [basic.string.literals]
Marshall Clowac868372013-10-05 21:18:32 +00004332inline namespace literals
Marshall Clowcba751f2013-07-23 17:05:24 +00004333{
4334 inline namespace string_literals
4335 {
Howard Hinnant5c167562013-08-07 19:39:48 +00004336 inline _LIBCPP_INLINE_VISIBILITY
4337 basic_string<char> operator "" s( const char *__str, size_t __len )
4338 {
4339 return basic_string<char> (__str, __len);
4340 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004341
Howard Hinnant5c167562013-08-07 19:39:48 +00004342 inline _LIBCPP_INLINE_VISIBILITY
4343 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4344 {
4345 return basic_string<wchar_t> (__str, __len);
4346 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004347
Marshall Clow8732fed2018-12-11 04:35:44 +00004348#ifndef _LIBCPP_NO_HAS_CHAR8_T
4349 inline _LIBCPP_INLINE_VISIBILITY
4350 basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPT
4351 {
4352 return basic_string<char8_t> (__str, __len);
4353 }
4354#endif
4355
Howard Hinnant5c167562013-08-07 19:39:48 +00004356 inline _LIBCPP_INLINE_VISIBILITY
4357 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4358 {
4359 return basic_string<char16_t> (__str, __len);
4360 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004361
Howard Hinnant5c167562013-08-07 19:39:48 +00004362 inline _LIBCPP_INLINE_VISIBILITY
4363 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4364 {
4365 return basic_string<char32_t> (__str, __len);
4366 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004367 }
4368}
4369#endif
4370
Howard Hinnantc51e1022010-05-11 19:42:16 +00004371_LIBCPP_END_NAMESPACE_STD
4372
Eric Fiselierf4433a32017-05-31 22:07:49 +00004373_LIBCPP_POP_MACROS
4374
Howard Hinnantc51e1022010-05-11 19:42:16 +00004375#endif // _LIBCPP_STRING