blob: 807e14a1d3070b8b57667ca6d15f271e53f1ae32 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- string -----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_STRING
12#define _LIBCPP_STRING
13
14/*
15 string synopsis
16
17namespace std
18{
19
20template <class stateT>
21class fpos
22{
23private:
24 stateT st;
25public:
26 fpos(streamoff = streamoff());
27
28 operator streamoff() const;
29
30 stateT state() const;
31 void state(stateT);
32
33 fpos& operator+=(streamoff);
34 fpos operator+ (streamoff) const;
35 fpos& operator-=(streamoff);
36 fpos operator- (streamoff) const;
37};
38
39template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
40
41template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
42template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
43
44template <class charT>
45struct char_traits
46{
47 typedef charT char_type;
48 typedef ... int_type;
49 typedef streamoff off_type;
50 typedef streampos pos_type;
51 typedef mbstate_t state_type;
52
Howard Hinnanta6119a82011-05-29 19:57:12 +000053 static void assign(char_type& c1, const char_type& c2) noexcept;
Howard Hinnant03d71812012-07-20 19:09:12 +000054 static constexpr bool eq(char_type c1, char_type c2) noexcept;
55 static constexpr bool lt(char_type c1, char_type c2) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056
57 static int compare(const char_type* s1, const char_type* s2, size_t n);
58 static size_t length(const char_type* s);
59 static const char_type* find(const char_type* s, size_t n, const char_type& a);
60 static char_type* move(char_type* s1, const char_type* s2, size_t n);
61 static char_type* copy(char_type* s1, const char_type* s2, size_t n);
62 static char_type* assign(char_type* s, size_t n, char_type a);
63
Howard Hinnant03d71812012-07-20 19:09:12 +000064 static constexpr int_type not_eof(int_type c) noexcept;
65 static constexpr char_type to_char_type(int_type c) noexcept;
66 static constexpr int_type to_int_type(char_type c) noexcept;
67 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
68 static constexpr int_type eof() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000069};
70
71template <> struct char_traits<char>;
72template <> struct char_traits<wchar_t>;
73
Howard Hinnant324bb032010-08-22 00:02:43 +000074template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000075class basic_string
76{
Howard Hinnant324bb032010-08-22 00:02:43 +000077public:
78// types:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000079 typedef traits traits_type;
80 typedef typename traits_type::char_type value_type;
81 typedef Allocator allocator_type;
82 typedef typename allocator_type::size_type size_type;
83 typedef typename allocator_type::difference_type difference_type;
84 typedef typename allocator_type::reference reference;
85 typedef typename allocator_type::const_reference const_reference;
86 typedef typename allocator_type::pointer pointer;
87 typedef typename allocator_type::const_pointer const_pointer;
88 typedef implementation-defined iterator;
89 typedef implementation-defined const_iterator;
90 typedef std::reverse_iterator<iterator> reverse_iterator;
91 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
92
93 static const size_type npos = -1;
94
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000095 basic_string()
96 noexcept(is_nothrow_default_constructible<allocator_type>::value);
97 explicit basic_string(const allocator_type& a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000098 basic_string(const basic_string& str);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000099 basic_string(basic_string&& str)
100 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000101 basic_string(const basic_string& str, size_type pos,
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000102 const allocator_type& a = allocator_type());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000103 basic_string(const basic_string& str, size_type pos, size_type n,
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000104 const Allocator& a = Allocator());
Marshall Clowdb7fa112016-11-14 18:22:19 +0000105 template<class T>
106 basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
Marshall Clow64c10d02018-07-02 18:41:15 +0000107 template <class T>
108 explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000109 basic_string(const value_type* s, const allocator_type& a = allocator_type());
110 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000111 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
112 template<class InputIterator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000113 basic_string(InputIterator begin, InputIterator end,
114 const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000115 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
116 basic_string(const basic_string&, const Allocator&);
117 basic_string(basic_string&&, const Allocator&);
118
119 ~basic_string();
120
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000121 operator basic_string_view<charT, traits>() const noexcept;
122
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000123 basic_string& operator=(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000124 template <class T>
125 basic_string& operator=(const T& t); // C++17
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000126 basic_string& operator=(basic_string&& str)
127 noexcept(
Marshall Clowaf961ed2015-08-18 18:57:00 +0000128 allocator_type::propagate_on_container_move_assignment::value ||
129 allocator_type::is_always_equal::value ); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000130 basic_string& operator=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000131 basic_string& operator=(value_type c);
132 basic_string& operator=(initializer_list<value_type>);
133
Howard Hinnanta6119a82011-05-29 19:57:12 +0000134 iterator begin() noexcept;
135 const_iterator begin() const noexcept;
136 iterator end() noexcept;
137 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000138
Howard Hinnanta6119a82011-05-29 19:57:12 +0000139 reverse_iterator rbegin() noexcept;
140 const_reverse_iterator rbegin() const noexcept;
141 reverse_iterator rend() noexcept;
142 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000143
Howard Hinnanta6119a82011-05-29 19:57:12 +0000144 const_iterator cbegin() const noexcept;
145 const_iterator cend() const noexcept;
146 const_reverse_iterator crbegin() const noexcept;
147 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000148
Howard Hinnanta6119a82011-05-29 19:57:12 +0000149 size_type size() const noexcept;
150 size_type length() const noexcept;
151 size_type max_size() const noexcept;
152 size_type capacity() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000153
154 void resize(size_type n, value_type c);
155 void resize(size_type n);
156
157 void reserve(size_type res_arg = 0);
158 void shrink_to_fit();
Howard Hinnanta6119a82011-05-29 19:57:12 +0000159 void clear() noexcept;
160 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000161
162 const_reference operator[](size_type pos) const;
163 reference operator[](size_type pos);
164
165 const_reference at(size_type n) const;
166 reference at(size_type n);
167
168 basic_string& operator+=(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000169 template <class T>
170 basic_string& operator+=(const T& t); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000171 basic_string& operator+=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000172 basic_string& operator+=(value_type c);
173 basic_string& operator+=(initializer_list<value_type>);
174
175 basic_string& append(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000176 template <class T>
177 basic_string& append(const T& t); // C++17
Marshall Clowa93b5e22014-03-04 19:17:19 +0000178 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000179 template <class T>
180 basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000181 basic_string& append(const value_type* s, size_type n);
182 basic_string& append(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000183 basic_string& append(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000184 template<class InputIterator>
185 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000186 basic_string& append(initializer_list<value_type>);
187
188 void push_back(value_type c);
189 void pop_back();
190 reference front();
191 const_reference front() const;
192 reference back();
193 const_reference back() const;
194
195 basic_string& assign(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000196 template <class T>
197 basic_string& assign(const T& t); // C++17
Howard Hinnanta6119a82011-05-29 19:57:12 +0000198 basic_string& assign(basic_string&& str);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000199 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000200 template <class T>
201 basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000202 basic_string& assign(const value_type* s, size_type n);
203 basic_string& assign(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000204 basic_string& assign(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000205 template<class InputIterator>
206 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000207 basic_string& assign(initializer_list<value_type>);
208
209 basic_string& insert(size_type pos1, const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000210 template <class T>
211 basic_string& insert(size_type pos1, const T& t);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000212 basic_string& insert(size_type pos1, const basic_string& str,
213 size_type pos2, size_type n);
Marshall Clow6ac8de02016-09-24 22:45:42 +0000214 template <class T>
215 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
Marshall Clowa93b5e22014-03-04 19:17:19 +0000216 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000217 basic_string& insert(size_type pos, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000218 basic_string& insert(size_type pos, size_type n, value_type c);
219 iterator insert(const_iterator p, value_type c);
220 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000221 template<class InputIterator>
222 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000223 iterator insert(const_iterator p, initializer_list<value_type>);
224
225 basic_string& erase(size_type pos = 0, size_type n = npos);
226 iterator erase(const_iterator position);
227 iterator erase(const_iterator first, const_iterator last);
228
229 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000230 template <class T>
231 basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000232 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000233 size_type pos2, size_type n2=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000234 template <class T>
235 basic_string& replace(size_type pos1, size_type n1, const T& t,
236 size_type pos2, size_type n); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000237 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
238 basic_string& replace(size_type pos, size_type n1, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000239 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000240 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000241 template <class T>
242 basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000243 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
244 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000245 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000246 template<class InputIterator>
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000247 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
248 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000249
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000250 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000251 basic_string substr(size_type pos = 0, size_type n = npos) const;
252
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000253 void swap(basic_string& str)
Marshall Clow7d914d12015-07-13 20:04:56 +0000254 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
255 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000257 const value_type* c_str() const noexcept;
258 const value_type* data() const noexcept;
Marshall Clowf532a702016-03-08 15:44:30 +0000259 value_type* data() noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000260
Howard Hinnanta6119a82011-05-29 19:57:12 +0000261 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000262
Howard Hinnanta6119a82011-05-29 19:57:12 +0000263 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000264 template <class T>
265 size_type find(const T& t, size_type pos = 0) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000266 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
267 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000268 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000269
Howard Hinnanta6119a82011-05-29 19:57:12 +0000270 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000271 template <class T>
272 size_type rfind(const T& t, size_type pos = npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000273 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
274 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000275 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276
Howard Hinnanta6119a82011-05-29 19:57:12 +0000277 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000278 template <class T>
279 size_type find_first_of(const T& t, size_type pos = 0) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000280 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
281 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000282 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000283
Howard Hinnanta6119a82011-05-29 19:57:12 +0000284 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000285 template <class T>
286 size_type find_last_of(const T& t, size_type pos = npos) const noexcept; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000287 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
288 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000289 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290
Howard Hinnanta6119a82011-05-29 19:57:12 +0000291 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000292 template <class T>
293 size_type find_first_not_of(const T& t, size_type pos = 0) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000294 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
295 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000296 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000297
Howard Hinnanta6119a82011-05-29 19:57:12 +0000298 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000299 template <class T>
300 size_type find_last_not_of(const T& t, size_type pos = npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000301 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
302 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000303 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000304
Howard Hinnanta6119a82011-05-29 19:57:12 +0000305 int compare(const basic_string& str) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000306 template <class T>
307 int compare(const T& t) const noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000308 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Marshall Clow64c10d02018-07-02 18:41:15 +0000309 template <class T>
310 int compare(size_type pos1, size_type n1, const T& t) const; // C++17
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000311 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000312 size_type pos2, size_type n2=npos) const; // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000313 template <class T>
314 int compare(size_type pos1, size_type n1, const T& t,
315 size_type pos2, size_type n2=npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000316 int compare(const value_type* s) const noexcept;
317 int compare(size_type pos1, size_type n1, const value_type* s) const;
318 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000319
Marshall Clow46b4ad52017-12-04 20:11:38 +0000320 bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
321 bool starts_with(charT c) const noexcept; // C++2a
322 bool starts_with(const charT* s) const; // C++2a
323 bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
324 bool ends_with(charT c) const noexcept; // C++2a
325 bool ends_with(const charT* s) const; // C++2a
326
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327 bool __invariants() const;
328};
329
Marshall Clow5b1e87e2018-02-08 06:34:03 +0000330template<class InputIterator,
331 class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
332basic_string(InputIterator, InputIterator, Allocator = Allocator())
333 -> basic_string<typename iterator_traits<InputIterator>::value_type,
334 char_traits<typename iterator_traits<InputIterator>::value_type>,
335 Allocator>; // C++17
336
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000337template<class charT, class traits, class Allocator>
338basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000339operator+(const basic_string<charT, traits, Allocator>& lhs,
340 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341
342template<class charT, class traits, class Allocator>
343basic_string<charT, traits, Allocator>
344operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
345
346template<class charT, class traits, class Allocator>
347basic_string<charT, traits, Allocator>
348operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
349
350template<class charT, class traits, class Allocator>
351basic_string<charT, traits, Allocator>
352operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
353
354template<class charT, class traits, class Allocator>
355basic_string<charT, traits, Allocator>
356operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
357
358template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000359bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000360 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361
362template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000363bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000364
365template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000366bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367
Howard Hinnant324bb032010-08-22 00:02:43 +0000368template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000369bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000370 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371
372template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000373bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374
375template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000376bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377
378template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000379bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000380 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381
382template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000383bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384
385template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000386bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000387
388template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000389bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000390 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000391
392template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000393bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394
395template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000396bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397
398template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000399bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000400 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000401
402template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000403bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404
405template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000406bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000407
408template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000409bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000410 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000411
412template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000413bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000414
415template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000416bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000417
418template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000419void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000420 basic_string<charT, traits, Allocator>& rhs)
421 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422
423template<class charT, class traits, class Allocator>
424basic_istream<charT, traits>&
425operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
426
427template<class charT, class traits, class Allocator>
428basic_ostream<charT, traits>&
429operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
430
431template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000432basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000433getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
434 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435
436template<class charT, class traits, class Allocator>
437basic_istream<charT, traits>&
438getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
439
440typedef basic_string<char> string;
441typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000442typedef basic_string<char16_t> u16string;
443typedef basic_string<char32_t> u32string;
444
445int stoi (const string& str, size_t* idx = 0, int base = 10);
446long stol (const string& str, size_t* idx = 0, int base = 10);
447unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
448long long stoll (const string& str, size_t* idx = 0, int base = 10);
449unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
450
451float stof (const string& str, size_t* idx = 0);
452double stod (const string& str, size_t* idx = 0);
453long double stold(const string& str, size_t* idx = 0);
454
455string to_string(int val);
456string to_string(unsigned val);
457string to_string(long val);
458string to_string(unsigned long val);
459string to_string(long long val);
460string to_string(unsigned long long val);
461string to_string(float val);
462string to_string(double val);
463string to_string(long double val);
464
465int stoi (const wstring& str, size_t* idx = 0, int base = 10);
466long stol (const wstring& str, size_t* idx = 0, int base = 10);
467unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
468long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
469unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
470
471float stof (const wstring& str, size_t* idx = 0);
472double stod (const wstring& str, size_t* idx = 0);
473long double stold(const wstring& str, size_t* idx = 0);
474
475wstring to_wstring(int val);
476wstring to_wstring(unsigned val);
477wstring to_wstring(long val);
478wstring to_wstring(unsigned long val);
479wstring to_wstring(long long val);
480wstring to_wstring(unsigned long long val);
481wstring to_wstring(float val);
482wstring to_wstring(double val);
483wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000484
485template <> struct hash<string>;
486template <> struct hash<u16string>;
487template <> struct hash<u32string>;
488template <> struct hash<wstring>;
489
Marshall Clow15234322013-07-23 17:05:24 +0000490basic_string<char> operator "" s( const char *str, size_t len ); // C++14
491basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
492basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
493basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
494
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495} // std
496
497*/
498
499#include <__config>
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000500#include <string_view>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501#include <iosfwd>
502#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000503#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504#include <cwchar>
505#include <algorithm>
506#include <iterator>
507#include <utility>
508#include <memory>
509#include <stdexcept>
510#include <type_traits>
511#include <initializer_list>
512#include <__functional_base>
Marshall Clowe3973fd2018-09-12 19:41:40 +0000513#include <version>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000514#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
515#include <cstdint>
516#endif
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000517
Eric Fiselierb9536102014-08-10 23:53:08 +0000518#include <__debug>
519
Howard Hinnant08e17472011-10-17 20:05:10 +0000520#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000522#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523
Eric Fiselier018a3d52017-05-31 22:07:49 +0000524_LIBCPP_PUSH_MACROS
525#include <__undef_macros>
526
527
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528_LIBCPP_BEGIN_NAMESPACE_STD
529
530// fpos
531
532template <class _StateT>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000533class _LIBCPP_TEMPLATE_VIS fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534{
535private:
536 _StateT __st_;
537 streamoff __off_;
538public:
539 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
540
541 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
542
543 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
544 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
545
546 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
547 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
548 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
549 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
550};
551
552template <class _StateT>
553inline _LIBCPP_INLINE_VISIBILITY
554streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
555 {return streamoff(__x) - streamoff(__y);}
556
557template <class _StateT>
558inline _LIBCPP_INLINE_VISIBILITY
559bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
560 {return streamoff(__x) == streamoff(__y);}
561
562template <class _StateT>
563inline _LIBCPP_INLINE_VISIBILITY
564bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
565 {return streamoff(__x) != streamoff(__y);}
566
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000567// basic_string
568
569template<class _CharT, class _Traits, class _Allocator>
570basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000571operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
572 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000573
574template<class _CharT, class _Traits, class _Allocator>
575basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000576operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000577
578template<class _CharT, class _Traits, class _Allocator>
579basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000580operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581
582template<class _CharT, class _Traits, class _Allocator>
583basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000584operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000585
586template<class _CharT, class _Traits, class _Allocator>
587basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000588operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000589
Shoaib Meenai487562f2017-07-29 02:54:41 +0000590_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
591
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000592template <bool>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000593class _LIBCPP_TEMPLATE_VIS __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000594{
595protected:
Marshall Clow14c09a22016-08-25 15:09:01 +0000596 _LIBCPP_NORETURN void __throw_length_error() const;
597 _LIBCPP_NORETURN void __throw_out_of_range() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000598};
599
600template <bool __b>
601void
602__basic_string_common<__b>::__throw_length_error() const
603{
Marshall Clow14c09a22016-08-25 15:09:01 +0000604 _VSTD::__throw_length_error("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000605}
606
607template <bool __b>
608void
609__basic_string_common<__b>::__throw_out_of_range() const
610{
Marshall Clow14c09a22016-08-25 15:09:01 +0000611 _VSTD::__throw_out_of_range("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000612}
613
Eric Fiselier833d6442016-09-15 22:27:07 +0000614_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000615
Marshall Clowdf9db312016-01-13 21:54:34 +0000616#ifdef _LIBCPP_NO_EXCEPTIONS
617template <class _Iter>
618struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
619#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
620template <class _Iter>
621struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
622#else
623template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
624struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
625 noexcept(++(declval<_Iter&>())) &&
626 is_nothrow_assignable<_Iter&, _Iter>::value &&
627 noexcept(declval<_Iter>() == declval<_Iter>()) &&
628 noexcept(*declval<_Iter>())
629)) {};
630
631template <class _Iter>
632struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
633#endif
634
635
636template <class _Iter>
637struct __libcpp_string_gets_noexcept_iterator
638 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
639
Marshall Clow6ac8de02016-09-24 22:45:42 +0000640template <class _CharT, class _Traits, class _Tp>
641struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
Marshall Clowf1729d92017-11-15 20:02:27 +0000642 ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
Marshall Clow6ac8de02016-09-24 22:45:42 +0000643 !is_convertible<const _Tp&, const _CharT*>::value)) {};
644
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000645#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000646
647template <class _CharT, size_t = sizeof(_CharT)>
648struct __padding
649{
650 unsigned char __xx[sizeof(_CharT)-1];
651};
652
653template <class _CharT>
654struct __padding<_CharT, 1>
655{
656};
657
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000658#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000659
Howard Hinnant324bb032010-08-22 00:02:43 +0000660template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000661class _LIBCPP_TEMPLATE_VIS basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000662 : private __basic_string_common<true>
663{
664public:
665 typedef basic_string __self;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000666 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667 typedef _Traits traits_type;
Marshall Clow2d4c3fa2017-03-15 18:41:11 +0000668 typedef _CharT value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000669 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000670 typedef allocator_traits<allocator_type> __alloc_traits;
671 typedef typename __alloc_traits::size_type size_type;
672 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000673 typedef value_type& reference;
674 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000675 typedef typename __alloc_traits::pointer pointer;
676 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000677
Marshall Clow256f1872018-03-21 00:36:05 +0000678 static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
679 static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
680 static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
681 static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
Howard Hinnant499cea12013-08-23 17:37:05 +0000682 "traits_type::char_type must be the same type as CharT");
Marshall Clow256f1872018-03-21 00:36:05 +0000683 static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
Howard Hinnant499cea12013-08-23 17:37:05 +0000684 "Allocator::value_type must be same type as value_type");
Marshall Clow64c10d02018-07-02 18:41:15 +0000685
Howard Hinnant499cea12013-08-23 17:37:05 +0000686#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000687 typedef pointer iterator;
688 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000689#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000690 typedef __wrap_iter<pointer> iterator;
691 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000692#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000693 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
694 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000695
696private:
Howard Hinnant15467182013-04-30 21:44:48 +0000697
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000698#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000699
700 struct __long
701 {
702 pointer __data_;
703 size_type __size_;
704 size_type __cap_;
705 };
706
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000707#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000708 static const size_type __short_mask = 0x01;
709 static const size_type __long_mask = 0x1ul;
Howard Hinnant15467182013-04-30 21:44:48 +0000710#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000711 static const size_type __short_mask = 0x80;
712 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant15467182013-04-30 21:44:48 +0000713#endif // _LIBCPP_BIG_ENDIAN
714
715 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
716 (sizeof(__long) - 1)/sizeof(value_type) : 2};
717
718 struct __short
719 {
720 value_type __data_[__min_cap];
721 struct
722 : __padding<value_type>
723 {
724 unsigned char __size_;
725 };
726 };
727
728#else
729
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000730 struct __long
731 {
732 size_type __cap_;
733 size_type __size_;
734 pointer __data_;
735 };
736
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000737#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000738 static const size_type __short_mask = 0x80;
739 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant324bb032010-08-22 00:02:43 +0000740#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000741 static const size_type __short_mask = 0x01;
742 static const size_type __long_mask = 0x1ul;
Howard Hinnant324bb032010-08-22 00:02:43 +0000743#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000744
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
746 (sizeof(__long) - 1)/sizeof(value_type) : 2};
747
748 struct __short
749 {
750 union
751 {
752 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +0000753 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000754 };
755 value_type __data_[__min_cap];
756 };
757
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000758#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000759
Howard Hinnant499cea12013-08-23 17:37:05 +0000760 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761
Howard Hinnant499cea12013-08-23 17:37:05 +0000762 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000763
764 struct __raw
765 {
766 size_type __words[__n_words];
767 };
768
769 struct __rep
770 {
771 union
772 {
773 __long __l;
774 __short __s;
775 __raw __r;
776 };
777 };
778
779 __compressed_pair<__rep, allocator_type> __r_;
780
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000781public:
782 static const size_type npos = -1;
783
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000784 _LIBCPP_INLINE_VISIBILITY basic_string()
785 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000786
787 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
788#if _LIBCPP_STD_VER <= 14
789 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
790#else
791 _NOEXCEPT;
792#endif
793
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000794 basic_string(const basic_string& __str);
795 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +0000796
Eric Fiselier3e928972017-04-19 00:28:44 +0000797#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant9f193f22011-01-26 00:06:59 +0000798 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000799 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +0000800#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000801 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000802#else
803 _NOEXCEPT;
804#endif
805
Howard Hinnant9f193f22011-01-26 00:06:59 +0000806 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000807 basic_string(basic_string&& __str, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000808#endif // _LIBCPP_CXX03_LANG
Marshall Clow64c10d02018-07-02 18:41:15 +0000809
Marshall Clow7e3ab172018-10-16 16:02:18 +0000810#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +0000811 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
Marshall Clow7e3ab172018-10-16 16:02:18 +0000812#endif
Eric Fiselierffbb91b2018-07-17 05:48:48 +0000813 _LIBCPP_INLINE_VISIBILITY
814 basic_string(const _CharT* __s) {
815 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
816 __init(__s, traits_type::length(__s));
817# if _LIBCPP_DEBUG_LEVEL >= 2
818 __get_db()->__insert_c(this);
819# endif
820 }
Marshall Clow64c10d02018-07-02 18:41:15 +0000821
Marshall Clow7e3ab172018-10-16 16:02:18 +0000822#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +0000823 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
Marshall Clow7e3ab172018-10-16 16:02:18 +0000824#endif
Marshall Clow64c10d02018-07-02 18:41:15 +0000825 _LIBCPP_INLINE_VISIBILITY
826 basic_string(const _CharT* __s, const _Allocator& __a);
827
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000828 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000829 basic_string(const _CharT* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000830 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000831 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000832 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000833 basic_string(size_type __n, _CharT __c);
Marshall Clow64c10d02018-07-02 18:41:15 +0000834
Marshall Clow7e3ab172018-10-16 16:02:18 +0000835#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +0000836 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
Marshall Clow7e3ab172018-10-16 16:02:18 +0000837#endif
Marshall Clow64c10d02018-07-02 18:41:15 +0000838 _LIBCPP_INLINE_VISIBILITY
839 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
840
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000841 basic_string(const basic_string& __str, size_type __pos, size_type __n,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000842 const _Allocator& __a = _Allocator());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000843 _LIBCPP_INLINE_VISIBILITY
844 basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000845 const _Allocator& __a = _Allocator());
Marshall Clow64c10d02018-07-02 18:41:15 +0000846
847 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 +0000848 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000849 basic_string(const _Tp& __t, size_type __pos, size_type __n,
Marshall Clow64c10d02018-07-02 18:41:15 +0000850 const allocator_type& __a = allocator_type());
851
852 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
853 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
854 explicit basic_string(const _Tp& __t);
855
856 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
857 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
858 explicit basic_string(const _Tp& __t, const allocator_type& __a);
859
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000860 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862 basic_string(_InputIterator __first, _InputIterator __last);
863 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000864 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000865 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000866#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000867 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000868 basic_string(initializer_list<_CharT> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000869 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000870 basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000871#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000872
Eric Fiselier51eb1d52016-10-31 03:42:50 +0000873 inline ~basic_string();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000874
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000875 _LIBCPP_INLINE_VISIBILITY
876 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
877
Howard Hinnante32b5e22010-11-17 17:55:08 +0000878 basic_string& operator=(const basic_string& __str);
Eric Fiselierf472d6c2017-01-23 21:24:58 +0000879
Marshall Clow64c10d02018-07-02 18:41:15 +0000880 template <class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
881 basic_string& operator=(const _Tp& __t)
882 {__self_view __sv = __t; return assign(__sv);}
883
Eric Fiselier3e928972017-04-19 00:28:44 +0000884#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000886 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +0000887 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Eric Fiselier3e928972017-04-19 00:28:44 +0000888 _LIBCPP_INLINE_VISIBILITY
889 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000890#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000891 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000892 basic_string& operator=(value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893
Howard Hinnant499cea12013-08-23 17:37:05 +0000894#if _LIBCPP_DEBUG_LEVEL >= 2
895 _LIBCPP_INLINE_VISIBILITY
896 iterator begin() _NOEXCEPT
897 {return iterator(this, __get_pointer());}
898 _LIBCPP_INLINE_VISIBILITY
899 const_iterator begin() const _NOEXCEPT
900 {return const_iterator(this, __get_pointer());}
901 _LIBCPP_INLINE_VISIBILITY
902 iterator end() _NOEXCEPT
903 {return iterator(this, __get_pointer() + size());}
904 _LIBCPP_INLINE_VISIBILITY
905 const_iterator end() const _NOEXCEPT
906 {return const_iterator(this, __get_pointer() + size());}
907#else
Howard Hinnanta6119a82011-05-29 19:57:12 +0000908 _LIBCPP_INLINE_VISIBILITY
909 iterator begin() _NOEXCEPT
910 {return iterator(__get_pointer());}
911 _LIBCPP_INLINE_VISIBILITY
912 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000913 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000914 _LIBCPP_INLINE_VISIBILITY
915 iterator end() _NOEXCEPT
916 {return iterator(__get_pointer() + size());}
917 _LIBCPP_INLINE_VISIBILITY
918 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000919 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +0000920#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +0000921 _LIBCPP_INLINE_VISIBILITY
922 reverse_iterator rbegin() _NOEXCEPT
923 {return reverse_iterator(end());}
924 _LIBCPP_INLINE_VISIBILITY
925 const_reverse_iterator rbegin() const _NOEXCEPT
926 {return const_reverse_iterator(end());}
927 _LIBCPP_INLINE_VISIBILITY
928 reverse_iterator rend() _NOEXCEPT
929 {return reverse_iterator(begin());}
930 _LIBCPP_INLINE_VISIBILITY
931 const_reverse_iterator rend() const _NOEXCEPT
932 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000933
Howard Hinnanta6119a82011-05-29 19:57:12 +0000934 _LIBCPP_INLINE_VISIBILITY
935 const_iterator cbegin() const _NOEXCEPT
936 {return begin();}
937 _LIBCPP_INLINE_VISIBILITY
938 const_iterator cend() const _NOEXCEPT
939 {return end();}
940 _LIBCPP_INLINE_VISIBILITY
941 const_reverse_iterator crbegin() const _NOEXCEPT
942 {return rbegin();}
943 _LIBCPP_INLINE_VISIBILITY
944 const_reverse_iterator crend() const _NOEXCEPT
945 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000946
Howard Hinnanta6119a82011-05-29 19:57:12 +0000947 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000948 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000949 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
950 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
951 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +0000952 {return (__is_long() ? __get_long_cap()
953 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000954
955 void resize(size_type __n, value_type __c);
956 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
957
Eric Fiselier59e24fe2017-06-01 02:29:37 +0000958 void reserve(size_type __res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000959 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000960 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000961 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +0000962 void clear() _NOEXCEPT;
Marshall Clowf1729d92017-11-15 20:02:27 +0000963 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
964 bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000965
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000966 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
967 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000968
969 const_reference at(size_type __n) const;
970 reference at(size_type __n);
971
972 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clow64c10d02018-07-02 18:41:15 +0000973
974 template <class _Tp>
975 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
976 typename enable_if
977 <
978 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
979 basic_string&
980 >::type
981 operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);}
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000982 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Eric Fiselier3e928972017-04-19 00:28:44 +0000984#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000985 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Eric Fiselier3e928972017-04-19 00:28:44 +0000986#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000988 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000989 basic_string& append(const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000990
991 template <class _Tp>
992 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
993 typename enable_if
994 <
995 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
996 basic_string&
997 >::type
998 append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +0000999 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow64c10d02018-07-02 18:41:15 +00001000
Marshall Clow42a87db2016-10-03 23:40:48 +00001001 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001002 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1003 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001004 <
1005 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1006 basic_string&
1007 >::type
1008 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001009 basic_string& append(const value_type* __s, size_type __n);
1010 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001011 basic_string& append(size_type __n, value_type __c);
Eric Fiselier026d38e2016-10-31 02:46:25 +00001012 template <class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001013 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1014 basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001015 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001016 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1017 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001018 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001019 __is_exactly_input_iterator<_InputIterator>::value
1020 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001021 basic_string&
1022 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +00001023 _LIBCPP_INLINE_VISIBILITY
1024 append(_InputIterator __first, _InputIterator __last) {
1025 const basic_string __temp (__first, __last, __alloc());
1026 append(__temp.data(), __temp.size());
1027 return *this;
1028 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001029 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001030 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1031 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001032 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001033 __is_forward_iterator<_ForwardIterator>::value
1034 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001035 basic_string&
1036 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +00001037 _LIBCPP_INLINE_VISIBILITY
1038 append(_ForwardIterator __first, _ForwardIterator __last) {
1039 return __append_forward_unsafe(__first, __last);
1040 }
1041
Eric Fiselier3e928972017-04-19 00:28:44 +00001042#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001044 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001045#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001046
1047 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001049 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001050 _LIBCPP_INLINE_VISIBILITY reference front();
1051 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1052 _LIBCPP_INLINE_VISIBILITY reference back();
1053 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054
Marshall Clow64c10d02018-07-02 18:41:15 +00001055 template <class _Tp>
1056 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1057 typename enable_if
1058 <
1059 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1060 basic_string&
1061 >::type
1062 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001063 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29 +00001064 basic_string& assign(const basic_string& __str) { return *this = __str; }
Eric Fiselier3e928972017-04-19 00:28:44 +00001065#ifndef _LIBCPP_CXX03_LANG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001066 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001067 basic_string& assign(basic_string&& __str)
Marshall Clow7ed093b2015-10-05 16:17:34 +00001068 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001069 {*this = _VSTD::move(__str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001070#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +00001071 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48 +00001072 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001073 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1074 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001075 <
1076 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1077 basic_string&
1078 >::type
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001079 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001080 basic_string& assign(const value_type* __s, size_type __n);
1081 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001082 basic_string& assign(size_type __n, value_type __c);
1083 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001084 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1085 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001086 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001087 __is_exactly_input_iterator<_InputIterator>::value
1088 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001089 basic_string&
1090 >::type
1091 assign(_InputIterator __first, _InputIterator __last);
1092 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001093 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1094 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001095 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001096 __is_forward_iterator<_ForwardIterator>::value
1097 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001098 basic_string&
1099 >::type
1100 assign(_ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001101#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001102 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001103 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001104#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001107 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001108
1109 template <class _Tp>
1110 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1111 typename enable_if
1112 <
1113 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1114 basic_string&
1115 >::type
1116 insert(size_type __pos1, const _Tp& __t)
1117 { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
1118
Marshall Clow6ac8de02016-09-24 22:45:42 +00001119 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001120 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1121 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001122 <
1123 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1124 basic_string&
1125 >::type
1126 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001127 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001128 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1129 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001130 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1131 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001132 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001133 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1134 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001135 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1136 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001137 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001138 __is_exactly_input_iterator<_InputIterator>::value
1139 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001140 iterator
1141 >::type
1142 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1143 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001144 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1145 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001146 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001147 __is_forward_iterator<_ForwardIterator>::value
1148 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149 iterator
1150 >::type
1151 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001152#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1155 {return insert(__pos, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001156#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001157
1158 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001160 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001161 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001162 iterator erase(const_iterator __first, const_iterator __last);
1163
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001165 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001166
1167 template <class _Tp>
1168 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1169 typename enable_if
1170 <
1171 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1172 basic_string&
1173 >::type
1174 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 +00001175 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 +00001176 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001177 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1178 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001179 <
1180 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1181 basic_string&
1182 >::type
1183 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001184 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1185 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001186 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001187 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001188 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001189
1190 template <class _Tp>
1191 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1192 typename enable_if
1193 <
1194 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1195 basic_string&
1196 >::type
1197 replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
1198
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001199 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001200 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001201 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001202 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001203 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001204 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001205 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001206 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1207 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001208 <
1209 __is_input_iterator<_InputIterator>::value,
1210 basic_string&
1211 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001212 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Eric Fiselier3e928972017-04-19 00:28:44 +00001213#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001214 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001215 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001216 {return replace(__i1, __i2, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001217#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001219 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001220 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001221 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1222
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001223 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001224 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001225#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00001226 _NOEXCEPT_DEBUG;
Marshall Clow7d914d12015-07-13 20:04:56 +00001227#else
Eric Fiselier47257c42016-12-28 05:53:01 +00001228 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00001229 __is_nothrow_swappable<allocator_type>::value);
1230#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001231
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001233 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001234 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001235 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Eric Fiselier10bebe22017-11-20 20:23:27 +00001236#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
Marshall Clowf532a702016-03-08 15:44:30 +00001237 _LIBCPP_INLINE_VISIBILITY
1238 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1239#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001240
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001241 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001242 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001243
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001245 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001246
1247 template <class _Tp>
1248 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1249 typename enable_if
1250 <
1251 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1252 size_type
1253 >::type
1254 find(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001255 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001257 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001258 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001259
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001261 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001262
1263 template <class _Tp>
1264 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1265 typename enable_if
1266 <
1267 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1268 size_type
1269 >::type
1270 rfind(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001271 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001272 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001273 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001274 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001275
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001277 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001278
1279 template <class _Tp>
1280 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1281 typename enable_if
1282 <
1283 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1284 size_type
1285 >::type
1286 find_first_of(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001287 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001289 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001291 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001292
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001293 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001294 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001295
1296 template <class _Tp>
1297 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1298 typename enable_if
1299 <
1300 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1301 size_type
1302 >::type
1303 find_last_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001304 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001306 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001307 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001308 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001310 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001311 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001312
1313 template <class _Tp>
1314 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1315 typename enable_if
1316 <
1317 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1318 size_type
1319 >::type
1320 find_first_not_of(const _Tp &__t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001321 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 +00001322 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001323 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001324 _LIBCPP_INLINE_VISIBILITY
1325 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1326
1327 _LIBCPP_INLINE_VISIBILITY
1328 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001329
1330 template <class _Tp>
1331 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1332 typename enable_if
1333 <
1334 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1335 size_type
1336 >::type
1337 find_last_not_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001338 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 +00001339 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001340 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001341 _LIBCPP_INLINE_VISIBILITY
1342 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1343
1344 _LIBCPP_INLINE_VISIBILITY
1345 int compare(const basic_string& __str) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001346
1347 template <class _Tp>
1348 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1349 typename enable_if
1350 <
1351 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1352 int
1353 >::type
1354 compare(const _Tp &__t) const;
1355
1356 template <class _Tp>
1357 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1358 typename enable_if
1359 <
1360 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1361 int
1362 >::type
1363 compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
1364
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001365 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001366 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001367 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 +00001368
Marshall Clow6ac8de02016-09-24 22:45:42 +00001369 template <class _Tp>
Eric Fiselier9dbc0532016-10-14 05:29:46 +00001370 inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow6ac8de02016-09-24 22:45:42 +00001371 typename enable_if
1372 <
1373 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1374 int
1375 >::type
1376 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 +00001377 int compare(const value_type* __s) const _NOEXCEPT;
1378 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1379 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001380
Marshall Clow46b4ad52017-12-04 20:11:38 +00001381#if _LIBCPP_STD_VER > 17
1382 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1383 bool starts_with(__self_view __sv) const _NOEXCEPT
1384 { return __self_view(data(), size()).starts_with(__sv); }
1385
1386 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1387 bool starts_with(value_type __c) const _NOEXCEPT
1388 { return !empty() && _Traits::eq(front(), __c); }
1389
1390 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1391 bool starts_with(const value_type* __s) const _NOEXCEPT
1392 { return starts_with(__self_view(__s)); }
1393
1394 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1395 bool ends_with(__self_view __sv) const _NOEXCEPT
1396 { return __self_view(data(), size()).ends_with( __sv); }
1397
1398 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1399 bool ends_with(value_type __c) const _NOEXCEPT
1400 { return !empty() && _Traits::eq(back(), __c); }
1401
1402 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1403 bool ends_with(const value_type* __s) const _NOEXCEPT
1404 { return ends_with(__self_view(__s)); }
1405#endif
1406
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001407 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001408
Marshall Clowab343bb2018-05-29 17:04:37 +00001409 _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT;
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001410
Howard Hinnant08dd2532013-04-22 23:55:13 +00001411 _LIBCPP_INLINE_VISIBILITY
1412 bool __is_long() const _NOEXCEPT
1413 {return bool(__r_.first().__s.__size_ & __short_mask);}
1414
Howard Hinnant499cea12013-08-23 17:37:05 +00001415#if _LIBCPP_DEBUG_LEVEL >= 2
1416
1417 bool __dereferenceable(const const_iterator* __i) const;
1418 bool __decrementable(const const_iterator* __i) const;
1419 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1420 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1421
1422#endif // _LIBCPP_DEBUG_LEVEL >= 2
1423
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001424private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001425 _LIBCPP_INLINE_VISIBILITY
1426 allocator_type& __alloc() _NOEXCEPT
1427 {return __r_.second();}
1428 _LIBCPP_INLINE_VISIBILITY
1429 const allocator_type& __alloc() const _NOEXCEPT
1430 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001431
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001432#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001433
Howard Hinnanta6119a82011-05-29 19:57:12 +00001434 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001435 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001436# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001438# else
1439 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1440# endif
1441
Howard Hinnanta6119a82011-05-29 19:57:12 +00001442 _LIBCPP_INLINE_VISIBILITY
1443 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001444# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001445 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001446# else
1447 {return __r_.first().__s.__size_;}
1448# endif
1449
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001450#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001451
1452 _LIBCPP_INLINE_VISIBILITY
1453 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001454# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001455 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1456# else
1457 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1458# endif
1459
1460 _LIBCPP_INLINE_VISIBILITY
1461 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001462# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001463 {return __r_.first().__s.__size_;}
1464# else
1465 {return __r_.first().__s.__size_ >> 1;}
1466# endif
1467
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001468#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001469
Howard Hinnanta6119a82011-05-29 19:57:12 +00001470 _LIBCPP_INLINE_VISIBILITY
1471 void __set_long_size(size_type __s) _NOEXCEPT
1472 {__r_.first().__l.__size_ = __s;}
1473 _LIBCPP_INLINE_VISIBILITY
1474 size_type __get_long_size() const _NOEXCEPT
1475 {return __r_.first().__l.__size_;}
1476 _LIBCPP_INLINE_VISIBILITY
1477 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001478 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1479
Howard Hinnanta6119a82011-05-29 19:57:12 +00001480 _LIBCPP_INLINE_VISIBILITY
1481 void __set_long_cap(size_type __s) _NOEXCEPT
1482 {__r_.first().__l.__cap_ = __long_mask | __s;}
1483 _LIBCPP_INLINE_VISIBILITY
1484 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001485 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001486
Howard Hinnanta6119a82011-05-29 19:57:12 +00001487 _LIBCPP_INLINE_VISIBILITY
1488 void __set_long_pointer(pointer __p) _NOEXCEPT
1489 {__r_.first().__l.__data_ = __p;}
1490 _LIBCPP_INLINE_VISIBILITY
1491 pointer __get_long_pointer() _NOEXCEPT
1492 {return __r_.first().__l.__data_;}
1493 _LIBCPP_INLINE_VISIBILITY
1494 const_pointer __get_long_pointer() const _NOEXCEPT
1495 {return __r_.first().__l.__data_;}
1496 _LIBCPP_INLINE_VISIBILITY
1497 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001498 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001499 _LIBCPP_INLINE_VISIBILITY
1500 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001501 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001502 _LIBCPP_INLINE_VISIBILITY
1503 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001504 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001505 _LIBCPP_INLINE_VISIBILITY
1506 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001507 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1508
Howard Hinnanta6119a82011-05-29 19:57:12 +00001509 _LIBCPP_INLINE_VISIBILITY
1510 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001511 {
1512 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1513 for (unsigned __i = 0; __i < __n_words; ++__i)
1514 __a[__i] = 0;
1515 }
1516
1517 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001519 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001520 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001521 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001522 static _LIBCPP_INLINE_VISIBILITY
1523 size_type __recommend(size_type __s) _NOEXCEPT
Marshall Clow088e6012018-02-07 21:30:17 +00001524 {
1525 if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
1526 size_type __guess = __align_it<sizeof(value_type) < __alignment ?
1527 __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
1528 if (__guess == __min_cap) ++__guess;
1529 return __guess;
1530 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001531
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001532 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001533 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001534 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001535 void __init(const value_type* __s, size_type __sz);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001536 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001537 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001538
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001539 template <class _InputIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001540 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001541 typename enable_if
1542 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001543 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001544 void
1545 >::type
1546 __init(_InputIterator __first, _InputIterator __last);
1547
1548 template <class _ForwardIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001549 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001550 typename enable_if
1551 <
1552 __is_forward_iterator<_ForwardIterator>::value,
1553 void
1554 >::type
1555 __init(_ForwardIterator __first, _ForwardIterator __last);
1556
1557 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001558 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001559 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1560 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001561 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001562
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001564 void __erase_to_end(size_type __pos);
1565
Howard Hinnante32b5e22010-11-17 17:55:08 +00001566 _LIBCPP_INLINE_VISIBILITY
1567 void __copy_assign_alloc(const basic_string& __str)
1568 {__copy_assign_alloc(__str, integral_constant<bool,
1569 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1570
1571 _LIBCPP_INLINE_VISIBILITY
1572 void __copy_assign_alloc(const basic_string& __str, true_type)
1573 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001574 if (__alloc() == __str.__alloc())
1575 __alloc() = __str.__alloc();
1576 else
Howard Hinnante32b5e22010-11-17 17:55:08 +00001577 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001578 if (!__str.__is_long())
1579 {
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001580 __clear_and_shrink();
Marshall Clow9247fd22017-01-31 03:40:52 +00001581 __alloc() = __str.__alloc();
1582 }
1583 else
1584 {
1585 allocator_type __a = __str.__alloc();
1586 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001587 __clear_and_shrink();
Marshall Clow9247fd22017-01-31 03:40:52 +00001588 __alloc() = _VSTD::move(__a);
1589 __set_long_pointer(__p);
1590 __set_long_cap(__str.__get_long_cap());
1591 __set_long_size(__str.size());
1592 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001593 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001594 }
1595
1596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001597 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001598 {}
1599
Eric Fiselier3e928972017-04-19 00:28:44 +00001600#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001601 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001602 void __move_assign(basic_string& __str, false_type)
1603 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001605 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001606#if _LIBCPP_STD_VER > 14
1607 _NOEXCEPT;
1608#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001609 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001610#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001611#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001612
1613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001614 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001615 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001616 _NOEXCEPT_(
1617 !__alloc_traits::propagate_on_container_move_assignment::value ||
1618 is_nothrow_move_assignable<allocator_type>::value)
1619 {__move_assign_alloc(__str, integral_constant<bool,
1620 __alloc_traits::propagate_on_container_move_assignment::value>());}
1621
1622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001623 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001624 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1625 {
1626 __alloc() = _VSTD::move(__c.__alloc());
1627 }
1628
1629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001630 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001631 _NOEXCEPT
1632 {}
1633
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001634 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1635 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001636
1637 friend basic_string operator+<>(const basic_string&, const basic_string&);
1638 friend basic_string operator+<>(const value_type*, const basic_string&);
1639 friend basic_string operator+<>(value_type, const basic_string&);
1640 friend basic_string operator+<>(const basic_string&, const value_type*);
1641 friend basic_string operator+<>(const basic_string&, value_type);
1642};
1643
Marshall Clow5b1e87e2018-02-08 06:34:03 +00001644#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1645template<class _InputIterator,
1646 class _CharT = typename iterator_traits<_InputIterator>::value_type,
1647 class _Allocator = allocator<_CharT>,
1648 class = typename enable_if<__is_input_iterator<_InputIterator>::value, void>::type,
1649 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1650 >
1651basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
1652 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
Marshall Clow64c10d02018-07-02 18:41:15 +00001653
1654template<class _CharT,
1655 class _Traits,
1656 class _Allocator = allocator<_CharT>,
1657 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1658 >
1659explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
1660 -> basic_string<_CharT, _Traits, _Allocator>;
1661
1662template<class _CharT,
1663 class _Traits,
1664 class _Allocator = allocator<_CharT>,
1665 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type,
1666 class _Sz = typename allocator_traits<_Allocator>::size_type
1667 >
1668basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
1669 -> basic_string<_CharT, _Traits, _Allocator>;
Marshall Clow5b1e87e2018-02-08 06:34:03 +00001670#endif
1671
1672
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001673template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001674inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001675void
1676basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1677{
Howard Hinnant499cea12013-08-23 17:37:05 +00001678#if _LIBCPP_DEBUG_LEVEL >= 2
1679 __get_db()->__invalidate_all(this);
1680#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001681}
1682
1683template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001684inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001685void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001686basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001687#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001688 __pos
1689#endif
1690 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001691{
Howard Hinnant499cea12013-08-23 17:37:05 +00001692#if _LIBCPP_DEBUG_LEVEL >= 2
1693 __c_node* __c = __get_db()->__find_c_and_lock(this);
1694 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001695 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001696 const_pointer __new_last = __get_pointer() + __pos;
1697 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001698 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001699 --__p;
1700 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1701 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001702 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001703 (*__p)->__c_ = nullptr;
1704 if (--__c->end_ != __p)
1705 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001706 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001707 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001708 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001709 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001710#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001711}
1712
1713template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001714inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001715basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001716 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001717{
Howard Hinnant499cea12013-08-23 17:37:05 +00001718#if _LIBCPP_DEBUG_LEVEL >= 2
1719 __get_db()->__insert_c(this);
1720#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001721 __zero();
1722}
1723
1724template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001725inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001726basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001727#if _LIBCPP_STD_VER <= 14
1728 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1729#else
1730 _NOEXCEPT
1731#endif
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001732: __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001733{
Howard Hinnant499cea12013-08-23 17:37:05 +00001734#if _LIBCPP_DEBUG_LEVEL >= 2
1735 __get_db()->__insert_c(this);
1736#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001737 __zero();
1738}
1739
1740template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001741void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1742 size_type __sz,
1743 size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001744{
1745 if (__reserve > max_size())
1746 this->__throw_length_error();
1747 pointer __p;
1748 if (__reserve < __min_cap)
1749 {
1750 __set_short_size(__sz);
1751 __p = __get_short_pointer();
1752 }
1753 else
1754 {
1755 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001756 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001757 __set_long_pointer(__p);
1758 __set_long_cap(__cap+1);
1759 __set_long_size(__sz);
1760 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001761 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001762 traits_type::assign(__p[__sz], value_type());
1763}
1764
1765template <class _CharT, class _Traits, class _Allocator>
1766void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001767basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001768{
1769 if (__sz > max_size())
1770 this->__throw_length_error();
1771 pointer __p;
1772 if (__sz < __min_cap)
1773 {
1774 __set_short_size(__sz);
1775 __p = __get_short_pointer();
1776 }
1777 else
1778 {
1779 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001780 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001781 __set_long_pointer(__p);
1782 __set_long_cap(__cap+1);
1783 __set_long_size(__sz);
1784 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001785 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001786 traits_type::assign(__p[__sz], value_type());
1787}
1788
1789template <class _CharT, class _Traits, class _Allocator>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001790#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +00001791template <class>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001792#endif
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001793basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001794 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001795{
Howard Hinnant499cea12013-08-23 17:37:05 +00001796 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001797 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001798#if _LIBCPP_DEBUG_LEVEL >= 2
1799 __get_db()->__insert_c(this);
1800#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001801}
1802
1803template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001804inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001805basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001806{
Howard Hinnant499cea12013-08-23 17:37:05 +00001807 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001808 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001809#if _LIBCPP_DEBUG_LEVEL >= 2
1810 __get_db()->__insert_c(this);
1811#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001812}
1813
1814template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001815inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001816basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001817 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001818{
Howard Hinnant499cea12013-08-23 17:37:05 +00001819 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001820 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001821#if _LIBCPP_DEBUG_LEVEL >= 2
1822 __get_db()->__insert_c(this);
1823#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001824}
1825
1826template <class _CharT, class _Traits, class _Allocator>
1827basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001828 : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001829{
1830 if (!__str.__is_long())
1831 __r_.first().__r = __str.__r_.first().__r;
1832 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001833 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001834#if _LIBCPP_DEBUG_LEVEL >= 2
1835 __get_db()->__insert_c(this);
1836#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001837}
1838
1839template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001840basic_string<_CharT, _Traits, _Allocator>::basic_string(
1841 const basic_string& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001842 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001843{
1844 if (!__str.__is_long())
1845 __r_.first().__r = __str.__r_.first().__r;
1846 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001847 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001848#if _LIBCPP_DEBUG_LEVEL >= 2
1849 __get_db()->__insert_c(this);
1850#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001851}
1852
Eric Fiselier3e928972017-04-19 00:28:44 +00001853#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001854
1855template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001856inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001857basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001858#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001859 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00001860#else
1861 _NOEXCEPT
1862#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001863 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001864{
1865 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00001866#if _LIBCPP_DEBUG_LEVEL >= 2
1867 __get_db()->__insert_c(this);
1868 if (__is_long())
1869 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001870#endif
1871}
1872
1873template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001874inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001875basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001876 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001877{
Marshall Clowd5549cc2014-07-17 15:32:20 +00001878 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001879 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00001880 else
1881 {
1882 __r_.first().__r = __str.__r_.first().__r;
1883 __str.__zero();
1884 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001885#if _LIBCPP_DEBUG_LEVEL >= 2
1886 __get_db()->__insert_c(this);
1887 if (__is_long())
1888 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001889#endif
1890}
1891
Eric Fiselier3e928972017-04-19 00:28:44 +00001892#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001893
1894template <class _CharT, class _Traits, class _Allocator>
1895void
1896basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1897{
1898 if (__n > max_size())
1899 this->__throw_length_error();
1900 pointer __p;
1901 if (__n < __min_cap)
1902 {
1903 __set_short_size(__n);
1904 __p = __get_short_pointer();
1905 }
1906 else
1907 {
1908 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001909 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001910 __set_long_pointer(__p);
1911 __set_long_cap(__cap+1);
1912 __set_long_size(__n);
1913 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001914 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001915 traits_type::assign(__p[__n], value_type());
1916}
1917
1918template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001919inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001920basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001921{
1922 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001923#if _LIBCPP_DEBUG_LEVEL >= 2
1924 __get_db()->__insert_c(this);
1925#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001926}
1927
1928template <class _CharT, class _Traits, class _Allocator>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001929#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +00001930template <class>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001931#endif
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001932basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001933 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001934{
1935 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001936#if _LIBCPP_DEBUG_LEVEL >= 2
1937 __get_db()->__insert_c(this);
1938#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001939}
1940
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001941template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001942basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1943 size_type __pos, size_type __n,
1944 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001945 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001946{
1947 size_type __str_sz = __str.size();
1948 if (__pos > __str_sz)
1949 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001950 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00001951#if _LIBCPP_DEBUG_LEVEL >= 2
1952 __get_db()->__insert_c(this);
1953#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001954}
1955
1956template <class _CharT, class _Traits, class _Allocator>
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001957inline _LIBCPP_INLINE_VISIBILITY
1958basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001959 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001960 : __r_(__second_tag(), __a)
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001961{
1962 size_type __str_sz = __str.size();
1963 if (__pos > __str_sz)
1964 this->__throw_out_of_range();
1965 __init(__str.data() + __pos, __str_sz - __pos);
1966#if _LIBCPP_DEBUG_LEVEL >= 2
1967 __get_db()->__insert_c(this);
1968#endif
1969}
1970
1971template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001972template <class _Tp, class>
Marshall Clowdb7fa112016-11-14 18:22:19 +00001973basic_string<_CharT, _Traits, _Allocator>::basic_string(
Marshall Clow64c10d02018-07-02 18:41:15 +00001974 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001975 : __r_(__second_tag(), __a)
Marshall Clowdb7fa112016-11-14 18:22:19 +00001976{
Marshall Clow64c10d02018-07-02 18:41:15 +00001977 __self_view __sv0 = __t;
1978 __self_view __sv = __sv0.substr(__pos, __n);
Marshall Clowdb7fa112016-11-14 18:22:19 +00001979 __init(__sv.data(), __sv.size());
1980#if _LIBCPP_DEBUG_LEVEL >= 2
1981 __get_db()->__insert_c(this);
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001982#endif
Marshall Clowdb7fa112016-11-14 18:22:19 +00001983}
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)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001988{
Marshall Clow64c10d02018-07-02 18:41:15 +00001989 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001990 __init(__sv.data(), __sv.size());
1991#if _LIBCPP_DEBUG_LEVEL >= 2
1992 __get_db()->__insert_c(this);
1993#endif
1994}
1995
1996template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001997template <class _Tp, class>
1998basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001999 : __r_(__second_tag(), __a)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002000{
Marshall Clow64c10d02018-07-02 18:41:15 +00002001 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002002 __init(__sv.data(), __sv.size());
2003#if _LIBCPP_DEBUG_LEVEL >= 2
2004 __get_db()->__insert_c(this);
2005#endif
2006}
2007
2008template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002009template <class _InputIterator>
2010typename enable_if
2011<
Marshall Clowdf9db312016-01-13 21:54:34 +00002012 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002013 void
2014>::type
2015basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2016{
2017 __zero();
2018#ifndef _LIBCPP_NO_EXCEPTIONS
2019 try
2020 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002021#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002022 for (; __first != __last; ++__first)
2023 push_back(*__first);
2024#ifndef _LIBCPP_NO_EXCEPTIONS
2025 }
2026 catch (...)
2027 {
2028 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002029 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002030 throw;
2031 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002032#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002033}
2034
2035template <class _CharT, class _Traits, class _Allocator>
2036template <class _ForwardIterator>
2037typename enable_if
2038<
2039 __is_forward_iterator<_ForwardIterator>::value,
2040 void
2041>::type
2042basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2043{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002044 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002045 if (__sz > max_size())
2046 this->__throw_length_error();
2047 pointer __p;
2048 if (__sz < __min_cap)
2049 {
2050 __set_short_size(__sz);
2051 __p = __get_short_pointer();
2052 }
2053 else
2054 {
2055 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002056 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002057 __set_long_pointer(__p);
2058 __set_long_cap(__cap+1);
2059 __set_long_size(__sz);
2060 }
Eric Fiselierb9919752014-10-27 19:28:20 +00002061 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002062 traits_type::assign(*__p, *__first);
2063 traits_type::assign(*__p, value_type());
2064}
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{
2071 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002072#if _LIBCPP_DEBUG_LEVEL >= 2
2073 __get_db()->__insert_c(this);
2074#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002075}
2076
2077template <class _CharT, class _Traits, class _Allocator>
2078template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002079inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002080basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2081 const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002082 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002083{
2084 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002085#if _LIBCPP_DEBUG_LEVEL >= 2
2086 __get_db()->__insert_c(this);
2087#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002088}
2089
Eric Fiselier3e928972017-04-19 00:28:44 +00002090#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00002091
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002092template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002093inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00002094basic_string<_CharT, _Traits, _Allocator>::basic_string(
2095 initializer_list<_CharT> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002096{
2097 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002098#if _LIBCPP_DEBUG_LEVEL >= 2
2099 __get_db()->__insert_c(this);
2100#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002101}
2102
2103template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002104inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002105
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00002106basic_string<_CharT, _Traits, _Allocator>::basic_string(
2107 initializer_list<_CharT> __il, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002108 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002109{
2110 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002111#if _LIBCPP_DEBUG_LEVEL >= 2
2112 __get_db()->__insert_c(this);
2113#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002114}
2115
Eric Fiselier3e928972017-04-19 00:28:44 +00002116#endif // _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00002117
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002118template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002119basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2120{
Howard Hinnant499cea12013-08-23 17:37:05 +00002121#if _LIBCPP_DEBUG_LEVEL >= 2
2122 __get_db()->__erase_c(this);
2123#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002124 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002125 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002126}
2127
2128template <class _CharT, class _Traits, class _Allocator>
2129void
2130basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2131 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002132 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 +00002133{
2134 size_type __ms = max_size();
2135 if (__delta_cap > __ms - __old_cap - 1)
2136 this->__throw_length_error();
2137 pointer __old_p = __get_pointer();
2138 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002139 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002140 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002141 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002142 __invalidate_all_iterators();
2143 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002144 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2145 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002146 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002147 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002148 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2149 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002150 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2151 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002152 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002153 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002154 __set_long_pointer(__p);
2155 __set_long_cap(__cap+1);
2156 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2157 __set_long_size(__old_sz);
2158 traits_type::assign(__p[__old_sz], value_type());
2159}
2160
2161template <class _CharT, class _Traits, class _Allocator>
2162void
2163basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2164 size_type __n_copy, size_type __n_del, size_type __n_add)
2165{
2166 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00002167 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002168 this->__throw_length_error();
2169 pointer __old_p = __get_pointer();
2170 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002171 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002172 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002173 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002174 __invalidate_all_iterators();
2175 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002176 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2177 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002178 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2179 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002180 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2181 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2182 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002183 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002184 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002185 __set_long_pointer(__p);
2186 __set_long_cap(__cap+1);
2187}
2188
2189// assign
2190
2191template <class _CharT, class _Traits, class _Allocator>
2192basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002193basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002194{
Alp Tokerec34c482014-05-15 11:27:39 +00002195 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002196 size_type __cap = capacity();
2197 if (__cap >= __n)
2198 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002199 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002200 traits_type::move(__p, __s, __n);
2201 traits_type::assign(__p[__n], value_type());
2202 __set_size(__n);
2203 __invalidate_iterators_past(__n);
2204 }
2205 else
2206 {
2207 size_type __sz = size();
2208 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2209 }
2210 return *this;
2211}
2212
2213template <class _CharT, class _Traits, class _Allocator>
2214basic_string<_CharT, _Traits, _Allocator>&
2215basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2216{
2217 size_type __cap = capacity();
2218 if (__cap < __n)
2219 {
2220 size_type __sz = size();
2221 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2222 }
2223 else
2224 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002225 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002226 traits_type::assign(__p, __n, __c);
2227 traits_type::assign(__p[__n], value_type());
2228 __set_size(__n);
2229 return *this;
2230}
2231
2232template <class _CharT, class _Traits, class _Allocator>
2233basic_string<_CharT, _Traits, _Allocator>&
2234basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2235{
2236 pointer __p;
2237 if (__is_long())
2238 {
2239 __p = __get_long_pointer();
2240 __set_long_size(1);
2241 }
2242 else
2243 {
2244 __p = __get_short_pointer();
2245 __set_short_size(1);
2246 }
2247 traits_type::assign(*__p, __c);
2248 traits_type::assign(*++__p, value_type());
2249 __invalidate_iterators_past(1);
2250 return *this;
2251}
2252
2253template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002254basic_string<_CharT, _Traits, _Allocator>&
2255basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2256{
2257 if (this != &__str)
2258 {
2259 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00002260 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00002261 }
2262 return *this;
2263}
2264
Eric Fiselier3e928972017-04-19 00:28:44 +00002265#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante32b5e22010-11-17 17:55:08 +00002266
2267template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002268inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002269void
2270basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002271 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002272{
2273 if (__alloc() != __str.__alloc())
2274 assign(__str);
2275 else
2276 __move_assign(__str, true_type());
2277}
2278
2279template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002280inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002281void
2282basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002283#if _LIBCPP_STD_VER > 14
2284 _NOEXCEPT
2285#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002286 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002287#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002288{
Vedant Kumar2b588cb2018-03-08 21:15:26 +00002289 __clear_and_shrink();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002290 __r_.first() = __str.__r_.first();
2291 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002292 __str.__zero();
2293}
2294
2295template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002296inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002297basic_string<_CharT, _Traits, _Allocator>&
2298basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002299 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002300{
2301 __move_assign(__str, integral_constant<bool,
2302 __alloc_traits::propagate_on_container_move_assignment::value>());
2303 return *this;
2304}
2305
2306#endif
2307
2308template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002309template<class _InputIterator>
2310typename enable_if
2311<
Marshall Clowdf9db312016-01-13 21:54:34 +00002312 __is_exactly_input_iterator <_InputIterator>::value
2313 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002314 basic_string<_CharT, _Traits, _Allocator>&
2315>::type
2316basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2317{
Marshall Clowd979eed2016-09-05 01:54:30 +00002318 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002319 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002320 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002321}
2322
2323template <class _CharT, class _Traits, class _Allocator>
2324template<class _ForwardIterator>
2325typename enable_if
2326<
Marshall Clowdf9db312016-01-13 21:54:34 +00002327 __is_forward_iterator<_ForwardIterator>::value
2328 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002329 basic_string<_CharT, _Traits, _Allocator>&
2330>::type
2331basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2332{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002333 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002334 size_type __cap = capacity();
2335 if (__cap < __n)
2336 {
2337 size_type __sz = size();
2338 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2339 }
2340 else
2341 __invalidate_iterators_past(__n);
2342 pointer __p = __get_pointer();
2343 for (; __first != __last; ++__first, ++__p)
2344 traits_type::assign(*__p, *__first);
2345 traits_type::assign(*__p, value_type());
2346 __set_size(__n);
2347 return *this;
2348}
2349
2350template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002351basic_string<_CharT, _Traits, _Allocator>&
2352basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2353{
2354 size_type __sz = __str.size();
2355 if (__pos > __sz)
2356 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002357 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002358}
2359
2360template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002361template <class _Tp>
2362typename enable_if
2363<
2364 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002365 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002366>::type
2367basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002368{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002369 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002370 size_type __sz = __sv.size();
2371 if (__pos > __sz)
2372 this->__throw_out_of_range();
2373 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2374}
2375
2376
2377template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002378basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002379basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002380{
Alp Tokerec34c482014-05-15 11:27:39 +00002381 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002382 return assign(__s, traits_type::length(__s));
2383}
2384
2385// append
2386
2387template <class _CharT, class _Traits, class _Allocator>
2388basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002389basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002390{
Alp Tokerec34c482014-05-15 11:27:39 +00002391 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002392 size_type __cap = capacity();
2393 size_type __sz = size();
2394 if (__cap - __sz >= __n)
2395 {
2396 if (__n)
2397 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002398 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002399 traits_type::copy(__p + __sz, __s, __n);
2400 __sz += __n;
2401 __set_size(__sz);
2402 traits_type::assign(__p[__sz], value_type());
2403 }
2404 }
2405 else
2406 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2407 return *this;
2408}
2409
2410template <class _CharT, class _Traits, class _Allocator>
2411basic_string<_CharT, _Traits, _Allocator>&
2412basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2413{
2414 if (__n)
2415 {
2416 size_type __cap = capacity();
2417 size_type __sz = size();
2418 if (__cap - __sz < __n)
2419 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2420 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002421 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002422 __sz += __n;
2423 __set_size(__sz);
2424 traits_type::assign(__p[__sz], value_type());
2425 }
2426 return *this;
2427}
2428
2429template <class _CharT, class _Traits, class _Allocator>
2430void
2431basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2432{
Howard Hinnant15467182013-04-30 21:44:48 +00002433 bool __is_short = !__is_long();
2434 size_type __cap;
2435 size_type __sz;
2436 if (__is_short)
2437 {
2438 __cap = __min_cap - 1;
2439 __sz = __get_short_size();
2440 }
2441 else
2442 {
2443 __cap = __get_long_cap() - 1;
2444 __sz = __get_long_size();
2445 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002446 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002447 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002448 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002449 __is_short = !__is_long();
2450 }
2451 pointer __p;
2452 if (__is_short)
2453 {
2454 __p = __get_short_pointer() + __sz;
2455 __set_short_size(__sz+1);
2456 }
2457 else
2458 {
2459 __p = __get_long_pointer() + __sz;
2460 __set_long_size(__sz+1);
2461 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002462 traits_type::assign(*__p, __c);
2463 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002464}
2465
Marshall Clowac655ef2016-09-07 03:32:06 +00002466template <class _Tp>
Marshall Clowd979eed2016-09-05 01:54:30 +00002467bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2468{
2469 return __first <= __p && __p < __last;
2470}
2471
Marshall Clowac655ef2016-09-07 03:32:06 +00002472template <class _Tp1, class _Tp2>
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00002473bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
Marshall Clowac655ef2016-09-07 03:32:06 +00002474{
2475 return false;
2476}
2477
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002478template <class _CharT, class _Traits, class _Allocator>
2479template<class _ForwardIterator>
Eric Fiselier026d38e2016-10-31 02:46:25 +00002480basic_string<_CharT, _Traits, _Allocator>&
2481basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2482 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002483{
Eric Fiselier026d38e2016-10-31 02:46:25 +00002484 static_assert(__is_forward_iterator<_ForwardIterator>::value,
2485 "function requires a ForwardIterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002486 size_type __sz = size();
2487 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002488 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002489 if (__n)
2490 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002491 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2492 _CharRef __tmp_ref = *__first;
2493 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002494 {
2495 const basic_string __temp (__first, __last, __alloc());
2496 append(__temp.data(), __temp.size());
2497 }
2498 else
2499 {
2500 if (__cap - __sz < __n)
2501 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2502 pointer __p = __get_pointer() + __sz;
2503 for (; __first != __last; ++__p, ++__first)
2504 traits_type::assign(*__p, *__first);
2505 traits_type::assign(*__p, value_type());
2506 __set_size(__sz + __n);
2507 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002508 }
2509 return *this;
2510}
2511
2512template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002513inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002514basic_string<_CharT, _Traits, _Allocator>&
2515basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2516{
2517 return append(__str.data(), __str.size());
2518}
2519
2520template <class _CharT, class _Traits, class _Allocator>
2521basic_string<_CharT, _Traits, _Allocator>&
2522basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2523{
2524 size_type __sz = __str.size();
2525 if (__pos > __sz)
2526 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002527 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002528}
2529
2530template <class _CharT, class _Traits, class _Allocator>
Marshall Clow42a87db2016-10-03 23:40:48 +00002531template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002532 typename enable_if
2533 <
2534 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2535 basic_string<_CharT, _Traits, _Allocator>&
2536 >::type
2537basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002538{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002539 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002540 size_type __sz = __sv.size();
2541 if (__pos > __sz)
2542 this->__throw_out_of_range();
2543 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2544}
2545
2546template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002547basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002548basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002549{
Alp Tokerec34c482014-05-15 11:27:39 +00002550 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002551 return append(__s, traits_type::length(__s));
2552}
2553
2554// insert
2555
2556template <class _CharT, class _Traits, class _Allocator>
2557basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002558basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002559{
Alp Tokerec34c482014-05-15 11:27:39 +00002560 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002561 size_type __sz = size();
2562 if (__pos > __sz)
2563 this->__throw_out_of_range();
2564 size_type __cap = capacity();
2565 if (__cap - __sz >= __n)
2566 {
2567 if (__n)
2568 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002569 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002570 size_type __n_move = __sz - __pos;
2571 if (__n_move != 0)
2572 {
2573 if (__p + __pos <= __s && __s < __p + __sz)
2574 __s += __n;
2575 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2576 }
2577 traits_type::move(__p + __pos, __s, __n);
2578 __sz += __n;
2579 __set_size(__sz);
2580 traits_type::assign(__p[__sz], value_type());
2581 }
2582 }
2583 else
2584 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2585 return *this;
2586}
2587
2588template <class _CharT, class _Traits, class _Allocator>
2589basic_string<_CharT, _Traits, _Allocator>&
2590basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2591{
2592 size_type __sz = size();
2593 if (__pos > __sz)
2594 this->__throw_out_of_range();
2595 if (__n)
2596 {
2597 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002598 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002599 if (__cap - __sz >= __n)
2600 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002601 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002602 size_type __n_move = __sz - __pos;
2603 if (__n_move != 0)
2604 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2605 }
2606 else
2607 {
2608 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002609 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002610 }
2611 traits_type::assign(__p + __pos, __n, __c);
2612 __sz += __n;
2613 __set_size(__sz);
2614 traits_type::assign(__p[__sz], value_type());
2615 }
2616 return *this;
2617}
2618
2619template <class _CharT, class _Traits, class _Allocator>
2620template<class _InputIterator>
2621typename enable_if
2622<
Marshall Clowdf9db312016-01-13 21:54:34 +00002623 __is_exactly_input_iterator<_InputIterator>::value
2624 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2625 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002626>::type
2627basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2628{
Howard Hinnant499cea12013-08-23 17:37:05 +00002629#if _LIBCPP_DEBUG_LEVEL >= 2
2630 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2631 "string::insert(iterator, range) called with an iterator not"
2632 " referring to this string");
2633#endif
Marshall Clowd979eed2016-09-05 01:54:30 +00002634 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002635 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002636}
2637
2638template <class _CharT, class _Traits, class _Allocator>
2639template<class _ForwardIterator>
2640typename enable_if
2641<
Marshall Clowdf9db312016-01-13 21:54:34 +00002642 __is_forward_iterator<_ForwardIterator>::value
2643 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002644 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2645>::type
2646basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2647{
Howard Hinnant499cea12013-08-23 17:37:05 +00002648#if _LIBCPP_DEBUG_LEVEL >= 2
2649 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2650 "string::insert(iterator, range) called with an iterator not"
2651 " referring to this string");
2652#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002653 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002654 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002655 if (__n)
2656 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002657 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2658 _CharRef __tmp_char = *__first;
2659 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002660 {
2661 const basic_string __temp(__first, __last, __alloc());
2662 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2663 }
2664
2665 size_type __sz = size();
2666 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002667 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002668 if (__cap - __sz >= __n)
2669 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002670 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002671 size_type __n_move = __sz - __ip;
2672 if (__n_move != 0)
2673 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2674 }
2675 else
2676 {
2677 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002678 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002679 }
2680 __sz += __n;
2681 __set_size(__sz);
2682 traits_type::assign(__p[__sz], value_type());
2683 for (__p += __ip; __first != __last; ++__p, ++__first)
2684 traits_type::assign(*__p, *__first);
2685 }
2686 return begin() + __ip;
2687}
2688
2689template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002690inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002691basic_string<_CharT, _Traits, _Allocator>&
2692basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2693{
2694 return insert(__pos1, __str.data(), __str.size());
2695}
2696
2697template <class _CharT, class _Traits, class _Allocator>
2698basic_string<_CharT, _Traits, _Allocator>&
2699basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2700 size_type __pos2, size_type __n)
2701{
2702 size_type __str_sz = __str.size();
2703 if (__pos2 > __str_sz)
2704 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002705 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002706}
2707
2708template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002709template <class _Tp>
2710typename enable_if
2711<
2712 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002713 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002714>::type
2715basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002716 size_type __pos2, size_type __n)
2717{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002718 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002719 size_type __str_sz = __sv.size();
2720 if (__pos2 > __str_sz)
2721 this->__throw_out_of_range();
2722 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2723}
2724
2725template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002726basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002727basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002728{
Alp Tokerec34c482014-05-15 11:27:39 +00002729 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002730 return insert(__pos, __s, traits_type::length(__s));
2731}
2732
2733template <class _CharT, class _Traits, class _Allocator>
2734typename basic_string<_CharT, _Traits, _Allocator>::iterator
2735basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2736{
2737 size_type __ip = static_cast<size_type>(__pos - begin());
2738 size_type __sz = size();
2739 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002740 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002741 if (__cap == __sz)
2742 {
2743 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002744 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002745 }
2746 else
2747 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002748 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002749 size_type __n_move = __sz - __ip;
2750 if (__n_move != 0)
2751 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2752 }
2753 traits_type::assign(__p[__ip], __c);
2754 traits_type::assign(__p[++__sz], value_type());
2755 __set_size(__sz);
2756 return begin() + static_cast<difference_type>(__ip);
2757}
2758
2759template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002760inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002761typename basic_string<_CharT, _Traits, _Allocator>::iterator
2762basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2763{
Howard Hinnant499cea12013-08-23 17:37:05 +00002764#if _LIBCPP_DEBUG_LEVEL >= 2
2765 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2766 "string::insert(iterator, n, value) called with an iterator not"
2767 " referring to this string");
2768#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002769 difference_type __p = __pos - begin();
2770 insert(static_cast<size_type>(__p), __n, __c);
2771 return begin() + __p;
2772}
2773
2774// replace
2775
2776template <class _CharT, class _Traits, class _Allocator>
2777basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002778basic_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 +00002779 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002780{
Alp Tokerec34c482014-05-15 11:27:39 +00002781 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002782 size_type __sz = size();
2783 if (__pos > __sz)
2784 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002785 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002786 size_type __cap = capacity();
2787 if (__cap - __sz + __n1 >= __n2)
2788 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002789 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002790 if (__n1 != __n2)
2791 {
2792 size_type __n_move = __sz - __pos - __n1;
2793 if (__n_move != 0)
2794 {
2795 if (__n1 > __n2)
2796 {
2797 traits_type::move(__p + __pos, __s, __n2);
2798 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2799 goto __finish;
2800 }
2801 if (__p + __pos < __s && __s < __p + __sz)
2802 {
2803 if (__p + __pos + __n1 <= __s)
2804 __s += __n2 - __n1;
2805 else // __p + __pos < __s < __p + __pos + __n1
2806 {
2807 traits_type::move(__p + __pos, __s, __n1);
2808 __pos += __n1;
2809 __s += __n2;
2810 __n2 -= __n1;
2811 __n1 = 0;
2812 }
2813 }
2814 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2815 }
2816 }
2817 traits_type::move(__p + __pos, __s, __n2);
2818__finish:
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002819// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
2820// but this is a safe operation, so we disable the check.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002821 __sz += __n2 - __n1;
2822 __set_size(__sz);
2823 __invalidate_iterators_past(__sz);
2824 traits_type::assign(__p[__sz], value_type());
2825 }
2826 else
2827 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2828 return *this;
2829}
2830
2831template <class _CharT, class _Traits, class _Allocator>
2832basic_string<_CharT, _Traits, _Allocator>&
2833basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002834 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002835{
2836 size_type __sz = size();
2837 if (__pos > __sz)
2838 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002839 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002840 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002841 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002842 if (__cap - __sz + __n1 >= __n2)
2843 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002844 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002845 if (__n1 != __n2)
2846 {
2847 size_type __n_move = __sz - __pos - __n1;
2848 if (__n_move != 0)
2849 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2850 }
2851 }
2852 else
2853 {
2854 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002855 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002856 }
2857 traits_type::assign(__p + __pos, __n2, __c);
2858 __sz += __n2 - __n1;
2859 __set_size(__sz);
2860 __invalidate_iterators_past(__sz);
2861 traits_type::assign(__p[__sz], value_type());
2862 return *this;
2863}
2864
2865template <class _CharT, class _Traits, class _Allocator>
2866template<class _InputIterator>
2867typename enable_if
2868<
2869 __is_input_iterator<_InputIterator>::value,
2870 basic_string<_CharT, _Traits, _Allocator>&
2871>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002872basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002873 _InputIterator __j1, _InputIterator __j2)
2874{
Marshall Clowd979eed2016-09-05 01:54:30 +00002875 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002876 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002877}
2878
2879template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002880inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002881basic_string<_CharT, _Traits, _Allocator>&
2882basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2883{
2884 return replace(__pos1, __n1, __str.data(), __str.size());
2885}
2886
2887template <class _CharT, class _Traits, class _Allocator>
2888basic_string<_CharT, _Traits, _Allocator>&
2889basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2890 size_type __pos2, size_type __n2)
2891{
2892 size_type __str_sz = __str.size();
2893 if (__pos2 > __str_sz)
2894 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002895 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002896}
2897
2898template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002899template <class _Tp>
2900typename enable_if
2901<
Marshall Clowf1729d92017-11-15 20:02:27 +00002902 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2903 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002904>::type
2905basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002906 size_type __pos2, size_type __n2)
2907{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002908 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002909 size_type __str_sz = __sv.size();
2910 if (__pos2 > __str_sz)
2911 this->__throw_out_of_range();
2912 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2913}
2914
2915template <class _CharT, class _Traits, class _Allocator>
2916basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002917basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002918{
Alp Tokerec34c482014-05-15 11:27:39 +00002919 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002920 return replace(__pos, __n1, __s, traits_type::length(__s));
2921}
2922
2923template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002924inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002925basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002926basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002927{
2928 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2929 __str.data(), __str.size());
2930}
2931
2932template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002933inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002934basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002935basic_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 +00002936{
2937 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2938}
2939
2940template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002941inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002942basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002943basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002944{
2945 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2946}
2947
2948template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002949inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002950basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002951basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002952{
2953 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2954}
2955
2956// erase
2957
2958template <class _CharT, class _Traits, class _Allocator>
2959basic_string<_CharT, _Traits, _Allocator>&
2960basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2961{
2962 size_type __sz = size();
2963 if (__pos > __sz)
2964 this->__throw_out_of_range();
2965 if (__n)
2966 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002967 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002968 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002969 size_type __n_move = __sz - __pos - __n;
2970 if (__n_move != 0)
2971 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2972 __sz -= __n;
2973 __set_size(__sz);
2974 __invalidate_iterators_past(__sz);
2975 traits_type::assign(__p[__sz], value_type());
2976 }
2977 return *this;
2978}
2979
2980template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002981inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002982typename basic_string<_CharT, _Traits, _Allocator>::iterator
2983basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2984{
Howard Hinnant499cea12013-08-23 17:37:05 +00002985#if _LIBCPP_DEBUG_LEVEL >= 2
2986 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2987 "string::erase(iterator) called with an iterator not"
2988 " referring to this string");
2989#endif
2990 _LIBCPP_ASSERT(__pos != end(),
2991 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002992 iterator __b = begin();
2993 size_type __r = static_cast<size_type>(__pos - __b);
2994 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002995 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002996}
2997
2998template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002999inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003000typename basic_string<_CharT, _Traits, _Allocator>::iterator
3001basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3002{
Howard Hinnant499cea12013-08-23 17:37:05 +00003003#if _LIBCPP_DEBUG_LEVEL >= 2
3004 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3005 "string::erase(iterator, iterator) called with an iterator not"
3006 " referring to this string");
3007#endif
3008 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003009 iterator __b = begin();
3010 size_type __r = static_cast<size_type>(__first - __b);
3011 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00003012 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003013}
3014
3015template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003016inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003017void
3018basic_string<_CharT, _Traits, _Allocator>::pop_back()
3019{
Howard Hinnant499cea12013-08-23 17:37:05 +00003020 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003021 size_type __sz;
3022 if (__is_long())
3023 {
3024 __sz = __get_long_size() - 1;
3025 __set_long_size(__sz);
3026 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3027 }
3028 else
3029 {
3030 __sz = __get_short_size() - 1;
3031 __set_short_size(__sz);
3032 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3033 }
3034 __invalidate_iterators_past(__sz);
3035}
3036
3037template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003038inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003039void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003040basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003041{
3042 __invalidate_all_iterators();
3043 if (__is_long())
3044 {
3045 traits_type::assign(*__get_long_pointer(), value_type());
3046 __set_long_size(0);
3047 }
3048 else
3049 {
3050 traits_type::assign(*__get_short_pointer(), value_type());
3051 __set_short_size(0);
3052 }
3053}
3054
3055template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003056inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003057void
3058basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3059{
3060 if (__is_long())
3061 {
3062 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3063 __set_long_size(__pos);
3064 }
3065 else
3066 {
3067 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3068 __set_short_size(__pos);
3069 }
3070 __invalidate_iterators_past(__pos);
3071}
3072
3073template <class _CharT, class _Traits, class _Allocator>
3074void
3075basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3076{
3077 size_type __sz = size();
3078 if (__n > __sz)
3079 append(__n - __sz, __c);
3080 else
3081 __erase_to_end(__n);
3082}
3083
3084template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003085inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003086typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003087basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003088{
Howard Hinnante32b5e22010-11-17 17:55:08 +00003089 size_type __m = __alloc_traits::max_size(__alloc());
Eric Fiselier5ccf0432017-10-17 13:16:01 +00003090#ifdef _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00003091 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003092#else
Marshall Clow09f85502013-10-31 17:23:08 +00003093 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003094#endif
3095}
3096
3097template <class _CharT, class _Traits, class _Allocator>
3098void
3099basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3100{
3101 if (__res_arg > max_size())
3102 this->__throw_length_error();
3103 size_type __cap = capacity();
3104 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003105 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003106 __res_arg = __recommend(__res_arg);
3107 if (__res_arg != __cap)
3108 {
3109 pointer __new_data, __p;
3110 bool __was_long, __now_long;
3111 if (__res_arg == __min_cap - 1)
3112 {
3113 __was_long = true;
3114 __now_long = false;
3115 __new_data = __get_short_pointer();
3116 __p = __get_long_pointer();
3117 }
3118 else
3119 {
3120 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003121 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003122 else
3123 {
3124 #ifndef _LIBCPP_NO_EXCEPTIONS
3125 try
3126 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003127 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00003128 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003129 #ifndef _LIBCPP_NO_EXCEPTIONS
3130 }
3131 catch (...)
3132 {
3133 return;
3134 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003135 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003136 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003137 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003138 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003139 }
3140 __now_long = true;
3141 __was_long = __is_long();
3142 __p = __get_pointer();
3143 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003144 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3145 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003146 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003147 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003148 if (__now_long)
3149 {
3150 __set_long_cap(__res_arg+1);
3151 __set_long_size(__sz);
3152 __set_long_pointer(__new_data);
3153 }
3154 else
3155 __set_short_size(__sz);
3156 __invalidate_all_iterators();
3157 }
3158}
3159
3160template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003161inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003162typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003163basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003164{
Howard Hinnant499cea12013-08-23 17:37:05 +00003165 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003166 return *(data() + __pos);
3167}
3168
3169template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003170inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003171typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003172basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003173{
Howard Hinnant499cea12013-08-23 17:37:05 +00003174 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003175 return *(__get_pointer() + __pos);
3176}
3177
3178template <class _CharT, class _Traits, class _Allocator>
3179typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3180basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3181{
3182 if (__n >= size())
3183 this->__throw_out_of_range();
3184 return (*this)[__n];
3185}
3186
3187template <class _CharT, class _Traits, class _Allocator>
3188typename basic_string<_CharT, _Traits, _Allocator>::reference
3189basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3190{
3191 if (__n >= size())
3192 this->__throw_out_of_range();
3193 return (*this)[__n];
3194}
3195
3196template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003197inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003198typename basic_string<_CharT, _Traits, _Allocator>::reference
3199basic_string<_CharT, _Traits, _Allocator>::front()
3200{
Howard Hinnant499cea12013-08-23 17:37:05 +00003201 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003202 return *__get_pointer();
3203}
3204
3205template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003206inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003207typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3208basic_string<_CharT, _Traits, _Allocator>::front() const
3209{
Howard Hinnant499cea12013-08-23 17:37:05 +00003210 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003211 return *data();
3212}
3213
3214template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003215inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003216typename basic_string<_CharT, _Traits, _Allocator>::reference
3217basic_string<_CharT, _Traits, _Allocator>::back()
3218{
Howard Hinnant499cea12013-08-23 17:37:05 +00003219 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003220 return *(__get_pointer() + size() - 1);
3221}
3222
3223template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003224inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003225typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3226basic_string<_CharT, _Traits, _Allocator>::back() const
3227{
Howard Hinnant499cea12013-08-23 17:37:05 +00003228 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003229 return *(data() + size() - 1);
3230}
3231
3232template <class _CharT, class _Traits, class _Allocator>
3233typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003234basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003235{
3236 size_type __sz = size();
3237 if (__pos > __sz)
3238 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003239 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003240 traits_type::copy(__s, data() + __pos, __rlen);
3241 return __rlen;
3242}
3243
3244template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003245inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003246basic_string<_CharT, _Traits, _Allocator>
3247basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3248{
3249 return basic_string(*this, __pos, __n, __alloc());
3250}
3251
3252template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003253inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003254void
3255basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00003256#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00003257 _NOEXCEPT_DEBUG
Marshall Clow7d914d12015-07-13 20:04:56 +00003258#else
Eric Fiselier47257c42016-12-28 05:53:01 +00003259 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00003260 __is_nothrow_swappable<allocator_type>::value)
3261#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003262{
Howard Hinnant499cea12013-08-23 17:37:05 +00003263#if _LIBCPP_DEBUG_LEVEL >= 2
3264 if (!__is_long())
3265 __get_db()->__invalidate_all(this);
3266 if (!__str.__is_long())
3267 __get_db()->__invalidate_all(&__str);
3268 __get_db()->swap(this, &__str);
3269#endif
Eric Fiselier47257c42016-12-28 05:53:01 +00003270 _LIBCPP_ASSERT(
3271 __alloc_traits::propagate_on_container_swap::value ||
3272 __alloc_traits::is_always_equal::value ||
3273 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnant0949eed2011-06-30 21:18:19 +00003274 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00003275 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003276}
3277
3278// find
3279
3280template <class _Traits>
3281struct _LIBCPP_HIDDEN __traits_eq
3282{
3283 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003284 _LIBCPP_INLINE_VISIBILITY
3285 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3286 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003287};
3288
3289template<class _CharT, class _Traits, class _Allocator>
3290typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003291basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003292 size_type __pos,
3293 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003294{
Alp Tokerec34c482014-05-15 11:27:39 +00003295 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003296 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003297 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003298}
3299
3300template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003301inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003302typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003303basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3304 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003305{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003306 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003307 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003308}
3309
3310template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003311template <class _Tp>
3312typename enable_if
3313<
3314 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3315 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3316>::type
3317basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
3318 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003319{
Marshall Clow64c10d02018-07-02 18:41:15 +00003320 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003321 return __str_find<value_type, size_type, traits_type, npos>
3322 (data(), size(), __sv.data(), __pos, __sv.size());
3323}
3324
3325template<class _CharT, class _Traits, class _Allocator>
3326inline _LIBCPP_INLINE_VISIBILITY
3327typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003328basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003329 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003330{
Alp Tokerec34c482014-05-15 11:27:39 +00003331 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003332 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003333 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003334}
3335
3336template<class _CharT, class _Traits, class _Allocator>
3337typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003338basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3339 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003340{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003341 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003342 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003343}
3344
3345// rfind
3346
3347template<class _CharT, class _Traits, class _Allocator>
3348typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003349basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003350 size_type __pos,
3351 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003352{
Alp Tokerec34c482014-05-15 11:27:39 +00003353 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003354 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003355 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003356}
3357
3358template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003359inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003360typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003361basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3362 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003363{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003364 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003365 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003366}
3367
3368template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003369template <class _Tp>
3370typename enable_if
3371<
3372 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3373 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3374>::type
3375basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
3376 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003377{
Marshall Clow64c10d02018-07-02 18:41:15 +00003378 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003379 return __str_rfind<value_type, size_type, traits_type, npos>
3380 (data(), size(), __sv.data(), __pos, __sv.size());
3381}
3382
3383template<class _CharT, class _Traits, class _Allocator>
3384inline _LIBCPP_INLINE_VISIBILITY
3385typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003386basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003387 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003388{
Alp Tokerec34c482014-05-15 11:27:39 +00003389 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003390 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003391 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003392}
3393
3394template<class _CharT, class _Traits, class _Allocator>
3395typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003396basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3397 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003398{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003399 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003400 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003401}
3402
3403// find_first_of
3404
3405template<class _CharT, class _Traits, class _Allocator>
3406typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003407basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003408 size_type __pos,
3409 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003410{
Alp Tokerec34c482014-05-15 11:27:39 +00003411 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003412 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003413 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003414}
3415
3416template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003417inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003418typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003419basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3420 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003421{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003422 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003423 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003424}
3425
3426template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003427template <class _Tp>
3428typename enable_if
3429<
3430 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3431 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3432>::type
3433basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
3434 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003435{
Marshall Clow64c10d02018-07-02 18:41:15 +00003436 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003437 return __str_find_first_of<value_type, size_type, traits_type, npos>
3438 (data(), size(), __sv.data(), __pos, __sv.size());
3439}
3440
3441template<class _CharT, class _Traits, class _Allocator>
3442inline _LIBCPP_INLINE_VISIBILITY
3443typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003444basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003445 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003446{
Alp Tokerec34c482014-05-15 11:27:39 +00003447 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003448 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003449 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003450}
3451
3452template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003453inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003454typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003455basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3456 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003457{
3458 return find(__c, __pos);
3459}
3460
3461// find_last_of
3462
3463template<class _CharT, class _Traits, class _Allocator>
3464typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003465basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003466 size_type __pos,
3467 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003468{
Alp Tokerec34c482014-05-15 11:27:39 +00003469 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003470 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003471 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003472}
3473
3474template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003475inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003476typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003477basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3478 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003479{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003480 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003481 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003482}
3483
3484template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003485template <class _Tp>
3486typename enable_if
3487<
3488 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3489 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3490>::type
3491basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
3492 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003493{
Marshall Clow64c10d02018-07-02 18:41:15 +00003494 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003495 return __str_find_last_of<value_type, size_type, traits_type, npos>
3496 (data(), size(), __sv.data(), __pos, __sv.size());
3497}
3498
3499template<class _CharT, class _Traits, class _Allocator>
3500inline _LIBCPP_INLINE_VISIBILITY
3501typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003502basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003503 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003504{
Alp Tokerec34c482014-05-15 11:27:39 +00003505 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003506 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003507 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003508}
3509
3510template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003511inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003512typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003513basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3514 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003515{
3516 return rfind(__c, __pos);
3517}
3518
3519// find_first_not_of
3520
3521template<class _CharT, class _Traits, class _Allocator>
3522typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003523basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003524 size_type __pos,
3525 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003526{
Alp Tokerec34c482014-05-15 11:27:39 +00003527 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003528 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003529 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003530}
3531
3532template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003533inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003534typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003535basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3536 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003537{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003538 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003539 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003540}
3541
3542template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003543template <class _Tp>
3544typename enable_if
3545<
3546 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3547 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3548>::type
3549basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
3550 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003551{
Marshall Clow64c10d02018-07-02 18:41:15 +00003552 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003553 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3554 (data(), size(), __sv.data(), __pos, __sv.size());
3555}
3556
3557template<class _CharT, class _Traits, class _Allocator>
3558inline _LIBCPP_INLINE_VISIBILITY
3559typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003560basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003561 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003562{
Alp Tokerec34c482014-05-15 11:27:39 +00003563 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003564 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003565 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003566}
3567
3568template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003569inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003570typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003571basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3572 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003573{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003574 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003575 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003576}
3577
3578// find_last_not_of
3579
3580template<class _CharT, class _Traits, class _Allocator>
3581typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003582basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003583 size_type __pos,
3584 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003585{
Alp Tokerec34c482014-05-15 11:27:39 +00003586 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003587 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003588 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003589}
3590
3591template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003592inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003593typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003594basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3595 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003596{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003597 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003598 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003599}
3600
3601template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003602template <class _Tp>
3603typename enable_if
3604<
3605 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3606 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3607>::type
3608basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
3609 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003610{
Marshall Clow64c10d02018-07-02 18:41:15 +00003611 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003612 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3613 (data(), size(), __sv.data(), __pos, __sv.size());
3614}
3615
3616template<class _CharT, class _Traits, class _Allocator>
3617inline _LIBCPP_INLINE_VISIBILITY
3618typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003619basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003620 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003621{
Alp Tokerec34c482014-05-15 11:27:39 +00003622 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003623 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003624 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003625}
3626
3627template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003628inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003629typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003630basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3631 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003632{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003633 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003634 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003635}
3636
3637// compare
3638
3639template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003640template <class _Tp>
3641typename enable_if
3642<
3643 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3644 int
3645>::type
3646basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003647{
Marshall Clow64c10d02018-07-02 18:41:15 +00003648 __self_view __sv = __t;
Howard Hinnantfa06d752011-07-24 21:45:06 +00003649 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003650 size_t __rhs_sz = __sv.size();
3651 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:06 +00003652 _VSTD::min(__lhs_sz, __rhs_sz));
3653 if (__result != 0)
3654 return __result;
3655 if (__lhs_sz < __rhs_sz)
3656 return -1;
3657 if (__lhs_sz > __rhs_sz)
3658 return 1;
3659 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003660}
3661
3662template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003663inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003664int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003665basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003666{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003667 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003668}
3669
3670template <class _CharT, class _Traits, class _Allocator>
3671int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003672basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3673 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003674 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003675 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003676{
Alp Tokerec34c482014-05-15 11:27:39 +00003677 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003678 size_type __sz = size();
3679 if (__pos1 > __sz || __n2 == npos)
3680 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003681 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3682 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003683 if (__r == 0)
3684 {
3685 if (__rlen < __n2)
3686 __r = -1;
3687 else if (__rlen > __n2)
3688 __r = 1;
3689 }
3690 return __r;
3691}
3692
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003693template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003694template <class _Tp>
3695typename enable_if
3696<
3697 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3698 int
3699>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003700basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3701 size_type __n1,
Marshall Clow64c10d02018-07-02 18:41:15 +00003702 const _Tp& __t) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003703{
Marshall Clow64c10d02018-07-02 18:41:15 +00003704 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003705 return compare(__pos1, __n1, __sv.data(), __sv.size());
3706}
3707
3708template <class _CharT, class _Traits, class _Allocator>
3709inline _LIBCPP_INLINE_VISIBILITY
3710int
3711basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3712 size_type __n1,
3713 const basic_string& __str) const
3714{
3715 return compare(__pos1, __n1, __str.data(), __str.size());
3716}
3717
3718template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00003719template <class _Tp>
3720typename enable_if
3721<
Marshall Clowf1729d92017-11-15 20:02:27 +00003722 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3723 int
Marshall Clow6ac8de02016-09-24 22:45:42 +00003724>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003725basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3726 size_type __n1,
Marshall Clow6ac8de02016-09-24 22:45:42 +00003727 const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003728 size_type __pos2,
3729 size_type __n2) const
3730{
Marshall Clow6ac8de02016-09-24 22:45:42 +00003731 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003732 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3733}
3734
3735template <class _CharT, class _Traits, class _Allocator>
3736int
3737basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3738 size_type __n1,
3739 const basic_string& __str,
3740 size_type __pos2,
3741 size_type __n2) const
3742{
3743 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3744}
3745
3746template <class _CharT, class _Traits, class _Allocator>
3747int
3748basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3749{
3750 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3751 return compare(0, npos, __s, traits_type::length(__s));
3752}
3753
3754template <class _CharT, class _Traits, class _Allocator>
3755int
3756basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3757 size_type __n1,
3758 const value_type* __s) const
3759{
3760 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3761 return compare(__pos1, __n1, __s, traits_type::length(__s));
3762}
3763
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003764// __invariants
3765
3766template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003767inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003768bool
3769basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3770{
3771 if (size() > capacity())
3772 return false;
3773 if (capacity() < __min_cap - 1)
3774 return false;
3775 if (data() == 0)
3776 return false;
3777 if (data()[size()] != value_type(0))
3778 return false;
3779 return true;
3780}
3781
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003782// __clear_and_shrink
3783
3784template<class _CharT, class _Traits, class _Allocator>
3785inline _LIBCPP_INLINE_VISIBILITY
3786void
Marshall Clowab343bb2018-05-29 17:04:37 +00003787basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003788{
3789 clear();
3790 if(__is_long())
3791 {
3792 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
3793 __set_long_cap(0);
3794 __set_short_size(0);
3795 }
3796}
3797
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003798// operator==
3799
3800template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003801inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003802bool
3803operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003804 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003805{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003806 size_t __lhs_sz = __lhs.size();
3807 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3808 __rhs.data(),
3809 __lhs_sz) == 0;
3810}
3811
3812template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003813inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003814bool
3815operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3816 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3817{
3818 size_t __lhs_sz = __lhs.size();
3819 if (__lhs_sz != __rhs.size())
3820 return false;
3821 const char* __lp = __lhs.data();
3822 const char* __rp = __rhs.data();
3823 if (__lhs.__is_long())
3824 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3825 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3826 if (*__lp != *__rp)
3827 return false;
3828 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003829}
3830
3831template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003832inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003833bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003834operator==(const _CharT* __lhs,
3835 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003836{
Eric Fiselier4f241822015-08-28 03:02:37 +00003837 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3838 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3839 size_t __lhs_len = _Traits::length(__lhs);
3840 if (__lhs_len != __rhs.size()) return false;
3841 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003842}
3843
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003844template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003845inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003846bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003847operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3848 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003849{
Eric Fiselier4f241822015-08-28 03:02:37 +00003850 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3851 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3852 size_t __rhs_len = _Traits::length(__rhs);
3853 if (__rhs_len != __lhs.size()) return false;
3854 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003855}
3856
Howard Hinnant324bb032010-08-22 00:02:43 +00003857template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003858inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003859bool
3860operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003861 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003862{
3863 return !(__lhs == __rhs);
3864}
3865
3866template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003867inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003868bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003869operator!=(const _CharT* __lhs,
3870 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003871{
3872 return !(__lhs == __rhs);
3873}
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
Howard Hinnanta6119a82011-05-29 19:57:12 +00003878operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3879 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003880{
3881 return !(__lhs == __rhs);
3882}
3883
3884// operator<
3885
3886template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003887inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003888bool
3889operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003890 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003891{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003892 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003893}
3894
3895template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003896inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003897bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003898operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3899 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003900{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003901 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003902}
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
Howard Hinnanta6119a82011-05-29 19:57:12 +00003907operator< (const _CharT* __lhs,
3908 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003909{
3910 return __rhs.compare(__lhs) > 0;
3911}
3912
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003913// operator>
3914
3915template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003916inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003917bool
3918operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003919 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003920{
3921 return __rhs < __lhs;
3922}
3923
3924template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003925inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003926bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003927operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3928 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003929{
3930 return __rhs < __lhs;
3931}
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
Howard Hinnanta6119a82011-05-29 19:57:12 +00003936operator> (const _CharT* __lhs,
3937 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003938{
3939 return __rhs < __lhs;
3940}
3941
3942// operator<=
3943
3944template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003945inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003946bool
3947operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003948 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003949{
3950 return !(__rhs < __lhs);
3951}
3952
3953template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003954inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003955bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003956operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3957 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003958{
3959 return !(__rhs < __lhs);
3960}
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
Howard Hinnanta6119a82011-05-29 19:57:12 +00003965operator<=(const _CharT* __lhs,
3966 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003967{
3968 return !(__rhs < __lhs);
3969}
3970
3971// operator>=
3972
3973template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003974inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003975bool
3976operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003977 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003978{
3979 return !(__lhs < __rhs);
3980}
3981
3982template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003983inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003984bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003985operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3986 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003987{
3988 return !(__lhs < __rhs);
3989}
3990
3991template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003992inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003993bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003994operator>=(const _CharT* __lhs,
3995 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003996{
3997 return !(__lhs < __rhs);
3998}
3999
4000// operator +
4001
4002template<class _CharT, class _Traits, class _Allocator>
4003basic_string<_CharT, _Traits, _Allocator>
4004operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4005 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4006{
4007 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4008 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4009 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4010 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4011 __r.append(__rhs.data(), __rhs_sz);
4012 return __r;
4013}
4014
4015template<class _CharT, class _Traits, class _Allocator>
4016basic_string<_CharT, _Traits, _Allocator>
4017operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4018{
4019 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4020 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4021 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4022 __r.__init(__lhs, __lhs_sz, __lhs_sz + __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+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4030{
4031 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4032 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4033 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4034 __r.append(__rhs.data(), __rhs_sz);
4035 return __r;
4036}
4037
4038template<class _CharT, class _Traits, class _Allocator>
4039basic_string<_CharT, _Traits, _Allocator>
4040operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4041{
4042 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4043 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4044 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4045 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4046 __r.append(__rhs, __rhs_sz);
4047 return __r;
4048}
4049
4050template<class _CharT, class _Traits, class _Allocator>
4051basic_string<_CharT, _Traits, _Allocator>
4052operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4053{
4054 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4055 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4056 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4057 __r.push_back(__rhs);
4058 return __r;
4059}
4060
Eric Fiselier3e928972017-04-19 00:28:44 +00004061#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004062
4063template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004064inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004065basic_string<_CharT, _Traits, _Allocator>
4066operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4067{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004068 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004069}
4070
4071template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004072inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004073basic_string<_CharT, _Traits, _Allocator>
4074operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4075{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004076 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004077}
4078
4079template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004080inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004081basic_string<_CharT, _Traits, _Allocator>
4082operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4083{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004084 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004085}
4086
4087template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004088inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004089basic_string<_CharT, _Traits, _Allocator>
4090operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4091{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004092 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004093}
4094
4095template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004096inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004097basic_string<_CharT, _Traits, _Allocator>
4098operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4099{
4100 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004101 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004102}
4103
4104template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004105inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004106basic_string<_CharT, _Traits, _Allocator>
4107operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4108{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004109 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004110}
4111
4112template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004113inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004114basic_string<_CharT, _Traits, _Allocator>
4115operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4116{
4117 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004118 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004119}
4120
Eric Fiselier3e928972017-04-19 00:28:44 +00004121#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004122
4123// swap
4124
4125template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004126inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004127void
Howard Hinnanta6119a82011-05-29 19:57:12 +00004128swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00004129 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4130 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004131{
4132 __lhs.swap(__rhs);
4133}
4134
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004135#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
4136
4137typedef basic_string<char16_t> u16string;
4138typedef basic_string<char32_t> u32string;
4139
Howard Hinnant324bb032010-08-22 00:02:43 +00004140#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004141
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004142_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4143_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4144_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4145_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4146_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004147
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004148_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4149_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4150_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004151
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004152_LIBCPP_FUNC_VIS string to_string(int __val);
4153_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4154_LIBCPP_FUNC_VIS string to_string(long __val);
4155_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4156_LIBCPP_FUNC_VIS string to_string(long long __val);
4157_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4158_LIBCPP_FUNC_VIS string to_string(float __val);
4159_LIBCPP_FUNC_VIS string to_string(double __val);
4160_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004161
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004162_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4163_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4164_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4165_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4166_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004167
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004168_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4169_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4170_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004171
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004172_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4173_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4174_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4175_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4176_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4177_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4178_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4179_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4180_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004181
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004182template<class _CharT, class _Traits, class _Allocator>
4183 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4184 basic_string<_CharT, _Traits, _Allocator>::npos;
4185
4186template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +00004187struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004188 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4189{
4190 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004191 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004192};
4193
4194template<class _CharT, class _Traits, class _Allocator>
4195size_t
4196hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004197 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004198{
Sean Huntaffd9e52011-07-29 23:31:56 +00004199 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004200}
4201
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004202template<class _CharT, class _Traits, class _Allocator>
4203basic_ostream<_CharT, _Traits>&
4204operator<<(basic_ostream<_CharT, _Traits>& __os,
4205 const basic_string<_CharT, _Traits, _Allocator>& __str);
4206
4207template<class _CharT, class _Traits, class _Allocator>
4208basic_istream<_CharT, _Traits>&
4209operator>>(basic_istream<_CharT, _Traits>& __is,
4210 basic_string<_CharT, _Traits, _Allocator>& __str);
4211
4212template<class _CharT, class _Traits, class _Allocator>
4213basic_istream<_CharT, _Traits>&
4214getline(basic_istream<_CharT, _Traits>& __is,
4215 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4216
4217template<class _CharT, class _Traits, class _Allocator>
4218inline _LIBCPP_INLINE_VISIBILITY
4219basic_istream<_CharT, _Traits>&
4220getline(basic_istream<_CharT, _Traits>& __is,
4221 basic_string<_CharT, _Traits, _Allocator>& __str);
4222
Eric Fiselier3e928972017-04-19 00:28:44 +00004223#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004224
4225template<class _CharT, class _Traits, class _Allocator>
4226inline _LIBCPP_INLINE_VISIBILITY
4227basic_istream<_CharT, _Traits>&
4228getline(basic_istream<_CharT, _Traits>&& __is,
4229 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4230
4231template<class _CharT, class _Traits, class _Allocator>
4232inline _LIBCPP_INLINE_VISIBILITY
4233basic_istream<_CharT, _Traits>&
4234getline(basic_istream<_CharT, _Traits>&& __is,
4235 basic_string<_CharT, _Traits, _Allocator>& __str);
4236
Eric Fiselier3e928972017-04-19 00:28:44 +00004237#endif // _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004238
Howard Hinnant499cea12013-08-23 17:37:05 +00004239#if _LIBCPP_DEBUG_LEVEL >= 2
4240
4241template<class _CharT, class _Traits, class _Allocator>
4242bool
4243basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4244{
4245 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4246 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4247}
4248
4249template<class _CharT, class _Traits, class _Allocator>
4250bool
4251basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4252{
4253 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4254 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4255}
4256
4257template<class _CharT, class _Traits, class _Allocator>
4258bool
4259basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4260{
4261 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4262 return this->data() <= __p && __p <= this->data() + this->size();
4263}
4264
4265template<class _CharT, class _Traits, class _Allocator>
4266bool
4267basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4268{
4269 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4270 return this->data() <= __p && __p < this->data() + this->size();
4271}
4272
4273#endif // _LIBCPP_DEBUG_LEVEL >= 2
4274
Shoaib Meenai68506702017-06-29 02:52:46 +00004275_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
4276_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Shoaib Meenai68506702017-06-29 02:52:46 +00004277
Marshall Clow15234322013-07-23 17:05:24 +00004278#if _LIBCPP_STD_VER > 11
4279// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004280inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004281{
4282 inline namespace string_literals
4283 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004284 inline _LIBCPP_INLINE_VISIBILITY
4285 basic_string<char> operator "" s( const char *__str, size_t __len )
4286 {
4287 return basic_string<char> (__str, __len);
4288 }
Marshall Clow15234322013-07-23 17:05:24 +00004289
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004290 inline _LIBCPP_INLINE_VISIBILITY
4291 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4292 {
4293 return basic_string<wchar_t> (__str, __len);
4294 }
Marshall Clow15234322013-07-23 17:05:24 +00004295
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004296 inline _LIBCPP_INLINE_VISIBILITY
4297 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4298 {
4299 return basic_string<char16_t> (__str, __len);
4300 }
Marshall Clow15234322013-07-23 17:05:24 +00004301
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004302 inline _LIBCPP_INLINE_VISIBILITY
4303 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4304 {
4305 return basic_string<char32_t> (__str, __len);
4306 }
Marshall Clow15234322013-07-23 17:05:24 +00004307 }
4308}
4309#endif
4310
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004311_LIBCPP_END_NAMESPACE_STD
4312
Eric Fiselier018a3d52017-05-31 22:07:49 +00004313_LIBCPP_POP_MACROS
4314
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004315#endif // _LIBCPP_STRING