blob: fb838d1e5dd2864cb05c11a6a4befe4a115edeaf [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- string -----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_STRING
12#define _LIBCPP_STRING
13
14/*
15 string synopsis
16
17namespace std
18{
19
20template <class stateT>
21class fpos
22{
23private:
24 stateT st;
25public:
26 fpos(streamoff = streamoff());
27
28 operator streamoff() const;
29
30 stateT state() const;
31 void state(stateT);
32
33 fpos& operator+=(streamoff);
34 fpos operator+ (streamoff) const;
35 fpos& operator-=(streamoff);
36 fpos operator- (streamoff) const;
37};
38
39template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
40
41template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
42template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
43
44template <class charT>
45struct char_traits
46{
47 typedef charT char_type;
48 typedef ... int_type;
49 typedef streamoff off_type;
50 typedef streampos pos_type;
51 typedef mbstate_t state_type;
52
Howard Hinnanta6119a82011-05-29 19:57:12 +000053 static void assign(char_type& c1, const char_type& c2) noexcept;
Howard Hinnant03d71812012-07-20 19:09:12 +000054 static constexpr bool eq(char_type c1, char_type c2) noexcept;
55 static constexpr bool lt(char_type c1, char_type c2) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056
57 static int compare(const char_type* s1, const char_type* s2, size_t n);
58 static size_t length(const char_type* s);
59 static const char_type* find(const char_type* s, size_t n, const char_type& a);
60 static char_type* move(char_type* s1, const char_type* s2, size_t n);
61 static char_type* copy(char_type* s1, const char_type* s2, size_t n);
62 static char_type* assign(char_type* s, size_t n, char_type a);
63
Howard Hinnant03d71812012-07-20 19:09:12 +000064 static constexpr int_type not_eof(int_type c) noexcept;
65 static constexpr char_type to_char_type(int_type c) noexcept;
66 static constexpr int_type to_int_type(char_type c) noexcept;
67 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
68 static constexpr int_type eof() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000069};
70
71template <> struct char_traits<char>;
72template <> struct char_traits<wchar_t>;
73
Howard Hinnant324bb032010-08-22 00:02:43 +000074template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000075class basic_string
76{
Howard Hinnant324bb032010-08-22 00:02:43 +000077public:
78// types:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000079 typedef traits traits_type;
80 typedef typename traits_type::char_type value_type;
81 typedef Allocator allocator_type;
82 typedef typename allocator_type::size_type size_type;
83 typedef typename allocator_type::difference_type difference_type;
84 typedef typename allocator_type::reference reference;
85 typedef typename allocator_type::const_reference const_reference;
86 typedef typename allocator_type::pointer pointer;
87 typedef typename allocator_type::const_pointer const_pointer;
88 typedef implementation-defined iterator;
89 typedef implementation-defined const_iterator;
90 typedef std::reverse_iterator<iterator> reverse_iterator;
91 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
92
93 static const size_type npos = -1;
94
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000095 basic_string()
96 noexcept(is_nothrow_default_constructible<allocator_type>::value);
97 explicit basic_string(const allocator_type& a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000098 basic_string(const basic_string& str);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000099 basic_string(basic_string&& str)
100 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000101 basic_string(const basic_string& str, size_type pos,
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000102 const allocator_type& a = allocator_type());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000103 basic_string(const basic_string& str, size_type pos, size_type n,
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000104 const Allocator& a = Allocator());
Marshall Clowdb7fa112016-11-14 18:22:19 +0000105 template<class T>
106 basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
Marshall Clow64c10d02018-07-02 18:41:15 +0000107 template <class T>
108 explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000109 basic_string(const value_type* s, const allocator_type& a = allocator_type());
110 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000111 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
112 template<class InputIterator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000113 basic_string(InputIterator begin, InputIterator end,
114 const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000115 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
116 basic_string(const basic_string&, const Allocator&);
117 basic_string(basic_string&&, const Allocator&);
118
119 ~basic_string();
120
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000121 operator basic_string_view<charT, traits>() const noexcept;
122
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000123 basic_string& operator=(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000124 template <class T>
125 basic_string& operator=(const T& t); // C++17
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000126 basic_string& operator=(basic_string&& str)
127 noexcept(
Marshall Clowaf961ed2015-08-18 18:57:00 +0000128 allocator_type::propagate_on_container_move_assignment::value ||
129 allocator_type::is_always_equal::value ); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000130 basic_string& operator=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000131 basic_string& operator=(value_type c);
132 basic_string& operator=(initializer_list<value_type>);
133
Howard Hinnanta6119a82011-05-29 19:57:12 +0000134 iterator begin() noexcept;
135 const_iterator begin() const noexcept;
136 iterator end() noexcept;
137 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000138
Howard Hinnanta6119a82011-05-29 19:57:12 +0000139 reverse_iterator rbegin() noexcept;
140 const_reverse_iterator rbegin() const noexcept;
141 reverse_iterator rend() noexcept;
142 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000143
Howard Hinnanta6119a82011-05-29 19:57:12 +0000144 const_iterator cbegin() const noexcept;
145 const_iterator cend() const noexcept;
146 const_reverse_iterator crbegin() const noexcept;
147 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000148
Howard Hinnanta6119a82011-05-29 19:57:12 +0000149 size_type size() const noexcept;
150 size_type length() const noexcept;
151 size_type max_size() const noexcept;
152 size_type capacity() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000153
154 void resize(size_type n, value_type c);
155 void resize(size_type n);
156
157 void reserve(size_type res_arg = 0);
158 void shrink_to_fit();
Howard Hinnanta6119a82011-05-29 19:57:12 +0000159 void clear() noexcept;
160 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000161
162 const_reference operator[](size_type pos) const;
163 reference operator[](size_type pos);
164
165 const_reference at(size_type n) const;
166 reference at(size_type n);
167
168 basic_string& operator+=(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000169 template <class T>
170 basic_string& operator+=(const T& t); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000171 basic_string& operator+=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000172 basic_string& operator+=(value_type c);
173 basic_string& operator+=(initializer_list<value_type>);
174
175 basic_string& append(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000176 template <class T>
177 basic_string& append(const T& t); // C++17
Marshall Clowa93b5e22014-03-04 19:17:19 +0000178 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000179 template <class T>
180 basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000181 basic_string& append(const value_type* s, size_type n);
182 basic_string& append(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000183 basic_string& append(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000184 template<class InputIterator>
185 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000186 basic_string& append(initializer_list<value_type>);
187
188 void push_back(value_type c);
189 void pop_back();
190 reference front();
191 const_reference front() const;
192 reference back();
193 const_reference back() const;
194
195 basic_string& assign(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000196 template <class T>
197 basic_string& assign(const T& t); // C++17
Howard Hinnanta6119a82011-05-29 19:57:12 +0000198 basic_string& assign(basic_string&& str);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000199 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000200 template <class T>
201 basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000202 basic_string& assign(const value_type* s, size_type n);
203 basic_string& assign(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000204 basic_string& assign(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000205 template<class InputIterator>
206 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000207 basic_string& assign(initializer_list<value_type>);
208
209 basic_string& insert(size_type pos1, const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000210 template <class T>
211 basic_string& insert(size_type pos1, const T& t);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000212 basic_string& insert(size_type pos1, const basic_string& str,
213 size_type pos2, size_type n);
Marshall Clow6ac8de02016-09-24 22:45:42 +0000214 template <class T>
215 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
Marshall Clowa93b5e22014-03-04 19:17:19 +0000216 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000217 basic_string& insert(size_type pos, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000218 basic_string& insert(size_type pos, size_type n, value_type c);
219 iterator insert(const_iterator p, value_type c);
220 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000221 template<class InputIterator>
222 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000223 iterator insert(const_iterator p, initializer_list<value_type>);
224
225 basic_string& erase(size_type pos = 0, size_type n = npos);
226 iterator erase(const_iterator position);
227 iterator erase(const_iterator first, const_iterator last);
228
229 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000230 template <class T>
231 basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000232 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000233 size_type pos2, size_type n2=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000234 template <class T>
235 basic_string& replace(size_type pos1, size_type n1, const T& t,
236 size_type pos2, size_type n); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000237 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
238 basic_string& replace(size_type pos, size_type n1, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000239 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000240 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000241 template <class T>
242 basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000243 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
244 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000245 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000246 template<class InputIterator>
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000247 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
248 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000249
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000250 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000251 basic_string substr(size_type pos = 0, size_type n = npos) const;
252
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000253 void swap(basic_string& str)
Marshall Clow7d914d12015-07-13 20:04:56 +0000254 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
255 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000257 const value_type* c_str() const noexcept;
258 const value_type* data() const noexcept;
Marshall Clowf532a702016-03-08 15:44:30 +0000259 value_type* data() noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000260
Howard Hinnanta6119a82011-05-29 19:57:12 +0000261 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000262
Howard Hinnanta6119a82011-05-29 19:57:12 +0000263 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000264 template <class T>
265 size_type find(const T& t, size_type pos = 0) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000266 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
267 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000268 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000269
Howard Hinnanta6119a82011-05-29 19:57:12 +0000270 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000271 template <class T>
272 size_type rfind(const T& t, size_type pos = npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000273 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
274 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000275 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276
Howard Hinnanta6119a82011-05-29 19:57:12 +0000277 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000278 template <class T>
279 size_type find_first_of(const T& t, size_type pos = 0) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000280 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
281 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000282 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000283
Howard Hinnanta6119a82011-05-29 19:57:12 +0000284 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000285 template <class T>
286 size_type find_last_of(const T& t, size_type pos = npos) const noexcept; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000287 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
288 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000289 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290
Howard Hinnanta6119a82011-05-29 19:57:12 +0000291 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000292 template <class T>
293 size_type find_first_not_of(const T& t, size_type pos = 0) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000294 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
295 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000296 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000297
Howard Hinnanta6119a82011-05-29 19:57:12 +0000298 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000299 template <class T>
300 size_type find_last_not_of(const T& t, size_type pos = npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000301 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
302 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000303 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000304
Howard Hinnanta6119a82011-05-29 19:57:12 +0000305 int compare(const basic_string& str) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000306 template <class T>
307 int compare(const T& t) const noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000308 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Marshall Clow64c10d02018-07-02 18:41:15 +0000309 template <class T>
310 int compare(size_type pos1, size_type n1, const T& t) const; // C++17
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000311 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000312 size_type pos2, size_type n2=npos) const; // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000313 template <class T>
314 int compare(size_type pos1, size_type n1, const T& t,
315 size_type pos2, size_type n2=npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000316 int compare(const value_type* s) const noexcept;
317 int compare(size_type pos1, size_type n1, const value_type* s) const;
318 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000319
Marshall Clow46b4ad52017-12-04 20:11:38 +0000320 bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
321 bool starts_with(charT c) const noexcept; // C++2a
322 bool starts_with(const charT* s) const; // C++2a
323 bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
324 bool ends_with(charT c) const noexcept; // C++2a
325 bool ends_with(const charT* s) const; // C++2a
326
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327 bool __invariants() const;
328};
329
Marshall Clow5b1e87e2018-02-08 06:34:03 +0000330template<class InputIterator,
331 class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
332basic_string(InputIterator, InputIterator, Allocator = Allocator())
333 -> basic_string<typename iterator_traits<InputIterator>::value_type,
334 char_traits<typename iterator_traits<InputIterator>::value_type>,
335 Allocator>; // C++17
336
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000337template<class charT, class traits, class Allocator>
338basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000339operator+(const basic_string<charT, traits, Allocator>& lhs,
340 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341
342template<class charT, class traits, class Allocator>
343basic_string<charT, traits, Allocator>
344operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
345
346template<class charT, class traits, class Allocator>
347basic_string<charT, traits, Allocator>
348operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
349
350template<class charT, class traits, class Allocator>
351basic_string<charT, traits, Allocator>
352operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
353
354template<class charT, class traits, class Allocator>
355basic_string<charT, traits, Allocator>
356operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
357
358template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000359bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000360 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361
362template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000363bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000364
365template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000366bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367
Howard Hinnant324bb032010-08-22 00:02:43 +0000368template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000369bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000370 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371
372template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000373bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374
375template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000376bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377
378template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000379bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000380 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381
382template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000383bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384
385template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000386bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000387
388template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000389bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000390 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000391
392template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000393bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394
395template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000396bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397
398template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000399bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000400 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000401
402template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000403bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404
405template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000406bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000407
408template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000409bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000410 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000411
412template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000413bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000414
415template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000416bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000417
418template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000419void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000420 basic_string<charT, traits, Allocator>& rhs)
421 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422
423template<class charT, class traits, class Allocator>
424basic_istream<charT, traits>&
425operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
426
427template<class charT, class traits, class Allocator>
428basic_ostream<charT, traits>&
429operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
430
431template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000432basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000433getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
434 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435
436template<class charT, class traits, class Allocator>
437basic_istream<charT, traits>&
438getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
439
Marshall Clowf9276352018-12-14 18:49:35 +0000440template<class charT, class traits, class Allocator, class U>
441void erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20
442template<class charT, class traits, class Allocator, class Predicate>
443void erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20
444
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000445typedef basic_string<char> string;
446typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000447typedef basic_string<char16_t> u16string;
448typedef basic_string<char32_t> u32string;
449
450int stoi (const string& str, size_t* idx = 0, int base = 10);
451long stol (const string& str, size_t* idx = 0, int base = 10);
452unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
453long long stoll (const string& str, size_t* idx = 0, int base = 10);
454unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
455
456float stof (const string& str, size_t* idx = 0);
457double stod (const string& str, size_t* idx = 0);
458long double stold(const string& str, size_t* idx = 0);
459
460string to_string(int val);
461string to_string(unsigned val);
462string to_string(long val);
463string to_string(unsigned long val);
464string to_string(long long val);
465string to_string(unsigned long long val);
466string to_string(float val);
467string to_string(double val);
468string to_string(long double val);
469
470int stoi (const wstring& str, size_t* idx = 0, int base = 10);
471long stol (const wstring& str, size_t* idx = 0, int base = 10);
472unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
473long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
474unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
475
476float stof (const wstring& str, size_t* idx = 0);
477double stod (const wstring& str, size_t* idx = 0);
478long double stold(const wstring& str, size_t* idx = 0);
479
480wstring to_wstring(int val);
481wstring to_wstring(unsigned val);
482wstring to_wstring(long val);
483wstring to_wstring(unsigned long val);
484wstring to_wstring(long long val);
485wstring to_wstring(unsigned long long val);
486wstring to_wstring(float val);
487wstring to_wstring(double val);
488wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000489
490template <> struct hash<string>;
491template <> struct hash<u16string>;
492template <> struct hash<u32string>;
493template <> struct hash<wstring>;
494
Marshall Clow15234322013-07-23 17:05:24 +0000495basic_string<char> operator "" s( const char *str, size_t len ); // C++14
496basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
497basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
498basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
499
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000500} // std
501
502*/
503
504#include <__config>
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000505#include <string_view>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000506#include <iosfwd>
507#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000508#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000509#include <cwchar>
510#include <algorithm>
511#include <iterator>
512#include <utility>
513#include <memory>
514#include <stdexcept>
515#include <type_traits>
516#include <initializer_list>
517#include <__functional_base>
Marshall Clowe3973fd2018-09-12 19:41:40 +0000518#include <version>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000519#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
520#include <cstdint>
521#endif
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000522
Eric Fiselierb9536102014-08-10 23:53:08 +0000523#include <__debug>
524
Howard Hinnant08e17472011-10-17 20:05:10 +0000525#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000526#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000527#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528
Eric Fiselier018a3d52017-05-31 22:07:49 +0000529_LIBCPP_PUSH_MACROS
530#include <__undef_macros>
531
532
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533_LIBCPP_BEGIN_NAMESPACE_STD
534
535// fpos
536
537template <class _StateT>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000538class _LIBCPP_TEMPLATE_VIS fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000539{
540private:
541 _StateT __st_;
542 streamoff __off_;
543public:
544 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
545
546 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
547
548 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
549 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
550
551 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
552 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
553 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
554 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
555};
556
557template <class _StateT>
558inline _LIBCPP_INLINE_VISIBILITY
559streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
560 {return streamoff(__x) - streamoff(__y);}
561
562template <class _StateT>
563inline _LIBCPP_INLINE_VISIBILITY
564bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
565 {return streamoff(__x) == streamoff(__y);}
566
567template <class _StateT>
568inline _LIBCPP_INLINE_VISIBILITY
569bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
570 {return streamoff(__x) != streamoff(__y);}
571
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572// basic_string
573
574template<class _CharT, class _Traits, class _Allocator>
575basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000576operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
577 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000578
579template<class _CharT, class _Traits, class _Allocator>
580basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000581operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000582
583template<class _CharT, class _Traits, class _Allocator>
584basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000585operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000586
587template<class _CharT, class _Traits, class _Allocator>
Louis Dionnece2232f2018-11-21 17:31:55 +0000588inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000589basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000590operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000591
592template<class _CharT, class _Traits, class _Allocator>
593basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000594operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595
Shoaib Meenai487562f2017-07-29 02:54:41 +0000596_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
597
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000598template <bool>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000599class _LIBCPP_TEMPLATE_VIS __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000600{
601protected:
Marshall Clow14c09a22016-08-25 15:09:01 +0000602 _LIBCPP_NORETURN void __throw_length_error() const;
603 _LIBCPP_NORETURN void __throw_out_of_range() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000604};
605
606template <bool __b>
607void
608__basic_string_common<__b>::__throw_length_error() const
609{
Marshall Clow14c09a22016-08-25 15:09:01 +0000610 _VSTD::__throw_length_error("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000611}
612
613template <bool __b>
614void
615__basic_string_common<__b>::__throw_out_of_range() const
616{
Marshall Clow14c09a22016-08-25 15:09:01 +0000617 _VSTD::__throw_out_of_range("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000618}
619
Eric Fiselier833d6442016-09-15 22:27:07 +0000620_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000621
Marshall Clowdf9db312016-01-13 21:54:34 +0000622#ifdef _LIBCPP_NO_EXCEPTIONS
623template <class _Iter>
624struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
625#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
626template <class _Iter>
627struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
628#else
629template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
630struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
631 noexcept(++(declval<_Iter&>())) &&
632 is_nothrow_assignable<_Iter&, _Iter>::value &&
633 noexcept(declval<_Iter>() == declval<_Iter>()) &&
634 noexcept(*declval<_Iter>())
635)) {};
636
637template <class _Iter>
638struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
639#endif
640
641
642template <class _Iter>
643struct __libcpp_string_gets_noexcept_iterator
644 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
645
Marshall Clow6ac8de02016-09-24 22:45:42 +0000646template <class _CharT, class _Traits, class _Tp>
647struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
Marshall Clowf1729d92017-11-15 20:02:27 +0000648 ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
Marshall Clow6ac8de02016-09-24 22:45:42 +0000649 !is_convertible<const _Tp&, const _CharT*>::value)) {};
650
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000651#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-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 Stepanov4f01aa82015-10-13 23:48:28 +0000664#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000665
Howard Hinnant324bb032010-08-22 00:02:43 +0000666template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000667class _LIBCPP_TEMPLATE_VIS basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668 : private __basic_string_common<true>
669{
670public:
671 typedef basic_string __self;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000672 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000673 typedef _Traits traits_type;
Marshall Clow2d4c3fa2017-03-15 18:41:11 +0000674 typedef _CharT value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000675 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-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 Hinnant53f7d4c2011-06-03 18:40:47 +0000679 typedef value_type& reference;
680 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000681 typedef typename __alloc_traits::pointer pointer;
682 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000683
Marshall Clow256f1872018-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 Hinnant499cea12013-08-23 17:37:05 +0000688 "traits_type::char_type must be the same type as CharT");
Marshall Clow256f1872018-03-21 00:36:05 +0000689 static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
Howard Hinnant499cea12013-08-23 17:37:05 +0000690 "Allocator::value_type must be same type as value_type");
Marshall Clow64c10d02018-07-02 18:41:15 +0000691
Howard Hinnant499cea12013-08-23 17:37:05 +0000692#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000693 typedef pointer iterator;
694 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000695#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000696 typedef __wrap_iter<pointer> iterator;
697 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000698#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000699 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
700 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000701
702private:
Howard Hinnant15467182013-04-30 21:44:48 +0000703
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000704#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000705
706 struct __long
707 {
708 pointer __data_;
709 size_type __size_;
710 size_type __cap_;
711 };
712
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000713#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000714 static const size_type __short_mask = 0x01;
715 static const size_type __long_mask = 0x1ul;
Howard Hinnant15467182013-04-30 21:44:48 +0000716#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-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 Hinnant15467182013-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 Hinnantbc8d3f92010-05-11 19:42:16 +0000736 struct __long
737 {
738 size_type __cap_;
739 size_type __size_;
740 pointer __data_;
741 };
742
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000743#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-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 Hinnant324bb032010-08-22 00:02:43 +0000746#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000747 static const size_type __short_mask = 0x01;
748 static const size_type __long_mask = 0x1ul;
Howard Hinnant324bb032010-08-22 00:02:43 +0000749#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000750
Howard Hinnantbc8d3f92010-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 Hinnant9c0df142012-10-30 19:06:59 +0000759 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000760 };
761 value_type __data_[__min_cap];
762 };
763
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000764#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000765
Howard Hinnant499cea12013-08-23 17:37:05 +0000766 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000767
Howard Hinnant499cea12013-08-23 17:37:05 +0000768 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-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 Hinnantbc8d3f92010-05-11 19:42:16 +0000787public:
788 static const size_type npos = -1;
789
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000790 _LIBCPP_INLINE_VISIBILITY basic_string()
791 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000792
793 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
794#if _LIBCPP_STD_VER <= 14
795 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
796#else
797 _NOEXCEPT;
798#endif
799
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000800 basic_string(const basic_string& __str);
801 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +0000802
Eric Fiselier3e928972017-04-19 00:28:44 +0000803#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant9f193f22011-01-26 00:06:59 +0000804 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000805 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +0000806#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000807 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000808#else
809 _NOEXCEPT;
810#endif
811
Howard Hinnant9f193f22011-01-26 00:06:59 +0000812 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000813 basic_string(basic_string&& __str, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000814#endif // _LIBCPP_CXX03_LANG
Marshall Clow64c10d02018-07-02 18:41:15 +0000815
Marshall Clow7e3ab172018-10-16 16:02:18 +0000816#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +0000817 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
Marshall Clow7e3ab172018-10-16 16:02:18 +0000818#endif
Eric Fiselierffbb91b2018-07-17 05:48:48 +0000819 _LIBCPP_INLINE_VISIBILITY
820 basic_string(const _CharT* __s) {
821 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
822 __init(__s, traits_type::length(__s));
823# if _LIBCPP_DEBUG_LEVEL >= 2
824 __get_db()->__insert_c(this);
825# endif
826 }
Marshall Clow64c10d02018-07-02 18:41:15 +0000827
Marshall Clow7e3ab172018-10-16 16:02:18 +0000828#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +0000829 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
Marshall Clow7e3ab172018-10-16 16:02:18 +0000830#endif
Marshall Clow64c10d02018-07-02 18:41:15 +0000831 _LIBCPP_INLINE_VISIBILITY
832 basic_string(const _CharT* __s, const _Allocator& __a);
833
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000834 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000835 basic_string(const _CharT* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000836 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000837 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000838 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000839 basic_string(size_type __n, _CharT __c);
Marshall Clow64c10d02018-07-02 18:41:15 +0000840
Marshall Clow7e3ab172018-10-16 16:02:18 +0000841#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +0000842 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
Marshall Clow7e3ab172018-10-16 16:02:18 +0000843#endif
Marshall Clow64c10d02018-07-02 18:41:15 +0000844 _LIBCPP_INLINE_VISIBILITY
845 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
846
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000847 basic_string(const basic_string& __str, size_type __pos, size_type __n,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000848 const _Allocator& __a = _Allocator());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000849 _LIBCPP_INLINE_VISIBILITY
850 basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000851 const _Allocator& __a = _Allocator());
Marshall Clow64c10d02018-07-02 18:41:15 +0000852
853 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +0000854 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000855 basic_string(const _Tp& __t, size_type __pos, size_type __n,
Marshall Clow64c10d02018-07-02 18:41:15 +0000856 const allocator_type& __a = allocator_type());
857
858 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
859 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
860 explicit basic_string(const _Tp& __t);
861
862 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
863 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
864 explicit basic_string(const _Tp& __t, const allocator_type& __a);
865
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868 basic_string(_InputIterator __first, _InputIterator __last);
869 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000872#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000873 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000874 basic_string(initializer_list<_CharT> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000875 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000876 basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000877#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878
Eric Fiselier51eb1d52016-10-31 03:42:50 +0000879 inline ~basic_string();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000880
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000881 _LIBCPP_INLINE_VISIBILITY
882 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
883
Howard Hinnante32b5e22010-11-17 17:55:08 +0000884 basic_string& operator=(const basic_string& __str);
Eric Fiselierf472d6c2017-01-23 21:24:58 +0000885
Marshall Clow64c10d02018-07-02 18:41:15 +0000886 template <class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
887 basic_string& operator=(const _Tp& __t)
888 {__self_view __sv = __t; return assign(__sv);}
889
Eric Fiselier3e928972017-04-19 00:28:44 +0000890#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000892 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +0000893 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Eric Fiselier3e928972017-04-19 00:28:44 +0000894 _LIBCPP_INLINE_VISIBILITY
895 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000897 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000898 basic_string& operator=(value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899
Howard Hinnant499cea12013-08-23 17:37:05 +0000900#if _LIBCPP_DEBUG_LEVEL >= 2
901 _LIBCPP_INLINE_VISIBILITY
902 iterator begin() _NOEXCEPT
903 {return iterator(this, __get_pointer());}
904 _LIBCPP_INLINE_VISIBILITY
905 const_iterator begin() const _NOEXCEPT
906 {return const_iterator(this, __get_pointer());}
907 _LIBCPP_INLINE_VISIBILITY
908 iterator end() _NOEXCEPT
909 {return iterator(this, __get_pointer() + size());}
910 _LIBCPP_INLINE_VISIBILITY
911 const_iterator end() const _NOEXCEPT
912 {return const_iterator(this, __get_pointer() + size());}
913#else
Howard Hinnanta6119a82011-05-29 19:57:12 +0000914 _LIBCPP_INLINE_VISIBILITY
915 iterator begin() _NOEXCEPT
916 {return iterator(__get_pointer());}
917 _LIBCPP_INLINE_VISIBILITY
918 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000919 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000920 _LIBCPP_INLINE_VISIBILITY
921 iterator end() _NOEXCEPT
922 {return iterator(__get_pointer() + size());}
923 _LIBCPP_INLINE_VISIBILITY
924 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000925 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +0000926#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +0000927 _LIBCPP_INLINE_VISIBILITY
928 reverse_iterator rbegin() _NOEXCEPT
929 {return reverse_iterator(end());}
930 _LIBCPP_INLINE_VISIBILITY
931 const_reverse_iterator rbegin() const _NOEXCEPT
932 {return const_reverse_iterator(end());}
933 _LIBCPP_INLINE_VISIBILITY
934 reverse_iterator rend() _NOEXCEPT
935 {return reverse_iterator(begin());}
936 _LIBCPP_INLINE_VISIBILITY
937 const_reverse_iterator rend() const _NOEXCEPT
938 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000939
Howard Hinnanta6119a82011-05-29 19:57:12 +0000940 _LIBCPP_INLINE_VISIBILITY
941 const_iterator cbegin() const _NOEXCEPT
942 {return begin();}
943 _LIBCPP_INLINE_VISIBILITY
944 const_iterator cend() const _NOEXCEPT
945 {return end();}
946 _LIBCPP_INLINE_VISIBILITY
947 const_reverse_iterator crbegin() const _NOEXCEPT
948 {return rbegin();}
949 _LIBCPP_INLINE_VISIBILITY
950 const_reverse_iterator crend() const _NOEXCEPT
951 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000952
Howard Hinnanta6119a82011-05-29 19:57:12 +0000953 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000954 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000955 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
956 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
957 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +0000958 {return (__is_long() ? __get_long_cap()
959 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000960
961 void resize(size_type __n, value_type __c);
962 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
963
Marshall Clow7593e792018-11-28 18:18:34 +0000964 void reserve(size_type __res_arg);
Eric Fiselierf9782de2018-11-26 20:15:38 +0000965 _LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n);
966
Marshall Clow7593e792018-11-28 18:18:34 +0000967 _LIBCPP_INLINE_VISIBILITY
968 void reserve() _NOEXCEPT {reserve(0);}
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000970 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +0000972 void clear() _NOEXCEPT;
Marshall Clowf1729d92017-11-15 20:02:27 +0000973 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
974 bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000975
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000976 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
977 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000978
979 const_reference at(size_type __n) const;
980 reference at(size_type __n);
981
982 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clow64c10d02018-07-02 18:41:15 +0000983
984 template <class _Tp>
985 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
986 typename enable_if
987 <
988 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
989 basic_string&
990 >::type
991 operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);}
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000992 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000993 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Eric Fiselier3e928972017-04-19 00:28:44 +0000994#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000995 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Eric Fiselier3e928972017-04-19 00:28:44 +0000996#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000997
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000998 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000999 basic_string& append(const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001000
1001 template <class _Tp>
1002 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1003 typename enable_if
1004 <
1005 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1006 basic_string&
1007 >::type
1008 append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +00001009 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow64c10d02018-07-02 18:41:15 +00001010
Marshall Clow42a87db2016-10-03 23:40:48 +00001011 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001012 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1013 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001014 <
1015 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1016 basic_string&
1017 >::type
1018 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001019 basic_string& append(const value_type* __s, size_type __n);
1020 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001021 basic_string& append(size_type __n, value_type __c);
Eric Fiselierf9782de2018-11-26 20:15:38 +00001022
1023 _LIBCPP_INLINE_VISIBILITY
1024 void __append_default_init(size_type __n);
1025
Eric Fiselier026d38e2016-10-31 02:46:25 +00001026 template <class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001027 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1028 basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001029 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001030 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1031 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001032 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001033 __is_exactly_input_iterator<_InputIterator>::value
1034 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001035 basic_string&
1036 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +00001037 _LIBCPP_INLINE_VISIBILITY
1038 append(_InputIterator __first, _InputIterator __last) {
1039 const basic_string __temp (__first, __last, __alloc());
1040 append(__temp.data(), __temp.size());
1041 return *this;
1042 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001043 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001044 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1045 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001046 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001047 __is_forward_iterator<_ForwardIterator>::value
1048 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001049 basic_string&
1050 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +00001051 _LIBCPP_INLINE_VISIBILITY
1052 append(_ForwardIterator __first, _ForwardIterator __last) {
1053 return __append_forward_unsafe(__first, __last);
1054 }
1055
Eric Fiselier3e928972017-04-19 00:28:44 +00001056#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001057 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001058 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001059#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001060
1061 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001062 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001063 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001064 _LIBCPP_INLINE_VISIBILITY reference front();
1065 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1066 _LIBCPP_INLINE_VISIBILITY reference back();
1067 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001068
Marshall Clow64c10d02018-07-02 18:41:15 +00001069 template <class _Tp>
1070 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1071 typename enable_if
1072 <
1073 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1074 basic_string&
1075 >::type
1076 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001077 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29 +00001078 basic_string& assign(const basic_string& __str) { return *this = __str; }
Eric Fiselier3e928972017-04-19 00:28:44 +00001079#ifndef _LIBCPP_CXX03_LANG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001080 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001081 basic_string& assign(basic_string&& __str)
Marshall Clow7ed093b2015-10-05 16:17:34 +00001082 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001083 {*this = _VSTD::move(__str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001084#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +00001085 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48 +00001086 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001087 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1088 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001089 <
1090 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1091 basic_string&
1092 >::type
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001093 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001094 basic_string& assign(const value_type* __s, size_type __n);
1095 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001096 basic_string& assign(size_type __n, value_type __c);
1097 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001098 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1099 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001100 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001101 __is_exactly_input_iterator<_InputIterator>::value
1102 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001103 basic_string&
1104 >::type
1105 assign(_InputIterator __first, _InputIterator __last);
1106 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001107 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1108 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001109 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001110 __is_forward_iterator<_ForwardIterator>::value
1111 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001112 basic_string&
1113 >::type
1114 assign(_ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001115#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001116 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001117 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001118#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001119
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001121 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001122
1123 template <class _Tp>
1124 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1125 typename enable_if
1126 <
1127 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1128 basic_string&
1129 >::type
1130 insert(size_type __pos1, const _Tp& __t)
1131 { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
1132
Marshall Clow6ac8de02016-09-24 22:45:42 +00001133 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001134 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1135 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001136 <
1137 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1138 basic_string&
1139 >::type
1140 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001141 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001142 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1143 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1145 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001146 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001147 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1148 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001149 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1150 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001151 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001152 __is_exactly_input_iterator<_InputIterator>::value
1153 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154 iterator
1155 >::type
1156 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1157 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001158 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1159 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001160 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001161 __is_forward_iterator<_ForwardIterator>::value
1162 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163 iterator
1164 >::type
1165 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001166#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001168 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1169 {return insert(__pos, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001170#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001171
1172 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001173 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001174 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001176 iterator erase(const_iterator __first, const_iterator __last);
1177
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001178 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001179 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001180
1181 template <class _Tp>
1182 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1183 typename enable_if
1184 <
1185 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1186 basic_string&
1187 >::type
1188 replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +00001189 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
Marshall Clow6ac8de02016-09-24 22:45:42 +00001190 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001191 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1192 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001193 <
1194 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1195 basic_string&
1196 >::type
1197 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001198 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1199 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001200 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001201 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001202 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001203
1204 template <class _Tp>
1205 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1206 typename enable_if
1207 <
1208 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1209 basic_string&
1210 >::type
1211 replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
1212
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001213 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001214 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001215 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001216 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001217 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001218 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001219 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001220 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1221 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222 <
1223 __is_input_iterator<_InputIterator>::value,
1224 basic_string&
1225 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001226 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Eric Fiselier3e928972017-04-19 00:28:44 +00001227#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001228 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001229 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001230 {return replace(__i1, __i2, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001231#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001232
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001233 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001234 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001235 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1236
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001237 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001238 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001239#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00001240 _NOEXCEPT_DEBUG;
Marshall Clow7d914d12015-07-13 20:04:56 +00001241#else
Eric Fiselier47257c42016-12-28 05:53:01 +00001242 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00001243 __is_nothrow_swappable<allocator_type>::value);
1244#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001245
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001247 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001249 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Eric Fiselier10bebe22017-11-20 20:23:27 +00001250#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
Marshall Clowf532a702016-03-08 15:44:30 +00001251 _LIBCPP_INLINE_VISIBILITY
1252 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1253#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001254
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001256 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001257
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001259 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001260
1261 template <class _Tp>
1262 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1263 typename enable_if
1264 <
1265 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1266 size_type
1267 >::type
1268 find(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001269 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001270 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001271 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001272 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001273
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001275 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001276
1277 template <class _Tp>
1278 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1279 typename enable_if
1280 <
1281 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1282 size_type
1283 >::type
1284 rfind(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001285 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001287 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001288 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001289
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001291 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001292
1293 template <class _Tp>
1294 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1295 typename enable_if
1296 <
1297 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1298 size_type
1299 >::type
1300 find_first_of(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001301 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001302 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001303 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001304 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001305 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001306
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001307 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001308 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001309
1310 template <class _Tp>
1311 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1312 typename enable_if
1313 <
1314 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1315 size_type
1316 >::type
1317 find_last_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001318 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001320 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001321 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001322 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001323
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001324 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001325 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001326
1327 template <class _Tp>
1328 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1329 typename enable_if
1330 <
1331 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1332 size_type
1333 >::type
1334 find_first_not_of(const _Tp &__t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001335 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001336 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001337 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001338 _LIBCPP_INLINE_VISIBILITY
1339 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1340
1341 _LIBCPP_INLINE_VISIBILITY
1342 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001343
1344 template <class _Tp>
1345 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1346 typename enable_if
1347 <
1348 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1349 size_type
1350 >::type
1351 find_last_not_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001352 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001353 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001354 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001355 _LIBCPP_INLINE_VISIBILITY
1356 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1357
1358 _LIBCPP_INLINE_VISIBILITY
1359 int compare(const basic_string& __str) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001360
1361 template <class _Tp>
1362 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1363 typename enable_if
1364 <
1365 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1366 int
1367 >::type
1368 compare(const _Tp &__t) const;
1369
1370 template <class _Tp>
1371 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1372 typename enable_if
1373 <
1374 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1375 int
1376 >::type
1377 compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
1378
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001379 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001380 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001381 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
Marshall Clow64c10d02018-07-02 18:41:15 +00001382
Marshall Clow6ac8de02016-09-24 22:45:42 +00001383 template <class _Tp>
Eric Fiselier9dbc0532016-10-14 05:29:46 +00001384 inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow6ac8de02016-09-24 22:45:42 +00001385 typename enable_if
1386 <
1387 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1388 int
1389 >::type
1390 compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001391 int compare(const value_type* __s) const _NOEXCEPT;
1392 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1393 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001394
Marshall Clow46b4ad52017-12-04 20:11:38 +00001395#if _LIBCPP_STD_VER > 17
1396 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1397 bool starts_with(__self_view __sv) const _NOEXCEPT
1398 { return __self_view(data(), size()).starts_with(__sv); }
1399
1400 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1401 bool starts_with(value_type __c) const _NOEXCEPT
1402 { return !empty() && _Traits::eq(front(), __c); }
1403
1404 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1405 bool starts_with(const value_type* __s) const _NOEXCEPT
1406 { return starts_with(__self_view(__s)); }
1407
1408 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1409 bool ends_with(__self_view __sv) const _NOEXCEPT
1410 { return __self_view(data(), size()).ends_with( __sv); }
1411
1412 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1413 bool ends_with(value_type __c) const _NOEXCEPT
1414 { return !empty() && _Traits::eq(back(), __c); }
1415
1416 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1417 bool ends_with(const value_type* __s) const _NOEXCEPT
1418 { return ends_with(__self_view(__s)); }
1419#endif
1420
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001421 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001422
Marshall Clowab343bb2018-05-29 17:04:37 +00001423 _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT;
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001424
Howard Hinnant08dd2532013-04-22 23:55:13 +00001425 _LIBCPP_INLINE_VISIBILITY
1426 bool __is_long() const _NOEXCEPT
1427 {return bool(__r_.first().__s.__size_ & __short_mask);}
1428
Howard Hinnant499cea12013-08-23 17:37:05 +00001429#if _LIBCPP_DEBUG_LEVEL >= 2
1430
1431 bool __dereferenceable(const const_iterator* __i) const;
1432 bool __decrementable(const const_iterator* __i) const;
1433 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1434 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1435
1436#endif // _LIBCPP_DEBUG_LEVEL >= 2
1437
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001438private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001439 _LIBCPP_INLINE_VISIBILITY
1440 allocator_type& __alloc() _NOEXCEPT
1441 {return __r_.second();}
1442 _LIBCPP_INLINE_VISIBILITY
1443 const allocator_type& __alloc() const _NOEXCEPT
1444 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001445
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001446#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001447
Howard Hinnanta6119a82011-05-29 19:57:12 +00001448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001449 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001450# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001451 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001452# else
1453 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1454# endif
1455
Howard Hinnanta6119a82011-05-29 19:57:12 +00001456 _LIBCPP_INLINE_VISIBILITY
1457 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001458# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001459 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001460# else
1461 {return __r_.first().__s.__size_;}
1462# endif
1463
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001464#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001465
1466 _LIBCPP_INLINE_VISIBILITY
1467 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001468# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001469 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1470# else
1471 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1472# endif
1473
1474 _LIBCPP_INLINE_VISIBILITY
1475 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001476# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001477 {return __r_.first().__s.__size_;}
1478# else
1479 {return __r_.first().__s.__size_ >> 1;}
1480# endif
1481
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001482#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001483
Howard Hinnanta6119a82011-05-29 19:57:12 +00001484 _LIBCPP_INLINE_VISIBILITY
1485 void __set_long_size(size_type __s) _NOEXCEPT
1486 {__r_.first().__l.__size_ = __s;}
1487 _LIBCPP_INLINE_VISIBILITY
1488 size_type __get_long_size() const _NOEXCEPT
1489 {return __r_.first().__l.__size_;}
1490 _LIBCPP_INLINE_VISIBILITY
1491 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001492 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1493
Howard Hinnanta6119a82011-05-29 19:57:12 +00001494 _LIBCPP_INLINE_VISIBILITY
1495 void __set_long_cap(size_type __s) _NOEXCEPT
1496 {__r_.first().__l.__cap_ = __long_mask | __s;}
1497 _LIBCPP_INLINE_VISIBILITY
1498 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001499 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001500
Howard Hinnanta6119a82011-05-29 19:57:12 +00001501 _LIBCPP_INLINE_VISIBILITY
1502 void __set_long_pointer(pointer __p) _NOEXCEPT
1503 {__r_.first().__l.__data_ = __p;}
1504 _LIBCPP_INLINE_VISIBILITY
1505 pointer __get_long_pointer() _NOEXCEPT
1506 {return __r_.first().__l.__data_;}
1507 _LIBCPP_INLINE_VISIBILITY
1508 const_pointer __get_long_pointer() const _NOEXCEPT
1509 {return __r_.first().__l.__data_;}
1510 _LIBCPP_INLINE_VISIBILITY
1511 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001512 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001513 _LIBCPP_INLINE_VISIBILITY
1514 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001515 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001516 _LIBCPP_INLINE_VISIBILITY
1517 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001519 _LIBCPP_INLINE_VISIBILITY
1520 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001521 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1522
Howard Hinnanta6119a82011-05-29 19:57:12 +00001523 _LIBCPP_INLINE_VISIBILITY
1524 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525 {
1526 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1527 for (unsigned __i = 0; __i < __n_words; ++__i)
1528 __a[__i] = 0;
1529 }
1530
1531 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001533 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001534 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001535 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001536 static _LIBCPP_INLINE_VISIBILITY
1537 size_type __recommend(size_type __s) _NOEXCEPT
Marshall Clow088e6012018-02-07 21:30:17 +00001538 {
1539 if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
1540 size_type __guess = __align_it<sizeof(value_type) < __alignment ?
1541 __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
1542 if (__guess == __min_cap) ++__guess;
1543 return __guess;
1544 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001545
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001546 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001547 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001548 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001549 void __init(const value_type* __s, size_type __sz);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001550 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001551 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001552
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001553 template <class _InputIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001554 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001555 typename enable_if
1556 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001557 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001558 void
1559 >::type
1560 __init(_InputIterator __first, _InputIterator __last);
1561
1562 template <class _ForwardIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001563 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001564 typename enable_if
1565 <
1566 __is_forward_iterator<_ForwardIterator>::value,
1567 void
1568 >::type
1569 __init(_ForwardIterator __first, _ForwardIterator __last);
1570
1571 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001572 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001573 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1574 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001575 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001576
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001578 void __erase_to_end(size_type __pos);
1579
Howard Hinnante32b5e22010-11-17 17:55:08 +00001580 _LIBCPP_INLINE_VISIBILITY
1581 void __copy_assign_alloc(const basic_string& __str)
1582 {__copy_assign_alloc(__str, integral_constant<bool,
1583 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1584
1585 _LIBCPP_INLINE_VISIBILITY
1586 void __copy_assign_alloc(const basic_string& __str, true_type)
1587 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001588 if (__alloc() == __str.__alloc())
1589 __alloc() = __str.__alloc();
1590 else
Howard Hinnante32b5e22010-11-17 17:55:08 +00001591 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001592 if (!__str.__is_long())
1593 {
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001594 __clear_and_shrink();
Marshall Clow9247fd22017-01-31 03:40:52 +00001595 __alloc() = __str.__alloc();
1596 }
1597 else
1598 {
1599 allocator_type __a = __str.__alloc();
1600 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001601 __clear_and_shrink();
Marshall Clow9247fd22017-01-31 03:40:52 +00001602 __alloc() = _VSTD::move(__a);
1603 __set_long_pointer(__p);
1604 __set_long_cap(__str.__get_long_cap());
1605 __set_long_size(__str.size());
1606 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001607 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001608 }
1609
1610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001611 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001612 {}
1613
Eric Fiselier3e928972017-04-19 00:28:44 +00001614#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001615 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001616 void __move_assign(basic_string& __str, false_type)
1617 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001619 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001620#if _LIBCPP_STD_VER > 14
1621 _NOEXCEPT;
1622#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001623 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001624#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001625#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001626
1627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001628 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001629 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001630 _NOEXCEPT_(
1631 !__alloc_traits::propagate_on_container_move_assignment::value ||
1632 is_nothrow_move_assignable<allocator_type>::value)
1633 {__move_assign_alloc(__str, integral_constant<bool,
1634 __alloc_traits::propagate_on_container_move_assignment::value>());}
1635
1636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001637 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001638 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1639 {
1640 __alloc() = _VSTD::move(__c.__alloc());
1641 }
1642
1643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001644 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001645 _NOEXCEPT
1646 {}
1647
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001648 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1649 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001650
1651 friend basic_string operator+<>(const basic_string&, const basic_string&);
1652 friend basic_string operator+<>(const value_type*, const basic_string&);
1653 friend basic_string operator+<>(value_type, const basic_string&);
1654 friend basic_string operator+<>(const basic_string&, const value_type*);
1655 friend basic_string operator+<>(const basic_string&, value_type);
1656};
1657
Marshall Clow5b1e87e2018-02-08 06:34:03 +00001658#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1659template<class _InputIterator,
1660 class _CharT = typename iterator_traits<_InputIterator>::value_type,
1661 class _Allocator = allocator<_CharT>,
1662 class = typename enable_if<__is_input_iterator<_InputIterator>::value, void>::type,
1663 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1664 >
1665basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
1666 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
Marshall Clow64c10d02018-07-02 18:41:15 +00001667
1668template<class _CharT,
1669 class _Traits,
1670 class _Allocator = allocator<_CharT>,
1671 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1672 >
1673explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
1674 -> basic_string<_CharT, _Traits, _Allocator>;
1675
1676template<class _CharT,
1677 class _Traits,
1678 class _Allocator = allocator<_CharT>,
1679 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type,
1680 class _Sz = typename allocator_traits<_Allocator>::size_type
1681 >
1682basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
1683 -> basic_string<_CharT, _Traits, _Allocator>;
Marshall Clow5b1e87e2018-02-08 06:34:03 +00001684#endif
1685
1686
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001687template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001688inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001689void
1690basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1691{
Howard Hinnant499cea12013-08-23 17:37:05 +00001692#if _LIBCPP_DEBUG_LEVEL >= 2
1693 __get_db()->__invalidate_all(this);
1694#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001695}
1696
1697template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001698inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001699void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001700basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001701#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001702 __pos
1703#endif
1704 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001705{
Howard Hinnant499cea12013-08-23 17:37:05 +00001706#if _LIBCPP_DEBUG_LEVEL >= 2
1707 __c_node* __c = __get_db()->__find_c_and_lock(this);
1708 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001709 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001710 const_pointer __new_last = __get_pointer() + __pos;
1711 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001712 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001713 --__p;
1714 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1715 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001716 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001717 (*__p)->__c_ = nullptr;
1718 if (--__c->end_ != __p)
1719 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001720 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001721 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001722 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001723 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001724#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001725}
1726
1727template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001728inline
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001729basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001730 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001731{
Howard Hinnant499cea12013-08-23 17:37:05 +00001732#if _LIBCPP_DEBUG_LEVEL >= 2
1733 __get_db()->__insert_c(this);
1734#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001735 __zero();
1736}
1737
1738template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001739inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001740basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001741#if _LIBCPP_STD_VER <= 14
1742 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1743#else
1744 _NOEXCEPT
1745#endif
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001746: __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001747{
Howard Hinnant499cea12013-08-23 17:37:05 +00001748#if _LIBCPP_DEBUG_LEVEL >= 2
1749 __get_db()->__insert_c(this);
1750#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001751 __zero();
1752}
1753
1754template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001755void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1756 size_type __sz,
1757 size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001758{
1759 if (__reserve > max_size())
1760 this->__throw_length_error();
1761 pointer __p;
1762 if (__reserve < __min_cap)
1763 {
1764 __set_short_size(__sz);
1765 __p = __get_short_pointer();
1766 }
1767 else
1768 {
1769 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001770 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001771 __set_long_pointer(__p);
1772 __set_long_cap(__cap+1);
1773 __set_long_size(__sz);
1774 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001775 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001776 traits_type::assign(__p[__sz], value_type());
1777}
1778
1779template <class _CharT, class _Traits, class _Allocator>
1780void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001781basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001782{
1783 if (__sz > max_size())
1784 this->__throw_length_error();
1785 pointer __p;
1786 if (__sz < __min_cap)
1787 {
1788 __set_short_size(__sz);
1789 __p = __get_short_pointer();
1790 }
1791 else
1792 {
1793 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001794 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001795 __set_long_pointer(__p);
1796 __set_long_cap(__cap+1);
1797 __set_long_size(__sz);
1798 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001799 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001800 traits_type::assign(__p[__sz], value_type());
1801}
1802
1803template <class _CharT, class _Traits, class _Allocator>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001804#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +00001805template <class>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001806#endif
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001807basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001808 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001809{
Howard Hinnant499cea12013-08-23 17:37:05 +00001810 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001811 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001812#if _LIBCPP_DEBUG_LEVEL >= 2
1813 __get_db()->__insert_c(this);
1814#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001815}
1816
1817template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001818inline
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001819basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001820{
Howard Hinnant499cea12013-08-23 17:37:05 +00001821 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001822 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001823#if _LIBCPP_DEBUG_LEVEL >= 2
1824 __get_db()->__insert_c(this);
1825#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001826}
1827
1828template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001829inline
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001830basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001831 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001832{
Howard Hinnant499cea12013-08-23 17:37:05 +00001833 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001834 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001835#if _LIBCPP_DEBUG_LEVEL >= 2
1836 __get_db()->__insert_c(this);
1837#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001838}
1839
1840template <class _CharT, class _Traits, class _Allocator>
1841basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001842 : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001843{
1844 if (!__str.__is_long())
1845 __r_.first().__r = __str.__r_.first().__r;
1846 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001847 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001848#if _LIBCPP_DEBUG_LEVEL >= 2
1849 __get_db()->__insert_c(this);
1850#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001851}
1852
1853template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001854basic_string<_CharT, _Traits, _Allocator>::basic_string(
1855 const basic_string& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001856 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001857{
1858 if (!__str.__is_long())
1859 __r_.first().__r = __str.__r_.first().__r;
1860 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001861 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001862#if _LIBCPP_DEBUG_LEVEL >= 2
1863 __get_db()->__insert_c(this);
1864#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001865}
1866
Eric Fiselier3e928972017-04-19 00:28:44 +00001867#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001868
1869template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001870inline
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001871basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001872#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001873 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00001874#else
1875 _NOEXCEPT
1876#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001877 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001878{
1879 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00001880#if _LIBCPP_DEBUG_LEVEL >= 2
1881 __get_db()->__insert_c(this);
1882 if (__is_long())
1883 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001884#endif
1885}
1886
1887template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001888inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001889basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001890 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001891{
Marshall Clowd5549cc2014-07-17 15:32:20 +00001892 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001893 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00001894 else
1895 {
1896 __r_.first().__r = __str.__r_.first().__r;
1897 __str.__zero();
1898 }
Howard Hinnant499cea12013-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 Hinnantbc8d3f92010-05-11 19:42:16 +00001903#endif
1904}
1905
Eric Fiselier3e928972017-04-19 00:28:44 +00001906#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001907
1908template <class _CharT, class _Traits, class _Allocator>
1909void
1910basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1911{
1912 if (__n > max_size())
1913 this->__throw_length_error();
1914 pointer __p;
1915 if (__n < __min_cap)
1916 {
1917 __set_short_size(__n);
1918 __p = __get_short_pointer();
1919 }
1920 else
1921 {
1922 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001923 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001924 __set_long_pointer(__p);
1925 __set_long_cap(__cap+1);
1926 __set_long_size(__n);
1927 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001928 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001929 traits_type::assign(__p[__n], value_type());
1930}
1931
1932template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001933inline
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001934basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935{
1936 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001937#if _LIBCPP_DEBUG_LEVEL >= 2
1938 __get_db()->__insert_c(this);
1939#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001940}
1941
1942template <class _CharT, class _Traits, class _Allocator>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001943#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +00001944template <class>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001945#endif
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001946basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001947 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001948{
1949 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001950#if _LIBCPP_DEBUG_LEVEL >= 2
1951 __get_db()->__insert_c(this);
1952#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001953}
1954
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001955template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001956basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1957 size_type __pos, size_type __n,
1958 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001959 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001960{
1961 size_type __str_sz = __str.size();
1962 if (__pos > __str_sz)
1963 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001964 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00001965#if _LIBCPP_DEBUG_LEVEL >= 2
1966 __get_db()->__insert_c(this);
1967#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001968}
1969
1970template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001971inline
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001972basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001973 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001974 : __r_(__second_tag(), __a)
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001975{
1976 size_type __str_sz = __str.size();
1977 if (__pos > __str_sz)
1978 this->__throw_out_of_range();
1979 __init(__str.data() + __pos, __str_sz - __pos);
1980#if _LIBCPP_DEBUG_LEVEL >= 2
1981 __get_db()->__insert_c(this);
1982#endif
1983}
1984
1985template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001986template <class _Tp, class>
Marshall Clowdb7fa112016-11-14 18:22:19 +00001987basic_string<_CharT, _Traits, _Allocator>::basic_string(
Marshall Clow64c10d02018-07-02 18:41:15 +00001988 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001989 : __r_(__second_tag(), __a)
Marshall Clowdb7fa112016-11-14 18:22:19 +00001990{
Marshall Clow64c10d02018-07-02 18:41:15 +00001991 __self_view __sv0 = __t;
1992 __self_view __sv = __sv0.substr(__pos, __n);
Marshall Clowdb7fa112016-11-14 18:22:19 +00001993 __init(__sv.data(), __sv.size());
1994#if _LIBCPP_DEBUG_LEVEL >= 2
1995 __get_db()->__insert_c(this);
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001996#endif
Marshall Clowdb7fa112016-11-14 18:22:19 +00001997}
1998
1999template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00002000template <class _Tp, class>
2001basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002002{
Marshall Clow64c10d02018-07-02 18:41:15 +00002003 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002004 __init(__sv.data(), __sv.size());
2005#if _LIBCPP_DEBUG_LEVEL >= 2
2006 __get_db()->__insert_c(this);
2007#endif
2008}
2009
2010template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00002011template <class _Tp, class>
2012basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002013 : __r_(__second_tag(), __a)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002014{
Marshall Clow64c10d02018-07-02 18:41:15 +00002015 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002016 __init(__sv.data(), __sv.size());
2017#if _LIBCPP_DEBUG_LEVEL >= 2
2018 __get_db()->__insert_c(this);
2019#endif
2020}
2021
2022template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002023template <class _InputIterator>
2024typename enable_if
2025<
Marshall Clowdf9db312016-01-13 21:54:34 +00002026 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002027 void
2028>::type
2029basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2030{
2031 __zero();
2032#ifndef _LIBCPP_NO_EXCEPTIONS
2033 try
2034 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002035#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002036 for (; __first != __last; ++__first)
2037 push_back(*__first);
2038#ifndef _LIBCPP_NO_EXCEPTIONS
2039 }
2040 catch (...)
2041 {
2042 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002043 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002044 throw;
2045 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002046#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002047}
2048
2049template <class _CharT, class _Traits, class _Allocator>
2050template <class _ForwardIterator>
2051typename enable_if
2052<
2053 __is_forward_iterator<_ForwardIterator>::value,
2054 void
2055>::type
2056basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2057{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002058 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002059 if (__sz > max_size())
2060 this->__throw_length_error();
2061 pointer __p;
2062 if (__sz < __min_cap)
2063 {
2064 __set_short_size(__sz);
2065 __p = __get_short_pointer();
2066 }
2067 else
2068 {
2069 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002070 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002071 __set_long_pointer(__p);
2072 __set_long_cap(__cap+1);
2073 __set_long_size(__sz);
2074 }
Eric Fiselierb9919752014-10-27 19:28:20 +00002075 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002076 traits_type::assign(*__p, *__first);
2077 traits_type::assign(*__p, value_type());
2078}
2079
2080template <class _CharT, class _Traits, class _Allocator>
2081template<class _InputIterator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002082inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002083basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2084{
2085 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002086#if _LIBCPP_DEBUG_LEVEL >= 2
2087 __get_db()->__insert_c(this);
2088#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002089}
2090
2091template <class _CharT, class _Traits, class _Allocator>
2092template<class _InputIterator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002093inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002094basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2095 const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002096 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002097{
2098 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002099#if _LIBCPP_DEBUG_LEVEL >= 2
2100 __get_db()->__insert_c(this);
2101#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002102}
2103
Eric Fiselier3e928972017-04-19 00:28:44 +00002104#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00002105
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002106template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002107inline
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00002108basic_string<_CharT, _Traits, _Allocator>::basic_string(
2109 initializer_list<_CharT> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002110{
2111 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002112#if _LIBCPP_DEBUG_LEVEL >= 2
2113 __get_db()->__insert_c(this);
2114#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002115}
2116
2117template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002118inline
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002119
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00002120basic_string<_CharT, _Traits, _Allocator>::basic_string(
2121 initializer_list<_CharT> __il, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002122 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002123{
2124 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002125#if _LIBCPP_DEBUG_LEVEL >= 2
2126 __get_db()->__insert_c(this);
2127#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002128}
2129
Eric Fiselier3e928972017-04-19 00:28:44 +00002130#endif // _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00002131
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002132template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002133basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2134{
Howard Hinnant499cea12013-08-23 17:37:05 +00002135#if _LIBCPP_DEBUG_LEVEL >= 2
2136 __get_db()->__erase_c(this);
2137#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002138 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002139 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002140}
2141
2142template <class _CharT, class _Traits, class _Allocator>
2143void
2144basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2145 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002146 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002147{
2148 size_type __ms = max_size();
2149 if (__delta_cap > __ms - __old_cap - 1)
2150 this->__throw_length_error();
2151 pointer __old_p = __get_pointer();
2152 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002153 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002154 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002155 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002156 __invalidate_all_iterators();
2157 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002158 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2159 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002160 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002161 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002162 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2163 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002164 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2165 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002166 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002167 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002168 __set_long_pointer(__p);
2169 __set_long_cap(__cap+1);
2170 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2171 __set_long_size(__old_sz);
2172 traits_type::assign(__p[__old_sz], value_type());
2173}
2174
2175template <class _CharT, class _Traits, class _Allocator>
2176void
2177basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2178 size_type __n_copy, size_type __n_del, size_type __n_add)
2179{
2180 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00002181 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002182 this->__throw_length_error();
2183 pointer __old_p = __get_pointer();
2184 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002185 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002186 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002187 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002188 __invalidate_all_iterators();
2189 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002190 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2191 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002192 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2193 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002194 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2195 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2196 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002197 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002198 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002199 __set_long_pointer(__p);
2200 __set_long_cap(__cap+1);
2201}
2202
2203// assign
2204
2205template <class _CharT, class _Traits, class _Allocator>
2206basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002207basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002208{
Alp Tokerec34c482014-05-15 11:27:39 +00002209 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002210 size_type __cap = capacity();
2211 if (__cap >= __n)
2212 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002213 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002214 traits_type::move(__p, __s, __n);
2215 traits_type::assign(__p[__n], value_type());
2216 __set_size(__n);
2217 __invalidate_iterators_past(__n);
2218 }
2219 else
2220 {
2221 size_type __sz = size();
2222 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2223 }
2224 return *this;
2225}
2226
2227template <class _CharT, class _Traits, class _Allocator>
2228basic_string<_CharT, _Traits, _Allocator>&
2229basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2230{
2231 size_type __cap = capacity();
2232 if (__cap < __n)
2233 {
2234 size_type __sz = size();
2235 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2236 }
2237 else
2238 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002239 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002240 traits_type::assign(__p, __n, __c);
2241 traits_type::assign(__p[__n], value_type());
2242 __set_size(__n);
2243 return *this;
2244}
2245
2246template <class _CharT, class _Traits, class _Allocator>
2247basic_string<_CharT, _Traits, _Allocator>&
2248basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2249{
2250 pointer __p;
2251 if (__is_long())
2252 {
2253 __p = __get_long_pointer();
2254 __set_long_size(1);
2255 }
2256 else
2257 {
2258 __p = __get_short_pointer();
2259 __set_short_size(1);
2260 }
2261 traits_type::assign(*__p, __c);
2262 traits_type::assign(*++__p, value_type());
2263 __invalidate_iterators_past(1);
2264 return *this;
2265}
2266
2267template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002268basic_string<_CharT, _Traits, _Allocator>&
2269basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2270{
2271 if (this != &__str)
2272 {
2273 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00002274 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00002275 }
2276 return *this;
2277}
2278
Eric Fiselier3e928972017-04-19 00:28:44 +00002279#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante32b5e22010-11-17 17:55:08 +00002280
2281template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002282inline
Howard Hinnante32b5e22010-11-17 17:55:08 +00002283void
2284basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002285 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002286{
2287 if (__alloc() != __str.__alloc())
2288 assign(__str);
2289 else
2290 __move_assign(__str, true_type());
2291}
2292
2293template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002294inline
Howard Hinnante32b5e22010-11-17 17:55:08 +00002295void
2296basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002297#if _LIBCPP_STD_VER > 14
2298 _NOEXCEPT
2299#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002300 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002301#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002302{
Vedant Kumar2b588cb2018-03-08 21:15:26 +00002303 __clear_and_shrink();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002304 __r_.first() = __str.__r_.first();
2305 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002306 __str.__zero();
2307}
2308
2309template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002310inline
Howard Hinnante32b5e22010-11-17 17:55:08 +00002311basic_string<_CharT, _Traits, _Allocator>&
2312basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002313 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002314{
2315 __move_assign(__str, integral_constant<bool,
2316 __alloc_traits::propagate_on_container_move_assignment::value>());
2317 return *this;
2318}
2319
2320#endif
2321
2322template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002323template<class _InputIterator>
2324typename enable_if
2325<
Marshall Clowdf9db312016-01-13 21:54:34 +00002326 __is_exactly_input_iterator <_InputIterator>::value
2327 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002328 basic_string<_CharT, _Traits, _Allocator>&
2329>::type
2330basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2331{
Marshall Clowd979eed2016-09-05 01:54:30 +00002332 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002333 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002334 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002335}
2336
2337template <class _CharT, class _Traits, class _Allocator>
2338template<class _ForwardIterator>
2339typename enable_if
2340<
Marshall Clowdf9db312016-01-13 21:54:34 +00002341 __is_forward_iterator<_ForwardIterator>::value
2342 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002343 basic_string<_CharT, _Traits, _Allocator>&
2344>::type
2345basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2346{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002347 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002348 size_type __cap = capacity();
2349 if (__cap < __n)
2350 {
2351 size_type __sz = size();
2352 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2353 }
2354 else
2355 __invalidate_iterators_past(__n);
2356 pointer __p = __get_pointer();
2357 for (; __first != __last; ++__first, ++__p)
2358 traits_type::assign(*__p, *__first);
2359 traits_type::assign(*__p, value_type());
2360 __set_size(__n);
2361 return *this;
2362}
2363
2364template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002365basic_string<_CharT, _Traits, _Allocator>&
2366basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2367{
2368 size_type __sz = __str.size();
2369 if (__pos > __sz)
2370 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002371 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002372}
2373
2374template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002375template <class _Tp>
2376typename enable_if
2377<
2378 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002379 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002380>::type
2381basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002382{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002383 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002384 size_type __sz = __sv.size();
2385 if (__pos > __sz)
2386 this->__throw_out_of_range();
2387 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2388}
2389
2390
2391template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002392basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002393basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002394{
Alp Tokerec34c482014-05-15 11:27:39 +00002395 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002396 return assign(__s, traits_type::length(__s));
2397}
2398
2399// append
2400
2401template <class _CharT, class _Traits, class _Allocator>
2402basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002403basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002404{
Alp Tokerec34c482014-05-15 11:27:39 +00002405 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002406 size_type __cap = capacity();
2407 size_type __sz = size();
2408 if (__cap - __sz >= __n)
2409 {
2410 if (__n)
2411 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002412 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002413 traits_type::copy(__p + __sz, __s, __n);
2414 __sz += __n;
2415 __set_size(__sz);
2416 traits_type::assign(__p[__sz], value_type());
2417 }
2418 }
2419 else
2420 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2421 return *this;
2422}
2423
2424template <class _CharT, class _Traits, class _Allocator>
2425basic_string<_CharT, _Traits, _Allocator>&
2426basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2427{
2428 if (__n)
2429 {
2430 size_type __cap = capacity();
2431 size_type __sz = size();
2432 if (__cap - __sz < __n)
2433 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2434 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002435 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002436 __sz += __n;
2437 __set_size(__sz);
2438 traits_type::assign(__p[__sz], value_type());
2439 }
2440 return *this;
2441}
2442
2443template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierf9782de2018-11-26 20:15:38 +00002444inline void
2445basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
2446{
2447 if (__n)
2448 {
2449 size_type __cap = capacity();
2450 size_type __sz = size();
2451 if (__cap - __sz < __n)
2452 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2453 pointer __p = __get_pointer();
2454 __sz += __n;
2455 __set_size(__sz);
2456 traits_type::assign(__p[__sz], value_type());
2457 }
2458}
2459
2460template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002461void
2462basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2463{
Howard Hinnant15467182013-04-30 21:44:48 +00002464 bool __is_short = !__is_long();
2465 size_type __cap;
2466 size_type __sz;
2467 if (__is_short)
2468 {
2469 __cap = __min_cap - 1;
2470 __sz = __get_short_size();
2471 }
2472 else
2473 {
2474 __cap = __get_long_cap() - 1;
2475 __sz = __get_long_size();
2476 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002477 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002478 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002479 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002480 __is_short = !__is_long();
2481 }
2482 pointer __p;
2483 if (__is_short)
2484 {
2485 __p = __get_short_pointer() + __sz;
2486 __set_short_size(__sz+1);
2487 }
2488 else
2489 {
2490 __p = __get_long_pointer() + __sz;
2491 __set_long_size(__sz+1);
2492 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002493 traits_type::assign(*__p, __c);
2494 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002495}
2496
Marshall Clowac655ef2016-09-07 03:32:06 +00002497template <class _Tp>
Marshall Clowd979eed2016-09-05 01:54:30 +00002498bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2499{
2500 return __first <= __p && __p < __last;
2501}
2502
Marshall Clowac655ef2016-09-07 03:32:06 +00002503template <class _Tp1, class _Tp2>
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00002504bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
Marshall Clowac655ef2016-09-07 03:32:06 +00002505{
2506 return false;
2507}
2508
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002509template <class _CharT, class _Traits, class _Allocator>
2510template<class _ForwardIterator>
Eric Fiselier026d38e2016-10-31 02:46:25 +00002511basic_string<_CharT, _Traits, _Allocator>&
2512basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2513 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002514{
Eric Fiselier026d38e2016-10-31 02:46:25 +00002515 static_assert(__is_forward_iterator<_ForwardIterator>::value,
2516 "function requires a ForwardIterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002517 size_type __sz = size();
2518 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002519 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002520 if (__n)
2521 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002522 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2523 _CharRef __tmp_ref = *__first;
2524 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002525 {
2526 const basic_string __temp (__first, __last, __alloc());
2527 append(__temp.data(), __temp.size());
2528 }
2529 else
2530 {
2531 if (__cap - __sz < __n)
2532 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2533 pointer __p = __get_pointer() + __sz;
2534 for (; __first != __last; ++__p, ++__first)
2535 traits_type::assign(*__p, *__first);
2536 traits_type::assign(*__p, value_type());
2537 __set_size(__sz + __n);
2538 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002539 }
2540 return *this;
2541}
2542
2543template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002544inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002545basic_string<_CharT, _Traits, _Allocator>&
2546basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2547{
2548 return append(__str.data(), __str.size());
2549}
2550
2551template <class _CharT, class _Traits, class _Allocator>
2552basic_string<_CharT, _Traits, _Allocator>&
2553basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2554{
2555 size_type __sz = __str.size();
2556 if (__pos > __sz)
2557 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002558 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002559}
2560
2561template <class _CharT, class _Traits, class _Allocator>
Marshall Clow42a87db2016-10-03 23:40:48 +00002562template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002563 typename enable_if
2564 <
2565 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2566 basic_string<_CharT, _Traits, _Allocator>&
2567 >::type
2568basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002569{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002570 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002571 size_type __sz = __sv.size();
2572 if (__pos > __sz)
2573 this->__throw_out_of_range();
2574 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2575}
2576
2577template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002578basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002579basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002580{
Alp Tokerec34c482014-05-15 11:27:39 +00002581 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002582 return append(__s, traits_type::length(__s));
2583}
2584
2585// insert
2586
2587template <class _CharT, class _Traits, class _Allocator>
2588basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002589basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002590{
Alp Tokerec34c482014-05-15 11:27:39 +00002591 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002592 size_type __sz = size();
2593 if (__pos > __sz)
2594 this->__throw_out_of_range();
2595 size_type __cap = capacity();
2596 if (__cap - __sz >= __n)
2597 {
2598 if (__n)
2599 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002600 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002601 size_type __n_move = __sz - __pos;
2602 if (__n_move != 0)
2603 {
2604 if (__p + __pos <= __s && __s < __p + __sz)
2605 __s += __n;
2606 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2607 }
2608 traits_type::move(__p + __pos, __s, __n);
2609 __sz += __n;
2610 __set_size(__sz);
2611 traits_type::assign(__p[__sz], value_type());
2612 }
2613 }
2614 else
2615 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2616 return *this;
2617}
2618
2619template <class _CharT, class _Traits, class _Allocator>
2620basic_string<_CharT, _Traits, _Allocator>&
2621basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2622{
2623 size_type __sz = size();
2624 if (__pos > __sz)
2625 this->__throw_out_of_range();
2626 if (__n)
2627 {
2628 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002629 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002630 if (__cap - __sz >= __n)
2631 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002632 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002633 size_type __n_move = __sz - __pos;
2634 if (__n_move != 0)
2635 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2636 }
2637 else
2638 {
2639 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002640 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002641 }
2642 traits_type::assign(__p + __pos, __n, __c);
2643 __sz += __n;
2644 __set_size(__sz);
2645 traits_type::assign(__p[__sz], value_type());
2646 }
2647 return *this;
2648}
2649
2650template <class _CharT, class _Traits, class _Allocator>
2651template<class _InputIterator>
2652typename enable_if
2653<
Marshall Clowdf9db312016-01-13 21:54:34 +00002654 __is_exactly_input_iterator<_InputIterator>::value
2655 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2656 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002657>::type
2658basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2659{
Howard Hinnant499cea12013-08-23 17:37:05 +00002660#if _LIBCPP_DEBUG_LEVEL >= 2
2661 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2662 "string::insert(iterator, range) called with an iterator not"
2663 " referring to this string");
2664#endif
Marshall Clowd979eed2016-09-05 01:54:30 +00002665 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002666 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002667}
2668
2669template <class _CharT, class _Traits, class _Allocator>
2670template<class _ForwardIterator>
2671typename enable_if
2672<
Marshall Clowdf9db312016-01-13 21:54:34 +00002673 __is_forward_iterator<_ForwardIterator>::value
2674 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002675 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2676>::type
2677basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2678{
Howard Hinnant499cea12013-08-23 17:37:05 +00002679#if _LIBCPP_DEBUG_LEVEL >= 2
2680 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2681 "string::insert(iterator, range) called with an iterator not"
2682 " referring to this string");
2683#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002684 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002685 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002686 if (__n)
2687 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002688 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2689 _CharRef __tmp_char = *__first;
2690 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002691 {
2692 const basic_string __temp(__first, __last, __alloc());
2693 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2694 }
2695
2696 size_type __sz = size();
2697 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002698 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002699 if (__cap - __sz >= __n)
2700 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002701 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002702 size_type __n_move = __sz - __ip;
2703 if (__n_move != 0)
2704 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2705 }
2706 else
2707 {
2708 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002709 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002710 }
2711 __sz += __n;
2712 __set_size(__sz);
2713 traits_type::assign(__p[__sz], value_type());
2714 for (__p += __ip; __first != __last; ++__p, ++__first)
2715 traits_type::assign(*__p, *__first);
2716 }
2717 return begin() + __ip;
2718}
2719
2720template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002721inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002722basic_string<_CharT, _Traits, _Allocator>&
2723basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2724{
2725 return insert(__pos1, __str.data(), __str.size());
2726}
2727
2728template <class _CharT, class _Traits, class _Allocator>
2729basic_string<_CharT, _Traits, _Allocator>&
2730basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2731 size_type __pos2, size_type __n)
2732{
2733 size_type __str_sz = __str.size();
2734 if (__pos2 > __str_sz)
2735 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002736 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002737}
2738
2739template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002740template <class _Tp>
2741typename enable_if
2742<
2743 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002744 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002745>::type
2746basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002747 size_type __pos2, size_type __n)
2748{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002749 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002750 size_type __str_sz = __sv.size();
2751 if (__pos2 > __str_sz)
2752 this->__throw_out_of_range();
2753 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2754}
2755
2756template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002757basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002758basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002759{
Alp Tokerec34c482014-05-15 11:27:39 +00002760 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002761 return insert(__pos, __s, traits_type::length(__s));
2762}
2763
2764template <class _CharT, class _Traits, class _Allocator>
2765typename basic_string<_CharT, _Traits, _Allocator>::iterator
2766basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2767{
2768 size_type __ip = static_cast<size_type>(__pos - begin());
2769 size_type __sz = size();
2770 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002771 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002772 if (__cap == __sz)
2773 {
2774 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002775 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002776 }
2777 else
2778 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002779 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002780 size_type __n_move = __sz - __ip;
2781 if (__n_move != 0)
2782 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2783 }
2784 traits_type::assign(__p[__ip], __c);
2785 traits_type::assign(__p[++__sz], value_type());
2786 __set_size(__sz);
2787 return begin() + static_cast<difference_type>(__ip);
2788}
2789
2790template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002791inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002792typename basic_string<_CharT, _Traits, _Allocator>::iterator
2793basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2794{
Howard Hinnant499cea12013-08-23 17:37:05 +00002795#if _LIBCPP_DEBUG_LEVEL >= 2
2796 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2797 "string::insert(iterator, n, value) called with an iterator not"
2798 " referring to this string");
2799#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002800 difference_type __p = __pos - begin();
2801 insert(static_cast<size_type>(__p), __n, __c);
2802 return begin() + __p;
2803}
2804
2805// replace
2806
2807template <class _CharT, class _Traits, class _Allocator>
2808basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002809basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002810 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002811{
Alp Tokerec34c482014-05-15 11:27:39 +00002812 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002813 size_type __sz = size();
2814 if (__pos > __sz)
2815 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002816 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002817 size_type __cap = capacity();
2818 if (__cap - __sz + __n1 >= __n2)
2819 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002820 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002821 if (__n1 != __n2)
2822 {
2823 size_type __n_move = __sz - __pos - __n1;
2824 if (__n_move != 0)
2825 {
2826 if (__n1 > __n2)
2827 {
2828 traits_type::move(__p + __pos, __s, __n2);
2829 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2830 goto __finish;
2831 }
2832 if (__p + __pos < __s && __s < __p + __sz)
2833 {
2834 if (__p + __pos + __n1 <= __s)
2835 __s += __n2 - __n1;
2836 else // __p + __pos < __s < __p + __pos + __n1
2837 {
2838 traits_type::move(__p + __pos, __s, __n1);
2839 __pos += __n1;
2840 __s += __n2;
2841 __n2 -= __n1;
2842 __n1 = 0;
2843 }
2844 }
2845 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2846 }
2847 }
2848 traits_type::move(__p + __pos, __s, __n2);
2849__finish:
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002850// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
2851// but this is a safe operation, so we disable the check.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002852 __sz += __n2 - __n1;
2853 __set_size(__sz);
2854 __invalidate_iterators_past(__sz);
2855 traits_type::assign(__p[__sz], value_type());
2856 }
2857 else
2858 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2859 return *this;
2860}
2861
2862template <class _CharT, class _Traits, class _Allocator>
2863basic_string<_CharT, _Traits, _Allocator>&
2864basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002865 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002866{
2867 size_type __sz = size();
2868 if (__pos > __sz)
2869 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002870 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002871 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002872 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002873 if (__cap - __sz + __n1 >= __n2)
2874 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002875 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002876 if (__n1 != __n2)
2877 {
2878 size_type __n_move = __sz - __pos - __n1;
2879 if (__n_move != 0)
2880 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2881 }
2882 }
2883 else
2884 {
2885 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002886 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002887 }
2888 traits_type::assign(__p + __pos, __n2, __c);
2889 __sz += __n2 - __n1;
2890 __set_size(__sz);
2891 __invalidate_iterators_past(__sz);
2892 traits_type::assign(__p[__sz], value_type());
2893 return *this;
2894}
2895
2896template <class _CharT, class _Traits, class _Allocator>
2897template<class _InputIterator>
2898typename enable_if
2899<
2900 __is_input_iterator<_InputIterator>::value,
2901 basic_string<_CharT, _Traits, _Allocator>&
2902>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002903basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002904 _InputIterator __j1, _InputIterator __j2)
2905{
Marshall Clowd979eed2016-09-05 01:54:30 +00002906 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002907 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002908}
2909
2910template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002911inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002912basic_string<_CharT, _Traits, _Allocator>&
2913basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2914{
2915 return replace(__pos1, __n1, __str.data(), __str.size());
2916}
2917
2918template <class _CharT, class _Traits, class _Allocator>
2919basic_string<_CharT, _Traits, _Allocator>&
2920basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2921 size_type __pos2, size_type __n2)
2922{
2923 size_type __str_sz = __str.size();
2924 if (__pos2 > __str_sz)
2925 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002926 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002927}
2928
2929template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002930template <class _Tp>
2931typename enable_if
2932<
Marshall Clowf1729d92017-11-15 20:02:27 +00002933 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2934 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002935>::type
2936basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002937 size_type __pos2, size_type __n2)
2938{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002939 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002940 size_type __str_sz = __sv.size();
2941 if (__pos2 > __str_sz)
2942 this->__throw_out_of_range();
2943 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2944}
2945
2946template <class _CharT, class _Traits, class _Allocator>
2947basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002948basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002949{
Alp Tokerec34c482014-05-15 11:27:39 +00002950 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002951 return replace(__pos, __n1, __s, traits_type::length(__s));
2952}
2953
2954template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002955inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002956basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002957basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002958{
2959 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2960 __str.data(), __str.size());
2961}
2962
2963template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002964inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002965basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002966basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002967{
2968 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2969}
2970
2971template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002972inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002973basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002974basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002975{
2976 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2977}
2978
2979template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002980inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002981basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002982basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002983{
2984 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2985}
2986
2987// erase
2988
2989template <class _CharT, class _Traits, class _Allocator>
2990basic_string<_CharT, _Traits, _Allocator>&
2991basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2992{
2993 size_type __sz = size();
2994 if (__pos > __sz)
2995 this->__throw_out_of_range();
2996 if (__n)
2997 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002998 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002999 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003000 size_type __n_move = __sz - __pos - __n;
3001 if (__n_move != 0)
3002 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3003 __sz -= __n;
3004 __set_size(__sz);
3005 __invalidate_iterators_past(__sz);
3006 traits_type::assign(__p[__sz], value_type());
3007 }
3008 return *this;
3009}
3010
3011template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003012inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003013typename basic_string<_CharT, _Traits, _Allocator>::iterator
3014basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3015{
Howard Hinnant499cea12013-08-23 17:37:05 +00003016#if _LIBCPP_DEBUG_LEVEL >= 2
3017 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3018 "string::erase(iterator) called with an iterator not"
3019 " referring to this string");
3020#endif
3021 _LIBCPP_ASSERT(__pos != end(),
3022 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003023 iterator __b = begin();
3024 size_type __r = static_cast<size_type>(__pos - __b);
3025 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00003026 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003027}
3028
3029template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003030inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003031typename basic_string<_CharT, _Traits, _Allocator>::iterator
3032basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3033{
Howard Hinnant499cea12013-08-23 17:37:05 +00003034#if _LIBCPP_DEBUG_LEVEL >= 2
3035 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3036 "string::erase(iterator, iterator) called with an iterator not"
3037 " referring to this string");
3038#endif
3039 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003040 iterator __b = begin();
3041 size_type __r = static_cast<size_type>(__first - __b);
3042 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00003043 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003044}
3045
3046template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003047inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003048void
3049basic_string<_CharT, _Traits, _Allocator>::pop_back()
3050{
Howard Hinnant499cea12013-08-23 17:37:05 +00003051 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003052 size_type __sz;
3053 if (__is_long())
3054 {
3055 __sz = __get_long_size() - 1;
3056 __set_long_size(__sz);
3057 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3058 }
3059 else
3060 {
3061 __sz = __get_short_size() - 1;
3062 __set_short_size(__sz);
3063 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3064 }
3065 __invalidate_iterators_past(__sz);
3066}
3067
3068template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003069inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003070void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003071basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003072{
3073 __invalidate_all_iterators();
3074 if (__is_long())
3075 {
3076 traits_type::assign(*__get_long_pointer(), value_type());
3077 __set_long_size(0);
3078 }
3079 else
3080 {
3081 traits_type::assign(*__get_short_pointer(), value_type());
3082 __set_short_size(0);
3083 }
3084}
3085
3086template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003087inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003088void
3089basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3090{
3091 if (__is_long())
3092 {
3093 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3094 __set_long_size(__pos);
3095 }
3096 else
3097 {
3098 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3099 __set_short_size(__pos);
3100 }
3101 __invalidate_iterators_past(__pos);
3102}
3103
3104template <class _CharT, class _Traits, class _Allocator>
3105void
3106basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3107{
3108 size_type __sz = size();
3109 if (__n > __sz)
3110 append(__n - __sz, __c);
3111 else
3112 __erase_to_end(__n);
3113}
3114
3115template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierf9782de2018-11-26 20:15:38 +00003116inline void
3117basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
3118{
3119 size_type __sz = size();
3120 if (__n > __sz) {
3121 __append_default_init(__n - __sz);
3122 } else
3123 __erase_to_end(__n);
3124}
3125
3126template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003127inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003128typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003129basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003130{
Howard Hinnante32b5e22010-11-17 17:55:08 +00003131 size_type __m = __alloc_traits::max_size(__alloc());
Eric Fiselier5ccf0432017-10-17 13:16:01 +00003132#ifdef _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00003133 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003134#else
Marshall Clow09f85502013-10-31 17:23:08 +00003135 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003136#endif
3137}
3138
3139template <class _CharT, class _Traits, class _Allocator>
3140void
3141basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3142{
3143 if (__res_arg > max_size())
3144 this->__throw_length_error();
3145 size_type __cap = capacity();
3146 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003147 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003148 __res_arg = __recommend(__res_arg);
3149 if (__res_arg != __cap)
3150 {
3151 pointer __new_data, __p;
3152 bool __was_long, __now_long;
3153 if (__res_arg == __min_cap - 1)
3154 {
3155 __was_long = true;
3156 __now_long = false;
3157 __new_data = __get_short_pointer();
3158 __p = __get_long_pointer();
3159 }
3160 else
3161 {
3162 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003163 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003164 else
3165 {
3166 #ifndef _LIBCPP_NO_EXCEPTIONS
3167 try
3168 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003169 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00003170 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003171 #ifndef _LIBCPP_NO_EXCEPTIONS
3172 }
3173 catch (...)
3174 {
3175 return;
3176 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003177 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003178 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003179 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003180 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003181 }
3182 __now_long = true;
3183 __was_long = __is_long();
3184 __p = __get_pointer();
3185 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003186 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3187 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003188 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003189 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003190 if (__now_long)
3191 {
3192 __set_long_cap(__res_arg+1);
3193 __set_long_size(__sz);
3194 __set_long_pointer(__new_data);
3195 }
3196 else
3197 __set_short_size(__sz);
3198 __invalidate_all_iterators();
3199 }
3200}
3201
3202template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003203inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003204typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003205basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003206{
Howard Hinnant499cea12013-08-23 17:37:05 +00003207 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003208 return *(data() + __pos);
3209}
3210
3211template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003212inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003213typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003214basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003215{
Howard Hinnant499cea12013-08-23 17:37:05 +00003216 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003217 return *(__get_pointer() + __pos);
3218}
3219
3220template <class _CharT, class _Traits, class _Allocator>
3221typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3222basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3223{
3224 if (__n >= size())
3225 this->__throw_out_of_range();
3226 return (*this)[__n];
3227}
3228
3229template <class _CharT, class _Traits, class _Allocator>
3230typename basic_string<_CharT, _Traits, _Allocator>::reference
3231basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3232{
3233 if (__n >= size())
3234 this->__throw_out_of_range();
3235 return (*this)[__n];
3236}
3237
3238template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003239inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003240typename basic_string<_CharT, _Traits, _Allocator>::reference
3241basic_string<_CharT, _Traits, _Allocator>::front()
3242{
Howard Hinnant499cea12013-08-23 17:37:05 +00003243 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003244 return *__get_pointer();
3245}
3246
3247template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003248inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003249typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3250basic_string<_CharT, _Traits, _Allocator>::front() const
3251{
Howard Hinnant499cea12013-08-23 17:37:05 +00003252 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003253 return *data();
3254}
3255
3256template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003257inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003258typename basic_string<_CharT, _Traits, _Allocator>::reference
3259basic_string<_CharT, _Traits, _Allocator>::back()
3260{
Howard Hinnant499cea12013-08-23 17:37:05 +00003261 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003262 return *(__get_pointer() + size() - 1);
3263}
3264
3265template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003266inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003267typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3268basic_string<_CharT, _Traits, _Allocator>::back() const
3269{
Howard Hinnant499cea12013-08-23 17:37:05 +00003270 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003271 return *(data() + size() - 1);
3272}
3273
3274template <class _CharT, class _Traits, class _Allocator>
3275typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003276basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003277{
3278 size_type __sz = size();
3279 if (__pos > __sz)
3280 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003281 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003282 traits_type::copy(__s, data() + __pos, __rlen);
3283 return __rlen;
3284}
3285
3286template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003287inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003288basic_string<_CharT, _Traits, _Allocator>
3289basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3290{
3291 return basic_string(*this, __pos, __n, __alloc());
3292}
3293
3294template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003295inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003296void
3297basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00003298#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00003299 _NOEXCEPT_DEBUG
Marshall Clow7d914d12015-07-13 20:04:56 +00003300#else
Eric Fiselier47257c42016-12-28 05:53:01 +00003301 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00003302 __is_nothrow_swappable<allocator_type>::value)
3303#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003304{
Howard Hinnant499cea12013-08-23 17:37:05 +00003305#if _LIBCPP_DEBUG_LEVEL >= 2
3306 if (!__is_long())
3307 __get_db()->__invalidate_all(this);
3308 if (!__str.__is_long())
3309 __get_db()->__invalidate_all(&__str);
3310 __get_db()->swap(this, &__str);
3311#endif
Eric Fiselier47257c42016-12-28 05:53:01 +00003312 _LIBCPP_ASSERT(
3313 __alloc_traits::propagate_on_container_swap::value ||
3314 __alloc_traits::is_always_equal::value ||
3315 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnant0949eed2011-06-30 21:18:19 +00003316 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00003317 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003318}
3319
3320// find
3321
3322template <class _Traits>
3323struct _LIBCPP_HIDDEN __traits_eq
3324{
3325 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003326 _LIBCPP_INLINE_VISIBILITY
3327 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3328 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003329};
3330
3331template<class _CharT, class _Traits, class _Allocator>
3332typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003333basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003334 size_type __pos,
3335 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003336{
Alp Tokerec34c482014-05-15 11:27:39 +00003337 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003338 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003339 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003340}
3341
3342template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003343inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003344typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003345basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3346 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003347{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003348 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003349 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003350}
3351
3352template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003353template <class _Tp>
3354typename enable_if
3355<
3356 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3357 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3358>::type
3359basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
3360 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003361{
Marshall Clow64c10d02018-07-02 18:41:15 +00003362 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003363 return __str_find<value_type, size_type, traits_type, npos>
3364 (data(), size(), __sv.data(), __pos, __sv.size());
3365}
3366
3367template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003368inline
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003369typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003370basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003371 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003372{
Alp Tokerec34c482014-05-15 11:27:39 +00003373 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003374 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003375 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003376}
3377
3378template<class _CharT, class _Traits, class _Allocator>
3379typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003380basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3381 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003382{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003383 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003384 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003385}
3386
3387// rfind
3388
3389template<class _CharT, class _Traits, class _Allocator>
3390typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003391basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003392 size_type __pos,
3393 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003394{
Alp Tokerec34c482014-05-15 11:27:39 +00003395 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003396 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003397 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003398}
3399
3400template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003401inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003402typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003403basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3404 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003405{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003406 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003407 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003408}
3409
3410template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003411template <class _Tp>
3412typename enable_if
3413<
3414 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3415 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3416>::type
3417basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
3418 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003419{
Marshall Clow64c10d02018-07-02 18:41:15 +00003420 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003421 return __str_rfind<value_type, size_type, traits_type, npos>
3422 (data(), size(), __sv.data(), __pos, __sv.size());
3423}
3424
3425template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003426inline
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003427typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003428basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003429 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003430{
Alp Tokerec34c482014-05-15 11:27:39 +00003431 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003432 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003433 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003434}
3435
3436template<class _CharT, class _Traits, class _Allocator>
3437typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003438basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3439 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003440{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003441 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003442 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003443}
3444
3445// find_first_of
3446
3447template<class _CharT, class _Traits, class _Allocator>
3448typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003449basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003450 size_type __pos,
3451 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003452{
Alp Tokerec34c482014-05-15 11:27:39 +00003453 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003454 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003455 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003456}
3457
3458template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003459inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003460typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003461basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3462 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003463{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003464 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003465 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003466}
3467
3468template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003469template <class _Tp>
3470typename enable_if
3471<
3472 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3473 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3474>::type
3475basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
3476 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003477{
Marshall Clow64c10d02018-07-02 18:41:15 +00003478 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003479 return __str_find_first_of<value_type, size_type, traits_type, npos>
3480 (data(), size(), __sv.data(), __pos, __sv.size());
3481}
3482
3483template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003484inline
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003485typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003486basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003487 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003488{
Alp Tokerec34c482014-05-15 11:27:39 +00003489 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003490 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003491 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003492}
3493
3494template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003495inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003496typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003497basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3498 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003499{
3500 return find(__c, __pos);
3501}
3502
3503// find_last_of
3504
3505template<class _CharT, class _Traits, class _Allocator>
3506typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003507basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003508 size_type __pos,
3509 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003510{
Alp Tokerec34c482014-05-15 11:27:39 +00003511 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003512 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003513 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003514}
3515
3516template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003517inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003518typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003519basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3520 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003521{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003522 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003523 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003524}
3525
3526template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003527template <class _Tp>
3528typename enable_if
3529<
3530 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3531 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3532>::type
3533basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
3534 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003535{
Marshall Clow64c10d02018-07-02 18:41:15 +00003536 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003537 return __str_find_last_of<value_type, size_type, traits_type, npos>
3538 (data(), size(), __sv.data(), __pos, __sv.size());
3539}
3540
3541template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003542inline
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003543typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003544basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003545 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003546{
Alp Tokerec34c482014-05-15 11:27:39 +00003547 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003548 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003549 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003550}
3551
3552template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003553inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003554typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003555basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3556 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003557{
3558 return rfind(__c, __pos);
3559}
3560
3561// find_first_not_of
3562
3563template<class _CharT, class _Traits, class _Allocator>
3564typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003565basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003566 size_type __pos,
3567 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003568{
Alp Tokerec34c482014-05-15 11:27:39 +00003569 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003570 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003571 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003572}
3573
3574template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003575inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003576typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003577basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3578 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003579{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003580 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003581 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003582}
3583
3584template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003585template <class _Tp>
3586typename enable_if
3587<
3588 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3589 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3590>::type
3591basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
3592 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003593{
Marshall Clow64c10d02018-07-02 18:41:15 +00003594 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003595 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3596 (data(), size(), __sv.data(), __pos, __sv.size());
3597}
3598
3599template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003600inline
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003601typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003602basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003603 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003604{
Alp Tokerec34c482014-05-15 11:27:39 +00003605 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003606 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003607 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003608}
3609
3610template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003611inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003612typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003613basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3614 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003615{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003616 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003617 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003618}
3619
3620// find_last_not_of
3621
3622template<class _CharT, class _Traits, class _Allocator>
3623typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003624basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003625 size_type __pos,
3626 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003627{
Alp Tokerec34c482014-05-15 11:27:39 +00003628 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003629 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003630 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003631}
3632
3633template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003634inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003635typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003636basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3637 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003638{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003639 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003640 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003641}
3642
3643template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003644template <class _Tp>
3645typename enable_if
3646<
3647 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3648 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3649>::type
3650basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
3651 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003652{
Marshall Clow64c10d02018-07-02 18:41:15 +00003653 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003654 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3655 (data(), size(), __sv.data(), __pos, __sv.size());
3656}
3657
3658template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003659inline
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003660typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003661basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003662 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003663{
Alp Tokerec34c482014-05-15 11:27:39 +00003664 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003665 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003666 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003667}
3668
3669template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003670inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003671typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003672basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3673 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003674{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003675 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003676 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003677}
3678
3679// compare
3680
3681template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003682template <class _Tp>
3683typename enable_if
3684<
3685 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3686 int
3687>::type
3688basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003689{
Marshall Clow64c10d02018-07-02 18:41:15 +00003690 __self_view __sv = __t;
Howard Hinnantfa06d752011-07-24 21:45:06 +00003691 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003692 size_t __rhs_sz = __sv.size();
3693 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:06 +00003694 _VSTD::min(__lhs_sz, __rhs_sz));
3695 if (__result != 0)
3696 return __result;
3697 if (__lhs_sz < __rhs_sz)
3698 return -1;
3699 if (__lhs_sz > __rhs_sz)
3700 return 1;
3701 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003702}
3703
3704template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003705inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003706int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003707basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003708{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003709 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003710}
3711
3712template <class _CharT, class _Traits, class _Allocator>
3713int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003714basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3715 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003716 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003717 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003718{
Alp Tokerec34c482014-05-15 11:27:39 +00003719 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003720 size_type __sz = size();
3721 if (__pos1 > __sz || __n2 == npos)
3722 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003723 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3724 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003725 if (__r == 0)
3726 {
3727 if (__rlen < __n2)
3728 __r = -1;
3729 else if (__rlen > __n2)
3730 __r = 1;
3731 }
3732 return __r;
3733}
3734
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003735template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003736template <class _Tp>
3737typename enable_if
3738<
3739 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3740 int
3741>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003742basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3743 size_type __n1,
Marshall Clow64c10d02018-07-02 18:41:15 +00003744 const _Tp& __t) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003745{
Marshall Clow64c10d02018-07-02 18:41:15 +00003746 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003747 return compare(__pos1, __n1, __sv.data(), __sv.size());
3748}
3749
3750template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003751inline
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003752int
3753basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3754 size_type __n1,
3755 const basic_string& __str) const
3756{
3757 return compare(__pos1, __n1, __str.data(), __str.size());
3758}
3759
3760template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00003761template <class _Tp>
3762typename enable_if
3763<
Marshall Clowf1729d92017-11-15 20:02:27 +00003764 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3765 int
Marshall Clow6ac8de02016-09-24 22:45:42 +00003766>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003767basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3768 size_type __n1,
Marshall Clow6ac8de02016-09-24 22:45:42 +00003769 const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003770 size_type __pos2,
3771 size_type __n2) const
3772{
Marshall Clow6ac8de02016-09-24 22:45:42 +00003773 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003774 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3775}
3776
3777template <class _CharT, class _Traits, class _Allocator>
3778int
3779basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3780 size_type __n1,
3781 const basic_string& __str,
3782 size_type __pos2,
3783 size_type __n2) const
3784{
3785 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3786}
3787
3788template <class _CharT, class _Traits, class _Allocator>
3789int
3790basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3791{
3792 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3793 return compare(0, npos, __s, traits_type::length(__s));
3794}
3795
3796template <class _CharT, class _Traits, class _Allocator>
3797int
3798basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3799 size_type __n1,
3800 const value_type* __s) const
3801{
3802 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3803 return compare(__pos1, __n1, __s, traits_type::length(__s));
3804}
3805
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003806// __invariants
3807
3808template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003809inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003810bool
3811basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3812{
3813 if (size() > capacity())
3814 return false;
3815 if (capacity() < __min_cap - 1)
3816 return false;
3817 if (data() == 0)
3818 return false;
3819 if (data()[size()] != value_type(0))
3820 return false;
3821 return true;
3822}
3823
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003824// __clear_and_shrink
3825
3826template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003827inline
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003828void
Marshall Clowab343bb2018-05-29 17:04:37 +00003829basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003830{
3831 clear();
3832 if(__is_long())
3833 {
3834 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
3835 __set_long_cap(0);
3836 __set_short_size(0);
3837 }
3838}
3839
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003840// operator==
3841
3842template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003843inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003844bool
3845operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003846 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003847{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003848 size_t __lhs_sz = __lhs.size();
3849 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3850 __rhs.data(),
3851 __lhs_sz) == 0;
3852}
3853
3854template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003855inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003856bool
3857operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3858 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3859{
3860 size_t __lhs_sz = __lhs.size();
3861 if (__lhs_sz != __rhs.size())
3862 return false;
3863 const char* __lp = __lhs.data();
3864 const char* __rp = __rhs.data();
3865 if (__lhs.__is_long())
3866 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3867 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3868 if (*__lp != *__rp)
3869 return false;
3870 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003871}
3872
3873template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003874inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003875bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003876operator==(const _CharT* __lhs,
3877 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003878{
Eric Fiselier4f241822015-08-28 03:02:37 +00003879 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3880 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3881 size_t __lhs_len = _Traits::length(__lhs);
3882 if (__lhs_len != __rhs.size()) return false;
3883 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003884}
3885
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003886template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003887inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003888bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003889operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3890 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003891{
Eric Fiselier4f241822015-08-28 03:02:37 +00003892 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3893 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3894 size_t __rhs_len = _Traits::length(__rhs);
3895 if (__rhs_len != __lhs.size()) return false;
3896 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003897}
3898
Howard Hinnant324bb032010-08-22 00:02:43 +00003899template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003900inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003901bool
3902operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003903 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003904{
3905 return !(__lhs == __rhs);
3906}
3907
3908template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003909inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003910bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003911operator!=(const _CharT* __lhs,
3912 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003913{
3914 return !(__lhs == __rhs);
3915}
3916
3917template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003918inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003919bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003920operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3921 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003922{
3923 return !(__lhs == __rhs);
3924}
3925
3926// operator<
3927
3928template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003929inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003930bool
3931operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003932 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003933{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003934 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003935}
3936
3937template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003938inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003939bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003940operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3941 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003942{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003943 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003944}
3945
3946template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003947inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003948bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003949operator< (const _CharT* __lhs,
3950 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003951{
3952 return __rhs.compare(__lhs) > 0;
3953}
3954
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003955// operator>
3956
3957template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003958inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003959bool
3960operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003961 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003962{
3963 return __rhs < __lhs;
3964}
3965
3966template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003967inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003968bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003969operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3970 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003971{
3972 return __rhs < __lhs;
3973}
3974
3975template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003976inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003977bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003978operator> (const _CharT* __lhs,
3979 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003980{
3981 return __rhs < __lhs;
3982}
3983
3984// operator<=
3985
3986template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003987inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003988bool
3989operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003990 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003991{
3992 return !(__rhs < __lhs);
3993}
3994
3995template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003996inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003997bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003998operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3999 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004000{
4001 return !(__rhs < __lhs);
4002}
4003
4004template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004005inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004006bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00004007operator<=(const _CharT* __lhs,
4008 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004009{
4010 return !(__rhs < __lhs);
4011}
4012
4013// operator>=
4014
4015template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004016inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004017bool
4018operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00004019 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004020{
4021 return !(__lhs < __rhs);
4022}
4023
4024template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004025inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004026bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00004027operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4028 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004029{
4030 return !(__lhs < __rhs);
4031}
4032
4033template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004034inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004035bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00004036operator>=(const _CharT* __lhs,
4037 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004038{
4039 return !(__lhs < __rhs);
4040}
4041
4042// operator +
4043
4044template<class _CharT, class _Traits, class _Allocator>
4045basic_string<_CharT, _Traits, _Allocator>
4046operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4047 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4048{
4049 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4050 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4051 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4052 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4053 __r.append(__rhs.data(), __rhs_sz);
4054 return __r;
4055}
4056
4057template<class _CharT, class _Traits, class _Allocator>
4058basic_string<_CharT, _Traits, _Allocator>
4059operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4060{
4061 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4062 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4063 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4064 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4065 __r.append(__rhs.data(), __rhs_sz);
4066 return __r;
4067}
4068
4069template<class _CharT, class _Traits, class _Allocator>
4070basic_string<_CharT, _Traits, _Allocator>
4071operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4072{
4073 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4074 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4075 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4076 __r.append(__rhs.data(), __rhs_sz);
4077 return __r;
4078}
4079
4080template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00004081inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004082basic_string<_CharT, _Traits, _Allocator>
4083operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4084{
4085 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4086 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4087 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4088 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4089 __r.append(__rhs, __rhs_sz);
4090 return __r;
4091}
4092
4093template<class _CharT, class _Traits, class _Allocator>
4094basic_string<_CharT, _Traits, _Allocator>
4095operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4096{
4097 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4098 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4099 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4100 __r.push_back(__rhs);
4101 return __r;
4102}
4103
Eric Fiselier3e928972017-04-19 00:28:44 +00004104#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004105
4106template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004107inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004108basic_string<_CharT, _Traits, _Allocator>
4109operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4110{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004111 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004112}
4113
4114template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004115inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004116basic_string<_CharT, _Traits, _Allocator>
4117operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4118{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004119 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004120}
4121
4122template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004123inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004124basic_string<_CharT, _Traits, _Allocator>
4125operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4126{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004127 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004128}
4129
4130template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004131inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004132basic_string<_CharT, _Traits, _Allocator>
4133operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4134{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004135 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004136}
4137
4138template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004139inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004140basic_string<_CharT, _Traits, _Allocator>
4141operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4142{
4143 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004144 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004145}
4146
4147template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004148inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004149basic_string<_CharT, _Traits, _Allocator>
4150operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4151{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004152 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004153}
4154
4155template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004156inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004157basic_string<_CharT, _Traits, _Allocator>
4158operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4159{
4160 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004161 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004162}
4163
Eric Fiselier3e928972017-04-19 00:28:44 +00004164#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004165
4166// swap
4167
4168template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004169inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004170void
Howard Hinnanta6119a82011-05-29 19:57:12 +00004171swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00004172 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4173 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004174{
4175 __lhs.swap(__rhs);
4176}
4177
Marshall Clow96484472018-12-11 04:35:44 +00004178#ifndef _LIBCPP_NO_HAS_CHAR8_T
4179typedef basic_string<char8_t> u8string;
4180#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004181
Marshall Clow96484472018-12-11 04:35:44 +00004182#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004183typedef basic_string<char16_t> u16string;
4184typedef basic_string<char32_t> u32string;
Howard Hinnant324bb032010-08-22 00:02:43 +00004185#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004186
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004187_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4188_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4189_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4190_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4191_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004192
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004193_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4194_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4195_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004196
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004197_LIBCPP_FUNC_VIS string to_string(int __val);
4198_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4199_LIBCPP_FUNC_VIS string to_string(long __val);
4200_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4201_LIBCPP_FUNC_VIS string to_string(long long __val);
4202_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4203_LIBCPP_FUNC_VIS string to_string(float __val);
4204_LIBCPP_FUNC_VIS string to_string(double __val);
4205_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004206
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004207_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4208_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4209_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4210_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4211_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004212
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004213_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4214_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4215_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004216
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004217_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4218_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4219_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4220_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4221_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4222_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4223_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4224_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4225_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004226
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004227template<class _CharT, class _Traits, class _Allocator>
4228 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4229 basic_string<_CharT, _Traits, _Allocator>::npos;
4230
4231template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +00004232struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004233 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4234{
4235 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004236 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004237};
4238
4239template<class _CharT, class _Traits, class _Allocator>
4240size_t
4241hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004242 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004243{
Sean Huntaffd9e52011-07-29 23:31:56 +00004244 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004245}
4246
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004247template<class _CharT, class _Traits, class _Allocator>
4248basic_ostream<_CharT, _Traits>&
4249operator<<(basic_ostream<_CharT, _Traits>& __os,
4250 const basic_string<_CharT, _Traits, _Allocator>& __str);
4251
4252template<class _CharT, class _Traits, class _Allocator>
4253basic_istream<_CharT, _Traits>&
4254operator>>(basic_istream<_CharT, _Traits>& __is,
4255 basic_string<_CharT, _Traits, _Allocator>& __str);
4256
4257template<class _CharT, class _Traits, class _Allocator>
4258basic_istream<_CharT, _Traits>&
4259getline(basic_istream<_CharT, _Traits>& __is,
4260 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4261
4262template<class _CharT, class _Traits, class _Allocator>
4263inline _LIBCPP_INLINE_VISIBILITY
4264basic_istream<_CharT, _Traits>&
4265getline(basic_istream<_CharT, _Traits>& __is,
4266 basic_string<_CharT, _Traits, _Allocator>& __str);
4267
Eric Fiselier3e928972017-04-19 00:28:44 +00004268#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004269
4270template<class _CharT, class _Traits, class _Allocator>
4271inline _LIBCPP_INLINE_VISIBILITY
4272basic_istream<_CharT, _Traits>&
4273getline(basic_istream<_CharT, _Traits>&& __is,
4274 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4275
4276template<class _CharT, class _Traits, class _Allocator>
4277inline _LIBCPP_INLINE_VISIBILITY
4278basic_istream<_CharT, _Traits>&
4279getline(basic_istream<_CharT, _Traits>&& __is,
4280 basic_string<_CharT, _Traits, _Allocator>& __str);
4281
Eric Fiselier3e928972017-04-19 00:28:44 +00004282#endif // _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004283
Marshall Clowf9276352018-12-14 18:49:35 +00004284#if _LIBCPP_STD_VER > 17
4285template<class _CharT, class _Traits, class _Allocator, class _Up>
4286inline _LIBCPP_INLINE_VISIBILITY
4287void erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v)
4288{ __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end()); }
4289
4290template<class _CharT, class _Traits, class _Allocator, class _Predicate>
4291inline _LIBCPP_INLINE_VISIBILITY
4292void erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, _Predicate __pred)
4293{ __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred), __str.end()); }
4294#endif
4295
Howard Hinnant499cea12013-08-23 17:37:05 +00004296#if _LIBCPP_DEBUG_LEVEL >= 2
4297
4298template<class _CharT, class _Traits, class _Allocator>
4299bool
4300basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4301{
4302 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4303 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4304}
4305
4306template<class _CharT, class _Traits, class _Allocator>
4307bool
4308basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4309{
4310 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4311 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4312}
4313
4314template<class _CharT, class _Traits, class _Allocator>
4315bool
4316basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4317{
4318 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4319 return this->data() <= __p && __p <= this->data() + this->size();
4320}
4321
4322template<class _CharT, class _Traits, class _Allocator>
4323bool
4324basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4325{
4326 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4327 return this->data() <= __p && __p < this->data() + this->size();
4328}
4329
4330#endif // _LIBCPP_DEBUG_LEVEL >= 2
4331
Shoaib Meenai68506702017-06-29 02:52:46 +00004332_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
4333_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Shoaib Meenai68506702017-06-29 02:52:46 +00004334
Marshall Clow15234322013-07-23 17:05:24 +00004335#if _LIBCPP_STD_VER > 11
4336// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004337inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004338{
4339 inline namespace string_literals
4340 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004341 inline _LIBCPP_INLINE_VISIBILITY
4342 basic_string<char> operator "" s( const char *__str, size_t __len )
4343 {
4344 return basic_string<char> (__str, __len);
4345 }
Marshall Clow15234322013-07-23 17:05:24 +00004346
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004347 inline _LIBCPP_INLINE_VISIBILITY
4348 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4349 {
4350 return basic_string<wchar_t> (__str, __len);
4351 }
Marshall Clow15234322013-07-23 17:05:24 +00004352
Marshall Clow96484472018-12-11 04:35:44 +00004353#ifndef _LIBCPP_NO_HAS_CHAR8_T
4354 inline _LIBCPP_INLINE_VISIBILITY
4355 basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPT
4356 {
4357 return basic_string<char8_t> (__str, __len);
4358 }
4359#endif
4360
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004361 inline _LIBCPP_INLINE_VISIBILITY
4362 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4363 {
4364 return basic_string<char16_t> (__str, __len);
4365 }
Marshall Clow15234322013-07-23 17:05:24 +00004366
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004367 inline _LIBCPP_INLINE_VISIBILITY
4368 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4369 {
4370 return basic_string<char32_t> (__str, __len);
4371 }
Marshall Clow15234322013-07-23 17:05:24 +00004372 }
4373}
4374#endif
4375
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004376_LIBCPP_END_NAMESPACE_STD
4377
Eric Fiselier018a3d52017-05-31 22:07:49 +00004378_LIBCPP_POP_MACROS
4379
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004380#endif // _LIBCPP_STRING