blob: 96d36f4f7f4af6cb5fcd78b6390fe3f288ae2284 [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
440typedef basic_string<char> string;
441typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000442typedef basic_string<char16_t> u16string;
443typedef basic_string<char32_t> u32string;
444
445int stoi (const string& str, size_t* idx = 0, int base = 10);
446long stol (const string& str, size_t* idx = 0, int base = 10);
447unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
448long long stoll (const string& str, size_t* idx = 0, int base = 10);
449unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
450
451float stof (const string& str, size_t* idx = 0);
452double stod (const string& str, size_t* idx = 0);
453long double stold(const string& str, size_t* idx = 0);
454
455string to_string(int val);
456string to_string(unsigned val);
457string to_string(long val);
458string to_string(unsigned long val);
459string to_string(long long val);
460string to_string(unsigned long long val);
461string to_string(float val);
462string to_string(double val);
463string to_string(long double val);
464
465int stoi (const wstring& str, size_t* idx = 0, int base = 10);
466long stol (const wstring& str, size_t* idx = 0, int base = 10);
467unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
468long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
469unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
470
471float stof (const wstring& str, size_t* idx = 0);
472double stod (const wstring& str, size_t* idx = 0);
473long double stold(const wstring& str, size_t* idx = 0);
474
475wstring to_wstring(int val);
476wstring to_wstring(unsigned val);
477wstring to_wstring(long val);
478wstring to_wstring(unsigned long val);
479wstring to_wstring(long long val);
480wstring to_wstring(unsigned long long val);
481wstring to_wstring(float val);
482wstring to_wstring(double val);
483wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000484
485template <> struct hash<string>;
486template <> struct hash<u16string>;
487template <> struct hash<u32string>;
488template <> struct hash<wstring>;
489
Marshall Clow15234322013-07-23 17:05:24 +0000490basic_string<char> operator "" s( const char *str, size_t len ); // C++14
491basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
492basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
493basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
494
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495} // std
496
497*/
498
499#include <__config>
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000500#include <string_view>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501#include <iosfwd>
502#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000503#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504#include <cwchar>
505#include <algorithm>
506#include <iterator>
507#include <utility>
508#include <memory>
509#include <stdexcept>
510#include <type_traits>
511#include <initializer_list>
512#include <__functional_base>
513#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
514#include <cstdint>
515#endif
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000516
Eric Fiselierb9536102014-08-10 23:53:08 +0000517#include <__debug>
518
Howard Hinnant08e17472011-10-17 20:05:10 +0000519#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000520#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000521#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000522
Eric Fiselier018a3d52017-05-31 22:07:49 +0000523_LIBCPP_PUSH_MACROS
524#include <__undef_macros>
525
526
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000527_LIBCPP_BEGIN_NAMESPACE_STD
528
529// fpos
530
531template <class _StateT>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000532class _LIBCPP_TEMPLATE_VIS fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533{
534private:
535 _StateT __st_;
536 streamoff __off_;
537public:
538 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
539
540 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
541
542 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
543 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
544
545 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
546 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
547 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
548 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
549};
550
551template <class _StateT>
552inline _LIBCPP_INLINE_VISIBILITY
553streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
554 {return streamoff(__x) - streamoff(__y);}
555
556template <class _StateT>
557inline _LIBCPP_INLINE_VISIBILITY
558bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
559 {return streamoff(__x) == streamoff(__y);}
560
561template <class _StateT>
562inline _LIBCPP_INLINE_VISIBILITY
563bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
564 {return streamoff(__x) != streamoff(__y);}
565
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000566// basic_string
567
568template<class _CharT, class _Traits, class _Allocator>
569basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000570operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
571 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572
573template<class _CharT, class _Traits, class _Allocator>
574basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000575operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000576
577template<class _CharT, class _Traits, class _Allocator>
578basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000579operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000580
581template<class _CharT, class _Traits, class _Allocator>
582basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000583operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000584
585template<class _CharT, class _Traits, class _Allocator>
586basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000587operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000588
Shoaib Meenai487562f2017-07-29 02:54:41 +0000589_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
590
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000591template <bool>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000592class _LIBCPP_TEMPLATE_VIS __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593{
594protected:
Marshall Clow14c09a22016-08-25 15:09:01 +0000595 _LIBCPP_NORETURN void __throw_length_error() const;
596 _LIBCPP_NORETURN void __throw_out_of_range() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000597};
598
599template <bool __b>
600void
601__basic_string_common<__b>::__throw_length_error() const
602{
Marshall Clow14c09a22016-08-25 15:09:01 +0000603 _VSTD::__throw_length_error("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000604}
605
606template <bool __b>
607void
608__basic_string_common<__b>::__throw_out_of_range() const
609{
Marshall Clow14c09a22016-08-25 15:09:01 +0000610 _VSTD::__throw_out_of_range("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000611}
612
Eric Fiselier833d6442016-09-15 22:27:07 +0000613_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000614
Marshall Clowdf9db312016-01-13 21:54:34 +0000615#ifdef _LIBCPP_NO_EXCEPTIONS
616template <class _Iter>
617struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
618#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
619template <class _Iter>
620struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
621#else
622template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
623struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
624 noexcept(++(declval<_Iter&>())) &&
625 is_nothrow_assignable<_Iter&, _Iter>::value &&
626 noexcept(declval<_Iter>() == declval<_Iter>()) &&
627 noexcept(*declval<_Iter>())
628)) {};
629
630template <class _Iter>
631struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
632#endif
633
634
635template <class _Iter>
636struct __libcpp_string_gets_noexcept_iterator
637 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
638
Marshall Clow6ac8de02016-09-24 22:45:42 +0000639template <class _CharT, class _Traits, class _Tp>
640struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
Marshall Clowf1729d92017-11-15 20:02:27 +0000641 ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
Marshall Clow6ac8de02016-09-24 22:45:42 +0000642 !is_convertible<const _Tp&, const _CharT*>::value)) {};
643
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000644#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000645
646template <class _CharT, size_t = sizeof(_CharT)>
647struct __padding
648{
649 unsigned char __xx[sizeof(_CharT)-1];
650};
651
652template <class _CharT>
653struct __padding<_CharT, 1>
654{
655};
656
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000657#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000658
Howard Hinnant324bb032010-08-22 00:02:43 +0000659template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000660class _LIBCPP_TEMPLATE_VIS basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661 : private __basic_string_common<true>
662{
663public:
664 typedef basic_string __self;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000665 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000666 typedef _Traits traits_type;
Marshall Clow2d4c3fa2017-03-15 18:41:11 +0000667 typedef _CharT value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000669 typedef allocator_traits<allocator_type> __alloc_traits;
670 typedef typename __alloc_traits::size_type size_type;
671 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000672 typedef value_type& reference;
673 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000674 typedef typename __alloc_traits::pointer pointer;
675 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676
Marshall Clow256f1872018-03-21 00:36:05 +0000677 static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
678 static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
679 static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
680 static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
Howard Hinnant499cea12013-08-23 17:37:05 +0000681 "traits_type::char_type must be the same type as CharT");
Marshall Clow256f1872018-03-21 00:36:05 +0000682 static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
Howard Hinnant499cea12013-08-23 17:37:05 +0000683 "Allocator::value_type must be same type as value_type");
Marshall Clow64c10d02018-07-02 18:41:15 +0000684
Howard Hinnant499cea12013-08-23 17:37:05 +0000685#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000686 typedef pointer iterator;
687 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000688#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689 typedef __wrap_iter<pointer> iterator;
690 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000691#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000692 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
693 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000694
695private:
Howard Hinnant15467182013-04-30 21:44:48 +0000696
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000697#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000698
699 struct __long
700 {
701 pointer __data_;
702 size_type __size_;
703 size_type __cap_;
704 };
705
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000706#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000707 static const size_type __short_mask = 0x01;
708 static const size_type __long_mask = 0x1ul;
Howard Hinnant15467182013-04-30 21:44:48 +0000709#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000710 static const size_type __short_mask = 0x80;
711 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant15467182013-04-30 21:44:48 +0000712#endif // _LIBCPP_BIG_ENDIAN
713
714 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
715 (sizeof(__long) - 1)/sizeof(value_type) : 2};
716
717 struct __short
718 {
719 value_type __data_[__min_cap];
720 struct
721 : __padding<value_type>
722 {
723 unsigned char __size_;
724 };
725 };
726
727#else
728
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000729 struct __long
730 {
731 size_type __cap_;
732 size_type __size_;
733 pointer __data_;
734 };
735
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000736#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000737 static const size_type __short_mask = 0x80;
738 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant324bb032010-08-22 00:02:43 +0000739#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000740 static const size_type __short_mask = 0x01;
741 static const size_type __long_mask = 0x1ul;
Howard Hinnant324bb032010-08-22 00:02:43 +0000742#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000744 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
745 (sizeof(__long) - 1)/sizeof(value_type) : 2};
746
747 struct __short
748 {
749 union
750 {
751 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +0000752 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000753 };
754 value_type __data_[__min_cap];
755 };
756
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000757#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000758
Howard Hinnant499cea12013-08-23 17:37:05 +0000759 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000760
Howard Hinnant499cea12013-08-23 17:37:05 +0000761 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000762
763 struct __raw
764 {
765 size_type __words[__n_words];
766 };
767
768 struct __rep
769 {
770 union
771 {
772 __long __l;
773 __short __s;
774 __raw __r;
775 };
776 };
777
778 __compressed_pair<__rep, allocator_type> __r_;
779
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000780public:
781 static const size_type npos = -1;
782
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000783 _LIBCPP_INLINE_VISIBILITY basic_string()
784 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000785
786 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
787#if _LIBCPP_STD_VER <= 14
788 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
789#else
790 _NOEXCEPT;
791#endif
792
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000793 basic_string(const basic_string& __str);
794 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +0000795
Eric Fiselier3e928972017-04-19 00:28:44 +0000796#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant9f193f22011-01-26 00:06:59 +0000797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000798 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +0000799#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000800 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000801#else
802 _NOEXCEPT;
803#endif
804
Howard Hinnant9f193f22011-01-26 00:06:59 +0000805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000806 basic_string(basic_string&& __str, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000807#endif // _LIBCPP_CXX03_LANG
Marshall Clow64c10d02018-07-02 18:41:15 +0000808
809 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
810 _LIBCPP_INLINE_VISIBILITY
811 basic_string(const _CharT* __s);
812
813 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
814 _LIBCPP_INLINE_VISIBILITY
815 basic_string(const _CharT* __s, const _Allocator& __a);
816
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000817 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000818 basic_string(const _CharT* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000819 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000820 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000821 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000822 basic_string(size_type __n, _CharT __c);
Marshall Clow64c10d02018-07-02 18:41:15 +0000823
824 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
825 _LIBCPP_INLINE_VISIBILITY
826 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
827
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000828 basic_string(const basic_string& __str, size_type __pos, size_type __n,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000829 const _Allocator& __a = _Allocator());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000830 _LIBCPP_INLINE_VISIBILITY
831 basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000832 const _Allocator& __a = _Allocator());
Marshall Clow64c10d02018-07-02 18:41:15 +0000833
834 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 +0000835 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000836 basic_string(const _Tp& __t, size_type __pos, size_type __n,
Marshall Clow64c10d02018-07-02 18:41:15 +0000837 const allocator_type& __a = allocator_type());
838
839 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
840 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
841 explicit basic_string(const _Tp& __t);
842
843 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
844 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
845 explicit basic_string(const _Tp& __t, const allocator_type& __a);
846
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000847 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000848 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849 basic_string(_InputIterator __first, _InputIterator __last);
850 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000852 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000853#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000854 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000855 basic_string(initializer_list<_CharT> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000856 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000857 basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000858#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000859
Eric Fiselier51eb1d52016-10-31 03:42:50 +0000860 inline ~basic_string();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000862 _LIBCPP_INLINE_VISIBILITY
863 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
864
Howard Hinnante32b5e22010-11-17 17:55:08 +0000865 basic_string& operator=(const basic_string& __str);
Eric Fiselierf472d6c2017-01-23 21:24:58 +0000866
Marshall Clow64c10d02018-07-02 18:41:15 +0000867 template <class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
868 basic_string& operator=(const _Tp& __t)
869 {__self_view __sv = __t; return assign(__sv);}
870
Eric Fiselier3e928972017-04-19 00:28:44 +0000871#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000872 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000873 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +0000874 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Eric Fiselier3e928972017-04-19 00:28:44 +0000875 _LIBCPP_INLINE_VISIBILITY
876 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000877#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000878 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000879 basic_string& operator=(value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000880
Howard Hinnant499cea12013-08-23 17:37:05 +0000881#if _LIBCPP_DEBUG_LEVEL >= 2
882 _LIBCPP_INLINE_VISIBILITY
883 iterator begin() _NOEXCEPT
884 {return iterator(this, __get_pointer());}
885 _LIBCPP_INLINE_VISIBILITY
886 const_iterator begin() const _NOEXCEPT
887 {return const_iterator(this, __get_pointer());}
888 _LIBCPP_INLINE_VISIBILITY
889 iterator end() _NOEXCEPT
890 {return iterator(this, __get_pointer() + size());}
891 _LIBCPP_INLINE_VISIBILITY
892 const_iterator end() const _NOEXCEPT
893 {return const_iterator(this, __get_pointer() + size());}
894#else
Howard Hinnanta6119a82011-05-29 19:57:12 +0000895 _LIBCPP_INLINE_VISIBILITY
896 iterator begin() _NOEXCEPT
897 {return iterator(__get_pointer());}
898 _LIBCPP_INLINE_VISIBILITY
899 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000900 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000901 _LIBCPP_INLINE_VISIBILITY
902 iterator end() _NOEXCEPT
903 {return iterator(__get_pointer() + size());}
904 _LIBCPP_INLINE_VISIBILITY
905 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000906 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +0000907#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +0000908 _LIBCPP_INLINE_VISIBILITY
909 reverse_iterator rbegin() _NOEXCEPT
910 {return reverse_iterator(end());}
911 _LIBCPP_INLINE_VISIBILITY
912 const_reverse_iterator rbegin() const _NOEXCEPT
913 {return const_reverse_iterator(end());}
914 _LIBCPP_INLINE_VISIBILITY
915 reverse_iterator rend() _NOEXCEPT
916 {return reverse_iterator(begin());}
917 _LIBCPP_INLINE_VISIBILITY
918 const_reverse_iterator rend() const _NOEXCEPT
919 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000920
Howard Hinnanta6119a82011-05-29 19:57:12 +0000921 _LIBCPP_INLINE_VISIBILITY
922 const_iterator cbegin() const _NOEXCEPT
923 {return begin();}
924 _LIBCPP_INLINE_VISIBILITY
925 const_iterator cend() const _NOEXCEPT
926 {return end();}
927 _LIBCPP_INLINE_VISIBILITY
928 const_reverse_iterator crbegin() const _NOEXCEPT
929 {return rbegin();}
930 _LIBCPP_INLINE_VISIBILITY
931 const_reverse_iterator crend() const _NOEXCEPT
932 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000933
Howard Hinnanta6119a82011-05-29 19:57:12 +0000934 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000935 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000936 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
937 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
938 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +0000939 {return (__is_long() ? __get_long_cap()
940 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000941
942 void resize(size_type __n, value_type __c);
943 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
944
Eric Fiselier59e24fe2017-06-01 02:29:37 +0000945 void reserve(size_type __res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000946 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000947 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000948 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +0000949 void clear() _NOEXCEPT;
Marshall Clowf1729d92017-11-15 20:02:27 +0000950 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
951 bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000952
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000953 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
954 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000955
956 const_reference at(size_type __n) const;
957 reference at(size_type __n);
958
959 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clow64c10d02018-07-02 18:41:15 +0000960
961 template <class _Tp>
962 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
963 typename enable_if
964 <
965 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
966 basic_string&
967 >::type
968 operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);}
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000969 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000970 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Eric Fiselier3e928972017-04-19 00:28:44 +0000971#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000972 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Eric Fiselier3e928972017-04-19 00:28:44 +0000973#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000974
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000975 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976 basic_string& append(const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000977
978 template <class _Tp>
979 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
980 typename enable_if
981 <
982 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
983 basic_string&
984 >::type
985 append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +0000986 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow64c10d02018-07-02 18:41:15 +0000987
Marshall Clow42a87db2016-10-03 23:40:48 +0000988 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +0000989 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
990 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +0000991 <
992 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
993 basic_string&
994 >::type
995 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000996 basic_string& append(const value_type* __s, size_type __n);
997 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000998 basic_string& append(size_type __n, value_type __c);
Eric Fiselier026d38e2016-10-31 02:46:25 +0000999 template <class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001000 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1001 basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001002 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001003 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1004 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001005 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001006 __is_exactly_input_iterator<_InputIterator>::value
1007 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001008 basic_string&
1009 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +00001010 _LIBCPP_INLINE_VISIBILITY
1011 append(_InputIterator __first, _InputIterator __last) {
1012 const basic_string __temp (__first, __last, __alloc());
1013 append(__temp.data(), __temp.size());
1014 return *this;
1015 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001016 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001017 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1018 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001019 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001020 __is_forward_iterator<_ForwardIterator>::value
1021 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001022 basic_string&
1023 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +00001024 _LIBCPP_INLINE_VISIBILITY
1025 append(_ForwardIterator __first, _ForwardIterator __last) {
1026 return __append_forward_unsafe(__first, __last);
1027 }
1028
Eric Fiselier3e928972017-04-19 00:28:44 +00001029#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001031 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001032#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001033
1034 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001036 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001037 _LIBCPP_INLINE_VISIBILITY reference front();
1038 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1039 _LIBCPP_INLINE_VISIBILITY reference back();
1040 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001041
Marshall Clow64c10d02018-07-02 18:41:15 +00001042 template <class _Tp>
1043 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1044 typename enable_if
1045 <
1046 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1047 basic_string&
1048 >::type
1049 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001050 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29 +00001051 basic_string& assign(const basic_string& __str) { return *this = __str; }
Eric Fiselier3e928972017-04-19 00:28:44 +00001052#ifndef _LIBCPP_CXX03_LANG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001053 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001054 basic_string& assign(basic_string&& __str)
Marshall Clow7ed093b2015-10-05 16:17:34 +00001055 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001056 {*this = _VSTD::move(__str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001057#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +00001058 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48 +00001059 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001060 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1061 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001062 <
1063 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1064 basic_string&
1065 >::type
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001066 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001067 basic_string& assign(const value_type* __s, size_type __n);
1068 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001069 basic_string& assign(size_type __n, value_type __c);
1070 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001071 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1072 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001073 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001074 __is_exactly_input_iterator<_InputIterator>::value
1075 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001076 basic_string&
1077 >::type
1078 assign(_InputIterator __first, _InputIterator __last);
1079 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001080 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1081 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001082 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001083 __is_forward_iterator<_ForwardIterator>::value
1084 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001085 basic_string&
1086 >::type
1087 assign(_ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001088#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001090 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001091#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001092
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001094 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001095
1096 template <class _Tp>
1097 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1098 typename enable_if
1099 <
1100 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1101 basic_string&
1102 >::type
1103 insert(size_type __pos1, const _Tp& __t)
1104 { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
1105
Marshall Clow6ac8de02016-09-24 22:45:42 +00001106 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001107 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1108 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001109 <
1110 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1111 basic_string&
1112 >::type
1113 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001114 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001115 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1116 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001117 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1118 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1121 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001122 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1123 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001124 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001125 __is_exactly_input_iterator<_InputIterator>::value
1126 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001127 iterator
1128 >::type
1129 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1130 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001131 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1132 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001133 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001134 __is_forward_iterator<_ForwardIterator>::value
1135 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001136 iterator
1137 >::type
1138 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001139#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001141 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1142 {return insert(__pos, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001143#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144
1145 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001146 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001147 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001148 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149 iterator erase(const_iterator __first, const_iterator __last);
1150
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001151 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001152 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001153
1154 template <class _Tp>
1155 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1156 typename enable_if
1157 <
1158 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1159 basic_string&
1160 >::type
1161 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 +00001162 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 +00001163 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001164 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1165 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001166 <
1167 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1168 basic_string&
1169 >::type
1170 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001171 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1172 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001173 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001174 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001175 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001176
1177 template <class _Tp>
1178 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1179 typename enable_if
1180 <
1181 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1182 basic_string&
1183 >::type
1184 replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
1185
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001186 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001187 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001188 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001189 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001190 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001191 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001192 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001193 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1194 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001195 <
1196 __is_input_iterator<_InputIterator>::value,
1197 basic_string&
1198 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001199 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Eric Fiselier3e928972017-04-19 00:28:44 +00001200#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001201 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001202 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001203 {return replace(__i1, __i2, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001204#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001205
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001206 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001207 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001208 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1209
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001210 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001211 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001212#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00001213 _NOEXCEPT_DEBUG;
Marshall Clow7d914d12015-07-13 20:04:56 +00001214#else
Eric Fiselier47257c42016-12-28 05:53:01 +00001215 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00001216 __is_nothrow_swappable<allocator_type>::value);
1217#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001219 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001220 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001222 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Eric Fiselier10bebe22017-11-20 20:23:27 +00001223#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
Marshall Clowf532a702016-03-08 15:44:30 +00001224 _LIBCPP_INLINE_VISIBILITY
1225 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1226#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001227
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001228 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001229 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001230
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001231 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001232 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001233
1234 template <class _Tp>
1235 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1236 typename enable_if
1237 <
1238 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1239 size_type
1240 >::type
1241 find(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001242 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001243 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001244 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001245 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001246
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001248 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001249
1250 template <class _Tp>
1251 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1252 typename enable_if
1253 <
1254 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1255 size_type
1256 >::type
1257 rfind(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001258 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001259 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001260 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001261 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001262
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001264 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001265
1266 template <class _Tp>
1267 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1268 typename enable_if
1269 <
1270 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1271 size_type
1272 >::type
1273 find_first_of(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001274 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001275 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001276 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001277 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001278 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001279
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001280 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001281 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001282
1283 template <class _Tp>
1284 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1285 typename enable_if
1286 <
1287 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1288 size_type
1289 >::type
1290 find_last_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001291 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001293 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001294 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001295 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001296
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001297 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001298 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001299
1300 template <class _Tp>
1301 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1302 typename enable_if
1303 <
1304 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1305 size_type
1306 >::type
1307 find_first_not_of(const _Tp &__t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001308 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 +00001309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001310 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001311 _LIBCPP_INLINE_VISIBILITY
1312 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1313
1314 _LIBCPP_INLINE_VISIBILITY
1315 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001316
1317 template <class _Tp>
1318 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1319 typename enable_if
1320 <
1321 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1322 size_type
1323 >::type
1324 find_last_not_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001325 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 +00001326 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001327 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001328 _LIBCPP_INLINE_VISIBILITY
1329 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1330
1331 _LIBCPP_INLINE_VISIBILITY
1332 int compare(const basic_string& __str) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001333
1334 template <class _Tp>
1335 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1336 typename enable_if
1337 <
1338 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1339 int
1340 >::type
1341 compare(const _Tp &__t) const;
1342
1343 template <class _Tp>
1344 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1345 typename enable_if
1346 <
1347 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1348 int
1349 >::type
1350 compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
1351
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001352 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001353 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001354 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 +00001355
Marshall Clow6ac8de02016-09-24 22:45:42 +00001356 template <class _Tp>
Eric Fiselier9dbc0532016-10-14 05:29:46 +00001357 inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow6ac8de02016-09-24 22:45:42 +00001358 typename enable_if
1359 <
1360 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1361 int
1362 >::type
1363 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 +00001364 int compare(const value_type* __s) const _NOEXCEPT;
1365 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1366 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001367
Marshall Clow46b4ad52017-12-04 20:11:38 +00001368#if _LIBCPP_STD_VER > 17
1369 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1370 bool starts_with(__self_view __sv) const _NOEXCEPT
1371 { return __self_view(data(), size()).starts_with(__sv); }
1372
1373 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1374 bool starts_with(value_type __c) const _NOEXCEPT
1375 { return !empty() && _Traits::eq(front(), __c); }
1376
1377 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1378 bool starts_with(const value_type* __s) const _NOEXCEPT
1379 { return starts_with(__self_view(__s)); }
1380
1381 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1382 bool ends_with(__self_view __sv) const _NOEXCEPT
1383 { return __self_view(data(), size()).ends_with( __sv); }
1384
1385 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1386 bool ends_with(value_type __c) const _NOEXCEPT
1387 { return !empty() && _Traits::eq(back(), __c); }
1388
1389 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1390 bool ends_with(const value_type* __s) const _NOEXCEPT
1391 { return ends_with(__self_view(__s)); }
1392#endif
1393
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001394 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001395
Marshall Clowab343bb2018-05-29 17:04:37 +00001396 _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT;
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001397
Howard Hinnant08dd2532013-04-22 23:55:13 +00001398 _LIBCPP_INLINE_VISIBILITY
1399 bool __is_long() const _NOEXCEPT
1400 {return bool(__r_.first().__s.__size_ & __short_mask);}
1401
Howard Hinnant499cea12013-08-23 17:37:05 +00001402#if _LIBCPP_DEBUG_LEVEL >= 2
1403
1404 bool __dereferenceable(const const_iterator* __i) const;
1405 bool __decrementable(const const_iterator* __i) const;
1406 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1407 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1408
1409#endif // _LIBCPP_DEBUG_LEVEL >= 2
1410
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001411private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001412 _LIBCPP_INLINE_VISIBILITY
1413 allocator_type& __alloc() _NOEXCEPT
1414 {return __r_.second();}
1415 _LIBCPP_INLINE_VISIBILITY
1416 const allocator_type& __alloc() const _NOEXCEPT
1417 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001418
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001419#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001420
Howard Hinnanta6119a82011-05-29 19:57:12 +00001421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001422 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001423# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001424 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001425# else
1426 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1427# endif
1428
Howard Hinnanta6119a82011-05-29 19:57:12 +00001429 _LIBCPP_INLINE_VISIBILITY
1430 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001431# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001432 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001433# else
1434 {return __r_.first().__s.__size_;}
1435# endif
1436
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001437#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001438
1439 _LIBCPP_INLINE_VISIBILITY
1440 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001441# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001442 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1443# else
1444 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1445# endif
1446
1447 _LIBCPP_INLINE_VISIBILITY
1448 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001449# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001450 {return __r_.first().__s.__size_;}
1451# else
1452 {return __r_.first().__s.__size_ >> 1;}
1453# endif
1454
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001455#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001456
Howard Hinnanta6119a82011-05-29 19:57:12 +00001457 _LIBCPP_INLINE_VISIBILITY
1458 void __set_long_size(size_type __s) _NOEXCEPT
1459 {__r_.first().__l.__size_ = __s;}
1460 _LIBCPP_INLINE_VISIBILITY
1461 size_type __get_long_size() const _NOEXCEPT
1462 {return __r_.first().__l.__size_;}
1463 _LIBCPP_INLINE_VISIBILITY
1464 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001465 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1466
Howard Hinnanta6119a82011-05-29 19:57:12 +00001467 _LIBCPP_INLINE_VISIBILITY
1468 void __set_long_cap(size_type __s) _NOEXCEPT
1469 {__r_.first().__l.__cap_ = __long_mask | __s;}
1470 _LIBCPP_INLINE_VISIBILITY
1471 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001472 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001473
Howard Hinnanta6119a82011-05-29 19:57:12 +00001474 _LIBCPP_INLINE_VISIBILITY
1475 void __set_long_pointer(pointer __p) _NOEXCEPT
1476 {__r_.first().__l.__data_ = __p;}
1477 _LIBCPP_INLINE_VISIBILITY
1478 pointer __get_long_pointer() _NOEXCEPT
1479 {return __r_.first().__l.__data_;}
1480 _LIBCPP_INLINE_VISIBILITY
1481 const_pointer __get_long_pointer() const _NOEXCEPT
1482 {return __r_.first().__l.__data_;}
1483 _LIBCPP_INLINE_VISIBILITY
1484 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001485 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001486 _LIBCPP_INLINE_VISIBILITY
1487 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001488 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001489 _LIBCPP_INLINE_VISIBILITY
1490 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001491 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001492 _LIBCPP_INLINE_VISIBILITY
1493 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001494 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1495
Howard Hinnanta6119a82011-05-29 19:57:12 +00001496 _LIBCPP_INLINE_VISIBILITY
1497 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001498 {
1499 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1500 for (unsigned __i = 0; __i < __n_words; ++__i)
1501 __a[__i] = 0;
1502 }
1503
1504 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001506 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001507 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001508 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001509 static _LIBCPP_INLINE_VISIBILITY
1510 size_type __recommend(size_type __s) _NOEXCEPT
Marshall Clow088e6012018-02-07 21:30:17 +00001511 {
1512 if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
1513 size_type __guess = __align_it<sizeof(value_type) < __alignment ?
1514 __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
1515 if (__guess == __min_cap) ++__guess;
1516 return __guess;
1517 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001519 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001520 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001521 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001522 void __init(const value_type* __s, size_type __sz);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001523 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001524 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001525
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001526 template <class _InputIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001527 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001528 typename enable_if
1529 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001530 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001531 void
1532 >::type
1533 __init(_InputIterator __first, _InputIterator __last);
1534
1535 template <class _ForwardIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001536 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001537 typename enable_if
1538 <
1539 __is_forward_iterator<_ForwardIterator>::value,
1540 void
1541 >::type
1542 __init(_ForwardIterator __first, _ForwardIterator __last);
1543
1544 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001545 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001546 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1547 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001548 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001549
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001551 void __erase_to_end(size_type __pos);
1552
Howard Hinnante32b5e22010-11-17 17:55:08 +00001553 _LIBCPP_INLINE_VISIBILITY
1554 void __copy_assign_alloc(const basic_string& __str)
1555 {__copy_assign_alloc(__str, integral_constant<bool,
1556 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1557
1558 _LIBCPP_INLINE_VISIBILITY
1559 void __copy_assign_alloc(const basic_string& __str, true_type)
1560 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001561 if (__alloc() == __str.__alloc())
1562 __alloc() = __str.__alloc();
1563 else
Howard Hinnante32b5e22010-11-17 17:55:08 +00001564 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001565 if (!__str.__is_long())
1566 {
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001567 __clear_and_shrink();
Marshall Clow9247fd22017-01-31 03:40:52 +00001568 __alloc() = __str.__alloc();
1569 }
1570 else
1571 {
1572 allocator_type __a = __str.__alloc();
1573 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001574 __clear_and_shrink();
Marshall Clow9247fd22017-01-31 03:40:52 +00001575 __alloc() = _VSTD::move(__a);
1576 __set_long_pointer(__p);
1577 __set_long_cap(__str.__get_long_cap());
1578 __set_long_size(__str.size());
1579 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001580 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001581 }
1582
1583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001584 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001585 {}
1586
Eric Fiselier3e928972017-04-19 00:28:44 +00001587#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001588 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001589 void __move_assign(basic_string& __str, false_type)
1590 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001592 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001593#if _LIBCPP_STD_VER > 14
1594 _NOEXCEPT;
1595#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001596 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001597#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001598#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001599
1600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001601 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001602 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001603 _NOEXCEPT_(
1604 !__alloc_traits::propagate_on_container_move_assignment::value ||
1605 is_nothrow_move_assignable<allocator_type>::value)
1606 {__move_assign_alloc(__str, integral_constant<bool,
1607 __alloc_traits::propagate_on_container_move_assignment::value>());}
1608
1609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001610 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001611 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1612 {
1613 __alloc() = _VSTD::move(__c.__alloc());
1614 }
1615
1616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001617 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001618 _NOEXCEPT
1619 {}
1620
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001621 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1622 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001623
1624 friend basic_string operator+<>(const basic_string&, const basic_string&);
1625 friend basic_string operator+<>(const value_type*, const basic_string&);
1626 friend basic_string operator+<>(value_type, const basic_string&);
1627 friend basic_string operator+<>(const basic_string&, const value_type*);
1628 friend basic_string operator+<>(const basic_string&, value_type);
1629};
1630
Marshall Clow5b1e87e2018-02-08 06:34:03 +00001631#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1632template<class _InputIterator,
1633 class _CharT = typename iterator_traits<_InputIterator>::value_type,
1634 class _Allocator = allocator<_CharT>,
1635 class = typename enable_if<__is_input_iterator<_InputIterator>::value, void>::type,
1636 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1637 >
1638basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
1639 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
Marshall Clow64c10d02018-07-02 18:41:15 +00001640
1641template<class _CharT,
1642 class _Traits,
1643 class _Allocator = allocator<_CharT>,
1644 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1645 >
1646explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
1647 -> basic_string<_CharT, _Traits, _Allocator>;
1648
1649template<class _CharT,
1650 class _Traits,
1651 class _Allocator = allocator<_CharT>,
1652 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type,
1653 class _Sz = typename allocator_traits<_Allocator>::size_type
1654 >
1655basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
1656 -> basic_string<_CharT, _Traits, _Allocator>;
Marshall Clow5b1e87e2018-02-08 06:34:03 +00001657#endif
1658
1659
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001660template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001661inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001662void
1663basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1664{
Howard Hinnant499cea12013-08-23 17:37:05 +00001665#if _LIBCPP_DEBUG_LEVEL >= 2
1666 __get_db()->__invalidate_all(this);
1667#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001668}
1669
1670template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001671inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001672void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001673basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001674#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001675 __pos
1676#endif
1677 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001678{
Howard Hinnant499cea12013-08-23 17:37:05 +00001679#if _LIBCPP_DEBUG_LEVEL >= 2
1680 __c_node* __c = __get_db()->__find_c_and_lock(this);
1681 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001682 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001683 const_pointer __new_last = __get_pointer() + __pos;
1684 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001685 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001686 --__p;
1687 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1688 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001689 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001690 (*__p)->__c_ = nullptr;
1691 if (--__c->end_ != __p)
1692 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001693 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001694 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001695 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001696 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001697#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001698}
1699
1700template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001701inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001702basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001703 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001704{
Howard Hinnant499cea12013-08-23 17:37:05 +00001705#if _LIBCPP_DEBUG_LEVEL >= 2
1706 __get_db()->__insert_c(this);
1707#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001708 __zero();
1709}
1710
1711template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001712inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001713basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001714#if _LIBCPP_STD_VER <= 14
1715 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1716#else
1717 _NOEXCEPT
1718#endif
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001719: __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001720{
Howard Hinnant499cea12013-08-23 17:37:05 +00001721#if _LIBCPP_DEBUG_LEVEL >= 2
1722 __get_db()->__insert_c(this);
1723#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001724 __zero();
1725}
1726
1727template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001728void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1729 size_type __sz,
1730 size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001731{
1732 if (__reserve > max_size())
1733 this->__throw_length_error();
1734 pointer __p;
1735 if (__reserve < __min_cap)
1736 {
1737 __set_short_size(__sz);
1738 __p = __get_short_pointer();
1739 }
1740 else
1741 {
1742 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001743 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001744 __set_long_pointer(__p);
1745 __set_long_cap(__cap+1);
1746 __set_long_size(__sz);
1747 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001748 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001749 traits_type::assign(__p[__sz], value_type());
1750}
1751
1752template <class _CharT, class _Traits, class _Allocator>
1753void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001754basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001755{
1756 if (__sz > max_size())
1757 this->__throw_length_error();
1758 pointer __p;
1759 if (__sz < __min_cap)
1760 {
1761 __set_short_size(__sz);
1762 __p = __get_short_pointer();
1763 }
1764 else
1765 {
1766 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001767 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001768 __set_long_pointer(__p);
1769 __set_long_cap(__cap+1);
1770 __set_long_size(__sz);
1771 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001772 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001773 traits_type::assign(__p[__sz], value_type());
1774}
1775
1776template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001777template <class>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001778basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001779{
Howard Hinnant499cea12013-08-23 17:37:05 +00001780 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001781 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001782#if _LIBCPP_DEBUG_LEVEL >= 2
1783 __get_db()->__insert_c(this);
1784#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001785}
1786
1787template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001788template <class>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001789basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001790 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001791{
Howard Hinnant499cea12013-08-23 17:37:05 +00001792 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001793 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001794#if _LIBCPP_DEBUG_LEVEL >= 2
1795 __get_db()->__insert_c(this);
1796#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001797}
1798
1799template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001800inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001801basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001802{
Howard Hinnant499cea12013-08-23 17:37:05 +00001803 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001804 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001805#if _LIBCPP_DEBUG_LEVEL >= 2
1806 __get_db()->__insert_c(this);
1807#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001808}
1809
1810template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001811inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001812basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001813 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001814{
Howard Hinnant499cea12013-08-23 17:37:05 +00001815 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001816 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001817#if _LIBCPP_DEBUG_LEVEL >= 2
1818 __get_db()->__insert_c(this);
1819#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001820}
1821
1822template <class _CharT, class _Traits, class _Allocator>
1823basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001824 : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001825{
1826 if (!__str.__is_long())
1827 __r_.first().__r = __str.__r_.first().__r;
1828 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001829 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001830#if _LIBCPP_DEBUG_LEVEL >= 2
1831 __get_db()->__insert_c(this);
1832#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001833}
1834
1835template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001836basic_string<_CharT, _Traits, _Allocator>::basic_string(
1837 const basic_string& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001838 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001839{
1840 if (!__str.__is_long())
1841 __r_.first().__r = __str.__r_.first().__r;
1842 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001843 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001844#if _LIBCPP_DEBUG_LEVEL >= 2
1845 __get_db()->__insert_c(this);
1846#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001847}
1848
Eric Fiselier3e928972017-04-19 00:28:44 +00001849#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001850
1851template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001852inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001853basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001854#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001855 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00001856#else
1857 _NOEXCEPT
1858#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001859 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001860{
1861 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00001862#if _LIBCPP_DEBUG_LEVEL >= 2
1863 __get_db()->__insert_c(this);
1864 if (__is_long())
1865 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001866#endif
1867}
1868
1869template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001870inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001871basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001872 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001873{
Marshall Clowd5549cc2014-07-17 15:32:20 +00001874 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001875 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00001876 else
1877 {
1878 __r_.first().__r = __str.__r_.first().__r;
1879 __str.__zero();
1880 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001881#if _LIBCPP_DEBUG_LEVEL >= 2
1882 __get_db()->__insert_c(this);
1883 if (__is_long())
1884 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001885#endif
1886}
1887
Eric Fiselier3e928972017-04-19 00:28:44 +00001888#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001889
1890template <class _CharT, class _Traits, class _Allocator>
1891void
1892basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1893{
1894 if (__n > max_size())
1895 this->__throw_length_error();
1896 pointer __p;
1897 if (__n < __min_cap)
1898 {
1899 __set_short_size(__n);
1900 __p = __get_short_pointer();
1901 }
1902 else
1903 {
1904 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001905 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001906 __set_long_pointer(__p);
1907 __set_long_cap(__cap+1);
1908 __set_long_size(__n);
1909 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001910 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001911 traits_type::assign(__p[__n], value_type());
1912}
1913
1914template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001915inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001916basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001917{
1918 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001919#if _LIBCPP_DEBUG_LEVEL >= 2
1920 __get_db()->__insert_c(this);
1921#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001922}
1923
1924template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001925template <class>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001926basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001927 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001928{
1929 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001930#if _LIBCPP_DEBUG_LEVEL >= 2
1931 __get_db()->__insert_c(this);
1932#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001933}
1934
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001936basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1937 size_type __pos, size_type __n,
1938 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001939 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001940{
1941 size_type __str_sz = __str.size();
1942 if (__pos > __str_sz)
1943 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001944 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00001945#if _LIBCPP_DEBUG_LEVEL >= 2
1946 __get_db()->__insert_c(this);
1947#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001948}
1949
1950template <class _CharT, class _Traits, class _Allocator>
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001951inline _LIBCPP_INLINE_VISIBILITY
1952basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001953 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001954 : __r_(__second_tag(), __a)
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001955{
1956 size_type __str_sz = __str.size();
1957 if (__pos > __str_sz)
1958 this->__throw_out_of_range();
1959 __init(__str.data() + __pos, __str_sz - __pos);
1960#if _LIBCPP_DEBUG_LEVEL >= 2
1961 __get_db()->__insert_c(this);
1962#endif
1963}
1964
1965template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001966template <class _Tp, class>
Marshall Clowdb7fa112016-11-14 18:22:19 +00001967basic_string<_CharT, _Traits, _Allocator>::basic_string(
Marshall Clow64c10d02018-07-02 18:41:15 +00001968 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001969 : __r_(__second_tag(), __a)
Marshall Clowdb7fa112016-11-14 18:22:19 +00001970{
Marshall Clow64c10d02018-07-02 18:41:15 +00001971 __self_view __sv0 = __t;
1972 __self_view __sv = __sv0.substr(__pos, __n);
Marshall Clowdb7fa112016-11-14 18:22:19 +00001973 __init(__sv.data(), __sv.size());
1974#if _LIBCPP_DEBUG_LEVEL >= 2
1975 __get_db()->__insert_c(this);
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001976#endif
Marshall Clowdb7fa112016-11-14 18:22:19 +00001977}
1978
1979template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001980template <class _Tp, class>
1981basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001982{
Marshall Clow64c10d02018-07-02 18:41:15 +00001983 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001984 __init(__sv.data(), __sv.size());
1985#if _LIBCPP_DEBUG_LEVEL >= 2
1986 __get_db()->__insert_c(this);
1987#endif
1988}
1989
1990template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001991template <class _Tp, class>
1992basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001993 : __r_(__second_tag(), __a)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001994{
Marshall Clow64c10d02018-07-02 18:41:15 +00001995 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001996 __init(__sv.data(), __sv.size());
1997#if _LIBCPP_DEBUG_LEVEL >= 2
1998 __get_db()->__insert_c(this);
1999#endif
2000}
2001
2002template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002003template <class _InputIterator>
2004typename enable_if
2005<
Marshall Clowdf9db312016-01-13 21:54:34 +00002006 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002007 void
2008>::type
2009basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2010{
2011 __zero();
2012#ifndef _LIBCPP_NO_EXCEPTIONS
2013 try
2014 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002015#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002016 for (; __first != __last; ++__first)
2017 push_back(*__first);
2018#ifndef _LIBCPP_NO_EXCEPTIONS
2019 }
2020 catch (...)
2021 {
2022 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002023 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002024 throw;
2025 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002026#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002027}
2028
2029template <class _CharT, class _Traits, class _Allocator>
2030template <class _ForwardIterator>
2031typename enable_if
2032<
2033 __is_forward_iterator<_ForwardIterator>::value,
2034 void
2035>::type
2036basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2037{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002038 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002039 if (__sz > max_size())
2040 this->__throw_length_error();
2041 pointer __p;
2042 if (__sz < __min_cap)
2043 {
2044 __set_short_size(__sz);
2045 __p = __get_short_pointer();
2046 }
2047 else
2048 {
2049 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002050 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002051 __set_long_pointer(__p);
2052 __set_long_cap(__cap+1);
2053 __set_long_size(__sz);
2054 }
Eric Fiselierb9919752014-10-27 19:28:20 +00002055 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002056 traits_type::assign(*__p, *__first);
2057 traits_type::assign(*__p, value_type());
2058}
2059
2060template <class _CharT, class _Traits, class _Allocator>
2061template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002062inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002063basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2064{
2065 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002066#if _LIBCPP_DEBUG_LEVEL >= 2
2067 __get_db()->__insert_c(this);
2068#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002069}
2070
2071template <class _CharT, class _Traits, class _Allocator>
2072template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002073inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002074basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2075 const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002076 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002077{
2078 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002079#if _LIBCPP_DEBUG_LEVEL >= 2
2080 __get_db()->__insert_c(this);
2081#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002082}
2083
Eric Fiselier3e928972017-04-19 00:28:44 +00002084#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00002085
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002086template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002087inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00002088basic_string<_CharT, _Traits, _Allocator>::basic_string(
2089 initializer_list<_CharT> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002090{
2091 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002092#if _LIBCPP_DEBUG_LEVEL >= 2
2093 __get_db()->__insert_c(this);
2094#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095}
2096
2097template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002098inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002099
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00002100basic_string<_CharT, _Traits, _Allocator>::basic_string(
2101 initializer_list<_CharT> __il, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002102 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002103{
2104 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002105#if _LIBCPP_DEBUG_LEVEL >= 2
2106 __get_db()->__insert_c(this);
2107#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002108}
2109
Eric Fiselier3e928972017-04-19 00:28:44 +00002110#endif // _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00002111
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002112template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002113basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2114{
Howard Hinnant499cea12013-08-23 17:37:05 +00002115#if _LIBCPP_DEBUG_LEVEL >= 2
2116 __get_db()->__erase_c(this);
2117#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002118 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002119 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002120}
2121
2122template <class _CharT, class _Traits, class _Allocator>
2123void
2124basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2125 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002126 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 +00002127{
2128 size_type __ms = max_size();
2129 if (__delta_cap > __ms - __old_cap - 1)
2130 this->__throw_length_error();
2131 pointer __old_p = __get_pointer();
2132 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002133 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002134 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002135 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002136 __invalidate_all_iterators();
2137 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002138 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2139 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002140 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002141 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002142 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2143 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002144 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2145 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002146 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002147 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002148 __set_long_pointer(__p);
2149 __set_long_cap(__cap+1);
2150 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2151 __set_long_size(__old_sz);
2152 traits_type::assign(__p[__old_sz], value_type());
2153}
2154
2155template <class _CharT, class _Traits, class _Allocator>
2156void
2157basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2158 size_type __n_copy, size_type __n_del, size_type __n_add)
2159{
2160 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00002161 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002162 this->__throw_length_error();
2163 pointer __old_p = __get_pointer();
2164 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002165 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002166 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002167 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002168 __invalidate_all_iterators();
2169 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002170 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2171 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002172 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2173 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002174 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2175 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2176 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002177 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002178 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002179 __set_long_pointer(__p);
2180 __set_long_cap(__cap+1);
2181}
2182
2183// assign
2184
2185template <class _CharT, class _Traits, class _Allocator>
2186basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002187basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002188{
Alp Tokerec34c482014-05-15 11:27:39 +00002189 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002190 size_type __cap = capacity();
2191 if (__cap >= __n)
2192 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002193 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002194 traits_type::move(__p, __s, __n);
2195 traits_type::assign(__p[__n], value_type());
2196 __set_size(__n);
2197 __invalidate_iterators_past(__n);
2198 }
2199 else
2200 {
2201 size_type __sz = size();
2202 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2203 }
2204 return *this;
2205}
2206
2207template <class _CharT, class _Traits, class _Allocator>
2208basic_string<_CharT, _Traits, _Allocator>&
2209basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2210{
2211 size_type __cap = capacity();
2212 if (__cap < __n)
2213 {
2214 size_type __sz = size();
2215 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2216 }
2217 else
2218 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002219 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002220 traits_type::assign(__p, __n, __c);
2221 traits_type::assign(__p[__n], value_type());
2222 __set_size(__n);
2223 return *this;
2224}
2225
2226template <class _CharT, class _Traits, class _Allocator>
2227basic_string<_CharT, _Traits, _Allocator>&
2228basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2229{
2230 pointer __p;
2231 if (__is_long())
2232 {
2233 __p = __get_long_pointer();
2234 __set_long_size(1);
2235 }
2236 else
2237 {
2238 __p = __get_short_pointer();
2239 __set_short_size(1);
2240 }
2241 traits_type::assign(*__p, __c);
2242 traits_type::assign(*++__p, value_type());
2243 __invalidate_iterators_past(1);
2244 return *this;
2245}
2246
2247template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002248basic_string<_CharT, _Traits, _Allocator>&
2249basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2250{
2251 if (this != &__str)
2252 {
2253 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00002254 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00002255 }
2256 return *this;
2257}
2258
Eric Fiselier3e928972017-04-19 00:28:44 +00002259#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante32b5e22010-11-17 17:55:08 +00002260
2261template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002262inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002263void
2264basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002265 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002266{
2267 if (__alloc() != __str.__alloc())
2268 assign(__str);
2269 else
2270 __move_assign(__str, true_type());
2271}
2272
2273template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002274inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002275void
2276basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002277#if _LIBCPP_STD_VER > 14
2278 _NOEXCEPT
2279#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002280 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002281#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002282{
Vedant Kumar2b588cb2018-03-08 21:15:26 +00002283 __clear_and_shrink();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002284 __r_.first() = __str.__r_.first();
2285 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002286 __str.__zero();
2287}
2288
2289template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002290inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002291basic_string<_CharT, _Traits, _Allocator>&
2292basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002293 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002294{
2295 __move_assign(__str, integral_constant<bool,
2296 __alloc_traits::propagate_on_container_move_assignment::value>());
2297 return *this;
2298}
2299
2300#endif
2301
2302template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002303template<class _InputIterator>
2304typename enable_if
2305<
Marshall Clowdf9db312016-01-13 21:54:34 +00002306 __is_exactly_input_iterator <_InputIterator>::value
2307 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002308 basic_string<_CharT, _Traits, _Allocator>&
2309>::type
2310basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2311{
Marshall Clowd979eed2016-09-05 01:54:30 +00002312 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002313 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002314 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002315}
2316
2317template <class _CharT, class _Traits, class _Allocator>
2318template<class _ForwardIterator>
2319typename enable_if
2320<
Marshall Clowdf9db312016-01-13 21:54:34 +00002321 __is_forward_iterator<_ForwardIterator>::value
2322 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002323 basic_string<_CharT, _Traits, _Allocator>&
2324>::type
2325basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2326{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002327 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002328 size_type __cap = capacity();
2329 if (__cap < __n)
2330 {
2331 size_type __sz = size();
2332 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2333 }
2334 else
2335 __invalidate_iterators_past(__n);
2336 pointer __p = __get_pointer();
2337 for (; __first != __last; ++__first, ++__p)
2338 traits_type::assign(*__p, *__first);
2339 traits_type::assign(*__p, value_type());
2340 __set_size(__n);
2341 return *this;
2342}
2343
2344template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002345basic_string<_CharT, _Traits, _Allocator>&
2346basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2347{
2348 size_type __sz = __str.size();
2349 if (__pos > __sz)
2350 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002351 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002352}
2353
2354template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002355template <class _Tp>
2356typename enable_if
2357<
2358 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002359 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002360>::type
2361basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002362{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002363 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002364 size_type __sz = __sv.size();
2365 if (__pos > __sz)
2366 this->__throw_out_of_range();
2367 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2368}
2369
2370
2371template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002372basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002373basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002374{
Alp Tokerec34c482014-05-15 11:27:39 +00002375 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002376 return assign(__s, traits_type::length(__s));
2377}
2378
2379// append
2380
2381template <class _CharT, class _Traits, class _Allocator>
2382basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002383basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002384{
Alp Tokerec34c482014-05-15 11:27:39 +00002385 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002386 size_type __cap = capacity();
2387 size_type __sz = size();
2388 if (__cap - __sz >= __n)
2389 {
2390 if (__n)
2391 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002392 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002393 traits_type::copy(__p + __sz, __s, __n);
2394 __sz += __n;
2395 __set_size(__sz);
2396 traits_type::assign(__p[__sz], value_type());
2397 }
2398 }
2399 else
2400 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2401 return *this;
2402}
2403
2404template <class _CharT, class _Traits, class _Allocator>
2405basic_string<_CharT, _Traits, _Allocator>&
2406basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2407{
2408 if (__n)
2409 {
2410 size_type __cap = capacity();
2411 size_type __sz = size();
2412 if (__cap - __sz < __n)
2413 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2414 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002415 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002416 __sz += __n;
2417 __set_size(__sz);
2418 traits_type::assign(__p[__sz], value_type());
2419 }
2420 return *this;
2421}
2422
2423template <class _CharT, class _Traits, class _Allocator>
2424void
2425basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2426{
Howard Hinnant15467182013-04-30 21:44:48 +00002427 bool __is_short = !__is_long();
2428 size_type __cap;
2429 size_type __sz;
2430 if (__is_short)
2431 {
2432 __cap = __min_cap - 1;
2433 __sz = __get_short_size();
2434 }
2435 else
2436 {
2437 __cap = __get_long_cap() - 1;
2438 __sz = __get_long_size();
2439 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002440 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002441 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002442 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002443 __is_short = !__is_long();
2444 }
2445 pointer __p;
2446 if (__is_short)
2447 {
2448 __p = __get_short_pointer() + __sz;
2449 __set_short_size(__sz+1);
2450 }
2451 else
2452 {
2453 __p = __get_long_pointer() + __sz;
2454 __set_long_size(__sz+1);
2455 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002456 traits_type::assign(*__p, __c);
2457 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002458}
2459
Marshall Clowac655ef2016-09-07 03:32:06 +00002460template <class _Tp>
Marshall Clowd979eed2016-09-05 01:54:30 +00002461bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2462{
2463 return __first <= __p && __p < __last;
2464}
2465
Marshall Clowac655ef2016-09-07 03:32:06 +00002466template <class _Tp1, class _Tp2>
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00002467bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
Marshall Clowac655ef2016-09-07 03:32:06 +00002468{
2469 return false;
2470}
2471
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002472template <class _CharT, class _Traits, class _Allocator>
2473template<class _ForwardIterator>
Eric Fiselier026d38e2016-10-31 02:46:25 +00002474basic_string<_CharT, _Traits, _Allocator>&
2475basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2476 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002477{
Eric Fiselier026d38e2016-10-31 02:46:25 +00002478 static_assert(__is_forward_iterator<_ForwardIterator>::value,
2479 "function requires a ForwardIterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002480 size_type __sz = size();
2481 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002482 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002483 if (__n)
2484 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002485 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2486 _CharRef __tmp_ref = *__first;
2487 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002488 {
2489 const basic_string __temp (__first, __last, __alloc());
2490 append(__temp.data(), __temp.size());
2491 }
2492 else
2493 {
2494 if (__cap - __sz < __n)
2495 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2496 pointer __p = __get_pointer() + __sz;
2497 for (; __first != __last; ++__p, ++__first)
2498 traits_type::assign(*__p, *__first);
2499 traits_type::assign(*__p, value_type());
2500 __set_size(__sz + __n);
2501 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002502 }
2503 return *this;
2504}
2505
2506template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002507inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002508basic_string<_CharT, _Traits, _Allocator>&
2509basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2510{
2511 return append(__str.data(), __str.size());
2512}
2513
2514template <class _CharT, class _Traits, class _Allocator>
2515basic_string<_CharT, _Traits, _Allocator>&
2516basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2517{
2518 size_type __sz = __str.size();
2519 if (__pos > __sz)
2520 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002521 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002522}
2523
2524template <class _CharT, class _Traits, class _Allocator>
Marshall Clow42a87db2016-10-03 23:40:48 +00002525template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002526 typename enable_if
2527 <
2528 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2529 basic_string<_CharT, _Traits, _Allocator>&
2530 >::type
2531basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002532{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002533 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002534 size_type __sz = __sv.size();
2535 if (__pos > __sz)
2536 this->__throw_out_of_range();
2537 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2538}
2539
2540template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002541basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002542basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002543{
Alp Tokerec34c482014-05-15 11:27:39 +00002544 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002545 return append(__s, traits_type::length(__s));
2546}
2547
2548// insert
2549
2550template <class _CharT, class _Traits, class _Allocator>
2551basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002552basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002553{
Alp Tokerec34c482014-05-15 11:27:39 +00002554 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002555 size_type __sz = size();
2556 if (__pos > __sz)
2557 this->__throw_out_of_range();
2558 size_type __cap = capacity();
2559 if (__cap - __sz >= __n)
2560 {
2561 if (__n)
2562 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002563 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002564 size_type __n_move = __sz - __pos;
2565 if (__n_move != 0)
2566 {
2567 if (__p + __pos <= __s && __s < __p + __sz)
2568 __s += __n;
2569 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2570 }
2571 traits_type::move(__p + __pos, __s, __n);
2572 __sz += __n;
2573 __set_size(__sz);
2574 traits_type::assign(__p[__sz], value_type());
2575 }
2576 }
2577 else
2578 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2579 return *this;
2580}
2581
2582template <class _CharT, class _Traits, class _Allocator>
2583basic_string<_CharT, _Traits, _Allocator>&
2584basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2585{
2586 size_type __sz = size();
2587 if (__pos > __sz)
2588 this->__throw_out_of_range();
2589 if (__n)
2590 {
2591 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002592 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002593 if (__cap - __sz >= __n)
2594 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002595 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002596 size_type __n_move = __sz - __pos;
2597 if (__n_move != 0)
2598 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2599 }
2600 else
2601 {
2602 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002603 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002604 }
2605 traits_type::assign(__p + __pos, __n, __c);
2606 __sz += __n;
2607 __set_size(__sz);
2608 traits_type::assign(__p[__sz], value_type());
2609 }
2610 return *this;
2611}
2612
2613template <class _CharT, class _Traits, class _Allocator>
2614template<class _InputIterator>
2615typename enable_if
2616<
Marshall Clowdf9db312016-01-13 21:54:34 +00002617 __is_exactly_input_iterator<_InputIterator>::value
2618 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2619 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002620>::type
2621basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2622{
Howard Hinnant499cea12013-08-23 17:37:05 +00002623#if _LIBCPP_DEBUG_LEVEL >= 2
2624 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2625 "string::insert(iterator, range) called with an iterator not"
2626 " referring to this string");
2627#endif
Marshall Clowd979eed2016-09-05 01:54:30 +00002628 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002629 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002630}
2631
2632template <class _CharT, class _Traits, class _Allocator>
2633template<class _ForwardIterator>
2634typename enable_if
2635<
Marshall Clowdf9db312016-01-13 21:54:34 +00002636 __is_forward_iterator<_ForwardIterator>::value
2637 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002638 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2639>::type
2640basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2641{
Howard Hinnant499cea12013-08-23 17:37:05 +00002642#if _LIBCPP_DEBUG_LEVEL >= 2
2643 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2644 "string::insert(iterator, range) called with an iterator not"
2645 " referring to this string");
2646#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002647 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002648 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002649 if (__n)
2650 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002651 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2652 _CharRef __tmp_char = *__first;
2653 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002654 {
2655 const basic_string __temp(__first, __last, __alloc());
2656 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2657 }
2658
2659 size_type __sz = size();
2660 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002661 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002662 if (__cap - __sz >= __n)
2663 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002664 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002665 size_type __n_move = __sz - __ip;
2666 if (__n_move != 0)
2667 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2668 }
2669 else
2670 {
2671 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002672 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002673 }
2674 __sz += __n;
2675 __set_size(__sz);
2676 traits_type::assign(__p[__sz], value_type());
2677 for (__p += __ip; __first != __last; ++__p, ++__first)
2678 traits_type::assign(*__p, *__first);
2679 }
2680 return begin() + __ip;
2681}
2682
2683template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002684inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002685basic_string<_CharT, _Traits, _Allocator>&
2686basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2687{
2688 return insert(__pos1, __str.data(), __str.size());
2689}
2690
2691template <class _CharT, class _Traits, class _Allocator>
2692basic_string<_CharT, _Traits, _Allocator>&
2693basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2694 size_type __pos2, size_type __n)
2695{
2696 size_type __str_sz = __str.size();
2697 if (__pos2 > __str_sz)
2698 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002699 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002700}
2701
2702template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002703template <class _Tp>
2704typename enable_if
2705<
2706 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002707 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002708>::type
2709basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002710 size_type __pos2, size_type __n)
2711{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002712 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002713 size_type __str_sz = __sv.size();
2714 if (__pos2 > __str_sz)
2715 this->__throw_out_of_range();
2716 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2717}
2718
2719template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002720basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002721basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002722{
Alp Tokerec34c482014-05-15 11:27:39 +00002723 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002724 return insert(__pos, __s, traits_type::length(__s));
2725}
2726
2727template <class _CharT, class _Traits, class _Allocator>
2728typename basic_string<_CharT, _Traits, _Allocator>::iterator
2729basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2730{
2731 size_type __ip = static_cast<size_type>(__pos - begin());
2732 size_type __sz = size();
2733 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002734 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002735 if (__cap == __sz)
2736 {
2737 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002738 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002739 }
2740 else
2741 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002742 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002743 size_type __n_move = __sz - __ip;
2744 if (__n_move != 0)
2745 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2746 }
2747 traits_type::assign(__p[__ip], __c);
2748 traits_type::assign(__p[++__sz], value_type());
2749 __set_size(__sz);
2750 return begin() + static_cast<difference_type>(__ip);
2751}
2752
2753template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002754inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002755typename basic_string<_CharT, _Traits, _Allocator>::iterator
2756basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2757{
Howard Hinnant499cea12013-08-23 17:37:05 +00002758#if _LIBCPP_DEBUG_LEVEL >= 2
2759 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2760 "string::insert(iterator, n, value) called with an iterator not"
2761 " referring to this string");
2762#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002763 difference_type __p = __pos - begin();
2764 insert(static_cast<size_type>(__p), __n, __c);
2765 return begin() + __p;
2766}
2767
2768// replace
2769
2770template <class _CharT, class _Traits, class _Allocator>
2771basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002772basic_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 +00002773 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002774{
Alp Tokerec34c482014-05-15 11:27:39 +00002775 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002776 size_type __sz = size();
2777 if (__pos > __sz)
2778 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002779 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002780 size_type __cap = capacity();
2781 if (__cap - __sz + __n1 >= __n2)
2782 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002783 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002784 if (__n1 != __n2)
2785 {
2786 size_type __n_move = __sz - __pos - __n1;
2787 if (__n_move != 0)
2788 {
2789 if (__n1 > __n2)
2790 {
2791 traits_type::move(__p + __pos, __s, __n2);
2792 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2793 goto __finish;
2794 }
2795 if (__p + __pos < __s && __s < __p + __sz)
2796 {
2797 if (__p + __pos + __n1 <= __s)
2798 __s += __n2 - __n1;
2799 else // __p + __pos < __s < __p + __pos + __n1
2800 {
2801 traits_type::move(__p + __pos, __s, __n1);
2802 __pos += __n1;
2803 __s += __n2;
2804 __n2 -= __n1;
2805 __n1 = 0;
2806 }
2807 }
2808 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2809 }
2810 }
2811 traits_type::move(__p + __pos, __s, __n2);
2812__finish:
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002813// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
2814// but this is a safe operation, so we disable the check.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002815 __sz += __n2 - __n1;
2816 __set_size(__sz);
2817 __invalidate_iterators_past(__sz);
2818 traits_type::assign(__p[__sz], value_type());
2819 }
2820 else
2821 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2822 return *this;
2823}
2824
2825template <class _CharT, class _Traits, class _Allocator>
2826basic_string<_CharT, _Traits, _Allocator>&
2827basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002828 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002829{
2830 size_type __sz = size();
2831 if (__pos > __sz)
2832 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002833 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002834 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002835 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002836 if (__cap - __sz + __n1 >= __n2)
2837 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002838 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002839 if (__n1 != __n2)
2840 {
2841 size_type __n_move = __sz - __pos - __n1;
2842 if (__n_move != 0)
2843 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2844 }
2845 }
2846 else
2847 {
2848 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002849 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002850 }
2851 traits_type::assign(__p + __pos, __n2, __c);
2852 __sz += __n2 - __n1;
2853 __set_size(__sz);
2854 __invalidate_iterators_past(__sz);
2855 traits_type::assign(__p[__sz], value_type());
2856 return *this;
2857}
2858
2859template <class _CharT, class _Traits, class _Allocator>
2860template<class _InputIterator>
2861typename enable_if
2862<
2863 __is_input_iterator<_InputIterator>::value,
2864 basic_string<_CharT, _Traits, _Allocator>&
2865>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002866basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002867 _InputIterator __j1, _InputIterator __j2)
2868{
Marshall Clowd979eed2016-09-05 01:54:30 +00002869 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002870 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002871}
2872
2873template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002874inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002875basic_string<_CharT, _Traits, _Allocator>&
2876basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2877{
2878 return replace(__pos1, __n1, __str.data(), __str.size());
2879}
2880
2881template <class _CharT, class _Traits, class _Allocator>
2882basic_string<_CharT, _Traits, _Allocator>&
2883basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2884 size_type __pos2, size_type __n2)
2885{
2886 size_type __str_sz = __str.size();
2887 if (__pos2 > __str_sz)
2888 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002889 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002890}
2891
2892template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002893template <class _Tp>
2894typename enable_if
2895<
Marshall Clowf1729d92017-11-15 20:02:27 +00002896 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2897 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002898>::type
2899basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002900 size_type __pos2, size_type __n2)
2901{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002902 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002903 size_type __str_sz = __sv.size();
2904 if (__pos2 > __str_sz)
2905 this->__throw_out_of_range();
2906 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2907}
2908
2909template <class _CharT, class _Traits, class _Allocator>
2910basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002911basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002912{
Alp Tokerec34c482014-05-15 11:27:39 +00002913 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002914 return replace(__pos, __n1, __s, traits_type::length(__s));
2915}
2916
2917template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002918inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002919basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002920basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002921{
2922 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2923 __str.data(), __str.size());
2924}
2925
2926template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002927inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002928basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002929basic_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 +00002930{
2931 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2932}
2933
2934template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002935inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002936basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002937basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002938{
2939 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2940}
2941
2942template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002943inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002944basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002945basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002946{
2947 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2948}
2949
2950// erase
2951
2952template <class _CharT, class _Traits, class _Allocator>
2953basic_string<_CharT, _Traits, _Allocator>&
2954basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2955{
2956 size_type __sz = size();
2957 if (__pos > __sz)
2958 this->__throw_out_of_range();
2959 if (__n)
2960 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002961 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002962 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002963 size_type __n_move = __sz - __pos - __n;
2964 if (__n_move != 0)
2965 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2966 __sz -= __n;
2967 __set_size(__sz);
2968 __invalidate_iterators_past(__sz);
2969 traits_type::assign(__p[__sz], value_type());
2970 }
2971 return *this;
2972}
2973
2974template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002975inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002976typename basic_string<_CharT, _Traits, _Allocator>::iterator
2977basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2978{
Howard Hinnant499cea12013-08-23 17:37:05 +00002979#if _LIBCPP_DEBUG_LEVEL >= 2
2980 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2981 "string::erase(iterator) called with an iterator not"
2982 " referring to this string");
2983#endif
2984 _LIBCPP_ASSERT(__pos != end(),
2985 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002986 iterator __b = begin();
2987 size_type __r = static_cast<size_type>(__pos - __b);
2988 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002989 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002990}
2991
2992template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002993inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002994typename basic_string<_CharT, _Traits, _Allocator>::iterator
2995basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2996{
Howard Hinnant499cea12013-08-23 17:37:05 +00002997#if _LIBCPP_DEBUG_LEVEL >= 2
2998 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2999 "string::erase(iterator, iterator) called with an iterator not"
3000 " referring to this string");
3001#endif
3002 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003003 iterator __b = begin();
3004 size_type __r = static_cast<size_type>(__first - __b);
3005 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00003006 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003007}
3008
3009template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003010inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003011void
3012basic_string<_CharT, _Traits, _Allocator>::pop_back()
3013{
Howard Hinnant499cea12013-08-23 17:37:05 +00003014 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003015 size_type __sz;
3016 if (__is_long())
3017 {
3018 __sz = __get_long_size() - 1;
3019 __set_long_size(__sz);
3020 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3021 }
3022 else
3023 {
3024 __sz = __get_short_size() - 1;
3025 __set_short_size(__sz);
3026 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3027 }
3028 __invalidate_iterators_past(__sz);
3029}
3030
3031template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003032inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003033void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003034basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003035{
3036 __invalidate_all_iterators();
3037 if (__is_long())
3038 {
3039 traits_type::assign(*__get_long_pointer(), value_type());
3040 __set_long_size(0);
3041 }
3042 else
3043 {
3044 traits_type::assign(*__get_short_pointer(), value_type());
3045 __set_short_size(0);
3046 }
3047}
3048
3049template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003050inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003051void
3052basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3053{
3054 if (__is_long())
3055 {
3056 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3057 __set_long_size(__pos);
3058 }
3059 else
3060 {
3061 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3062 __set_short_size(__pos);
3063 }
3064 __invalidate_iterators_past(__pos);
3065}
3066
3067template <class _CharT, class _Traits, class _Allocator>
3068void
3069basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3070{
3071 size_type __sz = size();
3072 if (__n > __sz)
3073 append(__n - __sz, __c);
3074 else
3075 __erase_to_end(__n);
3076}
3077
3078template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003079inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003080typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003081basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003082{
Howard Hinnante32b5e22010-11-17 17:55:08 +00003083 size_type __m = __alloc_traits::max_size(__alloc());
Eric Fiselier5ccf0432017-10-17 13:16:01 +00003084#ifdef _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00003085 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003086#else
Marshall Clow09f85502013-10-31 17:23:08 +00003087 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003088#endif
3089}
3090
3091template <class _CharT, class _Traits, class _Allocator>
3092void
3093basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3094{
3095 if (__res_arg > max_size())
3096 this->__throw_length_error();
3097 size_type __cap = capacity();
3098 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003099 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003100 __res_arg = __recommend(__res_arg);
3101 if (__res_arg != __cap)
3102 {
3103 pointer __new_data, __p;
3104 bool __was_long, __now_long;
3105 if (__res_arg == __min_cap - 1)
3106 {
3107 __was_long = true;
3108 __now_long = false;
3109 __new_data = __get_short_pointer();
3110 __p = __get_long_pointer();
3111 }
3112 else
3113 {
3114 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003115 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003116 else
3117 {
3118 #ifndef _LIBCPP_NO_EXCEPTIONS
3119 try
3120 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003121 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00003122 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003123 #ifndef _LIBCPP_NO_EXCEPTIONS
3124 }
3125 catch (...)
3126 {
3127 return;
3128 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003129 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003130 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003131 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003132 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003133 }
3134 __now_long = true;
3135 __was_long = __is_long();
3136 __p = __get_pointer();
3137 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003138 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3139 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003140 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003141 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003142 if (__now_long)
3143 {
3144 __set_long_cap(__res_arg+1);
3145 __set_long_size(__sz);
3146 __set_long_pointer(__new_data);
3147 }
3148 else
3149 __set_short_size(__sz);
3150 __invalidate_all_iterators();
3151 }
3152}
3153
3154template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003155inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003156typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003157basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003158{
Howard Hinnant499cea12013-08-23 17:37:05 +00003159 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003160 return *(data() + __pos);
3161}
3162
3163template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003164inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003165typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003166basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003167{
Howard Hinnant499cea12013-08-23 17:37:05 +00003168 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003169 return *(__get_pointer() + __pos);
3170}
3171
3172template <class _CharT, class _Traits, class _Allocator>
3173typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3174basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3175{
3176 if (__n >= size())
3177 this->__throw_out_of_range();
3178 return (*this)[__n];
3179}
3180
3181template <class _CharT, class _Traits, class _Allocator>
3182typename basic_string<_CharT, _Traits, _Allocator>::reference
3183basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3184{
3185 if (__n >= size())
3186 this->__throw_out_of_range();
3187 return (*this)[__n];
3188}
3189
3190template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003191inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003192typename basic_string<_CharT, _Traits, _Allocator>::reference
3193basic_string<_CharT, _Traits, _Allocator>::front()
3194{
Howard Hinnant499cea12013-08-23 17:37:05 +00003195 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003196 return *__get_pointer();
3197}
3198
3199template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003200inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003201typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3202basic_string<_CharT, _Traits, _Allocator>::front() const
3203{
Howard Hinnant499cea12013-08-23 17:37:05 +00003204 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003205 return *data();
3206}
3207
3208template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003209inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003210typename basic_string<_CharT, _Traits, _Allocator>::reference
3211basic_string<_CharT, _Traits, _Allocator>::back()
3212{
Howard Hinnant499cea12013-08-23 17:37:05 +00003213 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003214 return *(__get_pointer() + size() - 1);
3215}
3216
3217template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003218inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003219typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3220basic_string<_CharT, _Traits, _Allocator>::back() const
3221{
Howard Hinnant499cea12013-08-23 17:37:05 +00003222 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003223 return *(data() + size() - 1);
3224}
3225
3226template <class _CharT, class _Traits, class _Allocator>
3227typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003228basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003229{
3230 size_type __sz = size();
3231 if (__pos > __sz)
3232 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003233 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003234 traits_type::copy(__s, data() + __pos, __rlen);
3235 return __rlen;
3236}
3237
3238template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003239inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003240basic_string<_CharT, _Traits, _Allocator>
3241basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3242{
3243 return basic_string(*this, __pos, __n, __alloc());
3244}
3245
3246template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003247inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003248void
3249basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00003250#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00003251 _NOEXCEPT_DEBUG
Marshall Clow7d914d12015-07-13 20:04:56 +00003252#else
Eric Fiselier47257c42016-12-28 05:53:01 +00003253 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00003254 __is_nothrow_swappable<allocator_type>::value)
3255#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003256{
Howard Hinnant499cea12013-08-23 17:37:05 +00003257#if _LIBCPP_DEBUG_LEVEL >= 2
3258 if (!__is_long())
3259 __get_db()->__invalidate_all(this);
3260 if (!__str.__is_long())
3261 __get_db()->__invalidate_all(&__str);
3262 __get_db()->swap(this, &__str);
3263#endif
Eric Fiselier47257c42016-12-28 05:53:01 +00003264 _LIBCPP_ASSERT(
3265 __alloc_traits::propagate_on_container_swap::value ||
3266 __alloc_traits::is_always_equal::value ||
3267 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnant0949eed2011-06-30 21:18:19 +00003268 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00003269 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003270}
3271
3272// find
3273
3274template <class _Traits>
3275struct _LIBCPP_HIDDEN __traits_eq
3276{
3277 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003278 _LIBCPP_INLINE_VISIBILITY
3279 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3280 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003281};
3282
3283template<class _CharT, class _Traits, class _Allocator>
3284typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003285basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003286 size_type __pos,
3287 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003288{
Alp Tokerec34c482014-05-15 11:27:39 +00003289 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003290 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003291 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003292}
3293
3294template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003295inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003296typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003297basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3298 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003299{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003300 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003301 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003302}
3303
3304template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003305template <class _Tp>
3306typename enable_if
3307<
3308 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3309 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3310>::type
3311basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
3312 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003313{
Marshall Clow64c10d02018-07-02 18:41:15 +00003314 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003315 return __str_find<value_type, size_type, traits_type, npos>
3316 (data(), size(), __sv.data(), __pos, __sv.size());
3317}
3318
3319template<class _CharT, class _Traits, class _Allocator>
3320inline _LIBCPP_INLINE_VISIBILITY
3321typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003322basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003323 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003324{
Alp Tokerec34c482014-05-15 11:27:39 +00003325 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003326 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003327 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003328}
3329
3330template<class _CharT, class _Traits, class _Allocator>
3331typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003332basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3333 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003334{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003335 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003336 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003337}
3338
3339// rfind
3340
3341template<class _CharT, class _Traits, class _Allocator>
3342typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003343basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003344 size_type __pos,
3345 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003346{
Alp Tokerec34c482014-05-15 11:27:39 +00003347 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003348 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003349 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003350}
3351
3352template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003353inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003354typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003355basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3356 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003357{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003358 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003359 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003360}
3361
3362template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003363template <class _Tp>
3364typename enable_if
3365<
3366 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3367 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3368>::type
3369basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
3370 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003371{
Marshall Clow64c10d02018-07-02 18:41:15 +00003372 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003373 return __str_rfind<value_type, size_type, traits_type, npos>
3374 (data(), size(), __sv.data(), __pos, __sv.size());
3375}
3376
3377template<class _CharT, class _Traits, class _Allocator>
3378inline _LIBCPP_INLINE_VISIBILITY
3379typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003380basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003381 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003382{
Alp Tokerec34c482014-05-15 11:27:39 +00003383 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003384 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003385 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003386}
3387
3388template<class _CharT, class _Traits, class _Allocator>
3389typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003390basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3391 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003392{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003393 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003394 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003395}
3396
3397// find_first_of
3398
3399template<class _CharT, class _Traits, class _Allocator>
3400typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003401basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003402 size_type __pos,
3403 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003404{
Alp Tokerec34c482014-05-15 11:27:39 +00003405 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003406 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003407 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003408}
3409
3410template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003411inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003412typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003413basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3414 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003415{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003416 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003417 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003418}
3419
3420template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003421template <class _Tp>
3422typename enable_if
3423<
3424 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3425 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3426>::type
3427basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
3428 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003429{
Marshall Clow64c10d02018-07-02 18:41:15 +00003430 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003431 return __str_find_first_of<value_type, size_type, traits_type, npos>
3432 (data(), size(), __sv.data(), __pos, __sv.size());
3433}
3434
3435template<class _CharT, class _Traits, class _Allocator>
3436inline _LIBCPP_INLINE_VISIBILITY
3437typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003438basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003439 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003440{
Alp Tokerec34c482014-05-15 11:27:39 +00003441 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003442 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003443 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003444}
3445
3446template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003447inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003448typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003449basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3450 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003451{
3452 return find(__c, __pos);
3453}
3454
3455// find_last_of
3456
3457template<class _CharT, class _Traits, class _Allocator>
3458typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003459basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003460 size_type __pos,
3461 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003462{
Alp Tokerec34c482014-05-15 11:27:39 +00003463 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003464 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003465 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003466}
3467
3468template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003469inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003470typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003471basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3472 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003473{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003474 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003475 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003476}
3477
3478template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003479template <class _Tp>
3480typename enable_if
3481<
3482 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3483 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3484>::type
3485basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
3486 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003487{
Marshall Clow64c10d02018-07-02 18:41:15 +00003488 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003489 return __str_find_last_of<value_type, size_type, traits_type, npos>
3490 (data(), size(), __sv.data(), __pos, __sv.size());
3491}
3492
3493template<class _CharT, class _Traits, class _Allocator>
3494inline _LIBCPP_INLINE_VISIBILITY
3495typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003496basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003497 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003498{
Alp Tokerec34c482014-05-15 11:27:39 +00003499 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003500 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003501 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003502}
3503
3504template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003505inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003506typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003507basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3508 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003509{
3510 return rfind(__c, __pos);
3511}
3512
3513// find_first_not_of
3514
3515template<class _CharT, class _Traits, class _Allocator>
3516typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003517basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003518 size_type __pos,
3519 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003520{
Alp Tokerec34c482014-05-15 11:27:39 +00003521 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003522 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003523 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003524}
3525
3526template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003527inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003528typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003529basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3530 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003531{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003532 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003533 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003534}
3535
3536template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003537template <class _Tp>
3538typename enable_if
3539<
3540 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3541 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3542>::type
3543basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
3544 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003545{
Marshall Clow64c10d02018-07-02 18:41:15 +00003546 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003547 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3548 (data(), size(), __sv.data(), __pos, __sv.size());
3549}
3550
3551template<class _CharT, class _Traits, class _Allocator>
3552inline _LIBCPP_INLINE_VISIBILITY
3553typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003554basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003555 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003556{
Alp Tokerec34c482014-05-15 11:27:39 +00003557 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003558 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003559 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003560}
3561
3562template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003563inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003564typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003565basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3566 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003567{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003568 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003569 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003570}
3571
3572// find_last_not_of
3573
3574template<class _CharT, class _Traits, class _Allocator>
3575typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003576basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003577 size_type __pos,
3578 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003579{
Alp Tokerec34c482014-05-15 11:27:39 +00003580 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003581 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003582 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003583}
3584
3585template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003586inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003587typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003588basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3589 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003590{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003591 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003592 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003593}
3594
3595template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003596template <class _Tp>
3597typename enable_if
3598<
3599 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3600 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3601>::type
3602basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
3603 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003604{
Marshall Clow64c10d02018-07-02 18:41:15 +00003605 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003606 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3607 (data(), size(), __sv.data(), __pos, __sv.size());
3608}
3609
3610template<class _CharT, class _Traits, class _Allocator>
3611inline _LIBCPP_INLINE_VISIBILITY
3612typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003613basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003614 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003615{
Alp Tokerec34c482014-05-15 11:27:39 +00003616 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003617 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003618 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003619}
3620
3621template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003622inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003623typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003624basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3625 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003626{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003627 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003628 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003629}
3630
3631// compare
3632
3633template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003634template <class _Tp>
3635typename enable_if
3636<
3637 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3638 int
3639>::type
3640basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003641{
Marshall Clow64c10d02018-07-02 18:41:15 +00003642 __self_view __sv = __t;
Howard Hinnantfa06d752011-07-24 21:45:06 +00003643 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003644 size_t __rhs_sz = __sv.size();
3645 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:06 +00003646 _VSTD::min(__lhs_sz, __rhs_sz));
3647 if (__result != 0)
3648 return __result;
3649 if (__lhs_sz < __rhs_sz)
3650 return -1;
3651 if (__lhs_sz > __rhs_sz)
3652 return 1;
3653 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003654}
3655
3656template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003657inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003658int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003659basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003660{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003661 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003662}
3663
3664template <class _CharT, class _Traits, class _Allocator>
3665int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003666basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3667 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003668 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003669 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003670{
Alp Tokerec34c482014-05-15 11:27:39 +00003671 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003672 size_type __sz = size();
3673 if (__pos1 > __sz || __n2 == npos)
3674 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003675 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3676 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003677 if (__r == 0)
3678 {
3679 if (__rlen < __n2)
3680 __r = -1;
3681 else if (__rlen > __n2)
3682 __r = 1;
3683 }
3684 return __r;
3685}
3686
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003687template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003688template <class _Tp>
3689typename enable_if
3690<
3691 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3692 int
3693>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003694basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3695 size_type __n1,
Marshall Clow64c10d02018-07-02 18:41:15 +00003696 const _Tp& __t) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003697{
Marshall Clow64c10d02018-07-02 18:41:15 +00003698 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003699 return compare(__pos1, __n1, __sv.data(), __sv.size());
3700}
3701
3702template <class _CharT, class _Traits, class _Allocator>
3703inline _LIBCPP_INLINE_VISIBILITY
3704int
3705basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3706 size_type __n1,
3707 const basic_string& __str) const
3708{
3709 return compare(__pos1, __n1, __str.data(), __str.size());
3710}
3711
3712template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00003713template <class _Tp>
3714typename enable_if
3715<
Marshall Clowf1729d92017-11-15 20:02:27 +00003716 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3717 int
Marshall Clow6ac8de02016-09-24 22:45:42 +00003718>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003719basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3720 size_type __n1,
Marshall Clow6ac8de02016-09-24 22:45:42 +00003721 const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003722 size_type __pos2,
3723 size_type __n2) const
3724{
Marshall Clow6ac8de02016-09-24 22:45:42 +00003725 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003726 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3727}
3728
3729template <class _CharT, class _Traits, class _Allocator>
3730int
3731basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3732 size_type __n1,
3733 const basic_string& __str,
3734 size_type __pos2,
3735 size_type __n2) const
3736{
3737 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3738}
3739
3740template <class _CharT, class _Traits, class _Allocator>
3741int
3742basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3743{
3744 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3745 return compare(0, npos, __s, traits_type::length(__s));
3746}
3747
3748template <class _CharT, class _Traits, class _Allocator>
3749int
3750basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3751 size_type __n1,
3752 const value_type* __s) const
3753{
3754 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3755 return compare(__pos1, __n1, __s, traits_type::length(__s));
3756}
3757
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003758// __invariants
3759
3760template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003761inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003762bool
3763basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3764{
3765 if (size() > capacity())
3766 return false;
3767 if (capacity() < __min_cap - 1)
3768 return false;
3769 if (data() == 0)
3770 return false;
3771 if (data()[size()] != value_type(0))
3772 return false;
3773 return true;
3774}
3775
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003776// __clear_and_shrink
3777
3778template<class _CharT, class _Traits, class _Allocator>
3779inline _LIBCPP_INLINE_VISIBILITY
3780void
Marshall Clowab343bb2018-05-29 17:04:37 +00003781basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003782{
3783 clear();
3784 if(__is_long())
3785 {
3786 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
3787 __set_long_cap(0);
3788 __set_short_size(0);
3789 }
3790}
3791
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003792// operator==
3793
3794template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003795inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003796bool
3797operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003798 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003799{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003800 size_t __lhs_sz = __lhs.size();
3801 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3802 __rhs.data(),
3803 __lhs_sz) == 0;
3804}
3805
3806template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003807inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003808bool
3809operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3810 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3811{
3812 size_t __lhs_sz = __lhs.size();
3813 if (__lhs_sz != __rhs.size())
3814 return false;
3815 const char* __lp = __lhs.data();
3816 const char* __rp = __rhs.data();
3817 if (__lhs.__is_long())
3818 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3819 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3820 if (*__lp != *__rp)
3821 return false;
3822 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003823}
3824
3825template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003826inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003827bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003828operator==(const _CharT* __lhs,
3829 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003830{
Eric Fiselier4f241822015-08-28 03:02:37 +00003831 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3832 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3833 size_t __lhs_len = _Traits::length(__lhs);
3834 if (__lhs_len != __rhs.size()) return false;
3835 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003836}
3837
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003838template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003839inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003840bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003841operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3842 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003843{
Eric Fiselier4f241822015-08-28 03:02:37 +00003844 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3845 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3846 size_t __rhs_len = _Traits::length(__rhs);
3847 if (__rhs_len != __lhs.size()) return false;
3848 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003849}
3850
Howard Hinnant324bb032010-08-22 00:02:43 +00003851template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003852inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003853bool
3854operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003855 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003856{
3857 return !(__lhs == __rhs);
3858}
3859
3860template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003861inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003862bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003863operator!=(const _CharT* __lhs,
3864 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003865{
3866 return !(__lhs == __rhs);
3867}
3868
3869template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003870inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003871bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003872operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3873 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003874{
3875 return !(__lhs == __rhs);
3876}
3877
3878// operator<
3879
3880template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003881inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003882bool
3883operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003884 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003885{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003886 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003887}
3888
3889template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003890inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003891bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003892operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3893 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003894{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003895 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003896}
3897
3898template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003899inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003900bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003901operator< (const _CharT* __lhs,
3902 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003903{
3904 return __rhs.compare(__lhs) > 0;
3905}
3906
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003907// operator>
3908
3909template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003910inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003911bool
3912operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003913 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003914{
3915 return __rhs < __lhs;
3916}
3917
3918template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003919inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003920bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003921operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3922 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003923{
3924 return __rhs < __lhs;
3925}
3926
3927template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003928inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003929bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003930operator> (const _CharT* __lhs,
3931 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003932{
3933 return __rhs < __lhs;
3934}
3935
3936// operator<=
3937
3938template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003939inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003940bool
3941operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003942 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003943{
3944 return !(__rhs < __lhs);
3945}
3946
3947template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003948inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003949bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003950operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3951 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003952{
3953 return !(__rhs < __lhs);
3954}
3955
3956template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003957inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003958bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003959operator<=(const _CharT* __lhs,
3960 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003961{
3962 return !(__rhs < __lhs);
3963}
3964
3965// operator>=
3966
3967template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003968inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003969bool
3970operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003971 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003972{
3973 return !(__lhs < __rhs);
3974}
3975
3976template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003977inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003978bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003979operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3980 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003981{
3982 return !(__lhs < __rhs);
3983}
3984
3985template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003986inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003987bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003988operator>=(const _CharT* __lhs,
3989 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003990{
3991 return !(__lhs < __rhs);
3992}
3993
3994// operator +
3995
3996template<class _CharT, class _Traits, class _Allocator>
3997basic_string<_CharT, _Traits, _Allocator>
3998operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3999 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4000{
4001 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4002 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4003 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4004 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4005 __r.append(__rhs.data(), __rhs_sz);
4006 return __r;
4007}
4008
4009template<class _CharT, class _Traits, class _Allocator>
4010basic_string<_CharT, _Traits, _Allocator>
4011operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4012{
4013 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4014 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4015 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4016 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4017 __r.append(__rhs.data(), __rhs_sz);
4018 return __r;
4019}
4020
4021template<class _CharT, class _Traits, class _Allocator>
4022basic_string<_CharT, _Traits, _Allocator>
4023operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4024{
4025 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4026 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4027 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4028 __r.append(__rhs.data(), __rhs_sz);
4029 return __r;
4030}
4031
4032template<class _CharT, class _Traits, class _Allocator>
4033basic_string<_CharT, _Traits, _Allocator>
4034operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4035{
4036 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4037 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4038 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4039 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4040 __r.append(__rhs, __rhs_sz);
4041 return __r;
4042}
4043
4044template<class _CharT, class _Traits, class _Allocator>
4045basic_string<_CharT, _Traits, _Allocator>
4046operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4047{
4048 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4049 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4050 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4051 __r.push_back(__rhs);
4052 return __r;
4053}
4054
Eric Fiselier3e928972017-04-19 00:28:44 +00004055#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004056
4057template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004058inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004059basic_string<_CharT, _Traits, _Allocator>
4060operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4061{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004062 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004063}
4064
4065template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004066inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004067basic_string<_CharT, _Traits, _Allocator>
4068operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4069{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004070 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004071}
4072
4073template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004074inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004075basic_string<_CharT, _Traits, _Allocator>
4076operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4077{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004078 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004079}
4080
4081template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004082inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004083basic_string<_CharT, _Traits, _Allocator>
4084operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4085{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004086 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004087}
4088
4089template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004090inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004091basic_string<_CharT, _Traits, _Allocator>
4092operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4093{
4094 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004095 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004096}
4097
4098template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004099inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004100basic_string<_CharT, _Traits, _Allocator>
4101operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4102{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004103 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004104}
4105
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, _CharT __rhs)
4110{
4111 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004112 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004113}
4114
Eric Fiselier3e928972017-04-19 00:28:44 +00004115#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004116
4117// swap
4118
4119template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004120inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004121void
Howard Hinnanta6119a82011-05-29 19:57:12 +00004122swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00004123 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4124 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004125{
4126 __lhs.swap(__rhs);
4127}
4128
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004129#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
4130
4131typedef basic_string<char16_t> u16string;
4132typedef basic_string<char32_t> u32string;
4133
Howard Hinnant324bb032010-08-22 00:02:43 +00004134#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004135
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004136_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4137_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4138_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4139_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4140_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004141
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004142_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4143_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4144_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004145
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004146_LIBCPP_FUNC_VIS string to_string(int __val);
4147_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4148_LIBCPP_FUNC_VIS string to_string(long __val);
4149_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4150_LIBCPP_FUNC_VIS string to_string(long long __val);
4151_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4152_LIBCPP_FUNC_VIS string to_string(float __val);
4153_LIBCPP_FUNC_VIS string to_string(double __val);
4154_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004155
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004156_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4157_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4158_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4159_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4160_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004161
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004162_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4163_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4164_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004165
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004166_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4167_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4168_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4169_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4170_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4171_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4172_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4173_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4174_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004175
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004176template<class _CharT, class _Traits, class _Allocator>
4177 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4178 basic_string<_CharT, _Traits, _Allocator>::npos;
4179
4180template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +00004181struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004182 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4183{
4184 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004185 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004186};
4187
4188template<class _CharT, class _Traits, class _Allocator>
4189size_t
4190hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004191 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004192{
Sean Huntaffd9e52011-07-29 23:31:56 +00004193 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004194}
4195
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004196template<class _CharT, class _Traits, class _Allocator>
4197basic_ostream<_CharT, _Traits>&
4198operator<<(basic_ostream<_CharT, _Traits>& __os,
4199 const basic_string<_CharT, _Traits, _Allocator>& __str);
4200
4201template<class _CharT, class _Traits, class _Allocator>
4202basic_istream<_CharT, _Traits>&
4203operator>>(basic_istream<_CharT, _Traits>& __is,
4204 basic_string<_CharT, _Traits, _Allocator>& __str);
4205
4206template<class _CharT, class _Traits, class _Allocator>
4207basic_istream<_CharT, _Traits>&
4208getline(basic_istream<_CharT, _Traits>& __is,
4209 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4210
4211template<class _CharT, class _Traits, class _Allocator>
4212inline _LIBCPP_INLINE_VISIBILITY
4213basic_istream<_CharT, _Traits>&
4214getline(basic_istream<_CharT, _Traits>& __is,
4215 basic_string<_CharT, _Traits, _Allocator>& __str);
4216
Eric Fiselier3e928972017-04-19 00:28:44 +00004217#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004218
4219template<class _CharT, class _Traits, class _Allocator>
4220inline _LIBCPP_INLINE_VISIBILITY
4221basic_istream<_CharT, _Traits>&
4222getline(basic_istream<_CharT, _Traits>&& __is,
4223 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4224
4225template<class _CharT, class _Traits, class _Allocator>
4226inline _LIBCPP_INLINE_VISIBILITY
4227basic_istream<_CharT, _Traits>&
4228getline(basic_istream<_CharT, _Traits>&& __is,
4229 basic_string<_CharT, _Traits, _Allocator>& __str);
4230
Eric Fiselier3e928972017-04-19 00:28:44 +00004231#endif // _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004232
Howard Hinnant499cea12013-08-23 17:37:05 +00004233#if _LIBCPP_DEBUG_LEVEL >= 2
4234
4235template<class _CharT, class _Traits, class _Allocator>
4236bool
4237basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4238{
4239 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4240 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4241}
4242
4243template<class _CharT, class _Traits, class _Allocator>
4244bool
4245basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4246{
4247 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4248 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4249}
4250
4251template<class _CharT, class _Traits, class _Allocator>
4252bool
4253basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4254{
4255 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4256 return this->data() <= __p && __p <= this->data() + this->size();
4257}
4258
4259template<class _CharT, class _Traits, class _Allocator>
4260bool
4261basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4262{
4263 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4264 return this->data() <= __p && __p < this->data() + this->size();
4265}
4266
4267#endif // _LIBCPP_DEBUG_LEVEL >= 2
4268
Shoaib Meenai68506702017-06-29 02:52:46 +00004269_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
4270_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Shoaib Meenai68506702017-06-29 02:52:46 +00004271
Marshall Clow15234322013-07-23 17:05:24 +00004272#if _LIBCPP_STD_VER > 11
4273// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004274inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004275{
4276 inline namespace string_literals
4277 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004278 inline _LIBCPP_INLINE_VISIBILITY
4279 basic_string<char> operator "" s( const char *__str, size_t __len )
4280 {
4281 return basic_string<char> (__str, __len);
4282 }
Marshall Clow15234322013-07-23 17:05:24 +00004283
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004284 inline _LIBCPP_INLINE_VISIBILITY
4285 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4286 {
4287 return basic_string<wchar_t> (__str, __len);
4288 }
Marshall Clow15234322013-07-23 17:05:24 +00004289
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004290 inline _LIBCPP_INLINE_VISIBILITY
4291 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4292 {
4293 return basic_string<char16_t> (__str, __len);
4294 }
Marshall Clow15234322013-07-23 17:05:24 +00004295
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004296 inline _LIBCPP_INLINE_VISIBILITY
4297 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4298 {
4299 return basic_string<char32_t> (__str, __len);
4300 }
Marshall Clow15234322013-07-23 17:05:24 +00004301 }
4302}
4303#endif
4304
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004305_LIBCPP_END_NAMESPACE_STD
4306
Eric Fiselier018a3d52017-05-31 22:07:49 +00004307_LIBCPP_POP_MACROS
4308
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004309#endif // _LIBCPP_STRING