blob: f89ef5741e51d278c0e4e8096f8614c5b37b5b43 [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 Clow1e00d6d2016-07-21 05:31:24 +0000107 explicit basic_string(const basic_string_view<charT, traits> sv, const Allocator& a = Allocator());
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000108 basic_string(const value_type* s, const allocator_type& a = allocator_type());
109 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000110 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
111 template<class InputIterator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000112 basic_string(InputIterator begin, InputIterator end,
113 const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000114 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
115 basic_string(const basic_string&, const Allocator&);
116 basic_string(basic_string&&, const Allocator&);
117
118 ~basic_string();
119
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000120 operator basic_string_view<charT, traits>() const noexcept;
121
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000122 basic_string& operator=(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000123 basic_string& operator=(basic_string_view<charT, traits> sv);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000124 basic_string& operator=(basic_string&& str)
125 noexcept(
Marshall Clowaf961ed2015-08-18 18:57:00 +0000126 allocator_type::propagate_on_container_move_assignment::value ||
127 allocator_type::is_always_equal::value ); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000128 basic_string& operator=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000129 basic_string& operator=(value_type c);
130 basic_string& operator=(initializer_list<value_type>);
131
Howard Hinnanta6119a82011-05-29 19:57:12 +0000132 iterator begin() noexcept;
133 const_iterator begin() const noexcept;
134 iterator end() noexcept;
135 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000136
Howard Hinnanta6119a82011-05-29 19:57:12 +0000137 reverse_iterator rbegin() noexcept;
138 const_reverse_iterator rbegin() const noexcept;
139 reverse_iterator rend() noexcept;
140 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000141
Howard Hinnanta6119a82011-05-29 19:57:12 +0000142 const_iterator cbegin() const noexcept;
143 const_iterator cend() const noexcept;
144 const_reverse_iterator crbegin() const noexcept;
145 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000146
Howard Hinnanta6119a82011-05-29 19:57:12 +0000147 size_type size() const noexcept;
148 size_type length() const noexcept;
149 size_type max_size() const noexcept;
150 size_type capacity() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000151
152 void resize(size_type n, value_type c);
153 void resize(size_type n);
154
155 void reserve(size_type res_arg = 0);
156 void shrink_to_fit();
Howard Hinnanta6119a82011-05-29 19:57:12 +0000157 void clear() noexcept;
158 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000159
160 const_reference operator[](size_type pos) const;
161 reference operator[](size_type pos);
162
163 const_reference at(size_type n) const;
164 reference at(size_type n);
165
166 basic_string& operator+=(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000167 basic_string& operator+=(basic_string_view<charT, traits> sv);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000168 basic_string& operator+=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000169 basic_string& operator+=(value_type c);
170 basic_string& operator+=(initializer_list<value_type>);
171
172 basic_string& append(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000173 basic_string& append(basic_string_view<charT, traits> sv);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000174 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000175 template <class T>
176 basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000177 basic_string& append(const value_type* s, size_type n);
178 basic_string& append(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000179 basic_string& append(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000180 template<class InputIterator>
181 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000182 basic_string& append(initializer_list<value_type>);
183
184 void push_back(value_type c);
185 void pop_back();
186 reference front();
187 const_reference front() const;
188 reference back();
189 const_reference back() const;
190
191 basic_string& assign(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000192 basic_string& assign(basic_string_view<charT, traits> sv);
Howard Hinnanta6119a82011-05-29 19:57:12 +0000193 basic_string& assign(basic_string&& str);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000194 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000195 template <class T>
196 basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000197 basic_string& assign(const value_type* s, size_type n);
198 basic_string& assign(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000199 basic_string& assign(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000200 template<class InputIterator>
201 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000202 basic_string& assign(initializer_list<value_type>);
203
204 basic_string& insert(size_type pos1, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000205 basic_string& insert(size_type pos1, basic_string_view<charT, traits> sv);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000206 basic_string& insert(size_type pos1, const basic_string& str,
207 size_type pos2, size_type n);
Marshall Clow6ac8de02016-09-24 22:45:42 +0000208 template <class T>
209 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
Marshall Clowa93b5e22014-03-04 19:17:19 +0000210 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000211 basic_string& insert(size_type pos, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000212 basic_string& insert(size_type pos, size_type n, value_type c);
213 iterator insert(const_iterator p, value_type c);
214 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000215 template<class InputIterator>
216 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000217 iterator insert(const_iterator p, initializer_list<value_type>);
218
219 basic_string& erase(size_type pos = 0, size_type n = npos);
220 iterator erase(const_iterator position);
221 iterator erase(const_iterator first, const_iterator last);
222
223 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000224 basic_string& replace(size_type pos1, size_type n1, basic_string_view<charT, traits> sv);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000225 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000226 size_type pos2, size_type n2=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000227 template <class T>
228 basic_string& replace(size_type pos1, size_type n1, const T& t,
229 size_type pos2, size_type n); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000230 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
231 basic_string& replace(size_type pos, size_type n1, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000232 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000233 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000234 basic_string& replace(const_iterator i1, const_iterator i2, basic_string_view<charT, traits> sv);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000235 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
236 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000237 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000238 template<class InputIterator>
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000239 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
240 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000241
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000242 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000243 basic_string substr(size_type pos = 0, size_type n = npos) const;
244
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000245 void swap(basic_string& str)
Marshall Clow7d914d12015-07-13 20:04:56 +0000246 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
247 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000248
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000249 const value_type* c_str() const noexcept;
250 const value_type* data() const noexcept;
Marshall Clowf532a702016-03-08 15:44:30 +0000251 value_type* data() noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000252
Howard Hinnanta6119a82011-05-29 19:57:12 +0000253 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000254
Howard Hinnanta6119a82011-05-29 19:57:12 +0000255 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000256 size_type find(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000257 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
258 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000259 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000260
Howard Hinnanta6119a82011-05-29 19:57:12 +0000261 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow0b9db072017-09-07 04:19:32 +0000262 size_type rfind(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000263 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
264 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000265 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000266
Howard Hinnanta6119a82011-05-29 19:57:12 +0000267 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000268 size_type find_first_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000269 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
270 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000271 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000272
Howard Hinnanta6119a82011-05-29 19:57:12 +0000273 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow0b9db072017-09-07 04:19:32 +0000274 size_type find_last_of(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000275 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
276 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000277 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000278
Howard Hinnanta6119a82011-05-29 19:57:12 +0000279 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000280 size_type find_first_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000281 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
282 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000283 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000284
Howard Hinnanta6119a82011-05-29 19:57:12 +0000285 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow0b9db072017-09-07 04:19:32 +0000286 size_type find_last_not_of(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000287 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
288 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000289 size_type find_last_not_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 int compare(const basic_string& str) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000292 int compare(basic_string_view<charT, traits> sv) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000293 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000294 int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv) const;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000295 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000296 size_type pos2, size_type n2=npos) const; // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000297 template <class T>
298 int compare(size_type pos1, size_type n1, const T& t,
299 size_type pos2, size_type n2=npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000300 int compare(const value_type* s) const noexcept;
301 int compare(size_type pos1, size_type n1, const value_type* s) const;
302 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000303
Marshall Clow46b4ad52017-12-04 20:11:38 +0000304 bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
305 bool starts_with(charT c) const noexcept; // C++2a
306 bool starts_with(const charT* s) const; // C++2a
307 bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
308 bool ends_with(charT c) const noexcept; // C++2a
309 bool ends_with(const charT* s) const; // C++2a
310
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000311 bool __invariants() const;
312};
313
314template<class charT, class traits, class Allocator>
315basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000316operator+(const basic_string<charT, traits, Allocator>& lhs,
317 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000318
319template<class charT, class traits, class Allocator>
320basic_string<charT, traits, Allocator>
321operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
322
323template<class charT, class traits, class Allocator>
324basic_string<charT, traits, Allocator>
325operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
326
327template<class charT, class traits, class Allocator>
328basic_string<charT, traits, Allocator>
329operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
330
331template<class charT, class traits, class Allocator>
332basic_string<charT, traits, Allocator>
333operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
334
335template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000336bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000337 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000338
339template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000340bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341
342template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000343bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000344
Howard Hinnant324bb032010-08-22 00:02:43 +0000345template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000346bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000347 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000348
349template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000350bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000351
352template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000353bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000354
355template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000356bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000357 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358
359template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000360bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* 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 Hinnanta6a062d2010-06-02 18:20:39 +0000366bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000367 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000368
369template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000370bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* 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 Hinnanta6a062d2010-06-02 18:20:39 +0000376bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000377 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378
379template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000380bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* 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 charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384
385template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000386bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000387 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388
389template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000390bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* 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 charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394
395template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000396void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000397 basic_string<charT, traits, Allocator>& rhs)
398 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000399
400template<class charT, class traits, class Allocator>
401basic_istream<charT, traits>&
402operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
403
404template<class charT, class traits, class Allocator>
405basic_ostream<charT, traits>&
406operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
407
408template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000409basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000410getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
411 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000412
413template<class charT, class traits, class Allocator>
414basic_istream<charT, traits>&
415getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
416
417typedef basic_string<char> string;
418typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000419typedef basic_string<char16_t> u16string;
420typedef basic_string<char32_t> u32string;
421
422int stoi (const string& str, size_t* idx = 0, int base = 10);
423long stol (const string& str, size_t* idx = 0, int base = 10);
424unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
425long long stoll (const string& str, size_t* idx = 0, int base = 10);
426unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
427
428float stof (const string& str, size_t* idx = 0);
429double stod (const string& str, size_t* idx = 0);
430long double stold(const string& str, size_t* idx = 0);
431
432string to_string(int val);
433string to_string(unsigned val);
434string to_string(long val);
435string to_string(unsigned long val);
436string to_string(long long val);
437string to_string(unsigned long long val);
438string to_string(float val);
439string to_string(double val);
440string to_string(long double val);
441
442int stoi (const wstring& str, size_t* idx = 0, int base = 10);
443long stol (const wstring& str, size_t* idx = 0, int base = 10);
444unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
445long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
446unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
447
448float stof (const wstring& str, size_t* idx = 0);
449double stod (const wstring& str, size_t* idx = 0);
450long double stold(const wstring& str, size_t* idx = 0);
451
452wstring to_wstring(int val);
453wstring to_wstring(unsigned val);
454wstring to_wstring(long val);
455wstring to_wstring(unsigned long val);
456wstring to_wstring(long long val);
457wstring to_wstring(unsigned long long val);
458wstring to_wstring(float val);
459wstring to_wstring(double val);
460wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000461
462template <> struct hash<string>;
463template <> struct hash<u16string>;
464template <> struct hash<u32string>;
465template <> struct hash<wstring>;
466
Marshall Clow15234322013-07-23 17:05:24 +0000467basic_string<char> operator "" s( const char *str, size_t len ); // C++14
468basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
469basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
470basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
471
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000472} // std
473
474*/
475
476#include <__config>
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000477#include <string_view>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000478#include <iosfwd>
479#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000480#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000481#include <cwchar>
482#include <algorithm>
483#include <iterator>
484#include <utility>
485#include <memory>
486#include <stdexcept>
487#include <type_traits>
488#include <initializer_list>
489#include <__functional_base>
490#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
491#include <cstdint>
492#endif
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000493
Eric Fiselierb9536102014-08-10 23:53:08 +0000494#include <__debug>
495
Howard Hinnant08e17472011-10-17 20:05:10 +0000496#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000497#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000498#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000499
Eric Fiselier018a3d52017-05-31 22:07:49 +0000500_LIBCPP_PUSH_MACROS
501#include <__undef_macros>
502
503
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504_LIBCPP_BEGIN_NAMESPACE_STD
505
506// fpos
507
508template <class _StateT>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000509class _LIBCPP_TEMPLATE_VIS fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000510{
511private:
512 _StateT __st_;
513 streamoff __off_;
514public:
515 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
516
517 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
518
519 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
520 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
521
522 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
523 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
524 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
525 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
526};
527
528template <class _StateT>
529inline _LIBCPP_INLINE_VISIBILITY
530streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
531 {return streamoff(__x) - streamoff(__y);}
532
533template <class _StateT>
534inline _LIBCPP_INLINE_VISIBILITY
535bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
536 {return streamoff(__x) == streamoff(__y);}
537
538template <class _StateT>
539inline _LIBCPP_INLINE_VISIBILITY
540bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
541 {return streamoff(__x) != streamoff(__y);}
542
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000543// basic_string
544
545template<class _CharT, class _Traits, class _Allocator>
546basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000547operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
548 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000549
550template<class _CharT, class _Traits, class _Allocator>
551basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000552operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000553
554template<class _CharT, class _Traits, class _Allocator>
555basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000556operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000557
558template<class _CharT, class _Traits, class _Allocator>
559basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000560operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000561
562template<class _CharT, class _Traits, class _Allocator>
563basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000564operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000565
Shoaib Meenai487562f2017-07-29 02:54:41 +0000566_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
567
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000568template <bool>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000569class _LIBCPP_TEMPLATE_VIS __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000570{
571protected:
Marshall Clow14c09a22016-08-25 15:09:01 +0000572 _LIBCPP_NORETURN void __throw_length_error() const;
573 _LIBCPP_NORETURN void __throw_out_of_range() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000574};
575
576template <bool __b>
577void
578__basic_string_common<__b>::__throw_length_error() const
579{
Marshall Clow14c09a22016-08-25 15:09:01 +0000580 _VSTD::__throw_length_error("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581}
582
583template <bool __b>
584void
585__basic_string_common<__b>::__throw_out_of_range() const
586{
Marshall Clow14c09a22016-08-25 15:09:01 +0000587 _VSTD::__throw_out_of_range("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000588}
589
Eric Fiselier833d6442016-09-15 22:27:07 +0000590_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000591
Marshall Clowdf9db312016-01-13 21:54:34 +0000592#ifdef _LIBCPP_NO_EXCEPTIONS
593template <class _Iter>
594struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
595#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
596template <class _Iter>
597struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
598#else
599template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
600struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
601 noexcept(++(declval<_Iter&>())) &&
602 is_nothrow_assignable<_Iter&, _Iter>::value &&
603 noexcept(declval<_Iter>() == declval<_Iter>()) &&
604 noexcept(*declval<_Iter>())
605)) {};
606
607template <class _Iter>
608struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
609#endif
610
611
612template <class _Iter>
613struct __libcpp_string_gets_noexcept_iterator
614 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
615
Marshall Clow6ac8de02016-09-24 22:45:42 +0000616template <class _CharT, class _Traits, class _Tp>
617struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
Marshall Clowf1729d92017-11-15 20:02:27 +0000618 ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
Marshall Clow6ac8de02016-09-24 22:45:42 +0000619 !is_convertible<const _Tp&, const _CharT*>::value)) {};
620
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000621#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000622
623template <class _CharT, size_t = sizeof(_CharT)>
624struct __padding
625{
626 unsigned char __xx[sizeof(_CharT)-1];
627};
628
629template <class _CharT>
630struct __padding<_CharT, 1>
631{
632};
633
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000634#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000635
Howard Hinnant324bb032010-08-22 00:02:43 +0000636template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000637class _LIBCPP_TEMPLATE_VIS basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000638 : private __basic_string_common<true>
639{
640public:
641 typedef basic_string __self;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000642 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643 typedef _Traits traits_type;
Marshall Clow2d4c3fa2017-03-15 18:41:11 +0000644 typedef _CharT value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000645 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000646 typedef allocator_traits<allocator_type> __alloc_traits;
647 typedef typename __alloc_traits::size_type size_type;
648 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000649 typedef value_type& reference;
650 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000651 typedef typename __alloc_traits::pointer pointer;
652 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000653
Marshall Clow46ea17e2018-01-22 00:17:48 +0000654 static_assert(is_trivial<value_type>::value, "Character type of basic_string must be trivial");
Marshall Clow2d4c3fa2017-03-15 18:41:11 +0000655 static_assert((is_same<_CharT, typename traits_type::char_type>::value),
Howard Hinnant499cea12013-08-23 17:37:05 +0000656 "traits_type::char_type must be the same type as CharT");
657 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
658 "Allocator::value_type must be same type as value_type");
659#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000660 typedef pointer iterator;
661 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000662#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000663 typedef __wrap_iter<pointer> iterator;
664 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000665#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000666 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
667 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668
669private:
Howard Hinnant15467182013-04-30 21:44:48 +0000670
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000671#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000672
673 struct __long
674 {
675 pointer __data_;
676 size_type __size_;
677 size_type __cap_;
678 };
679
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000680#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000681 static const size_type __short_mask = 0x01;
682 static const size_type __long_mask = 0x1ul;
Howard Hinnant15467182013-04-30 21:44:48 +0000683#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000684 static const size_type __short_mask = 0x80;
685 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant15467182013-04-30 21:44:48 +0000686#endif // _LIBCPP_BIG_ENDIAN
687
688 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
689 (sizeof(__long) - 1)/sizeof(value_type) : 2};
690
691 struct __short
692 {
693 value_type __data_[__min_cap];
694 struct
695 : __padding<value_type>
696 {
697 unsigned char __size_;
698 };
699 };
700
701#else
702
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000703 struct __long
704 {
705 size_type __cap_;
706 size_type __size_;
707 pointer __data_;
708 };
709
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000710#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000711 static const size_type __short_mask = 0x80;
712 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant324bb032010-08-22 00:02:43 +0000713#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000714 static const size_type __short_mask = 0x01;
715 static const size_type __long_mask = 0x1ul;
Howard Hinnant324bb032010-08-22 00:02:43 +0000716#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000717
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000718 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
719 (sizeof(__long) - 1)/sizeof(value_type) : 2};
720
721 struct __short
722 {
723 union
724 {
725 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +0000726 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000727 };
728 value_type __data_[__min_cap];
729 };
730
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000731#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000732
Howard Hinnant499cea12013-08-23 17:37:05 +0000733 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734
Howard Hinnant499cea12013-08-23 17:37:05 +0000735 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000736
737 struct __raw
738 {
739 size_type __words[__n_words];
740 };
741
742 struct __rep
743 {
744 union
745 {
746 __long __l;
747 __short __s;
748 __raw __r;
749 };
750 };
751
752 __compressed_pair<__rep, allocator_type> __r_;
753
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000754public:
755 static const size_type npos = -1;
756
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000757 _LIBCPP_INLINE_VISIBILITY basic_string()
758 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000759
760 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
761#if _LIBCPP_STD_VER <= 14
762 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
763#else
764 _NOEXCEPT;
765#endif
766
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000767 basic_string(const basic_string& __str);
768 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +0000769
Eric Fiselier3e928972017-04-19 00:28:44 +0000770#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant9f193f22011-01-26 00:06:59 +0000771 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000772 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +0000773#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000774 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000775#else
776 _NOEXCEPT;
777#endif
778
Howard Hinnant9f193f22011-01-26 00:06:59 +0000779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000780 basic_string(basic_string&& __str, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000781#endif // _LIBCPP_CXX03_LANG
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000782 _LIBCPP_INLINE_VISIBILITY basic_string(const _CharT* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000783 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000784 basic_string(const _CharT* __s, const _Allocator& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000785 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000786 basic_string(const _CharT* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000787 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000788 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000789 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000790 basic_string(size_type __n, _CharT __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000791 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000792 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000793 basic_string(const basic_string& __str, size_type __pos, size_type __n,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000794 const _Allocator& __a = _Allocator());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000795 _LIBCPP_INLINE_VISIBILITY
796 basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000797 const _Allocator& __a = _Allocator());
Marshall Clowdb7fa112016-11-14 18:22:19 +0000798 template<class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +0000799 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000800 basic_string(const _Tp& __t, size_type __pos, size_type __n,
Marshall Clowdb7fa112016-11-14 18:22:19 +0000801 const allocator_type& __a = allocator_type(),
802 typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type* = 0);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000803 _LIBCPP_INLINE_VISIBILITY explicit
804 basic_string(__self_view __sv);
805 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000806 basic_string(__self_view __sv, const _Allocator& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000807 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000808 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000809 basic_string(_InputIterator __first, _InputIterator __last);
810 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000812 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000813#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000814 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000815 basic_string(initializer_list<_CharT> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000816 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000817 basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000818#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819
Eric Fiselier51eb1d52016-10-31 03:42:50 +0000820 inline ~basic_string();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000821
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000822 _LIBCPP_INLINE_VISIBILITY
823 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
824
Howard Hinnante32b5e22010-11-17 17:55:08 +0000825 basic_string& operator=(const basic_string& __str);
Eric Fiselierf472d6c2017-01-23 21:24:58 +0000826
827#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier37b2be92017-01-17 22:10:32 +0000828 template <class = void>
Eric Fiselierf472d6c2017-01-23 21:24:58 +0000829#endif
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000830 _LIBCPP_INLINE_VISIBILITY
831 basic_string& operator=(__self_view __sv) {return assign(__sv);}
Eric Fiselier3e928972017-04-19 00:28:44 +0000832#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000834 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +0000835 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Eric Fiselier3e928972017-04-19 00:28:44 +0000836 _LIBCPP_INLINE_VISIBILITY
837 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000839 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000840 basic_string& operator=(value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841
Howard Hinnant499cea12013-08-23 17:37:05 +0000842#if _LIBCPP_DEBUG_LEVEL >= 2
843 _LIBCPP_INLINE_VISIBILITY
844 iterator begin() _NOEXCEPT
845 {return iterator(this, __get_pointer());}
846 _LIBCPP_INLINE_VISIBILITY
847 const_iterator begin() const _NOEXCEPT
848 {return const_iterator(this, __get_pointer());}
849 _LIBCPP_INLINE_VISIBILITY
850 iterator end() _NOEXCEPT
851 {return iterator(this, __get_pointer() + size());}
852 _LIBCPP_INLINE_VISIBILITY
853 const_iterator end() const _NOEXCEPT
854 {return const_iterator(this, __get_pointer() + size());}
855#else
Howard Hinnanta6119a82011-05-29 19:57:12 +0000856 _LIBCPP_INLINE_VISIBILITY
857 iterator begin() _NOEXCEPT
858 {return iterator(__get_pointer());}
859 _LIBCPP_INLINE_VISIBILITY
860 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000861 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000862 _LIBCPP_INLINE_VISIBILITY
863 iterator end() _NOEXCEPT
864 {return iterator(__get_pointer() + size());}
865 _LIBCPP_INLINE_VISIBILITY
866 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000867 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +0000868#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +0000869 _LIBCPP_INLINE_VISIBILITY
870 reverse_iterator rbegin() _NOEXCEPT
871 {return reverse_iterator(end());}
872 _LIBCPP_INLINE_VISIBILITY
873 const_reverse_iterator rbegin() const _NOEXCEPT
874 {return const_reverse_iterator(end());}
875 _LIBCPP_INLINE_VISIBILITY
876 reverse_iterator rend() _NOEXCEPT
877 {return reverse_iterator(begin());}
878 _LIBCPP_INLINE_VISIBILITY
879 const_reverse_iterator rend() const _NOEXCEPT
880 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000881
Howard Hinnanta6119a82011-05-29 19:57:12 +0000882 _LIBCPP_INLINE_VISIBILITY
883 const_iterator cbegin() const _NOEXCEPT
884 {return begin();}
885 _LIBCPP_INLINE_VISIBILITY
886 const_iterator cend() const _NOEXCEPT
887 {return end();}
888 _LIBCPP_INLINE_VISIBILITY
889 const_reverse_iterator crbegin() const _NOEXCEPT
890 {return rbegin();}
891 _LIBCPP_INLINE_VISIBILITY
892 const_reverse_iterator crend() const _NOEXCEPT
893 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000894
Howard Hinnanta6119a82011-05-29 19:57:12 +0000895 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000897 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
898 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
899 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +0000900 {return (__is_long() ? __get_long_cap()
901 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000902
903 void resize(size_type __n, value_type __c);
904 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
905
Eric Fiselier59e24fe2017-06-01 02:29:37 +0000906 void reserve(size_type __res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000908 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +0000910 void clear() _NOEXCEPT;
Marshall Clowf1729d92017-11-15 20:02:27 +0000911 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
912 bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000913
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000914 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
915 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000916
917 const_reference at(size_type __n) const;
918 reference at(size_type __n);
919
920 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000921 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(__self_view __sv) {return append(__sv);}
922 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000923 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Eric Fiselier3e928972017-04-19 00:28:44 +0000924#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Eric Fiselier3e928972017-04-19 00:28:44 +0000926#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000927
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000928 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000929 basic_string& append(const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000930 _LIBCPP_INLINE_VISIBILITY
931 basic_string& append(__self_view __sv) { return append(__sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +0000932 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48 +0000933 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +0000934 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
935 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +0000936 <
937 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
938 basic_string&
939 >::type
940 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000941 basic_string& append(const value_type* __s, size_type __n);
942 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000943 basic_string& append(size_type __n, value_type __c);
Eric Fiselier026d38e2016-10-31 02:46:25 +0000944 template <class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +0000945 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
946 basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +0000948 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
949 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000950 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000951 __is_exactly_input_iterator<_InputIterator>::value
952 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000953 basic_string&
954 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +0000955 _LIBCPP_INLINE_VISIBILITY
956 append(_InputIterator __first, _InputIterator __last) {
957 const basic_string __temp (__first, __last, __alloc());
958 append(__temp.data(), __temp.size());
959 return *this;
960 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000961 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +0000962 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
963 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000964 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000965 __is_forward_iterator<_ForwardIterator>::value
966 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000967 basic_string&
968 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +0000969 _LIBCPP_INLINE_VISIBILITY
970 append(_ForwardIterator __first, _ForwardIterator __last) {
971 return __append_forward_unsafe(__first, __last);
972 }
973
Eric Fiselier3e928972017-04-19 00:28:44 +0000974#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000975 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +0000977#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000978
979 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000981 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000982 _LIBCPP_INLINE_VISIBILITY reference front();
983 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
984 _LIBCPP_INLINE_VISIBILITY reference back();
985 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000986
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000987 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000988 basic_string& assign(__self_view __sv) { return assign(__sv.data(), __sv.size()); }
989 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29 +0000990 basic_string& assign(const basic_string& __str) { return *this = __str; }
Eric Fiselier3e928972017-04-19 00:28:44 +0000991#ifndef _LIBCPP_CXX03_LANG
Howard Hinnanta6119a82011-05-29 19:57:12 +0000992 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier59e24fe2017-06-01 02:29:37 +0000993 basic_string& assign(basic_string&& __str)
Marshall Clow7ed093b2015-10-05 16:17:34 +0000994 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Eric Fiselier59e24fe2017-06-01 02:29:37 +0000995 {*this = _VSTD::move(__str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000996#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +0000997 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48 +0000998 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +0000999 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1000 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001001 <
1002 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1003 basic_string&
1004 >::type
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001005 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001006 basic_string& assign(const value_type* __s, size_type __n);
1007 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001008 basic_string& assign(size_type __n, value_type __c);
1009 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001010 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1011 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001012 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001013 __is_exactly_input_iterator<_InputIterator>::value
1014 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001015 basic_string&
1016 >::type
1017 assign(_InputIterator __first, _InputIterator __last);
1018 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001019 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1020 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001021 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001022 __is_forward_iterator<_ForwardIterator>::value
1023 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001024 basic_string&
1025 >::type
1026 assign(_ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001027#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001028 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001029 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001030#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001031
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001033 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001034 _LIBCPP_INLINE_VISIBILITY
1035 basic_string& insert(size_type __pos1, __self_view __sv) { return insert(__pos1, __sv.data(), __sv.size()); }
Marshall Clow6ac8de02016-09-24 22:45:42 +00001036 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001037 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1038 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001039 <
1040 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1041 basic_string&
1042 >::type
1043 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001044 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001045 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1046 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001047 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1048 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001050 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1051 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001052 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1053 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001055 __is_exactly_input_iterator<_InputIterator>::value
1056 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001057 iterator
1058 >::type
1059 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1060 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001061 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1062 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001063 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001064 __is_forward_iterator<_ForwardIterator>::value
1065 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001066 iterator
1067 >::type
1068 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001069#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001070 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001071 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1072 {return insert(__pos, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001073#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001074
1075 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001077 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001078 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001079 iterator erase(const_iterator __first, const_iterator __last);
1080
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001081 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001082 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001083 _LIBCPP_INLINE_VISIBILITY
1084 basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv) { return replace(__pos1, __n1, __sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +00001085 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 +00001086 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001087 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1088 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001089 <
1090 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1091 basic_string&
1092 >::type
1093 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001094 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1095 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001096 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001098 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001099 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001100 basic_string& replace(const_iterator __i1, const_iterator __i2, __self_view __sv) { return replace(__i1 - begin(), __i2 - __i1, __sv); }
1101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001102 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001104 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001105 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001106 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001107 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001108 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1109 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001110 <
1111 __is_input_iterator<_InputIterator>::value,
1112 basic_string&
1113 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001114 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Eric Fiselier3e928972017-04-19 00:28:44 +00001115#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001116 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001117 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001118 {return replace(__i1, __i2, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001119#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001121 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001123 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1124
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001125 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001126 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001127#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00001128 _NOEXCEPT_DEBUG;
Marshall Clow7d914d12015-07-13 20:04:56 +00001129#else
Eric Fiselier47257c42016-12-28 05:53:01 +00001130 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00001131 __is_nothrow_swappable<allocator_type>::value);
1132#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001133
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001134 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001135 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001136 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001137 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Eric Fiselier10bebe22017-11-20 20:23:27 +00001138#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
Marshall Clowf532a702016-03-08 15:44:30 +00001139 _LIBCPP_INLINE_VISIBILITY
1140 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1141#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001142
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001144 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001145
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001146 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001147 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001148 _LIBCPP_INLINE_VISIBILITY
1149 size_type find(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001150 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001151 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001152 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001153 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001156 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001157 _LIBCPP_INLINE_VISIBILITY
Marshall Clow0b9db072017-09-07 04:19:32 +00001158 size_type rfind(__self_view __sv, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001159 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001161 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001162 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001165 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001166 _LIBCPP_INLINE_VISIBILITY
1167 size_type find_first_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001168 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001170 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001172 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001173
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001174 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001175 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001176 _LIBCPP_INLINE_VISIBILITY
Marshall Clow0b9db072017-09-07 04:19:32 +00001177 size_type find_last_of(__self_view __sv, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001178 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001179 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001180 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001181 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001182 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001183
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001184 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001185 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001186 _LIBCPP_INLINE_VISIBILITY
1187 size_type find_first_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001188 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 +00001189 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001190 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001191 _LIBCPP_INLINE_VISIBILITY
1192 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1193
1194 _LIBCPP_INLINE_VISIBILITY
1195 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001196 _LIBCPP_INLINE_VISIBILITY
Marshall Clow0b9db072017-09-07 04:19:32 +00001197 size_type find_last_not_of(__self_view __sv, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001198 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 +00001199 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001200 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001201 _LIBCPP_INLINE_VISIBILITY
1202 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1203
1204 _LIBCPP_INLINE_VISIBILITY
1205 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001206 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001207 int compare(__self_view __sv) const _NOEXCEPT;
1208 _LIBCPP_INLINE_VISIBILITY
1209 int compare(size_type __pos1, size_type __n1, __self_view __sv) const;
1210 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001211 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001212 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
Marshall Clow6ac8de02016-09-24 22:45:42 +00001213 template <class _Tp>
Eric Fiselier9dbc0532016-10-14 05:29:46 +00001214 inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow6ac8de02016-09-24 22:45:42 +00001215 typename enable_if
1216 <
1217 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1218 int
1219 >::type
1220 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 +00001221 int compare(const value_type* __s) const _NOEXCEPT;
1222 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1223 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001224
Marshall Clow46b4ad52017-12-04 20:11:38 +00001225#if _LIBCPP_STD_VER > 17
1226 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1227 bool starts_with(__self_view __sv) const _NOEXCEPT
1228 { return __self_view(data(), size()).starts_with(__sv); }
1229
1230 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1231 bool starts_with(value_type __c) const _NOEXCEPT
1232 { return !empty() && _Traits::eq(front(), __c); }
1233
1234 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1235 bool starts_with(const value_type* __s) const _NOEXCEPT
1236 { return starts_with(__self_view(__s)); }
1237
1238 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1239 bool ends_with(__self_view __sv) const _NOEXCEPT
1240 { return __self_view(data(), size()).ends_with( __sv); }
1241
1242 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1243 bool ends_with(value_type __c) const _NOEXCEPT
1244 { return !empty() && _Traits::eq(back(), __c); }
1245
1246 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1247 bool ends_with(const value_type* __s) const _NOEXCEPT
1248 { return ends_with(__self_view(__s)); }
1249#endif
1250
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001251 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001252
1253 _LIBCPP_INLINE_VISIBILITY
1254 bool __is_long() const _NOEXCEPT
1255 {return bool(__r_.first().__s.__size_ & __short_mask);}
1256
Howard Hinnant499cea12013-08-23 17:37:05 +00001257#if _LIBCPP_DEBUG_LEVEL >= 2
1258
1259 bool __dereferenceable(const const_iterator* __i) const;
1260 bool __decrementable(const const_iterator* __i) const;
1261 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1262 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1263
1264#endif // _LIBCPP_DEBUG_LEVEL >= 2
1265
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001266private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001267 _LIBCPP_INLINE_VISIBILITY
1268 allocator_type& __alloc() _NOEXCEPT
1269 {return __r_.second();}
1270 _LIBCPP_INLINE_VISIBILITY
1271 const allocator_type& __alloc() const _NOEXCEPT
1272 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001273
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001274#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001275
Howard Hinnanta6119a82011-05-29 19:57:12 +00001276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001277 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001278# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001279 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001280# else
1281 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1282# endif
1283
Howard Hinnanta6119a82011-05-29 19:57:12 +00001284 _LIBCPP_INLINE_VISIBILITY
1285 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001286# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001287 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001288# else
1289 {return __r_.first().__s.__size_;}
1290# endif
1291
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001292#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001293
1294 _LIBCPP_INLINE_VISIBILITY
1295 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001296# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001297 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1298# else
1299 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1300# endif
1301
1302 _LIBCPP_INLINE_VISIBILITY
1303 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001304# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001305 {return __r_.first().__s.__size_;}
1306# else
1307 {return __r_.first().__s.__size_ >> 1;}
1308# endif
1309
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001310#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001311
Howard Hinnanta6119a82011-05-29 19:57:12 +00001312 _LIBCPP_INLINE_VISIBILITY
1313 void __set_long_size(size_type __s) _NOEXCEPT
1314 {__r_.first().__l.__size_ = __s;}
1315 _LIBCPP_INLINE_VISIBILITY
1316 size_type __get_long_size() const _NOEXCEPT
1317 {return __r_.first().__l.__size_;}
1318 _LIBCPP_INLINE_VISIBILITY
1319 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001320 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1321
Howard Hinnanta6119a82011-05-29 19:57:12 +00001322 _LIBCPP_INLINE_VISIBILITY
1323 void __set_long_cap(size_type __s) _NOEXCEPT
1324 {__r_.first().__l.__cap_ = __long_mask | __s;}
1325 _LIBCPP_INLINE_VISIBILITY
1326 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001327 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001328
Howard Hinnanta6119a82011-05-29 19:57:12 +00001329 _LIBCPP_INLINE_VISIBILITY
1330 void __set_long_pointer(pointer __p) _NOEXCEPT
1331 {__r_.first().__l.__data_ = __p;}
1332 _LIBCPP_INLINE_VISIBILITY
1333 pointer __get_long_pointer() _NOEXCEPT
1334 {return __r_.first().__l.__data_;}
1335 _LIBCPP_INLINE_VISIBILITY
1336 const_pointer __get_long_pointer() const _NOEXCEPT
1337 {return __r_.first().__l.__data_;}
1338 _LIBCPP_INLINE_VISIBILITY
1339 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001340 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001341 _LIBCPP_INLINE_VISIBILITY
1342 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001343 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001344 _LIBCPP_INLINE_VISIBILITY
1345 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001346 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001347 _LIBCPP_INLINE_VISIBILITY
1348 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001349 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1350
Howard Hinnanta6119a82011-05-29 19:57:12 +00001351 _LIBCPP_INLINE_VISIBILITY
1352 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001353 {
1354 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1355 for (unsigned __i = 0; __i < __n_words; ++__i)
1356 __a[__i] = 0;
1357 }
1358
1359 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001360 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001361 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001362 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001363 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001364 static _LIBCPP_INLINE_VISIBILITY
1365 size_type __recommend(size_type __s) _NOEXCEPT
Marshall Clow088e6012018-02-07 21:30:17 +00001366 {
1367 if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
1368 size_type __guess = __align_it<sizeof(value_type) < __alignment ?
1369 __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
1370 if (__guess == __min_cap) ++__guess;
1371 return __guess;
1372 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001373
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001374 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001375 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001376 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001377 void __init(const value_type* __s, size_type __sz);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001378 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001379 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001380
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001381 template <class _InputIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001382 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001383 typename enable_if
1384 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001385 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001386 void
1387 >::type
1388 __init(_InputIterator __first, _InputIterator __last);
1389
1390 template <class _ForwardIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001391 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001392 typename enable_if
1393 <
1394 __is_forward_iterator<_ForwardIterator>::value,
1395 void
1396 >::type
1397 __init(_ForwardIterator __first, _ForwardIterator __last);
1398
1399 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001400 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001401 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1402 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001403 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001404
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001405 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001406 void __erase_to_end(size_type __pos);
1407
Howard Hinnante32b5e22010-11-17 17:55:08 +00001408 _LIBCPP_INLINE_VISIBILITY
1409 void __copy_assign_alloc(const basic_string& __str)
1410 {__copy_assign_alloc(__str, integral_constant<bool,
1411 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1412
1413 _LIBCPP_INLINE_VISIBILITY
1414 void __copy_assign_alloc(const basic_string& __str, true_type)
1415 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001416 if (__alloc() == __str.__alloc())
1417 __alloc() = __str.__alloc();
1418 else
Howard Hinnante32b5e22010-11-17 17:55:08 +00001419 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001420 if (!__str.__is_long())
1421 {
1422 clear();
1423 shrink_to_fit();
1424 __alloc() = __str.__alloc();
1425 }
1426 else
1427 {
1428 allocator_type __a = __str.__alloc();
1429 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
1430 clear();
1431 shrink_to_fit();
1432 __alloc() = _VSTD::move(__a);
1433 __set_long_pointer(__p);
1434 __set_long_cap(__str.__get_long_cap());
1435 __set_long_size(__str.size());
1436 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001437 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001438 }
1439
1440 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001441 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001442 {}
1443
Eric Fiselier3e928972017-04-19 00:28:44 +00001444#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001445 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001446 void __move_assign(basic_string& __str, false_type)
1447 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001449 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001450#if _LIBCPP_STD_VER > 14
1451 _NOEXCEPT;
1452#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001453 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001454#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001455#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001456
1457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001458 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001459 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001460 _NOEXCEPT_(
1461 !__alloc_traits::propagate_on_container_move_assignment::value ||
1462 is_nothrow_move_assignable<allocator_type>::value)
1463 {__move_assign_alloc(__str, integral_constant<bool,
1464 __alloc_traits::propagate_on_container_move_assignment::value>());}
1465
1466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001467 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001468 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1469 {
1470 __alloc() = _VSTD::move(__c.__alloc());
1471 }
1472
1473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001474 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001475 _NOEXCEPT
1476 {}
1477
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001478 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1479 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001480
1481 friend basic_string operator+<>(const basic_string&, const basic_string&);
1482 friend basic_string operator+<>(const value_type*, const basic_string&);
1483 friend basic_string operator+<>(value_type, const basic_string&);
1484 friend basic_string operator+<>(const basic_string&, const value_type*);
1485 friend basic_string operator+<>(const basic_string&, value_type);
1486};
1487
1488template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001489inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001490void
1491basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1492{
Howard Hinnant499cea12013-08-23 17:37:05 +00001493#if _LIBCPP_DEBUG_LEVEL >= 2
1494 __get_db()->__invalidate_all(this);
1495#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001496}
1497
1498template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001499inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001500void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001501basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001502#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001503 __pos
1504#endif
1505 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001506{
Howard Hinnant499cea12013-08-23 17:37:05 +00001507#if _LIBCPP_DEBUG_LEVEL >= 2
1508 __c_node* __c = __get_db()->__find_c_and_lock(this);
1509 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001510 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001511 const_pointer __new_last = __get_pointer() + __pos;
1512 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001513 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001514 --__p;
1515 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1516 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001517 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001518 (*__p)->__c_ = nullptr;
1519 if (--__c->end_ != __p)
1520 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001521 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001522 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001523 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001524 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001525#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001526}
1527
1528template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001529inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001530basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001531 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001532{
Howard Hinnant499cea12013-08-23 17:37:05 +00001533#if _LIBCPP_DEBUG_LEVEL >= 2
1534 __get_db()->__insert_c(this);
1535#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001536 __zero();
1537}
1538
1539template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001540inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001541basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001542#if _LIBCPP_STD_VER <= 14
1543 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1544#else
1545 _NOEXCEPT
1546#endif
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001547: __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548{
Howard Hinnant499cea12013-08-23 17:37:05 +00001549#if _LIBCPP_DEBUG_LEVEL >= 2
1550 __get_db()->__insert_c(this);
1551#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001552 __zero();
1553}
1554
1555template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001556void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1557 size_type __sz,
1558 size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001559{
1560 if (__reserve > max_size())
1561 this->__throw_length_error();
1562 pointer __p;
1563 if (__reserve < __min_cap)
1564 {
1565 __set_short_size(__sz);
1566 __p = __get_short_pointer();
1567 }
1568 else
1569 {
1570 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001571 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001572 __set_long_pointer(__p);
1573 __set_long_cap(__cap+1);
1574 __set_long_size(__sz);
1575 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001576 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001577 traits_type::assign(__p[__sz], value_type());
1578}
1579
1580template <class _CharT, class _Traits, class _Allocator>
1581void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001582basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001583{
1584 if (__sz > max_size())
1585 this->__throw_length_error();
1586 pointer __p;
1587 if (__sz < __min_cap)
1588 {
1589 __set_short_size(__sz);
1590 __p = __get_short_pointer();
1591 }
1592 else
1593 {
1594 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001595 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001596 __set_long_pointer(__p);
1597 __set_long_cap(__cap+1);
1598 __set_long_size(__sz);
1599 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001600 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001601 traits_type::assign(__p[__sz], value_type());
1602}
1603
1604template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001605inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001606basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001607{
Howard Hinnant499cea12013-08-23 17:37:05 +00001608 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001609 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001610#if _LIBCPP_DEBUG_LEVEL >= 2
1611 __get_db()->__insert_c(this);
1612#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001613}
1614
1615template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001616inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001617basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001618 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001619{
Howard Hinnant499cea12013-08-23 17:37:05 +00001620 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001621 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001622#if _LIBCPP_DEBUG_LEVEL >= 2
1623 __get_db()->__insert_c(this);
1624#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001625}
1626
1627template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001628inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001629basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001630{
Howard Hinnant499cea12013-08-23 17:37:05 +00001631 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001632 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001633#if _LIBCPP_DEBUG_LEVEL >= 2
1634 __get_db()->__insert_c(this);
1635#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001636}
1637
1638template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001639inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001640basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001641 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001642{
Howard Hinnant499cea12013-08-23 17:37:05 +00001643 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001644 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001645#if _LIBCPP_DEBUG_LEVEL >= 2
1646 __get_db()->__insert_c(this);
1647#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001648}
1649
1650template <class _CharT, class _Traits, class _Allocator>
1651basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001652 : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001653{
1654 if (!__str.__is_long())
1655 __r_.first().__r = __str.__r_.first().__r;
1656 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001657 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001658#if _LIBCPP_DEBUG_LEVEL >= 2
1659 __get_db()->__insert_c(this);
1660#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001661}
1662
1663template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001664basic_string<_CharT, _Traits, _Allocator>::basic_string(
1665 const basic_string& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001666 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001667{
1668 if (!__str.__is_long())
1669 __r_.first().__r = __str.__r_.first().__r;
1670 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001671 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001672#if _LIBCPP_DEBUG_LEVEL >= 2
1673 __get_db()->__insert_c(this);
1674#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001675}
1676
Eric Fiselier3e928972017-04-19 00:28:44 +00001677#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001678
1679template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001680inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001681basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001682#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001683 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00001684#else
1685 _NOEXCEPT
1686#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001687 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001688{
1689 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00001690#if _LIBCPP_DEBUG_LEVEL >= 2
1691 __get_db()->__insert_c(this);
1692 if (__is_long())
1693 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001694#endif
1695}
1696
1697template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001698inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001699basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001700 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001701{
Marshall Clowd5549cc2014-07-17 15:32:20 +00001702 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001703 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00001704 else
1705 {
1706 __r_.first().__r = __str.__r_.first().__r;
1707 __str.__zero();
1708 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001709#if _LIBCPP_DEBUG_LEVEL >= 2
1710 __get_db()->__insert_c(this);
1711 if (__is_long())
1712 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001713#endif
1714}
1715
Eric Fiselier3e928972017-04-19 00:28:44 +00001716#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001717
1718template <class _CharT, class _Traits, class _Allocator>
1719void
1720basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1721{
1722 if (__n > max_size())
1723 this->__throw_length_error();
1724 pointer __p;
1725 if (__n < __min_cap)
1726 {
1727 __set_short_size(__n);
1728 __p = __get_short_pointer();
1729 }
1730 else
1731 {
1732 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001733 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001734 __set_long_pointer(__p);
1735 __set_long_cap(__cap+1);
1736 __set_long_size(__n);
1737 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001738 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001739 traits_type::assign(__p[__n], value_type());
1740}
1741
1742template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001743inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001744basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001745{
1746 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001747#if _LIBCPP_DEBUG_LEVEL >= 2
1748 __get_db()->__insert_c(this);
1749#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001750}
1751
1752template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001753inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001754basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001755 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001756{
1757 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001758#if _LIBCPP_DEBUG_LEVEL >= 2
1759 __get_db()->__insert_c(this);
1760#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001761}
1762
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001763template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001764basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1765 size_type __pos, size_type __n,
1766 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001767 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001768{
1769 size_type __str_sz = __str.size();
1770 if (__pos > __str_sz)
1771 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001772 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00001773#if _LIBCPP_DEBUG_LEVEL >= 2
1774 __get_db()->__insert_c(this);
1775#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001776}
1777
1778template <class _CharT, class _Traits, class _Allocator>
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001779inline _LIBCPP_INLINE_VISIBILITY
1780basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001781 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001782 : __r_(__second_tag(), __a)
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001783{
1784 size_type __str_sz = __str.size();
1785 if (__pos > __str_sz)
1786 this->__throw_out_of_range();
1787 __init(__str.data() + __pos, __str_sz - __pos);
1788#if _LIBCPP_DEBUG_LEVEL >= 2
1789 __get_db()->__insert_c(this);
1790#endif
1791}
1792
1793template <class _CharT, class _Traits, class _Allocator>
Marshall Clowdb7fa112016-11-14 18:22:19 +00001794template <class _Tp>
1795basic_string<_CharT, _Traits, _Allocator>::basic_string(
1796 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a,
Marshall Clowf1729d92017-11-15 20:02:27 +00001797 typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type *)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001798 : __r_(__second_tag(), __a)
Marshall Clowdb7fa112016-11-14 18:22:19 +00001799{
Marshall Clowf1729d92017-11-15 20:02:27 +00001800 __self_view __sv = __self_view(__t).substr(__pos, __n);
Marshall Clowdb7fa112016-11-14 18:22:19 +00001801 __init(__sv.data(), __sv.size());
1802#if _LIBCPP_DEBUG_LEVEL >= 2
1803 __get_db()->__insert_c(this);
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001804#endif
Marshall Clowdb7fa112016-11-14 18:22:19 +00001805}
1806
1807template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001808inline _LIBCPP_INLINE_VISIBILITY
1809basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv)
1810{
1811 __init(__sv.data(), __sv.size());
1812#if _LIBCPP_DEBUG_LEVEL >= 2
1813 __get_db()->__insert_c(this);
1814#endif
1815}
1816
1817template <class _CharT, class _Traits, class _Allocator>
1818inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001819basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001820 : __r_(__second_tag(), __a)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001821{
1822 __init(__sv.data(), __sv.size());
1823#if _LIBCPP_DEBUG_LEVEL >= 2
1824 __get_db()->__insert_c(this);
1825#endif
1826}
1827
1828template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001829template <class _InputIterator>
1830typename enable_if
1831<
Marshall Clowdf9db312016-01-13 21:54:34 +00001832 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001833 void
1834>::type
1835basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
1836{
1837 __zero();
1838#ifndef _LIBCPP_NO_EXCEPTIONS
1839 try
1840 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001841#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001842 for (; __first != __last; ++__first)
1843 push_back(*__first);
1844#ifndef _LIBCPP_NO_EXCEPTIONS
1845 }
1846 catch (...)
1847 {
1848 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001849 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001850 throw;
1851 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001852#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001853}
1854
1855template <class _CharT, class _Traits, class _Allocator>
1856template <class _ForwardIterator>
1857typename enable_if
1858<
1859 __is_forward_iterator<_ForwardIterator>::value,
1860 void
1861>::type
1862basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
1863{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001864 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001865 if (__sz > max_size())
1866 this->__throw_length_error();
1867 pointer __p;
1868 if (__sz < __min_cap)
1869 {
1870 __set_short_size(__sz);
1871 __p = __get_short_pointer();
1872 }
1873 else
1874 {
1875 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001876 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001877 __set_long_pointer(__p);
1878 __set_long_cap(__cap+1);
1879 __set_long_size(__sz);
1880 }
Eric Fiselierb9919752014-10-27 19:28:20 +00001881 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001882 traits_type::assign(*__p, *__first);
1883 traits_type::assign(*__p, value_type());
1884}
1885
1886template <class _CharT, class _Traits, class _Allocator>
1887template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001888inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001889basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
1890{
1891 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00001892#if _LIBCPP_DEBUG_LEVEL >= 2
1893 __get_db()->__insert_c(this);
1894#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001895}
1896
1897template <class _CharT, class _Traits, class _Allocator>
1898template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001899inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001900basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
1901 const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001902 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001903{
1904 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00001905#if _LIBCPP_DEBUG_LEVEL >= 2
1906 __get_db()->__insert_c(this);
1907#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001908}
1909
Eric Fiselier3e928972017-04-19 00:28:44 +00001910#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00001911
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001912template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001913inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001914basic_string<_CharT, _Traits, _Allocator>::basic_string(
1915 initializer_list<_CharT> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001916{
1917 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00001918#if _LIBCPP_DEBUG_LEVEL >= 2
1919 __get_db()->__insert_c(this);
1920#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001921}
1922
1923template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001924inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001925
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001926basic_string<_CharT, _Traits, _Allocator>::basic_string(
1927 initializer_list<_CharT> __il, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001928 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001929{
1930 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00001931#if _LIBCPP_DEBUG_LEVEL >= 2
1932 __get_db()->__insert_c(this);
1933#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001934}
1935
Eric Fiselier3e928972017-04-19 00:28:44 +00001936#endif // _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00001937
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001938template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001939basic_string<_CharT, _Traits, _Allocator>::~basic_string()
1940{
Howard Hinnant499cea12013-08-23 17:37:05 +00001941#if _LIBCPP_DEBUG_LEVEL >= 2
1942 __get_db()->__erase_c(this);
1943#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001944 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001945 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001946}
1947
1948template <class _CharT, class _Traits, class _Allocator>
1949void
1950basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
1951 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001952 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 +00001953{
1954 size_type __ms = max_size();
1955 if (__delta_cap > __ms - __old_cap - 1)
1956 this->__throw_length_error();
1957 pointer __old_p = __get_pointer();
1958 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00001959 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001960 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001961 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001962 __invalidate_all_iterators();
1963 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001964 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1965 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001966 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001967 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001968 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1969 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001970 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1971 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001972 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001973 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001974 __set_long_pointer(__p);
1975 __set_long_cap(__cap+1);
1976 __old_sz = __n_copy + __n_add + __sec_cp_sz;
1977 __set_long_size(__old_sz);
1978 traits_type::assign(__p[__old_sz], value_type());
1979}
1980
1981template <class _CharT, class _Traits, class _Allocator>
1982void
1983basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1984 size_type __n_copy, size_type __n_del, size_type __n_add)
1985{
1986 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00001987 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001988 this->__throw_length_error();
1989 pointer __old_p = __get_pointer();
1990 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00001991 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001992 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001993 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001994 __invalidate_all_iterators();
1995 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001996 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1997 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001998 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1999 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002000 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2001 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2002 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002003 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002004 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002005 __set_long_pointer(__p);
2006 __set_long_cap(__cap+1);
2007}
2008
2009// assign
2010
2011template <class _CharT, class _Traits, class _Allocator>
2012basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002013basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002014{
Alp Tokerec34c482014-05-15 11:27:39 +00002015 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002016 size_type __cap = capacity();
2017 if (__cap >= __n)
2018 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002019 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002020 traits_type::move(__p, __s, __n);
2021 traits_type::assign(__p[__n], value_type());
2022 __set_size(__n);
2023 __invalidate_iterators_past(__n);
2024 }
2025 else
2026 {
2027 size_type __sz = size();
2028 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2029 }
2030 return *this;
2031}
2032
2033template <class _CharT, class _Traits, class _Allocator>
2034basic_string<_CharT, _Traits, _Allocator>&
2035basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2036{
2037 size_type __cap = capacity();
2038 if (__cap < __n)
2039 {
2040 size_type __sz = size();
2041 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2042 }
2043 else
2044 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002045 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002046 traits_type::assign(__p, __n, __c);
2047 traits_type::assign(__p[__n], value_type());
2048 __set_size(__n);
2049 return *this;
2050}
2051
2052template <class _CharT, class _Traits, class _Allocator>
2053basic_string<_CharT, _Traits, _Allocator>&
2054basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2055{
2056 pointer __p;
2057 if (__is_long())
2058 {
2059 __p = __get_long_pointer();
2060 __set_long_size(1);
2061 }
2062 else
2063 {
2064 __p = __get_short_pointer();
2065 __set_short_size(1);
2066 }
2067 traits_type::assign(*__p, __c);
2068 traits_type::assign(*++__p, value_type());
2069 __invalidate_iterators_past(1);
2070 return *this;
2071}
2072
2073template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002074basic_string<_CharT, _Traits, _Allocator>&
2075basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2076{
2077 if (this != &__str)
2078 {
2079 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00002080 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00002081 }
2082 return *this;
2083}
2084
Eric Fiselier3e928972017-04-19 00:28:44 +00002085#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante32b5e22010-11-17 17:55:08 +00002086
2087template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002088inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002089void
2090basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002091 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002092{
2093 if (__alloc() != __str.__alloc())
2094 assign(__str);
2095 else
2096 __move_assign(__str, true_type());
2097}
2098
2099template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002100inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002101void
2102basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002103#if _LIBCPP_STD_VER > 14
2104 _NOEXCEPT
2105#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002106 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002107#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002108{
2109 clear();
2110 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002111 __r_.first() = __str.__r_.first();
2112 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002113 __str.__zero();
2114}
2115
2116template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002117inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002118basic_string<_CharT, _Traits, _Allocator>&
2119basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002120 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002121{
2122 __move_assign(__str, integral_constant<bool,
2123 __alloc_traits::propagate_on_container_move_assignment::value>());
2124 return *this;
2125}
2126
2127#endif
2128
2129template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002130template<class _InputIterator>
2131typename enable_if
2132<
Marshall Clowdf9db312016-01-13 21:54:34 +00002133 __is_exactly_input_iterator <_InputIterator>::value
2134 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002135 basic_string<_CharT, _Traits, _Allocator>&
2136>::type
2137basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2138{
Marshall Clowd979eed2016-09-05 01:54:30 +00002139 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002140 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002141 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002142}
2143
2144template <class _CharT, class _Traits, class _Allocator>
2145template<class _ForwardIterator>
2146typename enable_if
2147<
Marshall Clowdf9db312016-01-13 21:54:34 +00002148 __is_forward_iterator<_ForwardIterator>::value
2149 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002150 basic_string<_CharT, _Traits, _Allocator>&
2151>::type
2152basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2153{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002154 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002155 size_type __cap = capacity();
2156 if (__cap < __n)
2157 {
2158 size_type __sz = size();
2159 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2160 }
2161 else
2162 __invalidate_iterators_past(__n);
2163 pointer __p = __get_pointer();
2164 for (; __first != __last; ++__first, ++__p)
2165 traits_type::assign(*__p, *__first);
2166 traits_type::assign(*__p, value_type());
2167 __set_size(__n);
2168 return *this;
2169}
2170
2171template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002172basic_string<_CharT, _Traits, _Allocator>&
2173basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2174{
2175 size_type __sz = __str.size();
2176 if (__pos > __sz)
2177 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002178 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002179}
2180
2181template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002182template <class _Tp>
2183typename enable_if
2184<
2185 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002186 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002187>::type
2188basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002189{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002190 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002191 size_type __sz = __sv.size();
2192 if (__pos > __sz)
2193 this->__throw_out_of_range();
2194 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2195}
2196
2197
2198template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002199basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002200basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002201{
Alp Tokerec34c482014-05-15 11:27:39 +00002202 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002203 return assign(__s, traits_type::length(__s));
2204}
2205
2206// append
2207
2208template <class _CharT, class _Traits, class _Allocator>
2209basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002210basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002211{
Alp Tokerec34c482014-05-15 11:27:39 +00002212 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002213 size_type __cap = capacity();
2214 size_type __sz = size();
2215 if (__cap - __sz >= __n)
2216 {
2217 if (__n)
2218 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002219 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002220 traits_type::copy(__p + __sz, __s, __n);
2221 __sz += __n;
2222 __set_size(__sz);
2223 traits_type::assign(__p[__sz], value_type());
2224 }
2225 }
2226 else
2227 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2228 return *this;
2229}
2230
2231template <class _CharT, class _Traits, class _Allocator>
2232basic_string<_CharT, _Traits, _Allocator>&
2233basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2234{
2235 if (__n)
2236 {
2237 size_type __cap = capacity();
2238 size_type __sz = size();
2239 if (__cap - __sz < __n)
2240 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2241 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002242 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002243 __sz += __n;
2244 __set_size(__sz);
2245 traits_type::assign(__p[__sz], value_type());
2246 }
2247 return *this;
2248}
2249
2250template <class _CharT, class _Traits, class _Allocator>
2251void
2252basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2253{
Howard Hinnant15467182013-04-30 21:44:48 +00002254 bool __is_short = !__is_long();
2255 size_type __cap;
2256 size_type __sz;
2257 if (__is_short)
2258 {
2259 __cap = __min_cap - 1;
2260 __sz = __get_short_size();
2261 }
2262 else
2263 {
2264 __cap = __get_long_cap() - 1;
2265 __sz = __get_long_size();
2266 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002267 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002268 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002269 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002270 __is_short = !__is_long();
2271 }
2272 pointer __p;
2273 if (__is_short)
2274 {
2275 __p = __get_short_pointer() + __sz;
2276 __set_short_size(__sz+1);
2277 }
2278 else
2279 {
2280 __p = __get_long_pointer() + __sz;
2281 __set_long_size(__sz+1);
2282 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002283 traits_type::assign(*__p, __c);
2284 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002285}
2286
Marshall Clowac655ef2016-09-07 03:32:06 +00002287template <class _Tp>
Marshall Clowd979eed2016-09-05 01:54:30 +00002288bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2289{
2290 return __first <= __p && __p < __last;
2291}
2292
Marshall Clowac655ef2016-09-07 03:32:06 +00002293template <class _Tp1, class _Tp2>
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00002294bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
Marshall Clowac655ef2016-09-07 03:32:06 +00002295{
2296 return false;
2297}
2298
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002299template <class _CharT, class _Traits, class _Allocator>
2300template<class _ForwardIterator>
Eric Fiselier026d38e2016-10-31 02:46:25 +00002301basic_string<_CharT, _Traits, _Allocator>&
2302basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2303 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002304{
Eric Fiselier026d38e2016-10-31 02:46:25 +00002305 static_assert(__is_forward_iterator<_ForwardIterator>::value,
2306 "function requires a ForwardIterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002307 size_type __sz = size();
2308 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002309 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002310 if (__n)
2311 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002312 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2313 _CharRef __tmp_ref = *__first;
2314 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002315 {
2316 const basic_string __temp (__first, __last, __alloc());
2317 append(__temp.data(), __temp.size());
2318 }
2319 else
2320 {
2321 if (__cap - __sz < __n)
2322 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2323 pointer __p = __get_pointer() + __sz;
2324 for (; __first != __last; ++__p, ++__first)
2325 traits_type::assign(*__p, *__first);
2326 traits_type::assign(*__p, value_type());
2327 __set_size(__sz + __n);
2328 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002329 }
2330 return *this;
2331}
2332
2333template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002334inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002335basic_string<_CharT, _Traits, _Allocator>&
2336basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2337{
2338 return append(__str.data(), __str.size());
2339}
2340
2341template <class _CharT, class _Traits, class _Allocator>
2342basic_string<_CharT, _Traits, _Allocator>&
2343basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2344{
2345 size_type __sz = __str.size();
2346 if (__pos > __sz)
2347 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002348 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002349}
2350
2351template <class _CharT, class _Traits, class _Allocator>
Marshall Clow42a87db2016-10-03 23:40:48 +00002352template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002353 typename enable_if
2354 <
2355 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2356 basic_string<_CharT, _Traits, _Allocator>&
2357 >::type
2358basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002359{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002360 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002361 size_type __sz = __sv.size();
2362 if (__pos > __sz)
2363 this->__throw_out_of_range();
2364 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2365}
2366
2367template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002368basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002369basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002370{
Alp Tokerec34c482014-05-15 11:27:39 +00002371 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002372 return append(__s, traits_type::length(__s));
2373}
2374
2375// insert
2376
2377template <class _CharT, class _Traits, class _Allocator>
2378basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002379basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002380{
Alp Tokerec34c482014-05-15 11:27:39 +00002381 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002382 size_type __sz = size();
2383 if (__pos > __sz)
2384 this->__throw_out_of_range();
2385 size_type __cap = capacity();
2386 if (__cap - __sz >= __n)
2387 {
2388 if (__n)
2389 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002390 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002391 size_type __n_move = __sz - __pos;
2392 if (__n_move != 0)
2393 {
2394 if (__p + __pos <= __s && __s < __p + __sz)
2395 __s += __n;
2396 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2397 }
2398 traits_type::move(__p + __pos, __s, __n);
2399 __sz += __n;
2400 __set_size(__sz);
2401 traits_type::assign(__p[__sz], value_type());
2402 }
2403 }
2404 else
2405 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2406 return *this;
2407}
2408
2409template <class _CharT, class _Traits, class _Allocator>
2410basic_string<_CharT, _Traits, _Allocator>&
2411basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2412{
2413 size_type __sz = size();
2414 if (__pos > __sz)
2415 this->__throw_out_of_range();
2416 if (__n)
2417 {
2418 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002419 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002420 if (__cap - __sz >= __n)
2421 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002422 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002423 size_type __n_move = __sz - __pos;
2424 if (__n_move != 0)
2425 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2426 }
2427 else
2428 {
2429 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002430 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002431 }
2432 traits_type::assign(__p + __pos, __n, __c);
2433 __sz += __n;
2434 __set_size(__sz);
2435 traits_type::assign(__p[__sz], value_type());
2436 }
2437 return *this;
2438}
2439
2440template <class _CharT, class _Traits, class _Allocator>
2441template<class _InputIterator>
2442typename enable_if
2443<
Marshall Clowdf9db312016-01-13 21:54:34 +00002444 __is_exactly_input_iterator<_InputIterator>::value
2445 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2446 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002447>::type
2448basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2449{
Howard Hinnant499cea12013-08-23 17:37:05 +00002450#if _LIBCPP_DEBUG_LEVEL >= 2
2451 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2452 "string::insert(iterator, range) called with an iterator not"
2453 " referring to this string");
2454#endif
Marshall Clowd979eed2016-09-05 01:54:30 +00002455 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002456 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002457}
2458
2459template <class _CharT, class _Traits, class _Allocator>
2460template<class _ForwardIterator>
2461typename enable_if
2462<
Marshall Clowdf9db312016-01-13 21:54:34 +00002463 __is_forward_iterator<_ForwardIterator>::value
2464 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002465 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2466>::type
2467basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2468{
Howard Hinnant499cea12013-08-23 17:37:05 +00002469#if _LIBCPP_DEBUG_LEVEL >= 2
2470 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2471 "string::insert(iterator, range) called with an iterator not"
2472 " referring to this string");
2473#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002474 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002475 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002476 if (__n)
2477 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002478 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2479 _CharRef __tmp_char = *__first;
2480 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002481 {
2482 const basic_string __temp(__first, __last, __alloc());
2483 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2484 }
2485
2486 size_type __sz = size();
2487 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002488 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002489 if (__cap - __sz >= __n)
2490 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002491 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002492 size_type __n_move = __sz - __ip;
2493 if (__n_move != 0)
2494 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2495 }
2496 else
2497 {
2498 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002499 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002500 }
2501 __sz += __n;
2502 __set_size(__sz);
2503 traits_type::assign(__p[__sz], value_type());
2504 for (__p += __ip; __first != __last; ++__p, ++__first)
2505 traits_type::assign(*__p, *__first);
2506 }
2507 return begin() + __ip;
2508}
2509
2510template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002511inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002512basic_string<_CharT, _Traits, _Allocator>&
2513basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2514{
2515 return insert(__pos1, __str.data(), __str.size());
2516}
2517
2518template <class _CharT, class _Traits, class _Allocator>
2519basic_string<_CharT, _Traits, _Allocator>&
2520basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2521 size_type __pos2, size_type __n)
2522{
2523 size_type __str_sz = __str.size();
2524 if (__pos2 > __str_sz)
2525 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002526 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002527}
2528
2529template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002530template <class _Tp>
2531typename enable_if
2532<
2533 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002534 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002535>::type
2536basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002537 size_type __pos2, size_type __n)
2538{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002539 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002540 size_type __str_sz = __sv.size();
2541 if (__pos2 > __str_sz)
2542 this->__throw_out_of_range();
2543 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2544}
2545
2546template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002547basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002548basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002549{
Alp Tokerec34c482014-05-15 11:27:39 +00002550 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002551 return insert(__pos, __s, traits_type::length(__s));
2552}
2553
2554template <class _CharT, class _Traits, class _Allocator>
2555typename basic_string<_CharT, _Traits, _Allocator>::iterator
2556basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2557{
2558 size_type __ip = static_cast<size_type>(__pos - begin());
2559 size_type __sz = size();
2560 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002561 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002562 if (__cap == __sz)
2563 {
2564 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002565 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002566 }
2567 else
2568 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002569 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002570 size_type __n_move = __sz - __ip;
2571 if (__n_move != 0)
2572 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2573 }
2574 traits_type::assign(__p[__ip], __c);
2575 traits_type::assign(__p[++__sz], value_type());
2576 __set_size(__sz);
2577 return begin() + static_cast<difference_type>(__ip);
2578}
2579
2580template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002581inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002582typename basic_string<_CharT, _Traits, _Allocator>::iterator
2583basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2584{
Howard Hinnant499cea12013-08-23 17:37:05 +00002585#if _LIBCPP_DEBUG_LEVEL >= 2
2586 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2587 "string::insert(iterator, n, value) called with an iterator not"
2588 " referring to this string");
2589#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002590 difference_type __p = __pos - begin();
2591 insert(static_cast<size_type>(__p), __n, __c);
2592 return begin() + __p;
2593}
2594
2595// replace
2596
2597template <class _CharT, class _Traits, class _Allocator>
2598basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002599basic_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 +00002600 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002601{
Alp Tokerec34c482014-05-15 11:27:39 +00002602 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002603 size_type __sz = size();
2604 if (__pos > __sz)
2605 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002606 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002607 size_type __cap = capacity();
2608 if (__cap - __sz + __n1 >= __n2)
2609 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002610 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002611 if (__n1 != __n2)
2612 {
2613 size_type __n_move = __sz - __pos - __n1;
2614 if (__n_move != 0)
2615 {
2616 if (__n1 > __n2)
2617 {
2618 traits_type::move(__p + __pos, __s, __n2);
2619 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2620 goto __finish;
2621 }
2622 if (__p + __pos < __s && __s < __p + __sz)
2623 {
2624 if (__p + __pos + __n1 <= __s)
2625 __s += __n2 - __n1;
2626 else // __p + __pos < __s < __p + __pos + __n1
2627 {
2628 traits_type::move(__p + __pos, __s, __n1);
2629 __pos += __n1;
2630 __s += __n2;
2631 __n2 -= __n1;
2632 __n1 = 0;
2633 }
2634 }
2635 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2636 }
2637 }
2638 traits_type::move(__p + __pos, __s, __n2);
2639__finish:
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002640// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
2641// but this is a safe operation, so we disable the check.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002642 __sz += __n2 - __n1;
2643 __set_size(__sz);
2644 __invalidate_iterators_past(__sz);
2645 traits_type::assign(__p[__sz], value_type());
2646 }
2647 else
2648 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2649 return *this;
2650}
2651
2652template <class _CharT, class _Traits, class _Allocator>
2653basic_string<_CharT, _Traits, _Allocator>&
2654basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002655 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002656{
2657 size_type __sz = size();
2658 if (__pos > __sz)
2659 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002660 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002661 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002662 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002663 if (__cap - __sz + __n1 >= __n2)
2664 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002665 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002666 if (__n1 != __n2)
2667 {
2668 size_type __n_move = __sz - __pos - __n1;
2669 if (__n_move != 0)
2670 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2671 }
2672 }
2673 else
2674 {
2675 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002676 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002677 }
2678 traits_type::assign(__p + __pos, __n2, __c);
2679 __sz += __n2 - __n1;
2680 __set_size(__sz);
2681 __invalidate_iterators_past(__sz);
2682 traits_type::assign(__p[__sz], value_type());
2683 return *this;
2684}
2685
2686template <class _CharT, class _Traits, class _Allocator>
2687template<class _InputIterator>
2688typename enable_if
2689<
2690 __is_input_iterator<_InputIterator>::value,
2691 basic_string<_CharT, _Traits, _Allocator>&
2692>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002693basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002694 _InputIterator __j1, _InputIterator __j2)
2695{
Marshall Clowd979eed2016-09-05 01:54:30 +00002696 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002697 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002698}
2699
2700template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002701inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002702basic_string<_CharT, _Traits, _Allocator>&
2703basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2704{
2705 return replace(__pos1, __n1, __str.data(), __str.size());
2706}
2707
2708template <class _CharT, class _Traits, class _Allocator>
2709basic_string<_CharT, _Traits, _Allocator>&
2710basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2711 size_type __pos2, size_type __n2)
2712{
2713 size_type __str_sz = __str.size();
2714 if (__pos2 > __str_sz)
2715 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002716 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002717}
2718
2719template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002720template <class _Tp>
2721typename enable_if
2722<
Marshall Clowf1729d92017-11-15 20:02:27 +00002723 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2724 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002725>::type
2726basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002727 size_type __pos2, size_type __n2)
2728{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002729 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002730 size_type __str_sz = __sv.size();
2731 if (__pos2 > __str_sz)
2732 this->__throw_out_of_range();
2733 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2734}
2735
2736template <class _CharT, class _Traits, class _Allocator>
2737basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002738basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002739{
Alp Tokerec34c482014-05-15 11:27:39 +00002740 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002741 return replace(__pos, __n1, __s, traits_type::length(__s));
2742}
2743
2744template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002745inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002746basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002747basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002748{
2749 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2750 __str.data(), __str.size());
2751}
2752
2753template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002754inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002755basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002756basic_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 +00002757{
2758 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2759}
2760
2761template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002762inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002763basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002764basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002765{
2766 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2767}
2768
2769template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002770inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002771basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002772basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002773{
2774 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2775}
2776
2777// erase
2778
2779template <class _CharT, class _Traits, class _Allocator>
2780basic_string<_CharT, _Traits, _Allocator>&
2781basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2782{
2783 size_type __sz = size();
2784 if (__pos > __sz)
2785 this->__throw_out_of_range();
2786 if (__n)
2787 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002788 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002789 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002790 size_type __n_move = __sz - __pos - __n;
2791 if (__n_move != 0)
2792 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2793 __sz -= __n;
2794 __set_size(__sz);
2795 __invalidate_iterators_past(__sz);
2796 traits_type::assign(__p[__sz], value_type());
2797 }
2798 return *this;
2799}
2800
2801template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002802inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002803typename basic_string<_CharT, _Traits, _Allocator>::iterator
2804basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2805{
Howard Hinnant499cea12013-08-23 17:37:05 +00002806#if _LIBCPP_DEBUG_LEVEL >= 2
2807 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2808 "string::erase(iterator) called with an iterator not"
2809 " referring to this string");
2810#endif
2811 _LIBCPP_ASSERT(__pos != end(),
2812 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002813 iterator __b = begin();
2814 size_type __r = static_cast<size_type>(__pos - __b);
2815 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002816 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002817}
2818
2819template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002820inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002821typename basic_string<_CharT, _Traits, _Allocator>::iterator
2822basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2823{
Howard Hinnant499cea12013-08-23 17:37:05 +00002824#if _LIBCPP_DEBUG_LEVEL >= 2
2825 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2826 "string::erase(iterator, iterator) called with an iterator not"
2827 " referring to this string");
2828#endif
2829 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002830 iterator __b = begin();
2831 size_type __r = static_cast<size_type>(__first - __b);
2832 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00002833 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002834}
2835
2836template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002837inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002838void
2839basic_string<_CharT, _Traits, _Allocator>::pop_back()
2840{
Howard Hinnant499cea12013-08-23 17:37:05 +00002841 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002842 size_type __sz;
2843 if (__is_long())
2844 {
2845 __sz = __get_long_size() - 1;
2846 __set_long_size(__sz);
2847 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2848 }
2849 else
2850 {
2851 __sz = __get_short_size() - 1;
2852 __set_short_size(__sz);
2853 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2854 }
2855 __invalidate_iterators_past(__sz);
2856}
2857
2858template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002859inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002860void
Howard Hinnanta6119a82011-05-29 19:57:12 +00002861basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002862{
2863 __invalidate_all_iterators();
2864 if (__is_long())
2865 {
2866 traits_type::assign(*__get_long_pointer(), value_type());
2867 __set_long_size(0);
2868 }
2869 else
2870 {
2871 traits_type::assign(*__get_short_pointer(), value_type());
2872 __set_short_size(0);
2873 }
2874}
2875
2876template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002877inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002878void
2879basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2880{
2881 if (__is_long())
2882 {
2883 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2884 __set_long_size(__pos);
2885 }
2886 else
2887 {
2888 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2889 __set_short_size(__pos);
2890 }
2891 __invalidate_iterators_past(__pos);
2892}
2893
2894template <class _CharT, class _Traits, class _Allocator>
2895void
2896basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2897{
2898 size_type __sz = size();
2899 if (__n > __sz)
2900 append(__n - __sz, __c);
2901 else
2902 __erase_to_end(__n);
2903}
2904
2905template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002906inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002907typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002908basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002909{
Howard Hinnante32b5e22010-11-17 17:55:08 +00002910 size_type __m = __alloc_traits::max_size(__alloc());
Eric Fiselier5ccf0432017-10-17 13:16:01 +00002911#ifdef _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00002912 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002913#else
Marshall Clow09f85502013-10-31 17:23:08 +00002914 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002915#endif
2916}
2917
2918template <class _CharT, class _Traits, class _Allocator>
2919void
2920basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2921{
2922 if (__res_arg > max_size())
2923 this->__throw_length_error();
2924 size_type __cap = capacity();
2925 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002926 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002927 __res_arg = __recommend(__res_arg);
2928 if (__res_arg != __cap)
2929 {
2930 pointer __new_data, __p;
2931 bool __was_long, __now_long;
2932 if (__res_arg == __min_cap - 1)
2933 {
2934 __was_long = true;
2935 __now_long = false;
2936 __new_data = __get_short_pointer();
2937 __p = __get_long_pointer();
2938 }
2939 else
2940 {
2941 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002942 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002943 else
2944 {
2945 #ifndef _LIBCPP_NO_EXCEPTIONS
2946 try
2947 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002948 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00002949 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002950 #ifndef _LIBCPP_NO_EXCEPTIONS
2951 }
2952 catch (...)
2953 {
2954 return;
2955 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002956 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002957 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002958 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00002959 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002960 }
2961 __now_long = true;
2962 __was_long = __is_long();
2963 __p = __get_pointer();
2964 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002965 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
2966 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002967 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002968 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002969 if (__now_long)
2970 {
2971 __set_long_cap(__res_arg+1);
2972 __set_long_size(__sz);
2973 __set_long_pointer(__new_data);
2974 }
2975 else
2976 __set_short_size(__sz);
2977 __invalidate_all_iterators();
2978 }
2979}
2980
2981template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002982inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002983typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002984basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002985{
Howard Hinnant499cea12013-08-23 17:37:05 +00002986 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002987 return *(data() + __pos);
2988}
2989
2990template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002991inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002992typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002993basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002994{
Howard Hinnant499cea12013-08-23 17:37:05 +00002995 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002996 return *(__get_pointer() + __pos);
2997}
2998
2999template <class _CharT, class _Traits, class _Allocator>
3000typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3001basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3002{
3003 if (__n >= size())
3004 this->__throw_out_of_range();
3005 return (*this)[__n];
3006}
3007
3008template <class _CharT, class _Traits, class _Allocator>
3009typename basic_string<_CharT, _Traits, _Allocator>::reference
3010basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3011{
3012 if (__n >= size())
3013 this->__throw_out_of_range();
3014 return (*this)[__n];
3015}
3016
3017template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003018inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003019typename basic_string<_CharT, _Traits, _Allocator>::reference
3020basic_string<_CharT, _Traits, _Allocator>::front()
3021{
Howard Hinnant499cea12013-08-23 17:37:05 +00003022 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003023 return *__get_pointer();
3024}
3025
3026template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003027inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003028typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3029basic_string<_CharT, _Traits, _Allocator>::front() const
3030{
Howard Hinnant499cea12013-08-23 17:37:05 +00003031 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003032 return *data();
3033}
3034
3035template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003036inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003037typename basic_string<_CharT, _Traits, _Allocator>::reference
3038basic_string<_CharT, _Traits, _Allocator>::back()
3039{
Howard Hinnant499cea12013-08-23 17:37:05 +00003040 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003041 return *(__get_pointer() + size() - 1);
3042}
3043
3044template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003045inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003046typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3047basic_string<_CharT, _Traits, _Allocator>::back() const
3048{
Howard Hinnant499cea12013-08-23 17:37:05 +00003049 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003050 return *(data() + size() - 1);
3051}
3052
3053template <class _CharT, class _Traits, class _Allocator>
3054typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003055basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003056{
3057 size_type __sz = size();
3058 if (__pos > __sz)
3059 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003060 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003061 traits_type::copy(__s, data() + __pos, __rlen);
3062 return __rlen;
3063}
3064
3065template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003066inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003067basic_string<_CharT, _Traits, _Allocator>
3068basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3069{
3070 return basic_string(*this, __pos, __n, __alloc());
3071}
3072
3073template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003074inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003075void
3076basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00003077#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00003078 _NOEXCEPT_DEBUG
Marshall Clow7d914d12015-07-13 20:04:56 +00003079#else
Eric Fiselier47257c42016-12-28 05:53:01 +00003080 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00003081 __is_nothrow_swappable<allocator_type>::value)
3082#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003083{
Howard Hinnant499cea12013-08-23 17:37:05 +00003084#if _LIBCPP_DEBUG_LEVEL >= 2
3085 if (!__is_long())
3086 __get_db()->__invalidate_all(this);
3087 if (!__str.__is_long())
3088 __get_db()->__invalidate_all(&__str);
3089 __get_db()->swap(this, &__str);
3090#endif
Eric Fiselier47257c42016-12-28 05:53:01 +00003091 _LIBCPP_ASSERT(
3092 __alloc_traits::propagate_on_container_swap::value ||
3093 __alloc_traits::is_always_equal::value ||
3094 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnant0949eed2011-06-30 21:18:19 +00003095 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00003096 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003097}
3098
3099// find
3100
3101template <class _Traits>
3102struct _LIBCPP_HIDDEN __traits_eq
3103{
3104 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003105 _LIBCPP_INLINE_VISIBILITY
3106 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3107 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003108};
3109
3110template<class _CharT, class _Traits, class _Allocator>
3111typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003112basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003113 size_type __pos,
3114 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003115{
Alp Tokerec34c482014-05-15 11:27:39 +00003116 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003117 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003118 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003119}
3120
3121template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003122inline _LIBCPP_INLINE_VISIBILITY
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>::find(const basic_string& __str,
3125 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003126{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003127 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003128 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003129}
3130
3131template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003132inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003133typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003134basic_string<_CharT, _Traits, _Allocator>::find(__self_view __sv,
3135 size_type __pos) const _NOEXCEPT
3136{
3137 return __str_find<value_type, size_type, traits_type, npos>
3138 (data(), size(), __sv.data(), __pos, __sv.size());
3139}
3140
3141template<class _CharT, class _Traits, class _Allocator>
3142inline _LIBCPP_INLINE_VISIBILITY
3143typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003144basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003145 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003146{
Alp Tokerec34c482014-05-15 11:27:39 +00003147 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003148 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003149 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003150}
3151
3152template<class _CharT, class _Traits, class _Allocator>
3153typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003154basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3155 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003156{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003157 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003158 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003159}
3160
3161// rfind
3162
3163template<class _CharT, class _Traits, class _Allocator>
3164typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003165basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003166 size_type __pos,
3167 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003168{
Alp Tokerec34c482014-05-15 11:27:39 +00003169 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003170 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003171 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003172}
3173
3174template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003175inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003176typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003177basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3178 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003179{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003180 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003181 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003182}
3183
3184template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003185inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003186typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003187basic_string<_CharT, _Traits, _Allocator>::rfind(__self_view __sv,
3188 size_type __pos) const _NOEXCEPT
3189{
3190 return __str_rfind<value_type, size_type, traits_type, npos>
3191 (data(), size(), __sv.data(), __pos, __sv.size());
3192}
3193
3194template<class _CharT, class _Traits, class _Allocator>
3195inline _LIBCPP_INLINE_VISIBILITY
3196typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003197basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003198 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003199{
Alp Tokerec34c482014-05-15 11:27:39 +00003200 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003201 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003202 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003203}
3204
3205template<class _CharT, class _Traits, class _Allocator>
3206typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003207basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3208 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003209{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003210 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003211 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003212}
3213
3214// find_first_of
3215
3216template<class _CharT, class _Traits, class _Allocator>
3217typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003218basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003219 size_type __pos,
3220 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003221{
Alp Tokerec34c482014-05-15 11:27:39 +00003222 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003223 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003224 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003225}
3226
3227template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003228inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003229typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003230basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3231 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003232{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003233 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003234 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003235}
3236
3237template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003238inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003239typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003240basic_string<_CharT, _Traits, _Allocator>::find_first_of(__self_view __sv,
3241 size_type __pos) const _NOEXCEPT
3242{
3243 return __str_find_first_of<value_type, size_type, traits_type, npos>
3244 (data(), size(), __sv.data(), __pos, __sv.size());
3245}
3246
3247template<class _CharT, class _Traits, class _Allocator>
3248inline _LIBCPP_INLINE_VISIBILITY
3249typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003250basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003251 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003252{
Alp Tokerec34c482014-05-15 11:27:39 +00003253 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003254 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003255 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003256}
3257
3258template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003259inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003260typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003261basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3262 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003263{
3264 return find(__c, __pos);
3265}
3266
3267// find_last_of
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>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003272 size_type __pos,
3273 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003274{
Alp Tokerec34c482014-05-15 11:27:39 +00003275 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003276 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003277 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003278}
3279
3280template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003281inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003282typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003283basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3284 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003285{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003286 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003287 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003288}
3289
3290template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003291inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003292typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003293basic_string<_CharT, _Traits, _Allocator>::find_last_of(__self_view __sv,
3294 size_type __pos) const _NOEXCEPT
3295{
3296 return __str_find_last_of<value_type, size_type, traits_type, npos>
3297 (data(), size(), __sv.data(), __pos, __sv.size());
3298}
3299
3300template<class _CharT, class _Traits, class _Allocator>
3301inline _LIBCPP_INLINE_VISIBILITY
3302typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003303basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003304 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003305{
Alp Tokerec34c482014-05-15 11:27:39 +00003306 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003307 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003308 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003309}
3310
3311template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003312inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003313typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003314basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3315 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003316{
3317 return rfind(__c, __pos);
3318}
3319
3320// find_first_not_of
3321
3322template<class _CharT, class _Traits, class _Allocator>
3323typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003324basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003325 size_type __pos,
3326 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003327{
Alp Tokerec34c482014-05-15 11:27:39 +00003328 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003329 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003330 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003331}
3332
3333template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003334inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003335typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003336basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3337 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003338{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003339 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003340 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003341}
3342
3343template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003344inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003345typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003346basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(__self_view __sv,
3347 size_type __pos) const _NOEXCEPT
3348{
3349 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3350 (data(), size(), __sv.data(), __pos, __sv.size());
3351}
3352
3353template<class _CharT, class _Traits, class _Allocator>
3354inline _LIBCPP_INLINE_VISIBILITY
3355typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003356basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003357 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003358{
Alp Tokerec34c482014-05-15 11:27:39 +00003359 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003360 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003361 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003362}
3363
3364template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003365inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003366typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003367basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3368 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003369{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003370 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003371 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003372}
3373
3374// find_last_not_of
3375
3376template<class _CharT, class _Traits, class _Allocator>
3377typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003378basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003379 size_type __pos,
3380 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003381{
Alp Tokerec34c482014-05-15 11:27:39 +00003382 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003383 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003384 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003385}
3386
3387template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003388inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003389typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003390basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3391 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003392{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003393 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003394 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003395}
3396
3397template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003398inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003399typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003400basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(__self_view __sv,
3401 size_type __pos) const _NOEXCEPT
3402{
3403 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3404 (data(), size(), __sv.data(), __pos, __sv.size());
3405}
3406
3407template<class _CharT, class _Traits, class _Allocator>
3408inline _LIBCPP_INLINE_VISIBILITY
3409typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003410basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003411 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003412{
Alp Tokerec34c482014-05-15 11:27:39 +00003413 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003414 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003415 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003416}
3417
3418template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003419inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003420typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003421basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3422 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003423{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003424 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003425 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003426}
3427
3428// compare
3429
3430template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003431inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003432int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003433basic_string<_CharT, _Traits, _Allocator>::compare(__self_view __sv) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003434{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003435 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003436 size_t __rhs_sz = __sv.size();
3437 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:06 +00003438 _VSTD::min(__lhs_sz, __rhs_sz));
3439 if (__result != 0)
3440 return __result;
3441 if (__lhs_sz < __rhs_sz)
3442 return -1;
3443 if (__lhs_sz > __rhs_sz)
3444 return 1;
3445 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003446}
3447
3448template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003449inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003450int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003451basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003452{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003453 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003454}
3455
3456template <class _CharT, class _Traits, class _Allocator>
3457int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003458basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3459 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003460 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003461 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003462{
Alp Tokerec34c482014-05-15 11:27:39 +00003463 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003464 size_type __sz = size();
3465 if (__pos1 > __sz || __n2 == npos)
3466 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003467 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3468 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003469 if (__r == 0)
3470 {
3471 if (__rlen < __n2)
3472 __r = -1;
3473 else if (__rlen > __n2)
3474 __r = 1;
3475 }
3476 return __r;
3477}
3478
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003479template <class _CharT, class _Traits, class _Allocator>
3480inline _LIBCPP_INLINE_VISIBILITY
3481int
3482basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3483 size_type __n1,
3484 __self_view __sv) const
3485{
3486 return compare(__pos1, __n1, __sv.data(), __sv.size());
3487}
3488
3489template <class _CharT, class _Traits, class _Allocator>
3490inline _LIBCPP_INLINE_VISIBILITY
3491int
3492basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3493 size_type __n1,
3494 const basic_string& __str) const
3495{
3496 return compare(__pos1, __n1, __str.data(), __str.size());
3497}
3498
3499template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00003500template <class _Tp>
3501typename enable_if
3502<
Marshall Clowf1729d92017-11-15 20:02:27 +00003503 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3504 int
Marshall Clow6ac8de02016-09-24 22:45:42 +00003505>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003506basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3507 size_type __n1,
Marshall Clow6ac8de02016-09-24 22:45:42 +00003508 const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003509 size_type __pos2,
3510 size_type __n2) const
3511{
Marshall Clow6ac8de02016-09-24 22:45:42 +00003512 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003513 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3514}
3515
3516template <class _CharT, class _Traits, class _Allocator>
3517int
3518basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3519 size_type __n1,
3520 const basic_string& __str,
3521 size_type __pos2,
3522 size_type __n2) const
3523{
3524 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3525}
3526
3527template <class _CharT, class _Traits, class _Allocator>
3528int
3529basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3530{
3531 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3532 return compare(0, npos, __s, traits_type::length(__s));
3533}
3534
3535template <class _CharT, class _Traits, class _Allocator>
3536int
3537basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3538 size_type __n1,
3539 const value_type* __s) const
3540{
3541 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3542 return compare(__pos1, __n1, __s, traits_type::length(__s));
3543}
3544
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003545// __invariants
3546
3547template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003548inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003549bool
3550basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3551{
3552 if (size() > capacity())
3553 return false;
3554 if (capacity() < __min_cap - 1)
3555 return false;
3556 if (data() == 0)
3557 return false;
3558 if (data()[size()] != value_type(0))
3559 return false;
3560 return true;
3561}
3562
3563// operator==
3564
3565template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003566inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003567bool
3568operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003569 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003570{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003571 size_t __lhs_sz = __lhs.size();
3572 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3573 __rhs.data(),
3574 __lhs_sz) == 0;
3575}
3576
3577template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003578inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003579bool
3580operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3581 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3582{
3583 size_t __lhs_sz = __lhs.size();
3584 if (__lhs_sz != __rhs.size())
3585 return false;
3586 const char* __lp = __lhs.data();
3587 const char* __rp = __rhs.data();
3588 if (__lhs.__is_long())
3589 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3590 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3591 if (*__lp != *__rp)
3592 return false;
3593 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003594}
3595
3596template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003597inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003598bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003599operator==(const _CharT* __lhs,
3600 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003601{
Eric Fiselier4f241822015-08-28 03:02:37 +00003602 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3603 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3604 size_t __lhs_len = _Traits::length(__lhs);
3605 if (__lhs_len != __rhs.size()) return false;
3606 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003607}
3608
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003609template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003610inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003611bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003612operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3613 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003614{
Eric Fiselier4f241822015-08-28 03:02:37 +00003615 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3616 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3617 size_t __rhs_len = _Traits::length(__rhs);
3618 if (__rhs_len != __lhs.size()) return false;
3619 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003620}
3621
Howard Hinnant324bb032010-08-22 00:02:43 +00003622template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003623inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003624bool
3625operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003626 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003627{
3628 return !(__lhs == __rhs);
3629}
3630
3631template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003633bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003634operator!=(const _CharT* __lhs,
3635 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003636{
3637 return !(__lhs == __rhs);
3638}
3639
3640template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003641inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003642bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003643operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3644 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003645{
3646 return !(__lhs == __rhs);
3647}
3648
3649// operator<
3650
3651template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003652inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003653bool
3654operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003655 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003656{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003657 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003658}
3659
3660template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003661inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003662bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003663operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3664 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003665{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003666 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003667}
3668
3669template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003670inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003671bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003672operator< (const _CharT* __lhs,
3673 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003674{
3675 return __rhs.compare(__lhs) > 0;
3676}
3677
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003678// operator>
3679
3680template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003681inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003682bool
3683operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003684 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003685{
3686 return __rhs < __lhs;
3687}
3688
3689template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003690inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003691bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003692operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3693 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003694{
3695 return __rhs < __lhs;
3696}
3697
3698template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003699inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003700bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003701operator> (const _CharT* __lhs,
3702 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003703{
3704 return __rhs < __lhs;
3705}
3706
3707// operator<=
3708
3709template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003710inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003711bool
3712operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003713 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003714{
3715 return !(__rhs < __lhs);
3716}
3717
3718template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003719inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003720bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003721operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3722 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003723{
3724 return !(__rhs < __lhs);
3725}
3726
3727template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003728inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003729bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003730operator<=(const _CharT* __lhs,
3731 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003732{
3733 return !(__rhs < __lhs);
3734}
3735
3736// operator>=
3737
3738template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003739inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003740bool
3741operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003742 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003743{
3744 return !(__lhs < __rhs);
3745}
3746
3747template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003748inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003749bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003750operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3751 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003752{
3753 return !(__lhs < __rhs);
3754}
3755
3756template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003757inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003758bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003759operator>=(const _CharT* __lhs,
3760 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003761{
3762 return !(__lhs < __rhs);
3763}
3764
3765// operator +
3766
3767template<class _CharT, class _Traits, class _Allocator>
3768basic_string<_CharT, _Traits, _Allocator>
3769operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3770 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3771{
3772 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3773 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3774 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3775 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3776 __r.append(__rhs.data(), __rhs_sz);
3777 return __r;
3778}
3779
3780template<class _CharT, class _Traits, class _Allocator>
3781basic_string<_CharT, _Traits, _Allocator>
3782operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3783{
3784 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3785 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3786 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3787 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3788 __r.append(__rhs.data(), __rhs_sz);
3789 return __r;
3790}
3791
3792template<class _CharT, class _Traits, class _Allocator>
3793basic_string<_CharT, _Traits, _Allocator>
3794operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3795{
3796 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3797 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3798 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3799 __r.append(__rhs.data(), __rhs_sz);
3800 return __r;
3801}
3802
3803template<class _CharT, class _Traits, class _Allocator>
3804basic_string<_CharT, _Traits, _Allocator>
3805operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3806{
3807 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3808 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3809 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3810 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3811 __r.append(__rhs, __rhs_sz);
3812 return __r;
3813}
3814
3815template<class _CharT, class _Traits, class _Allocator>
3816basic_string<_CharT, _Traits, _Allocator>
3817operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3818{
3819 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3820 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3821 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3822 __r.push_back(__rhs);
3823 return __r;
3824}
3825
Eric Fiselier3e928972017-04-19 00:28:44 +00003826#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003827
3828template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003829inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003830basic_string<_CharT, _Traits, _Allocator>
3831operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3832{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003833 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003834}
3835
3836template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003837inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003838basic_string<_CharT, _Traits, _Allocator>
3839operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3840{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003841 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003842}
3843
3844template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003845inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003846basic_string<_CharT, _Traits, _Allocator>
3847operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3848{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003849 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003850}
3851
3852template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003853inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003854basic_string<_CharT, _Traits, _Allocator>
3855operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3856{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003857 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003858}
3859
3860template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003861inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003862basic_string<_CharT, _Traits, _Allocator>
3863operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3864{
3865 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003866 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003867}
3868
3869template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003870inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003871basic_string<_CharT, _Traits, _Allocator>
3872operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3873{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003874 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003875}
3876
3877template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003878inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003879basic_string<_CharT, _Traits, _Allocator>
3880operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3881{
3882 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003883 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003884}
3885
Eric Fiselier3e928972017-04-19 00:28:44 +00003886#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003887
3888// swap
3889
3890template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003891inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003892void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003893swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003894 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3895 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003896{
3897 __lhs.swap(__rhs);
3898}
3899
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003900#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3901
3902typedef basic_string<char16_t> u16string;
3903typedef basic_string<char32_t> u32string;
3904
Howard Hinnant324bb032010-08-22 00:02:43 +00003905#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003906
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003907_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3908_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3909_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3910_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
3911_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003912
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003913_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
3914_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
3915_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003916
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003917_LIBCPP_FUNC_VIS string to_string(int __val);
3918_LIBCPP_FUNC_VIS string to_string(unsigned __val);
3919_LIBCPP_FUNC_VIS string to_string(long __val);
3920_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
3921_LIBCPP_FUNC_VIS string to_string(long long __val);
3922_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
3923_LIBCPP_FUNC_VIS string to_string(float __val);
3924_LIBCPP_FUNC_VIS string to_string(double __val);
3925_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003926
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003927_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
3928_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
3929_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
3930_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
3931_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003932
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003933_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
3934_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
3935_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003936
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003937_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
3938_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
3939_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
3940_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
3941_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
3942_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
3943_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
3944_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
3945_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003946
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003947template<class _CharT, class _Traits, class _Allocator>
3948 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
3949 basic_string<_CharT, _Traits, _Allocator>::npos;
3950
3951template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +00003952struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003953 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
3954{
3955 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00003956 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003957};
3958
3959template<class _CharT, class _Traits, class _Allocator>
3960size_t
3961hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00003962 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003963{
Sean Huntaffd9e52011-07-29 23:31:56 +00003964 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003965}
3966
Howard Hinnant464aa5c2011-07-18 15:51:59 +00003967template<class _CharT, class _Traits, class _Allocator>
3968basic_ostream<_CharT, _Traits>&
3969operator<<(basic_ostream<_CharT, _Traits>& __os,
3970 const basic_string<_CharT, _Traits, _Allocator>& __str);
3971
3972template<class _CharT, class _Traits, class _Allocator>
3973basic_istream<_CharT, _Traits>&
3974operator>>(basic_istream<_CharT, _Traits>& __is,
3975 basic_string<_CharT, _Traits, _Allocator>& __str);
3976
3977template<class _CharT, class _Traits, class _Allocator>
3978basic_istream<_CharT, _Traits>&
3979getline(basic_istream<_CharT, _Traits>& __is,
3980 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3981
3982template<class _CharT, class _Traits, class _Allocator>
3983inline _LIBCPP_INLINE_VISIBILITY
3984basic_istream<_CharT, _Traits>&
3985getline(basic_istream<_CharT, _Traits>& __is,
3986 basic_string<_CharT, _Traits, _Allocator>& __str);
3987
Eric Fiselier3e928972017-04-19 00:28:44 +00003988#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00003989
3990template<class _CharT, class _Traits, class _Allocator>
3991inline _LIBCPP_INLINE_VISIBILITY
3992basic_istream<_CharT, _Traits>&
3993getline(basic_istream<_CharT, _Traits>&& __is,
3994 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3995
3996template<class _CharT, class _Traits, class _Allocator>
3997inline _LIBCPP_INLINE_VISIBILITY
3998basic_istream<_CharT, _Traits>&
3999getline(basic_istream<_CharT, _Traits>&& __is,
4000 basic_string<_CharT, _Traits, _Allocator>& __str);
4001
Eric Fiselier3e928972017-04-19 00:28:44 +00004002#endif // _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004003
Howard Hinnant499cea12013-08-23 17:37:05 +00004004#if _LIBCPP_DEBUG_LEVEL >= 2
4005
4006template<class _CharT, class _Traits, class _Allocator>
4007bool
4008basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4009{
4010 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4011 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4012}
4013
4014template<class _CharT, class _Traits, class _Allocator>
4015bool
4016basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4017{
4018 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4019 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4020}
4021
4022template<class _CharT, class _Traits, class _Allocator>
4023bool
4024basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4025{
4026 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4027 return this->data() <= __p && __p <= this->data() + this->size();
4028}
4029
4030template<class _CharT, class _Traits, class _Allocator>
4031bool
4032basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4033{
4034 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4035 return this->data() <= __p && __p < this->data() + this->size();
4036}
4037
4038#endif // _LIBCPP_DEBUG_LEVEL >= 2
4039
Shoaib Meenai68506702017-06-29 02:52:46 +00004040_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
4041_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Shoaib Meenai68506702017-06-29 02:52:46 +00004042
Marshall Clow15234322013-07-23 17:05:24 +00004043#if _LIBCPP_STD_VER > 11
4044// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004045inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004046{
4047 inline namespace string_literals
4048 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004049 inline _LIBCPP_INLINE_VISIBILITY
4050 basic_string<char> operator "" s( const char *__str, size_t __len )
4051 {
4052 return basic_string<char> (__str, __len);
4053 }
Marshall Clow15234322013-07-23 17:05:24 +00004054
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004055 inline _LIBCPP_INLINE_VISIBILITY
4056 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4057 {
4058 return basic_string<wchar_t> (__str, __len);
4059 }
Marshall Clow15234322013-07-23 17:05:24 +00004060
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004061 inline _LIBCPP_INLINE_VISIBILITY
4062 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4063 {
4064 return basic_string<char16_t> (__str, __len);
4065 }
Marshall Clow15234322013-07-23 17:05:24 +00004066
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004067 inline _LIBCPP_INLINE_VISIBILITY
4068 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4069 {
4070 return basic_string<char32_t> (__str, __len);
4071 }
Marshall Clow15234322013-07-23 17:05:24 +00004072 }
4073}
4074#endif
4075
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004076_LIBCPP_END_NAMESPACE_STD
4077
Eric Fiselier018a3d52017-05-31 22:07:49 +00004078_LIBCPP_POP_MACROS
4079
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004080#endif // _LIBCPP_STRING