blob: 0c9f1cf1b2b8c124b859a3db972a7838e982020b [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>
Marshall Clowe3973fd2018-09-12 19:41:40 +0000513#include <version>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000514#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
515#include <cstdint>
516#endif
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000517
Eric Fiselierb9536102014-08-10 23:53:08 +0000518#include <__debug>
519
Howard Hinnant08e17472011-10-17 20:05:10 +0000520#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000522#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523
Eric Fiselier018a3d52017-05-31 22:07:49 +0000524_LIBCPP_PUSH_MACROS
525#include <__undef_macros>
526
527
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528_LIBCPP_BEGIN_NAMESPACE_STD
529
530// fpos
531
532template <class _StateT>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000533class _LIBCPP_TEMPLATE_VIS fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534{
535private:
536 _StateT __st_;
537 streamoff __off_;
538public:
539 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
540
541 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
542
543 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
544 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
545
546 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
547 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
548 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
549 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
550};
551
552template <class _StateT>
553inline _LIBCPP_INLINE_VISIBILITY
554streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
555 {return streamoff(__x) - streamoff(__y);}
556
557template <class _StateT>
558inline _LIBCPP_INLINE_VISIBILITY
559bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
560 {return streamoff(__x) == streamoff(__y);}
561
562template <class _StateT>
563inline _LIBCPP_INLINE_VISIBILITY
564bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
565 {return streamoff(__x) != streamoff(__y);}
566
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000567// basic_string
568
569template<class _CharT, class _Traits, class _Allocator>
570basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000571operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
572 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000573
574template<class _CharT, class _Traits, class _Allocator>
575basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000576operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000577
578template<class _CharT, class _Traits, class _Allocator>
579basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000580operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581
582template<class _CharT, class _Traits, class _Allocator>
Louis Dionnece2232f2018-11-21 17:31:55 +0000583inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000584basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000585operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000586
587template<class _CharT, class _Traits, class _Allocator>
588basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000589operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000590
Shoaib Meenai487562f2017-07-29 02:54:41 +0000591_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
592
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593template <bool>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000594class _LIBCPP_TEMPLATE_VIS __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595{
596protected:
Marshall Clow14c09a22016-08-25 15:09:01 +0000597 _LIBCPP_NORETURN void __throw_length_error() const;
598 _LIBCPP_NORETURN void __throw_out_of_range() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000599};
600
601template <bool __b>
602void
603__basic_string_common<__b>::__throw_length_error() const
604{
Marshall Clow14c09a22016-08-25 15:09:01 +0000605 _VSTD::__throw_length_error("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606}
607
608template <bool __b>
609void
610__basic_string_common<__b>::__throw_out_of_range() const
611{
Marshall Clow14c09a22016-08-25 15:09:01 +0000612 _VSTD::__throw_out_of_range("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000613}
614
Eric Fiselier833d6442016-09-15 22:27:07 +0000615_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000616
Marshall Clowdf9db312016-01-13 21:54:34 +0000617#ifdef _LIBCPP_NO_EXCEPTIONS
618template <class _Iter>
619struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
620#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
621template <class _Iter>
622struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
623#else
624template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
625struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
626 noexcept(++(declval<_Iter&>())) &&
627 is_nothrow_assignable<_Iter&, _Iter>::value &&
628 noexcept(declval<_Iter>() == declval<_Iter>()) &&
629 noexcept(*declval<_Iter>())
630)) {};
631
632template <class _Iter>
633struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
634#endif
635
636
637template <class _Iter>
638struct __libcpp_string_gets_noexcept_iterator
639 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
640
Marshall Clow6ac8de02016-09-24 22:45:42 +0000641template <class _CharT, class _Traits, class _Tp>
642struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
Marshall Clowf1729d92017-11-15 20:02:27 +0000643 ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
Marshall Clow6ac8de02016-09-24 22:45:42 +0000644 !is_convertible<const _Tp&, const _CharT*>::value)) {};
645
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000646#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000647
648template <class _CharT, size_t = sizeof(_CharT)>
649struct __padding
650{
651 unsigned char __xx[sizeof(_CharT)-1];
652};
653
654template <class _CharT>
655struct __padding<_CharT, 1>
656{
657};
658
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000659#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000660
Howard Hinnant324bb032010-08-22 00:02:43 +0000661template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000662class _LIBCPP_TEMPLATE_VIS basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000663 : private __basic_string_common<true>
664{
665public:
666 typedef basic_string __self;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000667 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668 typedef _Traits traits_type;
Marshall Clow2d4c3fa2017-03-15 18:41:11 +0000669 typedef _CharT value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000671 typedef allocator_traits<allocator_type> __alloc_traits;
672 typedef typename __alloc_traits::size_type size_type;
673 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000674 typedef value_type& reference;
675 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000676 typedef typename __alloc_traits::pointer pointer;
677 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000678
Marshall Clow256f1872018-03-21 00:36:05 +0000679 static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
680 static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
681 static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
682 static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
Howard Hinnant499cea12013-08-23 17:37:05 +0000683 "traits_type::char_type must be the same type as CharT");
Marshall Clow256f1872018-03-21 00:36:05 +0000684 static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
Howard Hinnant499cea12013-08-23 17:37:05 +0000685 "Allocator::value_type must be same type as value_type");
Marshall Clow64c10d02018-07-02 18:41:15 +0000686
Howard Hinnant499cea12013-08-23 17:37:05 +0000687#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000688 typedef pointer iterator;
689 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000690#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000691 typedef __wrap_iter<pointer> iterator;
692 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000693#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000694 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
695 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000696
697private:
Howard Hinnant15467182013-04-30 21:44:48 +0000698
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000699#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000700
701 struct __long
702 {
703 pointer __data_;
704 size_type __size_;
705 size_type __cap_;
706 };
707
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000708#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000709 static const size_type __short_mask = 0x01;
710 static const size_type __long_mask = 0x1ul;
Howard Hinnant15467182013-04-30 21:44:48 +0000711#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000712 static const size_type __short_mask = 0x80;
713 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant15467182013-04-30 21:44:48 +0000714#endif // _LIBCPP_BIG_ENDIAN
715
716 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
717 (sizeof(__long) - 1)/sizeof(value_type) : 2};
718
719 struct __short
720 {
721 value_type __data_[__min_cap];
722 struct
723 : __padding<value_type>
724 {
725 unsigned char __size_;
726 };
727 };
728
729#else
730
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000731 struct __long
732 {
733 size_type __cap_;
734 size_type __size_;
735 pointer __data_;
736 };
737
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000738#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000739 static const size_type __short_mask = 0x80;
740 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant324bb032010-08-22 00:02:43 +0000741#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000742 static const size_type __short_mask = 0x01;
743 static const size_type __long_mask = 0x1ul;
Howard Hinnant324bb032010-08-22 00:02:43 +0000744#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000746 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
747 (sizeof(__long) - 1)/sizeof(value_type) : 2};
748
749 struct __short
750 {
751 union
752 {
753 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +0000754 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000755 };
756 value_type __data_[__min_cap];
757 };
758
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000759#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000760
Howard Hinnant499cea12013-08-23 17:37:05 +0000761 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000762
Howard Hinnant499cea12013-08-23 17:37:05 +0000763 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000764
765 struct __raw
766 {
767 size_type __words[__n_words];
768 };
769
770 struct __rep
771 {
772 union
773 {
774 __long __l;
775 __short __s;
776 __raw __r;
777 };
778 };
779
780 __compressed_pair<__rep, allocator_type> __r_;
781
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000782public:
783 static const size_type npos = -1;
784
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000785 _LIBCPP_INLINE_VISIBILITY basic_string()
786 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000787
788 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
789#if _LIBCPP_STD_VER <= 14
790 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
791#else
792 _NOEXCEPT;
793#endif
794
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000795 basic_string(const basic_string& __str);
796 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +0000797
Eric Fiselier3e928972017-04-19 00:28:44 +0000798#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant9f193f22011-01-26 00:06:59 +0000799 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000800 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +0000801#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000802 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000803#else
804 _NOEXCEPT;
805#endif
806
Howard Hinnant9f193f22011-01-26 00:06:59 +0000807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000808 basic_string(basic_string&& __str, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000809#endif // _LIBCPP_CXX03_LANG
Marshall Clow64c10d02018-07-02 18:41:15 +0000810
Marshall Clow7e3ab172018-10-16 16:02:18 +0000811#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +0000812 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
Marshall Clow7e3ab172018-10-16 16:02:18 +0000813#endif
Eric Fiselierffbb91b2018-07-17 05:48:48 +0000814 _LIBCPP_INLINE_VISIBILITY
815 basic_string(const _CharT* __s) {
816 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
817 __init(__s, traits_type::length(__s));
818# if _LIBCPP_DEBUG_LEVEL >= 2
819 __get_db()->__insert_c(this);
820# endif
821 }
Marshall Clow64c10d02018-07-02 18:41:15 +0000822
Marshall Clow7e3ab172018-10-16 16:02:18 +0000823#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +0000824 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
Marshall Clow7e3ab172018-10-16 16:02:18 +0000825#endif
Marshall Clow64c10d02018-07-02 18:41:15 +0000826 _LIBCPP_INLINE_VISIBILITY
827 basic_string(const _CharT* __s, const _Allocator& __a);
828
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000829 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000830 basic_string(const _CharT* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000831 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000832 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000833 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000834 basic_string(size_type __n, _CharT __c);
Marshall Clow64c10d02018-07-02 18:41:15 +0000835
Marshall Clow7e3ab172018-10-16 16:02:18 +0000836#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +0000837 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
Marshall Clow7e3ab172018-10-16 16:02:18 +0000838#endif
Marshall Clow64c10d02018-07-02 18:41:15 +0000839 _LIBCPP_INLINE_VISIBILITY
840 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
841
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000842 basic_string(const basic_string& __str, size_type __pos, size_type __n,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000843 const _Allocator& __a = _Allocator());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000844 _LIBCPP_INLINE_VISIBILITY
845 basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000846 const _Allocator& __a = _Allocator());
Marshall Clow64c10d02018-07-02 18:41:15 +0000847
848 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 +0000849 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000850 basic_string(const _Tp& __t, size_type __pos, size_type __n,
Marshall Clow64c10d02018-07-02 18:41:15 +0000851 const allocator_type& __a = allocator_type());
852
853 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
854 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
855 explicit basic_string(const _Tp& __t);
856
857 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
858 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
859 explicit basic_string(const _Tp& __t, const allocator_type& __a);
860
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000863 basic_string(_InputIterator __first, _InputIterator __last);
864 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000867#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000868 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000869 basic_string(initializer_list<_CharT> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000870 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000871 basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000872#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873
Eric Fiselier51eb1d52016-10-31 03:42:50 +0000874 inline ~basic_string();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000876 _LIBCPP_INLINE_VISIBILITY
877 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
878
Howard Hinnante32b5e22010-11-17 17:55:08 +0000879 basic_string& operator=(const basic_string& __str);
Eric Fiselierf472d6c2017-01-23 21:24:58 +0000880
Marshall Clow64c10d02018-07-02 18:41:15 +0000881 template <class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
882 basic_string& operator=(const _Tp& __t)
883 {__self_view __sv = __t; return assign(__sv);}
884
Eric Fiselier3e928972017-04-19 00:28:44 +0000885#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000887 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +0000888 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Eric Fiselier3e928972017-04-19 00:28:44 +0000889 _LIBCPP_INLINE_VISIBILITY
890 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000891#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000892 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893 basic_string& operator=(value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000894
Howard Hinnant499cea12013-08-23 17:37:05 +0000895#if _LIBCPP_DEBUG_LEVEL >= 2
896 _LIBCPP_INLINE_VISIBILITY
897 iterator begin() _NOEXCEPT
898 {return iterator(this, __get_pointer());}
899 _LIBCPP_INLINE_VISIBILITY
900 const_iterator begin() const _NOEXCEPT
901 {return const_iterator(this, __get_pointer());}
902 _LIBCPP_INLINE_VISIBILITY
903 iterator end() _NOEXCEPT
904 {return iterator(this, __get_pointer() + size());}
905 _LIBCPP_INLINE_VISIBILITY
906 const_iterator end() const _NOEXCEPT
907 {return const_iterator(this, __get_pointer() + size());}
908#else
Howard Hinnanta6119a82011-05-29 19:57:12 +0000909 _LIBCPP_INLINE_VISIBILITY
910 iterator begin() _NOEXCEPT
911 {return iterator(__get_pointer());}
912 _LIBCPP_INLINE_VISIBILITY
913 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000914 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000915 _LIBCPP_INLINE_VISIBILITY
916 iterator end() _NOEXCEPT
917 {return iterator(__get_pointer() + size());}
918 _LIBCPP_INLINE_VISIBILITY
919 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000920 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +0000921#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +0000922 _LIBCPP_INLINE_VISIBILITY
923 reverse_iterator rbegin() _NOEXCEPT
924 {return reverse_iterator(end());}
925 _LIBCPP_INLINE_VISIBILITY
926 const_reverse_iterator rbegin() const _NOEXCEPT
927 {return const_reverse_iterator(end());}
928 _LIBCPP_INLINE_VISIBILITY
929 reverse_iterator rend() _NOEXCEPT
930 {return reverse_iterator(begin());}
931 _LIBCPP_INLINE_VISIBILITY
932 const_reverse_iterator rend() const _NOEXCEPT
933 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000934
Howard Hinnanta6119a82011-05-29 19:57:12 +0000935 _LIBCPP_INLINE_VISIBILITY
936 const_iterator cbegin() const _NOEXCEPT
937 {return begin();}
938 _LIBCPP_INLINE_VISIBILITY
939 const_iterator cend() const _NOEXCEPT
940 {return end();}
941 _LIBCPP_INLINE_VISIBILITY
942 const_reverse_iterator crbegin() const _NOEXCEPT
943 {return rbegin();}
944 _LIBCPP_INLINE_VISIBILITY
945 const_reverse_iterator crend() const _NOEXCEPT
946 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947
Howard Hinnanta6119a82011-05-29 19:57:12 +0000948 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000949 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000950 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
951 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
952 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +0000953 {return (__is_long() ? __get_long_cap()
954 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000955
956 void resize(size_type __n, value_type __c);
957 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
958
Eric Fiselier59e24fe2017-06-01 02:29:37 +0000959 void reserve(size_type __res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000961 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +0000963 void clear() _NOEXCEPT;
Marshall Clowf1729d92017-11-15 20:02:27 +0000964 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
965 bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000966
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000967 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
968 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000969
970 const_reference at(size_type __n) const;
971 reference at(size_type __n);
972
973 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clow64c10d02018-07-02 18:41:15 +0000974
975 template <class _Tp>
976 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
977 typename enable_if
978 <
979 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
980 basic_string&
981 >::type
982 operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);}
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000983 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000984 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Eric Fiselier3e928972017-04-19 00:28:44 +0000985#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000986 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Eric Fiselier3e928972017-04-19 00:28:44 +0000987#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000988
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000990 basic_string& append(const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000991
992 template <class _Tp>
993 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
994 typename enable_if
995 <
996 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
997 basic_string&
998 >::type
999 append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +00001000 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow64c10d02018-07-02 18:41:15 +00001001
Marshall Clow42a87db2016-10-03 23:40:48 +00001002 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001003 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1004 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001005 <
1006 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1007 basic_string&
1008 >::type
1009 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001010 basic_string& append(const value_type* __s, size_type __n);
1011 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001012 basic_string& append(size_type __n, value_type __c);
Eric Fiselier026d38e2016-10-31 02:46:25 +00001013 template <class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001014 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1015 basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001016 template<class _InputIterator>
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_exactly_input_iterator<_InputIterator>::value
1021 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::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(_InputIterator __first, _InputIterator __last) {
1026 const basic_string __temp (__first, __last, __alloc());
1027 append(__temp.data(), __temp.size());
1028 return *this;
1029 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001030 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001031 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1032 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001033 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001034 __is_forward_iterator<_ForwardIterator>::value
1035 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001036 basic_string&
1037 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +00001038 _LIBCPP_INLINE_VISIBILITY
1039 append(_ForwardIterator __first, _ForwardIterator __last) {
1040 return __append_forward_unsafe(__first, __last);
1041 }
1042
Eric Fiselier3e928972017-04-19 00:28:44 +00001043#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001044 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001045 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001046#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001047
1048 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001050 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001051 _LIBCPP_INLINE_VISIBILITY reference front();
1052 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1053 _LIBCPP_INLINE_VISIBILITY reference back();
1054 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001055
Marshall Clow64c10d02018-07-02 18:41:15 +00001056 template <class _Tp>
1057 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1058 typename enable_if
1059 <
1060 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1061 basic_string&
1062 >::type
1063 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001064 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29 +00001065 basic_string& assign(const basic_string& __str) { return *this = __str; }
Eric Fiselier3e928972017-04-19 00:28:44 +00001066#ifndef _LIBCPP_CXX03_LANG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001067 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001068 basic_string& assign(basic_string&& __str)
Marshall Clow7ed093b2015-10-05 16:17:34 +00001069 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001070 {*this = _VSTD::move(__str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001071#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +00001072 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48 +00001073 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001074 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1075 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001076 <
1077 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1078 basic_string&
1079 >::type
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001080 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001081 basic_string& assign(const value_type* __s, size_type __n);
1082 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001083 basic_string& assign(size_type __n, value_type __c);
1084 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001085 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1086 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001087 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001088 __is_exactly_input_iterator<_InputIterator>::value
1089 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001090 basic_string&
1091 >::type
1092 assign(_InputIterator __first, _InputIterator __last);
1093 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001094 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1095 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001096 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001097 __is_forward_iterator<_ForwardIterator>::value
1098 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001099 basic_string&
1100 >::type
1101 assign(_ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001102#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001105#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001106
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001107 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001108 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001109
1110 template <class _Tp>
1111 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1112 typename enable_if
1113 <
1114 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1115 basic_string&
1116 >::type
1117 insert(size_type __pos1, const _Tp& __t)
1118 { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
1119
Marshall Clow6ac8de02016-09-24 22:45:42 +00001120 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001121 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1122 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001123 <
1124 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1125 basic_string&
1126 >::type
1127 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001128 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001129 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1130 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001131 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1132 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001133 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001134 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1135 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001136 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1137 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001138 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001139 __is_exactly_input_iterator<_InputIterator>::value
1140 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001141 iterator
1142 >::type
1143 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1144 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001145 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1146 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001147 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001148 __is_forward_iterator<_ForwardIterator>::value
1149 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001150 iterator
1151 >::type
1152 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001153#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1156 {return insert(__pos, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001157#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001158
1159 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001161 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001162 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163 iterator erase(const_iterator __first, const_iterator __last);
1164
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001165 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001166 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001167
1168 template <class _Tp>
1169 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1170 typename enable_if
1171 <
1172 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1173 basic_string&
1174 >::type
1175 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 +00001176 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 +00001177 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001178 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1179 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001180 <
1181 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1182 basic_string&
1183 >::type
1184 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001185 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1186 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001187 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001188 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001189 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001190
1191 template <class _Tp>
1192 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1193 typename enable_if
1194 <
1195 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1196 basic_string&
1197 >::type
1198 replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
1199
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001200 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001201 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001202 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001203 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001205 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001206 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001207 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1208 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001209 <
1210 __is_input_iterator<_InputIterator>::value,
1211 basic_string&
1212 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001213 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Eric Fiselier3e928972017-04-19 00:28:44 +00001214#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001215 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001216 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001217 {return replace(__i1, __i2, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001218#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001219
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001220 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1223
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001224 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001225 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001226#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00001227 _NOEXCEPT_DEBUG;
Marshall Clow7d914d12015-07-13 20:04:56 +00001228#else
Eric Fiselier47257c42016-12-28 05:53:01 +00001229 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00001230 __is_nothrow_swappable<allocator_type>::value);
1231#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001232
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001234 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001236 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Eric Fiselier10bebe22017-11-20 20:23:27 +00001237#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
Marshall Clowf532a702016-03-08 15:44:30 +00001238 _LIBCPP_INLINE_VISIBILITY
1239 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1240#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001241
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001242 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001243 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001244
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001245 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001246 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001247
1248 template <class _Tp>
1249 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1250 typename enable_if
1251 <
1252 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1253 size_type
1254 >::type
1255 find(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001256 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001258 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001259 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001260
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001261 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001262 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001263
1264 template <class _Tp>
1265 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1266 typename enable_if
1267 <
1268 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1269 size_type
1270 >::type
1271 rfind(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001272 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001273 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001274 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001275 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001276
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001277 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001278 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001279
1280 template <class _Tp>
1281 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1282 typename enable_if
1283 <
1284 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1285 size_type
1286 >::type
1287 find_first_of(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001288 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001290 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001292 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001293
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001294 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001295 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001296
1297 template <class _Tp>
1298 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1299 typename enable_if
1300 <
1301 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1302 size_type
1303 >::type
1304 find_last_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001305 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001306 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001307 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001308 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001309 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001310
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001311 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001312 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001313
1314 template <class _Tp>
1315 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1316 typename enable_if
1317 <
1318 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1319 size_type
1320 >::type
1321 find_first_not_of(const _Tp &__t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001322 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 +00001323 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001324 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001325 _LIBCPP_INLINE_VISIBILITY
1326 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1327
1328 _LIBCPP_INLINE_VISIBILITY
1329 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001330
1331 template <class _Tp>
1332 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1333 typename enable_if
1334 <
1335 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1336 size_type
1337 >::type
1338 find_last_not_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001339 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 +00001340 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001341 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001342 _LIBCPP_INLINE_VISIBILITY
1343 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1344
1345 _LIBCPP_INLINE_VISIBILITY
1346 int compare(const basic_string& __str) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001347
1348 template <class _Tp>
1349 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1350 typename enable_if
1351 <
1352 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1353 int
1354 >::type
1355 compare(const _Tp &__t) const;
1356
1357 template <class _Tp>
1358 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1359 typename enable_if
1360 <
1361 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1362 int
1363 >::type
1364 compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
1365
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001366 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001367 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001368 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 +00001369
Marshall Clow6ac8de02016-09-24 22:45:42 +00001370 template <class _Tp>
Eric Fiselier9dbc0532016-10-14 05:29:46 +00001371 inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow6ac8de02016-09-24 22:45:42 +00001372 typename enable_if
1373 <
1374 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1375 int
1376 >::type
1377 compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001378 int compare(const value_type* __s) const _NOEXCEPT;
1379 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1380 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001381
Marshall Clow46b4ad52017-12-04 20:11:38 +00001382#if _LIBCPP_STD_VER > 17
1383 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1384 bool starts_with(__self_view __sv) const _NOEXCEPT
1385 { return __self_view(data(), size()).starts_with(__sv); }
1386
1387 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1388 bool starts_with(value_type __c) const _NOEXCEPT
1389 { return !empty() && _Traits::eq(front(), __c); }
1390
1391 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1392 bool starts_with(const value_type* __s) const _NOEXCEPT
1393 { return starts_with(__self_view(__s)); }
1394
1395 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1396 bool ends_with(__self_view __sv) const _NOEXCEPT
1397 { return __self_view(data(), size()).ends_with( __sv); }
1398
1399 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1400 bool ends_with(value_type __c) const _NOEXCEPT
1401 { return !empty() && _Traits::eq(back(), __c); }
1402
1403 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1404 bool ends_with(const value_type* __s) const _NOEXCEPT
1405 { return ends_with(__self_view(__s)); }
1406#endif
1407
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001408 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001409
Marshall Clowab343bb2018-05-29 17:04:37 +00001410 _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT;
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001411
Howard Hinnant08dd2532013-04-22 23:55:13 +00001412 _LIBCPP_INLINE_VISIBILITY
1413 bool __is_long() const _NOEXCEPT
1414 {return bool(__r_.first().__s.__size_ & __short_mask);}
1415
Howard Hinnant499cea12013-08-23 17:37:05 +00001416#if _LIBCPP_DEBUG_LEVEL >= 2
1417
1418 bool __dereferenceable(const const_iterator* __i) const;
1419 bool __decrementable(const const_iterator* __i) const;
1420 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1421 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1422
1423#endif // _LIBCPP_DEBUG_LEVEL >= 2
1424
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001425private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001426 _LIBCPP_INLINE_VISIBILITY
1427 allocator_type& __alloc() _NOEXCEPT
1428 {return __r_.second();}
1429 _LIBCPP_INLINE_VISIBILITY
1430 const allocator_type& __alloc() const _NOEXCEPT
1431 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001432
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001433#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001434
Howard Hinnanta6119a82011-05-29 19:57:12 +00001435 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001436 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001437# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001438 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001439# else
1440 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1441# endif
1442
Howard Hinnanta6119a82011-05-29 19:57:12 +00001443 _LIBCPP_INLINE_VISIBILITY
1444 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001445# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001446 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001447# else
1448 {return __r_.first().__s.__size_;}
1449# endif
1450
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001451#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001452
1453 _LIBCPP_INLINE_VISIBILITY
1454 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001455# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001456 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1457# else
1458 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1459# endif
1460
1461 _LIBCPP_INLINE_VISIBILITY
1462 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001463# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001464 {return __r_.first().__s.__size_;}
1465# else
1466 {return __r_.first().__s.__size_ >> 1;}
1467# endif
1468
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001469#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001470
Howard Hinnanta6119a82011-05-29 19:57:12 +00001471 _LIBCPP_INLINE_VISIBILITY
1472 void __set_long_size(size_type __s) _NOEXCEPT
1473 {__r_.first().__l.__size_ = __s;}
1474 _LIBCPP_INLINE_VISIBILITY
1475 size_type __get_long_size() const _NOEXCEPT
1476 {return __r_.first().__l.__size_;}
1477 _LIBCPP_INLINE_VISIBILITY
1478 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001479 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1480
Howard Hinnanta6119a82011-05-29 19:57:12 +00001481 _LIBCPP_INLINE_VISIBILITY
1482 void __set_long_cap(size_type __s) _NOEXCEPT
1483 {__r_.first().__l.__cap_ = __long_mask | __s;}
1484 _LIBCPP_INLINE_VISIBILITY
1485 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001486 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001487
Howard Hinnanta6119a82011-05-29 19:57:12 +00001488 _LIBCPP_INLINE_VISIBILITY
1489 void __set_long_pointer(pointer __p) _NOEXCEPT
1490 {__r_.first().__l.__data_ = __p;}
1491 _LIBCPP_INLINE_VISIBILITY
1492 pointer __get_long_pointer() _NOEXCEPT
1493 {return __r_.first().__l.__data_;}
1494 _LIBCPP_INLINE_VISIBILITY
1495 const_pointer __get_long_pointer() const _NOEXCEPT
1496 {return __r_.first().__l.__data_;}
1497 _LIBCPP_INLINE_VISIBILITY
1498 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001499 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001500 _LIBCPP_INLINE_VISIBILITY
1501 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001502 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001503 _LIBCPP_INLINE_VISIBILITY
1504 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001505 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001506 _LIBCPP_INLINE_VISIBILITY
1507 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001508 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1509
Howard Hinnanta6119a82011-05-29 19:57:12 +00001510 _LIBCPP_INLINE_VISIBILITY
1511 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001512 {
1513 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1514 for (unsigned __i = 0; __i < __n_words; ++__i)
1515 __a[__i] = 0;
1516 }
1517
1518 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001520 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001521 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001522 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001523 static _LIBCPP_INLINE_VISIBILITY
1524 size_type __recommend(size_type __s) _NOEXCEPT
Marshall Clow088e6012018-02-07 21:30:17 +00001525 {
1526 if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
1527 size_type __guess = __align_it<sizeof(value_type) < __alignment ?
1528 __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
1529 if (__guess == __min_cap) ++__guess;
1530 return __guess;
1531 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001532
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001533 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001534 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001535 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001536 void __init(const value_type* __s, size_type __sz);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001537 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001538 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001539
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001540 template <class _InputIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001541 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001542 typename enable_if
1543 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001544 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001545 void
1546 >::type
1547 __init(_InputIterator __first, _InputIterator __last);
1548
1549 template <class _ForwardIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001550 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001551 typename enable_if
1552 <
1553 __is_forward_iterator<_ForwardIterator>::value,
1554 void
1555 >::type
1556 __init(_ForwardIterator __first, _ForwardIterator __last);
1557
1558 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001559 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001560 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1561 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001562 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001563
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001564 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001565 void __erase_to_end(size_type __pos);
1566
Howard Hinnante32b5e22010-11-17 17:55:08 +00001567 _LIBCPP_INLINE_VISIBILITY
1568 void __copy_assign_alloc(const basic_string& __str)
1569 {__copy_assign_alloc(__str, integral_constant<bool,
1570 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1571
1572 _LIBCPP_INLINE_VISIBILITY
1573 void __copy_assign_alloc(const basic_string& __str, true_type)
1574 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001575 if (__alloc() == __str.__alloc())
1576 __alloc() = __str.__alloc();
1577 else
Howard Hinnante32b5e22010-11-17 17:55:08 +00001578 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001579 if (!__str.__is_long())
1580 {
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001581 __clear_and_shrink();
Marshall Clow9247fd22017-01-31 03:40:52 +00001582 __alloc() = __str.__alloc();
1583 }
1584 else
1585 {
1586 allocator_type __a = __str.__alloc();
1587 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001588 __clear_and_shrink();
Marshall Clow9247fd22017-01-31 03:40:52 +00001589 __alloc() = _VSTD::move(__a);
1590 __set_long_pointer(__p);
1591 __set_long_cap(__str.__get_long_cap());
1592 __set_long_size(__str.size());
1593 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001594 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001595 }
1596
1597 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001598 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001599 {}
1600
Eric Fiselier3e928972017-04-19 00:28:44 +00001601#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001602 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001603 void __move_assign(basic_string& __str, false_type)
1604 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001606 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001607#if _LIBCPP_STD_VER > 14
1608 _NOEXCEPT;
1609#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001610 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001611#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001612#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001613
1614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001615 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001616 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001617 _NOEXCEPT_(
1618 !__alloc_traits::propagate_on_container_move_assignment::value ||
1619 is_nothrow_move_assignable<allocator_type>::value)
1620 {__move_assign_alloc(__str, integral_constant<bool,
1621 __alloc_traits::propagate_on_container_move_assignment::value>());}
1622
1623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001624 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001625 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1626 {
1627 __alloc() = _VSTD::move(__c.__alloc());
1628 }
1629
1630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001631 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001632 _NOEXCEPT
1633 {}
1634
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001635 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1636 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001637
1638 friend basic_string operator+<>(const basic_string&, const basic_string&);
1639 friend basic_string operator+<>(const value_type*, const basic_string&);
1640 friend basic_string operator+<>(value_type, const basic_string&);
1641 friend basic_string operator+<>(const basic_string&, const value_type*);
1642 friend basic_string operator+<>(const basic_string&, value_type);
1643};
1644
Marshall Clow5b1e87e2018-02-08 06:34:03 +00001645#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1646template<class _InputIterator,
1647 class _CharT = typename iterator_traits<_InputIterator>::value_type,
1648 class _Allocator = allocator<_CharT>,
1649 class = typename enable_if<__is_input_iterator<_InputIterator>::value, void>::type,
1650 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1651 >
1652basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
1653 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
Marshall Clow64c10d02018-07-02 18:41:15 +00001654
1655template<class _CharT,
1656 class _Traits,
1657 class _Allocator = allocator<_CharT>,
1658 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1659 >
1660explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
1661 -> basic_string<_CharT, _Traits, _Allocator>;
1662
1663template<class _CharT,
1664 class _Traits,
1665 class _Allocator = allocator<_CharT>,
1666 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type,
1667 class _Sz = typename allocator_traits<_Allocator>::size_type
1668 >
1669basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
1670 -> basic_string<_CharT, _Traits, _Allocator>;
Marshall Clow5b1e87e2018-02-08 06:34:03 +00001671#endif
1672
1673
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001674template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001675inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001676void
1677basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1678{
Howard Hinnant499cea12013-08-23 17:37:05 +00001679#if _LIBCPP_DEBUG_LEVEL >= 2
1680 __get_db()->__invalidate_all(this);
1681#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001682}
1683
1684template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001685inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001686void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001687basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001688#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001689 __pos
1690#endif
1691 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001692{
Howard Hinnant499cea12013-08-23 17:37:05 +00001693#if _LIBCPP_DEBUG_LEVEL >= 2
1694 __c_node* __c = __get_db()->__find_c_and_lock(this);
1695 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001696 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001697 const_pointer __new_last = __get_pointer() + __pos;
1698 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001699 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001700 --__p;
1701 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1702 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001703 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001704 (*__p)->__c_ = nullptr;
1705 if (--__c->end_ != __p)
1706 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001707 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001708 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001709 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001710 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001711#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001712}
1713
1714template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001715inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001716basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001717 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001718{
Howard Hinnant499cea12013-08-23 17:37:05 +00001719#if _LIBCPP_DEBUG_LEVEL >= 2
1720 __get_db()->__insert_c(this);
1721#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001722 __zero();
1723}
1724
1725template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001726inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001727basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001728#if _LIBCPP_STD_VER <= 14
1729 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1730#else
1731 _NOEXCEPT
1732#endif
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001733: __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001734{
Howard Hinnant499cea12013-08-23 17:37:05 +00001735#if _LIBCPP_DEBUG_LEVEL >= 2
1736 __get_db()->__insert_c(this);
1737#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001738 __zero();
1739}
1740
1741template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001742void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1743 size_type __sz,
1744 size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001745{
1746 if (__reserve > max_size())
1747 this->__throw_length_error();
1748 pointer __p;
1749 if (__reserve < __min_cap)
1750 {
1751 __set_short_size(__sz);
1752 __p = __get_short_pointer();
1753 }
1754 else
1755 {
1756 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001757 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001758 __set_long_pointer(__p);
1759 __set_long_cap(__cap+1);
1760 __set_long_size(__sz);
1761 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001762 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001763 traits_type::assign(__p[__sz], value_type());
1764}
1765
1766template <class _CharT, class _Traits, class _Allocator>
1767void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001768basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001769{
1770 if (__sz > max_size())
1771 this->__throw_length_error();
1772 pointer __p;
1773 if (__sz < __min_cap)
1774 {
1775 __set_short_size(__sz);
1776 __p = __get_short_pointer();
1777 }
1778 else
1779 {
1780 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001781 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001782 __set_long_pointer(__p);
1783 __set_long_cap(__cap+1);
1784 __set_long_size(__sz);
1785 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001786 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001787 traits_type::assign(__p[__sz], value_type());
1788}
1789
1790template <class _CharT, class _Traits, class _Allocator>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001791#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +00001792template <class>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001793#endif
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001794basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001795 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001796{
Howard Hinnant499cea12013-08-23 17:37:05 +00001797 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001798 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001799#if _LIBCPP_DEBUG_LEVEL >= 2
1800 __get_db()->__insert_c(this);
1801#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001802}
1803
1804template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001805inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001806basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001807{
Howard Hinnant499cea12013-08-23 17:37:05 +00001808 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001809 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001810#if _LIBCPP_DEBUG_LEVEL >= 2
1811 __get_db()->__insert_c(this);
1812#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001813}
1814
1815template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001816inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001817basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001818 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001819{
Howard Hinnant499cea12013-08-23 17:37:05 +00001820 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001821 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001822#if _LIBCPP_DEBUG_LEVEL >= 2
1823 __get_db()->__insert_c(this);
1824#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001825}
1826
1827template <class _CharT, class _Traits, class _Allocator>
1828basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001829 : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001830{
1831 if (!__str.__is_long())
1832 __r_.first().__r = __str.__r_.first().__r;
1833 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001834 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001835#if _LIBCPP_DEBUG_LEVEL >= 2
1836 __get_db()->__insert_c(this);
1837#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001838}
1839
1840template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001841basic_string<_CharT, _Traits, _Allocator>::basic_string(
1842 const basic_string& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001843 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001844{
1845 if (!__str.__is_long())
1846 __r_.first().__r = __str.__r_.first().__r;
1847 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001848 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001849#if _LIBCPP_DEBUG_LEVEL >= 2
1850 __get_db()->__insert_c(this);
1851#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001852}
1853
Eric Fiselier3e928972017-04-19 00:28:44 +00001854#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001855
1856template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001857inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001858basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001859#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001860 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00001861#else
1862 _NOEXCEPT
1863#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001864 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001865{
1866 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00001867#if _LIBCPP_DEBUG_LEVEL >= 2
1868 __get_db()->__insert_c(this);
1869 if (__is_long())
1870 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001871#endif
1872}
1873
1874template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001875inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001876basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001877 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001878{
Marshall Clowd5549cc2014-07-17 15:32:20 +00001879 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001880 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00001881 else
1882 {
1883 __r_.first().__r = __str.__r_.first().__r;
1884 __str.__zero();
1885 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001886#if _LIBCPP_DEBUG_LEVEL >= 2
1887 __get_db()->__insert_c(this);
1888 if (__is_long())
1889 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001890#endif
1891}
1892
Eric Fiselier3e928972017-04-19 00:28:44 +00001893#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001894
1895template <class _CharT, class _Traits, class _Allocator>
1896void
1897basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1898{
1899 if (__n > max_size())
1900 this->__throw_length_error();
1901 pointer __p;
1902 if (__n < __min_cap)
1903 {
1904 __set_short_size(__n);
1905 __p = __get_short_pointer();
1906 }
1907 else
1908 {
1909 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001910 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001911 __set_long_pointer(__p);
1912 __set_long_cap(__cap+1);
1913 __set_long_size(__n);
1914 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001915 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001916 traits_type::assign(__p[__n], value_type());
1917}
1918
1919template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001920inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001921basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001922{
1923 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001924#if _LIBCPP_DEBUG_LEVEL >= 2
1925 __get_db()->__insert_c(this);
1926#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001927}
1928
1929template <class _CharT, class _Traits, class _Allocator>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001930#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +00001931template <class>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001932#endif
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001933basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001934 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935{
1936 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001937#if _LIBCPP_DEBUG_LEVEL >= 2
1938 __get_db()->__insert_c(this);
1939#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001940}
1941
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001942template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001943basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1944 size_type __pos, size_type __n,
1945 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001946 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001947{
1948 size_type __str_sz = __str.size();
1949 if (__pos > __str_sz)
1950 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001951 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00001952#if _LIBCPP_DEBUG_LEVEL >= 2
1953 __get_db()->__insert_c(this);
1954#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001955}
1956
1957template <class _CharT, class _Traits, class _Allocator>
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001958inline _LIBCPP_INLINE_VISIBILITY
1959basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001960 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001961 : __r_(__second_tag(), __a)
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001962{
1963 size_type __str_sz = __str.size();
1964 if (__pos > __str_sz)
1965 this->__throw_out_of_range();
1966 __init(__str.data() + __pos, __str_sz - __pos);
1967#if _LIBCPP_DEBUG_LEVEL >= 2
1968 __get_db()->__insert_c(this);
1969#endif
1970}
1971
1972template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001973template <class _Tp, class>
Marshall Clowdb7fa112016-11-14 18:22:19 +00001974basic_string<_CharT, _Traits, _Allocator>::basic_string(
Marshall Clow64c10d02018-07-02 18:41:15 +00001975 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001976 : __r_(__second_tag(), __a)
Marshall Clowdb7fa112016-11-14 18:22:19 +00001977{
Marshall Clow64c10d02018-07-02 18:41:15 +00001978 __self_view __sv0 = __t;
1979 __self_view __sv = __sv0.substr(__pos, __n);
Marshall Clowdb7fa112016-11-14 18:22:19 +00001980 __init(__sv.data(), __sv.size());
1981#if _LIBCPP_DEBUG_LEVEL >= 2
1982 __get_db()->__insert_c(this);
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001983#endif
Marshall Clowdb7fa112016-11-14 18:22:19 +00001984}
1985
1986template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001987template <class _Tp, class>
1988basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001989{
Marshall Clow64c10d02018-07-02 18:41:15 +00001990 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001991 __init(__sv.data(), __sv.size());
1992#if _LIBCPP_DEBUG_LEVEL >= 2
1993 __get_db()->__insert_c(this);
1994#endif
1995}
1996
1997template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001998template <class _Tp, class>
1999basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002000 : __r_(__second_tag(), __a)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002001{
Marshall Clow64c10d02018-07-02 18:41:15 +00002002 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002003 __init(__sv.data(), __sv.size());
2004#if _LIBCPP_DEBUG_LEVEL >= 2
2005 __get_db()->__insert_c(this);
2006#endif
2007}
2008
2009template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002010template <class _InputIterator>
2011typename enable_if
2012<
Marshall Clowdf9db312016-01-13 21:54:34 +00002013 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002014 void
2015>::type
2016basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2017{
2018 __zero();
2019#ifndef _LIBCPP_NO_EXCEPTIONS
2020 try
2021 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002022#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002023 for (; __first != __last; ++__first)
2024 push_back(*__first);
2025#ifndef _LIBCPP_NO_EXCEPTIONS
2026 }
2027 catch (...)
2028 {
2029 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002030 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002031 throw;
2032 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002033#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002034}
2035
2036template <class _CharT, class _Traits, class _Allocator>
2037template <class _ForwardIterator>
2038typename enable_if
2039<
2040 __is_forward_iterator<_ForwardIterator>::value,
2041 void
2042>::type
2043basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2044{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002045 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002046 if (__sz > max_size())
2047 this->__throw_length_error();
2048 pointer __p;
2049 if (__sz < __min_cap)
2050 {
2051 __set_short_size(__sz);
2052 __p = __get_short_pointer();
2053 }
2054 else
2055 {
2056 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002057 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002058 __set_long_pointer(__p);
2059 __set_long_cap(__cap+1);
2060 __set_long_size(__sz);
2061 }
Eric Fiselierb9919752014-10-27 19:28:20 +00002062 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002063 traits_type::assign(*__p, *__first);
2064 traits_type::assign(*__p, value_type());
2065}
2066
2067template <class _CharT, class _Traits, class _Allocator>
2068template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002069inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002070basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2071{
2072 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002073#if _LIBCPP_DEBUG_LEVEL >= 2
2074 __get_db()->__insert_c(this);
2075#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002076}
2077
2078template <class _CharT, class _Traits, class _Allocator>
2079template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002080inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002081basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2082 const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002083 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002084{
2085 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002086#if _LIBCPP_DEBUG_LEVEL >= 2
2087 __get_db()->__insert_c(this);
2088#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002089}
2090
Eric Fiselier3e928972017-04-19 00:28:44 +00002091#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00002092
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002093template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002094inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00002095basic_string<_CharT, _Traits, _Allocator>::basic_string(
2096 initializer_list<_CharT> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002097{
2098 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002099#if _LIBCPP_DEBUG_LEVEL >= 2
2100 __get_db()->__insert_c(this);
2101#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002102}
2103
2104template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002105inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002106
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00002107basic_string<_CharT, _Traits, _Allocator>::basic_string(
2108 initializer_list<_CharT> __il, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002109 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002110{
2111 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002112#if _LIBCPP_DEBUG_LEVEL >= 2
2113 __get_db()->__insert_c(this);
2114#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002115}
2116
Eric Fiselier3e928972017-04-19 00:28:44 +00002117#endif // _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00002118
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002119template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002120basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2121{
Howard Hinnant499cea12013-08-23 17:37:05 +00002122#if _LIBCPP_DEBUG_LEVEL >= 2
2123 __get_db()->__erase_c(this);
2124#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002125 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002126 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002127}
2128
2129template <class _CharT, class _Traits, class _Allocator>
2130void
2131basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2132 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002133 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 +00002134{
2135 size_type __ms = max_size();
2136 if (__delta_cap > __ms - __old_cap - 1)
2137 this->__throw_length_error();
2138 pointer __old_p = __get_pointer();
2139 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002140 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002141 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002142 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002143 __invalidate_all_iterators();
2144 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002145 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2146 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002147 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002148 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002149 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2150 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002151 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2152 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002153 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002154 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002155 __set_long_pointer(__p);
2156 __set_long_cap(__cap+1);
2157 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2158 __set_long_size(__old_sz);
2159 traits_type::assign(__p[__old_sz], value_type());
2160}
2161
2162template <class _CharT, class _Traits, class _Allocator>
2163void
2164basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2165 size_type __n_copy, size_type __n_del, size_type __n_add)
2166{
2167 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00002168 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002169 this->__throw_length_error();
2170 pointer __old_p = __get_pointer();
2171 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002172 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002173 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002174 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002175 __invalidate_all_iterators();
2176 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002177 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2178 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002179 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2180 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002181 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2182 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2183 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002184 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002185 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002186 __set_long_pointer(__p);
2187 __set_long_cap(__cap+1);
2188}
2189
2190// assign
2191
2192template <class _CharT, class _Traits, class _Allocator>
2193basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002194basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002195{
Alp Tokerec34c482014-05-15 11:27:39 +00002196 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002197 size_type __cap = capacity();
2198 if (__cap >= __n)
2199 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002200 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002201 traits_type::move(__p, __s, __n);
2202 traits_type::assign(__p[__n], value_type());
2203 __set_size(__n);
2204 __invalidate_iterators_past(__n);
2205 }
2206 else
2207 {
2208 size_type __sz = size();
2209 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2210 }
2211 return *this;
2212}
2213
2214template <class _CharT, class _Traits, class _Allocator>
2215basic_string<_CharT, _Traits, _Allocator>&
2216basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2217{
2218 size_type __cap = capacity();
2219 if (__cap < __n)
2220 {
2221 size_type __sz = size();
2222 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2223 }
2224 else
2225 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002226 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002227 traits_type::assign(__p, __n, __c);
2228 traits_type::assign(__p[__n], value_type());
2229 __set_size(__n);
2230 return *this;
2231}
2232
2233template <class _CharT, class _Traits, class _Allocator>
2234basic_string<_CharT, _Traits, _Allocator>&
2235basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2236{
2237 pointer __p;
2238 if (__is_long())
2239 {
2240 __p = __get_long_pointer();
2241 __set_long_size(1);
2242 }
2243 else
2244 {
2245 __p = __get_short_pointer();
2246 __set_short_size(1);
2247 }
2248 traits_type::assign(*__p, __c);
2249 traits_type::assign(*++__p, value_type());
2250 __invalidate_iterators_past(1);
2251 return *this;
2252}
2253
2254template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002255basic_string<_CharT, _Traits, _Allocator>&
2256basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2257{
2258 if (this != &__str)
2259 {
2260 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00002261 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00002262 }
2263 return *this;
2264}
2265
Eric Fiselier3e928972017-04-19 00:28:44 +00002266#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante32b5e22010-11-17 17:55:08 +00002267
2268template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002269inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002270void
2271basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002272 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002273{
2274 if (__alloc() != __str.__alloc())
2275 assign(__str);
2276 else
2277 __move_assign(__str, true_type());
2278}
2279
2280template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002281inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002282void
2283basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002284#if _LIBCPP_STD_VER > 14
2285 _NOEXCEPT
2286#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002287 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002288#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002289{
Vedant Kumar2b588cb2018-03-08 21:15:26 +00002290 __clear_and_shrink();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002291 __r_.first() = __str.__r_.first();
2292 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002293 __str.__zero();
2294}
2295
2296template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002297inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002298basic_string<_CharT, _Traits, _Allocator>&
2299basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002300 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002301{
2302 __move_assign(__str, integral_constant<bool,
2303 __alloc_traits::propagate_on_container_move_assignment::value>());
2304 return *this;
2305}
2306
2307#endif
2308
2309template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002310template<class _InputIterator>
2311typename enable_if
2312<
Marshall Clowdf9db312016-01-13 21:54:34 +00002313 __is_exactly_input_iterator <_InputIterator>::value
2314 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002315 basic_string<_CharT, _Traits, _Allocator>&
2316>::type
2317basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2318{
Marshall Clowd979eed2016-09-05 01:54:30 +00002319 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002320 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002321 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002322}
2323
2324template <class _CharT, class _Traits, class _Allocator>
2325template<class _ForwardIterator>
2326typename enable_if
2327<
Marshall Clowdf9db312016-01-13 21:54:34 +00002328 __is_forward_iterator<_ForwardIterator>::value
2329 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002330 basic_string<_CharT, _Traits, _Allocator>&
2331>::type
2332basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2333{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002334 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002335 size_type __cap = capacity();
2336 if (__cap < __n)
2337 {
2338 size_type __sz = size();
2339 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2340 }
2341 else
2342 __invalidate_iterators_past(__n);
2343 pointer __p = __get_pointer();
2344 for (; __first != __last; ++__first, ++__p)
2345 traits_type::assign(*__p, *__first);
2346 traits_type::assign(*__p, value_type());
2347 __set_size(__n);
2348 return *this;
2349}
2350
2351template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002352basic_string<_CharT, _Traits, _Allocator>&
2353basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2354{
2355 size_type __sz = __str.size();
2356 if (__pos > __sz)
2357 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002358 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002359}
2360
2361template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002362template <class _Tp>
2363typename enable_if
2364<
2365 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002366 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002367>::type
2368basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002369{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002370 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002371 size_type __sz = __sv.size();
2372 if (__pos > __sz)
2373 this->__throw_out_of_range();
2374 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2375}
2376
2377
2378template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002379basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002380basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002381{
Alp Tokerec34c482014-05-15 11:27:39 +00002382 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002383 return assign(__s, traits_type::length(__s));
2384}
2385
2386// append
2387
2388template <class _CharT, class _Traits, class _Allocator>
2389basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002390basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002391{
Alp Tokerec34c482014-05-15 11:27:39 +00002392 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002393 size_type __cap = capacity();
2394 size_type __sz = size();
2395 if (__cap - __sz >= __n)
2396 {
2397 if (__n)
2398 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002399 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002400 traits_type::copy(__p + __sz, __s, __n);
2401 __sz += __n;
2402 __set_size(__sz);
2403 traits_type::assign(__p[__sz], value_type());
2404 }
2405 }
2406 else
2407 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2408 return *this;
2409}
2410
2411template <class _CharT, class _Traits, class _Allocator>
2412basic_string<_CharT, _Traits, _Allocator>&
2413basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2414{
2415 if (__n)
2416 {
2417 size_type __cap = capacity();
2418 size_type __sz = size();
2419 if (__cap - __sz < __n)
2420 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2421 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002422 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002423 __sz += __n;
2424 __set_size(__sz);
2425 traits_type::assign(__p[__sz], value_type());
2426 }
2427 return *this;
2428}
2429
2430template <class _CharT, class _Traits, class _Allocator>
2431void
2432basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2433{
Howard Hinnant15467182013-04-30 21:44:48 +00002434 bool __is_short = !__is_long();
2435 size_type __cap;
2436 size_type __sz;
2437 if (__is_short)
2438 {
2439 __cap = __min_cap - 1;
2440 __sz = __get_short_size();
2441 }
2442 else
2443 {
2444 __cap = __get_long_cap() - 1;
2445 __sz = __get_long_size();
2446 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002447 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002448 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002449 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002450 __is_short = !__is_long();
2451 }
2452 pointer __p;
2453 if (__is_short)
2454 {
2455 __p = __get_short_pointer() + __sz;
2456 __set_short_size(__sz+1);
2457 }
2458 else
2459 {
2460 __p = __get_long_pointer() + __sz;
2461 __set_long_size(__sz+1);
2462 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002463 traits_type::assign(*__p, __c);
2464 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002465}
2466
Marshall Clowac655ef2016-09-07 03:32:06 +00002467template <class _Tp>
Marshall Clowd979eed2016-09-05 01:54:30 +00002468bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2469{
2470 return __first <= __p && __p < __last;
2471}
2472
Marshall Clowac655ef2016-09-07 03:32:06 +00002473template <class _Tp1, class _Tp2>
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00002474bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
Marshall Clowac655ef2016-09-07 03:32:06 +00002475{
2476 return false;
2477}
2478
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002479template <class _CharT, class _Traits, class _Allocator>
2480template<class _ForwardIterator>
Eric Fiselier026d38e2016-10-31 02:46:25 +00002481basic_string<_CharT, _Traits, _Allocator>&
2482basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2483 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002484{
Eric Fiselier026d38e2016-10-31 02:46:25 +00002485 static_assert(__is_forward_iterator<_ForwardIterator>::value,
2486 "function requires a ForwardIterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002487 size_type __sz = size();
2488 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002489 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002490 if (__n)
2491 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002492 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2493 _CharRef __tmp_ref = *__first;
2494 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002495 {
2496 const basic_string __temp (__first, __last, __alloc());
2497 append(__temp.data(), __temp.size());
2498 }
2499 else
2500 {
2501 if (__cap - __sz < __n)
2502 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2503 pointer __p = __get_pointer() + __sz;
2504 for (; __first != __last; ++__p, ++__first)
2505 traits_type::assign(*__p, *__first);
2506 traits_type::assign(*__p, value_type());
2507 __set_size(__sz + __n);
2508 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002509 }
2510 return *this;
2511}
2512
2513template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002514inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002515basic_string<_CharT, _Traits, _Allocator>&
2516basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2517{
2518 return append(__str.data(), __str.size());
2519}
2520
2521template <class _CharT, class _Traits, class _Allocator>
2522basic_string<_CharT, _Traits, _Allocator>&
2523basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2524{
2525 size_type __sz = __str.size();
2526 if (__pos > __sz)
2527 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002528 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002529}
2530
2531template <class _CharT, class _Traits, class _Allocator>
Marshall Clow42a87db2016-10-03 23:40:48 +00002532template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002533 typename enable_if
2534 <
2535 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2536 basic_string<_CharT, _Traits, _Allocator>&
2537 >::type
2538basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002539{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002540 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002541 size_type __sz = __sv.size();
2542 if (__pos > __sz)
2543 this->__throw_out_of_range();
2544 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2545}
2546
2547template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002548basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002549basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002550{
Alp Tokerec34c482014-05-15 11:27:39 +00002551 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002552 return append(__s, traits_type::length(__s));
2553}
2554
2555// insert
2556
2557template <class _CharT, class _Traits, class _Allocator>
2558basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002559basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002560{
Alp Tokerec34c482014-05-15 11:27:39 +00002561 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002562 size_type __sz = size();
2563 if (__pos > __sz)
2564 this->__throw_out_of_range();
2565 size_type __cap = capacity();
2566 if (__cap - __sz >= __n)
2567 {
2568 if (__n)
2569 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002570 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002571 size_type __n_move = __sz - __pos;
2572 if (__n_move != 0)
2573 {
2574 if (__p + __pos <= __s && __s < __p + __sz)
2575 __s += __n;
2576 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2577 }
2578 traits_type::move(__p + __pos, __s, __n);
2579 __sz += __n;
2580 __set_size(__sz);
2581 traits_type::assign(__p[__sz], value_type());
2582 }
2583 }
2584 else
2585 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2586 return *this;
2587}
2588
2589template <class _CharT, class _Traits, class _Allocator>
2590basic_string<_CharT, _Traits, _Allocator>&
2591basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2592{
2593 size_type __sz = size();
2594 if (__pos > __sz)
2595 this->__throw_out_of_range();
2596 if (__n)
2597 {
2598 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002599 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002600 if (__cap - __sz >= __n)
2601 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002602 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002603 size_type __n_move = __sz - __pos;
2604 if (__n_move != 0)
2605 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2606 }
2607 else
2608 {
2609 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002610 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002611 }
2612 traits_type::assign(__p + __pos, __n, __c);
2613 __sz += __n;
2614 __set_size(__sz);
2615 traits_type::assign(__p[__sz], value_type());
2616 }
2617 return *this;
2618}
2619
2620template <class _CharT, class _Traits, class _Allocator>
2621template<class _InputIterator>
2622typename enable_if
2623<
Marshall Clowdf9db312016-01-13 21:54:34 +00002624 __is_exactly_input_iterator<_InputIterator>::value
2625 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2626 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002627>::type
2628basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2629{
Howard Hinnant499cea12013-08-23 17:37:05 +00002630#if _LIBCPP_DEBUG_LEVEL >= 2
2631 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2632 "string::insert(iterator, range) called with an iterator not"
2633 " referring to this string");
2634#endif
Marshall Clowd979eed2016-09-05 01:54:30 +00002635 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002636 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002637}
2638
2639template <class _CharT, class _Traits, class _Allocator>
2640template<class _ForwardIterator>
2641typename enable_if
2642<
Marshall Clowdf9db312016-01-13 21:54:34 +00002643 __is_forward_iterator<_ForwardIterator>::value
2644 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002645 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2646>::type
2647basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2648{
Howard Hinnant499cea12013-08-23 17:37:05 +00002649#if _LIBCPP_DEBUG_LEVEL >= 2
2650 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2651 "string::insert(iterator, range) called with an iterator not"
2652 " referring to this string");
2653#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002654 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002655 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002656 if (__n)
2657 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002658 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2659 _CharRef __tmp_char = *__first;
2660 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002661 {
2662 const basic_string __temp(__first, __last, __alloc());
2663 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2664 }
2665
2666 size_type __sz = size();
2667 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002668 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002669 if (__cap - __sz >= __n)
2670 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002671 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002672 size_type __n_move = __sz - __ip;
2673 if (__n_move != 0)
2674 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2675 }
2676 else
2677 {
2678 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002679 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002680 }
2681 __sz += __n;
2682 __set_size(__sz);
2683 traits_type::assign(__p[__sz], value_type());
2684 for (__p += __ip; __first != __last; ++__p, ++__first)
2685 traits_type::assign(*__p, *__first);
2686 }
2687 return begin() + __ip;
2688}
2689
2690template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002691inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002692basic_string<_CharT, _Traits, _Allocator>&
2693basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2694{
2695 return insert(__pos1, __str.data(), __str.size());
2696}
2697
2698template <class _CharT, class _Traits, class _Allocator>
2699basic_string<_CharT, _Traits, _Allocator>&
2700basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2701 size_type __pos2, size_type __n)
2702{
2703 size_type __str_sz = __str.size();
2704 if (__pos2 > __str_sz)
2705 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002706 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002707}
2708
2709template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002710template <class _Tp>
2711typename enable_if
2712<
2713 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002714 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002715>::type
2716basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002717 size_type __pos2, size_type __n)
2718{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002719 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002720 size_type __str_sz = __sv.size();
2721 if (__pos2 > __str_sz)
2722 this->__throw_out_of_range();
2723 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2724}
2725
2726template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002727basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002728basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002729{
Alp Tokerec34c482014-05-15 11:27:39 +00002730 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002731 return insert(__pos, __s, traits_type::length(__s));
2732}
2733
2734template <class _CharT, class _Traits, class _Allocator>
2735typename basic_string<_CharT, _Traits, _Allocator>::iterator
2736basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2737{
2738 size_type __ip = static_cast<size_type>(__pos - begin());
2739 size_type __sz = size();
2740 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002741 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002742 if (__cap == __sz)
2743 {
2744 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002745 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002746 }
2747 else
2748 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002749 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002750 size_type __n_move = __sz - __ip;
2751 if (__n_move != 0)
2752 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2753 }
2754 traits_type::assign(__p[__ip], __c);
2755 traits_type::assign(__p[++__sz], value_type());
2756 __set_size(__sz);
2757 return begin() + static_cast<difference_type>(__ip);
2758}
2759
2760template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002761inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002762typename basic_string<_CharT, _Traits, _Allocator>::iterator
2763basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2764{
Howard Hinnant499cea12013-08-23 17:37:05 +00002765#if _LIBCPP_DEBUG_LEVEL >= 2
2766 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2767 "string::insert(iterator, n, value) called with an iterator not"
2768 " referring to this string");
2769#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002770 difference_type __p = __pos - begin();
2771 insert(static_cast<size_type>(__p), __n, __c);
2772 return begin() + __p;
2773}
2774
2775// replace
2776
2777template <class _CharT, class _Traits, class _Allocator>
2778basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002779basic_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 +00002780 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002781{
Alp Tokerec34c482014-05-15 11:27:39 +00002782 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002783 size_type __sz = size();
2784 if (__pos > __sz)
2785 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002786 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002787 size_type __cap = capacity();
2788 if (__cap - __sz + __n1 >= __n2)
2789 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002790 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002791 if (__n1 != __n2)
2792 {
2793 size_type __n_move = __sz - __pos - __n1;
2794 if (__n_move != 0)
2795 {
2796 if (__n1 > __n2)
2797 {
2798 traits_type::move(__p + __pos, __s, __n2);
2799 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2800 goto __finish;
2801 }
2802 if (__p + __pos < __s && __s < __p + __sz)
2803 {
2804 if (__p + __pos + __n1 <= __s)
2805 __s += __n2 - __n1;
2806 else // __p + __pos < __s < __p + __pos + __n1
2807 {
2808 traits_type::move(__p + __pos, __s, __n1);
2809 __pos += __n1;
2810 __s += __n2;
2811 __n2 -= __n1;
2812 __n1 = 0;
2813 }
2814 }
2815 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2816 }
2817 }
2818 traits_type::move(__p + __pos, __s, __n2);
2819__finish:
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002820// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
2821// but this is a safe operation, so we disable the check.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002822 __sz += __n2 - __n1;
2823 __set_size(__sz);
2824 __invalidate_iterators_past(__sz);
2825 traits_type::assign(__p[__sz], value_type());
2826 }
2827 else
2828 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2829 return *this;
2830}
2831
2832template <class _CharT, class _Traits, class _Allocator>
2833basic_string<_CharT, _Traits, _Allocator>&
2834basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002835 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002836{
2837 size_type __sz = size();
2838 if (__pos > __sz)
2839 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002840 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002841 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002842 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002843 if (__cap - __sz + __n1 >= __n2)
2844 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002845 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002846 if (__n1 != __n2)
2847 {
2848 size_type __n_move = __sz - __pos - __n1;
2849 if (__n_move != 0)
2850 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2851 }
2852 }
2853 else
2854 {
2855 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002856 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002857 }
2858 traits_type::assign(__p + __pos, __n2, __c);
2859 __sz += __n2 - __n1;
2860 __set_size(__sz);
2861 __invalidate_iterators_past(__sz);
2862 traits_type::assign(__p[__sz], value_type());
2863 return *this;
2864}
2865
2866template <class _CharT, class _Traits, class _Allocator>
2867template<class _InputIterator>
2868typename enable_if
2869<
2870 __is_input_iterator<_InputIterator>::value,
2871 basic_string<_CharT, _Traits, _Allocator>&
2872>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002873basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002874 _InputIterator __j1, _InputIterator __j2)
2875{
Marshall Clowd979eed2016-09-05 01:54:30 +00002876 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002877 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002878}
2879
2880template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002881inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002882basic_string<_CharT, _Traits, _Allocator>&
2883basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2884{
2885 return replace(__pos1, __n1, __str.data(), __str.size());
2886}
2887
2888template <class _CharT, class _Traits, class _Allocator>
2889basic_string<_CharT, _Traits, _Allocator>&
2890basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2891 size_type __pos2, size_type __n2)
2892{
2893 size_type __str_sz = __str.size();
2894 if (__pos2 > __str_sz)
2895 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002896 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002897}
2898
2899template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002900template <class _Tp>
2901typename enable_if
2902<
Marshall Clowf1729d92017-11-15 20:02:27 +00002903 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2904 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002905>::type
2906basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002907 size_type __pos2, size_type __n2)
2908{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002909 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002910 size_type __str_sz = __sv.size();
2911 if (__pos2 > __str_sz)
2912 this->__throw_out_of_range();
2913 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2914}
2915
2916template <class _CharT, class _Traits, class _Allocator>
2917basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002918basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002919{
Alp Tokerec34c482014-05-15 11:27:39 +00002920 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002921 return replace(__pos, __n1, __s, traits_type::length(__s));
2922}
2923
2924template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002925inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002926basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002927basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002928{
2929 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2930 __str.data(), __str.size());
2931}
2932
2933template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002934inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002935basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002936basic_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 +00002937{
2938 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2939}
2940
2941template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002942inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002943basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002944basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002945{
2946 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2947}
2948
2949template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002950inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002951basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002952basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002953{
2954 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2955}
2956
2957// erase
2958
2959template <class _CharT, class _Traits, class _Allocator>
2960basic_string<_CharT, _Traits, _Allocator>&
2961basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2962{
2963 size_type __sz = size();
2964 if (__pos > __sz)
2965 this->__throw_out_of_range();
2966 if (__n)
2967 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002968 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002969 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002970 size_type __n_move = __sz - __pos - __n;
2971 if (__n_move != 0)
2972 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2973 __sz -= __n;
2974 __set_size(__sz);
2975 __invalidate_iterators_past(__sz);
2976 traits_type::assign(__p[__sz], value_type());
2977 }
2978 return *this;
2979}
2980
2981template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002982inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002983typename basic_string<_CharT, _Traits, _Allocator>::iterator
2984basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2985{
Howard Hinnant499cea12013-08-23 17:37:05 +00002986#if _LIBCPP_DEBUG_LEVEL >= 2
2987 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2988 "string::erase(iterator) called with an iterator not"
2989 " referring to this string");
2990#endif
2991 _LIBCPP_ASSERT(__pos != end(),
2992 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002993 iterator __b = begin();
2994 size_type __r = static_cast<size_type>(__pos - __b);
2995 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002996 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002997}
2998
2999template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003000inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003001typename basic_string<_CharT, _Traits, _Allocator>::iterator
3002basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3003{
Howard Hinnant499cea12013-08-23 17:37:05 +00003004#if _LIBCPP_DEBUG_LEVEL >= 2
3005 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3006 "string::erase(iterator, iterator) called with an iterator not"
3007 " referring to this string");
3008#endif
3009 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003010 iterator __b = begin();
3011 size_type __r = static_cast<size_type>(__first - __b);
3012 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00003013 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003014}
3015
3016template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003017inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003018void
3019basic_string<_CharT, _Traits, _Allocator>::pop_back()
3020{
Howard Hinnant499cea12013-08-23 17:37:05 +00003021 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003022 size_type __sz;
3023 if (__is_long())
3024 {
3025 __sz = __get_long_size() - 1;
3026 __set_long_size(__sz);
3027 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3028 }
3029 else
3030 {
3031 __sz = __get_short_size() - 1;
3032 __set_short_size(__sz);
3033 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3034 }
3035 __invalidate_iterators_past(__sz);
3036}
3037
3038template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003039inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003040void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003041basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003042{
3043 __invalidate_all_iterators();
3044 if (__is_long())
3045 {
3046 traits_type::assign(*__get_long_pointer(), value_type());
3047 __set_long_size(0);
3048 }
3049 else
3050 {
3051 traits_type::assign(*__get_short_pointer(), value_type());
3052 __set_short_size(0);
3053 }
3054}
3055
3056template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003057inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003058void
3059basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3060{
3061 if (__is_long())
3062 {
3063 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3064 __set_long_size(__pos);
3065 }
3066 else
3067 {
3068 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3069 __set_short_size(__pos);
3070 }
3071 __invalidate_iterators_past(__pos);
3072}
3073
3074template <class _CharT, class _Traits, class _Allocator>
3075void
3076basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3077{
3078 size_type __sz = size();
3079 if (__n > __sz)
3080 append(__n - __sz, __c);
3081 else
3082 __erase_to_end(__n);
3083}
3084
3085template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003086inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003087typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003088basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003089{
Howard Hinnante32b5e22010-11-17 17:55:08 +00003090 size_type __m = __alloc_traits::max_size(__alloc());
Eric Fiselier5ccf0432017-10-17 13:16:01 +00003091#ifdef _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00003092 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003093#else
Marshall Clow09f85502013-10-31 17:23:08 +00003094 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003095#endif
3096}
3097
3098template <class _CharT, class _Traits, class _Allocator>
3099void
3100basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3101{
3102 if (__res_arg > max_size())
3103 this->__throw_length_error();
3104 size_type __cap = capacity();
3105 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003106 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003107 __res_arg = __recommend(__res_arg);
3108 if (__res_arg != __cap)
3109 {
3110 pointer __new_data, __p;
3111 bool __was_long, __now_long;
3112 if (__res_arg == __min_cap - 1)
3113 {
3114 __was_long = true;
3115 __now_long = false;
3116 __new_data = __get_short_pointer();
3117 __p = __get_long_pointer();
3118 }
3119 else
3120 {
3121 if (__res_arg > __cap)
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 else
3124 {
3125 #ifndef _LIBCPP_NO_EXCEPTIONS
3126 try
3127 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003128 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00003129 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003130 #ifndef _LIBCPP_NO_EXCEPTIONS
3131 }
3132 catch (...)
3133 {
3134 return;
3135 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003136 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003137 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003138 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003139 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003140 }
3141 __now_long = true;
3142 __was_long = __is_long();
3143 __p = __get_pointer();
3144 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003145 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3146 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003147 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003148 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003149 if (__now_long)
3150 {
3151 __set_long_cap(__res_arg+1);
3152 __set_long_size(__sz);
3153 __set_long_pointer(__new_data);
3154 }
3155 else
3156 __set_short_size(__sz);
3157 __invalidate_all_iterators();
3158 }
3159}
3160
3161template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003162inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003163typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003164basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003165{
Howard Hinnant499cea12013-08-23 17:37:05 +00003166 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003167 return *(data() + __pos);
3168}
3169
3170template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003171inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003172typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003173basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003174{
Howard Hinnant499cea12013-08-23 17:37:05 +00003175 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003176 return *(__get_pointer() + __pos);
3177}
3178
3179template <class _CharT, class _Traits, class _Allocator>
3180typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3181basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3182{
3183 if (__n >= size())
3184 this->__throw_out_of_range();
3185 return (*this)[__n];
3186}
3187
3188template <class _CharT, class _Traits, class _Allocator>
3189typename basic_string<_CharT, _Traits, _Allocator>::reference
3190basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3191{
3192 if (__n >= size())
3193 this->__throw_out_of_range();
3194 return (*this)[__n];
3195}
3196
3197template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003198inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003199typename basic_string<_CharT, _Traits, _Allocator>::reference
3200basic_string<_CharT, _Traits, _Allocator>::front()
3201{
Howard Hinnant499cea12013-08-23 17:37:05 +00003202 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003203 return *__get_pointer();
3204}
3205
3206template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003207inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003208typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3209basic_string<_CharT, _Traits, _Allocator>::front() const
3210{
Howard Hinnant499cea12013-08-23 17:37:05 +00003211 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003212 return *data();
3213}
3214
3215template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003216inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003217typename basic_string<_CharT, _Traits, _Allocator>::reference
3218basic_string<_CharT, _Traits, _Allocator>::back()
3219{
Howard Hinnant499cea12013-08-23 17:37:05 +00003220 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003221 return *(__get_pointer() + size() - 1);
3222}
3223
3224template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003225inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003226typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3227basic_string<_CharT, _Traits, _Allocator>::back() const
3228{
Howard Hinnant499cea12013-08-23 17:37:05 +00003229 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003230 return *(data() + size() - 1);
3231}
3232
3233template <class _CharT, class _Traits, class _Allocator>
3234typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003235basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003236{
3237 size_type __sz = size();
3238 if (__pos > __sz)
3239 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003240 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003241 traits_type::copy(__s, data() + __pos, __rlen);
3242 return __rlen;
3243}
3244
3245template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003246inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003247basic_string<_CharT, _Traits, _Allocator>
3248basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3249{
3250 return basic_string(*this, __pos, __n, __alloc());
3251}
3252
3253template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003254inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003255void
3256basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00003257#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00003258 _NOEXCEPT_DEBUG
Marshall Clow7d914d12015-07-13 20:04:56 +00003259#else
Eric Fiselier47257c42016-12-28 05:53:01 +00003260 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00003261 __is_nothrow_swappable<allocator_type>::value)
3262#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003263{
Howard Hinnant499cea12013-08-23 17:37:05 +00003264#if _LIBCPP_DEBUG_LEVEL >= 2
3265 if (!__is_long())
3266 __get_db()->__invalidate_all(this);
3267 if (!__str.__is_long())
3268 __get_db()->__invalidate_all(&__str);
3269 __get_db()->swap(this, &__str);
3270#endif
Eric Fiselier47257c42016-12-28 05:53:01 +00003271 _LIBCPP_ASSERT(
3272 __alloc_traits::propagate_on_container_swap::value ||
3273 __alloc_traits::is_always_equal::value ||
3274 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnant0949eed2011-06-30 21:18:19 +00003275 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00003276 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003277}
3278
3279// find
3280
3281template <class _Traits>
3282struct _LIBCPP_HIDDEN __traits_eq
3283{
3284 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003285 _LIBCPP_INLINE_VISIBILITY
3286 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3287 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003288};
3289
3290template<class _CharT, class _Traits, class _Allocator>
3291typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003292basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003293 size_type __pos,
3294 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003295{
Alp Tokerec34c482014-05-15 11:27:39 +00003296 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003297 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003298 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003299}
3300
3301template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003302inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003303typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003304basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3305 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003306{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003307 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003308 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003309}
3310
3311template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003312template <class _Tp>
3313typename enable_if
3314<
3315 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3316 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3317>::type
3318basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
3319 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003320{
Marshall Clow64c10d02018-07-02 18:41:15 +00003321 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003322 return __str_find<value_type, size_type, traits_type, npos>
3323 (data(), size(), __sv.data(), __pos, __sv.size());
3324}
3325
3326template<class _CharT, class _Traits, class _Allocator>
3327inline _LIBCPP_INLINE_VISIBILITY
3328typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003329basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003330 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003331{
Alp Tokerec34c482014-05-15 11:27:39 +00003332 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003333 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003334 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003335}
3336
3337template<class _CharT, class _Traits, class _Allocator>
3338typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003339basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3340 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003341{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003342 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003343 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003344}
3345
3346// rfind
3347
3348template<class _CharT, class _Traits, class _Allocator>
3349typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003350basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003351 size_type __pos,
3352 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003353{
Alp Tokerec34c482014-05-15 11:27:39 +00003354 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003355 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003356 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003357}
3358
3359template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003360inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003361typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003362basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3363 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003364{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003365 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003366 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003367}
3368
3369template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003370template <class _Tp>
3371typename enable_if
3372<
3373 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3374 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3375>::type
3376basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
3377 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003378{
Marshall Clow64c10d02018-07-02 18:41:15 +00003379 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003380 return __str_rfind<value_type, size_type, traits_type, npos>
3381 (data(), size(), __sv.data(), __pos, __sv.size());
3382}
3383
3384template<class _CharT, class _Traits, class _Allocator>
3385inline _LIBCPP_INLINE_VISIBILITY
3386typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003387basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003388 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003389{
Alp Tokerec34c482014-05-15 11:27:39 +00003390 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003391 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003392 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003393}
3394
3395template<class _CharT, class _Traits, class _Allocator>
3396typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003397basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3398 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003399{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003400 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003401 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003402}
3403
3404// find_first_of
3405
3406template<class _CharT, class _Traits, class _Allocator>
3407typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003408basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003409 size_type __pos,
3410 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003411{
Alp Tokerec34c482014-05-15 11:27:39 +00003412 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003413 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003414 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003415}
3416
3417template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003418inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003419typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003420basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3421 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003422{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003423 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003424 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003425}
3426
3427template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003428template <class _Tp>
3429typename enable_if
3430<
3431 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3432 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3433>::type
3434basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
3435 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003436{
Marshall Clow64c10d02018-07-02 18:41:15 +00003437 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003438 return __str_find_first_of<value_type, size_type, traits_type, npos>
3439 (data(), size(), __sv.data(), __pos, __sv.size());
3440}
3441
3442template<class _CharT, class _Traits, class _Allocator>
3443inline _LIBCPP_INLINE_VISIBILITY
3444typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003445basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003446 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003447{
Alp Tokerec34c482014-05-15 11:27:39 +00003448 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003449 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003450 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003451}
3452
3453template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003454inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003455typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003456basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3457 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003458{
3459 return find(__c, __pos);
3460}
3461
3462// find_last_of
3463
3464template<class _CharT, class _Traits, class _Allocator>
3465typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003466basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003467 size_type __pos,
3468 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003469{
Alp Tokerec34c482014-05-15 11:27:39 +00003470 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003471 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003472 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003473}
3474
3475template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003476inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003477typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003478basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3479 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003480{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003481 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003482 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003483}
3484
3485template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003486template <class _Tp>
3487typename enable_if
3488<
3489 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3490 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3491>::type
3492basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
3493 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003494{
Marshall Clow64c10d02018-07-02 18:41:15 +00003495 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003496 return __str_find_last_of<value_type, size_type, traits_type, npos>
3497 (data(), size(), __sv.data(), __pos, __sv.size());
3498}
3499
3500template<class _CharT, class _Traits, class _Allocator>
3501inline _LIBCPP_INLINE_VISIBILITY
3502typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003503basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003504 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003505{
Alp Tokerec34c482014-05-15 11:27:39 +00003506 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003507 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003508 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003509}
3510
3511template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003512inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003513typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003514basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3515 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003516{
3517 return rfind(__c, __pos);
3518}
3519
3520// find_first_not_of
3521
3522template<class _CharT, class _Traits, class _Allocator>
3523typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003524basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003525 size_type __pos,
3526 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003527{
Alp Tokerec34c482014-05-15 11:27:39 +00003528 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003529 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003530 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003531}
3532
3533template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003534inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003535typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003536basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3537 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003538{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003539 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003540 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003541}
3542
3543template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003544template <class _Tp>
3545typename enable_if
3546<
3547 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3548 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3549>::type
3550basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
3551 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003552{
Marshall Clow64c10d02018-07-02 18:41:15 +00003553 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003554 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3555 (data(), size(), __sv.data(), __pos, __sv.size());
3556}
3557
3558template<class _CharT, class _Traits, class _Allocator>
3559inline _LIBCPP_INLINE_VISIBILITY
3560typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003561basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003562 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003563{
Alp Tokerec34c482014-05-15 11:27:39 +00003564 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003565 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003566 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003567}
3568
3569template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003570inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003571typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003572basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3573 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003574{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003575 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003576 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003577}
3578
3579// find_last_not_of
3580
3581template<class _CharT, class _Traits, class _Allocator>
3582typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003583basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003584 size_type __pos,
3585 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003586{
Alp Tokerec34c482014-05-15 11:27:39 +00003587 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003588 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003589 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003590}
3591
3592template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003593inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003594typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003595basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3596 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003597{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003598 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003599 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003600}
3601
3602template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003603template <class _Tp>
3604typename enable_if
3605<
3606 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3607 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3608>::type
3609basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
3610 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003611{
Marshall Clow64c10d02018-07-02 18:41:15 +00003612 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003613 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3614 (data(), size(), __sv.data(), __pos, __sv.size());
3615}
3616
3617template<class _CharT, class _Traits, class _Allocator>
3618inline _LIBCPP_INLINE_VISIBILITY
3619typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003620basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003621 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003622{
Alp Tokerec34c482014-05-15 11:27:39 +00003623 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003624 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003625 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003626}
3627
3628template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003629inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003630typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003631basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3632 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003633{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003634 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003635 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003636}
3637
3638// compare
3639
3640template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003641template <class _Tp>
3642typename enable_if
3643<
3644 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3645 int
3646>::type
3647basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003648{
Marshall Clow64c10d02018-07-02 18:41:15 +00003649 __self_view __sv = __t;
Howard Hinnantfa06d752011-07-24 21:45:06 +00003650 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003651 size_t __rhs_sz = __sv.size();
3652 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:06 +00003653 _VSTD::min(__lhs_sz, __rhs_sz));
3654 if (__result != 0)
3655 return __result;
3656 if (__lhs_sz < __rhs_sz)
3657 return -1;
3658 if (__lhs_sz > __rhs_sz)
3659 return 1;
3660 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003661}
3662
3663template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003664inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003665int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003666basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003667{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003668 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003669}
3670
3671template <class _CharT, class _Traits, class _Allocator>
3672int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003673basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3674 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003675 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003676 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003677{
Alp Tokerec34c482014-05-15 11:27:39 +00003678 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003679 size_type __sz = size();
3680 if (__pos1 > __sz || __n2 == npos)
3681 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003682 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3683 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003684 if (__r == 0)
3685 {
3686 if (__rlen < __n2)
3687 __r = -1;
3688 else if (__rlen > __n2)
3689 __r = 1;
3690 }
3691 return __r;
3692}
3693
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003694template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003695template <class _Tp>
3696typename enable_if
3697<
3698 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3699 int
3700>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003701basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3702 size_type __n1,
Marshall Clow64c10d02018-07-02 18:41:15 +00003703 const _Tp& __t) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003704{
Marshall Clow64c10d02018-07-02 18:41:15 +00003705 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003706 return compare(__pos1, __n1, __sv.data(), __sv.size());
3707}
3708
3709template <class _CharT, class _Traits, class _Allocator>
3710inline _LIBCPP_INLINE_VISIBILITY
3711int
3712basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3713 size_type __n1,
3714 const basic_string& __str) const
3715{
3716 return compare(__pos1, __n1, __str.data(), __str.size());
3717}
3718
3719template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00003720template <class _Tp>
3721typename enable_if
3722<
Marshall Clowf1729d92017-11-15 20:02:27 +00003723 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3724 int
Marshall Clow6ac8de02016-09-24 22:45:42 +00003725>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003726basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3727 size_type __n1,
Marshall Clow6ac8de02016-09-24 22:45:42 +00003728 const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003729 size_type __pos2,
3730 size_type __n2) const
3731{
Marshall Clow6ac8de02016-09-24 22:45:42 +00003732 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003733 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3734}
3735
3736template <class _CharT, class _Traits, class _Allocator>
3737int
3738basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3739 size_type __n1,
3740 const basic_string& __str,
3741 size_type __pos2,
3742 size_type __n2) const
3743{
3744 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3745}
3746
3747template <class _CharT, class _Traits, class _Allocator>
3748int
3749basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3750{
3751 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3752 return compare(0, npos, __s, traits_type::length(__s));
3753}
3754
3755template <class _CharT, class _Traits, class _Allocator>
3756int
3757basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3758 size_type __n1,
3759 const value_type* __s) const
3760{
3761 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3762 return compare(__pos1, __n1, __s, traits_type::length(__s));
3763}
3764
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003765// __invariants
3766
3767template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003768inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003769bool
3770basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3771{
3772 if (size() > capacity())
3773 return false;
3774 if (capacity() < __min_cap - 1)
3775 return false;
3776 if (data() == 0)
3777 return false;
3778 if (data()[size()] != value_type(0))
3779 return false;
3780 return true;
3781}
3782
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003783// __clear_and_shrink
3784
3785template<class _CharT, class _Traits, class _Allocator>
3786inline _LIBCPP_INLINE_VISIBILITY
3787void
Marshall Clowab343bb2018-05-29 17:04:37 +00003788basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003789{
3790 clear();
3791 if(__is_long())
3792 {
3793 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
3794 __set_long_cap(0);
3795 __set_short_size(0);
3796 }
3797}
3798
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003799// operator==
3800
3801template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003802inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003803bool
3804operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003805 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003806{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003807 size_t __lhs_sz = __lhs.size();
3808 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3809 __rhs.data(),
3810 __lhs_sz) == 0;
3811}
3812
3813template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003814inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003815bool
3816operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3817 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3818{
3819 size_t __lhs_sz = __lhs.size();
3820 if (__lhs_sz != __rhs.size())
3821 return false;
3822 const char* __lp = __lhs.data();
3823 const char* __rp = __rhs.data();
3824 if (__lhs.__is_long())
3825 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3826 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3827 if (*__lp != *__rp)
3828 return false;
3829 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003830}
3831
3832template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003833inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003834bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003835operator==(const _CharT* __lhs,
3836 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003837{
Eric Fiselier4f241822015-08-28 03:02:37 +00003838 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3839 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3840 size_t __lhs_len = _Traits::length(__lhs);
3841 if (__lhs_len != __rhs.size()) return false;
3842 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003843}
3844
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003845template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003846inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003847bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003848operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3849 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003850{
Eric Fiselier4f241822015-08-28 03:02:37 +00003851 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3852 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3853 size_t __rhs_len = _Traits::length(__rhs);
3854 if (__rhs_len != __lhs.size()) return false;
3855 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003856}
3857
Howard Hinnant324bb032010-08-22 00:02:43 +00003858template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003859inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003860bool
3861operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003862 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003863{
3864 return !(__lhs == __rhs);
3865}
3866
3867template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003868inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003869bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003870operator!=(const _CharT* __lhs,
3871 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003872{
3873 return !(__lhs == __rhs);
3874}
3875
3876template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003877inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003878bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003879operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3880 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003881{
3882 return !(__lhs == __rhs);
3883}
3884
3885// operator<
3886
3887template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003888inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003889bool
3890operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003891 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003892{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003893 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003894}
3895
3896template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003897inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003898bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003899operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3900 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003901{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003902 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003903}
3904
3905template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003906inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003907bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003908operator< (const _CharT* __lhs,
3909 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003910{
3911 return __rhs.compare(__lhs) > 0;
3912}
3913
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003914// operator>
3915
3916template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003917inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003918bool
3919operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003920 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003921{
3922 return __rhs < __lhs;
3923}
3924
3925template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003926inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003927bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003928operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3929 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003930{
3931 return __rhs < __lhs;
3932}
3933
3934template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003935inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003936bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003937operator> (const _CharT* __lhs,
3938 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003939{
3940 return __rhs < __lhs;
3941}
3942
3943// operator<=
3944
3945template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003946inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003947bool
3948operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003949 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003950{
3951 return !(__rhs < __lhs);
3952}
3953
3954template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003955inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003956bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003957operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3958 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003959{
3960 return !(__rhs < __lhs);
3961}
3962
3963template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003964inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003965bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003966operator<=(const _CharT* __lhs,
3967 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003968{
3969 return !(__rhs < __lhs);
3970}
3971
3972// operator>=
3973
3974template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003975inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003976bool
3977operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003978 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003979{
3980 return !(__lhs < __rhs);
3981}
3982
3983template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003984inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003985bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003986operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3987 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003988{
3989 return !(__lhs < __rhs);
3990}
3991
3992template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003993inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003994bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003995operator>=(const _CharT* __lhs,
3996 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003997{
3998 return !(__lhs < __rhs);
3999}
4000
4001// operator +
4002
4003template<class _CharT, class _Traits, class _Allocator>
4004basic_string<_CharT, _Traits, _Allocator>
4005operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4006 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4007{
4008 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4009 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4010 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4011 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4012 __r.append(__rhs.data(), __rhs_sz);
4013 return __r;
4014}
4015
4016template<class _CharT, class _Traits, class _Allocator>
4017basic_string<_CharT, _Traits, _Allocator>
4018operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4019{
4020 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4021 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4022 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4023 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4024 __r.append(__rhs.data(), __rhs_sz);
4025 return __r;
4026}
4027
4028template<class _CharT, class _Traits, class _Allocator>
4029basic_string<_CharT, _Traits, _Allocator>
4030operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4031{
4032 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4033 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4034 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4035 __r.append(__rhs.data(), __rhs_sz);
4036 return __r;
4037}
4038
4039template<class _CharT, class _Traits, class _Allocator>
Louis Dionneee6e0ce2018-11-21 17:00:52 +00004040inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004041basic_string<_CharT, _Traits, _Allocator>
4042operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4043{
4044 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4045 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4046 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4047 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4048 __r.append(__rhs, __rhs_sz);
4049 return __r;
4050}
4051
4052template<class _CharT, class _Traits, class _Allocator>
4053basic_string<_CharT, _Traits, _Allocator>
4054operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4055{
4056 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4057 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4058 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4059 __r.push_back(__rhs);
4060 return __r;
4061}
4062
Eric Fiselier3e928972017-04-19 00:28:44 +00004063#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004064
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+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4069{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004070 return _VSTD::move(__lhs.append(__rhs));
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+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4077{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004078 return _VSTD::move(__rhs.insert(0, __lhs));
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+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4085{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004086 return _VSTD::move(__lhs.append(__rhs));
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+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4093{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004094 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004095}
4096
4097template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004098inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004099basic_string<_CharT, _Traits, _Allocator>
4100operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4101{
4102 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004103 return _VSTD::move(__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, const _CharT* __rhs)
4110{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004111 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004112}
4113
4114template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004115inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004116basic_string<_CharT, _Traits, _Allocator>
4117operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4118{
4119 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004120 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004121}
4122
Eric Fiselier3e928972017-04-19 00:28:44 +00004123#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004124
4125// swap
4126
4127template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004128inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004129void
Howard Hinnanta6119a82011-05-29 19:57:12 +00004130swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00004131 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4132 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004133{
4134 __lhs.swap(__rhs);
4135}
4136
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004137#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
4138
4139typedef basic_string<char16_t> u16string;
4140typedef basic_string<char32_t> u32string;
4141
Howard Hinnant324bb032010-08-22 00:02:43 +00004142#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004143
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004144_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4145_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4146_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4147_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4148_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004149
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004150_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4151_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4152_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004153
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004154_LIBCPP_FUNC_VIS string to_string(int __val);
4155_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4156_LIBCPP_FUNC_VIS string to_string(long __val);
4157_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4158_LIBCPP_FUNC_VIS string to_string(long long __val);
4159_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4160_LIBCPP_FUNC_VIS string to_string(float __val);
4161_LIBCPP_FUNC_VIS string to_string(double __val);
4162_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004163
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004164_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4165_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4166_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4167_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4168_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004169
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004170_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4171_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4172_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004173
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004174_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4175_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4176_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4177_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4178_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4179_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4180_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4181_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4182_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004183
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004184template<class _CharT, class _Traits, class _Allocator>
4185 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4186 basic_string<_CharT, _Traits, _Allocator>::npos;
4187
4188template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +00004189struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004190 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4191{
4192 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004193 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004194};
4195
4196template<class _CharT, class _Traits, class _Allocator>
4197size_t
4198hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004199 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004200{
Sean Huntaffd9e52011-07-29 23:31:56 +00004201 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004202}
4203
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004204template<class _CharT, class _Traits, class _Allocator>
4205basic_ostream<_CharT, _Traits>&
4206operator<<(basic_ostream<_CharT, _Traits>& __os,
4207 const basic_string<_CharT, _Traits, _Allocator>& __str);
4208
4209template<class _CharT, class _Traits, class _Allocator>
4210basic_istream<_CharT, _Traits>&
4211operator>>(basic_istream<_CharT, _Traits>& __is,
4212 basic_string<_CharT, _Traits, _Allocator>& __str);
4213
4214template<class _CharT, class _Traits, class _Allocator>
4215basic_istream<_CharT, _Traits>&
4216getline(basic_istream<_CharT, _Traits>& __is,
4217 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4218
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);
4224
Eric Fiselier3e928972017-04-19 00:28:44 +00004225#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004226
4227template<class _CharT, class _Traits, class _Allocator>
4228inline _LIBCPP_INLINE_VISIBILITY
4229basic_istream<_CharT, _Traits>&
4230getline(basic_istream<_CharT, _Traits>&& __is,
4231 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4232
4233template<class _CharT, class _Traits, class _Allocator>
4234inline _LIBCPP_INLINE_VISIBILITY
4235basic_istream<_CharT, _Traits>&
4236getline(basic_istream<_CharT, _Traits>&& __is,
4237 basic_string<_CharT, _Traits, _Allocator>& __str);
4238
Eric Fiselier3e928972017-04-19 00:28:44 +00004239#endif // _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004240
Howard Hinnant499cea12013-08-23 17:37:05 +00004241#if _LIBCPP_DEBUG_LEVEL >= 2
4242
4243template<class _CharT, class _Traits, class _Allocator>
4244bool
4245basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(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>::__decrementable(const const_iterator* __i) const
4254{
4255 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4256 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4257}
4258
4259template<class _CharT, class _Traits, class _Allocator>
4260bool
4261basic_string<_CharT, _Traits, _Allocator>::__addable(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
4267template<class _CharT, class _Traits, class _Allocator>
4268bool
4269basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4270{
4271 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4272 return this->data() <= __p && __p < this->data() + this->size();
4273}
4274
4275#endif // _LIBCPP_DEBUG_LEVEL >= 2
4276
Shoaib Meenai68506702017-06-29 02:52:46 +00004277_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
4278_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Shoaib Meenai68506702017-06-29 02:52:46 +00004279
Marshall Clow15234322013-07-23 17:05:24 +00004280#if _LIBCPP_STD_VER > 11
4281// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004282inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004283{
4284 inline namespace string_literals
4285 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004286 inline _LIBCPP_INLINE_VISIBILITY
4287 basic_string<char> operator "" s( const char *__str, size_t __len )
4288 {
4289 return basic_string<char> (__str, __len);
4290 }
Marshall Clow15234322013-07-23 17:05:24 +00004291
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004292 inline _LIBCPP_INLINE_VISIBILITY
4293 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4294 {
4295 return basic_string<wchar_t> (__str, __len);
4296 }
Marshall Clow15234322013-07-23 17:05:24 +00004297
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004298 inline _LIBCPP_INLINE_VISIBILITY
4299 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4300 {
4301 return basic_string<char16_t> (__str, __len);
4302 }
Marshall Clow15234322013-07-23 17:05:24 +00004303
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004304 inline _LIBCPP_INLINE_VISIBILITY
4305 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4306 {
4307 return basic_string<char32_t> (__str, __len);
4308 }
Marshall Clow15234322013-07-23 17:05:24 +00004309 }
4310}
4311#endif
4312
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004313_LIBCPP_END_NAMESPACE_STD
4314
Eric Fiselier018a3d52017-05-31 22:07:49 +00004315_LIBCPP_POP_MACROS
4316
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004317#endif // _LIBCPP_STRING