blob: 162e54058c4263225ceb2e6948a247fe6403e0ed [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- string -----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_STRING
12#define _LIBCPP_STRING
13
14/*
15 string synopsis
16
17namespace std
18{
19
20template <class stateT>
21class fpos
22{
23private:
24 stateT st;
25public:
26 fpos(streamoff = streamoff());
27
28 operator streamoff() const;
29
30 stateT state() const;
31 void state(stateT);
32
33 fpos& operator+=(streamoff);
34 fpos operator+ (streamoff) const;
35 fpos& operator-=(streamoff);
36 fpos operator- (streamoff) const;
37};
38
39template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
40
41template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
42template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
43
44template <class charT>
45struct char_traits
46{
47 typedef charT char_type;
48 typedef ... int_type;
49 typedef streamoff off_type;
50 typedef streampos pos_type;
51 typedef mbstate_t state_type;
52
Howard Hinnanta6119a82011-05-29 19:57:12 +000053 static void assign(char_type& c1, const char_type& c2) noexcept;
Howard Hinnant03d71812012-07-20 19:09:12 +000054 static constexpr bool eq(char_type c1, char_type c2) noexcept;
55 static constexpr bool lt(char_type c1, char_type c2) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056
57 static int compare(const char_type* s1, const char_type* s2, size_t n);
58 static size_t length(const char_type* s);
59 static const char_type* find(const char_type* s, size_t n, const char_type& a);
60 static char_type* move(char_type* s1, const char_type* s2, size_t n);
61 static char_type* copy(char_type* s1, const char_type* s2, size_t n);
62 static char_type* assign(char_type* s, size_t n, char_type a);
63
Howard Hinnant03d71812012-07-20 19:09:12 +000064 static constexpr int_type not_eof(int_type c) noexcept;
65 static constexpr char_type to_char_type(int_type c) noexcept;
66 static constexpr int_type to_int_type(char_type c) noexcept;
67 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
68 static constexpr int_type eof() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000069};
70
71template <> struct char_traits<char>;
72template <> struct char_traits<wchar_t>;
73
Howard Hinnant324bb032010-08-22 00:02:43 +000074template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000075class basic_string
76{
Howard Hinnant324bb032010-08-22 00:02:43 +000077public:
78// types:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000079 typedef traits traits_type;
80 typedef typename traits_type::char_type value_type;
81 typedef Allocator allocator_type;
82 typedef typename allocator_type::size_type size_type;
83 typedef typename allocator_type::difference_type difference_type;
84 typedef typename allocator_type::reference reference;
85 typedef typename allocator_type::const_reference const_reference;
86 typedef typename allocator_type::pointer pointer;
87 typedef typename allocator_type::const_pointer const_pointer;
88 typedef implementation-defined iterator;
89 typedef implementation-defined const_iterator;
90 typedef std::reverse_iterator<iterator> reverse_iterator;
91 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
92
93 static const size_type npos = -1;
94
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000095 basic_string()
96 noexcept(is_nothrow_default_constructible<allocator_type>::value);
97 explicit basic_string(const allocator_type& a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000098 basic_string(const basic_string& str);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000099 basic_string(basic_string&& str)
100 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000101 basic_string(const basic_string& str, size_type pos,
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000102 const allocator_type& a = allocator_type());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000103 basic_string(const basic_string& str, size_type pos, size_type n,
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000104 const Allocator& a = Allocator());
Marshall Clowdb7fa112016-11-14 18:22:19 +0000105 template<class T>
106 basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
Marshall Clow64c10d02018-07-02 18:41:15 +0000107 template <class T>
108 explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000109 basic_string(const value_type* s, const allocator_type& a = allocator_type());
110 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000111 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
112 template<class InputIterator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000113 basic_string(InputIterator begin, InputIterator end,
114 const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000115 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
116 basic_string(const basic_string&, const Allocator&);
117 basic_string(basic_string&&, const Allocator&);
118
119 ~basic_string();
120
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000121 operator basic_string_view<charT, traits>() const noexcept;
122
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000123 basic_string& operator=(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000124 template <class T>
125 basic_string& operator=(const T& t); // C++17
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000126 basic_string& operator=(basic_string&& str)
127 noexcept(
Marshall Clowaf961ed2015-08-18 18:57:00 +0000128 allocator_type::propagate_on_container_move_assignment::value ||
129 allocator_type::is_always_equal::value ); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000130 basic_string& operator=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000131 basic_string& operator=(value_type c);
132 basic_string& operator=(initializer_list<value_type>);
133
Howard Hinnanta6119a82011-05-29 19:57:12 +0000134 iterator begin() noexcept;
135 const_iterator begin() const noexcept;
136 iterator end() noexcept;
137 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000138
Howard Hinnanta6119a82011-05-29 19:57:12 +0000139 reverse_iterator rbegin() noexcept;
140 const_reverse_iterator rbegin() const noexcept;
141 reverse_iterator rend() noexcept;
142 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000143
Howard Hinnanta6119a82011-05-29 19:57:12 +0000144 const_iterator cbegin() const noexcept;
145 const_iterator cend() const noexcept;
146 const_reverse_iterator crbegin() const noexcept;
147 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000148
Howard Hinnanta6119a82011-05-29 19:57:12 +0000149 size_type size() const noexcept;
150 size_type length() const noexcept;
151 size_type max_size() const noexcept;
152 size_type capacity() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000153
154 void resize(size_type n, value_type c);
155 void resize(size_type n);
156
157 void reserve(size_type res_arg = 0);
158 void shrink_to_fit();
Howard Hinnanta6119a82011-05-29 19:57:12 +0000159 void clear() noexcept;
160 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000161
162 const_reference operator[](size_type pos) const;
163 reference operator[](size_type pos);
164
165 const_reference at(size_type n) const;
166 reference at(size_type n);
167
168 basic_string& operator+=(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000169 template <class T>
170 basic_string& operator+=(const T& t); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000171 basic_string& operator+=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000172 basic_string& operator+=(value_type c);
173 basic_string& operator+=(initializer_list<value_type>);
174
175 basic_string& append(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000176 template <class T>
177 basic_string& append(const T& t); // C++17
Marshall Clowa93b5e22014-03-04 19:17:19 +0000178 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000179 template <class T>
180 basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000181 basic_string& append(const value_type* s, size_type n);
182 basic_string& append(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000183 basic_string& append(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000184 template<class InputIterator>
185 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000186 basic_string& append(initializer_list<value_type>);
187
188 void push_back(value_type c);
189 void pop_back();
190 reference front();
191 const_reference front() const;
192 reference back();
193 const_reference back() const;
194
195 basic_string& assign(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000196 template <class T>
197 basic_string& assign(const T& t); // C++17
Howard Hinnanta6119a82011-05-29 19:57:12 +0000198 basic_string& assign(basic_string&& str);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000199 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000200 template <class T>
201 basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000202 basic_string& assign(const value_type* s, size_type n);
203 basic_string& assign(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000204 basic_string& assign(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000205 template<class InputIterator>
206 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000207 basic_string& assign(initializer_list<value_type>);
208
209 basic_string& insert(size_type pos1, const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000210 template <class T>
211 basic_string& insert(size_type pos1, const T& t);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000212 basic_string& insert(size_type pos1, const basic_string& str,
213 size_type pos2, size_type n);
Marshall Clow6ac8de02016-09-24 22:45:42 +0000214 template <class T>
215 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
Marshall Clowa93b5e22014-03-04 19:17:19 +0000216 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000217 basic_string& insert(size_type pos, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000218 basic_string& insert(size_type pos, size_type n, value_type c);
219 iterator insert(const_iterator p, value_type c);
220 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000221 template<class InputIterator>
222 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000223 iterator insert(const_iterator p, initializer_list<value_type>);
224
225 basic_string& erase(size_type pos = 0, size_type n = npos);
226 iterator erase(const_iterator position);
227 iterator erase(const_iterator first, const_iterator last);
228
229 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000230 template <class T>
231 basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000232 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000233 size_type pos2, size_type n2=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000234 template <class T>
235 basic_string& replace(size_type pos1, size_type n1, const T& t,
236 size_type pos2, size_type n); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000237 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
238 basic_string& replace(size_type pos, size_type n1, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000239 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000240 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000241 template <class T>
242 basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000243 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
244 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000245 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000246 template<class InputIterator>
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000247 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
248 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000249
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000250 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000251 basic_string substr(size_type pos = 0, size_type n = npos) const;
252
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000253 void swap(basic_string& str)
Marshall Clow7d914d12015-07-13 20:04:56 +0000254 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
255 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000257 const value_type* c_str() const noexcept;
258 const value_type* data() const noexcept;
Marshall Clowf532a702016-03-08 15:44:30 +0000259 value_type* data() noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000260
Howard Hinnanta6119a82011-05-29 19:57:12 +0000261 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000262
Howard Hinnanta6119a82011-05-29 19:57:12 +0000263 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000264 template <class T>
265 size_type find(const T& t, size_type pos = 0) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000266 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
267 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000268 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000269
Howard Hinnanta6119a82011-05-29 19:57:12 +0000270 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000271 template <class T>
272 size_type rfind(const T& t, size_type pos = npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000273 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
274 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000275 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276
Howard Hinnanta6119a82011-05-29 19:57:12 +0000277 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000278 template <class T>
279 size_type find_first_of(const T& t, size_type pos = 0) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000280 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
281 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000282 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000283
Howard Hinnanta6119a82011-05-29 19:57:12 +0000284 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000285 template <class T>
286 size_type find_last_of(const T& t, size_type pos = npos) const noexcept; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000287 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
288 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000289 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290
Howard Hinnanta6119a82011-05-29 19:57:12 +0000291 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000292 template <class T>
293 size_type find_first_not_of(const T& t, size_type pos = 0) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000294 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
295 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000296 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000297
Howard Hinnanta6119a82011-05-29 19:57:12 +0000298 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000299 template <class T>
300 size_type find_last_not_of(const T& t, size_type pos = npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000301 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
302 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000303 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000304
Howard Hinnanta6119a82011-05-29 19:57:12 +0000305 int compare(const basic_string& str) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000306 template <class T>
307 int compare(const T& t) const noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000308 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Marshall Clow64c10d02018-07-02 18:41:15 +0000309 template <class T>
310 int compare(size_type pos1, size_type n1, const T& t) const; // C++17
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000311 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000312 size_type pos2, size_type n2=npos) const; // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000313 template <class T>
314 int compare(size_type pos1, size_type n1, const T& t,
315 size_type pos2, size_type n2=npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000316 int compare(const value_type* s) const noexcept;
317 int compare(size_type pos1, size_type n1, const value_type* s) const;
318 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000319
Marshall Clow46b4ad52017-12-04 20:11:38 +0000320 bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
321 bool starts_with(charT c) const noexcept; // C++2a
322 bool starts_with(const charT* s) const; // C++2a
323 bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
324 bool ends_with(charT c) const noexcept; // C++2a
325 bool ends_with(const charT* s) const; // C++2a
326
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327 bool __invariants() const;
328};
329
Marshall Clow5b1e87e2018-02-08 06:34:03 +0000330template<class InputIterator,
331 class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
332basic_string(InputIterator, InputIterator, Allocator = Allocator())
333 -> basic_string<typename iterator_traits<InputIterator>::value_type,
334 char_traits<typename iterator_traits<InputIterator>::value_type>,
335 Allocator>; // C++17
336
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000337template<class charT, class traits, class Allocator>
338basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000339operator+(const basic_string<charT, traits, Allocator>& lhs,
340 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341
342template<class charT, class traits, class Allocator>
343basic_string<charT, traits, Allocator>
344operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
345
346template<class charT, class traits, class Allocator>
347basic_string<charT, traits, Allocator>
348operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
349
350template<class charT, class traits, class Allocator>
351basic_string<charT, traits, Allocator>
352operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
353
354template<class charT, class traits, class Allocator>
355basic_string<charT, traits, Allocator>
356operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
357
358template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000359bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000360 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361
362template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000363bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000364
365template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000366bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367
Howard Hinnant324bb032010-08-22 00:02:43 +0000368template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000369bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000370 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371
372template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000373bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374
375template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000376bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377
378template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000379bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000380 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381
382template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000383bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384
385template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000386bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000387
388template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000389bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000390 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000391
392template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000393bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394
395template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000396bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397
398template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000399bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000400 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000401
402template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000403bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404
405template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000406bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000407
408template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000409bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000410 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000411
412template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000413bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000414
415template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000416bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000417
418template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000419void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000420 basic_string<charT, traits, Allocator>& rhs)
421 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422
423template<class charT, class traits, class Allocator>
424basic_istream<charT, traits>&
425operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
426
427template<class charT, class traits, class Allocator>
428basic_ostream<charT, traits>&
429operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
430
431template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000432basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000433getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
434 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435
436template<class charT, class traits, class Allocator>
437basic_istream<charT, traits>&
438getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
439
440typedef basic_string<char> string;
441typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000442typedef basic_string<char16_t> u16string;
443typedef basic_string<char32_t> u32string;
444
445int stoi (const string& str, size_t* idx = 0, int base = 10);
446long stol (const string& str, size_t* idx = 0, int base = 10);
447unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
448long long stoll (const string& str, size_t* idx = 0, int base = 10);
449unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
450
451float stof (const string& str, size_t* idx = 0);
452double stod (const string& str, size_t* idx = 0);
453long double stold(const string& str, size_t* idx = 0);
454
455string to_string(int val);
456string to_string(unsigned val);
457string to_string(long val);
458string to_string(unsigned long val);
459string to_string(long long val);
460string to_string(unsigned long long val);
461string to_string(float val);
462string to_string(double val);
463string to_string(long double val);
464
465int stoi (const wstring& str, size_t* idx = 0, int base = 10);
466long stol (const wstring& str, size_t* idx = 0, int base = 10);
467unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
468long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
469unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
470
471float stof (const wstring& str, size_t* idx = 0);
472double stod (const wstring& str, size_t* idx = 0);
473long double stold(const wstring& str, size_t* idx = 0);
474
475wstring to_wstring(int val);
476wstring to_wstring(unsigned val);
477wstring to_wstring(long val);
478wstring to_wstring(unsigned long val);
479wstring to_wstring(long long val);
480wstring to_wstring(unsigned long long val);
481wstring to_wstring(float val);
482wstring to_wstring(double val);
483wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000484
485template <> struct hash<string>;
486template <> struct hash<u16string>;
487template <> struct hash<u32string>;
488template <> struct hash<wstring>;
489
Marshall Clow15234322013-07-23 17:05:24 +0000490basic_string<char> operator "" s( const char *str, size_t len ); // C++14
491basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
492basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
493basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
494
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495} // std
496
497*/
498
499#include <__config>
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000500#include <string_view>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501#include <iosfwd>
502#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000503#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504#include <cwchar>
505#include <algorithm>
506#include <iterator>
507#include <utility>
508#include <memory>
509#include <stdexcept>
510#include <type_traits>
511#include <initializer_list>
512#include <__functional_base>
513#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
514#include <cstdint>
515#endif
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000516
Eric Fiselierb9536102014-08-10 23:53:08 +0000517#include <__debug>
518
Howard Hinnant08e17472011-10-17 20:05:10 +0000519#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000520#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000521#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000522
Eric Fiselier018a3d52017-05-31 22:07:49 +0000523_LIBCPP_PUSH_MACROS
524#include <__undef_macros>
525
526
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000527_LIBCPP_BEGIN_NAMESPACE_STD
528
529// fpos
530
531template <class _StateT>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000532class _LIBCPP_TEMPLATE_VIS fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533{
534private:
535 _StateT __st_;
536 streamoff __off_;
537public:
538 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
539
540 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
541
542 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
543 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
544
545 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
546 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
547 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
548 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
549};
550
551template <class _StateT>
552inline _LIBCPP_INLINE_VISIBILITY
553streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
554 {return streamoff(__x) - streamoff(__y);}
555
556template <class _StateT>
557inline _LIBCPP_INLINE_VISIBILITY
558bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
559 {return streamoff(__x) == streamoff(__y);}
560
561template <class _StateT>
562inline _LIBCPP_INLINE_VISIBILITY
563bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
564 {return streamoff(__x) != streamoff(__y);}
565
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000566// basic_string
567
568template<class _CharT, class _Traits, class _Allocator>
569basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000570operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
571 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572
573template<class _CharT, class _Traits, class _Allocator>
574basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000575operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000576
577template<class _CharT, class _Traits, class _Allocator>
578basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000579operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000580
581template<class _CharT, class _Traits, class _Allocator>
582basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000583operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000584
585template<class _CharT, class _Traits, class _Allocator>
586basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000587operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000588
Shoaib Meenai487562f2017-07-29 02:54:41 +0000589_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
590
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000591template <bool>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000592class _LIBCPP_TEMPLATE_VIS __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593{
594protected:
Marshall Clow14c09a22016-08-25 15:09:01 +0000595 _LIBCPP_NORETURN void __throw_length_error() const;
596 _LIBCPP_NORETURN void __throw_out_of_range() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000597};
598
599template <bool __b>
600void
601__basic_string_common<__b>::__throw_length_error() const
602{
Marshall Clow14c09a22016-08-25 15:09:01 +0000603 _VSTD::__throw_length_error("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000604}
605
606template <bool __b>
607void
608__basic_string_common<__b>::__throw_out_of_range() const
609{
Marshall Clow14c09a22016-08-25 15:09:01 +0000610 _VSTD::__throw_out_of_range("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000611}
612
Eric Fiselier833d6442016-09-15 22:27:07 +0000613_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000614
Marshall Clowdf9db312016-01-13 21:54:34 +0000615#ifdef _LIBCPP_NO_EXCEPTIONS
616template <class _Iter>
617struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
618#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
619template <class _Iter>
620struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
621#else
622template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
623struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
624 noexcept(++(declval<_Iter&>())) &&
625 is_nothrow_assignable<_Iter&, _Iter>::value &&
626 noexcept(declval<_Iter>() == declval<_Iter>()) &&
627 noexcept(*declval<_Iter>())
628)) {};
629
630template <class _Iter>
631struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
632#endif
633
634
635template <class _Iter>
636struct __libcpp_string_gets_noexcept_iterator
637 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
638
Marshall Clow6ac8de02016-09-24 22:45:42 +0000639template <class _CharT, class _Traits, class _Tp>
640struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
Marshall Clowf1729d92017-11-15 20:02:27 +0000641 ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
Marshall Clow6ac8de02016-09-24 22:45:42 +0000642 !is_convertible<const _Tp&, const _CharT*>::value)) {};
643
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000644#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000645
646template <class _CharT, size_t = sizeof(_CharT)>
647struct __padding
648{
649 unsigned char __xx[sizeof(_CharT)-1];
650};
651
652template <class _CharT>
653struct __padding<_CharT, 1>
654{
655};
656
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000657#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000658
Howard Hinnant324bb032010-08-22 00:02:43 +0000659template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000660class _LIBCPP_TEMPLATE_VIS basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661 : private __basic_string_common<true>
662{
663public:
664 typedef basic_string __self;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000665 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000666 typedef _Traits traits_type;
Marshall Clow2d4c3fa2017-03-15 18:41:11 +0000667 typedef _CharT value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000669 typedef allocator_traits<allocator_type> __alloc_traits;
670 typedef typename __alloc_traits::size_type size_type;
671 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000672 typedef value_type& reference;
673 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000674 typedef typename __alloc_traits::pointer pointer;
675 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676
Marshall Clow256f1872018-03-21 00:36:05 +0000677 static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
678 static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
679 static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
680 static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
Howard Hinnant499cea12013-08-23 17:37:05 +0000681 "traits_type::char_type must be the same type as CharT");
Marshall Clow256f1872018-03-21 00:36:05 +0000682 static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
Howard Hinnant499cea12013-08-23 17:37:05 +0000683 "Allocator::value_type must be same type as value_type");
Marshall Clow64c10d02018-07-02 18:41:15 +0000684
Howard Hinnant499cea12013-08-23 17:37:05 +0000685#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000686 typedef pointer iterator;
687 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000688#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689 typedef __wrap_iter<pointer> iterator;
690 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000691#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000692 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
693 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000694
695private:
Howard Hinnant15467182013-04-30 21:44:48 +0000696
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000697#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000698
699 struct __long
700 {
701 pointer __data_;
702 size_type __size_;
703 size_type __cap_;
704 };
705
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000706#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000707 static const size_type __short_mask = 0x01;
708 static const size_type __long_mask = 0x1ul;
Howard Hinnant15467182013-04-30 21:44:48 +0000709#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000710 static const size_type __short_mask = 0x80;
711 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant15467182013-04-30 21:44:48 +0000712#endif // _LIBCPP_BIG_ENDIAN
713
714 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
715 (sizeof(__long) - 1)/sizeof(value_type) : 2};
716
717 struct __short
718 {
719 value_type __data_[__min_cap];
720 struct
721 : __padding<value_type>
722 {
723 unsigned char __size_;
724 };
725 };
726
727#else
728
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000729 struct __long
730 {
731 size_type __cap_;
732 size_type __size_;
733 pointer __data_;
734 };
735
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000736#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000737 static const size_type __short_mask = 0x80;
738 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant324bb032010-08-22 00:02:43 +0000739#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000740 static const size_type __short_mask = 0x01;
741 static const size_type __long_mask = 0x1ul;
Howard Hinnant324bb032010-08-22 00:02:43 +0000742#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000744 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
745 (sizeof(__long) - 1)/sizeof(value_type) : 2};
746
747 struct __short
748 {
749 union
750 {
751 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +0000752 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000753 };
754 value_type __data_[__min_cap];
755 };
756
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000757#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000758
Howard Hinnant499cea12013-08-23 17:37:05 +0000759 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000760
Howard Hinnant499cea12013-08-23 17:37:05 +0000761 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000762
763 struct __raw
764 {
765 size_type __words[__n_words];
766 };
767
768 struct __rep
769 {
770 union
771 {
772 __long __l;
773 __short __s;
774 __raw __r;
775 };
776 };
777
778 __compressed_pair<__rep, allocator_type> __r_;
779
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000780public:
781 static const size_type npos = -1;
782
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000783 _LIBCPP_INLINE_VISIBILITY basic_string()
784 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000785
786 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
787#if _LIBCPP_STD_VER <= 14
788 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
789#else
790 _NOEXCEPT;
791#endif
792
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000793 basic_string(const basic_string& __str);
794 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +0000795
Eric Fiselier3e928972017-04-19 00:28:44 +0000796#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant9f193f22011-01-26 00:06:59 +0000797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000798 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +0000799#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000800 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000801#else
802 _NOEXCEPT;
803#endif
804
Howard Hinnant9f193f22011-01-26 00:06:59 +0000805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000806 basic_string(basic_string&& __str, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000807#endif // _LIBCPP_CXX03_LANG
Marshall Clow64c10d02018-07-02 18:41:15 +0000808
809 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
Eric Fiselierffbb91b2018-07-17 05:48:48 +0000810 _LIBCPP_INLINE_VISIBILITY
811 basic_string(const _CharT* __s) {
812 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
813 __init(__s, traits_type::length(__s));
814# if _LIBCPP_DEBUG_LEVEL >= 2
815 __get_db()->__insert_c(this);
816# endif
817 }
Marshall Clow64c10d02018-07-02 18:41:15 +0000818
819 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
820 _LIBCPP_INLINE_VISIBILITY
821 basic_string(const _CharT* __s, const _Allocator& __a);
822
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000823 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000824 basic_string(const _CharT* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000825 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000826 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000827 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000828 basic_string(size_type __n, _CharT __c);
Marshall Clow64c10d02018-07-02 18:41:15 +0000829
830 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
831 _LIBCPP_INLINE_VISIBILITY
832 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
833
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000834 basic_string(const basic_string& __str, size_type __pos, size_type __n,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000835 const _Allocator& __a = _Allocator());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000836 _LIBCPP_INLINE_VISIBILITY
837 basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000838 const _Allocator& __a = _Allocator());
Marshall Clow64c10d02018-07-02 18:41:15 +0000839
840 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 +0000841 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000842 basic_string(const _Tp& __t, size_type __pos, size_type __n,
Marshall Clow64c10d02018-07-02 18:41:15 +0000843 const allocator_type& __a = allocator_type());
844
845 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
846 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
847 explicit basic_string(const _Tp& __t);
848
849 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
850 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
851 explicit basic_string(const _Tp& __t, const allocator_type& __a);
852
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000853 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000855 basic_string(_InputIterator __first, _InputIterator __last);
856 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000858 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000859#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000860 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000861 basic_string(initializer_list<_CharT> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000862 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000863 basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000864#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000865
Eric Fiselier51eb1d52016-10-31 03:42:50 +0000866 inline ~basic_string();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000867
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000868 _LIBCPP_INLINE_VISIBILITY
869 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
870
Howard Hinnante32b5e22010-11-17 17:55:08 +0000871 basic_string& operator=(const basic_string& __str);
Eric Fiselierf472d6c2017-01-23 21:24:58 +0000872
Marshall Clow64c10d02018-07-02 18:41:15 +0000873 template <class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
874 basic_string& operator=(const _Tp& __t)
875 {__self_view __sv = __t; return assign(__sv);}
876
Eric Fiselier3e928972017-04-19 00:28:44 +0000877#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000879 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +0000880 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Eric Fiselier3e928972017-04-19 00:28:44 +0000881 _LIBCPP_INLINE_VISIBILITY
882 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000883#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000884 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000885 basic_string& operator=(value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000886
Howard Hinnant499cea12013-08-23 17:37:05 +0000887#if _LIBCPP_DEBUG_LEVEL >= 2
888 _LIBCPP_INLINE_VISIBILITY
889 iterator begin() _NOEXCEPT
890 {return iterator(this, __get_pointer());}
891 _LIBCPP_INLINE_VISIBILITY
892 const_iterator begin() const _NOEXCEPT
893 {return const_iterator(this, __get_pointer());}
894 _LIBCPP_INLINE_VISIBILITY
895 iterator end() _NOEXCEPT
896 {return iterator(this, __get_pointer() + size());}
897 _LIBCPP_INLINE_VISIBILITY
898 const_iterator end() const _NOEXCEPT
899 {return const_iterator(this, __get_pointer() + size());}
900#else
Howard Hinnanta6119a82011-05-29 19:57:12 +0000901 _LIBCPP_INLINE_VISIBILITY
902 iterator begin() _NOEXCEPT
903 {return iterator(__get_pointer());}
904 _LIBCPP_INLINE_VISIBILITY
905 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000906 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000907 _LIBCPP_INLINE_VISIBILITY
908 iterator end() _NOEXCEPT
909 {return iterator(__get_pointer() + size());}
910 _LIBCPP_INLINE_VISIBILITY
911 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000912 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +0000913#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +0000914 _LIBCPP_INLINE_VISIBILITY
915 reverse_iterator rbegin() _NOEXCEPT
916 {return reverse_iterator(end());}
917 _LIBCPP_INLINE_VISIBILITY
918 const_reverse_iterator rbegin() const _NOEXCEPT
919 {return const_reverse_iterator(end());}
920 _LIBCPP_INLINE_VISIBILITY
921 reverse_iterator rend() _NOEXCEPT
922 {return reverse_iterator(begin());}
923 _LIBCPP_INLINE_VISIBILITY
924 const_reverse_iterator rend() const _NOEXCEPT
925 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000926
Howard Hinnanta6119a82011-05-29 19:57:12 +0000927 _LIBCPP_INLINE_VISIBILITY
928 const_iterator cbegin() const _NOEXCEPT
929 {return begin();}
930 _LIBCPP_INLINE_VISIBILITY
931 const_iterator cend() const _NOEXCEPT
932 {return end();}
933 _LIBCPP_INLINE_VISIBILITY
934 const_reverse_iterator crbegin() const _NOEXCEPT
935 {return rbegin();}
936 _LIBCPP_INLINE_VISIBILITY
937 const_reverse_iterator crend() const _NOEXCEPT
938 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000939
Howard Hinnanta6119a82011-05-29 19:57:12 +0000940 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000941 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000942 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
943 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
944 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +0000945 {return (__is_long() ? __get_long_cap()
946 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947
948 void resize(size_type __n, value_type __c);
949 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
950
Eric Fiselier59e24fe2017-06-01 02:29:37 +0000951 void reserve(size_type __res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000952 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000953 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000954 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +0000955 void clear() _NOEXCEPT;
Marshall Clowf1729d92017-11-15 20:02:27 +0000956 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
957 bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000958
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000959 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
960 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000961
962 const_reference at(size_type __n) const;
963 reference at(size_type __n);
964
965 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clow64c10d02018-07-02 18:41:15 +0000966
967 template <class _Tp>
968 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
969 typename enable_if
970 <
971 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
972 basic_string&
973 >::type
974 operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);}
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000975 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Eric Fiselier3e928972017-04-19 00:28:44 +0000977#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000978 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Eric Fiselier3e928972017-04-19 00:28:44 +0000979#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000980
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000982 basic_string& append(const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000983
984 template <class _Tp>
985 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
986 typename enable_if
987 <
988 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
989 basic_string&
990 >::type
991 append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +0000992 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow64c10d02018-07-02 18:41:15 +0000993
Marshall Clow42a87db2016-10-03 23:40:48 +0000994 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +0000995 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
996 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +0000997 <
998 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
999 basic_string&
1000 >::type
1001 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001002 basic_string& append(const value_type* __s, size_type __n);
1003 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001004 basic_string& append(size_type __n, value_type __c);
Eric Fiselier026d38e2016-10-31 02:46:25 +00001005 template <class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001006 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1007 basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001008 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001009 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1010 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001011 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001012 __is_exactly_input_iterator<_InputIterator>::value
1013 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001014 basic_string&
1015 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +00001016 _LIBCPP_INLINE_VISIBILITY
1017 append(_InputIterator __first, _InputIterator __last) {
1018 const basic_string __temp (__first, __last, __alloc());
1019 append(__temp.data(), __temp.size());
1020 return *this;
1021 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001022 template<class _ForwardIterator>
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_forward_iterator<_ForwardIterator>::value
1027 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::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(_ForwardIterator __first, _ForwardIterator __last) {
1032 return __append_forward_unsafe(__first, __last);
1033 }
1034
Eric Fiselier3e928972017-04-19 00:28:44 +00001035#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001036 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001037 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001038#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001039
1040 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001041 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001042 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001043 _LIBCPP_INLINE_VISIBILITY reference front();
1044 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1045 _LIBCPP_INLINE_VISIBILITY reference back();
1046 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001047
Marshall Clow64c10d02018-07-02 18:41:15 +00001048 template <class _Tp>
1049 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1050 typename enable_if
1051 <
1052 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1053 basic_string&
1054 >::type
1055 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001056 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29 +00001057 basic_string& assign(const basic_string& __str) { return *this = __str; }
Eric Fiselier3e928972017-04-19 00:28:44 +00001058#ifndef _LIBCPP_CXX03_LANG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001059 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001060 basic_string& assign(basic_string&& __str)
Marshall Clow7ed093b2015-10-05 16:17:34 +00001061 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001062 {*this = _VSTD::move(__str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001063#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +00001064 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48 +00001065 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001066 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1067 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001068 <
1069 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1070 basic_string&
1071 >::type
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001072 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001073 basic_string& assign(const value_type* __s, size_type __n);
1074 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001075 basic_string& assign(size_type __n, value_type __c);
1076 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001077 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1078 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001079 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001080 __is_exactly_input_iterator<_InputIterator>::value
1081 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001082 basic_string&
1083 >::type
1084 assign(_InputIterator __first, _InputIterator __last);
1085 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001086 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1087 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001088 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001089 __is_forward_iterator<_ForwardIterator>::value
1090 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001091 basic_string&
1092 >::type
1093 assign(_ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001094#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001095 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001096 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001097#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001098
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001100 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001101
1102 template <class _Tp>
1103 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1104 typename enable_if
1105 <
1106 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1107 basic_string&
1108 >::type
1109 insert(size_type __pos1, const _Tp& __t)
1110 { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
1111
Marshall Clow6ac8de02016-09-24 22:45:42 +00001112 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001113 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1114 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001115 <
1116 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1117 basic_string&
1118 >::type
1119 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001120 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001121 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1122 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001123 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1124 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001125 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001126 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1127 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001128 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1129 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001130 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001131 __is_exactly_input_iterator<_InputIterator>::value
1132 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001133 iterator
1134 >::type
1135 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1136 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001137 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1138 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001139 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001140 __is_forward_iterator<_ForwardIterator>::value
1141 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001142 iterator
1143 >::type
1144 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001145#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001146 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001147 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1148 {return insert(__pos, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001149#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001150
1151 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001153 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155 iterator erase(const_iterator __first, const_iterator __last);
1156
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001157 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001158 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001159
1160 template <class _Tp>
1161 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1162 typename enable_if
1163 <
1164 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1165 basic_string&
1166 >::type
1167 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 +00001168 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 +00001169 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001170 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1171 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001172 <
1173 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1174 basic_string&
1175 >::type
1176 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001177 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1178 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001179 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001181 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001182
1183 template <class _Tp>
1184 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1185 typename enable_if
1186 <
1187 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1188 basic_string&
1189 >::type
1190 replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
1191
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001192 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001193 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001194 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001195 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001196 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001197 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001199 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1200 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001201 <
1202 __is_input_iterator<_InputIterator>::value,
1203 basic_string&
1204 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001205 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Eric Fiselier3e928972017-04-19 00:28:44 +00001206#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001207 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001208 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001209 {return replace(__i1, __i2, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001210#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001211
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001212 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001213 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001214 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1215
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001216 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001217 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001218#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00001219 _NOEXCEPT_DEBUG;
Marshall Clow7d914d12015-07-13 20:04:56 +00001220#else
Eric Fiselier47257c42016-12-28 05:53:01 +00001221 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00001222 __is_nothrow_swappable<allocator_type>::value);
1223#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001224
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001225 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001226 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001227 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001228 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Eric Fiselier10bebe22017-11-20 20:23:27 +00001229#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
Marshall Clowf532a702016-03-08 15:44:30 +00001230 _LIBCPP_INLINE_VISIBILITY
1231 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1232#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001233
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001234 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001235 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001236
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001237 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001238 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001239
1240 template <class _Tp>
1241 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1242 typename enable_if
1243 <
1244 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1245 size_type
1246 >::type
1247 find(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001248 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001249 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001250 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001251 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001252
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001254 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001255
1256 template <class _Tp>
1257 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1258 typename enable_if
1259 <
1260 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1261 size_type
1262 >::type
1263 rfind(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001264 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001265 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001266 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001267 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001268
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001270 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001271
1272 template <class _Tp>
1273 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1274 typename enable_if
1275 <
1276 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1277 size_type
1278 >::type
1279 find_first_of(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001280 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001281 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001282 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001283 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001284 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001285
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001287 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001288
1289 template <class _Tp>
1290 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1291 typename enable_if
1292 <
1293 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1294 size_type
1295 >::type
1296 find_last_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001297 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001299 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001301 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001302
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001303 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001304 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001305
1306 template <class _Tp>
1307 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1308 typename enable_if
1309 <
1310 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1311 size_type
1312 >::type
1313 find_first_not_of(const _Tp &__t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001314 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 +00001315 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001316 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001317 _LIBCPP_INLINE_VISIBILITY
1318 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1319
1320 _LIBCPP_INLINE_VISIBILITY
1321 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001322
1323 template <class _Tp>
1324 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1325 typename enable_if
1326 <
1327 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1328 size_type
1329 >::type
1330 find_last_not_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001331 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 +00001332 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001333 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001334 _LIBCPP_INLINE_VISIBILITY
1335 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1336
1337 _LIBCPP_INLINE_VISIBILITY
1338 int compare(const basic_string& __str) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001339
1340 template <class _Tp>
1341 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1342 typename enable_if
1343 <
1344 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1345 int
1346 >::type
1347 compare(const _Tp &__t) const;
1348
1349 template <class _Tp>
1350 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1351 typename enable_if
1352 <
1353 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1354 int
1355 >::type
1356 compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
1357
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001358 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001359 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001360 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 +00001361
Marshall Clow6ac8de02016-09-24 22:45:42 +00001362 template <class _Tp>
Eric Fiselier9dbc0532016-10-14 05:29:46 +00001363 inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow6ac8de02016-09-24 22:45:42 +00001364 typename enable_if
1365 <
1366 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1367 int
1368 >::type
1369 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 +00001370 int compare(const value_type* __s) const _NOEXCEPT;
1371 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1372 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001373
Marshall Clow46b4ad52017-12-04 20:11:38 +00001374#if _LIBCPP_STD_VER > 17
1375 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1376 bool starts_with(__self_view __sv) const _NOEXCEPT
1377 { return __self_view(data(), size()).starts_with(__sv); }
1378
1379 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1380 bool starts_with(value_type __c) const _NOEXCEPT
1381 { return !empty() && _Traits::eq(front(), __c); }
1382
1383 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1384 bool starts_with(const value_type* __s) const _NOEXCEPT
1385 { return starts_with(__self_view(__s)); }
1386
1387 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1388 bool ends_with(__self_view __sv) const _NOEXCEPT
1389 { return __self_view(data(), size()).ends_with( __sv); }
1390
1391 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1392 bool ends_with(value_type __c) const _NOEXCEPT
1393 { return !empty() && _Traits::eq(back(), __c); }
1394
1395 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1396 bool ends_with(const value_type* __s) const _NOEXCEPT
1397 { return ends_with(__self_view(__s)); }
1398#endif
1399
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001400 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001401
Marshall Clowab343bb2018-05-29 17:04:37 +00001402 _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT;
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001403
Howard Hinnant08dd2532013-04-22 23:55:13 +00001404 _LIBCPP_INLINE_VISIBILITY
1405 bool __is_long() const _NOEXCEPT
1406 {return bool(__r_.first().__s.__size_ & __short_mask);}
1407
Howard Hinnant499cea12013-08-23 17:37:05 +00001408#if _LIBCPP_DEBUG_LEVEL >= 2
1409
1410 bool __dereferenceable(const const_iterator* __i) const;
1411 bool __decrementable(const const_iterator* __i) const;
1412 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1413 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1414
1415#endif // _LIBCPP_DEBUG_LEVEL >= 2
1416
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001417private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001418 _LIBCPP_INLINE_VISIBILITY
1419 allocator_type& __alloc() _NOEXCEPT
1420 {return __r_.second();}
1421 _LIBCPP_INLINE_VISIBILITY
1422 const allocator_type& __alloc() const _NOEXCEPT
1423 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001424
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001425#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001426
Howard Hinnanta6119a82011-05-29 19:57:12 +00001427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001428 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001429# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001430 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001431# else
1432 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1433# endif
1434
Howard Hinnanta6119a82011-05-29 19:57:12 +00001435 _LIBCPP_INLINE_VISIBILITY
1436 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001437# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001438 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001439# else
1440 {return __r_.first().__s.__size_;}
1441# endif
1442
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001443#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001444
1445 _LIBCPP_INLINE_VISIBILITY
1446 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001447# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001448 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1449# else
1450 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1451# endif
1452
1453 _LIBCPP_INLINE_VISIBILITY
1454 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001455# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001456 {return __r_.first().__s.__size_;}
1457# else
1458 {return __r_.first().__s.__size_ >> 1;}
1459# endif
1460
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001461#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001462
Howard Hinnanta6119a82011-05-29 19:57:12 +00001463 _LIBCPP_INLINE_VISIBILITY
1464 void __set_long_size(size_type __s) _NOEXCEPT
1465 {__r_.first().__l.__size_ = __s;}
1466 _LIBCPP_INLINE_VISIBILITY
1467 size_type __get_long_size() const _NOEXCEPT
1468 {return __r_.first().__l.__size_;}
1469 _LIBCPP_INLINE_VISIBILITY
1470 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001471 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1472
Howard Hinnanta6119a82011-05-29 19:57:12 +00001473 _LIBCPP_INLINE_VISIBILITY
1474 void __set_long_cap(size_type __s) _NOEXCEPT
1475 {__r_.first().__l.__cap_ = __long_mask | __s;}
1476 _LIBCPP_INLINE_VISIBILITY
1477 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001478 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001479
Howard Hinnanta6119a82011-05-29 19:57:12 +00001480 _LIBCPP_INLINE_VISIBILITY
1481 void __set_long_pointer(pointer __p) _NOEXCEPT
1482 {__r_.first().__l.__data_ = __p;}
1483 _LIBCPP_INLINE_VISIBILITY
1484 pointer __get_long_pointer() _NOEXCEPT
1485 {return __r_.first().__l.__data_;}
1486 _LIBCPP_INLINE_VISIBILITY
1487 const_pointer __get_long_pointer() const _NOEXCEPT
1488 {return __r_.first().__l.__data_;}
1489 _LIBCPP_INLINE_VISIBILITY
1490 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001491 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001492 _LIBCPP_INLINE_VISIBILITY
1493 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001494 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001495 _LIBCPP_INLINE_VISIBILITY
1496 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001497 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001498 _LIBCPP_INLINE_VISIBILITY
1499 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001500 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1501
Howard Hinnanta6119a82011-05-29 19:57:12 +00001502 _LIBCPP_INLINE_VISIBILITY
1503 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001504 {
1505 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1506 for (unsigned __i = 0; __i < __n_words; ++__i)
1507 __a[__i] = 0;
1508 }
1509
1510 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001512 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001513 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001514 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001515 static _LIBCPP_INLINE_VISIBILITY
1516 size_type __recommend(size_type __s) _NOEXCEPT
Marshall Clow088e6012018-02-07 21:30:17 +00001517 {
1518 if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
1519 size_type __guess = __align_it<sizeof(value_type) < __alignment ?
1520 __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
1521 if (__guess == __min_cap) ++__guess;
1522 return __guess;
1523 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001524
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001525 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001526 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001527 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001528 void __init(const value_type* __s, size_type __sz);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001529 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001530 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001531
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001532 template <class _InputIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001533 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001534 typename enable_if
1535 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001536 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001537 void
1538 >::type
1539 __init(_InputIterator __first, _InputIterator __last);
1540
1541 template <class _ForwardIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001542 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001543 typename enable_if
1544 <
1545 __is_forward_iterator<_ForwardIterator>::value,
1546 void
1547 >::type
1548 __init(_ForwardIterator __first, _ForwardIterator __last);
1549
1550 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001551 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001552 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1553 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001554 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001555
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001557 void __erase_to_end(size_type __pos);
1558
Howard Hinnante32b5e22010-11-17 17:55:08 +00001559 _LIBCPP_INLINE_VISIBILITY
1560 void __copy_assign_alloc(const basic_string& __str)
1561 {__copy_assign_alloc(__str, integral_constant<bool,
1562 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1563
1564 _LIBCPP_INLINE_VISIBILITY
1565 void __copy_assign_alloc(const basic_string& __str, true_type)
1566 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001567 if (__alloc() == __str.__alloc())
1568 __alloc() = __str.__alloc();
1569 else
Howard Hinnante32b5e22010-11-17 17:55:08 +00001570 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001571 if (!__str.__is_long())
1572 {
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001573 __clear_and_shrink();
Marshall Clow9247fd22017-01-31 03:40:52 +00001574 __alloc() = __str.__alloc();
1575 }
1576 else
1577 {
1578 allocator_type __a = __str.__alloc();
1579 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001580 __clear_and_shrink();
Marshall Clow9247fd22017-01-31 03:40:52 +00001581 __alloc() = _VSTD::move(__a);
1582 __set_long_pointer(__p);
1583 __set_long_cap(__str.__get_long_cap());
1584 __set_long_size(__str.size());
1585 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001586 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001587 }
1588
1589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001590 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001591 {}
1592
Eric Fiselier3e928972017-04-19 00:28:44 +00001593#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001594 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001595 void __move_assign(basic_string& __str, false_type)
1596 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001597 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001598 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001599#if _LIBCPP_STD_VER > 14
1600 _NOEXCEPT;
1601#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001602 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001603#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001604#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001605
1606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001607 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001608 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001609 _NOEXCEPT_(
1610 !__alloc_traits::propagate_on_container_move_assignment::value ||
1611 is_nothrow_move_assignable<allocator_type>::value)
1612 {__move_assign_alloc(__str, integral_constant<bool,
1613 __alloc_traits::propagate_on_container_move_assignment::value>());}
1614
1615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001616 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001617 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1618 {
1619 __alloc() = _VSTD::move(__c.__alloc());
1620 }
1621
1622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001623 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001624 _NOEXCEPT
1625 {}
1626
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001627 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1628 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001629
1630 friend basic_string operator+<>(const basic_string&, const basic_string&);
1631 friend basic_string operator+<>(const value_type*, const basic_string&);
1632 friend basic_string operator+<>(value_type, const basic_string&);
1633 friend basic_string operator+<>(const basic_string&, const value_type*);
1634 friend basic_string operator+<>(const basic_string&, value_type);
1635};
1636
Marshall Clow5b1e87e2018-02-08 06:34:03 +00001637#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1638template<class _InputIterator,
1639 class _CharT = typename iterator_traits<_InputIterator>::value_type,
1640 class _Allocator = allocator<_CharT>,
1641 class = typename enable_if<__is_input_iterator<_InputIterator>::value, void>::type,
1642 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1643 >
1644basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
1645 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
Marshall Clow64c10d02018-07-02 18:41:15 +00001646
1647template<class _CharT,
1648 class _Traits,
1649 class _Allocator = allocator<_CharT>,
1650 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1651 >
1652explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
1653 -> basic_string<_CharT, _Traits, _Allocator>;
1654
1655template<class _CharT,
1656 class _Traits,
1657 class _Allocator = allocator<_CharT>,
1658 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type,
1659 class _Sz = typename allocator_traits<_Allocator>::size_type
1660 >
1661basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
1662 -> basic_string<_CharT, _Traits, _Allocator>;
Marshall Clow5b1e87e2018-02-08 06:34:03 +00001663#endif
1664
1665
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001666template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001667inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001668void
1669basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1670{
Howard Hinnant499cea12013-08-23 17:37:05 +00001671#if _LIBCPP_DEBUG_LEVEL >= 2
1672 __get_db()->__invalidate_all(this);
1673#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001674}
1675
1676template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001677inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001678void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001679basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001680#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001681 __pos
1682#endif
1683 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001684{
Howard Hinnant499cea12013-08-23 17:37:05 +00001685#if _LIBCPP_DEBUG_LEVEL >= 2
1686 __c_node* __c = __get_db()->__find_c_and_lock(this);
1687 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001688 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001689 const_pointer __new_last = __get_pointer() + __pos;
1690 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001691 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001692 --__p;
1693 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1694 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001695 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001696 (*__p)->__c_ = nullptr;
1697 if (--__c->end_ != __p)
1698 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001699 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001700 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001701 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001702 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001703#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001704}
1705
1706template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001707inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001708basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001709 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001710{
Howard Hinnant499cea12013-08-23 17:37:05 +00001711#if _LIBCPP_DEBUG_LEVEL >= 2
1712 __get_db()->__insert_c(this);
1713#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001714 __zero();
1715}
1716
1717template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001718inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001719basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001720#if _LIBCPP_STD_VER <= 14
1721 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1722#else
1723 _NOEXCEPT
1724#endif
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001725: __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001726{
Howard Hinnant499cea12013-08-23 17:37:05 +00001727#if _LIBCPP_DEBUG_LEVEL >= 2
1728 __get_db()->__insert_c(this);
1729#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001730 __zero();
1731}
1732
1733template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001734void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1735 size_type __sz,
1736 size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001737{
1738 if (__reserve > max_size())
1739 this->__throw_length_error();
1740 pointer __p;
1741 if (__reserve < __min_cap)
1742 {
1743 __set_short_size(__sz);
1744 __p = __get_short_pointer();
1745 }
1746 else
1747 {
1748 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001749 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001750 __set_long_pointer(__p);
1751 __set_long_cap(__cap+1);
1752 __set_long_size(__sz);
1753 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001754 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001755 traits_type::assign(__p[__sz], value_type());
1756}
1757
1758template <class _CharT, class _Traits, class _Allocator>
1759void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001760basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001761{
1762 if (__sz > max_size())
1763 this->__throw_length_error();
1764 pointer __p;
1765 if (__sz < __min_cap)
1766 {
1767 __set_short_size(__sz);
1768 __p = __get_short_pointer();
1769 }
1770 else
1771 {
1772 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001773 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001774 __set_long_pointer(__p);
1775 __set_long_cap(__cap+1);
1776 __set_long_size(__sz);
1777 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001778 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001779 traits_type::assign(__p[__sz], value_type());
1780}
1781
1782template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001783template <class>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001784basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001785 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001786{
Howard Hinnant499cea12013-08-23 17:37:05 +00001787 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001788 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001789#if _LIBCPP_DEBUG_LEVEL >= 2
1790 __get_db()->__insert_c(this);
1791#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001792}
1793
1794template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001795inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001796basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001797{
Howard Hinnant499cea12013-08-23 17:37:05 +00001798 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001799 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001800#if _LIBCPP_DEBUG_LEVEL >= 2
1801 __get_db()->__insert_c(this);
1802#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001803}
1804
1805template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001806inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001807basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001808 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001809{
Howard Hinnant499cea12013-08-23 17:37:05 +00001810 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001811 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001812#if _LIBCPP_DEBUG_LEVEL >= 2
1813 __get_db()->__insert_c(this);
1814#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001815}
1816
1817template <class _CharT, class _Traits, class _Allocator>
1818basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001819 : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001820{
1821 if (!__str.__is_long())
1822 __r_.first().__r = __str.__r_.first().__r;
1823 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001824 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001825#if _LIBCPP_DEBUG_LEVEL >= 2
1826 __get_db()->__insert_c(this);
1827#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001828}
1829
1830template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001831basic_string<_CharT, _Traits, _Allocator>::basic_string(
1832 const basic_string& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001833 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001834{
1835 if (!__str.__is_long())
1836 __r_.first().__r = __str.__r_.first().__r;
1837 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001838 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001839#if _LIBCPP_DEBUG_LEVEL >= 2
1840 __get_db()->__insert_c(this);
1841#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001842}
1843
Eric Fiselier3e928972017-04-19 00:28:44 +00001844#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001845
1846template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001847inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001848basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001849#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001850 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00001851#else
1852 _NOEXCEPT
1853#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001854 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001855{
1856 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00001857#if _LIBCPP_DEBUG_LEVEL >= 2
1858 __get_db()->__insert_c(this);
1859 if (__is_long())
1860 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001861#endif
1862}
1863
1864template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001865inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001866basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001867 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001868{
Marshall Clowd5549cc2014-07-17 15:32:20 +00001869 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001870 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00001871 else
1872 {
1873 __r_.first().__r = __str.__r_.first().__r;
1874 __str.__zero();
1875 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001876#if _LIBCPP_DEBUG_LEVEL >= 2
1877 __get_db()->__insert_c(this);
1878 if (__is_long())
1879 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001880#endif
1881}
1882
Eric Fiselier3e928972017-04-19 00:28:44 +00001883#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001884
1885template <class _CharT, class _Traits, class _Allocator>
1886void
1887basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1888{
1889 if (__n > max_size())
1890 this->__throw_length_error();
1891 pointer __p;
1892 if (__n < __min_cap)
1893 {
1894 __set_short_size(__n);
1895 __p = __get_short_pointer();
1896 }
1897 else
1898 {
1899 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001900 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001901 __set_long_pointer(__p);
1902 __set_long_cap(__cap+1);
1903 __set_long_size(__n);
1904 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001905 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001906 traits_type::assign(__p[__n], value_type());
1907}
1908
1909template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001910inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001911basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001912{
1913 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001914#if _LIBCPP_DEBUG_LEVEL >= 2
1915 __get_db()->__insert_c(this);
1916#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001917}
1918
1919template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001920template <class>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001921basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001922 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001923{
1924 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001925#if _LIBCPP_DEBUG_LEVEL >= 2
1926 __get_db()->__insert_c(this);
1927#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001928}
1929
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001930template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001931basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1932 size_type __pos, size_type __n,
1933 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001934 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935{
1936 size_type __str_sz = __str.size();
1937 if (__pos > __str_sz)
1938 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001939 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00001940#if _LIBCPP_DEBUG_LEVEL >= 2
1941 __get_db()->__insert_c(this);
1942#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001943}
1944
1945template <class _CharT, class _Traits, class _Allocator>
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001946inline _LIBCPP_INLINE_VISIBILITY
1947basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001948 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001949 : __r_(__second_tag(), __a)
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001950{
1951 size_type __str_sz = __str.size();
1952 if (__pos > __str_sz)
1953 this->__throw_out_of_range();
1954 __init(__str.data() + __pos, __str_sz - __pos);
1955#if _LIBCPP_DEBUG_LEVEL >= 2
1956 __get_db()->__insert_c(this);
1957#endif
1958}
1959
1960template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001961template <class _Tp, class>
Marshall Clowdb7fa112016-11-14 18:22:19 +00001962basic_string<_CharT, _Traits, _Allocator>::basic_string(
Marshall Clow64c10d02018-07-02 18:41:15 +00001963 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001964 : __r_(__second_tag(), __a)
Marshall Clowdb7fa112016-11-14 18:22:19 +00001965{
Marshall Clow64c10d02018-07-02 18:41:15 +00001966 __self_view __sv0 = __t;
1967 __self_view __sv = __sv0.substr(__pos, __n);
Marshall Clowdb7fa112016-11-14 18:22:19 +00001968 __init(__sv.data(), __sv.size());
1969#if _LIBCPP_DEBUG_LEVEL >= 2
1970 __get_db()->__insert_c(this);
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001971#endif
Marshall Clowdb7fa112016-11-14 18:22:19 +00001972}
1973
1974template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001975template <class _Tp, class>
1976basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001977{
Marshall Clow64c10d02018-07-02 18:41:15 +00001978 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001979 __init(__sv.data(), __sv.size());
1980#if _LIBCPP_DEBUG_LEVEL >= 2
1981 __get_db()->__insert_c(this);
1982#endif
1983}
1984
1985template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001986template <class _Tp, class>
1987basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001988 : __r_(__second_tag(), __a)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001989{
Marshall Clow64c10d02018-07-02 18:41:15 +00001990 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001991 __init(__sv.data(), __sv.size());
1992#if _LIBCPP_DEBUG_LEVEL >= 2
1993 __get_db()->__insert_c(this);
1994#endif
1995}
1996
1997template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001998template <class _InputIterator>
1999typename enable_if
2000<
Marshall Clowdf9db312016-01-13 21:54:34 +00002001 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002002 void
2003>::type
2004basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2005{
2006 __zero();
2007#ifndef _LIBCPP_NO_EXCEPTIONS
2008 try
2009 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002010#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002011 for (; __first != __last; ++__first)
2012 push_back(*__first);
2013#ifndef _LIBCPP_NO_EXCEPTIONS
2014 }
2015 catch (...)
2016 {
2017 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002018 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002019 throw;
2020 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002021#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002022}
2023
2024template <class _CharT, class _Traits, class _Allocator>
2025template <class _ForwardIterator>
2026typename enable_if
2027<
2028 __is_forward_iterator<_ForwardIterator>::value,
2029 void
2030>::type
2031basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2032{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002033 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002034 if (__sz > max_size())
2035 this->__throw_length_error();
2036 pointer __p;
2037 if (__sz < __min_cap)
2038 {
2039 __set_short_size(__sz);
2040 __p = __get_short_pointer();
2041 }
2042 else
2043 {
2044 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002045 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002046 __set_long_pointer(__p);
2047 __set_long_cap(__cap+1);
2048 __set_long_size(__sz);
2049 }
Eric Fiselierb9919752014-10-27 19:28:20 +00002050 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002051 traits_type::assign(*__p, *__first);
2052 traits_type::assign(*__p, value_type());
2053}
2054
2055template <class _CharT, class _Traits, class _Allocator>
2056template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002057inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002058basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2059{
2060 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002061#if _LIBCPP_DEBUG_LEVEL >= 2
2062 __get_db()->__insert_c(this);
2063#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002064}
2065
2066template <class _CharT, class _Traits, class _Allocator>
2067template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002068inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002069basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2070 const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002071 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002072{
2073 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002074#if _LIBCPP_DEBUG_LEVEL >= 2
2075 __get_db()->__insert_c(this);
2076#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002077}
2078
Eric Fiselier3e928972017-04-19 00:28:44 +00002079#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00002080
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002081template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002082inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00002083basic_string<_CharT, _Traits, _Allocator>::basic_string(
2084 initializer_list<_CharT> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002085{
2086 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002087#if _LIBCPP_DEBUG_LEVEL >= 2
2088 __get_db()->__insert_c(this);
2089#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002090}
2091
2092template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002093inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002094
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00002095basic_string<_CharT, _Traits, _Allocator>::basic_string(
2096 initializer_list<_CharT> __il, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002097 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002098{
2099 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002100#if _LIBCPP_DEBUG_LEVEL >= 2
2101 __get_db()->__insert_c(this);
2102#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002103}
2104
Eric Fiselier3e928972017-04-19 00:28:44 +00002105#endif // _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00002106
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002107template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002108basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2109{
Howard Hinnant499cea12013-08-23 17:37:05 +00002110#if _LIBCPP_DEBUG_LEVEL >= 2
2111 __get_db()->__erase_c(this);
2112#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002113 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002114 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002115}
2116
2117template <class _CharT, class _Traits, class _Allocator>
2118void
2119basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2120 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002121 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 +00002122{
2123 size_type __ms = max_size();
2124 if (__delta_cap > __ms - __old_cap - 1)
2125 this->__throw_length_error();
2126 pointer __old_p = __get_pointer();
2127 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002128 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002129 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002130 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002131 __invalidate_all_iterators();
2132 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002133 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2134 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002135 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002136 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002137 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2138 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002139 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2140 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002141 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002142 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002143 __set_long_pointer(__p);
2144 __set_long_cap(__cap+1);
2145 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2146 __set_long_size(__old_sz);
2147 traits_type::assign(__p[__old_sz], value_type());
2148}
2149
2150template <class _CharT, class _Traits, class _Allocator>
2151void
2152basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2153 size_type __n_copy, size_type __n_del, size_type __n_add)
2154{
2155 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00002156 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002157 this->__throw_length_error();
2158 pointer __old_p = __get_pointer();
2159 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002160 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002161 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002162 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002163 __invalidate_all_iterators();
2164 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002165 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2166 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002167 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2168 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002169 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2170 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2171 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002172 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002173 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002174 __set_long_pointer(__p);
2175 __set_long_cap(__cap+1);
2176}
2177
2178// assign
2179
2180template <class _CharT, class _Traits, class _Allocator>
2181basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002182basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002183{
Alp Tokerec34c482014-05-15 11:27:39 +00002184 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002185 size_type __cap = capacity();
2186 if (__cap >= __n)
2187 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002188 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002189 traits_type::move(__p, __s, __n);
2190 traits_type::assign(__p[__n], value_type());
2191 __set_size(__n);
2192 __invalidate_iterators_past(__n);
2193 }
2194 else
2195 {
2196 size_type __sz = size();
2197 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2198 }
2199 return *this;
2200}
2201
2202template <class _CharT, class _Traits, class _Allocator>
2203basic_string<_CharT, _Traits, _Allocator>&
2204basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2205{
2206 size_type __cap = capacity();
2207 if (__cap < __n)
2208 {
2209 size_type __sz = size();
2210 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2211 }
2212 else
2213 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002214 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002215 traits_type::assign(__p, __n, __c);
2216 traits_type::assign(__p[__n], value_type());
2217 __set_size(__n);
2218 return *this;
2219}
2220
2221template <class _CharT, class _Traits, class _Allocator>
2222basic_string<_CharT, _Traits, _Allocator>&
2223basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2224{
2225 pointer __p;
2226 if (__is_long())
2227 {
2228 __p = __get_long_pointer();
2229 __set_long_size(1);
2230 }
2231 else
2232 {
2233 __p = __get_short_pointer();
2234 __set_short_size(1);
2235 }
2236 traits_type::assign(*__p, __c);
2237 traits_type::assign(*++__p, value_type());
2238 __invalidate_iterators_past(1);
2239 return *this;
2240}
2241
2242template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002243basic_string<_CharT, _Traits, _Allocator>&
2244basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2245{
2246 if (this != &__str)
2247 {
2248 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00002249 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00002250 }
2251 return *this;
2252}
2253
Eric Fiselier3e928972017-04-19 00:28:44 +00002254#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante32b5e22010-11-17 17:55:08 +00002255
2256template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002257inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002258void
2259basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002260 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002261{
2262 if (__alloc() != __str.__alloc())
2263 assign(__str);
2264 else
2265 __move_assign(__str, true_type());
2266}
2267
2268template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002269inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002270void
2271basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002272#if _LIBCPP_STD_VER > 14
2273 _NOEXCEPT
2274#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002275 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002276#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002277{
Vedant Kumar2b588cb2018-03-08 21:15:26 +00002278 __clear_and_shrink();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002279 __r_.first() = __str.__r_.first();
2280 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002281 __str.__zero();
2282}
2283
2284template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002285inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002286basic_string<_CharT, _Traits, _Allocator>&
2287basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002288 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002289{
2290 __move_assign(__str, integral_constant<bool,
2291 __alloc_traits::propagate_on_container_move_assignment::value>());
2292 return *this;
2293}
2294
2295#endif
2296
2297template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002298template<class _InputIterator>
2299typename enable_if
2300<
Marshall Clowdf9db312016-01-13 21:54:34 +00002301 __is_exactly_input_iterator <_InputIterator>::value
2302 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002303 basic_string<_CharT, _Traits, _Allocator>&
2304>::type
2305basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2306{
Marshall Clowd979eed2016-09-05 01:54:30 +00002307 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002308 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002309 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002310}
2311
2312template <class _CharT, class _Traits, class _Allocator>
2313template<class _ForwardIterator>
2314typename enable_if
2315<
Marshall Clowdf9db312016-01-13 21:54:34 +00002316 __is_forward_iterator<_ForwardIterator>::value
2317 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002318 basic_string<_CharT, _Traits, _Allocator>&
2319>::type
2320basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2321{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002322 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002323 size_type __cap = capacity();
2324 if (__cap < __n)
2325 {
2326 size_type __sz = size();
2327 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2328 }
2329 else
2330 __invalidate_iterators_past(__n);
2331 pointer __p = __get_pointer();
2332 for (; __first != __last; ++__first, ++__p)
2333 traits_type::assign(*__p, *__first);
2334 traits_type::assign(*__p, value_type());
2335 __set_size(__n);
2336 return *this;
2337}
2338
2339template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002340basic_string<_CharT, _Traits, _Allocator>&
2341basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2342{
2343 size_type __sz = __str.size();
2344 if (__pos > __sz)
2345 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002346 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002347}
2348
2349template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002350template <class _Tp>
2351typename enable_if
2352<
2353 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002354 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002355>::type
2356basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002357{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002358 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002359 size_type __sz = __sv.size();
2360 if (__pos > __sz)
2361 this->__throw_out_of_range();
2362 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2363}
2364
2365
2366template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002367basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002368basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002369{
Alp Tokerec34c482014-05-15 11:27:39 +00002370 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002371 return assign(__s, traits_type::length(__s));
2372}
2373
2374// append
2375
2376template <class _CharT, class _Traits, class _Allocator>
2377basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002378basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002379{
Alp Tokerec34c482014-05-15 11:27:39 +00002380 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002381 size_type __cap = capacity();
2382 size_type __sz = size();
2383 if (__cap - __sz >= __n)
2384 {
2385 if (__n)
2386 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002387 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002388 traits_type::copy(__p + __sz, __s, __n);
2389 __sz += __n;
2390 __set_size(__sz);
2391 traits_type::assign(__p[__sz], value_type());
2392 }
2393 }
2394 else
2395 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2396 return *this;
2397}
2398
2399template <class _CharT, class _Traits, class _Allocator>
2400basic_string<_CharT, _Traits, _Allocator>&
2401basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2402{
2403 if (__n)
2404 {
2405 size_type __cap = capacity();
2406 size_type __sz = size();
2407 if (__cap - __sz < __n)
2408 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2409 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002410 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002411 __sz += __n;
2412 __set_size(__sz);
2413 traits_type::assign(__p[__sz], value_type());
2414 }
2415 return *this;
2416}
2417
2418template <class _CharT, class _Traits, class _Allocator>
2419void
2420basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2421{
Howard Hinnant15467182013-04-30 21:44:48 +00002422 bool __is_short = !__is_long();
2423 size_type __cap;
2424 size_type __sz;
2425 if (__is_short)
2426 {
2427 __cap = __min_cap - 1;
2428 __sz = __get_short_size();
2429 }
2430 else
2431 {
2432 __cap = __get_long_cap() - 1;
2433 __sz = __get_long_size();
2434 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002435 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002436 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002437 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002438 __is_short = !__is_long();
2439 }
2440 pointer __p;
2441 if (__is_short)
2442 {
2443 __p = __get_short_pointer() + __sz;
2444 __set_short_size(__sz+1);
2445 }
2446 else
2447 {
2448 __p = __get_long_pointer() + __sz;
2449 __set_long_size(__sz+1);
2450 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002451 traits_type::assign(*__p, __c);
2452 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002453}
2454
Marshall Clowac655ef2016-09-07 03:32:06 +00002455template <class _Tp>
Marshall Clowd979eed2016-09-05 01:54:30 +00002456bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2457{
2458 return __first <= __p && __p < __last;
2459}
2460
Marshall Clowac655ef2016-09-07 03:32:06 +00002461template <class _Tp1, class _Tp2>
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00002462bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
Marshall Clowac655ef2016-09-07 03:32:06 +00002463{
2464 return false;
2465}
2466
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002467template <class _CharT, class _Traits, class _Allocator>
2468template<class _ForwardIterator>
Eric Fiselier026d38e2016-10-31 02:46:25 +00002469basic_string<_CharT, _Traits, _Allocator>&
2470basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2471 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002472{
Eric Fiselier026d38e2016-10-31 02:46:25 +00002473 static_assert(__is_forward_iterator<_ForwardIterator>::value,
2474 "function requires a ForwardIterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002475 size_type __sz = size();
2476 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002477 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002478 if (__n)
2479 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002480 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2481 _CharRef __tmp_ref = *__first;
2482 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002483 {
2484 const basic_string __temp (__first, __last, __alloc());
2485 append(__temp.data(), __temp.size());
2486 }
2487 else
2488 {
2489 if (__cap - __sz < __n)
2490 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2491 pointer __p = __get_pointer() + __sz;
2492 for (; __first != __last; ++__p, ++__first)
2493 traits_type::assign(*__p, *__first);
2494 traits_type::assign(*__p, value_type());
2495 __set_size(__sz + __n);
2496 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002497 }
2498 return *this;
2499}
2500
2501template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002502inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002503basic_string<_CharT, _Traits, _Allocator>&
2504basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2505{
2506 return append(__str.data(), __str.size());
2507}
2508
2509template <class _CharT, class _Traits, class _Allocator>
2510basic_string<_CharT, _Traits, _Allocator>&
2511basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2512{
2513 size_type __sz = __str.size();
2514 if (__pos > __sz)
2515 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002516 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002517}
2518
2519template <class _CharT, class _Traits, class _Allocator>
Marshall Clow42a87db2016-10-03 23:40:48 +00002520template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002521 typename enable_if
2522 <
2523 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2524 basic_string<_CharT, _Traits, _Allocator>&
2525 >::type
2526basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002527{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002528 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002529 size_type __sz = __sv.size();
2530 if (__pos > __sz)
2531 this->__throw_out_of_range();
2532 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2533}
2534
2535template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002536basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002537basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002538{
Alp Tokerec34c482014-05-15 11:27:39 +00002539 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002540 return append(__s, traits_type::length(__s));
2541}
2542
2543// insert
2544
2545template <class _CharT, class _Traits, class _Allocator>
2546basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002547basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002548{
Alp Tokerec34c482014-05-15 11:27:39 +00002549 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002550 size_type __sz = size();
2551 if (__pos > __sz)
2552 this->__throw_out_of_range();
2553 size_type __cap = capacity();
2554 if (__cap - __sz >= __n)
2555 {
2556 if (__n)
2557 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002558 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002559 size_type __n_move = __sz - __pos;
2560 if (__n_move != 0)
2561 {
2562 if (__p + __pos <= __s && __s < __p + __sz)
2563 __s += __n;
2564 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2565 }
2566 traits_type::move(__p + __pos, __s, __n);
2567 __sz += __n;
2568 __set_size(__sz);
2569 traits_type::assign(__p[__sz], value_type());
2570 }
2571 }
2572 else
2573 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2574 return *this;
2575}
2576
2577template <class _CharT, class _Traits, class _Allocator>
2578basic_string<_CharT, _Traits, _Allocator>&
2579basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2580{
2581 size_type __sz = size();
2582 if (__pos > __sz)
2583 this->__throw_out_of_range();
2584 if (__n)
2585 {
2586 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002587 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002588 if (__cap - __sz >= __n)
2589 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002590 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002591 size_type __n_move = __sz - __pos;
2592 if (__n_move != 0)
2593 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2594 }
2595 else
2596 {
2597 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002598 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002599 }
2600 traits_type::assign(__p + __pos, __n, __c);
2601 __sz += __n;
2602 __set_size(__sz);
2603 traits_type::assign(__p[__sz], value_type());
2604 }
2605 return *this;
2606}
2607
2608template <class _CharT, class _Traits, class _Allocator>
2609template<class _InputIterator>
2610typename enable_if
2611<
Marshall Clowdf9db312016-01-13 21:54:34 +00002612 __is_exactly_input_iterator<_InputIterator>::value
2613 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2614 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002615>::type
2616basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2617{
Howard Hinnant499cea12013-08-23 17:37:05 +00002618#if _LIBCPP_DEBUG_LEVEL >= 2
2619 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2620 "string::insert(iterator, range) called with an iterator not"
2621 " referring to this string");
2622#endif
Marshall Clowd979eed2016-09-05 01:54:30 +00002623 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002624 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002625}
2626
2627template <class _CharT, class _Traits, class _Allocator>
2628template<class _ForwardIterator>
2629typename enable_if
2630<
Marshall Clowdf9db312016-01-13 21:54:34 +00002631 __is_forward_iterator<_ForwardIterator>::value
2632 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002633 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2634>::type
2635basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2636{
Howard Hinnant499cea12013-08-23 17:37:05 +00002637#if _LIBCPP_DEBUG_LEVEL >= 2
2638 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2639 "string::insert(iterator, range) called with an iterator not"
2640 " referring to this string");
2641#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002642 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002643 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002644 if (__n)
2645 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002646 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2647 _CharRef __tmp_char = *__first;
2648 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002649 {
2650 const basic_string __temp(__first, __last, __alloc());
2651 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2652 }
2653
2654 size_type __sz = size();
2655 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002656 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002657 if (__cap - __sz >= __n)
2658 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002659 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002660 size_type __n_move = __sz - __ip;
2661 if (__n_move != 0)
2662 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2663 }
2664 else
2665 {
2666 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002667 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002668 }
2669 __sz += __n;
2670 __set_size(__sz);
2671 traits_type::assign(__p[__sz], value_type());
2672 for (__p += __ip; __first != __last; ++__p, ++__first)
2673 traits_type::assign(*__p, *__first);
2674 }
2675 return begin() + __ip;
2676}
2677
2678template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002679inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002680basic_string<_CharT, _Traits, _Allocator>&
2681basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2682{
2683 return insert(__pos1, __str.data(), __str.size());
2684}
2685
2686template <class _CharT, class _Traits, class _Allocator>
2687basic_string<_CharT, _Traits, _Allocator>&
2688basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2689 size_type __pos2, size_type __n)
2690{
2691 size_type __str_sz = __str.size();
2692 if (__pos2 > __str_sz)
2693 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002694 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002695}
2696
2697template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002698template <class _Tp>
2699typename enable_if
2700<
2701 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002702 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002703>::type
2704basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002705 size_type __pos2, size_type __n)
2706{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002707 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002708 size_type __str_sz = __sv.size();
2709 if (__pos2 > __str_sz)
2710 this->__throw_out_of_range();
2711 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2712}
2713
2714template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002715basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002716basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002717{
Alp Tokerec34c482014-05-15 11:27:39 +00002718 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002719 return insert(__pos, __s, traits_type::length(__s));
2720}
2721
2722template <class _CharT, class _Traits, class _Allocator>
2723typename basic_string<_CharT, _Traits, _Allocator>::iterator
2724basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2725{
2726 size_type __ip = static_cast<size_type>(__pos - begin());
2727 size_type __sz = size();
2728 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002729 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002730 if (__cap == __sz)
2731 {
2732 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002733 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002734 }
2735 else
2736 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002737 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002738 size_type __n_move = __sz - __ip;
2739 if (__n_move != 0)
2740 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2741 }
2742 traits_type::assign(__p[__ip], __c);
2743 traits_type::assign(__p[++__sz], value_type());
2744 __set_size(__sz);
2745 return begin() + static_cast<difference_type>(__ip);
2746}
2747
2748template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002749inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002750typename basic_string<_CharT, _Traits, _Allocator>::iterator
2751basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2752{
Howard Hinnant499cea12013-08-23 17:37:05 +00002753#if _LIBCPP_DEBUG_LEVEL >= 2
2754 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2755 "string::insert(iterator, n, value) called with an iterator not"
2756 " referring to this string");
2757#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002758 difference_type __p = __pos - begin();
2759 insert(static_cast<size_type>(__p), __n, __c);
2760 return begin() + __p;
2761}
2762
2763// replace
2764
2765template <class _CharT, class _Traits, class _Allocator>
2766basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002767basic_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 +00002768 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002769{
Alp Tokerec34c482014-05-15 11:27:39 +00002770 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002771 size_type __sz = size();
2772 if (__pos > __sz)
2773 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002774 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002775 size_type __cap = capacity();
2776 if (__cap - __sz + __n1 >= __n2)
2777 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002778 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002779 if (__n1 != __n2)
2780 {
2781 size_type __n_move = __sz - __pos - __n1;
2782 if (__n_move != 0)
2783 {
2784 if (__n1 > __n2)
2785 {
2786 traits_type::move(__p + __pos, __s, __n2);
2787 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2788 goto __finish;
2789 }
2790 if (__p + __pos < __s && __s < __p + __sz)
2791 {
2792 if (__p + __pos + __n1 <= __s)
2793 __s += __n2 - __n1;
2794 else // __p + __pos < __s < __p + __pos + __n1
2795 {
2796 traits_type::move(__p + __pos, __s, __n1);
2797 __pos += __n1;
2798 __s += __n2;
2799 __n2 -= __n1;
2800 __n1 = 0;
2801 }
2802 }
2803 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2804 }
2805 }
2806 traits_type::move(__p + __pos, __s, __n2);
2807__finish:
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002808// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
2809// but this is a safe operation, so we disable the check.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002810 __sz += __n2 - __n1;
2811 __set_size(__sz);
2812 __invalidate_iterators_past(__sz);
2813 traits_type::assign(__p[__sz], value_type());
2814 }
2815 else
2816 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2817 return *this;
2818}
2819
2820template <class _CharT, class _Traits, class _Allocator>
2821basic_string<_CharT, _Traits, _Allocator>&
2822basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002823 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002824{
2825 size_type __sz = size();
2826 if (__pos > __sz)
2827 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002828 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002829 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002830 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002831 if (__cap - __sz + __n1 >= __n2)
2832 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002833 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002834 if (__n1 != __n2)
2835 {
2836 size_type __n_move = __sz - __pos - __n1;
2837 if (__n_move != 0)
2838 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2839 }
2840 }
2841 else
2842 {
2843 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002844 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002845 }
2846 traits_type::assign(__p + __pos, __n2, __c);
2847 __sz += __n2 - __n1;
2848 __set_size(__sz);
2849 __invalidate_iterators_past(__sz);
2850 traits_type::assign(__p[__sz], value_type());
2851 return *this;
2852}
2853
2854template <class _CharT, class _Traits, class _Allocator>
2855template<class _InputIterator>
2856typename enable_if
2857<
2858 __is_input_iterator<_InputIterator>::value,
2859 basic_string<_CharT, _Traits, _Allocator>&
2860>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002861basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002862 _InputIterator __j1, _InputIterator __j2)
2863{
Marshall Clowd979eed2016-09-05 01:54:30 +00002864 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002865 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002866}
2867
2868template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002869inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002870basic_string<_CharT, _Traits, _Allocator>&
2871basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2872{
2873 return replace(__pos1, __n1, __str.data(), __str.size());
2874}
2875
2876template <class _CharT, class _Traits, class _Allocator>
2877basic_string<_CharT, _Traits, _Allocator>&
2878basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2879 size_type __pos2, size_type __n2)
2880{
2881 size_type __str_sz = __str.size();
2882 if (__pos2 > __str_sz)
2883 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002884 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002885}
2886
2887template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002888template <class _Tp>
2889typename enable_if
2890<
Marshall Clowf1729d92017-11-15 20:02:27 +00002891 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2892 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002893>::type
2894basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002895 size_type __pos2, size_type __n2)
2896{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002897 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002898 size_type __str_sz = __sv.size();
2899 if (__pos2 > __str_sz)
2900 this->__throw_out_of_range();
2901 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2902}
2903
2904template <class _CharT, class _Traits, class _Allocator>
2905basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002906basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002907{
Alp Tokerec34c482014-05-15 11:27:39 +00002908 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002909 return replace(__pos, __n1, __s, traits_type::length(__s));
2910}
2911
2912template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002913inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002914basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002915basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002916{
2917 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2918 __str.data(), __str.size());
2919}
2920
2921template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002922inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002923basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002924basic_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 +00002925{
2926 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2927}
2928
2929template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002930inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002931basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002932basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002933{
2934 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2935}
2936
2937template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002938inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002939basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002940basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002941{
2942 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2943}
2944
2945// erase
2946
2947template <class _CharT, class _Traits, class _Allocator>
2948basic_string<_CharT, _Traits, _Allocator>&
2949basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2950{
2951 size_type __sz = size();
2952 if (__pos > __sz)
2953 this->__throw_out_of_range();
2954 if (__n)
2955 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002956 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002957 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002958 size_type __n_move = __sz - __pos - __n;
2959 if (__n_move != 0)
2960 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2961 __sz -= __n;
2962 __set_size(__sz);
2963 __invalidate_iterators_past(__sz);
2964 traits_type::assign(__p[__sz], value_type());
2965 }
2966 return *this;
2967}
2968
2969template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002970inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002971typename basic_string<_CharT, _Traits, _Allocator>::iterator
2972basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2973{
Howard Hinnant499cea12013-08-23 17:37:05 +00002974#if _LIBCPP_DEBUG_LEVEL >= 2
2975 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2976 "string::erase(iterator) called with an iterator not"
2977 " referring to this string");
2978#endif
2979 _LIBCPP_ASSERT(__pos != end(),
2980 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002981 iterator __b = begin();
2982 size_type __r = static_cast<size_type>(__pos - __b);
2983 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002984 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002985}
2986
2987template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002988inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002989typename basic_string<_CharT, _Traits, _Allocator>::iterator
2990basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2991{
Howard Hinnant499cea12013-08-23 17:37:05 +00002992#if _LIBCPP_DEBUG_LEVEL >= 2
2993 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2994 "string::erase(iterator, iterator) called with an iterator not"
2995 " referring to this string");
2996#endif
2997 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002998 iterator __b = begin();
2999 size_type __r = static_cast<size_type>(__first - __b);
3000 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00003001 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003002}
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 +00003006void
3007basic_string<_CharT, _Traits, _Allocator>::pop_back()
3008{
Howard Hinnant499cea12013-08-23 17:37:05 +00003009 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003010 size_type __sz;
3011 if (__is_long())
3012 {
3013 __sz = __get_long_size() - 1;
3014 __set_long_size(__sz);
3015 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3016 }
3017 else
3018 {
3019 __sz = __get_short_size() - 1;
3020 __set_short_size(__sz);
3021 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3022 }
3023 __invalidate_iterators_past(__sz);
3024}
3025
3026template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003027inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003028void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003029basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003030{
3031 __invalidate_all_iterators();
3032 if (__is_long())
3033 {
3034 traits_type::assign(*__get_long_pointer(), value_type());
3035 __set_long_size(0);
3036 }
3037 else
3038 {
3039 traits_type::assign(*__get_short_pointer(), value_type());
3040 __set_short_size(0);
3041 }
3042}
3043
3044template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003045inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003046void
3047basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3048{
3049 if (__is_long())
3050 {
3051 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3052 __set_long_size(__pos);
3053 }
3054 else
3055 {
3056 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3057 __set_short_size(__pos);
3058 }
3059 __invalidate_iterators_past(__pos);
3060}
3061
3062template <class _CharT, class _Traits, class _Allocator>
3063void
3064basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3065{
3066 size_type __sz = size();
3067 if (__n > __sz)
3068 append(__n - __sz, __c);
3069 else
3070 __erase_to_end(__n);
3071}
3072
3073template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003074inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003075typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003076basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003077{
Howard Hinnante32b5e22010-11-17 17:55:08 +00003078 size_type __m = __alloc_traits::max_size(__alloc());
Eric Fiselier5ccf0432017-10-17 13:16:01 +00003079#ifdef _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00003080 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003081#else
Marshall Clow09f85502013-10-31 17:23:08 +00003082 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003083#endif
3084}
3085
3086template <class _CharT, class _Traits, class _Allocator>
3087void
3088basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3089{
3090 if (__res_arg > max_size())
3091 this->__throw_length_error();
3092 size_type __cap = capacity();
3093 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003094 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003095 __res_arg = __recommend(__res_arg);
3096 if (__res_arg != __cap)
3097 {
3098 pointer __new_data, __p;
3099 bool __was_long, __now_long;
3100 if (__res_arg == __min_cap - 1)
3101 {
3102 __was_long = true;
3103 __now_long = false;
3104 __new_data = __get_short_pointer();
3105 __p = __get_long_pointer();
3106 }
3107 else
3108 {
3109 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003110 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003111 else
3112 {
3113 #ifndef _LIBCPP_NO_EXCEPTIONS
3114 try
3115 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003116 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00003117 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003118 #ifndef _LIBCPP_NO_EXCEPTIONS
3119 }
3120 catch (...)
3121 {
3122 return;
3123 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003124 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003125 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003126 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003127 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003128 }
3129 __now_long = true;
3130 __was_long = __is_long();
3131 __p = __get_pointer();
3132 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003133 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3134 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003135 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003136 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003137 if (__now_long)
3138 {
3139 __set_long_cap(__res_arg+1);
3140 __set_long_size(__sz);
3141 __set_long_pointer(__new_data);
3142 }
3143 else
3144 __set_short_size(__sz);
3145 __invalidate_all_iterators();
3146 }
3147}
3148
3149template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003150inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003151typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003152basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003153{
Howard Hinnant499cea12013-08-23 17:37:05 +00003154 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003155 return *(data() + __pos);
3156}
3157
3158template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003159inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003160typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003161basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003162{
Howard Hinnant499cea12013-08-23 17:37:05 +00003163 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003164 return *(__get_pointer() + __pos);
3165}
3166
3167template <class _CharT, class _Traits, class _Allocator>
3168typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3169basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3170{
3171 if (__n >= size())
3172 this->__throw_out_of_range();
3173 return (*this)[__n];
3174}
3175
3176template <class _CharT, class _Traits, class _Allocator>
3177typename basic_string<_CharT, _Traits, _Allocator>::reference
3178basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3179{
3180 if (__n >= size())
3181 this->__throw_out_of_range();
3182 return (*this)[__n];
3183}
3184
3185template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003186inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003187typename basic_string<_CharT, _Traits, _Allocator>::reference
3188basic_string<_CharT, _Traits, _Allocator>::front()
3189{
Howard Hinnant499cea12013-08-23 17:37:05 +00003190 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003191 return *__get_pointer();
3192}
3193
3194template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003195inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003196typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3197basic_string<_CharT, _Traits, _Allocator>::front() const
3198{
Howard Hinnant499cea12013-08-23 17:37:05 +00003199 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003200 return *data();
3201}
3202
3203template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003204inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003205typename basic_string<_CharT, _Traits, _Allocator>::reference
3206basic_string<_CharT, _Traits, _Allocator>::back()
3207{
Howard Hinnant499cea12013-08-23 17:37:05 +00003208 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003209 return *(__get_pointer() + size() - 1);
3210}
3211
3212template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003213inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003214typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3215basic_string<_CharT, _Traits, _Allocator>::back() const
3216{
Howard Hinnant499cea12013-08-23 17:37:05 +00003217 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003218 return *(data() + size() - 1);
3219}
3220
3221template <class _CharT, class _Traits, class _Allocator>
3222typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003223basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003224{
3225 size_type __sz = size();
3226 if (__pos > __sz)
3227 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003228 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003229 traits_type::copy(__s, data() + __pos, __rlen);
3230 return __rlen;
3231}
3232
3233template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003234inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003235basic_string<_CharT, _Traits, _Allocator>
3236basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3237{
3238 return basic_string(*this, __pos, __n, __alloc());
3239}
3240
3241template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003242inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003243void
3244basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00003245#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00003246 _NOEXCEPT_DEBUG
Marshall Clow7d914d12015-07-13 20:04:56 +00003247#else
Eric Fiselier47257c42016-12-28 05:53:01 +00003248 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00003249 __is_nothrow_swappable<allocator_type>::value)
3250#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003251{
Howard Hinnant499cea12013-08-23 17:37:05 +00003252#if _LIBCPP_DEBUG_LEVEL >= 2
3253 if (!__is_long())
3254 __get_db()->__invalidate_all(this);
3255 if (!__str.__is_long())
3256 __get_db()->__invalidate_all(&__str);
3257 __get_db()->swap(this, &__str);
3258#endif
Eric Fiselier47257c42016-12-28 05:53:01 +00003259 _LIBCPP_ASSERT(
3260 __alloc_traits::propagate_on_container_swap::value ||
3261 __alloc_traits::is_always_equal::value ||
3262 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnant0949eed2011-06-30 21:18:19 +00003263 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00003264 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003265}
3266
3267// find
3268
3269template <class _Traits>
3270struct _LIBCPP_HIDDEN __traits_eq
3271{
3272 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003273 _LIBCPP_INLINE_VISIBILITY
3274 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3275 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003276};
3277
3278template<class _CharT, class _Traits, class _Allocator>
3279typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003280basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003281 size_type __pos,
3282 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003283{
Alp Tokerec34c482014-05-15 11:27:39 +00003284 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003285 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003286 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003287}
3288
3289template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003290inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003291typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003292basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3293 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003294{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003295 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003296 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003297}
3298
3299template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003300template <class _Tp>
3301typename enable_if
3302<
3303 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3304 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3305>::type
3306basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
3307 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003308{
Marshall Clow64c10d02018-07-02 18:41:15 +00003309 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003310 return __str_find<value_type, size_type, traits_type, npos>
3311 (data(), size(), __sv.data(), __pos, __sv.size());
3312}
3313
3314template<class _CharT, class _Traits, class _Allocator>
3315inline _LIBCPP_INLINE_VISIBILITY
3316typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003317basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003318 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003319{
Alp Tokerec34c482014-05-15 11:27:39 +00003320 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003321 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003322 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003323}
3324
3325template<class _CharT, class _Traits, class _Allocator>
3326typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003327basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3328 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003329{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003330 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003331 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003332}
3333
3334// rfind
3335
3336template<class _CharT, class _Traits, class _Allocator>
3337typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003338basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003339 size_type __pos,
3340 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003341{
Alp Tokerec34c482014-05-15 11:27:39 +00003342 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003343 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003344 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003345}
3346
3347template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003348inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003349typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003350basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3351 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003352{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003353 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003354 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003355}
3356
3357template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003358template <class _Tp>
3359typename enable_if
3360<
3361 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3362 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3363>::type
3364basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
3365 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003366{
Marshall Clow64c10d02018-07-02 18:41:15 +00003367 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003368 return __str_rfind<value_type, size_type, traits_type, npos>
3369 (data(), size(), __sv.data(), __pos, __sv.size());
3370}
3371
3372template<class _CharT, class _Traits, class _Allocator>
3373inline _LIBCPP_INLINE_VISIBILITY
3374typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003375basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003376 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003377{
Alp Tokerec34c482014-05-15 11:27:39 +00003378 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003379 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003380 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003381}
3382
3383template<class _CharT, class _Traits, class _Allocator>
3384typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003385basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3386 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003387{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003388 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003389 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003390}
3391
3392// find_first_of
3393
3394template<class _CharT, class _Traits, class _Allocator>
3395typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003396basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003397 size_type __pos,
3398 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003399{
Alp Tokerec34c482014-05-15 11:27:39 +00003400 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003401 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003402 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003403}
3404
3405template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003406inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003407typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003408basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3409 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003410{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003411 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003412 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003413}
3414
3415template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003416template <class _Tp>
3417typename enable_if
3418<
3419 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3420 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3421>::type
3422basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
3423 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003424{
Marshall Clow64c10d02018-07-02 18:41:15 +00003425 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003426 return __str_find_first_of<value_type, size_type, traits_type, npos>
3427 (data(), size(), __sv.data(), __pos, __sv.size());
3428}
3429
3430template<class _CharT, class _Traits, class _Allocator>
3431inline _LIBCPP_INLINE_VISIBILITY
3432typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003433basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003434 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003435{
Alp Tokerec34c482014-05-15 11:27:39 +00003436 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003437 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003438 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003439}
3440
3441template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003442inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003443typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003444basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3445 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003446{
3447 return find(__c, __pos);
3448}
3449
3450// find_last_of
3451
3452template<class _CharT, class _Traits, class _Allocator>
3453typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003454basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003455 size_type __pos,
3456 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003457{
Alp Tokerec34c482014-05-15 11:27:39 +00003458 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003459 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003460 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003461}
3462
3463template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003464inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003465typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003466basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3467 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003468{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003469 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003470 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003471}
3472
3473template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003474template <class _Tp>
3475typename enable_if
3476<
3477 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3478 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3479>::type
3480basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
3481 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003482{
Marshall Clow64c10d02018-07-02 18:41:15 +00003483 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003484 return __str_find_last_of<value_type, size_type, traits_type, npos>
3485 (data(), size(), __sv.data(), __pos, __sv.size());
3486}
3487
3488template<class _CharT, class _Traits, class _Allocator>
3489inline _LIBCPP_INLINE_VISIBILITY
3490typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003491basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003492 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003493{
Alp Tokerec34c482014-05-15 11:27:39 +00003494 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003495 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003496 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003497}
3498
3499template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003500inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003501typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003502basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3503 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003504{
3505 return rfind(__c, __pos);
3506}
3507
3508// find_first_not_of
3509
3510template<class _CharT, class _Traits, class _Allocator>
3511typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003512basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003513 size_type __pos,
3514 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003515{
Alp Tokerec34c482014-05-15 11:27:39 +00003516 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003517 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003518 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003519}
3520
3521template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003522inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003523typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003524basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3525 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003526{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003527 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003528 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003529}
3530
3531template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003532template <class _Tp>
3533typename enable_if
3534<
3535 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3536 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3537>::type
3538basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
3539 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003540{
Marshall Clow64c10d02018-07-02 18:41:15 +00003541 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003542 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3543 (data(), size(), __sv.data(), __pos, __sv.size());
3544}
3545
3546template<class _CharT, class _Traits, class _Allocator>
3547inline _LIBCPP_INLINE_VISIBILITY
3548typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003549basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003550 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003551{
Alp Tokerec34c482014-05-15 11:27:39 +00003552 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003553 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003554 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003555}
3556
3557template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003558inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003559typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003560basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3561 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003562{
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(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003565}
3566
3567// find_last_not_of
3568
3569template<class _CharT, class _Traits, class _Allocator>
3570typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003571basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003572 size_type __pos,
3573 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003574{
Alp Tokerec34c482014-05-15 11:27:39 +00003575 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003576 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003577 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003578}
3579
3580template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003581inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003582typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003583basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3584 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003585{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003586 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003587 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003588}
3589
3590template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003591template <class _Tp>
3592typename enable_if
3593<
3594 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3595 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3596>::type
3597basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
3598 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003599{
Marshall Clow64c10d02018-07-02 18:41:15 +00003600 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003601 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3602 (data(), size(), __sv.data(), __pos, __sv.size());
3603}
3604
3605template<class _CharT, class _Traits, class _Allocator>
3606inline _LIBCPP_INLINE_VISIBILITY
3607typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003608basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003609 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003610{
Alp Tokerec34c482014-05-15 11:27:39 +00003611 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003612 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003613 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003614}
3615
3616template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003617inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003618typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003619basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3620 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003621{
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(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003624}
3625
3626// compare
3627
3628template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003629template <class _Tp>
3630typename enable_if
3631<
3632 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3633 int
3634>::type
3635basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003636{
Marshall Clow64c10d02018-07-02 18:41:15 +00003637 __self_view __sv = __t;
Howard Hinnantfa06d752011-07-24 21:45:06 +00003638 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003639 size_t __rhs_sz = __sv.size();
3640 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:06 +00003641 _VSTD::min(__lhs_sz, __rhs_sz));
3642 if (__result != 0)
3643 return __result;
3644 if (__lhs_sz < __rhs_sz)
3645 return -1;
3646 if (__lhs_sz > __rhs_sz)
3647 return 1;
3648 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003649}
3650
3651template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003652inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003653int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003654basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003655{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003656 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003657}
3658
3659template <class _CharT, class _Traits, class _Allocator>
3660int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003661basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3662 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003663 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003664 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003665{
Alp Tokerec34c482014-05-15 11:27:39 +00003666 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003667 size_type __sz = size();
3668 if (__pos1 > __sz || __n2 == npos)
3669 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003670 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3671 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003672 if (__r == 0)
3673 {
3674 if (__rlen < __n2)
3675 __r = -1;
3676 else if (__rlen > __n2)
3677 __r = 1;
3678 }
3679 return __r;
3680}
3681
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003682template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003683template <class _Tp>
3684typename enable_if
3685<
3686 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3687 int
3688>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003689basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3690 size_type __n1,
Marshall Clow64c10d02018-07-02 18:41:15 +00003691 const _Tp& __t) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003692{
Marshall Clow64c10d02018-07-02 18:41:15 +00003693 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003694 return compare(__pos1, __n1, __sv.data(), __sv.size());
3695}
3696
3697template <class _CharT, class _Traits, class _Allocator>
3698inline _LIBCPP_INLINE_VISIBILITY
3699int
3700basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3701 size_type __n1,
3702 const basic_string& __str) const
3703{
3704 return compare(__pos1, __n1, __str.data(), __str.size());
3705}
3706
3707template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00003708template <class _Tp>
3709typename enable_if
3710<
Marshall Clowf1729d92017-11-15 20:02:27 +00003711 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3712 int
Marshall Clow6ac8de02016-09-24 22:45:42 +00003713>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003714basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3715 size_type __n1,
Marshall Clow6ac8de02016-09-24 22:45:42 +00003716 const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003717 size_type __pos2,
3718 size_type __n2) const
3719{
Marshall Clow6ac8de02016-09-24 22:45:42 +00003720 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003721 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3722}
3723
3724template <class _CharT, class _Traits, class _Allocator>
3725int
3726basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3727 size_type __n1,
3728 const basic_string& __str,
3729 size_type __pos2,
3730 size_type __n2) const
3731{
3732 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3733}
3734
3735template <class _CharT, class _Traits, class _Allocator>
3736int
3737basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3738{
3739 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3740 return compare(0, npos, __s, traits_type::length(__s));
3741}
3742
3743template <class _CharT, class _Traits, class _Allocator>
3744int
3745basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3746 size_type __n1,
3747 const value_type* __s) const
3748{
3749 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3750 return compare(__pos1, __n1, __s, traits_type::length(__s));
3751}
3752
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003753// __invariants
3754
3755template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003756inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003757bool
3758basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3759{
3760 if (size() > capacity())
3761 return false;
3762 if (capacity() < __min_cap - 1)
3763 return false;
3764 if (data() == 0)
3765 return false;
3766 if (data()[size()] != value_type(0))
3767 return false;
3768 return true;
3769}
3770
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003771// __clear_and_shrink
3772
3773template<class _CharT, class _Traits, class _Allocator>
3774inline _LIBCPP_INLINE_VISIBILITY
3775void
Marshall Clowab343bb2018-05-29 17:04:37 +00003776basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003777{
3778 clear();
3779 if(__is_long())
3780 {
3781 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
3782 __set_long_cap(0);
3783 __set_short_size(0);
3784 }
3785}
3786
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003787// operator==
3788
3789template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003790inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003791bool
3792operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003793 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003794{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003795 size_t __lhs_sz = __lhs.size();
3796 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3797 __rhs.data(),
3798 __lhs_sz) == 0;
3799}
3800
3801template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003802inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003803bool
3804operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3805 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3806{
3807 size_t __lhs_sz = __lhs.size();
3808 if (__lhs_sz != __rhs.size())
3809 return false;
3810 const char* __lp = __lhs.data();
3811 const char* __rp = __rhs.data();
3812 if (__lhs.__is_long())
3813 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3814 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3815 if (*__lp != *__rp)
3816 return false;
3817 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003818}
3819
3820template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003821inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003822bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003823operator==(const _CharT* __lhs,
3824 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003825{
Eric Fiselier4f241822015-08-28 03:02:37 +00003826 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3827 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3828 size_t __lhs_len = _Traits::length(__lhs);
3829 if (__lhs_len != __rhs.size()) return false;
3830 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003831}
3832
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003833template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003834inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003835bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003836operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3837 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003838{
Eric Fiselier4f241822015-08-28 03:02:37 +00003839 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3840 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3841 size_t __rhs_len = _Traits::length(__rhs);
3842 if (__rhs_len != __lhs.size()) return false;
3843 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003844}
3845
Howard Hinnant324bb032010-08-22 00:02:43 +00003846template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003847inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003848bool
3849operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003850 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003851{
3852 return !(__lhs == __rhs);
3853}
3854
3855template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003856inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003857bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003858operator!=(const _CharT* __lhs,
3859 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003860{
3861 return !(__lhs == __rhs);
3862}
3863
3864template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003865inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003866bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003867operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3868 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003869{
3870 return !(__lhs == __rhs);
3871}
3872
3873// operator<
3874
3875template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003876inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003877bool
3878operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003879 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003880{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003881 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003882}
3883
3884template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003885inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003886bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003887operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3888 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003889{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003890 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003891}
3892
3893template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003894inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003895bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003896operator< (const _CharT* __lhs,
3897 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003898{
3899 return __rhs.compare(__lhs) > 0;
3900}
3901
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003902// operator>
3903
3904template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003905inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003906bool
3907operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003908 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003909{
3910 return __rhs < __lhs;
3911}
3912
3913template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003914inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003915bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003916operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3917 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003918{
3919 return __rhs < __lhs;
3920}
3921
3922template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003923inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003924bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003925operator> (const _CharT* __lhs,
3926 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003927{
3928 return __rhs < __lhs;
3929}
3930
3931// operator<=
3932
3933template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003934inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003935bool
3936operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003937 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003938{
3939 return !(__rhs < __lhs);
3940}
3941
3942template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003943inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003944bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003945operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3946 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003947{
3948 return !(__rhs < __lhs);
3949}
3950
3951template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003952inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003953bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003954operator<=(const _CharT* __lhs,
3955 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003956{
3957 return !(__rhs < __lhs);
3958}
3959
3960// operator>=
3961
3962template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003963inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003964bool
3965operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003966 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003967{
3968 return !(__lhs < __rhs);
3969}
3970
3971template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003972inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003973bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003974operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3975 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003976{
3977 return !(__lhs < __rhs);
3978}
3979
3980template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003981inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003982bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003983operator>=(const _CharT* __lhs,
3984 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003985{
3986 return !(__lhs < __rhs);
3987}
3988
3989// operator +
3990
3991template<class _CharT, class _Traits, class _Allocator>
3992basic_string<_CharT, _Traits, _Allocator>
3993operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3994 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3995{
3996 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3997 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3998 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3999 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4000 __r.append(__rhs.data(), __rhs_sz);
4001 return __r;
4002}
4003
4004template<class _CharT, class _Traits, class _Allocator>
4005basic_string<_CharT, _Traits, _Allocator>
4006operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4007{
4008 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4009 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4010 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4011 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4012 __r.append(__rhs.data(), __rhs_sz);
4013 return __r;
4014}
4015
4016template<class _CharT, class _Traits, class _Allocator>
4017basic_string<_CharT, _Traits, _Allocator>
4018operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4019{
4020 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4021 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4022 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4023 __r.append(__rhs.data(), __rhs_sz);
4024 return __r;
4025}
4026
4027template<class _CharT, class _Traits, class _Allocator>
4028basic_string<_CharT, _Traits, _Allocator>
4029operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4030{
4031 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4032 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4033 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4034 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4035 __r.append(__rhs, __rhs_sz);
4036 return __r;
4037}
4038
4039template<class _CharT, class _Traits, class _Allocator>
4040basic_string<_CharT, _Traits, _Allocator>
4041operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4042{
4043 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4044 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4045 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4046 __r.push_back(__rhs);
4047 return __r;
4048}
4049
Eric Fiselier3e928972017-04-19 00:28:44 +00004050#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004051
4052template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004053inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004054basic_string<_CharT, _Traits, _Allocator>
4055operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4056{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004057 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004058}
4059
4060template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004061inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004062basic_string<_CharT, _Traits, _Allocator>
4063operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4064{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004065 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004066}
4067
4068template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004069inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004070basic_string<_CharT, _Traits, _Allocator>
4071operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4072{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004073 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004074}
4075
4076template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004077inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004078basic_string<_CharT, _Traits, _Allocator>
4079operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4080{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004081 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004082}
4083
4084template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004085inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004086basic_string<_CharT, _Traits, _Allocator>
4087operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4088{
4089 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004090 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004091}
4092
4093template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004094inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004095basic_string<_CharT, _Traits, _Allocator>
4096operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4097{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004098 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004099}
4100
4101template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004102inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004103basic_string<_CharT, _Traits, _Allocator>
4104operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4105{
4106 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004107 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004108}
4109
Eric Fiselier3e928972017-04-19 00:28:44 +00004110#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004111
4112// swap
4113
4114template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004115inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004116void
Howard Hinnanta6119a82011-05-29 19:57:12 +00004117swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00004118 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4119 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004120{
4121 __lhs.swap(__rhs);
4122}
4123
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004124#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
4125
4126typedef basic_string<char16_t> u16string;
4127typedef basic_string<char32_t> u32string;
4128
Howard Hinnant324bb032010-08-22 00:02:43 +00004129#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004130
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004131_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4132_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4133_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4134_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4135_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004136
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004137_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4138_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4139_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004140
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004141_LIBCPP_FUNC_VIS string to_string(int __val);
4142_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4143_LIBCPP_FUNC_VIS string to_string(long __val);
4144_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4145_LIBCPP_FUNC_VIS string to_string(long long __val);
4146_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4147_LIBCPP_FUNC_VIS string to_string(float __val);
4148_LIBCPP_FUNC_VIS string to_string(double __val);
4149_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004150
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004151_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4152_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4153_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4154_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4155_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004156
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004157_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4158_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4159_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004160
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004161_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4162_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4163_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4164_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4165_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4166_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4167_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4168_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4169_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004170
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004171template<class _CharT, class _Traits, class _Allocator>
4172 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4173 basic_string<_CharT, _Traits, _Allocator>::npos;
4174
4175template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +00004176struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004177 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4178{
4179 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004180 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004181};
4182
4183template<class _CharT, class _Traits, class _Allocator>
4184size_t
4185hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004186 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004187{
Sean Huntaffd9e52011-07-29 23:31:56 +00004188 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004189}
4190
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004191template<class _CharT, class _Traits, class _Allocator>
4192basic_ostream<_CharT, _Traits>&
4193operator<<(basic_ostream<_CharT, _Traits>& __os,
4194 const basic_string<_CharT, _Traits, _Allocator>& __str);
4195
4196template<class _CharT, class _Traits, class _Allocator>
4197basic_istream<_CharT, _Traits>&
4198operator>>(basic_istream<_CharT, _Traits>& __is,
4199 basic_string<_CharT, _Traits, _Allocator>& __str);
4200
4201template<class _CharT, class _Traits, class _Allocator>
4202basic_istream<_CharT, _Traits>&
4203getline(basic_istream<_CharT, _Traits>& __is,
4204 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4205
4206template<class _CharT, class _Traits, class _Allocator>
4207inline _LIBCPP_INLINE_VISIBILITY
4208basic_istream<_CharT, _Traits>&
4209getline(basic_istream<_CharT, _Traits>& __is,
4210 basic_string<_CharT, _Traits, _Allocator>& __str);
4211
Eric Fiselier3e928972017-04-19 00:28:44 +00004212#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004213
4214template<class _CharT, class _Traits, class _Allocator>
4215inline _LIBCPP_INLINE_VISIBILITY
4216basic_istream<_CharT, _Traits>&
4217getline(basic_istream<_CharT, _Traits>&& __is,
4218 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4219
4220template<class _CharT, class _Traits, class _Allocator>
4221inline _LIBCPP_INLINE_VISIBILITY
4222basic_istream<_CharT, _Traits>&
4223getline(basic_istream<_CharT, _Traits>&& __is,
4224 basic_string<_CharT, _Traits, _Allocator>& __str);
4225
Eric Fiselier3e928972017-04-19 00:28:44 +00004226#endif // _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004227
Howard Hinnant499cea12013-08-23 17:37:05 +00004228#if _LIBCPP_DEBUG_LEVEL >= 2
4229
4230template<class _CharT, class _Traits, class _Allocator>
4231bool
4232basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4233{
4234 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4235 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4236}
4237
4238template<class _CharT, class _Traits, class _Allocator>
4239bool
4240basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4241{
4242 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4243 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4244}
4245
4246template<class _CharT, class _Traits, class _Allocator>
4247bool
4248basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4249{
4250 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4251 return this->data() <= __p && __p <= this->data() + this->size();
4252}
4253
4254template<class _CharT, class _Traits, class _Allocator>
4255bool
4256basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4257{
4258 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4259 return this->data() <= __p && __p < this->data() + this->size();
4260}
4261
4262#endif // _LIBCPP_DEBUG_LEVEL >= 2
4263
Shoaib Meenai68506702017-06-29 02:52:46 +00004264_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
4265_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Shoaib Meenai68506702017-06-29 02:52:46 +00004266
Marshall Clow15234322013-07-23 17:05:24 +00004267#if _LIBCPP_STD_VER > 11
4268// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004269inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004270{
4271 inline namespace string_literals
4272 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004273 inline _LIBCPP_INLINE_VISIBILITY
4274 basic_string<char> operator "" s( const char *__str, size_t __len )
4275 {
4276 return basic_string<char> (__str, __len);
4277 }
Marshall Clow15234322013-07-23 17:05:24 +00004278
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004279 inline _LIBCPP_INLINE_VISIBILITY
4280 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4281 {
4282 return basic_string<wchar_t> (__str, __len);
4283 }
Marshall Clow15234322013-07-23 17:05:24 +00004284
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004285 inline _LIBCPP_INLINE_VISIBILITY
4286 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4287 {
4288 return basic_string<char16_t> (__str, __len);
4289 }
Marshall Clow15234322013-07-23 17:05:24 +00004290
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004291 inline _LIBCPP_INLINE_VISIBILITY
4292 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4293 {
4294 return basic_string<char32_t> (__str, __len);
4295 }
Marshall Clow15234322013-07-23 17:05:24 +00004296 }
4297}
4298#endif
4299
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004300_LIBCPP_END_NAMESPACE_STD
4301
Eric Fiselier018a3d52017-05-31 22:07:49 +00004302_LIBCPP_POP_MACROS
4303
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004304#endif // _LIBCPP_STRING