blob: b937d295b84457c5bcaed92d5cb1ef717a547c83 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- string -----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_STRING
12#define _LIBCPP_STRING
13
14/*
15 string synopsis
16
17namespace std
18{
19
20template <class stateT>
21class fpos
22{
23private:
24 stateT st;
25public:
26 fpos(streamoff = streamoff());
27
28 operator streamoff() const;
29
30 stateT state() const;
31 void state(stateT);
32
33 fpos& operator+=(streamoff);
34 fpos operator+ (streamoff) const;
35 fpos& operator-=(streamoff);
36 fpos operator- (streamoff) const;
37};
38
39template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
40
41template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
42template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
43
44template <class charT>
45struct char_traits
46{
47 typedef charT char_type;
48 typedef ... int_type;
49 typedef streamoff off_type;
50 typedef streampos pos_type;
51 typedef mbstate_t state_type;
52
Howard Hinnanta6119a82011-05-29 19:57:12 +000053 static void assign(char_type& c1, const char_type& c2) noexcept;
Howard Hinnant03d71812012-07-20 19:09:12 +000054 static constexpr bool eq(char_type c1, char_type c2) noexcept;
55 static constexpr bool lt(char_type c1, char_type c2) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056
57 static int compare(const char_type* s1, const char_type* s2, size_t n);
58 static size_t length(const char_type* s);
59 static const char_type* find(const char_type* s, size_t n, const char_type& a);
60 static char_type* move(char_type* s1, const char_type* s2, size_t n);
61 static char_type* copy(char_type* s1, const char_type* s2, size_t n);
62 static char_type* assign(char_type* s, size_t n, char_type a);
63
Howard Hinnant03d71812012-07-20 19:09:12 +000064 static constexpr int_type not_eof(int_type c) noexcept;
65 static constexpr char_type to_char_type(int_type c) noexcept;
66 static constexpr int_type to_int_type(char_type c) noexcept;
67 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
68 static constexpr int_type eof() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000069};
70
71template <> struct char_traits<char>;
72template <> struct char_traits<wchar_t>;
73
Howard Hinnant324bb032010-08-22 00:02:43 +000074template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000075class basic_string
76{
Howard Hinnant324bb032010-08-22 00:02:43 +000077public:
78// types:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000079 typedef traits traits_type;
80 typedef typename traits_type::char_type value_type;
81 typedef Allocator allocator_type;
82 typedef typename allocator_type::size_type size_type;
83 typedef typename allocator_type::difference_type difference_type;
84 typedef typename allocator_type::reference reference;
85 typedef typename allocator_type::const_reference const_reference;
86 typedef typename allocator_type::pointer pointer;
87 typedef typename allocator_type::const_pointer const_pointer;
88 typedef implementation-defined iterator;
89 typedef implementation-defined const_iterator;
90 typedef std::reverse_iterator<iterator> reverse_iterator;
91 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
92
93 static const size_type npos = -1;
94
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000095 basic_string()
96 noexcept(is_nothrow_default_constructible<allocator_type>::value);
97 explicit basic_string(const allocator_type& a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000098 basic_string(const basic_string& str);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000099 basic_string(basic_string&& str)
100 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clowff0b9f52016-03-09 17:51:43 +0000101 basic_string(const basic_string& str, size_type pos, // LWG#2583
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000102 const allocator_type& a = allocator_type());
Marshall Clowff0b9f52016-03-09 17:51:43 +0000103 basic_string(const basic_string& str, size_type pos, size_type n, // LWG#2583
104 const Allocator& a = Allocator());
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000105 basic_string(const value_type* s, const allocator_type& a = allocator_type());
106 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000107 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
108 template<class InputIterator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000109 basic_string(InputIterator begin, InputIterator end,
110 const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000111 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
112 basic_string(const basic_string&, const Allocator&);
113 basic_string(basic_string&&, const Allocator&);
114
115 ~basic_string();
116
117 basic_string& operator=(const basic_string& str);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000118 basic_string& operator=(basic_string&& str)
119 noexcept(
Marshall Clowaf961ed2015-08-18 18:57:00 +0000120 allocator_type::propagate_on_container_move_assignment::value ||
121 allocator_type::is_always_equal::value ); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000122 basic_string& operator=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000123 basic_string& operator=(value_type c);
124 basic_string& operator=(initializer_list<value_type>);
125
Howard Hinnanta6119a82011-05-29 19:57:12 +0000126 iterator begin() noexcept;
127 const_iterator begin() const noexcept;
128 iterator end() noexcept;
129 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000130
Howard Hinnanta6119a82011-05-29 19:57:12 +0000131 reverse_iterator rbegin() noexcept;
132 const_reverse_iterator rbegin() const noexcept;
133 reverse_iterator rend() noexcept;
134 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000135
Howard Hinnanta6119a82011-05-29 19:57:12 +0000136 const_iterator cbegin() const noexcept;
137 const_iterator cend() const noexcept;
138 const_reverse_iterator crbegin() const noexcept;
139 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000140
Howard Hinnanta6119a82011-05-29 19:57:12 +0000141 size_type size() const noexcept;
142 size_type length() const noexcept;
143 size_type max_size() const noexcept;
144 size_type capacity() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000145
146 void resize(size_type n, value_type c);
147 void resize(size_type n);
148
149 void reserve(size_type res_arg = 0);
150 void shrink_to_fit();
Howard Hinnanta6119a82011-05-29 19:57:12 +0000151 void clear() noexcept;
152 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000153
154 const_reference operator[](size_type pos) const;
155 reference operator[](size_type pos);
156
157 const_reference at(size_type n) const;
158 reference at(size_type n);
159
160 basic_string& operator+=(const basic_string& str);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000161 basic_string& operator+=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000162 basic_string& operator+=(value_type c);
163 basic_string& operator+=(initializer_list<value_type>);
164
165 basic_string& append(const basic_string& str);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000166 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000167 basic_string& append(const value_type* s, size_type n);
168 basic_string& append(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000169 basic_string& append(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000170 template<class InputIterator>
171 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000172 basic_string& append(initializer_list<value_type>);
173
174 void push_back(value_type c);
175 void pop_back();
176 reference front();
177 const_reference front() const;
178 reference back();
179 const_reference back() const;
180
181 basic_string& assign(const basic_string& str);
Howard Hinnanta6119a82011-05-29 19:57:12 +0000182 basic_string& assign(basic_string&& str);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000183 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000184 basic_string& assign(const value_type* s, size_type n);
185 basic_string& assign(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000186 basic_string& assign(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000187 template<class InputIterator>
188 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000189 basic_string& assign(initializer_list<value_type>);
190
191 basic_string& insert(size_type pos1, const basic_string& str);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000192 basic_string& insert(size_type pos1, const basic_string& str,
193 size_type pos2, size_type n);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000194 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000195 basic_string& insert(size_type pos, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000196 basic_string& insert(size_type pos, size_type n, value_type c);
197 iterator insert(const_iterator p, value_type c);
198 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000199 template<class InputIterator>
200 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000201 iterator insert(const_iterator p, initializer_list<value_type>);
202
203 basic_string& erase(size_type pos = 0, size_type n = npos);
204 iterator erase(const_iterator position);
205 iterator erase(const_iterator first, const_iterator last);
206
207 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000208 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000209 size_type pos2, size_type n2=npos); // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000210 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
211 basic_string& replace(size_type pos, size_type n1, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000212 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000213 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000214 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
215 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000216 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000217 template<class InputIterator>
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000218 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
219 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000220
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000221 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000222 basic_string substr(size_type pos = 0, size_type n = npos) const;
223
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000224 void swap(basic_string& str)
Marshall Clow7d914d12015-07-13 20:04:56 +0000225 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
226 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000227
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000228 const value_type* c_str() const noexcept;
229 const value_type* data() const noexcept;
Marshall Clowf532a702016-03-08 15:44:30 +0000230 value_type* data() noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000231
Howard Hinnanta6119a82011-05-29 19:57:12 +0000232 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000233
Howard Hinnanta6119a82011-05-29 19:57:12 +0000234 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000235 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
236 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000237 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000238
Howard Hinnanta6119a82011-05-29 19:57:12 +0000239 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000240 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
241 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000242 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000243
Howard Hinnanta6119a82011-05-29 19:57:12 +0000244 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000245 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
246 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000247 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000248
Howard Hinnanta6119a82011-05-29 19:57:12 +0000249 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000250 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
251 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000252 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000253
Howard Hinnanta6119a82011-05-29 19:57:12 +0000254 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000255 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
256 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000257 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258
Howard Hinnanta6119a82011-05-29 19:57:12 +0000259 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000260 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
261 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000262 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000263
Howard Hinnanta6119a82011-05-29 19:57:12 +0000264 int compare(const basic_string& str) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000265 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000266 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000267 size_type pos2, size_type n2=npos) const; // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000268 int compare(const value_type* s) const noexcept;
269 int compare(size_type pos1, size_type n1, const value_type* s) const;
270 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000271
272 bool __invariants() const;
273};
274
275template<class charT, class traits, class Allocator>
276basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000277operator+(const basic_string<charT, traits, Allocator>& lhs,
278 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000279
280template<class charT, class traits, class Allocator>
281basic_string<charT, traits, Allocator>
282operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
283
284template<class charT, class traits, class Allocator>
285basic_string<charT, traits, Allocator>
286operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
287
288template<class charT, class traits, class Allocator>
289basic_string<charT, traits, Allocator>
290operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
291
292template<class charT, class traits, class Allocator>
293basic_string<charT, traits, Allocator>
294operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
295
296template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000297bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000298 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000299
300template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000301bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000302
303template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000304bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305
Howard Hinnant324bb032010-08-22 00:02:43 +0000306template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000307bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000308 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000309
310template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000311bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000312
313template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000314bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000315
316template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000317bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000318 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000319
320template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000321bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000322
323template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000324bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000325
326template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000327bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000328 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000329
330template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000331bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000332
333template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000334bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000335
336template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000337bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000338 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000339
340template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000341bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000342
343template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000344bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345
346template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000347bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000348 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000349
350template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000351bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000352
353template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000354bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355
356template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000357void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000358 basic_string<charT, traits, Allocator>& rhs)
359 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000360
361template<class charT, class traits, class Allocator>
362basic_istream<charT, traits>&
363operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
364
365template<class charT, class traits, class Allocator>
366basic_ostream<charT, traits>&
367operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
368
369template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000370basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000371getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
372 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000373
374template<class charT, class traits, class Allocator>
375basic_istream<charT, traits>&
376getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
377
378typedef basic_string<char> string;
379typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000380typedef basic_string<char16_t> u16string;
381typedef basic_string<char32_t> u32string;
382
383int stoi (const string& str, size_t* idx = 0, int base = 10);
384long stol (const string& str, size_t* idx = 0, int base = 10);
385unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
386long long stoll (const string& str, size_t* idx = 0, int base = 10);
387unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
388
389float stof (const string& str, size_t* idx = 0);
390double stod (const string& str, size_t* idx = 0);
391long double stold(const string& str, size_t* idx = 0);
392
393string to_string(int val);
394string to_string(unsigned val);
395string to_string(long val);
396string to_string(unsigned long val);
397string to_string(long long val);
398string to_string(unsigned long long val);
399string to_string(float val);
400string to_string(double val);
401string to_string(long double val);
402
403int stoi (const wstring& str, size_t* idx = 0, int base = 10);
404long stol (const wstring& str, size_t* idx = 0, int base = 10);
405unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
406long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
407unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
408
409float stof (const wstring& str, size_t* idx = 0);
410double stod (const wstring& str, size_t* idx = 0);
411long double stold(const wstring& str, size_t* idx = 0);
412
413wstring to_wstring(int val);
414wstring to_wstring(unsigned val);
415wstring to_wstring(long val);
416wstring to_wstring(unsigned long val);
417wstring to_wstring(long long val);
418wstring to_wstring(unsigned long long val);
419wstring to_wstring(float val);
420wstring to_wstring(double val);
421wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422
423template <> struct hash<string>;
424template <> struct hash<u16string>;
425template <> struct hash<u32string>;
426template <> struct hash<wstring>;
427
Marshall Clow15234322013-07-23 17:05:24 +0000428basic_string<char> operator "" s( const char *str, size_t len ); // C++14
429basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
430basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
431basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
432
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433} // std
434
435*/
436
437#include <__config>
438#include <iosfwd>
439#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000440#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000441#include <cwchar>
442#include <algorithm>
443#include <iterator>
444#include <utility>
445#include <memory>
446#include <stdexcept>
447#include <type_traits>
448#include <initializer_list>
449#include <__functional_base>
450#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
451#include <cstdint>
452#endif
Howard Hinnant499cea12013-08-23 17:37:05 +0000453#if defined(_LIBCPP_NO_EXCEPTIONS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000454#include <cassert>
455#endif
456
Howard Hinnant66c6f972011-11-29 16:45:27 +0000457#include <__undef_min_max>
458
Eric Fiselierb9536102014-08-10 23:53:08 +0000459#include <__debug>
460
Howard Hinnant08e17472011-10-17 20:05:10 +0000461#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000463#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000464
465_LIBCPP_BEGIN_NAMESPACE_STD
466
467// fpos
468
469template <class _StateT>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000470class _LIBCPP_TYPE_VIS_ONLY fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000471{
472private:
473 _StateT __st_;
474 streamoff __off_;
475public:
476 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
477
478 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
479
480 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
481 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
482
483 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
484 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
485 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
486 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
487};
488
489template <class _StateT>
490inline _LIBCPP_INLINE_VISIBILITY
491streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
492 {return streamoff(__x) - streamoff(__y);}
493
494template <class _StateT>
495inline _LIBCPP_INLINE_VISIBILITY
496bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
497 {return streamoff(__x) == streamoff(__y);}
498
499template <class _StateT>
500inline _LIBCPP_INLINE_VISIBILITY
501bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
502 {return streamoff(__x) != streamoff(__y);}
503
504// char_traits
505
506template <class _CharT>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000507struct _LIBCPP_TYPE_VIS_ONLY char_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000508{
509 typedef _CharT char_type;
510 typedef int int_type;
511 typedef streamoff off_type;
512 typedef streampos pos_type;
513 typedef mbstate_t state_type;
514
Dan Albert6d9505a2014-09-17 16:34:29 +0000515 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000516 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000517 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000518 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000519 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000520 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521
522 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524 static size_t length(const char_type* __s);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000526 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
527 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000531 static char_type* assign(char_type* __s, size_t __n, char_type __a);
532
Dan Albert6d9505a2014-09-17 16:34:29 +0000533 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000535 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000536 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000537 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000538 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000539 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000541 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000542 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000543};
544
545template <class _CharT>
546int
547char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
548{
549 for (; __n; --__n, ++__s1, ++__s2)
550 {
551 if (lt(*__s1, *__s2))
552 return -1;
553 if (lt(*__s2, *__s1))
554 return 1;
555 }
556 return 0;
557}
558
559template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000560inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000561size_t
562char_traits<_CharT>::length(const char_type* __s)
563{
564 size_t __len = 0;
565 for (; !eq(*__s, char_type(0)); ++__s)
566 ++__len;
567 return __len;
568}
569
570template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000571inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572const _CharT*
573char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
574{
575 for (; __n; --__n)
576 {
577 if (eq(*__s, __a))
578 return __s;
579 ++__s;
580 }
581 return 0;
582}
583
584template <class _CharT>
585_CharT*
586char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
587{
588 char_type* __r = __s1;
589 if (__s1 < __s2)
590 {
591 for (; __n; --__n, ++__s1, ++__s2)
592 assign(*__s1, *__s2);
593 }
594 else if (__s2 < __s1)
595 {
596 __s1 += __n;
597 __s2 += __n;
598 for (; __n; --__n)
599 assign(*--__s1, *--__s2);
600 }
601 return __r;
602}
603
604template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000605inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606_CharT*
607char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
608{
Howard Hinnant499cea12013-08-23 17:37:05 +0000609 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000610 char_type* __r = __s1;
611 for (; __n; --__n, ++__s1, ++__s2)
612 assign(*__s1, *__s2);
613 return __r;
614}
615
616template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000617inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000618_CharT*
619char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
620{
621 char_type* __r = __s;
622 for (; __n; --__n, ++__s)
623 assign(*__s, __a);
624 return __r;
625}
626
627// char_traits<char>
628
629template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000630struct _LIBCPP_TYPE_VIS_ONLY char_traits<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000631{
632 typedef char char_type;
633 typedef int int_type;
634 typedef streamoff off_type;
635 typedef streampos pos_type;
636 typedef mbstate_t state_type;
637
Dan Albert6d9505a2014-09-17 16:34:29 +0000638 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000639 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000640 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000641 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000642 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643 {return (unsigned char)__c1 < (unsigned char)__c2;}
644
Dan Albert6d9505a2014-09-17 16:34:29 +0000645 static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clowf2e36ef2015-02-12 23:34:52 +0000646 {return __n == 0 ? 0 : memcmp(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000647 static inline size_t length(const char_type* __s) {return strlen(__s);}
648 static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000649 {return __n == 0 ? NULL : (const char_type*) memchr(__s, to_int_type(__a), __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000650 static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000651 {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000652 static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnant499cea12013-08-23 17:37:05 +0000653 {
654 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Marshall Clow6bcbced2015-02-13 16:04:42 +0000655 return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +0000656 }
Dan Albert6d9505a2014-09-17 16:34:29 +0000657 static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000658 {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659
Dan Albert6d9505a2014-09-17 16:34:29 +0000660 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000662 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000663 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000664 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000665 {return int_type((unsigned char)__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000666 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000668 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000669 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670};
671
672// char_traits<wchar_t>
673
674template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000675struct _LIBCPP_TYPE_VIS_ONLY char_traits<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676{
677 typedef wchar_t char_type;
678 typedef wint_t int_type;
679 typedef streamoff off_type;
680 typedef streampos pos_type;
681 typedef mbstate_t state_type;
682
Dan Albert6d9505a2014-09-17 16:34:29 +0000683 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000684 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000685 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000686 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000687 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000688 {return __c1 < __c2;}
689
Dan Albert6d9505a2014-09-17 16:34:29 +0000690 static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clowf2e36ef2015-02-12 23:34:52 +0000691 {return __n == 0 ? 0 : wmemcmp(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000692 static inline size_t length(const char_type* __s)
Howard Hinnanta6119a82011-05-29 19:57:12 +0000693 {return wcslen(__s);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000694 static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000695 {return __n == 0 ? NULL : (const char_type*)wmemchr(__s, __a, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000696 static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000697 {return __n == 0 ? __s1 : (char_type*)wmemmove(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000698 static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnant499cea12013-08-23 17:37:05 +0000699 {
700 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Marshall Clow6bcbced2015-02-13 16:04:42 +0000701 return __n == 0 ? __s1 : (char_type*)wmemcpy(__s1, __s2, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +0000702 }
Dan Albert6d9505a2014-09-17 16:34:29 +0000703 static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000704 {return __n == 0 ? __s : (char_type*)wmemset(__s, __a, __n);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705
Dan Albert6d9505a2014-09-17 16:34:29 +0000706 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000708 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000709 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000710 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000711 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000712 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000714 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000715 {return int_type(WEOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000716};
717
718#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
719
720template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000721struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000722{
723 typedef char16_t char_type;
724 typedef uint_least16_t int_type;
725 typedef streamoff off_type;
726 typedef u16streampos pos_type;
727 typedef mbstate_t state_type;
728
Dan Albert6d9505a2014-09-17 16:34:29 +0000729 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000730 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000731 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000732 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000733 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000734 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000735
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000737 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000738 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000739 static size_t length(const char_type* __s);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000740 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000741 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747 static char_type* assign(char_type* __s, size_t __n, char_type __a);
748
Dan Albert6d9505a2014-09-17 16:34:29 +0000749 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000750 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000751 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000752 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000753 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000754 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000755 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000756 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000757 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Marshall Clow9a3c6892015-08-04 01:38:34 +0000758 {return int_type(0xFFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000759};
760
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000761inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000762int
763char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
764{
765 for (; __n; --__n, ++__s1, ++__s2)
766 {
767 if (lt(*__s1, *__s2))
768 return -1;
769 if (lt(*__s2, *__s1))
770 return 1;
771 }
772 return 0;
773}
774
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000775inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000776size_t
777char_traits<char16_t>::length(const char_type* __s)
778{
779 size_t __len = 0;
780 for (; !eq(*__s, char_type(0)); ++__s)
781 ++__len;
782 return __len;
783}
784
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000785inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000786const char16_t*
787char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
788{
789 for (; __n; --__n)
790 {
791 if (eq(*__s, __a))
792 return __s;
793 ++__s;
794 }
795 return 0;
796}
797
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000798inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000799char16_t*
800char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
801{
802 char_type* __r = __s1;
803 if (__s1 < __s2)
804 {
805 for (; __n; --__n, ++__s1, ++__s2)
806 assign(*__s1, *__s2);
807 }
808 else if (__s2 < __s1)
809 {
810 __s1 += __n;
811 __s2 += __n;
812 for (; __n; --__n)
813 assign(*--__s1, *--__s2);
814 }
815 return __r;
816}
817
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000818inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819char16_t*
820char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
821{
Howard Hinnant499cea12013-08-23 17:37:05 +0000822 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000823 char_type* __r = __s1;
824 for (; __n; --__n, ++__s1, ++__s2)
825 assign(*__s1, *__s2);
826 return __r;
827}
828
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000829inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000830char16_t*
831char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
832{
833 char_type* __r = __s;
834 for (; __n; --__n, ++__s)
835 assign(*__s, __a);
836 return __r;
837}
838
839template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000840struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841{
842 typedef char32_t char_type;
843 typedef uint_least32_t int_type;
844 typedef streamoff off_type;
845 typedef u32streampos pos_type;
846 typedef mbstate_t state_type;
847
Dan Albert6d9505a2014-09-17 16:34:29 +0000848 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000849 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000850 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000851 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000852 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000853 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000854
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000855 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000856 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000858 static size_t length(const char_type* __s);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000859 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000860 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000864 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866 static char_type* assign(char_type* __s, size_t __n, char_type __a);
867
Dan Albert6d9505a2014-09-17 16:34:29 +0000868 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000869 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000870 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000871 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000872 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000873 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000874 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000876 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000877 {return int_type(0xFFFFFFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878};
879
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000880inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000881int
882char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
883{
884 for (; __n; --__n, ++__s1, ++__s2)
885 {
886 if (lt(*__s1, *__s2))
887 return -1;
888 if (lt(*__s2, *__s1))
889 return 1;
890 }
891 return 0;
892}
893
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000894inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000895size_t
896char_traits<char32_t>::length(const char_type* __s)
897{
898 size_t __len = 0;
899 for (; !eq(*__s, char_type(0)); ++__s)
900 ++__len;
901 return __len;
902}
903
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000904inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905const char32_t*
906char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
907{
908 for (; __n; --__n)
909 {
910 if (eq(*__s, __a))
911 return __s;
912 ++__s;
913 }
914 return 0;
915}
916
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000917inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000918char32_t*
919char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
920{
921 char_type* __r = __s1;
922 if (__s1 < __s2)
923 {
924 for (; __n; --__n, ++__s1, ++__s2)
925 assign(*__s1, *__s2);
926 }
927 else if (__s2 < __s1)
928 {
929 __s1 += __n;
930 __s2 += __n;
931 for (; __n; --__n)
932 assign(*--__s1, *--__s2);
933 }
934 return __r;
935}
936
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000937inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938char32_t*
939char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
940{
Howard Hinnant499cea12013-08-23 17:37:05 +0000941 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000942 char_type* __r = __s1;
943 for (; __n; --__n, ++__s1, ++__s2)
944 assign(*__s1, *__s2);
945 return __r;
946}
947
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000948inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000949char32_t*
950char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
951{
952 char_type* __r = __s;
953 for (; __n; --__n, ++__s)
954 assign(*__s, __a);
955 return __r;
956}
957
Howard Hinnant324bb032010-08-22 00:02:43 +0000958#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000959
Marshall Clowb671fc92013-12-09 16:00:28 +0000960// helper fns for basic_string
961
Marshall Clow37025e12014-06-10 18:51:55 +0000962// __str_find
Marshall Clowb671fc92013-12-09 16:00:28 +0000963template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +0000964_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +0000965__str_find(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +0000966 _CharT __c, _SizeT __pos) _NOEXCEPT
967{
968 if (__pos >= __sz)
969 return __npos;
970 const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);
971 if (__r == 0)
972 return __npos;
973 return static_cast<_SizeT>(__r - __p);
974}
975
976template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
977_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +0000978__str_find(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +0000979 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
980{
981 if (__pos > __sz || __sz - __pos < __n)
982 return __npos;
983 if (__n == 0)
984 return __pos;
Marshall Clow360f3192014-06-02 02:22:49 +0000985 const _CharT* __r =
Marshall Clow37025e12014-06-10 18:51:55 +0000986 _VSTD::__search(__p + __pos, __p + __sz,
987 __s, __s + __n, _Traits::eq,
Marshall Clowf6d6b512016-03-08 15:12:52 +0000988 random_access_iterator_tag(), random_access_iterator_tag()).first;
Marshall Clow360f3192014-06-02 02:22:49 +0000989 if (__r == __p + __sz)
990 return __npos;
991 return static_cast<_SizeT>(__r - __p);
992}
993
994
Marshall Clow37025e12014-06-10 18:51:55 +0000995// __str_rfind
Marshall Clow360f3192014-06-02 02:22:49 +0000996
997template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
998_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +0000999__str_rfind(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001000 _CharT __c, _SizeT __pos) _NOEXCEPT
1001{
1002 if (__sz < 1)
Marshall Clowd5549cc2014-07-17 15:32:20 +00001003 return __npos;
1004 if (__pos < __sz)
1005 ++__pos;
1006 else
1007 __pos = __sz;
1008 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1009 {
1010 if (_Traits::eq(*--__ps, __c))
1011 return static_cast<_SizeT>(__ps - __p);
1012 }
Marshall Clow360f3192014-06-02 02:22:49 +00001013 return __npos;
1014}
1015
1016template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1017_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001018__str_rfind(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001019 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1020{
1021 __pos = _VSTD::min(__pos, __sz);
1022 if (__n < __sz - __pos)
1023 __pos += __n;
1024 else
1025 __pos = __sz;
Marshall Clow37025e12014-06-10 18:51:55 +00001026 const _CharT* __r = _VSTD::__find_end(
1027 __p, __p + __pos, __s, __s + __n, _Traits::eq,
1028 random_access_iterator_tag(), random_access_iterator_tag());
Marshall Clow360f3192014-06-02 02:22:49 +00001029 if (__n > 0 && __r == __p + __pos)
1030 return __npos;
1031 return static_cast<_SizeT>(__r - __p);
1032}
1033
Marshall Clow37025e12014-06-10 18:51:55 +00001034// __str_find_first_of
Marshall Clow360f3192014-06-02 02:22:49 +00001035template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1036_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001037__str_find_first_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001038 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001039{
1040 if (__pos >= __sz || __n == 0)
1041 return __npos;
Marshall Clow37025e12014-06-10 18:51:55 +00001042 const _CharT* __r = _VSTD::__find_first_of_ce
Marshall Clowb671fc92013-12-09 16:00:28 +00001043 (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
1044 if (__r == __p + __sz)
1045 return __npos;
1046 return static_cast<_SizeT>(__r - __p);
1047}
1048
Marshall Clow360f3192014-06-02 02:22:49 +00001049
Marshall Clow37025e12014-06-10 18:51:55 +00001050// __str_find_last_of
Marshall Clowb671fc92013-12-09 16:00:28 +00001051template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001052_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001053__str_find_last_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001054 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001055 {
1056 if (__n != 0)
1057 {
1058 if (__pos < __sz)
1059 ++__pos;
1060 else
1061 __pos = __sz;
1062 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1063 {
1064 const _CharT* __r = _Traits::find(__s, __n, *--__ps);
1065 if (__r)
1066 return static_cast<_SizeT>(__ps - __p);
1067 }
1068 }
1069 return __npos;
1070}
1071
1072
Marshall Clow37025e12014-06-10 18:51:55 +00001073// __str_find_first_not_of
Marshall Clowb671fc92013-12-09 16:00:28 +00001074template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001075_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001076__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001077 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001078{
1079 if (__pos < __sz)
1080 {
1081 const _CharT* __pe = __p + __sz;
1082 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1083 if (_Traits::find(__s, __n, *__ps) == 0)
1084 return static_cast<_SizeT>(__ps - __p);
1085 }
1086 return __npos;
1087}
1088
1089
1090template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001091_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001092__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001093 _CharT __c, _SizeT __pos) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001094{
1095 if (__pos < __sz)
1096 {
1097 const _CharT* __pe = __p + __sz;
1098 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1099 if (!_Traits::eq(*__ps, __c))
1100 return static_cast<_SizeT>(__ps - __p);
1101 }
1102 return __npos;
1103}
1104
1105
Marshall Clow37025e12014-06-10 18:51:55 +00001106// __str_find_last_not_of
Marshall Clowb671fc92013-12-09 16:00:28 +00001107template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001108_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001109__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001110 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001111{
1112 if (__pos < __sz)
1113 ++__pos;
1114 else
1115 __pos = __sz;
1116 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1117 if (_Traits::find(__s, __n, *--__ps) == 0)
1118 return static_cast<_SizeT>(__ps - __p);
1119 return __npos;
1120}
1121
1122
1123template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001124_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001125__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001126 _CharT __c, _SizeT __pos) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001127{
1128 if (__pos < __sz)
1129 ++__pos;
1130 else
1131 __pos = __sz;
1132 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1133 if (!_Traits::eq(*--__ps, __c))
1134 return static_cast<_SizeT>(__ps - __p);
1135 return __npos;
1136}
1137
1138template<class _Ptr>
1139size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
1140{
1141 typedef typename iterator_traits<_Ptr>::value_type value_type;
1142 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
1143}
1144
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001145// basic_string
1146
1147template<class _CharT, class _Traits, class _Allocator>
1148basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001149operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
1150 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001151
1152template<class _CharT, class _Traits, class _Allocator>
1153basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001154operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155
1156template<class _CharT, class _Traits, class _Allocator>
1157basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001158operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001159
1160template<class _CharT, class _Traits, class _Allocator>
1161basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001162operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163
1164template<class _CharT, class _Traits, class _Allocator>
1165basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001166operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001167
1168template <bool>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001169class _LIBCPP_TYPE_VIS_ONLY __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001170{
1171protected:
1172 void __throw_length_error() const;
1173 void __throw_out_of_range() const;
1174};
1175
1176template <bool __b>
1177void
1178__basic_string_common<__b>::__throw_length_error() const
1179{
1180#ifndef _LIBCPP_NO_EXCEPTIONS
1181 throw length_error("basic_string");
1182#else
1183 assert(!"basic_string length_error");
1184#endif
1185}
1186
1187template <bool __b>
1188void
1189__basic_string_common<__b>::__throw_out_of_range() const
1190{
1191#ifndef _LIBCPP_NO_EXCEPTIONS
1192 throw out_of_range("basic_string");
1193#else
1194 assert(!"basic_string out_of_range");
1195#endif
1196}
1197
Howard Hinnante9df0a52013-08-01 18:17:34 +00001198#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +00001199#pragma warning( push )
1200#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34 +00001201#endif // _LIBCPP_MSVC
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001202_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34 +00001203#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +00001204#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34 +00001205#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001206
Marshall Clowdf9db312016-01-13 21:54:34 +00001207#ifdef _LIBCPP_NO_EXCEPTIONS
1208template <class _Iter>
1209struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
1210#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
1211template <class _Iter>
1212struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
1213#else
1214template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
1215struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
1216 noexcept(++(declval<_Iter&>())) &&
1217 is_nothrow_assignable<_Iter&, _Iter>::value &&
1218 noexcept(declval<_Iter>() == declval<_Iter>()) &&
1219 noexcept(*declval<_Iter>())
1220)) {};
1221
1222template <class _Iter>
1223struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
1224#endif
1225
1226
1227template <class _Iter>
1228struct __libcpp_string_gets_noexcept_iterator
1229 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
1230
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001231#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001232
1233template <class _CharT, size_t = sizeof(_CharT)>
1234struct __padding
1235{
1236 unsigned char __xx[sizeof(_CharT)-1];
1237};
1238
1239template <class _CharT>
1240struct __padding<_CharT, 1>
1241{
1242};
1243
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001244#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001245
Howard Hinnant324bb032010-08-22 00:02:43 +00001246template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001247class _LIBCPP_TYPE_VIS_ONLY basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001248 : private __basic_string_common<true>
1249{
1250public:
1251 typedef basic_string __self;
1252 typedef _Traits traits_type;
1253 typedef typename traits_type::char_type value_type;
1254 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001255 typedef allocator_traits<allocator_type> __alloc_traits;
1256 typedef typename __alloc_traits::size_type size_type;
1257 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001258 typedef value_type& reference;
1259 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001260 typedef typename __alloc_traits::pointer pointer;
1261 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001262
Howard Hinnant499cea12013-08-23 17:37:05 +00001263 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
1264 static_assert((is_same<_CharT, value_type>::value),
1265 "traits_type::char_type must be the same type as CharT");
1266 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1267 "Allocator::value_type must be same type as value_type");
1268#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269 typedef pointer iterator;
1270 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001271#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001272 typedef __wrap_iter<pointer> iterator;
1273 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001274#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001275 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1276 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001277
1278private:
Howard Hinnant15467182013-04-30 21:44:48 +00001279
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001280#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001281
1282 struct __long
1283 {
1284 pointer __data_;
1285 size_type __size_;
1286 size_type __cap_;
1287 };
1288
1289#if _LIBCPP_BIG_ENDIAN
1290 enum {__short_mask = 0x01};
1291 enum {__long_mask = 0x1ul};
1292#else // _LIBCPP_BIG_ENDIAN
1293 enum {__short_mask = 0x80};
1294 enum {__long_mask = ~(size_type(~0) >> 1)};
1295#endif // _LIBCPP_BIG_ENDIAN
1296
1297 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1298 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1299
1300 struct __short
1301 {
1302 value_type __data_[__min_cap];
1303 struct
1304 : __padding<value_type>
1305 {
1306 unsigned char __size_;
1307 };
1308 };
1309
1310#else
1311
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001312 struct __long
1313 {
1314 size_type __cap_;
1315 size_type __size_;
1316 pointer __data_;
1317 };
1318
1319#if _LIBCPP_BIG_ENDIAN
1320 enum {__short_mask = 0x80};
1321 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43 +00001322#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001323 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04 +00001324 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43 +00001325#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001326
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001327 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1328 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1329
1330 struct __short
1331 {
1332 union
1333 {
1334 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +00001335 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001336 };
1337 value_type __data_[__min_cap];
1338 };
1339
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001340#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001341
Howard Hinnant499cea12013-08-23 17:37:05 +00001342 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343
Howard Hinnant499cea12013-08-23 17:37:05 +00001344 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345
1346 struct __raw
1347 {
1348 size_type __words[__n_words];
1349 };
1350
1351 struct __rep
1352 {
1353 union
1354 {
1355 __long __l;
1356 __short __s;
1357 __raw __r;
1358 };
1359 };
1360
1361 __compressed_pair<__rep, allocator_type> __r_;
1362
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001363public:
1364 static const size_type npos = -1;
1365
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001366 _LIBCPP_INLINE_VISIBILITY basic_string()
1367 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +00001368
1369 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
1370#if _LIBCPP_STD_VER <= 14
1371 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
1372#else
1373 _NOEXCEPT;
1374#endif
1375
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001376 basic_string(const basic_string& __str);
1377 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +00001378
Howard Hinnant73d21a42010-09-04 23:28:19 +00001379#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59 +00001380 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001381 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001382#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001383 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +00001384#else
1385 _NOEXCEPT;
1386#endif
1387
Howard Hinnant9f193f22011-01-26 00:06:59 +00001388 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001389 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001390#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001391 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001392 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001393 basic_string(const value_type* __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001395 basic_string(const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001396 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001397 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001398 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001399 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001400 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001401 basic_string(size_type __n, value_type __c, const allocator_type& __a);
Marshall Clowff0b9f52016-03-09 17:51:43 +00001402 basic_string(const basic_string& __str, size_type __pos, size_type __n,
1403 const allocator_type& __a = allocator_type());
1404 basic_string(const basic_string& __str, size_type __pos,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001405 const allocator_type& __a = allocator_type());
1406 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408 basic_string(_InputIterator __first, _InputIterator __last);
1409 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001411 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001412#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001414 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001415 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001416 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001417#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001418
1419 ~basic_string();
1420
Howard Hinnante32b5e22010-11-17 17:55:08 +00001421 basic_string& operator=(const basic_string& __str);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001422#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001423 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001424 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001425 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001426#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001427 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001428 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02 +00001429#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001430 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001431 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001432#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001433
Howard Hinnant499cea12013-08-23 17:37:05 +00001434#if _LIBCPP_DEBUG_LEVEL >= 2
1435 _LIBCPP_INLINE_VISIBILITY
1436 iterator begin() _NOEXCEPT
1437 {return iterator(this, __get_pointer());}
1438 _LIBCPP_INLINE_VISIBILITY
1439 const_iterator begin() const _NOEXCEPT
1440 {return const_iterator(this, __get_pointer());}
1441 _LIBCPP_INLINE_VISIBILITY
1442 iterator end() _NOEXCEPT
1443 {return iterator(this, __get_pointer() + size());}
1444 _LIBCPP_INLINE_VISIBILITY
1445 const_iterator end() const _NOEXCEPT
1446 {return const_iterator(this, __get_pointer() + size());}
1447#else
Howard Hinnanta6119a82011-05-29 19:57:12 +00001448 _LIBCPP_INLINE_VISIBILITY
1449 iterator begin() _NOEXCEPT
1450 {return iterator(__get_pointer());}
1451 _LIBCPP_INLINE_VISIBILITY
1452 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001453 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001454 _LIBCPP_INLINE_VISIBILITY
1455 iterator end() _NOEXCEPT
1456 {return iterator(__get_pointer() + size());}
1457 _LIBCPP_INLINE_VISIBILITY
1458 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001459 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +00001460#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +00001461 _LIBCPP_INLINE_VISIBILITY
1462 reverse_iterator rbegin() _NOEXCEPT
1463 {return reverse_iterator(end());}
1464 _LIBCPP_INLINE_VISIBILITY
1465 const_reverse_iterator rbegin() const _NOEXCEPT
1466 {return const_reverse_iterator(end());}
1467 _LIBCPP_INLINE_VISIBILITY
1468 reverse_iterator rend() _NOEXCEPT
1469 {return reverse_iterator(begin());}
1470 _LIBCPP_INLINE_VISIBILITY
1471 const_reverse_iterator rend() const _NOEXCEPT
1472 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001473
Howard Hinnanta6119a82011-05-29 19:57:12 +00001474 _LIBCPP_INLINE_VISIBILITY
1475 const_iterator cbegin() const _NOEXCEPT
1476 {return begin();}
1477 _LIBCPP_INLINE_VISIBILITY
1478 const_iterator cend() const _NOEXCEPT
1479 {return end();}
1480 _LIBCPP_INLINE_VISIBILITY
1481 const_reverse_iterator crbegin() const _NOEXCEPT
1482 {return rbegin();}
1483 _LIBCPP_INLINE_VISIBILITY
1484 const_reverse_iterator crend() const _NOEXCEPT
1485 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001486
Howard Hinnanta6119a82011-05-29 19:57:12 +00001487 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001488 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001489 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
1490 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
1491 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001492 {return (__is_long() ? __get_long_cap()
1493 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001494
1495 void resize(size_type __n, value_type __c);
1496 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
1497
1498 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001500 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001502 void clear() _NOEXCEPT;
1503 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001504
1505 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
1506 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
1507
1508 const_reference at(size_type __n) const;
1509 reference at(size_type __n);
1510
1511 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001512 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001513 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00001514#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001515 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02 +00001516#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001517
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001519 basic_string& append(const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001520 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001521 basic_string& append(const value_type* __s, size_type __n);
1522 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001523 basic_string& append(size_type __n, value_type __c);
1524 template<class _InputIterator>
1525 typename enable_if
1526 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001527 __is_exactly_input_iterator<_InputIterator>::value
1528 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001529 basic_string&
1530 >::type
1531 append(_InputIterator __first, _InputIterator __last);
1532 template<class _ForwardIterator>
1533 typename enable_if
1534 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001535 __is_forward_iterator<_ForwardIterator>::value
1536 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001537 basic_string&
1538 >::type
1539 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001540#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001541 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001542 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001543#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001544
1545 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001546 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001547 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001548 _LIBCPP_INLINE_VISIBILITY reference front();
1549 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1550 _LIBCPP_INLINE_VISIBILITY reference back();
1551 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001552
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001553 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29 +00001554 basic_string& assign(const basic_string& __str) { return *this = __str; }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001555#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1556 _LIBCPP_INLINE_VISIBILITY
1557 basic_string& assign(basic_string&& str)
Marshall Clow7ed093b2015-10-05 16:17:34 +00001558 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +00001559 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001560#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +00001561 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001562 basic_string& assign(const value_type* __s, size_type __n);
1563 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001564 basic_string& assign(size_type __n, value_type __c);
1565 template<class _InputIterator>
1566 typename enable_if
1567 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001568 __is_exactly_input_iterator<_InputIterator>::value
1569 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001570 basic_string&
1571 >::type
1572 assign(_InputIterator __first, _InputIterator __last);
1573 template<class _ForwardIterator>
1574 typename enable_if
1575 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001576 __is_forward_iterator<_ForwardIterator>::value
1577 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001578 basic_string&
1579 >::type
1580 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001581#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001583 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001584#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001585
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001587 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001588 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001589 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1590 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001591 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1592 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001594 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1595 template<class _InputIterator>
1596 typename enable_if
1597 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001598 __is_exactly_input_iterator<_InputIterator>::value
1599 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001600 iterator
1601 >::type
1602 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1603 template<class _ForwardIterator>
1604 typename enable_if
1605 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001606 __is_forward_iterator<_ForwardIterator>::value
1607 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001608 iterator
1609 >::type
1610 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001611#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001613 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1614 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001615#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001616
1617 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001619 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001620 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001621 iterator erase(const_iterator __first, const_iterator __last);
1622
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001624 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001625 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001626 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1627 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001628 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001630 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001632 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001634 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001636 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001637 template<class _InputIterator>
1638 typename enable_if
1639 <
1640 __is_input_iterator<_InputIterator>::value,
1641 basic_string&
1642 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001643 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:02 +00001644#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001646 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001647 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001648#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001649
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001650 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001651 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001652 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1653
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001655 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001656#if _LIBCPP_STD_VER >= 14
1657 _NOEXCEPT;
1658#else
1659 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1660 __is_nothrow_swappable<allocator_type>::value);
1661#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001662
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001664 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001666 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Marshall Clowf532a702016-03-08 15:44:30 +00001667#if _LIBCPP_STD_VER > 14
1668 _LIBCPP_INLINE_VISIBILITY
1669 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1670#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001671
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001673 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001674
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001676 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001677 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001679 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001680 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001681
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001683 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001684 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001686 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001687 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001688
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001690 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001691 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001693 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001694 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001695 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001696
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001698 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001699 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001700 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001701 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001703 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001704
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001706 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001707 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001709 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001710 _LIBCPP_INLINE_VISIBILITY
1711 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1712
1713 _LIBCPP_INLINE_VISIBILITY
1714 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001715 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001717 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001718 _LIBCPP_INLINE_VISIBILITY
1719 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1720
1721 _LIBCPP_INLINE_VISIBILITY
1722 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001724 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001725 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001726 int compare(const value_type* __s) const _NOEXCEPT;
1727 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1728 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001729
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001730 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001731
1732 _LIBCPP_INLINE_VISIBILITY
1733 bool __is_long() const _NOEXCEPT
1734 {return bool(__r_.first().__s.__size_ & __short_mask);}
1735
Howard Hinnant499cea12013-08-23 17:37:05 +00001736#if _LIBCPP_DEBUG_LEVEL >= 2
1737
1738 bool __dereferenceable(const const_iterator* __i) const;
1739 bool __decrementable(const const_iterator* __i) const;
1740 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1741 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1742
1743#endif // _LIBCPP_DEBUG_LEVEL >= 2
1744
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001745private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001746 _LIBCPP_INLINE_VISIBILITY
1747 allocator_type& __alloc() _NOEXCEPT
1748 {return __r_.second();}
1749 _LIBCPP_INLINE_VISIBILITY
1750 const allocator_type& __alloc() const _NOEXCEPT
1751 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001752
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001753#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001754
Howard Hinnanta6119a82011-05-29 19:57:12 +00001755 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001756 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001757# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001758 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001759# else
1760 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1761# endif
1762
Howard Hinnanta6119a82011-05-29 19:57:12 +00001763 _LIBCPP_INLINE_VISIBILITY
1764 size_type __get_short_size() const _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001765# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001766 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001767# else
1768 {return __r_.first().__s.__size_;}
1769# endif
1770
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001771#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001772
1773 _LIBCPP_INLINE_VISIBILITY
1774 void __set_short_size(size_type __s) _NOEXCEPT
1775# if _LIBCPP_BIG_ENDIAN
1776 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1777# else
1778 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1779# endif
1780
1781 _LIBCPP_INLINE_VISIBILITY
1782 size_type __get_short_size() const _NOEXCEPT
1783# if _LIBCPP_BIG_ENDIAN
1784 {return __r_.first().__s.__size_;}
1785# else
1786 {return __r_.first().__s.__size_ >> 1;}
1787# endif
1788
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001789#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001790
Howard Hinnanta6119a82011-05-29 19:57:12 +00001791 _LIBCPP_INLINE_VISIBILITY
1792 void __set_long_size(size_type __s) _NOEXCEPT
1793 {__r_.first().__l.__size_ = __s;}
1794 _LIBCPP_INLINE_VISIBILITY
1795 size_type __get_long_size() const _NOEXCEPT
1796 {return __r_.first().__l.__size_;}
1797 _LIBCPP_INLINE_VISIBILITY
1798 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001799 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1800
Howard Hinnanta6119a82011-05-29 19:57:12 +00001801 _LIBCPP_INLINE_VISIBILITY
1802 void __set_long_cap(size_type __s) _NOEXCEPT
1803 {__r_.first().__l.__cap_ = __long_mask | __s;}
1804 _LIBCPP_INLINE_VISIBILITY
1805 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001806 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001807
Howard Hinnanta6119a82011-05-29 19:57:12 +00001808 _LIBCPP_INLINE_VISIBILITY
1809 void __set_long_pointer(pointer __p) _NOEXCEPT
1810 {__r_.first().__l.__data_ = __p;}
1811 _LIBCPP_INLINE_VISIBILITY
1812 pointer __get_long_pointer() _NOEXCEPT
1813 {return __r_.first().__l.__data_;}
1814 _LIBCPP_INLINE_VISIBILITY
1815 const_pointer __get_long_pointer() const _NOEXCEPT
1816 {return __r_.first().__l.__data_;}
1817 _LIBCPP_INLINE_VISIBILITY
1818 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001819 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001820 _LIBCPP_INLINE_VISIBILITY
1821 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001822 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001823 _LIBCPP_INLINE_VISIBILITY
1824 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001825 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001826 _LIBCPP_INLINE_VISIBILITY
1827 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001828 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1829
Howard Hinnanta6119a82011-05-29 19:57:12 +00001830 _LIBCPP_INLINE_VISIBILITY
1831 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001832 {
1833 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1834 for (unsigned __i = 0; __i < __n_words; ++__i)
1835 __a[__i] = 0;
1836 }
1837
1838 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001840 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001841 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001842 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001843 static _LIBCPP_INLINE_VISIBILITY
1844 size_type __recommend(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001845 {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
Howard Hinnant7f764502013-08-14 18:00:20 +00001846 __align_it<sizeof(value_type) < __alignment ?
Howard Hinnanta6119a82011-05-29 19:57:12 +00001847 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001848
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001849 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1850 void __init(const value_type* __s, size_type __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001851 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001852
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001853 template <class _InputIterator>
1854 typename enable_if
1855 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001856 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001857 void
1858 >::type
1859 __init(_InputIterator __first, _InputIterator __last);
1860
1861 template <class _ForwardIterator>
1862 typename enable_if
1863 <
1864 __is_forward_iterator<_ForwardIterator>::value,
1865 void
1866 >::type
1867 __init(_ForwardIterator __first, _ForwardIterator __last);
1868
1869 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001870 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001871 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1872 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001873 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001874
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001876 void __erase_to_end(size_type __pos);
1877
Howard Hinnante32b5e22010-11-17 17:55:08 +00001878 _LIBCPP_INLINE_VISIBILITY
1879 void __copy_assign_alloc(const basic_string& __str)
1880 {__copy_assign_alloc(__str, integral_constant<bool,
1881 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1882
1883 _LIBCPP_INLINE_VISIBILITY
1884 void __copy_assign_alloc(const basic_string& __str, true_type)
1885 {
1886 if (__alloc() != __str.__alloc())
1887 {
1888 clear();
1889 shrink_to_fit();
1890 }
1891 __alloc() = __str.__alloc();
1892 }
1893
1894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001895 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001896 {}
1897
1898#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001899 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001900 void __move_assign(basic_string& __str, false_type)
1901 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001903 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001904#if _LIBCPP_STD_VER > 14
1905 _NOEXCEPT;
1906#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001907 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001908#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001909#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001910
1911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001912 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001913 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001914 _NOEXCEPT_(
1915 !__alloc_traits::propagate_on_container_move_assignment::value ||
1916 is_nothrow_move_assignable<allocator_type>::value)
1917 {__move_assign_alloc(__str, integral_constant<bool,
1918 __alloc_traits::propagate_on_container_move_assignment::value>());}
1919
1920 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001921 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001922 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1923 {
1924 __alloc() = _VSTD::move(__c.__alloc());
1925 }
1926
1927 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001928 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001929 _NOEXCEPT
1930 {}
1931
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001932 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1933 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001934
1935 friend basic_string operator+<>(const basic_string&, const basic_string&);
1936 friend basic_string operator+<>(const value_type*, const basic_string&);
1937 friend basic_string operator+<>(value_type, const basic_string&);
1938 friend basic_string operator+<>(const basic_string&, const value_type*);
1939 friend basic_string operator+<>(const basic_string&, value_type);
1940};
1941
1942template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001943inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001944void
1945basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1946{
Howard Hinnant499cea12013-08-23 17:37:05 +00001947#if _LIBCPP_DEBUG_LEVEL >= 2
1948 __get_db()->__invalidate_all(this);
1949#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001950}
1951
1952template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001953inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001954void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001955basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001956#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001957 __pos
1958#endif
1959 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001960{
Howard Hinnant499cea12013-08-23 17:37:05 +00001961#if _LIBCPP_DEBUG_LEVEL >= 2
1962 __c_node* __c = __get_db()->__find_c_and_lock(this);
1963 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001964 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001965 const_pointer __new_last = __get_pointer() + __pos;
1966 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001967 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001968 --__p;
1969 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1970 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001971 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001972 (*__p)->__c_ = nullptr;
1973 if (--__c->end_ != __p)
1974 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001975 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001976 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001977 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001978 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001979#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001980}
1981
1982template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001983inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001984basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001985 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001986{
Howard Hinnant499cea12013-08-23 17:37:05 +00001987#if _LIBCPP_DEBUG_LEVEL >= 2
1988 __get_db()->__insert_c(this);
1989#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001990 __zero();
1991}
1992
1993template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001994inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001995basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001996#if _LIBCPP_STD_VER <= 14
1997 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1998#else
1999 _NOEXCEPT
2000#endif
2001: __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002002{
Howard Hinnant499cea12013-08-23 17:37:05 +00002003#if _LIBCPP_DEBUG_LEVEL >= 2
2004 __get_db()->__insert_c(this);
2005#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002006 __zero();
2007}
2008
2009template <class _CharT, class _Traits, class _Allocator>
2010void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002011basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002012{
2013 if (__reserve > max_size())
2014 this->__throw_length_error();
2015 pointer __p;
2016 if (__reserve < __min_cap)
2017 {
2018 __set_short_size(__sz);
2019 __p = __get_short_pointer();
2020 }
2021 else
2022 {
2023 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002024 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002025 __set_long_pointer(__p);
2026 __set_long_cap(__cap+1);
2027 __set_long_size(__sz);
2028 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002029 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002030 traits_type::assign(__p[__sz], value_type());
2031}
2032
2033template <class _CharT, class _Traits, class _Allocator>
2034void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002035basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002036{
2037 if (__sz > max_size())
2038 this->__throw_length_error();
2039 pointer __p;
2040 if (__sz < __min_cap)
2041 {
2042 __set_short_size(__sz);
2043 __p = __get_short_pointer();
2044 }
2045 else
2046 {
2047 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002048 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002049 __set_long_pointer(__p);
2050 __set_long_cap(__cap+1);
2051 __set_long_size(__sz);
2052 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002053 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002054 traits_type::assign(__p[__sz], value_type());
2055}
2056
2057template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002058inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002059basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002060{
Howard Hinnant499cea12013-08-23 17:37:05 +00002061 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002062 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00002063#if _LIBCPP_DEBUG_LEVEL >= 2
2064 __get_db()->__insert_c(this);
2065#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002066}
2067
2068template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002069inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002070basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002071 : __r_(__a)
2072{
Howard Hinnant499cea12013-08-23 17:37:05 +00002073 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002074 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00002075#if _LIBCPP_DEBUG_LEVEL >= 2
2076 __get_db()->__insert_c(this);
2077#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002078}
2079
2080template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002081inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002082basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002083{
Howard Hinnant499cea12013-08-23 17:37:05 +00002084 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002085 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00002086#if _LIBCPP_DEBUG_LEVEL >= 2
2087 __get_db()->__insert_c(this);
2088#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002089}
2090
2091template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002092inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002093basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002094 : __r_(__a)
2095{
Howard Hinnant499cea12013-08-23 17:37:05 +00002096 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002097 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00002098#if _LIBCPP_DEBUG_LEVEL >= 2
2099 __get_db()->__insert_c(this);
2100#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002101}
2102
2103template <class _CharT, class _Traits, class _Allocator>
2104basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002105 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002106{
2107 if (!__str.__is_long())
2108 __r_.first().__r = __str.__r_.first().__r;
2109 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002110 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00002111#if _LIBCPP_DEBUG_LEVEL >= 2
2112 __get_db()->__insert_c(this);
2113#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002114}
2115
2116template <class _CharT, class _Traits, class _Allocator>
2117basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
2118 : __r_(__a)
2119{
2120 if (!__str.__is_long())
2121 __r_.first().__r = __str.__r_.first().__r;
2122 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002123 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00002124#if _LIBCPP_DEBUG_LEVEL >= 2
2125 __get_db()->__insert_c(this);
2126#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002127}
2128
Howard Hinnant73d21a42010-09-04 23:28:19 +00002129#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002130
2131template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002132inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002133basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00002134#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002135 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00002136#else
2137 _NOEXCEPT
2138#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00002139 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002140{
2141 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00002142#if _LIBCPP_DEBUG_LEVEL >= 2
2143 __get_db()->__insert_c(this);
2144 if (__is_long())
2145 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002146#endif
2147}
2148
2149template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002150inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002151basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002152 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002153{
Marshall Clowd5549cc2014-07-17 15:32:20 +00002154 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002155 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00002156 else
2157 {
2158 __r_.first().__r = __str.__r_.first().__r;
2159 __str.__zero();
2160 }
Howard Hinnant499cea12013-08-23 17:37:05 +00002161#if _LIBCPP_DEBUG_LEVEL >= 2
2162 __get_db()->__insert_c(this);
2163 if (__is_long())
2164 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002165#endif
2166}
2167
Howard Hinnant73d21a42010-09-04 23:28:19 +00002168#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002169
2170template <class _CharT, class _Traits, class _Allocator>
2171void
2172basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
2173{
2174 if (__n > max_size())
2175 this->__throw_length_error();
2176 pointer __p;
2177 if (__n < __min_cap)
2178 {
2179 __set_short_size(__n);
2180 __p = __get_short_pointer();
2181 }
2182 else
2183 {
2184 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002185 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002186 __set_long_pointer(__p);
2187 __set_long_cap(__cap+1);
2188 __set_long_size(__n);
2189 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002190 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002191 traits_type::assign(__p[__n], value_type());
2192}
2193
2194template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002195inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002196basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
2197{
2198 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00002199#if _LIBCPP_DEBUG_LEVEL >= 2
2200 __get_db()->__insert_c(this);
2201#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002202}
2203
2204template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002205inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002206basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
2207 : __r_(__a)
2208{
2209 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00002210#if _LIBCPP_DEBUG_LEVEL >= 2
2211 __get_db()->__insert_c(this);
2212#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002213}
2214
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002215template <class _CharT, class _Traits, class _Allocator>
2216basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
2217 const allocator_type& __a)
2218 : __r_(__a)
2219{
2220 size_type __str_sz = __str.size();
2221 if (__pos > __str_sz)
2222 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002223 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00002224#if _LIBCPP_DEBUG_LEVEL >= 2
2225 __get_db()->__insert_c(this);
2226#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002227}
2228
2229template <class _CharT, class _Traits, class _Allocator>
Marshall Clowff0b9f52016-03-09 17:51:43 +00002230basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
2231 const allocator_type& __a)
2232 : __r_(__a)
2233{
2234 size_type __str_sz = __str.size();
2235 if (__pos > __str_sz)
2236 this->__throw_out_of_range();
2237 __init(__str.data() + __pos, __str_sz - __pos);
2238#if _LIBCPP_DEBUG_LEVEL >= 2
2239 __get_db()->__insert_c(this);
2240#endif
2241}
2242
2243template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002244template <class _InputIterator>
2245typename enable_if
2246<
Marshall Clowdf9db312016-01-13 21:54:34 +00002247 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002248 void
2249>::type
2250basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2251{
2252 __zero();
2253#ifndef _LIBCPP_NO_EXCEPTIONS
2254 try
2255 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002256#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002257 for (; __first != __last; ++__first)
2258 push_back(*__first);
2259#ifndef _LIBCPP_NO_EXCEPTIONS
2260 }
2261 catch (...)
2262 {
2263 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002264 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002265 throw;
2266 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002267#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002268}
2269
2270template <class _CharT, class _Traits, class _Allocator>
2271template <class _ForwardIterator>
2272typename enable_if
2273<
2274 __is_forward_iterator<_ForwardIterator>::value,
2275 void
2276>::type
2277basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2278{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002279 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002280 if (__sz > max_size())
2281 this->__throw_length_error();
2282 pointer __p;
2283 if (__sz < __min_cap)
2284 {
2285 __set_short_size(__sz);
2286 __p = __get_short_pointer();
2287 }
2288 else
2289 {
2290 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002291 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002292 __set_long_pointer(__p);
2293 __set_long_cap(__cap+1);
2294 __set_long_size(__sz);
2295 }
Eric Fiselierb9919752014-10-27 19:28:20 +00002296 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002297 traits_type::assign(*__p, *__first);
2298 traits_type::assign(*__p, value_type());
2299}
2300
2301template <class _CharT, class _Traits, class _Allocator>
2302template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002303inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002304basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2305{
2306 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002307#if _LIBCPP_DEBUG_LEVEL >= 2
2308 __get_db()->__insert_c(this);
2309#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002310}
2311
2312template <class _CharT, class _Traits, class _Allocator>
2313template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002314inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002315basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2316 const allocator_type& __a)
2317 : __r_(__a)
2318{
2319 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002320#if _LIBCPP_DEBUG_LEVEL >= 2
2321 __get_db()->__insert_c(this);
2322#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002323}
2324
Howard Hinnante3e32912011-08-12 21:56:02 +00002325#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2326
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002327template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002328inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002329basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
2330{
2331 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002332#if _LIBCPP_DEBUG_LEVEL >= 2
2333 __get_db()->__insert_c(this);
2334#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002335}
2336
2337template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002338inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002339basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
2340 : __r_(__a)
2341{
2342 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002343#if _LIBCPP_DEBUG_LEVEL >= 2
2344 __get_db()->__insert_c(this);
2345#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002346}
2347
Howard Hinnante3e32912011-08-12 21:56:02 +00002348#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2349
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002350template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002351basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2352{
Howard Hinnant499cea12013-08-23 17:37:05 +00002353#if _LIBCPP_DEBUG_LEVEL >= 2
2354 __get_db()->__erase_c(this);
2355#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002356 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002357 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002358}
2359
2360template <class _CharT, class _Traits, class _Allocator>
2361void
2362basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2363 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002364 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002365{
2366 size_type __ms = max_size();
2367 if (__delta_cap > __ms - __old_cap - 1)
2368 this->__throw_length_error();
2369 pointer __old_p = __get_pointer();
2370 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002371 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002372 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002373 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002374 __invalidate_all_iterators();
2375 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002376 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2377 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002378 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002379 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002380 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2381 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002382 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2383 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002384 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002385 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002386 __set_long_pointer(__p);
2387 __set_long_cap(__cap+1);
2388 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2389 __set_long_size(__old_sz);
2390 traits_type::assign(__p[__old_sz], value_type());
2391}
2392
2393template <class _CharT, class _Traits, class _Allocator>
2394void
2395basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2396 size_type __n_copy, size_type __n_del, size_type __n_add)
2397{
2398 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00002399 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002400 this->__throw_length_error();
2401 pointer __old_p = __get_pointer();
2402 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002403 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002404 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002405 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002406 __invalidate_all_iterators();
2407 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002408 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2409 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002410 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2411 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002412 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2413 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2414 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002415 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002416 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002417 __set_long_pointer(__p);
2418 __set_long_cap(__cap+1);
2419}
2420
2421// assign
2422
2423template <class _CharT, class _Traits, class _Allocator>
2424basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002425basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002426{
Alp Tokerec34c482014-05-15 11:27:39 +00002427 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002428 size_type __cap = capacity();
2429 if (__cap >= __n)
2430 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002431 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002432 traits_type::move(__p, __s, __n);
2433 traits_type::assign(__p[__n], value_type());
2434 __set_size(__n);
2435 __invalidate_iterators_past(__n);
2436 }
2437 else
2438 {
2439 size_type __sz = size();
2440 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2441 }
2442 return *this;
2443}
2444
2445template <class _CharT, class _Traits, class _Allocator>
2446basic_string<_CharT, _Traits, _Allocator>&
2447basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2448{
2449 size_type __cap = capacity();
2450 if (__cap < __n)
2451 {
2452 size_type __sz = size();
2453 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2454 }
2455 else
2456 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002457 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002458 traits_type::assign(__p, __n, __c);
2459 traits_type::assign(__p[__n], value_type());
2460 __set_size(__n);
2461 return *this;
2462}
2463
2464template <class _CharT, class _Traits, class _Allocator>
2465basic_string<_CharT, _Traits, _Allocator>&
2466basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2467{
2468 pointer __p;
2469 if (__is_long())
2470 {
2471 __p = __get_long_pointer();
2472 __set_long_size(1);
2473 }
2474 else
2475 {
2476 __p = __get_short_pointer();
2477 __set_short_size(1);
2478 }
2479 traits_type::assign(*__p, __c);
2480 traits_type::assign(*++__p, value_type());
2481 __invalidate_iterators_past(1);
2482 return *this;
2483}
2484
2485template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002486basic_string<_CharT, _Traits, _Allocator>&
2487basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2488{
2489 if (this != &__str)
2490 {
2491 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00002492 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00002493 }
2494 return *this;
2495}
2496
2497#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2498
2499template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002500inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002501void
2502basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002503 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002504{
2505 if (__alloc() != __str.__alloc())
2506 assign(__str);
2507 else
2508 __move_assign(__str, true_type());
2509}
2510
2511template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002512inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002513void
2514basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002515#if _LIBCPP_STD_VER > 14
2516 _NOEXCEPT
2517#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002518 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002519#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002520{
2521 clear();
2522 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002523 __r_.first() = __str.__r_.first();
2524 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002525 __str.__zero();
2526}
2527
2528template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002529inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002530basic_string<_CharT, _Traits, _Allocator>&
2531basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002532 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002533{
2534 __move_assign(__str, integral_constant<bool,
2535 __alloc_traits::propagate_on_container_move_assignment::value>());
2536 return *this;
2537}
2538
2539#endif
2540
2541template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002542template<class _InputIterator>
2543typename enable_if
2544<
Marshall Clowdf9db312016-01-13 21:54:34 +00002545 __is_exactly_input_iterator <_InputIterator>::value
2546 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002547 basic_string<_CharT, _Traits, _Allocator>&
2548>::type
2549basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2550{
Marshall Clowdf9db312016-01-13 21:54:34 +00002551 basic_string __temp(__first, __last, __alloc());
2552 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002553 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002554}
2555
2556template <class _CharT, class _Traits, class _Allocator>
2557template<class _ForwardIterator>
2558typename enable_if
2559<
Marshall Clowdf9db312016-01-13 21:54:34 +00002560 __is_forward_iterator<_ForwardIterator>::value
2561 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002562 basic_string<_CharT, _Traits, _Allocator>&
2563>::type
2564basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2565{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002566 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002567 size_type __cap = capacity();
2568 if (__cap < __n)
2569 {
2570 size_type __sz = size();
2571 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2572 }
2573 else
2574 __invalidate_iterators_past(__n);
2575 pointer __p = __get_pointer();
2576 for (; __first != __last; ++__first, ++__p)
2577 traits_type::assign(*__p, *__first);
2578 traits_type::assign(*__p, value_type());
2579 __set_size(__n);
2580 return *this;
2581}
2582
2583template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002584basic_string<_CharT, _Traits, _Allocator>&
2585basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2586{
2587 size_type __sz = __str.size();
2588 if (__pos > __sz)
2589 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002590 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002591}
2592
2593template <class _CharT, class _Traits, class _Allocator>
2594basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002595basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002596{
Alp Tokerec34c482014-05-15 11:27:39 +00002597 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002598 return assign(__s, traits_type::length(__s));
2599}
2600
2601// append
2602
2603template <class _CharT, class _Traits, class _Allocator>
2604basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002605basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002606{
Alp Tokerec34c482014-05-15 11:27:39 +00002607 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002608 size_type __cap = capacity();
2609 size_type __sz = size();
2610 if (__cap - __sz >= __n)
2611 {
2612 if (__n)
2613 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002614 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002615 traits_type::copy(__p + __sz, __s, __n);
2616 __sz += __n;
2617 __set_size(__sz);
2618 traits_type::assign(__p[__sz], value_type());
2619 }
2620 }
2621 else
2622 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2623 return *this;
2624}
2625
2626template <class _CharT, class _Traits, class _Allocator>
2627basic_string<_CharT, _Traits, _Allocator>&
2628basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2629{
2630 if (__n)
2631 {
2632 size_type __cap = capacity();
2633 size_type __sz = size();
2634 if (__cap - __sz < __n)
2635 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2636 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002637 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002638 __sz += __n;
2639 __set_size(__sz);
2640 traits_type::assign(__p[__sz], value_type());
2641 }
2642 return *this;
2643}
2644
2645template <class _CharT, class _Traits, class _Allocator>
2646void
2647basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2648{
Howard Hinnant15467182013-04-30 21:44:48 +00002649 bool __is_short = !__is_long();
2650 size_type __cap;
2651 size_type __sz;
2652 if (__is_short)
2653 {
2654 __cap = __min_cap - 1;
2655 __sz = __get_short_size();
2656 }
2657 else
2658 {
2659 __cap = __get_long_cap() - 1;
2660 __sz = __get_long_size();
2661 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002662 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002663 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002664 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002665 __is_short = !__is_long();
2666 }
2667 pointer __p;
2668 if (__is_short)
2669 {
2670 __p = __get_short_pointer() + __sz;
2671 __set_short_size(__sz+1);
2672 }
2673 else
2674 {
2675 __p = __get_long_pointer() + __sz;
2676 __set_long_size(__sz+1);
2677 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002678 traits_type::assign(*__p, __c);
2679 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002680}
2681
2682template <class _CharT, class _Traits, class _Allocator>
2683template<class _InputIterator>
2684typename enable_if
2685<
Marshall Clowdf9db312016-01-13 21:54:34 +00002686 __is_exactly_input_iterator<_InputIterator>::value
2687 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002688 basic_string<_CharT, _Traits, _Allocator>&
2689>::type
2690basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2691{
Marshall Clowdf9db312016-01-13 21:54:34 +00002692 basic_string __temp (__first, __last, __alloc());
2693 append(__temp.data(), __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002694 return *this;
2695}
2696
2697template <class _CharT, class _Traits, class _Allocator>
2698template<class _ForwardIterator>
2699typename enable_if
2700<
Marshall Clowdf9db312016-01-13 21:54:34 +00002701 __is_forward_iterator<_ForwardIterator>::value
2702 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002703 basic_string<_CharT, _Traits, _Allocator>&
2704>::type
2705basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2706{
2707 size_type __sz = size();
2708 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002709 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002710 if (__n)
2711 {
2712 if (__cap - __sz < __n)
2713 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2714 pointer __p = __get_pointer() + __sz;
2715 for (; __first != __last; ++__p, ++__first)
2716 traits_type::assign(*__p, *__first);
2717 traits_type::assign(*__p, value_type());
2718 __set_size(__sz + __n);
2719 }
2720 return *this;
2721}
2722
2723template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002724inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002725basic_string<_CharT, _Traits, _Allocator>&
2726basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2727{
2728 return append(__str.data(), __str.size());
2729}
2730
2731template <class _CharT, class _Traits, class _Allocator>
2732basic_string<_CharT, _Traits, _Allocator>&
2733basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2734{
2735 size_type __sz = __str.size();
2736 if (__pos > __sz)
2737 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002738 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002739}
2740
2741template <class _CharT, class _Traits, class _Allocator>
2742basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002743basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002744{
Alp Tokerec34c482014-05-15 11:27:39 +00002745 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002746 return append(__s, traits_type::length(__s));
2747}
2748
2749// insert
2750
2751template <class _CharT, class _Traits, class _Allocator>
2752basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002753basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002754{
Alp Tokerec34c482014-05-15 11:27:39 +00002755 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002756 size_type __sz = size();
2757 if (__pos > __sz)
2758 this->__throw_out_of_range();
2759 size_type __cap = capacity();
2760 if (__cap - __sz >= __n)
2761 {
2762 if (__n)
2763 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002764 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002765 size_type __n_move = __sz - __pos;
2766 if (__n_move != 0)
2767 {
2768 if (__p + __pos <= __s && __s < __p + __sz)
2769 __s += __n;
2770 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2771 }
2772 traits_type::move(__p + __pos, __s, __n);
2773 __sz += __n;
2774 __set_size(__sz);
2775 traits_type::assign(__p[__sz], value_type());
2776 }
2777 }
2778 else
2779 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2780 return *this;
2781}
2782
2783template <class _CharT, class _Traits, class _Allocator>
2784basic_string<_CharT, _Traits, _Allocator>&
2785basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2786{
2787 size_type __sz = size();
2788 if (__pos > __sz)
2789 this->__throw_out_of_range();
2790 if (__n)
2791 {
2792 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002793 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002794 if (__cap - __sz >= __n)
2795 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002796 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002797 size_type __n_move = __sz - __pos;
2798 if (__n_move != 0)
2799 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2800 }
2801 else
2802 {
2803 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002804 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002805 }
2806 traits_type::assign(__p + __pos, __n, __c);
2807 __sz += __n;
2808 __set_size(__sz);
2809 traits_type::assign(__p[__sz], value_type());
2810 }
2811 return *this;
2812}
2813
2814template <class _CharT, class _Traits, class _Allocator>
2815template<class _InputIterator>
2816typename enable_if
2817<
Marshall Clowdf9db312016-01-13 21:54:34 +00002818 __is_exactly_input_iterator<_InputIterator>::value
2819 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2820 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002821>::type
2822basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2823{
Howard Hinnant499cea12013-08-23 17:37:05 +00002824#if _LIBCPP_DEBUG_LEVEL >= 2
2825 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2826 "string::insert(iterator, range) called with an iterator not"
2827 " referring to this string");
2828#endif
Marshall Clowdf9db312016-01-13 21:54:34 +00002829 basic_string __temp(__first, __last, __alloc());
2830 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002831}
2832
2833template <class _CharT, class _Traits, class _Allocator>
2834template<class _ForwardIterator>
2835typename enable_if
2836<
Marshall Clowdf9db312016-01-13 21:54:34 +00002837 __is_forward_iterator<_ForwardIterator>::value
2838 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002839 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2840>::type
2841basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2842{
Howard Hinnant499cea12013-08-23 17:37:05 +00002843#if _LIBCPP_DEBUG_LEVEL >= 2
2844 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2845 "string::insert(iterator, range) called with an iterator not"
2846 " referring to this string");
2847#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002848 size_type __ip = static_cast<size_type>(__pos - begin());
2849 size_type __sz = size();
2850 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002851 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002852 if (__n)
2853 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002854 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002855 if (__cap - __sz >= __n)
2856 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002857 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002858 size_type __n_move = __sz - __ip;
2859 if (__n_move != 0)
2860 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2861 }
2862 else
2863 {
2864 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002865 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002866 }
2867 __sz += __n;
2868 __set_size(__sz);
2869 traits_type::assign(__p[__sz], value_type());
2870 for (__p += __ip; __first != __last; ++__p, ++__first)
2871 traits_type::assign(*__p, *__first);
2872 }
2873 return begin() + __ip;
2874}
2875
2876template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002877inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002878basic_string<_CharT, _Traits, _Allocator>&
2879basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2880{
2881 return insert(__pos1, __str.data(), __str.size());
2882}
2883
2884template <class _CharT, class _Traits, class _Allocator>
2885basic_string<_CharT, _Traits, _Allocator>&
2886basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2887 size_type __pos2, size_type __n)
2888{
2889 size_type __str_sz = __str.size();
2890 if (__pos2 > __str_sz)
2891 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002892 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002893}
2894
2895template <class _CharT, class _Traits, class _Allocator>
2896basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002897basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002898{
Alp Tokerec34c482014-05-15 11:27:39 +00002899 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002900 return insert(__pos, __s, traits_type::length(__s));
2901}
2902
2903template <class _CharT, class _Traits, class _Allocator>
2904typename basic_string<_CharT, _Traits, _Allocator>::iterator
2905basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2906{
2907 size_type __ip = static_cast<size_type>(__pos - begin());
2908 size_type __sz = size();
2909 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002910 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002911 if (__cap == __sz)
2912 {
2913 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002914 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002915 }
2916 else
2917 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002918 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002919 size_type __n_move = __sz - __ip;
2920 if (__n_move != 0)
2921 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2922 }
2923 traits_type::assign(__p[__ip], __c);
2924 traits_type::assign(__p[++__sz], value_type());
2925 __set_size(__sz);
2926 return begin() + static_cast<difference_type>(__ip);
2927}
2928
2929template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002930inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002931typename basic_string<_CharT, _Traits, _Allocator>::iterator
2932basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2933{
Howard Hinnant499cea12013-08-23 17:37:05 +00002934#if _LIBCPP_DEBUG_LEVEL >= 2
2935 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2936 "string::insert(iterator, n, value) called with an iterator not"
2937 " referring to this string");
2938#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002939 difference_type __p = __pos - begin();
2940 insert(static_cast<size_type>(__p), __n, __c);
2941 return begin() + __p;
2942}
2943
2944// replace
2945
2946template <class _CharT, class _Traits, class _Allocator>
2947basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002948basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002949{
Alp Tokerec34c482014-05-15 11:27:39 +00002950 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002951 size_type __sz = size();
2952 if (__pos > __sz)
2953 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002954 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002955 size_type __cap = capacity();
2956 if (__cap - __sz + __n1 >= __n2)
2957 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002958 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002959 if (__n1 != __n2)
2960 {
2961 size_type __n_move = __sz - __pos - __n1;
2962 if (__n_move != 0)
2963 {
2964 if (__n1 > __n2)
2965 {
2966 traits_type::move(__p + __pos, __s, __n2);
2967 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2968 goto __finish;
2969 }
2970 if (__p + __pos < __s && __s < __p + __sz)
2971 {
2972 if (__p + __pos + __n1 <= __s)
2973 __s += __n2 - __n1;
2974 else // __p + __pos < __s < __p + __pos + __n1
2975 {
2976 traits_type::move(__p + __pos, __s, __n1);
2977 __pos += __n1;
2978 __s += __n2;
2979 __n2 -= __n1;
2980 __n1 = 0;
2981 }
2982 }
2983 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2984 }
2985 }
2986 traits_type::move(__p + __pos, __s, __n2);
2987__finish:
2988 __sz += __n2 - __n1;
2989 __set_size(__sz);
2990 __invalidate_iterators_past(__sz);
2991 traits_type::assign(__p[__sz], value_type());
2992 }
2993 else
2994 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2995 return *this;
2996}
2997
2998template <class _CharT, class _Traits, class _Allocator>
2999basic_string<_CharT, _Traits, _Allocator>&
3000basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
3001{
3002 size_type __sz = size();
3003 if (__pos > __sz)
3004 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003005 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003006 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003007 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003008 if (__cap - __sz + __n1 >= __n2)
3009 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003010 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003011 if (__n1 != __n2)
3012 {
3013 size_type __n_move = __sz - __pos - __n1;
3014 if (__n_move != 0)
3015 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
3016 }
3017 }
3018 else
3019 {
3020 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003021 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003022 }
3023 traits_type::assign(__p + __pos, __n2, __c);
3024 __sz += __n2 - __n1;
3025 __set_size(__sz);
3026 __invalidate_iterators_past(__sz);
3027 traits_type::assign(__p[__sz], value_type());
3028 return *this;
3029}
3030
3031template <class _CharT, class _Traits, class _Allocator>
3032template<class _InputIterator>
3033typename enable_if
3034<
3035 __is_input_iterator<_InputIterator>::value,
3036 basic_string<_CharT, _Traits, _Allocator>&
3037>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003038basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003039 _InputIterator __j1, _InputIterator __j2)
3040{
Marshall Clowdf9db312016-01-13 21:54:34 +00003041 basic_string __temp(__j1, __j2, __alloc());
3042 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003043}
3044
3045template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003046inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003047basic_string<_CharT, _Traits, _Allocator>&
3048basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
3049{
3050 return replace(__pos1, __n1, __str.data(), __str.size());
3051}
3052
3053template <class _CharT, class _Traits, class _Allocator>
3054basic_string<_CharT, _Traits, _Allocator>&
3055basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
3056 size_type __pos2, size_type __n2)
3057{
3058 size_type __str_sz = __str.size();
3059 if (__pos2 > __str_sz)
3060 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003061 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003062}
3063
3064template <class _CharT, class _Traits, class _Allocator>
3065basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003066basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003067{
Alp Tokerec34c482014-05-15 11:27:39 +00003068 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003069 return replace(__pos, __n1, __s, traits_type::length(__s));
3070}
3071
3072template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003073inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003074basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003075basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003076{
3077 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
3078 __str.data(), __str.size());
3079}
3080
3081template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003082inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003083basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003084basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003085{
3086 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
3087}
3088
3089template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003090inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003091basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003092basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003093{
3094 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
3095}
3096
3097template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003098inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003099basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003100basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003101{
3102 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
3103}
3104
3105// erase
3106
3107template <class _CharT, class _Traits, class _Allocator>
3108basic_string<_CharT, _Traits, _Allocator>&
3109basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
3110{
3111 size_type __sz = size();
3112 if (__pos > __sz)
3113 this->__throw_out_of_range();
3114 if (__n)
3115 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003116 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00003117 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003118 size_type __n_move = __sz - __pos - __n;
3119 if (__n_move != 0)
3120 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3121 __sz -= __n;
3122 __set_size(__sz);
3123 __invalidate_iterators_past(__sz);
3124 traits_type::assign(__p[__sz], value_type());
3125 }
3126 return *this;
3127}
3128
3129template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003130inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003131typename basic_string<_CharT, _Traits, _Allocator>::iterator
3132basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3133{
Howard Hinnant499cea12013-08-23 17:37:05 +00003134#if _LIBCPP_DEBUG_LEVEL >= 2
3135 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3136 "string::erase(iterator) called with an iterator not"
3137 " referring to this string");
3138#endif
3139 _LIBCPP_ASSERT(__pos != end(),
3140 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003141 iterator __b = begin();
3142 size_type __r = static_cast<size_type>(__pos - __b);
3143 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00003144 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003145}
3146
3147template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003148inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003149typename basic_string<_CharT, _Traits, _Allocator>::iterator
3150basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3151{
Howard Hinnant499cea12013-08-23 17:37:05 +00003152#if _LIBCPP_DEBUG_LEVEL >= 2
3153 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3154 "string::erase(iterator, iterator) called with an iterator not"
3155 " referring to this string");
3156#endif
3157 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003158 iterator __b = begin();
3159 size_type __r = static_cast<size_type>(__first - __b);
3160 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00003161 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003162}
3163
3164template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003165inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003166void
3167basic_string<_CharT, _Traits, _Allocator>::pop_back()
3168{
Howard Hinnant499cea12013-08-23 17:37:05 +00003169 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003170 size_type __sz;
3171 if (__is_long())
3172 {
3173 __sz = __get_long_size() - 1;
3174 __set_long_size(__sz);
3175 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3176 }
3177 else
3178 {
3179 __sz = __get_short_size() - 1;
3180 __set_short_size(__sz);
3181 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3182 }
3183 __invalidate_iterators_past(__sz);
3184}
3185
3186template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003187inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003188void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003189basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003190{
3191 __invalidate_all_iterators();
3192 if (__is_long())
3193 {
3194 traits_type::assign(*__get_long_pointer(), value_type());
3195 __set_long_size(0);
3196 }
3197 else
3198 {
3199 traits_type::assign(*__get_short_pointer(), value_type());
3200 __set_short_size(0);
3201 }
3202}
3203
3204template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003205inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003206void
3207basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3208{
3209 if (__is_long())
3210 {
3211 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3212 __set_long_size(__pos);
3213 }
3214 else
3215 {
3216 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3217 __set_short_size(__pos);
3218 }
3219 __invalidate_iterators_past(__pos);
3220}
3221
3222template <class _CharT, class _Traits, class _Allocator>
3223void
3224basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3225{
3226 size_type __sz = size();
3227 if (__n > __sz)
3228 append(__n - __sz, __c);
3229 else
3230 __erase_to_end(__n);
3231}
3232
3233template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003234inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003235typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003236basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003237{
Howard Hinnante32b5e22010-11-17 17:55:08 +00003238 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003239#if _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00003240 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003241#else
Marshall Clow09f85502013-10-31 17:23:08 +00003242 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003243#endif
3244}
3245
3246template <class _CharT, class _Traits, class _Allocator>
3247void
3248basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3249{
3250 if (__res_arg > max_size())
3251 this->__throw_length_error();
3252 size_type __cap = capacity();
3253 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003254 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003255 __res_arg = __recommend(__res_arg);
3256 if (__res_arg != __cap)
3257 {
3258 pointer __new_data, __p;
3259 bool __was_long, __now_long;
3260 if (__res_arg == __min_cap - 1)
3261 {
3262 __was_long = true;
3263 __now_long = false;
3264 __new_data = __get_short_pointer();
3265 __p = __get_long_pointer();
3266 }
3267 else
3268 {
3269 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003270 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003271 else
3272 {
3273 #ifndef _LIBCPP_NO_EXCEPTIONS
3274 try
3275 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003276 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00003277 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003278 #ifndef _LIBCPP_NO_EXCEPTIONS
3279 }
3280 catch (...)
3281 {
3282 return;
3283 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003284 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003285 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003286 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003287 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003288 }
3289 __now_long = true;
3290 __was_long = __is_long();
3291 __p = __get_pointer();
3292 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003293 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3294 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003295 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003296 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003297 if (__now_long)
3298 {
3299 __set_long_cap(__res_arg+1);
3300 __set_long_size(__sz);
3301 __set_long_pointer(__new_data);
3302 }
3303 else
3304 __set_short_size(__sz);
3305 __invalidate_all_iterators();
3306 }
3307}
3308
3309template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003310inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003311typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3312basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
3313{
Howard Hinnant499cea12013-08-23 17:37:05 +00003314 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003315 return *(data() + __pos);
3316}
3317
3318template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003319inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003320typename basic_string<_CharT, _Traits, _Allocator>::reference
3321basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
3322{
Howard Hinnant499cea12013-08-23 17:37:05 +00003323 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003324 return *(__get_pointer() + __pos);
3325}
3326
3327template <class _CharT, class _Traits, class _Allocator>
3328typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3329basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3330{
3331 if (__n >= size())
3332 this->__throw_out_of_range();
3333 return (*this)[__n];
3334}
3335
3336template <class _CharT, class _Traits, class _Allocator>
3337typename basic_string<_CharT, _Traits, _Allocator>::reference
3338basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3339{
3340 if (__n >= size())
3341 this->__throw_out_of_range();
3342 return (*this)[__n];
3343}
3344
3345template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003346inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003347typename basic_string<_CharT, _Traits, _Allocator>::reference
3348basic_string<_CharT, _Traits, _Allocator>::front()
3349{
Howard Hinnant499cea12013-08-23 17:37:05 +00003350 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003351 return *__get_pointer();
3352}
3353
3354template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003355inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003356typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3357basic_string<_CharT, _Traits, _Allocator>::front() const
3358{
Howard Hinnant499cea12013-08-23 17:37:05 +00003359 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003360 return *data();
3361}
3362
3363template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003364inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003365typename basic_string<_CharT, _Traits, _Allocator>::reference
3366basic_string<_CharT, _Traits, _Allocator>::back()
3367{
Howard Hinnant499cea12013-08-23 17:37:05 +00003368 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003369 return *(__get_pointer() + size() - 1);
3370}
3371
3372template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003373inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003374typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3375basic_string<_CharT, _Traits, _Allocator>::back() const
3376{
Howard Hinnant499cea12013-08-23 17:37:05 +00003377 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003378 return *(data() + size() - 1);
3379}
3380
3381template <class _CharT, class _Traits, class _Allocator>
3382typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003383basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003384{
3385 size_type __sz = size();
3386 if (__pos > __sz)
3387 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003388 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003389 traits_type::copy(__s, data() + __pos, __rlen);
3390 return __rlen;
3391}
3392
3393template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003394inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003395basic_string<_CharT, _Traits, _Allocator>
3396basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3397{
3398 return basic_string(*this, __pos, __n, __alloc());
3399}
3400
3401template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003402inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003403void
3404basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00003405#if _LIBCPP_STD_VER >= 14
3406 _NOEXCEPT
3407#else
3408 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3409 __is_nothrow_swappable<allocator_type>::value)
3410#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003411{
Howard Hinnant499cea12013-08-23 17:37:05 +00003412#if _LIBCPP_DEBUG_LEVEL >= 2
3413 if (!__is_long())
3414 __get_db()->__invalidate_all(this);
3415 if (!__str.__is_long())
3416 __get_db()->__invalidate_all(&__str);
3417 __get_db()->swap(this, &__str);
3418#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00003419 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00003420 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003421}
3422
3423// find
3424
3425template <class _Traits>
3426struct _LIBCPP_HIDDEN __traits_eq
3427{
3428 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003429 _LIBCPP_INLINE_VISIBILITY
3430 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3431 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003432};
3433
3434template<class _CharT, class _Traits, class _Allocator>
3435typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003436basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003437 size_type __pos,
3438 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003439{
Alp Tokerec34c482014-05-15 11:27:39 +00003440 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003441 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003442 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003443}
3444
3445template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003446inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003447typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003448basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3449 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003450{
Marshall Clow37025e12014-06-10 18:51:55 +00003451 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003452 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003453}
3454
3455template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003456inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003457typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003458basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003459 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003460{
Alp Tokerec34c482014-05-15 11:27:39 +00003461 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003462 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003463 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003464}
3465
3466template<class _CharT, class _Traits, class _Allocator>
3467typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003468basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3469 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003470{
Marshall Clow37025e12014-06-10 18:51:55 +00003471 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003472 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003473}
3474
3475// rfind
3476
3477template<class _CharT, class _Traits, class _Allocator>
3478typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003479basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003480 size_type __pos,
3481 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003482{
Alp Tokerec34c482014-05-15 11:27:39 +00003483 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003484 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003485 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003486}
3487
3488template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003489inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003490typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003491basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3492 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003493{
Marshall Clow37025e12014-06-10 18:51:55 +00003494 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003495 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003496}
3497
3498template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003499inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003500typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003501basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003502 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003503{
Alp Tokerec34c482014-05-15 11:27:39 +00003504 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003505 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003506 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003507}
3508
3509template<class _CharT, class _Traits, class _Allocator>
3510typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003511basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3512 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003513{
Marshall Clow37025e12014-06-10 18:51:55 +00003514 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003515 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003516}
3517
3518// find_first_of
3519
3520template<class _CharT, class _Traits, class _Allocator>
3521typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003522basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003523 size_type __pos,
3524 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003525{
Alp Tokerec34c482014-05-15 11:27:39 +00003526 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003527 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003528 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003529}
3530
3531template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003532inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003533typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003534basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3535 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003536{
Marshall Clow37025e12014-06-10 18:51:55 +00003537 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003538 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003539}
3540
3541template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003542inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003543typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003544basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003545 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003546{
Alp Tokerec34c482014-05-15 11:27:39 +00003547 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003548 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003549 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003550}
3551
3552template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003553inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003554typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003555basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3556 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003557{
3558 return find(__c, __pos);
3559}
3560
3561// find_last_of
3562
3563template<class _CharT, class _Traits, class _Allocator>
3564typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003565basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003566 size_type __pos,
3567 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003568{
Alp Tokerec34c482014-05-15 11:27:39 +00003569 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003570 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003571 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003572}
3573
3574template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003575inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003576typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003577basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3578 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003579{
Marshall Clow37025e12014-06-10 18:51:55 +00003580 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003581 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003582}
3583
3584template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003585inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003586typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003587basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003588 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003589{
Alp Tokerec34c482014-05-15 11:27:39 +00003590 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003591 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003592 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003593}
3594
3595template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003596inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003597typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003598basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3599 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003600{
3601 return rfind(__c, __pos);
3602}
3603
3604// find_first_not_of
3605
3606template<class _CharT, class _Traits, class _Allocator>
3607typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003608basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003609 size_type __pos,
3610 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003611{
Alp Tokerec34c482014-05-15 11:27:39 +00003612 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003613 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003614 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003615}
3616
3617template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003618inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003619typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003620basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3621 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003622{
Marshall Clow37025e12014-06-10 18:51:55 +00003623 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003624 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003625}
3626
3627template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003628inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003629typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003630basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003631 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003632{
Alp Tokerec34c482014-05-15 11:27:39 +00003633 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003634 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003635 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003636}
3637
3638template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003639inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003640typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003641basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3642 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003643{
Marshall Clow37025e12014-06-10 18:51:55 +00003644 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003645 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003646}
3647
3648// find_last_not_of
3649
3650template<class _CharT, class _Traits, class _Allocator>
3651typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003652basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003653 size_type __pos,
3654 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003655{
Alp Tokerec34c482014-05-15 11:27:39 +00003656 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003657 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003658 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003659}
3660
3661template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003662inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003663typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003664basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3665 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003666{
Marshall Clow37025e12014-06-10 18:51:55 +00003667 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003668 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003669}
3670
3671template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003672inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003673typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003674basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003675 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003676{
Alp Tokerec34c482014-05-15 11:27:39 +00003677 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003678 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003679 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003680}
3681
3682template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003683inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003684typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003685basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3686 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003687{
Marshall Clow37025e12014-06-10 18:51:55 +00003688 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003689 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003690}
3691
3692// compare
3693
3694template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003695inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003696int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003697basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003698{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003699 size_t __lhs_sz = size();
3700 size_t __rhs_sz = __str.size();
3701 int __result = traits_type::compare(data(), __str.data(),
3702 _VSTD::min(__lhs_sz, __rhs_sz));
3703 if (__result != 0)
3704 return __result;
3705 if (__lhs_sz < __rhs_sz)
3706 return -1;
3707 if (__lhs_sz > __rhs_sz)
3708 return 1;
3709 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003710}
3711
3712template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003713inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003714int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003715basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3716 size_type __n1,
3717 const basic_string& __str) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003718{
3719 return compare(__pos1, __n1, __str.data(), __str.size());
3720}
3721
3722template <class _CharT, class _Traits, class _Allocator>
3723int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003724basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3725 size_type __n1,
3726 const basic_string& __str,
3727 size_type __pos2,
3728 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003729{
3730 size_type __sz = __str.size();
3731 if (__pos2 > __sz)
3732 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003733 return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003734 __sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003735}
3736
3737template <class _CharT, class _Traits, class _Allocator>
3738int
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003739basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003740{
Alp Tokerec34c482014-05-15 11:27:39 +00003741 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003742 return compare(0, npos, __s, traits_type::length(__s));
3743}
3744
3745template <class _CharT, class _Traits, class _Allocator>
3746int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003747basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3748 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003749 const value_type* __s) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003750{
Alp Tokerec34c482014-05-15 11:27:39 +00003751 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003752 return compare(__pos1, __n1, __s, traits_type::length(__s));
3753}
3754
3755template <class _CharT, class _Traits, class _Allocator>
3756int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003757basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3758 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003759 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003760 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003761{
Alp Tokerec34c482014-05-15 11:27:39 +00003762 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003763 size_type __sz = size();
3764 if (__pos1 > __sz || __n2 == npos)
3765 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003766 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3767 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003768 if (__r == 0)
3769 {
3770 if (__rlen < __n2)
3771 __r = -1;
3772 else if (__rlen > __n2)
3773 __r = 1;
3774 }
3775 return __r;
3776}
3777
3778// __invariants
3779
3780template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003781inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003782bool
3783basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3784{
3785 if (size() > capacity())
3786 return false;
3787 if (capacity() < __min_cap - 1)
3788 return false;
3789 if (data() == 0)
3790 return false;
3791 if (data()[size()] != value_type(0))
3792 return false;
3793 return true;
3794}
3795
3796// operator==
3797
3798template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003799inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003800bool
3801operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003802 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003803{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003804 size_t __lhs_sz = __lhs.size();
3805 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3806 __rhs.data(),
3807 __lhs_sz) == 0;
3808}
3809
3810template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003811inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003812bool
3813operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3814 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3815{
3816 size_t __lhs_sz = __lhs.size();
3817 if (__lhs_sz != __rhs.size())
3818 return false;
3819 const char* __lp = __lhs.data();
3820 const char* __rp = __rhs.data();
3821 if (__lhs.__is_long())
3822 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3823 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3824 if (*__lp != *__rp)
3825 return false;
3826 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003827}
3828
3829template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003830inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003831bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003832operator==(const _CharT* __lhs,
3833 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003834{
Eric Fiselier4f241822015-08-28 03:02:37 +00003835 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3836 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3837 size_t __lhs_len = _Traits::length(__lhs);
3838 if (__lhs_len != __rhs.size()) return false;
3839 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003840}
3841
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003842template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003843inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003844bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003845operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3846 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003847{
Eric Fiselier4f241822015-08-28 03:02:37 +00003848 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3849 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3850 size_t __rhs_len = _Traits::length(__rhs);
3851 if (__rhs_len != __lhs.size()) return false;
3852 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003853}
3854
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003855// operator!=
3856
Howard Hinnant324bb032010-08-22 00:02:43 +00003857template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003858inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003859bool
3860operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003861 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003862{
3863 return !(__lhs == __rhs);
3864}
3865
3866template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003867inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003868bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003869operator!=(const _CharT* __lhs,
3870 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003871{
3872 return !(__lhs == __rhs);
3873}
3874
3875template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003876inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003877bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003878operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3879 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003880{
3881 return !(__lhs == __rhs);
3882}
3883
3884// operator<
3885
3886template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003887inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003888bool
3889operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003890 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003891{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003892 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003893}
3894
3895template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003896inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003897bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003898operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3899 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003900{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003901 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003902}
3903
3904template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003905inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003906bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003907operator< (const _CharT* __lhs,
3908 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003909{
3910 return __rhs.compare(__lhs) > 0;
3911}
3912
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003913// operator>
3914
3915template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003916inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003917bool
3918operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003919 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003920{
3921 return __rhs < __lhs;
3922}
3923
3924template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003925inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003926bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003927operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3928 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003929{
3930 return __rhs < __lhs;
3931}
3932
3933template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003934inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003935bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003936operator> (const _CharT* __lhs,
3937 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003938{
3939 return __rhs < __lhs;
3940}
3941
3942// operator<=
3943
3944template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003945inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003946bool
3947operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003948 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003949{
3950 return !(__rhs < __lhs);
3951}
3952
3953template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003954inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003955bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003956operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3957 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003958{
3959 return !(__rhs < __lhs);
3960}
3961
3962template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003963inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003964bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003965operator<=(const _CharT* __lhs,
3966 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003967{
3968 return !(__rhs < __lhs);
3969}
3970
3971// operator>=
3972
3973template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003974inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003975bool
3976operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003977 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003978{
3979 return !(__lhs < __rhs);
3980}
3981
3982template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003983inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003984bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003985operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3986 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003987{
3988 return !(__lhs < __rhs);
3989}
3990
3991template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003992inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003993bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003994operator>=(const _CharT* __lhs,
3995 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003996{
3997 return !(__lhs < __rhs);
3998}
3999
4000// operator +
4001
4002template<class _CharT, class _Traits, class _Allocator>
4003basic_string<_CharT, _Traits, _Allocator>
4004operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4005 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4006{
4007 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4008 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4009 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4010 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4011 __r.append(__rhs.data(), __rhs_sz);
4012 return __r;
4013}
4014
4015template<class _CharT, class _Traits, class _Allocator>
4016basic_string<_CharT, _Traits, _Allocator>
4017operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4018{
4019 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4020 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4021 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4022 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4023 __r.append(__rhs.data(), __rhs_sz);
4024 return __r;
4025}
4026
4027template<class _CharT, class _Traits, class _Allocator>
4028basic_string<_CharT, _Traits, _Allocator>
4029operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4030{
4031 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4032 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4033 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4034 __r.append(__rhs.data(), __rhs_sz);
4035 return __r;
4036}
4037
4038template<class _CharT, class _Traits, class _Allocator>
4039basic_string<_CharT, _Traits, _Allocator>
4040operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4041{
4042 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4043 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4044 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4045 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4046 __r.append(__rhs, __rhs_sz);
4047 return __r;
4048}
4049
4050template<class _CharT, class _Traits, class _Allocator>
4051basic_string<_CharT, _Traits, _Allocator>
4052operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4053{
4054 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4055 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4056 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4057 __r.push_back(__rhs);
4058 return __r;
4059}
4060
Howard Hinnant73d21a42010-09-04 23:28:19 +00004061#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004062
4063template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004064inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004065basic_string<_CharT, _Traits, _Allocator>
4066operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4067{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004068 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004069}
4070
4071template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004072inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004073basic_string<_CharT, _Traits, _Allocator>
4074operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4075{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004076 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004077}
4078
4079template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004080inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004081basic_string<_CharT, _Traits, _Allocator>
4082operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4083{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004084 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004085}
4086
4087template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004088inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004089basic_string<_CharT, _Traits, _Allocator>
4090operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4091{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004092 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004093}
4094
4095template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004096inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004097basic_string<_CharT, _Traits, _Allocator>
4098operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4099{
4100 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004101 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004102}
4103
4104template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004105inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004106basic_string<_CharT, _Traits, _Allocator>
4107operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4108{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004109 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004110}
4111
4112template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004113inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004114basic_string<_CharT, _Traits, _Allocator>
4115operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4116{
4117 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004118 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004119}
4120
Howard Hinnant73d21a42010-09-04 23:28:19 +00004121#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004122
4123// swap
4124
4125template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004126inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004127void
Howard Hinnanta6119a82011-05-29 19:57:12 +00004128swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00004129 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4130 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004131{
4132 __lhs.swap(__rhs);
4133}
4134
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004135#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
4136
4137typedef basic_string<char16_t> u16string;
4138typedef basic_string<char32_t> u32string;
4139
Howard Hinnant324bb032010-08-22 00:02:43 +00004140#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004141
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004142_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4143_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4144_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4145_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4146_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004147
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004148_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4149_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4150_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004151
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004152_LIBCPP_FUNC_VIS string to_string(int __val);
4153_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4154_LIBCPP_FUNC_VIS string to_string(long __val);
4155_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4156_LIBCPP_FUNC_VIS string to_string(long long __val);
4157_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4158_LIBCPP_FUNC_VIS string to_string(float __val);
4159_LIBCPP_FUNC_VIS string to_string(double __val);
4160_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004161
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004162_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4163_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4164_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4165_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4166_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004167
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004168_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4169_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4170_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004171
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004172_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4173_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4174_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4175_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4176_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4177_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4178_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4179_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4180_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004181
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004182template<class _CharT, class _Traits, class _Allocator>
4183 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4184 basic_string<_CharT, _Traits, _Allocator>::npos;
4185
4186template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004187struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004188 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4189{
4190 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004191 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004192};
4193
4194template<class _CharT, class _Traits, class _Allocator>
4195size_t
4196hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004197 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004198{
Sean Huntaffd9e52011-07-29 23:31:56 +00004199 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004200}
4201
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004202template<class _CharT, class _Traits, class _Allocator>
4203basic_ostream<_CharT, _Traits>&
4204operator<<(basic_ostream<_CharT, _Traits>& __os,
4205 const basic_string<_CharT, _Traits, _Allocator>& __str);
4206
4207template<class _CharT, class _Traits, class _Allocator>
4208basic_istream<_CharT, _Traits>&
4209operator>>(basic_istream<_CharT, _Traits>& __is,
4210 basic_string<_CharT, _Traits, _Allocator>& __str);
4211
4212template<class _CharT, class _Traits, class _Allocator>
4213basic_istream<_CharT, _Traits>&
4214getline(basic_istream<_CharT, _Traits>& __is,
4215 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4216
4217template<class _CharT, class _Traits, class _Allocator>
4218inline _LIBCPP_INLINE_VISIBILITY
4219basic_istream<_CharT, _Traits>&
4220getline(basic_istream<_CharT, _Traits>& __is,
4221 basic_string<_CharT, _Traits, _Allocator>& __str);
4222
4223#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4224
4225template<class _CharT, class _Traits, class _Allocator>
4226inline _LIBCPP_INLINE_VISIBILITY
4227basic_istream<_CharT, _Traits>&
4228getline(basic_istream<_CharT, _Traits>&& __is,
4229 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4230
4231template<class _CharT, class _Traits, class _Allocator>
4232inline _LIBCPP_INLINE_VISIBILITY
4233basic_istream<_CharT, _Traits>&
4234getline(basic_istream<_CharT, _Traits>&& __is,
4235 basic_string<_CharT, _Traits, _Allocator>& __str);
4236
4237#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4238
Howard Hinnant499cea12013-08-23 17:37:05 +00004239#if _LIBCPP_DEBUG_LEVEL >= 2
4240
4241template<class _CharT, class _Traits, class _Allocator>
4242bool
4243basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4244{
4245 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4246 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4247}
4248
4249template<class _CharT, class _Traits, class _Allocator>
4250bool
4251basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4252{
4253 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4254 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4255}
4256
4257template<class _CharT, class _Traits, class _Allocator>
4258bool
4259basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4260{
4261 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4262 return this->data() <= __p && __p <= this->data() + this->size();
4263}
4264
4265template<class _CharT, class _Traits, class _Allocator>
4266bool
4267basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4268{
4269 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4270 return this->data() <= __p && __p < this->data() + this->size();
4271}
4272
4273#endif // _LIBCPP_DEBUG_LEVEL >= 2
4274
Marshall Clow15234322013-07-23 17:05:24 +00004275#if _LIBCPP_STD_VER > 11
4276// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004277inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004278{
4279 inline namespace string_literals
4280 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004281 inline _LIBCPP_INLINE_VISIBILITY
4282 basic_string<char> operator "" s( const char *__str, size_t __len )
4283 {
4284 return basic_string<char> (__str, __len);
4285 }
Marshall Clow15234322013-07-23 17:05:24 +00004286
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004287 inline _LIBCPP_INLINE_VISIBILITY
4288 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4289 {
4290 return basic_string<wchar_t> (__str, __len);
4291 }
Marshall Clow15234322013-07-23 17:05:24 +00004292
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004293 inline _LIBCPP_INLINE_VISIBILITY
4294 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4295 {
4296 return basic_string<char16_t> (__str, __len);
4297 }
Marshall Clow15234322013-07-23 17:05:24 +00004298
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004299 inline _LIBCPP_INLINE_VISIBILITY
4300 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4301 {
4302 return basic_string<char32_t> (__str, __len);
4303 }
Marshall Clow15234322013-07-23 17:05:24 +00004304 }
4305}
4306#endif
4307
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004308_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>)
4309_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>)
Howard Hinnant499cea12013-08-23 17:37:05 +00004310_LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004311
4312_LIBCPP_END_NAMESPACE_STD
4313
4314#endif // _LIBCPP_STRING