blob: b56ab384b5dbfc3cb0bb2b6ce868a44a953f4e82 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===--------------------------- string -----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
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:1253 static void assign(char_type& c1, const char_type& c2) noexcept;
Howard Hinnant03d71812012-07-20 19:09:1254 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:1656
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:1264 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:1669};
70
71template <> struct char_traits<char>;
72template <> struct char_traits<wchar_t>;
73
Howard Hinnant324bb032010-08-22 00:02:4374template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
Howard Hinnantbc8d3f92010-05-11 19:42:1675class basic_string
76{
Howard Hinnant324bb032010-08-22 00:02:4377public:
78// types:
Howard Hinnantbc8d3f92010-05-11 19:42:1679 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:4795 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:1698 basic_string(const basic_string& str);
Howard Hinnant53f7d4c2011-06-03 18:40:4799 basic_string(basic_string&& str)
100 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clowf4f7d8f2016-04-07 18:13:41101 basic_string(const basic_string& str, size_type pos,
Howard Hinnanta6a062d2010-06-02 18:20:39102 const allocator_type& a = allocator_type());
Marshall Clowf4f7d8f2016-04-07 18:13:41103 basic_string(const basic_string& str, size_type pos, size_type n,
Marshall Clow1e00d6d2016-07-21 05:31:24104 const Allocator& a = Allocator());
105 explicit basic_string(const basic_string_view<charT, traits> sv, const Allocator& a = Allocator());
Howard Hinnant9dcdcde2013-06-28 16:59:19106 basic_string(const value_type* s, const allocator_type& a = allocator_type());
107 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16108 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
109 template<class InputIterator>
Howard Hinnanta6a062d2010-06-02 18:20:39110 basic_string(InputIterator begin, InputIterator end,
111 const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16112 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
113 basic_string(const basic_string&, const Allocator&);
114 basic_string(basic_string&&, const Allocator&);
115
116 ~basic_string();
117
Marshall Clow1e00d6d2016-07-21 05:31:24118 operator basic_string_view<charT, traits>() const noexcept;
119
Howard Hinnantbc8d3f92010-05-11 19:42:16120 basic_string& operator=(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24121 basic_string& operator=(basic_string_view<charT, traits> sv);
Howard Hinnant53f7d4c2011-06-03 18:40:47122 basic_string& operator=(basic_string&& str)
123 noexcept(
Marshall Clowaf961ed2015-08-18 18:57:00124 allocator_type::propagate_on_container_move_assignment::value ||
125 allocator_type::is_always_equal::value ); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19126 basic_string& operator=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16127 basic_string& operator=(value_type c);
128 basic_string& operator=(initializer_list<value_type>);
129
Howard Hinnanta6119a82011-05-29 19:57:12130 iterator begin() noexcept;
131 const_iterator begin() const noexcept;
132 iterator end() noexcept;
133 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16134
Howard Hinnanta6119a82011-05-29 19:57:12135 reverse_iterator rbegin() noexcept;
136 const_reverse_iterator rbegin() const noexcept;
137 reverse_iterator rend() noexcept;
138 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16139
Howard Hinnanta6119a82011-05-29 19:57:12140 const_iterator cbegin() const noexcept;
141 const_iterator cend() const noexcept;
142 const_reverse_iterator crbegin() const noexcept;
143 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16144
Howard Hinnanta6119a82011-05-29 19:57:12145 size_type size() const noexcept;
146 size_type length() const noexcept;
147 size_type max_size() const noexcept;
148 size_type capacity() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16149
150 void resize(size_type n, value_type c);
151 void resize(size_type n);
152
153 void reserve(size_type res_arg = 0);
154 void shrink_to_fit();
Howard Hinnanta6119a82011-05-29 19:57:12155 void clear() noexcept;
156 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16157
158 const_reference operator[](size_type pos) const;
159 reference operator[](size_type pos);
160
161 const_reference at(size_type n) const;
162 reference at(size_type n);
163
164 basic_string& operator+=(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24165 basic_string& operator+=(basic_string_view<charT, traits> sv);
Howard Hinnant9dcdcde2013-06-28 16:59:19166 basic_string& operator+=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16167 basic_string& operator+=(value_type c);
168 basic_string& operator+=(initializer_list<value_type>);
169
170 basic_string& append(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24171 basic_string& append(basic_string_view<charT, traits> sv);
Marshall Clowa93b5e22014-03-04 19:17:19172 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
Marshall Clow6ac8de02016-09-24 22:45:42173 template <class T>
174 basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19175 basic_string& append(const value_type* s, size_type n);
176 basic_string& append(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16177 basic_string& append(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39178 template<class InputIterator>
179 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16180 basic_string& append(initializer_list<value_type>);
181
182 void push_back(value_type c);
183 void pop_back();
184 reference front();
185 const_reference front() const;
186 reference back();
187 const_reference back() const;
188
189 basic_string& assign(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24190 basic_string& assign(basic_string_view<charT, traits> sv);
Howard Hinnanta6119a82011-05-29 19:57:12191 basic_string& assign(basic_string&& str);
Marshall Clowa93b5e22014-03-04 19:17:19192 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42193 template <class T>
194 basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19195 basic_string& assign(const value_type* s, size_type n);
196 basic_string& assign(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16197 basic_string& assign(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39198 template<class InputIterator>
199 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16200 basic_string& assign(initializer_list<value_type>);
201
202 basic_string& insert(size_type pos1, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24203 basic_string& insert(size_type pos1, basic_string_view<charT, traits> sv);
Howard Hinnanta6a062d2010-06-02 18:20:39204 basic_string& insert(size_type pos1, const basic_string& str,
205 size_type pos2, size_type n);
Marshall Clow6ac8de02016-09-24 22:45:42206 template <class T>
207 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
Marshall Clowa93b5e22014-03-04 19:17:19208 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19209 basic_string& insert(size_type pos, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16210 basic_string& insert(size_type pos, size_type n, value_type c);
211 iterator insert(const_iterator p, value_type c);
212 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39213 template<class InputIterator>
214 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16215 iterator insert(const_iterator p, initializer_list<value_type>);
216
217 basic_string& erase(size_type pos = 0, size_type n = npos);
218 iterator erase(const_iterator position);
219 iterator erase(const_iterator first, const_iterator last);
220
221 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24222 basic_string& replace(size_type pos1, size_type n1, basic_string_view<charT, traits> sv);
Howard Hinnanta6a062d2010-06-02 18:20:39223 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19224 size_type pos2, size_type n2=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42225 template <class T>
226 basic_string& replace(size_type pos1, size_type n1, const T& t,
227 size_type pos2, size_type n); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19228 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
229 basic_string& replace(size_type pos, size_type n1, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16230 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant7b2cb482010-11-17 21:11:40231 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24232 basic_string& replace(const_iterator i1, const_iterator i2, basic_string_view<charT, traits> sv);
Howard Hinnant9dcdcde2013-06-28 16:59:19233 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
234 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
Howard Hinnant7b2cb482010-11-17 21:11:40235 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39236 template<class InputIterator>
Howard Hinnant7b2cb482010-11-17 21:11:40237 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
238 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantbc8d3f92010-05-11 19:42:16239
Howard Hinnant9dcdcde2013-06-28 16:59:19240 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16241 basic_string substr(size_type pos = 0, size_type n = npos) const;
242
Howard Hinnant53f7d4c2011-06-03 18:40:47243 void swap(basic_string& str)
Marshall Clow7d914d12015-07-13 20:04:56244 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
245 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16246
Howard Hinnant9dcdcde2013-06-28 16:59:19247 const value_type* c_str() const noexcept;
248 const value_type* data() const noexcept;
Marshall Clowf532a702016-03-08 15:44:30249 value_type* data() noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16250
Howard Hinnanta6119a82011-05-29 19:57:12251 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16252
Howard Hinnanta6119a82011-05-29 19:57:12253 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24254 size_type find(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19255 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
256 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12257 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16258
Howard Hinnanta6119a82011-05-29 19:57:12259 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24260 size_type ffind(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19261 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
262 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12263 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16264
Howard Hinnanta6119a82011-05-29 19:57:12265 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24266 size_type find_first_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19267 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
268 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12269 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16270
Howard Hinnanta6119a82011-05-29 19:57:12271 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24272 size_type find_last_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19273 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
274 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12275 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16276
Howard Hinnanta6119a82011-05-29 19:57:12277 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24278 size_type find_first_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19279 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
280 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12281 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16282
Howard Hinnanta6119a82011-05-29 19:57:12283 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24284 size_type find_last_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19285 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
286 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12287 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16288
Howard Hinnanta6119a82011-05-29 19:57:12289 int compare(const basic_string& str) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24290 int compare(basic_string_view<charT, traits> sv) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16291 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Marshall Clow1e00d6d2016-07-21 05:31:24292 int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv) const;
Howard Hinnanta6a062d2010-06-02 18:20:39293 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19294 size_type pos2, size_type n2=npos) const; // C++14
Marshall Clow6ac8de02016-09-24 22:45:42295 template <class T>
296 int compare(size_type pos1, size_type n1, const T& t,
297 size_type pos2, size_type n2=npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19298 int compare(const value_type* s) const noexcept;
299 int compare(size_type pos1, size_type n1, const value_type* s) const;
300 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16301
302 bool __invariants() const;
303};
304
305template<class charT, class traits, class Allocator>
306basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39307operator+(const basic_string<charT, traits, Allocator>& lhs,
308 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16309
310template<class charT, class traits, class Allocator>
311basic_string<charT, traits, Allocator>
312operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
313
314template<class charT, class traits, class Allocator>
315basic_string<charT, traits, Allocator>
316operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
317
318template<class charT, class traits, class Allocator>
319basic_string<charT, traits, Allocator>
320operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
321
322template<class charT, class traits, class Allocator>
323basic_string<charT, traits, Allocator>
324operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
325
326template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39327bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12328 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16329
330template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12331bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16332
333template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12334bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16335
Howard Hinnant324bb032010-08-22 00:02:43336template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39337bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12338 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16339
340template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12341bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16342
343template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12344bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16345
346template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39347bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12348 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16349
350template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12351bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16352
353template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12354bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16355
356template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39357bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12358 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16359
360template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12361bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16362
363template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12364bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16365
366template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39367bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12368 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16369
370template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12371bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16372
373template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12374bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16375
376template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39377bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12378 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16379
380template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12381bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16382
383template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12384bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16385
386template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39387void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47388 basic_string<charT, traits, Allocator>& rhs)
389 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16390
391template<class charT, class traits, class Allocator>
392basic_istream<charT, traits>&
393operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
394
395template<class charT, class traits, class Allocator>
396basic_ostream<charT, traits>&
397operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
398
399template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43400basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39401getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
402 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16403
404template<class charT, class traits, class Allocator>
405basic_istream<charT, traits>&
406getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
407
408typedef basic_string<char> string;
409typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39410typedef basic_string<char16_t> u16string;
411typedef basic_string<char32_t> u32string;
412
413int stoi (const string& str, size_t* idx = 0, int base = 10);
414long stol (const string& str, size_t* idx = 0, int base = 10);
415unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
416long long stoll (const string& str, size_t* idx = 0, int base = 10);
417unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
418
419float stof (const string& str, size_t* idx = 0);
420double stod (const string& str, size_t* idx = 0);
421long double stold(const string& str, size_t* idx = 0);
422
423string to_string(int val);
424string to_string(unsigned val);
425string to_string(long val);
426string to_string(unsigned long val);
427string to_string(long long val);
428string to_string(unsigned long long val);
429string to_string(float val);
430string to_string(double val);
431string to_string(long double val);
432
433int stoi (const wstring& str, size_t* idx = 0, int base = 10);
434long stol (const wstring& str, size_t* idx = 0, int base = 10);
435unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
436long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
437unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
438
439float stof (const wstring& str, size_t* idx = 0);
440double stod (const wstring& str, size_t* idx = 0);
441long double stold(const wstring& str, size_t* idx = 0);
442
443wstring to_wstring(int val);
444wstring to_wstring(unsigned val);
445wstring to_wstring(long val);
446wstring to_wstring(unsigned long val);
447wstring to_wstring(long long val);
448wstring to_wstring(unsigned long long val);
449wstring to_wstring(float val);
450wstring to_wstring(double val);
451wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16452
453template <> struct hash<string>;
454template <> struct hash<u16string>;
455template <> struct hash<u32string>;
456template <> struct hash<wstring>;
457
Marshall Clow15234322013-07-23 17:05:24458basic_string<char> operator "" s( const char *str, size_t len ); // C++14
459basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
460basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
461basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
462
Howard Hinnantbc8d3f92010-05-11 19:42:16463} // std
464
465*/
466
467#include <__config>
Marshall Clow1e00d6d2016-07-21 05:31:24468#include <string_view>
Howard Hinnantbc8d3f92010-05-11 19:42:16469#include <iosfwd>
470#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41471#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16472#include <cwchar>
473#include <algorithm>
474#include <iterator>
475#include <utility>
476#include <memory>
477#include <stdexcept>
478#include <type_traits>
479#include <initializer_list>
480#include <__functional_base>
481#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
482#include <cstdint>
483#endif
Marshall Clow1e00d6d2016-07-21 05:31:24484
Howard Hinnant66c6f972011-11-29 16:45:27485#include <__undef_min_max>
486
Eric Fiselierb9536102014-08-10 23:53:08487#include <__debug>
488
Howard Hinnant08e17472011-10-17 20:05:10489#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16490#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10491#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16492
493_LIBCPP_BEGIN_NAMESPACE_STD
494
495// fpos
496
497template <class _StateT>
Howard Hinnant0f678bd2013-08-12 18:38:34498class _LIBCPP_TYPE_VIS_ONLY fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16499{
500private:
501 _StateT __st_;
502 streamoff __off_;
503public:
504 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
505
506 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
507
508 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
509 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
510
511 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
512 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
513 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
514 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
515};
516
517template <class _StateT>
518inline _LIBCPP_INLINE_VISIBILITY
519streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
520 {return streamoff(__x) - streamoff(__y);}
521
522template <class _StateT>
523inline _LIBCPP_INLINE_VISIBILITY
524bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
525 {return streamoff(__x) == streamoff(__y);}
526
527template <class _StateT>
528inline _LIBCPP_INLINE_VISIBILITY
529bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
530 {return streamoff(__x) != streamoff(__y);}
531
Howard Hinnantbc8d3f92010-05-11 19:42:16532// basic_string
533
534template<class _CharT, class _Traits, class _Allocator>
535basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17536operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
537 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16538
539template<class _CharT, class _Traits, class _Allocator>
540basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17541operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16542
543template<class _CharT, class _Traits, class _Allocator>
544basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17545operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16546
547template<class _CharT, class _Traits, class _Allocator>
548basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17549operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16550
551template<class _CharT, class _Traits, class _Allocator>
552basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17553operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16554
555template <bool>
Howard Hinnant0f678bd2013-08-12 18:38:34556class _LIBCPP_TYPE_VIS_ONLY __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16557{
558protected:
Marshall Clow14c09a22016-08-25 15:09:01559 _LIBCPP_NORETURN void __throw_length_error() const;
560 _LIBCPP_NORETURN void __throw_out_of_range() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16561};
562
563template <bool __b>
564void
565__basic_string_common<__b>::__throw_length_error() const
566{
Marshall Clow14c09a22016-08-25 15:09:01567 _VSTD::__throw_length_error("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16568}
569
570template <bool __b>
571void
572__basic_string_common<__b>::__throw_out_of_range() const
573{
Marshall Clow14c09a22016-08-25 15:09:01574 _VSTD::__throw_out_of_range("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16575}
576
Howard Hinnante9df0a52013-08-01 18:17:34577#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45578#pragma warning( push )
579#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34580#endif // _LIBCPP_MSVC
Eric Fiselier833d6442016-09-15 22:27:07581_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34582#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45583#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34584#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16585
Marshall Clowdf9db312016-01-13 21:54:34586#ifdef _LIBCPP_NO_EXCEPTIONS
587template <class _Iter>
588struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
589#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
590template <class _Iter>
591struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
592#else
593template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
594struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
595 noexcept(++(declval<_Iter&>())) &&
596 is_nothrow_assignable<_Iter&, _Iter>::value &&
597 noexcept(declval<_Iter>() == declval<_Iter>()) &&
598 noexcept(*declval<_Iter>())
599)) {};
600
601template <class _Iter>
602struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
603#endif
604
605
606template <class _Iter>
607struct __libcpp_string_gets_noexcept_iterator
608 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
609
Marshall Clow6ac8de02016-09-24 22:45:42610template <class _CharT, class _Traits, class _Tp>
611struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
612( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
613 !is_convertible<const _Tp&, const _CharT*>::value)) {};
614
Evgeniy Stepanov4f01aa82015-10-13 23:48:28615#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48616
617template <class _CharT, size_t = sizeof(_CharT)>
618struct __padding
619{
620 unsigned char __xx[sizeof(_CharT)-1];
621};
622
623template <class _CharT>
624struct __padding<_CharT, 1>
625{
626};
627
Evgeniy Stepanov4f01aa82015-10-13 23:48:28628#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48629
Howard Hinnant324bb032010-08-22 00:02:43630template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34631class _LIBCPP_TYPE_VIS_ONLY basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16632 : private __basic_string_common<true>
633{
634public:
635 typedef basic_string __self;
Marshall Clow1e00d6d2016-07-21 05:31:24636 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantbc8d3f92010-05-11 19:42:16637 typedef _Traits traits_type;
638 typedef typename traits_type::char_type value_type;
639 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08640 typedef allocator_traits<allocator_type> __alloc_traits;
641 typedef typename __alloc_traits::size_type size_type;
642 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47643 typedef value_type& reference;
644 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08645 typedef typename __alloc_traits::pointer pointer;
646 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16647
Howard Hinnant499cea12013-08-23 17:37:05648 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
649 static_assert((is_same<_CharT, value_type>::value),
650 "traits_type::char_type must be the same type as CharT");
651 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
652 "Allocator::value_type must be same type as value_type");
653#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16654 typedef pointer iterator;
655 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43656#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16657 typedef __wrap_iter<pointer> iterator;
658 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43659#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19660 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
661 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16662
663private:
Howard Hinnant15467182013-04-30 21:44:48664
Evgeniy Stepanov4f01aa82015-10-13 23:48:28665#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48666
667 struct __long
668 {
669 pointer __data_;
670 size_type __size_;
671 size_type __cap_;
672 };
673
674#if _LIBCPP_BIG_ENDIAN
675 enum {__short_mask = 0x01};
676 enum {__long_mask = 0x1ul};
677#else // _LIBCPP_BIG_ENDIAN
678 enum {__short_mask = 0x80};
679 enum {__long_mask = ~(size_type(~0) >> 1)};
680#endif // _LIBCPP_BIG_ENDIAN
681
682 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
683 (sizeof(__long) - 1)/sizeof(value_type) : 2};
684
685 struct __short
686 {
687 value_type __data_[__min_cap];
688 struct
689 : __padding<value_type>
690 {
691 unsigned char __size_;
692 };
693 };
694
695#else
696
Howard Hinnantbc8d3f92010-05-11 19:42:16697 struct __long
698 {
699 size_type __cap_;
700 size_type __size_;
701 pointer __data_;
702 };
703
704#if _LIBCPP_BIG_ENDIAN
705 enum {__short_mask = 0x80};
706 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43707#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16708 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04709 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43710#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16711
Howard Hinnantbc8d3f92010-05-11 19:42:16712 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
713 (sizeof(__long) - 1)/sizeof(value_type) : 2};
714
715 struct __short
716 {
717 union
718 {
719 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59720 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16721 };
722 value_type __data_[__min_cap];
723 };
724
Evgeniy Stepanov4f01aa82015-10-13 23:48:28725#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48726
Howard Hinnant499cea12013-08-23 17:37:05727 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16728
Howard Hinnant499cea12013-08-23 17:37:05729 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16730
731 struct __raw
732 {
733 size_type __words[__n_words];
734 };
735
736 struct __rep
737 {
738 union
739 {
740 __long __l;
741 __short __s;
742 __raw __r;
743 };
744 };
745
746 __compressed_pair<__rep, allocator_type> __r_;
747
Howard Hinnantbc8d3f92010-05-11 19:42:16748public:
749 static const size_type npos = -1;
750
Howard Hinnant53f7d4c2011-06-03 18:40:47751 _LIBCPP_INLINE_VISIBILITY basic_string()
752 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43753
754 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
755#if _LIBCPP_STD_VER <= 14
756 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
757#else
758 _NOEXCEPT;
759#endif
760
Howard Hinnantbc8d3f92010-05-11 19:42:16761 basic_string(const basic_string& __str);
762 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43763
Howard Hinnant73d21a42010-09-04 23:28:19764#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47766 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43767#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47768 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43769#else
770 _NOEXCEPT;
771#endif
772
Howard Hinnant9f193f22011-01-26 00:06:59773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16774 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19775#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19776 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43777 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19778 basic_string(const value_type* __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19780 basic_string(const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19782 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16784 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16786 basic_string(size_type __n, value_type __c, const allocator_type& __a);
Marshall Clowf4f7d8f2016-04-07 18:13:41787 basic_string(const basic_string& __str, size_type __pos, size_type __n,
788 const allocator_type& __a = allocator_type());
789 _LIBCPP_INLINE_VISIBILITY
790 basic_string(const basic_string& __str, size_type __pos,
Howard Hinnantbc8d3f92010-05-11 19:42:16791 const allocator_type& __a = allocator_type());
Marshall Clow1e00d6d2016-07-21 05:31:24792 _LIBCPP_INLINE_VISIBILITY explicit
793 basic_string(__self_view __sv);
794 _LIBCPP_INLINE_VISIBILITY
795 basic_string(__self_view __sv, const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16796 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16798 basic_string(_InputIterator __first, _InputIterator __last);
799 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43800 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16801 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02802#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16804 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16806 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02807#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16808
809 ~basic_string();
810
Marshall Clow1e00d6d2016-07-21 05:31:24811 _LIBCPP_INLINE_VISIBILITY
812 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
813
Howard Hinnante32b5e22010-11-17 17:55:08814 basic_string& operator=(const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24815 _LIBCPP_INLINE_VISIBILITY
816 basic_string& operator=(__self_view __sv) {return assign(__sv);}
Howard Hinnant73d21a42010-09-04 23:28:19817#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47819 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00820 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Howard Hinnantbc8d3f92010-05-11 19:42:16821#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19822 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16823 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02824#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16826 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02827#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16828
Howard Hinnant499cea12013-08-23 17:37:05829#if _LIBCPP_DEBUG_LEVEL >= 2
830 _LIBCPP_INLINE_VISIBILITY
831 iterator begin() _NOEXCEPT
832 {return iterator(this, __get_pointer());}
833 _LIBCPP_INLINE_VISIBILITY
834 const_iterator begin() const _NOEXCEPT
835 {return const_iterator(this, __get_pointer());}
836 _LIBCPP_INLINE_VISIBILITY
837 iterator end() _NOEXCEPT
838 {return iterator(this, __get_pointer() + size());}
839 _LIBCPP_INLINE_VISIBILITY
840 const_iterator end() const _NOEXCEPT
841 {return const_iterator(this, __get_pointer() + size());}
842#else
Howard Hinnanta6119a82011-05-29 19:57:12843 _LIBCPP_INLINE_VISIBILITY
844 iterator begin() _NOEXCEPT
845 {return iterator(__get_pointer());}
846 _LIBCPP_INLINE_VISIBILITY
847 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19848 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12849 _LIBCPP_INLINE_VISIBILITY
850 iterator end() _NOEXCEPT
851 {return iterator(__get_pointer() + size());}
852 _LIBCPP_INLINE_VISIBILITY
853 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19854 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05855#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12856 _LIBCPP_INLINE_VISIBILITY
857 reverse_iterator rbegin() _NOEXCEPT
858 {return reverse_iterator(end());}
859 _LIBCPP_INLINE_VISIBILITY
860 const_reverse_iterator rbegin() const _NOEXCEPT
861 {return const_reverse_iterator(end());}
862 _LIBCPP_INLINE_VISIBILITY
863 reverse_iterator rend() _NOEXCEPT
864 {return reverse_iterator(begin());}
865 _LIBCPP_INLINE_VISIBILITY
866 const_reverse_iterator rend() const _NOEXCEPT
867 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16868
Howard Hinnanta6119a82011-05-29 19:57:12869 _LIBCPP_INLINE_VISIBILITY
870 const_iterator cbegin() const _NOEXCEPT
871 {return begin();}
872 _LIBCPP_INLINE_VISIBILITY
873 const_iterator cend() const _NOEXCEPT
874 {return end();}
875 _LIBCPP_INLINE_VISIBILITY
876 const_reverse_iterator crbegin() const _NOEXCEPT
877 {return rbegin();}
878 _LIBCPP_INLINE_VISIBILITY
879 const_reverse_iterator crend() const _NOEXCEPT
880 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16881
Howard Hinnanta6119a82011-05-29 19:57:12882 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16883 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12884 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
885 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
886 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42887 {return (__is_long() ? __get_long_cap()
888 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16889
890 void resize(size_type __n, value_type __c);
891 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
892
893 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47895 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12897 void clear() _NOEXCEPT;
898 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16899
Marshall Clow1e00d6d2016-07-21 05:31:24900 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
901 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16902
903 const_reference at(size_type __n) const;
904 reference at(size_type __n);
905
906 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clow1e00d6d2016-07-21 05:31:24907 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(__self_view __sv) {return append(__sv);}
908 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16909 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02910#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16911 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02912#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16913
Howard Hinnant2d72b1e2010-12-17 14:46:43914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16915 basic_string& append(const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24916 _LIBCPP_INLINE_VISIBILITY
917 basic_string& append(__self_view __sv) { return append(__sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19918 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48919 template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42920 typename enable_if
921 <
922 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
923 basic_string&
924 >::type
925 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19926 basic_string& append(const value_type* __s, size_type __n);
927 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16928 basic_string& append(size_type __n, value_type __c);
929 template<class _InputIterator>
930 typename enable_if
931 <
Marshall Clowdf9db312016-01-13 21:54:34932 __is_exactly_input_iterator<_InputIterator>::value
933 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16934 basic_string&
935 >::type
936 append(_InputIterator __first, _InputIterator __last);
937 template<class _ForwardIterator>
938 typename enable_if
939 <
Marshall Clowdf9db312016-01-13 21:54:34940 __is_forward_iterator<_ForwardIterator>::value
941 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16942 basic_string&
943 >::type
944 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02945#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07946 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16947 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02948#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16949
950 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43951 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16952 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43953 _LIBCPP_INLINE_VISIBILITY reference front();
954 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
955 _LIBCPP_INLINE_VISIBILITY reference back();
956 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16957
Howard Hinnant2d72b1e2010-12-17 14:46:43958 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24959 basic_string& assign(__self_view __sv) { return assign(__sv.data(), __sv.size()); }
960 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29961 basic_string& assign(const basic_string& __str) { return *this = __str; }
Howard Hinnanta6119a82011-05-29 19:57:12962#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
963 _LIBCPP_INLINE_VISIBILITY
964 basic_string& assign(basic_string&& str)
Marshall Clow7ed093b2015-10-05 16:17:34965 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnant0949eed2011-06-30 21:18:19966 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12967#endif
Marshall Clowa93b5e22014-03-04 19:17:19968 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48969 template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42970 typename enable_if
971 <
972 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
973 basic_string&
974 >::type
975 assign(const _Tp & __t, size_type pos, size_type n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19976 basic_string& assign(const value_type* __s, size_type __n);
977 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16978 basic_string& assign(size_type __n, value_type __c);
979 template<class _InputIterator>
980 typename enable_if
981 <
Marshall Clowdf9db312016-01-13 21:54:34982 __is_exactly_input_iterator<_InputIterator>::value
983 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16984 basic_string&
985 >::type
986 assign(_InputIterator __first, _InputIterator __last);
987 template<class _ForwardIterator>
988 typename enable_if
989 <
Marshall Clowdf9db312016-01-13 21:54:34990 __is_forward_iterator<_ForwardIterator>::value
991 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16992 basic_string&
993 >::type
994 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02995#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16997 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02998#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16999
Howard Hinnant2d72b1e2010-12-17 14:46:431000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161001 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:241002 _LIBCPP_INLINE_VISIBILITY
1003 basic_string& insert(size_type __pos1, __self_view __sv) { return insert(__pos1, __sv.data(), __sv.size()); }
Marshall Clow6ac8de02016-09-24 22:45:421004 template <class _Tp>
1005 typename enable_if
1006 <
1007 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1008 basic_string&
1009 >::type
1010 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Marshall Clowa93b5e22014-03-04 19:17:191011 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:191012 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1013 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:161014 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1015 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:431016 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161017 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1018 template<class _InputIterator>
1019 typename enable_if
1020 <
Marshall Clowdf9db312016-01-13 21:54:341021 __is_exactly_input_iterator<_InputIterator>::value
1022 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161023 iterator
1024 >::type
1025 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1026 template<class _ForwardIterator>
1027 typename enable_if
1028 <
Marshall Clowdf9db312016-01-13 21:54:341029 __is_forward_iterator<_ForwardIterator>::value
1030 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161031 iterator
1032 >::type
1033 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:021034#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:071035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161036 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1037 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:021038#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:161039
1040 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:431041 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161042 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:431043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161044 iterator erase(const_iterator __first, const_iterator __last);
1045
Howard Hinnant2d72b1e2010-12-17 14:46:431046 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161047 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:241048 _LIBCPP_INLINE_VISIBILITY
1049 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:191050 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:421051 template <class _Tp>
1052 typename enable_if
1053 <
1054 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1055 basic_string&
1056 >::type
1057 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:191058 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1059 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:161060 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:431061 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:401062 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:431063 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:241064 basic_string& replace(const_iterator __i1, const_iterator __i2, __self_view __sv) { return replace(__i1 - begin(), __i2 - __i1, __sv); }
1065 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191066 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:431067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191068 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:431069 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:401070 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:161071 template<class _InputIterator>
1072 typename enable_if
1073 <
1074 __is_input_iterator<_InputIterator>::value,
1075 basic_string&
1076 >::type
Howard Hinnant7b2cb482010-11-17 21:11:401077 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:021078#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:071079 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:401080 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:161081 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:021082#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:161083
Howard Hinnant9dcdcde2013-06-28 16:59:191084 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:431085 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161086 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1087
Howard Hinnant2d72b1e2010-12-17 14:46:431088 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:471089 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:561090#if _LIBCPP_STD_VER >= 14
1091 _NOEXCEPT;
1092#else
1093 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1094 __is_nothrow_swappable<allocator_type>::value);
1095#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161096
Howard Hinnant2d72b1e2010-12-17 14:46:431097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191098 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:431099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191100 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Marshall Clowf532a702016-03-08 15:44:301101#if _LIBCPP_STD_VER > 14
1102 _LIBCPP_INLINE_VISIBILITY
1103 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1104#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161105
Howard Hinnant2d72b1e2010-12-17 14:46:431106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121107 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:161108
Howard Hinnant2d72b1e2010-12-17 14:46:431109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121110 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:241111 _LIBCPP_INLINE_VISIBILITY
1112 size_type find(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:191113 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:431114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191115 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:121116 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161117
Howard Hinnant2d72b1e2010-12-17 14:46:431118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121119 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:241120 _LIBCPP_INLINE_VISIBILITY
1121 size_type rfind(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:191122 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:431123 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191124 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:121125 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161126
Howard Hinnant2d72b1e2010-12-17 14:46:431127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121128 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:241129 _LIBCPP_INLINE_VISIBILITY
1130 size_type find_first_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:191131 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:431132 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191133 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:431134 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121135 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161136
Howard Hinnant2d72b1e2010-12-17 14:46:431137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121138 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:241139 _LIBCPP_INLINE_VISIBILITY
1140 size_type find_last_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:191141 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:431142 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191143 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:431144 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121145 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161146
Howard Hinnant2d72b1e2010-12-17 14:46:431147 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121148 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:241149 _LIBCPP_INLINE_VISIBILITY
1150 size_type find_first_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:191151 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:121152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191153 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:121154 _LIBCPP_INLINE_VISIBILITY
1155 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1156
1157 _LIBCPP_INLINE_VISIBILITY
1158 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:241159 _LIBCPP_INLINE_VISIBILITY
1160 size_type find_last_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:191161 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:121162 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191163 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:121164 _LIBCPP_INLINE_VISIBILITY
1165 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1166
1167 _LIBCPP_INLINE_VISIBILITY
1168 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:431169 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:241170 int compare(__self_view __sv) const _NOEXCEPT;
1171 _LIBCPP_INLINE_VISIBILITY
1172 int compare(size_type __pos1, size_type __n1, __self_view __sv) const;
1173 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161174 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:191175 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:421176 template <class _Tp>
Eric Fiselier9dbc0532016-10-14 05:29:461177 inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow6ac8de02016-09-24 22:45:421178 typename enable_if
1179 <
1180 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1181 int
1182 >::type
1183 compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:191184 int compare(const value_type* __s) const _NOEXCEPT;
1185 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1186 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:161187
Howard Hinnant2d72b1e2010-12-17 14:46:431188 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:131189
1190 _LIBCPP_INLINE_VISIBILITY
1191 bool __is_long() const _NOEXCEPT
1192 {return bool(__r_.first().__s.__size_ & __short_mask);}
1193
Howard Hinnant499cea12013-08-23 17:37:051194#if _LIBCPP_DEBUG_LEVEL >= 2
1195
1196 bool __dereferenceable(const const_iterator* __i) const;
1197 bool __decrementable(const const_iterator* __i) const;
1198 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1199 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1200
1201#endif // _LIBCPP_DEBUG_LEVEL >= 2
1202
Howard Hinnantbc8d3f92010-05-11 19:42:161203private:
Howard Hinnanta6119a82011-05-29 19:57:121204 _LIBCPP_INLINE_VISIBILITY
1205 allocator_type& __alloc() _NOEXCEPT
1206 {return __r_.second();}
1207 _LIBCPP_INLINE_VISIBILITY
1208 const allocator_type& __alloc() const _NOEXCEPT
1209 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:161210
Evgeniy Stepanov4f01aa82015-10-13 23:48:281211#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:481212
Howard Hinnanta6119a82011-05-29 19:57:121213 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121214 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:481215# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:161216 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:481217# else
1218 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1219# endif
1220
Howard Hinnanta6119a82011-05-29 19:57:121221 _LIBCPP_INLINE_VISIBILITY
1222 size_type __get_short_size() const _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:481223# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:161224 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:481225# else
1226 {return __r_.first().__s.__size_;}
1227# endif
1228
Evgeniy Stepanov4f01aa82015-10-13 23:48:281229#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:481230
1231 _LIBCPP_INLINE_VISIBILITY
1232 void __set_short_size(size_type __s) _NOEXCEPT
1233# if _LIBCPP_BIG_ENDIAN
1234 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1235# else
1236 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1237# endif
1238
1239 _LIBCPP_INLINE_VISIBILITY
1240 size_type __get_short_size() const _NOEXCEPT
1241# if _LIBCPP_BIG_ENDIAN
1242 {return __r_.first().__s.__size_;}
1243# else
1244 {return __r_.first().__s.__size_ >> 1;}
1245# endif
1246
Evgeniy Stepanov4f01aa82015-10-13 23:48:281247#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:481248
Howard Hinnanta6119a82011-05-29 19:57:121249 _LIBCPP_INLINE_VISIBILITY
1250 void __set_long_size(size_type __s) _NOEXCEPT
1251 {__r_.first().__l.__size_ = __s;}
1252 _LIBCPP_INLINE_VISIBILITY
1253 size_type __get_long_size() const _NOEXCEPT
1254 {return __r_.first().__l.__size_;}
1255 _LIBCPP_INLINE_VISIBILITY
1256 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161257 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1258
Howard Hinnanta6119a82011-05-29 19:57:121259 _LIBCPP_INLINE_VISIBILITY
1260 void __set_long_cap(size_type __s) _NOEXCEPT
1261 {__r_.first().__l.__cap_ = __long_mask | __s;}
1262 _LIBCPP_INLINE_VISIBILITY
1263 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:041264 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:161265
Howard Hinnanta6119a82011-05-29 19:57:121266 _LIBCPP_INLINE_VISIBILITY
1267 void __set_long_pointer(pointer __p) _NOEXCEPT
1268 {__r_.first().__l.__data_ = __p;}
1269 _LIBCPP_INLINE_VISIBILITY
1270 pointer __get_long_pointer() _NOEXCEPT
1271 {return __r_.first().__l.__data_;}
1272 _LIBCPP_INLINE_VISIBILITY
1273 const_pointer __get_long_pointer() const _NOEXCEPT
1274 {return __r_.first().__l.__data_;}
1275 _LIBCPP_INLINE_VISIBILITY
1276 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:191277 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:121278 _LIBCPP_INLINE_VISIBILITY
1279 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:191280 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:121281 _LIBCPP_INLINE_VISIBILITY
1282 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161283 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:121284 _LIBCPP_INLINE_VISIBILITY
1285 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161286 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1287
Howard Hinnanta6119a82011-05-29 19:57:121288 _LIBCPP_INLINE_VISIBILITY
1289 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161290 {
1291 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1292 for (unsigned __i = 0; __i < __n_words; ++__i)
1293 __a[__i] = 0;
1294 }
1295
1296 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:121297 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:201298 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:421299 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:161300 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:121301 static _LIBCPP_INLINE_VISIBILITY
1302 size_type __recommend(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:421303 {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
Howard Hinnant7f764502013-08-14 18:00:201304 __align_it<sizeof(value_type) < __alignment ?
Howard Hinnanta6119a82011-05-29 19:57:121305 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:161306
Eric Fiselier6dbed462016-09-16 00:00:481307 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191308 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Eric Fiselier6dbed462016-09-16 00:00:481309 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191310 void __init(const value_type* __s, size_type __sz);
Eric Fiselier6dbed462016-09-16 00:00:481311 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161312 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:431313
Howard Hinnantbc8d3f92010-05-11 19:42:161314 template <class _InputIterator>
Eric Fiselier6dbed462016-09-16 00:00:481315 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161316 typename enable_if
1317 <
Marshall Clowdf9db312016-01-13 21:54:341318 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161319 void
1320 >::type
1321 __init(_InputIterator __first, _InputIterator __last);
1322
1323 template <class _ForwardIterator>
Eric Fiselier6dbed462016-09-16 00:00:481324 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161325 typename enable_if
1326 <
1327 __is_forward_iterator<_ForwardIterator>::value,
1328 void
1329 >::type
1330 __init(_ForwardIterator __first, _ForwardIterator __last);
1331
1332 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:431333 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:161334 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1335 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:191336 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:161337
Howard Hinnant2d72b1e2010-12-17 14:46:431338 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161339 void __erase_to_end(size_type __pos);
1340
Howard Hinnante32b5e22010-11-17 17:55:081341 _LIBCPP_INLINE_VISIBILITY
1342 void __copy_assign_alloc(const basic_string& __str)
1343 {__copy_assign_alloc(__str, integral_constant<bool,
1344 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1345
1346 _LIBCPP_INLINE_VISIBILITY
1347 void __copy_assign_alloc(const basic_string& __str, true_type)
1348 {
1349 if (__alloc() != __str.__alloc())
1350 {
1351 clear();
1352 shrink_to_fit();
1353 }
1354 __alloc() = __str.__alloc();
1355 }
1356
1357 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:041358 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:081359 {}
1360
1361#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:431362 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:001363 void __move_assign(basic_string& __str, false_type)
1364 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:431365 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:471366 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:001367#if _LIBCPP_STD_VER > 14
1368 _NOEXCEPT;
1369#else
Howard Hinnant53f7d4c2011-06-03 18:40:471370 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:081371#endif
Marshall Clowaf961ed2015-08-18 18:57:001372#endif
Howard Hinnante32b5e22010-11-17 17:55:081373
1374 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:181375 void
Howard Hinnant9cbee432011-09-02 20:42:311376 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:181377 _NOEXCEPT_(
1378 !__alloc_traits::propagate_on_container_move_assignment::value ||
1379 is_nothrow_move_assignable<allocator_type>::value)
1380 {__move_assign_alloc(__str, integral_constant<bool,
1381 __alloc_traits::propagate_on_container_move_assignment::value>());}
1382
1383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:311384 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:181385 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1386 {
1387 __alloc() = _VSTD::move(__c.__alloc());
1388 }
1389
1390 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:041391 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:181392 _NOEXCEPT
1393 {}
1394
Howard Hinnant2d72b1e2010-12-17 14:46:431395 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1396 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:161397
1398 friend basic_string operator+<>(const basic_string&, const basic_string&);
1399 friend basic_string operator+<>(const value_type*, const basic_string&);
1400 friend basic_string operator+<>(value_type, const basic_string&);
1401 friend basic_string operator+<>(const basic_string&, const value_type*);
1402 friend basic_string operator+<>(const basic_string&, value_type);
1403};
1404
1405template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001406inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161407void
1408basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1409{
Howard Hinnant499cea12013-08-23 17:37:051410#if _LIBCPP_DEBUG_LEVEL >= 2
1411 __get_db()->__invalidate_all(this);
1412#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:161413}
1414
1415template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001416inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161417void
Howard Hinnantec3773c2011-12-01 20:21:041418basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:051419#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:041420 __pos
1421#endif
1422 )
Howard Hinnantbc8d3f92010-05-11 19:42:161423{
Howard Hinnant499cea12013-08-23 17:37:051424#if _LIBCPP_DEBUG_LEVEL >= 2
1425 __c_node* __c = __get_db()->__find_c_and_lock(this);
1426 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:161427 {
Howard Hinnant499cea12013-08-23 17:37:051428 const_pointer __new_last = __get_pointer() + __pos;
1429 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:161430 {
Howard Hinnant499cea12013-08-23 17:37:051431 --__p;
1432 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1433 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:161434 {
Howard Hinnant499cea12013-08-23 17:37:051435 (*__p)->__c_ = nullptr;
1436 if (--__c->end_ != __p)
1437 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:161438 }
Howard Hinnantbc8d3f92010-05-11 19:42:161439 }
Howard Hinnant499cea12013-08-23 17:37:051440 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:161441 }
Howard Hinnant499cea12013-08-23 17:37:051442#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:161443}
1444
1445template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001446inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:471447basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:411448 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161449{
Howard Hinnant499cea12013-08-23 17:37:051450#if _LIBCPP_DEBUG_LEVEL >= 2
1451 __get_db()->__insert_c(this);
1452#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161453 __zero();
1454}
1455
1456template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001457inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161458basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:461459#if _LIBCPP_STD_VER <= 14
1460 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1461#else
1462 _NOEXCEPT
1463#endif
1464: __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:161465{
Howard Hinnant499cea12013-08-23 17:37:051466#if _LIBCPP_DEBUG_LEVEL >= 2
1467 __get_db()->__insert_c(this);
1468#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161469 __zero();
1470}
1471
1472template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier6dbed462016-09-16 00:00:481473void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1474 size_type __sz,
1475 size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:161476{
1477 if (__reserve > max_size())
1478 this->__throw_length_error();
1479 pointer __p;
1480 if (__reserve < __min_cap)
1481 {
1482 __set_short_size(__sz);
1483 __p = __get_short_pointer();
1484 }
1485 else
1486 {
1487 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:081488 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161489 __set_long_pointer(__p);
1490 __set_long_cap(__cap+1);
1491 __set_long_size(__sz);
1492 }
Howard Hinnant9dcdcde2013-06-28 16:59:191493 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:161494 traits_type::assign(__p[__sz], value_type());
1495}
1496
1497template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161498void
Howard Hinnant9dcdcde2013-06-28 16:59:191499basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:161500{
1501 if (__sz > max_size())
1502 this->__throw_length_error();
1503 pointer __p;
1504 if (__sz < __min_cap)
1505 {
1506 __set_short_size(__sz);
1507 __p = __get_short_pointer();
1508 }
1509 else
1510 {
1511 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:081512 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161513 __set_long_pointer(__p);
1514 __set_long_cap(__cap+1);
1515 __set_long_size(__sz);
1516 }
Howard Hinnant9dcdcde2013-06-28 16:59:191517 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:161518 traits_type::assign(__p[__sz], value_type());
1519}
1520
1521template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001522inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191523basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:161524{
Howard Hinnant499cea12013-08-23 17:37:051525 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:161526 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:051527#if _LIBCPP_DEBUG_LEVEL >= 2
1528 __get_db()->__insert_c(this);
1529#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161530}
1531
1532template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001533inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191534basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:161535 : __r_(__a)
1536{
Howard Hinnant499cea12013-08-23 17:37:051537 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:161538 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:051539#if _LIBCPP_DEBUG_LEVEL >= 2
1540 __get_db()->__insert_c(this);
1541#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161542}
1543
1544template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001545inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191546basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:161547{
Howard Hinnant499cea12013-08-23 17:37:051548 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:161549 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:051550#if _LIBCPP_DEBUG_LEVEL >= 2
1551 __get_db()->__insert_c(this);
1552#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161553}
1554
1555template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001556inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191557basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:161558 : __r_(__a)
1559{
Howard Hinnant499cea12013-08-23 17:37:051560 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:161561 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:051562#if _LIBCPP_DEBUG_LEVEL >= 2
1563 __get_db()->__insert_c(this);
1564#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161565}
1566
1567template <class _CharT, class _Traits, class _Allocator>
1568basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:081569 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:161570{
1571 if (!__str.__is_long())
1572 __r_.first().__r = __str.__r_.first().__r;
1573 else
Howard Hinnant9dcdcde2013-06-28 16:59:191574 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:051575#if _LIBCPP_DEBUG_LEVEL >= 2
1576 __get_db()->__insert_c(this);
1577#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161578}
1579
1580template <class _CharT, class _Traits, class _Allocator>
1581basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
1582 : __r_(__a)
1583{
1584 if (!__str.__is_long())
1585 __r_.first().__r = __str.__r_.first().__r;
1586 else
Howard Hinnant9dcdcde2013-06-28 16:59:191587 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:051588#if _LIBCPP_DEBUG_LEVEL >= 2
1589 __get_db()->__insert_c(this);
1590#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161591}
1592
Howard Hinnant73d21a42010-09-04 23:28:191593#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161594
1595template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001596inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:471597basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:431598#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:471599 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:431600#else
1601 _NOEXCEPT
1602#endif
Howard Hinnant0949eed2011-06-30 21:18:191603 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:161604{
1605 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:051606#if _LIBCPP_DEBUG_LEVEL >= 2
1607 __get_db()->__insert_c(this);
1608 if (__is_long())
1609 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:161610#endif
1611}
1612
1613template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001614inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161615basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:081616 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:161617{
Marshall Clowd5549cc2014-07-17 15:32:201618 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:191619 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:201620 else
1621 {
1622 __r_.first().__r = __str.__r_.first().__r;
1623 __str.__zero();
1624 }
Howard Hinnant499cea12013-08-23 17:37:051625#if _LIBCPP_DEBUG_LEVEL >= 2
1626 __get_db()->__insert_c(this);
1627 if (__is_long())
1628 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:161629#endif
1630}
1631
Howard Hinnant73d21a42010-09-04 23:28:191632#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161633
1634template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161635void
1636basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1637{
1638 if (__n > max_size())
1639 this->__throw_length_error();
1640 pointer __p;
1641 if (__n < __min_cap)
1642 {
1643 __set_short_size(__n);
1644 __p = __get_short_pointer();
1645 }
1646 else
1647 {
1648 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:081649 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161650 __set_long_pointer(__p);
1651 __set_long_cap(__cap+1);
1652 __set_long_size(__n);
1653 }
Howard Hinnant9dcdcde2013-06-28 16:59:191654 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:161655 traits_type::assign(__p[__n], value_type());
1656}
1657
1658template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001659inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161660basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
1661{
1662 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:051663#if _LIBCPP_DEBUG_LEVEL >= 2
1664 __get_db()->__insert_c(this);
1665#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161666}
1667
1668template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001669inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161670basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
1671 : __r_(__a)
1672{
1673 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:051674#if _LIBCPP_DEBUG_LEVEL >= 2
1675 __get_db()->__insert_c(this);
1676#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161677}
1678
Howard Hinnantbc8d3f92010-05-11 19:42:161679template <class _CharT, class _Traits, class _Allocator>
1680basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
1681 const allocator_type& __a)
1682 : __r_(__a)
1683{
1684 size_type __str_sz = __str.size();
1685 if (__pos > __str_sz)
1686 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:191687 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:051688#if _LIBCPP_DEBUG_LEVEL >= 2
1689 __get_db()->__insert_c(this);
1690#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161691}
1692
1693template <class _CharT, class _Traits, class _Allocator>
Marshall Clowf4f7d8f2016-04-07 18:13:411694inline _LIBCPP_INLINE_VISIBILITY
1695basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
1696 const allocator_type& __a)
1697 : __r_(__a)
1698{
1699 size_type __str_sz = __str.size();
1700 if (__pos > __str_sz)
1701 this->__throw_out_of_range();
1702 __init(__str.data() + __pos, __str_sz - __pos);
1703#if _LIBCPP_DEBUG_LEVEL >= 2
1704 __get_db()->__insert_c(this);
1705#endif
1706}
1707
1708template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:241709inline _LIBCPP_INLINE_VISIBILITY
1710basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv)
1711{
1712 __init(__sv.data(), __sv.size());
1713#if _LIBCPP_DEBUG_LEVEL >= 2
1714 __get_db()->__insert_c(this);
1715#endif
1716}
1717
1718template <class _CharT, class _Traits, class _Allocator>
1719inline _LIBCPP_INLINE_VISIBILITY
1720basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const allocator_type& __a)
1721 : __r_(__a)
1722{
1723 __init(__sv.data(), __sv.size());
1724#if _LIBCPP_DEBUG_LEVEL >= 2
1725 __get_db()->__insert_c(this);
1726#endif
1727}
1728
1729template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161730template <class _InputIterator>
Howard Hinnantbc8d3f92010-05-11 19:42:161731typename enable_if
1732<
Marshall Clowdf9db312016-01-13 21:54:341733 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161734 void
1735>::type
1736basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
1737{
1738 __zero();
1739#ifndef _LIBCPP_NO_EXCEPTIONS
1740 try
1741 {
Howard Hinnant324bb032010-08-22 00:02:431742#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161743 for (; __first != __last; ++__first)
1744 push_back(*__first);
1745#ifndef _LIBCPP_NO_EXCEPTIONS
1746 }
1747 catch (...)
1748 {
1749 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:081750 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:161751 throw;
1752 }
Howard Hinnant324bb032010-08-22 00:02:431753#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161754}
1755
1756template <class _CharT, class _Traits, class _Allocator>
1757template <class _ForwardIterator>
Howard Hinnantbc8d3f92010-05-11 19:42:161758typename enable_if
1759<
1760 __is_forward_iterator<_ForwardIterator>::value,
1761 void
1762>::type
1763basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
1764{
Howard Hinnant0949eed2011-06-30 21:18:191765 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:161766 if (__sz > max_size())
1767 this->__throw_length_error();
1768 pointer __p;
1769 if (__sz < __min_cap)
1770 {
1771 __set_short_size(__sz);
1772 __p = __get_short_pointer();
1773 }
1774 else
1775 {
1776 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:081777 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161778 __set_long_pointer(__p);
1779 __set_long_cap(__cap+1);
1780 __set_long_size(__sz);
1781 }
Eric Fiselierb9919752014-10-27 19:28:201782 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:161783 traits_type::assign(*__p, *__first);
1784 traits_type::assign(*__p, value_type());
1785}
1786
1787template <class _CharT, class _Traits, class _Allocator>
1788template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:001789inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161790basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
1791{
1792 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:051793#if _LIBCPP_DEBUG_LEVEL >= 2
1794 __get_db()->__insert_c(this);
1795#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161796}
1797
1798template <class _CharT, class _Traits, class _Allocator>
1799template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:001800inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161801basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
1802 const allocator_type& __a)
1803 : __r_(__a)
1804{
1805 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:051806#if _LIBCPP_DEBUG_LEVEL >= 2
1807 __get_db()->__insert_c(this);
1808#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161809}
1810
Howard Hinnante3e32912011-08-12 21:56:021811#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1812
Howard Hinnantbc8d3f92010-05-11 19:42:161813template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001814inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161815basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
1816{
1817 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:051818#if _LIBCPP_DEBUG_LEVEL >= 2
1819 __get_db()->__insert_c(this);
1820#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161821}
1822
1823template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001824inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161825basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
1826 : __r_(__a)
1827{
1828 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:051829#if _LIBCPP_DEBUG_LEVEL >= 2
1830 __get_db()->__insert_c(this);
1831#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161832}
1833
Howard Hinnante3e32912011-08-12 21:56:021834#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1835
Howard Hinnantbc8d3f92010-05-11 19:42:161836template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161837basic_string<_CharT, _Traits, _Allocator>::~basic_string()
1838{
Howard Hinnant499cea12013-08-23 17:37:051839#if _LIBCPP_DEBUG_LEVEL >= 2
1840 __get_db()->__erase_c(this);
1841#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161842 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:081843 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:161844}
1845
1846template <class _CharT, class _Traits, class _Allocator>
1847void
1848basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
1849 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:191850 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
Howard Hinnantbc8d3f92010-05-11 19:42:161851{
1852 size_type __ms = max_size();
1853 if (__delta_cap > __ms - __old_cap - 1)
1854 this->__throw_length_error();
1855 pointer __old_p = __get_pointer();
1856 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:191857 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:161858 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:081859 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161860 __invalidate_all_iterators();
1861 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:191862 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1863 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:161864 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:191865 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:161866 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1867 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:191868 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1869 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:161870 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:081871 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161872 __set_long_pointer(__p);
1873 __set_long_cap(__cap+1);
1874 __old_sz = __n_copy + __n_add + __sec_cp_sz;
1875 __set_long_size(__old_sz);
1876 traits_type::assign(__p[__old_sz], value_type());
1877}
1878
1879template <class _CharT, class _Traits, class _Allocator>
1880void
1881basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1882 size_type __n_copy, size_type __n_del, size_type __n_add)
1883{
1884 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:381885 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:161886 this->__throw_length_error();
1887 pointer __old_p = __get_pointer();
1888 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:191889 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:161890 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:081891 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161892 __invalidate_all_iterators();
1893 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:191894 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1895 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:161896 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1897 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:191898 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1899 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
1900 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:161901 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:081902 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161903 __set_long_pointer(__p);
1904 __set_long_cap(__cap+1);
1905}
1906
1907// assign
1908
1909template <class _CharT, class _Traits, class _Allocator>
1910basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:191911basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:161912{
Alp Tokerec34c482014-05-15 11:27:391913 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:161914 size_type __cap = capacity();
1915 if (__cap >= __n)
1916 {
Howard Hinnant9dcdcde2013-06-28 16:59:191917 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:161918 traits_type::move(__p, __s, __n);
1919 traits_type::assign(__p[__n], value_type());
1920 __set_size(__n);
1921 __invalidate_iterators_past(__n);
1922 }
1923 else
1924 {
1925 size_type __sz = size();
1926 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
1927 }
1928 return *this;
1929}
1930
1931template <class _CharT, class _Traits, class _Allocator>
1932basic_string<_CharT, _Traits, _Allocator>&
1933basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
1934{
1935 size_type __cap = capacity();
1936 if (__cap < __n)
1937 {
1938 size_type __sz = size();
1939 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
1940 }
1941 else
1942 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:191943 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:161944 traits_type::assign(__p, __n, __c);
1945 traits_type::assign(__p[__n], value_type());
1946 __set_size(__n);
1947 return *this;
1948}
1949
1950template <class _CharT, class _Traits, class _Allocator>
1951basic_string<_CharT, _Traits, _Allocator>&
1952basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
1953{
1954 pointer __p;
1955 if (__is_long())
1956 {
1957 __p = __get_long_pointer();
1958 __set_long_size(1);
1959 }
1960 else
1961 {
1962 __p = __get_short_pointer();
1963 __set_short_size(1);
1964 }
1965 traits_type::assign(*__p, __c);
1966 traits_type::assign(*++__p, value_type());
1967 __invalidate_iterators_past(1);
1968 return *this;
1969}
1970
1971template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:081972basic_string<_CharT, _Traits, _Allocator>&
1973basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
1974{
1975 if (this != &__str)
1976 {
1977 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:291978 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:081979 }
1980 return *this;
1981}
1982
1983#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1984
1985template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001986inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:081987void
1988basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:001989 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:081990{
1991 if (__alloc() != __str.__alloc())
1992 assign(__str);
1993 else
1994 __move_assign(__str, true_type());
1995}
1996
1997template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001998inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:081999void
2000basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:002001#if _LIBCPP_STD_VER > 14
2002 _NOEXCEPT
2003#else
Howard Hinnant53f7d4c2011-06-03 18:40:472004 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:002005#endif
Howard Hinnante32b5e22010-11-17 17:55:082006{
2007 clear();
2008 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:182009 __r_.first() = __str.__r_.first();
2010 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:082011 __str.__zero();
2012}
2013
2014template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002015inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:082016basic_string<_CharT, _Traits, _Allocator>&
2017basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:002018 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:082019{
2020 __move_assign(__str, integral_constant<bool,
2021 __alloc_traits::propagate_on_container_move_assignment::value>());
2022 return *this;
2023}
2024
2025#endif
2026
2027template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:162028template<class _InputIterator>
2029typename enable_if
2030<
Marshall Clowdf9db312016-01-13 21:54:342031 __is_exactly_input_iterator <_InputIterator>::value
2032 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:162033 basic_string<_CharT, _Traits, _Allocator>&
2034>::type
2035basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2036{
Marshall Clowd979eed2016-09-05 01:54:302037 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:342038 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:452039 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:162040}
2041
2042template <class _CharT, class _Traits, class _Allocator>
2043template<class _ForwardIterator>
2044typename enable_if
2045<
Marshall Clowdf9db312016-01-13 21:54:342046 __is_forward_iterator<_ForwardIterator>::value
2047 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:162048 basic_string<_CharT, _Traits, _Allocator>&
2049>::type
2050basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2051{
Howard Hinnant0949eed2011-06-30 21:18:192052 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:162053 size_type __cap = capacity();
2054 if (__cap < __n)
2055 {
2056 size_type __sz = size();
2057 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2058 }
2059 else
2060 __invalidate_iterators_past(__n);
2061 pointer __p = __get_pointer();
2062 for (; __first != __last; ++__first, ++__p)
2063 traits_type::assign(*__p, *__first);
2064 traits_type::assign(*__p, value_type());
2065 __set_size(__n);
2066 return *this;
2067}
2068
2069template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:162070basic_string<_CharT, _Traits, _Allocator>&
2071basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2072{
2073 size_type __sz = __str.size();
2074 if (__pos > __sz)
2075 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:192076 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:162077}
2078
2079template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:422080template <class _Tp>
2081typename enable_if
2082<
2083 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2084basic_string<_CharT, _Traits, _Allocator>&
2085>::type
2086basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:242087{
Marshall Clow6ac8de02016-09-24 22:45:422088 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:242089 size_type __sz = __sv.size();
2090 if (__pos > __sz)
2091 this->__throw_out_of_range();
2092 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2093}
2094
2095
2096template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:162097basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192098basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:162099{
Alp Tokerec34c482014-05-15 11:27:392100 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:162101 return assign(__s, traits_type::length(__s));
2102}
2103
2104// append
2105
2106template <class _CharT, class _Traits, class _Allocator>
2107basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192108basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:162109{
Alp Tokerec34c482014-05-15 11:27:392110 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:162111 size_type __cap = capacity();
2112 size_type __sz = size();
2113 if (__cap - __sz >= __n)
2114 {
2115 if (__n)
2116 {
Howard Hinnant9dcdcde2013-06-28 16:59:192117 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162118 traits_type::copy(__p + __sz, __s, __n);
2119 __sz += __n;
2120 __set_size(__sz);
2121 traits_type::assign(__p[__sz], value_type());
2122 }
2123 }
2124 else
2125 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2126 return *this;
2127}
2128
2129template <class _CharT, class _Traits, class _Allocator>
2130basic_string<_CharT, _Traits, _Allocator>&
2131basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2132{
2133 if (__n)
2134 {
2135 size_type __cap = capacity();
2136 size_type __sz = size();
2137 if (__cap - __sz < __n)
2138 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2139 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:192140 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:162141 __sz += __n;
2142 __set_size(__sz);
2143 traits_type::assign(__p[__sz], value_type());
2144 }
2145 return *this;
2146}
2147
2148template <class _CharT, class _Traits, class _Allocator>
2149void
2150basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2151{
Howard Hinnant15467182013-04-30 21:44:482152 bool __is_short = !__is_long();
2153 size_type __cap;
2154 size_type __sz;
2155 if (__is_short)
2156 {
2157 __cap = __min_cap - 1;
2158 __sz = __get_short_size();
2159 }
2160 else
2161 {
2162 __cap = __get_long_cap() - 1;
2163 __sz = __get_long_size();
2164 }
Howard Hinnantbc8d3f92010-05-11 19:42:162165 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:482166 {
Howard Hinnantbc8d3f92010-05-11 19:42:162167 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:482168 __is_short = !__is_long();
2169 }
2170 pointer __p;
2171 if (__is_short)
2172 {
2173 __p = __get_short_pointer() + __sz;
2174 __set_short_size(__sz+1);
2175 }
2176 else
2177 {
2178 __p = __get_long_pointer() + __sz;
2179 __set_long_size(__sz+1);
2180 }
Howard Hinnantbc8d3f92010-05-11 19:42:162181 traits_type::assign(*__p, __c);
2182 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:162183}
2184
2185template <class _CharT, class _Traits, class _Allocator>
2186template<class _InputIterator>
2187typename enable_if
2188<
Marshall Clowdf9db312016-01-13 21:54:342189 __is_exactly_input_iterator<_InputIterator>::value
2190 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:162191 basic_string<_CharT, _Traits, _Allocator>&
2192>::type
2193basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2194{
Marshall Clowd979eed2016-09-05 01:54:302195 const basic_string __temp (__first, __last, __alloc());
Marshall Clow1e00d6d2016-07-21 05:31:242196 append(__temp.data(), __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:162197 return *this;
2198}
2199
Marshall Clowac655ef2016-09-07 03:32:062200template <class _Tp>
Marshall Clowd979eed2016-09-05 01:54:302201bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2202{
2203 return __first <= __p && __p < __last;
2204}
2205
Marshall Clowac655ef2016-09-07 03:32:062206template <class _Tp1, class _Tp2>
2207bool __ptr_in_range (const _Tp1* __p, const _Tp2* __first, const _Tp2* __last)
2208{
2209 return false;
2210}
2211
Howard Hinnantbc8d3f92010-05-11 19:42:162212template <class _CharT, class _Traits, class _Allocator>
2213template<class _ForwardIterator>
2214typename enable_if
2215<
Marshall Clowdf9db312016-01-13 21:54:342216 __is_forward_iterator<_ForwardIterator>::value
2217 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:162218 basic_string<_CharT, _Traits, _Allocator>&
2219>::type
2220basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2221{
2222 size_type __sz = size();
2223 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:192224 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:162225 if (__n)
2226 {
Marshall Clowd979eed2016-09-05 01:54:302227 if ( __ptr_in_range(&*__first, data(), data() + size()))
2228 {
2229 const basic_string __temp (__first, __last, __alloc());
2230 append(__temp.data(), __temp.size());
2231 }
2232 else
2233 {
2234 if (__cap - __sz < __n)
2235 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2236 pointer __p = __get_pointer() + __sz;
2237 for (; __first != __last; ++__p, ++__first)
2238 traits_type::assign(*__p, *__first);
2239 traits_type::assign(*__p, value_type());
2240 __set_size(__sz + __n);
2241 }
Howard Hinnantbc8d3f92010-05-11 19:42:162242 }
2243 return *this;
2244}
2245
2246template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002247inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162248basic_string<_CharT, _Traits, _Allocator>&
2249basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2250{
2251 return append(__str.data(), __str.size());
2252}
2253
2254template <class _CharT, class _Traits, class _Allocator>
2255basic_string<_CharT, _Traits, _Allocator>&
2256basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2257{
2258 size_type __sz = __str.size();
2259 if (__pos > __sz)
2260 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:192261 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:162262}
2263
2264template <class _CharT, class _Traits, class _Allocator>
Marshall Clow42a87db2016-10-03 23:40:482265template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:422266 typename enable_if
2267 <
2268 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2269 basic_string<_CharT, _Traits, _Allocator>&
2270 >::type
2271basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:242272{
Marshall Clow6ac8de02016-09-24 22:45:422273 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:242274 size_type __sz = __sv.size();
2275 if (__pos > __sz)
2276 this->__throw_out_of_range();
2277 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2278}
2279
2280template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:162281basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192282basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:162283{
Alp Tokerec34c482014-05-15 11:27:392284 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:162285 return append(__s, traits_type::length(__s));
2286}
2287
2288// insert
2289
2290template <class _CharT, class _Traits, class _Allocator>
2291basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192292basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:162293{
Alp Tokerec34c482014-05-15 11:27:392294 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:162295 size_type __sz = size();
2296 if (__pos > __sz)
2297 this->__throw_out_of_range();
2298 size_type __cap = capacity();
2299 if (__cap - __sz >= __n)
2300 {
2301 if (__n)
2302 {
Howard Hinnant9dcdcde2013-06-28 16:59:192303 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162304 size_type __n_move = __sz - __pos;
2305 if (__n_move != 0)
2306 {
2307 if (__p + __pos <= __s && __s < __p + __sz)
2308 __s += __n;
2309 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2310 }
2311 traits_type::move(__p + __pos, __s, __n);
2312 __sz += __n;
2313 __set_size(__sz);
2314 traits_type::assign(__p[__sz], value_type());
2315 }
2316 }
2317 else
2318 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2319 return *this;
2320}
2321
2322template <class _CharT, class _Traits, class _Allocator>
2323basic_string<_CharT, _Traits, _Allocator>&
2324basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2325{
2326 size_type __sz = size();
2327 if (__pos > __sz)
2328 this->__throw_out_of_range();
2329 if (__n)
2330 {
2331 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:192332 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:162333 if (__cap - __sz >= __n)
2334 {
Howard Hinnant9dcdcde2013-06-28 16:59:192335 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162336 size_type __n_move = __sz - __pos;
2337 if (__n_move != 0)
2338 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2339 }
2340 else
2341 {
2342 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:192343 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162344 }
2345 traits_type::assign(__p + __pos, __n, __c);
2346 __sz += __n;
2347 __set_size(__sz);
2348 traits_type::assign(__p[__sz], value_type());
2349 }
2350 return *this;
2351}
2352
2353template <class _CharT, class _Traits, class _Allocator>
2354template<class _InputIterator>
2355typename enable_if
2356<
Marshall Clowdf9db312016-01-13 21:54:342357 __is_exactly_input_iterator<_InputIterator>::value
2358 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2359 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:162360>::type
2361basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2362{
Howard Hinnant499cea12013-08-23 17:37:052363#if _LIBCPP_DEBUG_LEVEL >= 2
2364 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2365 "string::insert(iterator, range) called with an iterator not"
2366 " referring to this string");
2367#endif
Marshall Clowd979eed2016-09-05 01:54:302368 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:342369 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:162370}
2371
2372template <class _CharT, class _Traits, class _Allocator>
2373template<class _ForwardIterator>
2374typename enable_if
2375<
Marshall Clowdf9db312016-01-13 21:54:342376 __is_forward_iterator<_ForwardIterator>::value
2377 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:162378 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2379>::type
2380basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2381{
Howard Hinnant499cea12013-08-23 17:37:052382#if _LIBCPP_DEBUG_LEVEL >= 2
2383 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2384 "string::insert(iterator, range) called with an iterator not"
2385 " referring to this string");
2386#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162387 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnant0949eed2011-06-30 21:18:192388 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:162389 if (__n)
2390 {
Marshall Clowd979eed2016-09-05 01:54:302391 if ( __ptr_in_range(&*__first, data(), data() + size()))
2392 {
2393 const basic_string __temp(__first, __last, __alloc());
2394 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2395 }
2396
2397 size_type __sz = size();
2398 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:192399 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:162400 if (__cap - __sz >= __n)
2401 {
Howard Hinnant9dcdcde2013-06-28 16:59:192402 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162403 size_type __n_move = __sz - __ip;
2404 if (__n_move != 0)
2405 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2406 }
2407 else
2408 {
2409 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:192410 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162411 }
2412 __sz += __n;
2413 __set_size(__sz);
2414 traits_type::assign(__p[__sz], value_type());
2415 for (__p += __ip; __first != __last; ++__p, ++__first)
2416 traits_type::assign(*__p, *__first);
2417 }
2418 return begin() + __ip;
2419}
2420
2421template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002422inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162423basic_string<_CharT, _Traits, _Allocator>&
2424basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2425{
2426 return insert(__pos1, __str.data(), __str.size());
2427}
2428
2429template <class _CharT, class _Traits, class _Allocator>
2430basic_string<_CharT, _Traits, _Allocator>&
2431basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2432 size_type __pos2, size_type __n)
2433{
2434 size_type __str_sz = __str.size();
2435 if (__pos2 > __str_sz)
2436 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:192437 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:162438}
2439
2440template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:422441template <class _Tp>
2442typename enable_if
2443<
2444 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2445basic_string<_CharT, _Traits, _Allocator>&
2446>::type
2447basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:242448 size_type __pos2, size_type __n)
2449{
Marshall Clow6ac8de02016-09-24 22:45:422450 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:242451 size_type __str_sz = __sv.size();
2452 if (__pos2 > __str_sz)
2453 this->__throw_out_of_range();
2454 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2455}
2456
2457template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:162458basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192459basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:162460{
Alp Tokerec34c482014-05-15 11:27:392461 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:162462 return insert(__pos, __s, traits_type::length(__s));
2463}
2464
2465template <class _CharT, class _Traits, class _Allocator>
2466typename basic_string<_CharT, _Traits, _Allocator>::iterator
2467basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2468{
2469 size_type __ip = static_cast<size_type>(__pos - begin());
2470 size_type __sz = size();
2471 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:192472 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:162473 if (__cap == __sz)
2474 {
2475 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:192476 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162477 }
2478 else
2479 {
Howard Hinnant9dcdcde2013-06-28 16:59:192480 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162481 size_type __n_move = __sz - __ip;
2482 if (__n_move != 0)
2483 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2484 }
2485 traits_type::assign(__p[__ip], __c);
2486 traits_type::assign(__p[++__sz], value_type());
2487 __set_size(__sz);
2488 return begin() + static_cast<difference_type>(__ip);
2489}
2490
2491template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002492inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162493typename basic_string<_CharT, _Traits, _Allocator>::iterator
2494basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2495{
Howard Hinnant499cea12013-08-23 17:37:052496#if _LIBCPP_DEBUG_LEVEL >= 2
2497 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2498 "string::insert(iterator, n, value) called with an iterator not"
2499 " referring to this string");
2500#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162501 difference_type __p = __pos - begin();
2502 insert(static_cast<size_type>(__p), __n, __c);
2503 return begin() + __p;
2504}
2505
2506// replace
2507
2508template <class _CharT, class _Traits, class _Allocator>
2509basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192510basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
Howard Hinnantbc8d3f92010-05-11 19:42:162511{
Alp Tokerec34c482014-05-15 11:27:392512 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:162513 size_type __sz = size();
2514 if (__pos > __sz)
2515 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:192516 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:162517 size_type __cap = capacity();
2518 if (__cap - __sz + __n1 >= __n2)
2519 {
Howard Hinnant9dcdcde2013-06-28 16:59:192520 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162521 if (__n1 != __n2)
2522 {
2523 size_type __n_move = __sz - __pos - __n1;
2524 if (__n_move != 0)
2525 {
2526 if (__n1 > __n2)
2527 {
2528 traits_type::move(__p + __pos, __s, __n2);
2529 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2530 goto __finish;
2531 }
2532 if (__p + __pos < __s && __s < __p + __sz)
2533 {
2534 if (__p + __pos + __n1 <= __s)
2535 __s += __n2 - __n1;
2536 else // __p + __pos < __s < __p + __pos + __n1
2537 {
2538 traits_type::move(__p + __pos, __s, __n1);
2539 __pos += __n1;
2540 __s += __n2;
2541 __n2 -= __n1;
2542 __n1 = 0;
2543 }
2544 }
2545 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2546 }
2547 }
2548 traits_type::move(__p + __pos, __s, __n2);
2549__finish:
2550 __sz += __n2 - __n1;
2551 __set_size(__sz);
2552 __invalidate_iterators_past(__sz);
2553 traits_type::assign(__p[__sz], value_type());
2554 }
2555 else
2556 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2557 return *this;
2558}
2559
2560template <class _CharT, class _Traits, class _Allocator>
2561basic_string<_CharT, _Traits, _Allocator>&
2562basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2563{
2564 size_type __sz = size();
2565 if (__pos > __sz)
2566 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:192567 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:162568 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:192569 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:162570 if (__cap - __sz + __n1 >= __n2)
2571 {
Howard Hinnant9dcdcde2013-06-28 16:59:192572 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162573 if (__n1 != __n2)
2574 {
2575 size_type __n_move = __sz - __pos - __n1;
2576 if (__n_move != 0)
2577 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2578 }
2579 }
2580 else
2581 {
2582 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:192583 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162584 }
2585 traits_type::assign(__p + __pos, __n2, __c);
2586 __sz += __n2 - __n1;
2587 __set_size(__sz);
2588 __invalidate_iterators_past(__sz);
2589 traits_type::assign(__p[__sz], value_type());
2590 return *this;
2591}
2592
2593template <class _CharT, class _Traits, class _Allocator>
2594template<class _InputIterator>
2595typename enable_if
2596<
2597 __is_input_iterator<_InputIterator>::value,
2598 basic_string<_CharT, _Traits, _Allocator>&
2599>::type
Howard Hinnant7b2cb482010-11-17 21:11:402600basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:162601 _InputIterator __j1, _InputIterator __j2)
2602{
Marshall Clowd979eed2016-09-05 01:54:302603 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clowdf9db312016-01-13 21:54:342604 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:162605}
2606
2607template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002608inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162609basic_string<_CharT, _Traits, _Allocator>&
2610basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2611{
2612 return replace(__pos1, __n1, __str.data(), __str.size());
2613}
2614
2615template <class _CharT, class _Traits, class _Allocator>
2616basic_string<_CharT, _Traits, _Allocator>&
2617basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2618 size_type __pos2, size_type __n2)
2619{
2620 size_type __str_sz = __str.size();
2621 if (__pos2 > __str_sz)
2622 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:192623 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:162624}
2625
2626template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:422627template <class _Tp>
2628typename enable_if
2629<
2630__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2631basic_string<_CharT, _Traits, _Allocator>&
2632>::type
2633basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:242634 size_type __pos2, size_type __n2)
2635{
Marshall Clow6ac8de02016-09-24 22:45:422636 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:242637 size_type __str_sz = __sv.size();
2638 if (__pos2 > __str_sz)
2639 this->__throw_out_of_range();
2640 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2641}
2642
2643template <class _CharT, class _Traits, class _Allocator>
2644basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192645basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:162646{
Alp Tokerec34c482014-05-15 11:27:392647 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:162648 return replace(__pos, __n1, __s, traits_type::length(__s));
2649}
2650
2651template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002652inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162653basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:402654basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:162655{
2656 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2657 __str.data(), __str.size());
2658}
2659
2660template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002661inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162662basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192663basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:162664{
2665 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2666}
2667
2668template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002669inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162670basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192671basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:162672{
2673 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2674}
2675
2676template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002677inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162678basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:402679basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:162680{
2681 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2682}
2683
2684// erase
2685
2686template <class _CharT, class _Traits, class _Allocator>
2687basic_string<_CharT, _Traits, _Allocator>&
2688basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2689{
2690 size_type __sz = size();
2691 if (__pos > __sz)
2692 this->__throw_out_of_range();
2693 if (__n)
2694 {
Howard Hinnant9dcdcde2013-06-28 16:59:192695 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:192696 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:162697 size_type __n_move = __sz - __pos - __n;
2698 if (__n_move != 0)
2699 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2700 __sz -= __n;
2701 __set_size(__sz);
2702 __invalidate_iterators_past(__sz);
2703 traits_type::assign(__p[__sz], value_type());
2704 }
2705 return *this;
2706}
2707
2708template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002709inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162710typename basic_string<_CharT, _Traits, _Allocator>::iterator
2711basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2712{
Howard Hinnant499cea12013-08-23 17:37:052713#if _LIBCPP_DEBUG_LEVEL >= 2
2714 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2715 "string::erase(iterator) called with an iterator not"
2716 " referring to this string");
2717#endif
2718 _LIBCPP_ASSERT(__pos != end(),
2719 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:162720 iterator __b = begin();
2721 size_type __r = static_cast<size_type>(__pos - __b);
2722 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:042723 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:162724}
2725
2726template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002727inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162728typename basic_string<_CharT, _Traits, _Allocator>::iterator
2729basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2730{
Howard Hinnant499cea12013-08-23 17:37:052731#if _LIBCPP_DEBUG_LEVEL >= 2
2732 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2733 "string::erase(iterator, iterator) called with an iterator not"
2734 " referring to this string");
2735#endif
2736 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:162737 iterator __b = begin();
2738 size_type __r = static_cast<size_type>(__first - __b);
2739 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:042740 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:162741}
2742
2743template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002744inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162745void
2746basic_string<_CharT, _Traits, _Allocator>::pop_back()
2747{
Howard Hinnant499cea12013-08-23 17:37:052748 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:162749 size_type __sz;
2750 if (__is_long())
2751 {
2752 __sz = __get_long_size() - 1;
2753 __set_long_size(__sz);
2754 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2755 }
2756 else
2757 {
2758 __sz = __get_short_size() - 1;
2759 __set_short_size(__sz);
2760 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2761 }
2762 __invalidate_iterators_past(__sz);
2763}
2764
2765template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002766inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162767void
Howard Hinnanta6119a82011-05-29 19:57:122768basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162769{
2770 __invalidate_all_iterators();
2771 if (__is_long())
2772 {
2773 traits_type::assign(*__get_long_pointer(), value_type());
2774 __set_long_size(0);
2775 }
2776 else
2777 {
2778 traits_type::assign(*__get_short_pointer(), value_type());
2779 __set_short_size(0);
2780 }
2781}
2782
2783template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002784inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162785void
2786basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2787{
2788 if (__is_long())
2789 {
2790 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2791 __set_long_size(__pos);
2792 }
2793 else
2794 {
2795 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2796 __set_short_size(__pos);
2797 }
2798 __invalidate_iterators_past(__pos);
2799}
2800
2801template <class _CharT, class _Traits, class _Allocator>
2802void
2803basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2804{
2805 size_type __sz = size();
2806 if (__n > __sz)
2807 append(__n - __sz, __c);
2808 else
2809 __erase_to_end(__n);
2810}
2811
2812template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002813inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162814typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:122815basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162816{
Howard Hinnante32b5e22010-11-17 17:55:082817 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:162818#if _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:082819 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:162820#else
Marshall Clow09f85502013-10-31 17:23:082821 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:162822#endif
2823}
2824
2825template <class _CharT, class _Traits, class _Allocator>
2826void
2827basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2828{
2829 if (__res_arg > max_size())
2830 this->__throw_length_error();
2831 size_type __cap = capacity();
2832 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:192833 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:162834 __res_arg = __recommend(__res_arg);
2835 if (__res_arg != __cap)
2836 {
2837 pointer __new_data, __p;
2838 bool __was_long, __now_long;
2839 if (__res_arg == __min_cap - 1)
2840 {
2841 __was_long = true;
2842 __now_long = false;
2843 __new_data = __get_short_pointer();
2844 __p = __get_long_pointer();
2845 }
2846 else
2847 {
2848 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:082849 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:162850 else
2851 {
2852 #ifndef _LIBCPP_NO_EXCEPTIONS
2853 try
2854 {
Howard Hinnant324bb032010-08-22 00:02:432855 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:082856 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:162857 #ifndef _LIBCPP_NO_EXCEPTIONS
2858 }
2859 catch (...)
2860 {
2861 return;
2862 }
Howard Hinnant324bb032010-08-22 00:02:432863 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:192864 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:162865 return;
Howard Hinnant324bb032010-08-22 00:02:432866 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:162867 }
2868 __now_long = true;
2869 __was_long = __is_long();
2870 __p = __get_pointer();
2871 }
Howard Hinnant9dcdcde2013-06-28 16:59:192872 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
2873 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:162874 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:082875 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:162876 if (__now_long)
2877 {
2878 __set_long_cap(__res_arg+1);
2879 __set_long_size(__sz);
2880 __set_long_pointer(__new_data);
2881 }
2882 else
2883 __set_short_size(__sz);
2884 __invalidate_all_iterators();
2885 }
2886}
2887
2888template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002889inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162890typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:242891basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162892{
Howard Hinnant499cea12013-08-23 17:37:052893 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:162894 return *(data() + __pos);
2895}
2896
2897template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002898inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162899typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:242900basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162901{
Howard Hinnant499cea12013-08-23 17:37:052902 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:162903 return *(__get_pointer() + __pos);
2904}
2905
2906template <class _CharT, class _Traits, class _Allocator>
2907typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2908basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
2909{
2910 if (__n >= size())
2911 this->__throw_out_of_range();
2912 return (*this)[__n];
2913}
2914
2915template <class _CharT, class _Traits, class _Allocator>
2916typename basic_string<_CharT, _Traits, _Allocator>::reference
2917basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
2918{
2919 if (__n >= size())
2920 this->__throw_out_of_range();
2921 return (*this)[__n];
2922}
2923
2924template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002925inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162926typename basic_string<_CharT, _Traits, _Allocator>::reference
2927basic_string<_CharT, _Traits, _Allocator>::front()
2928{
Howard Hinnant499cea12013-08-23 17:37:052929 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:162930 return *__get_pointer();
2931}
2932
2933template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002934inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162935typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2936basic_string<_CharT, _Traits, _Allocator>::front() const
2937{
Howard Hinnant499cea12013-08-23 17:37:052938 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:162939 return *data();
2940}
2941
2942template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002943inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162944typename basic_string<_CharT, _Traits, _Allocator>::reference
2945basic_string<_CharT, _Traits, _Allocator>::back()
2946{
Howard Hinnant499cea12013-08-23 17:37:052947 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:162948 return *(__get_pointer() + size() - 1);
2949}
2950
2951template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002952inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162953typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2954basic_string<_CharT, _Traits, _Allocator>::back() const
2955{
Howard Hinnant499cea12013-08-23 17:37:052956 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:162957 return *(data() + size() - 1);
2958}
2959
2960template <class _CharT, class _Traits, class _Allocator>
2961typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:192962basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:162963{
2964 size_type __sz = size();
2965 if (__pos > __sz)
2966 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:192967 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:162968 traits_type::copy(__s, data() + __pos, __rlen);
2969 return __rlen;
2970}
2971
2972template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002973inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162974basic_string<_CharT, _Traits, _Allocator>
2975basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
2976{
2977 return basic_string(*this, __pos, __n, __alloc());
2978}
2979
2980template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002981inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162982void
2983basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:562984#if _LIBCPP_STD_VER >= 14
2985 _NOEXCEPT
2986#else
2987 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2988 __is_nothrow_swappable<allocator_type>::value)
2989#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162990{
Howard Hinnant499cea12013-08-23 17:37:052991#if _LIBCPP_DEBUG_LEVEL >= 2
2992 if (!__is_long())
2993 __get_db()->__invalidate_all(this);
2994 if (!__str.__is_long())
2995 __get_db()->__invalidate_all(&__str);
2996 __get_db()->swap(this, &__str);
2997#endif
Howard Hinnant0949eed2011-06-30 21:18:192998 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:562999 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:163000}
3001
3002// find
3003
3004template <class _Traits>
3005struct _LIBCPP_HIDDEN __traits_eq
3006{
3007 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:123008 _LIBCPP_INLINE_VISIBILITY
3009 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3010 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:163011};
3012
3013template<class _CharT, class _Traits, class _Allocator>
3014typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193015basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123016 size_type __pos,
3017 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163018{
Alp Tokerec34c482014-05-15 11:27:393019 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243020 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:493021 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:163022}
3023
3024template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003025inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163026typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123027basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3028 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163029{
Marshall Clow1e00d6d2016-07-21 05:31:243030 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:493031 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:163032}
3033
3034template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003035inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163036typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:243037basic_string<_CharT, _Traits, _Allocator>::find(__self_view __sv,
3038 size_type __pos) const _NOEXCEPT
3039{
3040 return __str_find<value_type, size_type, traits_type, npos>
3041 (data(), size(), __sv.data(), __pos, __sv.size());
3042}
3043
3044template<class _CharT, class _Traits, class _Allocator>
3045inline _LIBCPP_INLINE_VISIBILITY
3046typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193047basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123048 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163049{
Alp Tokerec34c482014-05-15 11:27:393050 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243051 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:493052 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:163053}
3054
3055template<class _CharT, class _Traits, class _Allocator>
3056typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123057basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3058 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163059{
Marshall Clow1e00d6d2016-07-21 05:31:243060 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:493061 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:163062}
3063
3064// rfind
3065
3066template<class _CharT, class _Traits, class _Allocator>
3067typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193068basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123069 size_type __pos,
3070 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163071{
Alp Tokerec34c482014-05-15 11:27:393072 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243073 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:493074 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:163075}
3076
3077template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003078inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163079typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123080basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3081 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163082{
Marshall Clow1e00d6d2016-07-21 05:31:243083 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:493084 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:163085}
3086
3087template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003088inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163089typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:243090basic_string<_CharT, _Traits, _Allocator>::rfind(__self_view __sv,
3091 size_type __pos) const _NOEXCEPT
3092{
3093 return __str_rfind<value_type, size_type, traits_type, npos>
3094 (data(), size(), __sv.data(), __pos, __sv.size());
3095}
3096
3097template<class _CharT, class _Traits, class _Allocator>
3098inline _LIBCPP_INLINE_VISIBILITY
3099typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193100basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123101 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163102{
Alp Tokerec34c482014-05-15 11:27:393103 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243104 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:493105 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:163106}
3107
3108template<class _CharT, class _Traits, class _Allocator>
3109typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123110basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3111 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163112{
Marshall Clow1e00d6d2016-07-21 05:31:243113 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:493114 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:163115}
3116
3117// find_first_of
3118
3119template<class _CharT, class _Traits, class _Allocator>
3120typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193121basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123122 size_type __pos,
3123 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163124{
Alp Tokerec34c482014-05-15 11:27:393125 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243126 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263127 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:163128}
3129
3130template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003131inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163132typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123133basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3134 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163135{
Marshall Clow1e00d6d2016-07-21 05:31:243136 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263137 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:163138}
3139
3140template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003141inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163142typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:243143basic_string<_CharT, _Traits, _Allocator>::find_first_of(__self_view __sv,
3144 size_type __pos) const _NOEXCEPT
3145{
3146 return __str_find_first_of<value_type, size_type, traits_type, npos>
3147 (data(), size(), __sv.data(), __pos, __sv.size());
3148}
3149
3150template<class _CharT, class _Traits, class _Allocator>
3151inline _LIBCPP_INLINE_VISIBILITY
3152typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193153basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123154 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163155{
Alp Tokerec34c482014-05-15 11:27:393156 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243157 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263158 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:163159}
3160
3161template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003162inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163163typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123164basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3165 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163166{
3167 return find(__c, __pos);
3168}
3169
3170// find_last_of
3171
3172template<class _CharT, class _Traits, class _Allocator>
3173typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193174basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123175 size_type __pos,
3176 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163177{
Alp Tokerec34c482014-05-15 11:27:393178 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243179 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263180 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:163181}
3182
3183template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003184inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163185typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123186basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3187 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163188{
Marshall Clow1e00d6d2016-07-21 05:31:243189 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263190 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:163191}
3192
3193template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003194inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163195typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:243196basic_string<_CharT, _Traits, _Allocator>::find_last_of(__self_view __sv,
3197 size_type __pos) const _NOEXCEPT
3198{
3199 return __str_find_last_of<value_type, size_type, traits_type, npos>
3200 (data(), size(), __sv.data(), __pos, __sv.size());
3201}
3202
3203template<class _CharT, class _Traits, class _Allocator>
3204inline _LIBCPP_INLINE_VISIBILITY
3205typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193206basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123207 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163208{
Alp Tokerec34c482014-05-15 11:27:393209 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243210 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263211 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:163212}
3213
3214template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003215inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163216typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123217basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3218 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163219{
3220 return rfind(__c, __pos);
3221}
3222
3223// find_first_not_of
3224
3225template<class _CharT, class _Traits, class _Allocator>
3226typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193227basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123228 size_type __pos,
3229 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163230{
Alp Tokerec34c482014-05-15 11:27:393231 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243232 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263233 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:163234}
3235
3236template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003237inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163238typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123239basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3240 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163241{
Marshall Clow1e00d6d2016-07-21 05:31:243242 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263243 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:163244}
3245
3246template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003247inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163248typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:243249basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(__self_view __sv,
3250 size_type __pos) const _NOEXCEPT
3251{
3252 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3253 (data(), size(), __sv.data(), __pos, __sv.size());
3254}
3255
3256template<class _CharT, class _Traits, class _Allocator>
3257inline _LIBCPP_INLINE_VISIBILITY
3258typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193259basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123260 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163261{
Alp Tokerec34c482014-05-15 11:27:393262 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243263 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263264 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:163265}
3266
3267template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003268inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163269typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123270basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3271 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163272{
Marshall Clow1e00d6d2016-07-21 05:31:243273 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263274 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:163275}
3276
3277// find_last_not_of
3278
3279template<class _CharT, class _Traits, class _Allocator>
3280typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193281basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123282 size_type __pos,
3283 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163284{
Alp Tokerec34c482014-05-15 11:27:393285 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243286 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263287 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:163288}
3289
3290template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003291inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163292typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123293basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3294 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163295{
Marshall Clow1e00d6d2016-07-21 05:31:243296 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263297 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:163298}
3299
3300template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003301inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163302typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:243303basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(__self_view __sv,
3304 size_type __pos) const _NOEXCEPT
3305{
3306 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3307 (data(), size(), __sv.data(), __pos, __sv.size());
3308}
3309
3310template<class _CharT, class _Traits, class _Allocator>
3311inline _LIBCPP_INLINE_VISIBILITY
3312typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193313basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123314 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163315{
Alp Tokerec34c482014-05-15 11:27:393316 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243317 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263318 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:163319}
3320
3321template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003322inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163323typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123324basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3325 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163326{
Marshall Clow1e00d6d2016-07-21 05:31:243327 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263328 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:163329}
3330
3331// compare
3332
3333template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003334inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163335int
Marshall Clow1e00d6d2016-07-21 05:31:243336basic_string<_CharT, _Traits, _Allocator>::compare(__self_view __sv) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163337{
Howard Hinnantfa06d752011-07-24 21:45:063338 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:243339 size_t __rhs_sz = __sv.size();
3340 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:063341 _VSTD::min(__lhs_sz, __rhs_sz));
3342 if (__result != 0)
3343 return __result;
3344 if (__lhs_sz < __rhs_sz)
3345 return -1;
3346 if (__lhs_sz > __rhs_sz)
3347 return 1;
3348 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:163349}
3350
3351template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003352inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163353int
Marshall Clow1e00d6d2016-07-21 05:31:243354basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163355{
Marshall Clow1e00d6d2016-07-21 05:31:243356 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:163357}
3358
3359template <class _CharT, class _Traits, class _Allocator>
3360int
Howard Hinnanta6119a82011-05-29 19:57:123361basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3362 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:193363 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123364 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:163365{
Alp Tokerec34c482014-05-15 11:27:393366 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:163367 size_type __sz = size();
3368 if (__pos1 > __sz || __n2 == npos)
3369 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:193370 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3371 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:163372 if (__r == 0)
3373 {
3374 if (__rlen < __n2)
3375 __r = -1;
3376 else if (__rlen > __n2)
3377 __r = 1;
3378 }
3379 return __r;
3380}
3381
Marshall Clow1e00d6d2016-07-21 05:31:243382template <class _CharT, class _Traits, class _Allocator>
3383inline _LIBCPP_INLINE_VISIBILITY
3384int
3385basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3386 size_type __n1,
3387 __self_view __sv) const
3388{
3389 return compare(__pos1, __n1, __sv.data(), __sv.size());
3390}
3391
3392template <class _CharT, class _Traits, class _Allocator>
3393inline _LIBCPP_INLINE_VISIBILITY
3394int
3395basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3396 size_type __n1,
3397 const basic_string& __str) const
3398{
3399 return compare(__pos1, __n1, __str.data(), __str.size());
3400}
3401
3402template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:423403template <class _Tp>
3404typename enable_if
3405<
3406__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3407int
3408>::type
Marshall Clow1e00d6d2016-07-21 05:31:243409basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3410 size_type __n1,
Marshall Clow6ac8de02016-09-24 22:45:423411 const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:243412 size_type __pos2,
3413 size_type __n2) const
3414{
Marshall Clow6ac8de02016-09-24 22:45:423415 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:243416 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3417}
3418
3419template <class _CharT, class _Traits, class _Allocator>
3420int
3421basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3422 size_type __n1,
3423 const basic_string& __str,
3424 size_type __pos2,
3425 size_type __n2) const
3426{
3427 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3428}
3429
3430template <class _CharT, class _Traits, class _Allocator>
3431int
3432basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3433{
3434 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3435 return compare(0, npos, __s, traits_type::length(__s));
3436}
3437
3438template <class _CharT, class _Traits, class _Allocator>
3439int
3440basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3441 size_type __n1,
3442 const value_type* __s) const
3443{
3444 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3445 return compare(__pos1, __n1, __s, traits_type::length(__s));
3446}
3447
Howard Hinnantbc8d3f92010-05-11 19:42:163448// __invariants
3449
3450template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003451inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163452bool
3453basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3454{
3455 if (size() > capacity())
3456 return false;
3457 if (capacity() < __min_cap - 1)
3458 return false;
3459 if (data() == 0)
3460 return false;
3461 if (data()[size()] != value_type(0))
3462 return false;
3463 return true;
3464}
3465
3466// operator==
3467
3468template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003469inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163470bool
3471operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:123472 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163473{
Howard Hinnant08dd2532013-04-22 23:55:133474 size_t __lhs_sz = __lhs.size();
3475 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3476 __rhs.data(),
3477 __lhs_sz) == 0;
3478}
3479
3480template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003481inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:133482bool
3483operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3484 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3485{
3486 size_t __lhs_sz = __lhs.size();
3487 if (__lhs_sz != __rhs.size())
3488 return false;
3489 const char* __lp = __lhs.data();
3490 const char* __rp = __rhs.data();
3491 if (__lhs.__is_long())
3492 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3493 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3494 if (*__lp != *__rp)
3495 return false;
3496 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:163497}
3498
3499template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003500inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163501bool
Howard Hinnanta6119a82011-05-29 19:57:123502operator==(const _CharT* __lhs,
3503 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163504{
Eric Fiselier4f241822015-08-28 03:02:373505 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3506 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3507 size_t __lhs_len = _Traits::length(__lhs);
3508 if (__lhs_len != __rhs.size()) return false;
3509 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:163510}
3511
Howard Hinnantbc8d3f92010-05-11 19:42:163512template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003513inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163514bool
Howard Hinnanta6119a82011-05-29 19:57:123515operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3516 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163517{
Eric Fiselier4f241822015-08-28 03:02:373518 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3519 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3520 size_t __rhs_len = _Traits::length(__rhs);
3521 if (__rhs_len != __lhs.size()) return false;
3522 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:163523}
3524
Howard Hinnant324bb032010-08-22 00:02:433525template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003526inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163527bool
3528operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:123529 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163530{
3531 return !(__lhs == __rhs);
3532}
3533
3534template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003535inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163536bool
Howard Hinnanta6119a82011-05-29 19:57:123537operator!=(const _CharT* __lhs,
3538 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163539{
3540 return !(__lhs == __rhs);
3541}
3542
3543template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003544inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163545bool
Howard Hinnanta6119a82011-05-29 19:57:123546operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3547 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163548{
3549 return !(__lhs == __rhs);
3550}
3551
3552// operator<
3553
3554template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003555inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163556bool
3557operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:123558 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163559{
Howard Hinnant2644a7b2011-07-24 15:07:213560 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:163561}
3562
3563template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003564inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163565bool
Howard Hinnanta6119a82011-05-29 19:57:123566operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3567 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163568{
Howard Hinnant2644a7b2011-07-24 15:07:213569 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:163570}
3571
3572template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003573inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163574bool
Howard Hinnanta6119a82011-05-29 19:57:123575operator< (const _CharT* __lhs,
3576 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163577{
3578 return __rhs.compare(__lhs) > 0;
3579}
3580
Howard Hinnantbc8d3f92010-05-11 19:42:163581// operator>
3582
3583template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003584inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163585bool
3586operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:123587 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163588{
3589 return __rhs < __lhs;
3590}
3591
3592template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003593inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163594bool
Howard Hinnanta6119a82011-05-29 19:57:123595operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3596 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163597{
3598 return __rhs < __lhs;
3599}
3600
3601template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003602inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163603bool
Howard Hinnanta6119a82011-05-29 19:57:123604operator> (const _CharT* __lhs,
3605 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163606{
3607 return __rhs < __lhs;
3608}
3609
3610// operator<=
3611
3612template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003613inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163614bool
3615operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:123616 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163617{
3618 return !(__rhs < __lhs);
3619}
3620
3621template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003622inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163623bool
Howard Hinnanta6119a82011-05-29 19:57:123624operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3625 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163626{
3627 return !(__rhs < __lhs);
3628}
3629
3630template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003631inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163632bool
Howard Hinnanta6119a82011-05-29 19:57:123633operator<=(const _CharT* __lhs,
3634 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163635{
3636 return !(__rhs < __lhs);
3637}
3638
3639// operator>=
3640
3641template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003642inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163643bool
3644operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:123645 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163646{
3647 return !(__lhs < __rhs);
3648}
3649
3650template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003651inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163652bool
Howard Hinnanta6119a82011-05-29 19:57:123653operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3654 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163655{
3656 return !(__lhs < __rhs);
3657}
3658
3659template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003660inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163661bool
Howard Hinnanta6119a82011-05-29 19:57:123662operator>=(const _CharT* __lhs,
3663 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163664{
3665 return !(__lhs < __rhs);
3666}
3667
3668// operator +
3669
3670template<class _CharT, class _Traits, class _Allocator>
3671basic_string<_CharT, _Traits, _Allocator>
3672operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3673 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3674{
3675 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3676 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3677 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3678 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3679 __r.append(__rhs.data(), __rhs_sz);
3680 return __r;
3681}
3682
3683template<class _CharT, class _Traits, class _Allocator>
3684basic_string<_CharT, _Traits, _Allocator>
3685operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3686{
3687 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3688 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3689 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3690 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3691 __r.append(__rhs.data(), __rhs_sz);
3692 return __r;
3693}
3694
3695template<class _CharT, class _Traits, class _Allocator>
3696basic_string<_CharT, _Traits, _Allocator>
3697operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3698{
3699 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3700 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3701 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3702 __r.append(__rhs.data(), __rhs_sz);
3703 return __r;
3704}
3705
3706template<class _CharT, class _Traits, class _Allocator>
3707basic_string<_CharT, _Traits, _Allocator>
3708operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3709{
3710 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3711 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3712 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3713 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3714 __r.append(__rhs, __rhs_sz);
3715 return __r;
3716}
3717
3718template<class _CharT, class _Traits, class _Allocator>
3719basic_string<_CharT, _Traits, _Allocator>
3720operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3721{
3722 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3723 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3724 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3725 __r.push_back(__rhs);
3726 return __r;
3727}
3728
Howard Hinnant73d21a42010-09-04 23:28:193729#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:163730
3731template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003732inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163733basic_string<_CharT, _Traits, _Allocator>
3734operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3735{
Howard Hinnant0949eed2011-06-30 21:18:193736 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:163737}
3738
3739template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003740inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163741basic_string<_CharT, _Traits, _Allocator>
3742operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3743{
Howard Hinnant0949eed2011-06-30 21:18:193744 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:163745}
3746
3747template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003748inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163749basic_string<_CharT, _Traits, _Allocator>
3750operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3751{
Howard Hinnant0949eed2011-06-30 21:18:193752 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:163753}
3754
3755template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003756inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163757basic_string<_CharT, _Traits, _Allocator>
3758operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3759{
Howard Hinnant0949eed2011-06-30 21:18:193760 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:163761}
3762
3763template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003764inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163765basic_string<_CharT, _Traits, _Allocator>
3766operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3767{
3768 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:193769 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:163770}
3771
3772template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003773inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163774basic_string<_CharT, _Traits, _Allocator>
3775operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3776{
Howard Hinnant0949eed2011-06-30 21:18:193777 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:163778}
3779
3780template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003781inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163782basic_string<_CharT, _Traits, _Allocator>
3783operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3784{
3785 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:193786 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:163787}
3788
Howard Hinnant73d21a42010-09-04 23:28:193789#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:163790
3791// swap
3792
3793template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003794inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163795void
Howard Hinnanta6119a82011-05-29 19:57:123796swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:473797 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3798 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:163799{
3800 __lhs.swap(__rhs);
3801}
3802
Howard Hinnantbc8d3f92010-05-11 19:42:163803#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3804
3805typedef basic_string<char16_t> u16string;
3806typedef basic_string<char32_t> u32string;
3807
Howard Hinnant324bb032010-08-22 00:02:433808#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:163809
Howard Hinnant0f678bd2013-08-12 18:38:343810_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3811_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3812_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3813_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
3814_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:393815
Howard Hinnant0f678bd2013-08-12 18:38:343816_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
3817_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
3818_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:393819
Howard Hinnant0f678bd2013-08-12 18:38:343820_LIBCPP_FUNC_VIS string to_string(int __val);
3821_LIBCPP_FUNC_VIS string to_string(unsigned __val);
3822_LIBCPP_FUNC_VIS string to_string(long __val);
3823_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
3824_LIBCPP_FUNC_VIS string to_string(long long __val);
3825_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
3826_LIBCPP_FUNC_VIS string to_string(float __val);
3827_LIBCPP_FUNC_VIS string to_string(double __val);
3828_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:393829
Howard Hinnant0f678bd2013-08-12 18:38:343830_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
3831_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
3832_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
3833_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
3834_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:393835
Howard Hinnant0f678bd2013-08-12 18:38:343836_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
3837_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
3838_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:393839
Howard Hinnant0f678bd2013-08-12 18:38:343840_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
3841_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
3842_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
3843_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
3844_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
3845_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
3846_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
3847_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
3848_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:393849
Howard Hinnantbc8d3f92010-05-11 19:42:163850template<class _CharT, class _Traits, class _Allocator>
3851 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
3852 basic_string<_CharT, _Traits, _Allocator>::npos;
3853
3854template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:343855struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:163856 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
3857{
3858 size_t
Howard Hinnanta6119a82011-05-29 19:57:123859 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:163860};
3861
3862template<class _CharT, class _Traits, class _Allocator>
3863size_t
3864hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:123865 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163866{
Sean Huntaffd9e52011-07-29 23:31:563867 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:163868}
3869
Howard Hinnant464aa5c2011-07-18 15:51:593870template<class _CharT, class _Traits, class _Allocator>
3871basic_ostream<_CharT, _Traits>&
3872operator<<(basic_ostream<_CharT, _Traits>& __os,
3873 const basic_string<_CharT, _Traits, _Allocator>& __str);
3874
3875template<class _CharT, class _Traits, class _Allocator>
3876basic_istream<_CharT, _Traits>&
3877operator>>(basic_istream<_CharT, _Traits>& __is,
3878 basic_string<_CharT, _Traits, _Allocator>& __str);
3879
3880template<class _CharT, class _Traits, class _Allocator>
3881basic_istream<_CharT, _Traits>&
3882getline(basic_istream<_CharT, _Traits>& __is,
3883 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3884
3885template<class _CharT, class _Traits, class _Allocator>
3886inline _LIBCPP_INLINE_VISIBILITY
3887basic_istream<_CharT, _Traits>&
3888getline(basic_istream<_CharT, _Traits>& __is,
3889 basic_string<_CharT, _Traits, _Allocator>& __str);
3890
3891#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3892
3893template<class _CharT, class _Traits, class _Allocator>
3894inline _LIBCPP_INLINE_VISIBILITY
3895basic_istream<_CharT, _Traits>&
3896getline(basic_istream<_CharT, _Traits>&& __is,
3897 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3898
3899template<class _CharT, class _Traits, class _Allocator>
3900inline _LIBCPP_INLINE_VISIBILITY
3901basic_istream<_CharT, _Traits>&
3902getline(basic_istream<_CharT, _Traits>&& __is,
3903 basic_string<_CharT, _Traits, _Allocator>& __str);
3904
3905#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3906
Howard Hinnant499cea12013-08-23 17:37:053907#if _LIBCPP_DEBUG_LEVEL >= 2
3908
3909template<class _CharT, class _Traits, class _Allocator>
3910bool
3911basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
3912{
3913 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
3914 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
3915}
3916
3917template<class _CharT, class _Traits, class _Allocator>
3918bool
3919basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
3920{
3921 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
3922 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
3923}
3924
3925template<class _CharT, class _Traits, class _Allocator>
3926bool
3927basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
3928{
3929 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
3930 return this->data() <= __p && __p <= this->data() + this->size();
3931}
3932
3933template<class _CharT, class _Traits, class _Allocator>
3934bool
3935basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
3936{
3937 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
3938 return this->data() <= __p && __p < this->data() + this->size();
3939}
3940
3941#endif // _LIBCPP_DEBUG_LEVEL >= 2
3942
Marshall Clow15234322013-07-23 17:05:243943#if _LIBCPP_STD_VER > 11
3944// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:323945inline namespace literals
Marshall Clow15234322013-07-23 17:05:243946{
3947 inline namespace string_literals
3948 {
Howard Hinnantab61b2c2013-08-07 19:39:483949 inline _LIBCPP_INLINE_VISIBILITY
3950 basic_string<char> operator "" s( const char *__str, size_t __len )
3951 {
3952 return basic_string<char> (__str, __len);
3953 }
Marshall Clow15234322013-07-23 17:05:243954
Howard Hinnantab61b2c2013-08-07 19:39:483955 inline _LIBCPP_INLINE_VISIBILITY
3956 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
3957 {
3958 return basic_string<wchar_t> (__str, __len);
3959 }
Marshall Clow15234322013-07-23 17:05:243960
Howard Hinnantab61b2c2013-08-07 19:39:483961 inline _LIBCPP_INLINE_VISIBILITY
3962 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
3963 {
3964 return basic_string<char16_t> (__str, __len);
3965 }
Marshall Clow15234322013-07-23 17:05:243966
Howard Hinnantab61b2c2013-08-07 19:39:483967 inline _LIBCPP_INLINE_VISIBILITY
3968 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
3969 {
3970 return basic_string<char32_t> (__str, __len);
3971 }
Marshall Clow15234322013-07-23 17:05:243972 }
3973}
3974#endif
3975
Eric Fiselier833d6442016-09-15 22:27:073976_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
3977_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Howard Hinnant499cea12013-08-23 17:37:053978_LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
Howard Hinnantbc8d3f92010-05-11 19:42:163979
3980_LIBCPP_END_NAMESPACE_STD
3981
3982#endif // _LIBCPP_STRING