blob: 94e70e0b159735e729ffac07cabd83769aa47841 [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 Clow1e00d6d2016-07-21 05:31:24173 basic_string& append(basic_string_view<charT, traits> sv, size_type pos, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19174 basic_string& append(const value_type* s, size_type n);
175 basic_string& append(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16176 basic_string& append(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39177 template<class InputIterator>
178 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16179 basic_string& append(initializer_list<value_type>);
180
181 void push_back(value_type c);
182 void pop_back();
183 reference front();
184 const_reference front() const;
185 reference back();
186 const_reference back() const;
187
188 basic_string& assign(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24189 basic_string& assign(basic_string_view<charT, traits> sv);
Howard Hinnanta6119a82011-05-29 19:57:12190 basic_string& assign(basic_string&& str);
Marshall Clowa93b5e22014-03-04 19:17:19191 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
Marshall Clow1e00d6d2016-07-21 05:31:24192 basic_string& assign(basic_string_view<charT, traits> sv, size_type pos, size_type n=npos); // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19193 basic_string& assign(const value_type* s, size_type n);
194 basic_string& assign(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16195 basic_string& assign(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39196 template<class InputIterator>
197 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16198 basic_string& assign(initializer_list<value_type>);
199
200 basic_string& insert(size_type pos1, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24201 basic_string& insert(size_type pos1, basic_string_view<charT, traits> sv);
Howard Hinnanta6a062d2010-06-02 18:20:39202 basic_string& insert(size_type pos1, const basic_string& str,
203 size_type pos2, size_type n);
Marshall Clow1e00d6d2016-07-21 05:31:24204 basic_string& insert(size_type pos1, basic_string_view<charT, traits> sv,
205 size_type pos2, size_type n);
Marshall Clowa93b5e22014-03-04 19:17:19206 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19207 basic_string& insert(size_type pos, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16208 basic_string& insert(size_type pos, size_type n, value_type c);
209 iterator insert(const_iterator p, value_type c);
210 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39211 template<class InputIterator>
212 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16213 iterator insert(const_iterator p, initializer_list<value_type>);
214
215 basic_string& erase(size_type pos = 0, size_type n = npos);
216 iterator erase(const_iterator position);
217 iterator erase(const_iterator first, const_iterator last);
218
219 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24220 basic_string& replace(size_type pos1, size_type n1, basic_string_view<charT, traits> sv);
Howard Hinnanta6a062d2010-06-02 18:20:39221 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19222 size_type pos2, size_type n2=npos); // C++14
Marshall Clow1e00d6d2016-07-21 05:31:24223 basic_string& replace(size_type pos1, size_type n1, basic_string_view<charT, traits> sv,
224 size_type pos2, size_type n2=npos); // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19225 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
226 basic_string& replace(size_type pos, size_type n1, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16227 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant7b2cb482010-11-17 21:11:40228 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24229 basic_string& replace(const_iterator i1, const_iterator i2, basic_string_view<charT, traits> sv);
Howard Hinnant9dcdcde2013-06-28 16:59:19230 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
231 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
Howard Hinnant7b2cb482010-11-17 21:11:40232 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39233 template<class InputIterator>
Howard Hinnant7b2cb482010-11-17 21:11:40234 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
235 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantbc8d3f92010-05-11 19:42:16236
Howard Hinnant9dcdcde2013-06-28 16:59:19237 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16238 basic_string substr(size_type pos = 0, size_type n = npos) const;
239
Howard Hinnant53f7d4c2011-06-03 18:40:47240 void swap(basic_string& str)
Marshall Clow7d914d12015-07-13 20:04:56241 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
242 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16243
Howard Hinnant9dcdcde2013-06-28 16:59:19244 const value_type* c_str() const noexcept;
245 const value_type* data() const noexcept;
Marshall Clowf532a702016-03-08 15:44:30246 value_type* data() noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16247
Howard Hinnanta6119a82011-05-29 19:57:12248 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16249
Howard Hinnanta6119a82011-05-29 19:57:12250 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24251 size_type find(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19252 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
253 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12254 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16255
Howard Hinnanta6119a82011-05-29 19:57:12256 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24257 size_type ffind(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19258 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
259 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12260 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16261
Howard Hinnanta6119a82011-05-29 19:57:12262 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24263 size_type find_first_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19264 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
265 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12266 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16267
Howard Hinnanta6119a82011-05-29 19:57:12268 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24269 size_type find_last_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19270 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
271 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12272 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16273
Howard Hinnanta6119a82011-05-29 19:57:12274 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24275 size_type find_first_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19276 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
277 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12278 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16279
Howard Hinnanta6119a82011-05-29 19:57:12280 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24281 size_type find_last_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19282 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
283 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12284 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16285
Howard Hinnanta6119a82011-05-29 19:57:12286 int compare(const basic_string& str) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24287 int compare(basic_string_view<charT, traits> sv) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16288 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Marshall Clow1e00d6d2016-07-21 05:31:24289 int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv) const;
Howard Hinnanta6a062d2010-06-02 18:20:39290 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19291 size_type pos2, size_type n2=npos) const; // C++14
Marshall Clow1e00d6d2016-07-21 05:31:24292 int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv,
293 size_type pos2, size_type n2=npos) const; // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19294 int compare(const value_type* s) const noexcept;
295 int compare(size_type pos1, size_type n1, const value_type* s) const;
296 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16297
298 bool __invariants() const;
299};
300
301template<class charT, class traits, class Allocator>
302basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39303operator+(const basic_string<charT, traits, Allocator>& lhs,
304 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16305
306template<class charT, class traits, class Allocator>
307basic_string<charT, traits, Allocator>
308operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
309
310template<class charT, class traits, class Allocator>
311basic_string<charT, traits, Allocator>
312operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
313
314template<class charT, class traits, class Allocator>
315basic_string<charT, traits, Allocator>
316operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
317
318template<class charT, class traits, class Allocator>
319basic_string<charT, traits, Allocator>
320operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
321
322template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39323bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12324 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16325
326template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12327bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16328
329template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12330bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16331
Howard Hinnant324bb032010-08-22 00:02:43332template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39333bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12334 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16335
336template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12337bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16338
339template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12340bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16341
342template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39343bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12344 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16345
346template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12347bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16348
349template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12350bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16351
352template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39353bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12354 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16355
356template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12357bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16358
359template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12360bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16361
362template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39363bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12364 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16365
366template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12367bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16368
369template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12370bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16371
372template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39373bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12374 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16375
376template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12377bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16378
379template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12380bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16381
382template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39383void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47384 basic_string<charT, traits, Allocator>& rhs)
385 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16386
387template<class charT, class traits, class Allocator>
388basic_istream<charT, traits>&
389operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
390
391template<class charT, class traits, class Allocator>
392basic_ostream<charT, traits>&
393operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
394
395template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43396basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39397getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
398 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16399
400template<class charT, class traits, class Allocator>
401basic_istream<charT, traits>&
402getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
403
404typedef basic_string<char> string;
405typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39406typedef basic_string<char16_t> u16string;
407typedef basic_string<char32_t> u32string;
408
409int stoi (const string& str, size_t* idx = 0, int base = 10);
410long stol (const string& str, size_t* idx = 0, int base = 10);
411unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
412long long stoll (const string& str, size_t* idx = 0, int base = 10);
413unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
414
415float stof (const string& str, size_t* idx = 0);
416double stod (const string& str, size_t* idx = 0);
417long double stold(const string& str, size_t* idx = 0);
418
419string to_string(int val);
420string to_string(unsigned val);
421string to_string(long val);
422string to_string(unsigned long val);
423string to_string(long long val);
424string to_string(unsigned long long val);
425string to_string(float val);
426string to_string(double val);
427string to_string(long double val);
428
429int stoi (const wstring& str, size_t* idx = 0, int base = 10);
430long stol (const wstring& str, size_t* idx = 0, int base = 10);
431unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
432long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
433unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
434
435float stof (const wstring& str, size_t* idx = 0);
436double stod (const wstring& str, size_t* idx = 0);
437long double stold(const wstring& str, size_t* idx = 0);
438
439wstring to_wstring(int val);
440wstring to_wstring(unsigned val);
441wstring to_wstring(long val);
442wstring to_wstring(unsigned long val);
443wstring to_wstring(long long val);
444wstring to_wstring(unsigned long long val);
445wstring to_wstring(float val);
446wstring to_wstring(double val);
447wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16448
449template <> struct hash<string>;
450template <> struct hash<u16string>;
451template <> struct hash<u32string>;
452template <> struct hash<wstring>;
453
Marshall Clow15234322013-07-23 17:05:24454basic_string<char> operator "" s( const char *str, size_t len ); // C++14
455basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
456basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
457basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
458
Howard Hinnantbc8d3f92010-05-11 19:42:16459} // std
460
461*/
462
463#include <__config>
Marshall Clow1e00d6d2016-07-21 05:31:24464#include <string_view>
Howard Hinnantbc8d3f92010-05-11 19:42:16465#include <iosfwd>
466#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41467#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16468#include <cwchar>
469#include <algorithm>
470#include <iterator>
471#include <utility>
472#include <memory>
473#include <stdexcept>
474#include <type_traits>
475#include <initializer_list>
476#include <__functional_base>
477#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
478#include <cstdint>
479#endif
Howard Hinnant499cea12013-08-23 17:37:05480#if defined(_LIBCPP_NO_EXCEPTIONS)
Howard Hinnantbc8d3f92010-05-11 19:42:16481#include <cassert>
482#endif
483
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:
559 void __throw_length_error() const;
560 void __throw_out_of_range() const;
561};
562
563template <bool __b>
564void
565__basic_string_common<__b>::__throw_length_error() const
566{
567#ifndef _LIBCPP_NO_EXCEPTIONS
568 throw length_error("basic_string");
569#else
570 assert(!"basic_string length_error");
571#endif
572}
573
574template <bool __b>
575void
576__basic_string_common<__b>::__throw_out_of_range() const
577{
578#ifndef _LIBCPP_NO_EXCEPTIONS
579 throw out_of_range("basic_string");
580#else
581 assert(!"basic_string out_of_range");
582#endif
583}
584
Howard Hinnante9df0a52013-08-01 18:17:34585#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45586#pragma warning( push )
587#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34588#endif // _LIBCPP_MSVC
Howard Hinnant0f678bd2013-08-12 18:38:34589_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34590#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45591#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34592#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16593
Marshall Clowdf9db312016-01-13 21:54:34594#ifdef _LIBCPP_NO_EXCEPTIONS
595template <class _Iter>
596struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
597#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
598template <class _Iter>
599struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
600#else
601template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
602struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
603 noexcept(++(declval<_Iter&>())) &&
604 is_nothrow_assignable<_Iter&, _Iter>::value &&
605 noexcept(declval<_Iter>() == declval<_Iter>()) &&
606 noexcept(*declval<_Iter>())
607)) {};
608
609template <class _Iter>
610struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
611#endif
612
613
614template <class _Iter>
615struct __libcpp_string_gets_noexcept_iterator
616 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
617
Evgeniy Stepanov4f01aa82015-10-13 23:48:28618#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48619
620template <class _CharT, size_t = sizeof(_CharT)>
621struct __padding
622{
623 unsigned char __xx[sizeof(_CharT)-1];
624};
625
626template <class _CharT>
627struct __padding<_CharT, 1>
628{
629};
630
Evgeniy Stepanov4f01aa82015-10-13 23:48:28631#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48632
Howard Hinnant324bb032010-08-22 00:02:43633template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34634class _LIBCPP_TYPE_VIS_ONLY basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16635 : private __basic_string_common<true>
636{
637public:
638 typedef basic_string __self;
Marshall Clow1e00d6d2016-07-21 05:31:24639 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantbc8d3f92010-05-11 19:42:16640 typedef _Traits traits_type;
641 typedef typename traits_type::char_type value_type;
642 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08643 typedef allocator_traits<allocator_type> __alloc_traits;
644 typedef typename __alloc_traits::size_type size_type;
645 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47646 typedef value_type& reference;
647 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08648 typedef typename __alloc_traits::pointer pointer;
649 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16650
Howard Hinnant499cea12013-08-23 17:37:05651 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
652 static_assert((is_same<_CharT, value_type>::value),
653 "traits_type::char_type must be the same type as CharT");
654 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
655 "Allocator::value_type must be same type as value_type");
656#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16657 typedef pointer iterator;
658 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43659#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16660 typedef __wrap_iter<pointer> iterator;
661 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43662#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19663 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
664 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16665
666private:
Howard Hinnant15467182013-04-30 21:44:48667
Evgeniy Stepanov4f01aa82015-10-13 23:48:28668#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48669
670 struct __long
671 {
672 pointer __data_;
673 size_type __size_;
674 size_type __cap_;
675 };
676
677#if _LIBCPP_BIG_ENDIAN
678 enum {__short_mask = 0x01};
679 enum {__long_mask = 0x1ul};
680#else // _LIBCPP_BIG_ENDIAN
681 enum {__short_mask = 0x80};
682 enum {__long_mask = ~(size_type(~0) >> 1)};
683#endif // _LIBCPP_BIG_ENDIAN
684
685 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
686 (sizeof(__long) - 1)/sizeof(value_type) : 2};
687
688 struct __short
689 {
690 value_type __data_[__min_cap];
691 struct
692 : __padding<value_type>
693 {
694 unsigned char __size_;
695 };
696 };
697
698#else
699
Howard Hinnantbc8d3f92010-05-11 19:42:16700 struct __long
701 {
702 size_type __cap_;
703 size_type __size_;
704 pointer __data_;
705 };
706
707#if _LIBCPP_BIG_ENDIAN
708 enum {__short_mask = 0x80};
709 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43710#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16711 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04712 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43713#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16714
Howard Hinnantbc8d3f92010-05-11 19:42:16715 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
716 (sizeof(__long) - 1)/sizeof(value_type) : 2};
717
718 struct __short
719 {
720 union
721 {
722 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59723 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16724 };
725 value_type __data_[__min_cap];
726 };
727
Evgeniy Stepanov4f01aa82015-10-13 23:48:28728#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48729
Howard Hinnant499cea12013-08-23 17:37:05730 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16731
Howard Hinnant499cea12013-08-23 17:37:05732 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16733
734 struct __raw
735 {
736 size_type __words[__n_words];
737 };
738
739 struct __rep
740 {
741 union
742 {
743 __long __l;
744 __short __s;
745 __raw __r;
746 };
747 };
748
749 __compressed_pair<__rep, allocator_type> __r_;
750
Howard Hinnantbc8d3f92010-05-11 19:42:16751public:
752 static const size_type npos = -1;
753
Howard Hinnant53f7d4c2011-06-03 18:40:47754 _LIBCPP_INLINE_VISIBILITY basic_string()
755 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43756
757 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
758#if _LIBCPP_STD_VER <= 14
759 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
760#else
761 _NOEXCEPT;
762#endif
763
Howard Hinnantbc8d3f92010-05-11 19:42:16764 basic_string(const basic_string& __str);
765 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43766
Howard Hinnant73d21a42010-09-04 23:28:19767#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59768 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47769 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43770#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47771 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43772#else
773 _NOEXCEPT;
774#endif
775
Howard Hinnant9f193f22011-01-26 00:06:59776 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16777 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19778#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19779 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43780 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19781 basic_string(const value_type* __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43782 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19783 basic_string(const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19785 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16787 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43788 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16789 basic_string(size_type __n, value_type __c, const allocator_type& __a);
Marshall Clowf4f7d8f2016-04-07 18:13:41790 basic_string(const basic_string& __str, size_type __pos, size_type __n,
791 const allocator_type& __a = allocator_type());
792 _LIBCPP_INLINE_VISIBILITY
793 basic_string(const basic_string& __str, size_type __pos,
Howard Hinnantbc8d3f92010-05-11 19:42:16794 const allocator_type& __a = allocator_type());
Marshall Clow1e00d6d2016-07-21 05:31:24795 _LIBCPP_INLINE_VISIBILITY explicit
796 basic_string(__self_view __sv);
797 _LIBCPP_INLINE_VISIBILITY
798 basic_string(__self_view __sv, const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16799 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);
802 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16804 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02805#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43806 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16807 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43808 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16809 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02810#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16811
812 ~basic_string();
813
Marshall Clow1e00d6d2016-07-21 05:31:24814 _LIBCPP_INLINE_VISIBILITY
815 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
816
Howard Hinnante32b5e22010-11-17 17:55:08817 basic_string& operator=(const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24818 _LIBCPP_INLINE_VISIBILITY
819 basic_string& operator=(__self_view __sv) {return assign(__sv);}
Howard Hinnant73d21a42010-09-04 23:28:19820#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43821 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47822 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00823 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Howard Hinnantbc8d3f92010-05-11 19:42:16824#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19825 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16826 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02827#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07828 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16829 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02830#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16831
Howard Hinnant499cea12013-08-23 17:37:05832#if _LIBCPP_DEBUG_LEVEL >= 2
833 _LIBCPP_INLINE_VISIBILITY
834 iterator begin() _NOEXCEPT
835 {return iterator(this, __get_pointer());}
836 _LIBCPP_INLINE_VISIBILITY
837 const_iterator begin() const _NOEXCEPT
838 {return const_iterator(this, __get_pointer());}
839 _LIBCPP_INLINE_VISIBILITY
840 iterator end() _NOEXCEPT
841 {return iterator(this, __get_pointer() + size());}
842 _LIBCPP_INLINE_VISIBILITY
843 const_iterator end() const _NOEXCEPT
844 {return const_iterator(this, __get_pointer() + size());}
845#else
Howard Hinnanta6119a82011-05-29 19:57:12846 _LIBCPP_INLINE_VISIBILITY
847 iterator begin() _NOEXCEPT
848 {return iterator(__get_pointer());}
849 _LIBCPP_INLINE_VISIBILITY
850 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19851 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12852 _LIBCPP_INLINE_VISIBILITY
853 iterator end() _NOEXCEPT
854 {return iterator(__get_pointer() + size());}
855 _LIBCPP_INLINE_VISIBILITY
856 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19857 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05858#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12859 _LIBCPP_INLINE_VISIBILITY
860 reverse_iterator rbegin() _NOEXCEPT
861 {return reverse_iterator(end());}
862 _LIBCPP_INLINE_VISIBILITY
863 const_reverse_iterator rbegin() const _NOEXCEPT
864 {return const_reverse_iterator(end());}
865 _LIBCPP_INLINE_VISIBILITY
866 reverse_iterator rend() _NOEXCEPT
867 {return reverse_iterator(begin());}
868 _LIBCPP_INLINE_VISIBILITY
869 const_reverse_iterator rend() const _NOEXCEPT
870 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16871
Howard Hinnanta6119a82011-05-29 19:57:12872 _LIBCPP_INLINE_VISIBILITY
873 const_iterator cbegin() const _NOEXCEPT
874 {return begin();}
875 _LIBCPP_INLINE_VISIBILITY
876 const_iterator cend() const _NOEXCEPT
877 {return end();}
878 _LIBCPP_INLINE_VISIBILITY
879 const_reverse_iterator crbegin() const _NOEXCEPT
880 {return rbegin();}
881 _LIBCPP_INLINE_VISIBILITY
882 const_reverse_iterator crend() const _NOEXCEPT
883 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16884
Howard Hinnanta6119a82011-05-29 19:57:12885 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16886 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12887 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
888 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
889 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42890 {return (__is_long() ? __get_long_cap()
891 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16892
893 void resize(size_type __n, value_type __c);
894 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
895
896 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47898 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12900 void clear() _NOEXCEPT;
901 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16902
Marshall Clow1e00d6d2016-07-21 05:31:24903 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
904 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16905
906 const_reference at(size_type __n) const;
907 reference at(size_type __n);
908
909 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clow1e00d6d2016-07-21 05:31:24910 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(__self_view __sv) {return append(__sv);}
911 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16912 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02913#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16914 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02915#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16916
Howard Hinnant2d72b1e2010-12-17 14:46:43917 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16918 basic_string& append(const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24919 _LIBCPP_INLINE_VISIBILITY
920 basic_string& append(__self_view __sv) { return append(__sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19921 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow1e00d6d2016-07-21 05:31:24922 _LIBCPP_INLINE_VISIBILITY
923 basic_string& append(__self_view __sv, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19924 basic_string& append(const value_type* __s, size_type __n);
925 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16926 basic_string& append(size_type __n, value_type __c);
927 template<class _InputIterator>
928 typename enable_if
929 <
Marshall Clowdf9db312016-01-13 21:54:34930 __is_exactly_input_iterator<_InputIterator>::value
931 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16932 basic_string&
933 >::type
934 append(_InputIterator __first, _InputIterator __last);
935 template<class _ForwardIterator>
936 typename enable_if
937 <
Marshall Clowdf9db312016-01-13 21:54:34938 __is_forward_iterator<_ForwardIterator>::value
939 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16940 basic_string&
941 >::type
942 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02943#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16945 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02946#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16947
948 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43949 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16950 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43951 _LIBCPP_INLINE_VISIBILITY reference front();
952 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
953 _LIBCPP_INLINE_VISIBILITY reference back();
954 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16955
Howard Hinnant2d72b1e2010-12-17 14:46:43956 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24957 basic_string& assign(__self_view __sv) { return assign(__sv.data(), __sv.size()); }
958 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29959 basic_string& assign(const basic_string& __str) { return *this = __str; }
Howard Hinnanta6119a82011-05-29 19:57:12960#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
961 _LIBCPP_INLINE_VISIBILITY
962 basic_string& assign(basic_string&& str)
Marshall Clow7ed093b2015-10-05 16:17:34963 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnant0949eed2011-06-30 21:18:19964 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12965#endif
Marshall Clowa93b5e22014-03-04 19:17:19966 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow1e00d6d2016-07-21 05:31:24967 _LIBCPP_INLINE_VISIBILITY
968 basic_string& assign(__self_view __sv, size_type pos, size_type n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19969 basic_string& assign(const value_type* __s, size_type __n);
970 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16971 basic_string& assign(size_type __n, value_type __c);
972 template<class _InputIterator>
973 typename enable_if
974 <
Marshall Clowdf9db312016-01-13 21:54:34975 __is_exactly_input_iterator<_InputIterator>::value
976 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16977 basic_string&
978 >::type
979 assign(_InputIterator __first, _InputIterator __last);
980 template<class _ForwardIterator>
981 typename enable_if
982 <
Marshall Clowdf9db312016-01-13 21:54:34983 __is_forward_iterator<_ForwardIterator>::value
984 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16985 basic_string&
986 >::type
987 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02988#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16990 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02991#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16992
Howard Hinnant2d72b1e2010-12-17 14:46:43993 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16994 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24995 _LIBCPP_INLINE_VISIBILITY
996 basic_string& insert(size_type __pos1, __self_view __sv) { return insert(__pos1, __sv.data(), __sv.size()); }
997 _LIBCPP_INLINE_VISIBILITY
998 basic_string& insert(size_type __pos1, __self_view __sv, size_type __pos2, size_type __n=npos);
Marshall Clowa93b5e22014-03-04 19:17:19999 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:191000 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1001 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:161002 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1003 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:431004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161005 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1006 template<class _InputIterator>
1007 typename enable_if
1008 <
Marshall Clowdf9db312016-01-13 21:54:341009 __is_exactly_input_iterator<_InputIterator>::value
1010 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161011 iterator
1012 >::type
1013 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1014 template<class _ForwardIterator>
1015 typename enable_if
1016 <
Marshall Clowdf9db312016-01-13 21:54:341017 __is_forward_iterator<_ForwardIterator>::value
1018 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161019 iterator
1020 >::type
1021 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:021022#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:071023 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161024 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1025 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:021026#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:161027
1028 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:431029 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161030 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:431031 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161032 iterator erase(const_iterator __first, const_iterator __last);
1033
Howard Hinnant2d72b1e2010-12-17 14:46:431034 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161035 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:241036 _LIBCPP_INLINE_VISIBILITY
1037 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:191038 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
Marshall Clow1e00d6d2016-07-21 05:31:241039 _LIBCPP_INLINE_VISIBILITY
1040 basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:191041 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1042 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:161043 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:431044 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:401045 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:431046 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:241047 basic_string& replace(const_iterator __i1, const_iterator __i2, __self_view __sv) { return replace(__i1 - begin(), __i2 - __i1, __sv); }
1048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191049 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:431050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191051 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:431052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:401053 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:161054 template<class _InputIterator>
1055 typename enable_if
1056 <
1057 __is_input_iterator<_InputIterator>::value,
1058 basic_string&
1059 >::type
Howard Hinnant7b2cb482010-11-17 21:11:401060 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:021061#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:071062 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:401063 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:161064 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:021065#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:161066
Howard Hinnant9dcdcde2013-06-28 16:59:191067 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:431068 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161069 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1070
Howard Hinnant2d72b1e2010-12-17 14:46:431071 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:471072 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:561073#if _LIBCPP_STD_VER >= 14
1074 _NOEXCEPT;
1075#else
1076 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1077 __is_nothrow_swappable<allocator_type>::value);
1078#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161079
Howard Hinnant2d72b1e2010-12-17 14:46:431080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191081 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:431082 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191083 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Marshall Clowf532a702016-03-08 15:44:301084#if _LIBCPP_STD_VER > 14
1085 _LIBCPP_INLINE_VISIBILITY
1086 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1087#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161088
Howard Hinnant2d72b1e2010-12-17 14:46:431089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121090 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:161091
Howard Hinnant2d72b1e2010-12-17 14:46:431092 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121093 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:241094 _LIBCPP_INLINE_VISIBILITY
1095 size_type find(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:191096 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:431097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191098 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:121099 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161100
Howard Hinnant2d72b1e2010-12-17 14:46:431101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121102 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:241103 _LIBCPP_INLINE_VISIBILITY
1104 size_type rfind(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:191105 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:431106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191107 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:121108 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161109
Howard Hinnant2d72b1e2010-12-17 14:46:431110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121111 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:241112 _LIBCPP_INLINE_VISIBILITY
1113 size_type find_first_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:191114 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:431115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191116 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:431117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121118 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161119
Howard Hinnant2d72b1e2010-12-17 14:46:431120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121121 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:241122 _LIBCPP_INLINE_VISIBILITY
1123 size_type find_last_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:191124 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:431125 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191126 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:431127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121128 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161129
Howard Hinnant2d72b1e2010-12-17 14:46:431130 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121131 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:241132 _LIBCPP_INLINE_VISIBILITY
1133 size_type find_first_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:191134 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:121135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191136 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:121137 _LIBCPP_INLINE_VISIBILITY
1138 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1139
1140 _LIBCPP_INLINE_VISIBILITY
1141 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:241142 _LIBCPP_INLINE_VISIBILITY
1143 size_type find_last_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:191144 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:121145 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191146 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:121147 _LIBCPP_INLINE_VISIBILITY
1148 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1149
1150 _LIBCPP_INLINE_VISIBILITY
1151 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:431152 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:241153 int compare(__self_view __sv) const _NOEXCEPT;
1154 _LIBCPP_INLINE_VISIBILITY
1155 int compare(size_type __pos1, size_type __n1, __self_view __sv) const;
1156 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161157 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:191158 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
Marshall Clow1e00d6d2016-07-21 05:31:241159 _LIBCPP_INLINE_VISIBILITY
1160 int compare(size_type __pos1, size_type __n1, __self_view __sv, size_type __pos2, size_type __n2=npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:191161 int compare(const value_type* __s) const _NOEXCEPT;
1162 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1163 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:161164
Howard Hinnant2d72b1e2010-12-17 14:46:431165 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:131166
1167 _LIBCPP_INLINE_VISIBILITY
1168 bool __is_long() const _NOEXCEPT
1169 {return bool(__r_.first().__s.__size_ & __short_mask);}
1170
Howard Hinnant499cea12013-08-23 17:37:051171#if _LIBCPP_DEBUG_LEVEL >= 2
1172
1173 bool __dereferenceable(const const_iterator* __i) const;
1174 bool __decrementable(const const_iterator* __i) const;
1175 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1176 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1177
1178#endif // _LIBCPP_DEBUG_LEVEL >= 2
1179
Howard Hinnantbc8d3f92010-05-11 19:42:161180private:
Howard Hinnanta6119a82011-05-29 19:57:121181 _LIBCPP_INLINE_VISIBILITY
1182 allocator_type& __alloc() _NOEXCEPT
1183 {return __r_.second();}
1184 _LIBCPP_INLINE_VISIBILITY
1185 const allocator_type& __alloc() const _NOEXCEPT
1186 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:161187
Evgeniy Stepanov4f01aa82015-10-13 23:48:281188#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:481189
Howard Hinnanta6119a82011-05-29 19:57:121190 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:121191 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:481192# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:161193 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:481194# else
1195 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1196# endif
1197
Howard Hinnanta6119a82011-05-29 19:57:121198 _LIBCPP_INLINE_VISIBILITY
1199 size_type __get_short_size() const _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:481200# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:161201 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:481202# else
1203 {return __r_.first().__s.__size_;}
1204# endif
1205
Evgeniy Stepanov4f01aa82015-10-13 23:48:281206#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:481207
1208 _LIBCPP_INLINE_VISIBILITY
1209 void __set_short_size(size_type __s) _NOEXCEPT
1210# if _LIBCPP_BIG_ENDIAN
1211 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1212# else
1213 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1214# endif
1215
1216 _LIBCPP_INLINE_VISIBILITY
1217 size_type __get_short_size() const _NOEXCEPT
1218# if _LIBCPP_BIG_ENDIAN
1219 {return __r_.first().__s.__size_;}
1220# else
1221 {return __r_.first().__s.__size_ >> 1;}
1222# endif
1223
Evgeniy Stepanov4f01aa82015-10-13 23:48:281224#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:481225
Howard Hinnanta6119a82011-05-29 19:57:121226 _LIBCPP_INLINE_VISIBILITY
1227 void __set_long_size(size_type __s) _NOEXCEPT
1228 {__r_.first().__l.__size_ = __s;}
1229 _LIBCPP_INLINE_VISIBILITY
1230 size_type __get_long_size() const _NOEXCEPT
1231 {return __r_.first().__l.__size_;}
1232 _LIBCPP_INLINE_VISIBILITY
1233 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161234 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1235
Howard Hinnanta6119a82011-05-29 19:57:121236 _LIBCPP_INLINE_VISIBILITY
1237 void __set_long_cap(size_type __s) _NOEXCEPT
1238 {__r_.first().__l.__cap_ = __long_mask | __s;}
1239 _LIBCPP_INLINE_VISIBILITY
1240 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:041241 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:161242
Howard Hinnanta6119a82011-05-29 19:57:121243 _LIBCPP_INLINE_VISIBILITY
1244 void __set_long_pointer(pointer __p) _NOEXCEPT
1245 {__r_.first().__l.__data_ = __p;}
1246 _LIBCPP_INLINE_VISIBILITY
1247 pointer __get_long_pointer() _NOEXCEPT
1248 {return __r_.first().__l.__data_;}
1249 _LIBCPP_INLINE_VISIBILITY
1250 const_pointer __get_long_pointer() const _NOEXCEPT
1251 {return __r_.first().__l.__data_;}
1252 _LIBCPP_INLINE_VISIBILITY
1253 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:191254 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:121255 _LIBCPP_INLINE_VISIBILITY
1256 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:191257 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:121258 _LIBCPP_INLINE_VISIBILITY
1259 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161260 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:121261 _LIBCPP_INLINE_VISIBILITY
1262 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161263 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1264
Howard Hinnanta6119a82011-05-29 19:57:121265 _LIBCPP_INLINE_VISIBILITY
1266 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161267 {
1268 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1269 for (unsigned __i = 0; __i < __n_words; ++__i)
1270 __a[__i] = 0;
1271 }
1272
1273 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:121274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:201275 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:421276 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:161277 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:121278 static _LIBCPP_INLINE_VISIBILITY
1279 size_type __recommend(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:421280 {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
Howard Hinnant7f764502013-08-14 18:00:201281 __align_it<sizeof(value_type) < __alignment ?
Howard Hinnanta6119a82011-05-29 19:57:121282 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:161283
Howard Hinnant9dcdcde2013-06-28 16:59:191284 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1285 void __init(const value_type* __s, size_type __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:161286 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:431287
Howard Hinnantbc8d3f92010-05-11 19:42:161288 template <class _InputIterator>
1289 typename enable_if
1290 <
Marshall Clowdf9db312016-01-13 21:54:341291 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161292 void
1293 >::type
1294 __init(_InputIterator __first, _InputIterator __last);
1295
1296 template <class _ForwardIterator>
1297 typename enable_if
1298 <
1299 __is_forward_iterator<_ForwardIterator>::value,
1300 void
1301 >::type
1302 __init(_ForwardIterator __first, _ForwardIterator __last);
1303
1304 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:431305 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:161306 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1307 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:191308 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:161309
Howard Hinnant2d72b1e2010-12-17 14:46:431310 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161311 void __erase_to_end(size_type __pos);
1312
Howard Hinnante32b5e22010-11-17 17:55:081313 _LIBCPP_INLINE_VISIBILITY
1314 void __copy_assign_alloc(const basic_string& __str)
1315 {__copy_assign_alloc(__str, integral_constant<bool,
1316 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1317
1318 _LIBCPP_INLINE_VISIBILITY
1319 void __copy_assign_alloc(const basic_string& __str, true_type)
1320 {
1321 if (__alloc() != __str.__alloc())
1322 {
1323 clear();
1324 shrink_to_fit();
1325 }
1326 __alloc() = __str.__alloc();
1327 }
1328
1329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:041330 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:081331 {}
1332
1333#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:431334 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:001335 void __move_assign(basic_string& __str, false_type)
1336 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:431337 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:471338 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:001339#if _LIBCPP_STD_VER > 14
1340 _NOEXCEPT;
1341#else
Howard Hinnant53f7d4c2011-06-03 18:40:471342 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:081343#endif
Marshall Clowaf961ed2015-08-18 18:57:001344#endif
Howard Hinnante32b5e22010-11-17 17:55:081345
1346 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:181347 void
Howard Hinnant9cbee432011-09-02 20:42:311348 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:181349 _NOEXCEPT_(
1350 !__alloc_traits::propagate_on_container_move_assignment::value ||
1351 is_nothrow_move_assignable<allocator_type>::value)
1352 {__move_assign_alloc(__str, integral_constant<bool,
1353 __alloc_traits::propagate_on_container_move_assignment::value>());}
1354
1355 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:311356 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:181357 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1358 {
1359 __alloc() = _VSTD::move(__c.__alloc());
1360 }
1361
1362 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:041363 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:181364 _NOEXCEPT
1365 {}
1366
Howard Hinnant2d72b1e2010-12-17 14:46:431367 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1368 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:161369
1370 friend basic_string operator+<>(const basic_string&, const basic_string&);
1371 friend basic_string operator+<>(const value_type*, const basic_string&);
1372 friend basic_string operator+<>(value_type, const basic_string&);
1373 friend basic_string operator+<>(const basic_string&, const value_type*);
1374 friend basic_string operator+<>(const basic_string&, value_type);
1375};
1376
1377template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001378inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161379void
1380basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1381{
Howard Hinnant499cea12013-08-23 17:37:051382#if _LIBCPP_DEBUG_LEVEL >= 2
1383 __get_db()->__invalidate_all(this);
1384#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:161385}
1386
1387template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001388inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161389void
Howard Hinnantec3773c2011-12-01 20:21:041390basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:051391#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:041392 __pos
1393#endif
1394 )
Howard Hinnantbc8d3f92010-05-11 19:42:161395{
Howard Hinnant499cea12013-08-23 17:37:051396#if _LIBCPP_DEBUG_LEVEL >= 2
1397 __c_node* __c = __get_db()->__find_c_and_lock(this);
1398 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:161399 {
Howard Hinnant499cea12013-08-23 17:37:051400 const_pointer __new_last = __get_pointer() + __pos;
1401 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:161402 {
Howard Hinnant499cea12013-08-23 17:37:051403 --__p;
1404 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1405 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:161406 {
Howard Hinnant499cea12013-08-23 17:37:051407 (*__p)->__c_ = nullptr;
1408 if (--__c->end_ != __p)
1409 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:161410 }
Howard Hinnantbc8d3f92010-05-11 19:42:161411 }
Howard Hinnant499cea12013-08-23 17:37:051412 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:161413 }
Howard Hinnant499cea12013-08-23 17:37:051414#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:161415}
1416
1417template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001418inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:471419basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:411420 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161421{
Howard Hinnant499cea12013-08-23 17:37:051422#if _LIBCPP_DEBUG_LEVEL >= 2
1423 __get_db()->__insert_c(this);
1424#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161425 __zero();
1426}
1427
1428template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001429inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161430basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:461431#if _LIBCPP_STD_VER <= 14
1432 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1433#else
1434 _NOEXCEPT
1435#endif
1436: __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:161437{
Howard Hinnant499cea12013-08-23 17:37:051438#if _LIBCPP_DEBUG_LEVEL >= 2
1439 __get_db()->__insert_c(this);
1440#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161441 __zero();
1442}
1443
1444template <class _CharT, class _Traits, class _Allocator>
1445void
Howard Hinnant9dcdcde2013-06-28 16:59:191446basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:161447{
1448 if (__reserve > max_size())
1449 this->__throw_length_error();
1450 pointer __p;
1451 if (__reserve < __min_cap)
1452 {
1453 __set_short_size(__sz);
1454 __p = __get_short_pointer();
1455 }
1456 else
1457 {
1458 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:081459 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161460 __set_long_pointer(__p);
1461 __set_long_cap(__cap+1);
1462 __set_long_size(__sz);
1463 }
Howard Hinnant9dcdcde2013-06-28 16:59:191464 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:161465 traits_type::assign(__p[__sz], value_type());
1466}
1467
1468template <class _CharT, class _Traits, class _Allocator>
1469void
Howard Hinnant9dcdcde2013-06-28 16:59:191470basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:161471{
1472 if (__sz > max_size())
1473 this->__throw_length_error();
1474 pointer __p;
1475 if (__sz < __min_cap)
1476 {
1477 __set_short_size(__sz);
1478 __p = __get_short_pointer();
1479 }
1480 else
1481 {
1482 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:081483 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161484 __set_long_pointer(__p);
1485 __set_long_cap(__cap+1);
1486 __set_long_size(__sz);
1487 }
Howard Hinnant9dcdcde2013-06-28 16:59:191488 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:161489 traits_type::assign(__p[__sz], value_type());
1490}
1491
1492template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001493inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191494basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:161495{
Howard Hinnant499cea12013-08-23 17:37:051496 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:161497 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:051498#if _LIBCPP_DEBUG_LEVEL >= 2
1499 __get_db()->__insert_c(this);
1500#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161501}
1502
1503template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001504inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191505basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:161506 : __r_(__a)
1507{
Howard Hinnant499cea12013-08-23 17:37:051508 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:161509 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:051510#if _LIBCPP_DEBUG_LEVEL >= 2
1511 __get_db()->__insert_c(this);
1512#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161513}
1514
1515template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001516inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191517basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:161518{
Howard Hinnant499cea12013-08-23 17:37:051519 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:161520 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:051521#if _LIBCPP_DEBUG_LEVEL >= 2
1522 __get_db()->__insert_c(this);
1523#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161524}
1525
1526template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001527inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:191528basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:161529 : __r_(__a)
1530{
Howard Hinnant499cea12013-08-23 17:37:051531 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:161532 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:051533#if _LIBCPP_DEBUG_LEVEL >= 2
1534 __get_db()->__insert_c(this);
1535#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161536}
1537
1538template <class _CharT, class _Traits, class _Allocator>
1539basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:081540 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:161541{
1542 if (!__str.__is_long())
1543 __r_.first().__r = __str.__r_.first().__r;
1544 else
Howard Hinnant9dcdcde2013-06-28 16:59:191545 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:051546#if _LIBCPP_DEBUG_LEVEL >= 2
1547 __get_db()->__insert_c(this);
1548#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161549}
1550
1551template <class _CharT, class _Traits, class _Allocator>
1552basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
1553 : __r_(__a)
1554{
1555 if (!__str.__is_long())
1556 __r_.first().__r = __str.__r_.first().__r;
1557 else
Howard Hinnant9dcdcde2013-06-28 16:59:191558 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:051559#if _LIBCPP_DEBUG_LEVEL >= 2
1560 __get_db()->__insert_c(this);
1561#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161562}
1563
Howard Hinnant73d21a42010-09-04 23:28:191564#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161565
1566template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001567inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:471568basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:431569#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:471570 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:431571#else
1572 _NOEXCEPT
1573#endif
Howard Hinnant0949eed2011-06-30 21:18:191574 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:161575{
1576 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:051577#if _LIBCPP_DEBUG_LEVEL >= 2
1578 __get_db()->__insert_c(this);
1579 if (__is_long())
1580 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:161581#endif
1582}
1583
1584template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001585inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161586basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:081587 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:161588{
Marshall Clowd5549cc2014-07-17 15:32:201589 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:191590 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:201591 else
1592 {
1593 __r_.first().__r = __str.__r_.first().__r;
1594 __str.__zero();
1595 }
Howard Hinnant499cea12013-08-23 17:37:051596#if _LIBCPP_DEBUG_LEVEL >= 2
1597 __get_db()->__insert_c(this);
1598 if (__is_long())
1599 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:161600#endif
1601}
1602
Howard Hinnant73d21a42010-09-04 23:28:191603#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161604
1605template <class _CharT, class _Traits, class _Allocator>
1606void
1607basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1608{
1609 if (__n > max_size())
1610 this->__throw_length_error();
1611 pointer __p;
1612 if (__n < __min_cap)
1613 {
1614 __set_short_size(__n);
1615 __p = __get_short_pointer();
1616 }
1617 else
1618 {
1619 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:081620 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161621 __set_long_pointer(__p);
1622 __set_long_cap(__cap+1);
1623 __set_long_size(__n);
1624 }
Howard Hinnant9dcdcde2013-06-28 16:59:191625 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:161626 traits_type::assign(__p[__n], value_type());
1627}
1628
1629template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001630inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161631basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
1632{
1633 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:051634#if _LIBCPP_DEBUG_LEVEL >= 2
1635 __get_db()->__insert_c(this);
1636#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161637}
1638
1639template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001640inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161641basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
1642 : __r_(__a)
1643{
1644 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:051645#if _LIBCPP_DEBUG_LEVEL >= 2
1646 __get_db()->__insert_c(this);
1647#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161648}
1649
Howard Hinnantbc8d3f92010-05-11 19:42:161650template <class _CharT, class _Traits, class _Allocator>
1651basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
1652 const allocator_type& __a)
1653 : __r_(__a)
1654{
1655 size_type __str_sz = __str.size();
1656 if (__pos > __str_sz)
1657 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:191658 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:051659#if _LIBCPP_DEBUG_LEVEL >= 2
1660 __get_db()->__insert_c(this);
1661#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161662}
1663
1664template <class _CharT, class _Traits, class _Allocator>
Marshall Clowf4f7d8f2016-04-07 18:13:411665inline _LIBCPP_INLINE_VISIBILITY
1666basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
1667 const allocator_type& __a)
1668 : __r_(__a)
1669{
1670 size_type __str_sz = __str.size();
1671 if (__pos > __str_sz)
1672 this->__throw_out_of_range();
1673 __init(__str.data() + __pos, __str_sz - __pos);
1674#if _LIBCPP_DEBUG_LEVEL >= 2
1675 __get_db()->__insert_c(this);
1676#endif
1677}
1678
1679template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:241680inline _LIBCPP_INLINE_VISIBILITY
1681basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv)
1682{
1683 __init(__sv.data(), __sv.size());
1684#if _LIBCPP_DEBUG_LEVEL >= 2
1685 __get_db()->__insert_c(this);
1686#endif
1687}
1688
1689template <class _CharT, class _Traits, class _Allocator>
1690inline _LIBCPP_INLINE_VISIBILITY
1691basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const allocator_type& __a)
1692 : __r_(__a)
1693{
1694 __init(__sv.data(), __sv.size());
1695#if _LIBCPP_DEBUG_LEVEL >= 2
1696 __get_db()->__insert_c(this);
1697#endif
1698}
1699
1700template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161701template <class _InputIterator>
1702typename enable_if
1703<
Marshall Clowdf9db312016-01-13 21:54:341704 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161705 void
1706>::type
1707basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
1708{
1709 __zero();
1710#ifndef _LIBCPP_NO_EXCEPTIONS
1711 try
1712 {
Howard Hinnant324bb032010-08-22 00:02:431713#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161714 for (; __first != __last; ++__first)
1715 push_back(*__first);
1716#ifndef _LIBCPP_NO_EXCEPTIONS
1717 }
1718 catch (...)
1719 {
1720 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:081721 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:161722 throw;
1723 }
Howard Hinnant324bb032010-08-22 00:02:431724#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161725}
1726
1727template <class _CharT, class _Traits, class _Allocator>
1728template <class _ForwardIterator>
1729typename enable_if
1730<
1731 __is_forward_iterator<_ForwardIterator>::value,
1732 void
1733>::type
1734basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
1735{
Howard Hinnant0949eed2011-06-30 21:18:191736 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:161737 if (__sz > max_size())
1738 this->__throw_length_error();
1739 pointer __p;
1740 if (__sz < __min_cap)
1741 {
1742 __set_short_size(__sz);
1743 __p = __get_short_pointer();
1744 }
1745 else
1746 {
1747 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:081748 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161749 __set_long_pointer(__p);
1750 __set_long_cap(__cap+1);
1751 __set_long_size(__sz);
1752 }
Eric Fiselierb9919752014-10-27 19:28:201753 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:161754 traits_type::assign(*__p, *__first);
1755 traits_type::assign(*__p, value_type());
1756}
1757
1758template <class _CharT, class _Traits, class _Allocator>
1759template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:001760inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161761basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
1762{
1763 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:051764#if _LIBCPP_DEBUG_LEVEL >= 2
1765 __get_db()->__insert_c(this);
1766#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161767}
1768
1769template <class _CharT, class _Traits, class _Allocator>
1770template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:001771inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161772basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
1773 const allocator_type& __a)
1774 : __r_(__a)
1775{
1776 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:051777#if _LIBCPP_DEBUG_LEVEL >= 2
1778 __get_db()->__insert_c(this);
1779#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161780}
1781
Howard Hinnante3e32912011-08-12 21:56:021782#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1783
Howard Hinnantbc8d3f92010-05-11 19:42:161784template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001785inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161786basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
1787{
1788 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:051789#if _LIBCPP_DEBUG_LEVEL >= 2
1790 __get_db()->__insert_c(this);
1791#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161792}
1793
1794template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001795inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161796basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
1797 : __r_(__a)
1798{
1799 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:051800#if _LIBCPP_DEBUG_LEVEL >= 2
1801 __get_db()->__insert_c(this);
1802#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161803}
1804
Howard Hinnante3e32912011-08-12 21:56:021805#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1806
Howard Hinnantbc8d3f92010-05-11 19:42:161807template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161808basic_string<_CharT, _Traits, _Allocator>::~basic_string()
1809{
Howard Hinnant499cea12013-08-23 17:37:051810#if _LIBCPP_DEBUG_LEVEL >= 2
1811 __get_db()->__erase_c(this);
1812#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161813 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:081814 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:161815}
1816
1817template <class _CharT, class _Traits, class _Allocator>
1818void
1819basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
1820 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:191821 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
Howard Hinnantbc8d3f92010-05-11 19:42:161822{
1823 size_type __ms = max_size();
1824 if (__delta_cap > __ms - __old_cap - 1)
1825 this->__throw_length_error();
1826 pointer __old_p = __get_pointer();
1827 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:191828 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:161829 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:081830 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161831 __invalidate_all_iterators();
1832 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:191833 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1834 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:161835 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:191836 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:161837 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1838 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:191839 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1840 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:161841 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:081842 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161843 __set_long_pointer(__p);
1844 __set_long_cap(__cap+1);
1845 __old_sz = __n_copy + __n_add + __sec_cp_sz;
1846 __set_long_size(__old_sz);
1847 traits_type::assign(__p[__old_sz], value_type());
1848}
1849
1850template <class _CharT, class _Traits, class _Allocator>
1851void
1852basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1853 size_type __n_copy, size_type __n_del, size_type __n_add)
1854{
1855 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:381856 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:161857 this->__throw_length_error();
1858 pointer __old_p = __get_pointer();
1859 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:191860 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:161861 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:081862 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161863 __invalidate_all_iterators();
1864 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:191865 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1866 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:161867 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1868 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:191869 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1870 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
1871 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:161872 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:081873 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:161874 __set_long_pointer(__p);
1875 __set_long_cap(__cap+1);
1876}
1877
1878// assign
1879
1880template <class _CharT, class _Traits, class _Allocator>
1881basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:191882basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:161883{
Alp Tokerec34c482014-05-15 11:27:391884 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:161885 size_type __cap = capacity();
1886 if (__cap >= __n)
1887 {
Howard Hinnant9dcdcde2013-06-28 16:59:191888 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:161889 traits_type::move(__p, __s, __n);
1890 traits_type::assign(__p[__n], value_type());
1891 __set_size(__n);
1892 __invalidate_iterators_past(__n);
1893 }
1894 else
1895 {
1896 size_type __sz = size();
1897 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
1898 }
1899 return *this;
1900}
1901
1902template <class _CharT, class _Traits, class _Allocator>
1903basic_string<_CharT, _Traits, _Allocator>&
1904basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
1905{
1906 size_type __cap = capacity();
1907 if (__cap < __n)
1908 {
1909 size_type __sz = size();
1910 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
1911 }
1912 else
1913 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:191914 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:161915 traits_type::assign(__p, __n, __c);
1916 traits_type::assign(__p[__n], value_type());
1917 __set_size(__n);
1918 return *this;
1919}
1920
1921template <class _CharT, class _Traits, class _Allocator>
1922basic_string<_CharT, _Traits, _Allocator>&
1923basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
1924{
1925 pointer __p;
1926 if (__is_long())
1927 {
1928 __p = __get_long_pointer();
1929 __set_long_size(1);
1930 }
1931 else
1932 {
1933 __p = __get_short_pointer();
1934 __set_short_size(1);
1935 }
1936 traits_type::assign(*__p, __c);
1937 traits_type::assign(*++__p, value_type());
1938 __invalidate_iterators_past(1);
1939 return *this;
1940}
1941
1942template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:081943basic_string<_CharT, _Traits, _Allocator>&
1944basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
1945{
1946 if (this != &__str)
1947 {
1948 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:291949 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:081950 }
1951 return *this;
1952}
1953
1954#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1955
1956template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001957inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:081958void
1959basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:001960 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:081961{
1962 if (__alloc() != __str.__alloc())
1963 assign(__str);
1964 else
1965 __move_assign(__str, true_type());
1966}
1967
1968template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001969inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:081970void
1971basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:001972#if _LIBCPP_STD_VER > 14
1973 _NOEXCEPT
1974#else
Howard Hinnant53f7d4c2011-06-03 18:40:471975 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:001976#endif
Howard Hinnante32b5e22010-11-17 17:55:081977{
1978 clear();
1979 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:181980 __r_.first() = __str.__r_.first();
1981 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:081982 __str.__zero();
1983}
1984
1985template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001986inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:081987basic_string<_CharT, _Traits, _Allocator>&
1988basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:001989 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:081990{
1991 __move_assign(__str, integral_constant<bool,
1992 __alloc_traits::propagate_on_container_move_assignment::value>());
1993 return *this;
1994}
1995
1996#endif
1997
1998template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161999template<class _InputIterator>
2000typename enable_if
2001<
Marshall Clowdf9db312016-01-13 21:54:342002 __is_exactly_input_iterator <_InputIterator>::value
2003 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:162004 basic_string<_CharT, _Traits, _Allocator>&
2005>::type
2006basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2007{
Marshall Clowdf9db312016-01-13 21:54:342008 basic_string __temp(__first, __last, __alloc());
2009 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:452010 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:162011}
2012
2013template <class _CharT, class _Traits, class _Allocator>
2014template<class _ForwardIterator>
2015typename enable_if
2016<
Marshall Clowdf9db312016-01-13 21:54:342017 __is_forward_iterator<_ForwardIterator>::value
2018 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:162019 basic_string<_CharT, _Traits, _Allocator>&
2020>::type
2021basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2022{
Howard Hinnant0949eed2011-06-30 21:18:192023 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:162024 size_type __cap = capacity();
2025 if (__cap < __n)
2026 {
2027 size_type __sz = size();
2028 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2029 }
2030 else
2031 __invalidate_iterators_past(__n);
2032 pointer __p = __get_pointer();
2033 for (; __first != __last; ++__first, ++__p)
2034 traits_type::assign(*__p, *__first);
2035 traits_type::assign(*__p, value_type());
2036 __set_size(__n);
2037 return *this;
2038}
2039
2040template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:162041basic_string<_CharT, _Traits, _Allocator>&
2042basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2043{
2044 size_type __sz = __str.size();
2045 if (__pos > __sz)
2046 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:192047 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:162048}
2049
2050template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:242051inline _LIBCPP_INLINE_VISIBILITY
2052basic_string<_CharT, _Traits, _Allocator>&
2053basic_string<_CharT, _Traits, _Allocator>::assign(__self_view __sv, size_type __pos, size_type __n)
2054{
2055 size_type __sz = __sv.size();
2056 if (__pos > __sz)
2057 this->__throw_out_of_range();
2058 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2059}
2060
2061
2062template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:162063basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192064basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:162065{
Alp Tokerec34c482014-05-15 11:27:392066 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:162067 return assign(__s, traits_type::length(__s));
2068}
2069
2070// append
2071
2072template <class _CharT, class _Traits, class _Allocator>
2073basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192074basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:162075{
Alp Tokerec34c482014-05-15 11:27:392076 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:162077 size_type __cap = capacity();
2078 size_type __sz = size();
2079 if (__cap - __sz >= __n)
2080 {
2081 if (__n)
2082 {
Howard Hinnant9dcdcde2013-06-28 16:59:192083 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162084 traits_type::copy(__p + __sz, __s, __n);
2085 __sz += __n;
2086 __set_size(__sz);
2087 traits_type::assign(__p[__sz], value_type());
2088 }
2089 }
2090 else
2091 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2092 return *this;
2093}
2094
2095template <class _CharT, class _Traits, class _Allocator>
2096basic_string<_CharT, _Traits, _Allocator>&
2097basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2098{
2099 if (__n)
2100 {
2101 size_type __cap = capacity();
2102 size_type __sz = size();
2103 if (__cap - __sz < __n)
2104 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2105 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:192106 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:162107 __sz += __n;
2108 __set_size(__sz);
2109 traits_type::assign(__p[__sz], value_type());
2110 }
2111 return *this;
2112}
2113
2114template <class _CharT, class _Traits, class _Allocator>
2115void
2116basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2117{
Howard Hinnant15467182013-04-30 21:44:482118 bool __is_short = !__is_long();
2119 size_type __cap;
2120 size_type __sz;
2121 if (__is_short)
2122 {
2123 __cap = __min_cap - 1;
2124 __sz = __get_short_size();
2125 }
2126 else
2127 {
2128 __cap = __get_long_cap() - 1;
2129 __sz = __get_long_size();
2130 }
Howard Hinnantbc8d3f92010-05-11 19:42:162131 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:482132 {
Howard Hinnantbc8d3f92010-05-11 19:42:162133 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:482134 __is_short = !__is_long();
2135 }
2136 pointer __p;
2137 if (__is_short)
2138 {
2139 __p = __get_short_pointer() + __sz;
2140 __set_short_size(__sz+1);
2141 }
2142 else
2143 {
2144 __p = __get_long_pointer() + __sz;
2145 __set_long_size(__sz+1);
2146 }
Howard Hinnantbc8d3f92010-05-11 19:42:162147 traits_type::assign(*__p, __c);
2148 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:162149}
2150
2151template <class _CharT, class _Traits, class _Allocator>
2152template<class _InputIterator>
2153typename enable_if
2154<
Marshall Clowdf9db312016-01-13 21:54:342155 __is_exactly_input_iterator<_InputIterator>::value
2156 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:162157 basic_string<_CharT, _Traits, _Allocator>&
2158>::type
2159basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2160{
Marshall Clow1e00d6d2016-07-21 05:31:242161 basic_string __temp (__first, __last, __alloc());
2162 append(__temp.data(), __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:162163 return *this;
2164}
2165
2166template <class _CharT, class _Traits, class _Allocator>
2167template<class _ForwardIterator>
2168typename enable_if
2169<
Marshall Clowdf9db312016-01-13 21:54:342170 __is_forward_iterator<_ForwardIterator>::value
2171 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:162172 basic_string<_CharT, _Traits, _Allocator>&
2173>::type
2174basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2175{
2176 size_type __sz = size();
2177 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:192178 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:162179 if (__n)
2180 {
2181 if (__cap - __sz < __n)
2182 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2183 pointer __p = __get_pointer() + __sz;
2184 for (; __first != __last; ++__p, ++__first)
2185 traits_type::assign(*__p, *__first);
2186 traits_type::assign(*__p, value_type());
2187 __set_size(__sz + __n);
2188 }
2189 return *this;
2190}
2191
2192template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002193inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162194basic_string<_CharT, _Traits, _Allocator>&
2195basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2196{
2197 return append(__str.data(), __str.size());
2198}
2199
2200template <class _CharT, class _Traits, class _Allocator>
2201basic_string<_CharT, _Traits, _Allocator>&
2202basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2203{
2204 size_type __sz = __str.size();
2205 if (__pos > __sz)
2206 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:192207 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:162208}
2209
2210template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:242211inline _LIBCPP_INLINE_VISIBILITY
2212basic_string<_CharT, _Traits, _Allocator>&
2213basic_string<_CharT, _Traits, _Allocator>::append(__self_view __sv, size_type __pos, size_type __n)
2214{
2215 size_type __sz = __sv.size();
2216 if (__pos > __sz)
2217 this->__throw_out_of_range();
2218 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2219}
2220
2221template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:162222basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192223basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:162224{
Alp Tokerec34c482014-05-15 11:27:392225 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:162226 return append(__s, traits_type::length(__s));
2227}
2228
2229// insert
2230
2231template <class _CharT, class _Traits, class _Allocator>
2232basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192233basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:162234{
Alp Tokerec34c482014-05-15 11:27:392235 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:162236 size_type __sz = size();
2237 if (__pos > __sz)
2238 this->__throw_out_of_range();
2239 size_type __cap = capacity();
2240 if (__cap - __sz >= __n)
2241 {
2242 if (__n)
2243 {
Howard Hinnant9dcdcde2013-06-28 16:59:192244 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162245 size_type __n_move = __sz - __pos;
2246 if (__n_move != 0)
2247 {
2248 if (__p + __pos <= __s && __s < __p + __sz)
2249 __s += __n;
2250 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2251 }
2252 traits_type::move(__p + __pos, __s, __n);
2253 __sz += __n;
2254 __set_size(__sz);
2255 traits_type::assign(__p[__sz], value_type());
2256 }
2257 }
2258 else
2259 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2260 return *this;
2261}
2262
2263template <class _CharT, class _Traits, class _Allocator>
2264basic_string<_CharT, _Traits, _Allocator>&
2265basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2266{
2267 size_type __sz = size();
2268 if (__pos > __sz)
2269 this->__throw_out_of_range();
2270 if (__n)
2271 {
2272 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:192273 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:162274 if (__cap - __sz >= __n)
2275 {
Howard Hinnant9dcdcde2013-06-28 16:59:192276 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162277 size_type __n_move = __sz - __pos;
2278 if (__n_move != 0)
2279 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2280 }
2281 else
2282 {
2283 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:192284 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162285 }
2286 traits_type::assign(__p + __pos, __n, __c);
2287 __sz += __n;
2288 __set_size(__sz);
2289 traits_type::assign(__p[__sz], value_type());
2290 }
2291 return *this;
2292}
2293
2294template <class _CharT, class _Traits, class _Allocator>
2295template<class _InputIterator>
2296typename enable_if
2297<
Marshall Clowdf9db312016-01-13 21:54:342298 __is_exactly_input_iterator<_InputIterator>::value
2299 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2300 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:162301>::type
2302basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2303{
Howard Hinnant499cea12013-08-23 17:37:052304#if _LIBCPP_DEBUG_LEVEL >= 2
2305 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2306 "string::insert(iterator, range) called with an iterator not"
2307 " referring to this string");
2308#endif
Marshall Clowdf9db312016-01-13 21:54:342309 basic_string __temp(__first, __last, __alloc());
2310 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:162311}
2312
2313template <class _CharT, class _Traits, class _Allocator>
2314template<class _ForwardIterator>
2315typename enable_if
2316<
Marshall Clowdf9db312016-01-13 21:54:342317 __is_forward_iterator<_ForwardIterator>::value
2318 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:162319 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2320>::type
2321basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2322{
Howard Hinnant499cea12013-08-23 17:37:052323#if _LIBCPP_DEBUG_LEVEL >= 2
2324 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2325 "string::insert(iterator, range) called with an iterator not"
2326 " referring to this string");
2327#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162328 size_type __ip = static_cast<size_type>(__pos - begin());
2329 size_type __sz = size();
2330 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:192331 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:162332 if (__n)
2333 {
Howard Hinnant9dcdcde2013-06-28 16:59:192334 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:162335 if (__cap - __sz >= __n)
2336 {
Howard Hinnant9dcdcde2013-06-28 16:59:192337 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162338 size_type __n_move = __sz - __ip;
2339 if (__n_move != 0)
2340 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2341 }
2342 else
2343 {
2344 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:192345 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162346 }
2347 __sz += __n;
2348 __set_size(__sz);
2349 traits_type::assign(__p[__sz], value_type());
2350 for (__p += __ip; __first != __last; ++__p, ++__first)
2351 traits_type::assign(*__p, *__first);
2352 }
2353 return begin() + __ip;
2354}
2355
2356template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002357inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162358basic_string<_CharT, _Traits, _Allocator>&
2359basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2360{
2361 return insert(__pos1, __str.data(), __str.size());
2362}
2363
2364template <class _CharT, class _Traits, class _Allocator>
2365basic_string<_CharT, _Traits, _Allocator>&
2366basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2367 size_type __pos2, size_type __n)
2368{
2369 size_type __str_sz = __str.size();
2370 if (__pos2 > __str_sz)
2371 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:192372 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:162373}
2374
2375template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:242376inline _LIBCPP_INLINE_VISIBILITY
2377basic_string<_CharT, _Traits, _Allocator>&
2378basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, __self_view __sv,
2379 size_type __pos2, size_type __n)
2380{
2381 size_type __str_sz = __sv.size();
2382 if (__pos2 > __str_sz)
2383 this->__throw_out_of_range();
2384 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2385}
2386
2387template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:162388basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192389basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:162390{
Alp Tokerec34c482014-05-15 11:27:392391 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:162392 return insert(__pos, __s, traits_type::length(__s));
2393}
2394
2395template <class _CharT, class _Traits, class _Allocator>
2396typename basic_string<_CharT, _Traits, _Allocator>::iterator
2397basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2398{
2399 size_type __ip = static_cast<size_type>(__pos - begin());
2400 size_type __sz = size();
2401 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:192402 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:162403 if (__cap == __sz)
2404 {
2405 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:192406 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162407 }
2408 else
2409 {
Howard Hinnant9dcdcde2013-06-28 16:59:192410 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162411 size_type __n_move = __sz - __ip;
2412 if (__n_move != 0)
2413 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2414 }
2415 traits_type::assign(__p[__ip], __c);
2416 traits_type::assign(__p[++__sz], value_type());
2417 __set_size(__sz);
2418 return begin() + static_cast<difference_type>(__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:162423typename basic_string<_CharT, _Traits, _Allocator>::iterator
2424basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2425{
Howard Hinnant499cea12013-08-23 17:37:052426#if _LIBCPP_DEBUG_LEVEL >= 2
2427 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2428 "string::insert(iterator, n, value) called with an iterator not"
2429 " referring to this string");
2430#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162431 difference_type __p = __pos - begin();
2432 insert(static_cast<size_type>(__p), __n, __c);
2433 return begin() + __p;
2434}
2435
2436// replace
2437
2438template <class _CharT, class _Traits, class _Allocator>
2439basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192440basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
Howard Hinnantbc8d3f92010-05-11 19:42:162441{
Alp Tokerec34c482014-05-15 11:27:392442 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:162443 size_type __sz = size();
2444 if (__pos > __sz)
2445 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:192446 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:162447 size_type __cap = capacity();
2448 if (__cap - __sz + __n1 >= __n2)
2449 {
Howard Hinnant9dcdcde2013-06-28 16:59:192450 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162451 if (__n1 != __n2)
2452 {
2453 size_type __n_move = __sz - __pos - __n1;
2454 if (__n_move != 0)
2455 {
2456 if (__n1 > __n2)
2457 {
2458 traits_type::move(__p + __pos, __s, __n2);
2459 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2460 goto __finish;
2461 }
2462 if (__p + __pos < __s && __s < __p + __sz)
2463 {
2464 if (__p + __pos + __n1 <= __s)
2465 __s += __n2 - __n1;
2466 else // __p + __pos < __s < __p + __pos + __n1
2467 {
2468 traits_type::move(__p + __pos, __s, __n1);
2469 __pos += __n1;
2470 __s += __n2;
2471 __n2 -= __n1;
2472 __n1 = 0;
2473 }
2474 }
2475 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2476 }
2477 }
2478 traits_type::move(__p + __pos, __s, __n2);
2479__finish:
2480 __sz += __n2 - __n1;
2481 __set_size(__sz);
2482 __invalidate_iterators_past(__sz);
2483 traits_type::assign(__p[__sz], value_type());
2484 }
2485 else
2486 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2487 return *this;
2488}
2489
2490template <class _CharT, class _Traits, class _Allocator>
2491basic_string<_CharT, _Traits, _Allocator>&
2492basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2493{
2494 size_type __sz = size();
2495 if (__pos > __sz)
2496 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:192497 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:162498 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:192499 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:162500 if (__cap - __sz + __n1 >= __n2)
2501 {
Howard Hinnant9dcdcde2013-06-28 16:59:192502 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162503 if (__n1 != __n2)
2504 {
2505 size_type __n_move = __sz - __pos - __n1;
2506 if (__n_move != 0)
2507 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2508 }
2509 }
2510 else
2511 {
2512 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:192513 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:162514 }
2515 traits_type::assign(__p + __pos, __n2, __c);
2516 __sz += __n2 - __n1;
2517 __set_size(__sz);
2518 __invalidate_iterators_past(__sz);
2519 traits_type::assign(__p[__sz], value_type());
2520 return *this;
2521}
2522
2523template <class _CharT, class _Traits, class _Allocator>
2524template<class _InputIterator>
2525typename enable_if
2526<
2527 __is_input_iterator<_InputIterator>::value,
2528 basic_string<_CharT, _Traits, _Allocator>&
2529>::type
Howard Hinnant7b2cb482010-11-17 21:11:402530basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:162531 _InputIterator __j1, _InputIterator __j2)
2532{
Marshall Clowdf9db312016-01-13 21:54:342533 basic_string __temp(__j1, __j2, __alloc());
2534 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:162535}
2536
2537template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002538inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162539basic_string<_CharT, _Traits, _Allocator>&
2540basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2541{
2542 return replace(__pos1, __n1, __str.data(), __str.size());
2543}
2544
2545template <class _CharT, class _Traits, class _Allocator>
2546basic_string<_CharT, _Traits, _Allocator>&
2547basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2548 size_type __pos2, size_type __n2)
2549{
2550 size_type __str_sz = __str.size();
2551 if (__pos2 > __str_sz)
2552 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:192553 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:162554}
2555
2556template <class _CharT, class _Traits, class _Allocator>
2557basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow1e00d6d2016-07-21 05:31:242558basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, __self_view __sv,
2559 size_type __pos2, size_type __n2)
2560{
2561 size_type __str_sz = __sv.size();
2562 if (__pos2 > __str_sz)
2563 this->__throw_out_of_range();
2564 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2565}
2566
2567template <class _CharT, class _Traits, class _Allocator>
2568basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192569basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:162570{
Alp Tokerec34c482014-05-15 11:27:392571 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:162572 return replace(__pos, __n1, __s, traits_type::length(__s));
2573}
2574
2575template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002576inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162577basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:402578basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:162579{
2580 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2581 __str.data(), __str.size());
2582}
2583
2584template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002585inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162586basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192587basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:162588{
2589 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2590}
2591
2592template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002593inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162594basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:192595basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:162596{
2597 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2598}
2599
2600template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002601inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162602basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:402603basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:162604{
2605 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2606}
2607
2608// erase
2609
2610template <class _CharT, class _Traits, class _Allocator>
2611basic_string<_CharT, _Traits, _Allocator>&
2612basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2613{
2614 size_type __sz = size();
2615 if (__pos > __sz)
2616 this->__throw_out_of_range();
2617 if (__n)
2618 {
Howard Hinnant9dcdcde2013-06-28 16:59:192619 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:192620 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:162621 size_type __n_move = __sz - __pos - __n;
2622 if (__n_move != 0)
2623 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2624 __sz -= __n;
2625 __set_size(__sz);
2626 __invalidate_iterators_past(__sz);
2627 traits_type::assign(__p[__sz], value_type());
2628 }
2629 return *this;
2630}
2631
2632template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002633inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162634typename basic_string<_CharT, _Traits, _Allocator>::iterator
2635basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2636{
Howard Hinnant499cea12013-08-23 17:37:052637#if _LIBCPP_DEBUG_LEVEL >= 2
2638 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2639 "string::erase(iterator) called with an iterator not"
2640 " referring to this string");
2641#endif
2642 _LIBCPP_ASSERT(__pos != end(),
2643 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:162644 iterator __b = begin();
2645 size_type __r = static_cast<size_type>(__pos - __b);
2646 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:042647 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:162648}
2649
2650template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002651inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162652typename basic_string<_CharT, _Traits, _Allocator>::iterator
2653basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2654{
Howard Hinnant499cea12013-08-23 17:37:052655#if _LIBCPP_DEBUG_LEVEL >= 2
2656 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2657 "string::erase(iterator, iterator) called with an iterator not"
2658 " referring to this string");
2659#endif
2660 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:162661 iterator __b = begin();
2662 size_type __r = static_cast<size_type>(__first - __b);
2663 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:042664 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:162665}
2666
2667template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002668inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162669void
2670basic_string<_CharT, _Traits, _Allocator>::pop_back()
2671{
Howard Hinnant499cea12013-08-23 17:37:052672 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:162673 size_type __sz;
2674 if (__is_long())
2675 {
2676 __sz = __get_long_size() - 1;
2677 __set_long_size(__sz);
2678 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2679 }
2680 else
2681 {
2682 __sz = __get_short_size() - 1;
2683 __set_short_size(__sz);
2684 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2685 }
2686 __invalidate_iterators_past(__sz);
2687}
2688
2689template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002690inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162691void
Howard Hinnanta6119a82011-05-29 19:57:122692basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162693{
2694 __invalidate_all_iterators();
2695 if (__is_long())
2696 {
2697 traits_type::assign(*__get_long_pointer(), value_type());
2698 __set_long_size(0);
2699 }
2700 else
2701 {
2702 traits_type::assign(*__get_short_pointer(), value_type());
2703 __set_short_size(0);
2704 }
2705}
2706
2707template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002708inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162709void
2710basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2711{
2712 if (__is_long())
2713 {
2714 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2715 __set_long_size(__pos);
2716 }
2717 else
2718 {
2719 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2720 __set_short_size(__pos);
2721 }
2722 __invalidate_iterators_past(__pos);
2723}
2724
2725template <class _CharT, class _Traits, class _Allocator>
2726void
2727basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2728{
2729 size_type __sz = size();
2730 if (__n > __sz)
2731 append(__n - __sz, __c);
2732 else
2733 __erase_to_end(__n);
2734}
2735
2736template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002737inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162738typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:122739basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162740{
Howard Hinnante32b5e22010-11-17 17:55:082741 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:162742#if _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:082743 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:162744#else
Marshall Clow09f85502013-10-31 17:23:082745 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:162746#endif
2747}
2748
2749template <class _CharT, class _Traits, class _Allocator>
2750void
2751basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2752{
2753 if (__res_arg > max_size())
2754 this->__throw_length_error();
2755 size_type __cap = capacity();
2756 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:192757 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:162758 __res_arg = __recommend(__res_arg);
2759 if (__res_arg != __cap)
2760 {
2761 pointer __new_data, __p;
2762 bool __was_long, __now_long;
2763 if (__res_arg == __min_cap - 1)
2764 {
2765 __was_long = true;
2766 __now_long = false;
2767 __new_data = __get_short_pointer();
2768 __p = __get_long_pointer();
2769 }
2770 else
2771 {
2772 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:082773 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:162774 else
2775 {
2776 #ifndef _LIBCPP_NO_EXCEPTIONS
2777 try
2778 {
Howard Hinnant324bb032010-08-22 00:02:432779 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:082780 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:162781 #ifndef _LIBCPP_NO_EXCEPTIONS
2782 }
2783 catch (...)
2784 {
2785 return;
2786 }
Howard Hinnant324bb032010-08-22 00:02:432787 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:192788 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:162789 return;
Howard Hinnant324bb032010-08-22 00:02:432790 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:162791 }
2792 __now_long = true;
2793 __was_long = __is_long();
2794 __p = __get_pointer();
2795 }
Howard Hinnant9dcdcde2013-06-28 16:59:192796 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
2797 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:162798 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:082799 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:162800 if (__now_long)
2801 {
2802 __set_long_cap(__res_arg+1);
2803 __set_long_size(__sz);
2804 __set_long_pointer(__new_data);
2805 }
2806 else
2807 __set_short_size(__sz);
2808 __invalidate_all_iterators();
2809 }
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>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:242815basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162816{
Howard Hinnant499cea12013-08-23 17:37:052817 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:162818 return *(data() + __pos);
2819}
2820
2821template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002822inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162823typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:242824basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162825{
Howard Hinnant499cea12013-08-23 17:37:052826 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:162827 return *(__get_pointer() + __pos);
2828}
2829
2830template <class _CharT, class _Traits, class _Allocator>
2831typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2832basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
2833{
2834 if (__n >= size())
2835 this->__throw_out_of_range();
2836 return (*this)[__n];
2837}
2838
2839template <class _CharT, class _Traits, class _Allocator>
2840typename basic_string<_CharT, _Traits, _Allocator>::reference
2841basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
2842{
2843 if (__n >= size())
2844 this->__throw_out_of_range();
2845 return (*this)[__n];
2846}
2847
2848template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002849inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162850typename basic_string<_CharT, _Traits, _Allocator>::reference
2851basic_string<_CharT, _Traits, _Allocator>::front()
2852{
Howard Hinnant499cea12013-08-23 17:37:052853 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:162854 return *__get_pointer();
2855}
2856
2857template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002858inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162859typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2860basic_string<_CharT, _Traits, _Allocator>::front() const
2861{
Howard Hinnant499cea12013-08-23 17:37:052862 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:162863 return *data();
2864}
2865
2866template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002867inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162868typename basic_string<_CharT, _Traits, _Allocator>::reference
2869basic_string<_CharT, _Traits, _Allocator>::back()
2870{
Howard Hinnant499cea12013-08-23 17:37:052871 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:162872 return *(__get_pointer() + size() - 1);
2873}
2874
2875template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002876inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162877typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2878basic_string<_CharT, _Traits, _Allocator>::back() const
2879{
Howard Hinnant499cea12013-08-23 17:37:052880 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:162881 return *(data() + size() - 1);
2882}
2883
2884template <class _CharT, class _Traits, class _Allocator>
2885typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:192886basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:162887{
2888 size_type __sz = size();
2889 if (__pos > __sz)
2890 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:192891 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:162892 traits_type::copy(__s, data() + __pos, __rlen);
2893 return __rlen;
2894}
2895
2896template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002897inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162898basic_string<_CharT, _Traits, _Allocator>
2899basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
2900{
2901 return basic_string(*this, __pos, __n, __alloc());
2902}
2903
2904template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002905inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162906void
2907basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:562908#if _LIBCPP_STD_VER >= 14
2909 _NOEXCEPT
2910#else
2911 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2912 __is_nothrow_swappable<allocator_type>::value)
2913#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162914{
Howard Hinnant499cea12013-08-23 17:37:052915#if _LIBCPP_DEBUG_LEVEL >= 2
2916 if (!__is_long())
2917 __get_db()->__invalidate_all(this);
2918 if (!__str.__is_long())
2919 __get_db()->__invalidate_all(&__str);
2920 __get_db()->swap(this, &__str);
2921#endif
Howard Hinnant0949eed2011-06-30 21:18:192922 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:562923 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:162924}
2925
2926// find
2927
2928template <class _Traits>
2929struct _LIBCPP_HIDDEN __traits_eq
2930{
2931 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:122932 _LIBCPP_INLINE_VISIBILITY
2933 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
2934 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:162935};
2936
2937template<class _CharT, class _Traits, class _Allocator>
2938typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:192939basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:122940 size_type __pos,
2941 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162942{
Alp Tokerec34c482014-05-15 11:27:392943 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:242944 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:492945 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:162946}
2947
2948template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002949inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162950typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:122951basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
2952 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162953{
Marshall Clow1e00d6d2016-07-21 05:31:242954 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:492955 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:162956}
2957
2958template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002959inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162960typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:242961basic_string<_CharT, _Traits, _Allocator>::find(__self_view __sv,
2962 size_type __pos) const _NOEXCEPT
2963{
2964 return __str_find<value_type, size_type, traits_type, npos>
2965 (data(), size(), __sv.data(), __pos, __sv.size());
2966}
2967
2968template<class _CharT, class _Traits, class _Allocator>
2969inline _LIBCPP_INLINE_VISIBILITY
2970typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:192971basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:122972 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162973{
Alp Tokerec34c482014-05-15 11:27:392974 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:242975 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:492976 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:162977}
2978
2979template<class _CharT, class _Traits, class _Allocator>
2980typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:122981basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
2982 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162983{
Marshall Clow1e00d6d2016-07-21 05:31:242984 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:492985 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:162986}
2987
2988// rfind
2989
2990template<class _CharT, class _Traits, class _Allocator>
2991typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:192992basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:122993 size_type __pos,
2994 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162995{
Alp Tokerec34c482014-05-15 11:27:392996 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:242997 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:492998 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:162999}
3000
3001template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003002inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163003typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123004basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3005 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163006{
Marshall Clow1e00d6d2016-07-21 05:31:243007 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:493008 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:163009}
3010
3011template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003012inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163013typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:243014basic_string<_CharT, _Traits, _Allocator>::rfind(__self_view __sv,
3015 size_type __pos) const _NOEXCEPT
3016{
3017 return __str_rfind<value_type, size_type, traits_type, npos>
3018 (data(), size(), __sv.data(), __pos, __sv.size());
3019}
3020
3021template<class _CharT, class _Traits, class _Allocator>
3022inline _LIBCPP_INLINE_VISIBILITY
3023typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193024basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123025 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163026{
Alp Tokerec34c482014-05-15 11:27:393027 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243028 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:493029 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:163030}
3031
3032template<class _CharT, class _Traits, class _Allocator>
3033typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123034basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3035 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163036{
Marshall Clow1e00d6d2016-07-21 05:31:243037 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:493038 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:163039}
3040
3041// find_first_of
3042
3043template<class _CharT, class _Traits, class _Allocator>
3044typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193045basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123046 size_type __pos,
3047 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163048{
Alp Tokerec34c482014-05-15 11:27:393049 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243050 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263051 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:163052}
3053
3054template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003055inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163056typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123057basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3058 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163059{
Marshall Clow1e00d6d2016-07-21 05:31:243060 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263061 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:163062}
3063
3064template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003065inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163066typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:243067basic_string<_CharT, _Traits, _Allocator>::find_first_of(__self_view __sv,
3068 size_type __pos) const _NOEXCEPT
3069{
3070 return __str_find_first_of<value_type, size_type, traits_type, npos>
3071 (data(), size(), __sv.data(), __pos, __sv.size());
3072}
3073
3074template<class _CharT, class _Traits, class _Allocator>
3075inline _LIBCPP_INLINE_VISIBILITY
3076typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193077basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123078 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163079{
Alp Tokerec34c482014-05-15 11:27:393080 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243081 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263082 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:163083}
3084
3085template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003086inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163087typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123088basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3089 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163090{
3091 return find(__c, __pos);
3092}
3093
3094// find_last_of
3095
3096template<class _CharT, class _Traits, class _Allocator>
3097typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193098basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123099 size_type __pos,
3100 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163101{
Alp Tokerec34c482014-05-15 11:27:393102 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243103 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263104 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:163105}
3106
3107template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003108inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163109typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123110basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3111 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163112{
Marshall Clow1e00d6d2016-07-21 05:31:243113 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263114 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:163115}
3116
3117template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003118inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163119typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:243120basic_string<_CharT, _Traits, _Allocator>::find_last_of(__self_view __sv,
3121 size_type __pos) const _NOEXCEPT
3122{
3123 return __str_find_last_of<value_type, size_type, traits_type, npos>
3124 (data(), size(), __sv.data(), __pos, __sv.size());
3125}
3126
3127template<class _CharT, class _Traits, class _Allocator>
3128inline _LIBCPP_INLINE_VISIBILITY
3129typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193130basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123131 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163132{
Alp Tokerec34c482014-05-15 11:27:393133 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243134 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263135 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:163136}
3137
3138template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003139inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163140typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123141basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3142 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163143{
3144 return rfind(__c, __pos);
3145}
3146
3147// find_first_not_of
3148
3149template<class _CharT, class _Traits, class _Allocator>
3150typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193151basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123152 size_type __pos,
3153 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163154{
Alp Tokerec34c482014-05-15 11:27:393155 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243156 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263157 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:163158}
3159
3160template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003161inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163162typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123163basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3164 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163165{
Marshall Clow1e00d6d2016-07-21 05:31:243166 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263167 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:163168}
3169
3170template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003171inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163172typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:243173basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(__self_view __sv,
3174 size_type __pos) const _NOEXCEPT
3175{
3176 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3177 (data(), size(), __sv.data(), __pos, __sv.size());
3178}
3179
3180template<class _CharT, class _Traits, class _Allocator>
3181inline _LIBCPP_INLINE_VISIBILITY
3182typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193183basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123184 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163185{
Alp Tokerec34c482014-05-15 11:27:393186 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243187 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263188 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:163189}
3190
3191template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003192inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163193typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123194basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3195 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163196{
Marshall Clow1e00d6d2016-07-21 05:31:243197 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263198 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:163199}
3200
3201// find_last_not_of
3202
3203template<class _CharT, class _Traits, class _Allocator>
3204typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193205basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123206 size_type __pos,
3207 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163208{
Alp Tokerec34c482014-05-15 11:27:393209 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243210 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263211 (data(), size(), __s, __pos, __n);
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_not_of(const basic_string& __str,
3218 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163219{
Marshall Clow1e00d6d2016-07-21 05:31:243220 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263221 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:163222}
3223
3224template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003225inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163226typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:243227basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(__self_view __sv,
3228 size_type __pos) const _NOEXCEPT
3229{
3230 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3231 (data(), size(), __sv.data(), __pos, __sv.size());
3232}
3233
3234template<class _CharT, class _Traits, class _Allocator>
3235inline _LIBCPP_INLINE_VISIBILITY
3236typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:193237basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123238 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163239{
Alp Tokerec34c482014-05-15 11:27:393240 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:243241 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263242 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:163243}
3244
3245template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003246inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163247typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:123248basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3249 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163250{
Marshall Clow1e00d6d2016-07-21 05:31:243251 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:263252 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:163253}
3254
3255// compare
3256
3257template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003258inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163259int
Marshall Clow1e00d6d2016-07-21 05:31:243260basic_string<_CharT, _Traits, _Allocator>::compare(__self_view __sv) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163261{
Howard Hinnantfa06d752011-07-24 21:45:063262 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:243263 size_t __rhs_sz = __sv.size();
3264 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:063265 _VSTD::min(__lhs_sz, __rhs_sz));
3266 if (__result != 0)
3267 return __result;
3268 if (__lhs_sz < __rhs_sz)
3269 return -1;
3270 if (__lhs_sz > __rhs_sz)
3271 return 1;
3272 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:163273}
3274
3275template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003276inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163277int
Marshall Clow1e00d6d2016-07-21 05:31:243278basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163279{
Marshall Clow1e00d6d2016-07-21 05:31:243280 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:163281}
3282
3283template <class _CharT, class _Traits, class _Allocator>
3284int
Howard Hinnanta6119a82011-05-29 19:57:123285basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3286 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:193287 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:123288 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:163289{
Alp Tokerec34c482014-05-15 11:27:393290 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:163291 size_type __sz = size();
3292 if (__pos1 > __sz || __n2 == npos)
3293 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:193294 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3295 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:163296 if (__r == 0)
3297 {
3298 if (__rlen < __n2)
3299 __r = -1;
3300 else if (__rlen > __n2)
3301 __r = 1;
3302 }
3303 return __r;
3304}
3305
Marshall Clow1e00d6d2016-07-21 05:31:243306template <class _CharT, class _Traits, class _Allocator>
3307inline _LIBCPP_INLINE_VISIBILITY
3308int
3309basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3310 size_type __n1,
3311 __self_view __sv) const
3312{
3313 return compare(__pos1, __n1, __sv.data(), __sv.size());
3314}
3315
3316template <class _CharT, class _Traits, class _Allocator>
3317inline _LIBCPP_INLINE_VISIBILITY
3318int
3319basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3320 size_type __n1,
3321 const basic_string& __str) const
3322{
3323 return compare(__pos1, __n1, __str.data(), __str.size());
3324}
3325
3326template <class _CharT, class _Traits, class _Allocator>
3327int inline _LIBCPP_INLINE_VISIBILITY
3328basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3329 size_type __n1,
3330 __self_view __sv,
3331 size_type __pos2,
3332 size_type __n2) const
3333{
3334 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3335}
3336
3337template <class _CharT, class _Traits, class _Allocator>
3338int
3339basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3340 size_type __n1,
3341 const basic_string& __str,
3342 size_type __pos2,
3343 size_type __n2) const
3344{
3345 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3346}
3347
3348template <class _CharT, class _Traits, class _Allocator>
3349int
3350basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3351{
3352 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3353 return compare(0, npos, __s, traits_type::length(__s));
3354}
3355
3356template <class _CharT, class _Traits, class _Allocator>
3357int
3358basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3359 size_type __n1,
3360 const value_type* __s) const
3361{
3362 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3363 return compare(__pos1, __n1, __s, traits_type::length(__s));
3364}
3365
Howard Hinnantbc8d3f92010-05-11 19:42:163366// __invariants
3367
3368template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003369inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163370bool
3371basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3372{
3373 if (size() > capacity())
3374 return false;
3375 if (capacity() < __min_cap - 1)
3376 return false;
3377 if (data() == 0)
3378 return false;
3379 if (data()[size()] != value_type(0))
3380 return false;
3381 return true;
3382}
3383
3384// operator==
3385
3386template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003387inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163388bool
3389operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:123390 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163391{
Howard Hinnant08dd2532013-04-22 23:55:133392 size_t __lhs_sz = __lhs.size();
3393 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3394 __rhs.data(),
3395 __lhs_sz) == 0;
3396}
3397
3398template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003399inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:133400bool
3401operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3402 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3403{
3404 size_t __lhs_sz = __lhs.size();
3405 if (__lhs_sz != __rhs.size())
3406 return false;
3407 const char* __lp = __lhs.data();
3408 const char* __rp = __rhs.data();
3409 if (__lhs.__is_long())
3410 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3411 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3412 if (*__lp != *__rp)
3413 return false;
3414 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:163415}
3416
3417template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003418inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163419bool
Howard Hinnanta6119a82011-05-29 19:57:123420operator==(const _CharT* __lhs,
3421 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163422{
Eric Fiselier4f241822015-08-28 03:02:373423 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3424 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3425 size_t __lhs_len = _Traits::length(__lhs);
3426 if (__lhs_len != __rhs.size()) return false;
3427 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:163428}
3429
Howard Hinnantbc8d3f92010-05-11 19:42:163430template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003431inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163432bool
Howard Hinnanta6119a82011-05-29 19:57:123433operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3434 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163435{
Eric Fiselier4f241822015-08-28 03:02:373436 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3437 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3438 size_t __rhs_len = _Traits::length(__rhs);
3439 if (__rhs_len != __lhs.size()) return false;
3440 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:163441}
3442
Howard Hinnant324bb032010-08-22 00:02:433443template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003444inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163445bool
3446operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:123447 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163448{
3449 return !(__lhs == __rhs);
3450}
3451
3452template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003453inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163454bool
Howard Hinnanta6119a82011-05-29 19:57:123455operator!=(const _CharT* __lhs,
3456 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163457{
3458 return !(__lhs == __rhs);
3459}
3460
3461template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003462inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163463bool
Howard Hinnanta6119a82011-05-29 19:57:123464operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3465 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163466{
3467 return !(__lhs == __rhs);
3468}
3469
3470// operator<
3471
3472template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003473inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163474bool
3475operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:123476 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163477{
Howard Hinnant2644a7b2011-07-24 15:07:213478 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:163479}
3480
3481template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003482inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163483bool
Howard Hinnanta6119a82011-05-29 19:57:123484operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3485 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163486{
Howard Hinnant2644a7b2011-07-24 15:07:213487 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:163488}
3489
3490template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003491inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163492bool
Howard Hinnanta6119a82011-05-29 19:57:123493operator< (const _CharT* __lhs,
3494 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163495{
3496 return __rhs.compare(__lhs) > 0;
3497}
3498
Howard Hinnantbc8d3f92010-05-11 19:42:163499// operator>
3500
3501template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003502inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163503bool
3504operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:123505 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163506{
3507 return __rhs < __lhs;
3508}
3509
3510template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003511inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163512bool
Howard Hinnanta6119a82011-05-29 19:57:123513operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3514 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163515{
3516 return __rhs < __lhs;
3517}
3518
3519template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003520inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163521bool
Howard Hinnanta6119a82011-05-29 19:57:123522operator> (const _CharT* __lhs,
3523 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163524{
3525 return __rhs < __lhs;
3526}
3527
3528// operator<=
3529
3530template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003531inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163532bool
3533operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:123534 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163535{
3536 return !(__rhs < __lhs);
3537}
3538
3539template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003540inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163541bool
Howard Hinnanta6119a82011-05-29 19:57:123542operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3543 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163544{
3545 return !(__rhs < __lhs);
3546}
3547
3548template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003549inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163550bool
Howard Hinnanta6119a82011-05-29 19:57:123551operator<=(const _CharT* __lhs,
3552 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163553{
3554 return !(__rhs < __lhs);
3555}
3556
3557// operator>=
3558
3559template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003560inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163561bool
3562operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:123563 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163564{
3565 return !(__lhs < __rhs);
3566}
3567
3568template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003569inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163570bool
Howard Hinnanta6119a82011-05-29 19:57:123571operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3572 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163573{
3574 return !(__lhs < __rhs);
3575}
3576
3577template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003578inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163579bool
Howard Hinnanta6119a82011-05-29 19:57:123580operator>=(const _CharT* __lhs,
3581 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163582{
3583 return !(__lhs < __rhs);
3584}
3585
3586// operator +
3587
3588template<class _CharT, class _Traits, class _Allocator>
3589basic_string<_CharT, _Traits, _Allocator>
3590operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3591 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3592{
3593 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3594 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3595 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3596 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3597 __r.append(__rhs.data(), __rhs_sz);
3598 return __r;
3599}
3600
3601template<class _CharT, class _Traits, class _Allocator>
3602basic_string<_CharT, _Traits, _Allocator>
3603operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3604{
3605 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3606 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3607 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3608 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3609 __r.append(__rhs.data(), __rhs_sz);
3610 return __r;
3611}
3612
3613template<class _CharT, class _Traits, class _Allocator>
3614basic_string<_CharT, _Traits, _Allocator>
3615operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3616{
3617 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3618 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3619 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3620 __r.append(__rhs.data(), __rhs_sz);
3621 return __r;
3622}
3623
3624template<class _CharT, class _Traits, class _Allocator>
3625basic_string<_CharT, _Traits, _Allocator>
3626operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3627{
3628 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3629 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3630 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3631 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3632 __r.append(__rhs, __rhs_sz);
3633 return __r;
3634}
3635
3636template<class _CharT, class _Traits, class _Allocator>
3637basic_string<_CharT, _Traits, _Allocator>
3638operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3639{
3640 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3641 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3642 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3643 __r.push_back(__rhs);
3644 return __r;
3645}
3646
Howard Hinnant73d21a42010-09-04 23:28:193647#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:163648
3649template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003650inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163651basic_string<_CharT, _Traits, _Allocator>
3652operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3653{
Howard Hinnant0949eed2011-06-30 21:18:193654 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:163655}
3656
3657template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003658inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163659basic_string<_CharT, _Traits, _Allocator>
3660operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3661{
Howard Hinnant0949eed2011-06-30 21:18:193662 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:163663}
3664
3665template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003666inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163667basic_string<_CharT, _Traits, _Allocator>
3668operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3669{
Howard Hinnant0949eed2011-06-30 21:18:193670 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:163671}
3672
3673template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003674inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163675basic_string<_CharT, _Traits, _Allocator>
3676operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3677{
Howard Hinnant0949eed2011-06-30 21:18:193678 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:163679}
3680
3681template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003682inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163683basic_string<_CharT, _Traits, _Allocator>
3684operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3685{
3686 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:193687 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:163688}
3689
3690template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003691inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163692basic_string<_CharT, _Traits, _Allocator>
3693operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3694{
Howard Hinnant0949eed2011-06-30 21:18:193695 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:163696}
3697
3698template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003699inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163700basic_string<_CharT, _Traits, _Allocator>
3701operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3702{
3703 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:193704 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:163705}
3706
Howard Hinnant73d21a42010-09-04 23:28:193707#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:163708
3709// swap
3710
3711template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003712inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163713void
Howard Hinnanta6119a82011-05-29 19:57:123714swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:473715 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3716 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:163717{
3718 __lhs.swap(__rhs);
3719}
3720
Howard Hinnantbc8d3f92010-05-11 19:42:163721#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3722
3723typedef basic_string<char16_t> u16string;
3724typedef basic_string<char32_t> u32string;
3725
Howard Hinnant324bb032010-08-22 00:02:433726#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:163727
Howard Hinnant0f678bd2013-08-12 18:38:343728_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3729_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3730_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3731_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
3732_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:393733
Howard Hinnant0f678bd2013-08-12 18:38:343734_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
3735_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
3736_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:393737
Howard Hinnant0f678bd2013-08-12 18:38:343738_LIBCPP_FUNC_VIS string to_string(int __val);
3739_LIBCPP_FUNC_VIS string to_string(unsigned __val);
3740_LIBCPP_FUNC_VIS string to_string(long __val);
3741_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
3742_LIBCPP_FUNC_VIS string to_string(long long __val);
3743_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
3744_LIBCPP_FUNC_VIS string to_string(float __val);
3745_LIBCPP_FUNC_VIS string to_string(double __val);
3746_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:393747
Howard Hinnant0f678bd2013-08-12 18:38:343748_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
3749_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
3750_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
3751_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
3752_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:393753
Howard Hinnant0f678bd2013-08-12 18:38:343754_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
3755_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
3756_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:393757
Howard Hinnant0f678bd2013-08-12 18:38:343758_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
3759_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
3760_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
3761_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
3762_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
3763_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
3764_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
3765_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
3766_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:393767
Howard Hinnantbc8d3f92010-05-11 19:42:163768template<class _CharT, class _Traits, class _Allocator>
3769 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
3770 basic_string<_CharT, _Traits, _Allocator>::npos;
3771
3772template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:343773struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:163774 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
3775{
3776 size_t
Howard Hinnanta6119a82011-05-29 19:57:123777 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:163778};
3779
3780template<class _CharT, class _Traits, class _Allocator>
3781size_t
3782hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:123783 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163784{
Sean Huntaffd9e52011-07-29 23:31:563785 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:163786}
3787
Howard Hinnant464aa5c2011-07-18 15:51:593788template<class _CharT, class _Traits, class _Allocator>
3789basic_ostream<_CharT, _Traits>&
3790operator<<(basic_ostream<_CharT, _Traits>& __os,
3791 const basic_string<_CharT, _Traits, _Allocator>& __str);
3792
3793template<class _CharT, class _Traits, class _Allocator>
3794basic_istream<_CharT, _Traits>&
3795operator>>(basic_istream<_CharT, _Traits>& __is,
3796 basic_string<_CharT, _Traits, _Allocator>& __str);
3797
3798template<class _CharT, class _Traits, class _Allocator>
3799basic_istream<_CharT, _Traits>&
3800getline(basic_istream<_CharT, _Traits>& __is,
3801 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3802
3803template<class _CharT, class _Traits, class _Allocator>
3804inline _LIBCPP_INLINE_VISIBILITY
3805basic_istream<_CharT, _Traits>&
3806getline(basic_istream<_CharT, _Traits>& __is,
3807 basic_string<_CharT, _Traits, _Allocator>& __str);
3808
3809#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3810
3811template<class _CharT, class _Traits, class _Allocator>
3812inline _LIBCPP_INLINE_VISIBILITY
3813basic_istream<_CharT, _Traits>&
3814getline(basic_istream<_CharT, _Traits>&& __is,
3815 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3816
3817template<class _CharT, class _Traits, class _Allocator>
3818inline _LIBCPP_INLINE_VISIBILITY
3819basic_istream<_CharT, _Traits>&
3820getline(basic_istream<_CharT, _Traits>&& __is,
3821 basic_string<_CharT, _Traits, _Allocator>& __str);
3822
3823#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3824
Howard Hinnant499cea12013-08-23 17:37:053825#if _LIBCPP_DEBUG_LEVEL >= 2
3826
3827template<class _CharT, class _Traits, class _Allocator>
3828bool
3829basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
3830{
3831 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
3832 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
3833}
3834
3835template<class _CharT, class _Traits, class _Allocator>
3836bool
3837basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
3838{
3839 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
3840 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
3841}
3842
3843template<class _CharT, class _Traits, class _Allocator>
3844bool
3845basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
3846{
3847 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
3848 return this->data() <= __p && __p <= this->data() + this->size();
3849}
3850
3851template<class _CharT, class _Traits, class _Allocator>
3852bool
3853basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
3854{
3855 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
3856 return this->data() <= __p && __p < this->data() + this->size();
3857}
3858
3859#endif // _LIBCPP_DEBUG_LEVEL >= 2
3860
Marshall Clow15234322013-07-23 17:05:243861#if _LIBCPP_STD_VER > 11
3862// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:323863inline namespace literals
Marshall Clow15234322013-07-23 17:05:243864{
3865 inline namespace string_literals
3866 {
Howard Hinnantab61b2c2013-08-07 19:39:483867 inline _LIBCPP_INLINE_VISIBILITY
3868 basic_string<char> operator "" s( const char *__str, size_t __len )
3869 {
3870 return basic_string<char> (__str, __len);
3871 }
Marshall Clow15234322013-07-23 17:05:243872
Howard Hinnantab61b2c2013-08-07 19:39:483873 inline _LIBCPP_INLINE_VISIBILITY
3874 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
3875 {
3876 return basic_string<wchar_t> (__str, __len);
3877 }
Marshall Clow15234322013-07-23 17:05:243878
Howard Hinnantab61b2c2013-08-07 19:39:483879 inline _LIBCPP_INLINE_VISIBILITY
3880 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
3881 {
3882 return basic_string<char16_t> (__str, __len);
3883 }
Marshall Clow15234322013-07-23 17:05:243884
Howard Hinnantab61b2c2013-08-07 19:39:483885 inline _LIBCPP_INLINE_VISIBILITY
3886 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
3887 {
3888 return basic_string<char32_t> (__str, __len);
3889 }
Marshall Clow15234322013-07-23 17:05:243890 }
3891}
3892#endif
3893
Howard Hinnant0f678bd2013-08-12 18:38:343894_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>)
3895_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>)
Howard Hinnant499cea12013-08-23 17:37:053896_LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
Howard Hinnantbc8d3f92010-05-11 19:42:163897
3898_LIBCPP_END_NAMESPACE_STD
3899
3900#endif // _LIBCPP_STRING