blob: 383b5c072ec6c6a98f4a3078ca4d7bee4467a717 [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 Fiselierf9782de2018-11-26 20:15:38 +0000959 _LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n);
960
Eric Fiselier59e24fe2017-06-01 02:29:37 +0000961 void reserve(size_type __res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000963 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +0000965 void clear() _NOEXCEPT;
Marshall Clowf1729d92017-11-15 20:02:27 +0000966 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
967 bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000968
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000969 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
970 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971
972 const_reference at(size_type __n) const;
973 reference at(size_type __n);
974
975 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clow64c10d02018-07-02 18:41:15 +0000976
977 template <class _Tp>
978 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
979 typename enable_if
980 <
981 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
982 basic_string&
983 >::type
984 operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);}
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000985 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000986 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Eric Fiselier3e928972017-04-19 00:28:44 +0000987#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000988 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Eric Fiselier3e928972017-04-19 00:28:44 +0000989#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000990
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000992 basic_string& append(const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000993
994 template <class _Tp>
995 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
996 typename enable_if
997 <
998 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
999 basic_string&
1000 >::type
1001 append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +00001002 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow64c10d02018-07-02 18:41:15 +00001003
Marshall Clow42a87db2016-10-03 23:40:48 +00001004 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001005 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1006 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001007 <
1008 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1009 basic_string&
1010 >::type
1011 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001012 basic_string& append(const value_type* __s, size_type __n);
1013 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001014 basic_string& append(size_type __n, value_type __c);
Eric Fiselierf9782de2018-11-26 20:15:38 +00001015
1016 _LIBCPP_INLINE_VISIBILITY
1017 void __append_default_init(size_type __n);
1018
Eric Fiselier026d38e2016-10-31 02:46:25 +00001019 template <class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001020 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1021 basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001022 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001023 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1024 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001025 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001026 __is_exactly_input_iterator<_InputIterator>::value
1027 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001028 basic_string&
1029 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +00001030 _LIBCPP_INLINE_VISIBILITY
1031 append(_InputIterator __first, _InputIterator __last) {
1032 const basic_string __temp (__first, __last, __alloc());
1033 append(__temp.data(), __temp.size());
1034 return *this;
1035 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001036 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001037 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1038 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001039 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001040 __is_forward_iterator<_ForwardIterator>::value
1041 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001042 basic_string&
1043 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +00001044 _LIBCPP_INLINE_VISIBILITY
1045 append(_ForwardIterator __first, _ForwardIterator __last) {
1046 return __append_forward_unsafe(__first, __last);
1047 }
1048
Eric Fiselier3e928972017-04-19 00:28:44 +00001049#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001051 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001052#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001053
1054 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001055 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001056 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001057 _LIBCPP_INLINE_VISIBILITY reference front();
1058 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1059 _LIBCPP_INLINE_VISIBILITY reference back();
1060 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001061
Marshall Clow64c10d02018-07-02 18:41:15 +00001062 template <class _Tp>
1063 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1064 typename enable_if
1065 <
1066 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1067 basic_string&
1068 >::type
1069 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001070 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29 +00001071 basic_string& assign(const basic_string& __str) { return *this = __str; }
Eric Fiselier3e928972017-04-19 00:28:44 +00001072#ifndef _LIBCPP_CXX03_LANG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001073 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001074 basic_string& assign(basic_string&& __str)
Marshall Clow7ed093b2015-10-05 16:17:34 +00001075 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001076 {*this = _VSTD::move(__str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001077#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +00001078 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48 +00001079 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001080 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1081 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001082 <
1083 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1084 basic_string&
1085 >::type
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001086 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001087 basic_string& assign(const value_type* __s, size_type __n);
1088 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001089 basic_string& assign(size_type __n, value_type __c);
1090 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001091 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1092 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001093 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001094 __is_exactly_input_iterator<_InputIterator>::value
1095 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001096 basic_string&
1097 >::type
1098 assign(_InputIterator __first, _InputIterator __last);
1099 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001100 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1101 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001102 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001103 __is_forward_iterator<_ForwardIterator>::value
1104 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105 basic_string&
1106 >::type
1107 assign(_ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001108#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001110 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001111#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001112
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001113 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001114 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001115
1116 template <class _Tp>
1117 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1118 typename enable_if
1119 <
1120 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1121 basic_string&
1122 >::type
1123 insert(size_type __pos1, const _Tp& __t)
1124 { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
1125
Marshall Clow6ac8de02016-09-24 22:45:42 +00001126 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001127 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1128 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001129 <
1130 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1131 basic_string&
1132 >::type
1133 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001134 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001135 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1136 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001137 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1138 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001140 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1141 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001142 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1143 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001145 __is_exactly_input_iterator<_InputIterator>::value
1146 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001147 iterator
1148 >::type
1149 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1150 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001151 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1152 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001153 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001154 __is_forward_iterator<_ForwardIterator>::value
1155 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001156 iterator
1157 >::type
1158 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001159#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001161 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1162 {return insert(__pos, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001163#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001164
1165 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001166 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001167 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001168 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001169 iterator erase(const_iterator __first, const_iterator __last);
1170
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001172 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001173
1174 template <class _Tp>
1175 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1176 typename enable_if
1177 <
1178 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1179 basic_string&
1180 >::type
1181 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 +00001182 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 +00001183 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001184 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1185 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001186 <
1187 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1188 basic_string&
1189 >::type
1190 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001191 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1192 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001193 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001194 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001195 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001196
1197 template <class _Tp>
1198 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1199 typename enable_if
1200 <
1201 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1202 basic_string&
1203 >::type
1204 replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
1205
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001206 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001207 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001209 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001210 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001211 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001212 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001213 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1214 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001215 <
1216 __is_input_iterator<_InputIterator>::value,
1217 basic_string&
1218 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001219 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Eric Fiselier3e928972017-04-19 00:28:44 +00001220#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001222 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001223 {return replace(__i1, __i2, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001224#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001225
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001226 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001227 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001228 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1229
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001230 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001231 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001232#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00001233 _NOEXCEPT_DEBUG;
Marshall Clow7d914d12015-07-13 20:04:56 +00001234#else
Eric Fiselier47257c42016-12-28 05:53:01 +00001235 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00001236 __is_nothrow_swappable<allocator_type>::value);
1237#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001238
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001239 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001240 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001241 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001242 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Eric Fiselier10bebe22017-11-20 20:23:27 +00001243#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
Marshall Clowf532a702016-03-08 15:44:30 +00001244 _LIBCPP_INLINE_VISIBILITY
1245 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1246#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001247
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001249 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001251 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001252 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001253
1254 template <class _Tp>
1255 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1256 typename enable_if
1257 <
1258 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1259 size_type
1260 >::type
1261 find(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001262 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001264 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001265 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001266
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001267 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001268 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001269
1270 template <class _Tp>
1271 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1272 typename enable_if
1273 <
1274 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1275 size_type
1276 >::type
1277 rfind(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001278 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001279 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001280 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001281 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001282
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001283 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001284 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001285
1286 template <class _Tp>
1287 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1288 typename enable_if
1289 <
1290 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1291 size_type
1292 >::type
1293 find_first_of(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001294 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001295 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001296 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001297 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001298 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001299
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001301 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001302
1303 template <class _Tp>
1304 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1305 typename enable_if
1306 <
1307 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1308 size_type
1309 >::type
1310 find_last_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001311 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001313 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001314 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001315 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001316
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001317 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001318 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001319
1320 template <class _Tp>
1321 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1322 typename enable_if
1323 <
1324 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1325 size_type
1326 >::type
1327 find_first_not_of(const _Tp &__t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001328 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 +00001329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001330 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001331 _LIBCPP_INLINE_VISIBILITY
1332 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1333
1334 _LIBCPP_INLINE_VISIBILITY
1335 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001336
1337 template <class _Tp>
1338 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1339 typename enable_if
1340 <
1341 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1342 size_type
1343 >::type
1344 find_last_not_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001345 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 +00001346 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001347 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001348 _LIBCPP_INLINE_VISIBILITY
1349 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1350
1351 _LIBCPP_INLINE_VISIBILITY
1352 int compare(const basic_string& __str) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001353
1354 template <class _Tp>
1355 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1356 typename enable_if
1357 <
1358 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1359 int
1360 >::type
1361 compare(const _Tp &__t) const;
1362
1363 template <class _Tp>
1364 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1365 typename enable_if
1366 <
1367 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1368 int
1369 >::type
1370 compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
1371
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001372 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001373 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001374 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 +00001375
Marshall Clow6ac8de02016-09-24 22:45:42 +00001376 template <class _Tp>
Eric Fiselier9dbc0532016-10-14 05:29:46 +00001377 inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow6ac8de02016-09-24 22:45:42 +00001378 typename enable_if
1379 <
1380 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1381 int
1382 >::type
1383 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 +00001384 int compare(const value_type* __s) const _NOEXCEPT;
1385 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1386 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001387
Marshall Clow46b4ad52017-12-04 20:11:38 +00001388#if _LIBCPP_STD_VER > 17
1389 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1390 bool starts_with(__self_view __sv) const _NOEXCEPT
1391 { return __self_view(data(), size()).starts_with(__sv); }
1392
1393 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1394 bool starts_with(value_type __c) const _NOEXCEPT
1395 { return !empty() && _Traits::eq(front(), __c); }
1396
1397 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1398 bool starts_with(const value_type* __s) const _NOEXCEPT
1399 { return starts_with(__self_view(__s)); }
1400
1401 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1402 bool ends_with(__self_view __sv) const _NOEXCEPT
1403 { return __self_view(data(), size()).ends_with( __sv); }
1404
1405 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1406 bool ends_with(value_type __c) const _NOEXCEPT
1407 { return !empty() && _Traits::eq(back(), __c); }
1408
1409 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1410 bool ends_with(const value_type* __s) const _NOEXCEPT
1411 { return ends_with(__self_view(__s)); }
1412#endif
1413
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001414 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001415
Marshall Clowab343bb2018-05-29 17:04:37 +00001416 _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT;
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001417
Howard Hinnant08dd2532013-04-22 23:55:13 +00001418 _LIBCPP_INLINE_VISIBILITY
1419 bool __is_long() const _NOEXCEPT
1420 {return bool(__r_.first().__s.__size_ & __short_mask);}
1421
Howard Hinnant499cea12013-08-23 17:37:05 +00001422#if _LIBCPP_DEBUG_LEVEL >= 2
1423
1424 bool __dereferenceable(const const_iterator* __i) const;
1425 bool __decrementable(const const_iterator* __i) const;
1426 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1427 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1428
1429#endif // _LIBCPP_DEBUG_LEVEL >= 2
1430
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001431private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001432 _LIBCPP_INLINE_VISIBILITY
1433 allocator_type& __alloc() _NOEXCEPT
1434 {return __r_.second();}
1435 _LIBCPP_INLINE_VISIBILITY
1436 const allocator_type& __alloc() const _NOEXCEPT
1437 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001438
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001439#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001440
Howard Hinnanta6119a82011-05-29 19:57:12 +00001441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001442 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001443# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001444 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001445# else
1446 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1447# endif
1448
Howard Hinnanta6119a82011-05-29 19:57:12 +00001449 _LIBCPP_INLINE_VISIBILITY
1450 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001451# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001452 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001453# else
1454 {return __r_.first().__s.__size_;}
1455# endif
1456
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001457#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001458
1459 _LIBCPP_INLINE_VISIBILITY
1460 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001461# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001462 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1463# else
1464 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1465# endif
1466
1467 _LIBCPP_INLINE_VISIBILITY
1468 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001469# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001470 {return __r_.first().__s.__size_;}
1471# else
1472 {return __r_.first().__s.__size_ >> 1;}
1473# endif
1474
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001475#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001476
Howard Hinnanta6119a82011-05-29 19:57:12 +00001477 _LIBCPP_INLINE_VISIBILITY
1478 void __set_long_size(size_type __s) _NOEXCEPT
1479 {__r_.first().__l.__size_ = __s;}
1480 _LIBCPP_INLINE_VISIBILITY
1481 size_type __get_long_size() const _NOEXCEPT
1482 {return __r_.first().__l.__size_;}
1483 _LIBCPP_INLINE_VISIBILITY
1484 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001485 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1486
Howard Hinnanta6119a82011-05-29 19:57:12 +00001487 _LIBCPP_INLINE_VISIBILITY
1488 void __set_long_cap(size_type __s) _NOEXCEPT
1489 {__r_.first().__l.__cap_ = __long_mask | __s;}
1490 _LIBCPP_INLINE_VISIBILITY
1491 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001492 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001493
Howard Hinnanta6119a82011-05-29 19:57:12 +00001494 _LIBCPP_INLINE_VISIBILITY
1495 void __set_long_pointer(pointer __p) _NOEXCEPT
1496 {__r_.first().__l.__data_ = __p;}
1497 _LIBCPP_INLINE_VISIBILITY
1498 pointer __get_long_pointer() _NOEXCEPT
1499 {return __r_.first().__l.__data_;}
1500 _LIBCPP_INLINE_VISIBILITY
1501 const_pointer __get_long_pointer() const _NOEXCEPT
1502 {return __r_.first().__l.__data_;}
1503 _LIBCPP_INLINE_VISIBILITY
1504 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001505 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001506 _LIBCPP_INLINE_VISIBILITY
1507 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001508 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001509 _LIBCPP_INLINE_VISIBILITY
1510 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001511 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001512 _LIBCPP_INLINE_VISIBILITY
1513 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001514 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1515
Howard Hinnanta6119a82011-05-29 19:57:12 +00001516 _LIBCPP_INLINE_VISIBILITY
1517 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518 {
1519 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1520 for (unsigned __i = 0; __i < __n_words; ++__i)
1521 __a[__i] = 0;
1522 }
1523
1524 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001526 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001527 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001528 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001529 static _LIBCPP_INLINE_VISIBILITY
1530 size_type __recommend(size_type __s) _NOEXCEPT
Marshall Clow088e6012018-02-07 21:30:17 +00001531 {
1532 if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
1533 size_type __guess = __align_it<sizeof(value_type) < __alignment ?
1534 __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
1535 if (__guess == __min_cap) ++__guess;
1536 return __guess;
1537 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001538
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001539 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001540 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001541 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001542 void __init(const value_type* __s, size_type __sz);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001543 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001544 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001545
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001546 template <class _InputIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001547 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548 typename enable_if
1549 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001550 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001551 void
1552 >::type
1553 __init(_InputIterator __first, _InputIterator __last);
1554
1555 template <class _ForwardIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001556 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001557 typename enable_if
1558 <
1559 __is_forward_iterator<_ForwardIterator>::value,
1560 void
1561 >::type
1562 __init(_ForwardIterator __first, _ForwardIterator __last);
1563
1564 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001565 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001566 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1567 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001568 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001569
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001571 void __erase_to_end(size_type __pos);
1572
Howard Hinnante32b5e22010-11-17 17:55:08 +00001573 _LIBCPP_INLINE_VISIBILITY
1574 void __copy_assign_alloc(const basic_string& __str)
1575 {__copy_assign_alloc(__str, integral_constant<bool,
1576 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1577
1578 _LIBCPP_INLINE_VISIBILITY
1579 void __copy_assign_alloc(const basic_string& __str, true_type)
1580 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001581 if (__alloc() == __str.__alloc())
1582 __alloc() = __str.__alloc();
1583 else
Howard Hinnante32b5e22010-11-17 17:55:08 +00001584 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001585 if (!__str.__is_long())
1586 {
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001587 __clear_and_shrink();
Marshall Clow9247fd22017-01-31 03:40:52 +00001588 __alloc() = __str.__alloc();
1589 }
1590 else
1591 {
1592 allocator_type __a = __str.__alloc();
1593 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001594 __clear_and_shrink();
Marshall Clow9247fd22017-01-31 03:40:52 +00001595 __alloc() = _VSTD::move(__a);
1596 __set_long_pointer(__p);
1597 __set_long_cap(__str.__get_long_cap());
1598 __set_long_size(__str.size());
1599 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001600 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001601 }
1602
1603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001604 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001605 {}
1606
Eric Fiselier3e928972017-04-19 00:28:44 +00001607#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001608 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001609 void __move_assign(basic_string& __str, false_type)
1610 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001612 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001613#if _LIBCPP_STD_VER > 14
1614 _NOEXCEPT;
1615#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001616 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001617#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001618#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001619
1620 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001621 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001622 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001623 _NOEXCEPT_(
1624 !__alloc_traits::propagate_on_container_move_assignment::value ||
1625 is_nothrow_move_assignable<allocator_type>::value)
1626 {__move_assign_alloc(__str, integral_constant<bool,
1627 __alloc_traits::propagate_on_container_move_assignment::value>());}
1628
1629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001630 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001631 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1632 {
1633 __alloc() = _VSTD::move(__c.__alloc());
1634 }
1635
1636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001637 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001638 _NOEXCEPT
1639 {}
1640
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001641 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1642 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001643
1644 friend basic_string operator+<>(const basic_string&, const basic_string&);
1645 friend basic_string operator+<>(const value_type*, const basic_string&);
1646 friend basic_string operator+<>(value_type, const basic_string&);
1647 friend basic_string operator+<>(const basic_string&, const value_type*);
1648 friend basic_string operator+<>(const basic_string&, value_type);
1649};
1650
Marshall Clow5b1e87e2018-02-08 06:34:03 +00001651#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1652template<class _InputIterator,
1653 class _CharT = typename iterator_traits<_InputIterator>::value_type,
1654 class _Allocator = allocator<_CharT>,
1655 class = typename enable_if<__is_input_iterator<_InputIterator>::value, void>::type,
1656 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1657 >
1658basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
1659 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
Marshall Clow64c10d02018-07-02 18:41:15 +00001660
1661template<class _CharT,
1662 class _Traits,
1663 class _Allocator = allocator<_CharT>,
1664 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1665 >
1666explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
1667 -> basic_string<_CharT, _Traits, _Allocator>;
1668
1669template<class _CharT,
1670 class _Traits,
1671 class _Allocator = allocator<_CharT>,
1672 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type,
1673 class _Sz = typename allocator_traits<_Allocator>::size_type
1674 >
1675basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
1676 -> basic_string<_CharT, _Traits, _Allocator>;
Marshall Clow5b1e87e2018-02-08 06:34:03 +00001677#endif
1678
1679
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001680template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001681inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001682void
1683basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1684{
Howard Hinnant499cea12013-08-23 17:37:05 +00001685#if _LIBCPP_DEBUG_LEVEL >= 2
1686 __get_db()->__invalidate_all(this);
1687#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001688}
1689
1690template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001691inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001692void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001693basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001694#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001695 __pos
1696#endif
1697 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001698{
Howard Hinnant499cea12013-08-23 17:37:05 +00001699#if _LIBCPP_DEBUG_LEVEL >= 2
1700 __c_node* __c = __get_db()->__find_c_and_lock(this);
1701 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001702 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001703 const_pointer __new_last = __get_pointer() + __pos;
1704 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001705 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001706 --__p;
1707 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1708 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001709 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001710 (*__p)->__c_ = nullptr;
1711 if (--__c->end_ != __p)
1712 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001713 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001714 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001715 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001716 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001717#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001718}
1719
1720template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001721inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001722basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001723 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001724{
Howard Hinnant499cea12013-08-23 17:37:05 +00001725#if _LIBCPP_DEBUG_LEVEL >= 2
1726 __get_db()->__insert_c(this);
1727#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001728 __zero();
1729}
1730
1731template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001732inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001733basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001734#if _LIBCPP_STD_VER <= 14
1735 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1736#else
1737 _NOEXCEPT
1738#endif
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001739: __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001740{
Howard Hinnant499cea12013-08-23 17:37:05 +00001741#if _LIBCPP_DEBUG_LEVEL >= 2
1742 __get_db()->__insert_c(this);
1743#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001744 __zero();
1745}
1746
1747template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001748void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1749 size_type __sz,
1750 size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001751{
1752 if (__reserve > max_size())
1753 this->__throw_length_error();
1754 pointer __p;
1755 if (__reserve < __min_cap)
1756 {
1757 __set_short_size(__sz);
1758 __p = __get_short_pointer();
1759 }
1760 else
1761 {
1762 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001763 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001764 __set_long_pointer(__p);
1765 __set_long_cap(__cap+1);
1766 __set_long_size(__sz);
1767 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001768 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001769 traits_type::assign(__p[__sz], value_type());
1770}
1771
1772template <class _CharT, class _Traits, class _Allocator>
1773void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001774basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001775{
1776 if (__sz > max_size())
1777 this->__throw_length_error();
1778 pointer __p;
1779 if (__sz < __min_cap)
1780 {
1781 __set_short_size(__sz);
1782 __p = __get_short_pointer();
1783 }
1784 else
1785 {
1786 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001787 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001788 __set_long_pointer(__p);
1789 __set_long_cap(__cap+1);
1790 __set_long_size(__sz);
1791 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001792 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001793 traits_type::assign(__p[__sz], value_type());
1794}
1795
1796template <class _CharT, class _Traits, class _Allocator>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001797#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +00001798template <class>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001799#endif
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001800basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001801 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001802{
Howard Hinnant499cea12013-08-23 17:37:05 +00001803 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001804 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001805#if _LIBCPP_DEBUG_LEVEL >= 2
1806 __get_db()->__insert_c(this);
1807#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001808}
1809
1810template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001811inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001812basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001813{
Howard Hinnant499cea12013-08-23 17:37:05 +00001814 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001815 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001816#if _LIBCPP_DEBUG_LEVEL >= 2
1817 __get_db()->__insert_c(this);
1818#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001819}
1820
1821template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001822inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001823basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001824 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001825{
Howard Hinnant499cea12013-08-23 17:37:05 +00001826 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001827 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001828#if _LIBCPP_DEBUG_LEVEL >= 2
1829 __get_db()->__insert_c(this);
1830#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001831}
1832
1833template <class _CharT, class _Traits, class _Allocator>
1834basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001835 : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001836{
1837 if (!__str.__is_long())
1838 __r_.first().__r = __str.__r_.first().__r;
1839 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001840 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001841#if _LIBCPP_DEBUG_LEVEL >= 2
1842 __get_db()->__insert_c(this);
1843#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001844}
1845
1846template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001847basic_string<_CharT, _Traits, _Allocator>::basic_string(
1848 const basic_string& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001849 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001850{
1851 if (!__str.__is_long())
1852 __r_.first().__r = __str.__r_.first().__r;
1853 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001854 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001855#if _LIBCPP_DEBUG_LEVEL >= 2
1856 __get_db()->__insert_c(this);
1857#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001858}
1859
Eric Fiselier3e928972017-04-19 00:28:44 +00001860#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001861
1862template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001863inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001864basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001865#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001866 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00001867#else
1868 _NOEXCEPT
1869#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001870 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001871{
1872 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00001873#if _LIBCPP_DEBUG_LEVEL >= 2
1874 __get_db()->__insert_c(this);
1875 if (__is_long())
1876 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001877#endif
1878}
1879
1880template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001881inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001882basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001883 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001884{
Marshall Clowd5549cc2014-07-17 15:32:20 +00001885 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001886 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00001887 else
1888 {
1889 __r_.first().__r = __str.__r_.first().__r;
1890 __str.__zero();
1891 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001892#if _LIBCPP_DEBUG_LEVEL >= 2
1893 __get_db()->__insert_c(this);
1894 if (__is_long())
1895 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001896#endif
1897}
1898
Eric Fiselier3e928972017-04-19 00:28:44 +00001899#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001900
1901template <class _CharT, class _Traits, class _Allocator>
1902void
1903basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1904{
1905 if (__n > max_size())
1906 this->__throw_length_error();
1907 pointer __p;
1908 if (__n < __min_cap)
1909 {
1910 __set_short_size(__n);
1911 __p = __get_short_pointer();
1912 }
1913 else
1914 {
1915 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001916 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001917 __set_long_pointer(__p);
1918 __set_long_cap(__cap+1);
1919 __set_long_size(__n);
1920 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001921 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001922 traits_type::assign(__p[__n], value_type());
1923}
1924
1925template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001926inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001927basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001928{
1929 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001930#if _LIBCPP_DEBUG_LEVEL >= 2
1931 __get_db()->__insert_c(this);
1932#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001933}
1934
1935template <class _CharT, class _Traits, class _Allocator>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001936#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +00001937template <class>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001938#endif
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001939basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001940 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001941{
1942 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001943#if _LIBCPP_DEBUG_LEVEL >= 2
1944 __get_db()->__insert_c(this);
1945#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001946}
1947
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001948template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001949basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1950 size_type __pos, size_type __n,
1951 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001952 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001953{
1954 size_type __str_sz = __str.size();
1955 if (__pos > __str_sz)
1956 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001957 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00001958#if _LIBCPP_DEBUG_LEVEL >= 2
1959 __get_db()->__insert_c(this);
1960#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001961}
1962
1963template <class _CharT, class _Traits, class _Allocator>
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001964inline _LIBCPP_INLINE_VISIBILITY
1965basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001966 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001967 : __r_(__second_tag(), __a)
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001968{
1969 size_type __str_sz = __str.size();
1970 if (__pos > __str_sz)
1971 this->__throw_out_of_range();
1972 __init(__str.data() + __pos, __str_sz - __pos);
1973#if _LIBCPP_DEBUG_LEVEL >= 2
1974 __get_db()->__insert_c(this);
1975#endif
1976}
1977
1978template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001979template <class _Tp, class>
Marshall Clowdb7fa112016-11-14 18:22:19 +00001980basic_string<_CharT, _Traits, _Allocator>::basic_string(
Marshall Clow64c10d02018-07-02 18:41:15 +00001981 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001982 : __r_(__second_tag(), __a)
Marshall Clowdb7fa112016-11-14 18:22:19 +00001983{
Marshall Clow64c10d02018-07-02 18:41:15 +00001984 __self_view __sv0 = __t;
1985 __self_view __sv = __sv0.substr(__pos, __n);
Marshall Clowdb7fa112016-11-14 18:22:19 +00001986 __init(__sv.data(), __sv.size());
1987#if _LIBCPP_DEBUG_LEVEL >= 2
1988 __get_db()->__insert_c(this);
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001989#endif
Marshall Clowdb7fa112016-11-14 18:22:19 +00001990}
1991
1992template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001993template <class _Tp, class>
1994basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001995{
Marshall Clow64c10d02018-07-02 18:41:15 +00001996 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001997 __init(__sv.data(), __sv.size());
1998#if _LIBCPP_DEBUG_LEVEL >= 2
1999 __get_db()->__insert_c(this);
2000#endif
2001}
2002
2003template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00002004template <class _Tp, class>
2005basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002006 : __r_(__second_tag(), __a)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002007{
Marshall Clow64c10d02018-07-02 18:41:15 +00002008 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002009 __init(__sv.data(), __sv.size());
2010#if _LIBCPP_DEBUG_LEVEL >= 2
2011 __get_db()->__insert_c(this);
2012#endif
2013}
2014
2015template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002016template <class _InputIterator>
2017typename enable_if
2018<
Marshall Clowdf9db312016-01-13 21:54:34 +00002019 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002020 void
2021>::type
2022basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2023{
2024 __zero();
2025#ifndef _LIBCPP_NO_EXCEPTIONS
2026 try
2027 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002028#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002029 for (; __first != __last; ++__first)
2030 push_back(*__first);
2031#ifndef _LIBCPP_NO_EXCEPTIONS
2032 }
2033 catch (...)
2034 {
2035 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002036 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002037 throw;
2038 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002039#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002040}
2041
2042template <class _CharT, class _Traits, class _Allocator>
2043template <class _ForwardIterator>
2044typename enable_if
2045<
2046 __is_forward_iterator<_ForwardIterator>::value,
2047 void
2048>::type
2049basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2050{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002051 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002052 if (__sz > max_size())
2053 this->__throw_length_error();
2054 pointer __p;
2055 if (__sz < __min_cap)
2056 {
2057 __set_short_size(__sz);
2058 __p = __get_short_pointer();
2059 }
2060 else
2061 {
2062 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002063 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002064 __set_long_pointer(__p);
2065 __set_long_cap(__cap+1);
2066 __set_long_size(__sz);
2067 }
Eric Fiselierb9919752014-10-27 19:28:20 +00002068 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002069 traits_type::assign(*__p, *__first);
2070 traits_type::assign(*__p, value_type());
2071}
2072
2073template <class _CharT, class _Traits, class _Allocator>
2074template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002075inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002076basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2077{
2078 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002079#if _LIBCPP_DEBUG_LEVEL >= 2
2080 __get_db()->__insert_c(this);
2081#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002082}
2083
2084template <class _CharT, class _Traits, class _Allocator>
2085template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002086inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002087basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2088 const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002089 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002090{
2091 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002092#if _LIBCPP_DEBUG_LEVEL >= 2
2093 __get_db()->__insert_c(this);
2094#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095}
2096
Eric Fiselier3e928972017-04-19 00:28:44 +00002097#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00002098
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002099template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002100inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00002101basic_string<_CharT, _Traits, _Allocator>::basic_string(
2102 initializer_list<_CharT> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002103{
2104 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002105#if _LIBCPP_DEBUG_LEVEL >= 2
2106 __get_db()->__insert_c(this);
2107#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002108}
2109
2110template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002111inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002112
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00002113basic_string<_CharT, _Traits, _Allocator>::basic_string(
2114 initializer_list<_CharT> __il, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002115 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002116{
2117 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002118#if _LIBCPP_DEBUG_LEVEL >= 2
2119 __get_db()->__insert_c(this);
2120#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002121}
2122
Eric Fiselier3e928972017-04-19 00:28:44 +00002123#endif // _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00002124
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002125template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002126basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2127{
Howard Hinnant499cea12013-08-23 17:37:05 +00002128#if _LIBCPP_DEBUG_LEVEL >= 2
2129 __get_db()->__erase_c(this);
2130#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002131 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002132 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002133}
2134
2135template <class _CharT, class _Traits, class _Allocator>
2136void
2137basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2138 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002139 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 +00002140{
2141 size_type __ms = max_size();
2142 if (__delta_cap > __ms - __old_cap - 1)
2143 this->__throw_length_error();
2144 pointer __old_p = __get_pointer();
2145 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002146 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002147 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002148 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002149 __invalidate_all_iterators();
2150 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002151 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2152 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002153 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002154 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002155 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2156 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002157 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2158 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002159 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002160 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002161 __set_long_pointer(__p);
2162 __set_long_cap(__cap+1);
2163 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2164 __set_long_size(__old_sz);
2165 traits_type::assign(__p[__old_sz], value_type());
2166}
2167
2168template <class _CharT, class _Traits, class _Allocator>
2169void
2170basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2171 size_type __n_copy, size_type __n_del, size_type __n_add)
2172{
2173 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00002174 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002175 this->__throw_length_error();
2176 pointer __old_p = __get_pointer();
2177 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002178 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002179 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002180 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002181 __invalidate_all_iterators();
2182 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002183 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2184 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002185 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2186 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002187 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2188 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2189 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002190 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002191 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002192 __set_long_pointer(__p);
2193 __set_long_cap(__cap+1);
2194}
2195
2196// assign
2197
2198template <class _CharT, class _Traits, class _Allocator>
2199basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002200basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002201{
Alp Tokerec34c482014-05-15 11:27:39 +00002202 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002203 size_type __cap = capacity();
2204 if (__cap >= __n)
2205 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002206 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002207 traits_type::move(__p, __s, __n);
2208 traits_type::assign(__p[__n], value_type());
2209 __set_size(__n);
2210 __invalidate_iterators_past(__n);
2211 }
2212 else
2213 {
2214 size_type __sz = size();
2215 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2216 }
2217 return *this;
2218}
2219
2220template <class _CharT, class _Traits, class _Allocator>
2221basic_string<_CharT, _Traits, _Allocator>&
2222basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2223{
2224 size_type __cap = capacity();
2225 if (__cap < __n)
2226 {
2227 size_type __sz = size();
2228 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2229 }
2230 else
2231 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002232 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002233 traits_type::assign(__p, __n, __c);
2234 traits_type::assign(__p[__n], value_type());
2235 __set_size(__n);
2236 return *this;
2237}
2238
2239template <class _CharT, class _Traits, class _Allocator>
2240basic_string<_CharT, _Traits, _Allocator>&
2241basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2242{
2243 pointer __p;
2244 if (__is_long())
2245 {
2246 __p = __get_long_pointer();
2247 __set_long_size(1);
2248 }
2249 else
2250 {
2251 __p = __get_short_pointer();
2252 __set_short_size(1);
2253 }
2254 traits_type::assign(*__p, __c);
2255 traits_type::assign(*++__p, value_type());
2256 __invalidate_iterators_past(1);
2257 return *this;
2258}
2259
2260template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002261basic_string<_CharT, _Traits, _Allocator>&
2262basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2263{
2264 if (this != &__str)
2265 {
2266 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00002267 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00002268 }
2269 return *this;
2270}
2271
Eric Fiselier3e928972017-04-19 00:28:44 +00002272#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante32b5e22010-11-17 17:55:08 +00002273
2274template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002275inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002276void
2277basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002278 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002279{
2280 if (__alloc() != __str.__alloc())
2281 assign(__str);
2282 else
2283 __move_assign(__str, true_type());
2284}
2285
2286template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002287inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002288void
2289basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002290#if _LIBCPP_STD_VER > 14
2291 _NOEXCEPT
2292#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002293 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002294#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002295{
Vedant Kumar2b588cb2018-03-08 21:15:26 +00002296 __clear_and_shrink();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002297 __r_.first() = __str.__r_.first();
2298 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002299 __str.__zero();
2300}
2301
2302template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002303inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002304basic_string<_CharT, _Traits, _Allocator>&
2305basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002306 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002307{
2308 __move_assign(__str, integral_constant<bool,
2309 __alloc_traits::propagate_on_container_move_assignment::value>());
2310 return *this;
2311}
2312
2313#endif
2314
2315template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002316template<class _InputIterator>
2317typename enable_if
2318<
Marshall Clowdf9db312016-01-13 21:54:34 +00002319 __is_exactly_input_iterator <_InputIterator>::value
2320 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002321 basic_string<_CharT, _Traits, _Allocator>&
2322>::type
2323basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2324{
Marshall Clowd979eed2016-09-05 01:54:30 +00002325 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002326 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002327 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002328}
2329
2330template <class _CharT, class _Traits, class _Allocator>
2331template<class _ForwardIterator>
2332typename enable_if
2333<
Marshall Clowdf9db312016-01-13 21:54:34 +00002334 __is_forward_iterator<_ForwardIterator>::value
2335 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002336 basic_string<_CharT, _Traits, _Allocator>&
2337>::type
2338basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2339{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002340 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002341 size_type __cap = capacity();
2342 if (__cap < __n)
2343 {
2344 size_type __sz = size();
2345 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2346 }
2347 else
2348 __invalidate_iterators_past(__n);
2349 pointer __p = __get_pointer();
2350 for (; __first != __last; ++__first, ++__p)
2351 traits_type::assign(*__p, *__first);
2352 traits_type::assign(*__p, value_type());
2353 __set_size(__n);
2354 return *this;
2355}
2356
2357template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002358basic_string<_CharT, _Traits, _Allocator>&
2359basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2360{
2361 size_type __sz = __str.size();
2362 if (__pos > __sz)
2363 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002364 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002365}
2366
2367template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002368template <class _Tp>
2369typename enable_if
2370<
2371 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002372 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002373>::type
2374basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002375{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002376 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002377 size_type __sz = __sv.size();
2378 if (__pos > __sz)
2379 this->__throw_out_of_range();
2380 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2381}
2382
2383
2384template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002385basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002386basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002387{
Alp Tokerec34c482014-05-15 11:27:39 +00002388 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002389 return assign(__s, traits_type::length(__s));
2390}
2391
2392// append
2393
2394template <class _CharT, class _Traits, class _Allocator>
2395basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002396basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002397{
Alp Tokerec34c482014-05-15 11:27:39 +00002398 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002399 size_type __cap = capacity();
2400 size_type __sz = size();
2401 if (__cap - __sz >= __n)
2402 {
2403 if (__n)
2404 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002405 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002406 traits_type::copy(__p + __sz, __s, __n);
2407 __sz += __n;
2408 __set_size(__sz);
2409 traits_type::assign(__p[__sz], value_type());
2410 }
2411 }
2412 else
2413 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2414 return *this;
2415}
2416
2417template <class _CharT, class _Traits, class _Allocator>
2418basic_string<_CharT, _Traits, _Allocator>&
2419basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2420{
2421 if (__n)
2422 {
2423 size_type __cap = capacity();
2424 size_type __sz = size();
2425 if (__cap - __sz < __n)
2426 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2427 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002428 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002429 __sz += __n;
2430 __set_size(__sz);
2431 traits_type::assign(__p[__sz], value_type());
2432 }
2433 return *this;
2434}
2435
2436template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierf9782de2018-11-26 20:15:38 +00002437inline void
2438basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
2439{
2440 if (__n)
2441 {
2442 size_type __cap = capacity();
2443 size_type __sz = size();
2444 if (__cap - __sz < __n)
2445 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2446 pointer __p = __get_pointer();
2447 __sz += __n;
2448 __set_size(__sz);
2449 traits_type::assign(__p[__sz], value_type());
2450 }
2451}
2452
2453template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002454void
2455basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2456{
Howard Hinnant15467182013-04-30 21:44:48 +00002457 bool __is_short = !__is_long();
2458 size_type __cap;
2459 size_type __sz;
2460 if (__is_short)
2461 {
2462 __cap = __min_cap - 1;
2463 __sz = __get_short_size();
2464 }
2465 else
2466 {
2467 __cap = __get_long_cap() - 1;
2468 __sz = __get_long_size();
2469 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002470 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002471 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002472 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002473 __is_short = !__is_long();
2474 }
2475 pointer __p;
2476 if (__is_short)
2477 {
2478 __p = __get_short_pointer() + __sz;
2479 __set_short_size(__sz+1);
2480 }
2481 else
2482 {
2483 __p = __get_long_pointer() + __sz;
2484 __set_long_size(__sz+1);
2485 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002486 traits_type::assign(*__p, __c);
2487 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002488}
2489
Marshall Clowac655ef2016-09-07 03:32:06 +00002490template <class _Tp>
Marshall Clowd979eed2016-09-05 01:54:30 +00002491bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2492{
2493 return __first <= __p && __p < __last;
2494}
2495
Marshall Clowac655ef2016-09-07 03:32:06 +00002496template <class _Tp1, class _Tp2>
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00002497bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
Marshall Clowac655ef2016-09-07 03:32:06 +00002498{
2499 return false;
2500}
2501
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002502template <class _CharT, class _Traits, class _Allocator>
2503template<class _ForwardIterator>
Eric Fiselier026d38e2016-10-31 02:46:25 +00002504basic_string<_CharT, _Traits, _Allocator>&
2505basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2506 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002507{
Eric Fiselier026d38e2016-10-31 02:46:25 +00002508 static_assert(__is_forward_iterator<_ForwardIterator>::value,
2509 "function requires a ForwardIterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002510 size_type __sz = size();
2511 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002512 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002513 if (__n)
2514 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002515 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2516 _CharRef __tmp_ref = *__first;
2517 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002518 {
2519 const basic_string __temp (__first, __last, __alloc());
2520 append(__temp.data(), __temp.size());
2521 }
2522 else
2523 {
2524 if (__cap - __sz < __n)
2525 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2526 pointer __p = __get_pointer() + __sz;
2527 for (; __first != __last; ++__p, ++__first)
2528 traits_type::assign(*__p, *__first);
2529 traits_type::assign(*__p, value_type());
2530 __set_size(__sz + __n);
2531 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002532 }
2533 return *this;
2534}
2535
2536template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002537inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002538basic_string<_CharT, _Traits, _Allocator>&
2539basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2540{
2541 return append(__str.data(), __str.size());
2542}
2543
2544template <class _CharT, class _Traits, class _Allocator>
2545basic_string<_CharT, _Traits, _Allocator>&
2546basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2547{
2548 size_type __sz = __str.size();
2549 if (__pos > __sz)
2550 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002551 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002552}
2553
2554template <class _CharT, class _Traits, class _Allocator>
Marshall Clow42a87db2016-10-03 23:40:48 +00002555template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002556 typename enable_if
2557 <
2558 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2559 basic_string<_CharT, _Traits, _Allocator>&
2560 >::type
2561basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002562{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002563 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002564 size_type __sz = __sv.size();
2565 if (__pos > __sz)
2566 this->__throw_out_of_range();
2567 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2568}
2569
2570template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002571basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002572basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002573{
Alp Tokerec34c482014-05-15 11:27:39 +00002574 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002575 return append(__s, traits_type::length(__s));
2576}
2577
2578// insert
2579
2580template <class _CharT, class _Traits, class _Allocator>
2581basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002582basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002583{
Alp Tokerec34c482014-05-15 11:27:39 +00002584 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002585 size_type __sz = size();
2586 if (__pos > __sz)
2587 this->__throw_out_of_range();
2588 size_type __cap = capacity();
2589 if (__cap - __sz >= __n)
2590 {
2591 if (__n)
2592 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002593 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002594 size_type __n_move = __sz - __pos;
2595 if (__n_move != 0)
2596 {
2597 if (__p + __pos <= __s && __s < __p + __sz)
2598 __s += __n;
2599 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2600 }
2601 traits_type::move(__p + __pos, __s, __n);
2602 __sz += __n;
2603 __set_size(__sz);
2604 traits_type::assign(__p[__sz], value_type());
2605 }
2606 }
2607 else
2608 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2609 return *this;
2610}
2611
2612template <class _CharT, class _Traits, class _Allocator>
2613basic_string<_CharT, _Traits, _Allocator>&
2614basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2615{
2616 size_type __sz = size();
2617 if (__pos > __sz)
2618 this->__throw_out_of_range();
2619 if (__n)
2620 {
2621 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002622 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002623 if (__cap - __sz >= __n)
2624 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002625 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002626 size_type __n_move = __sz - __pos;
2627 if (__n_move != 0)
2628 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2629 }
2630 else
2631 {
2632 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002633 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002634 }
2635 traits_type::assign(__p + __pos, __n, __c);
2636 __sz += __n;
2637 __set_size(__sz);
2638 traits_type::assign(__p[__sz], value_type());
2639 }
2640 return *this;
2641}
2642
2643template <class _CharT, class _Traits, class _Allocator>
2644template<class _InputIterator>
2645typename enable_if
2646<
Marshall Clowdf9db312016-01-13 21:54:34 +00002647 __is_exactly_input_iterator<_InputIterator>::value
2648 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2649 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002650>::type
2651basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2652{
Howard Hinnant499cea12013-08-23 17:37:05 +00002653#if _LIBCPP_DEBUG_LEVEL >= 2
2654 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2655 "string::insert(iterator, range) called with an iterator not"
2656 " referring to this string");
2657#endif
Marshall Clowd979eed2016-09-05 01:54:30 +00002658 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002659 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002660}
2661
2662template <class _CharT, class _Traits, class _Allocator>
2663template<class _ForwardIterator>
2664typename enable_if
2665<
Marshall Clowdf9db312016-01-13 21:54:34 +00002666 __is_forward_iterator<_ForwardIterator>::value
2667 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002668 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2669>::type
2670basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2671{
Howard Hinnant499cea12013-08-23 17:37:05 +00002672#if _LIBCPP_DEBUG_LEVEL >= 2
2673 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2674 "string::insert(iterator, range) called with an iterator not"
2675 " referring to this string");
2676#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002677 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002678 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002679 if (__n)
2680 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002681 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2682 _CharRef __tmp_char = *__first;
2683 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002684 {
2685 const basic_string __temp(__first, __last, __alloc());
2686 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2687 }
2688
2689 size_type __sz = size();
2690 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002691 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002692 if (__cap - __sz >= __n)
2693 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002694 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002695 size_type __n_move = __sz - __ip;
2696 if (__n_move != 0)
2697 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2698 }
2699 else
2700 {
2701 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002702 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002703 }
2704 __sz += __n;
2705 __set_size(__sz);
2706 traits_type::assign(__p[__sz], value_type());
2707 for (__p += __ip; __first != __last; ++__p, ++__first)
2708 traits_type::assign(*__p, *__first);
2709 }
2710 return begin() + __ip;
2711}
2712
2713template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002714inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002715basic_string<_CharT, _Traits, _Allocator>&
2716basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2717{
2718 return insert(__pos1, __str.data(), __str.size());
2719}
2720
2721template <class _CharT, class _Traits, class _Allocator>
2722basic_string<_CharT, _Traits, _Allocator>&
2723basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2724 size_type __pos2, size_type __n)
2725{
2726 size_type __str_sz = __str.size();
2727 if (__pos2 > __str_sz)
2728 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002729 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002730}
2731
2732template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002733template <class _Tp>
2734typename enable_if
2735<
2736 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002737 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002738>::type
2739basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002740 size_type __pos2, size_type __n)
2741{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002742 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002743 size_type __str_sz = __sv.size();
2744 if (__pos2 > __str_sz)
2745 this->__throw_out_of_range();
2746 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2747}
2748
2749template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002750basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002751basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002752{
Alp Tokerec34c482014-05-15 11:27:39 +00002753 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002754 return insert(__pos, __s, traits_type::length(__s));
2755}
2756
2757template <class _CharT, class _Traits, class _Allocator>
2758typename basic_string<_CharT, _Traits, _Allocator>::iterator
2759basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2760{
2761 size_type __ip = static_cast<size_type>(__pos - begin());
2762 size_type __sz = size();
2763 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002764 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002765 if (__cap == __sz)
2766 {
2767 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002768 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002769 }
2770 else
2771 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002772 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002773 size_type __n_move = __sz - __ip;
2774 if (__n_move != 0)
2775 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2776 }
2777 traits_type::assign(__p[__ip], __c);
2778 traits_type::assign(__p[++__sz], value_type());
2779 __set_size(__sz);
2780 return begin() + static_cast<difference_type>(__ip);
2781}
2782
2783template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002784inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002785typename basic_string<_CharT, _Traits, _Allocator>::iterator
2786basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2787{
Howard Hinnant499cea12013-08-23 17:37:05 +00002788#if _LIBCPP_DEBUG_LEVEL >= 2
2789 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2790 "string::insert(iterator, n, value) called with an iterator not"
2791 " referring to this string");
2792#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002793 difference_type __p = __pos - begin();
2794 insert(static_cast<size_type>(__p), __n, __c);
2795 return begin() + __p;
2796}
2797
2798// replace
2799
2800template <class _CharT, class _Traits, class _Allocator>
2801basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002802basic_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 +00002803 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002804{
Alp Tokerec34c482014-05-15 11:27:39 +00002805 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002806 size_type __sz = size();
2807 if (__pos > __sz)
2808 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002809 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002810 size_type __cap = capacity();
2811 if (__cap - __sz + __n1 >= __n2)
2812 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002813 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002814 if (__n1 != __n2)
2815 {
2816 size_type __n_move = __sz - __pos - __n1;
2817 if (__n_move != 0)
2818 {
2819 if (__n1 > __n2)
2820 {
2821 traits_type::move(__p + __pos, __s, __n2);
2822 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2823 goto __finish;
2824 }
2825 if (__p + __pos < __s && __s < __p + __sz)
2826 {
2827 if (__p + __pos + __n1 <= __s)
2828 __s += __n2 - __n1;
2829 else // __p + __pos < __s < __p + __pos + __n1
2830 {
2831 traits_type::move(__p + __pos, __s, __n1);
2832 __pos += __n1;
2833 __s += __n2;
2834 __n2 -= __n1;
2835 __n1 = 0;
2836 }
2837 }
2838 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2839 }
2840 }
2841 traits_type::move(__p + __pos, __s, __n2);
2842__finish:
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002843// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
2844// but this is a safe operation, so we disable the check.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002845 __sz += __n2 - __n1;
2846 __set_size(__sz);
2847 __invalidate_iterators_past(__sz);
2848 traits_type::assign(__p[__sz], value_type());
2849 }
2850 else
2851 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2852 return *this;
2853}
2854
2855template <class _CharT, class _Traits, class _Allocator>
2856basic_string<_CharT, _Traits, _Allocator>&
2857basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002858 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002859{
2860 size_type __sz = size();
2861 if (__pos > __sz)
2862 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002863 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002864 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002865 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002866 if (__cap - __sz + __n1 >= __n2)
2867 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002868 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002869 if (__n1 != __n2)
2870 {
2871 size_type __n_move = __sz - __pos - __n1;
2872 if (__n_move != 0)
2873 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2874 }
2875 }
2876 else
2877 {
2878 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002879 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002880 }
2881 traits_type::assign(__p + __pos, __n2, __c);
2882 __sz += __n2 - __n1;
2883 __set_size(__sz);
2884 __invalidate_iterators_past(__sz);
2885 traits_type::assign(__p[__sz], value_type());
2886 return *this;
2887}
2888
2889template <class _CharT, class _Traits, class _Allocator>
2890template<class _InputIterator>
2891typename enable_if
2892<
2893 __is_input_iterator<_InputIterator>::value,
2894 basic_string<_CharT, _Traits, _Allocator>&
2895>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002896basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002897 _InputIterator __j1, _InputIterator __j2)
2898{
Marshall Clowd979eed2016-09-05 01:54:30 +00002899 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002900 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002901}
2902
2903template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002904inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002905basic_string<_CharT, _Traits, _Allocator>&
2906basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2907{
2908 return replace(__pos1, __n1, __str.data(), __str.size());
2909}
2910
2911template <class _CharT, class _Traits, class _Allocator>
2912basic_string<_CharT, _Traits, _Allocator>&
2913basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2914 size_type __pos2, size_type __n2)
2915{
2916 size_type __str_sz = __str.size();
2917 if (__pos2 > __str_sz)
2918 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002919 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002920}
2921
2922template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002923template <class _Tp>
2924typename enable_if
2925<
Marshall Clowf1729d92017-11-15 20:02:27 +00002926 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2927 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002928>::type
2929basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002930 size_type __pos2, size_type __n2)
2931{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002932 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002933 size_type __str_sz = __sv.size();
2934 if (__pos2 > __str_sz)
2935 this->__throw_out_of_range();
2936 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2937}
2938
2939template <class _CharT, class _Traits, class _Allocator>
2940basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002941basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002942{
Alp Tokerec34c482014-05-15 11:27:39 +00002943 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002944 return replace(__pos, __n1, __s, traits_type::length(__s));
2945}
2946
2947template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002948inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002949basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002950basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002951{
2952 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2953 __str.data(), __str.size());
2954}
2955
2956template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002957inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002958basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002959basic_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 +00002960{
2961 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2962}
2963
2964template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002965inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002966basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002967basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002968{
2969 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2970}
2971
2972template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002973inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002974basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002975basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002976{
2977 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2978}
2979
2980// erase
2981
2982template <class _CharT, class _Traits, class _Allocator>
2983basic_string<_CharT, _Traits, _Allocator>&
2984basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2985{
2986 size_type __sz = size();
2987 if (__pos > __sz)
2988 this->__throw_out_of_range();
2989 if (__n)
2990 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002991 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002992 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002993 size_type __n_move = __sz - __pos - __n;
2994 if (__n_move != 0)
2995 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2996 __sz -= __n;
2997 __set_size(__sz);
2998 __invalidate_iterators_past(__sz);
2999 traits_type::assign(__p[__sz], value_type());
3000 }
3001 return *this;
3002}
3003
3004template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003005inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003006typename basic_string<_CharT, _Traits, _Allocator>::iterator
3007basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3008{
Howard Hinnant499cea12013-08-23 17:37:05 +00003009#if _LIBCPP_DEBUG_LEVEL >= 2
3010 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3011 "string::erase(iterator) called with an iterator not"
3012 " referring to this string");
3013#endif
3014 _LIBCPP_ASSERT(__pos != end(),
3015 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003016 iterator __b = begin();
3017 size_type __r = static_cast<size_type>(__pos - __b);
3018 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00003019 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003020}
3021
3022template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003023inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003024typename basic_string<_CharT, _Traits, _Allocator>::iterator
3025basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3026{
Howard Hinnant499cea12013-08-23 17:37:05 +00003027#if _LIBCPP_DEBUG_LEVEL >= 2
3028 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3029 "string::erase(iterator, iterator) called with an iterator not"
3030 " referring to this string");
3031#endif
3032 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003033 iterator __b = begin();
3034 size_type __r = static_cast<size_type>(__first - __b);
3035 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00003036 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003037}
3038
3039template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003040inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003041void
3042basic_string<_CharT, _Traits, _Allocator>::pop_back()
3043{
Howard Hinnant499cea12013-08-23 17:37:05 +00003044 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003045 size_type __sz;
3046 if (__is_long())
3047 {
3048 __sz = __get_long_size() - 1;
3049 __set_long_size(__sz);
3050 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3051 }
3052 else
3053 {
3054 __sz = __get_short_size() - 1;
3055 __set_short_size(__sz);
3056 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3057 }
3058 __invalidate_iterators_past(__sz);
3059}
3060
3061template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003062inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003063void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003064basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003065{
3066 __invalidate_all_iterators();
3067 if (__is_long())
3068 {
3069 traits_type::assign(*__get_long_pointer(), value_type());
3070 __set_long_size(0);
3071 }
3072 else
3073 {
3074 traits_type::assign(*__get_short_pointer(), value_type());
3075 __set_short_size(0);
3076 }
3077}
3078
3079template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003080inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003081void
3082basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3083{
3084 if (__is_long())
3085 {
3086 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3087 __set_long_size(__pos);
3088 }
3089 else
3090 {
3091 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3092 __set_short_size(__pos);
3093 }
3094 __invalidate_iterators_past(__pos);
3095}
3096
3097template <class _CharT, class _Traits, class _Allocator>
3098void
3099basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3100{
3101 size_type __sz = size();
3102 if (__n > __sz)
3103 append(__n - __sz, __c);
3104 else
3105 __erase_to_end(__n);
3106}
3107
3108template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierf9782de2018-11-26 20:15:38 +00003109inline void
3110basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
3111{
3112 size_type __sz = size();
3113 if (__n > __sz) {
3114 __append_default_init(__n - __sz);
3115 } else
3116 __erase_to_end(__n);
3117}
3118
3119template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003120inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003121typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003122basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003123{
Howard Hinnante32b5e22010-11-17 17:55:08 +00003124 size_type __m = __alloc_traits::max_size(__alloc());
Eric Fiselier5ccf0432017-10-17 13:16:01 +00003125#ifdef _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00003126 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003127#else
Marshall Clow09f85502013-10-31 17:23:08 +00003128 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003129#endif
3130}
3131
3132template <class _CharT, class _Traits, class _Allocator>
3133void
3134basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3135{
3136 if (__res_arg > max_size())
3137 this->__throw_length_error();
3138 size_type __cap = capacity();
3139 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003140 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003141 __res_arg = __recommend(__res_arg);
3142 if (__res_arg != __cap)
3143 {
3144 pointer __new_data, __p;
3145 bool __was_long, __now_long;
3146 if (__res_arg == __min_cap - 1)
3147 {
3148 __was_long = true;
3149 __now_long = false;
3150 __new_data = __get_short_pointer();
3151 __p = __get_long_pointer();
3152 }
3153 else
3154 {
3155 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003156 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003157 else
3158 {
3159 #ifndef _LIBCPP_NO_EXCEPTIONS
3160 try
3161 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003162 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00003163 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003164 #ifndef _LIBCPP_NO_EXCEPTIONS
3165 }
3166 catch (...)
3167 {
3168 return;
3169 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003170 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003171 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003172 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003173 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003174 }
3175 __now_long = true;
3176 __was_long = __is_long();
3177 __p = __get_pointer();
3178 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003179 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3180 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003181 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003182 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003183 if (__now_long)
3184 {
3185 __set_long_cap(__res_arg+1);
3186 __set_long_size(__sz);
3187 __set_long_pointer(__new_data);
3188 }
3189 else
3190 __set_short_size(__sz);
3191 __invalidate_all_iterators();
3192 }
3193}
3194
3195template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003196inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003197typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003198basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003199{
Howard Hinnant499cea12013-08-23 17:37:05 +00003200 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003201 return *(data() + __pos);
3202}
3203
3204template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003205inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003206typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003207basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003208{
Howard Hinnant499cea12013-08-23 17:37:05 +00003209 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003210 return *(__get_pointer() + __pos);
3211}
3212
3213template <class _CharT, class _Traits, class _Allocator>
3214typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3215basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3216{
3217 if (__n >= size())
3218 this->__throw_out_of_range();
3219 return (*this)[__n];
3220}
3221
3222template <class _CharT, class _Traits, class _Allocator>
3223typename basic_string<_CharT, _Traits, _Allocator>::reference
3224basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3225{
3226 if (__n >= size())
3227 this->__throw_out_of_range();
3228 return (*this)[__n];
3229}
3230
3231template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003232inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003233typename basic_string<_CharT, _Traits, _Allocator>::reference
3234basic_string<_CharT, _Traits, _Allocator>::front()
3235{
Howard Hinnant499cea12013-08-23 17:37:05 +00003236 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003237 return *__get_pointer();
3238}
3239
3240template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003241inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003242typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3243basic_string<_CharT, _Traits, _Allocator>::front() const
3244{
Howard Hinnant499cea12013-08-23 17:37:05 +00003245 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003246 return *data();
3247}
3248
3249template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003250inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003251typename basic_string<_CharT, _Traits, _Allocator>::reference
3252basic_string<_CharT, _Traits, _Allocator>::back()
3253{
Howard Hinnant499cea12013-08-23 17:37:05 +00003254 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003255 return *(__get_pointer() + size() - 1);
3256}
3257
3258template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003259inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003260typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3261basic_string<_CharT, _Traits, _Allocator>::back() const
3262{
Howard Hinnant499cea12013-08-23 17:37:05 +00003263 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003264 return *(data() + size() - 1);
3265}
3266
3267template <class _CharT, class _Traits, class _Allocator>
3268typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003269basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003270{
3271 size_type __sz = size();
3272 if (__pos > __sz)
3273 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003274 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003275 traits_type::copy(__s, data() + __pos, __rlen);
3276 return __rlen;
3277}
3278
3279template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003280inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003281basic_string<_CharT, _Traits, _Allocator>
3282basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3283{
3284 return basic_string(*this, __pos, __n, __alloc());
3285}
3286
3287template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003288inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003289void
3290basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00003291#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00003292 _NOEXCEPT_DEBUG
Marshall Clow7d914d12015-07-13 20:04:56 +00003293#else
Eric Fiselier47257c42016-12-28 05:53:01 +00003294 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00003295 __is_nothrow_swappable<allocator_type>::value)
3296#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003297{
Howard Hinnant499cea12013-08-23 17:37:05 +00003298#if _LIBCPP_DEBUG_LEVEL >= 2
3299 if (!__is_long())
3300 __get_db()->__invalidate_all(this);
3301 if (!__str.__is_long())
3302 __get_db()->__invalidate_all(&__str);
3303 __get_db()->swap(this, &__str);
3304#endif
Eric Fiselier47257c42016-12-28 05:53:01 +00003305 _LIBCPP_ASSERT(
3306 __alloc_traits::propagate_on_container_swap::value ||
3307 __alloc_traits::is_always_equal::value ||
3308 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnant0949eed2011-06-30 21:18:19 +00003309 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00003310 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003311}
3312
3313// find
3314
3315template <class _Traits>
3316struct _LIBCPP_HIDDEN __traits_eq
3317{
3318 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003319 _LIBCPP_INLINE_VISIBILITY
3320 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3321 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003322};
3323
3324template<class _CharT, class _Traits, class _Allocator>
3325typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003326basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003327 size_type __pos,
3328 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003329{
Alp Tokerec34c482014-05-15 11:27:39 +00003330 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003331 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003332 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003333}
3334
3335template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003336inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003337typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003338basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3339 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003340{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003341 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003342 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003343}
3344
3345template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003346template <class _Tp>
3347typename enable_if
3348<
3349 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3350 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3351>::type
3352basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
3353 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003354{
Marshall Clow64c10d02018-07-02 18:41:15 +00003355 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003356 return __str_find<value_type, size_type, traits_type, npos>
3357 (data(), size(), __sv.data(), __pos, __sv.size());
3358}
3359
3360template<class _CharT, class _Traits, class _Allocator>
3361inline _LIBCPP_INLINE_VISIBILITY
3362typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003363basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003364 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003365{
Alp Tokerec34c482014-05-15 11:27:39 +00003366 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003367 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003368 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003369}
3370
3371template<class _CharT, class _Traits, class _Allocator>
3372typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003373basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3374 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003375{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003376 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003377 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003378}
3379
3380// rfind
3381
3382template<class _CharT, class _Traits, class _Allocator>
3383typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003384basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003385 size_type __pos,
3386 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003387{
Alp Tokerec34c482014-05-15 11:27:39 +00003388 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003389 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003390 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003391}
3392
3393template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003394inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003395typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003396basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3397 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003398{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003399 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003400 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003401}
3402
3403template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003404template <class _Tp>
3405typename enable_if
3406<
3407 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3408 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3409>::type
3410basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
3411 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003412{
Marshall Clow64c10d02018-07-02 18:41:15 +00003413 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003414 return __str_rfind<value_type, size_type, traits_type, npos>
3415 (data(), size(), __sv.data(), __pos, __sv.size());
3416}
3417
3418template<class _CharT, class _Traits, class _Allocator>
3419inline _LIBCPP_INLINE_VISIBILITY
3420typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003421basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003422 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003423{
Alp Tokerec34c482014-05-15 11:27:39 +00003424 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003425 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003426 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003427}
3428
3429template<class _CharT, class _Traits, class _Allocator>
3430typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003431basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3432 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003433{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003434 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003435 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003436}
3437
3438// find_first_of
3439
3440template<class _CharT, class _Traits, class _Allocator>
3441typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003442basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003443 size_type __pos,
3444 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003445{
Alp Tokerec34c482014-05-15 11:27:39 +00003446 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003447 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003448 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003449}
3450
3451template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003452inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003453typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003454basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3455 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003456{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003457 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003458 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003459}
3460
3461template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003462template <class _Tp>
3463typename enable_if
3464<
3465 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3466 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3467>::type
3468basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
3469 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003470{
Marshall Clow64c10d02018-07-02 18:41:15 +00003471 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003472 return __str_find_first_of<value_type, size_type, traits_type, npos>
3473 (data(), size(), __sv.data(), __pos, __sv.size());
3474}
3475
3476template<class _CharT, class _Traits, class _Allocator>
3477inline _LIBCPP_INLINE_VISIBILITY
3478typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003479basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003480 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003481{
Alp Tokerec34c482014-05-15 11:27:39 +00003482 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003483 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003484 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003485}
3486
3487template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003488inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003489typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003490basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3491 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003492{
3493 return find(__c, __pos);
3494}
3495
3496// find_last_of
3497
3498template<class _CharT, class _Traits, class _Allocator>
3499typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003500basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003501 size_type __pos,
3502 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003503{
Alp Tokerec34c482014-05-15 11:27:39 +00003504 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003505 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003506 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003507}
3508
3509template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003510inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003511typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003512basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3513 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003514{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003515 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003516 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003517}
3518
3519template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003520template <class _Tp>
3521typename enable_if
3522<
3523 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3524 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3525>::type
3526basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
3527 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003528{
Marshall Clow64c10d02018-07-02 18:41:15 +00003529 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003530 return __str_find_last_of<value_type, size_type, traits_type, npos>
3531 (data(), size(), __sv.data(), __pos, __sv.size());
3532}
3533
3534template<class _CharT, class _Traits, class _Allocator>
3535inline _LIBCPP_INLINE_VISIBILITY
3536typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003537basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003538 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003539{
Alp Tokerec34c482014-05-15 11:27:39 +00003540 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003541 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003542 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003543}
3544
3545template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003546inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003547typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003548basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3549 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003550{
3551 return rfind(__c, __pos);
3552}
3553
3554// find_first_not_of
3555
3556template<class _CharT, class _Traits, class _Allocator>
3557typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003558basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003559 size_type __pos,
3560 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003561{
Alp Tokerec34c482014-05-15 11:27:39 +00003562 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003563 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003564 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003565}
3566
3567template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003568inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003569typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003570basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3571 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003572{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003573 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003574 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003575}
3576
3577template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003578template <class _Tp>
3579typename enable_if
3580<
3581 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3582 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3583>::type
3584basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
3585 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003586{
Marshall Clow64c10d02018-07-02 18:41:15 +00003587 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003588 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3589 (data(), size(), __sv.data(), __pos, __sv.size());
3590}
3591
3592template<class _CharT, class _Traits, class _Allocator>
3593inline _LIBCPP_INLINE_VISIBILITY
3594typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003595basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003596 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003597{
Alp Tokerec34c482014-05-15 11:27:39 +00003598 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003599 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003600 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003601}
3602
3603template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003604inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003605typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003606basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3607 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003608{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003609 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003610 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003611}
3612
3613// find_last_not_of
3614
3615template<class _CharT, class _Traits, class _Allocator>
3616typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003617basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003618 size_type __pos,
3619 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003620{
Alp Tokerec34c482014-05-15 11:27:39 +00003621 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003622 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003623 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003624}
3625
3626template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003627inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003628typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003629basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3630 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003631{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003632 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003633 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003634}
3635
3636template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003637template <class _Tp>
3638typename enable_if
3639<
3640 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3641 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3642>::type
3643basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
3644 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003645{
Marshall Clow64c10d02018-07-02 18:41:15 +00003646 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003647 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3648 (data(), size(), __sv.data(), __pos, __sv.size());
3649}
3650
3651template<class _CharT, class _Traits, class _Allocator>
3652inline _LIBCPP_INLINE_VISIBILITY
3653typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003654basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003655 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003656{
Alp Tokerec34c482014-05-15 11:27:39 +00003657 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003658 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003659 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003660}
3661
3662template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003663inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003664typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003665basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3666 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003667{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003668 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003669 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003670}
3671
3672// compare
3673
3674template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003675template <class _Tp>
3676typename enable_if
3677<
3678 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3679 int
3680>::type
3681basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003682{
Marshall Clow64c10d02018-07-02 18:41:15 +00003683 __self_view __sv = __t;
Howard Hinnantfa06d752011-07-24 21:45:06 +00003684 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003685 size_t __rhs_sz = __sv.size();
3686 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:06 +00003687 _VSTD::min(__lhs_sz, __rhs_sz));
3688 if (__result != 0)
3689 return __result;
3690 if (__lhs_sz < __rhs_sz)
3691 return -1;
3692 if (__lhs_sz > __rhs_sz)
3693 return 1;
3694 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003695}
3696
3697template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003698inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003699int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003700basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003701{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003702 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003703}
3704
3705template <class _CharT, class _Traits, class _Allocator>
3706int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003707basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3708 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003709 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003710 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003711{
Alp Tokerec34c482014-05-15 11:27:39 +00003712 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003713 size_type __sz = size();
3714 if (__pos1 > __sz || __n2 == npos)
3715 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003716 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3717 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003718 if (__r == 0)
3719 {
3720 if (__rlen < __n2)
3721 __r = -1;
3722 else if (__rlen > __n2)
3723 __r = 1;
3724 }
3725 return __r;
3726}
3727
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003728template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003729template <class _Tp>
3730typename enable_if
3731<
3732 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3733 int
3734>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003735basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3736 size_type __n1,
Marshall Clow64c10d02018-07-02 18:41:15 +00003737 const _Tp& __t) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003738{
Marshall Clow64c10d02018-07-02 18:41:15 +00003739 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003740 return compare(__pos1, __n1, __sv.data(), __sv.size());
3741}
3742
3743template <class _CharT, class _Traits, class _Allocator>
3744inline _LIBCPP_INLINE_VISIBILITY
3745int
3746basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3747 size_type __n1,
3748 const basic_string& __str) const
3749{
3750 return compare(__pos1, __n1, __str.data(), __str.size());
3751}
3752
3753template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00003754template <class _Tp>
3755typename enable_if
3756<
Marshall Clowf1729d92017-11-15 20:02:27 +00003757 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3758 int
Marshall Clow6ac8de02016-09-24 22:45:42 +00003759>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003760basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3761 size_type __n1,
Marshall Clow6ac8de02016-09-24 22:45:42 +00003762 const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003763 size_type __pos2,
3764 size_type __n2) const
3765{
Marshall Clow6ac8de02016-09-24 22:45:42 +00003766 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003767 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3768}
3769
3770template <class _CharT, class _Traits, class _Allocator>
3771int
3772basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3773 size_type __n1,
3774 const basic_string& __str,
3775 size_type __pos2,
3776 size_type __n2) const
3777{
3778 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3779}
3780
3781template <class _CharT, class _Traits, class _Allocator>
3782int
3783basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3784{
3785 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3786 return compare(0, npos, __s, traits_type::length(__s));
3787}
3788
3789template <class _CharT, class _Traits, class _Allocator>
3790int
3791basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3792 size_type __n1,
3793 const value_type* __s) const
3794{
3795 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3796 return compare(__pos1, __n1, __s, traits_type::length(__s));
3797}
3798
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003799// __invariants
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
3804basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3805{
3806 if (size() > capacity())
3807 return false;
3808 if (capacity() < __min_cap - 1)
3809 return false;
3810 if (data() == 0)
3811 return false;
3812 if (data()[size()] != value_type(0))
3813 return false;
3814 return true;
3815}
3816
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003817// __clear_and_shrink
3818
3819template<class _CharT, class _Traits, class _Allocator>
3820inline _LIBCPP_INLINE_VISIBILITY
3821void
Marshall Clowab343bb2018-05-29 17:04:37 +00003822basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003823{
3824 clear();
3825 if(__is_long())
3826 {
3827 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
3828 __set_long_cap(0);
3829 __set_short_size(0);
3830 }
3831}
3832
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003833// operator==
3834
3835template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003836inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003837bool
3838operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003839 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003840{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003841 size_t __lhs_sz = __lhs.size();
3842 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3843 __rhs.data(),
3844 __lhs_sz) == 0;
3845}
3846
3847template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003848inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003849bool
3850operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3851 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3852{
3853 size_t __lhs_sz = __lhs.size();
3854 if (__lhs_sz != __rhs.size())
3855 return false;
3856 const char* __lp = __lhs.data();
3857 const char* __rp = __rhs.data();
3858 if (__lhs.__is_long())
3859 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3860 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3861 if (*__lp != *__rp)
3862 return false;
3863 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003864}
3865
3866template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003867inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003868bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003869operator==(const _CharT* __lhs,
3870 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003871{
Eric Fiselier4f241822015-08-28 03:02:37 +00003872 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3873 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3874 size_t __lhs_len = _Traits::length(__lhs);
3875 if (__lhs_len != __rhs.size()) return false;
3876 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003877}
3878
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003879template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003880inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003881bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003882operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3883 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003884{
Eric Fiselier4f241822015-08-28 03:02:37 +00003885 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3886 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3887 size_t __rhs_len = _Traits::length(__rhs);
3888 if (__rhs_len != __lhs.size()) return false;
3889 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003890}
3891
Howard Hinnant324bb032010-08-22 00:02:43 +00003892template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003893inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003894bool
3895operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003896 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003897{
3898 return !(__lhs == __rhs);
3899}
3900
3901template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003902inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003903bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003904operator!=(const _CharT* __lhs,
3905 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003906{
3907 return !(__lhs == __rhs);
3908}
3909
3910template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003911inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003912bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003913operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3914 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003915{
3916 return !(__lhs == __rhs);
3917}
3918
3919// operator<
3920
3921template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003922inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003923bool
3924operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003925 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003926{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003927 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003928}
3929
3930template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003931inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003932bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003933operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3934 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003935{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003936 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003937}
3938
3939template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003940inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003941bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003942operator< (const _CharT* __lhs,
3943 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003944{
3945 return __rhs.compare(__lhs) > 0;
3946}
3947
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003948// operator>
3949
3950template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003951inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003952bool
3953operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003954 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003955{
3956 return __rhs < __lhs;
3957}
3958
3959template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003960inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003961bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003962operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3963 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003964{
3965 return __rhs < __lhs;
3966}
3967
3968template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003969inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003970bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003971operator> (const _CharT* __lhs,
3972 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003973{
3974 return __rhs < __lhs;
3975}
3976
3977// operator<=
3978
3979template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003980inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003981bool
3982operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003983 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003984{
3985 return !(__rhs < __lhs);
3986}
3987
3988template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003989inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003990bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003991operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3992 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003993{
3994 return !(__rhs < __lhs);
3995}
3996
3997template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003998inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003999bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00004000operator<=(const _CharT* __lhs,
4001 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004002{
4003 return !(__rhs < __lhs);
4004}
4005
4006// operator>=
4007
4008template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004009inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004010bool
4011operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00004012 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004013{
4014 return !(__lhs < __rhs);
4015}
4016
4017template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004018inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004019bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00004020operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4021 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004022{
4023 return !(__lhs < __rhs);
4024}
4025
4026template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004027inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004028bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00004029operator>=(const _CharT* __lhs,
4030 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004031{
4032 return !(__lhs < __rhs);
4033}
4034
4035// operator +
4036
4037template<class _CharT, class _Traits, class _Allocator>
4038basic_string<_CharT, _Traits, _Allocator>
4039operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4040 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4041{
4042 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4043 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4044 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4045 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4046 __r.append(__rhs.data(), __rhs_sz);
4047 return __r;
4048}
4049
4050template<class _CharT, class _Traits, class _Allocator>
4051basic_string<_CharT, _Traits, _Allocator>
4052operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4053{
4054 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4055 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4056 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4057 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4058 __r.append(__rhs.data(), __rhs_sz);
4059 return __r;
4060}
4061
4062template<class _CharT, class _Traits, class _Allocator>
4063basic_string<_CharT, _Traits, _Allocator>
4064operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4065{
4066 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4067 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4068 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4069 __r.append(__rhs.data(), __rhs_sz);
4070 return __r;
4071}
4072
4073template<class _CharT, class _Traits, class _Allocator>
Louis Dionneee6e0ce2018-11-21 17:00:52 +00004074inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004075basic_string<_CharT, _Traits, _Allocator>
4076operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4077{
4078 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4079 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4080 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4081 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4082 __r.append(__rhs, __rhs_sz);
4083 return __r;
4084}
4085
4086template<class _CharT, class _Traits, class _Allocator>
4087basic_string<_CharT, _Traits, _Allocator>
4088operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4089{
4090 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4091 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4092 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4093 __r.push_back(__rhs);
4094 return __r;
4095}
4096
Eric Fiselier3e928972017-04-19 00:28:44 +00004097#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004098
4099template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004100inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004101basic_string<_CharT, _Traits, _Allocator>
4102operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4103{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004104 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004105}
4106
4107template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004108inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004109basic_string<_CharT, _Traits, _Allocator>
4110operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4111{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004112 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004113}
4114
4115template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004116inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004117basic_string<_CharT, _Traits, _Allocator>
4118operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4119{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004120 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004121}
4122
4123template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004124inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004125basic_string<_CharT, _Traits, _Allocator>
4126operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4127{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004128 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004129}
4130
4131template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004132inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004133basic_string<_CharT, _Traits, _Allocator>
4134operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4135{
4136 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004137 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004138}
4139
4140template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004141inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004142basic_string<_CharT, _Traits, _Allocator>
4143operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4144{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004145 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004146}
4147
4148template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004149inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004150basic_string<_CharT, _Traits, _Allocator>
4151operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4152{
4153 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004154 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004155}
4156
Eric Fiselier3e928972017-04-19 00:28:44 +00004157#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004158
4159// swap
4160
4161template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004162inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004163void
Howard Hinnanta6119a82011-05-29 19:57:12 +00004164swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00004165 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4166 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004167{
4168 __lhs.swap(__rhs);
4169}
4170
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004171#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
4172
4173typedef basic_string<char16_t> u16string;
4174typedef basic_string<char32_t> u32string;
4175
Howard Hinnant324bb032010-08-22 00:02:43 +00004176#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004177
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004178_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4179_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4180_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4181_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4182_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004183
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004184_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4185_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4186_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004187
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004188_LIBCPP_FUNC_VIS string to_string(int __val);
4189_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4190_LIBCPP_FUNC_VIS string to_string(long __val);
4191_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4192_LIBCPP_FUNC_VIS string to_string(long long __val);
4193_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4194_LIBCPP_FUNC_VIS string to_string(float __val);
4195_LIBCPP_FUNC_VIS string to_string(double __val);
4196_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004197
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004198_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4199_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4200_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4201_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4202_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004203
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004204_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4205_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4206_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004207
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004208_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4209_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4210_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4211_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4212_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4213_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4214_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4215_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4216_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004217
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004218template<class _CharT, class _Traits, class _Allocator>
4219 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4220 basic_string<_CharT, _Traits, _Allocator>::npos;
4221
4222template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +00004223struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004224 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4225{
4226 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004227 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004228};
4229
4230template<class _CharT, class _Traits, class _Allocator>
4231size_t
4232hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004233 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004234{
Sean Huntaffd9e52011-07-29 23:31:56 +00004235 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004236}
4237
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004238template<class _CharT, class _Traits, class _Allocator>
4239basic_ostream<_CharT, _Traits>&
4240operator<<(basic_ostream<_CharT, _Traits>& __os,
4241 const basic_string<_CharT, _Traits, _Allocator>& __str);
4242
4243template<class _CharT, class _Traits, class _Allocator>
4244basic_istream<_CharT, _Traits>&
4245operator>>(basic_istream<_CharT, _Traits>& __is,
4246 basic_string<_CharT, _Traits, _Allocator>& __str);
4247
4248template<class _CharT, class _Traits, class _Allocator>
4249basic_istream<_CharT, _Traits>&
4250getline(basic_istream<_CharT, _Traits>& __is,
4251 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4252
4253template<class _CharT, class _Traits, class _Allocator>
4254inline _LIBCPP_INLINE_VISIBILITY
4255basic_istream<_CharT, _Traits>&
4256getline(basic_istream<_CharT, _Traits>& __is,
4257 basic_string<_CharT, _Traits, _Allocator>& __str);
4258
Eric Fiselier3e928972017-04-19 00:28:44 +00004259#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004260
4261template<class _CharT, class _Traits, class _Allocator>
4262inline _LIBCPP_INLINE_VISIBILITY
4263basic_istream<_CharT, _Traits>&
4264getline(basic_istream<_CharT, _Traits>&& __is,
4265 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4266
4267template<class _CharT, class _Traits, class _Allocator>
4268inline _LIBCPP_INLINE_VISIBILITY
4269basic_istream<_CharT, _Traits>&
4270getline(basic_istream<_CharT, _Traits>&& __is,
4271 basic_string<_CharT, _Traits, _Allocator>& __str);
4272
Eric Fiselier3e928972017-04-19 00:28:44 +00004273#endif // _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004274
Howard Hinnant499cea12013-08-23 17:37:05 +00004275#if _LIBCPP_DEBUG_LEVEL >= 2
4276
4277template<class _CharT, class _Traits, class _Allocator>
4278bool
4279basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4280{
4281 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4282 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4283}
4284
4285template<class _CharT, class _Traits, class _Allocator>
4286bool
4287basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4288{
4289 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4290 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4291}
4292
4293template<class _CharT, class _Traits, class _Allocator>
4294bool
4295basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4296{
4297 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4298 return this->data() <= __p && __p <= this->data() + this->size();
4299}
4300
4301template<class _CharT, class _Traits, class _Allocator>
4302bool
4303basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4304{
4305 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4306 return this->data() <= __p && __p < this->data() + this->size();
4307}
4308
4309#endif // _LIBCPP_DEBUG_LEVEL >= 2
4310
Shoaib Meenai68506702017-06-29 02:52:46 +00004311_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
4312_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Shoaib Meenai68506702017-06-29 02:52:46 +00004313
Marshall Clow15234322013-07-23 17:05:24 +00004314#if _LIBCPP_STD_VER > 11
4315// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004316inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004317{
4318 inline namespace string_literals
4319 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004320 inline _LIBCPP_INLINE_VISIBILITY
4321 basic_string<char> operator "" s( const char *__str, size_t __len )
4322 {
4323 return basic_string<char> (__str, __len);
4324 }
Marshall Clow15234322013-07-23 17:05:24 +00004325
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004326 inline _LIBCPP_INLINE_VISIBILITY
4327 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4328 {
4329 return basic_string<wchar_t> (__str, __len);
4330 }
Marshall Clow15234322013-07-23 17:05:24 +00004331
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004332 inline _LIBCPP_INLINE_VISIBILITY
4333 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4334 {
4335 return basic_string<char16_t> (__str, __len);
4336 }
Marshall Clow15234322013-07-23 17:05:24 +00004337
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004338 inline _LIBCPP_INLINE_VISIBILITY
4339 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4340 {
4341 return basic_string<char32_t> (__str, __len);
4342 }
Marshall Clow15234322013-07-23 17:05:24 +00004343 }
4344}
4345#endif
4346
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004347_LIBCPP_END_NAMESPACE_STD
4348
Eric Fiselier018a3d52017-05-31 22:07:49 +00004349_LIBCPP_POP_MACROS
4350
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004351#endif // _LIBCPP_STRING