blob: ffa8c66f7e359c26d8931746e3ea432dcfc9151c [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
Martijn Velsf0e53fe2020-03-03 17:47:23 -05001552 // Slow path for the (inlined) copy constructor for 'long' strings.
1553 // Always externally instantiated and not inlined.
1554 // Requires that __s is zero terminated.
1555 // The main reason for this function to exist is because for unstable, we
1556 // want to allow inlining of the copy constructor. However, we don't want
1557 // to call the __init() functions as those are marked as inline which may
1558 // result in over-aggressive inlining by the compiler, where our aim is
1559 // to only inline the fast path code directly in the ctor.
1560 void __init_copy_ctor_external(const value_type* __s, size_type __sz);
1561
Howard Hinnantc51e1022010-05-11 19:42:16 +00001562 template <class _InputIterator>
Duncan P. N. Exon Smitheb584632017-04-01 03:20:48 +00001563 inline
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001564 _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00001565 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001566 __is_exactly_cpp17_input_iterator<_InputIterator>::value
1567 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001568 __init(_InputIterator __first, _InputIterator __last);
1569
1570 template <class _ForwardIterator>
Duncan P. N. Exon Smitheb584632017-04-01 03:20:48 +00001571 inline
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001572 _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00001573 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001574 __is_cpp17_forward_iterator<_ForwardIterator>::value
1575 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001576 __init(_ForwardIterator __first, _ForwardIterator __last);
1577
1578 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001579 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001580 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1581 size_type __n_copy, size_type __n_del,
Howard Hinnantd17880b2013-06-28 16:59:19 +00001582 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001583
Martijn Vels596e3de2020-02-26 15:55:49 -05001584 // __assign_no_alias is invoked for assignment operations where we
1585 // have proof that the input does not alias the current instance.
1586 // For example, operator=(basic_string) performs a 'self' check.
1587 template <bool __is_short>
1588 void __assign_no_alias(const value_type* __s, size_type __n);
1589
Howard Hinnantcf823322010-12-17 14:46:43 +00001590 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001591 void __erase_to_end(size_type __pos);
1592
Martijn Velsa81fc792020-02-26 13:25:43 -05001593 // __erase_external_with_move is invoked for erase() invocations where
1594 // `n ~= npos`, likely requiring memory moves on the string data.
1595 void __erase_external_with_move(size_type __pos, size_type __n);
1596
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001597 _LIBCPP_INLINE_VISIBILITY
1598 void __copy_assign_alloc(const basic_string& __str)
1599 {__copy_assign_alloc(__str, integral_constant<bool,
1600 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1601
1602 _LIBCPP_INLINE_VISIBILITY
1603 void __copy_assign_alloc(const basic_string& __str, true_type)
1604 {
Marshall Clowf258c202017-01-31 03:40:52 +00001605 if (__alloc() == __str.__alloc())
1606 __alloc() = __str.__alloc();
1607 else
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001608 {
Marshall Clowf258c202017-01-31 03:40:52 +00001609 if (!__str.__is_long())
1610 {
Vedant Kumar55e007e2018-03-08 21:15:26 +00001611 __clear_and_shrink();
Marshall Clowf258c202017-01-31 03:40:52 +00001612 __alloc() = __str.__alloc();
1613 }
1614 else
1615 {
1616 allocator_type __a = __str.__alloc();
1617 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
Vedant Kumar55e007e2018-03-08 21:15:26 +00001618 __clear_and_shrink();
Marshall Clowf258c202017-01-31 03:40:52 +00001619 __alloc() = _VSTD::move(__a);
1620 __set_long_pointer(__p);
1621 __set_long_cap(__str.__get_long_cap());
1622 __set_long_size(__str.size());
1623 }
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001624 }
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001625 }
1626
1627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant28b24882011-12-01 20:21:04 +00001628 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001629 {}
1630
Eric Fiselierfc92be82017-04-19 00:28:44 +00001631#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantcf823322010-12-17 14:46:43 +00001632 _LIBCPP_INLINE_VISIBILITY
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00001633 void __move_assign(basic_string& __str, false_type)
1634 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnantcf823322010-12-17 14:46:43 +00001635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e276872011-06-03 18:40:47 +00001636 void __move_assign(basic_string& __str, true_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00001637#if _LIBCPP_STD_VER > 14
1638 _NOEXCEPT;
1639#else
Howard Hinnant3e276872011-06-03 18:40:47 +00001640 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001641#endif
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00001642#endif
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001643
1644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001645 void
Howard Hinnantc2734962011-09-02 20:42:31 +00001646 __move_assign_alloc(basic_string& __str)
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001647 _NOEXCEPT_(
1648 !__alloc_traits::propagate_on_container_move_assignment::value ||
1649 is_nothrow_move_assignable<allocator_type>::value)
1650 {__move_assign_alloc(__str, integral_constant<bool,
1651 __alloc_traits::propagate_on_container_move_assignment::value>());}
1652
1653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc2734962011-09-02 20:42:31 +00001654 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001655 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1656 {
1657 __alloc() = _VSTD::move(__c.__alloc());
1658 }
1659
1660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant28b24882011-12-01 20:21:04 +00001661 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001662 _NOEXCEPT
1663 {}
1664
Howard Hinnantcf823322010-12-17 14:46:43 +00001665 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1666 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001667
1668 friend basic_string operator+<>(const basic_string&, const basic_string&);
1669 friend basic_string operator+<>(const value_type*, const basic_string&);
1670 friend basic_string operator+<>(value_type, const basic_string&);
1671 friend basic_string operator+<>(const basic_string&, const value_type*);
1672 friend basic_string operator+<>(const basic_string&, value_type);
1673};
1674
Marshall Clowa0563332018-02-08 06:34:03 +00001675#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1676template<class _InputIterator,
1677 class _CharT = typename iterator_traits<_InputIterator>::value_type,
1678 class _Allocator = allocator<_CharT>,
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001679 class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value>,
1680 class = _EnableIf<__is_allocator<_Allocator>::value>
Marshall Clowa0563332018-02-08 06:34:03 +00001681 >
1682basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
1683 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
Marshall Clowe46031a2018-07-02 18:41:15 +00001684
1685template<class _CharT,
1686 class _Traits,
1687 class _Allocator = allocator<_CharT>,
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001688 class = _EnableIf<__is_allocator<_Allocator>::value>
Marshall Clowe46031a2018-07-02 18:41:15 +00001689 >
1690explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
1691 -> basic_string<_CharT, _Traits, _Allocator>;
1692
1693template<class _CharT,
1694 class _Traits,
1695 class _Allocator = allocator<_CharT>,
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001696 class = _EnableIf<__is_allocator<_Allocator>::value>,
Marshall Clowe46031a2018-07-02 18:41:15 +00001697 class _Sz = typename allocator_traits<_Allocator>::size_type
1698 >
1699basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
1700 -> basic_string<_CharT, _Traits, _Allocator>;
Marshall Clowa0563332018-02-08 06:34:03 +00001701#endif
1702
Howard Hinnantc51e1022010-05-11 19:42:16 +00001703template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001704inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001705void
1706basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1707{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001708#if _LIBCPP_DEBUG_LEVEL >= 2
1709 __get_db()->__invalidate_all(this);
1710#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantc51e1022010-05-11 19:42:16 +00001711}
1712
1713template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001714inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001715void
Howard Hinnant28b24882011-12-01 20:21:04 +00001716basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant8ea98242013-08-23 17:37:05 +00001717#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant28b24882011-12-01 20:21:04 +00001718 __pos
1719#endif
1720 )
Howard Hinnantc51e1022010-05-11 19:42:16 +00001721{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001722#if _LIBCPP_DEBUG_LEVEL >= 2
1723 __c_node* __c = __get_db()->__find_c_and_lock(this);
1724 if (__c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001725 {
Howard Hinnant8ea98242013-08-23 17:37:05 +00001726 const_pointer __new_last = __get_pointer() + __pos;
1727 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantc51e1022010-05-11 19:42:16 +00001728 {
Howard Hinnant8ea98242013-08-23 17:37:05 +00001729 --__p;
1730 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1731 if (__i->base() > __new_last)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001732 {
Howard Hinnant8ea98242013-08-23 17:37:05 +00001733 (*__p)->__c_ = nullptr;
1734 if (--__c->end_ != __p)
1735 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001736 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001737 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001738 __get_db()->unlock();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001739 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001740#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantc51e1022010-05-11 19:42:16 +00001741}
1742
1743template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001744inline
Howard Hinnant3e276872011-06-03 18:40:47 +00001745basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowe546cbb2015-06-04 02:05:41 +00001746 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001747 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001748{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001749#if _LIBCPP_DEBUG_LEVEL >= 2
1750 __get_db()->__insert_c(this);
1751#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001752 __zero();
1753}
1754
1755template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001756inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001757basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiseliere012bf22015-07-18 20:40:46 +00001758#if _LIBCPP_STD_VER <= 14
1759 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1760#else
1761 _NOEXCEPT
1762#endif
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001763: __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001764{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001765#if _LIBCPP_DEBUG_LEVEL >= 2
1766 __get_db()->__insert_c(this);
1767#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001768 __zero();
1769}
1770
1771template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier815ed732016-09-16 00:00:48 +00001772void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1773 size_type __sz,
1774 size_type __reserve)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001775{
1776 if (__reserve > max_size())
1777 this->__throw_length_error();
1778 pointer __p;
1779 if (__reserve < __min_cap)
1780 {
1781 __set_short_size(__sz);
1782 __p = __get_short_pointer();
1783 }
1784 else
1785 {
1786 size_type __cap = __recommend(__reserve);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001787 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001788 __set_long_pointer(__p);
1789 __set_long_cap(__cap+1);
1790 __set_long_size(__sz);
1791 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001792 traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001793 traits_type::assign(__p[__sz], value_type());
1794}
1795
1796template <class _CharT, class _Traits, class _Allocator>
1797void
Howard Hinnantd17880b2013-06-28 16:59:19 +00001798basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001799{
1800 if (__sz > max_size())
1801 this->__throw_length_error();
1802 pointer __p;
1803 if (__sz < __min_cap)
1804 {
1805 __set_short_size(__sz);
1806 __p = __get_short_pointer();
1807 }
1808 else
1809 {
1810 size_type __cap = __recommend(__sz);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001811 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001812 __set_long_pointer(__p);
1813 __set_long_cap(__cap+1);
1814 __set_long_size(__sz);
1815 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001816 traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001817 traits_type::assign(__p[__sz], value_type());
1818}
1819
1820template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00001821template <class>
Eric Fiselier812882b2017-02-17 01:17:10 +00001822basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001823 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001824{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001825 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001826 __init(__s, traits_type::length(__s));
Howard Hinnant8ea98242013-08-23 17:37:05 +00001827#if _LIBCPP_DEBUG_LEVEL >= 2
1828 __get_db()->__insert_c(this);
1829#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001830}
1831
1832template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001833inline
Eric Fiselier812882b2017-02-17 01:17:10 +00001834basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001835 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001836{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001837 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001838 __init(__s, __n);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001839#if _LIBCPP_DEBUG_LEVEL >= 2
1840 __get_db()->__insert_c(this);
1841#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001842}
1843
1844template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001845inline
Eric Fiselier812882b2017-02-17 01:17:10 +00001846basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001847 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001848{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001849 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001850 __init(__s, __n);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001851#if _LIBCPP_DEBUG_LEVEL >= 2
1852 __get_db()->__insert_c(this);
1853#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001854}
1855
1856template <class _CharT, class _Traits, class _Allocator>
1857basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001858 : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001859{
1860 if (!__str.__is_long())
1861 __r_.first().__r = __str.__r_.first().__r;
1862 else
Martijn Velsf0e53fe2020-03-03 17:47:23 -05001863 __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
1864 __str.__get_long_size());
1865
Howard Hinnant8ea98242013-08-23 17:37:05 +00001866#if _LIBCPP_DEBUG_LEVEL >= 2
1867 __get_db()->__insert_c(this);
1868#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001869}
1870
1871template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier812882b2017-02-17 01:17:10 +00001872basic_string<_CharT, _Traits, _Allocator>::basic_string(
1873 const basic_string& __str, const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001874 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001875{
1876 if (!__str.__is_long())
1877 __r_.first().__r = __str.__r_.first().__r;
1878 else
Martijn Velsf0e53fe2020-03-03 17:47:23 -05001879 __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
1880 __str.__get_long_size());
Howard Hinnant8ea98242013-08-23 17:37:05 +00001881#if _LIBCPP_DEBUG_LEVEL >= 2
1882 __get_db()->__insert_c(this);
1883#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001884}
1885
Eric Fiselierfc92be82017-04-19 00:28:44 +00001886#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001887
1888template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001889inline
Howard Hinnant3e276872011-06-03 18:40:47 +00001890basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clowa80abc72015-06-03 19:56:43 +00001891#if _LIBCPP_STD_VER <= 14
Howard Hinnant3e276872011-06-03 18:40:47 +00001892 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clowa80abc72015-06-03 19:56:43 +00001893#else
1894 _NOEXCEPT
1895#endif
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001896 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001897{
1898 __str.__zero();
Howard Hinnant8ea98242013-08-23 17:37:05 +00001899#if _LIBCPP_DEBUG_LEVEL >= 2
1900 __get_db()->__insert_c(this);
1901 if (__is_long())
1902 __get_db()->swap(this, &__str);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001903#endif
1904}
1905
1906template <class _CharT, class _Traits, class _Allocator>
Martijn Velsf0e53fe2020-03-03 17:47:23 -05001907void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
1908 const value_type* __s, size_type __sz) {
1909 pointer __p;
1910 if (__sz < __min_cap) {
1911 __p = __get_short_pointer();
1912 __set_short_size(__sz);
1913 } else {
1914 if (__sz > max_size())
1915 this->__throw_length_error();
1916 size_t __cap = __recommend(__sz);
1917 __p = __alloc_traits::allocate(__alloc(), __cap + 1);
1918 __set_long_pointer(__p);
1919 __set_long_cap(__cap + 1);
1920 __set_long_size(__sz);
1921 }
1922 traits_type::copy(_VSTD::__to_address(__p), __s, __sz + 1);
1923}
1924
1925template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001926inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001927basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001928 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001929{
Marshall Clowd2d24692014-07-17 15:32:20 +00001930 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001931 __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd2d24692014-07-17 15:32:20 +00001932 else
1933 {
1934 __r_.first().__r = __str.__r_.first().__r;
1935 __str.__zero();
1936 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001937#if _LIBCPP_DEBUG_LEVEL >= 2
1938 __get_db()->__insert_c(this);
1939 if (__is_long())
1940 __get_db()->swap(this, &__str);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001941#endif
1942}
1943
Eric Fiselierfc92be82017-04-19 00:28:44 +00001944#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001945
1946template <class _CharT, class _Traits, class _Allocator>
1947void
1948basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1949{
1950 if (__n > max_size())
1951 this->__throw_length_error();
1952 pointer __p;
1953 if (__n < __min_cap)
1954 {
1955 __set_short_size(__n);
1956 __p = __get_short_pointer();
1957 }
1958 else
1959 {
1960 size_type __cap = __recommend(__n);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001961 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001962 __set_long_pointer(__p);
1963 __set_long_cap(__cap+1);
1964 __set_long_size(__n);
1965 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001966 traits_type::assign(_VSTD::__to_address(__p), __n, __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001967 traits_type::assign(__p[__n], value_type());
1968}
1969
1970template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00001971inline
Eric Fiselier812882b2017-02-17 01:17:10 +00001972basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001973 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001974{
1975 __init(__n, __c);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001976#if _LIBCPP_DEBUG_LEVEL >= 2
1977 __get_db()->__insert_c(this);
1978#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001979}
1980
1981template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00001982template <class>
Eric Fiselier812882b2017-02-17 01:17:10 +00001983basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001984 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001985{
1986 __init(__n, __c);
Howard Hinnant8ea98242013-08-23 17:37:05 +00001987#if _LIBCPP_DEBUG_LEVEL >= 2
1988 __get_db()->__insert_c(this);
1989#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001990}
1991
Howard Hinnantc51e1022010-05-11 19:42:16 +00001992template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier812882b2017-02-17 01:17:10 +00001993basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1994 size_type __pos, size_type __n,
1995 const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001996 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001997{
1998 size_type __str_sz = __str.size();
1999 if (__pos > __str_sz)
2000 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002001 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant8ea98242013-08-23 17:37:05 +00002002#if _LIBCPP_DEBUG_LEVEL >= 2
2003 __get_db()->__insert_c(this);
2004#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002005}
2006
2007template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002008inline
Marshall Clow83445802016-04-07 18:13:41 +00002009basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier812882b2017-02-17 01:17:10 +00002010 const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002011 : __r_(__default_init_tag(), __a)
Marshall Clow83445802016-04-07 18:13:41 +00002012{
2013 size_type __str_sz = __str.size();
2014 if (__pos > __str_sz)
2015 this->__throw_out_of_range();
2016 __init(__str.data() + __pos, __str_sz - __pos);
2017#if _LIBCPP_DEBUG_LEVEL >= 2
2018 __get_db()->__insert_c(this);
2019#endif
2020}
2021
2022template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002023template <class _Tp, class>
Marshall Clow78dbe462016-11-14 18:22:19 +00002024basic_string<_CharT, _Traits, _Allocator>::basic_string(
Marshall Clowe46031a2018-07-02 18:41:15 +00002025 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002026 : __r_(__default_init_tag(), __a)
Marshall Clow78dbe462016-11-14 18:22:19 +00002027{
Marshall Clowe46031a2018-07-02 18:41:15 +00002028 __self_view __sv0 = __t;
2029 __self_view __sv = __sv0.substr(__pos, __n);
Marshall Clow78dbe462016-11-14 18:22:19 +00002030 __init(__sv.data(), __sv.size());
2031#if _LIBCPP_DEBUG_LEVEL >= 2
2032 __get_db()->__insert_c(this);
Eric Fiselier812882b2017-02-17 01:17:10 +00002033#endif
Marshall Clow78dbe462016-11-14 18:22:19 +00002034}
2035
2036template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002037template <class _Tp, class>
2038basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002039 : __r_(__default_init_tag(), __default_init_tag())
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002040{
Marshall Clowe46031a2018-07-02 18:41:15 +00002041 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002042 __init(__sv.data(), __sv.size());
2043#if _LIBCPP_DEBUG_LEVEL >= 2
2044 __get_db()->__insert_c(this);
2045#endif
2046}
2047
2048template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002049template <class _Tp, class>
2050basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002051 : __r_(__default_init_tag(), __a)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002052{
Marshall Clowe46031a2018-07-02 18:41:15 +00002053 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002054 __init(__sv.data(), __sv.size());
2055#if _LIBCPP_DEBUG_LEVEL >= 2
2056 __get_db()->__insert_c(this);
2057#endif
2058}
2059
2060template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002061template <class _InputIterator>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002062_EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002063<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002064 __is_exactly_cpp17_input_iterator<_InputIterator>::value
2065>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002066basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2067{
2068 __zero();
2069#ifndef _LIBCPP_NO_EXCEPTIONS
2070 try
2071 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002072#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002073 for (; __first != __last; ++__first)
2074 push_back(*__first);
2075#ifndef _LIBCPP_NO_EXCEPTIONS
2076 }
2077 catch (...)
2078 {
2079 if (__is_long())
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002080 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002081 throw;
2082 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002083#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002084}
2085
2086template <class _CharT, class _Traits, class _Allocator>
2087template <class _ForwardIterator>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002088_EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002089<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002090 __is_cpp17_forward_iterator<_ForwardIterator>::value
2091>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002092basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2093{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002094 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002095 if (__sz > max_size())
2096 this->__throw_length_error();
2097 pointer __p;
2098 if (__sz < __min_cap)
2099 {
2100 __set_short_size(__sz);
2101 __p = __get_short_pointer();
2102 }
2103 else
2104 {
2105 size_type __cap = __recommend(__sz);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002106 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002107 __set_long_pointer(__p);
2108 __set_long_cap(__cap+1);
2109 __set_long_size(__sz);
2110 }
Eric Fiseliera09a3b42014-10-27 19:28:20 +00002111 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002112 traits_type::assign(*__p, *__first);
2113 traits_type::assign(*__p, value_type());
2114}
2115
2116template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierc0f566d2019-03-14 12:31:10 +00002117template<class _InputIterator, class>
Eric Fiselierbea70602018-11-26 22:51:35 +00002118inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002119basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002120 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00002121{
2122 __init(__first, __last);
Howard Hinnant8ea98242013-08-23 17:37:05 +00002123#if _LIBCPP_DEBUG_LEVEL >= 2
2124 __get_db()->__insert_c(this);
2125#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002126}
2127
2128template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierc0f566d2019-03-14 12:31:10 +00002129template<class _InputIterator, class>
Eric Fiselierbea70602018-11-26 22:51:35 +00002130inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002131basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2132 const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002133 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002134{
2135 __init(__first, __last);
Howard Hinnant8ea98242013-08-23 17:37:05 +00002136#if _LIBCPP_DEBUG_LEVEL >= 2
2137 __get_db()->__insert_c(this);
2138#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002139}
2140
Eric Fiselierfc92be82017-04-19 00:28:44 +00002141#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant33711792011-08-12 21:56:02 +00002142
Howard Hinnantc51e1022010-05-11 19:42:16 +00002143template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002144inline
Eric Fiselier812882b2017-02-17 01:17:10 +00002145basic_string<_CharT, _Traits, _Allocator>::basic_string(
2146 initializer_list<_CharT> __il)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002147 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00002148{
2149 __init(__il.begin(), __il.end());
Howard Hinnant8ea98242013-08-23 17:37:05 +00002150#if _LIBCPP_DEBUG_LEVEL >= 2
2151 __get_db()->__insert_c(this);
2152#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002153}
2154
2155template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002156inline
Eric Fiselier9d355982017-04-12 23:45:53 +00002157
Eric Fiselier812882b2017-02-17 01:17:10 +00002158basic_string<_CharT, _Traits, _Allocator>::basic_string(
2159 initializer_list<_CharT> __il, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002160 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002161{
2162 __init(__il.begin(), __il.end());
Howard Hinnant8ea98242013-08-23 17:37:05 +00002163#if _LIBCPP_DEBUG_LEVEL >= 2
2164 __get_db()->__insert_c(this);
2165#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002166}
2167
Eric Fiselierfc92be82017-04-19 00:28:44 +00002168#endif // _LIBCPP_CXX03_LANG
Howard Hinnant33711792011-08-12 21:56:02 +00002169
Howard Hinnantc51e1022010-05-11 19:42:16 +00002170template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002171basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2172{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002173#if _LIBCPP_DEBUG_LEVEL >= 2
2174 __get_db()->__erase_c(this);
2175#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002176 if (__is_long())
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002177 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002178}
2179
2180template <class _CharT, class _Traits, class _Allocator>
2181void
2182basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2183 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnantd17880b2013-06-28 16:59:19 +00002184 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 +00002185{
2186 size_type __ms = max_size();
2187 if (__delta_cap > __ms - __old_cap - 1)
2188 this->__throw_length_error();
2189 pointer __old_p = __get_pointer();
2190 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002191 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantc51e1022010-05-11 19:42:16 +00002192 __ms - 1;
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002193 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002194 __invalidate_all_iterators();
2195 if (__n_copy != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002196 traits_type::copy(_VSTD::__to_address(__p),
2197 _VSTD::__to_address(__old_p), __n_copy);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002198 if (__n_add != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002199 traits_type::copy(_VSTD::__to_address(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002200 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2201 if (__sec_cp_sz != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002202 traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2203 _VSTD::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002204 if (__old_cap+1 != __min_cap)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002205 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002206 __set_long_pointer(__p);
2207 __set_long_cap(__cap+1);
2208 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2209 __set_long_size(__old_sz);
2210 traits_type::assign(__p[__old_sz], value_type());
2211}
2212
2213template <class _CharT, class _Traits, class _Allocator>
2214void
2215basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2216 size_type __n_copy, size_type __n_del, size_type __n_add)
2217{
2218 size_type __ms = max_size();
Marshall Clow2267c5d2013-11-06 14:24:38 +00002219 if (__delta_cap > __ms - __old_cap)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002220 this->__throw_length_error();
2221 pointer __old_p = __get_pointer();
2222 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002223 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantc51e1022010-05-11 19:42:16 +00002224 __ms - 1;
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002225 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002226 __invalidate_all_iterators();
2227 if (__n_copy != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002228 traits_type::copy(_VSTD::__to_address(__p),
2229 _VSTD::__to_address(__old_p), __n_copy);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002230 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2231 if (__sec_cp_sz != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002232 traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2233 _VSTD::__to_address(__old_p) + __n_copy + __n_del,
Howard Hinnantd17880b2013-06-28 16:59:19 +00002234 __sec_cp_sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002235 if (__old_cap+1 != __min_cap)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002236 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002237 __set_long_pointer(__p);
2238 __set_long_cap(__cap+1);
2239}
2240
2241// assign
2242
2243template <class _CharT, class _Traits, class _Allocator>
Martijn Vels596e3de2020-02-26 15:55:49 -05002244template <bool __is_short>
2245void basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(
2246 const value_type* __s, size_type __n) {
2247 size_type __cap = __is_short ? __min_cap : __get_long_cap();
2248 if (__n < __cap) {
2249 pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer();
2250 __is_short ? __set_short_size(__n) : __set_long_size(__n);
2251 traits_type::copy(_VSTD::__to_address(__p), __s, __n);
2252 traits_type::assign(__p[__n], value_type());
2253 __invalidate_iterators_past(__n);
2254 } else {
2255 size_type __sz = __is_short ? __get_short_size() : __get_long_size();
2256 __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s);
2257 }
2258}
2259
2260template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002261basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002262basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002263{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002264 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002265 size_type __cap = capacity();
2266 if (__cap >= __n)
2267 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002268 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002269 traits_type::move(__p, __s, __n);
2270 traits_type::assign(__p[__n], value_type());
2271 __set_size(__n);
2272 __invalidate_iterators_past(__n);
2273 }
2274 else
2275 {
2276 size_type __sz = size();
2277 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2278 }
2279 return *this;
2280}
2281
2282template <class _CharT, class _Traits, class _Allocator>
2283basic_string<_CharT, _Traits, _Allocator>&
2284basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2285{
2286 size_type __cap = capacity();
2287 if (__cap < __n)
2288 {
2289 size_type __sz = size();
2290 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2291 }
2292 else
2293 __invalidate_iterators_past(__n);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002294 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002295 traits_type::assign(__p, __n, __c);
2296 traits_type::assign(__p[__n], value_type());
2297 __set_size(__n);
2298 return *this;
2299}
2300
2301template <class _CharT, class _Traits, class _Allocator>
2302basic_string<_CharT, _Traits, _Allocator>&
2303basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2304{
2305 pointer __p;
2306 if (__is_long())
2307 {
2308 __p = __get_long_pointer();
2309 __set_long_size(1);
2310 }
2311 else
2312 {
2313 __p = __get_short_pointer();
2314 __set_short_size(1);
2315 }
2316 traits_type::assign(*__p, __c);
2317 traits_type::assign(*++__p, value_type());
2318 __invalidate_iterators_past(1);
2319 return *this;
2320}
2321
2322template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002323basic_string<_CharT, _Traits, _Allocator>&
2324basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2325{
Martijn Vels596e3de2020-02-26 15:55:49 -05002326 if (this != &__str) {
2327 __copy_assign_alloc(__str);
2328 if (!__is_long()) {
2329 if (!__str.__is_long()) {
Eric Fiselier03bbc922020-01-15 17:27:10 -05002330 __r_.first().__r = __str.__r_.first().__r;
Martijn Vels596e3de2020-02-26 15:55:49 -05002331 } else {
2332 __assign_no_alias<true>(__str.data(), __str.size());
2333 }
2334 } else {
2335 __assign_no_alias<false>(__str.data(), __str.size());
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002336 }
Martijn Vels596e3de2020-02-26 15:55:49 -05002337 }
2338 return *this;
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002339}
2340
Eric Fiselierfc92be82017-04-19 00:28:44 +00002341#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002342
2343template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002344inline
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002345void
2346basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002347 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002348{
2349 if (__alloc() != __str.__alloc())
2350 assign(__str);
2351 else
2352 __move_assign(__str, true_type());
2353}
2354
2355template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002356inline
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002357void
2358basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002359#if _LIBCPP_STD_VER > 14
2360 _NOEXCEPT
2361#else
Howard Hinnant3e276872011-06-03 18:40:47 +00002362 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002363#endif
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002364{
marshall2ed41622019-11-27 07:13:00 -08002365 if (__is_long()) {
2366 __alloc_traits::deallocate(__alloc(), __get_long_pointer(),
2367 __get_long_cap());
2368#if _LIBCPP_STD_VER <= 14
2369 if (!is_nothrow_move_assignable<allocator_type>::value) {
2370 __set_short_size(0);
2371 traits_type::assign(__get_short_pointer()[0], value_type());
2372 }
2373#endif
2374 }
2375 __move_assign_alloc(__str);
2376 __r_.first() = __str.__r_.first();
2377 __str.__set_short_size(0);
2378 traits_type::assign(__str.__get_short_pointer()[0], value_type());
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002379}
2380
2381template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002382inline
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002383basic_string<_CharT, _Traits, _Allocator>&
2384basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002385 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002386{
2387 __move_assign(__str, integral_constant<bool,
2388 __alloc_traits::propagate_on_container_move_assignment::value>());
2389 return *this;
2390}
2391
2392#endif
2393
2394template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002395template<class _InputIterator>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002396_EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002397<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002398 __is_exactly_cpp17_input_iterator <_InputIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002399 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002400 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002401>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002402basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2403{
Marshall Clow958362f2016-09-05 01:54:30 +00002404 const basic_string __temp(__first, __last, __alloc());
Marshall Clow039b2f02016-01-13 21:54:34 +00002405 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002406 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002407}
2408
2409template <class _CharT, class _Traits, class _Allocator>
2410template<class _ForwardIterator>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002411_EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002412<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002413 __is_cpp17_forward_iterator<_ForwardIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002414 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002415 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002416>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002417basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2418{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002419 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002420 size_type __cap = capacity();
2421 if (__cap < __n)
2422 {
2423 size_type __sz = size();
2424 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2425 }
2426 else
2427 __invalidate_iterators_past(__n);
2428 pointer __p = __get_pointer();
2429 for (; __first != __last; ++__first, ++__p)
2430 traits_type::assign(*__p, *__first);
2431 traits_type::assign(*__p, value_type());
2432 __set_size(__n);
2433 return *this;
2434}
2435
2436template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002437basic_string<_CharT, _Traits, _Allocator>&
2438basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2439{
2440 size_type __sz = __str.size();
2441 if (__pos > __sz)
2442 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002443 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002444}
2445
2446template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00002447template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002448_EnableIf
Marshall Clow82513342016-09-24 22:45:42 +00002449<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002450 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
2451 && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00002452 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002453>
Marshall Clow82513342016-09-24 22:45:42 +00002454basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002455{
Marshall Clow82513342016-09-24 22:45:42 +00002456 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002457 size_type __sz = __sv.size();
2458 if (__pos > __sz)
2459 this->__throw_out_of_range();
2460 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2461}
2462
2463
2464template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002465basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002466basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002467{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002468 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002469 return assign(__s, traits_type::length(__s));
2470}
2471
2472// append
2473
2474template <class _CharT, class _Traits, class _Allocator>
2475basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002476basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002477{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002478 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002479 size_type __cap = capacity();
2480 size_type __sz = size();
2481 if (__cap - __sz >= __n)
2482 {
2483 if (__n)
2484 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002485 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002486 traits_type::copy(__p + __sz, __s, __n);
2487 __sz += __n;
2488 __set_size(__sz);
2489 traits_type::assign(__p[__sz], value_type());
2490 }
2491 }
2492 else
2493 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2494 return *this;
2495}
2496
2497template <class _CharT, class _Traits, class _Allocator>
2498basic_string<_CharT, _Traits, _Allocator>&
2499basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2500{
2501 if (__n)
2502 {
2503 size_type __cap = capacity();
2504 size_type __sz = size();
2505 if (__cap - __sz < __n)
2506 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2507 pointer __p = __get_pointer();
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002508 traits_type::assign(_VSTD::__to_address(__p) + __sz, __n, __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002509 __sz += __n;
2510 __set_size(__sz);
2511 traits_type::assign(__p[__sz], value_type());
2512 }
2513 return *this;
2514}
2515
2516template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier451d5582018-11-26 20:15:38 +00002517inline void
2518basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
2519{
2520 if (__n)
2521 {
2522 size_type __cap = capacity();
2523 size_type __sz = size();
2524 if (__cap - __sz < __n)
2525 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2526 pointer __p = __get_pointer();
2527 __sz += __n;
2528 __set_size(__sz);
2529 traits_type::assign(__p[__sz], value_type());
2530 }
2531}
2532
2533template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002534void
2535basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2536{
Howard Hinnant68bf1812013-04-30 21:44:48 +00002537 bool __is_short = !__is_long();
2538 size_type __cap;
2539 size_type __sz;
2540 if (__is_short)
2541 {
2542 __cap = __min_cap - 1;
2543 __sz = __get_short_size();
2544 }
2545 else
2546 {
2547 __cap = __get_long_cap() - 1;
2548 __sz = __get_long_size();
2549 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002550 if (__sz == __cap)
Howard Hinnant68bf1812013-04-30 21:44:48 +00002551 {
Howard Hinnantc51e1022010-05-11 19:42:16 +00002552 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant68bf1812013-04-30 21:44:48 +00002553 __is_short = !__is_long();
2554 }
2555 pointer __p;
2556 if (__is_short)
2557 {
2558 __p = __get_short_pointer() + __sz;
2559 __set_short_size(__sz+1);
2560 }
2561 else
2562 {
2563 __p = __get_long_pointer() + __sz;
2564 __set_long_size(__sz+1);
2565 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002566 traits_type::assign(*__p, __c);
2567 traits_type::assign(*++__p, value_type());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002568}
2569
Marshall Clow6ebbf662016-09-07 03:32:06 +00002570template <class _Tp>
Marshall Clow958362f2016-09-05 01:54:30 +00002571bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2572{
2573 return __first <= __p && __p < __last;
2574}
2575
Marshall Clow6ebbf662016-09-07 03:32:06 +00002576template <class _Tp1, class _Tp2>
Eric Fiselier6003c772016-12-23 23:37:52 +00002577bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
Marshall Clow6ebbf662016-09-07 03:32:06 +00002578{
2579 return false;
2580}
2581
Howard Hinnantc51e1022010-05-11 19:42:16 +00002582template <class _CharT, class _Traits, class _Allocator>
2583template<class _ForwardIterator>
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00002584basic_string<_CharT, _Traits, _Allocator>&
2585basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2586 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002587{
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002588 static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00002589 "function requires a ForwardIterator");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002590 size_type __sz = size();
2591 size_type __cap = capacity();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002592 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002593 if (__n)
2594 {
Eric Fiselier96866b52017-04-15 06:49:02 +00002595 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2596 _CharRef __tmp_ref = *__first;
2597 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
Marshall Clow958362f2016-09-05 01:54:30 +00002598 {
2599 const basic_string __temp (__first, __last, __alloc());
2600 append(__temp.data(), __temp.size());
2601 }
Louis Dionne173f29e2019-05-29 16:01:36 +00002602 else
Marshall Clow958362f2016-09-05 01:54:30 +00002603 {
2604 if (__cap - __sz < __n)
2605 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2606 pointer __p = __get_pointer() + __sz;
2607 for (; __first != __last; ++__p, ++__first)
2608 traits_type::assign(*__p, *__first);
2609 traits_type::assign(*__p, value_type());
2610 __set_size(__sz + __n);
2611 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002612 }
2613 return *this;
2614}
2615
2616template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002617inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002618basic_string<_CharT, _Traits, _Allocator>&
2619basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2620{
2621 return append(__str.data(), __str.size());
2622}
2623
2624template <class _CharT, class _Traits, class _Allocator>
2625basic_string<_CharT, _Traits, _Allocator>&
2626basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2627{
2628 size_type __sz = __str.size();
2629 if (__pos > __sz)
2630 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002631 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002632}
2633
2634template <class _CharT, class _Traits, class _Allocator>
Marshall Clow62953962016-10-03 23:40:48 +00002635template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002636 _EnableIf
Marshall Clow82513342016-09-24 22:45:42 +00002637 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002638 __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 +00002639 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002640 >
Marshall Clow82513342016-09-24 22:45:42 +00002641basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002642{
Marshall Clow82513342016-09-24 22:45:42 +00002643 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002644 size_type __sz = __sv.size();
2645 if (__pos > __sz)
2646 this->__throw_out_of_range();
2647 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2648}
2649
2650template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002651basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002652basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002653{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002654 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002655 return append(__s, traits_type::length(__s));
2656}
2657
2658// insert
2659
2660template <class _CharT, class _Traits, class _Allocator>
2661basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002662basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002663{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002664 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002665 size_type __sz = size();
2666 if (__pos > __sz)
2667 this->__throw_out_of_range();
2668 size_type __cap = capacity();
2669 if (__cap - __sz >= __n)
2670 {
2671 if (__n)
2672 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002673 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002674 size_type __n_move = __sz - __pos;
2675 if (__n_move != 0)
2676 {
2677 if (__p + __pos <= __s && __s < __p + __sz)
2678 __s += __n;
2679 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2680 }
2681 traits_type::move(__p + __pos, __s, __n);
2682 __sz += __n;
2683 __set_size(__sz);
2684 traits_type::assign(__p[__sz], value_type());
2685 }
2686 }
2687 else
2688 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2689 return *this;
2690}
2691
2692template <class _CharT, class _Traits, class _Allocator>
2693basic_string<_CharT, _Traits, _Allocator>&
2694basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2695{
2696 size_type __sz = size();
2697 if (__pos > __sz)
2698 this->__throw_out_of_range();
2699 if (__n)
2700 {
2701 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002702 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002703 if (__cap - __sz >= __n)
2704 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002705 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002706 size_type __n_move = __sz - __pos;
2707 if (__n_move != 0)
2708 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2709 }
2710 else
2711 {
2712 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002713 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002714 }
2715 traits_type::assign(__p + __pos, __n, __c);
2716 __sz += __n;
2717 __set_size(__sz);
2718 traits_type::assign(__p[__sz], value_type());
2719 }
2720 return *this;
2721}
2722
2723template <class _CharT, class _Traits, class _Allocator>
2724template<class _InputIterator>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002725_EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002726<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002727 __is_exactly_cpp17_input_iterator<_InputIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002728 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2729 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002730>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002731basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2732{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002733#if _LIBCPP_DEBUG_LEVEL >= 2
2734 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2735 "string::insert(iterator, range) called with an iterator not"
2736 " referring to this string");
2737#endif
Marshall Clow958362f2016-09-05 01:54:30 +00002738 const basic_string __temp(__first, __last, __alloc());
Marshall Clow039b2f02016-01-13 21:54:34 +00002739 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002740}
2741
2742template <class _CharT, class _Traits, class _Allocator>
2743template<class _ForwardIterator>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002744_EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002745<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002746 __is_cpp17_forward_iterator<_ForwardIterator>::value
Marshall Clow039b2f02016-01-13 21:54:34 +00002747 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002748 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002749>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002750basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2751{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002752#if _LIBCPP_DEBUG_LEVEL >= 2
2753 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2754 "string::insert(iterator, range) called with an iterator not"
2755 " referring to this string");
2756#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002757 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002758 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002759 if (__n)
2760 {
Eric Fiselier96866b52017-04-15 06:49:02 +00002761 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2762 _CharRef __tmp_char = *__first;
2763 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
Marshall Clow958362f2016-09-05 01:54:30 +00002764 {
2765 const basic_string __temp(__first, __last, __alloc());
2766 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2767 }
2768
2769 size_type __sz = size();
2770 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002771 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002772 if (__cap - __sz >= __n)
2773 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002774 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002775 size_type __n_move = __sz - __ip;
2776 if (__n_move != 0)
2777 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2778 }
2779 else
2780 {
2781 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002782 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002783 }
2784 __sz += __n;
2785 __set_size(__sz);
2786 traits_type::assign(__p[__sz], value_type());
2787 for (__p += __ip; __first != __last; ++__p, ++__first)
2788 traits_type::assign(*__p, *__first);
2789 }
2790 return begin() + __ip;
2791}
2792
2793template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002794inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002795basic_string<_CharT, _Traits, _Allocator>&
2796basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2797{
2798 return insert(__pos1, __str.data(), __str.size());
2799}
2800
2801template <class _CharT, class _Traits, class _Allocator>
2802basic_string<_CharT, _Traits, _Allocator>&
2803basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2804 size_type __pos2, size_type __n)
2805{
2806 size_type __str_sz = __str.size();
2807 if (__pos2 > __str_sz)
2808 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002809 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002810}
2811
2812template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00002813template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002814_EnableIf
Marshall Clow82513342016-09-24 22:45:42 +00002815<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002816 __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 +00002817 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002818>
Marshall Clow82513342016-09-24 22:45:42 +00002819basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002820 size_type __pos2, size_type __n)
2821{
Marshall Clow82513342016-09-24 22:45:42 +00002822 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002823 size_type __str_sz = __sv.size();
2824 if (__pos2 > __str_sz)
2825 this->__throw_out_of_range();
2826 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2827}
2828
2829template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002830basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002831basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002832{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002833 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002834 return insert(__pos, __s, traits_type::length(__s));
2835}
2836
2837template <class _CharT, class _Traits, class _Allocator>
2838typename basic_string<_CharT, _Traits, _Allocator>::iterator
2839basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2840{
2841 size_type __ip = static_cast<size_type>(__pos - begin());
2842 size_type __sz = size();
2843 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002844 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002845 if (__cap == __sz)
2846 {
2847 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002848 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002849 }
2850 else
2851 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002852 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002853 size_type __n_move = __sz - __ip;
2854 if (__n_move != 0)
2855 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2856 }
2857 traits_type::assign(__p[__ip], __c);
2858 traits_type::assign(__p[++__sz], value_type());
2859 __set_size(__sz);
2860 return begin() + static_cast<difference_type>(__ip);
2861}
2862
2863template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002864inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002865typename basic_string<_CharT, _Traits, _Allocator>::iterator
2866basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2867{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002868#if _LIBCPP_DEBUG_LEVEL >= 2
2869 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2870 "string::insert(iterator, n, value) called with an iterator not"
2871 " referring to this string");
2872#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002873 difference_type __p = __pos - begin();
2874 insert(static_cast<size_type>(__p), __n, __c);
2875 return begin() + __p;
2876}
2877
2878// replace
2879
2880template <class _CharT, class _Traits, class _Allocator>
2881basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002882basic_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 +00002883 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantc51e1022010-05-11 19:42:16 +00002884{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002885 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002886 size_type __sz = size();
2887 if (__pos > __sz)
2888 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002889 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002890 size_type __cap = capacity();
2891 if (__cap - __sz + __n1 >= __n2)
2892 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002893 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002894 if (__n1 != __n2)
2895 {
2896 size_type __n_move = __sz - __pos - __n1;
2897 if (__n_move != 0)
2898 {
2899 if (__n1 > __n2)
2900 {
2901 traits_type::move(__p + __pos, __s, __n2);
2902 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2903 goto __finish;
2904 }
2905 if (__p + __pos < __s && __s < __p + __sz)
2906 {
2907 if (__p + __pos + __n1 <= __s)
2908 __s += __n2 - __n1;
2909 else // __p + __pos < __s < __p + __pos + __n1
2910 {
2911 traits_type::move(__p + __pos, __s, __n1);
2912 __pos += __n1;
2913 __s += __n2;
2914 __n2 -= __n1;
2915 __n1 = 0;
2916 }
2917 }
2918 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2919 }
2920 }
2921 traits_type::move(__p + __pos, __s, __n2);
2922__finish:
Martijn Vels1c48afb2020-01-28 13:43:19 -05002923// __sz += __n2 - __n1; in this and the below function below can cause unsigned
2924// integer overflow, but this is a safe operation, so we disable the check.
Howard Hinnantc51e1022010-05-11 19:42:16 +00002925 __sz += __n2 - __n1;
2926 __set_size(__sz);
2927 __invalidate_iterators_past(__sz);
2928 traits_type::assign(__p[__sz], value_type());
2929 }
2930 else
2931 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2932 return *this;
2933}
2934
2935template <class _CharT, class _Traits, class _Allocator>
2936basic_string<_CharT, _Traits, _Allocator>&
2937basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
Eric Fiseliere5b21842017-03-09 01:54:13 +00002938 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantc51e1022010-05-11 19:42:16 +00002939{
2940 size_type __sz = size();
2941 if (__pos > __sz)
2942 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002943 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002944 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002945 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002946 if (__cap - __sz + __n1 >= __n2)
2947 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002948 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002949 if (__n1 != __n2)
2950 {
2951 size_type __n_move = __sz - __pos - __n1;
2952 if (__n_move != 0)
2953 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2954 }
2955 }
2956 else
2957 {
2958 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002959 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002960 }
2961 traits_type::assign(__p + __pos, __n2, __c);
2962 __sz += __n2 - __n1;
2963 __set_size(__sz);
2964 __invalidate_iterators_past(__sz);
2965 traits_type::assign(__p[__sz], value_type());
2966 return *this;
2967}
2968
2969template <class _CharT, class _Traits, class _Allocator>
2970template<class _InputIterator>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002971_EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002972<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05002973 __is_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002974 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002975>
Howard Hinnant990d6e82010-11-17 21:11:40 +00002976basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002977 _InputIterator __j1, _InputIterator __j2)
2978{
Marshall Clow958362f2016-09-05 01:54:30 +00002979 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clow039b2f02016-01-13 21:54:34 +00002980 return this->replace(__i1, __i2, __temp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002981}
2982
2983template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00002984inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00002985basic_string<_CharT, _Traits, _Allocator>&
2986basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2987{
2988 return replace(__pos1, __n1, __str.data(), __str.size());
2989}
2990
2991template <class _CharT, class _Traits, class _Allocator>
2992basic_string<_CharT, _Traits, _Allocator>&
2993basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2994 size_type __pos2, size_type __n2)
2995{
2996 size_type __str_sz = __str.size();
2997 if (__pos2 > __str_sz)
2998 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002999 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003000}
3001
3002template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00003003template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003004_EnableIf
Marshall Clow82513342016-09-24 22:45:42 +00003005<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003006 __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 +00003007 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003008>
Marshall Clow82513342016-09-24 22:45:42 +00003009basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003010 size_type __pos2, size_type __n2)
3011{
Marshall Clow82513342016-09-24 22:45:42 +00003012 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003013 size_type __str_sz = __sv.size();
3014 if (__pos2 > __str_sz)
3015 this->__throw_out_of_range();
3016 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
3017}
3018
3019template <class _CharT, class _Traits, class _Allocator>
3020basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00003021basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003022{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003023 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003024 return replace(__pos, __n1, __s, traits_type::length(__s));
3025}
3026
3027template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003028inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003029basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant990d6e82010-11-17 21:11:40 +00003030basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003031{
3032 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
3033 __str.data(), __str.size());
3034}
3035
3036template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003037inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003038basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00003039basic_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 +00003040{
3041 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
3042}
3043
3044template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003045inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003046basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00003047basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003048{
3049 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
3050}
3051
3052template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003053inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003054basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant990d6e82010-11-17 21:11:40 +00003055basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003056{
3057 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
3058}
3059
3060// erase
3061
Martijn Velsa81fc792020-02-26 13:25:43 -05003062// 'externally instantiated' erase() implementation, called when __n != npos.
3063// Does not check __pos against size()
Howard Hinnantc51e1022010-05-11 19:42:16 +00003064template <class _CharT, class _Traits, class _Allocator>
Martijn Velsa81fc792020-02-26 13:25:43 -05003065void
3066basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move(
3067 size_type __pos, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003068{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003069 if (__n)
3070 {
Martijn Velsa81fc792020-02-26 13:25:43 -05003071 size_type __sz = size();
Eric Fiselierc1b87a72019-11-16 17:13:26 -05003072 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003073 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003074 size_type __n_move = __sz - __pos - __n;
3075 if (__n_move != 0)
3076 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3077 __sz -= __n;
3078 __set_size(__sz);
3079 __invalidate_iterators_past(__sz);
3080 traits_type::assign(__p[__sz], value_type());
3081 }
Martijn Velsa81fc792020-02-26 13:25:43 -05003082}
3083
3084template <class _CharT, class _Traits, class _Allocator>
3085basic_string<_CharT, _Traits, _Allocator>&
3086basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos,
3087 size_type __n) {
3088 if (__pos > size()) this->__throw_out_of_range();
3089 if (__n == npos) {
3090 __erase_to_end(__pos);
3091 } else {
3092 __erase_external_with_move(__pos, __n);
3093 }
3094 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003095}
3096
3097template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003098inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003099typename basic_string<_CharT, _Traits, _Allocator>::iterator
3100basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3101{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003102#if _LIBCPP_DEBUG_LEVEL >= 2
3103 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3104 "string::erase(iterator) called with an iterator not"
3105 " referring to this string");
3106#endif
3107 _LIBCPP_ASSERT(__pos != end(),
3108 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003109 iterator __b = begin();
3110 size_type __r = static_cast<size_type>(__pos - __b);
3111 erase(__r, 1);
Howard Hinnant28b24882011-12-01 20:21:04 +00003112 return __b + static_cast<difference_type>(__r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003113}
3114
3115template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003116inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003117typename basic_string<_CharT, _Traits, _Allocator>::iterator
3118basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3119{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003120#if _LIBCPP_DEBUG_LEVEL >= 2
3121 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3122 "string::erase(iterator, iterator) called with an iterator not"
3123 " referring to this string");
3124#endif
3125 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003126 iterator __b = begin();
3127 size_type __r = static_cast<size_type>(__first - __b);
3128 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnant28b24882011-12-01 20:21:04 +00003129 return __b + static_cast<difference_type>(__r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003130}
3131
3132template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003133inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003134void
3135basic_string<_CharT, _Traits, _Allocator>::pop_back()
3136{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003137 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003138 size_type __sz;
3139 if (__is_long())
3140 {
3141 __sz = __get_long_size() - 1;
3142 __set_long_size(__sz);
3143 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3144 }
3145 else
3146 {
3147 __sz = __get_short_size() - 1;
3148 __set_short_size(__sz);
3149 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3150 }
3151 __invalidate_iterators_past(__sz);
3152}
3153
3154template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003155inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003156void
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003157basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003158{
3159 __invalidate_all_iterators();
3160 if (__is_long())
3161 {
3162 traits_type::assign(*__get_long_pointer(), value_type());
3163 __set_long_size(0);
3164 }
3165 else
3166 {
3167 traits_type::assign(*__get_short_pointer(), value_type());
3168 __set_short_size(0);
3169 }
3170}
3171
3172template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003173inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003174void
3175basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3176{
3177 if (__is_long())
3178 {
3179 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3180 __set_long_size(__pos);
3181 }
3182 else
3183 {
3184 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3185 __set_short_size(__pos);
3186 }
3187 __invalidate_iterators_past(__pos);
3188}
3189
3190template <class _CharT, class _Traits, class _Allocator>
3191void
3192basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3193{
3194 size_type __sz = size();
3195 if (__n > __sz)
3196 append(__n - __sz, __c);
3197 else
3198 __erase_to_end(__n);
3199}
3200
3201template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier451d5582018-11-26 20:15:38 +00003202inline void
3203basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
3204{
3205 size_type __sz = size();
3206 if (__n > __sz) {
3207 __append_default_init(__n - __sz);
3208 } else
3209 __erase_to_end(__n);
3210}
3211
3212template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003213inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003214typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003215basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003216{
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003217 size_type __m = __alloc_traits::max_size(__alloc());
Eric Fiseliere9cc5922017-10-17 13:16:01 +00003218#ifdef _LIBCPP_BIG_ENDIAN
Marshall Clow6dd6cb72013-10-31 17:23:08 +00003219 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003220#else
Marshall Clow6dd6cb72013-10-31 17:23:08 +00003221 return __m - __alignment;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003222#endif
3223}
3224
3225template <class _CharT, class _Traits, class _Allocator>
3226void
3227basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3228{
3229 if (__res_arg > max_size())
3230 this->__throw_length_error();
3231 size_type __cap = capacity();
3232 size_type __sz = size();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003233 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003234 __res_arg = __recommend(__res_arg);
3235 if (__res_arg != __cap)
3236 {
3237 pointer __new_data, __p;
3238 bool __was_long, __now_long;
3239 if (__res_arg == __min_cap - 1)
3240 {
3241 __was_long = true;
3242 __now_long = false;
3243 __new_data = __get_short_pointer();
3244 __p = __get_long_pointer();
3245 }
3246 else
3247 {
3248 if (__res_arg > __cap)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003249 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003250 else
3251 {
3252 #ifndef _LIBCPP_NO_EXCEPTIONS
3253 try
3254 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003255 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003256 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003257 #ifndef _LIBCPP_NO_EXCEPTIONS
3258 }
3259 catch (...)
3260 {
3261 return;
3262 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003263 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantd17880b2013-06-28 16:59:19 +00003264 if (__new_data == nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003265 return;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003266 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00003267 }
3268 __now_long = true;
3269 __was_long = __is_long();
3270 __p = __get_pointer();
3271 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05003272 traits_type::copy(_VSTD::__to_address(__new_data),
3273 _VSTD::__to_address(__p), size()+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003274 if (__was_long)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003275 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003276 if (__now_long)
3277 {
3278 __set_long_cap(__res_arg+1);
3279 __set_long_size(__sz);
3280 __set_long_pointer(__new_data);
3281 }
3282 else
3283 __set_short_size(__sz);
3284 __invalidate_all_iterators();
3285 }
3286}
3287
3288template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003289inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003290typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003291basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003292{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003293 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003294 return *(data() + __pos);
3295}
3296
3297template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003298inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003299typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003300basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003301{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003302 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003303 return *(__get_pointer() + __pos);
3304}
3305
3306template <class _CharT, class _Traits, class _Allocator>
3307typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3308basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3309{
3310 if (__n >= size())
3311 this->__throw_out_of_range();
3312 return (*this)[__n];
3313}
3314
3315template <class _CharT, class _Traits, class _Allocator>
3316typename basic_string<_CharT, _Traits, _Allocator>::reference
3317basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3318{
3319 if (__n >= size())
3320 this->__throw_out_of_range();
3321 return (*this)[__n];
3322}
3323
3324template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003325inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003326typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003327basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003328{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003329 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003330 return *__get_pointer();
3331}
3332
3333template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003334inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003335typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003336basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003337{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003338 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003339 return *data();
3340}
3341
3342template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003343inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003344typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003345basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003346{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003347 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003348 return *(__get_pointer() + size() - 1);
3349}
3350
3351template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003352inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003353typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003354basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003355{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003356 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003357 return *(data() + size() - 1);
3358}
3359
3360template <class _CharT, class _Traits, class _Allocator>
3361typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003362basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003363{
3364 size_type __sz = size();
3365 if (__pos > __sz)
3366 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003367 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003368 traits_type::copy(__s, data() + __pos, __rlen);
3369 return __rlen;
3370}
3371
3372template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003373inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003374basic_string<_CharT, _Traits, _Allocator>
3375basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3376{
3377 return basic_string(*this, __pos, __n, __alloc());
3378}
3379
3380template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003381inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003382void
3383basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow8982dcd2015-07-13 20:04:56 +00003384#if _LIBCPP_STD_VER >= 14
Eric Fiselier873b8d32019-03-18 21:50:12 +00003385 _NOEXCEPT
Marshall Clow8982dcd2015-07-13 20:04:56 +00003386#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00003387 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow8982dcd2015-07-13 20:04:56 +00003388 __is_nothrow_swappable<allocator_type>::value)
3389#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003390{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003391#if _LIBCPP_DEBUG_LEVEL >= 2
3392 if (!__is_long())
3393 __get_db()->__invalidate_all(this);
3394 if (!__str.__is_long())
3395 __get_db()->__invalidate_all(&__str);
3396 __get_db()->swap(this, &__str);
3397#endif
Eric Fiselier9bf691f2016-12-28 05:53:01 +00003398 _LIBCPP_ASSERT(
3399 __alloc_traits::propagate_on_container_swap::value ||
3400 __alloc_traits::is_always_equal::value ||
3401 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003402 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow8982dcd2015-07-13 20:04:56 +00003403 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003404}
3405
3406// find
3407
3408template <class _Traits>
3409struct _LIBCPP_HIDDEN __traits_eq
3410{
3411 typedef typename _Traits::char_type char_type;
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003412 _LIBCPP_INLINE_VISIBILITY
3413 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3414 {return _Traits::eq(__x, __y);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003415};
3416
3417template<class _CharT, class _Traits, class _Allocator>
3418typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003419basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003420 size_type __pos,
3421 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003422{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003423 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003424 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003425 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003426}
3427
3428template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003429inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003430typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003431basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3432 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003433{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003434 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003435 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003436}
3437
3438template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003439template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003440_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003441<
3442 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3443 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003444>
Marshall Clowe46031a2018-07-02 18:41:15 +00003445basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
3446 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003447{
Marshall Clowe46031a2018-07-02 18:41:15 +00003448 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003449 return __str_find<value_type, size_type, traits_type, npos>
3450 (data(), size(), __sv.data(), __pos, __sv.size());
3451}
3452
3453template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003454inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003455typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003456basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003457 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003458{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003459 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003460 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003461 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003462}
3463
3464template<class _CharT, class _Traits, class _Allocator>
3465typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003466basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3467 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003468{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003469 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003470 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003471}
3472
3473// rfind
3474
3475template<class _CharT, class _Traits, class _Allocator>
3476typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003477basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003478 size_type __pos,
3479 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003480{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003481 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003482 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003483 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003484}
3485
3486template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003487inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003488typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003489basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3490 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003491{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003492 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003493 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003494}
3495
3496template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003497template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003498_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003499<
3500 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3501 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003502>
Marshall Clowe46031a2018-07-02 18:41:15 +00003503basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
3504 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003505{
Marshall Clowe46031a2018-07-02 18:41:15 +00003506 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003507 return __str_rfind<value_type, size_type, traits_type, npos>
3508 (data(), size(), __sv.data(), __pos, __sv.size());
3509}
3510
3511template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003512inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003513typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003514basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003515 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003516{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003517 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003518 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003519 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003520}
3521
3522template<class _CharT, class _Traits, class _Allocator>
3523typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003524basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3525 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003526{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003527 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003528 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003529}
3530
3531// find_first_of
3532
3533template<class _CharT, class _Traits, class _Allocator>
3534typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003535basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003536 size_type __pos,
3537 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003538{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003539 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003540 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003541 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003542}
3543
3544template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003545inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003546typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003547basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3548 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003549{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003550 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003551 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003552}
3553
3554template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003555template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003556_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003557<
3558 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3559 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003560>
Marshall Clowe46031a2018-07-02 18:41:15 +00003561basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
3562 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003563{
Marshall Clowe46031a2018-07-02 18:41:15 +00003564 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003565 return __str_find_first_of<value_type, size_type, traits_type, npos>
3566 (data(), size(), __sv.data(), __pos, __sv.size());
3567}
3568
3569template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003570inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003571typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003572basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003573 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003574{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003575 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003576 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003577 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003578}
3579
3580template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003581inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003582typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003583basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3584 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003585{
3586 return find(__c, __pos);
3587}
3588
3589// find_last_of
3590
3591template<class _CharT, class _Traits, class _Allocator>
3592typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003593basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003594 size_type __pos,
3595 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003596{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003597 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003598 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003599 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003600}
3601
3602template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003603inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003604typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003605basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3606 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003607{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003608 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003609 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003610}
3611
3612template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003613template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003614_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003615<
3616 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3617 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003618>
Marshall Clowe46031a2018-07-02 18:41:15 +00003619basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
3620 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003621{
Marshall Clowe46031a2018-07-02 18:41:15 +00003622 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003623 return __str_find_last_of<value_type, size_type, traits_type, npos>
3624 (data(), size(), __sv.data(), __pos, __sv.size());
3625}
3626
3627template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003628inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003629typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003630basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003631 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003632{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003633 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003634 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003635 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003636}
3637
3638template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003639inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003640typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003641basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3642 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003643{
3644 return rfind(__c, __pos);
3645}
3646
3647// find_first_not_of
3648
3649template<class _CharT, class _Traits, class _Allocator>
3650typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003651basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003652 size_type __pos,
3653 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003654{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003655 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003656 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003657 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003658}
3659
3660template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003661inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003662typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003663basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3664 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003665{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003666 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003667 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003668}
3669
3670template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003671template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003672_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003673<
3674 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3675 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003676>
Marshall Clowe46031a2018-07-02 18:41:15 +00003677basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
3678 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003679{
Marshall Clowe46031a2018-07-02 18:41:15 +00003680 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003681 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3682 (data(), size(), __sv.data(), __pos, __sv.size());
3683}
3684
3685template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003686inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003687typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003688basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003689 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003690{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003691 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003692 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003693 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003694}
3695
3696template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003697inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003698typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003699basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3700 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003701{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003702 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003703 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003704}
3705
3706// find_last_not_of
3707
3708template<class _CharT, class _Traits, class _Allocator>
3709typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003710basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003711 size_type __pos,
3712 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003713{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003714 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003715 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003716 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003717}
3718
3719template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003720inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003721typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003722basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3723 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003724{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003725 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003726 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003727}
3728
3729template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003730template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003731_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003732<
3733 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3734 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003735>
Marshall Clowe46031a2018-07-02 18:41:15 +00003736basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
3737 size_type __pos) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003738{
Marshall Clowe46031a2018-07-02 18:41:15 +00003739 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003740 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3741 (data(), size(), __sv.data(), __pos, __sv.size());
3742}
3743
3744template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003745inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003746typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003747basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003748 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003749{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003750 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003751 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003752 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003753}
3754
3755template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003756inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003757typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003758basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3759 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003760{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003761 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003762 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003763}
3764
3765// compare
3766
3767template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003768template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003769_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003770<
3771 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3772 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003773>
Marshall Clowe46031a2018-07-02 18:41:15 +00003774basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003775{
Marshall Clowe46031a2018-07-02 18:41:15 +00003776 __self_view __sv = __t;
Howard Hinnantb0485532011-07-24 21:45:06 +00003777 size_t __lhs_sz = size();
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003778 size_t __rhs_sz = __sv.size();
3779 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantb0485532011-07-24 21:45:06 +00003780 _VSTD::min(__lhs_sz, __rhs_sz));
3781 if (__result != 0)
3782 return __result;
3783 if (__lhs_sz < __rhs_sz)
3784 return -1;
3785 if (__lhs_sz > __rhs_sz)
3786 return 1;
3787 return 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003788}
3789
3790template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003791inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003792int
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003793basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003794{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003795 return compare(__self_view(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003796}
3797
3798template <class _CharT, class _Traits, class _Allocator>
3799int
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003800basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3801 size_type __n1,
Howard Hinnantd17880b2013-06-28 16:59:19 +00003802 const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003803 size_type __n2) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003804{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003805 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003806 size_type __sz = size();
3807 if (__pos1 > __sz || __n2 == npos)
3808 this->__throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003809 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3810 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003811 if (__r == 0)
3812 {
3813 if (__rlen < __n2)
3814 __r = -1;
3815 else if (__rlen > __n2)
3816 __r = 1;
3817 }
3818 return __r;
3819}
3820
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003821template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003822template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003823_EnableIf
Marshall Clowe46031a2018-07-02 18:41:15 +00003824<
3825 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3826 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003827>
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003828basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3829 size_type __n1,
Marshall Clowe46031a2018-07-02 18:41:15 +00003830 const _Tp& __t) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003831{
Marshall Clowe46031a2018-07-02 18:41:15 +00003832 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003833 return compare(__pos1, __n1, __sv.data(), __sv.size());
3834}
3835
3836template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003837inline
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003838int
3839basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3840 size_type __n1,
3841 const basic_string& __str) const
3842{
3843 return compare(__pos1, __n1, __str.data(), __str.size());
3844}
3845
3846template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00003847template <class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003848_EnableIf
Marshall Clow82513342016-09-24 22:45:42 +00003849<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003850 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
3851 && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00003852 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003853>
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003854basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3855 size_type __n1,
Marshall Clow82513342016-09-24 22:45:42 +00003856 const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003857 size_type __pos2,
3858 size_type __n2) const
3859{
Marshall Clow82513342016-09-24 22:45:42 +00003860 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003861 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3862}
3863
3864template <class _CharT, class _Traits, class _Allocator>
3865int
3866basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3867 size_type __n1,
3868 const basic_string& __str,
3869 size_type __pos2,
3870 size_type __n2) const
3871{
3872 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3873}
3874
3875template <class _CharT, class _Traits, class _Allocator>
3876int
3877basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3878{
3879 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3880 return compare(0, npos, __s, traits_type::length(__s));
3881}
3882
3883template <class _CharT, class _Traits, class _Allocator>
3884int
3885basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3886 size_type __n1,
3887 const value_type* __s) const
3888{
3889 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3890 return compare(__pos1, __n1, __s, traits_type::length(__s));
3891}
3892
Howard Hinnantc51e1022010-05-11 19:42:16 +00003893// __invariants
3894
3895template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003896inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00003897bool
3898basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3899{
3900 if (size() > capacity())
3901 return false;
3902 if (capacity() < __min_cap - 1)
3903 return false;
3904 if (data() == 0)
3905 return false;
3906 if (data()[size()] != value_type(0))
3907 return false;
3908 return true;
3909}
3910
Vedant Kumar55e007e2018-03-08 21:15:26 +00003911// __clear_and_shrink
3912
3913template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00003914inline
Louis Dionne173f29e2019-05-29 16:01:36 +00003915void
Marshall Clowe60a7182018-05-29 17:04:37 +00003916basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
Vedant Kumar55e007e2018-03-08 21:15:26 +00003917{
3918 clear();
3919 if(__is_long())
3920 {
3921 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
3922 __set_long_cap(0);
3923 __set_short_size(0);
3924 }
Louis Dionne173f29e2019-05-29 16:01:36 +00003925}
Vedant Kumar55e007e2018-03-08 21:15:26 +00003926
Howard Hinnantc51e1022010-05-11 19:42:16 +00003927// operator==
3928
3929template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003930inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003931bool
3932operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003933 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003934{
Howard Hinnantaaeb1132013-04-22 23:55:13 +00003935 size_t __lhs_sz = __lhs.size();
3936 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3937 __rhs.data(),
3938 __lhs_sz) == 0;
3939}
3940
3941template<class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003942inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaaeb1132013-04-22 23:55:13 +00003943bool
3944operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3945 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3946{
3947 size_t __lhs_sz = __lhs.size();
3948 if (__lhs_sz != __rhs.size())
3949 return false;
3950 const char* __lp = __lhs.data();
3951 const char* __rp = __rhs.data();
3952 if (__lhs.__is_long())
3953 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3954 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3955 if (*__lp != *__rp)
3956 return false;
3957 return true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003958}
3959
3960template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003961inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003962bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003963operator==(const _CharT* __lhs,
3964 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003965{
Eric Fiselier0cafa3f2015-08-28 03:02:37 +00003966 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3967 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3968 size_t __lhs_len = _Traits::length(__lhs);
3969 if (__lhs_len != __rhs.size()) return false;
3970 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003971}
3972
Howard Hinnantc51e1022010-05-11 19:42:16 +00003973template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003974inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003975bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003976operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3977 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003978{
Eric Fiselier0cafa3f2015-08-28 03:02:37 +00003979 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3980 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3981 size_t __rhs_len = _Traits::length(__rhs);
3982 if (__rhs_len != __lhs.size()) return false;
3983 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003984}
3985
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003986template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003987inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003988bool
3989operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003990 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003991{
3992 return !(__lhs == __rhs);
3993}
3994
3995template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00003996inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003997bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003998operator!=(const _CharT* __lhs,
3999 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004000{
4001 return !(__lhs == __rhs);
4002}
4003
4004template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004005inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004006bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004007operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4008 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004009{
4010 return !(__lhs == __rhs);
4011}
4012
4013// operator<
4014
4015template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004016inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004017bool
4018operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004019 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004020{
Howard Hinnanta2660c12011-07-24 15:07:21 +00004021 return __lhs.compare(__rhs) < 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004022}
4023
4024template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004025inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004026bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004027operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4028 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004029{
Howard Hinnanta2660c12011-07-24 15:07:21 +00004030 return __lhs.compare(__rhs) < 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004031}
4032
4033template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004034inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004035bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004036operator< (const _CharT* __lhs,
4037 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004038{
4039 return __rhs.compare(__lhs) > 0;
4040}
4041
Howard Hinnantc51e1022010-05-11 19:42:16 +00004042// operator>
4043
4044template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004045inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004046bool
4047operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004048 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004049{
4050 return __rhs < __lhs;
4051}
4052
4053template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004054inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004055bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004056operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4057 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004058{
4059 return __rhs < __lhs;
4060}
4061
4062template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004063inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004064bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004065operator> (const _CharT* __lhs,
4066 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004067{
4068 return __rhs < __lhs;
4069}
4070
4071// operator<=
4072
4073template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004074inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004075bool
4076operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004077 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004078{
4079 return !(__rhs < __lhs);
4080}
4081
4082template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004083inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004084bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004085operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4086 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004087{
4088 return !(__rhs < __lhs);
4089}
4090
4091template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004092inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004093bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004094operator<=(const _CharT* __lhs,
4095 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004096{
4097 return !(__rhs < __lhs);
4098}
4099
4100// operator>=
4101
4102template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004103inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004104bool
4105operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004106 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004107{
4108 return !(__lhs < __rhs);
4109}
4110
4111template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004112inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004113bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004114operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4115 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004116{
4117 return !(__lhs < __rhs);
4118}
4119
4120template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004121inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004122bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004123operator>=(const _CharT* __lhs,
4124 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004125{
4126 return !(__lhs < __rhs);
4127}
4128
4129// operator +
4130
4131template<class _CharT, class _Traits, class _Allocator>
4132basic_string<_CharT, _Traits, _Allocator>
4133operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4134 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4135{
4136 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4137 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4138 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4139 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4140 __r.append(__rhs.data(), __rhs_sz);
4141 return __r;
4142}
4143
4144template<class _CharT, class _Traits, class _Allocator>
4145basic_string<_CharT, _Traits, _Allocator>
4146operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4147{
4148 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4149 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4150 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4151 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4152 __r.append(__rhs.data(), __rhs_sz);
4153 return __r;
4154}
4155
4156template<class _CharT, class _Traits, class _Allocator>
4157basic_string<_CharT, _Traits, _Allocator>
4158operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4159{
4160 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4161 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4162 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4163 __r.append(__rhs.data(), __rhs_sz);
4164 return __r;
4165}
4166
4167template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierbea70602018-11-26 22:51:35 +00004168inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004169basic_string<_CharT, _Traits, _Allocator>
4170operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4171{
4172 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4173 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4174 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4175 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4176 __r.append(__rhs, __rhs_sz);
4177 return __r;
4178}
4179
4180template<class _CharT, class _Traits, class _Allocator>
4181basic_string<_CharT, _Traits, _Allocator>
4182operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4183{
4184 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4185 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4186 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4187 __r.push_back(__rhs);
4188 return __r;
4189}
4190
Eric Fiselierfc92be82017-04-19 00:28:44 +00004191#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00004192
4193template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004194inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004195basic_string<_CharT, _Traits, _Allocator>
4196operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4197{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004198 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004199}
4200
4201template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004202inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004203basic_string<_CharT, _Traits, _Allocator>
4204operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4205{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004206 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004207}
4208
4209template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004210inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004211basic_string<_CharT, _Traits, _Allocator>
4212operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4213{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004214 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004215}
4216
4217template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004218inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004219basic_string<_CharT, _Traits, _Allocator>
4220operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4221{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004222 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004223}
4224
4225template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004226inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004227basic_string<_CharT, _Traits, _Allocator>
4228operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4229{
4230 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004231 return _VSTD::move(__rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004232}
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 +00004236basic_string<_CharT, _Traits, _Allocator>
4237operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4238{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004239 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004240}
4241
4242template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004243inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004244basic_string<_CharT, _Traits, _Allocator>
4245operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4246{
4247 __lhs.push_back(__rhs);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004248 return _VSTD::move(__lhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004249}
4250
Eric Fiselierfc92be82017-04-19 00:28:44 +00004251#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00004252
4253// swap
4254
4255template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +00004256inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004257void
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004258swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant3e276872011-06-03 18:40:47 +00004259 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4260 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00004261{
4262 __lhs.swap(__rhs);
4263}
4264
Marshall Clow8732fed2018-12-11 04:35:44 +00004265#ifndef _LIBCPP_NO_HAS_CHAR8_T
4266typedef basic_string<char8_t> u8string;
4267#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00004268
Marshall Clow8732fed2018-12-11 04:35:44 +00004269#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004270typedef basic_string<char16_t> u16string;
4271typedef basic_string<char32_t> u32string;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004272#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004273
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004274_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4275_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4276_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4277_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4278_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004279
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004280_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4281_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4282_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004283
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004284_LIBCPP_FUNC_VIS string to_string(int __val);
4285_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4286_LIBCPP_FUNC_VIS string to_string(long __val);
4287_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4288_LIBCPP_FUNC_VIS string to_string(long long __val);
4289_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4290_LIBCPP_FUNC_VIS string to_string(float __val);
4291_LIBCPP_FUNC_VIS string to_string(double __val);
4292_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004293
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004294_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4295_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4296_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4297_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4298_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004299
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004300_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4301_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4302_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004303
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004304_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4305_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4306_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4307_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4308_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4309_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4310_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4311_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4312_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004313
Howard Hinnantc51e1022010-05-11 19:42:16 +00004314template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc9fdaf12020-01-15 17:02:17 -05004315_LIBCPP_FUNC_VIS
4316const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4317 basic_string<_CharT, _Traits, _Allocator>::npos;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004318
Marshall Clow851b9ec2019-05-20 21:56:51 +00004319template <class _CharT, class _Allocator>
4320struct _LIBCPP_TEMPLATE_VIS
4321 hash<basic_string<_CharT, char_traits<_CharT>, _Allocator> >
4322 : public unary_function<
4323 basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004324{
4325 size_t
Marshall Clow851b9ec2019-05-20 21:56:51 +00004326 operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT
4327 { return __do_string_hash(__val.data(), __val.data() + __val.size()); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00004328};
4329
Howard Hinnantc51e1022010-05-11 19:42:16 +00004330
Howard Hinnantdc095972011-07-18 15:51:59 +00004331template<class _CharT, class _Traits, class _Allocator>
4332basic_ostream<_CharT, _Traits>&
4333operator<<(basic_ostream<_CharT, _Traits>& __os,
4334 const basic_string<_CharT, _Traits, _Allocator>& __str);
4335
4336template<class _CharT, class _Traits, class _Allocator>
4337basic_istream<_CharT, _Traits>&
4338operator>>(basic_istream<_CharT, _Traits>& __is,
4339 basic_string<_CharT, _Traits, _Allocator>& __str);
4340
4341template<class _CharT, class _Traits, class _Allocator>
4342basic_istream<_CharT, _Traits>&
4343getline(basic_istream<_CharT, _Traits>& __is,
4344 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4345
4346template<class _CharT, class _Traits, class _Allocator>
4347inline _LIBCPP_INLINE_VISIBILITY
4348basic_istream<_CharT, _Traits>&
4349getline(basic_istream<_CharT, _Traits>& __is,
4350 basic_string<_CharT, _Traits, _Allocator>& __str);
4351
Eric Fiselierfc92be82017-04-19 00:28:44 +00004352#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantdc095972011-07-18 15:51:59 +00004353
4354template<class _CharT, class _Traits, class _Allocator>
4355inline _LIBCPP_INLINE_VISIBILITY
4356basic_istream<_CharT, _Traits>&
4357getline(basic_istream<_CharT, _Traits>&& __is,
4358 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4359
4360template<class _CharT, class _Traits, class _Allocator>
4361inline _LIBCPP_INLINE_VISIBILITY
4362basic_istream<_CharT, _Traits>&
4363getline(basic_istream<_CharT, _Traits>&& __is,
4364 basic_string<_CharT, _Traits, _Allocator>& __str);
4365
Eric Fiselierfc92be82017-04-19 00:28:44 +00004366#endif // _LIBCPP_CXX03_LANG
Howard Hinnantdc095972011-07-18 15:51:59 +00004367
Marshall Clow29b53f22018-12-14 18:49:35 +00004368#if _LIBCPP_STD_VER > 17
4369template<class _CharT, class _Traits, class _Allocator, class _Up>
4370inline _LIBCPP_INLINE_VISIBILITY
4371void erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v)
4372{ __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end()); }
4373
4374template<class _CharT, class _Traits, class _Allocator, class _Predicate>
4375inline _LIBCPP_INLINE_VISIBILITY
4376void erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, _Predicate __pred)
4377{ __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred), __str.end()); }
4378#endif
4379
Howard Hinnant8ea98242013-08-23 17:37:05 +00004380#if _LIBCPP_DEBUG_LEVEL >= 2
4381
4382template<class _CharT, class _Traits, class _Allocator>
4383bool
4384basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4385{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004386 return this->data() <= _VSTD::__to_address(__i->base()) &&
4387 _VSTD::__to_address(__i->base()) < this->data() + this->size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004388}
4389
4390template<class _CharT, class _Traits, class _Allocator>
4391bool
4392basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4393{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004394 return this->data() < _VSTD::__to_address(__i->base()) &&
4395 _VSTD::__to_address(__i->base()) <= this->data() + this->size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004396}
4397
4398template<class _CharT, class _Traits, class _Allocator>
4399bool
4400basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4401{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004402 const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
Howard Hinnant8ea98242013-08-23 17:37:05 +00004403 return this->data() <= __p && __p <= this->data() + this->size();
4404}
4405
4406template<class _CharT, class _Traits, class _Allocator>
4407bool
4408basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4409{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004410 const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
Howard Hinnant8ea98242013-08-23 17:37:05 +00004411 return this->data() <= __p && __p < this->data() + this->size();
4412}
4413
4414#endif // _LIBCPP_DEBUG_LEVEL >= 2
4415
Martijn Velsb17d5802020-03-02 10:11:35 -05004416#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
Martijn Vels1e63ba02020-02-19 16:27:50 -05004417_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
4418_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
4419#else
4420_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
4421_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
4422#endif
Shoaib Meenai6eb5f112017-06-29 02:52:46 +00004423
Louis Dionne173f29e2019-05-29 16:01:36 +00004424#if _LIBCPP_STD_VER > 11
Marshall Clowcba751f2013-07-23 17:05:24 +00004425// Literal suffixes for basic_string [basic.string.literals]
Marshall Clowac868372013-10-05 21:18:32 +00004426inline namespace literals
Marshall Clowcba751f2013-07-23 17:05:24 +00004427{
4428 inline namespace string_literals
4429 {
Howard Hinnant5c167562013-08-07 19:39:48 +00004430 inline _LIBCPP_INLINE_VISIBILITY
4431 basic_string<char> operator "" s( const char *__str, size_t __len )
4432 {
4433 return basic_string<char> (__str, __len);
4434 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004435
Howard Hinnant5c167562013-08-07 19:39:48 +00004436 inline _LIBCPP_INLINE_VISIBILITY
4437 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4438 {
4439 return basic_string<wchar_t> (__str, __len);
4440 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004441
Marshall Clow8732fed2018-12-11 04:35:44 +00004442#ifndef _LIBCPP_NO_HAS_CHAR8_T
4443 inline _LIBCPP_INLINE_VISIBILITY
4444 basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPT
4445 {
4446 return basic_string<char8_t> (__str, __len);
4447 }
4448#endif
4449
Howard Hinnant5c167562013-08-07 19:39:48 +00004450 inline _LIBCPP_INLINE_VISIBILITY
4451 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4452 {
4453 return basic_string<char16_t> (__str, __len);
4454 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004455
Howard Hinnant5c167562013-08-07 19:39:48 +00004456 inline _LIBCPP_INLINE_VISIBILITY
4457 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4458 {
4459 return basic_string<char32_t> (__str, __len);
4460 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004461 }
4462}
4463#endif
4464
Howard Hinnantc51e1022010-05-11 19:42:16 +00004465_LIBCPP_END_NAMESPACE_STD
4466
Eric Fiselierf4433a32017-05-31 22:07:49 +00004467_LIBCPP_POP_MACROS
4468
Howard Hinnantc51e1022010-05-11 19:42:16 +00004469#endif // _LIBCPP_STRING