blob: a35c7b1338d14ceef4b3bd29205bedc7a8713345 [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>
Eric Fiselierc522ceb2020-01-15 16:57:08 -0500646struct __can_be_converted_to_string_view : public _BoolConstant<
647 is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
648 !is_convertible<const _Tp&, const _CharT*>::value
649 > {};
Marshall Clow82513342016-09-24 22:45:42 +0000650
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000651#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +0000652
653template <class _CharT, size_t = sizeof(_CharT)>
654struct __padding
655{
656 unsigned char __xx[sizeof(_CharT)-1];
657};
658
659template <class _CharT>
660struct __padding<_CharT, 1>
661{
662};
663
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000664#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +0000665
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000666template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000667class _LIBCPP_TEMPLATE_VIS basic_string
Howard Hinnantc51e1022010-05-11 19:42:16 +0000668 : private __basic_string_common<true>
669{
670public:
671 typedef basic_string __self;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000672 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000673 typedef _Traits traits_type;
Marshall Clowa3a74e02017-03-15 18:41:11 +0000674 typedef _CharT value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675 typedef _Allocator allocator_type;
Howard Hinnantea8f7e12010-11-17 17:55:08 +0000676 typedef allocator_traits<allocator_type> __alloc_traits;
677 typedef typename __alloc_traits::size_type size_type;
678 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant3e276872011-06-03 18:40:47 +0000679 typedef value_type& reference;
680 typedef const value_type& const_reference;
Howard Hinnantea8f7e12010-11-17 17:55:08 +0000681 typedef typename __alloc_traits::pointer pointer;
682 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000683
Marshall Clow79f33542018-03-21 00:36:05 +0000684 static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
685 static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
686 static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
687 static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
Howard Hinnant8ea98242013-08-23 17:37:05 +0000688 "traits_type::char_type must be the same type as CharT");
Marshall Clow79f33542018-03-21 00:36:05 +0000689 static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
Howard Hinnant8ea98242013-08-23 17:37:05 +0000690 "Allocator::value_type must be same type as value_type");
Marshall Clowe46031a2018-07-02 18:41:15 +0000691
Howard Hinnant8ea98242013-08-23 17:37:05 +0000692#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693 typedef pointer iterator;
694 typedef const_pointer const_iterator;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000695#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000696 typedef __wrap_iter<pointer> iterator;
697 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000698#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000699 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
700 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701
702private:
Howard Hinnant68bf1812013-04-30 21:44:48 +0000703
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000704#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +0000705
706 struct __long
707 {
708 pointer __data_;
709 size_type __size_;
710 size_type __cap_;
711 };
712
Eric Fiseliere9cc5922017-10-17 13:16:01 +0000713#ifdef _LIBCPP_BIG_ENDIAN
Ben Craig4b6f5f12017-07-12 01:45:13 +0000714 static const size_type __short_mask = 0x01;
715 static const size_type __long_mask = 0x1ul;
Howard Hinnant68bf1812013-04-30 21:44:48 +0000716#else // _LIBCPP_BIG_ENDIAN
Ben Craig4b6f5f12017-07-12 01:45:13 +0000717 static const size_type __short_mask = 0x80;
718 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant68bf1812013-04-30 21:44:48 +0000719#endif // _LIBCPP_BIG_ENDIAN
720
721 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
722 (sizeof(__long) - 1)/sizeof(value_type) : 2};
723
724 struct __short
725 {
726 value_type __data_[__min_cap];
727 struct
728 : __padding<value_type>
729 {
730 unsigned char __size_;
731 };
732 };
733
734#else
735
Howard Hinnantc51e1022010-05-11 19:42:16 +0000736 struct __long
737 {
738 size_type __cap_;
739 size_type __size_;
740 pointer __data_;
741 };
742
Eric Fiseliere9cc5922017-10-17 13:16:01 +0000743#ifdef _LIBCPP_BIG_ENDIAN
Ben Craig4b6f5f12017-07-12 01:45:13 +0000744 static const size_type __short_mask = 0x80;
745 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000746#else // _LIBCPP_BIG_ENDIAN
Ben Craig4b6f5f12017-07-12 01:45:13 +0000747 static const size_type __short_mask = 0x01;
748 static const size_type __long_mask = 0x1ul;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000749#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantc51e1022010-05-11 19:42:16 +0000750
Howard Hinnantc51e1022010-05-11 19:42:16 +0000751 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
752 (sizeof(__long) - 1)/sizeof(value_type) : 2};
753
754 struct __short
755 {
756 union
757 {
758 unsigned char __size_;
Howard Hinnant49e145e2012-10-30 19:06:59 +0000759 value_type __lx;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760 };
761 value_type __data_[__min_cap];
762 };
763
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000764#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +0000765
Howard Hinnant8ea98242013-08-23 17:37:05 +0000766 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000767
Howard Hinnant8ea98242013-08-23 17:37:05 +0000768 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000769
770 struct __raw
771 {
772 size_type __words[__n_words];
773 };
774
775 struct __rep
776 {
777 union
778 {
779 __long __l;
780 __short __s;
781 __raw __r;
782 };
783 };
784
785 __compressed_pair<__rep, allocator_type> __r_;
786
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787public:
Eric Fiselier2ae9e062020-01-16 15:00:34 -0500788 _LIBCPP_FUNC_VIS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000789 static const size_type npos = -1;
790
Howard Hinnant3e276872011-06-03 18:40:47 +0000791 _LIBCPP_INLINE_VISIBILITY basic_string()
792 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clowa80abc72015-06-03 19:56:43 +0000793
794 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
795#if _LIBCPP_STD_VER <= 14
796 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
797#else
798 _NOEXCEPT;
799#endif
800
Howard Hinnantc51e1022010-05-11 19:42:16 +0000801 basic_string(const basic_string& __str);
802 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clowa80abc72015-06-03 19:56:43 +0000803
Eric Fiselierfc92be82017-04-19 00:28:44 +0000804#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantebb0edf2011-01-26 00:06:59 +0000805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e276872011-06-03 18:40:47 +0000806 basic_string(basic_string&& __str)
Marshall Clowa80abc72015-06-03 19:56:43 +0000807#if _LIBCPP_STD_VER <= 14
Howard Hinnant3e276872011-06-03 18:40:47 +0000808 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clowa80abc72015-06-03 19:56:43 +0000809#else
810 _NOEXCEPT;
811#endif
812
Howard Hinnantebb0edf2011-01-26 00:06:59 +0000813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000814 basic_string(basic_string&& __str, const allocator_type& __a);
Eric Fiselierfc92be82017-04-19 00:28:44 +0000815#endif // _LIBCPP_CXX03_LANG
Marshall Clowe46031a2018-07-02 18:41:15 +0000816
Eric Fiselierfe7fe0a2020-01-15 17:29:55 -0500817 template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
Eric Fiseliera8567862018-07-17 05:48:48 +0000818 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5169d1c2019-12-16 19:03:23 -0500819 basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) {
Eric Fiseliera8567862018-07-17 05:48:48 +0000820 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
821 __init(__s, traits_type::length(__s));
822# if _LIBCPP_DEBUG_LEVEL >= 2
823 __get_db()->__insert_c(this);
824# endif
825 }
Marshall Clowe46031a2018-07-02 18:41:15 +0000826
Eric Fiselierfe7fe0a2020-01-15 17:29:55 -0500827 template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
Marshall Clowe46031a2018-07-02 18:41:15 +0000828 _LIBCPP_INLINE_VISIBILITY
829 basic_string(const _CharT* __s, const _Allocator& __a);
830
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);
Howard Hinnantcf823322010-12-17 14:46:43 +0000833 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier812882b2017-02-17 01:17:10 +0000834 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
Howard Hinnantcf823322010-12-17 14:46:43 +0000835 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier812882b2017-02-17 01:17:10 +0000836 basic_string(size_type __n, _CharT __c);
Marshall Clowe46031a2018-07-02 18:41:15 +0000837
Eric Fiselierfe7fe0a2020-01-15 17:29:55 -0500838 template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
Marshall Clowe46031a2018-07-02 18:41:15 +0000839 _LIBCPP_INLINE_VISIBILITY
840 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
841
Marshall Clow83445802016-04-07 18:13:41 +0000842 basic_string(const basic_string& __str, size_type __pos, size_type __n,
Eric Fiselier812882b2017-02-17 01:17:10 +0000843 const _Allocator& __a = _Allocator());
Marshall Clow83445802016-04-07 18:13:41 +0000844 _LIBCPP_INLINE_VISIBILITY
845 basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier812882b2017-02-17 01:17:10 +0000846 const _Allocator& __a = _Allocator());
Marshall Clowe46031a2018-07-02 18:41:15 +0000847
Eric Fiselierc522ceb2020-01-15 16:57:08 -0500848 template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
Shoaib Meenai69c57412017-03-02 03:02:50 +0000849 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselier812882b2017-02-17 01:17:10 +0000850 basic_string(const _Tp& __t, size_type __pos, size_type __n,
Eric Fiselierc522ceb2020-01-15 16:57:08 -0500851 const allocator_type& __a = allocator_type());
Marshall Clowe46031a2018-07-02 18:41:15 +0000852
Eric Fiselierc522ceb2020-01-15 16:57:08 -0500853 template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
854 !__is_same_uncvref<_Tp, basic_string>::value> >
Marshall Clowe46031a2018-07-02 18:41:15 +0000855 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
856 explicit basic_string(const _Tp& __t);
857
Eric Fiselierc522ceb2020-01-15 16:57:08 -0500858 template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
Marshall Clowe46031a2018-07-02 18:41:15 +0000859 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
860 explicit basic_string(const _Tp& __t, const allocator_type& __a);
861
Eric Fiselierfe7fe0a2020-01-15 17:29:55 -0500862 template<class _InputIterator, class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value> >
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);
Eric Fiselierfe7fe0a2020-01-15 17:29:55 -0500865 template<class _InputIterator, class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value> >
Howard Hinnantcf823322010-12-17 14:46:43 +0000866 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Eric Fiselierfc92be82017-04-19 00:28:44 +0000868#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantcf823322010-12-17 14:46:43 +0000869 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier812882b2017-02-17 01:17:10 +0000870 basic_string(initializer_list<_CharT> __il);
Howard Hinnantcf823322010-12-17 14:46:43 +0000871 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier812882b2017-02-17 01:17:10 +0000872 basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
Eric Fiselierfc92be82017-04-19 00:28:44 +0000873#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874
Eric Fiselierd9a702a2016-10-31 03:42:50 +0000875 inline ~basic_string();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000876
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000877 _LIBCPP_INLINE_VISIBILITY
878 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
879
Howard Hinnantea8f7e12010-11-17 17:55:08 +0000880 basic_string& operator=(const basic_string& __str);
Eric Fiselier5ec13b12017-01-23 21:24:58 +0000881
Eric Fiselierc522ceb2020-01-15 16:57:08 -0500882 template <class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
Marshall Clowe46031a2018-07-02 18:41:15 +0000883 basic_string& operator=(const _Tp& __t)
884 {__self_view __sv = __t; return assign(__sv);}
885
Eric Fiselierfc92be82017-04-19 00:28:44 +0000886#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantcf823322010-12-17 14:46:43 +0000887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e276872011-06-03 18:40:47 +0000888 basic_string& operator=(basic_string&& __str)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +0000889 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Eric Fiselierfc92be82017-04-19 00:28:44 +0000890 _LIBCPP_INLINE_VISIBILITY
891 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000892#endif
Howard Hinnantd17880b2013-06-28 16:59:19 +0000893 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000894 basic_string& operator=(value_type __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000895
Howard Hinnant8ea98242013-08-23 17:37:05 +0000896#if _LIBCPP_DEBUG_LEVEL >= 2
897 _LIBCPP_INLINE_VISIBILITY
898 iterator begin() _NOEXCEPT
899 {return iterator(this, __get_pointer());}
900 _LIBCPP_INLINE_VISIBILITY
901 const_iterator begin() const _NOEXCEPT
902 {return const_iterator(this, __get_pointer());}
903 _LIBCPP_INLINE_VISIBILITY
904 iterator end() _NOEXCEPT
905 {return iterator(this, __get_pointer() + size());}
906 _LIBCPP_INLINE_VISIBILITY
907 const_iterator end() const _NOEXCEPT
908 {return const_iterator(this, __get_pointer() + size());}
909#else
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000910 _LIBCPP_INLINE_VISIBILITY
911 iterator begin() _NOEXCEPT
912 {return iterator(__get_pointer());}
913 _LIBCPP_INLINE_VISIBILITY
914 const_iterator begin() const _NOEXCEPT
Howard Hinnantd17880b2013-06-28 16:59:19 +0000915 {return const_iterator(__get_pointer());}
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000916 _LIBCPP_INLINE_VISIBILITY
917 iterator end() _NOEXCEPT
918 {return iterator(__get_pointer() + size());}
919 _LIBCPP_INLINE_VISIBILITY
920 const_iterator end() const _NOEXCEPT
Howard Hinnantd17880b2013-06-28 16:59:19 +0000921 {return const_iterator(__get_pointer() + size());}
Howard Hinnant8ea98242013-08-23 17:37:05 +0000922#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000923 _LIBCPP_INLINE_VISIBILITY
924 reverse_iterator rbegin() _NOEXCEPT
925 {return reverse_iterator(end());}
926 _LIBCPP_INLINE_VISIBILITY
927 const_reverse_iterator rbegin() const _NOEXCEPT
928 {return const_reverse_iterator(end());}
929 _LIBCPP_INLINE_VISIBILITY
930 reverse_iterator rend() _NOEXCEPT
931 {return reverse_iterator(begin());}
932 _LIBCPP_INLINE_VISIBILITY
933 const_reverse_iterator rend() const _NOEXCEPT
934 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000935
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000936 _LIBCPP_INLINE_VISIBILITY
937 const_iterator cbegin() const _NOEXCEPT
938 {return begin();}
939 _LIBCPP_INLINE_VISIBILITY
940 const_iterator cend() const _NOEXCEPT
941 {return end();}
942 _LIBCPP_INLINE_VISIBILITY
943 const_reverse_iterator crbegin() const _NOEXCEPT
944 {return rbegin();}
945 _LIBCPP_INLINE_VISIBILITY
946 const_reverse_iterator crend() const _NOEXCEPT
947 {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000948
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000949 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000950 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000951 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
952 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
953 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiselier8599fcc2015-08-28 07:02:42 +0000954 {return (__is_long() ? __get_long_cap()
955 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000956
957 void resize(size_type __n, value_type __c);
958 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
959
Marshall Clow6ae12a82018-11-28 18:18:34 +0000960 void reserve(size_type __res_arg);
Eric Fiselier451d5582018-11-26 20:15:38 +0000961 _LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n);
962
Marshall Clow6ae12a82018-11-28 18:18:34 +0000963 _LIBCPP_INLINE_VISIBILITY
964 void reserve() _NOEXCEPT {reserve(0);}
Howard Hinnant186dca82010-09-23 17:31:07 +0000965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e276872011-06-03 18:40:47 +0000966 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnantcf823322010-12-17 14:46:43 +0000967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000968 void clear() _NOEXCEPT;
Marshall Clowb7db4972017-11-15 20:02:27 +0000969 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
970 bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000971
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000972 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
973 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000974
975 const_reference at(size_type __n) const;
976 reference at(size_type __n);
977
978 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clowe46031a2018-07-02 18:41:15 +0000979
980 template <class _Tp>
981 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -0500982 _EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +0000983 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -0500984 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
985 && !__is_same_uncvref<_Tp, basic_string >::value,
Marshall Clowe46031a2018-07-02 18:41:15 +0000986 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -0500987 >
Marshall Clowe46031a2018-07-02 18:41:15 +0000988 operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);}
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000989 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000990 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Eric Fiselierfc92be82017-04-19 00:28:44 +0000991#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Eric Fiselierfc92be82017-04-19 00:28:44 +0000993#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000994
Howard Hinnantcf823322010-12-17 14:46:43 +0000995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996 basic_string& append(const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +0000997
998 template <class _Tp>
999 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001000 _EnableIf<
1001 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1002 && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clowe46031a2018-07-02 18:41:15 +00001003 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001004 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001005 append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
Marshall Clow8db7fb02014-03-04 19:17:19 +00001006 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clowe46031a2018-07-02 18:41:15 +00001007
Marshall Clow62953962016-10-03 23:40:48 +00001008 template <class _Tp>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001009 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001010 _EnableIf
Marshall Clow82513342016-09-24 22:45:42 +00001011 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001012 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1013 && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clow82513342016-09-24 22:45:42 +00001014 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001015 >
Marshall Clow82513342016-09-24 22:45:42 +00001016 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Howard Hinnantd17880b2013-06-28 16:59:19 +00001017 basic_string& append(const value_type* __s, size_type __n);
1018 basic_string& append(const value_type* __s);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001019 basic_string& append(size_type __n, value_type __c);
Eric Fiselier451d5582018-11-26 20:15:38 +00001020
1021 _LIBCPP_INLINE_VISIBILITY
1022 void __append_default_init(size_type __n);
1023
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00001024 template <class _ForwardIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001025 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1026 basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001027 template<class _InputIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001028 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001029 _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00001030 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001031 __is_exactly_cpp17_input_iterator<_InputIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00001032 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001034 >
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00001035 _LIBCPP_INLINE_VISIBILITY
1036 append(_InputIterator __first, _InputIterator __last) {
1037 const basic_string __temp (__first, __last, __alloc());
1038 append(__temp.data(), __temp.size());
1039 return *this;
1040 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001041 template<class _ForwardIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001042 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001043 _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00001044 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001045 __is_cpp17_forward_iterator<_ForwardIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00001046 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001048 >
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00001049 _LIBCPP_INLINE_VISIBILITY
1050 append(_ForwardIterator __first, _ForwardIterator __last) {
1051 return __append_forward_unsafe(__first, __last);
1052 }
1053
Eric Fiselierfc92be82017-04-19 00:28:44 +00001054#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant186dca82010-09-23 17:31:07 +00001055 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001056 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Eric Fiselierfc92be82017-04-19 00:28:44 +00001057#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001058
1059 void push_back(value_type __c);
Howard Hinnantcf823322010-12-17 14:46:43 +00001060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001061 void pop_back();
Marshall Clow05cf6692019-03-19 03:30:07 +00001062 _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT;
1063 _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT;
1064 _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT;
1065 _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066
Marshall Clowe46031a2018-07-02 18:41:15 +00001067 template <class _Tp>
1068 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001069 _EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00001070 <
1071 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1072 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001073 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001074 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001075 _LIBCPP_INLINE_VISIBILITY
Marshall Clow95d5e9a2016-03-09 18:08:29 +00001076 basic_string& assign(const basic_string& __str) { return *this = __str; }
Eric Fiselierfc92be82017-04-19 00:28:44 +00001077#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001078 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001079 basic_string& assign(basic_string&& __str)
Marshall Clow5aa9e942015-10-05 16:17:34 +00001080 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001081 {*this = _VSTD::move(__str); return *this;}
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001082#endif
Marshall Clow8db7fb02014-03-04 19:17:19 +00001083 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow62953962016-10-03 23:40:48 +00001084 template <class _Tp>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001085 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001086 _EnableIf
Marshall Clow82513342016-09-24 22:45:42 +00001087 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001088 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1089 && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clow82513342016-09-24 22:45:42 +00001090 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001091 >
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001092 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
Howard Hinnantd17880b2013-06-28 16:59:19 +00001093 basic_string& assign(const value_type* __s, size_type __n);
1094 basic_string& assign(const value_type* __s);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001095 basic_string& assign(size_type __n, value_type __c);
1096 template<class _InputIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001097 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001098 _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001100 __is_exactly_cpp17_input_iterator<_InputIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00001101 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001102 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001103 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001104 assign(_InputIterator __first, _InputIterator __last);
1105 template<class _ForwardIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001106 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001107 _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00001108 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001109 __is_cpp17_forward_iterator<_ForwardIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00001110 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001111 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001112 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001113 assign(_ForwardIterator __first, _ForwardIterator __last);
Eric Fiselierfc92be82017-04-19 00:28:44 +00001114#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant186dca82010-09-23 17:31:07 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Eric Fiselierfc92be82017-04-19 00:28:44 +00001117#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001118
Howard Hinnantcf823322010-12-17 14:46:43 +00001119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001120 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +00001121
1122 template <class _Tp>
1123 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001124 _EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00001125 <
1126 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1127 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001128 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001129 insert(size_type __pos1, const _Tp& __t)
1130 { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
1131
Marshall Clow82513342016-09-24 22:45:42 +00001132 template <class _Tp>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001133 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001134 _EnableIf
Marshall Clow82513342016-09-24 22:45:42 +00001135 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001136 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clow82513342016-09-24 22:45:42 +00001137 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001138 >
Marshall Clow82513342016-09-24 22:45:42 +00001139 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Marshall Clow8db7fb02014-03-04 19:17:19 +00001140 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnantd17880b2013-06-28 16:59:19 +00001141 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1142 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001143 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1144 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnantcf823322010-12-17 14:46:43 +00001145 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001146 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1147 template<class _InputIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001148 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001149 _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00001150 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001151 __is_exactly_cpp17_input_iterator<_InputIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00001152 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001153 iterator
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001154 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001155 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1156 template<class _ForwardIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001157 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001158 _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00001159 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001160 __is_cpp17_forward_iterator<_ForwardIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00001161 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001162 iterator
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001163 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001164 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Eric Fiselierfc92be82017-04-19 00:28:44 +00001165#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant186dca82010-09-23 17:31:07 +00001166 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001167 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1168 {return insert(__pos, __il.begin(), __il.end());}
Eric Fiselierfc92be82017-04-19 00:28:44 +00001169#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170
1171 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnantcf823322010-12-17 14:46:43 +00001172 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001173 iterator erase(const_iterator __pos);
Howard Hinnantcf823322010-12-17 14:46:43 +00001174 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001175 iterator erase(const_iterator __first, const_iterator __last);
1176
Howard Hinnantcf823322010-12-17 14:46:43 +00001177 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001178 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +00001179
1180 template <class _Tp>
1181 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001182 _EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00001183 <
1184 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1185 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001186 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001187 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 +00001188 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 +00001189 template <class _Tp>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001190 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001191 _EnableIf
Marshall Clow82513342016-09-24 22:45:42 +00001192 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001193 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clow82513342016-09-24 22:45:42 +00001194 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001195 >
Marshall Clow82513342016-09-24 22:45:42 +00001196 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Howard Hinnantd17880b2013-06-28 16:59:19 +00001197 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1198 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001199 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnantcf823322010-12-17 14:46:43 +00001200 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant990d6e82010-11-17 21:11:40 +00001201 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +00001202
1203 template <class _Tp>
1204 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001205 _EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00001206 <
1207 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1208 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001209 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001210 replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
1211
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001212 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001213 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnantcf823322010-12-17 14:46:43 +00001214 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001215 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnantcf823322010-12-17 14:46:43 +00001216 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant990d6e82010-11-17 21:11:40 +00001217 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001218 template<class _InputIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001219 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001220 _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00001221 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001222 __is_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001223 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001224 >
Howard Hinnant990d6e82010-11-17 21:11:40 +00001225 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Eric Fiselierfc92be82017-04-19 00:28:44 +00001226#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant186dca82010-09-23 17:31:07 +00001227 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant990d6e82010-11-17 21:11:40 +00001228 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001229 {return replace(__i1, __i2, __il.begin(), __il.end());}
Eric Fiselierfc92be82017-04-19 00:28:44 +00001230#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001231
Howard Hinnantd17880b2013-06-28 16:59:19 +00001232 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnantcf823322010-12-17 14:46:43 +00001233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001234 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1235
Howard Hinnantcf823322010-12-17 14:46:43 +00001236 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e276872011-06-03 18:40:47 +00001237 void swap(basic_string& __str)
Marshall Clow8982dcd2015-07-13 20:04:56 +00001238#if _LIBCPP_STD_VER >= 14
Eric Fiselier873b8d32019-03-18 21:50:12 +00001239 _NOEXCEPT;
Marshall Clow8982dcd2015-07-13 20:04:56 +00001240#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001241 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow8982dcd2015-07-13 20:04:56 +00001242 __is_nothrow_swappable<allocator_type>::value);
1243#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001244
Howard Hinnantcf823322010-12-17 14:46:43 +00001245 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001246 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnantcf823322010-12-17 14:46:43 +00001247 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001248 const value_type* data() const _NOEXCEPT {return _VSTD::__to_address(__get_pointer());}
Eric Fiselier4ee2a892017-11-20 20:23:27 +00001249#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
Marshall Clowd3c22392016-03-08 15:44:30 +00001250 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001251 value_type* data() _NOEXCEPT {return _VSTD::__to_address(__get_pointer());}
Marshall Clowd3c22392016-03-08 15:44:30 +00001252#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001253
Howard Hinnantcf823322010-12-17 14:46:43 +00001254 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001255 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001256
Howard Hinnantcf823322010-12-17 14:46:43 +00001257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001258 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001259
1260 template <class _Tp>
1261 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001262 _EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00001263 <
1264 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1265 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001266 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001267 find(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnantd17880b2013-06-28 16:59:19 +00001268 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnantcf823322010-12-17 14:46:43 +00001269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001270 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001271 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001272
Howard Hinnantcf823322010-12-17 14:46:43 +00001273 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001274 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001275
1276 template <class _Tp>
1277 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001278 _EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00001279 <
1280 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1281 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001282 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001283 rfind(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnantd17880b2013-06-28 16:59:19 +00001284 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnantcf823322010-12-17 14:46:43 +00001285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001286 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001287 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001288
Howard Hinnantcf823322010-12-17 14:46:43 +00001289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001290 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001291
1292 template <class _Tp>
1293 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001294 _EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00001295 <
1296 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1297 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001298 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001299 find_first_of(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnantd17880b2013-06-28 16:59:19 +00001300 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnantcf823322010-12-17 14:46:43 +00001301 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001302 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantcf823322010-12-17 14:46:43 +00001303 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001304 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001305
Howard Hinnantcf823322010-12-17 14:46:43 +00001306 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001307 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001308
1309 template <class _Tp>
1310 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001311 _EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00001312 <
1313 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1314 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001315 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001316 find_last_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnantd17880b2013-06-28 16:59:19 +00001317 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnantcf823322010-12-17 14:46:43 +00001318 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001319 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantcf823322010-12-17 14:46:43 +00001320 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001321 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001322
Howard Hinnantcf823322010-12-17 14:46:43 +00001323 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001324 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001325
1326 template <class _Tp>
1327 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001328 _EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00001329 <
1330 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1331 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001332 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001333 find_first_not_of(const _Tp &__t, size_type __pos = 0) const;
Howard Hinnantd17880b2013-06-28 16:59:19 +00001334 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 +00001335 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001336 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001337 _LIBCPP_INLINE_VISIBILITY
1338 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1339
1340 _LIBCPP_INLINE_VISIBILITY
1341 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001342
1343 template <class _Tp>
1344 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001345 _EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00001346 <
1347 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1348 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001349 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001350 find_last_not_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnantd17880b2013-06-28 16:59:19 +00001351 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 +00001352 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd17880b2013-06-28 16:59:19 +00001353 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001354 _LIBCPP_INLINE_VISIBILITY
1355 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1356
1357 _LIBCPP_INLINE_VISIBILITY
1358 int compare(const basic_string& __str) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001359
1360 template <class _Tp>
1361 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001362 _EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00001363 <
1364 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1365 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001366 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001367 compare(const _Tp &__t) const;
1368
1369 template <class _Tp>
1370 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001371 _EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00001372 <
1373 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1374 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001375 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001376 compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
1377
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001378 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001379 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clow8db7fb02014-03-04 19:17:19 +00001380 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 +00001381
Marshall Clow82513342016-09-24 22:45:42 +00001382 template <class _Tp>
Eric Fiselier7d4aa5c2016-10-14 05:29:46 +00001383 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001384 _EnableIf
Marshall Clow82513342016-09-24 22:45:42 +00001385 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001386 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clow82513342016-09-24 22:45:42 +00001387 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001388 >
Marshall Clow82513342016-09-24 22:45:42 +00001389 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 +00001390 int compare(const value_type* __s) const _NOEXCEPT;
1391 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1392 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001393
Marshall Clow18c293b2017-12-04 20:11:38 +00001394#if _LIBCPP_STD_VER > 17
1395 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1396 bool starts_with(__self_view __sv) const _NOEXCEPT
1397 { return __self_view(data(), size()).starts_with(__sv); }
1398
1399 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1400 bool starts_with(value_type __c) const _NOEXCEPT
1401 { return !empty() && _Traits::eq(front(), __c); }
1402
1403 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1404 bool starts_with(const value_type* __s) const _NOEXCEPT
1405 { return starts_with(__self_view(__s)); }
1406
1407 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1408 bool ends_with(__self_view __sv) const _NOEXCEPT
1409 { return __self_view(data(), size()).ends_with( __sv); }
1410
1411 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1412 bool ends_with(value_type __c) const _NOEXCEPT
1413 { return !empty() && _Traits::eq(back(), __c); }
1414
1415 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1416 bool ends_with(const value_type* __s) const _NOEXCEPT
1417 { return ends_with(__self_view(__s)); }
1418#endif
1419
Howard Hinnantcf823322010-12-17 14:46:43 +00001420 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnantaaeb1132013-04-22 23:55:13 +00001421
Marshall Clowe60a7182018-05-29 17:04:37 +00001422 _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT;
Marshall Clow851b9ec2019-05-20 21:56:51 +00001423
Howard Hinnantaaeb1132013-04-22 23:55:13 +00001424 _LIBCPP_INLINE_VISIBILITY
1425 bool __is_long() const _NOEXCEPT
1426 {return bool(__r_.first().__s.__size_ & __short_mask);}
1427
Howard Hinnant8ea98242013-08-23 17:37:05 +00001428#if _LIBCPP_DEBUG_LEVEL >= 2
1429
1430 bool __dereferenceable(const const_iterator* __i) const;
1431 bool __decrementable(const const_iterator* __i) const;
1432 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1433 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1434
1435#endif // _LIBCPP_DEBUG_LEVEL >= 2
1436
Howard Hinnantc51e1022010-05-11 19:42:16 +00001437private:
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001438 _LIBCPP_INLINE_VISIBILITY
1439 allocator_type& __alloc() _NOEXCEPT
1440 {return __r_.second();}
1441 _LIBCPP_INLINE_VISIBILITY
1442 const allocator_type& __alloc() const _NOEXCEPT
1443 {return __r_.second();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +00001445#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +00001446
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001448 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiseliere9cc5922017-10-17 13:16:01 +00001449# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantc51e1022010-05-11 19:42:16 +00001450 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant68bf1812013-04-30 21:44:48 +00001451# else
1452 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1453# endif
1454
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001455 _LIBCPP_INLINE_VISIBILITY
1456 size_type __get_short_size() const _NOEXCEPT
Eric Fiseliere9cc5922017-10-17 13:16:01 +00001457# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantc51e1022010-05-11 19:42:16 +00001458 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant68bf1812013-04-30 21:44:48 +00001459# else
1460 {return __r_.first().__s.__size_;}
1461# endif
1462
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +00001463#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +00001464
1465 _LIBCPP_INLINE_VISIBILITY
1466 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiseliere9cc5922017-10-17 13:16:01 +00001467# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant68bf1812013-04-30 21:44:48 +00001468 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1469# else
1470 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1471# endif
1472
1473 _LIBCPP_INLINE_VISIBILITY
1474 size_type __get_short_size() const _NOEXCEPT
Eric Fiseliere9cc5922017-10-17 13:16:01 +00001475# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant68bf1812013-04-30 21:44:48 +00001476 {return __r_.first().__s.__size_;}
1477# else
1478 {return __r_.first().__s.__size_ >> 1;}
1479# endif
1480
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +00001481#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +00001482
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001483 _LIBCPP_INLINE_VISIBILITY
1484 void __set_long_size(size_type __s) _NOEXCEPT
1485 {__r_.first().__l.__size_ = __s;}
1486 _LIBCPP_INLINE_VISIBILITY
1487 size_type __get_long_size() const _NOEXCEPT
1488 {return __r_.first().__l.__size_;}
1489 _LIBCPP_INLINE_VISIBILITY
1490 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001491 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1492
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001493 _LIBCPP_INLINE_VISIBILITY
1494 void __set_long_cap(size_type __s) _NOEXCEPT
1495 {__r_.first().__l.__cap_ = __long_mask | __s;}
1496 _LIBCPP_INLINE_VISIBILITY
1497 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnant28b24882011-12-01 20:21:04 +00001498 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001499
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001500 _LIBCPP_INLINE_VISIBILITY
1501 void __set_long_pointer(pointer __p) _NOEXCEPT
1502 {__r_.first().__l.__data_ = __p;}
1503 _LIBCPP_INLINE_VISIBILITY
1504 pointer __get_long_pointer() _NOEXCEPT
1505 {return __r_.first().__l.__data_;}
1506 _LIBCPP_INLINE_VISIBILITY
1507 const_pointer __get_long_pointer() const _NOEXCEPT
1508 {return __r_.first().__l.__data_;}
1509 _LIBCPP_INLINE_VISIBILITY
1510 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnantd17880b2013-06-28 16:59:19 +00001511 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001512 _LIBCPP_INLINE_VISIBILITY
1513 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnantd17880b2013-06-28 16:59:19 +00001514 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001515 _LIBCPP_INLINE_VISIBILITY
1516 pointer __get_pointer() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001517 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001518 _LIBCPP_INLINE_VISIBILITY
1519 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001520 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1521
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001522 _LIBCPP_INLINE_VISIBILITY
1523 void __zero() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001524 {
1525 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1526 for (unsigned __i = 0; __i < __n_words; ++__i)
1527 __a[__i] = 0;
1528 }
1529
1530 template <size_type __a> static
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantea382952013-08-14 18:00:20 +00001532 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiselier8599fcc2015-08-28 07:02:42 +00001533 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001534 enum {__alignment = 16};
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001535 static _LIBCPP_INLINE_VISIBILITY
1536 size_type __recommend(size_type __s) _NOEXCEPT
Marshall Clow80584522018-02-07 21:30:17 +00001537 {
1538 if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
1539 size_type __guess = __align_it<sizeof(value_type) < __alignment ?
1540 __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
1541 if (__guess == __min_cap) ++__guess;
1542 return __guess;
1543 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001544
Duncan P. N. Exon Smitheb584632017-04-01 03:20:48 +00001545 inline
Howard Hinnantd17880b2013-06-28 16:59:19 +00001546 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Duncan P. N. Exon Smitheb584632017-04-01 03:20:48 +00001547 inline
Howard Hinnantd17880b2013-06-28 16:59:19 +00001548 void __init(const value_type* __s, size_type __sz);
Duncan P. N. Exon Smitheb584632017-04-01 03:20:48 +00001549 inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001550 void __init(size_type __n, value_type __c);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001551
Howard Hinnantc51e1022010-05-11 19:42:16 +00001552 template <class _InputIterator>
Duncan P. N. Exon Smitheb584632017-04-01 03:20:48 +00001553 inline
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001554 _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00001555 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001556 __is_exactly_cpp17_input_iterator<_InputIterator>::value
1557 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001558 __init(_InputIterator __first, _InputIterator __last);
1559
1560 template <class _ForwardIterator>
Duncan P. N. Exon Smitheb584632017-04-01 03:20:48 +00001561 inline
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001562 _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00001563 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001564 __is_cpp17_forward_iterator<_ForwardIterator>::value
1565 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001566 __init(_ForwardIterator __first, _ForwardIterator __last);
1567
1568 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001569 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001570 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1571 size_type __n_copy, size_type __n_del,
Howard Hinnantd17880b2013-06-28 16:59:19 +00001572 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001573
Martijn Vels596e3de2020-02-26 15:55:49 -05001574 // __assign_no_alias is invoked for assignment operations where we
1575 // have proof that the input does not alias the current instance.
1576 // For example, operator=(basic_string) performs a 'self' check.
1577 template <bool __is_short>
1578 void __assign_no_alias(const value_type* __s, size_type __n);
1579
Howard Hinnantcf823322010-12-17 14:46:43 +00001580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001581 void __erase_to_end(size_type __pos);
1582
Martijn Velsa81fc792020-02-26 13:25:43 -05001583 // __erase_external_with_move is invoked for erase() invocations where
1584 // `n ~= npos`, likely requiring memory moves on the string data.
1585 void __erase_external_with_move(size_type __pos, size_type __n);
1586
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001587 _LIBCPP_INLINE_VISIBILITY
1588 void __copy_assign_alloc(const basic_string& __str)
1589 {__copy_assign_alloc(__str, integral_constant<bool,
1590 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1591
1592 _LIBCPP_INLINE_VISIBILITY
1593 void __copy_assign_alloc(const basic_string& __str, true_type)
1594 {
Marshall Clowf258c202017-01-31 03:40:52 +00001595 if (__alloc() == __str.__alloc())
1596 __alloc() = __str.__alloc();
1597 else
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001598 {
Marshall Clowf258c202017-01-31 03:40:52 +00001599 if (!__str.__is_long())
1600 {
Vedant Kumar55e007e2018-03-08 21:15:26 +00001601 __clear_and_shrink();
Marshall Clowf258c202017-01-31 03:40:52 +00001602 __alloc() = __str.__alloc();
1603 }
1604 else
1605 {
1606 allocator_type __a = __str.__alloc();
1607 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
Vedant Kumar55e007e2018-03-08 21:15:26 +00001608 __clear_and_shrink();
Marshall Clowf258c202017-01-31 03:40:52 +00001609 __alloc() = _VSTD::move(__a);
1610 __set_long_pointer(__p);
1611 __set_long_cap(__str.__get_long_cap());
1612 __set_long_size(__str.size());
1613 }
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001614 }
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001615 }
1616
1617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant28b24882011-12-01 20:21:04 +00001618 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001619 {}
1620
Eric Fiselierfc92be82017-04-19 00:28:44 +00001621#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantcf823322010-12-17 14:46:43 +00001622 _LIBCPP_INLINE_VISIBILITY
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00001623 void __move_assign(basic_string& __str, false_type)
1624 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnantcf823322010-12-17 14:46:43 +00001625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e276872011-06-03 18:40:47 +00001626 void __move_assign(basic_string& __str, true_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00001627#if _LIBCPP_STD_VER > 14
1628 _NOEXCEPT;
1629#else
Howard Hinnant3e276872011-06-03 18:40:47 +00001630 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001631#endif
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00001632#endif
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001633
1634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001635 void
Howard Hinnantc2734962011-09-02 20:42:31 +00001636 __move_assign_alloc(basic_string& __str)
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001637 _NOEXCEPT_(
1638 !__alloc_traits::propagate_on_container_move_assignment::value ||
1639 is_nothrow_move_assignable<allocator_type>::value)
1640 {__move_assign_alloc(__str, integral_constant<bool,
1641 __alloc_traits::propagate_on_container_move_assignment::value>());}
1642
1643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc2734962011-09-02 20:42:31 +00001644 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001645 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1646 {
1647 __alloc() = _VSTD::move(__c.__alloc());
1648 }
1649
1650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant28b24882011-12-01 20:21:04 +00001651 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001652 _NOEXCEPT
1653 {}
1654
Howard Hinnantcf823322010-12-17 14:46:43 +00001655 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1656 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001657
1658 friend basic_string operator+<>(const basic_string&, const basic_string&);
1659 friend basic_string operator+<>(const value_type*, const basic_string&);
1660 friend basic_string operator+<>(value_type, const basic_string&);
1661 friend basic_string operator+<>(const basic_string&, const value_type*);
1662 friend basic_string operator+<>(const basic_string&, value_type);
1663};
1664
Eric Fiselier2ed640b2020-03-04 13:54:04 -05001665// These declarations must appear before any functions are implicitly used
1666// so that they have the correct visibility specifier.
1667#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
1668_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1669_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1670#else
1671_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1672_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1673#endif
1674
1675
Marshall Clowa0563332018-02-08 06:34:03 +00001676#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1677template<class _InputIterator,
1678 class _CharT = typename iterator_traits<_InputIterator>::value_type,
1679 class _Allocator = allocator<_CharT>,
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001680 class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value>,
1681 class = _EnableIf<__is_allocator<_Allocator>::value>
Marshall Clowa0563332018-02-08 06:34:03 +00001682 >
1683basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
1684 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
Marshall Clowe46031a2018-07-02 18:41:15 +00001685
1686template<class _CharT,
1687 class _Traits,
1688 class _Allocator = allocator<_CharT>,
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001689 class = _EnableIf<__is_allocator<_Allocator>::value>
Marshall Clowe46031a2018-07-02 18:41:15 +00001690 >
1691explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
1692 -> basic_string<_CharT, _Traits, _Allocator>;
1693
1694template<class _CharT,
1695 class _Traits,
1696 class _Allocator = allocator<_CharT>,
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001697 class = _EnableIf<__is_allocator<_Allocator>::value>,
Marshall Clowe46031a2018-07-02 18:41:15 +00001698 class _Sz = typename allocator_traits<_Allocator>::size_type
1699 >
1700basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
1701 -> basic_string<_CharT, _Traits, _Allocator>;
Marshall Clowa0563332018-02-08 06:34:03 +00001702#endif
1703
Howard Hinnantc51e1022010-05-11 19:42:16 +00001704template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001705inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001706void
1707basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1708{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001709#if _LIBCPP_DEBUG_LEVEL >= 2
1710 __get_db()->__invalidate_all(this);
1711#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantc51e1022010-05-11 19:42:16 +00001712}
1713
1714template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001715inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001716void
Howard Hinnant28b24882011-12-01 20:21:04 +00001717basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant8ea98242013-08-23 17:37:05 +00001718#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant28b24882011-12-01 20:21:04 +00001719 __pos
1720#endif
1721 )
Howard Hinnantc51e1022010-05-11 19:42:16 +00001722{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001723#if _LIBCPP_DEBUG_LEVEL >= 2
1724 __c_node* __c = __get_db()->__find_c_and_lock(this);
1725 if (__c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001726 {
Howard Hinnant8ea98242013-08-23 17:37:05 +00001727 const_pointer __new_last = __get_pointer() + __pos;
1728 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantc51e1022010-05-11 19:42:16 +00001729 {
Howard Hinnant8ea98242013-08-23 17:37:05 +00001730 --__p;
1731 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1732 if (__i->base() > __new_last)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001733 {
Howard Hinnant8ea98242013-08-23 17:37:05 +00001734 (*__p)->__c_ = nullptr;
1735 if (--__c->end_ != __p)
1736 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001737 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001738 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001739 __get_db()->unlock();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001740 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001741#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantc51e1022010-05-11 19:42:16 +00001742}
1743
1744template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001745inline
Howard Hinnant3e276872011-06-03 18:40:47 +00001746basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowe546cbb2015-06-04 02:05:41 +00001747 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001748 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001749{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001750#if _LIBCPP_DEBUG_LEVEL >= 2
1751 __get_db()->__insert_c(this);
1752#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001753 __zero();
1754}
1755
1756template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001757inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001758basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiseliere012bf22015-07-18 20:40:46 +00001759#if _LIBCPP_STD_VER <= 14
1760 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1761#else
1762 _NOEXCEPT
1763#endif
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001764: __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001765{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001766#if _LIBCPP_DEBUG_LEVEL >= 2
1767 __get_db()->__insert_c(this);
1768#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001769 __zero();
1770}
1771
1772template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier815ed732016-09-16 00:00:48 +00001773void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1774 size_type __sz,
1775 size_type __reserve)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001776{
1777 if (__reserve > max_size())
1778 this->__throw_length_error();
1779 pointer __p;
1780 if (__reserve < __min_cap)
1781 {
1782 __set_short_size(__sz);
1783 __p = __get_short_pointer();
1784 }
1785 else
1786 {
1787 size_type __cap = __recommend(__reserve);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001788 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001789 __set_long_pointer(__p);
1790 __set_long_cap(__cap+1);
1791 __set_long_size(__sz);
1792 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001793 traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001794 traits_type::assign(__p[__sz], value_type());
1795}
1796
1797template <class _CharT, class _Traits, class _Allocator>
1798void
Howard Hinnantd17880b2013-06-28 16:59:19 +00001799basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001800{
1801 if (__sz > max_size())
1802 this->__throw_length_error();
1803 pointer __p;
1804 if (__sz < __min_cap)
1805 {
1806 __set_short_size(__sz);
1807 __p = __get_short_pointer();
1808 }
1809 else
1810 {
1811 size_type __cap = __recommend(__sz);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001812 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001813 __set_long_pointer(__p);
1814 __set_long_cap(__cap+1);
1815 __set_long_size(__sz);
1816 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001817 traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001818 traits_type::assign(__p[__sz], value_type());
1819}
1820
1821template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00001822template <class>
Eric Fiselier812882b2017-02-17 01:17:10 +00001823basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001824 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001825{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001826 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001827 __init(__s, traits_type::length(__s));
Howard Hinnant8ea98242013-08-23 17:37:05 +00001828#if _LIBCPP_DEBUG_LEVEL >= 2
1829 __get_db()->__insert_c(this);
1830#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001831}
1832
1833template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001834inline
Eric Fiselier812882b2017-02-17 01:17:10 +00001835basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001836 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001837{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001838 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001839 __init(__s, __n);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001840#if _LIBCPP_DEBUG_LEVEL >= 2
1841 __get_db()->__insert_c(this);
1842#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001843}
1844
1845template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001846inline
Eric Fiselier812882b2017-02-17 01:17:10 +00001847basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001848 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001849{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001850 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001851 __init(__s, __n);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001852#if _LIBCPP_DEBUG_LEVEL >= 2
1853 __get_db()->__insert_c(this);
1854#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001855}
1856
1857template <class _CharT, class _Traits, class _Allocator>
1858basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001859 : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001860{
1861 if (!__str.__is_long())
1862 __r_.first().__r = __str.__r_.first().__r;
1863 else
Martijn Velsad633422020-03-04 14:51:21 -05001864 __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant8ea98242013-08-23 17:37:05 +00001865#if _LIBCPP_DEBUG_LEVEL >= 2
1866 __get_db()->__insert_c(this);
1867#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001868}
1869
1870template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier812882b2017-02-17 01:17:10 +00001871basic_string<_CharT, _Traits, _Allocator>::basic_string(
1872 const basic_string& __str, const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001873 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001874{
1875 if (!__str.__is_long())
1876 __r_.first().__r = __str.__r_.first().__r;
1877 else
Martijn Velsad633422020-03-04 14:51:21 -05001878 __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant8ea98242013-08-23 17:37:05 +00001879#if _LIBCPP_DEBUG_LEVEL >= 2
1880 __get_db()->__insert_c(this);
1881#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001882}
1883
Eric Fiselierfc92be82017-04-19 00:28:44 +00001884#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001885
1886template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001887inline
Howard Hinnant3e276872011-06-03 18:40:47 +00001888basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clowa80abc72015-06-03 19:56:43 +00001889#if _LIBCPP_STD_VER <= 14
Howard Hinnant3e276872011-06-03 18:40:47 +00001890 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clowa80abc72015-06-03 19:56:43 +00001891#else
1892 _NOEXCEPT
1893#endif
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001894 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001895{
1896 __str.__zero();
Howard Hinnant8ea98242013-08-23 17:37:05 +00001897#if _LIBCPP_DEBUG_LEVEL >= 2
1898 __get_db()->__insert_c(this);
1899 if (__is_long())
1900 __get_db()->swap(this, &__str);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001901#endif
1902}
1903
1904template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001905inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001906basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001907 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001908{
Marshall Clowd2d24692014-07-17 15:32:20 +00001909 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001910 __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd2d24692014-07-17 15:32:20 +00001911 else
1912 {
1913 __r_.first().__r = __str.__r_.first().__r;
1914 __str.__zero();
1915 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001916#if _LIBCPP_DEBUG_LEVEL >= 2
1917 __get_db()->__insert_c(this);
1918 if (__is_long())
1919 __get_db()->swap(this, &__str);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001920#endif
1921}
1922
Eric Fiselierfc92be82017-04-19 00:28:44 +00001923#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001924
1925template <class _CharT, class _Traits, class _Allocator>
1926void
1927basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1928{
1929 if (__n > max_size())
1930 this->__throw_length_error();
1931 pointer __p;
1932 if (__n < __min_cap)
1933 {
1934 __set_short_size(__n);
1935 __p = __get_short_pointer();
1936 }
1937 else
1938 {
1939 size_type __cap = __recommend(__n);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001940 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001941 __set_long_pointer(__p);
1942 __set_long_cap(__cap+1);
1943 __set_long_size(__n);
1944 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001945 traits_type::assign(_VSTD::__to_address(__p), __n, __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001946 traits_type::assign(__p[__n], value_type());
1947}
1948
1949template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001950inline
Eric Fiselier812882b2017-02-17 01:17:10 +00001951basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001952 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001953{
1954 __init(__n, __c);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001955#if _LIBCPP_DEBUG_LEVEL >= 2
1956 __get_db()->__insert_c(this);
1957#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001958}
1959
1960template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00001961template <class>
Eric Fiselier812882b2017-02-17 01:17:10 +00001962basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001963 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001964{
1965 __init(__n, __c);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001966#if _LIBCPP_DEBUG_LEVEL >= 2
1967 __get_db()->__insert_c(this);
1968#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001969}
1970
Howard Hinnantc51e1022010-05-11 19:42:16 +00001971template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier812882b2017-02-17 01:17:10 +00001972basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1973 size_type __pos, size_type __n,
1974 const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001975 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001976{
1977 size_type __str_sz = __str.size();
1978 if (__pos > __str_sz)
1979 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001980 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant8ea98242013-08-23 17:37:05 +00001981#if _LIBCPP_DEBUG_LEVEL >= 2
1982 __get_db()->__insert_c(this);
1983#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001984}
1985
1986template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001987inline
Marshall Clow83445802016-04-07 18:13:41 +00001988basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier812882b2017-02-17 01:17:10 +00001989 const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001990 : __r_(__default_init_tag(), __a)
Marshall Clow83445802016-04-07 18:13:41 +00001991{
1992 size_type __str_sz = __str.size();
1993 if (__pos > __str_sz)
1994 this->__throw_out_of_range();
1995 __init(__str.data() + __pos, __str_sz - __pos);
1996#if _LIBCPP_DEBUG_LEVEL >= 2
1997 __get_db()->__insert_c(this);
1998#endif
1999}
2000
2001template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002002template <class _Tp, class>
Marshall Clow78dbe462016-11-14 18:22:19 +00002003basic_string<_CharT, _Traits, _Allocator>::basic_string(
Marshall Clowe46031a2018-07-02 18:41:15 +00002004 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002005 : __r_(__default_init_tag(), __a)
Marshall Clow78dbe462016-11-14 18:22:19 +00002006{
Marshall Clowe46031a2018-07-02 18:41:15 +00002007 __self_view __sv0 = __t;
2008 __self_view __sv = __sv0.substr(__pos, __n);
Marshall Clow78dbe462016-11-14 18:22:19 +00002009 __init(__sv.data(), __sv.size());
2010#if _LIBCPP_DEBUG_LEVEL >= 2
2011 __get_db()->__insert_c(this);
Eric Fiselier812882b2017-02-17 01:17:10 +00002012#endif
Marshall Clow78dbe462016-11-14 18:22:19 +00002013}
2014
2015template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002016template <class _Tp, class>
2017basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002018 : __r_(__default_init_tag(), __default_init_tag())
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002019{
Marshall Clowe46031a2018-07-02 18:41:15 +00002020 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002021 __init(__sv.data(), __sv.size());
2022#if _LIBCPP_DEBUG_LEVEL >= 2
2023 __get_db()->__insert_c(this);
2024#endif
2025}
2026
2027template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002028template <class _Tp, class>
2029basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002030 : __r_(__default_init_tag(), __a)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002031{
Marshall Clowe46031a2018-07-02 18:41:15 +00002032 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002033 __init(__sv.data(), __sv.size());
2034#if _LIBCPP_DEBUG_LEVEL >= 2
2035 __get_db()->__insert_c(this);
2036#endif
2037}
2038
2039template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002040template <class _InputIterator>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002041_EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002042<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002043 __is_exactly_cpp17_input_iterator<_InputIterator>::value
2044>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002045basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2046{
2047 __zero();
2048#ifndef _LIBCPP_NO_EXCEPTIONS
2049 try
2050 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002051#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002052 for (; __first != __last; ++__first)
2053 push_back(*__first);
2054#ifndef _LIBCPP_NO_EXCEPTIONS
2055 }
2056 catch (...)
2057 {
2058 if (__is_long())
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002059 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002060 throw;
2061 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002062#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002063}
2064
2065template <class _CharT, class _Traits, class _Allocator>
2066template <class _ForwardIterator>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002067_EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002068<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002069 __is_cpp17_forward_iterator<_ForwardIterator>::value
2070>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002071basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2072{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002073 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002074 if (__sz > max_size())
2075 this->__throw_length_error();
2076 pointer __p;
2077 if (__sz < __min_cap)
2078 {
2079 __set_short_size(__sz);
2080 __p = __get_short_pointer();
2081 }
2082 else
2083 {
2084 size_type __cap = __recommend(__sz);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002085 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002086 __set_long_pointer(__p);
2087 __set_long_cap(__cap+1);
2088 __set_long_size(__sz);
2089 }
Eric Fiseliera09a3b42014-10-27 19:28:20 +00002090 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002091 traits_type::assign(*__p, *__first);
2092 traits_type::assign(*__p, value_type());
2093}
2094
2095template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierc0f566d2019-03-14 12:31:10 +00002096template<class _InputIterator, class>
Eric Fiselierbea70602018-11-26 22:51:35 +00002097inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002098basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002099 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00002100{
2101 __init(__first, __last);
Howard Hinnant8ea98242013-08-23 17:37:05 +00002102#if _LIBCPP_DEBUG_LEVEL >= 2
2103 __get_db()->__insert_c(this);
2104#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002105}
2106
2107template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierc0f566d2019-03-14 12:31:10 +00002108template<class _InputIterator, class>
Eric Fiselierbea70602018-11-26 22:51:35 +00002109inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002110basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2111 const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002112 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002113{
2114 __init(__first, __last);
Howard Hinnant8ea98242013-08-23 17:37:05 +00002115#if _LIBCPP_DEBUG_LEVEL >= 2
2116 __get_db()->__insert_c(this);
2117#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002118}
2119
Eric Fiselierfc92be82017-04-19 00:28:44 +00002120#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant33711792011-08-12 21:56:02 +00002121
Howard Hinnantc51e1022010-05-11 19:42:16 +00002122template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002123inline
Eric Fiselier812882b2017-02-17 01:17:10 +00002124basic_string<_CharT, _Traits, _Allocator>::basic_string(
2125 initializer_list<_CharT> __il)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002126 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00002127{
2128 __init(__il.begin(), __il.end());
Howard Hinnant8ea98242013-08-23 17:37:05 +00002129#if _LIBCPP_DEBUG_LEVEL >= 2
2130 __get_db()->__insert_c(this);
2131#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002132}
2133
2134template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002135inline
Eric Fiselier9d355982017-04-12 23:45:53 +00002136
Eric Fiselier812882b2017-02-17 01:17:10 +00002137basic_string<_CharT, _Traits, _Allocator>::basic_string(
2138 initializer_list<_CharT> __il, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002139 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002140{
2141 __init(__il.begin(), __il.end());
Howard Hinnant8ea98242013-08-23 17:37:05 +00002142#if _LIBCPP_DEBUG_LEVEL >= 2
2143 __get_db()->__insert_c(this);
2144#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002145}
2146
Eric Fiselierfc92be82017-04-19 00:28:44 +00002147#endif // _LIBCPP_CXX03_LANG
Howard Hinnant33711792011-08-12 21:56:02 +00002148
Howard Hinnantc51e1022010-05-11 19:42:16 +00002149template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002150basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2151{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002152#if _LIBCPP_DEBUG_LEVEL >= 2
2153 __get_db()->__erase_c(this);
2154#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002155 if (__is_long())
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002156 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002157}
2158
2159template <class _CharT, class _Traits, class _Allocator>
2160void
2161basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2162 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnantd17880b2013-06-28 16:59:19 +00002163 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 +00002164{
2165 size_type __ms = max_size();
2166 if (__delta_cap > __ms - __old_cap - 1)
2167 this->__throw_length_error();
2168 pointer __old_p = __get_pointer();
2169 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002170 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantc51e1022010-05-11 19:42:16 +00002171 __ms - 1;
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002172 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002173 __invalidate_all_iterators();
2174 if (__n_copy != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002175 traits_type::copy(_VSTD::__to_address(__p),
2176 _VSTD::__to_address(__old_p), __n_copy);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002177 if (__n_add != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002178 traits_type::copy(_VSTD::__to_address(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002179 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2180 if (__sec_cp_sz != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002181 traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2182 _VSTD::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002183 if (__old_cap+1 != __min_cap)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002184 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002185 __set_long_pointer(__p);
2186 __set_long_cap(__cap+1);
2187 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2188 __set_long_size(__old_sz);
2189 traits_type::assign(__p[__old_sz], value_type());
2190}
2191
2192template <class _CharT, class _Traits, class _Allocator>
2193void
2194basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2195 size_type __n_copy, size_type __n_del, size_type __n_add)
2196{
2197 size_type __ms = max_size();
Marshall Clow2267c5d2013-11-06 14:24:38 +00002198 if (__delta_cap > __ms - __old_cap)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002199 this->__throw_length_error();
2200 pointer __old_p = __get_pointer();
2201 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002202 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantc51e1022010-05-11 19:42:16 +00002203 __ms - 1;
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002204 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002205 __invalidate_all_iterators();
2206 if (__n_copy != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002207 traits_type::copy(_VSTD::__to_address(__p),
2208 _VSTD::__to_address(__old_p), __n_copy);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002209 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2210 if (__sec_cp_sz != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002211 traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2212 _VSTD::__to_address(__old_p) + __n_copy + __n_del,
Howard Hinnantd17880b2013-06-28 16:59:19 +00002213 __sec_cp_sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002214 if (__old_cap+1 != __min_cap)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002215 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002216 __set_long_pointer(__p);
2217 __set_long_cap(__cap+1);
2218}
2219
2220// assign
2221
2222template <class _CharT, class _Traits, class _Allocator>
Martijn Vels596e3de2020-02-26 15:55:49 -05002223template <bool __is_short>
2224void basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(
2225 const value_type* __s, size_type __n) {
2226 size_type __cap = __is_short ? __min_cap : __get_long_cap();
2227 if (__n < __cap) {
2228 pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer();
2229 __is_short ? __set_short_size(__n) : __set_long_size(__n);
2230 traits_type::copy(_VSTD::__to_address(__p), __s, __n);
2231 traits_type::assign(__p[__n], value_type());
2232 __invalidate_iterators_past(__n);
2233 } else {
2234 size_type __sz = __is_short ? __get_short_size() : __get_long_size();
2235 __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s);
2236 }
2237}
2238
2239template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002240basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002241basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002242{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002243 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002244 size_type __cap = capacity();
2245 if (__cap >= __n)
2246 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002247 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002248 traits_type::move(__p, __s, __n);
2249 traits_type::assign(__p[__n], value_type());
2250 __set_size(__n);
2251 __invalidate_iterators_past(__n);
2252 }
2253 else
2254 {
2255 size_type __sz = size();
2256 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2257 }
2258 return *this;
2259}
2260
2261template <class _CharT, class _Traits, class _Allocator>
2262basic_string<_CharT, _Traits, _Allocator>&
2263basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2264{
2265 size_type __cap = capacity();
2266 if (__cap < __n)
2267 {
2268 size_type __sz = size();
2269 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2270 }
2271 else
2272 __invalidate_iterators_past(__n);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002273 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002274 traits_type::assign(__p, __n, __c);
2275 traits_type::assign(__p[__n], value_type());
2276 __set_size(__n);
2277 return *this;
2278}
2279
2280template <class _CharT, class _Traits, class _Allocator>
2281basic_string<_CharT, _Traits, _Allocator>&
2282basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2283{
2284 pointer __p;
2285 if (__is_long())
2286 {
2287 __p = __get_long_pointer();
2288 __set_long_size(1);
2289 }
2290 else
2291 {
2292 __p = __get_short_pointer();
2293 __set_short_size(1);
2294 }
2295 traits_type::assign(*__p, __c);
2296 traits_type::assign(*++__p, value_type());
2297 __invalidate_iterators_past(1);
2298 return *this;
2299}
2300
2301template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002302basic_string<_CharT, _Traits, _Allocator>&
2303basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2304{
Martijn Vels596e3de2020-02-26 15:55:49 -05002305 if (this != &__str) {
2306 __copy_assign_alloc(__str);
2307 if (!__is_long()) {
2308 if (!__str.__is_long()) {
Eric Fiselier03bbc922020-01-15 17:27:10 -05002309 __r_.first().__r = __str.__r_.first().__r;
Martijn Vels596e3de2020-02-26 15:55:49 -05002310 } else {
2311 __assign_no_alias<true>(__str.data(), __str.size());
2312 }
2313 } else {
2314 __assign_no_alias<false>(__str.data(), __str.size());
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002315 }
Martijn Vels596e3de2020-02-26 15:55:49 -05002316 }
2317 return *this;
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002318}
2319
Eric Fiselierfc92be82017-04-19 00:28:44 +00002320#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002321
2322template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002323inline
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002324void
2325basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002326 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002327{
2328 if (__alloc() != __str.__alloc())
2329 assign(__str);
2330 else
2331 __move_assign(__str, true_type());
2332}
2333
2334template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002335inline
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002336void
2337basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002338#if _LIBCPP_STD_VER > 14
2339 _NOEXCEPT
2340#else
Howard Hinnant3e276872011-06-03 18:40:47 +00002341 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002342#endif
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002343{
marshall2ed41622019-11-27 07:13:00 -08002344 if (__is_long()) {
2345 __alloc_traits::deallocate(__alloc(), __get_long_pointer(),
2346 __get_long_cap());
2347#if _LIBCPP_STD_VER <= 14
2348 if (!is_nothrow_move_assignable<allocator_type>::value) {
2349 __set_short_size(0);
2350 traits_type::assign(__get_short_pointer()[0], value_type());
2351 }
2352#endif
2353 }
2354 __move_assign_alloc(__str);
2355 __r_.first() = __str.__r_.first();
2356 __str.__set_short_size(0);
2357 traits_type::assign(__str.__get_short_pointer()[0], value_type());
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002358}
2359
2360template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002361inline
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002362basic_string<_CharT, _Traits, _Allocator>&
2363basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002364 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002365{
2366 __move_assign(__str, integral_constant<bool,
2367 __alloc_traits::propagate_on_container_move_assignment::value>());
2368 return *this;
2369}
2370
2371#endif
2372
2373template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002374template<class _InputIterator>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002375_EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002376<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002377 __is_exactly_cpp17_input_iterator <_InputIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002378 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002379 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002380>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002381basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2382{
Marshall Clow958362f2016-09-05 01:54:30 +00002383 const basic_string __temp(__first, __last, __alloc());
Marshall Clow039b2f02016-01-13 21:54:34 +00002384 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002385 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002386}
2387
2388template <class _CharT, class _Traits, class _Allocator>
2389template<class _ForwardIterator>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002390_EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002391<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002392 __is_cpp17_forward_iterator<_ForwardIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002393 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002394 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002395>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002396basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2397{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002398 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002399 size_type __cap = capacity();
2400 if (__cap < __n)
2401 {
2402 size_type __sz = size();
2403 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2404 }
2405 else
2406 __invalidate_iterators_past(__n);
2407 pointer __p = __get_pointer();
2408 for (; __first != __last; ++__first, ++__p)
2409 traits_type::assign(*__p, *__first);
2410 traits_type::assign(*__p, value_type());
2411 __set_size(__n);
2412 return *this;
2413}
2414
2415template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002416basic_string<_CharT, _Traits, _Allocator>&
2417basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2418{
2419 size_type __sz = __str.size();
2420 if (__pos > __sz)
2421 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002422 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002423}
2424
2425template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00002426template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002427_EnableIf
Marshall Clow82513342016-09-24 22:45:42 +00002428<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002429 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
2430 && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00002431 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002432>
Marshall Clow82513342016-09-24 22:45:42 +00002433basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002434{
Marshall Clow82513342016-09-24 22:45:42 +00002435 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002436 size_type __sz = __sv.size();
2437 if (__pos > __sz)
2438 this->__throw_out_of_range();
2439 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2440}
2441
2442
2443template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002444basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002445basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002446{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002447 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002448 return assign(__s, traits_type::length(__s));
2449}
2450
2451// append
2452
2453template <class _CharT, class _Traits, class _Allocator>
2454basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002455basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002456{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002457 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002458 size_type __cap = capacity();
2459 size_type __sz = size();
2460 if (__cap - __sz >= __n)
2461 {
2462 if (__n)
2463 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002464 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002465 traits_type::copy(__p + __sz, __s, __n);
2466 __sz += __n;
2467 __set_size(__sz);
2468 traits_type::assign(__p[__sz], value_type());
2469 }
2470 }
2471 else
2472 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2473 return *this;
2474}
2475
2476template <class _CharT, class _Traits, class _Allocator>
2477basic_string<_CharT, _Traits, _Allocator>&
2478basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2479{
2480 if (__n)
2481 {
2482 size_type __cap = capacity();
2483 size_type __sz = size();
2484 if (__cap - __sz < __n)
2485 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2486 pointer __p = __get_pointer();
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002487 traits_type::assign(_VSTD::__to_address(__p) + __sz, __n, __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002488 __sz += __n;
2489 __set_size(__sz);
2490 traits_type::assign(__p[__sz], value_type());
2491 }
2492 return *this;
2493}
2494
2495template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier451d5582018-11-26 20:15:38 +00002496inline void
2497basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
2498{
2499 if (__n)
2500 {
2501 size_type __cap = capacity();
2502 size_type __sz = size();
2503 if (__cap - __sz < __n)
2504 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2505 pointer __p = __get_pointer();
2506 __sz += __n;
2507 __set_size(__sz);
2508 traits_type::assign(__p[__sz], value_type());
2509 }
2510}
2511
2512template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002513void
2514basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2515{
Howard Hinnant68bf1812013-04-30 21:44:48 +00002516 bool __is_short = !__is_long();
2517 size_type __cap;
2518 size_type __sz;
2519 if (__is_short)
2520 {
2521 __cap = __min_cap - 1;
2522 __sz = __get_short_size();
2523 }
2524 else
2525 {
2526 __cap = __get_long_cap() - 1;
2527 __sz = __get_long_size();
2528 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002529 if (__sz == __cap)
Howard Hinnant68bf1812013-04-30 21:44:48 +00002530 {
Howard Hinnantc51e1022010-05-11 19:42:16 +00002531 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant68bf1812013-04-30 21:44:48 +00002532 __is_short = !__is_long();
2533 }
2534 pointer __p;
2535 if (__is_short)
2536 {
2537 __p = __get_short_pointer() + __sz;
2538 __set_short_size(__sz+1);
2539 }
2540 else
2541 {
2542 __p = __get_long_pointer() + __sz;
2543 __set_long_size(__sz+1);
2544 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002545 traits_type::assign(*__p, __c);
2546 traits_type::assign(*++__p, value_type());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002547}
2548
Marshall Clow6ebbf662016-09-07 03:32:06 +00002549template <class _Tp>
Marshall Clow958362f2016-09-05 01:54:30 +00002550bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2551{
2552 return __first <= __p && __p < __last;
2553}
2554
Marshall Clow6ebbf662016-09-07 03:32:06 +00002555template <class _Tp1, class _Tp2>
Eric Fiselier6003c772016-12-23 23:37:52 +00002556bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
Marshall Clow6ebbf662016-09-07 03:32:06 +00002557{
2558 return false;
2559}
2560
Howard Hinnantc51e1022010-05-11 19:42:16 +00002561template <class _CharT, class _Traits, class _Allocator>
2562template<class _ForwardIterator>
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00002563basic_string<_CharT, _Traits, _Allocator>&
2564basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2565 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002566{
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002567 static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00002568 "function requires a ForwardIterator");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002569 size_type __sz = size();
2570 size_type __cap = capacity();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002571 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002572 if (__n)
2573 {
Eric Fiselier96866b52017-04-15 06:49:02 +00002574 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2575 _CharRef __tmp_ref = *__first;
2576 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
Marshall Clow958362f2016-09-05 01:54:30 +00002577 {
2578 const basic_string __temp (__first, __last, __alloc());
2579 append(__temp.data(), __temp.size());
2580 }
Louis Dionne173f29e2019-05-29 16:01:36 +00002581 else
Marshall Clow958362f2016-09-05 01:54:30 +00002582 {
2583 if (__cap - __sz < __n)
2584 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2585 pointer __p = __get_pointer() + __sz;
2586 for (; __first != __last; ++__p, ++__first)
2587 traits_type::assign(*__p, *__first);
2588 traits_type::assign(*__p, value_type());
2589 __set_size(__sz + __n);
2590 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002591 }
2592 return *this;
2593}
2594
2595template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002596inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002597basic_string<_CharT, _Traits, _Allocator>&
2598basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2599{
2600 return append(__str.data(), __str.size());
2601}
2602
2603template <class _CharT, class _Traits, class _Allocator>
2604basic_string<_CharT, _Traits, _Allocator>&
2605basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2606{
2607 size_type __sz = __str.size();
2608 if (__pos > __sz)
2609 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002610 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002611}
2612
2613template <class _CharT, class _Traits, class _Allocator>
Marshall Clow62953962016-10-03 23:40:48 +00002614template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002615 _EnableIf
Marshall Clow82513342016-09-24 22:45:42 +00002616 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002617 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
Marshall Clow82513342016-09-24 22:45:42 +00002618 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002619 >
Marshall Clow82513342016-09-24 22:45:42 +00002620basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002621{
Marshall Clow82513342016-09-24 22:45:42 +00002622 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002623 size_type __sz = __sv.size();
2624 if (__pos > __sz)
2625 this->__throw_out_of_range();
2626 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2627}
2628
2629template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002630basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002631basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002632{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002633 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002634 return append(__s, traits_type::length(__s));
2635}
2636
2637// insert
2638
2639template <class _CharT, class _Traits, class _Allocator>
2640basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002641basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002642{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002643 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002644 size_type __sz = size();
2645 if (__pos > __sz)
2646 this->__throw_out_of_range();
2647 size_type __cap = capacity();
2648 if (__cap - __sz >= __n)
2649 {
2650 if (__n)
2651 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002652 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002653 size_type __n_move = __sz - __pos;
2654 if (__n_move != 0)
2655 {
2656 if (__p + __pos <= __s && __s < __p + __sz)
2657 __s += __n;
2658 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2659 }
2660 traits_type::move(__p + __pos, __s, __n);
2661 __sz += __n;
2662 __set_size(__sz);
2663 traits_type::assign(__p[__sz], value_type());
2664 }
2665 }
2666 else
2667 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2668 return *this;
2669}
2670
2671template <class _CharT, class _Traits, class _Allocator>
2672basic_string<_CharT, _Traits, _Allocator>&
2673basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2674{
2675 size_type __sz = size();
2676 if (__pos > __sz)
2677 this->__throw_out_of_range();
2678 if (__n)
2679 {
2680 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002681 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002682 if (__cap - __sz >= __n)
2683 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002684 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002685 size_type __n_move = __sz - __pos;
2686 if (__n_move != 0)
2687 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2688 }
2689 else
2690 {
2691 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002692 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002693 }
2694 traits_type::assign(__p + __pos, __n, __c);
2695 __sz += __n;
2696 __set_size(__sz);
2697 traits_type::assign(__p[__sz], value_type());
2698 }
2699 return *this;
2700}
2701
2702template <class _CharT, class _Traits, class _Allocator>
2703template<class _InputIterator>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002704_EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002705<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002706 __is_exactly_cpp17_input_iterator<_InputIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002707 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2708 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002709>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002710basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2711{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002712#if _LIBCPP_DEBUG_LEVEL >= 2
2713 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2714 "string::insert(iterator, range) called with an iterator not"
2715 " referring to this string");
2716#endif
Marshall Clow958362f2016-09-05 01:54:30 +00002717 const basic_string __temp(__first, __last, __alloc());
Marshall Clow039b2f02016-01-13 21:54:34 +00002718 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002719}
2720
2721template <class _CharT, class _Traits, class _Allocator>
2722template<class _ForwardIterator>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002723_EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002724<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002725 __is_cpp17_forward_iterator<_ForwardIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002726 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002727 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002728>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002729basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2730{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002731#if _LIBCPP_DEBUG_LEVEL >= 2
2732 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2733 "string::insert(iterator, range) called with an iterator not"
2734 " referring to this string");
2735#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002736 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002737 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002738 if (__n)
2739 {
Eric Fiselier96866b52017-04-15 06:49:02 +00002740 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2741 _CharRef __tmp_char = *__first;
2742 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
Marshall Clow958362f2016-09-05 01:54:30 +00002743 {
2744 const basic_string __temp(__first, __last, __alloc());
2745 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2746 }
2747
2748 size_type __sz = size();
2749 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002750 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002751 if (__cap - __sz >= __n)
2752 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002753 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002754 size_type __n_move = __sz - __ip;
2755 if (__n_move != 0)
2756 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2757 }
2758 else
2759 {
2760 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002761 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002762 }
2763 __sz += __n;
2764 __set_size(__sz);
2765 traits_type::assign(__p[__sz], value_type());
2766 for (__p += __ip; __first != __last; ++__p, ++__first)
2767 traits_type::assign(*__p, *__first);
2768 }
2769 return begin() + __ip;
2770}
2771
2772template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002773inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002774basic_string<_CharT, _Traits, _Allocator>&
2775basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2776{
2777 return insert(__pos1, __str.data(), __str.size());
2778}
2779
2780template <class _CharT, class _Traits, class _Allocator>
2781basic_string<_CharT, _Traits, _Allocator>&
2782basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2783 size_type __pos2, size_type __n)
2784{
2785 size_type __str_sz = __str.size();
2786 if (__pos2 > __str_sz)
2787 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002788 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002789}
2790
2791template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00002792template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002793_EnableIf
Marshall Clow82513342016-09-24 22:45:42 +00002794<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002795 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00002796 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002797>
Marshall Clow82513342016-09-24 22:45:42 +00002798basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002799 size_type __pos2, size_type __n)
2800{
Marshall Clow82513342016-09-24 22:45:42 +00002801 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002802 size_type __str_sz = __sv.size();
2803 if (__pos2 > __str_sz)
2804 this->__throw_out_of_range();
2805 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2806}
2807
2808template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002809basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002810basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002811{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002812 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002813 return insert(__pos, __s, traits_type::length(__s));
2814}
2815
2816template <class _CharT, class _Traits, class _Allocator>
2817typename basic_string<_CharT, _Traits, _Allocator>::iterator
2818basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2819{
2820 size_type __ip = static_cast<size_type>(__pos - begin());
2821 size_type __sz = size();
2822 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002823 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002824 if (__cap == __sz)
2825 {
2826 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002827 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002828 }
2829 else
2830 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002831 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002832 size_type __n_move = __sz - __ip;
2833 if (__n_move != 0)
2834 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2835 }
2836 traits_type::assign(__p[__ip], __c);
2837 traits_type::assign(__p[++__sz], value_type());
2838 __set_size(__sz);
2839 return begin() + static_cast<difference_type>(__ip);
2840}
2841
2842template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002843inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002844typename basic_string<_CharT, _Traits, _Allocator>::iterator
2845basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2846{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002847#if _LIBCPP_DEBUG_LEVEL >= 2
2848 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2849 "string::insert(iterator, n, value) called with an iterator not"
2850 " referring to this string");
2851#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002852 difference_type __p = __pos - begin();
2853 insert(static_cast<size_type>(__p), __n, __c);
2854 return begin() + __p;
2855}
2856
2857// replace
2858
2859template <class _CharT, class _Traits, class _Allocator>
2860basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002861basic_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 +00002862 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantc51e1022010-05-11 19:42:16 +00002863{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002864 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002865 size_type __sz = size();
2866 if (__pos > __sz)
2867 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002868 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002869 size_type __cap = capacity();
2870 if (__cap - __sz + __n1 >= __n2)
2871 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002872 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002873 if (__n1 != __n2)
2874 {
2875 size_type __n_move = __sz - __pos - __n1;
2876 if (__n_move != 0)
2877 {
2878 if (__n1 > __n2)
2879 {
2880 traits_type::move(__p + __pos, __s, __n2);
2881 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2882 goto __finish;
2883 }
2884 if (__p + __pos < __s && __s < __p + __sz)
2885 {
2886 if (__p + __pos + __n1 <= __s)
2887 __s += __n2 - __n1;
2888 else // __p + __pos < __s < __p + __pos + __n1
2889 {
2890 traits_type::move(__p + __pos, __s, __n1);
2891 __pos += __n1;
2892 __s += __n2;
2893 __n2 -= __n1;
2894 __n1 = 0;
2895 }
2896 }
2897 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2898 }
2899 }
2900 traits_type::move(__p + __pos, __s, __n2);
2901__finish:
Martijn Vels1c48afb2020-01-28 13:43:19 -05002902// __sz += __n2 - __n1; in this and the below function below can cause unsigned
2903// integer overflow, but this is a safe operation, so we disable the check.
Howard Hinnantc51e1022010-05-11 19:42:16 +00002904 __sz += __n2 - __n1;
2905 __set_size(__sz);
2906 __invalidate_iterators_past(__sz);
2907 traits_type::assign(__p[__sz], value_type());
2908 }
2909 else
2910 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2911 return *this;
2912}
2913
2914template <class _CharT, class _Traits, class _Allocator>
2915basic_string<_CharT, _Traits, _Allocator>&
2916basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
Eric Fiseliere5b21842017-03-09 01:54:13 +00002917 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantc51e1022010-05-11 19:42:16 +00002918{
2919 size_type __sz = size();
2920 if (__pos > __sz)
2921 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002922 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002923 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002924 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002925 if (__cap - __sz + __n1 >= __n2)
2926 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002927 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002928 if (__n1 != __n2)
2929 {
2930 size_type __n_move = __sz - __pos - __n1;
2931 if (__n_move != 0)
2932 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2933 }
2934 }
2935 else
2936 {
2937 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002938 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002939 }
2940 traits_type::assign(__p + __pos, __n2, __c);
2941 __sz += __n2 - __n1;
2942 __set_size(__sz);
2943 __invalidate_iterators_past(__sz);
2944 traits_type::assign(__p[__sz], value_type());
2945 return *this;
2946}
2947
2948template <class _CharT, class _Traits, class _Allocator>
2949template<class _InputIterator>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002950_EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002951<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002952 __is_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002953 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002954>
Howard Hinnant990d6e82010-11-17 21:11:40 +00002955basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002956 _InputIterator __j1, _InputIterator __j2)
2957{
Marshall Clow958362f2016-09-05 01:54:30 +00002958 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clow039b2f02016-01-13 21:54:34 +00002959 return this->replace(__i1, __i2, __temp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002960}
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>&
2965basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2966{
2967 return replace(__pos1, __n1, __str.data(), __str.size());
2968}
2969
2970template <class _CharT, class _Traits, class _Allocator>
2971basic_string<_CharT, _Traits, _Allocator>&
2972basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2973 size_type __pos2, size_type __n2)
2974{
2975 size_type __str_sz = __str.size();
2976 if (__pos2 > __str_sz)
2977 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002978 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002979}
2980
2981template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00002982template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002983_EnableIf
Marshall Clow82513342016-09-24 22:45:42 +00002984<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002985 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00002986 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002987>
Marshall Clow82513342016-09-24 22:45:42 +00002988basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002989 size_type __pos2, size_type __n2)
2990{
Marshall Clow82513342016-09-24 22:45:42 +00002991 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002992 size_type __str_sz = __sv.size();
2993 if (__pos2 > __str_sz)
2994 this->__throw_out_of_range();
2995 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2996}
2997
2998template <class _CharT, class _Traits, class _Allocator>
2999basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00003000basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003001{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003002 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003003 return replace(__pos, __n1, __s, traits_type::length(__s));
3004}
3005
3006template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003007inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003008basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant990d6e82010-11-17 21:11:40 +00003009basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003010{
3011 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
3012 __str.data(), __str.size());
3013}
3014
3015template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003016inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003017basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00003018basic_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 +00003019{
3020 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
3021}
3022
3023template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003024inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003025basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00003026basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003027{
3028 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
3029}
3030
3031template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003032inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003033basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant990d6e82010-11-17 21:11:40 +00003034basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003035{
3036 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
3037}
3038
3039// erase
3040
Martijn Velsa81fc792020-02-26 13:25:43 -05003041// 'externally instantiated' erase() implementation, called when __n != npos.
3042// Does not check __pos against size()
Howard Hinnantc51e1022010-05-11 19:42:16 +00003043template <class _CharT, class _Traits, class _Allocator>
Martijn Velsa81fc792020-02-26 13:25:43 -05003044void
3045basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move(
3046 size_type __pos, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003047{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003048 if (__n)
3049 {
Martijn Velsa81fc792020-02-26 13:25:43 -05003050 size_type __sz = size();
Eric Fiselierc1b87a72019-11-16 17:13:26 -05003051 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003052 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003053 size_type __n_move = __sz - __pos - __n;
3054 if (__n_move != 0)
3055 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3056 __sz -= __n;
3057 __set_size(__sz);
3058 __invalidate_iterators_past(__sz);
3059 traits_type::assign(__p[__sz], value_type());
3060 }
Martijn Velsa81fc792020-02-26 13:25:43 -05003061}
3062
3063template <class _CharT, class _Traits, class _Allocator>
3064basic_string<_CharT, _Traits, _Allocator>&
3065basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos,
3066 size_type __n) {
3067 if (__pos > size()) this->__throw_out_of_range();
3068 if (__n == npos) {
3069 __erase_to_end(__pos);
3070 } else {
3071 __erase_external_with_move(__pos, __n);
3072 }
3073 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003074}
3075
3076template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003077inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003078typename basic_string<_CharT, _Traits, _Allocator>::iterator
3079basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3080{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003081#if _LIBCPP_DEBUG_LEVEL >= 2
3082 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3083 "string::erase(iterator) called with an iterator not"
3084 " referring to this string");
3085#endif
3086 _LIBCPP_ASSERT(__pos != end(),
3087 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003088 iterator __b = begin();
3089 size_type __r = static_cast<size_type>(__pos - __b);
3090 erase(__r, 1);
Howard Hinnant28b24882011-12-01 20:21:04 +00003091 return __b + static_cast<difference_type>(__r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003092}
3093
3094template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003095inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003096typename basic_string<_CharT, _Traits, _Allocator>::iterator
3097basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3098{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003099#if _LIBCPP_DEBUG_LEVEL >= 2
3100 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3101 "string::erase(iterator, iterator) called with an iterator not"
3102 " referring to this string");
3103#endif
3104 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003105 iterator __b = begin();
3106 size_type __r = static_cast<size_type>(__first - __b);
3107 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnant28b24882011-12-01 20:21:04 +00003108 return __b + static_cast<difference_type>(__r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003109}
3110
3111template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003112inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003113void
3114basic_string<_CharT, _Traits, _Allocator>::pop_back()
3115{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003116 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003117 size_type __sz;
3118 if (__is_long())
3119 {
3120 __sz = __get_long_size() - 1;
3121 __set_long_size(__sz);
3122 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3123 }
3124 else
3125 {
3126 __sz = __get_short_size() - 1;
3127 __set_short_size(__sz);
3128 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3129 }
3130 __invalidate_iterators_past(__sz);
3131}
3132
3133template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003134inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003135void
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003136basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003137{
3138 __invalidate_all_iterators();
3139 if (__is_long())
3140 {
3141 traits_type::assign(*__get_long_pointer(), value_type());
3142 __set_long_size(0);
3143 }
3144 else
3145 {
3146 traits_type::assign(*__get_short_pointer(), value_type());
3147 __set_short_size(0);
3148 }
3149}
3150
3151template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003152inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003153void
3154basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3155{
3156 if (__is_long())
3157 {
3158 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3159 __set_long_size(__pos);
3160 }
3161 else
3162 {
3163 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3164 __set_short_size(__pos);
3165 }
3166 __invalidate_iterators_past(__pos);
3167}
3168
3169template <class _CharT, class _Traits, class _Allocator>
3170void
3171basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3172{
3173 size_type __sz = size();
3174 if (__n > __sz)
3175 append(__n - __sz, __c);
3176 else
3177 __erase_to_end(__n);
3178}
3179
3180template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier451d5582018-11-26 20:15:38 +00003181inline void
3182basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
3183{
3184 size_type __sz = size();
3185 if (__n > __sz) {
3186 __append_default_init(__n - __sz);
3187 } else
3188 __erase_to_end(__n);
3189}
3190
3191template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003192inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003193typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003194basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003195{
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003196 size_type __m = __alloc_traits::max_size(__alloc());
Eric Fiseliere9cc5922017-10-17 13:16:01 +00003197#ifdef _LIBCPP_BIG_ENDIAN
Marshall Clow6dd6cb72013-10-31 17:23:08 +00003198 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003199#else
Marshall Clow6dd6cb72013-10-31 17:23:08 +00003200 return __m - __alignment;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003201#endif
3202}
3203
3204template <class _CharT, class _Traits, class _Allocator>
3205void
3206basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3207{
3208 if (__res_arg > max_size())
3209 this->__throw_length_error();
3210 size_type __cap = capacity();
3211 size_type __sz = size();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003212 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003213 __res_arg = __recommend(__res_arg);
3214 if (__res_arg != __cap)
3215 {
3216 pointer __new_data, __p;
3217 bool __was_long, __now_long;
3218 if (__res_arg == __min_cap - 1)
3219 {
3220 __was_long = true;
3221 __now_long = false;
3222 __new_data = __get_short_pointer();
3223 __p = __get_long_pointer();
3224 }
3225 else
3226 {
3227 if (__res_arg > __cap)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003228 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003229 else
3230 {
3231 #ifndef _LIBCPP_NO_EXCEPTIONS
3232 try
3233 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003234 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003235 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003236 #ifndef _LIBCPP_NO_EXCEPTIONS
3237 }
3238 catch (...)
3239 {
3240 return;
3241 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003242 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantd17880b2013-06-28 16:59:19 +00003243 if (__new_data == nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003244 return;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003245 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00003246 }
3247 __now_long = true;
3248 __was_long = __is_long();
3249 __p = __get_pointer();
3250 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05003251 traits_type::copy(_VSTD::__to_address(__new_data),
3252 _VSTD::__to_address(__p), size()+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003253 if (__was_long)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003254 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003255 if (__now_long)
3256 {
3257 __set_long_cap(__res_arg+1);
3258 __set_long_size(__sz);
3259 __set_long_pointer(__new_data);
3260 }
3261 else
3262 __set_short_size(__sz);
3263 __invalidate_all_iterators();
3264 }
3265}
3266
3267template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003268inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003269typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003270basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003271{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003272 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003273 return *(data() + __pos);
3274}
3275
3276template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003277inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003278typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003279basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003280{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003281 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003282 return *(__get_pointer() + __pos);
3283}
3284
3285template <class _CharT, class _Traits, class _Allocator>
3286typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3287basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3288{
3289 if (__n >= size())
3290 this->__throw_out_of_range();
3291 return (*this)[__n];
3292}
3293
3294template <class _CharT, class _Traits, class _Allocator>
3295typename basic_string<_CharT, _Traits, _Allocator>::reference
3296basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3297{
3298 if (__n >= size())
3299 this->__throw_out_of_range();
3300 return (*this)[__n];
3301}
3302
3303template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003304inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003305typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003306basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003307{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003308 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003309 return *__get_pointer();
3310}
3311
3312template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003313inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003314typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003315basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003316{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003317 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003318 return *data();
3319}
3320
3321template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003322inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003323typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003324basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003325{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003326 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003327 return *(__get_pointer() + size() - 1);
3328}
3329
3330template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003331inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003332typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003333basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003334{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003335 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003336 return *(data() + size() - 1);
3337}
3338
3339template <class _CharT, class _Traits, class _Allocator>
3340typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003341basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003342{
3343 size_type __sz = size();
3344 if (__pos > __sz)
3345 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003346 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003347 traits_type::copy(__s, data() + __pos, __rlen);
3348 return __rlen;
3349}
3350
3351template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003352inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003353basic_string<_CharT, _Traits, _Allocator>
3354basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3355{
3356 return basic_string(*this, __pos, __n, __alloc());
3357}
3358
3359template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003360inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003361void
3362basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow8982dcd2015-07-13 20:04:56 +00003363#if _LIBCPP_STD_VER >= 14
Eric Fiselier873b8d32019-03-18 21:50:12 +00003364 _NOEXCEPT
Marshall Clow8982dcd2015-07-13 20:04:56 +00003365#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00003366 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow8982dcd2015-07-13 20:04:56 +00003367 __is_nothrow_swappable<allocator_type>::value)
3368#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003369{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003370#if _LIBCPP_DEBUG_LEVEL >= 2
3371 if (!__is_long())
3372 __get_db()->__invalidate_all(this);
3373 if (!__str.__is_long())
3374 __get_db()->__invalidate_all(&__str);
3375 __get_db()->swap(this, &__str);
3376#endif
Eric Fiselier9bf691f2016-12-28 05:53:01 +00003377 _LIBCPP_ASSERT(
3378 __alloc_traits::propagate_on_container_swap::value ||
3379 __alloc_traits::is_always_equal::value ||
3380 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003381 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow8982dcd2015-07-13 20:04:56 +00003382 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003383}
3384
3385// find
3386
3387template <class _Traits>
3388struct _LIBCPP_HIDDEN __traits_eq
3389{
3390 typedef typename _Traits::char_type char_type;
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003391 _LIBCPP_INLINE_VISIBILITY
3392 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3393 {return _Traits::eq(__x, __y);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003394};
3395
3396template<class _CharT, class _Traits, class _Allocator>
3397typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003398basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003399 size_type __pos,
3400 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003401{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003402 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003403 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003404 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003405}
3406
3407template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003408inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003409typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003410basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3411 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003412{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003413 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003414 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003415}
3416
3417template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003418template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003419_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003420<
3421 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3422 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003423>
Marshall Clowe46031a2018-07-02 18:41:15 +00003424basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
3425 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003426{
Marshall Clowe46031a2018-07-02 18:41:15 +00003427 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003428 return __str_find<value_type, size_type, traits_type, npos>
3429 (data(), size(), __sv.data(), __pos, __sv.size());
3430}
3431
3432template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003433inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003434typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003435basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003436 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003437{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003438 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003439 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003440 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003441}
3442
3443template<class _CharT, class _Traits, class _Allocator>
3444typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003445basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3446 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003447{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003448 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003449 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003450}
3451
3452// rfind
3453
3454template<class _CharT, class _Traits, class _Allocator>
3455typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003456basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003457 size_type __pos,
3458 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003459{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003460 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003461 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003462 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003463}
3464
3465template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003466inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003467typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003468basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3469 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003470{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003471 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003472 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003473}
3474
3475template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003476template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003477_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003478<
3479 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3480 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003481>
Marshall Clowe46031a2018-07-02 18:41:15 +00003482basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
3483 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003484{
Marshall Clowe46031a2018-07-02 18:41:15 +00003485 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003486 return __str_rfind<value_type, size_type, traits_type, npos>
3487 (data(), size(), __sv.data(), __pos, __sv.size());
3488}
3489
3490template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003491inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003492typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003493basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003494 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003495{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003496 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003497 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003498 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003499}
3500
3501template<class _CharT, class _Traits, class _Allocator>
3502typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003503basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3504 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003505{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003506 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003507 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003508}
3509
3510// find_first_of
3511
3512template<class _CharT, class _Traits, class _Allocator>
3513typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003514basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003515 size_type __pos,
3516 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003517{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003518 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003519 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003520 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003521}
3522
3523template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003524inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003525typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003526basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3527 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003528{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003529 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003530 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003531}
3532
3533template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003534template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003535_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003536<
3537 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3538 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003539>
Marshall Clowe46031a2018-07-02 18:41:15 +00003540basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
3541 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003542{
Marshall Clowe46031a2018-07-02 18:41:15 +00003543 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003544 return __str_find_first_of<value_type, size_type, traits_type, npos>
3545 (data(), size(), __sv.data(), __pos, __sv.size());
3546}
3547
3548template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003549inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003550typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003551basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003552 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003553{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003554 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003555 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003556 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003557}
3558
3559template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003560inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003561typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003562basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3563 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003564{
3565 return find(__c, __pos);
3566}
3567
3568// find_last_of
3569
3570template<class _CharT, class _Traits, class _Allocator>
3571typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003572basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003573 size_type __pos,
3574 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003575{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003576 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003577 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003578 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003579}
3580
3581template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003582inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003583typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003584basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3585 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003586{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003587 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003588 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003589}
3590
3591template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003592template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003593_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003594<
3595 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3596 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003597>
Marshall Clowe46031a2018-07-02 18:41:15 +00003598basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
3599 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003600{
Marshall Clowe46031a2018-07-02 18:41:15 +00003601 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003602 return __str_find_last_of<value_type, size_type, traits_type, npos>
3603 (data(), size(), __sv.data(), __pos, __sv.size());
3604}
3605
3606template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003607inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003608typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003609basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003610 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003611{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003612 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003613 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003614 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003615}
3616
3617template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003618inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003619typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003620basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3621 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003622{
3623 return rfind(__c, __pos);
3624}
3625
3626// find_first_not_of
3627
3628template<class _CharT, class _Traits, class _Allocator>
3629typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003630basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003631 size_type __pos,
3632 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003633{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003634 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003635 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003636 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003637}
3638
3639template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003640inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003641typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003642basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3643 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003644{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003645 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003646 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003647}
3648
3649template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003650template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003651_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003652<
3653 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3654 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003655>
Marshall Clowe46031a2018-07-02 18:41:15 +00003656basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
3657 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003658{
Marshall Clowe46031a2018-07-02 18:41:15 +00003659 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003660 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3661 (data(), size(), __sv.data(), __pos, __sv.size());
3662}
3663
3664template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003665inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003666typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003667basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003668 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003669{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003670 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003671 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003672 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003673}
3674
3675template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003676inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003677typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003678basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3679 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003680{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003681 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003682 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003683}
3684
3685// find_last_not_of
3686
3687template<class _CharT, class _Traits, class _Allocator>
3688typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003689basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003690 size_type __pos,
3691 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003692{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003693 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003694 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003695 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003696}
3697
3698template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003699inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003700typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003701basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3702 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003703{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003704 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003705 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003706}
3707
3708template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003709template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003710_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003711<
3712 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3713 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003714>
Marshall Clowe46031a2018-07-02 18:41:15 +00003715basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
3716 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003717{
Marshall Clowe46031a2018-07-02 18:41:15 +00003718 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003719 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3720 (data(), size(), __sv.data(), __pos, __sv.size());
3721}
3722
3723template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003724inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003725typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003726basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003727 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003728{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003729 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003730 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003731 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003732}
3733
3734template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003735inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003736typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003737basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3738 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003739{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003740 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003741 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003742}
3743
3744// compare
3745
3746template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003747template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003748_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003749<
3750 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3751 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003752>
Marshall Clowe46031a2018-07-02 18:41:15 +00003753basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003754{
Marshall Clowe46031a2018-07-02 18:41:15 +00003755 __self_view __sv = __t;
Howard Hinnantb0485532011-07-24 21:45:06 +00003756 size_t __lhs_sz = size();
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003757 size_t __rhs_sz = __sv.size();
3758 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantb0485532011-07-24 21:45:06 +00003759 _VSTD::min(__lhs_sz, __rhs_sz));
3760 if (__result != 0)
3761 return __result;
3762 if (__lhs_sz < __rhs_sz)
3763 return -1;
3764 if (__lhs_sz > __rhs_sz)
3765 return 1;
3766 return 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003767}
3768
3769template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003770inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003771int
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003772basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003773{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003774 return compare(__self_view(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003775}
3776
3777template <class _CharT, class _Traits, class _Allocator>
3778int
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003779basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3780 size_type __n1,
Howard Hinnantd17880b2013-06-28 16:59:19 +00003781 const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003782 size_type __n2) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003783{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003784 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003785 size_type __sz = size();
3786 if (__pos1 > __sz || __n2 == npos)
3787 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003788 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3789 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003790 if (__r == 0)
3791 {
3792 if (__rlen < __n2)
3793 __r = -1;
3794 else if (__rlen > __n2)
3795 __r = 1;
3796 }
3797 return __r;
3798}
3799
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003800template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003801template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003802_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003803<
3804 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3805 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003806>
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003807basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3808 size_type __n1,
Marshall Clowe46031a2018-07-02 18:41:15 +00003809 const _Tp& __t) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003810{
Marshall Clowe46031a2018-07-02 18:41:15 +00003811 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003812 return compare(__pos1, __n1, __sv.data(), __sv.size());
3813}
3814
3815template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003816inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003817int
3818basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3819 size_type __n1,
3820 const basic_string& __str) const
3821{
3822 return compare(__pos1, __n1, __str.data(), __str.size());
3823}
3824
3825template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00003826template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003827_EnableIf
Marshall Clow82513342016-09-24 22:45:42 +00003828<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003829 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
3830 && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00003831 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003832>
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003833basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3834 size_type __n1,
Marshall Clow82513342016-09-24 22:45:42 +00003835 const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003836 size_type __pos2,
3837 size_type __n2) const
3838{
Marshall Clow82513342016-09-24 22:45:42 +00003839 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003840 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3841}
3842
3843template <class _CharT, class _Traits, class _Allocator>
3844int
3845basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3846 size_type __n1,
3847 const basic_string& __str,
3848 size_type __pos2,
3849 size_type __n2) const
3850{
3851 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3852}
3853
3854template <class _CharT, class _Traits, class _Allocator>
3855int
3856basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3857{
3858 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3859 return compare(0, npos, __s, traits_type::length(__s));
3860}
3861
3862template <class _CharT, class _Traits, class _Allocator>
3863int
3864basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3865 size_type __n1,
3866 const value_type* __s) const
3867{
3868 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3869 return compare(__pos1, __n1, __s, traits_type::length(__s));
3870}
3871
Howard Hinnantc51e1022010-05-11 19:42:16 +00003872// __invariants
3873
3874template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003875inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003876bool
3877basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3878{
3879 if (size() > capacity())
3880 return false;
3881 if (capacity() < __min_cap - 1)
3882 return false;
3883 if (data() == 0)
3884 return false;
3885 if (data()[size()] != value_type(0))
3886 return false;
3887 return true;
3888}
3889
Vedant Kumar55e007e2018-03-08 21:15:26 +00003890// __clear_and_shrink
3891
3892template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003893inline
Louis Dionne173f29e2019-05-29 16:01:36 +00003894void
Marshall Clowe60a7182018-05-29 17:04:37 +00003895basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
Vedant Kumar55e007e2018-03-08 21:15:26 +00003896{
3897 clear();
3898 if(__is_long())
3899 {
3900 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
3901 __set_long_cap(0);
3902 __set_short_size(0);
3903 }
Louis Dionne173f29e2019-05-29 16:01:36 +00003904}
Vedant Kumar55e007e2018-03-08 21:15:26 +00003905
Howard Hinnantc51e1022010-05-11 19:42:16 +00003906// operator==
3907
3908template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003909inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003910bool
3911operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003912 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003913{
Howard Hinnantaaeb1132013-04-22 23:55:13 +00003914 size_t __lhs_sz = __lhs.size();
3915 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3916 __rhs.data(),
3917 __lhs_sz) == 0;
3918}
3919
3920template<class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003921inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaaeb1132013-04-22 23:55:13 +00003922bool
3923operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3924 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3925{
3926 size_t __lhs_sz = __lhs.size();
3927 if (__lhs_sz != __rhs.size())
3928 return false;
3929 const char* __lp = __lhs.data();
3930 const char* __rp = __rhs.data();
3931 if (__lhs.__is_long())
3932 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3933 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3934 if (*__lp != *__rp)
3935 return false;
3936 return true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003937}
3938
3939template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003940inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003941bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003942operator==(const _CharT* __lhs,
3943 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003944{
Eric Fiselier0cafa3f2015-08-28 03:02:37 +00003945 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3946 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3947 size_t __lhs_len = _Traits::length(__lhs);
3948 if (__lhs_len != __rhs.size()) return false;
3949 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003950}
3951
Howard Hinnantc51e1022010-05-11 19:42:16 +00003952template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003953inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003954bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003955operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3956 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003957{
Eric Fiselier0cafa3f2015-08-28 03:02:37 +00003958 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3959 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3960 size_t __rhs_len = _Traits::length(__rhs);
3961 if (__rhs_len != __lhs.size()) return false;
3962 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003963}
3964
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003965template<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
3968operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003969 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003970{
3971 return !(__lhs == __rhs);
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 !(__lhs == __rhs);
3981}
3982
3983template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003984inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003985bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003986operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3987 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003988{
3989 return !(__lhs == __rhs);
3990}
3991
3992// operator<
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
3997operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003998 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003999{
Howard Hinnanta2660c12011-07-24 15:07:21 +00004000 return __lhs.compare(__rhs) < 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004001}
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 basic_string<_CharT, _Traits, _Allocator>& __lhs,
4007 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004008{
Howard Hinnanta2660c12011-07-24 15:07:21 +00004009 return __lhs.compare(__rhs) < 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004010}
4011
4012template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004013inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004014bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004015operator< (const _CharT* __lhs,
4016 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004017{
4018 return __rhs.compare(__lhs) > 0;
4019}
4020
Howard Hinnantc51e1022010-05-11 19:42:16 +00004021// operator>
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
4026operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004027 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004028{
4029 return __rhs < __lhs;
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 basic_string<_CharT, _Traits, _Allocator>& __lhs,
4036 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004037{
4038 return __rhs < __lhs;
4039}
4040
4041template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004042inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004043bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004044operator> (const _CharT* __lhs,
4045 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004046{
4047 return __rhs < __lhs;
4048}
4049
4050// operator<=
4051
4052template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004053inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004054bool
4055operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004056 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004057{
4058 return !(__rhs < __lhs);
4059}
4060
4061template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004062inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004063bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004064operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4065 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004066{
4067 return !(__rhs < __lhs);
4068}
4069
4070template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004071inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004072bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004073operator<=(const _CharT* __lhs,
4074 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004075{
4076 return !(__rhs < __lhs);
4077}
4078
4079// operator>=
4080
4081template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004082inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004083bool
4084operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004085 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004086{
4087 return !(__lhs < __rhs);
4088}
4089
4090template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004091inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004092bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004093operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4094 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004095{
4096 return !(__lhs < __rhs);
4097}
4098
4099template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004100inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004101bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004102operator>=(const _CharT* __lhs,
4103 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004104{
4105 return !(__lhs < __rhs);
4106}
4107
4108// operator +
4109
4110template<class _CharT, class _Traits, class _Allocator>
4111basic_string<_CharT, _Traits, _Allocator>
4112operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4113 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4114{
4115 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4116 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4117 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4118 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4119 __r.append(__rhs.data(), __rhs_sz);
4120 return __r;
4121}
4122
4123template<class _CharT, class _Traits, class _Allocator>
4124basic_string<_CharT, _Traits, _Allocator>
4125operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4126{
4127 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4128 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4129 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4130 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4131 __r.append(__rhs.data(), __rhs_sz);
4132 return __r;
4133}
4134
4135template<class _CharT, class _Traits, class _Allocator>
4136basic_string<_CharT, _Traits, _Allocator>
4137operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4138{
4139 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4140 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4141 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4142 __r.append(__rhs.data(), __rhs_sz);
4143 return __r;
4144}
4145
4146template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00004147inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004148basic_string<_CharT, _Traits, _Allocator>
4149operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4150{
4151 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4152 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4153 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4154 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4155 __r.append(__rhs, __rhs_sz);
4156 return __r;
4157}
4158
4159template<class _CharT, class _Traits, class _Allocator>
4160basic_string<_CharT, _Traits, _Allocator>
4161operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4162{
4163 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4164 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4165 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4166 __r.push_back(__rhs);
4167 return __r;
4168}
4169
Eric Fiselierfc92be82017-04-19 00:28:44 +00004170#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00004171
4172template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004173inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004174basic_string<_CharT, _Traits, _Allocator>
4175operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4176{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004177 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004178}
4179
4180template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004181inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004182basic_string<_CharT, _Traits, _Allocator>
4183operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4184{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004185 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004186}
4187
4188template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004189inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004190basic_string<_CharT, _Traits, _Allocator>
4191operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4192{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004193 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004194}
4195
4196template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004197inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004198basic_string<_CharT, _Traits, _Allocator>
4199operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4200{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004201 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004202}
4203
4204template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004205inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004206basic_string<_CharT, _Traits, _Allocator>
4207operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4208{
4209 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004210 return _VSTD::move(__rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004211}
4212
4213template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004214inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004215basic_string<_CharT, _Traits, _Allocator>
4216operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4217{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004218 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004219}
4220
4221template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004222inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004223basic_string<_CharT, _Traits, _Allocator>
4224operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4225{
4226 __lhs.push_back(__rhs);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004227 return _VSTD::move(__lhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004228}
4229
Eric Fiselierfc92be82017-04-19 00:28:44 +00004230#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00004231
4232// swap
4233
4234template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004235inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004236void
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004237swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant3e276872011-06-03 18:40:47 +00004238 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4239 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00004240{
4241 __lhs.swap(__rhs);
4242}
4243
Marshall Clow8732fed2018-12-11 04:35:44 +00004244#ifndef _LIBCPP_NO_HAS_CHAR8_T
4245typedef basic_string<char8_t> u8string;
4246#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00004247
Marshall Clow8732fed2018-12-11 04:35:44 +00004248#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004249typedef basic_string<char16_t> u16string;
4250typedef basic_string<char32_t> u32string;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004251#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004252
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004253_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4254_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4255_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4256_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4257_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004258
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004259_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4260_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4261_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004262
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004263_LIBCPP_FUNC_VIS string to_string(int __val);
4264_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4265_LIBCPP_FUNC_VIS string to_string(long __val);
4266_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4267_LIBCPP_FUNC_VIS string to_string(long long __val);
4268_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4269_LIBCPP_FUNC_VIS string to_string(float __val);
4270_LIBCPP_FUNC_VIS string to_string(double __val);
4271_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004272
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004273_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4274_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4275_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4276_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4277_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004278
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004279_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4280_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4281_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004282
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004283_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4284_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4285_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4286_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4287_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4288_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4289_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4290_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4291_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004292
Howard Hinnantc51e1022010-05-11 19:42:16 +00004293template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc9fdaf12020-01-15 17:02:17 -05004294_LIBCPP_FUNC_VIS
4295const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4296 basic_string<_CharT, _Traits, _Allocator>::npos;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004297
Marshall Clow851b9ec2019-05-20 21:56:51 +00004298template <class _CharT, class _Allocator>
4299struct _LIBCPP_TEMPLATE_VIS
4300 hash<basic_string<_CharT, char_traits<_CharT>, _Allocator> >
4301 : public unary_function<
4302 basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004303{
4304 size_t
Marshall Clow851b9ec2019-05-20 21:56:51 +00004305 operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT
4306 { return __do_string_hash(__val.data(), __val.data() + __val.size()); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00004307};
4308
Howard Hinnantc51e1022010-05-11 19:42:16 +00004309
Howard Hinnantdc095972011-07-18 15:51:59 +00004310template<class _CharT, class _Traits, class _Allocator>
4311basic_ostream<_CharT, _Traits>&
4312operator<<(basic_ostream<_CharT, _Traits>& __os,
4313 const basic_string<_CharT, _Traits, _Allocator>& __str);
4314
4315template<class _CharT, class _Traits, class _Allocator>
4316basic_istream<_CharT, _Traits>&
4317operator>>(basic_istream<_CharT, _Traits>& __is,
4318 basic_string<_CharT, _Traits, _Allocator>& __str);
4319
4320template<class _CharT, class _Traits, class _Allocator>
4321basic_istream<_CharT, _Traits>&
4322getline(basic_istream<_CharT, _Traits>& __is,
4323 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4324
4325template<class _CharT, class _Traits, class _Allocator>
4326inline _LIBCPP_INLINE_VISIBILITY
4327basic_istream<_CharT, _Traits>&
4328getline(basic_istream<_CharT, _Traits>& __is,
4329 basic_string<_CharT, _Traits, _Allocator>& __str);
4330
Eric Fiselierfc92be82017-04-19 00:28:44 +00004331#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantdc095972011-07-18 15:51:59 +00004332
4333template<class _CharT, class _Traits, class _Allocator>
4334inline _LIBCPP_INLINE_VISIBILITY
4335basic_istream<_CharT, _Traits>&
4336getline(basic_istream<_CharT, _Traits>&& __is,
4337 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4338
4339template<class _CharT, class _Traits, class _Allocator>
4340inline _LIBCPP_INLINE_VISIBILITY
4341basic_istream<_CharT, _Traits>&
4342getline(basic_istream<_CharT, _Traits>&& __is,
4343 basic_string<_CharT, _Traits, _Allocator>& __str);
4344
Eric Fiselierfc92be82017-04-19 00:28:44 +00004345#endif // _LIBCPP_CXX03_LANG
Howard Hinnantdc095972011-07-18 15:51:59 +00004346
Marshall Clow29b53f22018-12-14 18:49:35 +00004347#if _LIBCPP_STD_VER > 17
4348template<class _CharT, class _Traits, class _Allocator, class _Up>
4349inline _LIBCPP_INLINE_VISIBILITY
4350void erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v)
4351{ __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end()); }
4352
4353template<class _CharT, class _Traits, class _Allocator, class _Predicate>
4354inline _LIBCPP_INLINE_VISIBILITY
4355void erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, _Predicate __pred)
4356{ __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred), __str.end()); }
4357#endif
4358
Howard Hinnant8ea98242013-08-23 17:37:05 +00004359#if _LIBCPP_DEBUG_LEVEL >= 2
4360
4361template<class _CharT, class _Traits, class _Allocator>
4362bool
4363basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4364{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004365 return this->data() <= _VSTD::__to_address(__i->base()) &&
4366 _VSTD::__to_address(__i->base()) < this->data() + this->size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004367}
4368
4369template<class _CharT, class _Traits, class _Allocator>
4370bool
4371basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4372{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004373 return this->data() < _VSTD::__to_address(__i->base()) &&
4374 _VSTD::__to_address(__i->base()) <= this->data() + this->size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004375}
4376
4377template<class _CharT, class _Traits, class _Allocator>
4378bool
4379basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4380{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004381 const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
Howard Hinnant8ea98242013-08-23 17:37:05 +00004382 return this->data() <= __p && __p <= this->data() + this->size();
4383}
4384
4385template<class _CharT, class _Traits, class _Allocator>
4386bool
4387basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4388{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004389 const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
Howard Hinnant8ea98242013-08-23 17:37:05 +00004390 return this->data() <= __p && __p < this->data() + this->size();
4391}
4392
4393#endif // _LIBCPP_DEBUG_LEVEL >= 2
4394
Louis Dionne173f29e2019-05-29 16:01:36 +00004395#if _LIBCPP_STD_VER > 11
Marshall Clowcba751f2013-07-23 17:05:24 +00004396// Literal suffixes for basic_string [basic.string.literals]
Marshall Clowac868372013-10-05 21:18:32 +00004397inline namespace literals
Marshall Clowcba751f2013-07-23 17:05:24 +00004398{
4399 inline namespace string_literals
4400 {
Howard Hinnant5c167562013-08-07 19:39:48 +00004401 inline _LIBCPP_INLINE_VISIBILITY
4402 basic_string<char> operator "" s( const char *__str, size_t __len )
4403 {
4404 return basic_string<char> (__str, __len);
4405 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004406
Howard Hinnant5c167562013-08-07 19:39:48 +00004407 inline _LIBCPP_INLINE_VISIBILITY
4408 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4409 {
4410 return basic_string<wchar_t> (__str, __len);
4411 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004412
Marshall Clow8732fed2018-12-11 04:35:44 +00004413#ifndef _LIBCPP_NO_HAS_CHAR8_T
4414 inline _LIBCPP_INLINE_VISIBILITY
4415 basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPT
4416 {
4417 return basic_string<char8_t> (__str, __len);
4418 }
4419#endif
4420
Howard Hinnant5c167562013-08-07 19:39:48 +00004421 inline _LIBCPP_INLINE_VISIBILITY
4422 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4423 {
4424 return basic_string<char16_t> (__str, __len);
4425 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004426
Howard Hinnant5c167562013-08-07 19:39:48 +00004427 inline _LIBCPP_INLINE_VISIBILITY
4428 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4429 {
4430 return basic_string<char32_t> (__str, __len);
4431 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004432 }
4433}
4434#endif
4435
Howard Hinnantc51e1022010-05-11 19:42:16 +00004436_LIBCPP_END_NAMESPACE_STD
4437
Eric Fiselierf4433a32017-05-31 22:07:49 +00004438_LIBCPP_POP_MACROS
4439
Howard Hinnantc51e1022010-05-11 19:42:16 +00004440#endif // _LIBCPP_STRING