blob: 31ad307e57b48896bca1b5045bbf3bb034c32c9f [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- string -----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_STRING
12#define _LIBCPP_STRING
13
14/*
15 string synopsis
16
17namespace std
18{
19
20template <class stateT>
21class fpos
22{
23private:
24 stateT st;
25public:
26 fpos(streamoff = streamoff());
27
28 operator streamoff() const;
29
30 stateT state() const;
31 void state(stateT);
32
33 fpos& operator+=(streamoff);
34 fpos operator+ (streamoff) const;
35 fpos& operator-=(streamoff);
36 fpos operator- (streamoff) const;
37};
38
39template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
40
41template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
42template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
43
44template <class charT>
45struct char_traits
46{
47 typedef charT char_type;
48 typedef ... int_type;
49 typedef streamoff off_type;
50 typedef streampos pos_type;
51 typedef mbstate_t state_type;
52
Howard Hinnanta6119a82011-05-29 19:57:12 +000053 static void assign(char_type& c1, const char_type& c2) noexcept;
Howard Hinnant03d71812012-07-20 19:09:12 +000054 static constexpr bool eq(char_type c1, char_type c2) noexcept;
55 static constexpr bool lt(char_type c1, char_type c2) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056
57 static int compare(const char_type* s1, const char_type* s2, size_t n);
58 static size_t length(const char_type* s);
59 static const char_type* find(const char_type* s, size_t n, const char_type& a);
60 static char_type* move(char_type* s1, const char_type* s2, size_t n);
61 static char_type* copy(char_type* s1, const char_type* s2, size_t n);
62 static char_type* assign(char_type* s, size_t n, char_type a);
63
Howard Hinnant03d71812012-07-20 19:09:12 +000064 static constexpr int_type not_eof(int_type c) noexcept;
65 static constexpr char_type to_char_type(int_type c) noexcept;
66 static constexpr int_type to_int_type(char_type c) noexcept;
67 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
68 static constexpr int_type eof() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000069};
70
71template <> struct char_traits<char>;
72template <> struct char_traits<wchar_t>;
73
Howard Hinnant324bb032010-08-22 00:02:43 +000074template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000075class basic_string
76{
Howard Hinnant324bb032010-08-22 00:02:43 +000077public:
78// types:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000079 typedef traits traits_type;
80 typedef typename traits_type::char_type value_type;
81 typedef Allocator allocator_type;
82 typedef typename allocator_type::size_type size_type;
83 typedef typename allocator_type::difference_type difference_type;
84 typedef typename allocator_type::reference reference;
85 typedef typename allocator_type::const_reference const_reference;
86 typedef typename allocator_type::pointer pointer;
87 typedef typename allocator_type::const_pointer const_pointer;
88 typedef implementation-defined iterator;
89 typedef implementation-defined const_iterator;
90 typedef std::reverse_iterator<iterator> reverse_iterator;
91 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
92
93 static const size_type npos = -1;
94
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000095 basic_string()
96 noexcept(is_nothrow_default_constructible<allocator_type>::value);
97 explicit basic_string(const allocator_type& a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000098 basic_string(const basic_string& str);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000099 basic_string(basic_string&& str)
100 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000101 basic_string(const basic_string& str, size_type pos,
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000102 const allocator_type& a = allocator_type());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000103 basic_string(const basic_string& str, size_type pos, size_type n,
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000104 const Allocator& a = Allocator());
Marshall Clowdb7fa112016-11-14 18:22:19 +0000105 template<class T>
106 basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
Marshall Clow64c10d02018-07-02 18:41:15 +0000107 template <class T>
108 explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000109 basic_string(const value_type* s, const allocator_type& a = allocator_type());
110 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000111 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
112 template<class InputIterator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000113 basic_string(InputIterator begin, InputIterator end,
114 const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000115 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
116 basic_string(const basic_string&, const Allocator&);
117 basic_string(basic_string&&, const Allocator&);
118
119 ~basic_string();
120
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000121 operator basic_string_view<charT, traits>() const noexcept;
122
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000123 basic_string& operator=(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000124 template <class T>
125 basic_string& operator=(const T& t); // C++17
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000126 basic_string& operator=(basic_string&& str)
127 noexcept(
Marshall Clowaf961ed2015-08-18 18:57:00 +0000128 allocator_type::propagate_on_container_move_assignment::value ||
129 allocator_type::is_always_equal::value ); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000130 basic_string& operator=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000131 basic_string& operator=(value_type c);
132 basic_string& operator=(initializer_list<value_type>);
133
Howard Hinnanta6119a82011-05-29 19:57:12 +0000134 iterator begin() noexcept;
135 const_iterator begin() const noexcept;
136 iterator end() noexcept;
137 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000138
Howard Hinnanta6119a82011-05-29 19:57:12 +0000139 reverse_iterator rbegin() noexcept;
140 const_reverse_iterator rbegin() const noexcept;
141 reverse_iterator rend() noexcept;
142 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000143
Howard Hinnanta6119a82011-05-29 19:57:12 +0000144 const_iterator cbegin() const noexcept;
145 const_iterator cend() const noexcept;
146 const_reverse_iterator crbegin() const noexcept;
147 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000148
Howard Hinnanta6119a82011-05-29 19:57:12 +0000149 size_type size() const noexcept;
150 size_type length() const noexcept;
151 size_type max_size() const noexcept;
152 size_type capacity() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000153
154 void resize(size_type n, value_type c);
155 void resize(size_type n);
156
157 void reserve(size_type res_arg = 0);
158 void shrink_to_fit();
Howard Hinnanta6119a82011-05-29 19:57:12 +0000159 void clear() noexcept;
160 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000161
162 const_reference operator[](size_type pos) const;
163 reference operator[](size_type pos);
164
165 const_reference at(size_type n) const;
166 reference at(size_type n);
167
168 basic_string& operator+=(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000169 template <class T>
170 basic_string& operator+=(const T& t); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000171 basic_string& operator+=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000172 basic_string& operator+=(value_type c);
173 basic_string& operator+=(initializer_list<value_type>);
174
175 basic_string& append(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000176 template <class T>
177 basic_string& append(const T& t); // C++17
Marshall Clowa93b5e22014-03-04 19:17:19 +0000178 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000179 template <class T>
180 basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000181 basic_string& append(const value_type* s, size_type n);
182 basic_string& append(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000183 basic_string& append(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000184 template<class InputIterator>
185 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000186 basic_string& append(initializer_list<value_type>);
187
188 void push_back(value_type c);
189 void pop_back();
190 reference front();
191 const_reference front() const;
192 reference back();
193 const_reference back() const;
194
195 basic_string& assign(const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000196 template <class T>
197 basic_string& assign(const T& t); // C++17
Howard Hinnanta6119a82011-05-29 19:57:12 +0000198 basic_string& assign(basic_string&& str);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000199 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000200 template <class T>
201 basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000202 basic_string& assign(const value_type* s, size_type n);
203 basic_string& assign(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000204 basic_string& assign(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000205 template<class InputIterator>
206 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000207 basic_string& assign(initializer_list<value_type>);
208
209 basic_string& insert(size_type pos1, const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000210 template <class T>
211 basic_string& insert(size_type pos1, const T& t);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000212 basic_string& insert(size_type pos1, const basic_string& str,
213 size_type pos2, size_type n);
Marshall Clow6ac8de02016-09-24 22:45:42 +0000214 template <class T>
215 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
Marshall Clowa93b5e22014-03-04 19:17:19 +0000216 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000217 basic_string& insert(size_type pos, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000218 basic_string& insert(size_type pos, size_type n, value_type c);
219 iterator insert(const_iterator p, value_type c);
220 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000221 template<class InputIterator>
222 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000223 iterator insert(const_iterator p, initializer_list<value_type>);
224
225 basic_string& erase(size_type pos = 0, size_type n = npos);
226 iterator erase(const_iterator position);
227 iterator erase(const_iterator first, const_iterator last);
228
229 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000230 template <class T>
231 basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000232 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000233 size_type pos2, size_type n2=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000234 template <class T>
235 basic_string& replace(size_type pos1, size_type n1, const T& t,
236 size_type pos2, size_type n); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000237 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
238 basic_string& replace(size_type pos, size_type n1, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000239 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000240 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000241 template <class T>
242 basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000243 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
244 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000245 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000246 template<class InputIterator>
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000247 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
248 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000249
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000250 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000251 basic_string substr(size_type pos = 0, size_type n = npos) const;
252
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000253 void swap(basic_string& str)
Marshall Clow7d914d12015-07-13 20:04:56 +0000254 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
255 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000257 const value_type* c_str() const noexcept;
258 const value_type* data() const noexcept;
Marshall Clowf532a702016-03-08 15:44:30 +0000259 value_type* data() noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000260
Howard Hinnanta6119a82011-05-29 19:57:12 +0000261 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000262
Howard Hinnanta6119a82011-05-29 19:57:12 +0000263 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000264 template <class T>
265 size_type find(const T& t, size_type pos = 0) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000266 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
267 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000268 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000269
Howard Hinnanta6119a82011-05-29 19:57:12 +0000270 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000271 template <class T>
272 size_type rfind(const T& t, size_type pos = npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000273 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
274 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000275 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276
Howard Hinnanta6119a82011-05-29 19:57:12 +0000277 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000278 template <class T>
279 size_type find_first_of(const T& t, size_type pos = 0) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000280 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
281 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000282 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000283
Howard Hinnanta6119a82011-05-29 19:57:12 +0000284 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000285 template <class T>
286 size_type find_last_of(const T& t, size_type pos = npos) const noexcept; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000287 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
288 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000289 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290
Howard Hinnanta6119a82011-05-29 19:57:12 +0000291 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000292 template <class T>
293 size_type find_first_not_of(const T& t, size_type pos = 0) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000294 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
295 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000296 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000297
Howard Hinnanta6119a82011-05-29 19:57:12 +0000298 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000299 template <class T>
300 size_type find_last_not_of(const T& t, size_type pos = npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000301 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
302 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000303 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000304
Howard Hinnanta6119a82011-05-29 19:57:12 +0000305 int compare(const basic_string& str) const noexcept;
Marshall Clow64c10d02018-07-02 18:41:15 +0000306 template <class T>
307 int compare(const T& t) const noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000308 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Marshall Clow64c10d02018-07-02 18:41:15 +0000309 template <class T>
310 int compare(size_type pos1, size_type n1, const T& t) const; // C++17
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000311 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000312 size_type pos2, size_type n2=npos) const; // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000313 template <class T>
314 int compare(size_type pos1, size_type n1, const T& t,
315 size_type pos2, size_type n2=npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000316 int compare(const value_type* s) const noexcept;
317 int compare(size_type pos1, size_type n1, const value_type* s) const;
318 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000319
Marshall Clow46b4ad52017-12-04 20:11:38 +0000320 bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
321 bool starts_with(charT c) const noexcept; // C++2a
322 bool starts_with(const charT* s) const; // C++2a
323 bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
324 bool ends_with(charT c) const noexcept; // C++2a
325 bool ends_with(const charT* s) const; // C++2a
326
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327 bool __invariants() const;
328};
329
Marshall Clow5b1e87e2018-02-08 06:34:03 +0000330template<class InputIterator,
331 class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
332basic_string(InputIterator, InputIterator, Allocator = Allocator())
333 -> basic_string<typename iterator_traits<InputIterator>::value_type,
334 char_traits<typename iterator_traits<InputIterator>::value_type>,
335 Allocator>; // C++17
336
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000337template<class charT, class traits, class Allocator>
338basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000339operator+(const basic_string<charT, traits, Allocator>& lhs,
340 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341
342template<class charT, class traits, class Allocator>
343basic_string<charT, traits, Allocator>
344operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
345
346template<class charT, class traits, class Allocator>
347basic_string<charT, traits, Allocator>
348operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
349
350template<class charT, class traits, class Allocator>
351basic_string<charT, traits, Allocator>
352operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
353
354template<class charT, class traits, class Allocator>
355basic_string<charT, traits, Allocator>
356operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
357
358template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000359bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000360 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361
362template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000363bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000364
365template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000366bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367
Howard Hinnant324bb032010-08-22 00:02:43 +0000368template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000369bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000370 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371
372template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000373bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374
375template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000376bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377
378template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000379bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000380 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381
382template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000383bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384
385template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000386bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000387
388template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000389bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000390 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000391
392template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000393bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394
395template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000396bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397
398template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000399bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000400 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000401
402template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000403bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404
405template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000406bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000407
408template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000409bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000410 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000411
412template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000413bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000414
415template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000416bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000417
418template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000419void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000420 basic_string<charT, traits, Allocator>& rhs)
421 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422
423template<class charT, class traits, class Allocator>
424basic_istream<charT, traits>&
425operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
426
427template<class charT, class traits, class Allocator>
428basic_ostream<charT, traits>&
429operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
430
431template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000432basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000433getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
434 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435
436template<class charT, class traits, class Allocator>
437basic_istream<charT, traits>&
438getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
439
440typedef basic_string<char> string;
441typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000442typedef basic_string<char16_t> u16string;
443typedef basic_string<char32_t> u32string;
444
445int stoi (const string& str, size_t* idx = 0, int base = 10);
446long stol (const string& str, size_t* idx = 0, int base = 10);
447unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
448long long stoll (const string& str, size_t* idx = 0, int base = 10);
449unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
450
451float stof (const string& str, size_t* idx = 0);
452double stod (const string& str, size_t* idx = 0);
453long double stold(const string& str, size_t* idx = 0);
454
455string to_string(int val);
456string to_string(unsigned val);
457string to_string(long val);
458string to_string(unsigned long val);
459string to_string(long long val);
460string to_string(unsigned long long val);
461string to_string(float val);
462string to_string(double val);
463string to_string(long double val);
464
465int stoi (const wstring& str, size_t* idx = 0, int base = 10);
466long stol (const wstring& str, size_t* idx = 0, int base = 10);
467unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
468long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
469unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
470
471float stof (const wstring& str, size_t* idx = 0);
472double stod (const wstring& str, size_t* idx = 0);
473long double stold(const wstring& str, size_t* idx = 0);
474
475wstring to_wstring(int val);
476wstring to_wstring(unsigned val);
477wstring to_wstring(long val);
478wstring to_wstring(unsigned long val);
479wstring to_wstring(long long val);
480wstring to_wstring(unsigned long long val);
481wstring to_wstring(float val);
482wstring to_wstring(double val);
483wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000484
485template <> struct hash<string>;
486template <> struct hash<u16string>;
487template <> struct hash<u32string>;
488template <> struct hash<wstring>;
489
Marshall Clow15234322013-07-23 17:05:24 +0000490basic_string<char> operator "" s( const char *str, size_t len ); // C++14
491basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
492basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
493basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
494
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495} // std
496
497*/
498
499#include <__config>
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000500#include <string_view>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501#include <iosfwd>
502#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000503#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504#include <cwchar>
505#include <algorithm>
506#include <iterator>
507#include <utility>
508#include <memory>
509#include <stdexcept>
510#include <type_traits>
511#include <initializer_list>
512#include <__functional_base>
Marshall Clowe3973fd2018-09-12 19:41:40 +0000513#include <version>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000514#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
515#include <cstdint>
516#endif
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000517
Eric Fiselierb9536102014-08-10 23:53:08 +0000518#include <__debug>
519
Howard Hinnant08e17472011-10-17 20:05:10 +0000520#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000522#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523
Eric Fiselier018a3d52017-05-31 22:07:49 +0000524_LIBCPP_PUSH_MACROS
525#include <__undef_macros>
526
527
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528_LIBCPP_BEGIN_NAMESPACE_STD
529
530// fpos
531
532template <class _StateT>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000533class _LIBCPP_TEMPLATE_VIS fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534{
535private:
536 _StateT __st_;
537 streamoff __off_;
538public:
539 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
540
541 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
542
543 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
544 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
545
546 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
547 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
548 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
549 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
550};
551
552template <class _StateT>
553inline _LIBCPP_INLINE_VISIBILITY
554streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
555 {return streamoff(__x) - streamoff(__y);}
556
557template <class _StateT>
558inline _LIBCPP_INLINE_VISIBILITY
559bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
560 {return streamoff(__x) == streamoff(__y);}
561
562template <class _StateT>
563inline _LIBCPP_INLINE_VISIBILITY
564bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
565 {return streamoff(__x) != streamoff(__y);}
566
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000567// basic_string
568
569template<class _CharT, class _Traits, class _Allocator>
570basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000571operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
572 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000573
574template<class _CharT, class _Traits, class _Allocator>
575basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000576operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000577
578template<class _CharT, class _Traits, class _Allocator>
579basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000580operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581
582template<class _CharT, class _Traits, class _Allocator>
Louis Dionnece2232f2018-11-21 17:31:55 +0000583inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000584basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000585operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000586
587template<class _CharT, class _Traits, class _Allocator>
588basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000589operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000590
Shoaib Meenai487562f2017-07-29 02:54:41 +0000591_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
592
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593template <bool>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000594class _LIBCPP_TEMPLATE_VIS __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595{
596protected:
Marshall Clow14c09a22016-08-25 15:09:01 +0000597 _LIBCPP_NORETURN void __throw_length_error() const;
598 _LIBCPP_NORETURN void __throw_out_of_range() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000599};
600
601template <bool __b>
602void
603__basic_string_common<__b>::__throw_length_error() const
604{
Marshall Clow14c09a22016-08-25 15:09:01 +0000605 _VSTD::__throw_length_error("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606}
607
608template <bool __b>
609void
610__basic_string_common<__b>::__throw_out_of_range() const
611{
Marshall Clow14c09a22016-08-25 15:09:01 +0000612 _VSTD::__throw_out_of_range("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000613}
614
Eric Fiselier833d6442016-09-15 22:27:07 +0000615_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000616
Marshall Clowdf9db312016-01-13 21:54:34 +0000617#ifdef _LIBCPP_NO_EXCEPTIONS
618template <class _Iter>
619struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
620#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
621template <class _Iter>
622struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
623#else
624template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
625struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
626 noexcept(++(declval<_Iter&>())) &&
627 is_nothrow_assignable<_Iter&, _Iter>::value &&
628 noexcept(declval<_Iter>() == declval<_Iter>()) &&
629 noexcept(*declval<_Iter>())
630)) {};
631
632template <class _Iter>
633struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
634#endif
635
636
637template <class _Iter>
638struct __libcpp_string_gets_noexcept_iterator
639 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
640
Marshall Clow6ac8de02016-09-24 22:45:42 +0000641template <class _CharT, class _Traits, class _Tp>
642struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
Marshall Clowf1729d92017-11-15 20:02:27 +0000643 ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
Marshall Clow6ac8de02016-09-24 22:45:42 +0000644 !is_convertible<const _Tp&, const _CharT*>::value)) {};
645
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000646#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000647
648template <class _CharT, size_t = sizeof(_CharT)>
649struct __padding
650{
651 unsigned char __xx[sizeof(_CharT)-1];
652};
653
654template <class _CharT>
655struct __padding<_CharT, 1>
656{
657};
658
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000659#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000660
Howard Hinnant324bb032010-08-22 00:02:43 +0000661template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000662class _LIBCPP_TEMPLATE_VIS basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000663 : private __basic_string_common<true>
664{
665public:
666 typedef basic_string __self;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000667 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668 typedef _Traits traits_type;
Marshall Clow2d4c3fa2017-03-15 18:41:11 +0000669 typedef _CharT value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000671 typedef allocator_traits<allocator_type> __alloc_traits;
672 typedef typename __alloc_traits::size_type size_type;
673 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000674 typedef value_type& reference;
675 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000676 typedef typename __alloc_traits::pointer pointer;
677 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000678
Marshall Clow256f1872018-03-21 00:36:05 +0000679 static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
680 static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
681 static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
682 static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
Howard Hinnant499cea12013-08-23 17:37:05 +0000683 "traits_type::char_type must be the same type as CharT");
Marshall Clow256f1872018-03-21 00:36:05 +0000684 static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
Howard Hinnant499cea12013-08-23 17:37:05 +0000685 "Allocator::value_type must be same type as value_type");
Marshall Clow64c10d02018-07-02 18:41:15 +0000686
Howard Hinnant499cea12013-08-23 17:37:05 +0000687#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000688 typedef pointer iterator;
689 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000690#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000691 typedef __wrap_iter<pointer> iterator;
692 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000693#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000694 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
695 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000696
697private:
Howard Hinnant15467182013-04-30 21:44:48 +0000698
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000699#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000700
701 struct __long
702 {
703 pointer __data_;
704 size_type __size_;
705 size_type __cap_;
706 };
707
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000708#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000709 static const size_type __short_mask = 0x01;
710 static const size_type __long_mask = 0x1ul;
Howard Hinnant15467182013-04-30 21:44:48 +0000711#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000712 static const size_type __short_mask = 0x80;
713 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant15467182013-04-30 21:44:48 +0000714#endif // _LIBCPP_BIG_ENDIAN
715
716 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
717 (sizeof(__long) - 1)/sizeof(value_type) : 2};
718
719 struct __short
720 {
721 value_type __data_[__min_cap];
722 struct
723 : __padding<value_type>
724 {
725 unsigned char __size_;
726 };
727 };
728
729#else
730
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000731 struct __long
732 {
733 size_type __cap_;
734 size_type __size_;
735 pointer __data_;
736 };
737
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000738#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000739 static const size_type __short_mask = 0x80;
740 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant324bb032010-08-22 00:02:43 +0000741#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000742 static const size_type __short_mask = 0x01;
743 static const size_type __long_mask = 0x1ul;
Howard Hinnant324bb032010-08-22 00:02:43 +0000744#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000746 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
747 (sizeof(__long) - 1)/sizeof(value_type) : 2};
748
749 struct __short
750 {
751 union
752 {
753 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +0000754 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000755 };
756 value_type __data_[__min_cap];
757 };
758
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000759#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000760
Howard Hinnant499cea12013-08-23 17:37:05 +0000761 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000762
Howard Hinnant499cea12013-08-23 17:37:05 +0000763 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000764
765 struct __raw
766 {
767 size_type __words[__n_words];
768 };
769
770 struct __rep
771 {
772 union
773 {
774 __long __l;
775 __short __s;
776 __raw __r;
777 };
778 };
779
780 __compressed_pair<__rep, allocator_type> __r_;
781
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000782public:
783 static const size_type npos = -1;
784
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000785 _LIBCPP_INLINE_VISIBILITY basic_string()
786 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000787
788 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
789#if _LIBCPP_STD_VER <= 14
790 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
791#else
792 _NOEXCEPT;
793#endif
794
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000795 basic_string(const basic_string& __str);
796 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +0000797
Eric Fiselier3e928972017-04-19 00:28:44 +0000798#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant9f193f22011-01-26 00:06:59 +0000799 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000800 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +0000801#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000802 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000803#else
804 _NOEXCEPT;
805#endif
806
Howard Hinnant9f193f22011-01-26 00:06:59 +0000807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000808 basic_string(basic_string&& __str, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000809#endif // _LIBCPP_CXX03_LANG
Marshall Clow64c10d02018-07-02 18:41:15 +0000810
Marshall Clow7e3ab172018-10-16 16:02:18 +0000811#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +0000812 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
Marshall Clow7e3ab172018-10-16 16:02:18 +0000813#endif
Eric Fiselierffbb91b2018-07-17 05:48:48 +0000814 _LIBCPP_INLINE_VISIBILITY
815 basic_string(const _CharT* __s) {
816 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
817 __init(__s, traits_type::length(__s));
818# if _LIBCPP_DEBUG_LEVEL >= 2
819 __get_db()->__insert_c(this);
820# endif
821 }
Marshall Clow64c10d02018-07-02 18:41:15 +0000822
Marshall Clow7e3ab172018-10-16 16:02:18 +0000823#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +0000824 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
Marshall Clow7e3ab172018-10-16 16:02:18 +0000825#endif
Marshall Clow64c10d02018-07-02 18:41:15 +0000826 _LIBCPP_INLINE_VISIBILITY
827 basic_string(const _CharT* __s, const _Allocator& __a);
828
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000829 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000830 basic_string(const _CharT* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000831 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000832 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000833 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000834 basic_string(size_type __n, _CharT __c);
Marshall Clow64c10d02018-07-02 18:41:15 +0000835
Marshall Clow7e3ab172018-10-16 16:02:18 +0000836#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +0000837 template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
Marshall Clow7e3ab172018-10-16 16:02:18 +0000838#endif
Marshall Clow64c10d02018-07-02 18:41:15 +0000839 _LIBCPP_INLINE_VISIBILITY
840 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
841
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000842 basic_string(const basic_string& __str, size_type __pos, size_type __n,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000843 const _Allocator& __a = _Allocator());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000844 _LIBCPP_INLINE_VISIBILITY
845 basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000846 const _Allocator& __a = _Allocator());
Marshall Clow64c10d02018-07-02 18:41:15 +0000847
848 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +0000849 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000850 basic_string(const _Tp& __t, size_type __pos, size_type __n,
Marshall Clow64c10d02018-07-02 18:41:15 +0000851 const allocator_type& __a = allocator_type());
852
853 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
854 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
855 explicit basic_string(const _Tp& __t);
856
857 template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
858 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
859 explicit basic_string(const _Tp& __t, const allocator_type& __a);
860
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000863 basic_string(_InputIterator __first, _InputIterator __last);
864 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000867#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000868 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000869 basic_string(initializer_list<_CharT> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000870 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000871 basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000872#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873
Eric Fiselier51eb1d52016-10-31 03:42:50 +0000874 inline ~basic_string();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000876 _LIBCPP_INLINE_VISIBILITY
877 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
878
Howard Hinnante32b5e22010-11-17 17:55:08 +0000879 basic_string& operator=(const basic_string& __str);
Eric Fiselierf472d6c2017-01-23 21:24:58 +0000880
Marshall Clow64c10d02018-07-02 18:41:15 +0000881 template <class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
882 basic_string& operator=(const _Tp& __t)
883 {__self_view __sv = __t; return assign(__sv);}
884
Eric Fiselier3e928972017-04-19 00:28:44 +0000885#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000887 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +0000888 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Eric Fiselier3e928972017-04-19 00:28:44 +0000889 _LIBCPP_INLINE_VISIBILITY
890 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000891#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000892 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893 basic_string& operator=(value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000894
Howard Hinnant499cea12013-08-23 17:37:05 +0000895#if _LIBCPP_DEBUG_LEVEL >= 2
896 _LIBCPP_INLINE_VISIBILITY
897 iterator begin() _NOEXCEPT
898 {return iterator(this, __get_pointer());}
899 _LIBCPP_INLINE_VISIBILITY
900 const_iterator begin() const _NOEXCEPT
901 {return const_iterator(this, __get_pointer());}
902 _LIBCPP_INLINE_VISIBILITY
903 iterator end() _NOEXCEPT
904 {return iterator(this, __get_pointer() + size());}
905 _LIBCPP_INLINE_VISIBILITY
906 const_iterator end() const _NOEXCEPT
907 {return const_iterator(this, __get_pointer() + size());}
908#else
Howard Hinnanta6119a82011-05-29 19:57:12 +0000909 _LIBCPP_INLINE_VISIBILITY
910 iterator begin() _NOEXCEPT
911 {return iterator(__get_pointer());}
912 _LIBCPP_INLINE_VISIBILITY
913 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000914 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000915 _LIBCPP_INLINE_VISIBILITY
916 iterator end() _NOEXCEPT
917 {return iterator(__get_pointer() + size());}
918 _LIBCPP_INLINE_VISIBILITY
919 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000920 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +0000921#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +0000922 _LIBCPP_INLINE_VISIBILITY
923 reverse_iterator rbegin() _NOEXCEPT
924 {return reverse_iterator(end());}
925 _LIBCPP_INLINE_VISIBILITY
926 const_reverse_iterator rbegin() const _NOEXCEPT
927 {return const_reverse_iterator(end());}
928 _LIBCPP_INLINE_VISIBILITY
929 reverse_iterator rend() _NOEXCEPT
930 {return reverse_iterator(begin());}
931 _LIBCPP_INLINE_VISIBILITY
932 const_reverse_iterator rend() const _NOEXCEPT
933 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000934
Howard Hinnanta6119a82011-05-29 19:57:12 +0000935 _LIBCPP_INLINE_VISIBILITY
936 const_iterator cbegin() const _NOEXCEPT
937 {return begin();}
938 _LIBCPP_INLINE_VISIBILITY
939 const_iterator cend() const _NOEXCEPT
940 {return end();}
941 _LIBCPP_INLINE_VISIBILITY
942 const_reverse_iterator crbegin() const _NOEXCEPT
943 {return rbegin();}
944 _LIBCPP_INLINE_VISIBILITY
945 const_reverse_iterator crend() const _NOEXCEPT
946 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947
Howard Hinnanta6119a82011-05-29 19:57:12 +0000948 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000949 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000950 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
951 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
952 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +0000953 {return (__is_long() ? __get_long_cap()
954 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000955
956 void resize(size_type __n, value_type __c);
957 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
958
Marshall Clow7593e792018-11-28 18:18:34 +0000959 void reserve(size_type __res_arg);
Eric Fiselierf9782de2018-11-26 20:15:38 +0000960 _LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n);
961
Marshall Clow7593e792018-11-28 18:18:34 +0000962 _LIBCPP_INLINE_VISIBILITY
963 void reserve() _NOEXCEPT {reserve(0);}
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000965 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000966 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +0000967 void clear() _NOEXCEPT;
Marshall Clowf1729d92017-11-15 20:02:27 +0000968 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
969 bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000970
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000971 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
972 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973
974 const_reference at(size_type __n) const;
975 reference at(size_type __n);
976
977 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clow64c10d02018-07-02 18:41:15 +0000978
979 template <class _Tp>
980 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
981 typename enable_if
982 <
983 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
984 basic_string&
985 >::type
986 operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);}
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000987 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000988 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Eric Fiselier3e928972017-04-19 00:28:44 +0000989#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000990 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Eric Fiselier3e928972017-04-19 00:28:44 +0000991#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000992
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000993 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000994 basic_string& append(const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +0000995
996 template <class _Tp>
997 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
998 typename enable_if
999 <
1000 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1001 basic_string&
1002 >::type
1003 append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +00001004 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow64c10d02018-07-02 18:41:15 +00001005
Marshall Clow42a87db2016-10-03 23:40:48 +00001006 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001007 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1008 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001009 <
1010 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1011 basic_string&
1012 >::type
1013 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001014 basic_string& append(const value_type* __s, size_type __n);
1015 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001016 basic_string& append(size_type __n, value_type __c);
Eric Fiselierf9782de2018-11-26 20:15:38 +00001017
1018 _LIBCPP_INLINE_VISIBILITY
1019 void __append_default_init(size_type __n);
1020
Eric Fiselier026d38e2016-10-31 02:46:25 +00001021 template <class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001022 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1023 basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001024 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001025 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1026 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001027 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001028 __is_exactly_input_iterator<_InputIterator>::value
1029 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001030 basic_string&
1031 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +00001032 _LIBCPP_INLINE_VISIBILITY
1033 append(_InputIterator __first, _InputIterator __last) {
1034 const basic_string __temp (__first, __last, __alloc());
1035 append(__temp.data(), __temp.size());
1036 return *this;
1037 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001038 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001039 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1040 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001041 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001042 __is_forward_iterator<_ForwardIterator>::value
1043 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001044 basic_string&
1045 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +00001046 _LIBCPP_INLINE_VISIBILITY
1047 append(_ForwardIterator __first, _ForwardIterator __last) {
1048 return __append_forward_unsafe(__first, __last);
1049 }
1050
Eric Fiselier3e928972017-04-19 00:28:44 +00001051#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001053 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001054#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001055
1056 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001057 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001058 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001059 _LIBCPP_INLINE_VISIBILITY reference front();
1060 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1061 _LIBCPP_INLINE_VISIBILITY reference back();
1062 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001063
Marshall Clow64c10d02018-07-02 18:41:15 +00001064 template <class _Tp>
1065 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1066 typename enable_if
1067 <
1068 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1069 basic_string&
1070 >::type
1071 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001072 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29 +00001073 basic_string& assign(const basic_string& __str) { return *this = __str; }
Eric Fiselier3e928972017-04-19 00:28:44 +00001074#ifndef _LIBCPP_CXX03_LANG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001075 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001076 basic_string& assign(basic_string&& __str)
Marshall Clow7ed093b2015-10-05 16:17:34 +00001077 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001078 {*this = _VSTD::move(__str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001079#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +00001080 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48 +00001081 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001082 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1083 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001084 <
1085 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1086 basic_string&
1087 >::type
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001088 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001089 basic_string& assign(const value_type* __s, size_type __n);
1090 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001091 basic_string& assign(size_type __n, value_type __c);
1092 template<class _InputIterator>
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_exactly_input_iterator<_InputIterator>::value
1097 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001098 basic_string&
1099 >::type
1100 assign(_InputIterator __first, _InputIterator __last);
1101 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001102 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1103 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001105 __is_forward_iterator<_ForwardIterator>::value
1106 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001107 basic_string&
1108 >::type
1109 assign(_ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001110#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001111 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001112 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001113#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001114
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001116 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001117
1118 template <class _Tp>
1119 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1120 typename enable_if
1121 <
1122 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1123 basic_string&
1124 >::type
1125 insert(size_type __pos1, const _Tp& __t)
1126 { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
1127
Marshall Clow6ac8de02016-09-24 22:45:42 +00001128 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001129 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1130 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001131 <
1132 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1133 basic_string&
1134 >::type
1135 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001136 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001137 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1138 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001139 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1140 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001142 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1143 template<class _InputIterator>
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_exactly_input_iterator<_InputIterator>::value
1148 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149 iterator
1150 >::type
1151 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1152 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001153 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1154 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001156 __is_forward_iterator<_ForwardIterator>::value
1157 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001158 iterator
1159 >::type
1160 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001161#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001162 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1164 {return insert(__pos, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001165#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001166
1167 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001168 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001169 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001170 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001171 iterator erase(const_iterator __first, const_iterator __last);
1172
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001173 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001174 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001175
1176 template <class _Tp>
1177 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1178 typename enable_if
1179 <
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) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +00001184 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 +00001185 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001186 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1187 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001188 <
1189 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1190 basic_string&
1191 >::type
1192 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001193 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1194 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001195 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001196 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001197 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Marshall Clow64c10d02018-07-02 18:41:15 +00001198
1199 template <class _Tp>
1200 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1201 typename enable_if
1202 <
1203 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1204 basic_string&
1205 >::type
1206 replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
1207
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001209 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001210 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001211 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001212 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001213 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001214 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001215 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1216 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001217 <
1218 __is_input_iterator<_InputIterator>::value,
1219 basic_string&
1220 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001221 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Eric Fiselier3e928972017-04-19 00:28:44 +00001222#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001223 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001224 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001225 {return replace(__i1, __i2, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001226#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001227
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001228 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001230 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1231
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001233 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001234#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00001235 _NOEXCEPT_DEBUG;
Marshall Clow7d914d12015-07-13 20:04:56 +00001236#else
Eric Fiselier47257c42016-12-28 05:53:01 +00001237 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00001238 __is_nothrow_swappable<allocator_type>::value);
1239#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001240
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001241 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001242 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001243 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001244 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Eric Fiselier10bebe22017-11-20 20:23:27 +00001245#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
Marshall Clowf532a702016-03-08 15:44:30 +00001246 _LIBCPP_INLINE_VISIBILITY
1247 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1248#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001249
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001251 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001252
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001254 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001255
1256 template <class _Tp>
1257 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1258 typename enable_if
1259 <
1260 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1261 size_type
1262 >::type
1263 find(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001264 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001265 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001266 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001267 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001268
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001270 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001271
1272 template <class _Tp>
1273 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1274 typename enable_if
1275 <
1276 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1277 size_type
1278 >::type
1279 rfind(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001280 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001281 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001282 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001283 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001284
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001286 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001287
1288 template <class _Tp>
1289 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1290 typename enable_if
1291 <
1292 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1293 size_type
1294 >::type
1295 find_first_of(const _Tp& __t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001296 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001297 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001298 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001299 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001300 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001301
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001302 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001303 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001304
1305 template <class _Tp>
1306 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1307 typename enable_if
1308 <
1309 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1310 size_type
1311 >::type
1312 find_last_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001313 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001314 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001315 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001316 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001317 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001318
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001320 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001321
1322 template <class _Tp>
1323 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1324 typename enable_if
1325 <
1326 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1327 size_type
1328 >::type
1329 find_first_not_of(const _Tp &__t, size_type __pos = 0) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001330 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 +00001331 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001332 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001333 _LIBCPP_INLINE_VISIBILITY
1334 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1335
1336 _LIBCPP_INLINE_VISIBILITY
1337 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001338
1339 template <class _Tp>
1340 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1341 typename enable_if
1342 <
1343 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1344 size_type
1345 >::type
1346 find_last_not_of(const _Tp& __t, size_type __pos = npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001347 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 +00001348 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001349 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001350 _LIBCPP_INLINE_VISIBILITY
1351 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1352
1353 _LIBCPP_INLINE_VISIBILITY
1354 int compare(const basic_string& __str) const _NOEXCEPT;
Marshall Clow64c10d02018-07-02 18:41:15 +00001355
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(const _Tp &__t) const;
1364
1365 template <class _Tp>
1366 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1367 typename enable_if
1368 <
1369 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1370 int
1371 >::type
1372 compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
1373
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001374 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001375 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001376 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 +00001377
Marshall Clow6ac8de02016-09-24 22:45:42 +00001378 template <class _Tp>
Eric Fiselier9dbc0532016-10-14 05:29:46 +00001379 inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow6ac8de02016-09-24 22:45:42 +00001380 typename enable_if
1381 <
1382 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1383 int
1384 >::type
1385 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 +00001386 int compare(const value_type* __s) const _NOEXCEPT;
1387 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1388 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001389
Marshall Clow46b4ad52017-12-04 20:11:38 +00001390#if _LIBCPP_STD_VER > 17
1391 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1392 bool starts_with(__self_view __sv) const _NOEXCEPT
1393 { return __self_view(data(), size()).starts_with(__sv); }
1394
1395 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1396 bool starts_with(value_type __c) const _NOEXCEPT
1397 { return !empty() && _Traits::eq(front(), __c); }
1398
1399 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1400 bool starts_with(const value_type* __s) const _NOEXCEPT
1401 { return starts_with(__self_view(__s)); }
1402
1403 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1404 bool ends_with(__self_view __sv) const _NOEXCEPT
1405 { return __self_view(data(), size()).ends_with( __sv); }
1406
1407 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1408 bool ends_with(value_type __c) const _NOEXCEPT
1409 { return !empty() && _Traits::eq(back(), __c); }
1410
1411 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1412 bool ends_with(const value_type* __s) const _NOEXCEPT
1413 { return ends_with(__self_view(__s)); }
1414#endif
1415
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001416 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001417
Marshall Clowab343bb2018-05-29 17:04:37 +00001418 _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT;
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001419
Howard Hinnant08dd2532013-04-22 23:55:13 +00001420 _LIBCPP_INLINE_VISIBILITY
1421 bool __is_long() const _NOEXCEPT
1422 {return bool(__r_.first().__s.__size_ & __short_mask);}
1423
Howard Hinnant499cea12013-08-23 17:37:05 +00001424#if _LIBCPP_DEBUG_LEVEL >= 2
1425
1426 bool __dereferenceable(const const_iterator* __i) const;
1427 bool __decrementable(const const_iterator* __i) const;
1428 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1429 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1430
1431#endif // _LIBCPP_DEBUG_LEVEL >= 2
1432
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001433private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001434 _LIBCPP_INLINE_VISIBILITY
1435 allocator_type& __alloc() _NOEXCEPT
1436 {return __r_.second();}
1437 _LIBCPP_INLINE_VISIBILITY
1438 const allocator_type& __alloc() const _NOEXCEPT
1439 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001440
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001441#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001442
Howard Hinnanta6119a82011-05-29 19:57:12 +00001443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001444 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001445# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001446 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001447# else
1448 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1449# endif
1450
Howard Hinnanta6119a82011-05-29 19:57:12 +00001451 _LIBCPP_INLINE_VISIBILITY
1452 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001453# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001454 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001455# else
1456 {return __r_.first().__s.__size_;}
1457# endif
1458
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001459#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001460
1461 _LIBCPP_INLINE_VISIBILITY
1462 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001463# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001464 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1465# else
1466 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1467# endif
1468
1469 _LIBCPP_INLINE_VISIBILITY
1470 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001471# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001472 {return __r_.first().__s.__size_;}
1473# else
1474 {return __r_.first().__s.__size_ >> 1;}
1475# endif
1476
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001477#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001478
Howard Hinnanta6119a82011-05-29 19:57:12 +00001479 _LIBCPP_INLINE_VISIBILITY
1480 void __set_long_size(size_type __s) _NOEXCEPT
1481 {__r_.first().__l.__size_ = __s;}
1482 _LIBCPP_INLINE_VISIBILITY
1483 size_type __get_long_size() const _NOEXCEPT
1484 {return __r_.first().__l.__size_;}
1485 _LIBCPP_INLINE_VISIBILITY
1486 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001487 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1488
Howard Hinnanta6119a82011-05-29 19:57:12 +00001489 _LIBCPP_INLINE_VISIBILITY
1490 void __set_long_cap(size_type __s) _NOEXCEPT
1491 {__r_.first().__l.__cap_ = __long_mask | __s;}
1492 _LIBCPP_INLINE_VISIBILITY
1493 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001494 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001495
Howard Hinnanta6119a82011-05-29 19:57:12 +00001496 _LIBCPP_INLINE_VISIBILITY
1497 void __set_long_pointer(pointer __p) _NOEXCEPT
1498 {__r_.first().__l.__data_ = __p;}
1499 _LIBCPP_INLINE_VISIBILITY
1500 pointer __get_long_pointer() _NOEXCEPT
1501 {return __r_.first().__l.__data_;}
1502 _LIBCPP_INLINE_VISIBILITY
1503 const_pointer __get_long_pointer() const _NOEXCEPT
1504 {return __r_.first().__l.__data_;}
1505 _LIBCPP_INLINE_VISIBILITY
1506 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001507 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001508 _LIBCPP_INLINE_VISIBILITY
1509 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001510 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001511 _LIBCPP_INLINE_VISIBILITY
1512 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001513 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001514 _LIBCPP_INLINE_VISIBILITY
1515 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001516 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1517
Howard Hinnanta6119a82011-05-29 19:57:12 +00001518 _LIBCPP_INLINE_VISIBILITY
1519 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001520 {
1521 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1522 for (unsigned __i = 0; __i < __n_words; ++__i)
1523 __a[__i] = 0;
1524 }
1525
1526 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001528 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001529 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001530 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001531 static _LIBCPP_INLINE_VISIBILITY
1532 size_type __recommend(size_type __s) _NOEXCEPT
Marshall Clow088e6012018-02-07 21:30:17 +00001533 {
1534 if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
1535 size_type __guess = __align_it<sizeof(value_type) < __alignment ?
1536 __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
1537 if (__guess == __min_cap) ++__guess;
1538 return __guess;
1539 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001540
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001541 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001542 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001543 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001544 void __init(const value_type* __s, size_type __sz);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001545 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001546 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001547
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548 template <class _InputIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001549 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001550 typename enable_if
1551 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001552 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001553 void
1554 >::type
1555 __init(_InputIterator __first, _InputIterator __last);
1556
1557 template <class _ForwardIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001558 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001559 typename enable_if
1560 <
1561 __is_forward_iterator<_ForwardIterator>::value,
1562 void
1563 >::type
1564 __init(_ForwardIterator __first, _ForwardIterator __last);
1565
1566 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001567 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001568 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1569 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001570 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001571
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001573 void __erase_to_end(size_type __pos);
1574
Howard Hinnante32b5e22010-11-17 17:55:08 +00001575 _LIBCPP_INLINE_VISIBILITY
1576 void __copy_assign_alloc(const basic_string& __str)
1577 {__copy_assign_alloc(__str, integral_constant<bool,
1578 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1579
1580 _LIBCPP_INLINE_VISIBILITY
1581 void __copy_assign_alloc(const basic_string& __str, true_type)
1582 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001583 if (__alloc() == __str.__alloc())
1584 __alloc() = __str.__alloc();
1585 else
Howard Hinnante32b5e22010-11-17 17:55:08 +00001586 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001587 if (!__str.__is_long())
1588 {
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001589 __clear_and_shrink();
Marshall Clow9247fd22017-01-31 03:40:52 +00001590 __alloc() = __str.__alloc();
1591 }
1592 else
1593 {
1594 allocator_type __a = __str.__alloc();
1595 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
Vedant Kumar2b588cb2018-03-08 21:15:26 +00001596 __clear_and_shrink();
Marshall Clow9247fd22017-01-31 03:40:52 +00001597 __alloc() = _VSTD::move(__a);
1598 __set_long_pointer(__p);
1599 __set_long_cap(__str.__get_long_cap());
1600 __set_long_size(__str.size());
1601 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001602 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001603 }
1604
1605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001606 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001607 {}
1608
Eric Fiselier3e928972017-04-19 00:28:44 +00001609#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001610 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001611 void __move_assign(basic_string& __str, false_type)
1612 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001614 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001615#if _LIBCPP_STD_VER > 14
1616 _NOEXCEPT;
1617#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001618 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001619#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001620#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001621
1622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001623 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001624 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001625 _NOEXCEPT_(
1626 !__alloc_traits::propagate_on_container_move_assignment::value ||
1627 is_nothrow_move_assignable<allocator_type>::value)
1628 {__move_assign_alloc(__str, integral_constant<bool,
1629 __alloc_traits::propagate_on_container_move_assignment::value>());}
1630
1631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001632 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001633 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1634 {
1635 __alloc() = _VSTD::move(__c.__alloc());
1636 }
1637
1638 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001639 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001640 _NOEXCEPT
1641 {}
1642
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001643 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1644 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001645
1646 friend basic_string operator+<>(const basic_string&, const basic_string&);
1647 friend basic_string operator+<>(const value_type*, const basic_string&);
1648 friend basic_string operator+<>(value_type, const basic_string&);
1649 friend basic_string operator+<>(const basic_string&, const value_type*);
1650 friend basic_string operator+<>(const basic_string&, value_type);
1651};
1652
Marshall Clow5b1e87e2018-02-08 06:34:03 +00001653#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1654template<class _InputIterator,
1655 class _CharT = typename iterator_traits<_InputIterator>::value_type,
1656 class _Allocator = allocator<_CharT>,
1657 class = typename enable_if<__is_input_iterator<_InputIterator>::value, void>::type,
1658 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1659 >
1660basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
1661 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
Marshall Clow64c10d02018-07-02 18:41:15 +00001662
1663template<class _CharT,
1664 class _Traits,
1665 class _Allocator = allocator<_CharT>,
1666 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1667 >
1668explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
1669 -> basic_string<_CharT, _Traits, _Allocator>;
1670
1671template<class _CharT,
1672 class _Traits,
1673 class _Allocator = allocator<_CharT>,
1674 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type,
1675 class _Sz = typename allocator_traits<_Allocator>::size_type
1676 >
1677basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
1678 -> basic_string<_CharT, _Traits, _Allocator>;
Marshall Clow5b1e87e2018-02-08 06:34:03 +00001679#endif
1680
1681
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001682template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001683inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001684void
1685basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1686{
Howard Hinnant499cea12013-08-23 17:37:05 +00001687#if _LIBCPP_DEBUG_LEVEL >= 2
1688 __get_db()->__invalidate_all(this);
1689#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001690}
1691
1692template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001693inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001694void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001695basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001696#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001697 __pos
1698#endif
1699 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001700{
Howard Hinnant499cea12013-08-23 17:37:05 +00001701#if _LIBCPP_DEBUG_LEVEL >= 2
1702 __c_node* __c = __get_db()->__find_c_and_lock(this);
1703 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001704 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001705 const_pointer __new_last = __get_pointer() + __pos;
1706 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001707 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001708 --__p;
1709 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1710 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001711 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001712 (*__p)->__c_ = nullptr;
1713 if (--__c->end_ != __p)
1714 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001715 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001716 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001717 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001718 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001719#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001720}
1721
1722template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001723inline
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001724basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001725 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001726{
Howard Hinnant499cea12013-08-23 17:37:05 +00001727#if _LIBCPP_DEBUG_LEVEL >= 2
1728 __get_db()->__insert_c(this);
1729#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001730 __zero();
1731}
1732
1733template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001734inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001735basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001736#if _LIBCPP_STD_VER <= 14
1737 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1738#else
1739 _NOEXCEPT
1740#endif
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001741: __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742{
Howard Hinnant499cea12013-08-23 17:37:05 +00001743#if _LIBCPP_DEBUG_LEVEL >= 2
1744 __get_db()->__insert_c(this);
1745#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001746 __zero();
1747}
1748
1749template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001750void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1751 size_type __sz,
1752 size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001753{
1754 if (__reserve > max_size())
1755 this->__throw_length_error();
1756 pointer __p;
1757 if (__reserve < __min_cap)
1758 {
1759 __set_short_size(__sz);
1760 __p = __get_short_pointer();
1761 }
1762 else
1763 {
1764 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001765 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001766 __set_long_pointer(__p);
1767 __set_long_cap(__cap+1);
1768 __set_long_size(__sz);
1769 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001770 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001771 traits_type::assign(__p[__sz], value_type());
1772}
1773
1774template <class _CharT, class _Traits, class _Allocator>
1775void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001776basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001777{
1778 if (__sz > max_size())
1779 this->__throw_length_error();
1780 pointer __p;
1781 if (__sz < __min_cap)
1782 {
1783 __set_short_size(__sz);
1784 __p = __get_short_pointer();
1785 }
1786 else
1787 {
1788 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001789 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001790 __set_long_pointer(__p);
1791 __set_long_cap(__cap+1);
1792 __set_long_size(__sz);
1793 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001794 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001795 traits_type::assign(__p[__sz], value_type());
1796}
1797
1798template <class _CharT, class _Traits, class _Allocator>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001799#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +00001800template <class>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001801#endif
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001802basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001803 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001804{
Howard Hinnant499cea12013-08-23 17:37:05 +00001805 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001806 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001807#if _LIBCPP_DEBUG_LEVEL >= 2
1808 __get_db()->__insert_c(this);
1809#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001810}
1811
1812template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001813inline
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001814basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001815{
Howard Hinnant499cea12013-08-23 17:37:05 +00001816 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001817 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001818#if _LIBCPP_DEBUG_LEVEL >= 2
1819 __get_db()->__insert_c(this);
1820#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001821}
1822
1823template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001824inline
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001825basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001826 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001827{
Howard Hinnant499cea12013-08-23 17:37:05 +00001828 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001829 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001830#if _LIBCPP_DEBUG_LEVEL >= 2
1831 __get_db()->__insert_c(this);
1832#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001833}
1834
1835template <class _CharT, class _Traits, class _Allocator>
1836basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001837 : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001838{
1839 if (!__str.__is_long())
1840 __r_.first().__r = __str.__r_.first().__r;
1841 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001842 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001843#if _LIBCPP_DEBUG_LEVEL >= 2
1844 __get_db()->__insert_c(this);
1845#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001846}
1847
1848template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001849basic_string<_CharT, _Traits, _Allocator>::basic_string(
1850 const basic_string& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001851 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001852{
1853 if (!__str.__is_long())
1854 __r_.first().__r = __str.__r_.first().__r;
1855 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001856 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001857#if _LIBCPP_DEBUG_LEVEL >= 2
1858 __get_db()->__insert_c(this);
1859#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001860}
1861
Eric Fiselier3e928972017-04-19 00:28:44 +00001862#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001863
1864template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001865inline
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001866basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001867#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001868 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00001869#else
1870 _NOEXCEPT
1871#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001872 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001873{
1874 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00001875#if _LIBCPP_DEBUG_LEVEL >= 2
1876 __get_db()->__insert_c(this);
1877 if (__is_long())
1878 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001879#endif
1880}
1881
1882template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001883inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001884basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001885 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001886{
Marshall Clowd5549cc2014-07-17 15:32:20 +00001887 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001888 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00001889 else
1890 {
1891 __r_.first().__r = __str.__r_.first().__r;
1892 __str.__zero();
1893 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001894#if _LIBCPP_DEBUG_LEVEL >= 2
1895 __get_db()->__insert_c(this);
1896 if (__is_long())
1897 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001898#endif
1899}
1900
Eric Fiselier3e928972017-04-19 00:28:44 +00001901#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001902
1903template <class _CharT, class _Traits, class _Allocator>
1904void
1905basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1906{
1907 if (__n > max_size())
1908 this->__throw_length_error();
1909 pointer __p;
1910 if (__n < __min_cap)
1911 {
1912 __set_short_size(__n);
1913 __p = __get_short_pointer();
1914 }
1915 else
1916 {
1917 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001918 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001919 __set_long_pointer(__p);
1920 __set_long_cap(__cap+1);
1921 __set_long_size(__n);
1922 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001923 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001924 traits_type::assign(__p[__n], value_type());
1925}
1926
1927template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001928inline
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001929basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001930{
1931 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001932#if _LIBCPP_DEBUG_LEVEL >= 2
1933 __get_db()->__insert_c(this);
1934#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935}
1936
1937template <class _CharT, class _Traits, class _Allocator>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001938#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow64c10d02018-07-02 18:41:15 +00001939template <class>
Marshall Clow7e3ab172018-10-16 16:02:18 +00001940#endif
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001941basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001942 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001943{
1944 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001945#if _LIBCPP_DEBUG_LEVEL >= 2
1946 __get_db()->__insert_c(this);
1947#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001948}
1949
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001950template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001951basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1952 size_type __pos, size_type __n,
1953 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001954 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001955{
1956 size_type __str_sz = __str.size();
1957 if (__pos > __str_sz)
1958 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001959 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00001960#if _LIBCPP_DEBUG_LEVEL >= 2
1961 __get_db()->__insert_c(this);
1962#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001963}
1964
1965template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00001966inline
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001967basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001968 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001969 : __r_(__second_tag(), __a)
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001970{
1971 size_type __str_sz = __str.size();
1972 if (__pos > __str_sz)
1973 this->__throw_out_of_range();
1974 __init(__str.data() + __pos, __str_sz - __pos);
1975#if _LIBCPP_DEBUG_LEVEL >= 2
1976 __get_db()->__insert_c(this);
1977#endif
1978}
1979
1980template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001981template <class _Tp, class>
Marshall Clowdb7fa112016-11-14 18:22:19 +00001982basic_string<_CharT, _Traits, _Allocator>::basic_string(
Marshall Clow64c10d02018-07-02 18:41:15 +00001983 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001984 : __r_(__second_tag(), __a)
Marshall Clowdb7fa112016-11-14 18:22:19 +00001985{
Marshall Clow64c10d02018-07-02 18:41:15 +00001986 __self_view __sv0 = __t;
1987 __self_view __sv = __sv0.substr(__pos, __n);
Marshall Clowdb7fa112016-11-14 18:22:19 +00001988 __init(__sv.data(), __sv.size());
1989#if _LIBCPP_DEBUG_LEVEL >= 2
1990 __get_db()->__insert_c(this);
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001991#endif
Marshall Clowdb7fa112016-11-14 18:22:19 +00001992}
1993
1994template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00001995template <class _Tp, class>
1996basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001997{
Marshall Clow64c10d02018-07-02 18:41:15 +00001998 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001999 __init(__sv.data(), __sv.size());
2000#if _LIBCPP_DEBUG_LEVEL >= 2
2001 __get_db()->__insert_c(this);
2002#endif
2003}
2004
2005template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00002006template <class _Tp, class>
2007basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002008 : __r_(__second_tag(), __a)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002009{
Marshall Clow64c10d02018-07-02 18:41:15 +00002010 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002011 __init(__sv.data(), __sv.size());
2012#if _LIBCPP_DEBUG_LEVEL >= 2
2013 __get_db()->__insert_c(this);
2014#endif
2015}
2016
2017template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002018template <class _InputIterator>
2019typename enable_if
2020<
Marshall Clowdf9db312016-01-13 21:54:34 +00002021 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002022 void
2023>::type
2024basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2025{
2026 __zero();
2027#ifndef _LIBCPP_NO_EXCEPTIONS
2028 try
2029 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002030#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002031 for (; __first != __last; ++__first)
2032 push_back(*__first);
2033#ifndef _LIBCPP_NO_EXCEPTIONS
2034 }
2035 catch (...)
2036 {
2037 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002038 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002039 throw;
2040 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002041#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002042}
2043
2044template <class _CharT, class _Traits, class _Allocator>
2045template <class _ForwardIterator>
2046typename enable_if
2047<
2048 __is_forward_iterator<_ForwardIterator>::value,
2049 void
2050>::type
2051basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2052{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002053 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002054 if (__sz > max_size())
2055 this->__throw_length_error();
2056 pointer __p;
2057 if (__sz < __min_cap)
2058 {
2059 __set_short_size(__sz);
2060 __p = __get_short_pointer();
2061 }
2062 else
2063 {
2064 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002065 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002066 __set_long_pointer(__p);
2067 __set_long_cap(__cap+1);
2068 __set_long_size(__sz);
2069 }
Eric Fiselierb9919752014-10-27 19:28:20 +00002070 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002071 traits_type::assign(*__p, *__first);
2072 traits_type::assign(*__p, value_type());
2073}
2074
2075template <class _CharT, class _Traits, class _Allocator>
2076template<class _InputIterator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002077inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002078basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2079{
2080 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002081#if _LIBCPP_DEBUG_LEVEL >= 2
2082 __get_db()->__insert_c(this);
2083#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002084}
2085
2086template <class _CharT, class _Traits, class _Allocator>
2087template<class _InputIterator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002088inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002089basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2090 const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002091 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002092{
2093 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002094#if _LIBCPP_DEBUG_LEVEL >= 2
2095 __get_db()->__insert_c(this);
2096#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002097}
2098
Eric Fiselier3e928972017-04-19 00:28:44 +00002099#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00002100
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002101template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002102inline
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00002103basic_string<_CharT, _Traits, _Allocator>::basic_string(
2104 initializer_list<_CharT> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002105{
2106 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002107#if _LIBCPP_DEBUG_LEVEL >= 2
2108 __get_db()->__insert_c(this);
2109#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002110}
2111
2112template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002113inline
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002114
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00002115basic_string<_CharT, _Traits, _Allocator>::basic_string(
2116 initializer_list<_CharT> __il, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00002117 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002118{
2119 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002120#if _LIBCPP_DEBUG_LEVEL >= 2
2121 __get_db()->__insert_c(this);
2122#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002123}
2124
Eric Fiselier3e928972017-04-19 00:28:44 +00002125#endif // _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00002126
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002127template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002128basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2129{
Howard Hinnant499cea12013-08-23 17:37:05 +00002130#if _LIBCPP_DEBUG_LEVEL >= 2
2131 __get_db()->__erase_c(this);
2132#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002133 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002134 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002135}
2136
2137template <class _CharT, class _Traits, class _Allocator>
2138void
2139basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2140 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002141 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 +00002142{
2143 size_type __ms = max_size();
2144 if (__delta_cap > __ms - __old_cap - 1)
2145 this->__throw_length_error();
2146 pointer __old_p = __get_pointer();
2147 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002148 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002149 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002150 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002151 __invalidate_all_iterators();
2152 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002153 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2154 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002155 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002156 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002157 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2158 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002159 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2160 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002161 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002162 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002163 __set_long_pointer(__p);
2164 __set_long_cap(__cap+1);
2165 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2166 __set_long_size(__old_sz);
2167 traits_type::assign(__p[__old_sz], value_type());
2168}
2169
2170template <class _CharT, class _Traits, class _Allocator>
2171void
2172basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2173 size_type __n_copy, size_type __n_del, size_type __n_add)
2174{
2175 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00002176 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002177 this->__throw_length_error();
2178 pointer __old_p = __get_pointer();
2179 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002180 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002181 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002182 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002183 __invalidate_all_iterators();
2184 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002185 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2186 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002187 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2188 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002189 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2190 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2191 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002192 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002193 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002194 __set_long_pointer(__p);
2195 __set_long_cap(__cap+1);
2196}
2197
2198// assign
2199
2200template <class _CharT, class _Traits, class _Allocator>
2201basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002202basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002203{
Alp Tokerec34c482014-05-15 11:27:39 +00002204 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002205 size_type __cap = capacity();
2206 if (__cap >= __n)
2207 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002208 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002209 traits_type::move(__p, __s, __n);
2210 traits_type::assign(__p[__n], value_type());
2211 __set_size(__n);
2212 __invalidate_iterators_past(__n);
2213 }
2214 else
2215 {
2216 size_type __sz = size();
2217 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2218 }
2219 return *this;
2220}
2221
2222template <class _CharT, class _Traits, class _Allocator>
2223basic_string<_CharT, _Traits, _Allocator>&
2224basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2225{
2226 size_type __cap = capacity();
2227 if (__cap < __n)
2228 {
2229 size_type __sz = size();
2230 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2231 }
2232 else
2233 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002234 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002235 traits_type::assign(__p, __n, __c);
2236 traits_type::assign(__p[__n], value_type());
2237 __set_size(__n);
2238 return *this;
2239}
2240
2241template <class _CharT, class _Traits, class _Allocator>
2242basic_string<_CharT, _Traits, _Allocator>&
2243basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2244{
2245 pointer __p;
2246 if (__is_long())
2247 {
2248 __p = __get_long_pointer();
2249 __set_long_size(1);
2250 }
2251 else
2252 {
2253 __p = __get_short_pointer();
2254 __set_short_size(1);
2255 }
2256 traits_type::assign(*__p, __c);
2257 traits_type::assign(*++__p, value_type());
2258 __invalidate_iterators_past(1);
2259 return *this;
2260}
2261
2262template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002263basic_string<_CharT, _Traits, _Allocator>&
2264basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2265{
2266 if (this != &__str)
2267 {
2268 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00002269 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00002270 }
2271 return *this;
2272}
2273
Eric Fiselier3e928972017-04-19 00:28:44 +00002274#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante32b5e22010-11-17 17:55:08 +00002275
2276template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002277inline
Howard Hinnante32b5e22010-11-17 17:55:08 +00002278void
2279basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002280 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002281{
2282 if (__alloc() != __str.__alloc())
2283 assign(__str);
2284 else
2285 __move_assign(__str, true_type());
2286}
2287
2288template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002289inline
Howard Hinnante32b5e22010-11-17 17:55:08 +00002290void
2291basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002292#if _LIBCPP_STD_VER > 14
2293 _NOEXCEPT
2294#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002295 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002296#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002297{
Vedant Kumar2b588cb2018-03-08 21:15:26 +00002298 __clear_and_shrink();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002299 __r_.first() = __str.__r_.first();
2300 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002301 __str.__zero();
2302}
2303
2304template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002305inline
Howard Hinnante32b5e22010-11-17 17:55:08 +00002306basic_string<_CharT, _Traits, _Allocator>&
2307basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002308 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002309{
2310 __move_assign(__str, integral_constant<bool,
2311 __alloc_traits::propagate_on_container_move_assignment::value>());
2312 return *this;
2313}
2314
2315#endif
2316
2317template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002318template<class _InputIterator>
2319typename enable_if
2320<
Marshall Clowdf9db312016-01-13 21:54:34 +00002321 __is_exactly_input_iterator <_InputIterator>::value
2322 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002323 basic_string<_CharT, _Traits, _Allocator>&
2324>::type
2325basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2326{
Marshall Clowd979eed2016-09-05 01:54:30 +00002327 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002328 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002329 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002330}
2331
2332template <class _CharT, class _Traits, class _Allocator>
2333template<class _ForwardIterator>
2334typename enable_if
2335<
Marshall Clowdf9db312016-01-13 21:54:34 +00002336 __is_forward_iterator<_ForwardIterator>::value
2337 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002338 basic_string<_CharT, _Traits, _Allocator>&
2339>::type
2340basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2341{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002342 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002343 size_type __cap = capacity();
2344 if (__cap < __n)
2345 {
2346 size_type __sz = size();
2347 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2348 }
2349 else
2350 __invalidate_iterators_past(__n);
2351 pointer __p = __get_pointer();
2352 for (; __first != __last; ++__first, ++__p)
2353 traits_type::assign(*__p, *__first);
2354 traits_type::assign(*__p, value_type());
2355 __set_size(__n);
2356 return *this;
2357}
2358
2359template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002360basic_string<_CharT, _Traits, _Allocator>&
2361basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2362{
2363 size_type __sz = __str.size();
2364 if (__pos > __sz)
2365 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002366 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002367}
2368
2369template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002370template <class _Tp>
2371typename enable_if
2372<
2373 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002374 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002375>::type
2376basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002377{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002378 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002379 size_type __sz = __sv.size();
2380 if (__pos > __sz)
2381 this->__throw_out_of_range();
2382 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2383}
2384
2385
2386template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002387basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002388basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002389{
Alp Tokerec34c482014-05-15 11:27:39 +00002390 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002391 return assign(__s, traits_type::length(__s));
2392}
2393
2394// append
2395
2396template <class _CharT, class _Traits, class _Allocator>
2397basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002398basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002399{
Alp Tokerec34c482014-05-15 11:27:39 +00002400 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002401 size_type __cap = capacity();
2402 size_type __sz = size();
2403 if (__cap - __sz >= __n)
2404 {
2405 if (__n)
2406 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002407 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002408 traits_type::copy(__p + __sz, __s, __n);
2409 __sz += __n;
2410 __set_size(__sz);
2411 traits_type::assign(__p[__sz], value_type());
2412 }
2413 }
2414 else
2415 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2416 return *this;
2417}
2418
2419template <class _CharT, class _Traits, class _Allocator>
2420basic_string<_CharT, _Traits, _Allocator>&
2421basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2422{
2423 if (__n)
2424 {
2425 size_type __cap = capacity();
2426 size_type __sz = size();
2427 if (__cap - __sz < __n)
2428 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2429 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002430 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002431 __sz += __n;
2432 __set_size(__sz);
2433 traits_type::assign(__p[__sz], value_type());
2434 }
2435 return *this;
2436}
2437
2438template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierf9782de2018-11-26 20:15:38 +00002439inline void
2440basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
2441{
2442 if (__n)
2443 {
2444 size_type __cap = capacity();
2445 size_type __sz = size();
2446 if (__cap - __sz < __n)
2447 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2448 pointer __p = __get_pointer();
2449 __sz += __n;
2450 __set_size(__sz);
2451 traits_type::assign(__p[__sz], value_type());
2452 }
2453}
2454
2455template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002456void
2457basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2458{
Howard Hinnant15467182013-04-30 21:44:48 +00002459 bool __is_short = !__is_long();
2460 size_type __cap;
2461 size_type __sz;
2462 if (__is_short)
2463 {
2464 __cap = __min_cap - 1;
2465 __sz = __get_short_size();
2466 }
2467 else
2468 {
2469 __cap = __get_long_cap() - 1;
2470 __sz = __get_long_size();
2471 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002472 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002473 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002474 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002475 __is_short = !__is_long();
2476 }
2477 pointer __p;
2478 if (__is_short)
2479 {
2480 __p = __get_short_pointer() + __sz;
2481 __set_short_size(__sz+1);
2482 }
2483 else
2484 {
2485 __p = __get_long_pointer() + __sz;
2486 __set_long_size(__sz+1);
2487 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002488 traits_type::assign(*__p, __c);
2489 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002490}
2491
Marshall Clowac655ef2016-09-07 03:32:06 +00002492template <class _Tp>
Marshall Clowd979eed2016-09-05 01:54:30 +00002493bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2494{
2495 return __first <= __p && __p < __last;
2496}
2497
Marshall Clowac655ef2016-09-07 03:32:06 +00002498template <class _Tp1, class _Tp2>
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00002499bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
Marshall Clowac655ef2016-09-07 03:32:06 +00002500{
2501 return false;
2502}
2503
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002504template <class _CharT, class _Traits, class _Allocator>
2505template<class _ForwardIterator>
Eric Fiselier026d38e2016-10-31 02:46:25 +00002506basic_string<_CharT, _Traits, _Allocator>&
2507basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2508 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002509{
Eric Fiselier026d38e2016-10-31 02:46:25 +00002510 static_assert(__is_forward_iterator<_ForwardIterator>::value,
2511 "function requires a ForwardIterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002512 size_type __sz = size();
2513 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002514 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002515 if (__n)
2516 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002517 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2518 _CharRef __tmp_ref = *__first;
2519 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002520 {
2521 const basic_string __temp (__first, __last, __alloc());
2522 append(__temp.data(), __temp.size());
2523 }
2524 else
2525 {
2526 if (__cap - __sz < __n)
2527 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2528 pointer __p = __get_pointer() + __sz;
2529 for (; __first != __last; ++__p, ++__first)
2530 traits_type::assign(*__p, *__first);
2531 traits_type::assign(*__p, value_type());
2532 __set_size(__sz + __n);
2533 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002534 }
2535 return *this;
2536}
2537
2538template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002539inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002540basic_string<_CharT, _Traits, _Allocator>&
2541basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2542{
2543 return append(__str.data(), __str.size());
2544}
2545
2546template <class _CharT, class _Traits, class _Allocator>
2547basic_string<_CharT, _Traits, _Allocator>&
2548basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2549{
2550 size_type __sz = __str.size();
2551 if (__pos > __sz)
2552 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002553 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002554}
2555
2556template <class _CharT, class _Traits, class _Allocator>
Marshall Clow42a87db2016-10-03 23:40:48 +00002557template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002558 typename enable_if
2559 <
2560 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2561 basic_string<_CharT, _Traits, _Allocator>&
2562 >::type
2563basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002564{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002565 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002566 size_type __sz = __sv.size();
2567 if (__pos > __sz)
2568 this->__throw_out_of_range();
2569 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2570}
2571
2572template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002573basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002574basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002575{
Alp Tokerec34c482014-05-15 11:27:39 +00002576 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002577 return append(__s, traits_type::length(__s));
2578}
2579
2580// insert
2581
2582template <class _CharT, class _Traits, class _Allocator>
2583basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002584basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002585{
Alp Tokerec34c482014-05-15 11:27:39 +00002586 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002587 size_type __sz = size();
2588 if (__pos > __sz)
2589 this->__throw_out_of_range();
2590 size_type __cap = capacity();
2591 if (__cap - __sz >= __n)
2592 {
2593 if (__n)
2594 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002595 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002596 size_type __n_move = __sz - __pos;
2597 if (__n_move != 0)
2598 {
2599 if (__p + __pos <= __s && __s < __p + __sz)
2600 __s += __n;
2601 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2602 }
2603 traits_type::move(__p + __pos, __s, __n);
2604 __sz += __n;
2605 __set_size(__sz);
2606 traits_type::assign(__p[__sz], value_type());
2607 }
2608 }
2609 else
2610 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2611 return *this;
2612}
2613
2614template <class _CharT, class _Traits, class _Allocator>
2615basic_string<_CharT, _Traits, _Allocator>&
2616basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2617{
2618 size_type __sz = size();
2619 if (__pos > __sz)
2620 this->__throw_out_of_range();
2621 if (__n)
2622 {
2623 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002624 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002625 if (__cap - __sz >= __n)
2626 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002627 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002628 size_type __n_move = __sz - __pos;
2629 if (__n_move != 0)
2630 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2631 }
2632 else
2633 {
2634 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002635 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002636 }
2637 traits_type::assign(__p + __pos, __n, __c);
2638 __sz += __n;
2639 __set_size(__sz);
2640 traits_type::assign(__p[__sz], value_type());
2641 }
2642 return *this;
2643}
2644
2645template <class _CharT, class _Traits, class _Allocator>
2646template<class _InputIterator>
2647typename enable_if
2648<
Marshall Clowdf9db312016-01-13 21:54:34 +00002649 __is_exactly_input_iterator<_InputIterator>::value
2650 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2651 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002652>::type
2653basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2654{
Howard Hinnant499cea12013-08-23 17:37:05 +00002655#if _LIBCPP_DEBUG_LEVEL >= 2
2656 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2657 "string::insert(iterator, range) called with an iterator not"
2658 " referring to this string");
2659#endif
Marshall Clowd979eed2016-09-05 01:54:30 +00002660 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002661 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002662}
2663
2664template <class _CharT, class _Traits, class _Allocator>
2665template<class _ForwardIterator>
2666typename enable_if
2667<
Marshall Clowdf9db312016-01-13 21:54:34 +00002668 __is_forward_iterator<_ForwardIterator>::value
2669 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002670 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2671>::type
2672basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2673{
Howard Hinnant499cea12013-08-23 17:37:05 +00002674#if _LIBCPP_DEBUG_LEVEL >= 2
2675 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2676 "string::insert(iterator, range) called with an iterator not"
2677 " referring to this string");
2678#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002679 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002680 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002681 if (__n)
2682 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002683 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2684 _CharRef __tmp_char = *__first;
2685 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002686 {
2687 const basic_string __temp(__first, __last, __alloc());
2688 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2689 }
2690
2691 size_type __sz = size();
2692 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002693 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002694 if (__cap - __sz >= __n)
2695 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002696 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002697 size_type __n_move = __sz - __ip;
2698 if (__n_move != 0)
2699 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2700 }
2701 else
2702 {
2703 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002704 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002705 }
2706 __sz += __n;
2707 __set_size(__sz);
2708 traits_type::assign(__p[__sz], value_type());
2709 for (__p += __ip; __first != __last; ++__p, ++__first)
2710 traits_type::assign(*__p, *__first);
2711 }
2712 return begin() + __ip;
2713}
2714
2715template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002716inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002717basic_string<_CharT, _Traits, _Allocator>&
2718basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2719{
2720 return insert(__pos1, __str.data(), __str.size());
2721}
2722
2723template <class _CharT, class _Traits, class _Allocator>
2724basic_string<_CharT, _Traits, _Allocator>&
2725basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2726 size_type __pos2, size_type __n)
2727{
2728 size_type __str_sz = __str.size();
2729 if (__pos2 > __str_sz)
2730 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002731 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002732}
2733
2734template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002735template <class _Tp>
2736typename enable_if
2737<
2738 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002739 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002740>::type
2741basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002742 size_type __pos2, size_type __n)
2743{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002744 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002745 size_type __str_sz = __sv.size();
2746 if (__pos2 > __str_sz)
2747 this->__throw_out_of_range();
2748 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2749}
2750
2751template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002752basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002753basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002754{
Alp Tokerec34c482014-05-15 11:27:39 +00002755 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002756 return insert(__pos, __s, traits_type::length(__s));
2757}
2758
2759template <class _CharT, class _Traits, class _Allocator>
2760typename basic_string<_CharT, _Traits, _Allocator>::iterator
2761basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2762{
2763 size_type __ip = static_cast<size_type>(__pos - begin());
2764 size_type __sz = size();
2765 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002766 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002767 if (__cap == __sz)
2768 {
2769 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002770 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002771 }
2772 else
2773 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002774 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002775 size_type __n_move = __sz - __ip;
2776 if (__n_move != 0)
2777 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2778 }
2779 traits_type::assign(__p[__ip], __c);
2780 traits_type::assign(__p[++__sz], value_type());
2781 __set_size(__sz);
2782 return begin() + static_cast<difference_type>(__ip);
2783}
2784
2785template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002786inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002787typename basic_string<_CharT, _Traits, _Allocator>::iterator
2788basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2789{
Howard Hinnant499cea12013-08-23 17:37:05 +00002790#if _LIBCPP_DEBUG_LEVEL >= 2
2791 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2792 "string::insert(iterator, n, value) called with an iterator not"
2793 " referring to this string");
2794#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002795 difference_type __p = __pos - begin();
2796 insert(static_cast<size_type>(__p), __n, __c);
2797 return begin() + __p;
2798}
2799
2800// replace
2801
2802template <class _CharT, class _Traits, class _Allocator>
2803basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002804basic_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 +00002805 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002806{
Alp Tokerec34c482014-05-15 11:27:39 +00002807 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002808 size_type __sz = size();
2809 if (__pos > __sz)
2810 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002811 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002812 size_type __cap = capacity();
2813 if (__cap - __sz + __n1 >= __n2)
2814 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002815 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002816 if (__n1 != __n2)
2817 {
2818 size_type __n_move = __sz - __pos - __n1;
2819 if (__n_move != 0)
2820 {
2821 if (__n1 > __n2)
2822 {
2823 traits_type::move(__p + __pos, __s, __n2);
2824 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2825 goto __finish;
2826 }
2827 if (__p + __pos < __s && __s < __p + __sz)
2828 {
2829 if (__p + __pos + __n1 <= __s)
2830 __s += __n2 - __n1;
2831 else // __p + __pos < __s < __p + __pos + __n1
2832 {
2833 traits_type::move(__p + __pos, __s, __n1);
2834 __pos += __n1;
2835 __s += __n2;
2836 __n2 -= __n1;
2837 __n1 = 0;
2838 }
2839 }
2840 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2841 }
2842 }
2843 traits_type::move(__p + __pos, __s, __n2);
2844__finish:
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002845// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
2846// but this is a safe operation, so we disable the check.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002847 __sz += __n2 - __n1;
2848 __set_size(__sz);
2849 __invalidate_iterators_past(__sz);
2850 traits_type::assign(__p[__sz], value_type());
2851 }
2852 else
2853 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2854 return *this;
2855}
2856
2857template <class _CharT, class _Traits, class _Allocator>
2858basic_string<_CharT, _Traits, _Allocator>&
2859basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002860 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002861{
2862 size_type __sz = size();
2863 if (__pos > __sz)
2864 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002865 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002866 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002867 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002868 if (__cap - __sz + __n1 >= __n2)
2869 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002870 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002871 if (__n1 != __n2)
2872 {
2873 size_type __n_move = __sz - __pos - __n1;
2874 if (__n_move != 0)
2875 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2876 }
2877 }
2878 else
2879 {
2880 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002881 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002882 }
2883 traits_type::assign(__p + __pos, __n2, __c);
2884 __sz += __n2 - __n1;
2885 __set_size(__sz);
2886 __invalidate_iterators_past(__sz);
2887 traits_type::assign(__p[__sz], value_type());
2888 return *this;
2889}
2890
2891template <class _CharT, class _Traits, class _Allocator>
2892template<class _InputIterator>
2893typename enable_if
2894<
2895 __is_input_iterator<_InputIterator>::value,
2896 basic_string<_CharT, _Traits, _Allocator>&
2897>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002898basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002899 _InputIterator __j1, _InputIterator __j2)
2900{
Marshall Clowd979eed2016-09-05 01:54:30 +00002901 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002902 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002903}
2904
2905template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002906inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002907basic_string<_CharT, _Traits, _Allocator>&
2908basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2909{
2910 return replace(__pos1, __n1, __str.data(), __str.size());
2911}
2912
2913template <class _CharT, class _Traits, class _Allocator>
2914basic_string<_CharT, _Traits, _Allocator>&
2915basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2916 size_type __pos2, size_type __n2)
2917{
2918 size_type __str_sz = __str.size();
2919 if (__pos2 > __str_sz)
2920 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002921 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002922}
2923
2924template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002925template <class _Tp>
2926typename enable_if
2927<
Marshall Clowf1729d92017-11-15 20:02:27 +00002928 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2929 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002930>::type
2931basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002932 size_type __pos2, size_type __n2)
2933{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002934 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002935 size_type __str_sz = __sv.size();
2936 if (__pos2 > __str_sz)
2937 this->__throw_out_of_range();
2938 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2939}
2940
2941template <class _CharT, class _Traits, class _Allocator>
2942basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002943basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002944{
Alp Tokerec34c482014-05-15 11:27:39 +00002945 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002946 return replace(__pos, __n1, __s, traits_type::length(__s));
2947}
2948
2949template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002950inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002951basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002952basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002953{
2954 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2955 __str.data(), __str.size());
2956}
2957
2958template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002959inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002960basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002961basic_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 +00002962{
2963 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2964}
2965
2966template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002967inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002968basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002969basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002970{
2971 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2972}
2973
2974template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00002975inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002976basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002977basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002978{
2979 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2980}
2981
2982// erase
2983
2984template <class _CharT, class _Traits, class _Allocator>
2985basic_string<_CharT, _Traits, _Allocator>&
2986basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2987{
2988 size_type __sz = size();
2989 if (__pos > __sz)
2990 this->__throw_out_of_range();
2991 if (__n)
2992 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002993 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002994 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002995 size_type __n_move = __sz - __pos - __n;
2996 if (__n_move != 0)
2997 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2998 __sz -= __n;
2999 __set_size(__sz);
3000 __invalidate_iterators_past(__sz);
3001 traits_type::assign(__p[__sz], value_type());
3002 }
3003 return *this;
3004}
3005
3006template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003007inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003008typename basic_string<_CharT, _Traits, _Allocator>::iterator
3009basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3010{
Howard Hinnant499cea12013-08-23 17:37:05 +00003011#if _LIBCPP_DEBUG_LEVEL >= 2
3012 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3013 "string::erase(iterator) called with an iterator not"
3014 " referring to this string");
3015#endif
3016 _LIBCPP_ASSERT(__pos != end(),
3017 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003018 iterator __b = begin();
3019 size_type __r = static_cast<size_type>(__pos - __b);
3020 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00003021 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003022}
3023
3024template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003025inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003026typename basic_string<_CharT, _Traits, _Allocator>::iterator
3027basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3028{
Howard Hinnant499cea12013-08-23 17:37:05 +00003029#if _LIBCPP_DEBUG_LEVEL >= 2
3030 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3031 "string::erase(iterator, iterator) called with an iterator not"
3032 " referring to this string");
3033#endif
3034 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003035 iterator __b = begin();
3036 size_type __r = static_cast<size_type>(__first - __b);
3037 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00003038 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003039}
3040
3041template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003042inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003043void
3044basic_string<_CharT, _Traits, _Allocator>::pop_back()
3045{
Howard Hinnant499cea12013-08-23 17:37:05 +00003046 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003047 size_type __sz;
3048 if (__is_long())
3049 {
3050 __sz = __get_long_size() - 1;
3051 __set_long_size(__sz);
3052 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3053 }
3054 else
3055 {
3056 __sz = __get_short_size() - 1;
3057 __set_short_size(__sz);
3058 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3059 }
3060 __invalidate_iterators_past(__sz);
3061}
3062
3063template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003064inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003065void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003066basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003067{
3068 __invalidate_all_iterators();
3069 if (__is_long())
3070 {
3071 traits_type::assign(*__get_long_pointer(), value_type());
3072 __set_long_size(0);
3073 }
3074 else
3075 {
3076 traits_type::assign(*__get_short_pointer(), value_type());
3077 __set_short_size(0);
3078 }
3079}
3080
3081template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003082inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003083void
3084basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3085{
3086 if (__is_long())
3087 {
3088 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3089 __set_long_size(__pos);
3090 }
3091 else
3092 {
3093 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3094 __set_short_size(__pos);
3095 }
3096 __invalidate_iterators_past(__pos);
3097}
3098
3099template <class _CharT, class _Traits, class _Allocator>
3100void
3101basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3102{
3103 size_type __sz = size();
3104 if (__n > __sz)
3105 append(__n - __sz, __c);
3106 else
3107 __erase_to_end(__n);
3108}
3109
3110template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierf9782de2018-11-26 20:15:38 +00003111inline void
3112basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
3113{
3114 size_type __sz = size();
3115 if (__n > __sz) {
3116 __append_default_init(__n - __sz);
3117 } else
3118 __erase_to_end(__n);
3119}
3120
3121template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003122inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003123typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003124basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003125{
Howard Hinnante32b5e22010-11-17 17:55:08 +00003126 size_type __m = __alloc_traits::max_size(__alloc());
Eric Fiselier5ccf0432017-10-17 13:16:01 +00003127#ifdef _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00003128 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003129#else
Marshall Clow09f85502013-10-31 17:23:08 +00003130 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003131#endif
3132}
3133
3134template <class _CharT, class _Traits, class _Allocator>
3135void
3136basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3137{
3138 if (__res_arg > max_size())
3139 this->__throw_length_error();
3140 size_type __cap = capacity();
3141 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003142 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003143 __res_arg = __recommend(__res_arg);
3144 if (__res_arg != __cap)
3145 {
3146 pointer __new_data, __p;
3147 bool __was_long, __now_long;
3148 if (__res_arg == __min_cap - 1)
3149 {
3150 __was_long = true;
3151 __now_long = false;
3152 __new_data = __get_short_pointer();
3153 __p = __get_long_pointer();
3154 }
3155 else
3156 {
3157 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003158 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003159 else
3160 {
3161 #ifndef _LIBCPP_NO_EXCEPTIONS
3162 try
3163 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003164 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00003165 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003166 #ifndef _LIBCPP_NO_EXCEPTIONS
3167 }
3168 catch (...)
3169 {
3170 return;
3171 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003172 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003173 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003174 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003175 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003176 }
3177 __now_long = true;
3178 __was_long = __is_long();
3179 __p = __get_pointer();
3180 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003181 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3182 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003183 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003184 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003185 if (__now_long)
3186 {
3187 __set_long_cap(__res_arg+1);
3188 __set_long_size(__sz);
3189 __set_long_pointer(__new_data);
3190 }
3191 else
3192 __set_short_size(__sz);
3193 __invalidate_all_iterators();
3194 }
3195}
3196
3197template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003198inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003199typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003200basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003201{
Howard Hinnant499cea12013-08-23 17:37:05 +00003202 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003203 return *(data() + __pos);
3204}
3205
3206template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003207inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003208typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003209basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003210{
Howard Hinnant499cea12013-08-23 17:37:05 +00003211 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003212 return *(__get_pointer() + __pos);
3213}
3214
3215template <class _CharT, class _Traits, class _Allocator>
3216typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3217basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3218{
3219 if (__n >= size())
3220 this->__throw_out_of_range();
3221 return (*this)[__n];
3222}
3223
3224template <class _CharT, class _Traits, class _Allocator>
3225typename basic_string<_CharT, _Traits, _Allocator>::reference
3226basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3227{
3228 if (__n >= size())
3229 this->__throw_out_of_range();
3230 return (*this)[__n];
3231}
3232
3233template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003234inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003235typename basic_string<_CharT, _Traits, _Allocator>::reference
3236basic_string<_CharT, _Traits, _Allocator>::front()
3237{
Howard Hinnant499cea12013-08-23 17:37:05 +00003238 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003239 return *__get_pointer();
3240}
3241
3242template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003243inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003244typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3245basic_string<_CharT, _Traits, _Allocator>::front() const
3246{
Howard Hinnant499cea12013-08-23 17:37:05 +00003247 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003248 return *data();
3249}
3250
3251template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003252inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003253typename basic_string<_CharT, _Traits, _Allocator>::reference
3254basic_string<_CharT, _Traits, _Allocator>::back()
3255{
Howard Hinnant499cea12013-08-23 17:37:05 +00003256 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003257 return *(__get_pointer() + size() - 1);
3258}
3259
3260template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003261inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003262typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3263basic_string<_CharT, _Traits, _Allocator>::back() const
3264{
Howard Hinnant499cea12013-08-23 17:37:05 +00003265 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003266 return *(data() + size() - 1);
3267}
3268
3269template <class _CharT, class _Traits, class _Allocator>
3270typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003271basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003272{
3273 size_type __sz = size();
3274 if (__pos > __sz)
3275 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003276 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003277 traits_type::copy(__s, data() + __pos, __rlen);
3278 return __rlen;
3279}
3280
3281template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003282inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003283basic_string<_CharT, _Traits, _Allocator>
3284basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3285{
3286 return basic_string(*this, __pos, __n, __alloc());
3287}
3288
3289template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003290inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003291void
3292basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00003293#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00003294 _NOEXCEPT_DEBUG
Marshall Clow7d914d12015-07-13 20:04:56 +00003295#else
Eric Fiselier47257c42016-12-28 05:53:01 +00003296 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00003297 __is_nothrow_swappable<allocator_type>::value)
3298#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003299{
Howard Hinnant499cea12013-08-23 17:37:05 +00003300#if _LIBCPP_DEBUG_LEVEL >= 2
3301 if (!__is_long())
3302 __get_db()->__invalidate_all(this);
3303 if (!__str.__is_long())
3304 __get_db()->__invalidate_all(&__str);
3305 __get_db()->swap(this, &__str);
3306#endif
Eric Fiselier47257c42016-12-28 05:53:01 +00003307 _LIBCPP_ASSERT(
3308 __alloc_traits::propagate_on_container_swap::value ||
3309 __alloc_traits::is_always_equal::value ||
3310 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnant0949eed2011-06-30 21:18:19 +00003311 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00003312 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003313}
3314
3315// find
3316
3317template <class _Traits>
3318struct _LIBCPP_HIDDEN __traits_eq
3319{
3320 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003321 _LIBCPP_INLINE_VISIBILITY
3322 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3323 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003324};
3325
3326template<class _CharT, class _Traits, class _Allocator>
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,
3330 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003331{
Alp Tokerec34c482014-05-15 11:27:39 +00003332 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003333 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003334 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003335}
3336
3337template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003338inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003339typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003340basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3341 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003342{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003343 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003344 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003345}
3346
3347template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003348template <class _Tp>
3349typename enable_if
3350<
3351 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3352 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3353>::type
3354basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
3355 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003356{
Marshall Clow64c10d02018-07-02 18:41:15 +00003357 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003358 return __str_find<value_type, size_type, traits_type, npos>
3359 (data(), size(), __sv.data(), __pos, __sv.size());
3360}
3361
3362template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003363inline
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003364typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003365basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003366 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003367{
Alp Tokerec34c482014-05-15 11:27:39 +00003368 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003369 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003370 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003371}
3372
3373template<class _CharT, class _Traits, class _Allocator>
3374typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003375basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3376 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003377{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003378 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003379 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003380}
3381
3382// rfind
3383
3384template<class _CharT, class _Traits, class _Allocator>
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,
3388 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003389{
Alp Tokerec34c482014-05-15 11:27:39 +00003390 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003391 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003392 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003393}
3394
3395template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003396inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003397typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003398basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3399 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003400{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003401 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003402 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003403}
3404
3405template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003406template <class _Tp>
3407typename enable_if
3408<
3409 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3410 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3411>::type
3412basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
3413 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003414{
Marshall Clow64c10d02018-07-02 18:41:15 +00003415 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003416 return __str_rfind<value_type, size_type, traits_type, npos>
3417 (data(), size(), __sv.data(), __pos, __sv.size());
3418}
3419
3420template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003421inline
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003422typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003423basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003424 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003425{
Alp Tokerec34c482014-05-15 11:27:39 +00003426 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003427 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003428 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003429}
3430
3431template<class _CharT, class _Traits, class _Allocator>
3432typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003433basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3434 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003435{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003436 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003437 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003438}
3439
3440// find_first_of
3441
3442template<class _CharT, class _Traits, class _Allocator>
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,
3446 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003447{
Alp Tokerec34c482014-05-15 11:27:39 +00003448 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003449 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003450 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003451}
3452
3453template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003454inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003455typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003456basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3457 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003458{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003459 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003460 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003461}
3462
3463template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003464template <class _Tp>
3465typename enable_if
3466<
3467 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3468 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3469>::type
3470basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
3471 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003472{
Marshall Clow64c10d02018-07-02 18:41:15 +00003473 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003474 return __str_find_first_of<value_type, size_type, traits_type, npos>
3475 (data(), size(), __sv.data(), __pos, __sv.size());
3476}
3477
3478template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003479inline
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003480typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003481basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003482 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003483{
Alp Tokerec34c482014-05-15 11:27:39 +00003484 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003485 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003486 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003487}
3488
3489template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003490inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003491typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003492basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3493 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003494{
3495 return find(__c, __pos);
3496}
3497
3498// find_last_of
3499
3500template<class _CharT, class _Traits, class _Allocator>
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,
3504 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003505{
Alp Tokerec34c482014-05-15 11:27:39 +00003506 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003507 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003508 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003509}
3510
3511template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003512inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003513typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003514basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3515 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003516{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003517 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003518 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003519}
3520
3521template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003522template <class _Tp>
3523typename enable_if
3524<
3525 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3526 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3527>::type
3528basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
3529 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003530{
Marshall Clow64c10d02018-07-02 18:41:15 +00003531 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003532 return __str_find_last_of<value_type, size_type, traits_type, npos>
3533 (data(), size(), __sv.data(), __pos, __sv.size());
3534}
3535
3536template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003537inline
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003538typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003539basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003540 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003541{
Alp Tokerec34c482014-05-15 11:27:39 +00003542 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003543 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003544 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003545}
3546
3547template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003548inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003549typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003550basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3551 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003552{
3553 return rfind(__c, __pos);
3554}
3555
3556// find_first_not_of
3557
3558template<class _CharT, class _Traits, class _Allocator>
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,
3562 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003563{
Alp Tokerec34c482014-05-15 11:27:39 +00003564 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003565 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003566 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003567}
3568
3569template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003570inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003571typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003572basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3573 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003574{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003575 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003576 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003577}
3578
3579template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003580template <class _Tp>
3581typename enable_if
3582<
3583 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3584 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3585>::type
3586basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
3587 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003588{
Marshall Clow64c10d02018-07-02 18:41:15 +00003589 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003590 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3591 (data(), size(), __sv.data(), __pos, __sv.size());
3592}
3593
3594template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003595inline
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003596typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003597basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003598 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003599{
Alp Tokerec34c482014-05-15 11:27:39 +00003600 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003601 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003602 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003603}
3604
3605template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003606inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003607typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003608basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3609 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003610{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003611 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003612 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003613}
3614
3615// find_last_not_of
3616
3617template<class _CharT, class _Traits, class _Allocator>
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,
3621 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003622{
Alp Tokerec34c482014-05-15 11:27:39 +00003623 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003624 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003625 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003626}
3627
3628template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003629inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003630typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003631basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3632 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003633{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003634 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003635 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003636}
3637
3638template<class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003639template <class _Tp>
3640typename enable_if
3641<
3642 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3643 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3644>::type
3645basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
3646 size_type __pos) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003647{
Marshall Clow64c10d02018-07-02 18:41:15 +00003648 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003649 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3650 (data(), size(), __sv.data(), __pos, __sv.size());
3651}
3652
3653template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003654inline
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003655typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003656basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003657 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003658{
Alp Tokerec34c482014-05-15 11:27:39 +00003659 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003660 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003661 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003662}
3663
3664template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003665inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003666typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003667basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3668 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003669{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003670 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003671 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003672}
3673
3674// compare
3675
3676template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003677template <class _Tp>
3678typename enable_if
3679<
3680 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3681 int
3682>::type
3683basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003684{
Marshall Clow64c10d02018-07-02 18:41:15 +00003685 __self_view __sv = __t;
Howard Hinnantfa06d752011-07-24 21:45:06 +00003686 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003687 size_t __rhs_sz = __sv.size();
3688 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:06 +00003689 _VSTD::min(__lhs_sz, __rhs_sz));
3690 if (__result != 0)
3691 return __result;
3692 if (__lhs_sz < __rhs_sz)
3693 return -1;
3694 if (__lhs_sz > __rhs_sz)
3695 return 1;
3696 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003697}
3698
3699template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003700inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003701int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003702basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003703{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003704 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003705}
3706
3707template <class _CharT, class _Traits, class _Allocator>
3708int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003709basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3710 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003711 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003712 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003713{
Alp Tokerec34c482014-05-15 11:27:39 +00003714 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003715 size_type __sz = size();
3716 if (__pos1 > __sz || __n2 == npos)
3717 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003718 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3719 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003720 if (__r == 0)
3721 {
3722 if (__rlen < __n2)
3723 __r = -1;
3724 else if (__rlen > __n2)
3725 __r = 1;
3726 }
3727 return __r;
3728}
3729
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003730template <class _CharT, class _Traits, class _Allocator>
Marshall Clow64c10d02018-07-02 18:41:15 +00003731template <class _Tp>
3732typename enable_if
3733<
3734 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3735 int
3736>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003737basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3738 size_type __n1,
Marshall Clow64c10d02018-07-02 18:41:15 +00003739 const _Tp& __t) const
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003740{
Marshall Clow64c10d02018-07-02 18:41:15 +00003741 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003742 return compare(__pos1, __n1, __sv.data(), __sv.size());
3743}
3744
3745template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003746inline
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003747int
3748basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3749 size_type __n1,
3750 const basic_string& __str) const
3751{
3752 return compare(__pos1, __n1, __str.data(), __str.size());
3753}
3754
3755template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00003756template <class _Tp>
3757typename enable_if
3758<
Marshall Clowf1729d92017-11-15 20:02:27 +00003759 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3760 int
Marshall Clow6ac8de02016-09-24 22:45:42 +00003761>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003762basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3763 size_type __n1,
Marshall Clow6ac8de02016-09-24 22:45:42 +00003764 const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003765 size_type __pos2,
3766 size_type __n2) const
3767{
Marshall Clow6ac8de02016-09-24 22:45:42 +00003768 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003769 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3770}
3771
3772template <class _CharT, class _Traits, class _Allocator>
3773int
3774basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3775 size_type __n1,
3776 const basic_string& __str,
3777 size_type __pos2,
3778 size_type __n2) const
3779{
3780 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3781}
3782
3783template <class _CharT, class _Traits, class _Allocator>
3784int
3785basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3786{
3787 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3788 return compare(0, npos, __s, traits_type::length(__s));
3789}
3790
3791template <class _CharT, class _Traits, class _Allocator>
3792int
3793basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3794 size_type __n1,
3795 const value_type* __s) const
3796{
3797 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3798 return compare(__pos1, __n1, __s, traits_type::length(__s));
3799}
3800
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003801// __invariants
3802
3803template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003804inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003805bool
3806basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3807{
3808 if (size() > capacity())
3809 return false;
3810 if (capacity() < __min_cap - 1)
3811 return false;
3812 if (data() == 0)
3813 return false;
3814 if (data()[size()] != value_type(0))
3815 return false;
3816 return true;
3817}
3818
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003819// __clear_and_shrink
3820
3821template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00003822inline
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003823void
Marshall Clowab343bb2018-05-29 17:04:37 +00003824basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
Vedant Kumar2b588cb2018-03-08 21:15:26 +00003825{
3826 clear();
3827 if(__is_long())
3828 {
3829 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
3830 __set_long_cap(0);
3831 __set_short_size(0);
3832 }
3833}
3834
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003835// operator==
3836
3837template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003838inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003839bool
3840operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003841 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003842{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003843 size_t __lhs_sz = __lhs.size();
3844 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3845 __rhs.data(),
3846 __lhs_sz) == 0;
3847}
3848
3849template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003850inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003851bool
3852operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3853 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3854{
3855 size_t __lhs_sz = __lhs.size();
3856 if (__lhs_sz != __rhs.size())
3857 return false;
3858 const char* __lp = __lhs.data();
3859 const char* __rp = __rhs.data();
3860 if (__lhs.__is_long())
3861 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3862 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3863 if (*__lp != *__rp)
3864 return false;
3865 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003866}
3867
3868template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003869inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003870bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003871operator==(const _CharT* __lhs,
3872 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003873{
Eric Fiselier4f241822015-08-28 03:02:37 +00003874 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3875 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3876 size_t __lhs_len = _Traits::length(__lhs);
3877 if (__lhs_len != __rhs.size()) return false;
3878 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003879}
3880
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003881template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003882inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003883bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003884operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3885 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003886{
Eric Fiselier4f241822015-08-28 03:02:37 +00003887 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3888 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3889 size_t __rhs_len = _Traits::length(__rhs);
3890 if (__rhs_len != __lhs.size()) return false;
3891 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003892}
3893
Howard Hinnant324bb032010-08-22 00:02:43 +00003894template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003895inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003896bool
3897operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003898 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003899{
3900 return !(__lhs == __rhs);
3901}
3902
3903template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003904inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003905bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003906operator!=(const _CharT* __lhs,
3907 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003908{
3909 return !(__lhs == __rhs);
3910}
3911
3912template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003913inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003914bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003915operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3916 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003917{
3918 return !(__lhs == __rhs);
3919}
3920
3921// operator<
3922
3923template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003924inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003925bool
3926operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003927 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003928{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003929 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003930}
3931
3932template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003933inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003934bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003935operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3936 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003937{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003938 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003939}
3940
3941template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003942inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003943bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003944operator< (const _CharT* __lhs,
3945 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003946{
3947 return __rhs.compare(__lhs) > 0;
3948}
3949
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003950// operator>
3951
3952template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003953inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003954bool
3955operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003956 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003957{
3958 return __rhs < __lhs;
3959}
3960
3961template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003962inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003963bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003964operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3965 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003966{
3967 return __rhs < __lhs;
3968}
3969
3970template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003971inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003972bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003973operator> (const _CharT* __lhs,
3974 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003975{
3976 return __rhs < __lhs;
3977}
3978
3979// operator<=
3980
3981template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003982inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003983bool
3984operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003985 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003986{
3987 return !(__rhs < __lhs);
3988}
3989
3990template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003991inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003992bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003993operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3994 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003995{
3996 return !(__rhs < __lhs);
3997}
3998
3999template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004000inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004001bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00004002operator<=(const _CharT* __lhs,
4003 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004004{
4005 return !(__rhs < __lhs);
4006}
4007
4008// operator>=
4009
4010template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004011inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004012bool
4013operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00004014 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004015{
4016 return !(__lhs < __rhs);
4017}
4018
4019template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004020inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004021bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00004022operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4023 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004024{
4025 return !(__lhs < __rhs);
4026}
4027
4028template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004029inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004030bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00004031operator>=(const _CharT* __lhs,
4032 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004033{
4034 return !(__lhs < __rhs);
4035}
4036
4037// operator +
4038
4039template<class _CharT, class _Traits, class _Allocator>
4040basic_string<_CharT, _Traits, _Allocator>
4041operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4042 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4043{
4044 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4045 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4046 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4047 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4048 __r.append(__rhs.data(), __rhs_sz);
4049 return __r;
4050}
4051
4052template<class _CharT, class _Traits, class _Allocator>
4053basic_string<_CharT, _Traits, _Allocator>
4054operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4055{
4056 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4057 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4058 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4059 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4060 __r.append(__rhs.data(), __rhs_sz);
4061 return __r;
4062}
4063
4064template<class _CharT, class _Traits, class _Allocator>
4065basic_string<_CharT, _Traits, _Allocator>
4066operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4067{
4068 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4069 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4070 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4071 __r.append(__rhs.data(), __rhs_sz);
4072 return __r;
4073}
4074
4075template<class _CharT, class _Traits, class _Allocator>
Eric Fiselier5f3377c2018-11-26 22:51:35 +00004076inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004077basic_string<_CharT, _Traits, _Allocator>
4078operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4079{
4080 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4081 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4082 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4083 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4084 __r.append(__rhs, __rhs_sz);
4085 return __r;
4086}
4087
4088template<class _CharT, class _Traits, class _Allocator>
4089basic_string<_CharT, _Traits, _Allocator>
4090operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4091{
4092 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4093 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4094 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4095 __r.push_back(__rhs);
4096 return __r;
4097}
4098
Eric Fiselier3e928972017-04-19 00:28:44 +00004099#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004100
4101template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004102inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004103basic_string<_CharT, _Traits, _Allocator>
4104operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4105{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004106 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004107}
4108
4109template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004110inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004111basic_string<_CharT, _Traits, _Allocator>
4112operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4113{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004114 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004115}
4116
4117template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004118inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004119basic_string<_CharT, _Traits, _Allocator>
4120operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4121{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004122 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004123}
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 +00004127basic_string<_CharT, _Traits, _Allocator>
4128operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4129{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004130 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004131}
4132
4133template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004134inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004135basic_string<_CharT, _Traits, _Allocator>
4136operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4137{
4138 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004139 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004140}
4141
4142template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004143inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004144basic_string<_CharT, _Traits, _Allocator>
4145operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4146{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004147 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004148}
4149
4150template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004151inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004152basic_string<_CharT, _Traits, _Allocator>
4153operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4154{
4155 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004156 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004157}
4158
Eric Fiselier3e928972017-04-19 00:28:44 +00004159#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004160
4161// swap
4162
4163template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004164inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004165void
Howard Hinnanta6119a82011-05-29 19:57:12 +00004166swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00004167 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4168 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004169{
4170 __lhs.swap(__rhs);
4171}
4172
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004173#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
4174
4175typedef basic_string<char16_t> u16string;
4176typedef basic_string<char32_t> u32string;
4177
Howard Hinnant324bb032010-08-22 00:02:43 +00004178#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004179
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004180_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4181_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4182_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4183_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4184_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004185
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004186_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4187_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4188_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004189
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004190_LIBCPP_FUNC_VIS string to_string(int __val);
4191_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4192_LIBCPP_FUNC_VIS string to_string(long __val);
4193_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4194_LIBCPP_FUNC_VIS string to_string(long long __val);
4195_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4196_LIBCPP_FUNC_VIS string to_string(float __val);
4197_LIBCPP_FUNC_VIS string to_string(double __val);
4198_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004199
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004200_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4201_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4202_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4203_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4204_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004205
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004206_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4207_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4208_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004209
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004210_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4211_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4212_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4213_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4214_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4215_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4216_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4217_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4218_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004219
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004220template<class _CharT, class _Traits, class _Allocator>
4221 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4222 basic_string<_CharT, _Traits, _Allocator>::npos;
4223
4224template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +00004225struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004226 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4227{
4228 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004229 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004230};
4231
4232template<class _CharT, class _Traits, class _Allocator>
4233size_t
4234hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004235 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004236{
Sean Huntaffd9e52011-07-29 23:31:56 +00004237 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004238}
4239
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004240template<class _CharT, class _Traits, class _Allocator>
4241basic_ostream<_CharT, _Traits>&
4242operator<<(basic_ostream<_CharT, _Traits>& __os,
4243 const basic_string<_CharT, _Traits, _Allocator>& __str);
4244
4245template<class _CharT, class _Traits, class _Allocator>
4246basic_istream<_CharT, _Traits>&
4247operator>>(basic_istream<_CharT, _Traits>& __is,
4248 basic_string<_CharT, _Traits, _Allocator>& __str);
4249
4250template<class _CharT, class _Traits, class _Allocator>
4251basic_istream<_CharT, _Traits>&
4252getline(basic_istream<_CharT, _Traits>& __is,
4253 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4254
4255template<class _CharT, class _Traits, class _Allocator>
4256inline _LIBCPP_INLINE_VISIBILITY
4257basic_istream<_CharT, _Traits>&
4258getline(basic_istream<_CharT, _Traits>& __is,
4259 basic_string<_CharT, _Traits, _Allocator>& __str);
4260
Eric Fiselier3e928972017-04-19 00:28:44 +00004261#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004262
4263template<class _CharT, class _Traits, class _Allocator>
4264inline _LIBCPP_INLINE_VISIBILITY
4265basic_istream<_CharT, _Traits>&
4266getline(basic_istream<_CharT, _Traits>&& __is,
4267 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4268
4269template<class _CharT, class _Traits, class _Allocator>
4270inline _LIBCPP_INLINE_VISIBILITY
4271basic_istream<_CharT, _Traits>&
4272getline(basic_istream<_CharT, _Traits>&& __is,
4273 basic_string<_CharT, _Traits, _Allocator>& __str);
4274
Eric Fiselier3e928972017-04-19 00:28:44 +00004275#endif // _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004276
Howard Hinnant499cea12013-08-23 17:37:05 +00004277#if _LIBCPP_DEBUG_LEVEL >= 2
4278
4279template<class _CharT, class _Traits, class _Allocator>
4280bool
4281basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4282{
4283 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4284 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4285}
4286
4287template<class _CharT, class _Traits, class _Allocator>
4288bool
4289basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4290{
4291 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4292 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4293}
4294
4295template<class _CharT, class _Traits, class _Allocator>
4296bool
4297basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4298{
4299 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4300 return this->data() <= __p && __p <= this->data() + this->size();
4301}
4302
4303template<class _CharT, class _Traits, class _Allocator>
4304bool
4305basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4306{
4307 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4308 return this->data() <= __p && __p < this->data() + this->size();
4309}
4310
4311#endif // _LIBCPP_DEBUG_LEVEL >= 2
4312
Shoaib Meenai68506702017-06-29 02:52:46 +00004313_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
4314_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Shoaib Meenai68506702017-06-29 02:52:46 +00004315
Marshall Clow15234322013-07-23 17:05:24 +00004316#if _LIBCPP_STD_VER > 11
4317// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004318inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004319{
4320 inline namespace string_literals
4321 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004322 inline _LIBCPP_INLINE_VISIBILITY
4323 basic_string<char> operator "" s( const char *__str, size_t __len )
4324 {
4325 return basic_string<char> (__str, __len);
4326 }
Marshall Clow15234322013-07-23 17:05:24 +00004327
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004328 inline _LIBCPP_INLINE_VISIBILITY
4329 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4330 {
4331 return basic_string<wchar_t> (__str, __len);
4332 }
Marshall Clow15234322013-07-23 17:05:24 +00004333
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004334 inline _LIBCPP_INLINE_VISIBILITY
4335 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4336 {
4337 return basic_string<char16_t> (__str, __len);
4338 }
Marshall Clow15234322013-07-23 17:05:24 +00004339
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004340 inline _LIBCPP_INLINE_VISIBILITY
4341 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4342 {
4343 return basic_string<char32_t> (__str, __len);
4344 }
Marshall Clow15234322013-07-23 17:05:24 +00004345 }
4346}
4347#endif
4348
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004349_LIBCPP_END_NAMESPACE_STD
4350
Eric Fiselier018a3d52017-05-31 22:07:49 +00004351_LIBCPP_POP_MACROS
4352
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004353#endif // _LIBCPP_STRING