blob: b213cd411d15b878e6558b8090742dd82166da25 [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
Eric Fiseliere2d48922015-08-28 07:02:42 +00001366 {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
Howard Hinnant7f764502013-08-14 18:00:20 +00001367 __align_it<sizeof(value_type) < __alignment ?
Howard Hinnanta6119a82011-05-29 19:57:12 +00001368 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001369
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001370 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001371 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001372 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001373 void __init(const value_type* __s, size_type __sz);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001374 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001375 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001376
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001377 template <class _InputIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001378 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001379 typename enable_if
1380 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001381 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001382 void
1383 >::type
1384 __init(_InputIterator __first, _InputIterator __last);
1385
1386 template <class _ForwardIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001387 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001388 typename enable_if
1389 <
1390 __is_forward_iterator<_ForwardIterator>::value,
1391 void
1392 >::type
1393 __init(_ForwardIterator __first, _ForwardIterator __last);
1394
1395 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001396 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001397 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1398 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001399 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001400
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001402 void __erase_to_end(size_type __pos);
1403
Howard Hinnante32b5e22010-11-17 17:55:08 +00001404 _LIBCPP_INLINE_VISIBILITY
1405 void __copy_assign_alloc(const basic_string& __str)
1406 {__copy_assign_alloc(__str, integral_constant<bool,
1407 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1408
1409 _LIBCPP_INLINE_VISIBILITY
1410 void __copy_assign_alloc(const basic_string& __str, true_type)
1411 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001412 if (__alloc() == __str.__alloc())
1413 __alloc() = __str.__alloc();
1414 else
Howard Hinnante32b5e22010-11-17 17:55:08 +00001415 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001416 if (!__str.__is_long())
1417 {
1418 clear();
1419 shrink_to_fit();
1420 __alloc() = __str.__alloc();
1421 }
1422 else
1423 {
1424 allocator_type __a = __str.__alloc();
1425 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
1426 clear();
1427 shrink_to_fit();
1428 __alloc() = _VSTD::move(__a);
1429 __set_long_pointer(__p);
1430 __set_long_cap(__str.__get_long_cap());
1431 __set_long_size(__str.size());
1432 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001433 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001434 }
1435
1436 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001437 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001438 {}
1439
Eric Fiselier3e928972017-04-19 00:28:44 +00001440#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001441 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001442 void __move_assign(basic_string& __str, false_type)
1443 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001444 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001445 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001446#if _LIBCPP_STD_VER > 14
1447 _NOEXCEPT;
1448#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001449 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001450#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001451#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001452
1453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001454 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001455 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001456 _NOEXCEPT_(
1457 !__alloc_traits::propagate_on_container_move_assignment::value ||
1458 is_nothrow_move_assignable<allocator_type>::value)
1459 {__move_assign_alloc(__str, integral_constant<bool,
1460 __alloc_traits::propagate_on_container_move_assignment::value>());}
1461
1462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001463 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001464 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1465 {
1466 __alloc() = _VSTD::move(__c.__alloc());
1467 }
1468
1469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001470 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001471 _NOEXCEPT
1472 {}
1473
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001474 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1475 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001476
1477 friend basic_string operator+<>(const basic_string&, const basic_string&);
1478 friend basic_string operator+<>(const value_type*, const basic_string&);
1479 friend basic_string operator+<>(value_type, const basic_string&);
1480 friend basic_string operator+<>(const basic_string&, const value_type*);
1481 friend basic_string operator+<>(const basic_string&, value_type);
1482};
1483
1484template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001485inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001486void
1487basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1488{
Howard Hinnant499cea12013-08-23 17:37:05 +00001489#if _LIBCPP_DEBUG_LEVEL >= 2
1490 __get_db()->__invalidate_all(this);
1491#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001492}
1493
1494template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001495inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001496void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001497basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001498#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001499 __pos
1500#endif
1501 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001502{
Howard Hinnant499cea12013-08-23 17:37:05 +00001503#if _LIBCPP_DEBUG_LEVEL >= 2
1504 __c_node* __c = __get_db()->__find_c_and_lock(this);
1505 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001506 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001507 const_pointer __new_last = __get_pointer() + __pos;
1508 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001509 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001510 --__p;
1511 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1512 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001513 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001514 (*__p)->__c_ = nullptr;
1515 if (--__c->end_ != __p)
1516 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001517 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001519 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001520 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001521#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001522}
1523
1524template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001525inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001526basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001527 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001528{
Howard Hinnant499cea12013-08-23 17:37:05 +00001529#if _LIBCPP_DEBUG_LEVEL >= 2
1530 __get_db()->__insert_c(this);
1531#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001532 __zero();
1533}
1534
1535template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001536inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001537basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001538#if _LIBCPP_STD_VER <= 14
1539 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1540#else
1541 _NOEXCEPT
1542#endif
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001543: __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001544{
Howard Hinnant499cea12013-08-23 17:37:05 +00001545#if _LIBCPP_DEBUG_LEVEL >= 2
1546 __get_db()->__insert_c(this);
1547#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548 __zero();
1549}
1550
1551template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001552void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1553 size_type __sz,
1554 size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001555{
1556 if (__reserve > max_size())
1557 this->__throw_length_error();
1558 pointer __p;
1559 if (__reserve < __min_cap)
1560 {
1561 __set_short_size(__sz);
1562 __p = __get_short_pointer();
1563 }
1564 else
1565 {
1566 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001567 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001568 __set_long_pointer(__p);
1569 __set_long_cap(__cap+1);
1570 __set_long_size(__sz);
1571 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001572 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001573 traits_type::assign(__p[__sz], value_type());
1574}
1575
1576template <class _CharT, class _Traits, class _Allocator>
1577void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001578basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001579{
1580 if (__sz > max_size())
1581 this->__throw_length_error();
1582 pointer __p;
1583 if (__sz < __min_cap)
1584 {
1585 __set_short_size(__sz);
1586 __p = __get_short_pointer();
1587 }
1588 else
1589 {
1590 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001591 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001592 __set_long_pointer(__p);
1593 __set_long_cap(__cap+1);
1594 __set_long_size(__sz);
1595 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001596 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001597 traits_type::assign(__p[__sz], value_type());
1598}
1599
1600template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001601inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001602basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001603{
Howard Hinnant499cea12013-08-23 17:37:05 +00001604 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001605 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001606#if _LIBCPP_DEBUG_LEVEL >= 2
1607 __get_db()->__insert_c(this);
1608#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001609}
1610
1611template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001612inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001613basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001614 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001615{
Howard Hinnant499cea12013-08-23 17:37:05 +00001616 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001617 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001618#if _LIBCPP_DEBUG_LEVEL >= 2
1619 __get_db()->__insert_c(this);
1620#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001621}
1622
1623template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001624inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001625basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001626{
Howard Hinnant499cea12013-08-23 17:37:05 +00001627 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001628 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001629#if _LIBCPP_DEBUG_LEVEL >= 2
1630 __get_db()->__insert_c(this);
1631#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001632}
1633
1634template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001635inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001636basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001637 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001638{
Howard Hinnant499cea12013-08-23 17:37:05 +00001639 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001640 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001641#if _LIBCPP_DEBUG_LEVEL >= 2
1642 __get_db()->__insert_c(this);
1643#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001644}
1645
1646template <class _CharT, class _Traits, class _Allocator>
1647basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001648 : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001649{
1650 if (!__str.__is_long())
1651 __r_.first().__r = __str.__r_.first().__r;
1652 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001653 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001654#if _LIBCPP_DEBUG_LEVEL >= 2
1655 __get_db()->__insert_c(this);
1656#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001657}
1658
1659template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001660basic_string<_CharT, _Traits, _Allocator>::basic_string(
1661 const basic_string& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001662 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001663{
1664 if (!__str.__is_long())
1665 __r_.first().__r = __str.__r_.first().__r;
1666 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001667 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001668#if _LIBCPP_DEBUG_LEVEL >= 2
1669 __get_db()->__insert_c(this);
1670#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001671}
1672
Eric Fiselier3e928972017-04-19 00:28:44 +00001673#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001674
1675template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001676inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001677basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001678#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001679 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00001680#else
1681 _NOEXCEPT
1682#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001683 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001684{
1685 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00001686#if _LIBCPP_DEBUG_LEVEL >= 2
1687 __get_db()->__insert_c(this);
1688 if (__is_long())
1689 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001690#endif
1691}
1692
1693template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001694inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001695basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001696 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001697{
Marshall Clowd5549cc2014-07-17 15:32:20 +00001698 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001699 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00001700 else
1701 {
1702 __r_.first().__r = __str.__r_.first().__r;
1703 __str.__zero();
1704 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001705#if _LIBCPP_DEBUG_LEVEL >= 2
1706 __get_db()->__insert_c(this);
1707 if (__is_long())
1708 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001709#endif
1710}
1711
Eric Fiselier3e928972017-04-19 00:28:44 +00001712#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001713
1714template <class _CharT, class _Traits, class _Allocator>
1715void
1716basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1717{
1718 if (__n > max_size())
1719 this->__throw_length_error();
1720 pointer __p;
1721 if (__n < __min_cap)
1722 {
1723 __set_short_size(__n);
1724 __p = __get_short_pointer();
1725 }
1726 else
1727 {
1728 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001729 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001730 __set_long_pointer(__p);
1731 __set_long_cap(__cap+1);
1732 __set_long_size(__n);
1733 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001734 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001735 traits_type::assign(__p[__n], value_type());
1736}
1737
1738template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001739inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001740basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001741{
1742 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001743#if _LIBCPP_DEBUG_LEVEL >= 2
1744 __get_db()->__insert_c(this);
1745#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001746}
1747
1748template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001749inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001750basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001751 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001752{
1753 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001754#if _LIBCPP_DEBUG_LEVEL >= 2
1755 __get_db()->__insert_c(this);
1756#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001757}
1758
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001759template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001760basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1761 size_type __pos, size_type __n,
1762 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001763 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001764{
1765 size_type __str_sz = __str.size();
1766 if (__pos > __str_sz)
1767 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001768 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00001769#if _LIBCPP_DEBUG_LEVEL >= 2
1770 __get_db()->__insert_c(this);
1771#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001772}
1773
1774template <class _CharT, class _Traits, class _Allocator>
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001775inline _LIBCPP_INLINE_VISIBILITY
1776basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001777 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001778 : __r_(__second_tag(), __a)
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001779{
1780 size_type __str_sz = __str.size();
1781 if (__pos > __str_sz)
1782 this->__throw_out_of_range();
1783 __init(__str.data() + __pos, __str_sz - __pos);
1784#if _LIBCPP_DEBUG_LEVEL >= 2
1785 __get_db()->__insert_c(this);
1786#endif
1787}
1788
1789template <class _CharT, class _Traits, class _Allocator>
Marshall Clowdb7fa112016-11-14 18:22:19 +00001790template <class _Tp>
1791basic_string<_CharT, _Traits, _Allocator>::basic_string(
1792 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a,
Marshall Clowf1729d92017-11-15 20:02:27 +00001793 typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type *)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001794 : __r_(__second_tag(), __a)
Marshall Clowdb7fa112016-11-14 18:22:19 +00001795{
Marshall Clowf1729d92017-11-15 20:02:27 +00001796 __self_view __sv = __self_view(__t).substr(__pos, __n);
Marshall Clowdb7fa112016-11-14 18:22:19 +00001797 __init(__sv.data(), __sv.size());
1798#if _LIBCPP_DEBUG_LEVEL >= 2
1799 __get_db()->__insert_c(this);
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001800#endif
Marshall Clowdb7fa112016-11-14 18:22:19 +00001801}
1802
1803template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001804inline _LIBCPP_INLINE_VISIBILITY
1805basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv)
1806{
1807 __init(__sv.data(), __sv.size());
1808#if _LIBCPP_DEBUG_LEVEL >= 2
1809 __get_db()->__insert_c(this);
1810#endif
1811}
1812
1813template <class _CharT, class _Traits, class _Allocator>
1814inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001815basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001816 : __r_(__second_tag(), __a)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001817{
1818 __init(__sv.data(), __sv.size());
1819#if _LIBCPP_DEBUG_LEVEL >= 2
1820 __get_db()->__insert_c(this);
1821#endif
1822}
1823
1824template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001825template <class _InputIterator>
1826typename enable_if
1827<
Marshall Clowdf9db312016-01-13 21:54:34 +00001828 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001829 void
1830>::type
1831basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
1832{
1833 __zero();
1834#ifndef _LIBCPP_NO_EXCEPTIONS
1835 try
1836 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001837#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001838 for (; __first != __last; ++__first)
1839 push_back(*__first);
1840#ifndef _LIBCPP_NO_EXCEPTIONS
1841 }
1842 catch (...)
1843 {
1844 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001845 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001846 throw;
1847 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001848#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001849}
1850
1851template <class _CharT, class _Traits, class _Allocator>
1852template <class _ForwardIterator>
1853typename enable_if
1854<
1855 __is_forward_iterator<_ForwardIterator>::value,
1856 void
1857>::type
1858basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
1859{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001860 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001861 if (__sz > max_size())
1862 this->__throw_length_error();
1863 pointer __p;
1864 if (__sz < __min_cap)
1865 {
1866 __set_short_size(__sz);
1867 __p = __get_short_pointer();
1868 }
1869 else
1870 {
1871 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001872 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001873 __set_long_pointer(__p);
1874 __set_long_cap(__cap+1);
1875 __set_long_size(__sz);
1876 }
Eric Fiselierb9919752014-10-27 19:28:20 +00001877 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001878 traits_type::assign(*__p, *__first);
1879 traits_type::assign(*__p, value_type());
1880}
1881
1882template <class _CharT, class _Traits, class _Allocator>
1883template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001884inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001885basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
1886{
1887 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00001888#if _LIBCPP_DEBUG_LEVEL >= 2
1889 __get_db()->__insert_c(this);
1890#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001891}
1892
1893template <class _CharT, class _Traits, class _Allocator>
1894template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001895inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001896basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
1897 const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001898 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001899{
1900 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00001901#if _LIBCPP_DEBUG_LEVEL >= 2
1902 __get_db()->__insert_c(this);
1903#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001904}
1905
Eric Fiselier3e928972017-04-19 00:28:44 +00001906#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00001907
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001908template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001909inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001910basic_string<_CharT, _Traits, _Allocator>::basic_string(
1911 initializer_list<_CharT> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001912{
1913 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00001914#if _LIBCPP_DEBUG_LEVEL >= 2
1915 __get_db()->__insert_c(this);
1916#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001917}
1918
1919template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001920inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001921
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001922basic_string<_CharT, _Traits, _Allocator>::basic_string(
1923 initializer_list<_CharT> __il, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001924 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001925{
1926 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00001927#if _LIBCPP_DEBUG_LEVEL >= 2
1928 __get_db()->__insert_c(this);
1929#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001930}
1931
Eric Fiselier3e928972017-04-19 00:28:44 +00001932#endif // _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00001933
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001934template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935basic_string<_CharT, _Traits, _Allocator>::~basic_string()
1936{
Howard Hinnant499cea12013-08-23 17:37:05 +00001937#if _LIBCPP_DEBUG_LEVEL >= 2
1938 __get_db()->__erase_c(this);
1939#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001940 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001941 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001942}
1943
1944template <class _CharT, class _Traits, class _Allocator>
1945void
1946basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
1947 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001948 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 +00001949{
1950 size_type __ms = max_size();
1951 if (__delta_cap > __ms - __old_cap - 1)
1952 this->__throw_length_error();
1953 pointer __old_p = __get_pointer();
1954 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00001955 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001956 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001957 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001958 __invalidate_all_iterators();
1959 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001960 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1961 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001962 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001963 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001964 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1965 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001966 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1967 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001968 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001969 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001970 __set_long_pointer(__p);
1971 __set_long_cap(__cap+1);
1972 __old_sz = __n_copy + __n_add + __sec_cp_sz;
1973 __set_long_size(__old_sz);
1974 traits_type::assign(__p[__old_sz], value_type());
1975}
1976
1977template <class _CharT, class _Traits, class _Allocator>
1978void
1979basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1980 size_type __n_copy, size_type __n_del, size_type __n_add)
1981{
1982 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00001983 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001984 this->__throw_length_error();
1985 pointer __old_p = __get_pointer();
1986 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00001987 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001988 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001989 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001990 __invalidate_all_iterators();
1991 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001992 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1993 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001994 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1995 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001996 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1997 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
1998 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001999 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002000 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002001 __set_long_pointer(__p);
2002 __set_long_cap(__cap+1);
2003}
2004
2005// assign
2006
2007template <class _CharT, class _Traits, class _Allocator>
2008basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002009basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002010{
Alp Tokerec34c482014-05-15 11:27:39 +00002011 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002012 size_type __cap = capacity();
2013 if (__cap >= __n)
2014 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002015 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002016 traits_type::move(__p, __s, __n);
2017 traits_type::assign(__p[__n], value_type());
2018 __set_size(__n);
2019 __invalidate_iterators_past(__n);
2020 }
2021 else
2022 {
2023 size_type __sz = size();
2024 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2025 }
2026 return *this;
2027}
2028
2029template <class _CharT, class _Traits, class _Allocator>
2030basic_string<_CharT, _Traits, _Allocator>&
2031basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2032{
2033 size_type __cap = capacity();
2034 if (__cap < __n)
2035 {
2036 size_type __sz = size();
2037 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2038 }
2039 else
2040 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002041 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002042 traits_type::assign(__p, __n, __c);
2043 traits_type::assign(__p[__n], value_type());
2044 __set_size(__n);
2045 return *this;
2046}
2047
2048template <class _CharT, class _Traits, class _Allocator>
2049basic_string<_CharT, _Traits, _Allocator>&
2050basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2051{
2052 pointer __p;
2053 if (__is_long())
2054 {
2055 __p = __get_long_pointer();
2056 __set_long_size(1);
2057 }
2058 else
2059 {
2060 __p = __get_short_pointer();
2061 __set_short_size(1);
2062 }
2063 traits_type::assign(*__p, __c);
2064 traits_type::assign(*++__p, value_type());
2065 __invalidate_iterators_past(1);
2066 return *this;
2067}
2068
2069template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002070basic_string<_CharT, _Traits, _Allocator>&
2071basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2072{
2073 if (this != &__str)
2074 {
2075 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00002076 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00002077 }
2078 return *this;
2079}
2080
Eric Fiselier3e928972017-04-19 00:28:44 +00002081#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante32b5e22010-11-17 17:55:08 +00002082
2083template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002084inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002085void
2086basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002087 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002088{
2089 if (__alloc() != __str.__alloc())
2090 assign(__str);
2091 else
2092 __move_assign(__str, true_type());
2093}
2094
2095template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002096inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002097void
2098basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002099#if _LIBCPP_STD_VER > 14
2100 _NOEXCEPT
2101#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002102 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002103#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002104{
2105 clear();
2106 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002107 __r_.first() = __str.__r_.first();
2108 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002109 __str.__zero();
2110}
2111
2112template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002113inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002114basic_string<_CharT, _Traits, _Allocator>&
2115basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002116 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002117{
2118 __move_assign(__str, integral_constant<bool,
2119 __alloc_traits::propagate_on_container_move_assignment::value>());
2120 return *this;
2121}
2122
2123#endif
2124
2125template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002126template<class _InputIterator>
2127typename enable_if
2128<
Marshall Clowdf9db312016-01-13 21:54:34 +00002129 __is_exactly_input_iterator <_InputIterator>::value
2130 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002131 basic_string<_CharT, _Traits, _Allocator>&
2132>::type
2133basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2134{
Marshall Clowd979eed2016-09-05 01:54:30 +00002135 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002136 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002137 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002138}
2139
2140template <class _CharT, class _Traits, class _Allocator>
2141template<class _ForwardIterator>
2142typename enable_if
2143<
Marshall Clowdf9db312016-01-13 21:54:34 +00002144 __is_forward_iterator<_ForwardIterator>::value
2145 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002146 basic_string<_CharT, _Traits, _Allocator>&
2147>::type
2148basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2149{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002150 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002151 size_type __cap = capacity();
2152 if (__cap < __n)
2153 {
2154 size_type __sz = size();
2155 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2156 }
2157 else
2158 __invalidate_iterators_past(__n);
2159 pointer __p = __get_pointer();
2160 for (; __first != __last; ++__first, ++__p)
2161 traits_type::assign(*__p, *__first);
2162 traits_type::assign(*__p, value_type());
2163 __set_size(__n);
2164 return *this;
2165}
2166
2167template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002168basic_string<_CharT, _Traits, _Allocator>&
2169basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2170{
2171 size_type __sz = __str.size();
2172 if (__pos > __sz)
2173 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002174 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002175}
2176
2177template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002178template <class _Tp>
2179typename enable_if
2180<
2181 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002182 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002183>::type
2184basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002185{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002186 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002187 size_type __sz = __sv.size();
2188 if (__pos > __sz)
2189 this->__throw_out_of_range();
2190 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2191}
2192
2193
2194template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002195basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002196basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002197{
Alp Tokerec34c482014-05-15 11:27:39 +00002198 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002199 return assign(__s, traits_type::length(__s));
2200}
2201
2202// append
2203
2204template <class _CharT, class _Traits, class _Allocator>
2205basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002206basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002207{
Alp Tokerec34c482014-05-15 11:27:39 +00002208 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002209 size_type __cap = capacity();
2210 size_type __sz = size();
2211 if (__cap - __sz >= __n)
2212 {
2213 if (__n)
2214 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002215 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002216 traits_type::copy(__p + __sz, __s, __n);
2217 __sz += __n;
2218 __set_size(__sz);
2219 traits_type::assign(__p[__sz], value_type());
2220 }
2221 }
2222 else
2223 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2224 return *this;
2225}
2226
2227template <class _CharT, class _Traits, class _Allocator>
2228basic_string<_CharT, _Traits, _Allocator>&
2229basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2230{
2231 if (__n)
2232 {
2233 size_type __cap = capacity();
2234 size_type __sz = size();
2235 if (__cap - __sz < __n)
2236 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2237 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002238 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002239 __sz += __n;
2240 __set_size(__sz);
2241 traits_type::assign(__p[__sz], value_type());
2242 }
2243 return *this;
2244}
2245
2246template <class _CharT, class _Traits, class _Allocator>
2247void
2248basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2249{
Howard Hinnant15467182013-04-30 21:44:48 +00002250 bool __is_short = !__is_long();
2251 size_type __cap;
2252 size_type __sz;
2253 if (__is_short)
2254 {
2255 __cap = __min_cap - 1;
2256 __sz = __get_short_size();
2257 }
2258 else
2259 {
2260 __cap = __get_long_cap() - 1;
2261 __sz = __get_long_size();
2262 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002263 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002264 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002265 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002266 __is_short = !__is_long();
2267 }
2268 pointer __p;
2269 if (__is_short)
2270 {
2271 __p = __get_short_pointer() + __sz;
2272 __set_short_size(__sz+1);
2273 }
2274 else
2275 {
2276 __p = __get_long_pointer() + __sz;
2277 __set_long_size(__sz+1);
2278 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002279 traits_type::assign(*__p, __c);
2280 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002281}
2282
Marshall Clowac655ef2016-09-07 03:32:06 +00002283template <class _Tp>
Marshall Clowd979eed2016-09-05 01:54:30 +00002284bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2285{
2286 return __first <= __p && __p < __last;
2287}
2288
Marshall Clowac655ef2016-09-07 03:32:06 +00002289template <class _Tp1, class _Tp2>
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00002290bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
Marshall Clowac655ef2016-09-07 03:32:06 +00002291{
2292 return false;
2293}
2294
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002295template <class _CharT, class _Traits, class _Allocator>
2296template<class _ForwardIterator>
Eric Fiselier026d38e2016-10-31 02:46:25 +00002297basic_string<_CharT, _Traits, _Allocator>&
2298basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2299 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002300{
Eric Fiselier026d38e2016-10-31 02:46:25 +00002301 static_assert(__is_forward_iterator<_ForwardIterator>::value,
2302 "function requires a ForwardIterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002303 size_type __sz = size();
2304 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002305 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002306 if (__n)
2307 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002308 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2309 _CharRef __tmp_ref = *__first;
2310 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002311 {
2312 const basic_string __temp (__first, __last, __alloc());
2313 append(__temp.data(), __temp.size());
2314 }
2315 else
2316 {
2317 if (__cap - __sz < __n)
2318 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2319 pointer __p = __get_pointer() + __sz;
2320 for (; __first != __last; ++__p, ++__first)
2321 traits_type::assign(*__p, *__first);
2322 traits_type::assign(*__p, value_type());
2323 __set_size(__sz + __n);
2324 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002325 }
2326 return *this;
2327}
2328
2329template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002330inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002331basic_string<_CharT, _Traits, _Allocator>&
2332basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2333{
2334 return append(__str.data(), __str.size());
2335}
2336
2337template <class _CharT, class _Traits, class _Allocator>
2338basic_string<_CharT, _Traits, _Allocator>&
2339basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2340{
2341 size_type __sz = __str.size();
2342 if (__pos > __sz)
2343 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002344 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002345}
2346
2347template <class _CharT, class _Traits, class _Allocator>
Marshall Clow42a87db2016-10-03 23:40:48 +00002348template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002349 typename enable_if
2350 <
2351 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2352 basic_string<_CharT, _Traits, _Allocator>&
2353 >::type
2354basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002355{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002356 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002357 size_type __sz = __sv.size();
2358 if (__pos > __sz)
2359 this->__throw_out_of_range();
2360 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2361}
2362
2363template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002364basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002365basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002366{
Alp Tokerec34c482014-05-15 11:27:39 +00002367 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002368 return append(__s, traits_type::length(__s));
2369}
2370
2371// insert
2372
2373template <class _CharT, class _Traits, class _Allocator>
2374basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002375basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002376{
Alp Tokerec34c482014-05-15 11:27:39 +00002377 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002378 size_type __sz = size();
2379 if (__pos > __sz)
2380 this->__throw_out_of_range();
2381 size_type __cap = capacity();
2382 if (__cap - __sz >= __n)
2383 {
2384 if (__n)
2385 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002386 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002387 size_type __n_move = __sz - __pos;
2388 if (__n_move != 0)
2389 {
2390 if (__p + __pos <= __s && __s < __p + __sz)
2391 __s += __n;
2392 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2393 }
2394 traits_type::move(__p + __pos, __s, __n);
2395 __sz += __n;
2396 __set_size(__sz);
2397 traits_type::assign(__p[__sz], value_type());
2398 }
2399 }
2400 else
2401 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2402 return *this;
2403}
2404
2405template <class _CharT, class _Traits, class _Allocator>
2406basic_string<_CharT, _Traits, _Allocator>&
2407basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2408{
2409 size_type __sz = size();
2410 if (__pos > __sz)
2411 this->__throw_out_of_range();
2412 if (__n)
2413 {
2414 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002415 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002416 if (__cap - __sz >= __n)
2417 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002418 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002419 size_type __n_move = __sz - __pos;
2420 if (__n_move != 0)
2421 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2422 }
2423 else
2424 {
2425 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002426 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002427 }
2428 traits_type::assign(__p + __pos, __n, __c);
2429 __sz += __n;
2430 __set_size(__sz);
2431 traits_type::assign(__p[__sz], value_type());
2432 }
2433 return *this;
2434}
2435
2436template <class _CharT, class _Traits, class _Allocator>
2437template<class _InputIterator>
2438typename enable_if
2439<
Marshall Clowdf9db312016-01-13 21:54:34 +00002440 __is_exactly_input_iterator<_InputIterator>::value
2441 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2442 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002443>::type
2444basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2445{
Howard Hinnant499cea12013-08-23 17:37:05 +00002446#if _LIBCPP_DEBUG_LEVEL >= 2
2447 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2448 "string::insert(iterator, range) called with an iterator not"
2449 " referring to this string");
2450#endif
Marshall Clowd979eed2016-09-05 01:54:30 +00002451 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002452 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002453}
2454
2455template <class _CharT, class _Traits, class _Allocator>
2456template<class _ForwardIterator>
2457typename enable_if
2458<
Marshall Clowdf9db312016-01-13 21:54:34 +00002459 __is_forward_iterator<_ForwardIterator>::value
2460 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002461 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2462>::type
2463basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2464{
Howard Hinnant499cea12013-08-23 17:37:05 +00002465#if _LIBCPP_DEBUG_LEVEL >= 2
2466 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2467 "string::insert(iterator, range) called with an iterator not"
2468 " referring to this string");
2469#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002470 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002471 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002472 if (__n)
2473 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002474 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2475 _CharRef __tmp_char = *__first;
2476 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002477 {
2478 const basic_string __temp(__first, __last, __alloc());
2479 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2480 }
2481
2482 size_type __sz = size();
2483 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002484 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002485 if (__cap - __sz >= __n)
2486 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002487 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002488 size_type __n_move = __sz - __ip;
2489 if (__n_move != 0)
2490 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2491 }
2492 else
2493 {
2494 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002495 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002496 }
2497 __sz += __n;
2498 __set_size(__sz);
2499 traits_type::assign(__p[__sz], value_type());
2500 for (__p += __ip; __first != __last; ++__p, ++__first)
2501 traits_type::assign(*__p, *__first);
2502 }
2503 return begin() + __ip;
2504}
2505
2506template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002507inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002508basic_string<_CharT, _Traits, _Allocator>&
2509basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2510{
2511 return insert(__pos1, __str.data(), __str.size());
2512}
2513
2514template <class _CharT, class _Traits, class _Allocator>
2515basic_string<_CharT, _Traits, _Allocator>&
2516basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2517 size_type __pos2, size_type __n)
2518{
2519 size_type __str_sz = __str.size();
2520 if (__pos2 > __str_sz)
2521 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002522 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002523}
2524
2525template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002526template <class _Tp>
2527typename enable_if
2528<
2529 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002530 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002531>::type
2532basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002533 size_type __pos2, size_type __n)
2534{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002535 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002536 size_type __str_sz = __sv.size();
2537 if (__pos2 > __str_sz)
2538 this->__throw_out_of_range();
2539 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2540}
2541
2542template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002543basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002544basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002545{
Alp Tokerec34c482014-05-15 11:27:39 +00002546 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002547 return insert(__pos, __s, traits_type::length(__s));
2548}
2549
2550template <class _CharT, class _Traits, class _Allocator>
2551typename basic_string<_CharT, _Traits, _Allocator>::iterator
2552basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2553{
2554 size_type __ip = static_cast<size_type>(__pos - begin());
2555 size_type __sz = size();
2556 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002557 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002558 if (__cap == __sz)
2559 {
2560 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002561 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002562 }
2563 else
2564 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002565 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002566 size_type __n_move = __sz - __ip;
2567 if (__n_move != 0)
2568 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2569 }
2570 traits_type::assign(__p[__ip], __c);
2571 traits_type::assign(__p[++__sz], value_type());
2572 __set_size(__sz);
2573 return begin() + static_cast<difference_type>(__ip);
2574}
2575
2576template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002577inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002578typename basic_string<_CharT, _Traits, _Allocator>::iterator
2579basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2580{
Howard Hinnant499cea12013-08-23 17:37:05 +00002581#if _LIBCPP_DEBUG_LEVEL >= 2
2582 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2583 "string::insert(iterator, n, value) called with an iterator not"
2584 " referring to this string");
2585#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002586 difference_type __p = __pos - begin();
2587 insert(static_cast<size_type>(__p), __n, __c);
2588 return begin() + __p;
2589}
2590
2591// replace
2592
2593template <class _CharT, class _Traits, class _Allocator>
2594basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002595basic_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 +00002596 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002597{
Alp Tokerec34c482014-05-15 11:27:39 +00002598 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002599 size_type __sz = size();
2600 if (__pos > __sz)
2601 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002602 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002603 size_type __cap = capacity();
2604 if (__cap - __sz + __n1 >= __n2)
2605 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002606 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002607 if (__n1 != __n2)
2608 {
2609 size_type __n_move = __sz - __pos - __n1;
2610 if (__n_move != 0)
2611 {
2612 if (__n1 > __n2)
2613 {
2614 traits_type::move(__p + __pos, __s, __n2);
2615 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2616 goto __finish;
2617 }
2618 if (__p + __pos < __s && __s < __p + __sz)
2619 {
2620 if (__p + __pos + __n1 <= __s)
2621 __s += __n2 - __n1;
2622 else // __p + __pos < __s < __p + __pos + __n1
2623 {
2624 traits_type::move(__p + __pos, __s, __n1);
2625 __pos += __n1;
2626 __s += __n2;
2627 __n2 -= __n1;
2628 __n1 = 0;
2629 }
2630 }
2631 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2632 }
2633 }
2634 traits_type::move(__p + __pos, __s, __n2);
2635__finish:
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002636// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
2637// but this is a safe operation, so we disable the check.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002638 __sz += __n2 - __n1;
2639 __set_size(__sz);
2640 __invalidate_iterators_past(__sz);
2641 traits_type::assign(__p[__sz], value_type());
2642 }
2643 else
2644 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2645 return *this;
2646}
2647
2648template <class _CharT, class _Traits, class _Allocator>
2649basic_string<_CharT, _Traits, _Allocator>&
2650basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002651 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002652{
2653 size_type __sz = size();
2654 if (__pos > __sz)
2655 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002656 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002657 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002658 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002659 if (__cap - __sz + __n1 >= __n2)
2660 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002661 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002662 if (__n1 != __n2)
2663 {
2664 size_type __n_move = __sz - __pos - __n1;
2665 if (__n_move != 0)
2666 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2667 }
2668 }
2669 else
2670 {
2671 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002672 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002673 }
2674 traits_type::assign(__p + __pos, __n2, __c);
2675 __sz += __n2 - __n1;
2676 __set_size(__sz);
2677 __invalidate_iterators_past(__sz);
2678 traits_type::assign(__p[__sz], value_type());
2679 return *this;
2680}
2681
2682template <class _CharT, class _Traits, class _Allocator>
2683template<class _InputIterator>
2684typename enable_if
2685<
2686 __is_input_iterator<_InputIterator>::value,
2687 basic_string<_CharT, _Traits, _Allocator>&
2688>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002689basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002690 _InputIterator __j1, _InputIterator __j2)
2691{
Marshall Clowd979eed2016-09-05 01:54:30 +00002692 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002693 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002694}
2695
2696template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002697inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002698basic_string<_CharT, _Traits, _Allocator>&
2699basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2700{
2701 return replace(__pos1, __n1, __str.data(), __str.size());
2702}
2703
2704template <class _CharT, class _Traits, class _Allocator>
2705basic_string<_CharT, _Traits, _Allocator>&
2706basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2707 size_type __pos2, size_type __n2)
2708{
2709 size_type __str_sz = __str.size();
2710 if (__pos2 > __str_sz)
2711 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002712 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002713}
2714
2715template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002716template <class _Tp>
2717typename enable_if
2718<
Marshall Clowf1729d92017-11-15 20:02:27 +00002719 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2720 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002721>::type
2722basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002723 size_type __pos2, size_type __n2)
2724{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002725 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002726 size_type __str_sz = __sv.size();
2727 if (__pos2 > __str_sz)
2728 this->__throw_out_of_range();
2729 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2730}
2731
2732template <class _CharT, class _Traits, class _Allocator>
2733basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002734basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002735{
Alp Tokerec34c482014-05-15 11:27:39 +00002736 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002737 return replace(__pos, __n1, __s, traits_type::length(__s));
2738}
2739
2740template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002741inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002742basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002743basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002744{
2745 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2746 __str.data(), __str.size());
2747}
2748
2749template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002750inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002751basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002752basic_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 +00002753{
2754 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2755}
2756
2757template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002758inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002759basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002760basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002761{
2762 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2763}
2764
2765template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002766inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002767basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002768basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002769{
2770 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2771}
2772
2773// erase
2774
2775template <class _CharT, class _Traits, class _Allocator>
2776basic_string<_CharT, _Traits, _Allocator>&
2777basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2778{
2779 size_type __sz = size();
2780 if (__pos > __sz)
2781 this->__throw_out_of_range();
2782 if (__n)
2783 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002784 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002785 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002786 size_type __n_move = __sz - __pos - __n;
2787 if (__n_move != 0)
2788 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2789 __sz -= __n;
2790 __set_size(__sz);
2791 __invalidate_iterators_past(__sz);
2792 traits_type::assign(__p[__sz], value_type());
2793 }
2794 return *this;
2795}
2796
2797template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002798inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002799typename basic_string<_CharT, _Traits, _Allocator>::iterator
2800basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2801{
Howard Hinnant499cea12013-08-23 17:37:05 +00002802#if _LIBCPP_DEBUG_LEVEL >= 2
2803 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2804 "string::erase(iterator) called with an iterator not"
2805 " referring to this string");
2806#endif
2807 _LIBCPP_ASSERT(__pos != end(),
2808 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002809 iterator __b = begin();
2810 size_type __r = static_cast<size_type>(__pos - __b);
2811 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002812 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002813}
2814
2815template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002816inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002817typename basic_string<_CharT, _Traits, _Allocator>::iterator
2818basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2819{
Howard Hinnant499cea12013-08-23 17:37:05 +00002820#if _LIBCPP_DEBUG_LEVEL >= 2
2821 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2822 "string::erase(iterator, iterator) called with an iterator not"
2823 " referring to this string");
2824#endif
2825 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002826 iterator __b = begin();
2827 size_type __r = static_cast<size_type>(__first - __b);
2828 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00002829 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002830}
2831
2832template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002833inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002834void
2835basic_string<_CharT, _Traits, _Allocator>::pop_back()
2836{
Howard Hinnant499cea12013-08-23 17:37:05 +00002837 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002838 size_type __sz;
2839 if (__is_long())
2840 {
2841 __sz = __get_long_size() - 1;
2842 __set_long_size(__sz);
2843 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2844 }
2845 else
2846 {
2847 __sz = __get_short_size() - 1;
2848 __set_short_size(__sz);
2849 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2850 }
2851 __invalidate_iterators_past(__sz);
2852}
2853
2854template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002855inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002856void
Howard Hinnanta6119a82011-05-29 19:57:12 +00002857basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002858{
2859 __invalidate_all_iterators();
2860 if (__is_long())
2861 {
2862 traits_type::assign(*__get_long_pointer(), value_type());
2863 __set_long_size(0);
2864 }
2865 else
2866 {
2867 traits_type::assign(*__get_short_pointer(), value_type());
2868 __set_short_size(0);
2869 }
2870}
2871
2872template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002873inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002874void
2875basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2876{
2877 if (__is_long())
2878 {
2879 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2880 __set_long_size(__pos);
2881 }
2882 else
2883 {
2884 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2885 __set_short_size(__pos);
2886 }
2887 __invalidate_iterators_past(__pos);
2888}
2889
2890template <class _CharT, class _Traits, class _Allocator>
2891void
2892basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2893{
2894 size_type __sz = size();
2895 if (__n > __sz)
2896 append(__n - __sz, __c);
2897 else
2898 __erase_to_end(__n);
2899}
2900
2901template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002902inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002903typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002904basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002905{
Howard Hinnante32b5e22010-11-17 17:55:08 +00002906 size_type __m = __alloc_traits::max_size(__alloc());
Eric Fiselier5ccf0432017-10-17 13:16:01 +00002907#ifdef _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00002908 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002909#else
Marshall Clow09f85502013-10-31 17:23:08 +00002910 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002911#endif
2912}
2913
2914template <class _CharT, class _Traits, class _Allocator>
2915void
2916basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2917{
2918 if (__res_arg > max_size())
2919 this->__throw_length_error();
2920 size_type __cap = capacity();
2921 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002922 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002923 __res_arg = __recommend(__res_arg);
2924 if (__res_arg != __cap)
2925 {
2926 pointer __new_data, __p;
2927 bool __was_long, __now_long;
2928 if (__res_arg == __min_cap - 1)
2929 {
2930 __was_long = true;
2931 __now_long = false;
2932 __new_data = __get_short_pointer();
2933 __p = __get_long_pointer();
2934 }
2935 else
2936 {
2937 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002938 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002939 else
2940 {
2941 #ifndef _LIBCPP_NO_EXCEPTIONS
2942 try
2943 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002944 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00002945 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002946 #ifndef _LIBCPP_NO_EXCEPTIONS
2947 }
2948 catch (...)
2949 {
2950 return;
2951 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002952 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002953 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002954 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00002955 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002956 }
2957 __now_long = true;
2958 __was_long = __is_long();
2959 __p = __get_pointer();
2960 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002961 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
2962 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002963 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002964 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002965 if (__now_long)
2966 {
2967 __set_long_cap(__res_arg+1);
2968 __set_long_size(__sz);
2969 __set_long_pointer(__new_data);
2970 }
2971 else
2972 __set_short_size(__sz);
2973 __invalidate_all_iterators();
2974 }
2975}
2976
2977template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002978inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002979typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002980basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002981{
Howard Hinnant499cea12013-08-23 17:37:05 +00002982 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002983 return *(data() + __pos);
2984}
2985
2986template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002987inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002988typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002989basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002990{
Howard Hinnant499cea12013-08-23 17:37:05 +00002991 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002992 return *(__get_pointer() + __pos);
2993}
2994
2995template <class _CharT, class _Traits, class _Allocator>
2996typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2997basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
2998{
2999 if (__n >= size())
3000 this->__throw_out_of_range();
3001 return (*this)[__n];
3002}
3003
3004template <class _CharT, class _Traits, class _Allocator>
3005typename basic_string<_CharT, _Traits, _Allocator>::reference
3006basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3007{
3008 if (__n >= size())
3009 this->__throw_out_of_range();
3010 return (*this)[__n];
3011}
3012
3013template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003014inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003015typename basic_string<_CharT, _Traits, _Allocator>::reference
3016basic_string<_CharT, _Traits, _Allocator>::front()
3017{
Howard Hinnant499cea12013-08-23 17:37:05 +00003018 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003019 return *__get_pointer();
3020}
3021
3022template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003023inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003024typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3025basic_string<_CharT, _Traits, _Allocator>::front() const
3026{
Howard Hinnant499cea12013-08-23 17:37:05 +00003027 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003028 return *data();
3029}
3030
3031template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003032inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003033typename basic_string<_CharT, _Traits, _Allocator>::reference
3034basic_string<_CharT, _Traits, _Allocator>::back()
3035{
Howard Hinnant499cea12013-08-23 17:37:05 +00003036 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003037 return *(__get_pointer() + size() - 1);
3038}
3039
3040template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003041inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003042typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3043basic_string<_CharT, _Traits, _Allocator>::back() const
3044{
Howard Hinnant499cea12013-08-23 17:37:05 +00003045 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003046 return *(data() + size() - 1);
3047}
3048
3049template <class _CharT, class _Traits, class _Allocator>
3050typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003051basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003052{
3053 size_type __sz = size();
3054 if (__pos > __sz)
3055 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003056 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003057 traits_type::copy(__s, data() + __pos, __rlen);
3058 return __rlen;
3059}
3060
3061template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003062inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003063basic_string<_CharT, _Traits, _Allocator>
3064basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3065{
3066 return basic_string(*this, __pos, __n, __alloc());
3067}
3068
3069template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003070inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003071void
3072basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00003073#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00003074 _NOEXCEPT_DEBUG
Marshall Clow7d914d12015-07-13 20:04:56 +00003075#else
Eric Fiselier47257c42016-12-28 05:53:01 +00003076 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00003077 __is_nothrow_swappable<allocator_type>::value)
3078#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003079{
Howard Hinnant499cea12013-08-23 17:37:05 +00003080#if _LIBCPP_DEBUG_LEVEL >= 2
3081 if (!__is_long())
3082 __get_db()->__invalidate_all(this);
3083 if (!__str.__is_long())
3084 __get_db()->__invalidate_all(&__str);
3085 __get_db()->swap(this, &__str);
3086#endif
Eric Fiselier47257c42016-12-28 05:53:01 +00003087 _LIBCPP_ASSERT(
3088 __alloc_traits::propagate_on_container_swap::value ||
3089 __alloc_traits::is_always_equal::value ||
3090 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnant0949eed2011-06-30 21:18:19 +00003091 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00003092 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003093}
3094
3095// find
3096
3097template <class _Traits>
3098struct _LIBCPP_HIDDEN __traits_eq
3099{
3100 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003101 _LIBCPP_INLINE_VISIBILITY
3102 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3103 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003104};
3105
3106template<class _CharT, class _Traits, class _Allocator>
3107typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003108basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003109 size_type __pos,
3110 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003111{
Alp Tokerec34c482014-05-15 11:27:39 +00003112 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003113 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003114 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003115}
3116
3117template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003118inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003119typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003120basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3121 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003122{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003123 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003124 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003125}
3126
3127template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003128inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003129typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003130basic_string<_CharT, _Traits, _Allocator>::find(__self_view __sv,
3131 size_type __pos) const _NOEXCEPT
3132{
3133 return __str_find<value_type, size_type, traits_type, npos>
3134 (data(), size(), __sv.data(), __pos, __sv.size());
3135}
3136
3137template<class _CharT, class _Traits, class _Allocator>
3138inline _LIBCPP_INLINE_VISIBILITY
3139typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003140basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003141 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003142{
Alp Tokerec34c482014-05-15 11:27:39 +00003143 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003144 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003145 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003146}
3147
3148template<class _CharT, class _Traits, class _Allocator>
3149typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003150basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3151 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003152{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003153 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003154 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003155}
3156
3157// rfind
3158
3159template<class _CharT, class _Traits, class _Allocator>
3160typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003161basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003162 size_type __pos,
3163 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003164{
Alp Tokerec34c482014-05-15 11:27:39 +00003165 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003166 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003167 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003168}
3169
3170template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003171inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003172typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003173basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3174 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003175{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003176 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003177 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003178}
3179
3180template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003181inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003182typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003183basic_string<_CharT, _Traits, _Allocator>::rfind(__self_view __sv,
3184 size_type __pos) const _NOEXCEPT
3185{
3186 return __str_rfind<value_type, size_type, traits_type, npos>
3187 (data(), size(), __sv.data(), __pos, __sv.size());
3188}
3189
3190template<class _CharT, class _Traits, class _Allocator>
3191inline _LIBCPP_INLINE_VISIBILITY
3192typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003193basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003194 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003195{
Alp Tokerec34c482014-05-15 11:27:39 +00003196 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003197 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003198 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003199}
3200
3201template<class _CharT, class _Traits, class _Allocator>
3202typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003203basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3204 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003205{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003206 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003207 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003208}
3209
3210// find_first_of
3211
3212template<class _CharT, class _Traits, class _Allocator>
3213typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003214basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003215 size_type __pos,
3216 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003217{
Alp Tokerec34c482014-05-15 11:27:39 +00003218 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003219 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003220 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003221}
3222
3223template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003224inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003225typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003226basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3227 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003228{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003229 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003230 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003231}
3232
3233template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003234inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003235typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003236basic_string<_CharT, _Traits, _Allocator>::find_first_of(__self_view __sv,
3237 size_type __pos) const _NOEXCEPT
3238{
3239 return __str_find_first_of<value_type, size_type, traits_type, npos>
3240 (data(), size(), __sv.data(), __pos, __sv.size());
3241}
3242
3243template<class _CharT, class _Traits, class _Allocator>
3244inline _LIBCPP_INLINE_VISIBILITY
3245typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003246basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003247 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003248{
Alp Tokerec34c482014-05-15 11:27:39 +00003249 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003250 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003251 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003252}
3253
3254template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003255inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003256typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003257basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3258 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003259{
3260 return find(__c, __pos);
3261}
3262
3263// find_last_of
3264
3265template<class _CharT, class _Traits, class _Allocator>
3266typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003267basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003268 size_type __pos,
3269 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003270{
Alp Tokerec34c482014-05-15 11:27:39 +00003271 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003272 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003273 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003274}
3275
3276template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003277inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003278typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003279basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3280 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003281{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003282 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003283 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003284}
3285
3286template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003287inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003288typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003289basic_string<_CharT, _Traits, _Allocator>::find_last_of(__self_view __sv,
3290 size_type __pos) const _NOEXCEPT
3291{
3292 return __str_find_last_of<value_type, size_type, traits_type, npos>
3293 (data(), size(), __sv.data(), __pos, __sv.size());
3294}
3295
3296template<class _CharT, class _Traits, class _Allocator>
3297inline _LIBCPP_INLINE_VISIBILITY
3298typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003299basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003300 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003301{
Alp Tokerec34c482014-05-15 11:27:39 +00003302 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003303 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003304 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003305}
3306
3307template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003308inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003309typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003310basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3311 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003312{
3313 return rfind(__c, __pos);
3314}
3315
3316// find_first_not_of
3317
3318template<class _CharT, class _Traits, class _Allocator>
3319typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003320basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003321 size_type __pos,
3322 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003323{
Alp Tokerec34c482014-05-15 11:27:39 +00003324 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003325 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003326 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003327}
3328
3329template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003330inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003331typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003332basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3333 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003334{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003335 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003336 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003337}
3338
3339template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003340inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003341typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003342basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(__self_view __sv,
3343 size_type __pos) const _NOEXCEPT
3344{
3345 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3346 (data(), size(), __sv.data(), __pos, __sv.size());
3347}
3348
3349template<class _CharT, class _Traits, class _Allocator>
3350inline _LIBCPP_INLINE_VISIBILITY
3351typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003352basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003353 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003354{
Alp Tokerec34c482014-05-15 11:27:39 +00003355 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003356 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003357 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003358}
3359
3360template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003361inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003362typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003363basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3364 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003365{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003366 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003367 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003368}
3369
3370// find_last_not_of
3371
3372template<class _CharT, class _Traits, class _Allocator>
3373typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003374basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003375 size_type __pos,
3376 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003377{
Alp Tokerec34c482014-05-15 11:27:39 +00003378 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003379 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003380 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003381}
3382
3383template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003384inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003385typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003386basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3387 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003388{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003389 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003390 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003391}
3392
3393template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003394inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003395typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003396basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(__self_view __sv,
3397 size_type __pos) const _NOEXCEPT
3398{
3399 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3400 (data(), size(), __sv.data(), __pos, __sv.size());
3401}
3402
3403template<class _CharT, class _Traits, class _Allocator>
3404inline _LIBCPP_INLINE_VISIBILITY
3405typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003406basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003407 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003408{
Alp Tokerec34c482014-05-15 11:27:39 +00003409 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003410 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003411 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003412}
3413
3414template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003415inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003416typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003417basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3418 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003419{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003420 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003421 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003422}
3423
3424// compare
3425
3426template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003427inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003428int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003429basic_string<_CharT, _Traits, _Allocator>::compare(__self_view __sv) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003430{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003431 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003432 size_t __rhs_sz = __sv.size();
3433 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:06 +00003434 _VSTD::min(__lhs_sz, __rhs_sz));
3435 if (__result != 0)
3436 return __result;
3437 if (__lhs_sz < __rhs_sz)
3438 return -1;
3439 if (__lhs_sz > __rhs_sz)
3440 return 1;
3441 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003442}
3443
3444template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003445inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003446int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003447basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003448{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003449 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003450}
3451
3452template <class _CharT, class _Traits, class _Allocator>
3453int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003454basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3455 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003456 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003457 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003458{
Alp Tokerec34c482014-05-15 11:27:39 +00003459 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003460 size_type __sz = size();
3461 if (__pos1 > __sz || __n2 == npos)
3462 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003463 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3464 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003465 if (__r == 0)
3466 {
3467 if (__rlen < __n2)
3468 __r = -1;
3469 else if (__rlen > __n2)
3470 __r = 1;
3471 }
3472 return __r;
3473}
3474
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003475template <class _CharT, class _Traits, class _Allocator>
3476inline _LIBCPP_INLINE_VISIBILITY
3477int
3478basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3479 size_type __n1,
3480 __self_view __sv) const
3481{
3482 return compare(__pos1, __n1, __sv.data(), __sv.size());
3483}
3484
3485template <class _CharT, class _Traits, class _Allocator>
3486inline _LIBCPP_INLINE_VISIBILITY
3487int
3488basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3489 size_type __n1,
3490 const basic_string& __str) const
3491{
3492 return compare(__pos1, __n1, __str.data(), __str.size());
3493}
3494
3495template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00003496template <class _Tp>
3497typename enable_if
3498<
Marshall Clowf1729d92017-11-15 20:02:27 +00003499 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3500 int
Marshall Clow6ac8de02016-09-24 22:45:42 +00003501>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003502basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3503 size_type __n1,
Marshall Clow6ac8de02016-09-24 22:45:42 +00003504 const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003505 size_type __pos2,
3506 size_type __n2) const
3507{
Marshall Clow6ac8de02016-09-24 22:45:42 +00003508 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003509 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3510}
3511
3512template <class _CharT, class _Traits, class _Allocator>
3513int
3514basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3515 size_type __n1,
3516 const basic_string& __str,
3517 size_type __pos2,
3518 size_type __n2) const
3519{
3520 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3521}
3522
3523template <class _CharT, class _Traits, class _Allocator>
3524int
3525basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3526{
3527 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3528 return compare(0, npos, __s, traits_type::length(__s));
3529}
3530
3531template <class _CharT, class _Traits, class _Allocator>
3532int
3533basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3534 size_type __n1,
3535 const value_type* __s) const
3536{
3537 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3538 return compare(__pos1, __n1, __s, traits_type::length(__s));
3539}
3540
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003541// __invariants
3542
3543template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003544inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003545bool
3546basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3547{
3548 if (size() > capacity())
3549 return false;
3550 if (capacity() < __min_cap - 1)
3551 return false;
3552 if (data() == 0)
3553 return false;
3554 if (data()[size()] != value_type(0))
3555 return false;
3556 return true;
3557}
3558
3559// operator==
3560
3561template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003562inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003563bool
3564operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003565 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003566{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003567 size_t __lhs_sz = __lhs.size();
3568 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3569 __rhs.data(),
3570 __lhs_sz) == 0;
3571}
3572
3573template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003574inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003575bool
3576operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3577 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3578{
3579 size_t __lhs_sz = __lhs.size();
3580 if (__lhs_sz != __rhs.size())
3581 return false;
3582 const char* __lp = __lhs.data();
3583 const char* __rp = __rhs.data();
3584 if (__lhs.__is_long())
3585 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3586 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3587 if (*__lp != *__rp)
3588 return false;
3589 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003590}
3591
3592template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003593inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003594bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003595operator==(const _CharT* __lhs,
3596 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003597{
Eric Fiselier4f241822015-08-28 03:02:37 +00003598 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3599 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3600 size_t __lhs_len = _Traits::length(__lhs);
3601 if (__lhs_len != __rhs.size()) return false;
3602 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003603}
3604
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003605template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003606inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003607bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003608operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3609 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003610{
Eric Fiselier4f241822015-08-28 03:02:37 +00003611 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3612 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3613 size_t __rhs_len = _Traits::length(__rhs);
3614 if (__rhs_len != __lhs.size()) return false;
3615 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003616}
3617
Howard Hinnant324bb032010-08-22 00:02:43 +00003618template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003619inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003620bool
3621operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003622 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003623{
3624 return !(__lhs == __rhs);
3625}
3626
3627template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003628inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003629bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003630operator!=(const _CharT* __lhs,
3631 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003632{
3633 return !(__lhs == __rhs);
3634}
3635
3636template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003637inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003638bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003639operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3640 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003641{
3642 return !(__lhs == __rhs);
3643}
3644
3645// operator<
3646
3647template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003648inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003649bool
3650operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003651 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003652{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003653 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003654}
3655
3656template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003657inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003658bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003659operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3660 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003661{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003662 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003663}
3664
3665template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003666inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003667bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003668operator< (const _CharT* __lhs,
3669 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003670{
3671 return __rhs.compare(__lhs) > 0;
3672}
3673
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003674// operator>
3675
3676template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003677inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003678bool
3679operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003680 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003681{
3682 return __rhs < __lhs;
3683}
3684
3685template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003686inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003687bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003688operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3689 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003690{
3691 return __rhs < __lhs;
3692}
3693
3694template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003695inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003696bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003697operator> (const _CharT* __lhs,
3698 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003699{
3700 return __rhs < __lhs;
3701}
3702
3703// operator<=
3704
3705template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003706inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003707bool
3708operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003709 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003710{
3711 return !(__rhs < __lhs);
3712}
3713
3714template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003715inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003716bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003717operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3718 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003719{
3720 return !(__rhs < __lhs);
3721}
3722
3723template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003724inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003725bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003726operator<=(const _CharT* __lhs,
3727 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003728{
3729 return !(__rhs < __lhs);
3730}
3731
3732// operator>=
3733
3734template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003735inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003736bool
3737operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003738 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003739{
3740 return !(__lhs < __rhs);
3741}
3742
3743template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003744inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003745bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003746operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3747 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003748{
3749 return !(__lhs < __rhs);
3750}
3751
3752template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003753inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003754bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003755operator>=(const _CharT* __lhs,
3756 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003757{
3758 return !(__lhs < __rhs);
3759}
3760
3761// operator +
3762
3763template<class _CharT, class _Traits, class _Allocator>
3764basic_string<_CharT, _Traits, _Allocator>
3765operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3766 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3767{
3768 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3769 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3770 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3771 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3772 __r.append(__rhs.data(), __rhs_sz);
3773 return __r;
3774}
3775
3776template<class _CharT, class _Traits, class _Allocator>
3777basic_string<_CharT, _Traits, _Allocator>
3778operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3779{
3780 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3781 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3782 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3783 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3784 __r.append(__rhs.data(), __rhs_sz);
3785 return __r;
3786}
3787
3788template<class _CharT, class _Traits, class _Allocator>
3789basic_string<_CharT, _Traits, _Allocator>
3790operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3791{
3792 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3793 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3794 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3795 __r.append(__rhs.data(), __rhs_sz);
3796 return __r;
3797}
3798
3799template<class _CharT, class _Traits, class _Allocator>
3800basic_string<_CharT, _Traits, _Allocator>
3801operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3802{
3803 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3804 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3805 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3806 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3807 __r.append(__rhs, __rhs_sz);
3808 return __r;
3809}
3810
3811template<class _CharT, class _Traits, class _Allocator>
3812basic_string<_CharT, _Traits, _Allocator>
3813operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3814{
3815 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3816 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3817 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3818 __r.push_back(__rhs);
3819 return __r;
3820}
3821
Eric Fiselier3e928972017-04-19 00:28:44 +00003822#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003823
3824template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003825inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003826basic_string<_CharT, _Traits, _Allocator>
3827operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3828{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003829 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003830}
3831
3832template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003833inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003834basic_string<_CharT, _Traits, _Allocator>
3835operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3836{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003837 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003838}
3839
3840template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003841inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003842basic_string<_CharT, _Traits, _Allocator>
3843operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3844{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003845 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003846}
3847
3848template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003849inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003850basic_string<_CharT, _Traits, _Allocator>
3851operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3852{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003853 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003854}
3855
3856template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003857inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003858basic_string<_CharT, _Traits, _Allocator>
3859operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3860{
3861 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003862 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003863}
3864
3865template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003866inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003867basic_string<_CharT, _Traits, _Allocator>
3868operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3869{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003870 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003871}
3872
3873template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003874inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003875basic_string<_CharT, _Traits, _Allocator>
3876operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3877{
3878 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003879 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003880}
3881
Eric Fiselier3e928972017-04-19 00:28:44 +00003882#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003883
3884// swap
3885
3886template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003887inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003888void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003889swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003890 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3891 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003892{
3893 __lhs.swap(__rhs);
3894}
3895
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003896#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3897
3898typedef basic_string<char16_t> u16string;
3899typedef basic_string<char32_t> u32string;
3900
Howard Hinnant324bb032010-08-22 00:02:43 +00003901#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003902
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003903_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3904_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3905_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3906_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
3907_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003908
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003909_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
3910_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
3911_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003912
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003913_LIBCPP_FUNC_VIS string to_string(int __val);
3914_LIBCPP_FUNC_VIS string to_string(unsigned __val);
3915_LIBCPP_FUNC_VIS string to_string(long __val);
3916_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
3917_LIBCPP_FUNC_VIS string to_string(long long __val);
3918_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
3919_LIBCPP_FUNC_VIS string to_string(float __val);
3920_LIBCPP_FUNC_VIS string to_string(double __val);
3921_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003922
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003923_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
3924_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
3925_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
3926_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
3927_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003928
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003929_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
3930_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
3931_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003932
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003933_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
3934_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
3935_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
3936_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
3937_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
3938_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
3939_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
3940_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
3941_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003942
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003943template<class _CharT, class _Traits, class _Allocator>
3944 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
3945 basic_string<_CharT, _Traits, _Allocator>::npos;
3946
3947template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +00003948struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003949 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
3950{
3951 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00003952 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003953};
3954
3955template<class _CharT, class _Traits, class _Allocator>
3956size_t
3957hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00003958 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003959{
Sean Huntaffd9e52011-07-29 23:31:56 +00003960 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003961}
3962
Howard Hinnant464aa5c2011-07-18 15:51:59 +00003963template<class _CharT, class _Traits, class _Allocator>
3964basic_ostream<_CharT, _Traits>&
3965operator<<(basic_ostream<_CharT, _Traits>& __os,
3966 const basic_string<_CharT, _Traits, _Allocator>& __str);
3967
3968template<class _CharT, class _Traits, class _Allocator>
3969basic_istream<_CharT, _Traits>&
3970operator>>(basic_istream<_CharT, _Traits>& __is,
3971 basic_string<_CharT, _Traits, _Allocator>& __str);
3972
3973template<class _CharT, class _Traits, class _Allocator>
3974basic_istream<_CharT, _Traits>&
3975getline(basic_istream<_CharT, _Traits>& __is,
3976 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3977
3978template<class _CharT, class _Traits, class _Allocator>
3979inline _LIBCPP_INLINE_VISIBILITY
3980basic_istream<_CharT, _Traits>&
3981getline(basic_istream<_CharT, _Traits>& __is,
3982 basic_string<_CharT, _Traits, _Allocator>& __str);
3983
Eric Fiselier3e928972017-04-19 00:28:44 +00003984#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00003985
3986template<class _CharT, class _Traits, class _Allocator>
3987inline _LIBCPP_INLINE_VISIBILITY
3988basic_istream<_CharT, _Traits>&
3989getline(basic_istream<_CharT, _Traits>&& __is,
3990 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3991
3992template<class _CharT, class _Traits, class _Allocator>
3993inline _LIBCPP_INLINE_VISIBILITY
3994basic_istream<_CharT, _Traits>&
3995getline(basic_istream<_CharT, _Traits>&& __is,
3996 basic_string<_CharT, _Traits, _Allocator>& __str);
3997
Eric Fiselier3e928972017-04-19 00:28:44 +00003998#endif // _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00003999
Howard Hinnant499cea12013-08-23 17:37:05 +00004000#if _LIBCPP_DEBUG_LEVEL >= 2
4001
4002template<class _CharT, class _Traits, class _Allocator>
4003bool
4004basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4005{
4006 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4007 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4008}
4009
4010template<class _CharT, class _Traits, class _Allocator>
4011bool
4012basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4013{
4014 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4015 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4016}
4017
4018template<class _CharT, class _Traits, class _Allocator>
4019bool
4020basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4021{
4022 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4023 return this->data() <= __p && __p <= this->data() + this->size();
4024}
4025
4026template<class _CharT, class _Traits, class _Allocator>
4027bool
4028basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4029{
4030 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4031 return this->data() <= __p && __p < this->data() + this->size();
4032}
4033
4034#endif // _LIBCPP_DEBUG_LEVEL >= 2
4035
Shoaib Meenai68506702017-06-29 02:52:46 +00004036_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
4037_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Shoaib Meenai68506702017-06-29 02:52:46 +00004038
Marshall Clow15234322013-07-23 17:05:24 +00004039#if _LIBCPP_STD_VER > 11
4040// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004041inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004042{
4043 inline namespace string_literals
4044 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004045 inline _LIBCPP_INLINE_VISIBILITY
4046 basic_string<char> operator "" s( const char *__str, size_t __len )
4047 {
4048 return basic_string<char> (__str, __len);
4049 }
Marshall Clow15234322013-07-23 17:05:24 +00004050
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004051 inline _LIBCPP_INLINE_VISIBILITY
4052 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4053 {
4054 return basic_string<wchar_t> (__str, __len);
4055 }
Marshall Clow15234322013-07-23 17:05:24 +00004056
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004057 inline _LIBCPP_INLINE_VISIBILITY
4058 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4059 {
4060 return basic_string<char16_t> (__str, __len);
4061 }
Marshall Clow15234322013-07-23 17:05:24 +00004062
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004063 inline _LIBCPP_INLINE_VISIBILITY
4064 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4065 {
4066 return basic_string<char32_t> (__str, __len);
4067 }
Marshall Clow15234322013-07-23 17:05:24 +00004068 }
4069}
4070#endif
4071
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004072_LIBCPP_END_NAMESPACE_STD
4073
Eric Fiselier018a3d52017-05-31 22:07:49 +00004074_LIBCPP_POP_MACROS
4075
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004076#endif // _LIBCPP_STRING