blob: 85eb463da0e105c0236dcdd63c662cc795049429 [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);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000101 basic_string(const basic_string& str, size_type pos, size_type n = npos,
102 const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000103 basic_string(const_pointer s, const allocator_type& a = allocator_type());
104 basic_string(const_pointer s, size_type n, const allocator_type& a = allocator_type());
105 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
106 template<class InputIterator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000107 basic_string(InputIterator begin, InputIterator end,
108 const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000109 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
110 basic_string(const basic_string&, const Allocator&);
111 basic_string(basic_string&&, const Allocator&);
112
113 ~basic_string();
114
115 basic_string& operator=(const basic_string& str);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000116 basic_string& operator=(basic_string&& str)
117 noexcept(
118 allocator_type::propagate_on_container_move_assignment::value &&
119 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120 basic_string& operator=(const_pointer s);
121 basic_string& operator=(value_type c);
122 basic_string& operator=(initializer_list<value_type>);
123
Howard Hinnanta6119a82011-05-29 19:57:12 +0000124 iterator begin() noexcept;
125 const_iterator begin() const noexcept;
126 iterator end() noexcept;
127 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000128
Howard Hinnanta6119a82011-05-29 19:57:12 +0000129 reverse_iterator rbegin() noexcept;
130 const_reverse_iterator rbegin() const noexcept;
131 reverse_iterator rend() noexcept;
132 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000133
Howard Hinnanta6119a82011-05-29 19:57:12 +0000134 const_iterator cbegin() const noexcept;
135 const_iterator cend() const noexcept;
136 const_reverse_iterator crbegin() const noexcept;
137 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000138
Howard Hinnanta6119a82011-05-29 19:57:12 +0000139 size_type size() const noexcept;
140 size_type length() const noexcept;
141 size_type max_size() const noexcept;
142 size_type capacity() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000143
144 void resize(size_type n, value_type c);
145 void resize(size_type n);
146
147 void reserve(size_type res_arg = 0);
148 void shrink_to_fit();
Howard Hinnanta6119a82011-05-29 19:57:12 +0000149 void clear() noexcept;
150 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000151
152 const_reference operator[](size_type pos) const;
153 reference operator[](size_type pos);
154
155 const_reference at(size_type n) const;
156 reference at(size_type n);
157
158 basic_string& operator+=(const basic_string& str);
159 basic_string& operator+=(const_pointer s);
160 basic_string& operator+=(value_type c);
161 basic_string& operator+=(initializer_list<value_type>);
162
163 basic_string& append(const basic_string& str);
164 basic_string& append(const basic_string& str, size_type pos, size_type n);
165 basic_string& append(const_pointer s, size_type n);
166 basic_string& append(const_pointer s);
167 basic_string& append(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000168 template<class InputIterator>
169 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000170 basic_string& append(initializer_list<value_type>);
171
172 void push_back(value_type c);
173 void pop_back();
174 reference front();
175 const_reference front() const;
176 reference back();
177 const_reference back() const;
178
179 basic_string& assign(const basic_string& str);
Howard Hinnanta6119a82011-05-29 19:57:12 +0000180 basic_string& assign(basic_string&& str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000181 basic_string& assign(const basic_string& str, size_type pos, size_type n);
182 basic_string& assign(const_pointer s, size_type n);
183 basic_string& assign(const_pointer s);
184 basic_string& assign(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000185 template<class InputIterator>
186 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000187 basic_string& assign(initializer_list<value_type>);
188
189 basic_string& insert(size_type pos1, const basic_string& str);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000190 basic_string& insert(size_type pos1, const basic_string& str,
191 size_type pos2, size_type n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000192 basic_string& insert(size_type pos, const_pointer s, size_type n);
193 basic_string& insert(size_type pos, const_pointer s);
194 basic_string& insert(size_type pos, size_type n, value_type c);
195 iterator insert(const_iterator p, value_type c);
196 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000197 template<class InputIterator>
198 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000199 iterator insert(const_iterator p, initializer_list<value_type>);
200
201 basic_string& erase(size_type pos = 0, size_type n = npos);
202 iterator erase(const_iterator position);
203 iterator erase(const_iterator first, const_iterator last);
204
205 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000206 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
207 size_type pos2, size_type n2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000208 basic_string& replace(size_type pos, size_type n1, const_pointer s, size_type n2);
209 basic_string& replace(size_type pos, size_type n1, const_pointer s);
210 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000211 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
212 basic_string& replace(const_iterator i1, const_iterator i2, const_pointer s, size_type n);
213 basic_string& replace(const_iterator i1, const_iterator i2, const_pointer s);
214 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000215 template<class InputIterator>
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000216 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
217 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000218
219 size_type copy(pointer s, size_type n, size_type pos = 0) const;
220 basic_string substr(size_type pos = 0, size_type n = npos) const;
221
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000222 void swap(basic_string& str)
223 noexcept(!allocator_type::propagate_on_container_swap::value ||
224 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000225
Howard Hinnanta6119a82011-05-29 19:57:12 +0000226 const_pointer c_str() const noexcept;
227 const_pointer data() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000228
Howard Hinnanta6119a82011-05-29 19:57:12 +0000229 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000230
Howard Hinnanta6119a82011-05-29 19:57:12 +0000231 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
232 size_type find(const_pointer s, size_type pos, size_type n) const noexcept;
233 size_type find(const_pointer s, size_type pos = 0) const noexcept;
234 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000235
Howard Hinnanta6119a82011-05-29 19:57:12 +0000236 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
237 size_type rfind(const_pointer s, size_type pos, size_type n) const noexcept;
238 size_type rfind(const_pointer s, size_type pos = npos) const noexcept;
239 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000240
Howard Hinnanta6119a82011-05-29 19:57:12 +0000241 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
242 size_type find_first_of(const_pointer s, size_type pos, size_type n) const noexcept;
243 size_type find_first_of(const_pointer s, size_type pos = 0) const noexcept;
244 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000245
Howard Hinnanta6119a82011-05-29 19:57:12 +0000246 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
247 size_type find_last_of(const_pointer s, size_type pos, size_type n) const noexcept;
248 size_type find_last_of(const_pointer s, size_type pos = npos) const noexcept;
249 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000250
Howard Hinnanta6119a82011-05-29 19:57:12 +0000251 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
252 size_type find_first_not_of(const_pointer s, size_type pos, size_type n) const noexcept;
253 size_type find_first_not_of(const_pointer s, size_type pos = 0) const noexcept;
254 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000255
Howard Hinnanta6119a82011-05-29 19:57:12 +0000256 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
257 size_type find_last_not_of(const_pointer s, size_type pos, size_type n) const noexcept;
258 size_type find_last_not_of(const_pointer s, size_type pos = npos) const noexcept;
259 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000260
Howard Hinnanta6119a82011-05-29 19:57:12 +0000261 int compare(const basic_string& str) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000262 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000263 int compare(size_type pos1, size_type n1, const basic_string& str,
264 size_type pos2, size_type n2) const;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000265 int compare(const_pointer s) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000266 int compare(size_type pos1, size_type n1, const_pointer s) const;
267 int compare(size_type pos1, size_type n1, const_pointer s, size_type n2) const;
268
269 bool __invariants() const;
270};
271
272template<class charT, class traits, class Allocator>
273basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000274operator+(const basic_string<charT, traits, Allocator>& lhs,
275 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276
277template<class charT, class traits, class Allocator>
278basic_string<charT, traits, Allocator>
279operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
280
281template<class charT, class traits, class Allocator>
282basic_string<charT, traits, Allocator>
283operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
284
285template<class charT, class traits, class Allocator>
286basic_string<charT, traits, Allocator>
287operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
288
289template<class charT, class traits, class Allocator>
290basic_string<charT, traits, Allocator>
291operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
292
293template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000294bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000295 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296
297template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000298bool operator==(const charT* lhs, 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 basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000302
Howard Hinnant324bb032010-08-22 00:02:43 +0000303template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000304bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000305 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000306
307template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000308bool operator!=(const charT* lhs, 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 basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000312
313template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000314bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000315 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000316
317template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000318bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* 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 charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000322
323template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000324bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000325 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000326
327template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000328bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* 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 charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000332
333template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000334bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000335 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000336
337template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000338bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* 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 charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000342
343template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000344bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000345 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000346
347template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000348bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* 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 charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000352
353template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000354void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000355 basic_string<charT, traits, Allocator>& rhs)
356 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000357
358template<class charT, class traits, class Allocator>
359basic_istream<charT, traits>&
360operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
361
362template<class charT, class traits, class Allocator>
363basic_ostream<charT, traits>&
364operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
365
366template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000367basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000368getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
369 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000370
371template<class charT, class traits, class Allocator>
372basic_istream<charT, traits>&
373getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
374
375typedef basic_string<char> string;
376typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000377typedef basic_string<char16_t> u16string;
378typedef basic_string<char32_t> u32string;
379
380int stoi (const string& str, size_t* idx = 0, int base = 10);
381long stol (const string& str, size_t* idx = 0, int base = 10);
382unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
383long long stoll (const string& str, size_t* idx = 0, int base = 10);
384unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
385
386float stof (const string& str, size_t* idx = 0);
387double stod (const string& str, size_t* idx = 0);
388long double stold(const string& str, size_t* idx = 0);
389
390string to_string(int val);
391string to_string(unsigned val);
392string to_string(long val);
393string to_string(unsigned long val);
394string to_string(long long val);
395string to_string(unsigned long long val);
396string to_string(float val);
397string to_string(double val);
398string to_string(long double val);
399
400int stoi (const wstring& str, size_t* idx = 0, int base = 10);
401long stol (const wstring& str, size_t* idx = 0, int base = 10);
402unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
403long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
404unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
405
406float stof (const wstring& str, size_t* idx = 0);
407double stod (const wstring& str, size_t* idx = 0);
408long double stold(const wstring& str, size_t* idx = 0);
409
410wstring to_wstring(int val);
411wstring to_wstring(unsigned val);
412wstring to_wstring(long val);
413wstring to_wstring(unsigned long val);
414wstring to_wstring(long long val);
415wstring to_wstring(unsigned long long val);
416wstring to_wstring(float val);
417wstring to_wstring(double val);
418wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419
420template <> struct hash<string>;
421template <> struct hash<u16string>;
422template <> struct hash<u32string>;
423template <> struct hash<wstring>;
424
425} // std
426
427*/
428
429#include <__config>
430#include <iosfwd>
431#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000432#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433#include <cwchar>
434#include <algorithm>
435#include <iterator>
436#include <utility>
437#include <memory>
438#include <stdexcept>
439#include <type_traits>
440#include <initializer_list>
441#include <__functional_base>
442#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
443#include <cstdint>
444#endif
445#if defined(_LIBCPP_NO_EXCEPTIONS) || defined(_LIBCPP_DEBUG)
446#include <cassert>
447#endif
448
Howard Hinnant66c6f972011-11-29 16:45:27 +0000449#include <__undef_min_max>
450
Howard Hinnant08e17472011-10-17 20:05:10 +0000451#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000452#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000453#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000454
455_LIBCPP_BEGIN_NAMESPACE_STD
456
457// fpos
458
459template <class _StateT>
Howard Hinnant83eade62013-03-06 23:30:19 +0000460class _LIBCPP_TYPE_VIS fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000461{
462private:
463 _StateT __st_;
464 streamoff __off_;
465public:
466 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
467
468 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
469
470 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
471 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
472
473 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
474 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
475 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
476 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
477};
478
479template <class _StateT>
480inline _LIBCPP_INLINE_VISIBILITY
481streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
482 {return streamoff(__x) - streamoff(__y);}
483
484template <class _StateT>
485inline _LIBCPP_INLINE_VISIBILITY
486bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
487 {return streamoff(__x) == streamoff(__y);}
488
489template <class _StateT>
490inline _LIBCPP_INLINE_VISIBILITY
491bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
492 {return streamoff(__x) != streamoff(__y);}
493
494// char_traits
495
496template <class _CharT>
Howard Hinnant83eade62013-03-06 23:30:19 +0000497struct _LIBCPP_TYPE_VIS char_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000498{
499 typedef _CharT char_type;
500 typedef int int_type;
501 typedef streamoff off_type;
502 typedef streampos pos_type;
503 typedef mbstate_t state_type;
504
Howard Hinnanta6119a82011-05-29 19:57:12 +0000505 _LIBCPP_INLINE_VISIBILITY
506 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
507 {__c1 = __c2;}
508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000509 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000510 {return __c1 == __c2;}
511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000512 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000513 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000514
515 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
516 static size_t length(const char_type* __s);
517 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
518 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
519 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
520 static char_type* assign(char_type* __s, size_t __n, char_type __a);
521
Howard Hinnant03d71812012-07-20 19:09:12 +0000522 _LIBCPP_INLINE_VISIBILITY
523 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000526 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000527 {return char_type(__c);}
528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000529 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000530 {return int_type(__c);}
531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000532 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000534 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000535 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000536 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000537};
538
539template <class _CharT>
540int
541char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
542{
543 for (; __n; --__n, ++__s1, ++__s2)
544 {
545 if (lt(*__s1, *__s2))
546 return -1;
547 if (lt(*__s2, *__s1))
548 return 1;
549 }
550 return 0;
551}
552
553template <class _CharT>
554inline _LIBCPP_INLINE_VISIBILITY
555size_t
556char_traits<_CharT>::length(const char_type* __s)
557{
558 size_t __len = 0;
559 for (; !eq(*__s, char_type(0)); ++__s)
560 ++__len;
561 return __len;
562}
563
564template <class _CharT>
565inline _LIBCPP_INLINE_VISIBILITY
566const _CharT*
567char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
568{
569 for (; __n; --__n)
570 {
571 if (eq(*__s, __a))
572 return __s;
573 ++__s;
574 }
575 return 0;
576}
577
578template <class _CharT>
579_CharT*
580char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
581{
582 char_type* __r = __s1;
583 if (__s1 < __s2)
584 {
585 for (; __n; --__n, ++__s1, ++__s2)
586 assign(*__s1, *__s2);
587 }
588 else if (__s2 < __s1)
589 {
590 __s1 += __n;
591 __s2 += __n;
592 for (; __n; --__n)
593 assign(*--__s1, *--__s2);
594 }
595 return __r;
596}
597
598template <class _CharT>
599inline _LIBCPP_INLINE_VISIBILITY
600_CharT*
601char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
602{
603 char_type* __r = __s1;
604 for (; __n; --__n, ++__s1, ++__s2)
605 assign(*__s1, *__s2);
606 return __r;
607}
608
609template <class _CharT>
610inline _LIBCPP_INLINE_VISIBILITY
611_CharT*
612char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
613{
614 char_type* __r = __s;
615 for (; __n; --__n, ++__s)
616 assign(*__s, __a);
617 return __r;
618}
619
620// char_traits<char>
621
622template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000623struct _LIBCPP_TYPE_VIS char_traits<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000624{
625 typedef char char_type;
626 typedef int int_type;
627 typedef streamoff off_type;
628 typedef streampos pos_type;
629 typedef mbstate_t state_type;
630
Howard Hinnanta6119a82011-05-29 19:57:12 +0000631 _LIBCPP_INLINE_VISIBILITY
632 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
633 {__c1 = __c2;}
634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000635 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000636 {return __c1 == __c2;}
637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000638 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000639 {return (unsigned char)__c1 < (unsigned char)__c2;}
640
Howard Hinnanta6119a82011-05-29 19:57:12 +0000641 _LIBCPP_INLINE_VISIBILITY
642 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643 {return memcmp(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000644 _LIBCPP_INLINE_VISIBILITY
645 static size_t length(const char_type* __s) {return strlen(__s);}
646 _LIBCPP_INLINE_VISIBILITY
647 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000648 {return (const char_type*)memchr(__s, to_int_type(__a), __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000649 _LIBCPP_INLINE_VISIBILITY
650 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000651 {return (char_type*)memmove(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000652 _LIBCPP_INLINE_VISIBILITY
653 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000654 {return (char_type*)memcpy(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000655 _LIBCPP_INLINE_VISIBILITY
656 static char_type* assign(char_type* __s, size_t __n, char_type __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657 {return (char_type*)memset(__s, to_int_type(__a), __n);}
658
Howard Hinnant03d71812012-07-20 19:09:12 +0000659 _LIBCPP_INLINE_VISIBILITY
660 static _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;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000663 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000664 {return char_type(__c);}
665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000666 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000667 {return int_type((unsigned char)__c);}
668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000669 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000672 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000673 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000674};
675
676// char_traits<wchar_t>
677
678template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000679struct _LIBCPP_TYPE_VIS char_traits<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680{
681 typedef wchar_t char_type;
682 typedef wint_t int_type;
683 typedef streamoff off_type;
684 typedef streampos pos_type;
685 typedef mbstate_t state_type;
686
Howard Hinnanta6119a82011-05-29 19:57:12 +0000687 _LIBCPP_INLINE_VISIBILITY
688 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
689 {__c1 = __c2;}
690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000691 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000692 {return __c1 == __c2;}
693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000694 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000695 {return __c1 < __c2;}
696
Howard Hinnanta6119a82011-05-29 19:57:12 +0000697 _LIBCPP_INLINE_VISIBILITY
698 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000699 {return wmemcmp(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000700 _LIBCPP_INLINE_VISIBILITY
701 static size_t length(const char_type* __s)
702 {return wcslen(__s);}
703 _LIBCPP_INLINE_VISIBILITY
704 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705 {return (const char_type*)wmemchr(__s, __a, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000706 _LIBCPP_INLINE_VISIBILITY
707 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708 {return (char_type*)wmemmove(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000709 _LIBCPP_INLINE_VISIBILITY
710 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711 {return (char_type*)wmemcpy(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000712 _LIBCPP_INLINE_VISIBILITY
713 static char_type* assign(char_type* __s, size_t __n, char_type __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714 {return (char_type*)wmemset(__s, __a, __n);}
715
Howard Hinnanta6119a82011-05-29 19:57:12 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000717 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000718 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000720 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000721 {return char_type(__c);}
722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000723 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000724 {return int_type(__c);}
725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000726 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000727 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000728 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000729 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000730 {return int_type(WEOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000731};
732
733#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
734
735template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000736struct _LIBCPP_TYPE_VIS char_traits<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000737{
738 typedef char16_t char_type;
739 typedef uint_least16_t int_type;
740 typedef streamoff off_type;
741 typedef u16streampos pos_type;
742 typedef mbstate_t state_type;
743
Howard Hinnanta6119a82011-05-29 19:57:12 +0000744 _LIBCPP_INLINE_VISIBILITY
745 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
746 {__c1 = __c2;}
747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000748 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000749 {return __c1 == __c2;}
750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000751 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000752 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000753
754 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
755 static size_t length(const char_type* __s);
756 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
757 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
758 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
759 static char_type* assign(char_type* __s, size_t __n, char_type __a);
760
Howard Hinnanta6119a82011-05-29 19:57:12 +0000761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000762 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000763 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000765 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000766 {return char_type(__c);}
767 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000768 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000769 {return int_type(__c);}
770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000771 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000772 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000774 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000775 {return int_type(0xDFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000776};
777
778inline _LIBCPP_INLINE_VISIBILITY
779int
780char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
781{
782 for (; __n; --__n, ++__s1, ++__s2)
783 {
784 if (lt(*__s1, *__s2))
785 return -1;
786 if (lt(*__s2, *__s1))
787 return 1;
788 }
789 return 0;
790}
791
792inline _LIBCPP_INLINE_VISIBILITY
793size_t
794char_traits<char16_t>::length(const char_type* __s)
795{
796 size_t __len = 0;
797 for (; !eq(*__s, char_type(0)); ++__s)
798 ++__len;
799 return __len;
800}
801
802inline _LIBCPP_INLINE_VISIBILITY
803const char16_t*
804char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
805{
806 for (; __n; --__n)
807 {
808 if (eq(*__s, __a))
809 return __s;
810 ++__s;
811 }
812 return 0;
813}
814
815inline _LIBCPP_INLINE_VISIBILITY
816char16_t*
817char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
818{
819 char_type* __r = __s1;
820 if (__s1 < __s2)
821 {
822 for (; __n; --__n, ++__s1, ++__s2)
823 assign(*__s1, *__s2);
824 }
825 else if (__s2 < __s1)
826 {
827 __s1 += __n;
828 __s2 += __n;
829 for (; __n; --__n)
830 assign(*--__s1, *--__s2);
831 }
832 return __r;
833}
834
835inline _LIBCPP_INLINE_VISIBILITY
836char16_t*
837char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
838{
839 char_type* __r = __s1;
840 for (; __n; --__n, ++__s1, ++__s2)
841 assign(*__s1, *__s2);
842 return __r;
843}
844
845inline _LIBCPP_INLINE_VISIBILITY
846char16_t*
847char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
848{
849 char_type* __r = __s;
850 for (; __n; --__n, ++__s)
851 assign(*__s, __a);
852 return __r;
853}
854
855template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000856struct _LIBCPP_TYPE_VIS char_traits<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857{
858 typedef char32_t char_type;
859 typedef uint_least32_t int_type;
860 typedef streamoff off_type;
861 typedef u32streampos pos_type;
862 typedef mbstate_t state_type;
863
Howard Hinnanta6119a82011-05-29 19:57:12 +0000864 _LIBCPP_INLINE_VISIBILITY
865 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
866 {__c1 = __c2;}
867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000868 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000869 {return __c1 == __c2;}
870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000871 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000872 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873
874 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
875 static size_t length(const char_type* __s);
876 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
877 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
878 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
879 static char_type* assign(char_type* __s, size_t __n, char_type __a);
880
Howard Hinnanta6119a82011-05-29 19:57:12 +0000881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000882 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000883 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000884 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000885 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000886 {return char_type(__c);}
887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000888 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000889 {return int_type(__c);}
890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000891 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000892 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000894 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000895 {return int_type(0xFFFFFFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896};
897
898inline _LIBCPP_INLINE_VISIBILITY
899int
900char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
901{
902 for (; __n; --__n, ++__s1, ++__s2)
903 {
904 if (lt(*__s1, *__s2))
905 return -1;
906 if (lt(*__s2, *__s1))
907 return 1;
908 }
909 return 0;
910}
911
912inline _LIBCPP_INLINE_VISIBILITY
913size_t
914char_traits<char32_t>::length(const char_type* __s)
915{
916 size_t __len = 0;
917 for (; !eq(*__s, char_type(0)); ++__s)
918 ++__len;
919 return __len;
920}
921
922inline _LIBCPP_INLINE_VISIBILITY
923const char32_t*
924char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
925{
926 for (; __n; --__n)
927 {
928 if (eq(*__s, __a))
929 return __s;
930 ++__s;
931 }
932 return 0;
933}
934
935inline _LIBCPP_INLINE_VISIBILITY
936char32_t*
937char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
938{
939 char_type* __r = __s1;
940 if (__s1 < __s2)
941 {
942 for (; __n; --__n, ++__s1, ++__s2)
943 assign(*__s1, *__s2);
944 }
945 else if (__s2 < __s1)
946 {
947 __s1 += __n;
948 __s2 += __n;
949 for (; __n; --__n)
950 assign(*--__s1, *--__s2);
951 }
952 return __r;
953}
954
955inline _LIBCPP_INLINE_VISIBILITY
956char32_t*
957char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
958{
959 char_type* __r = __s1;
960 for (; __n; --__n, ++__s1, ++__s2)
961 assign(*__s1, *__s2);
962 return __r;
963}
964
965inline _LIBCPP_INLINE_VISIBILITY
966char32_t*
967char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
968{
969 char_type* __r = __s;
970 for (; __n; --__n, ++__s)
971 assign(*__s, __a);
972 return __r;
973}
974
Howard Hinnant324bb032010-08-22 00:02:43 +0000975#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976
977// basic_string
978
979template<class _CharT, class _Traits, class _Allocator>
980basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000981operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
982 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983
984template<class _CharT, class _Traits, class _Allocator>
985basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000986operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987
988template<class _CharT, class _Traits, class _Allocator>
989basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000990operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000991
992template<class _CharT, class _Traits, class _Allocator>
993basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000994operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000995
996template<class _CharT, class _Traits, class _Allocator>
997basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000998operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000999
1000template <bool>
1001class __basic_string_common
1002{
1003protected:
1004 void __throw_length_error() const;
1005 void __throw_out_of_range() const;
1006};
1007
1008template <bool __b>
1009void
1010__basic_string_common<__b>::__throw_length_error() const
1011{
1012#ifndef _LIBCPP_NO_EXCEPTIONS
1013 throw length_error("basic_string");
1014#else
1015 assert(!"basic_string length_error");
1016#endif
1017}
1018
1019template <bool __b>
1020void
1021__basic_string_common<__b>::__throw_out_of_range() const
1022{
1023#ifndef _LIBCPP_NO_EXCEPTIONS
1024 throw out_of_range("basic_string");
1025#else
1026 assert(!"basic_string out_of_range");
1027#endif
1028}
1029
Howard Hinnant78b68282011-10-22 20:59:45 +00001030#ifdef _MSC_VER
1031#pragma warning( push )
1032#pragma warning( disable: 4231 )
1033#endif // _MSC_VER
Howard Hinnantff926772012-11-06 21:08:48 +00001034_LIBCPP_EXTERN_TEMPLATE(class __basic_string_common<true>)
Howard Hinnant78b68282011-10-22 20:59:45 +00001035#ifdef _MSC_VER
1036#pragma warning( pop )
1037#endif // _MSC_VER
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001038
Howard Hinnant15467182013-04-30 21:44:48 +00001039#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1040
1041template <class _CharT, size_t = sizeof(_CharT)>
1042struct __padding
1043{
1044 unsigned char __xx[sizeof(_CharT)-1];
1045};
1046
1047template <class _CharT>
1048struct __padding<_CharT, 1>
1049{
1050};
1051
1052#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1053
Howard Hinnant324bb032010-08-22 00:02:43 +00001054template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant83eade62013-03-06 23:30:19 +00001055class _LIBCPP_TYPE_VIS basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001056 : private __basic_string_common<true>
1057{
1058public:
1059 typedef basic_string __self;
1060 typedef _Traits traits_type;
1061 typedef typename traits_type::char_type value_type;
1062 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001063 typedef allocator_traits<allocator_type> __alloc_traits;
1064 typedef typename __alloc_traits::size_type size_type;
1065 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001066 typedef value_type& reference;
1067 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001068 typedef typename __alloc_traits::pointer pointer;
1069 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070#ifdef _LIBCPP_DEBUG
1071 typedef __debug_iter<basic_string, pointer> iterator;
1072 typedef __debug_iter<basic_string, const_pointer> const_iterator;
1073
1074 friend class __debug_iter<basic_string, pointer>;
1075 friend class __debug_iter<basic_string, const_pointer>;
1076#elif defined(_LIBCPP_RAW_ITERATORS)
1077 typedef pointer iterator;
1078 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001079#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001080 typedef __wrap_iter<pointer> iterator;
1081 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001082#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001083 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1084 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001085
1086private:
Howard Hinnant15467182013-04-30 21:44:48 +00001087
1088#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1089
1090 struct __long
1091 {
1092 pointer __data_;
1093 size_type __size_;
1094 size_type __cap_;
1095 };
1096
1097#if _LIBCPP_BIG_ENDIAN
1098 enum {__short_mask = 0x01};
1099 enum {__long_mask = 0x1ul};
1100#else // _LIBCPP_BIG_ENDIAN
1101 enum {__short_mask = 0x80};
1102 enum {__long_mask = ~(size_type(~0) >> 1)};
1103#endif // _LIBCPP_BIG_ENDIAN
1104
1105 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1106 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1107
1108 struct __short
1109 {
1110 value_type __data_[__min_cap];
1111 struct
1112 : __padding<value_type>
1113 {
1114 unsigned char __size_;
1115 };
1116 };
1117
1118#else
1119
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120 struct __long
1121 {
1122 size_type __cap_;
1123 size_type __size_;
1124 pointer __data_;
1125 };
1126
1127#if _LIBCPP_BIG_ENDIAN
1128 enum {__short_mask = 0x80};
1129 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43 +00001130#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001131 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04 +00001132 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43 +00001133#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001134
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001135 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1136 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1137
1138 struct __short
1139 {
1140 union
1141 {
1142 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +00001143 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144 };
1145 value_type __data_[__min_cap];
1146 };
1147
Howard Hinnant15467182013-04-30 21:44:48 +00001148#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1149
Howard Hinnant9c0df142012-10-30 19:06:59 +00001150 union __lx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001151
Howard Hinnant9c0df142012-10-30 19:06:59 +00001152 enum {__n_words = sizeof(__lx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001153
1154 struct __raw
1155 {
1156 size_type __words[__n_words];
1157 };
1158
1159 struct __rep
1160 {
1161 union
1162 {
1163 __long __l;
1164 __short __s;
1165 __raw __r;
1166 };
1167 };
1168
1169 __compressed_pair<__rep, allocator_type> __r_;
1170
1171#ifdef _LIBCPP_DEBUG
1172
1173 pair<iterator*, const_iterator*> __iterator_list_;
1174
1175 _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;}
1176 _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
1177
1178#endif // _LIBCPP_DEBUG
1179
1180public:
1181 static const size_type npos = -1;
1182
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001183 _LIBCPP_INLINE_VISIBILITY basic_string()
1184 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001185 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001186 basic_string(const basic_string& __str);
1187 basic_string(const basic_string& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001188#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59 +00001189 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001190 basic_string(basic_string&& __str)
1191 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant9f193f22011-01-26 00:06:59 +00001192 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001193 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001194#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001195 _LIBCPP_INLINE_VISIBILITY basic_string(const_pointer __s);
1196 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001197 basic_string(const_pointer __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001198 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001199 basic_string(const_pointer __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001200 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001201 basic_string(const_pointer __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001202 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001203 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001205 basic_string(size_type __n, value_type __c, const allocator_type& __a);
1206 basic_string(const basic_string& __str, size_type __pos, size_type __n = npos,
1207 const allocator_type& __a = allocator_type());
1208 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001209 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001210 basic_string(_InputIterator __first, _InputIterator __last);
1211 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001212 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001213 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001214#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001215 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001216 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001217 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001219#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001220
1221 ~basic_string();
1222
Howard Hinnante32b5e22010-11-17 17:55:08 +00001223 basic_string& operator=(const basic_string& __str);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001224#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001225 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001226 basic_string& operator=(basic_string&& __str)
1227 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1228 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001229#endif
Howard Hinnanta6119a82011-05-29 19:57:12 +00001230 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const_pointer __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001231 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02 +00001232#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001234 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001235#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001236
1237#ifndef _LIBCPP_DEBUG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001238 _LIBCPP_INLINE_VISIBILITY
1239 iterator begin() _NOEXCEPT
1240 {return iterator(__get_pointer());}
1241 _LIBCPP_INLINE_VISIBILITY
1242 const_iterator begin() const _NOEXCEPT
1243 {return const_iterator(data());}
1244 _LIBCPP_INLINE_VISIBILITY
1245 iterator end() _NOEXCEPT
1246 {return iterator(__get_pointer() + size());}
1247 _LIBCPP_INLINE_VISIBILITY
1248 const_iterator end() const _NOEXCEPT
1249 {return const_iterator(data() + size());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250#else // _LIBCPP_DEBUG
1251 _LIBCPP_INLINE_VISIBILITY iterator begin() {return iterator(this, __get_pointer());}
1252 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return const_iterator(this, data());}
1253 _LIBCPP_INLINE_VISIBILITY iterator end() {return iterator(this, __get_pointer() + size());}
1254 _LIBCPP_INLINE_VISIBILITY const_iterator end() const {return const_iterator(this, data() + size());}
1255#endif // _LIBCPP_DEBUG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001256 _LIBCPP_INLINE_VISIBILITY
1257 reverse_iterator rbegin() _NOEXCEPT
1258 {return reverse_iterator(end());}
1259 _LIBCPP_INLINE_VISIBILITY
1260 const_reverse_iterator rbegin() const _NOEXCEPT
1261 {return const_reverse_iterator(end());}
1262 _LIBCPP_INLINE_VISIBILITY
1263 reverse_iterator rend() _NOEXCEPT
1264 {return reverse_iterator(begin());}
1265 _LIBCPP_INLINE_VISIBILITY
1266 const_reverse_iterator rend() const _NOEXCEPT
1267 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001268
Howard Hinnanta6119a82011-05-29 19:57:12 +00001269 _LIBCPP_INLINE_VISIBILITY
1270 const_iterator cbegin() const _NOEXCEPT
1271 {return begin();}
1272 _LIBCPP_INLINE_VISIBILITY
1273 const_iterator cend() const _NOEXCEPT
1274 {return end();}
1275 _LIBCPP_INLINE_VISIBILITY
1276 const_reverse_iterator crbegin() const _NOEXCEPT
1277 {return rbegin();}
1278 _LIBCPP_INLINE_VISIBILITY
1279 const_reverse_iterator crend() const _NOEXCEPT
1280 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001281
Howard Hinnanta6119a82011-05-29 19:57:12 +00001282 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001283 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001284 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
1285 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
1286 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001287 {return (__is_long() ? __get_long_cap() : __min_cap) - 1;}
1288
1289 void resize(size_type __n, value_type __c);
1290 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
1291
1292 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001293 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001294 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001295 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001296 void clear() _NOEXCEPT;
1297 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001298
1299 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
1300 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
1301
1302 const_reference at(size_type __n) const;
1303 reference at(size_type __n);
1304
1305 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
1306 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const_pointer __s) {return append(__s);}
1307 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00001308#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02 +00001310#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001311
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001313 basic_string& append(const basic_string& __str);
1314 basic_string& append(const basic_string& __str, size_type __pos, size_type __n);
1315 basic_string& append(const_pointer __s, size_type __n);
1316 basic_string& append(const_pointer __s);
1317 basic_string& append(size_type __n, value_type __c);
1318 template<class _InputIterator>
1319 typename enable_if
1320 <
1321 __is_input_iterator <_InputIterator>::value &&
1322 !__is_forward_iterator<_InputIterator>::value,
1323 basic_string&
1324 >::type
1325 append(_InputIterator __first, _InputIterator __last);
1326 template<class _ForwardIterator>
1327 typename enable_if
1328 <
1329 __is_forward_iterator<_ForwardIterator>::value,
1330 basic_string&
1331 >::type
1332 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001333#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001334 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001335 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001336#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001337
1338 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001339 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001341 _LIBCPP_INLINE_VISIBILITY reference front();
1342 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1343 _LIBCPP_INLINE_VISIBILITY reference back();
1344 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001346 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001347 basic_string& assign(const basic_string& __str);
Howard Hinnanta6119a82011-05-29 19:57:12 +00001348#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1349 _LIBCPP_INLINE_VISIBILITY
1350 basic_string& assign(basic_string&& str)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001351 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001352#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001353 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n);
1354 basic_string& assign(const_pointer __s, size_type __n);
1355 basic_string& assign(const_pointer __s);
1356 basic_string& assign(size_type __n, value_type __c);
1357 template<class _InputIterator>
1358 typename enable_if
1359 <
1360 __is_input_iterator <_InputIterator>::value &&
1361 !__is_forward_iterator<_InputIterator>::value,
1362 basic_string&
1363 >::type
1364 assign(_InputIterator __first, _InputIterator __last);
1365 template<class _ForwardIterator>
1366 typename enable_if
1367 <
1368 __is_forward_iterator<_ForwardIterator>::value,
1369 basic_string&
1370 >::type
1371 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001372#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001373 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001374 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001375#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001376
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001377 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001378 basic_string& insert(size_type __pos1, const basic_string& __str);
1379 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n);
1380 basic_string& insert(size_type __pos, const_pointer __s, size_type __n);
1381 basic_string& insert(size_type __pos, const_pointer __s);
1382 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1383 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001384 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001385 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1386 template<class _InputIterator>
1387 typename enable_if
1388 <
1389 __is_input_iterator <_InputIterator>::value &&
1390 !__is_forward_iterator<_InputIterator>::value,
1391 iterator
1392 >::type
1393 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1394 template<class _ForwardIterator>
1395 typename enable_if
1396 <
1397 __is_forward_iterator<_ForwardIterator>::value,
1398 iterator
1399 >::type
1400 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001401#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001402 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1404 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001405#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001406
1407 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001409 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001411 iterator erase(const_iterator __first, const_iterator __last);
1412
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001414 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
1415 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2);
1416 basic_string& replace(size_type __pos, size_type __n1, const_pointer __s, size_type __n2);
1417 basic_string& replace(size_type __pos, size_type __n1, const_pointer __s);
1418 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001420 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001422 basic_string& replace(const_iterator __i1, const_iterator __i2, const_pointer __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001423 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001424 basic_string& replace(const_iterator __i1, const_iterator __i2, const_pointer __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001426 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001427 template<class _InputIterator>
1428 typename enable_if
1429 <
1430 __is_input_iterator<_InputIterator>::value,
1431 basic_string&
1432 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001433 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:02 +00001434#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001435 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001436 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001438#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001439
1440 size_type copy(pointer __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001442 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1443
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001444 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001445 void swap(basic_string& __str)
1446 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1447 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001448
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001450 const_pointer c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001452 const_pointer data() const _NOEXCEPT {return __get_pointer();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001453
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001455 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001456
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001458 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1459 size_type find(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001461 size_type find(const_pointer __s, size_type __pos = 0) const _NOEXCEPT;
1462 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001463
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001464 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001465 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1466 size_type rfind(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001468 size_type rfind(const_pointer __s, size_type __pos = npos) const _NOEXCEPT;
1469 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001470
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001471 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001472 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1473 size_type find_first_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001475 size_type find_first_of(const_pointer __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001477 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001478
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001480 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1481 size_type find_last_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001483 size_type find_last_of(const_pointer __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001485 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001486
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001488 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1489 size_type find_first_not_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
1490 _LIBCPP_INLINE_VISIBILITY
1491 size_type find_first_not_of(const_pointer __s, size_type __pos = 0) const _NOEXCEPT;
1492 _LIBCPP_INLINE_VISIBILITY
1493 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1494
1495 _LIBCPP_INLINE_VISIBILITY
1496 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1497 size_type find_last_not_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
1498 _LIBCPP_INLINE_VISIBILITY
1499 size_type find_last_not_of(const_pointer __s, size_type __pos = npos) const _NOEXCEPT;
1500 _LIBCPP_INLINE_VISIBILITY
1501 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1502
1503 _LIBCPP_INLINE_VISIBILITY
1504 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001506 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
1507 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2) const;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001508 int compare(const_pointer __s) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001509 int compare(size_type __pos1, size_type __n1, const_pointer __s) const;
1510 int compare(size_type __pos1, size_type __n1, const_pointer __s, size_type __n2) const;
1511
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001512 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001513
1514 _LIBCPP_INLINE_VISIBILITY
1515 bool __is_long() const _NOEXCEPT
1516 {return bool(__r_.first().__s.__size_ & __short_mask);}
1517
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001519 _LIBCPP_INLINE_VISIBILITY
1520 allocator_type& __alloc() _NOEXCEPT
1521 {return __r_.second();}
1522 _LIBCPP_INLINE_VISIBILITY
1523 const allocator_type& __alloc() const _NOEXCEPT
1524 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525
Howard Hinnant15467182013-04-30 21:44:48 +00001526#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1527
Howard Hinnanta6119a82011-05-29 19:57:12 +00001528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001529 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001530# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001531 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001532# else
1533 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1534# endif
1535
Howard Hinnanta6119a82011-05-29 19:57:12 +00001536 _LIBCPP_INLINE_VISIBILITY
1537 size_type __get_short_size() const _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001538# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001539 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001540# else
1541 {return __r_.first().__s.__size_;}
1542# endif
1543
1544#else // _LIBCPP_ALTERNATE_STRING_LAYOUT
1545
1546 _LIBCPP_INLINE_VISIBILITY
1547 void __set_short_size(size_type __s) _NOEXCEPT
1548# if _LIBCPP_BIG_ENDIAN
1549 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1550# else
1551 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1552# endif
1553
1554 _LIBCPP_INLINE_VISIBILITY
1555 size_type __get_short_size() const _NOEXCEPT
1556# if _LIBCPP_BIG_ENDIAN
1557 {return __r_.first().__s.__size_;}
1558# else
1559 {return __r_.first().__s.__size_ >> 1;}
1560# endif
1561
1562#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1563
Howard Hinnanta6119a82011-05-29 19:57:12 +00001564 _LIBCPP_INLINE_VISIBILITY
1565 void __set_long_size(size_type __s) _NOEXCEPT
1566 {__r_.first().__l.__size_ = __s;}
1567 _LIBCPP_INLINE_VISIBILITY
1568 size_type __get_long_size() const _NOEXCEPT
1569 {return __r_.first().__l.__size_;}
1570 _LIBCPP_INLINE_VISIBILITY
1571 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001572 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1573
Howard Hinnanta6119a82011-05-29 19:57:12 +00001574 _LIBCPP_INLINE_VISIBILITY
1575 void __set_long_cap(size_type __s) _NOEXCEPT
1576 {__r_.first().__l.__cap_ = __long_mask | __s;}
1577 _LIBCPP_INLINE_VISIBILITY
1578 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001579 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001580
Howard Hinnanta6119a82011-05-29 19:57:12 +00001581 _LIBCPP_INLINE_VISIBILITY
1582 void __set_long_pointer(pointer __p) _NOEXCEPT
1583 {__r_.first().__l.__data_ = __p;}
1584 _LIBCPP_INLINE_VISIBILITY
1585 pointer __get_long_pointer() _NOEXCEPT
1586 {return __r_.first().__l.__data_;}
1587 _LIBCPP_INLINE_VISIBILITY
1588 const_pointer __get_long_pointer() const _NOEXCEPT
1589 {return __r_.first().__l.__data_;}
1590 _LIBCPP_INLINE_VISIBILITY
1591 pointer __get_short_pointer() _NOEXCEPT
1592 {return __r_.first().__s.__data_;}
1593 _LIBCPP_INLINE_VISIBILITY
1594 const_pointer __get_short_pointer() const _NOEXCEPT
1595 {return __r_.first().__s.__data_;}
1596 _LIBCPP_INLINE_VISIBILITY
1597 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001598 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001599 _LIBCPP_INLINE_VISIBILITY
1600 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001601 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1602
Howard Hinnanta6119a82011-05-29 19:57:12 +00001603 _LIBCPP_INLINE_VISIBILITY
1604 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001605 {
1606 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1607 for (unsigned __i = 0; __i < __n_words; ++__i)
1608 __a[__i] = 0;
1609 }
1610
1611 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001612 _LIBCPP_INLINE_VISIBILITY
1613 size_type __align(size_type __s) _NOEXCEPT
1614 {return __s + (__a-1) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001615 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001616 static _LIBCPP_INLINE_VISIBILITY
1617 size_type __recommend(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001618 {return (__s < __min_cap ? __min_cap :
Howard Hinnanta6119a82011-05-29 19:57:12 +00001619 __align<sizeof(value_type) < __alignment ?
1620 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001621
1622 void __init(const_pointer __s, size_type __sz, size_type __reserve);
1623 void __init(const_pointer __s, size_type __sz);
1624 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001625
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001626 template <class _InputIterator>
1627 typename enable_if
1628 <
1629 __is_input_iterator <_InputIterator>::value &&
1630 !__is_forward_iterator<_InputIterator>::value,
1631 void
1632 >::type
1633 __init(_InputIterator __first, _InputIterator __last);
1634
1635 template <class _ForwardIterator>
1636 typename enable_if
1637 <
1638 __is_forward_iterator<_ForwardIterator>::value,
1639 void
1640 >::type
1641 __init(_ForwardIterator __first, _ForwardIterator __last);
1642
1643 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001644 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001645 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1646 size_type __n_copy, size_type __n_del,
1647 size_type __n_add, const_pointer __p_new_stuff);
1648
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001650 void __erase_to_end(size_type __pos);
1651
Howard Hinnante32b5e22010-11-17 17:55:08 +00001652 _LIBCPP_INLINE_VISIBILITY
1653 void __copy_assign_alloc(const basic_string& __str)
1654 {__copy_assign_alloc(__str, integral_constant<bool,
1655 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1656
1657 _LIBCPP_INLINE_VISIBILITY
1658 void __copy_assign_alloc(const basic_string& __str, true_type)
1659 {
1660 if (__alloc() != __str.__alloc())
1661 {
1662 clear();
1663 shrink_to_fit();
1664 }
1665 __alloc() = __str.__alloc();
1666 }
1667
1668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001669 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001670 {}
1671
1672#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00001674 void __move_assign(basic_string& __str, false_type);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001676 void __move_assign(basic_string& __str, true_type)
1677 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001678#endif
1679
1680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001681 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001682 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001683 _NOEXCEPT_(
1684 !__alloc_traits::propagate_on_container_move_assignment::value ||
1685 is_nothrow_move_assignable<allocator_type>::value)
1686 {__move_assign_alloc(__str, integral_constant<bool,
1687 __alloc_traits::propagate_on_container_move_assignment::value>());}
1688
1689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001690 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001691 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1692 {
1693 __alloc() = _VSTD::move(__c.__alloc());
1694 }
1695
1696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001697 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001698 _NOEXCEPT
1699 {}
1700
1701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001702 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
1703 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1704 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001705 {__swap_alloc(__x, __y, integral_constant<bool,
1706 __alloc_traits::propagate_on_container_swap::value>());}
1707
1708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001709 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
1710 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001711 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001712 using _VSTD::swap;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001713 swap(__x, __y);
1714 }
1715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001716 static void __swap_alloc(allocator_type&, allocator_type&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001717 {}
1718
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001719 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1720 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001721
1722 friend basic_string operator+<>(const basic_string&, const basic_string&);
1723 friend basic_string operator+<>(const value_type*, const basic_string&);
1724 friend basic_string operator+<>(value_type, const basic_string&);
1725 friend basic_string operator+<>(const basic_string&, const value_type*);
1726 friend basic_string operator+<>(const basic_string&, value_type);
1727};
1728
1729template <class _CharT, class _Traits, class _Allocator>
1730#ifndef _LIBCPP_DEBUG
1731_LIBCPP_INLINE_VISIBILITY inline
1732#endif
1733void
1734basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1735{
1736#ifdef _LIBCPP_DEBUG
1737 iterator::__remove_all(this);
1738 const_iterator::__remove_all(this);
Howard Hinnant324bb032010-08-22 00:02:43 +00001739#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001740}
1741
1742template <class _CharT, class _Traits, class _Allocator>
1743#ifndef _LIBCPP_DEBUG
1744_LIBCPP_INLINE_VISIBILITY inline
1745#endif
1746void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001747basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
1748#ifdef _LIBCPP_DEBUG
1749 __pos
1750#endif
1751 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001752{
1753#ifdef _LIBCPP_DEBUG
1754 const_iterator __beg = begin();
1755 if (__iterator_list_.first)
1756 {
1757 for (iterator* __p = __iterator_list_.first; __p;)
1758 {
1759 if (*__p - __beg > static_cast<difference_type>(__pos))
1760 {
1761 iterator* __n = __p;
1762 __p = __p->__next;
1763 __n->__remove_owner();
1764 }
1765 else
1766 __p = __p->__next;
1767 }
1768 }
1769 if (__iterator_list_.second)
1770 {
1771 for (const_iterator* __p = __iterator_list_.second; __p;)
1772 {
1773 if (*__p - __beg > static_cast<difference_type>(__pos))
1774 {
1775 const_iterator* __n = __p;
1776 __p = __p->__next;
1777 __n->__remove_owner();
1778 }
1779 else
1780 __p = __p->__next;
1781 }
1782 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001783#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001784}
1785
1786template <class _CharT, class _Traits, class _Allocator>
1787_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001788basic_string<_CharT, _Traits, _Allocator>::basic_string()
1789 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001790{
1791 __zero();
1792}
1793
1794template <class _CharT, class _Traits, class _Allocator>
1795_LIBCPP_INLINE_VISIBILITY inline
1796basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
1797 : __r_(__a)
1798{
1799 __zero();
1800}
1801
1802template <class _CharT, class _Traits, class _Allocator>
1803void
1804basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type __sz, size_type __reserve)
1805{
1806 if (__reserve > max_size())
1807 this->__throw_length_error();
1808 pointer __p;
1809 if (__reserve < __min_cap)
1810 {
1811 __set_short_size(__sz);
1812 __p = __get_short_pointer();
1813 }
1814 else
1815 {
1816 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001817 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001818 __set_long_pointer(__p);
1819 __set_long_cap(__cap+1);
1820 __set_long_size(__sz);
1821 }
1822 traits_type::copy(__p, __s, __sz);
1823 traits_type::assign(__p[__sz], value_type());
1824}
1825
1826template <class _CharT, class _Traits, class _Allocator>
1827void
1828basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type __sz)
1829{
1830 if (__sz > max_size())
1831 this->__throw_length_error();
1832 pointer __p;
1833 if (__sz < __min_cap)
1834 {
1835 __set_short_size(__sz);
1836 __p = __get_short_pointer();
1837 }
1838 else
1839 {
1840 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001841 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001842 __set_long_pointer(__p);
1843 __set_long_cap(__cap+1);
1844 __set_long_size(__sz);
1845 }
1846 traits_type::copy(__p, __s, __sz);
1847 traits_type::assign(__p[__sz], value_type());
1848}
1849
1850template <class _CharT, class _Traits, class _Allocator>
1851_LIBCPP_INLINE_VISIBILITY inline
1852basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s)
1853{
1854#ifdef _LIBCPP_DEBUG
1855 assert(__s != 0);
1856#endif
1857 __init(__s, traits_type::length(__s));
1858}
1859
1860template <class _CharT, class _Traits, class _Allocator>
1861_LIBCPP_INLINE_VISIBILITY inline
1862basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, const allocator_type& __a)
1863 : __r_(__a)
1864{
1865#ifdef _LIBCPP_DEBUG
1866 assert(__s != 0);
1867#endif
1868 __init(__s, traits_type::length(__s));
1869}
1870
1871template <class _CharT, class _Traits, class _Allocator>
1872_LIBCPP_INLINE_VISIBILITY inline
1873basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, size_type __n)
1874{
1875#ifdef _LIBCPP_DEBUG
1876 assert(__s != 0);
1877#endif
1878 __init(__s, __n);
1879}
1880
1881template <class _CharT, class _Traits, class _Allocator>
1882_LIBCPP_INLINE_VISIBILITY inline
1883basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, size_type __n, const allocator_type& __a)
1884 : __r_(__a)
1885{
1886#ifdef _LIBCPP_DEBUG
1887 assert(__s != 0);
1888#endif
1889 __init(__s, __n);
1890}
1891
1892template <class _CharT, class _Traits, class _Allocator>
1893basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001894 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001895{
1896 if (!__str.__is_long())
1897 __r_.first().__r = __str.__r_.first().__r;
1898 else
1899 __init(__str.__get_long_pointer(), __str.__get_long_size());
1900}
1901
1902template <class _CharT, class _Traits, class _Allocator>
1903basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
1904 : __r_(__a)
1905{
1906 if (!__str.__is_long())
1907 __r_.first().__r = __str.__r_.first().__r;
1908 else
1909 __init(__str.__get_long_pointer(), __str.__get_long_size());
1910}
1911
Howard Hinnant73d21a42010-09-04 23:28:19 +00001912#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001913
1914template <class _CharT, class _Traits, class _Allocator>
1915_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001916basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
1917 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001918 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001919{
1920 __str.__zero();
1921#ifdef _LIBCPP_DEBUG
1922 __str.__invalidate_all_iterators();
1923#endif
1924}
1925
1926template <class _CharT, class _Traits, class _Allocator>
1927_LIBCPP_INLINE_VISIBILITY inline
1928basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001929 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001930{
Howard Hinnante32b5e22010-11-17 17:55:08 +00001931 if (__a == __str.__alloc() || !__str.__is_long())
1932 __r_.first().__r = __str.__r_.first().__r;
1933 else
1934 __init(__str.__get_long_pointer(), __str.__get_long_size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935 __str.__zero();
1936#ifdef _LIBCPP_DEBUG
1937 __str.__invalidate_all_iterators();
1938#endif
1939}
1940
Howard Hinnant73d21a42010-09-04 23:28:19 +00001941#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001942
1943template <class _CharT, class _Traits, class _Allocator>
1944void
1945basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1946{
1947 if (__n > max_size())
1948 this->__throw_length_error();
1949 pointer __p;
1950 if (__n < __min_cap)
1951 {
1952 __set_short_size(__n);
1953 __p = __get_short_pointer();
1954 }
1955 else
1956 {
1957 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001958 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001959 __set_long_pointer(__p);
1960 __set_long_cap(__cap+1);
1961 __set_long_size(__n);
1962 }
1963 traits_type::assign(__p, __n, __c);
1964 traits_type::assign(__p[__n], value_type());
1965}
1966
1967template <class _CharT, class _Traits, class _Allocator>
1968_LIBCPP_INLINE_VISIBILITY inline
1969basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
1970{
1971 __init(__n, __c);
1972}
1973
1974template <class _CharT, class _Traits, class _Allocator>
1975_LIBCPP_INLINE_VISIBILITY inline
1976basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
1977 : __r_(__a)
1978{
1979 __init(__n, __c);
1980}
1981
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001982template <class _CharT, class _Traits, class _Allocator>
1983basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
1984 const allocator_type& __a)
1985 : __r_(__a)
1986{
1987 size_type __str_sz = __str.size();
1988 if (__pos > __str_sz)
1989 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001990 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001991}
1992
1993template <class _CharT, class _Traits, class _Allocator>
1994template <class _InputIterator>
1995typename enable_if
1996<
1997 __is_input_iterator <_InputIterator>::value &&
1998 !__is_forward_iterator<_InputIterator>::value,
1999 void
2000>::type
2001basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2002{
2003 __zero();
2004#ifndef _LIBCPP_NO_EXCEPTIONS
2005 try
2006 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002007#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002008 for (; __first != __last; ++__first)
2009 push_back(*__first);
2010#ifndef _LIBCPP_NO_EXCEPTIONS
2011 }
2012 catch (...)
2013 {
2014 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002015 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002016 throw;
2017 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002018#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002019}
2020
2021template <class _CharT, class _Traits, class _Allocator>
2022template <class _ForwardIterator>
2023typename enable_if
2024<
2025 __is_forward_iterator<_ForwardIterator>::value,
2026 void
2027>::type
2028basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2029{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002030 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002031 if (__sz > max_size())
2032 this->__throw_length_error();
2033 pointer __p;
2034 if (__sz < __min_cap)
2035 {
2036 __set_short_size(__sz);
2037 __p = __get_short_pointer();
2038 }
2039 else
2040 {
2041 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002042 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002043 __set_long_pointer(__p);
2044 __set_long_cap(__cap+1);
2045 __set_long_size(__sz);
2046 }
2047 for (; __first != __last; ++__first, ++__p)
2048 traits_type::assign(*__p, *__first);
2049 traits_type::assign(*__p, value_type());
2050}
2051
2052template <class _CharT, class _Traits, class _Allocator>
2053template<class _InputIterator>
2054_LIBCPP_INLINE_VISIBILITY inline
2055basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2056{
2057 __init(__first, __last);
2058}
2059
2060template <class _CharT, class _Traits, class _Allocator>
2061template<class _InputIterator>
2062_LIBCPP_INLINE_VISIBILITY inline
2063basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2064 const allocator_type& __a)
2065 : __r_(__a)
2066{
2067 __init(__first, __last);
2068}
2069
Howard Hinnante3e32912011-08-12 21:56:02 +00002070#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2071
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002072template <class _CharT, class _Traits, class _Allocator>
2073_LIBCPP_INLINE_VISIBILITY inline
2074basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
2075{
2076 __init(__il.begin(), __il.end());
2077}
2078
2079template <class _CharT, class _Traits, class _Allocator>
2080_LIBCPP_INLINE_VISIBILITY inline
2081basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
2082 : __r_(__a)
2083{
2084 __init(__il.begin(), __il.end());
2085}
2086
Howard Hinnante3e32912011-08-12 21:56:02 +00002087#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2088
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002089template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002090basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2091{
2092 __invalidate_all_iterators();
2093 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002094 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095}
2096
2097template <class _CharT, class _Traits, class _Allocator>
2098void
2099basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2100 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2101 size_type __n_copy, size_type __n_del, size_type __n_add, const_pointer __p_new_stuff)
2102{
2103 size_type __ms = max_size();
2104 if (__delta_cap > __ms - __old_cap - 1)
2105 this->__throw_length_error();
2106 pointer __old_p = __get_pointer();
2107 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002108 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002109 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002110 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002111 __invalidate_all_iterators();
2112 if (__n_copy != 0)
2113 traits_type::copy(__p, __old_p, __n_copy);
2114 if (__n_add != 0)
2115 traits_type::copy(__p + __n_copy, __p_new_stuff, __n_add);
2116 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2117 if (__sec_cp_sz != 0)
2118 traits_type::copy(__p + __n_copy + __n_add, __old_p + __n_copy + __n_del, __sec_cp_sz);
2119 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002120 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002121 __set_long_pointer(__p);
2122 __set_long_cap(__cap+1);
2123 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2124 __set_long_size(__old_sz);
2125 traits_type::assign(__p[__old_sz], value_type());
2126}
2127
2128template <class _CharT, class _Traits, class _Allocator>
2129void
2130basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2131 size_type __n_copy, size_type __n_del, size_type __n_add)
2132{
2133 size_type __ms = max_size();
2134 if (__delta_cap > __ms - __old_cap - 1)
2135 this->__throw_length_error();
2136 pointer __old_p = __get_pointer();
2137 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002138 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002139 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002140 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002141 __invalidate_all_iterators();
2142 if (__n_copy != 0)
Howard Hinnant635bbbb2013-02-07 15:31:44 +00002143 traits_type::copy(__p, __old_p, __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002144 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2145 if (__sec_cp_sz != 0)
Howard Hinnant635bbbb2013-02-07 15:31:44 +00002146 traits_type::copy(__p + __n_copy + __n_add, __old_p + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002147 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002148 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002149 __set_long_pointer(__p);
2150 __set_long_cap(__cap+1);
2151}
2152
2153// assign
2154
2155template <class _CharT, class _Traits, class _Allocator>
2156basic_string<_CharT, _Traits, _Allocator>&
2157basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s, size_type __n)
2158{
2159#ifdef _LIBCPP_DEBUG
2160 assert(__s != 0);
2161#endif
2162 size_type __cap = capacity();
2163 if (__cap >= __n)
2164 {
2165 pointer __p = __get_pointer();
2166 traits_type::move(__p, __s, __n);
2167 traits_type::assign(__p[__n], value_type());
2168 __set_size(__n);
2169 __invalidate_iterators_past(__n);
2170 }
2171 else
2172 {
2173 size_type __sz = size();
2174 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2175 }
2176 return *this;
2177}
2178
2179template <class _CharT, class _Traits, class _Allocator>
2180basic_string<_CharT, _Traits, _Allocator>&
2181basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2182{
2183 size_type __cap = capacity();
2184 if (__cap < __n)
2185 {
2186 size_type __sz = size();
2187 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2188 }
2189 else
2190 __invalidate_iterators_past(__n);
2191 pointer __p = __get_pointer();
2192 traits_type::assign(__p, __n, __c);
2193 traits_type::assign(__p[__n], value_type());
2194 __set_size(__n);
2195 return *this;
2196}
2197
2198template <class _CharT, class _Traits, class _Allocator>
2199basic_string<_CharT, _Traits, _Allocator>&
2200basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2201{
2202 pointer __p;
2203 if (__is_long())
2204 {
2205 __p = __get_long_pointer();
2206 __set_long_size(1);
2207 }
2208 else
2209 {
2210 __p = __get_short_pointer();
2211 __set_short_size(1);
2212 }
2213 traits_type::assign(*__p, __c);
2214 traits_type::assign(*++__p, value_type());
2215 __invalidate_iterators_past(1);
2216 return *this;
2217}
2218
2219template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002220basic_string<_CharT, _Traits, _Allocator>&
2221basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2222{
2223 if (this != &__str)
2224 {
2225 __copy_assign_alloc(__str);
2226 assign(__str);
2227 }
2228 return *this;
2229}
2230
2231#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2232
2233template <class _CharT, class _Traits, class _Allocator>
2234_LIBCPP_INLINE_VISIBILITY inline
2235void
2236basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2237{
2238 if (__alloc() != __str.__alloc())
2239 assign(__str);
2240 else
2241 __move_assign(__str, true_type());
2242}
2243
2244template <class _CharT, class _Traits, class _Allocator>
2245_LIBCPP_INLINE_VISIBILITY inline
2246void
2247basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002248 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002249{
2250 clear();
2251 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002252 __r_.first() = __str.__r_.first();
2253 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002254 __str.__zero();
2255}
2256
2257template <class _CharT, class _Traits, class _Allocator>
2258_LIBCPP_INLINE_VISIBILITY inline
2259basic_string<_CharT, _Traits, _Allocator>&
2260basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002261 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
2262 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002263{
2264 __move_assign(__str, integral_constant<bool,
2265 __alloc_traits::propagate_on_container_move_assignment::value>());
2266 return *this;
2267}
2268
2269#endif
2270
2271template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002272template<class _InputIterator>
2273typename enable_if
2274<
2275 __is_input_iterator <_InputIterator>::value &&
2276 !__is_forward_iterator<_InputIterator>::value,
2277 basic_string<_CharT, _Traits, _Allocator>&
2278>::type
2279basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2280{
2281 clear();
2282 for (; __first != __last; ++__first)
2283 push_back(*__first);
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002284 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002285}
2286
2287template <class _CharT, class _Traits, class _Allocator>
2288template<class _ForwardIterator>
2289typename enable_if
2290<
2291 __is_forward_iterator<_ForwardIterator>::value,
2292 basic_string<_CharT, _Traits, _Allocator>&
2293>::type
2294basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2295{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002296 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002297 size_type __cap = capacity();
2298 if (__cap < __n)
2299 {
2300 size_type __sz = size();
2301 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2302 }
2303 else
2304 __invalidate_iterators_past(__n);
2305 pointer __p = __get_pointer();
2306 for (; __first != __last; ++__first, ++__p)
2307 traits_type::assign(*__p, *__first);
2308 traits_type::assign(*__p, value_type());
2309 __set_size(__n);
2310 return *this;
2311}
2312
2313template <class _CharT, class _Traits, class _Allocator>
2314_LIBCPP_INLINE_VISIBILITY inline
2315basic_string<_CharT, _Traits, _Allocator>&
2316basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
2317{
2318 return assign(__str.data(), __str.size());
2319}
2320
2321template <class _CharT, class _Traits, class _Allocator>
2322basic_string<_CharT, _Traits, _Allocator>&
2323basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2324{
2325 size_type __sz = __str.size();
2326 if (__pos > __sz)
2327 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002328 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002329}
2330
2331template <class _CharT, class _Traits, class _Allocator>
2332basic_string<_CharT, _Traits, _Allocator>&
2333basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s)
2334{
2335#ifdef _LIBCPP_DEBUG
2336 assert(__s != 0);
2337#endif
2338 return assign(__s, traits_type::length(__s));
2339}
2340
2341// append
2342
2343template <class _CharT, class _Traits, class _Allocator>
2344basic_string<_CharT, _Traits, _Allocator>&
2345basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s, size_type __n)
2346{
2347#ifdef _LIBCPP_DEBUG
2348 assert(__s != 0);
2349#endif
2350 size_type __cap = capacity();
2351 size_type __sz = size();
2352 if (__cap - __sz >= __n)
2353 {
2354 if (__n)
2355 {
2356 pointer __p = __get_pointer();
2357 traits_type::copy(__p + __sz, __s, __n);
2358 __sz += __n;
2359 __set_size(__sz);
2360 traits_type::assign(__p[__sz], value_type());
2361 }
2362 }
2363 else
2364 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2365 return *this;
2366}
2367
2368template <class _CharT, class _Traits, class _Allocator>
2369basic_string<_CharT, _Traits, _Allocator>&
2370basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2371{
2372 if (__n)
2373 {
2374 size_type __cap = capacity();
2375 size_type __sz = size();
2376 if (__cap - __sz < __n)
2377 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2378 pointer __p = __get_pointer();
Howard Hinnant635bbbb2013-02-07 15:31:44 +00002379 traits_type::assign(__p + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002380 __sz += __n;
2381 __set_size(__sz);
2382 traits_type::assign(__p[__sz], value_type());
2383 }
2384 return *this;
2385}
2386
2387template <class _CharT, class _Traits, class _Allocator>
2388void
2389basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2390{
Howard Hinnant15467182013-04-30 21:44:48 +00002391 bool __is_short = !__is_long();
2392 size_type __cap;
2393 size_type __sz;
2394 if (__is_short)
2395 {
2396 __cap = __min_cap - 1;
2397 __sz = __get_short_size();
2398 }
2399 else
2400 {
2401 __cap = __get_long_cap() - 1;
2402 __sz = __get_long_size();
2403 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002404 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002405 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002406 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002407 __is_short = !__is_long();
2408 }
2409 pointer __p;
2410 if (__is_short)
2411 {
2412 __p = __get_short_pointer() + __sz;
2413 __set_short_size(__sz+1);
2414 }
2415 else
2416 {
2417 __p = __get_long_pointer() + __sz;
2418 __set_long_size(__sz+1);
2419 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002420 traits_type::assign(*__p, __c);
2421 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002422}
2423
2424template <class _CharT, class _Traits, class _Allocator>
2425template<class _InputIterator>
2426typename enable_if
2427<
2428 __is_input_iterator <_InputIterator>::value &&
2429 !__is_forward_iterator<_InputIterator>::value,
2430 basic_string<_CharT, _Traits, _Allocator>&
2431>::type
2432basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2433{
2434 for (; __first != __last; ++__first)
2435 push_back(*__first);
2436 return *this;
2437}
2438
2439template <class _CharT, class _Traits, class _Allocator>
2440template<class _ForwardIterator>
2441typename enable_if
2442<
2443 __is_forward_iterator<_ForwardIterator>::value,
2444 basic_string<_CharT, _Traits, _Allocator>&
2445>::type
2446basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2447{
2448 size_type __sz = size();
2449 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002450 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002451 if (__n)
2452 {
2453 if (__cap - __sz < __n)
2454 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2455 pointer __p = __get_pointer() + __sz;
2456 for (; __first != __last; ++__p, ++__first)
2457 traits_type::assign(*__p, *__first);
2458 traits_type::assign(*__p, value_type());
2459 __set_size(__sz + __n);
2460 }
2461 return *this;
2462}
2463
2464template <class _CharT, class _Traits, class _Allocator>
2465_LIBCPP_INLINE_VISIBILITY inline
2466basic_string<_CharT, _Traits, _Allocator>&
2467basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2468{
2469 return append(__str.data(), __str.size());
2470}
2471
2472template <class _CharT, class _Traits, class _Allocator>
2473basic_string<_CharT, _Traits, _Allocator>&
2474basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2475{
2476 size_type __sz = __str.size();
2477 if (__pos > __sz)
2478 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002479 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002480}
2481
2482template <class _CharT, class _Traits, class _Allocator>
2483basic_string<_CharT, _Traits, _Allocator>&
2484basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s)
2485{
2486#ifdef _LIBCPP_DEBUG
2487 assert(__s != 0);
2488#endif
2489 return append(__s, traits_type::length(__s));
2490}
2491
2492// insert
2493
2494template <class _CharT, class _Traits, class _Allocator>
2495basic_string<_CharT, _Traits, _Allocator>&
2496basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const_pointer __s, size_type __n)
2497{
2498#ifdef _LIBCPP_DEBUG
2499 assert(__s != 0);
2500#endif
2501 size_type __sz = size();
2502 if (__pos > __sz)
2503 this->__throw_out_of_range();
2504 size_type __cap = capacity();
2505 if (__cap - __sz >= __n)
2506 {
2507 if (__n)
2508 {
2509 pointer __p = __get_pointer();
2510 size_type __n_move = __sz - __pos;
2511 if (__n_move != 0)
2512 {
2513 if (__p + __pos <= __s && __s < __p + __sz)
2514 __s += __n;
2515 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2516 }
2517 traits_type::move(__p + __pos, __s, __n);
2518 __sz += __n;
2519 __set_size(__sz);
2520 traits_type::assign(__p[__sz], value_type());
2521 }
2522 }
2523 else
2524 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2525 return *this;
2526}
2527
2528template <class _CharT, class _Traits, class _Allocator>
2529basic_string<_CharT, _Traits, _Allocator>&
2530basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2531{
2532 size_type __sz = size();
2533 if (__pos > __sz)
2534 this->__throw_out_of_range();
2535 if (__n)
2536 {
2537 size_type __cap = capacity();
2538 pointer __p;
2539 if (__cap - __sz >= __n)
2540 {
2541 __p = __get_pointer();
2542 size_type __n_move = __sz - __pos;
2543 if (__n_move != 0)
2544 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2545 }
2546 else
2547 {
2548 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
2549 __p = __get_long_pointer();
2550 }
2551 traits_type::assign(__p + __pos, __n, __c);
2552 __sz += __n;
2553 __set_size(__sz);
2554 traits_type::assign(__p[__sz], value_type());
2555 }
2556 return *this;
2557}
2558
2559template <class _CharT, class _Traits, class _Allocator>
2560template<class _InputIterator>
2561typename enable_if
2562<
2563 __is_input_iterator <_InputIterator>::value &&
2564 !__is_forward_iterator<_InputIterator>::value,
2565 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2566>::type
2567basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2568{
2569 size_type __old_sz = size();
2570 difference_type __ip = __pos - begin();
2571 for (; __first != __last; ++__first)
2572 push_back(*__first);
2573 pointer __p = __get_pointer();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002574 _VSTD::rotate(__p + __ip, __p + __old_sz, __p + size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002575 return iterator(__p + __ip);
2576}
2577
2578template <class _CharT, class _Traits, class _Allocator>
2579template<class _ForwardIterator>
2580typename enable_if
2581<
2582 __is_forward_iterator<_ForwardIterator>::value,
2583 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2584>::type
2585basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2586{
2587 size_type __ip = static_cast<size_type>(__pos - begin());
2588 size_type __sz = size();
2589 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002590 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002591 if (__n)
2592 {
2593 pointer __p;
2594 if (__cap - __sz >= __n)
2595 {
2596 __p = __get_pointer();
2597 size_type __n_move = __sz - __ip;
2598 if (__n_move != 0)
2599 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2600 }
2601 else
2602 {
2603 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
2604 __p = __get_long_pointer();
2605 }
2606 __sz += __n;
2607 __set_size(__sz);
2608 traits_type::assign(__p[__sz], value_type());
2609 for (__p += __ip; __first != __last; ++__p, ++__first)
2610 traits_type::assign(*__p, *__first);
2611 }
2612 return begin() + __ip;
2613}
2614
2615template <class _CharT, class _Traits, class _Allocator>
2616_LIBCPP_INLINE_VISIBILITY inline
2617basic_string<_CharT, _Traits, _Allocator>&
2618basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2619{
2620 return insert(__pos1, __str.data(), __str.size());
2621}
2622
2623template <class _CharT, class _Traits, class _Allocator>
2624basic_string<_CharT, _Traits, _Allocator>&
2625basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2626 size_type __pos2, size_type __n)
2627{
2628 size_type __str_sz = __str.size();
2629 if (__pos2 > __str_sz)
2630 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002631 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002632}
2633
2634template <class _CharT, class _Traits, class _Allocator>
2635basic_string<_CharT, _Traits, _Allocator>&
2636basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const_pointer __s)
2637{
2638#ifdef _LIBCPP_DEBUG
2639 assert(__s != 0);
2640#endif
2641 return insert(__pos, __s, traits_type::length(__s));
2642}
2643
2644template <class _CharT, class _Traits, class _Allocator>
2645typename basic_string<_CharT, _Traits, _Allocator>::iterator
2646basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2647{
2648 size_type __ip = static_cast<size_type>(__pos - begin());
2649 size_type __sz = size();
2650 size_type __cap = capacity();
2651 pointer __p;
2652 if (__cap == __sz)
2653 {
2654 __grow_by(__cap, 1, __sz, __ip, 0, 1);
2655 __p = __get_long_pointer();
2656 }
2657 else
2658 {
2659 __p = __get_pointer();
2660 size_type __n_move = __sz - __ip;
2661 if (__n_move != 0)
2662 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2663 }
2664 traits_type::assign(__p[__ip], __c);
2665 traits_type::assign(__p[++__sz], value_type());
2666 __set_size(__sz);
2667 return begin() + static_cast<difference_type>(__ip);
2668}
2669
2670template <class _CharT, class _Traits, class _Allocator>
2671_LIBCPP_INLINE_VISIBILITY inline
2672typename basic_string<_CharT, _Traits, _Allocator>::iterator
2673basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2674{
2675 difference_type __p = __pos - begin();
2676 insert(static_cast<size_type>(__p), __n, __c);
2677 return begin() + __p;
2678}
2679
2680// replace
2681
2682template <class _CharT, class _Traits, class _Allocator>
2683basic_string<_CharT, _Traits, _Allocator>&
2684basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const_pointer __s, size_type __n2)
2685{
2686#ifdef _LIBCPP_DEBUG
2687 assert(__s != 0);
2688#endif
2689 size_type __sz = size();
2690 if (__pos > __sz)
2691 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002692 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002693 size_type __cap = capacity();
2694 if (__cap - __sz + __n1 >= __n2)
2695 {
2696 pointer __p = __get_pointer();
2697 if (__n1 != __n2)
2698 {
2699 size_type __n_move = __sz - __pos - __n1;
2700 if (__n_move != 0)
2701 {
2702 if (__n1 > __n2)
2703 {
2704 traits_type::move(__p + __pos, __s, __n2);
2705 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2706 goto __finish;
2707 }
2708 if (__p + __pos < __s && __s < __p + __sz)
2709 {
2710 if (__p + __pos + __n1 <= __s)
2711 __s += __n2 - __n1;
2712 else // __p + __pos < __s < __p + __pos + __n1
2713 {
2714 traits_type::move(__p + __pos, __s, __n1);
2715 __pos += __n1;
2716 __s += __n2;
2717 __n2 -= __n1;
2718 __n1 = 0;
2719 }
2720 }
2721 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2722 }
2723 }
2724 traits_type::move(__p + __pos, __s, __n2);
2725__finish:
2726 __sz += __n2 - __n1;
2727 __set_size(__sz);
2728 __invalidate_iterators_past(__sz);
2729 traits_type::assign(__p[__sz], value_type());
2730 }
2731 else
2732 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2733 return *this;
2734}
2735
2736template <class _CharT, class _Traits, class _Allocator>
2737basic_string<_CharT, _Traits, _Allocator>&
2738basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2739{
2740 size_type __sz = size();
2741 if (__pos > __sz)
2742 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002743 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002744 size_type __cap = capacity();
2745 pointer __p;
2746 if (__cap - __sz + __n1 >= __n2)
2747 {
2748 __p = __get_pointer();
2749 if (__n1 != __n2)
2750 {
2751 size_type __n_move = __sz - __pos - __n1;
2752 if (__n_move != 0)
2753 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2754 }
2755 }
2756 else
2757 {
2758 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
2759 __p = __get_long_pointer();
2760 }
2761 traits_type::assign(__p + __pos, __n2, __c);
2762 __sz += __n2 - __n1;
2763 __set_size(__sz);
2764 __invalidate_iterators_past(__sz);
2765 traits_type::assign(__p[__sz], value_type());
2766 return *this;
2767}
2768
2769template <class _CharT, class _Traits, class _Allocator>
2770template<class _InputIterator>
2771typename enable_if
2772<
2773 __is_input_iterator<_InputIterator>::value,
2774 basic_string<_CharT, _Traits, _Allocator>&
2775>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002776basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002777 _InputIterator __j1, _InputIterator __j2)
2778{
2779 for (; true; ++__i1, ++__j1)
2780 {
2781 if (__i1 == __i2)
2782 {
2783 if (__j1 != __j2)
2784 insert(__i1, __j1, __j2);
2785 break;
2786 }
2787 if (__j1 == __j2)
2788 {
2789 erase(__i1, __i2);
2790 break;
2791 }
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002792 traits_type::assign(const_cast<value_type&>(*__i1), *__j1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002793 }
2794 return *this;
2795}
2796
2797template <class _CharT, class _Traits, class _Allocator>
2798_LIBCPP_INLINE_VISIBILITY inline
2799basic_string<_CharT, _Traits, _Allocator>&
2800basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2801{
2802 return replace(__pos1, __n1, __str.data(), __str.size());
2803}
2804
2805template <class _CharT, class _Traits, class _Allocator>
2806basic_string<_CharT, _Traits, _Allocator>&
2807basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2808 size_type __pos2, size_type __n2)
2809{
2810 size_type __str_sz = __str.size();
2811 if (__pos2 > __str_sz)
2812 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002813 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002814}
2815
2816template <class _CharT, class _Traits, class _Allocator>
2817basic_string<_CharT, _Traits, _Allocator>&
2818basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const_pointer __s)
2819{
2820#ifdef _LIBCPP_DEBUG
2821 assert(__s != 0);
2822#endif
2823 return replace(__pos, __n1, __s, traits_type::length(__s));
2824}
2825
2826template <class _CharT, class _Traits, class _Allocator>
2827_LIBCPP_INLINE_VISIBILITY inline
2828basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002829basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002830{
2831 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2832 __str.data(), __str.size());
2833}
2834
2835template <class _CharT, class _Traits, class _Allocator>
2836_LIBCPP_INLINE_VISIBILITY inline
2837basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002838basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const_pointer __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002839{
2840 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2841}
2842
2843template <class _CharT, class _Traits, class _Allocator>
2844_LIBCPP_INLINE_VISIBILITY inline
2845basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002846basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const_pointer __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002847{
2848 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2849}
2850
2851template <class _CharT, class _Traits, class _Allocator>
2852_LIBCPP_INLINE_VISIBILITY inline
2853basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002854basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002855{
2856 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2857}
2858
2859// erase
2860
2861template <class _CharT, class _Traits, class _Allocator>
2862basic_string<_CharT, _Traits, _Allocator>&
2863basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2864{
2865 size_type __sz = size();
2866 if (__pos > __sz)
2867 this->__throw_out_of_range();
2868 if (__n)
2869 {
2870 pointer __p = __get_pointer();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002871 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002872 size_type __n_move = __sz - __pos - __n;
2873 if (__n_move != 0)
2874 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2875 __sz -= __n;
2876 __set_size(__sz);
2877 __invalidate_iterators_past(__sz);
2878 traits_type::assign(__p[__sz], value_type());
2879 }
2880 return *this;
2881}
2882
2883template <class _CharT, class _Traits, class _Allocator>
2884_LIBCPP_INLINE_VISIBILITY inline
2885typename basic_string<_CharT, _Traits, _Allocator>::iterator
2886basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2887{
2888 iterator __b = begin();
2889 size_type __r = static_cast<size_type>(__pos - __b);
2890 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002891 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002892}
2893
2894template <class _CharT, class _Traits, class _Allocator>
2895_LIBCPP_INLINE_VISIBILITY inline
2896typename basic_string<_CharT, _Traits, _Allocator>::iterator
2897basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2898{
2899 iterator __b = begin();
2900 size_type __r = static_cast<size_type>(__first - __b);
2901 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00002902 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002903}
2904
2905template <class _CharT, class _Traits, class _Allocator>
2906_LIBCPP_INLINE_VISIBILITY inline
2907void
2908basic_string<_CharT, _Traits, _Allocator>::pop_back()
2909{
2910#ifdef _LIBCPP_DEBUG
2911 assert(!empty());
2912#endif
2913 size_type __sz;
2914 if (__is_long())
2915 {
2916 __sz = __get_long_size() - 1;
2917 __set_long_size(__sz);
2918 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2919 }
2920 else
2921 {
2922 __sz = __get_short_size() - 1;
2923 __set_short_size(__sz);
2924 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2925 }
2926 __invalidate_iterators_past(__sz);
2927}
2928
2929template <class _CharT, class _Traits, class _Allocator>
2930_LIBCPP_INLINE_VISIBILITY inline
2931void
Howard Hinnanta6119a82011-05-29 19:57:12 +00002932basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002933{
2934 __invalidate_all_iterators();
2935 if (__is_long())
2936 {
2937 traits_type::assign(*__get_long_pointer(), value_type());
2938 __set_long_size(0);
2939 }
2940 else
2941 {
2942 traits_type::assign(*__get_short_pointer(), value_type());
2943 __set_short_size(0);
2944 }
2945}
2946
2947template <class _CharT, class _Traits, class _Allocator>
2948_LIBCPP_INLINE_VISIBILITY inline
2949void
2950basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2951{
2952 if (__is_long())
2953 {
2954 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2955 __set_long_size(__pos);
2956 }
2957 else
2958 {
2959 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2960 __set_short_size(__pos);
2961 }
2962 __invalidate_iterators_past(__pos);
2963}
2964
2965template <class _CharT, class _Traits, class _Allocator>
2966void
2967basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2968{
2969 size_type __sz = size();
2970 if (__n > __sz)
2971 append(__n - __sz, __c);
2972 else
2973 __erase_to_end(__n);
2974}
2975
2976template <class _CharT, class _Traits, class _Allocator>
2977_LIBCPP_INLINE_VISIBILITY inline
2978typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002979basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002980{
Howard Hinnante32b5e22010-11-17 17:55:08 +00002981 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002982#if _LIBCPP_BIG_ENDIAN
2983 return (__m <= ~__long_mask ? __m : __m/2) - 1;
2984#else
2985 return __m - 1;
2986#endif
2987}
2988
2989template <class _CharT, class _Traits, class _Allocator>
2990void
2991basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2992{
2993 if (__res_arg > max_size())
2994 this->__throw_length_error();
2995 size_type __cap = capacity();
2996 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002997 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002998 __res_arg = __recommend(__res_arg);
2999 if (__res_arg != __cap)
3000 {
3001 pointer __new_data, __p;
3002 bool __was_long, __now_long;
3003 if (__res_arg == __min_cap - 1)
3004 {
3005 __was_long = true;
3006 __now_long = false;
3007 __new_data = __get_short_pointer();
3008 __p = __get_long_pointer();
3009 }
3010 else
3011 {
3012 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003013 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003014 else
3015 {
3016 #ifndef _LIBCPP_NO_EXCEPTIONS
3017 try
3018 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003019 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00003020 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003021 #ifndef _LIBCPP_NO_EXCEPTIONS
3022 }
3023 catch (...)
3024 {
3025 return;
3026 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003027 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003028 if (__new_data == 0)
3029 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003030 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003031 }
3032 __now_long = true;
3033 __was_long = __is_long();
3034 __p = __get_pointer();
3035 }
3036 traits_type::copy(__new_data, __p, size()+1);
3037 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003038 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003039 if (__now_long)
3040 {
3041 __set_long_cap(__res_arg+1);
3042 __set_long_size(__sz);
3043 __set_long_pointer(__new_data);
3044 }
3045 else
3046 __set_short_size(__sz);
3047 __invalidate_all_iterators();
3048 }
3049}
3050
3051template <class _CharT, class _Traits, class _Allocator>
3052_LIBCPP_INLINE_VISIBILITY inline
3053typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3054basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
3055{
3056#ifdef __LIBCPP_DEBUG
3057 assert(__pos <= size());
3058#endif
3059 return *(data() + __pos);
3060}
3061
3062template <class _CharT, class _Traits, class _Allocator>
3063_LIBCPP_INLINE_VISIBILITY inline
3064typename basic_string<_CharT, _Traits, _Allocator>::reference
3065basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
3066{
3067#ifdef __LIBCPP_DEBUG
3068 assert(__pos < size());
3069#endif
3070 return *(__get_pointer() + __pos);
3071}
3072
3073template <class _CharT, class _Traits, class _Allocator>
3074typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3075basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3076{
3077 if (__n >= size())
3078 this->__throw_out_of_range();
3079 return (*this)[__n];
3080}
3081
3082template <class _CharT, class _Traits, class _Allocator>
3083typename basic_string<_CharT, _Traits, _Allocator>::reference
3084basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3085{
3086 if (__n >= size())
3087 this->__throw_out_of_range();
3088 return (*this)[__n];
3089}
3090
3091template <class _CharT, class _Traits, class _Allocator>
3092_LIBCPP_INLINE_VISIBILITY inline
3093typename basic_string<_CharT, _Traits, _Allocator>::reference
3094basic_string<_CharT, _Traits, _Allocator>::front()
3095{
3096#ifdef _LIBCPP_DEBUG
3097 assert(!empty());
3098#endif
3099 return *__get_pointer();
3100}
3101
3102template <class _CharT, class _Traits, class _Allocator>
3103_LIBCPP_INLINE_VISIBILITY inline
3104typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3105basic_string<_CharT, _Traits, _Allocator>::front() const
3106{
3107#ifdef _LIBCPP_DEBUG
3108 assert(!empty());
3109#endif
3110 return *data();
3111}
3112
3113template <class _CharT, class _Traits, class _Allocator>
3114_LIBCPP_INLINE_VISIBILITY inline
3115typename basic_string<_CharT, _Traits, _Allocator>::reference
3116basic_string<_CharT, _Traits, _Allocator>::back()
3117{
3118#ifdef _LIBCPP_DEBUG
3119 assert(!empty());
3120#endif
3121 return *(__get_pointer() + size() - 1);
3122}
3123
3124template <class _CharT, class _Traits, class _Allocator>
3125_LIBCPP_INLINE_VISIBILITY inline
3126typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3127basic_string<_CharT, _Traits, _Allocator>::back() const
3128{
3129#ifdef _LIBCPP_DEBUG
3130 assert(!empty());
3131#endif
3132 return *(data() + size() - 1);
3133}
3134
3135template <class _CharT, class _Traits, class _Allocator>
3136typename basic_string<_CharT, _Traits, _Allocator>::size_type
3137basic_string<_CharT, _Traits, _Allocator>::copy(pointer __s, size_type __n, size_type __pos) const
3138{
3139 size_type __sz = size();
3140 if (__pos > __sz)
3141 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003142 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003143 traits_type::copy(__s, data() + __pos, __rlen);
3144 return __rlen;
3145}
3146
3147template <class _CharT, class _Traits, class _Allocator>
3148_LIBCPP_INLINE_VISIBILITY inline
3149basic_string<_CharT, _Traits, _Allocator>
3150basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3151{
3152 return basic_string(*this, __pos, __n, __alloc());
3153}
3154
3155template <class _CharT, class _Traits, class _Allocator>
3156_LIBCPP_INLINE_VISIBILITY inline
3157void
3158basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003159 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3160 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003161{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003162 _VSTD::swap(__r_.first(), __str.__r_.first());
Howard Hinnante32b5e22010-11-17 17:55:08 +00003163 __swap_alloc(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003164#ifdef _LIBCPP_DEBUG
3165 __invalidate_all_iterators();
3166 __str.__invalidate_all_iterators();
Howard Hinnant324bb032010-08-22 00:02:43 +00003167#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003168}
3169
3170// find
3171
3172template <class _Traits>
3173struct _LIBCPP_HIDDEN __traits_eq
3174{
3175 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003176 _LIBCPP_INLINE_VISIBILITY
3177 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3178 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003179};
3180
3181template<class _CharT, class _Traits, class _Allocator>
3182typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003183basic_string<_CharT, _Traits, _Allocator>::find(const_pointer __s,
3184 size_type __pos,
3185 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003186{
3187#ifdef _LIBCPP_DEBUG
3188 assert(__s != 0);
3189#endif
3190 size_type __sz = size();
3191 if (__pos > __sz || __sz - __pos < __n)
3192 return npos;
3193 if (__n == 0)
3194 return __pos;
3195 const_pointer __p = data();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003196 const_pointer __r = _VSTD::search(__p + __pos, __p + __sz, __s, __s + __n,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003197 __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003198 if (__r == __p + __sz)
3199 return npos;
3200 return static_cast<size_type>(__r - __p);
3201}
3202
3203template<class _CharT, class _Traits, class _Allocator>
3204_LIBCPP_INLINE_VISIBILITY inline
3205typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003206basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3207 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003208{
3209 return find(__str.data(), __pos, __str.size());
3210}
3211
3212template<class _CharT, class _Traits, class _Allocator>
3213_LIBCPP_INLINE_VISIBILITY inline
3214typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003215basic_string<_CharT, _Traits, _Allocator>::find(const_pointer __s,
3216 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003217{
3218#ifdef _LIBCPP_DEBUG
3219 assert(__s != 0);
3220#endif
3221 return find(__s, __pos, traits_type::length(__s));
3222}
3223
3224template<class _CharT, class _Traits, class _Allocator>
3225typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003226basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3227 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003228{
3229 size_type __sz = size();
3230 if (__pos >= __sz)
3231 return npos;
3232 const_pointer __p = data();
3233 const_pointer __r = traits_type::find(__p + __pos, __sz - __pos, __c);
3234 if (__r == 0)
3235 return npos;
3236 return static_cast<size_type>(__r - __p);
3237}
3238
3239// rfind
3240
3241template<class _CharT, class _Traits, class _Allocator>
3242typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003243basic_string<_CharT, _Traits, _Allocator>::rfind(const_pointer __s,
3244 size_type __pos,
3245 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003246{
3247#ifdef _LIBCPP_DEBUG
3248 assert(__s != 0);
3249#endif
3250 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003251 __pos = _VSTD::min(__pos, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003252 if (__n < __sz - __pos)
3253 __pos += __n;
3254 else
3255 __pos = __sz;
3256 const_pointer __p = data();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003257 const_pointer __r = _VSTD::find_end(__p, __p + __pos, __s, __s + __n,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003258 __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003259 if (__n > 0 && __r == __p + __pos)
3260 return npos;
3261 return static_cast<size_type>(__r - __p);
3262}
3263
3264template<class _CharT, class _Traits, class _Allocator>
3265_LIBCPP_INLINE_VISIBILITY inline
3266typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003267basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3268 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003269{
3270 return rfind(__str.data(), __pos, __str.size());
3271}
3272
3273template<class _CharT, class _Traits, class _Allocator>
3274_LIBCPP_INLINE_VISIBILITY inline
3275typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003276basic_string<_CharT, _Traits, _Allocator>::rfind(const_pointer __s,
3277 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003278{
3279#ifdef _LIBCPP_DEBUG
3280 assert(__s != 0);
3281#endif
3282 return rfind(__s, __pos, traits_type::length(__s));
3283}
3284
3285template<class _CharT, class _Traits, class _Allocator>
3286typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003287basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3288 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003289{
3290 size_type __sz = size();
3291 if (__sz)
3292 {
3293 if (__pos < __sz)
3294 ++__pos;
3295 else
3296 __pos = __sz;
3297 const_pointer __p = data();
3298 for (const_pointer __ps = __p + __pos; __ps != __p;)
3299 {
3300 if (traits_type::eq(*--__ps, __c))
3301 return static_cast<size_type>(__ps - __p);
3302 }
3303 }
3304 return npos;
3305}
3306
3307// find_first_of
3308
3309template<class _CharT, class _Traits, class _Allocator>
3310typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003311basic_string<_CharT, _Traits, _Allocator>::find_first_of(const_pointer __s,
3312 size_type __pos,
3313 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003314{
3315#ifdef _LIBCPP_DEBUG
3316 assert(__s != 0);
3317#endif
3318 size_type __sz = size();
3319 if (__pos >= __sz || __n == 0)
3320 return npos;
3321 const_pointer __p = data();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003322 const_pointer __r = _VSTD::find_first_of(__p + __pos, __p + __sz, __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003323 __s + __n, __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003324 if (__r == __p + __sz)
3325 return npos;
3326 return static_cast<size_type>(__r - __p);
3327}
3328
3329template<class _CharT, class _Traits, class _Allocator>
3330_LIBCPP_INLINE_VISIBILITY inline
3331typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003332basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3333 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003334{
3335 return find_first_of(__str.data(), __pos, __str.size());
3336}
3337
3338template<class _CharT, class _Traits, class _Allocator>
3339_LIBCPP_INLINE_VISIBILITY inline
3340typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003341basic_string<_CharT, _Traits, _Allocator>::find_first_of(const_pointer __s,
3342 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003343{
3344#ifdef _LIBCPP_DEBUG
3345 assert(__s != 0);
3346#endif
3347 return find_first_of(__s, __pos, traits_type::length(__s));
3348}
3349
3350template<class _CharT, class _Traits, class _Allocator>
3351_LIBCPP_INLINE_VISIBILITY inline
3352typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003353basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3354 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003355{
3356 return find(__c, __pos);
3357}
3358
3359// find_last_of
3360
3361template<class _CharT, class _Traits, class _Allocator>
3362typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003363basic_string<_CharT, _Traits, _Allocator>::find_last_of(const_pointer __s,
3364 size_type __pos,
3365 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003366{
3367#ifdef _LIBCPP_DEBUG
3368 assert(__s != 0);
3369#endif
3370 if (__n != 0)
3371 {
3372 size_type __sz = size();
3373 if (__pos < __sz)
3374 ++__pos;
3375 else
3376 __pos = __sz;
3377 const_pointer __p = data();
3378 for (const_pointer __ps = __p + __pos; __ps != __p;)
3379 {
3380 const_pointer __r = traits_type::find(__s, __n, *--__ps);
3381 if (__r)
3382 return static_cast<size_type>(__ps - __p);
3383 }
3384 }
3385 return npos;
3386}
3387
3388template<class _CharT, class _Traits, class _Allocator>
3389_LIBCPP_INLINE_VISIBILITY inline
3390typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003391basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3392 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003393{
3394 return find_last_of(__str.data(), __pos, __str.size());
3395}
3396
3397template<class _CharT, class _Traits, class _Allocator>
3398_LIBCPP_INLINE_VISIBILITY inline
3399typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003400basic_string<_CharT, _Traits, _Allocator>::find_last_of(const_pointer __s,
3401 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003402{
3403#ifdef _LIBCPP_DEBUG
3404 assert(__s != 0);
3405#endif
3406 return find_last_of(__s, __pos, traits_type::length(__s));
3407}
3408
3409template<class _CharT, class _Traits, class _Allocator>
3410_LIBCPP_INLINE_VISIBILITY inline
3411typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003412basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3413 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003414{
3415 return rfind(__c, __pos);
3416}
3417
3418// find_first_not_of
3419
3420template<class _CharT, class _Traits, class _Allocator>
3421typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003422basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const_pointer __s,
3423 size_type __pos,
3424 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003425{
3426#ifdef _LIBCPP_DEBUG
3427 assert(__s != 0);
3428#endif
3429 size_type __sz = size();
3430 if (__pos < __sz)
3431 {
3432 const_pointer __p = data();
3433 const_pointer __pe = __p + __sz;
3434 for (const_pointer __ps = __p + __pos; __ps != __pe; ++__ps)
3435 if (traits_type::find(__s, __n, *__ps) == 0)
3436 return static_cast<size_type>(__ps - __p);
3437 }
3438 return npos;
3439}
3440
3441template<class _CharT, class _Traits, class _Allocator>
3442_LIBCPP_INLINE_VISIBILITY inline
3443typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003444basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3445 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003446{
3447 return find_first_not_of(__str.data(), __pos, __str.size());
3448}
3449
3450template<class _CharT, class _Traits, class _Allocator>
3451_LIBCPP_INLINE_VISIBILITY inline
3452typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003453basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const_pointer __s,
3454 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003455{
3456#ifdef _LIBCPP_DEBUG
3457 assert(__s != 0);
3458#endif
3459 return find_first_not_of(__s, __pos, traits_type::length(__s));
3460}
3461
3462template<class _CharT, class _Traits, class _Allocator>
3463_LIBCPP_INLINE_VISIBILITY inline
3464typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003465basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3466 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003467{
3468 size_type __sz = size();
3469 if (__pos < __sz)
3470 {
3471 const_pointer __p = data();
3472 const_pointer __pe = __p + __sz;
Howard Hinnant352bd3a2012-12-31 20:09:48 +00003473 for (const_pointer __ps = __p + __pos; __ps != __pe; ++__ps)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003474 if (!traits_type::eq(*__ps, __c))
3475 return static_cast<size_type>(__ps - __p);
3476 }
3477 return npos;
3478}
3479
3480// find_last_not_of
3481
3482template<class _CharT, class _Traits, class _Allocator>
3483typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003484basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const_pointer __s,
3485 size_type __pos,
3486 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003487{
3488#ifdef _LIBCPP_DEBUG
3489 assert(__s != 0);
3490#endif
3491 size_type __sz = size();
3492 if (__pos < __sz)
3493 ++__pos;
3494 else
3495 __pos = __sz;
3496 const_pointer __p = data();
3497 for (const_pointer __ps = __p + __pos; __ps != __p;)
3498 if (traits_type::find(__s, __n, *--__ps) == 0)
3499 return static_cast<size_type>(__ps - __p);
3500 return npos;
3501}
3502
3503template<class _CharT, class _Traits, class _Allocator>
3504_LIBCPP_INLINE_VISIBILITY inline
3505typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003506basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3507 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003508{
3509 return find_last_not_of(__str.data(), __pos, __str.size());
3510}
3511
3512template<class _CharT, class _Traits, class _Allocator>
3513_LIBCPP_INLINE_VISIBILITY inline
3514typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003515basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const_pointer __s,
3516 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003517{
3518#ifdef _LIBCPP_DEBUG
3519 assert(__s != 0);
3520#endif
3521 return find_last_not_of(__s, __pos, traits_type::length(__s));
3522}
3523
3524template<class _CharT, class _Traits, class _Allocator>
3525_LIBCPP_INLINE_VISIBILITY inline
3526typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003527basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3528 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003529{
3530 size_type __sz = size();
3531 if (__pos < __sz)
3532 ++__pos;
3533 else
3534 __pos = __sz;
3535 const_pointer __p = data();
3536 for (const_pointer __ps = __p + __pos; __ps != __p;)
3537 if (!traits_type::eq(*--__ps, __c))
3538 return static_cast<size_type>(__ps - __p);
3539 return npos;
3540}
3541
3542// compare
3543
3544template <class _CharT, class _Traits, class _Allocator>
3545_LIBCPP_INLINE_VISIBILITY inline
3546int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003547basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003548{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003549 size_t __lhs_sz = size();
3550 size_t __rhs_sz = __str.size();
3551 int __result = traits_type::compare(data(), __str.data(),
3552 _VSTD::min(__lhs_sz, __rhs_sz));
3553 if (__result != 0)
3554 return __result;
3555 if (__lhs_sz < __rhs_sz)
3556 return -1;
3557 if (__lhs_sz > __rhs_sz)
3558 return 1;
3559 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003560}
3561
3562template <class _CharT, class _Traits, class _Allocator>
3563_LIBCPP_INLINE_VISIBILITY inline
3564int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003565basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3566 size_type __n1,
3567 const basic_string& __str) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003568{
3569 return compare(__pos1, __n1, __str.data(), __str.size());
3570}
3571
3572template <class _CharT, class _Traits, class _Allocator>
3573int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003574basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3575 size_type __n1,
3576 const basic_string& __str,
3577 size_type __pos2,
3578 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003579{
3580 size_type __sz = __str.size();
3581 if (__pos2 > __sz)
3582 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003583 return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003584 __sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003585}
3586
3587template <class _CharT, class _Traits, class _Allocator>
3588int
Howard Hinnantec3773c2011-12-01 20:21:04 +00003589basic_string<_CharT, _Traits, _Allocator>::compare(const_pointer __s) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003590{
3591#ifdef _LIBCPP_DEBUG
3592 assert(__s != 0);
3593#endif
3594 return compare(0, npos, __s, traits_type::length(__s));
3595}
3596
3597template <class _CharT, class _Traits, class _Allocator>
3598int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003599basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3600 size_type __n1,
3601 const_pointer __s) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003602{
3603#ifdef _LIBCPP_DEBUG
3604 assert(__s != 0);
3605#endif
3606 return compare(__pos1, __n1, __s, traits_type::length(__s));
3607}
3608
3609template <class _CharT, class _Traits, class _Allocator>
3610int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003611basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3612 size_type __n1,
3613 const_pointer __s,
3614 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003615{
3616#ifdef _LIBCPP_DEBUG
3617 assert(__s != 0);
3618#endif
3619 size_type __sz = size();
3620 if (__pos1 > __sz || __n2 == npos)
3621 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003622 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3623 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003624 if (__r == 0)
3625 {
3626 if (__rlen < __n2)
3627 __r = -1;
3628 else if (__rlen > __n2)
3629 __r = 1;
3630 }
3631 return __r;
3632}
3633
3634// __invariants
3635
3636template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00003637_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003638bool
3639basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3640{
3641 if (size() > capacity())
3642 return false;
3643 if (capacity() < __min_cap - 1)
3644 return false;
3645 if (data() == 0)
3646 return false;
3647 if (data()[size()] != value_type(0))
3648 return false;
3649 return true;
3650}
3651
3652// operator==
3653
3654template<class _CharT, class _Traits, class _Allocator>
3655_LIBCPP_INLINE_VISIBILITY inline
3656bool
3657operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003658 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003659{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003660 size_t __lhs_sz = __lhs.size();
3661 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3662 __rhs.data(),
3663 __lhs_sz) == 0;
3664}
3665
3666template<class _Allocator>
3667_LIBCPP_INLINE_VISIBILITY inline
3668bool
3669operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3670 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3671{
3672 size_t __lhs_sz = __lhs.size();
3673 if (__lhs_sz != __rhs.size())
3674 return false;
3675 const char* __lp = __lhs.data();
3676 const char* __rp = __rhs.data();
3677 if (__lhs.__is_long())
3678 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3679 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3680 if (*__lp != *__rp)
3681 return false;
3682 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003683}
3684
3685template<class _CharT, class _Traits, class _Allocator>
3686_LIBCPP_INLINE_VISIBILITY inline
3687bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003688operator==(const _CharT* __lhs,
3689 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003690{
3691 return __rhs.compare(__lhs) == 0;
3692}
3693
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003694template<class _CharT, class _Traits, class _Allocator>
3695_LIBCPP_INLINE_VISIBILITY inline
3696bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003697operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3698 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003699{
3700 return __lhs.compare(__rhs) == 0;
3701}
3702
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003703// operator!=
3704
Howard Hinnant324bb032010-08-22 00:02:43 +00003705template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003706_LIBCPP_INLINE_VISIBILITY inline
3707bool
3708operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003709 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003710{
3711 return !(__lhs == __rhs);
3712}
3713
3714template<class _CharT, class _Traits, class _Allocator>
3715_LIBCPP_INLINE_VISIBILITY inline
3716bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003717operator!=(const _CharT* __lhs,
3718 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003719{
3720 return !(__lhs == __rhs);
3721}
3722
3723template<class _CharT, class _Traits, class _Allocator>
3724_LIBCPP_INLINE_VISIBILITY inline
3725bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003726operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3727 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003728{
3729 return !(__lhs == __rhs);
3730}
3731
3732// operator<
3733
3734template<class _CharT, class _Traits, class _Allocator>
3735_LIBCPP_INLINE_VISIBILITY inline
3736bool
3737operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003738 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003739{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003740 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003741}
3742
3743template<class _CharT, class _Traits, class _Allocator>
3744_LIBCPP_INLINE_VISIBILITY inline
3745bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003746operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3747 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003748{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003749 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003750}
3751
3752template<class _CharT, class _Traits, class _Allocator>
3753_LIBCPP_INLINE_VISIBILITY inline
3754bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003755operator< (const _CharT* __lhs,
3756 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003757{
3758 return __rhs.compare(__lhs) > 0;
3759}
3760
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003761// operator>
3762
3763template<class _CharT, class _Traits, class _Allocator>
3764_LIBCPP_INLINE_VISIBILITY inline
3765bool
3766operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003767 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003768{
3769 return __rhs < __lhs;
3770}
3771
3772template<class _CharT, class _Traits, class _Allocator>
3773_LIBCPP_INLINE_VISIBILITY inline
3774bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003775operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3776 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003777{
3778 return __rhs < __lhs;
3779}
3780
3781template<class _CharT, class _Traits, class _Allocator>
3782_LIBCPP_INLINE_VISIBILITY inline
3783bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003784operator> (const _CharT* __lhs,
3785 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003786{
3787 return __rhs < __lhs;
3788}
3789
3790// operator<=
3791
3792template<class _CharT, class _Traits, class _Allocator>
3793_LIBCPP_INLINE_VISIBILITY inline
3794bool
3795operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003796 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003797{
3798 return !(__rhs < __lhs);
3799}
3800
3801template<class _CharT, class _Traits, class _Allocator>
3802_LIBCPP_INLINE_VISIBILITY inline
3803bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003804operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3805 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003806{
3807 return !(__rhs < __lhs);
3808}
3809
3810template<class _CharT, class _Traits, class _Allocator>
3811_LIBCPP_INLINE_VISIBILITY inline
3812bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003813operator<=(const _CharT* __lhs,
3814 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003815{
3816 return !(__rhs < __lhs);
3817}
3818
3819// operator>=
3820
3821template<class _CharT, class _Traits, class _Allocator>
3822_LIBCPP_INLINE_VISIBILITY inline
3823bool
3824operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003825 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003826{
3827 return !(__lhs < __rhs);
3828}
3829
3830template<class _CharT, class _Traits, class _Allocator>
3831_LIBCPP_INLINE_VISIBILITY inline
3832bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003833operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3834 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003835{
3836 return !(__lhs < __rhs);
3837}
3838
3839template<class _CharT, class _Traits, class _Allocator>
3840_LIBCPP_INLINE_VISIBILITY inline
3841bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003842operator>=(const _CharT* __lhs,
3843 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003844{
3845 return !(__lhs < __rhs);
3846}
3847
3848// operator +
3849
3850template<class _CharT, class _Traits, class _Allocator>
3851basic_string<_CharT, _Traits, _Allocator>
3852operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3853 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3854{
3855 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3856 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3857 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3858 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3859 __r.append(__rhs.data(), __rhs_sz);
3860 return __r;
3861}
3862
3863template<class _CharT, class _Traits, class _Allocator>
3864basic_string<_CharT, _Traits, _Allocator>
3865operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3866{
3867 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3868 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3869 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3870 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3871 __r.append(__rhs.data(), __rhs_sz);
3872 return __r;
3873}
3874
3875template<class _CharT, class _Traits, class _Allocator>
3876basic_string<_CharT, _Traits, _Allocator>
3877operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3878{
3879 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3880 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3881 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3882 __r.append(__rhs.data(), __rhs_sz);
3883 return __r;
3884}
3885
3886template<class _CharT, class _Traits, class _Allocator>
3887basic_string<_CharT, _Traits, _Allocator>
3888operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3889{
3890 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3891 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3892 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3893 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3894 __r.append(__rhs, __rhs_sz);
3895 return __r;
3896}
3897
3898template<class _CharT, class _Traits, class _Allocator>
3899basic_string<_CharT, _Traits, _Allocator>
3900operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3901{
3902 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3903 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3904 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3905 __r.push_back(__rhs);
3906 return __r;
3907}
3908
Howard Hinnant73d21a42010-09-04 23:28:19 +00003909#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003910
3911template<class _CharT, class _Traits, class _Allocator>
3912_LIBCPP_INLINE_VISIBILITY inline
3913basic_string<_CharT, _Traits, _Allocator>
3914operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3915{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003916 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003917}
3918
3919template<class _CharT, class _Traits, class _Allocator>
3920_LIBCPP_INLINE_VISIBILITY inline
3921basic_string<_CharT, _Traits, _Allocator>
3922operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3923{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003924 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003925}
3926
3927template<class _CharT, class _Traits, class _Allocator>
3928_LIBCPP_INLINE_VISIBILITY inline
3929basic_string<_CharT, _Traits, _Allocator>
3930operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3931{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003932 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003933}
3934
3935template<class _CharT, class _Traits, class _Allocator>
3936_LIBCPP_INLINE_VISIBILITY inline
3937basic_string<_CharT, _Traits, _Allocator>
3938operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3939{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003940 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003941}
3942
3943template<class _CharT, class _Traits, class _Allocator>
3944_LIBCPP_INLINE_VISIBILITY inline
3945basic_string<_CharT, _Traits, _Allocator>
3946operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3947{
3948 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003949 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003950}
3951
3952template<class _CharT, class _Traits, class _Allocator>
3953_LIBCPP_INLINE_VISIBILITY inline
3954basic_string<_CharT, _Traits, _Allocator>
3955operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3956{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003957 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003958}
3959
3960template<class _CharT, class _Traits, class _Allocator>
3961_LIBCPP_INLINE_VISIBILITY inline
3962basic_string<_CharT, _Traits, _Allocator>
3963operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3964{
3965 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003966 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003967}
3968
Howard Hinnant73d21a42010-09-04 23:28:19 +00003969#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003970
3971// swap
3972
3973template<class _CharT, class _Traits, class _Allocator>
3974_LIBCPP_INLINE_VISIBILITY inline
3975void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003976swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003977 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3978 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003979{
3980 __lhs.swap(__rhs);
3981}
3982
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003983#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3984
3985typedef basic_string<char16_t> u16string;
3986typedef basic_string<char32_t> u32string;
3987
Howard Hinnant324bb032010-08-22 00:02:43 +00003988#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003989
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003990int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3991long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3992unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3993long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
3994unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
3995
3996float stof (const string& __str, size_t* __idx = 0);
3997double stod (const string& __str, size_t* __idx = 0);
3998long double stold(const string& __str, size_t* __idx = 0);
3999
4000string to_string(int __val);
4001string to_string(unsigned __val);
4002string to_string(long __val);
4003string to_string(unsigned long __val);
4004string to_string(long long __val);
4005string to_string(unsigned long long __val);
4006string to_string(float __val);
4007string to_string(double __val);
4008string to_string(long double __val);
4009
4010int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4011long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4012unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4013long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4014unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
4015
4016float stof (const wstring& __str, size_t* __idx = 0);
4017double stod (const wstring& __str, size_t* __idx = 0);
4018long double stold(const wstring& __str, size_t* __idx = 0);
4019
4020wstring to_wstring(int __val);
4021wstring to_wstring(unsigned __val);
4022wstring to_wstring(long __val);
4023wstring to_wstring(unsigned long __val);
4024wstring to_wstring(long long __val);
4025wstring to_wstring(unsigned long long __val);
4026wstring to_wstring(float __val);
4027wstring to_wstring(double __val);
4028wstring to_wstring(long double __val);
4029
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004030template<class _CharT, class _Traits, class _Allocator>
4031 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4032 basic_string<_CharT, _Traits, _Allocator>::npos;
4033
Sean Huntaffd9e52011-07-29 23:31:56 +00004034template<class _Ptr>
4035size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
4036{
Howard Hinnant40c13d32011-12-05 00:08:45 +00004037 typedef typename iterator_traits<_Ptr>::value_type value_type;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00004038 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
Sean Huntaffd9e52011-07-29 23:31:56 +00004039}
4040
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004041template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant83eade62013-03-06 23:30:19 +00004042struct _LIBCPP_TYPE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004043 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4044{
4045 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004046 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004047};
4048
4049template<class _CharT, class _Traits, class _Allocator>
4050size_t
4051hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004052 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004053{
Sean Huntaffd9e52011-07-29 23:31:56 +00004054 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004055}
4056
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004057template<class _CharT, class _Traits, class _Allocator>
4058basic_ostream<_CharT, _Traits>&
4059operator<<(basic_ostream<_CharT, _Traits>& __os,
4060 const basic_string<_CharT, _Traits, _Allocator>& __str);
4061
4062template<class _CharT, class _Traits, class _Allocator>
4063basic_istream<_CharT, _Traits>&
4064operator>>(basic_istream<_CharT, _Traits>& __is,
4065 basic_string<_CharT, _Traits, _Allocator>& __str);
4066
4067template<class _CharT, class _Traits, class _Allocator>
4068basic_istream<_CharT, _Traits>&
4069getline(basic_istream<_CharT, _Traits>& __is,
4070 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4071
4072template<class _CharT, class _Traits, class _Allocator>
4073inline _LIBCPP_INLINE_VISIBILITY
4074basic_istream<_CharT, _Traits>&
4075getline(basic_istream<_CharT, _Traits>& __is,
4076 basic_string<_CharT, _Traits, _Allocator>& __str);
4077
4078#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4079
4080template<class _CharT, class _Traits, class _Allocator>
4081inline _LIBCPP_INLINE_VISIBILITY
4082basic_istream<_CharT, _Traits>&
4083getline(basic_istream<_CharT, _Traits>&& __is,
4084 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4085
4086template<class _CharT, class _Traits, class _Allocator>
4087inline _LIBCPP_INLINE_VISIBILITY
4088basic_istream<_CharT, _Traits>&
4089getline(basic_istream<_CharT, _Traits>&& __is,
4090 basic_string<_CharT, _Traits, _Allocator>& __str);
4091
4092#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4093
Howard Hinnantff926772012-11-06 21:08:48 +00004094_LIBCPP_EXTERN_TEMPLATE(class basic_string<char>)
4095_LIBCPP_EXTERN_TEMPLATE(class basic_string<wchar_t>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004096
4097extern template
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004098 string
4099 operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
4100
4101_LIBCPP_END_NAMESPACE_STD
4102
4103#endif // _LIBCPP_STRING