blob: e8ec709c25aaf7c24f1f6e944ee2133d8edf523d [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
Marshall Clow5b1e87e2018-02-08 06:34:03 +0000314template<class InputIterator,
315 class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
316basic_string(InputIterator, InputIterator, Allocator = Allocator())
317 -> basic_string<typename iterator_traits<InputIterator>::value_type,
318 char_traits<typename iterator_traits<InputIterator>::value_type>,
319 Allocator>; // C++17
320
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000321template<class charT, class traits, class Allocator>
322basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000323operator+(const basic_string<charT, traits, Allocator>& lhs,
324 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000325
326template<class charT, class traits, class Allocator>
327basic_string<charT, traits, Allocator>
328operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
329
330template<class charT, class traits, class Allocator>
331basic_string<charT, traits, Allocator>
332operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
333
334template<class charT, class traits, class Allocator>
335basic_string<charT, traits, Allocator>
336operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
337
338template<class charT, class traits, class Allocator>
339basic_string<charT, traits, Allocator>
340operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
341
342template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000343bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000344 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345
346template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000347bool operator==(const charT* lhs, 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 basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000351
Howard Hinnant324bb032010-08-22 00:02:43 +0000352template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000353bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000354 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355
356template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000357bool operator!=(const charT* lhs, 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 Hinnanta6a062d2010-06-02 18:20:39 +0000363bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000364 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365
366template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000367bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* 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 charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371
372template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000373bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000374 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000375
376template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000377bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* 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 charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381
382template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000383bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000384 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000385
386template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000387bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* 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 charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000391
392template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000393bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000394 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000395
396template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000397bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000398
399template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000400bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000401
402template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000403void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000404 basic_string<charT, traits, Allocator>& rhs)
405 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000406
407template<class charT, class traits, class Allocator>
408basic_istream<charT, traits>&
409operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
410
411template<class charT, class traits, class Allocator>
412basic_ostream<charT, traits>&
413operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
414
415template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000416basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000417getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
418 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419
420template<class charT, class traits, class Allocator>
421basic_istream<charT, traits>&
422getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
423
424typedef basic_string<char> string;
425typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000426typedef basic_string<char16_t> u16string;
427typedef basic_string<char32_t> u32string;
428
429int stoi (const string& str, size_t* idx = 0, int base = 10);
430long stol (const string& str, size_t* idx = 0, int base = 10);
431unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
432long long stoll (const string& str, size_t* idx = 0, int base = 10);
433unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
434
435float stof (const string& str, size_t* idx = 0);
436double stod (const string& str, size_t* idx = 0);
437long double stold(const string& str, size_t* idx = 0);
438
439string to_string(int val);
440string to_string(unsigned val);
441string to_string(long val);
442string to_string(unsigned long val);
443string to_string(long long val);
444string to_string(unsigned long long val);
445string to_string(float val);
446string to_string(double val);
447string to_string(long double val);
448
449int stoi (const wstring& str, size_t* idx = 0, int base = 10);
450long stol (const wstring& str, size_t* idx = 0, int base = 10);
451unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
452long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
453unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
454
455float stof (const wstring& str, size_t* idx = 0);
456double stod (const wstring& str, size_t* idx = 0);
457long double stold(const wstring& str, size_t* idx = 0);
458
459wstring to_wstring(int val);
460wstring to_wstring(unsigned val);
461wstring to_wstring(long val);
462wstring to_wstring(unsigned long val);
463wstring to_wstring(long long val);
464wstring to_wstring(unsigned long long val);
465wstring to_wstring(float val);
466wstring to_wstring(double val);
467wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000468
469template <> struct hash<string>;
470template <> struct hash<u16string>;
471template <> struct hash<u32string>;
472template <> struct hash<wstring>;
473
Marshall Clow15234322013-07-23 17:05:24 +0000474basic_string<char> operator "" s( const char *str, size_t len ); // C++14
475basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
476basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
477basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
478
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000479} // std
480
481*/
482
483#include <__config>
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000484#include <string_view>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000485#include <iosfwd>
486#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000487#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000488#include <cwchar>
489#include <algorithm>
490#include <iterator>
491#include <utility>
492#include <memory>
493#include <stdexcept>
494#include <type_traits>
495#include <initializer_list>
496#include <__functional_base>
497#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
498#include <cstdint>
499#endif
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000500
Eric Fiselierb9536102014-08-10 23:53:08 +0000501#include <__debug>
502
Howard Hinnant08e17472011-10-17 20:05:10 +0000503#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000505#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000506
Eric Fiselier018a3d52017-05-31 22:07:49 +0000507_LIBCPP_PUSH_MACROS
508#include <__undef_macros>
509
510
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000511_LIBCPP_BEGIN_NAMESPACE_STD
512
513// fpos
514
515template <class _StateT>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000516class _LIBCPP_TEMPLATE_VIS fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517{
518private:
519 _StateT __st_;
520 streamoff __off_;
521public:
522 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
523
524 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
525
526 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
527 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
528
529 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
530 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
531 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
532 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
533};
534
535template <class _StateT>
536inline _LIBCPP_INLINE_VISIBILITY
537streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
538 {return streamoff(__x) - streamoff(__y);}
539
540template <class _StateT>
541inline _LIBCPP_INLINE_VISIBILITY
542bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
543 {return streamoff(__x) == streamoff(__y);}
544
545template <class _StateT>
546inline _LIBCPP_INLINE_VISIBILITY
547bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
548 {return streamoff(__x) != streamoff(__y);}
549
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000550// basic_string
551
552template<class _CharT, class _Traits, class _Allocator>
553basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000554operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
555 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000556
557template<class _CharT, class _Traits, class _Allocator>
558basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000559operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000560
561template<class _CharT, class _Traits, class _Allocator>
562basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000563operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000564
565template<class _CharT, class _Traits, class _Allocator>
566basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000567operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000568
569template<class _CharT, class _Traits, class _Allocator>
570basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000571operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572
Shoaib Meenai487562f2017-07-29 02:54:41 +0000573_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
574
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000575template <bool>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000576class _LIBCPP_TEMPLATE_VIS __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000577{
578protected:
Marshall Clow14c09a22016-08-25 15:09:01 +0000579 _LIBCPP_NORETURN void __throw_length_error() const;
580 _LIBCPP_NORETURN void __throw_out_of_range() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581};
582
583template <bool __b>
584void
585__basic_string_common<__b>::__throw_length_error() const
586{
Marshall Clow14c09a22016-08-25 15:09:01 +0000587 _VSTD::__throw_length_error("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000588}
589
590template <bool __b>
591void
592__basic_string_common<__b>::__throw_out_of_range() const
593{
Marshall Clow14c09a22016-08-25 15:09:01 +0000594 _VSTD::__throw_out_of_range("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595}
596
Eric Fiselier833d6442016-09-15 22:27:07 +0000597_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000598
Marshall Clowdf9db312016-01-13 21:54:34 +0000599#ifdef _LIBCPP_NO_EXCEPTIONS
600template <class _Iter>
601struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
602#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
603template <class _Iter>
604struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
605#else
606template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
607struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
608 noexcept(++(declval<_Iter&>())) &&
609 is_nothrow_assignable<_Iter&, _Iter>::value &&
610 noexcept(declval<_Iter>() == declval<_Iter>()) &&
611 noexcept(*declval<_Iter>())
612)) {};
613
614template <class _Iter>
615struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
616#endif
617
618
619template <class _Iter>
620struct __libcpp_string_gets_noexcept_iterator
621 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
622
Marshall Clow6ac8de02016-09-24 22:45:42 +0000623template <class _CharT, class _Traits, class _Tp>
624struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
Marshall Clowf1729d92017-11-15 20:02:27 +0000625 ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
Marshall Clow6ac8de02016-09-24 22:45:42 +0000626 !is_convertible<const _Tp&, const _CharT*>::value)) {};
627
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000628#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000629
630template <class _CharT, size_t = sizeof(_CharT)>
631struct __padding
632{
633 unsigned char __xx[sizeof(_CharT)-1];
634};
635
636template <class _CharT>
637struct __padding<_CharT, 1>
638{
639};
640
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000641#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000642
Howard Hinnant324bb032010-08-22 00:02:43 +0000643template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000644class _LIBCPP_TEMPLATE_VIS basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000645 : private __basic_string_common<true>
646{
647public:
648 typedef basic_string __self;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000649 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000650 typedef _Traits traits_type;
Marshall Clow2d4c3fa2017-03-15 18:41:11 +0000651 typedef _CharT value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000652 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000653 typedef allocator_traits<allocator_type> __alloc_traits;
654 typedef typename __alloc_traits::size_type size_type;
655 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000656 typedef value_type& reference;
657 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000658 typedef typename __alloc_traits::pointer pointer;
659 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000660
Marshall Clow46ea17e2018-01-22 00:17:48 +0000661 static_assert(is_trivial<value_type>::value, "Character type of basic_string must be trivial");
Marshall Clow2d4c3fa2017-03-15 18:41:11 +0000662 static_assert((is_same<_CharT, typename traits_type::char_type>::value),
Howard Hinnant499cea12013-08-23 17:37:05 +0000663 "traits_type::char_type must be the same type as CharT");
664 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
665 "Allocator::value_type must be same type as value_type");
666#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667 typedef pointer iterator;
668 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000669#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670 typedef __wrap_iter<pointer> iterator;
671 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000672#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000673 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
674 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000675
676private:
Howard Hinnant15467182013-04-30 21:44:48 +0000677
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000678#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000679
680 struct __long
681 {
682 pointer __data_;
683 size_type __size_;
684 size_type __cap_;
685 };
686
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000687#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000688 static const size_type __short_mask = 0x01;
689 static const size_type __long_mask = 0x1ul;
Howard Hinnant15467182013-04-30 21:44:48 +0000690#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000691 static const size_type __short_mask = 0x80;
692 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant15467182013-04-30 21:44:48 +0000693#endif // _LIBCPP_BIG_ENDIAN
694
695 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
696 (sizeof(__long) - 1)/sizeof(value_type) : 2};
697
698 struct __short
699 {
700 value_type __data_[__min_cap];
701 struct
702 : __padding<value_type>
703 {
704 unsigned char __size_;
705 };
706 };
707
708#else
709
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000710 struct __long
711 {
712 size_type __cap_;
713 size_type __size_;
714 pointer __data_;
715 };
716
Eric Fiselier5ccf0432017-10-17 13:16:01 +0000717#ifdef _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000718 static const size_type __short_mask = 0x80;
719 static const size_type __long_mask = ~(size_type(~0) >> 1);
Howard Hinnant324bb032010-08-22 00:02:43 +0000720#else // _LIBCPP_BIG_ENDIAN
Ben Craigde79ab62017-07-12 01:45:13 +0000721 static const size_type __short_mask = 0x01;
722 static const size_type __long_mask = 0x1ul;
Howard Hinnant324bb032010-08-22 00:02:43 +0000723#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000724
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000725 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
726 (sizeof(__long) - 1)/sizeof(value_type) : 2};
727
728 struct __short
729 {
730 union
731 {
732 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +0000733 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734 };
735 value_type __data_[__min_cap];
736 };
737
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000738#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000739
Howard Hinnant499cea12013-08-23 17:37:05 +0000740 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000741
Howard Hinnant499cea12013-08-23 17:37:05 +0000742 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743
744 struct __raw
745 {
746 size_type __words[__n_words];
747 };
748
749 struct __rep
750 {
751 union
752 {
753 __long __l;
754 __short __s;
755 __raw __r;
756 };
757 };
758
759 __compressed_pair<__rep, allocator_type> __r_;
760
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761public:
762 static const size_type npos = -1;
763
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000764 _LIBCPP_INLINE_VISIBILITY basic_string()
765 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000766
767 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
768#if _LIBCPP_STD_VER <= 14
769 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
770#else
771 _NOEXCEPT;
772#endif
773
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000774 basic_string(const basic_string& __str);
775 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +0000776
Eric Fiselier3e928972017-04-19 00:28:44 +0000777#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant9f193f22011-01-26 00:06:59 +0000778 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000779 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +0000780#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000781 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000782#else
783 _NOEXCEPT;
784#endif
785
Howard Hinnant9f193f22011-01-26 00:06:59 +0000786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000787 basic_string(basic_string&& __str, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000788#endif // _LIBCPP_CXX03_LANG
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000789 _LIBCPP_INLINE_VISIBILITY basic_string(const _CharT* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000790 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000791 basic_string(const _CharT* __s, const _Allocator& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000792 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000793 basic_string(const _CharT* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000794 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000795 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000796 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000797 basic_string(size_type __n, _CharT __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000798 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000799 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000800 basic_string(const basic_string& __str, size_type __pos, size_type __n,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000801 const _Allocator& __a = _Allocator());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000802 _LIBCPP_INLINE_VISIBILITY
803 basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000804 const _Allocator& __a = _Allocator());
Marshall Clowdb7fa112016-11-14 18:22:19 +0000805 template<class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +0000806 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000807 basic_string(const _Tp& __t, size_type __pos, size_type __n,
Marshall Clowdb7fa112016-11-14 18:22:19 +0000808 const allocator_type& __a = allocator_type(),
809 typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type* = 0);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000810 _LIBCPP_INLINE_VISIBILITY explicit
811 basic_string(__self_view __sv);
812 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000813 basic_string(__self_view __sv, const _Allocator& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000814 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000815 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000816 basic_string(_InputIterator __first, _InputIterator __last);
817 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000820#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000821 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000822 basic_string(initializer_list<_CharT> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000823 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +0000824 basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
Eric Fiselier3e928972017-04-19 00:28:44 +0000825#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000826
Eric Fiselier51eb1d52016-10-31 03:42:50 +0000827 inline ~basic_string();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000828
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000829 _LIBCPP_INLINE_VISIBILITY
830 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
831
Howard Hinnante32b5e22010-11-17 17:55:08 +0000832 basic_string& operator=(const basic_string& __str);
Eric Fiselierf472d6c2017-01-23 21:24:58 +0000833
834#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier37b2be92017-01-17 22:10:32 +0000835 template <class = void>
Eric Fiselierf472d6c2017-01-23 21:24:58 +0000836#endif
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000837 _LIBCPP_INLINE_VISIBILITY
838 basic_string& operator=(__self_view __sv) {return assign(__sv);}
Eric Fiselier3e928972017-04-19 00:28:44 +0000839#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000841 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +0000842 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Eric Fiselier3e928972017-04-19 00:28:44 +0000843 _LIBCPP_INLINE_VISIBILITY
844 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000845#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000846 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000847 basic_string& operator=(value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000848
Howard Hinnant499cea12013-08-23 17:37:05 +0000849#if _LIBCPP_DEBUG_LEVEL >= 2
850 _LIBCPP_INLINE_VISIBILITY
851 iterator begin() _NOEXCEPT
852 {return iterator(this, __get_pointer());}
853 _LIBCPP_INLINE_VISIBILITY
854 const_iterator begin() const _NOEXCEPT
855 {return const_iterator(this, __get_pointer());}
856 _LIBCPP_INLINE_VISIBILITY
857 iterator end() _NOEXCEPT
858 {return iterator(this, __get_pointer() + size());}
859 _LIBCPP_INLINE_VISIBILITY
860 const_iterator end() const _NOEXCEPT
861 {return const_iterator(this, __get_pointer() + size());}
862#else
Howard Hinnanta6119a82011-05-29 19:57:12 +0000863 _LIBCPP_INLINE_VISIBILITY
864 iterator begin() _NOEXCEPT
865 {return iterator(__get_pointer());}
866 _LIBCPP_INLINE_VISIBILITY
867 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000868 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000869 _LIBCPP_INLINE_VISIBILITY
870 iterator end() _NOEXCEPT
871 {return iterator(__get_pointer() + size());}
872 _LIBCPP_INLINE_VISIBILITY
873 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000874 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +0000875#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +0000876 _LIBCPP_INLINE_VISIBILITY
877 reverse_iterator rbegin() _NOEXCEPT
878 {return reverse_iterator(end());}
879 _LIBCPP_INLINE_VISIBILITY
880 const_reverse_iterator rbegin() const _NOEXCEPT
881 {return const_reverse_iterator(end());}
882 _LIBCPP_INLINE_VISIBILITY
883 reverse_iterator rend() _NOEXCEPT
884 {return reverse_iterator(begin());}
885 _LIBCPP_INLINE_VISIBILITY
886 const_reverse_iterator rend() const _NOEXCEPT
887 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888
Howard Hinnanta6119a82011-05-29 19:57:12 +0000889 _LIBCPP_INLINE_VISIBILITY
890 const_iterator cbegin() const _NOEXCEPT
891 {return begin();}
892 _LIBCPP_INLINE_VISIBILITY
893 const_iterator cend() const _NOEXCEPT
894 {return end();}
895 _LIBCPP_INLINE_VISIBILITY
896 const_reverse_iterator crbegin() const _NOEXCEPT
897 {return rbegin();}
898 _LIBCPP_INLINE_VISIBILITY
899 const_reverse_iterator crend() const _NOEXCEPT
900 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901
Howard Hinnanta6119a82011-05-29 19:57:12 +0000902 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000904 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
905 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
906 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +0000907 {return (__is_long() ? __get_long_cap()
908 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000909
910 void resize(size_type __n, value_type __c);
911 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
912
Eric Fiselier59e24fe2017-06-01 02:29:37 +0000913 void reserve(size_type __res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000915 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +0000917 void clear() _NOEXCEPT;
Marshall Clowf1729d92017-11-15 20:02:27 +0000918 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
919 bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000920
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000921 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
922 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000923
924 const_reference at(size_type __n) const;
925 reference at(size_type __n);
926
927 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000928 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(__self_view __sv) {return append(__sv);}
929 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000930 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Eric Fiselier3e928972017-04-19 00:28:44 +0000931#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000932 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Eric Fiselier3e928972017-04-19 00:28:44 +0000933#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000934
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000935 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000936 basic_string& append(const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000937 _LIBCPP_INLINE_VISIBILITY
938 basic_string& append(__self_view __sv) { return append(__sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +0000939 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48 +0000940 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +0000941 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
942 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +0000943 <
944 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
945 basic_string&
946 >::type
947 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000948 basic_string& append(const value_type* __s, size_type __n);
949 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000950 basic_string& append(size_type __n, value_type __c);
Eric Fiselier026d38e2016-10-31 02:46:25 +0000951 template <class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +0000952 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
953 basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000954 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +0000955 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
956 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000957 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000958 __is_exactly_input_iterator<_InputIterator>::value
959 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000960 basic_string&
961 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +0000962 _LIBCPP_INLINE_VISIBILITY
963 append(_InputIterator __first, _InputIterator __last) {
964 const basic_string __temp (__first, __last, __alloc());
965 append(__temp.data(), __temp.size());
966 return *this;
967 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000968 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +0000969 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
970 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000972 __is_forward_iterator<_ForwardIterator>::value
973 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000974 basic_string&
975 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +0000976 _LIBCPP_INLINE_VISIBILITY
977 append(_ForwardIterator __first, _ForwardIterator __last) {
978 return __append_forward_unsafe(__first, __last);
979 }
980
Eric Fiselier3e928972017-04-19 00:28:44 +0000981#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000982 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +0000984#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000985
986 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000987 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000988 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000989 _LIBCPP_INLINE_VISIBILITY reference front();
990 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
991 _LIBCPP_INLINE_VISIBILITY reference back();
992 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000993
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000994 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000995 basic_string& assign(__self_view __sv) { return assign(__sv.data(), __sv.size()); }
996 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29 +0000997 basic_string& assign(const basic_string& __str) { return *this = __str; }
Eric Fiselier3e928972017-04-19 00:28:44 +0000998#ifndef _LIBCPP_CXX03_LANG
Howard Hinnanta6119a82011-05-29 19:57:12 +0000999 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001000 basic_string& assign(basic_string&& __str)
Marshall Clow7ed093b2015-10-05 16:17:34 +00001001 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001002 {*this = _VSTD::move(__str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001003#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +00001004 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48 +00001005 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001006 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1007 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001008 <
1009 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1010 basic_string&
1011 >::type
Eric Fiselier59e24fe2017-06-01 02:29:37 +00001012 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001013 basic_string& assign(const value_type* __s, size_type __n);
1014 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001015 basic_string& assign(size_type __n, value_type __c);
1016 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001017 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1018 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001019 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001020 __is_exactly_input_iterator<_InputIterator>::value
1021 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001022 basic_string&
1023 >::type
1024 assign(_InputIterator __first, _InputIterator __last);
1025 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001026 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1027 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001028 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001029 __is_forward_iterator<_ForwardIterator>::value
1030 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001031 basic_string&
1032 >::type
1033 assign(_ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001034#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001036 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001037#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001038
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001039 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001040 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001041 _LIBCPP_INLINE_VISIBILITY
1042 basic_string& insert(size_type __pos1, __self_view __sv) { return insert(__pos1, __sv.data(), __sv.size()); }
Marshall Clow6ac8de02016-09-24 22:45:42 +00001043 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001044 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1045 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001046 <
1047 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1048 basic_string&
1049 >::type
1050 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001051 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001052 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1053 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1055 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001057 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1058 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001059 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1060 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001061 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001062 __is_exactly_input_iterator<_InputIterator>::value
1063 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064 iterator
1065 >::type
1066 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1067 template<class _ForwardIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001068 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1069 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001071 __is_forward_iterator<_ForwardIterator>::value
1072 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001073 iterator
1074 >::type
1075 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Eric Fiselier3e928972017-04-19 00:28:44 +00001076#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001078 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1079 {return insert(__pos, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001080#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001081
1082 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001083 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001084 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001085 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001086 iterator erase(const_iterator __first, const_iterator __last);
1087
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001088 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001089 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001090 _LIBCPP_INLINE_VISIBILITY
1091 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 +00001092 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 +00001093 template <class _Tp>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001094 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1095 typename enable_if
Marshall Clow6ac8de02016-09-24 22:45:42 +00001096 <
1097 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1098 basic_string&
1099 >::type
1100 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001101 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1102 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001103 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001104 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001105 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001106 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001107 basic_string& replace(const_iterator __i1, const_iterator __i2, __self_view __sv) { return replace(__i1 - begin(), __i2 - __i1, __sv); }
1108 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001109 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001111 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001112 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001113 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001114 template<class _InputIterator>
Shoaib Meenai24e8dbd2017-03-02 03:02:50 +00001115 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1116 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001117 <
1118 __is_input_iterator<_InputIterator>::value,
1119 basic_string&
1120 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001121 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Eric Fiselier3e928972017-04-19 00:28:44 +00001122#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001123 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001124 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001125 {return replace(__i1, __i2, __il.begin(), __il.end());}
Eric Fiselier3e928972017-04-19 00:28:44 +00001126#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001127
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001128 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001129 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001130 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1131
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001132 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001133 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001134#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00001135 _NOEXCEPT_DEBUG;
Marshall Clow7d914d12015-07-13 20:04:56 +00001136#else
Eric Fiselier47257c42016-12-28 05:53:01 +00001137 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00001138 __is_nothrow_swappable<allocator_type>::value);
1139#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001140
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001142 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001144 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Eric Fiselier10bebe22017-11-20 20:23:27 +00001145#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
Marshall Clowf532a702016-03-08 15:44:30 +00001146 _LIBCPP_INLINE_VISIBILITY
1147 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1148#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001151 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001152
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001154 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001155 _LIBCPP_INLINE_VISIBILITY
1156 size_type find(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001157 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001158 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001159 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001160 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001161
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001162 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001163 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001164 _LIBCPP_INLINE_VISIBILITY
Marshall Clow0b9db072017-09-07 04:19:32 +00001165 size_type rfind(__self_view __sv, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001166 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001168 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001169 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001170
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001172 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001173 _LIBCPP_INLINE_VISIBILITY
1174 size_type find_first_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001175 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001177 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001178 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001179 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001180
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001181 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001182 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001183 _LIBCPP_INLINE_VISIBILITY
Marshall Clow0b9db072017-09-07 04:19:32 +00001184 size_type find_last_of(__self_view __sv, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001185 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001186 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001187 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001188 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001189 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001190
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001191 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001192 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001193 _LIBCPP_INLINE_VISIBILITY
1194 size_type find_first_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001195 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 +00001196 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001197 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001198 _LIBCPP_INLINE_VISIBILITY
1199 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1200
1201 _LIBCPP_INLINE_VISIBILITY
1202 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001203 _LIBCPP_INLINE_VISIBILITY
Marshall Clow0b9db072017-09-07 04:19:32 +00001204 size_type find_last_not_of(__self_view __sv, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001205 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 +00001206 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001207 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001208 _LIBCPP_INLINE_VISIBILITY
1209 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1210
1211 _LIBCPP_INLINE_VISIBILITY
1212 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001213 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001214 int compare(__self_view __sv) const _NOEXCEPT;
1215 _LIBCPP_INLINE_VISIBILITY
1216 int compare(size_type __pos1, size_type __n1, __self_view __sv) const;
1217 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001219 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 +00001220 template <class _Tp>
Eric Fiselier9dbc0532016-10-14 05:29:46 +00001221 inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow6ac8de02016-09-24 22:45:42 +00001222 typename enable_if
1223 <
1224 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1225 int
1226 >::type
1227 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 +00001228 int compare(const value_type* __s) const _NOEXCEPT;
1229 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1230 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001231
Marshall Clow46b4ad52017-12-04 20:11:38 +00001232#if _LIBCPP_STD_VER > 17
1233 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1234 bool starts_with(__self_view __sv) const _NOEXCEPT
1235 { return __self_view(data(), size()).starts_with(__sv); }
1236
1237 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1238 bool starts_with(value_type __c) const _NOEXCEPT
1239 { return !empty() && _Traits::eq(front(), __c); }
1240
1241 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1242 bool starts_with(const value_type* __s) const _NOEXCEPT
1243 { return starts_with(__self_view(__s)); }
1244
1245 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1246 bool ends_with(__self_view __sv) const _NOEXCEPT
1247 { return __self_view(data(), size()).ends_with( __sv); }
1248
1249 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1250 bool ends_with(value_type __c) const _NOEXCEPT
1251 { return !empty() && _Traits::eq(back(), __c); }
1252
1253 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1254 bool ends_with(const value_type* __s) const _NOEXCEPT
1255 { return ends_with(__self_view(__s)); }
1256#endif
1257
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001258 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001259
1260 _LIBCPP_INLINE_VISIBILITY
1261 bool __is_long() const _NOEXCEPT
1262 {return bool(__r_.first().__s.__size_ & __short_mask);}
1263
Howard Hinnant499cea12013-08-23 17:37:05 +00001264#if _LIBCPP_DEBUG_LEVEL >= 2
1265
1266 bool __dereferenceable(const const_iterator* __i) const;
1267 bool __decrementable(const const_iterator* __i) const;
1268 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1269 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1270
1271#endif // _LIBCPP_DEBUG_LEVEL >= 2
1272
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001273private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001274 _LIBCPP_INLINE_VISIBILITY
1275 allocator_type& __alloc() _NOEXCEPT
1276 {return __r_.second();}
1277 _LIBCPP_INLINE_VISIBILITY
1278 const allocator_type& __alloc() const _NOEXCEPT
1279 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001280
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001281#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001282
Howard Hinnanta6119a82011-05-29 19:57:12 +00001283 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001284 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001285# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001286 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001287# else
1288 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1289# endif
1290
Howard Hinnanta6119a82011-05-29 19:57:12 +00001291 _LIBCPP_INLINE_VISIBILITY
1292 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001293# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001294 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001295# else
1296 {return __r_.first().__s.__size_;}
1297# endif
1298
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001299#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001300
1301 _LIBCPP_INLINE_VISIBILITY
1302 void __set_short_size(size_type __s) _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001303# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001304 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1305# else
1306 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1307# endif
1308
1309 _LIBCPP_INLINE_VISIBILITY
1310 size_type __get_short_size() const _NOEXCEPT
Eric Fiselier5ccf0432017-10-17 13:16:01 +00001311# ifdef _LIBCPP_BIG_ENDIAN
Howard Hinnant15467182013-04-30 21:44:48 +00001312 {return __r_.first().__s.__size_;}
1313# else
1314 {return __r_.first().__s.__size_ >> 1;}
1315# endif
1316
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001317#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001318
Howard Hinnanta6119a82011-05-29 19:57:12 +00001319 _LIBCPP_INLINE_VISIBILITY
1320 void __set_long_size(size_type __s) _NOEXCEPT
1321 {__r_.first().__l.__size_ = __s;}
1322 _LIBCPP_INLINE_VISIBILITY
1323 size_type __get_long_size() const _NOEXCEPT
1324 {return __r_.first().__l.__size_;}
1325 _LIBCPP_INLINE_VISIBILITY
1326 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001327 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1328
Howard Hinnanta6119a82011-05-29 19:57:12 +00001329 _LIBCPP_INLINE_VISIBILITY
1330 void __set_long_cap(size_type __s) _NOEXCEPT
1331 {__r_.first().__l.__cap_ = __long_mask | __s;}
1332 _LIBCPP_INLINE_VISIBILITY
1333 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001334 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001335
Howard Hinnanta6119a82011-05-29 19:57:12 +00001336 _LIBCPP_INLINE_VISIBILITY
1337 void __set_long_pointer(pointer __p) _NOEXCEPT
1338 {__r_.first().__l.__data_ = __p;}
1339 _LIBCPP_INLINE_VISIBILITY
1340 pointer __get_long_pointer() _NOEXCEPT
1341 {return __r_.first().__l.__data_;}
1342 _LIBCPP_INLINE_VISIBILITY
1343 const_pointer __get_long_pointer() const _NOEXCEPT
1344 {return __r_.first().__l.__data_;}
1345 _LIBCPP_INLINE_VISIBILITY
1346 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001347 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001348 _LIBCPP_INLINE_VISIBILITY
1349 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001350 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001351 _LIBCPP_INLINE_VISIBILITY
1352 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001353 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001354 _LIBCPP_INLINE_VISIBILITY
1355 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001356 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1357
Howard Hinnanta6119a82011-05-29 19:57:12 +00001358 _LIBCPP_INLINE_VISIBILITY
1359 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001360 {
1361 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1362 for (unsigned __i = 0; __i < __n_words; ++__i)
1363 __a[__i] = 0;
1364 }
1365
1366 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001367 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001368 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001369 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001370 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001371 static _LIBCPP_INLINE_VISIBILITY
1372 size_type __recommend(size_type __s) _NOEXCEPT
Marshall Clow088e6012018-02-07 21:30:17 +00001373 {
1374 if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
1375 size_type __guess = __align_it<sizeof(value_type) < __alignment ?
1376 __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
1377 if (__guess == __min_cap) ++__guess;
1378 return __guess;
1379 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001380
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001381 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001382 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001383 inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001384 void __init(const value_type* __s, size_type __sz);
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001385 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001386 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001387
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001388 template <class _InputIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001389 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001390 typename enable_if
1391 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001392 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001393 void
1394 >::type
1395 __init(_InputIterator __first, _InputIterator __last);
1396
1397 template <class _ForwardIterator>
Duncan P. N. Exon Smithed3c0e62017-04-01 03:20:48 +00001398 inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001399 typename enable_if
1400 <
1401 __is_forward_iterator<_ForwardIterator>::value,
1402 void
1403 >::type
1404 __init(_ForwardIterator __first, _ForwardIterator __last);
1405
1406 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001407 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1409 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001410 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001411
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001413 void __erase_to_end(size_type __pos);
1414
Howard Hinnante32b5e22010-11-17 17:55:08 +00001415 _LIBCPP_INLINE_VISIBILITY
1416 void __copy_assign_alloc(const basic_string& __str)
1417 {__copy_assign_alloc(__str, integral_constant<bool,
1418 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1419
1420 _LIBCPP_INLINE_VISIBILITY
1421 void __copy_assign_alloc(const basic_string& __str, true_type)
1422 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001423 if (__alloc() == __str.__alloc())
1424 __alloc() = __str.__alloc();
1425 else
Howard Hinnante32b5e22010-11-17 17:55:08 +00001426 {
Marshall Clow9247fd22017-01-31 03:40:52 +00001427 if (!__str.__is_long())
1428 {
1429 clear();
1430 shrink_to_fit();
1431 __alloc() = __str.__alloc();
1432 }
1433 else
1434 {
1435 allocator_type __a = __str.__alloc();
1436 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
1437 clear();
1438 shrink_to_fit();
1439 __alloc() = _VSTD::move(__a);
1440 __set_long_pointer(__p);
1441 __set_long_cap(__str.__get_long_cap());
1442 __set_long_size(__str.size());
1443 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001444 }
Howard Hinnante32b5e22010-11-17 17:55:08 +00001445 }
1446
1447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001448 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001449 {}
1450
Eric Fiselier3e928972017-04-19 00:28:44 +00001451#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001452 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001453 void __move_assign(basic_string& __str, false_type)
1454 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001456 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001457#if _LIBCPP_STD_VER > 14
1458 _NOEXCEPT;
1459#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001460 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001461#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001462#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001463
1464 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001465 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001466 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001467 _NOEXCEPT_(
1468 !__alloc_traits::propagate_on_container_move_assignment::value ||
1469 is_nothrow_move_assignable<allocator_type>::value)
1470 {__move_assign_alloc(__str, integral_constant<bool,
1471 __alloc_traits::propagate_on_container_move_assignment::value>());}
1472
1473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001474 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001475 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1476 {
1477 __alloc() = _VSTD::move(__c.__alloc());
1478 }
1479
1480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001481 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001482 _NOEXCEPT
1483 {}
1484
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001485 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1486 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001487
1488 friend basic_string operator+<>(const basic_string&, const basic_string&);
1489 friend basic_string operator+<>(const value_type*, const basic_string&);
1490 friend basic_string operator+<>(value_type, const basic_string&);
1491 friend basic_string operator+<>(const basic_string&, const value_type*);
1492 friend basic_string operator+<>(const basic_string&, value_type);
1493};
1494
Marshall Clow5b1e87e2018-02-08 06:34:03 +00001495#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1496template<class _InputIterator,
1497 class _CharT = typename iterator_traits<_InputIterator>::value_type,
1498 class _Allocator = allocator<_CharT>,
1499 class = typename enable_if<__is_input_iterator<_InputIterator>::value, void>::type,
1500 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
1501 >
1502basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
1503 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
1504#endif
1505
1506
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001507template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001508inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001509void
1510basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1511{
Howard Hinnant499cea12013-08-23 17:37:05 +00001512#if _LIBCPP_DEBUG_LEVEL >= 2
1513 __get_db()->__invalidate_all(this);
1514#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001515}
1516
1517template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001518inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001519void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001520basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001521#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001522 __pos
1523#endif
1524 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525{
Howard Hinnant499cea12013-08-23 17:37:05 +00001526#if _LIBCPP_DEBUG_LEVEL >= 2
1527 __c_node* __c = __get_db()->__find_c_and_lock(this);
1528 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001529 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001530 const_pointer __new_last = __get_pointer() + __pos;
1531 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001532 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001533 --__p;
1534 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1535 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001536 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001537 (*__p)->__c_ = nullptr;
1538 if (--__c->end_ != __p)
1539 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001540 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001541 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001542 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001543 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001544#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001545}
1546
1547template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001548inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001549basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001550 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001551{
Howard Hinnant499cea12013-08-23 17:37:05 +00001552#if _LIBCPP_DEBUG_LEVEL >= 2
1553 __get_db()->__insert_c(this);
1554#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001555 __zero();
1556}
1557
1558template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001559inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001560basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001561#if _LIBCPP_STD_VER <= 14
1562 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1563#else
1564 _NOEXCEPT
1565#endif
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001566: __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001567{
Howard Hinnant499cea12013-08-23 17:37:05 +00001568#if _LIBCPP_DEBUG_LEVEL >= 2
1569 __get_db()->__insert_c(this);
1570#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001571 __zero();
1572}
1573
1574template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001575void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1576 size_type __sz,
1577 size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001578{
1579 if (__reserve > max_size())
1580 this->__throw_length_error();
1581 pointer __p;
1582 if (__reserve < __min_cap)
1583 {
1584 __set_short_size(__sz);
1585 __p = __get_short_pointer();
1586 }
1587 else
1588 {
1589 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001590 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001591 __set_long_pointer(__p);
1592 __set_long_cap(__cap+1);
1593 __set_long_size(__sz);
1594 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001595 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001596 traits_type::assign(__p[__sz], value_type());
1597}
1598
1599template <class _CharT, class _Traits, class _Allocator>
1600void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001601basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001602{
1603 if (__sz > max_size())
1604 this->__throw_length_error();
1605 pointer __p;
1606 if (__sz < __min_cap)
1607 {
1608 __set_short_size(__sz);
1609 __p = __get_short_pointer();
1610 }
1611 else
1612 {
1613 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001614 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001615 __set_long_pointer(__p);
1616 __set_long_cap(__cap+1);
1617 __set_long_size(__sz);
1618 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001619 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001620 traits_type::assign(__p[__sz], value_type());
1621}
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)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001626{
Howard Hinnant499cea12013-08-23 17:37:05 +00001627 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001628 __init(__s, traits_type::length(__s));
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, 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(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001640 __init(__s, traits_type::length(__s));
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>
Howard Hinnant1e564242013-10-04 22:09:00 +00001647inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001648basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001649{
Howard Hinnant499cea12013-08-23 17:37:05 +00001650 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001651 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001652#if _LIBCPP_DEBUG_LEVEL >= 2
1653 __get_db()->__insert_c(this);
1654#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001655}
1656
1657template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001658inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001659basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001660 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001661{
Howard Hinnant499cea12013-08-23 17:37:05 +00001662 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001663 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001664#if _LIBCPP_DEBUG_LEVEL >= 2
1665 __get_db()->__insert_c(this);
1666#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001667}
1668
1669template <class _CharT, class _Traits, class _Allocator>
1670basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001671 : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001672{
1673 if (!__str.__is_long())
1674 __r_.first().__r = __str.__r_.first().__r;
1675 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001676 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001677#if _LIBCPP_DEBUG_LEVEL >= 2
1678 __get_db()->__insert_c(this);
1679#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001680}
1681
1682template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001683basic_string<_CharT, _Traits, _Allocator>::basic_string(
1684 const basic_string& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001685 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001686{
1687 if (!__str.__is_long())
1688 __r_.first().__r = __str.__r_.first().__r;
1689 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001690 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001691#if _LIBCPP_DEBUG_LEVEL >= 2
1692 __get_db()->__insert_c(this);
1693#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001694}
1695
Eric Fiselier3e928972017-04-19 00:28:44 +00001696#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001697
1698template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001699inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001700basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001701#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001702 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00001703#else
1704 _NOEXCEPT
1705#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001706 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001707{
1708 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00001709#if _LIBCPP_DEBUG_LEVEL >= 2
1710 __get_db()->__insert_c(this);
1711 if (__is_long())
1712 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001713#endif
1714}
1715
1716template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001717inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001718basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001719 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001720{
Marshall Clowd5549cc2014-07-17 15:32:20 +00001721 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001722 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00001723 else
1724 {
1725 __r_.first().__r = __str.__r_.first().__r;
1726 __str.__zero();
1727 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001728#if _LIBCPP_DEBUG_LEVEL >= 2
1729 __get_db()->__insert_c(this);
1730 if (__is_long())
1731 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001732#endif
1733}
1734
Eric Fiselier3e928972017-04-19 00:28:44 +00001735#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001736
1737template <class _CharT, class _Traits, class _Allocator>
1738void
1739basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1740{
1741 if (__n > max_size())
1742 this->__throw_length_error();
1743 pointer __p;
1744 if (__n < __min_cap)
1745 {
1746 __set_short_size(__n);
1747 __p = __get_short_pointer();
1748 }
1749 else
1750 {
1751 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001752 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001753 __set_long_pointer(__p);
1754 __set_long_cap(__cap+1);
1755 __set_long_size(__n);
1756 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001757 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001758 traits_type::assign(__p[__n], value_type());
1759}
1760
1761template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001762inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001763basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001764{
1765 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001766#if _LIBCPP_DEBUG_LEVEL >= 2
1767 __get_db()->__insert_c(this);
1768#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001769}
1770
1771template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001772inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001773basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001774 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001775{
1776 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001777#if _LIBCPP_DEBUG_LEVEL >= 2
1778 __get_db()->__insert_c(this);
1779#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001780}
1781
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001782template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001783basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1784 size_type __pos, size_type __n,
1785 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001786 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001787{
1788 size_type __str_sz = __str.size();
1789 if (__pos > __str_sz)
1790 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001791 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00001792#if _LIBCPP_DEBUG_LEVEL >= 2
1793 __get_db()->__insert_c(this);
1794#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001795}
1796
1797template <class _CharT, class _Traits, class _Allocator>
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001798inline _LIBCPP_INLINE_VISIBILITY
1799basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001800 const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001801 : __r_(__second_tag(), __a)
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001802{
1803 size_type __str_sz = __str.size();
1804 if (__pos > __str_sz)
1805 this->__throw_out_of_range();
1806 __init(__str.data() + __pos, __str_sz - __pos);
1807#if _LIBCPP_DEBUG_LEVEL >= 2
1808 __get_db()->__insert_c(this);
1809#endif
1810}
1811
1812template <class _CharT, class _Traits, class _Allocator>
Marshall Clowdb7fa112016-11-14 18:22:19 +00001813template <class _Tp>
1814basic_string<_CharT, _Traits, _Allocator>::basic_string(
1815 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a,
Marshall Clowf1729d92017-11-15 20:02:27 +00001816 typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type *)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001817 : __r_(__second_tag(), __a)
Marshall Clowdb7fa112016-11-14 18:22:19 +00001818{
Marshall Clowf1729d92017-11-15 20:02:27 +00001819 __self_view __sv = __self_view(__t).substr(__pos, __n);
Marshall Clowdb7fa112016-11-14 18:22:19 +00001820 __init(__sv.data(), __sv.size());
1821#if _LIBCPP_DEBUG_LEVEL >= 2
1822 __get_db()->__insert_c(this);
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001823#endif
Marshall Clowdb7fa112016-11-14 18:22:19 +00001824}
1825
1826template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001827inline _LIBCPP_INLINE_VISIBILITY
1828basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv)
1829{
1830 __init(__sv.data(), __sv.size());
1831#if _LIBCPP_DEBUG_LEVEL >= 2
1832 __get_db()->__insert_c(this);
1833#endif
1834}
1835
1836template <class _CharT, class _Traits, class _Allocator>
1837inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001838basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001839 : __r_(__second_tag(), __a)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001840{
1841 __init(__sv.data(), __sv.size());
1842#if _LIBCPP_DEBUG_LEVEL >= 2
1843 __get_db()->__insert_c(this);
1844#endif
1845}
1846
1847template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001848template <class _InputIterator>
1849typename enable_if
1850<
Marshall Clowdf9db312016-01-13 21:54:34 +00001851 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001852 void
1853>::type
1854basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
1855{
1856 __zero();
1857#ifndef _LIBCPP_NO_EXCEPTIONS
1858 try
1859 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001860#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001861 for (; __first != __last; ++__first)
1862 push_back(*__first);
1863#ifndef _LIBCPP_NO_EXCEPTIONS
1864 }
1865 catch (...)
1866 {
1867 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001868 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001869 throw;
1870 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001871#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001872}
1873
1874template <class _CharT, class _Traits, class _Allocator>
1875template <class _ForwardIterator>
1876typename enable_if
1877<
1878 __is_forward_iterator<_ForwardIterator>::value,
1879 void
1880>::type
1881basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
1882{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001883 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001884 if (__sz > max_size())
1885 this->__throw_length_error();
1886 pointer __p;
1887 if (__sz < __min_cap)
1888 {
1889 __set_short_size(__sz);
1890 __p = __get_short_pointer();
1891 }
1892 else
1893 {
1894 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001895 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001896 __set_long_pointer(__p);
1897 __set_long_cap(__cap+1);
1898 __set_long_size(__sz);
1899 }
Eric Fiselierb9919752014-10-27 19:28:20 +00001900 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001901 traits_type::assign(*__p, *__first);
1902 traits_type::assign(*__p, value_type());
1903}
1904
1905template <class _CharT, class _Traits, class _Allocator>
1906template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001907inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001908basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
1909{
1910 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00001911#if _LIBCPP_DEBUG_LEVEL >= 2
1912 __get_db()->__insert_c(this);
1913#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001914}
1915
1916template <class _CharT, class _Traits, class _Allocator>
1917template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001918inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001919basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
1920 const allocator_type& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001921 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001922{
1923 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00001924#if _LIBCPP_DEBUG_LEVEL >= 2
1925 __get_db()->__insert_c(this);
1926#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001927}
1928
Eric Fiselier3e928972017-04-19 00:28:44 +00001929#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00001930
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001931template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001932inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001933basic_string<_CharT, _Traits, _Allocator>::basic_string(
1934 initializer_list<_CharT> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935{
1936 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00001937#if _LIBCPP_DEBUG_LEVEL >= 2
1938 __get_db()->__insert_c(this);
1939#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001940}
1941
1942template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001943inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001944
Eric Fiselier0eaf2e82017-02-17 01:17:10 +00001945basic_string<_CharT, _Traits, _Allocator>::basic_string(
1946 initializer_list<_CharT> __il, const _Allocator& __a)
Eric Fiselierdb14bcc2017-04-12 23:45:53 +00001947 : __r_(__second_tag(), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001948{
1949 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00001950#if _LIBCPP_DEBUG_LEVEL >= 2
1951 __get_db()->__insert_c(this);
1952#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001953}
1954
Eric Fiselier3e928972017-04-19 00:28:44 +00001955#endif // _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00001956
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001957template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001958basic_string<_CharT, _Traits, _Allocator>::~basic_string()
1959{
Howard Hinnant499cea12013-08-23 17:37:05 +00001960#if _LIBCPP_DEBUG_LEVEL >= 2
1961 __get_db()->__erase_c(this);
1962#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001963 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001964 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001965}
1966
1967template <class _CharT, class _Traits, class _Allocator>
1968void
1969basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
1970 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001971 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 +00001972{
1973 size_type __ms = max_size();
1974 if (__delta_cap > __ms - __old_cap - 1)
1975 this->__throw_length_error();
1976 pointer __old_p = __get_pointer();
1977 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00001978 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001979 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001980 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001981 __invalidate_all_iterators();
1982 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001983 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1984 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001985 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001986 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001987 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1988 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001989 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1990 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001991 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001992 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001993 __set_long_pointer(__p);
1994 __set_long_cap(__cap+1);
1995 __old_sz = __n_copy + __n_add + __sec_cp_sz;
1996 __set_long_size(__old_sz);
1997 traits_type::assign(__p[__old_sz], value_type());
1998}
1999
2000template <class _CharT, class _Traits, class _Allocator>
2001void
2002basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2003 size_type __n_copy, size_type __n_del, size_type __n_add)
2004{
2005 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00002006 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002007 this->__throw_length_error();
2008 pointer __old_p = __get_pointer();
2009 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002010 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002011 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002012 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002013 __invalidate_all_iterators();
2014 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002015 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2016 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002017 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2018 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002019 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2020 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2021 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002022 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002023 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002024 __set_long_pointer(__p);
2025 __set_long_cap(__cap+1);
2026}
2027
2028// assign
2029
2030template <class _CharT, class _Traits, class _Allocator>
2031basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002032basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002033{
Alp Tokerec34c482014-05-15 11:27:39 +00002034 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002035 size_type __cap = capacity();
2036 if (__cap >= __n)
2037 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002038 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002039 traits_type::move(__p, __s, __n);
2040 traits_type::assign(__p[__n], value_type());
2041 __set_size(__n);
2042 __invalidate_iterators_past(__n);
2043 }
2044 else
2045 {
2046 size_type __sz = size();
2047 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2048 }
2049 return *this;
2050}
2051
2052template <class _CharT, class _Traits, class _Allocator>
2053basic_string<_CharT, _Traits, _Allocator>&
2054basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2055{
2056 size_type __cap = capacity();
2057 if (__cap < __n)
2058 {
2059 size_type __sz = size();
2060 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2061 }
2062 else
2063 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002064 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002065 traits_type::assign(__p, __n, __c);
2066 traits_type::assign(__p[__n], value_type());
2067 __set_size(__n);
2068 return *this;
2069}
2070
2071template <class _CharT, class _Traits, class _Allocator>
2072basic_string<_CharT, _Traits, _Allocator>&
2073basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2074{
2075 pointer __p;
2076 if (__is_long())
2077 {
2078 __p = __get_long_pointer();
2079 __set_long_size(1);
2080 }
2081 else
2082 {
2083 __p = __get_short_pointer();
2084 __set_short_size(1);
2085 }
2086 traits_type::assign(*__p, __c);
2087 traits_type::assign(*++__p, value_type());
2088 __invalidate_iterators_past(1);
2089 return *this;
2090}
2091
2092template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002093basic_string<_CharT, _Traits, _Allocator>&
2094basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2095{
2096 if (this != &__str)
2097 {
2098 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00002099 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00002100 }
2101 return *this;
2102}
2103
Eric Fiselier3e928972017-04-19 00:28:44 +00002104#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante32b5e22010-11-17 17:55:08 +00002105
2106template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002107inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002108void
2109basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002110 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002111{
2112 if (__alloc() != __str.__alloc())
2113 assign(__str);
2114 else
2115 __move_assign(__str, true_type());
2116}
2117
2118template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002119inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002120void
2121basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002122#if _LIBCPP_STD_VER > 14
2123 _NOEXCEPT
2124#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002125 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002126#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002127{
2128 clear();
2129 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002130 __r_.first() = __str.__r_.first();
2131 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002132 __str.__zero();
2133}
2134
2135template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002136inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002137basic_string<_CharT, _Traits, _Allocator>&
2138basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002139 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002140{
2141 __move_assign(__str, integral_constant<bool,
2142 __alloc_traits::propagate_on_container_move_assignment::value>());
2143 return *this;
2144}
2145
2146#endif
2147
2148template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002149template<class _InputIterator>
2150typename enable_if
2151<
Marshall Clowdf9db312016-01-13 21:54:34 +00002152 __is_exactly_input_iterator <_InputIterator>::value
2153 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002154 basic_string<_CharT, _Traits, _Allocator>&
2155>::type
2156basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2157{
Marshall Clowd979eed2016-09-05 01:54:30 +00002158 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002159 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002160 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002161}
2162
2163template <class _CharT, class _Traits, class _Allocator>
2164template<class _ForwardIterator>
2165typename enable_if
2166<
Marshall Clowdf9db312016-01-13 21:54:34 +00002167 __is_forward_iterator<_ForwardIterator>::value
2168 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002169 basic_string<_CharT, _Traits, _Allocator>&
2170>::type
2171basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2172{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002173 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002174 size_type __cap = capacity();
2175 if (__cap < __n)
2176 {
2177 size_type __sz = size();
2178 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2179 }
2180 else
2181 __invalidate_iterators_past(__n);
2182 pointer __p = __get_pointer();
2183 for (; __first != __last; ++__first, ++__p)
2184 traits_type::assign(*__p, *__first);
2185 traits_type::assign(*__p, value_type());
2186 __set_size(__n);
2187 return *this;
2188}
2189
2190template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002191basic_string<_CharT, _Traits, _Allocator>&
2192basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2193{
2194 size_type __sz = __str.size();
2195 if (__pos > __sz)
2196 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002197 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002198}
2199
2200template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002201template <class _Tp>
2202typename enable_if
2203<
2204 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002205 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002206>::type
2207basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002208{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002209 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002210 size_type __sz = __sv.size();
2211 if (__pos > __sz)
2212 this->__throw_out_of_range();
2213 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2214}
2215
2216
2217template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002218basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002219basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002220{
Alp Tokerec34c482014-05-15 11:27:39 +00002221 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002222 return assign(__s, traits_type::length(__s));
2223}
2224
2225// append
2226
2227template <class _CharT, class _Traits, class _Allocator>
2228basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002229basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002230{
Alp Tokerec34c482014-05-15 11:27:39 +00002231 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002232 size_type __cap = capacity();
2233 size_type __sz = size();
2234 if (__cap - __sz >= __n)
2235 {
2236 if (__n)
2237 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002238 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002239 traits_type::copy(__p + __sz, __s, __n);
2240 __sz += __n;
2241 __set_size(__sz);
2242 traits_type::assign(__p[__sz], value_type());
2243 }
2244 }
2245 else
2246 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2247 return *this;
2248}
2249
2250template <class _CharT, class _Traits, class _Allocator>
2251basic_string<_CharT, _Traits, _Allocator>&
2252basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2253{
2254 if (__n)
2255 {
2256 size_type __cap = capacity();
2257 size_type __sz = size();
2258 if (__cap - __sz < __n)
2259 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2260 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002261 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002262 __sz += __n;
2263 __set_size(__sz);
2264 traits_type::assign(__p[__sz], value_type());
2265 }
2266 return *this;
2267}
2268
2269template <class _CharT, class _Traits, class _Allocator>
2270void
2271basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2272{
Howard Hinnant15467182013-04-30 21:44:48 +00002273 bool __is_short = !__is_long();
2274 size_type __cap;
2275 size_type __sz;
2276 if (__is_short)
2277 {
2278 __cap = __min_cap - 1;
2279 __sz = __get_short_size();
2280 }
2281 else
2282 {
2283 __cap = __get_long_cap() - 1;
2284 __sz = __get_long_size();
2285 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002286 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002287 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002288 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002289 __is_short = !__is_long();
2290 }
2291 pointer __p;
2292 if (__is_short)
2293 {
2294 __p = __get_short_pointer() + __sz;
2295 __set_short_size(__sz+1);
2296 }
2297 else
2298 {
2299 __p = __get_long_pointer() + __sz;
2300 __set_long_size(__sz+1);
2301 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002302 traits_type::assign(*__p, __c);
2303 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002304}
2305
Marshall Clowac655ef2016-09-07 03:32:06 +00002306template <class _Tp>
Marshall Clowd979eed2016-09-05 01:54:30 +00002307bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2308{
2309 return __first <= __p && __p < __last;
2310}
2311
Marshall Clowac655ef2016-09-07 03:32:06 +00002312template <class _Tp1, class _Tp2>
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00002313bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
Marshall Clowac655ef2016-09-07 03:32:06 +00002314{
2315 return false;
2316}
2317
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002318template <class _CharT, class _Traits, class _Allocator>
2319template<class _ForwardIterator>
Eric Fiselier026d38e2016-10-31 02:46:25 +00002320basic_string<_CharT, _Traits, _Allocator>&
2321basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2322 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002323{
Eric Fiselier026d38e2016-10-31 02:46:25 +00002324 static_assert(__is_forward_iterator<_ForwardIterator>::value,
2325 "function requires a ForwardIterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002326 size_type __sz = size();
2327 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002328 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002329 if (__n)
2330 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002331 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2332 _CharRef __tmp_ref = *__first;
2333 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002334 {
2335 const basic_string __temp (__first, __last, __alloc());
2336 append(__temp.data(), __temp.size());
2337 }
2338 else
2339 {
2340 if (__cap - __sz < __n)
2341 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2342 pointer __p = __get_pointer() + __sz;
2343 for (; __first != __last; ++__p, ++__first)
2344 traits_type::assign(*__p, *__first);
2345 traits_type::assign(*__p, value_type());
2346 __set_size(__sz + __n);
2347 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002348 }
2349 return *this;
2350}
2351
2352template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002353inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002354basic_string<_CharT, _Traits, _Allocator>&
2355basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2356{
2357 return append(__str.data(), __str.size());
2358}
2359
2360template <class _CharT, class _Traits, class _Allocator>
2361basic_string<_CharT, _Traits, _Allocator>&
2362basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2363{
2364 size_type __sz = __str.size();
2365 if (__pos > __sz)
2366 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002367 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002368}
2369
2370template <class _CharT, class _Traits, class _Allocator>
Marshall Clow42a87db2016-10-03 23:40:48 +00002371template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002372 typename enable_if
2373 <
2374 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2375 basic_string<_CharT, _Traits, _Allocator>&
2376 >::type
2377basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002378{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002379 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002380 size_type __sz = __sv.size();
2381 if (__pos > __sz)
2382 this->__throw_out_of_range();
2383 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2384}
2385
2386template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002387basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002388basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002389{
Alp Tokerec34c482014-05-15 11:27:39 +00002390 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002391 return append(__s, traits_type::length(__s));
2392}
2393
2394// insert
2395
2396template <class _CharT, class _Traits, class _Allocator>
2397basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002398basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002399{
Alp Tokerec34c482014-05-15 11:27:39 +00002400 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002401 size_type __sz = size();
2402 if (__pos > __sz)
2403 this->__throw_out_of_range();
2404 size_type __cap = capacity();
2405 if (__cap - __sz >= __n)
2406 {
2407 if (__n)
2408 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002409 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002410 size_type __n_move = __sz - __pos;
2411 if (__n_move != 0)
2412 {
2413 if (__p + __pos <= __s && __s < __p + __sz)
2414 __s += __n;
2415 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2416 }
2417 traits_type::move(__p + __pos, __s, __n);
2418 __sz += __n;
2419 __set_size(__sz);
2420 traits_type::assign(__p[__sz], value_type());
2421 }
2422 }
2423 else
2424 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2425 return *this;
2426}
2427
2428template <class _CharT, class _Traits, class _Allocator>
2429basic_string<_CharT, _Traits, _Allocator>&
2430basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2431{
2432 size_type __sz = size();
2433 if (__pos > __sz)
2434 this->__throw_out_of_range();
2435 if (__n)
2436 {
2437 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002438 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002439 if (__cap - __sz >= __n)
2440 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002441 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002442 size_type __n_move = __sz - __pos;
2443 if (__n_move != 0)
2444 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2445 }
2446 else
2447 {
2448 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002449 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002450 }
2451 traits_type::assign(__p + __pos, __n, __c);
2452 __sz += __n;
2453 __set_size(__sz);
2454 traits_type::assign(__p[__sz], value_type());
2455 }
2456 return *this;
2457}
2458
2459template <class _CharT, class _Traits, class _Allocator>
2460template<class _InputIterator>
2461typename enable_if
2462<
Marshall Clowdf9db312016-01-13 21:54:34 +00002463 __is_exactly_input_iterator<_InputIterator>::value
2464 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2465 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002466>::type
2467basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2468{
Howard Hinnant499cea12013-08-23 17:37:05 +00002469#if _LIBCPP_DEBUG_LEVEL >= 2
2470 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2471 "string::insert(iterator, range) called with an iterator not"
2472 " referring to this string");
2473#endif
Marshall Clowd979eed2016-09-05 01:54:30 +00002474 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002475 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002476}
2477
2478template <class _CharT, class _Traits, class _Allocator>
2479template<class _ForwardIterator>
2480typename enable_if
2481<
Marshall Clowdf9db312016-01-13 21:54:34 +00002482 __is_forward_iterator<_ForwardIterator>::value
2483 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002484 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2485>::type
2486basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2487{
Howard Hinnant499cea12013-08-23 17:37:05 +00002488#if _LIBCPP_DEBUG_LEVEL >= 2
2489 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2490 "string::insert(iterator, range) called with an iterator not"
2491 " referring to this string");
2492#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002493 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002494 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002495 if (__n)
2496 {
Eric Fiselier622c7d52017-04-15 06:49:02 +00002497 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2498 _CharRef __tmp_char = *__first;
2499 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
Marshall Clowd979eed2016-09-05 01:54:30 +00002500 {
2501 const basic_string __temp(__first, __last, __alloc());
2502 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2503 }
2504
2505 size_type __sz = size();
2506 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002507 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002508 if (__cap - __sz >= __n)
2509 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002510 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002511 size_type __n_move = __sz - __ip;
2512 if (__n_move != 0)
2513 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2514 }
2515 else
2516 {
2517 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002518 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002519 }
2520 __sz += __n;
2521 __set_size(__sz);
2522 traits_type::assign(__p[__sz], value_type());
2523 for (__p += __ip; __first != __last; ++__p, ++__first)
2524 traits_type::assign(*__p, *__first);
2525 }
2526 return begin() + __ip;
2527}
2528
2529template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002530inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002531basic_string<_CharT, _Traits, _Allocator>&
2532basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2533{
2534 return insert(__pos1, __str.data(), __str.size());
2535}
2536
2537template <class _CharT, class _Traits, class _Allocator>
2538basic_string<_CharT, _Traits, _Allocator>&
2539basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2540 size_type __pos2, size_type __n)
2541{
2542 size_type __str_sz = __str.size();
2543 if (__pos2 > __str_sz)
2544 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002545 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002546}
2547
2548template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002549template <class _Tp>
2550typename enable_if
2551<
2552 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
Marshall Clowf1729d92017-11-15 20:02:27 +00002553 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002554>::type
2555basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002556 size_type __pos2, size_type __n)
2557{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002558 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002559 size_type __str_sz = __sv.size();
2560 if (__pos2 > __str_sz)
2561 this->__throw_out_of_range();
2562 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2563}
2564
2565template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002566basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002567basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002568{
Alp Tokerec34c482014-05-15 11:27:39 +00002569 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002570 return insert(__pos, __s, traits_type::length(__s));
2571}
2572
2573template <class _CharT, class _Traits, class _Allocator>
2574typename basic_string<_CharT, _Traits, _Allocator>::iterator
2575basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2576{
2577 size_type __ip = static_cast<size_type>(__pos - begin());
2578 size_type __sz = size();
2579 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002580 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002581 if (__cap == __sz)
2582 {
2583 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002584 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002585 }
2586 else
2587 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002588 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002589 size_type __n_move = __sz - __ip;
2590 if (__n_move != 0)
2591 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2592 }
2593 traits_type::assign(__p[__ip], __c);
2594 traits_type::assign(__p[++__sz], value_type());
2595 __set_size(__sz);
2596 return begin() + static_cast<difference_type>(__ip);
2597}
2598
2599template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002600inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002601typename basic_string<_CharT, _Traits, _Allocator>::iterator
2602basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2603{
Howard Hinnant499cea12013-08-23 17:37:05 +00002604#if _LIBCPP_DEBUG_LEVEL >= 2
2605 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2606 "string::insert(iterator, n, value) called with an iterator not"
2607 " referring to this string");
2608#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002609 difference_type __p = __pos - begin();
2610 insert(static_cast<size_type>(__p), __n, __c);
2611 return begin() + __p;
2612}
2613
2614// replace
2615
2616template <class _CharT, class _Traits, class _Allocator>
2617basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002618basic_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 +00002619 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002620{
Alp Tokerec34c482014-05-15 11:27:39 +00002621 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002622 size_type __sz = size();
2623 if (__pos > __sz)
2624 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002625 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002626 size_type __cap = capacity();
2627 if (__cap - __sz + __n1 >= __n2)
2628 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002629 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002630 if (__n1 != __n2)
2631 {
2632 size_type __n_move = __sz - __pos - __n1;
2633 if (__n_move != 0)
2634 {
2635 if (__n1 > __n2)
2636 {
2637 traits_type::move(__p + __pos, __s, __n2);
2638 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2639 goto __finish;
2640 }
2641 if (__p + __pos < __s && __s < __p + __sz)
2642 {
2643 if (__p + __pos + __n1 <= __s)
2644 __s += __n2 - __n1;
2645 else // __p + __pos < __s < __p + __pos + __n1
2646 {
2647 traits_type::move(__p + __pos, __s, __n1);
2648 __pos += __n1;
2649 __s += __n2;
2650 __n2 -= __n1;
2651 __n1 = 0;
2652 }
2653 }
2654 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2655 }
2656 }
2657 traits_type::move(__p + __pos, __s, __n2);
2658__finish:
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002659// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
2660// but this is a safe operation, so we disable the check.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002661 __sz += __n2 - __n1;
2662 __set_size(__sz);
2663 __invalidate_iterators_past(__sz);
2664 traits_type::assign(__p[__sz], value_type());
2665 }
2666 else
2667 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2668 return *this;
2669}
2670
2671template <class _CharT, class _Traits, class _Allocator>
2672basic_string<_CharT, _Traits, _Allocator>&
2673basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
Eric Fiselier3b7c1342017-03-09 01:54:13 +00002674 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002675{
2676 size_type __sz = size();
2677 if (__pos > __sz)
2678 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002679 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002680 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002681 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002682 if (__cap - __sz + __n1 >= __n2)
2683 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002684 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002685 if (__n1 != __n2)
2686 {
2687 size_type __n_move = __sz - __pos - __n1;
2688 if (__n_move != 0)
2689 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2690 }
2691 }
2692 else
2693 {
2694 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002695 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002696 }
2697 traits_type::assign(__p + __pos, __n2, __c);
2698 __sz += __n2 - __n1;
2699 __set_size(__sz);
2700 __invalidate_iterators_past(__sz);
2701 traits_type::assign(__p[__sz], value_type());
2702 return *this;
2703}
2704
2705template <class _CharT, class _Traits, class _Allocator>
2706template<class _InputIterator>
2707typename enable_if
2708<
2709 __is_input_iterator<_InputIterator>::value,
2710 basic_string<_CharT, _Traits, _Allocator>&
2711>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002712basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002713 _InputIterator __j1, _InputIterator __j2)
2714{
Marshall Clowd979eed2016-09-05 01:54:30 +00002715 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002716 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002717}
2718
2719template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002720inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002721basic_string<_CharT, _Traits, _Allocator>&
2722basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2723{
2724 return replace(__pos1, __n1, __str.data(), __str.size());
2725}
2726
2727template <class _CharT, class _Traits, class _Allocator>
2728basic_string<_CharT, _Traits, _Allocator>&
2729basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2730 size_type __pos2, size_type __n2)
2731{
2732 size_type __str_sz = __str.size();
2733 if (__pos2 > __str_sz)
2734 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002735 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002736}
2737
2738template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002739template <class _Tp>
2740typename enable_if
2741<
Marshall Clowf1729d92017-11-15 20:02:27 +00002742 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2743 basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow6ac8de02016-09-24 22:45:42 +00002744>::type
2745basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002746 size_type __pos2, size_type __n2)
2747{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002748 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002749 size_type __str_sz = __sv.size();
2750 if (__pos2 > __str_sz)
2751 this->__throw_out_of_range();
2752 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2753}
2754
2755template <class _CharT, class _Traits, class _Allocator>
2756basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002757basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002758{
Alp Tokerec34c482014-05-15 11:27:39 +00002759 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002760 return replace(__pos, __n1, __s, traits_type::length(__s));
2761}
2762
2763template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002764inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002765basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002766basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002767{
2768 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2769 __str.data(), __str.size());
2770}
2771
2772template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002773inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002774basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002775basic_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 +00002776{
2777 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2778}
2779
2780template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002781inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002782basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002783basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002784{
2785 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2786}
2787
2788template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002789inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002790basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002791basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002792{
2793 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2794}
2795
2796// erase
2797
2798template <class _CharT, class _Traits, class _Allocator>
2799basic_string<_CharT, _Traits, _Allocator>&
2800basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2801{
2802 size_type __sz = size();
2803 if (__pos > __sz)
2804 this->__throw_out_of_range();
2805 if (__n)
2806 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002807 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002808 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002809 size_type __n_move = __sz - __pos - __n;
2810 if (__n_move != 0)
2811 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2812 __sz -= __n;
2813 __set_size(__sz);
2814 __invalidate_iterators_past(__sz);
2815 traits_type::assign(__p[__sz], value_type());
2816 }
2817 return *this;
2818}
2819
2820template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002821inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002822typename basic_string<_CharT, _Traits, _Allocator>::iterator
2823basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2824{
Howard Hinnant499cea12013-08-23 17:37:05 +00002825#if _LIBCPP_DEBUG_LEVEL >= 2
2826 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2827 "string::erase(iterator) called with an iterator not"
2828 " referring to this string");
2829#endif
2830 _LIBCPP_ASSERT(__pos != end(),
2831 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002832 iterator __b = begin();
2833 size_type __r = static_cast<size_type>(__pos - __b);
2834 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002835 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002836}
2837
2838template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002839inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002840typename basic_string<_CharT, _Traits, _Allocator>::iterator
2841basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2842{
Howard Hinnant499cea12013-08-23 17:37:05 +00002843#if _LIBCPP_DEBUG_LEVEL >= 2
2844 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2845 "string::erase(iterator, iterator) called with an iterator not"
2846 " referring to this string");
2847#endif
2848 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002849 iterator __b = begin();
2850 size_type __r = static_cast<size_type>(__first - __b);
2851 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00002852 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002853}
2854
2855template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002856inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002857void
2858basic_string<_CharT, _Traits, _Allocator>::pop_back()
2859{
Howard Hinnant499cea12013-08-23 17:37:05 +00002860 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002861 size_type __sz;
2862 if (__is_long())
2863 {
2864 __sz = __get_long_size() - 1;
2865 __set_long_size(__sz);
2866 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2867 }
2868 else
2869 {
2870 __sz = __get_short_size() - 1;
2871 __set_short_size(__sz);
2872 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2873 }
2874 __invalidate_iterators_past(__sz);
2875}
2876
2877template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002878inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002879void
Howard Hinnanta6119a82011-05-29 19:57:12 +00002880basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002881{
2882 __invalidate_all_iterators();
2883 if (__is_long())
2884 {
2885 traits_type::assign(*__get_long_pointer(), value_type());
2886 __set_long_size(0);
2887 }
2888 else
2889 {
2890 traits_type::assign(*__get_short_pointer(), value_type());
2891 __set_short_size(0);
2892 }
2893}
2894
2895template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002896inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002897void
2898basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2899{
2900 if (__is_long())
2901 {
2902 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2903 __set_long_size(__pos);
2904 }
2905 else
2906 {
2907 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2908 __set_short_size(__pos);
2909 }
2910 __invalidate_iterators_past(__pos);
2911}
2912
2913template <class _CharT, class _Traits, class _Allocator>
2914void
2915basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2916{
2917 size_type __sz = size();
2918 if (__n > __sz)
2919 append(__n - __sz, __c);
2920 else
2921 __erase_to_end(__n);
2922}
2923
2924template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002925inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002926typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002927basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002928{
Howard Hinnante32b5e22010-11-17 17:55:08 +00002929 size_type __m = __alloc_traits::max_size(__alloc());
Eric Fiselier5ccf0432017-10-17 13:16:01 +00002930#ifdef _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00002931 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002932#else
Marshall Clow09f85502013-10-31 17:23:08 +00002933 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002934#endif
2935}
2936
2937template <class _CharT, class _Traits, class _Allocator>
2938void
2939basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2940{
2941 if (__res_arg > max_size())
2942 this->__throw_length_error();
2943 size_type __cap = capacity();
2944 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002945 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002946 __res_arg = __recommend(__res_arg);
2947 if (__res_arg != __cap)
2948 {
2949 pointer __new_data, __p;
2950 bool __was_long, __now_long;
2951 if (__res_arg == __min_cap - 1)
2952 {
2953 __was_long = true;
2954 __now_long = false;
2955 __new_data = __get_short_pointer();
2956 __p = __get_long_pointer();
2957 }
2958 else
2959 {
2960 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002961 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002962 else
2963 {
2964 #ifndef _LIBCPP_NO_EXCEPTIONS
2965 try
2966 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002967 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00002968 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002969 #ifndef _LIBCPP_NO_EXCEPTIONS
2970 }
2971 catch (...)
2972 {
2973 return;
2974 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002975 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002976 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002977 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00002978 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002979 }
2980 __now_long = true;
2981 __was_long = __is_long();
2982 __p = __get_pointer();
2983 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002984 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
2985 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002986 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002987 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002988 if (__now_long)
2989 {
2990 __set_long_cap(__res_arg+1);
2991 __set_long_size(__sz);
2992 __set_long_pointer(__new_data);
2993 }
2994 else
2995 __set_short_size(__sz);
2996 __invalidate_all_iterators();
2997 }
2998}
2999
3000template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003001inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003002typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003003basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003004{
Howard Hinnant499cea12013-08-23 17:37:05 +00003005 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003006 return *(data() + __pos);
3007}
3008
3009template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003010inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003011typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003012basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003013{
Howard Hinnant499cea12013-08-23 17:37:05 +00003014 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003015 return *(__get_pointer() + __pos);
3016}
3017
3018template <class _CharT, class _Traits, class _Allocator>
3019typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3020basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3021{
3022 if (__n >= size())
3023 this->__throw_out_of_range();
3024 return (*this)[__n];
3025}
3026
3027template <class _CharT, class _Traits, class _Allocator>
3028typename basic_string<_CharT, _Traits, _Allocator>::reference
3029basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3030{
3031 if (__n >= size())
3032 this->__throw_out_of_range();
3033 return (*this)[__n];
3034}
3035
3036template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003037inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003038typename basic_string<_CharT, _Traits, _Allocator>::reference
3039basic_string<_CharT, _Traits, _Allocator>::front()
3040{
Howard Hinnant499cea12013-08-23 17:37:05 +00003041 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003042 return *__get_pointer();
3043}
3044
3045template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003046inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003047typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3048basic_string<_CharT, _Traits, _Allocator>::front() const
3049{
Howard Hinnant499cea12013-08-23 17:37:05 +00003050 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003051 return *data();
3052}
3053
3054template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003055inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003056typename basic_string<_CharT, _Traits, _Allocator>::reference
3057basic_string<_CharT, _Traits, _Allocator>::back()
3058{
Howard Hinnant499cea12013-08-23 17:37:05 +00003059 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003060 return *(__get_pointer() + size() - 1);
3061}
3062
3063template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003064inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003065typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3066basic_string<_CharT, _Traits, _Allocator>::back() const
3067{
Howard Hinnant499cea12013-08-23 17:37:05 +00003068 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003069 return *(data() + size() - 1);
3070}
3071
3072template <class _CharT, class _Traits, class _Allocator>
3073typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003074basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003075{
3076 size_type __sz = size();
3077 if (__pos > __sz)
3078 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003079 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003080 traits_type::copy(__s, data() + __pos, __rlen);
3081 return __rlen;
3082}
3083
3084template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003085inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003086basic_string<_CharT, _Traits, _Allocator>
3087basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3088{
3089 return basic_string(*this, __pos, __n, __alloc());
3090}
3091
3092template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003093inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003094void
3095basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00003096#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00003097 _NOEXCEPT_DEBUG
Marshall Clow7d914d12015-07-13 20:04:56 +00003098#else
Eric Fiselier47257c42016-12-28 05:53:01 +00003099 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00003100 __is_nothrow_swappable<allocator_type>::value)
3101#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003102{
Howard Hinnant499cea12013-08-23 17:37:05 +00003103#if _LIBCPP_DEBUG_LEVEL >= 2
3104 if (!__is_long())
3105 __get_db()->__invalidate_all(this);
3106 if (!__str.__is_long())
3107 __get_db()->__invalidate_all(&__str);
3108 __get_db()->swap(this, &__str);
3109#endif
Eric Fiselier47257c42016-12-28 05:53:01 +00003110 _LIBCPP_ASSERT(
3111 __alloc_traits::propagate_on_container_swap::value ||
3112 __alloc_traits::is_always_equal::value ||
3113 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnant0949eed2011-06-30 21:18:19 +00003114 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00003115 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003116}
3117
3118// find
3119
3120template <class _Traits>
3121struct _LIBCPP_HIDDEN __traits_eq
3122{
3123 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003124 _LIBCPP_INLINE_VISIBILITY
3125 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3126 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003127};
3128
3129template<class _CharT, class _Traits, class _Allocator>
3130typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003131basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003132 size_type __pos,
3133 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003134{
Alp Tokerec34c482014-05-15 11:27:39 +00003135 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003136 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003137 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003138}
3139
3140template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003141inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003142typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003143basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3144 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003145{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003146 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003147 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003148}
3149
3150template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003151inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003152typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003153basic_string<_CharT, _Traits, _Allocator>::find(__self_view __sv,
3154 size_type __pos) const _NOEXCEPT
3155{
3156 return __str_find<value_type, size_type, traits_type, npos>
3157 (data(), size(), __sv.data(), __pos, __sv.size());
3158}
3159
3160template<class _CharT, class _Traits, class _Allocator>
3161inline _LIBCPP_INLINE_VISIBILITY
3162typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003163basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003164 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003165{
Alp Tokerec34c482014-05-15 11:27:39 +00003166 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003167 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003168 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003169}
3170
3171template<class _CharT, class _Traits, class _Allocator>
3172typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003173basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3174 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003175{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003176 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003177 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003178}
3179
3180// rfind
3181
3182template<class _CharT, class _Traits, class _Allocator>
3183typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003184basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003185 size_type __pos,
3186 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003187{
Alp Tokerec34c482014-05-15 11:27:39 +00003188 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003189 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003190 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003191}
3192
3193template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003194inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003195typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003196basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3197 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003198{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003199 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003200 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003201}
3202
3203template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003204inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003205typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003206basic_string<_CharT, _Traits, _Allocator>::rfind(__self_view __sv,
3207 size_type __pos) const _NOEXCEPT
3208{
3209 return __str_rfind<value_type, size_type, traits_type, npos>
3210 (data(), size(), __sv.data(), __pos, __sv.size());
3211}
3212
3213template<class _CharT, class _Traits, class _Allocator>
3214inline _LIBCPP_INLINE_VISIBILITY
3215typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003216basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003217 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003218{
Alp Tokerec34c482014-05-15 11:27:39 +00003219 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003220 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003221 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003222}
3223
3224template<class _CharT, class _Traits, class _Allocator>
3225typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003226basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3227 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003228{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003229 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003230 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003231}
3232
3233// find_first_of
3234
3235template<class _CharT, class _Traits, class _Allocator>
3236typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003237basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003238 size_type __pos,
3239 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003240{
Alp Tokerec34c482014-05-15 11:27:39 +00003241 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003242 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003243 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003244}
3245
3246template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003247inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003248typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003249basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3250 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003251{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003252 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003253 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003254}
3255
3256template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003257inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003258typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003259basic_string<_CharT, _Traits, _Allocator>::find_first_of(__self_view __sv,
3260 size_type __pos) const _NOEXCEPT
3261{
3262 return __str_find_first_of<value_type, size_type, traits_type, npos>
3263 (data(), size(), __sv.data(), __pos, __sv.size());
3264}
3265
3266template<class _CharT, class _Traits, class _Allocator>
3267inline _LIBCPP_INLINE_VISIBILITY
3268typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003269basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003270 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003271{
Alp Tokerec34c482014-05-15 11:27:39 +00003272 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003273 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003274 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003275}
3276
3277template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003278inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003279typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003280basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3281 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003282{
3283 return find(__c, __pos);
3284}
3285
3286// find_last_of
3287
3288template<class _CharT, class _Traits, class _Allocator>
3289typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003290basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003291 size_type __pos,
3292 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003293{
Alp Tokerec34c482014-05-15 11:27:39 +00003294 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003295 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003296 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003297}
3298
3299template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003300inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003301typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003302basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3303 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003304{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003305 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003306 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003307}
3308
3309template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003310inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003311typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003312basic_string<_CharT, _Traits, _Allocator>::find_last_of(__self_view __sv,
3313 size_type __pos) const _NOEXCEPT
3314{
3315 return __str_find_last_of<value_type, size_type, traits_type, npos>
3316 (data(), size(), __sv.data(), __pos, __sv.size());
3317}
3318
3319template<class _CharT, class _Traits, class _Allocator>
3320inline _LIBCPP_INLINE_VISIBILITY
3321typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003322basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003323 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003324{
Alp Tokerec34c482014-05-15 11:27:39 +00003325 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003326 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003327 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003328}
3329
3330template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003331inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003332typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003333basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3334 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003335{
3336 return rfind(__c, __pos);
3337}
3338
3339// find_first_not_of
3340
3341template<class _CharT, class _Traits, class _Allocator>
3342typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003343basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003344 size_type __pos,
3345 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003346{
Alp Tokerec34c482014-05-15 11:27:39 +00003347 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003348 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003349 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003350}
3351
3352template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003353inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003354typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003355basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3356 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003357{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003358 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003359 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003360}
3361
3362template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003363inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003364typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003365basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(__self_view __sv,
3366 size_type __pos) const _NOEXCEPT
3367{
3368 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3369 (data(), size(), __sv.data(), __pos, __sv.size());
3370}
3371
3372template<class _CharT, class _Traits, class _Allocator>
3373inline _LIBCPP_INLINE_VISIBILITY
3374typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003375basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003376 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003377{
Alp Tokerec34c482014-05-15 11:27:39 +00003378 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003379 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003380 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003381}
3382
3383template<class _CharT, class _Traits, class _Allocator>
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_first_not_of(value_type __c,
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_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003390 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003391}
3392
3393// find_last_not_of
3394
3395template<class _CharT, class _Traits, class _Allocator>
3396typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003397basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003398 size_type __pos,
3399 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003400{
Alp Tokerec34c482014-05-15 11:27:39 +00003401 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003402 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003403 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003404}
3405
3406template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003407inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003408typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003409basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3410 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003411{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003412 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003413 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003414}
3415
3416template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003417inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003418typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003419basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(__self_view __sv,
3420 size_type __pos) const _NOEXCEPT
3421{
3422 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3423 (data(), size(), __sv.data(), __pos, __sv.size());
3424}
3425
3426template<class _CharT, class _Traits, class _Allocator>
3427inline _LIBCPP_INLINE_VISIBILITY
3428typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003429basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003430 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003431{
Alp Tokerec34c482014-05-15 11:27:39 +00003432 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003433 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003434 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003435}
3436
3437template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003438inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003439typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003440basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3441 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003442{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003443 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003444 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003445}
3446
3447// compare
3448
3449template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003450inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003451int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003452basic_string<_CharT, _Traits, _Allocator>::compare(__self_view __sv) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003453{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003454 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003455 size_t __rhs_sz = __sv.size();
3456 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:06 +00003457 _VSTD::min(__lhs_sz, __rhs_sz));
3458 if (__result != 0)
3459 return __result;
3460 if (__lhs_sz < __rhs_sz)
3461 return -1;
3462 if (__lhs_sz > __rhs_sz)
3463 return 1;
3464 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003465}
3466
3467template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003468inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003469int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003470basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003471{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003472 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003473}
3474
3475template <class _CharT, class _Traits, class _Allocator>
3476int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003477basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3478 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003479 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003480 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003481{
Alp Tokerec34c482014-05-15 11:27:39 +00003482 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003483 size_type __sz = size();
3484 if (__pos1 > __sz || __n2 == npos)
3485 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003486 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3487 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003488 if (__r == 0)
3489 {
3490 if (__rlen < __n2)
3491 __r = -1;
3492 else if (__rlen > __n2)
3493 __r = 1;
3494 }
3495 return __r;
3496}
3497
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003498template <class _CharT, class _Traits, class _Allocator>
3499inline _LIBCPP_INLINE_VISIBILITY
3500int
3501basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3502 size_type __n1,
3503 __self_view __sv) const
3504{
3505 return compare(__pos1, __n1, __sv.data(), __sv.size());
3506}
3507
3508template <class _CharT, class _Traits, class _Allocator>
3509inline _LIBCPP_INLINE_VISIBILITY
3510int
3511basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3512 size_type __n1,
3513 const basic_string& __str) const
3514{
3515 return compare(__pos1, __n1, __str.data(), __str.size());
3516}
3517
3518template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00003519template <class _Tp>
3520typename enable_if
3521<
Marshall Clowf1729d92017-11-15 20:02:27 +00003522 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3523 int
Marshall Clow6ac8de02016-09-24 22:45:42 +00003524>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003525basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3526 size_type __n1,
Marshall Clow6ac8de02016-09-24 22:45:42 +00003527 const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003528 size_type __pos2,
3529 size_type __n2) const
3530{
Marshall Clow6ac8de02016-09-24 22:45:42 +00003531 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003532 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3533}
3534
3535template <class _CharT, class _Traits, class _Allocator>
3536int
3537basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3538 size_type __n1,
3539 const basic_string& __str,
3540 size_type __pos2,
3541 size_type __n2) const
3542{
3543 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3544}
3545
3546template <class _CharT, class _Traits, class _Allocator>
3547int
3548basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3549{
3550 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3551 return compare(0, npos, __s, traits_type::length(__s));
3552}
3553
3554template <class _CharT, class _Traits, class _Allocator>
3555int
3556basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3557 size_type __n1,
3558 const value_type* __s) const
3559{
3560 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3561 return compare(__pos1, __n1, __s, traits_type::length(__s));
3562}
3563
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003564// __invariants
3565
3566template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003567inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003568bool
3569basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3570{
3571 if (size() > capacity())
3572 return false;
3573 if (capacity() < __min_cap - 1)
3574 return false;
3575 if (data() == 0)
3576 return false;
3577 if (data()[size()] != value_type(0))
3578 return false;
3579 return true;
3580}
3581
3582// operator==
3583
3584template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003585inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003586bool
3587operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003588 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003589{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003590 size_t __lhs_sz = __lhs.size();
3591 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3592 __rhs.data(),
3593 __lhs_sz) == 0;
3594}
3595
3596template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003597inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003598bool
3599operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3600 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3601{
3602 size_t __lhs_sz = __lhs.size();
3603 if (__lhs_sz != __rhs.size())
3604 return false;
3605 const char* __lp = __lhs.data();
3606 const char* __rp = __rhs.data();
3607 if (__lhs.__is_long())
3608 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3609 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3610 if (*__lp != *__rp)
3611 return false;
3612 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003613}
3614
3615template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003616inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003617bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003618operator==(const _CharT* __lhs,
3619 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003620{
Eric Fiselier4f241822015-08-28 03:02:37 +00003621 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3622 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3623 size_t __lhs_len = _Traits::length(__lhs);
3624 if (__lhs_len != __rhs.size()) return false;
3625 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003626}
3627
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003628template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003629inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003630bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003631operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3632 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003633{
Eric Fiselier4f241822015-08-28 03:02:37 +00003634 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3635 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3636 size_t __rhs_len = _Traits::length(__rhs);
3637 if (__rhs_len != __lhs.size()) return false;
3638 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003639}
3640
Howard Hinnant324bb032010-08-22 00:02:43 +00003641template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003642inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003643bool
3644operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003645 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003646{
3647 return !(__lhs == __rhs);
3648}
3649
3650template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003651inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003652bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003653operator!=(const _CharT* __lhs,
3654 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003655{
3656 return !(__lhs == __rhs);
3657}
3658
3659template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003660inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003661bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003662operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3663 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003664{
3665 return !(__lhs == __rhs);
3666}
3667
3668// operator<
3669
3670template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003671inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003672bool
3673operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003674 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003675{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003676 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003677}
3678
3679template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003680inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003681bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003682operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3683 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003684{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003685 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003686}
3687
3688template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003689inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003690bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003691operator< (const _CharT* __lhs,
3692 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003693{
3694 return __rhs.compare(__lhs) > 0;
3695}
3696
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003697// operator>
3698
3699template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003700inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003701bool
3702operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003703 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003704{
3705 return __rhs < __lhs;
3706}
3707
3708template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003709inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003710bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003711operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3712 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003713{
3714 return __rhs < __lhs;
3715}
3716
3717template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003718inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003719bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003720operator> (const _CharT* __lhs,
3721 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003722{
3723 return __rhs < __lhs;
3724}
3725
3726// operator<=
3727
3728template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003729inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003730bool
3731operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003732 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003733{
3734 return !(__rhs < __lhs);
3735}
3736
3737template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003738inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003739bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003740operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3741 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003742{
3743 return !(__rhs < __lhs);
3744}
3745
3746template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003747inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003748bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003749operator<=(const _CharT* __lhs,
3750 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003751{
3752 return !(__rhs < __lhs);
3753}
3754
3755// operator>=
3756
3757template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003758inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003759bool
3760operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003761 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003762{
3763 return !(__lhs < __rhs);
3764}
3765
3766template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003767inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003768bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003769operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3770 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003771{
3772 return !(__lhs < __rhs);
3773}
3774
3775template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003776inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003777bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003778operator>=(const _CharT* __lhs,
3779 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003780{
3781 return !(__lhs < __rhs);
3782}
3783
3784// operator +
3785
3786template<class _CharT, class _Traits, class _Allocator>
3787basic_string<_CharT, _Traits, _Allocator>
3788operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3789 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3790{
3791 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3792 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3793 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3794 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __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 _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3802{
3803 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3804 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3805 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3806 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3807 __r.append(__rhs.data(), __rhs_sz);
3808 return __r;
3809}
3810
3811template<class _CharT, class _Traits, class _Allocator>
3812basic_string<_CharT, _Traits, _Allocator>
3813operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3814{
3815 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3816 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3817 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3818 __r.append(__rhs.data(), __rhs_sz);
3819 return __r;
3820}
3821
3822template<class _CharT, class _Traits, class _Allocator>
3823basic_string<_CharT, _Traits, _Allocator>
3824operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3825{
3826 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3827 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3828 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3829 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3830 __r.append(__rhs, __rhs_sz);
3831 return __r;
3832}
3833
3834template<class _CharT, class _Traits, class _Allocator>
3835basic_string<_CharT, _Traits, _Allocator>
3836operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3837{
3838 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3839 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3840 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3841 __r.push_back(__rhs);
3842 return __r;
3843}
3844
Eric Fiselier3e928972017-04-19 00:28:44 +00003845#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003846
3847template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003848inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003849basic_string<_CharT, _Traits, _Allocator>
3850operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3851{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003852 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003853}
3854
3855template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003856inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003857basic_string<_CharT, _Traits, _Allocator>
3858operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3859{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003860 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003861}
3862
3863template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003864inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003865basic_string<_CharT, _Traits, _Allocator>
3866operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3867{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003868 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003869}
3870
3871template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003872inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003873basic_string<_CharT, _Traits, _Allocator>
3874operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3875{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003876 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003877}
3878
3879template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003880inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003881basic_string<_CharT, _Traits, _Allocator>
3882operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3883{
3884 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003885 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003886}
3887
3888template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003889inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003890basic_string<_CharT, _Traits, _Allocator>
3891operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3892{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003893 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003894}
3895
3896template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003897inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003898basic_string<_CharT, _Traits, _Allocator>
3899operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3900{
3901 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003902 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003903}
3904
Eric Fiselier3e928972017-04-19 00:28:44 +00003905#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003906
3907// swap
3908
3909template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003910inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003911void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003912swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003913 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3914 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003915{
3916 __lhs.swap(__rhs);
3917}
3918
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003919#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3920
3921typedef basic_string<char16_t> u16string;
3922typedef basic_string<char32_t> u32string;
3923
Howard Hinnant324bb032010-08-22 00:02:43 +00003924#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003925
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003926_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3927_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3928_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3929_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
3930_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003931
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003932_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
3933_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
3934_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003935
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003936_LIBCPP_FUNC_VIS string to_string(int __val);
3937_LIBCPP_FUNC_VIS string to_string(unsigned __val);
3938_LIBCPP_FUNC_VIS string to_string(long __val);
3939_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
3940_LIBCPP_FUNC_VIS string to_string(long long __val);
3941_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
3942_LIBCPP_FUNC_VIS string to_string(float __val);
3943_LIBCPP_FUNC_VIS string to_string(double __val);
3944_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003945
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003946_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
3947_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
3948_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
3949_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
3950_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003951
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003952_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
3953_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
3954_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003955
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003956_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
3957_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
3958_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
3959_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
3960_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
3961_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
3962_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
3963_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
3964_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003965
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003966template<class _CharT, class _Traits, class _Allocator>
3967 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
3968 basic_string<_CharT, _Traits, _Allocator>::npos;
3969
3970template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +00003971struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003972 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
3973{
3974 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00003975 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003976};
3977
3978template<class _CharT, class _Traits, class _Allocator>
3979size_t
3980hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00003981 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003982{
Sean Huntaffd9e52011-07-29 23:31:56 +00003983 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003984}
3985
Howard Hinnant464aa5c2011-07-18 15:51:59 +00003986template<class _CharT, class _Traits, class _Allocator>
3987basic_ostream<_CharT, _Traits>&
3988operator<<(basic_ostream<_CharT, _Traits>& __os,
3989 const basic_string<_CharT, _Traits, _Allocator>& __str);
3990
3991template<class _CharT, class _Traits, class _Allocator>
3992basic_istream<_CharT, _Traits>&
3993operator>>(basic_istream<_CharT, _Traits>& __is,
3994 basic_string<_CharT, _Traits, _Allocator>& __str);
3995
3996template<class _CharT, class _Traits, class _Allocator>
3997basic_istream<_CharT, _Traits>&
3998getline(basic_istream<_CharT, _Traits>& __is,
3999 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4000
4001template<class _CharT, class _Traits, class _Allocator>
4002inline _LIBCPP_INLINE_VISIBILITY
4003basic_istream<_CharT, _Traits>&
4004getline(basic_istream<_CharT, _Traits>& __is,
4005 basic_string<_CharT, _Traits, _Allocator>& __str);
4006
Eric Fiselier3e928972017-04-19 00:28:44 +00004007#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004008
4009template<class _CharT, class _Traits, class _Allocator>
4010inline _LIBCPP_INLINE_VISIBILITY
4011basic_istream<_CharT, _Traits>&
4012getline(basic_istream<_CharT, _Traits>&& __is,
4013 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4014
4015template<class _CharT, class _Traits, class _Allocator>
4016inline _LIBCPP_INLINE_VISIBILITY
4017basic_istream<_CharT, _Traits>&
4018getline(basic_istream<_CharT, _Traits>&& __is,
4019 basic_string<_CharT, _Traits, _Allocator>& __str);
4020
Eric Fiselier3e928972017-04-19 00:28:44 +00004021#endif // _LIBCPP_CXX03_LANG
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004022
Howard Hinnant499cea12013-08-23 17:37:05 +00004023#if _LIBCPP_DEBUG_LEVEL >= 2
4024
4025template<class _CharT, class _Traits, class _Allocator>
4026bool
4027basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4028{
4029 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4030 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4031}
4032
4033template<class _CharT, class _Traits, class _Allocator>
4034bool
4035basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4036{
4037 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4038 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4039}
4040
4041template<class _CharT, class _Traits, class _Allocator>
4042bool
4043basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4044{
4045 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4046 return this->data() <= __p && __p <= this->data() + this->size();
4047}
4048
4049template<class _CharT, class _Traits, class _Allocator>
4050bool
4051basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4052{
4053 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4054 return this->data() <= __p && __p < this->data() + this->size();
4055}
4056
4057#endif // _LIBCPP_DEBUG_LEVEL >= 2
4058
Shoaib Meenai68506702017-06-29 02:52:46 +00004059_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
4060_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Shoaib Meenai68506702017-06-29 02:52:46 +00004061
Marshall Clow15234322013-07-23 17:05:24 +00004062#if _LIBCPP_STD_VER > 11
4063// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004064inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004065{
4066 inline namespace string_literals
4067 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004068 inline _LIBCPP_INLINE_VISIBILITY
4069 basic_string<char> operator "" s( const char *__str, size_t __len )
4070 {
4071 return basic_string<char> (__str, __len);
4072 }
Marshall Clow15234322013-07-23 17:05:24 +00004073
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004074 inline _LIBCPP_INLINE_VISIBILITY
4075 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4076 {
4077 return basic_string<wchar_t> (__str, __len);
4078 }
Marshall Clow15234322013-07-23 17:05:24 +00004079
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004080 inline _LIBCPP_INLINE_VISIBILITY
4081 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4082 {
4083 return basic_string<char16_t> (__str, __len);
4084 }
Marshall Clow15234322013-07-23 17:05:24 +00004085
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004086 inline _LIBCPP_INLINE_VISIBILITY
4087 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4088 {
4089 return basic_string<char32_t> (__str, __len);
4090 }
Marshall Clow15234322013-07-23 17:05:24 +00004091 }
4092}
4093#endif
4094
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004095_LIBCPP_END_NAMESPACE_STD
4096
Eric Fiselier018a3d52017-05-31 22:07:49 +00004097_LIBCPP_POP_MACROS
4098
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004099#endif // _LIBCPP_STRING