blob: f05fe367cc0a368d2493d34ea354333746102113 [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;
54 static bool eq(char_type c1, char_type c2) noexcept;
55 static 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 Hinnanta6119a82011-05-29 19:57:12 +000064 static int_type not_eof(int_type c) noexcept;
65 static char_type to_char_type(int_type c) noexcept;
66 static int_type to_int_type(char_type c) noexcept;
67 static bool eq_int_type(int_type c1, int_type c2) noexcept;
68 static 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
449#pragma GCC system_header
450
451_LIBCPP_BEGIN_NAMESPACE_STD
452
453// fpos
454
455template <class _StateT>
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000456class _LIBCPP_VISIBLE fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000457{
458private:
459 _StateT __st_;
460 streamoff __off_;
461public:
462 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
463
464 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
465
466 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
467 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
468
469 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
470 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
471 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
472 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
473};
474
475template <class _StateT>
476inline _LIBCPP_INLINE_VISIBILITY
477streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
478 {return streamoff(__x) - streamoff(__y);}
479
480template <class _StateT>
481inline _LIBCPP_INLINE_VISIBILITY
482bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
483 {return streamoff(__x) == streamoff(__y);}
484
485template <class _StateT>
486inline _LIBCPP_INLINE_VISIBILITY
487bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
488 {return streamoff(__x) != streamoff(__y);}
489
490// char_traits
491
492template <class _CharT>
Howard Hinnant36cdf022010-09-10 16:42:26 +0000493struct _LIBCPP_VISIBLE char_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000494{
495 typedef _CharT char_type;
496 typedef int int_type;
497 typedef streamoff off_type;
498 typedef streampos pos_type;
499 typedef mbstate_t state_type;
500
Howard Hinnanta6119a82011-05-29 19:57:12 +0000501 _LIBCPP_INLINE_VISIBILITY
502 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
503 {__c1 = __c2;}
504 _LIBCPP_INLINE_VISIBILITY
505 static bool eq(char_type __c1, char_type __c2) _NOEXCEPT
506 {return __c1 == __c2;}
507 _LIBCPP_INLINE_VISIBILITY
508 static bool lt(char_type __c1, char_type __c2) _NOEXCEPT
509 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000510
511 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
512 static size_t length(const char_type* __s);
513 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
514 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
515 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
516 static char_type* assign(char_type* __s, size_t __n, char_type __a);
517
Howard Hinnanta6119a82011-05-29 19:57:12 +0000518 _LIBCPP_INLINE_VISIBILITY static int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000519 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000520 _LIBCPP_INLINE_VISIBILITY
521 static char_type to_char_type(int_type __c) _NOEXCEPT
522 {return char_type(__c);}
523 _LIBCPP_INLINE_VISIBILITY
524 static int_type to_int_type(char_type __c) _NOEXCEPT
525 {return int_type(__c);}
526 _LIBCPP_INLINE_VISIBILITY
527 static bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000529 _LIBCPP_INLINE_VISIBILITY
530 static int_type eof() _NOEXCEPT
531 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532};
533
534template <class _CharT>
535int
536char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
537{
538 for (; __n; --__n, ++__s1, ++__s2)
539 {
540 if (lt(*__s1, *__s2))
541 return -1;
542 if (lt(*__s2, *__s1))
543 return 1;
544 }
545 return 0;
546}
547
548template <class _CharT>
549inline _LIBCPP_INLINE_VISIBILITY
550size_t
551char_traits<_CharT>::length(const char_type* __s)
552{
553 size_t __len = 0;
554 for (; !eq(*__s, char_type(0)); ++__s)
555 ++__len;
556 return __len;
557}
558
559template <class _CharT>
560inline _LIBCPP_INLINE_VISIBILITY
561const _CharT*
562char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
563{
564 for (; __n; --__n)
565 {
566 if (eq(*__s, __a))
567 return __s;
568 ++__s;
569 }
570 return 0;
571}
572
573template <class _CharT>
574_CharT*
575char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
576{
577 char_type* __r = __s1;
578 if (__s1 < __s2)
579 {
580 for (; __n; --__n, ++__s1, ++__s2)
581 assign(*__s1, *__s2);
582 }
583 else if (__s2 < __s1)
584 {
585 __s1 += __n;
586 __s2 += __n;
587 for (; __n; --__n)
588 assign(*--__s1, *--__s2);
589 }
590 return __r;
591}
592
593template <class _CharT>
594inline _LIBCPP_INLINE_VISIBILITY
595_CharT*
596char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
597{
598 char_type* __r = __s1;
599 for (; __n; --__n, ++__s1, ++__s2)
600 assign(*__s1, *__s2);
601 return __r;
602}
603
604template <class _CharT>
605inline _LIBCPP_INLINE_VISIBILITY
606_CharT*
607char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
608{
609 char_type* __r = __s;
610 for (; __n; --__n, ++__s)
611 assign(*__s, __a);
612 return __r;
613}
614
615// char_traits<char>
616
617template <>
Howard Hinnant36cdf022010-09-10 16:42:26 +0000618struct _LIBCPP_VISIBLE char_traits<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619{
620 typedef char char_type;
621 typedef int int_type;
622 typedef streamoff off_type;
623 typedef streampos pos_type;
624 typedef mbstate_t state_type;
625
Howard Hinnanta6119a82011-05-29 19:57:12 +0000626 _LIBCPP_INLINE_VISIBILITY
627 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
628 {__c1 = __c2;}
629 _LIBCPP_INLINE_VISIBILITY
630 static bool eq(char_type __c1, char_type __c2) _NOEXCEPT
631 {return __c1 == __c2;}
632 _LIBCPP_INLINE_VISIBILITY
633 static bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000634 {return (unsigned char)__c1 < (unsigned char)__c2;}
635
Howard Hinnanta6119a82011-05-29 19:57:12 +0000636 _LIBCPP_INLINE_VISIBILITY
637 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000638 {return memcmp(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000639 _LIBCPP_INLINE_VISIBILITY
640 static size_t length(const char_type* __s) {return strlen(__s);}
641 _LIBCPP_INLINE_VISIBILITY
642 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643 {return (const char_type*)memchr(__s, to_int_type(__a), __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000644 _LIBCPP_INLINE_VISIBILITY
645 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000646 {return (char_type*)memmove(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000647 _LIBCPP_INLINE_VISIBILITY
648 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000649 {return (char_type*)memcpy(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000650 _LIBCPP_INLINE_VISIBILITY
651 static char_type* assign(char_type* __s, size_t __n, char_type __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000652 {return (char_type*)memset(__s, to_int_type(__a), __n);}
653
Howard Hinnanta6119a82011-05-29 19:57:12 +0000654 _LIBCPP_INLINE_VISIBILITY static int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000655 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000656 _LIBCPP_INLINE_VISIBILITY
657 static char_type to_char_type(int_type __c) _NOEXCEPT
658 {return char_type(__c);}
659 _LIBCPP_INLINE_VISIBILITY
660 static int_type to_int_type(char_type __c) _NOEXCEPT
661 {return int_type((unsigned char)__c);}
662 _LIBCPP_INLINE_VISIBILITY
663 static bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000664 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000665 _LIBCPP_INLINE_VISIBILITY
666 static int_type eof() _NOEXCEPT
667 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668};
669
670// char_traits<wchar_t>
671
672template <>
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000673struct _LIBCPP_VISIBLE char_traits<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000674{
675 typedef wchar_t char_type;
676 typedef wint_t int_type;
677 typedef streamoff off_type;
678 typedef streampos pos_type;
679 typedef mbstate_t state_type;
680
Howard Hinnanta6119a82011-05-29 19:57:12 +0000681 _LIBCPP_INLINE_VISIBILITY
682 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
683 {__c1 = __c2;}
684 _LIBCPP_INLINE_VISIBILITY
685 static bool eq(char_type __c1, char_type __c2) _NOEXCEPT
686 {return __c1 == __c2;}
687 _LIBCPP_INLINE_VISIBILITY
688 static bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689 {return __c1 < __c2;}
690
Howard Hinnanta6119a82011-05-29 19:57:12 +0000691 _LIBCPP_INLINE_VISIBILITY
692 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000693 {return wmemcmp(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000694 _LIBCPP_INLINE_VISIBILITY
695 static size_t length(const char_type* __s)
696 {return wcslen(__s);}
697 _LIBCPP_INLINE_VISIBILITY
698 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000699 {return (const char_type*)wmemchr(__s, __a, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000700 _LIBCPP_INLINE_VISIBILITY
701 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000702 {return (char_type*)wmemmove(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000703 _LIBCPP_INLINE_VISIBILITY
704 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705 {return (char_type*)wmemcpy(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000706 _LIBCPP_INLINE_VISIBILITY
707 static char_type* assign(char_type* __s, size_t __n, char_type __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708 {return (char_type*)wmemset(__s, __a, __n);}
709
Howard Hinnanta6119a82011-05-29 19:57:12 +0000710 _LIBCPP_INLINE_VISIBILITY
711 static int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000712 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000713 _LIBCPP_INLINE_VISIBILITY
714 static char_type to_char_type(int_type __c) _NOEXCEPT
715 {return char_type(__c);}
716 _LIBCPP_INLINE_VISIBILITY
717 static int_type to_int_type(char_type __c) _NOEXCEPT
718 {return int_type(__c);}
719 _LIBCPP_INLINE_VISIBILITY
720 static bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000721 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000722 _LIBCPP_INLINE_VISIBILITY
723 static int_type eof() _NOEXCEPT
724 {return int_type(WEOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000725};
726
727#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
728
729template <>
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000730struct _LIBCPP_VISIBLE char_traits<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000731{
732 typedef char16_t char_type;
733 typedef uint_least16_t int_type;
734 typedef streamoff off_type;
735 typedef u16streampos pos_type;
736 typedef mbstate_t state_type;
737
Howard Hinnanta6119a82011-05-29 19:57:12 +0000738 _LIBCPP_INLINE_VISIBILITY
739 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
740 {__c1 = __c2;}
741 _LIBCPP_INLINE_VISIBILITY
742 static bool eq(char_type __c1, char_type __c2) _NOEXCEPT
743 {return __c1 == __c2;}
744 _LIBCPP_INLINE_VISIBILITY
745 static bool lt(char_type __c1, char_type __c2) _NOEXCEPT
746 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747
748 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
749 static size_t length(const char_type* __s);
750 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
751 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
752 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
753 static char_type* assign(char_type* __s, size_t __n, char_type __a);
754
Howard Hinnanta6119a82011-05-29 19:57:12 +0000755 _LIBCPP_INLINE_VISIBILITY
756 static int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000757 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000758 _LIBCPP_INLINE_VISIBILITY
759 static char_type to_char_type(int_type __c) _NOEXCEPT
760 {return char_type(__c);}
761 _LIBCPP_INLINE_VISIBILITY
762 static int_type to_int_type(char_type __c) _NOEXCEPT
763 {return int_type(__c);}
764 _LIBCPP_INLINE_VISIBILITY
765 static bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000766 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000767 _LIBCPP_INLINE_VISIBILITY
768 static int_type eof() _NOEXCEPT
769 {return int_type(0xDFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000770};
771
772inline _LIBCPP_INLINE_VISIBILITY
773int
774char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
775{
776 for (; __n; --__n, ++__s1, ++__s2)
777 {
778 if (lt(*__s1, *__s2))
779 return -1;
780 if (lt(*__s2, *__s1))
781 return 1;
782 }
783 return 0;
784}
785
786inline _LIBCPP_INLINE_VISIBILITY
787size_t
788char_traits<char16_t>::length(const char_type* __s)
789{
790 size_t __len = 0;
791 for (; !eq(*__s, char_type(0)); ++__s)
792 ++__len;
793 return __len;
794}
795
796inline _LIBCPP_INLINE_VISIBILITY
797const char16_t*
798char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
799{
800 for (; __n; --__n)
801 {
802 if (eq(*__s, __a))
803 return __s;
804 ++__s;
805 }
806 return 0;
807}
808
809inline _LIBCPP_INLINE_VISIBILITY
810char16_t*
811char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
812{
813 char_type* __r = __s1;
814 if (__s1 < __s2)
815 {
816 for (; __n; --__n, ++__s1, ++__s2)
817 assign(*__s1, *__s2);
818 }
819 else if (__s2 < __s1)
820 {
821 __s1 += __n;
822 __s2 += __n;
823 for (; __n; --__n)
824 assign(*--__s1, *--__s2);
825 }
826 return __r;
827}
828
829inline _LIBCPP_INLINE_VISIBILITY
830char16_t*
831char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
832{
833 char_type* __r = __s1;
834 for (; __n; --__n, ++__s1, ++__s2)
835 assign(*__s1, *__s2);
836 return __r;
837}
838
839inline _LIBCPP_INLINE_VISIBILITY
840char16_t*
841char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
842{
843 char_type* __r = __s;
844 for (; __n; --__n, ++__s)
845 assign(*__s, __a);
846 return __r;
847}
848
849template <>
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000850struct _LIBCPP_VISIBLE char_traits<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000851{
852 typedef char32_t char_type;
853 typedef uint_least32_t int_type;
854 typedef streamoff off_type;
855 typedef u32streampos pos_type;
856 typedef mbstate_t state_type;
857
Howard Hinnanta6119a82011-05-29 19:57:12 +0000858 _LIBCPP_INLINE_VISIBILITY
859 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
860 {__c1 = __c2;}
861 _LIBCPP_INLINE_VISIBILITY
862 static bool eq(char_type __c1, char_type __c2) _NOEXCEPT
863 {return __c1 == __c2;}
864 _LIBCPP_INLINE_VISIBILITY
865 static bool lt(char_type __c1, char_type __c2) _NOEXCEPT
866 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000867
868 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
869 static size_t length(const char_type* __s);
870 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
871 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
872 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
873 static char_type* assign(char_type* __s, size_t __n, char_type __a);
874
Howard Hinnanta6119a82011-05-29 19:57:12 +0000875 _LIBCPP_INLINE_VISIBILITY
876 static int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000877 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000878 _LIBCPP_INLINE_VISIBILITY
879 static char_type to_char_type(int_type __c) _NOEXCEPT
880 {return char_type(__c);}
881 _LIBCPP_INLINE_VISIBILITY
882 static int_type to_int_type(char_type __c) _NOEXCEPT
883 {return int_type(__c);}
884 _LIBCPP_INLINE_VISIBILITY
885 static bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000886 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000887 _LIBCPP_INLINE_VISIBILITY
888 static int_type eof() _NOEXCEPT
889 {return int_type(0xFFFFFFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000890};
891
892inline _LIBCPP_INLINE_VISIBILITY
893int
894char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
895{
896 for (; __n; --__n, ++__s1, ++__s2)
897 {
898 if (lt(*__s1, *__s2))
899 return -1;
900 if (lt(*__s2, *__s1))
901 return 1;
902 }
903 return 0;
904}
905
906inline _LIBCPP_INLINE_VISIBILITY
907size_t
908char_traits<char32_t>::length(const char_type* __s)
909{
910 size_t __len = 0;
911 for (; !eq(*__s, char_type(0)); ++__s)
912 ++__len;
913 return __len;
914}
915
916inline _LIBCPP_INLINE_VISIBILITY
917const char32_t*
918char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
919{
920 for (; __n; --__n)
921 {
922 if (eq(*__s, __a))
923 return __s;
924 ++__s;
925 }
926 return 0;
927}
928
929inline _LIBCPP_INLINE_VISIBILITY
930char32_t*
931char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
932{
933 char_type* __r = __s1;
934 if (__s1 < __s2)
935 {
936 for (; __n; --__n, ++__s1, ++__s2)
937 assign(*__s1, *__s2);
938 }
939 else if (__s2 < __s1)
940 {
941 __s1 += __n;
942 __s2 += __n;
943 for (; __n; --__n)
944 assign(*--__s1, *--__s2);
945 }
946 return __r;
947}
948
949inline _LIBCPP_INLINE_VISIBILITY
950char32_t*
951char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
952{
953 char_type* __r = __s1;
954 for (; __n; --__n, ++__s1, ++__s2)
955 assign(*__s1, *__s2);
956 return __r;
957}
958
959inline _LIBCPP_INLINE_VISIBILITY
960char32_t*
961char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
962{
963 char_type* __r = __s;
964 for (; __n; --__n, ++__s)
965 assign(*__s, __a);
966 return __r;
967}
968
Howard Hinnant324bb032010-08-22 00:02:43 +0000969#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000970
971// basic_string
972
973template<class _CharT, class _Traits, class _Allocator>
974basic_string<_CharT, _Traits, _Allocator>
975operator+(const basic_string<_CharT, _Traits, _Allocator>&, const basic_string<_CharT, _Traits, _Allocator>&);
976
977template<class _CharT, class _Traits, class _Allocator>
978basic_string<_CharT, _Traits, _Allocator>
979operator+(const _CharT*, const basic_string<_CharT,_Traits,_Allocator>&);
980
981template<class _CharT, class _Traits, class _Allocator>
982basic_string<_CharT, _Traits, _Allocator>
983operator+(_CharT, const basic_string<_CharT,_Traits,_Allocator>&);
984
985template<class _CharT, class _Traits, class _Allocator>
986basic_string<_CharT, _Traits, _Allocator>
987operator+(const basic_string<_CharT, _Traits, _Allocator>&, const _CharT*);
988
989template<class _CharT, class _Traits, class _Allocator>
990basic_string<_CharT, _Traits, _Allocator>
991operator+(const basic_string<_CharT, _Traits, _Allocator>&, _CharT);
992
993template <bool>
994class __basic_string_common
995{
996protected:
997 void __throw_length_error() const;
998 void __throw_out_of_range() const;
999};
1000
1001template <bool __b>
1002void
1003__basic_string_common<__b>::__throw_length_error() const
1004{
1005#ifndef _LIBCPP_NO_EXCEPTIONS
1006 throw length_error("basic_string");
1007#else
1008 assert(!"basic_string length_error");
1009#endif
1010}
1011
1012template <bool __b>
1013void
1014__basic_string_common<__b>::__throw_out_of_range() const
1015{
1016#ifndef _LIBCPP_NO_EXCEPTIONS
1017 throw out_of_range("basic_string");
1018#else
1019 assert(!"basic_string out_of_range");
1020#endif
1021}
1022
1023extern template class __basic_string_common<true>;
1024
Howard Hinnant324bb032010-08-22 00:02:43 +00001025template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant36cdf022010-09-10 16:42:26 +00001026class _LIBCPP_VISIBLE basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001027 : private __basic_string_common<true>
1028{
1029public:
1030 typedef basic_string __self;
1031 typedef _Traits traits_type;
1032 typedef typename traits_type::char_type value_type;
1033 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001034 typedef allocator_traits<allocator_type> __alloc_traits;
1035 typedef typename __alloc_traits::size_type size_type;
1036 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001037 typedef value_type& reference;
1038 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001039 typedef typename __alloc_traits::pointer pointer;
1040 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001041#ifdef _LIBCPP_DEBUG
1042 typedef __debug_iter<basic_string, pointer> iterator;
1043 typedef __debug_iter<basic_string, const_pointer> const_iterator;
1044
1045 friend class __debug_iter<basic_string, pointer>;
1046 friend class __debug_iter<basic_string, const_pointer>;
1047#elif defined(_LIBCPP_RAW_ITERATORS)
1048 typedef pointer iterator;
1049 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001050#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001051 typedef __wrap_iter<pointer> iterator;
1052 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001053#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054 typedef _STD::reverse_iterator<iterator> reverse_iterator;
1055 typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator;
1056
1057private:
1058 struct __long
1059 {
1060 size_type __cap_;
1061 size_type __size_;
1062 pointer __data_;
1063 };
1064
1065#if _LIBCPP_BIG_ENDIAN
1066 enum {__short_mask = 0x80};
1067 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43 +00001068#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001069 enum {__short_mask = 0x01};
1070 enum {__long_mask = 0x1};
Howard Hinnant324bb032010-08-22 00:02:43 +00001071#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072
1073 enum {__mask = size_type(~0) >> 1};
1074
1075 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1076 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1077
1078 struct __short
1079 {
1080 union
1081 {
1082 unsigned char __size_;
1083 value_type _;
1084 };
1085 value_type __data_[__min_cap];
1086 };
1087
1088 union _{__long _; __short __;};
1089
1090 enum {__n_words = sizeof(_) / sizeof(size_type)};
1091
1092 struct __raw
1093 {
1094 size_type __words[__n_words];
1095 };
1096
1097 struct __rep
1098 {
1099 union
1100 {
1101 __long __l;
1102 __short __s;
1103 __raw __r;
1104 };
1105 };
1106
1107 __compressed_pair<__rep, allocator_type> __r_;
1108
1109#ifdef _LIBCPP_DEBUG
1110
1111 pair<iterator*, const_iterator*> __iterator_list_;
1112
1113 _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;}
1114 _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
1115
1116#endif // _LIBCPP_DEBUG
1117
1118public:
1119 static const size_type npos = -1;
1120
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001121 _LIBCPP_INLINE_VISIBILITY basic_string()
1122 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001123 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001124 basic_string(const basic_string& __str);
1125 basic_string(const basic_string& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001126#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59 +00001127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001128 basic_string(basic_string&& __str)
1129 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant9f193f22011-01-26 00:06:59 +00001130 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001131 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001132#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001133 _LIBCPP_INLINE_VISIBILITY basic_string(const_pointer __s);
1134 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001135 basic_string(const_pointer __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001136 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001137 basic_string(const_pointer __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001138 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001139 basic_string(const_pointer __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001141 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001142 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001143 basic_string(size_type __n, value_type __c, const allocator_type& __a);
1144 basic_string(const basic_string& __str, size_type __pos, size_type __n = npos,
1145 const allocator_type& __a = allocator_type());
1146 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001147 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001148 basic_string(_InputIterator __first, _InputIterator __last);
1149 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001151 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001153 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
1156
1157 ~basic_string();
1158
Howard Hinnante32b5e22010-11-17 17:55:08 +00001159 basic_string& operator=(const basic_string& __str);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001160#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001161 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001162 basic_string& operator=(basic_string&& __str)
1163 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1164 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001165#endif
Howard Hinnanta6119a82011-05-29 19:57:12 +00001166 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const_pointer __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001167 basic_string& operator=(value_type __c);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001168 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001169 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
1170
1171#ifndef _LIBCPP_DEBUG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001172 _LIBCPP_INLINE_VISIBILITY
1173 iterator begin() _NOEXCEPT
1174 {return iterator(__get_pointer());}
1175 _LIBCPP_INLINE_VISIBILITY
1176 const_iterator begin() const _NOEXCEPT
1177 {return const_iterator(data());}
1178 _LIBCPP_INLINE_VISIBILITY
1179 iterator end() _NOEXCEPT
1180 {return iterator(__get_pointer() + size());}
1181 _LIBCPP_INLINE_VISIBILITY
1182 const_iterator end() const _NOEXCEPT
1183 {return const_iterator(data() + size());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001184#else // _LIBCPP_DEBUG
1185 _LIBCPP_INLINE_VISIBILITY iterator begin() {return iterator(this, __get_pointer());}
1186 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return const_iterator(this, data());}
1187 _LIBCPP_INLINE_VISIBILITY iterator end() {return iterator(this, __get_pointer() + size());}
1188 _LIBCPP_INLINE_VISIBILITY const_iterator end() const {return const_iterator(this, data() + size());}
1189#endif // _LIBCPP_DEBUG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001190 _LIBCPP_INLINE_VISIBILITY
1191 reverse_iterator rbegin() _NOEXCEPT
1192 {return reverse_iterator(end());}
1193 _LIBCPP_INLINE_VISIBILITY
1194 const_reverse_iterator rbegin() const _NOEXCEPT
1195 {return const_reverse_iterator(end());}
1196 _LIBCPP_INLINE_VISIBILITY
1197 reverse_iterator rend() _NOEXCEPT
1198 {return reverse_iterator(begin());}
1199 _LIBCPP_INLINE_VISIBILITY
1200 const_reverse_iterator rend() const _NOEXCEPT
1201 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001202
Howard Hinnanta6119a82011-05-29 19:57:12 +00001203 _LIBCPP_INLINE_VISIBILITY
1204 const_iterator cbegin() const _NOEXCEPT
1205 {return begin();}
1206 _LIBCPP_INLINE_VISIBILITY
1207 const_iterator cend() const _NOEXCEPT
1208 {return end();}
1209 _LIBCPP_INLINE_VISIBILITY
1210 const_reverse_iterator crbegin() const _NOEXCEPT
1211 {return rbegin();}
1212 _LIBCPP_INLINE_VISIBILITY
1213 const_reverse_iterator crend() const _NOEXCEPT
1214 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001215
Howard Hinnanta6119a82011-05-29 19:57:12 +00001216 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001217 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001218 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
1219 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
1220 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001221 {return (__is_long() ? __get_long_cap() : __min_cap) - 1;}
1222
1223 void resize(size_type __n, value_type __c);
1224 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
1225
1226 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001227 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001228 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001230 void clear() _NOEXCEPT;
1231 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001232
1233 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
1234 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
1235
1236 const_reference at(size_type __n) const;
1237 reference at(size_type __n);
1238
1239 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
1240 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const_pointer __s) {return append(__s);}
1241 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
1242 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
1243
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001245 basic_string& append(const basic_string& __str);
1246 basic_string& append(const basic_string& __str, size_type __pos, size_type __n);
1247 basic_string& append(const_pointer __s, size_type __n);
1248 basic_string& append(const_pointer __s);
1249 basic_string& append(size_type __n, value_type __c);
1250 template<class _InputIterator>
1251 typename enable_if
1252 <
1253 __is_input_iterator <_InputIterator>::value &&
1254 !__is_forward_iterator<_InputIterator>::value,
1255 basic_string&
1256 >::type
1257 append(_InputIterator __first, _InputIterator __last);
1258 template<class _ForwardIterator>
1259 typename enable_if
1260 <
1261 __is_forward_iterator<_ForwardIterator>::value,
1262 basic_string&
1263 >::type
1264 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001265 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001266 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
1267
1268 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001270 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001271 _LIBCPP_INLINE_VISIBILITY reference front();
1272 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1273 _LIBCPP_INLINE_VISIBILITY reference back();
1274 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001275
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001277 basic_string& assign(const basic_string& __str);
Howard Hinnanta6119a82011-05-29 19:57:12 +00001278#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1279 _LIBCPP_INLINE_VISIBILITY
1280 basic_string& assign(basic_string&& str)
1281 {*this = _STD::move(str); return *this;}
1282#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001283 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n);
1284 basic_string& assign(const_pointer __s, size_type __n);
1285 basic_string& assign(const_pointer __s);
1286 basic_string& assign(size_type __n, value_type __c);
1287 template<class _InputIterator>
1288 typename enable_if
1289 <
1290 __is_input_iterator <_InputIterator>::value &&
1291 !__is_forward_iterator<_InputIterator>::value,
1292 basic_string&
1293 >::type
1294 assign(_InputIterator __first, _InputIterator __last);
1295 template<class _ForwardIterator>
1296 typename enable_if
1297 <
1298 __is_forward_iterator<_ForwardIterator>::value,
1299 basic_string&
1300 >::type
1301 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001302 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001303 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
1304
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001306 basic_string& insert(size_type __pos1, const basic_string& __str);
1307 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n);
1308 basic_string& insert(size_type __pos, const_pointer __s, size_type __n);
1309 basic_string& insert(size_type __pos, const_pointer __s);
1310 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1311 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001313 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1314 template<class _InputIterator>
1315 typename enable_if
1316 <
1317 __is_input_iterator <_InputIterator>::value &&
1318 !__is_forward_iterator<_InputIterator>::value,
1319 iterator
1320 >::type
1321 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1322 template<class _ForwardIterator>
1323 typename enable_if
1324 <
1325 __is_forward_iterator<_ForwardIterator>::value,
1326 iterator
1327 >::type
1328 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001330 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1331 {return insert(__pos, __il.begin(), __il.end());}
1332
1333 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001334 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001335 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001336 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001337 iterator erase(const_iterator __first, const_iterator __last);
1338
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001339 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
1341 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2);
1342 basic_string& replace(size_type __pos, size_type __n1, const_pointer __s, size_type __n2);
1343 basic_string& replace(size_type __pos, size_type __n1, const_pointer __s);
1344 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001345 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001346 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001347 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001348 basic_string& replace(const_iterator __i1, const_iterator __i2, const_pointer __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001349 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001350 basic_string& replace(const_iterator __i1, const_iterator __i2, const_pointer __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001351 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001352 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001353 template<class _InputIterator>
1354 typename enable_if
1355 <
1356 __is_input_iterator<_InputIterator>::value,
1357 basic_string&
1358 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001359 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001360 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001361 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001362 {return replace(__i1, __i2, __il.begin(), __il.end());}
1363
1364 size_type copy(pointer __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001365 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001366 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1367
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001368 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001369 void swap(basic_string& __str)
1370 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1371 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001372
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001373 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001374 const_pointer c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001375 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001376 const_pointer data() const _NOEXCEPT {return __get_pointer();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001377
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001378 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001379 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001380
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001381 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001382 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1383 size_type find(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001384 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001385 size_type find(const_pointer __s, size_type __pos = 0) const _NOEXCEPT;
1386 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001387
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001388 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001389 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1390 size_type rfind(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001392 size_type rfind(const_pointer __s, size_type __pos = npos) const _NOEXCEPT;
1393 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001394
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001395 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001396 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1397 size_type find_first_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001398 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001399 size_type find_first_of(const_pointer __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001400 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001401 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001402
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001403 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001404 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1405 size_type find_last_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001406 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001407 size_type find_last_of(const_pointer __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001409 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001410
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001411 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001412 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1413 size_type find_first_not_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
1414 _LIBCPP_INLINE_VISIBILITY
1415 size_type find_first_not_of(const_pointer __s, size_type __pos = 0) const _NOEXCEPT;
1416 _LIBCPP_INLINE_VISIBILITY
1417 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1418
1419 _LIBCPP_INLINE_VISIBILITY
1420 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1421 size_type find_last_not_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
1422 _LIBCPP_INLINE_VISIBILITY
1423 size_type find_last_not_of(const_pointer __s, size_type __pos = npos) const _NOEXCEPT;
1424 _LIBCPP_INLINE_VISIBILITY
1425 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1426
1427 _LIBCPP_INLINE_VISIBILITY
1428 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001429 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001430 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
1431 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 +00001432 int compare(const_pointer __s) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001433 int compare(size_type __pos1, size_type __n1, const_pointer __s) const;
1434 int compare(size_type __pos1, size_type __n1, const_pointer __s, size_type __n2) const;
1435
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001436 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001438 _LIBCPP_INLINE_VISIBILITY
1439 allocator_type& __alloc() _NOEXCEPT
1440 {return __r_.second();}
1441 _LIBCPP_INLINE_VISIBILITY
1442 const allocator_type& __alloc() const _NOEXCEPT
1443 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001444
Howard Hinnanta6119a82011-05-29 19:57:12 +00001445 _LIBCPP_INLINE_VISIBILITY
1446 bool __is_long() const _NOEXCEPT
1447 {return bool(__r_.first().__s.__size_ & __short_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001448
Howard Hinnanta6119a82011-05-29 19:57:12 +00001449 _LIBCPP_INLINE_VISIBILITY
1450 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001451#if _LIBCPP_BIG_ENDIAN
1452 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1453#else
1454 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1455#endif
Howard Hinnanta6119a82011-05-29 19:57:12 +00001456 _LIBCPP_INLINE_VISIBILITY
1457 size_type __get_short_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001458#if _LIBCPP_BIG_ENDIAN
1459 {return __r_.first().__s.__size_;}
1460#else
1461 {return __r_.first().__s.__size_ >> 1;}
1462#endif
Howard Hinnanta6119a82011-05-29 19:57:12 +00001463 _LIBCPP_INLINE_VISIBILITY
1464 void __set_long_size(size_type __s) _NOEXCEPT
1465 {__r_.first().__l.__size_ = __s;}
1466 _LIBCPP_INLINE_VISIBILITY
1467 size_type __get_long_size() const _NOEXCEPT
1468 {return __r_.first().__l.__size_;}
1469 _LIBCPP_INLINE_VISIBILITY
1470 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001471 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1472
Howard Hinnanta6119a82011-05-29 19:57:12 +00001473 _LIBCPP_INLINE_VISIBILITY
1474 void __set_long_cap(size_type __s) _NOEXCEPT
1475 {__r_.first().__l.__cap_ = __long_mask | __s;}
1476 _LIBCPP_INLINE_VISIBILITY
1477 size_type __get_long_cap() const _NOEXCEPT
1478 {return __r_.first().__l.__cap_ & ~__long_mask;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001479
Howard Hinnanta6119a82011-05-29 19:57:12 +00001480 _LIBCPP_INLINE_VISIBILITY
1481 void __set_long_pointer(pointer __p) _NOEXCEPT
1482 {__r_.first().__l.__data_ = __p;}
1483 _LIBCPP_INLINE_VISIBILITY
1484 pointer __get_long_pointer() _NOEXCEPT
1485 {return __r_.first().__l.__data_;}
1486 _LIBCPP_INLINE_VISIBILITY
1487 const_pointer __get_long_pointer() const _NOEXCEPT
1488 {return __r_.first().__l.__data_;}
1489 _LIBCPP_INLINE_VISIBILITY
1490 pointer __get_short_pointer() _NOEXCEPT
1491 {return __r_.first().__s.__data_;}
1492 _LIBCPP_INLINE_VISIBILITY
1493 const_pointer __get_short_pointer() const _NOEXCEPT
1494 {return __r_.first().__s.__data_;}
1495 _LIBCPP_INLINE_VISIBILITY
1496 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001497 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001498 _LIBCPP_INLINE_VISIBILITY
1499 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001500 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1501
Howard Hinnanta6119a82011-05-29 19:57:12 +00001502 _LIBCPP_INLINE_VISIBILITY
1503 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001504 {
1505 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1506 for (unsigned __i = 0; __i < __n_words; ++__i)
1507 __a[__i] = 0;
1508 }
1509
1510 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001511 _LIBCPP_INLINE_VISIBILITY
1512 size_type __align(size_type __s) _NOEXCEPT
1513 {return __s + (__a-1) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001514 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001515 static _LIBCPP_INLINE_VISIBILITY
1516 size_type __recommend(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001517 {return (__s < __min_cap ? __min_cap :
Howard Hinnanta6119a82011-05-29 19:57:12 +00001518 __align<sizeof(value_type) < __alignment ?
1519 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001520
1521 void __init(const_pointer __s, size_type __sz, size_type __reserve);
1522 void __init(const_pointer __s, size_type __sz);
1523 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001524
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525 template <class _InputIterator>
1526 typename enable_if
1527 <
1528 __is_input_iterator <_InputIterator>::value &&
1529 !__is_forward_iterator<_InputIterator>::value,
1530 void
1531 >::type
1532 __init(_InputIterator __first, _InputIterator __last);
1533
1534 template <class _ForwardIterator>
1535 typename enable_if
1536 <
1537 __is_forward_iterator<_ForwardIterator>::value,
1538 void
1539 >::type
1540 __init(_ForwardIterator __first, _ForwardIterator __last);
1541
1542 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001543 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001544 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1545 size_type __n_copy, size_type __n_del,
1546 size_type __n_add, const_pointer __p_new_stuff);
1547
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001549 void __erase_to_end(size_type __pos);
1550
Howard Hinnante32b5e22010-11-17 17:55:08 +00001551 _LIBCPP_INLINE_VISIBILITY
1552 void __copy_assign_alloc(const basic_string& __str)
1553 {__copy_assign_alloc(__str, integral_constant<bool,
1554 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1555
1556 _LIBCPP_INLINE_VISIBILITY
1557 void __copy_assign_alloc(const basic_string& __str, true_type)
1558 {
1559 if (__alloc() != __str.__alloc())
1560 {
1561 clear();
1562 shrink_to_fit();
1563 }
1564 __alloc() = __str.__alloc();
1565 }
1566
1567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001568 void __copy_assign_alloc(const basic_string& __str, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001569 {}
1570
1571#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00001573 void __move_assign(basic_string& __str, false_type);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001574 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001575 void __move_assign(basic_string& __str, true_type)
1576 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001577#endif
1578
1579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001580 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
1581 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1582 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001583 {__swap_alloc(__x, __y, integral_constant<bool,
1584 __alloc_traits::propagate_on_container_swap::value>());}
1585
1586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001587 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
1588 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001589 {
1590 using _STD::swap;
1591 swap(__x, __y);
1592 }
1593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001594 static void __swap_alloc(allocator_type& __x, allocator_type& __y, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001595 {}
1596
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001597 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1598 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001599
1600 friend basic_string operator+<>(const basic_string&, const basic_string&);
1601 friend basic_string operator+<>(const value_type*, const basic_string&);
1602 friend basic_string operator+<>(value_type, const basic_string&);
1603 friend basic_string operator+<>(const basic_string&, const value_type*);
1604 friend basic_string operator+<>(const basic_string&, value_type);
1605};
1606
1607template <class _CharT, class _Traits, class _Allocator>
1608#ifndef _LIBCPP_DEBUG
1609_LIBCPP_INLINE_VISIBILITY inline
1610#endif
1611void
1612basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1613{
1614#ifdef _LIBCPP_DEBUG
1615 iterator::__remove_all(this);
1616 const_iterator::__remove_all(this);
Howard Hinnant324bb032010-08-22 00:02:43 +00001617#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001618}
1619
1620template <class _CharT, class _Traits, class _Allocator>
1621#ifndef _LIBCPP_DEBUG
1622_LIBCPP_INLINE_VISIBILITY inline
1623#endif
1624void
1625basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos)
1626{
1627#ifdef _LIBCPP_DEBUG
1628 const_iterator __beg = begin();
1629 if (__iterator_list_.first)
1630 {
1631 for (iterator* __p = __iterator_list_.first; __p;)
1632 {
1633 if (*__p - __beg > static_cast<difference_type>(__pos))
1634 {
1635 iterator* __n = __p;
1636 __p = __p->__next;
1637 __n->__remove_owner();
1638 }
1639 else
1640 __p = __p->__next;
1641 }
1642 }
1643 if (__iterator_list_.second)
1644 {
1645 for (const_iterator* __p = __iterator_list_.second; __p;)
1646 {
1647 if (*__p - __beg > static_cast<difference_type>(__pos))
1648 {
1649 const_iterator* __n = __p;
1650 __p = __p->__next;
1651 __n->__remove_owner();
1652 }
1653 else
1654 __p = __p->__next;
1655 }
1656 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001657#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001658}
1659
1660template <class _CharT, class _Traits, class _Allocator>
1661_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001662basic_string<_CharT, _Traits, _Allocator>::basic_string()
1663 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001664{
1665 __zero();
1666}
1667
1668template <class _CharT, class _Traits, class _Allocator>
1669_LIBCPP_INLINE_VISIBILITY inline
1670basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
1671 : __r_(__a)
1672{
1673 __zero();
1674}
1675
1676template <class _CharT, class _Traits, class _Allocator>
1677void
1678basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type __sz, size_type __reserve)
1679{
1680 if (__reserve > max_size())
1681 this->__throw_length_error();
1682 pointer __p;
1683 if (__reserve < __min_cap)
1684 {
1685 __set_short_size(__sz);
1686 __p = __get_short_pointer();
1687 }
1688 else
1689 {
1690 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001691 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001692 __set_long_pointer(__p);
1693 __set_long_cap(__cap+1);
1694 __set_long_size(__sz);
1695 }
1696 traits_type::copy(__p, __s, __sz);
1697 traits_type::assign(__p[__sz], value_type());
1698}
1699
1700template <class _CharT, class _Traits, class _Allocator>
1701void
1702basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type __sz)
1703{
1704 if (__sz > max_size())
1705 this->__throw_length_error();
1706 pointer __p;
1707 if (__sz < __min_cap)
1708 {
1709 __set_short_size(__sz);
1710 __p = __get_short_pointer();
1711 }
1712 else
1713 {
1714 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001715 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001716 __set_long_pointer(__p);
1717 __set_long_cap(__cap+1);
1718 __set_long_size(__sz);
1719 }
1720 traits_type::copy(__p, __s, __sz);
1721 traits_type::assign(__p[__sz], value_type());
1722}
1723
1724template <class _CharT, class _Traits, class _Allocator>
1725_LIBCPP_INLINE_VISIBILITY inline
1726basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s)
1727{
1728#ifdef _LIBCPP_DEBUG
1729 assert(__s != 0);
1730#endif
1731 __init(__s, traits_type::length(__s));
1732}
1733
1734template <class _CharT, class _Traits, class _Allocator>
1735_LIBCPP_INLINE_VISIBILITY inline
1736basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, const allocator_type& __a)
1737 : __r_(__a)
1738{
1739#ifdef _LIBCPP_DEBUG
1740 assert(__s != 0);
1741#endif
1742 __init(__s, traits_type::length(__s));
1743}
1744
1745template <class _CharT, class _Traits, class _Allocator>
1746_LIBCPP_INLINE_VISIBILITY inline
1747basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, size_type __n)
1748{
1749#ifdef _LIBCPP_DEBUG
1750 assert(__s != 0);
1751#endif
1752 __init(__s, __n);
1753}
1754
1755template <class _CharT, class _Traits, class _Allocator>
1756_LIBCPP_INLINE_VISIBILITY inline
1757basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, size_type __n, const allocator_type& __a)
1758 : __r_(__a)
1759{
1760#ifdef _LIBCPP_DEBUG
1761 assert(__s != 0);
1762#endif
1763 __init(__s, __n);
1764}
1765
1766template <class _CharT, class _Traits, class _Allocator>
1767basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001768 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001769{
1770 if (!__str.__is_long())
1771 __r_.first().__r = __str.__r_.first().__r;
1772 else
1773 __init(__str.__get_long_pointer(), __str.__get_long_size());
1774}
1775
1776template <class _CharT, class _Traits, class _Allocator>
1777basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
1778 : __r_(__a)
1779{
1780 if (!__str.__is_long())
1781 __r_.first().__r = __str.__r_.first().__r;
1782 else
1783 __init(__str.__get_long_pointer(), __str.__get_long_size());
1784}
1785
Howard Hinnant73d21a42010-09-04 23:28:19 +00001786#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001787
1788template <class _CharT, class _Traits, class _Allocator>
1789_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001790basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
1791 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001792 : __r_(_STD::move(__str.__r_))
1793{
1794 __str.__zero();
1795#ifdef _LIBCPP_DEBUG
1796 __str.__invalidate_all_iterators();
1797#endif
1798}
1799
1800template <class _CharT, class _Traits, class _Allocator>
1801_LIBCPP_INLINE_VISIBILITY inline
1802basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001803 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001804{
Howard Hinnante32b5e22010-11-17 17:55:08 +00001805 if (__a == __str.__alloc() || !__str.__is_long())
1806 __r_.first().__r = __str.__r_.first().__r;
1807 else
1808 __init(__str.__get_long_pointer(), __str.__get_long_size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001809 __str.__zero();
1810#ifdef _LIBCPP_DEBUG
1811 __str.__invalidate_all_iterators();
1812#endif
1813}
1814
Howard Hinnant73d21a42010-09-04 23:28:19 +00001815#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001816
1817template <class _CharT, class _Traits, class _Allocator>
1818void
1819basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1820{
1821 if (__n > max_size())
1822 this->__throw_length_error();
1823 pointer __p;
1824 if (__n < __min_cap)
1825 {
1826 __set_short_size(__n);
1827 __p = __get_short_pointer();
1828 }
1829 else
1830 {
1831 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001832 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001833 __set_long_pointer(__p);
1834 __set_long_cap(__cap+1);
1835 __set_long_size(__n);
1836 }
1837 traits_type::assign(__p, __n, __c);
1838 traits_type::assign(__p[__n], value_type());
1839}
1840
1841template <class _CharT, class _Traits, class _Allocator>
1842_LIBCPP_INLINE_VISIBILITY inline
1843basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
1844{
1845 __init(__n, __c);
1846}
1847
1848template <class _CharT, class _Traits, class _Allocator>
1849_LIBCPP_INLINE_VISIBILITY inline
1850basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
1851 : __r_(__a)
1852{
1853 __init(__n, __c);
1854}
1855
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001856template <class _CharT, class _Traits, class _Allocator>
1857basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
1858 const allocator_type& __a)
1859 : __r_(__a)
1860{
1861 size_type __str_sz = __str.size();
1862 if (__pos > __str_sz)
1863 this->__throw_out_of_range();
1864 __init(__str.data() + __pos, _STD::min(__n, __str_sz - __pos));
1865}
1866
1867template <class _CharT, class _Traits, class _Allocator>
1868template <class _InputIterator>
1869typename enable_if
1870<
1871 __is_input_iterator <_InputIterator>::value &&
1872 !__is_forward_iterator<_InputIterator>::value,
1873 void
1874>::type
1875basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
1876{
1877 __zero();
1878#ifndef _LIBCPP_NO_EXCEPTIONS
1879 try
1880 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001881#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001882 for (; __first != __last; ++__first)
1883 push_back(*__first);
1884#ifndef _LIBCPP_NO_EXCEPTIONS
1885 }
1886 catch (...)
1887 {
1888 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001889 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001890 throw;
1891 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001892#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001893}
1894
1895template <class _CharT, class _Traits, class _Allocator>
1896template <class _ForwardIterator>
1897typename enable_if
1898<
1899 __is_forward_iterator<_ForwardIterator>::value,
1900 void
1901>::type
1902basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
1903{
1904 size_type __sz = static_cast<size_type>(_STD::distance(__first, __last));
1905 if (__sz > max_size())
1906 this->__throw_length_error();
1907 pointer __p;
1908 if (__sz < __min_cap)
1909 {
1910 __set_short_size(__sz);
1911 __p = __get_short_pointer();
1912 }
1913 else
1914 {
1915 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001916 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001917 __set_long_pointer(__p);
1918 __set_long_cap(__cap+1);
1919 __set_long_size(__sz);
1920 }
1921 for (; __first != __last; ++__first, ++__p)
1922 traits_type::assign(*__p, *__first);
1923 traits_type::assign(*__p, value_type());
1924}
1925
1926template <class _CharT, class _Traits, class _Allocator>
1927template<class _InputIterator>
1928_LIBCPP_INLINE_VISIBILITY inline
1929basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
1930{
1931 __init(__first, __last);
1932}
1933
1934template <class _CharT, class _Traits, class _Allocator>
1935template<class _InputIterator>
1936_LIBCPP_INLINE_VISIBILITY inline
1937basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
1938 const allocator_type& __a)
1939 : __r_(__a)
1940{
1941 __init(__first, __last);
1942}
1943
1944template <class _CharT, class _Traits, class _Allocator>
1945_LIBCPP_INLINE_VISIBILITY inline
1946basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
1947{
1948 __init(__il.begin(), __il.end());
1949}
1950
1951template <class _CharT, class _Traits, class _Allocator>
1952_LIBCPP_INLINE_VISIBILITY inline
1953basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
1954 : __r_(__a)
1955{
1956 __init(__il.begin(), __il.end());
1957}
1958
1959template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001960basic_string<_CharT, _Traits, _Allocator>::~basic_string()
1961{
1962 __invalidate_all_iterators();
1963 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001964 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001965}
1966
1967template <class _CharT, class _Traits, class _Allocator>
1968void
1969basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
1970 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1971 size_type __n_copy, size_type __n_del, size_type __n_add, const_pointer __p_new_stuff)
1972{
1973 size_type __ms = max_size();
1974 if (__delta_cap > __ms - __old_cap - 1)
1975 this->__throw_length_error();
1976 pointer __old_p = __get_pointer();
1977 size_type __cap = __old_cap < __ms / 2 - __alignment ?
1978 __recommend(_STD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
1979 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001980 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001981 __invalidate_all_iterators();
1982 if (__n_copy != 0)
1983 traits_type::copy(__p, __old_p, __n_copy);
1984 if (__n_add != 0)
1985 traits_type::copy(__p + __n_copy, __p_new_stuff, __n_add);
1986 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1987 if (__sec_cp_sz != 0)
1988 traits_type::copy(__p + __n_copy + __n_add, __old_p + __n_copy + __n_del, __sec_cp_sz);
1989 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001990 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001991 __set_long_pointer(__p);
1992 __set_long_cap(__cap+1);
1993 __old_sz = __n_copy + __n_add + __sec_cp_sz;
1994 __set_long_size(__old_sz);
1995 traits_type::assign(__p[__old_sz], value_type());
1996}
1997
1998template <class _CharT, class _Traits, class _Allocator>
1999void
2000basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2001 size_type __n_copy, size_type __n_del, size_type __n_add)
2002{
2003 size_type __ms = max_size();
2004 if (__delta_cap > __ms - __old_cap - 1)
2005 this->__throw_length_error();
2006 pointer __old_p = __get_pointer();
2007 size_type __cap = __old_cap < __ms / 2 - __alignment ?
2008 __recommend(_STD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
2009 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002010 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002011 __invalidate_all_iterators();
2012 if (__n_copy != 0)
2013 traits_type::copy(__p, __old_p, __n_copy);
2014 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2015 if (__sec_cp_sz != 0)
2016 traits_type::copy(__p + __n_copy + __n_add, __old_p + __n_copy + __n_del, __sec_cp_sz);
2017 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002018 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002019 __set_long_pointer(__p);
2020 __set_long_cap(__cap+1);
2021}
2022
2023// assign
2024
2025template <class _CharT, class _Traits, class _Allocator>
2026basic_string<_CharT, _Traits, _Allocator>&
2027basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s, size_type __n)
2028{
2029#ifdef _LIBCPP_DEBUG
2030 assert(__s != 0);
2031#endif
2032 size_type __cap = capacity();
2033 if (__cap >= __n)
2034 {
2035 pointer __p = __get_pointer();
2036 traits_type::move(__p, __s, __n);
2037 traits_type::assign(__p[__n], value_type());
2038 __set_size(__n);
2039 __invalidate_iterators_past(__n);
2040 }
2041 else
2042 {
2043 size_type __sz = size();
2044 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2045 }
2046 return *this;
2047}
2048
2049template <class _CharT, class _Traits, class _Allocator>
2050basic_string<_CharT, _Traits, _Allocator>&
2051basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2052{
2053 size_type __cap = capacity();
2054 if (__cap < __n)
2055 {
2056 size_type __sz = size();
2057 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2058 }
2059 else
2060 __invalidate_iterators_past(__n);
2061 pointer __p = __get_pointer();
2062 traits_type::assign(__p, __n, __c);
2063 traits_type::assign(__p[__n], value_type());
2064 __set_size(__n);
2065 return *this;
2066}
2067
2068template <class _CharT, class _Traits, class _Allocator>
2069basic_string<_CharT, _Traits, _Allocator>&
2070basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2071{
2072 pointer __p;
2073 if (__is_long())
2074 {
2075 __p = __get_long_pointer();
2076 __set_long_size(1);
2077 }
2078 else
2079 {
2080 __p = __get_short_pointer();
2081 __set_short_size(1);
2082 }
2083 traits_type::assign(*__p, __c);
2084 traits_type::assign(*++__p, value_type());
2085 __invalidate_iterators_past(1);
2086 return *this;
2087}
2088
2089template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002090basic_string<_CharT, _Traits, _Allocator>&
2091basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2092{
2093 if (this != &__str)
2094 {
2095 __copy_assign_alloc(__str);
2096 assign(__str);
2097 }
2098 return *this;
2099}
2100
2101#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2102
2103template <class _CharT, class _Traits, class _Allocator>
2104_LIBCPP_INLINE_VISIBILITY inline
2105void
2106basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2107{
2108 if (__alloc() != __str.__alloc())
2109 assign(__str);
2110 else
2111 __move_assign(__str, true_type());
2112}
2113
2114template <class _CharT, class _Traits, class _Allocator>
2115_LIBCPP_INLINE_VISIBILITY inline
2116void
2117basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002118 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002119{
2120 clear();
2121 shrink_to_fit();
2122 __r_ = _STD::move(__str.__r_);
2123 __str.__zero();
2124}
2125
2126template <class _CharT, class _Traits, class _Allocator>
2127_LIBCPP_INLINE_VISIBILITY inline
2128basic_string<_CharT, _Traits, _Allocator>&
2129basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002130 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
2131 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002132{
2133 __move_assign(__str, integral_constant<bool,
2134 __alloc_traits::propagate_on_container_move_assignment::value>());
2135 return *this;
2136}
2137
2138#endif
2139
2140template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002141template<class _InputIterator>
2142typename enable_if
2143<
2144 __is_input_iterator <_InputIterator>::value &&
2145 !__is_forward_iterator<_InputIterator>::value,
2146 basic_string<_CharT, _Traits, _Allocator>&
2147>::type
2148basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2149{
2150 clear();
2151 for (; __first != __last; ++__first)
2152 push_back(*__first);
2153}
2154
2155template <class _CharT, class _Traits, class _Allocator>
2156template<class _ForwardIterator>
2157typename enable_if
2158<
2159 __is_forward_iterator<_ForwardIterator>::value,
2160 basic_string<_CharT, _Traits, _Allocator>&
2161>::type
2162basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2163{
2164 size_type __n = static_cast<size_type>(_STD::distance(__first, __last));
2165 size_type __cap = capacity();
2166 if (__cap < __n)
2167 {
2168 size_type __sz = size();
2169 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2170 }
2171 else
2172 __invalidate_iterators_past(__n);
2173 pointer __p = __get_pointer();
2174 for (; __first != __last; ++__first, ++__p)
2175 traits_type::assign(*__p, *__first);
2176 traits_type::assign(*__p, value_type());
2177 __set_size(__n);
2178 return *this;
2179}
2180
2181template <class _CharT, class _Traits, class _Allocator>
2182_LIBCPP_INLINE_VISIBILITY inline
2183basic_string<_CharT, _Traits, _Allocator>&
2184basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
2185{
2186 return assign(__str.data(), __str.size());
2187}
2188
2189template <class _CharT, class _Traits, class _Allocator>
2190basic_string<_CharT, _Traits, _Allocator>&
2191basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2192{
2193 size_type __sz = __str.size();
2194 if (__pos > __sz)
2195 this->__throw_out_of_range();
2196 return assign(__str.data() + __pos, _STD::min(__n, __sz - __pos));
2197}
2198
2199template <class _CharT, class _Traits, class _Allocator>
2200basic_string<_CharT, _Traits, _Allocator>&
2201basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s)
2202{
2203#ifdef _LIBCPP_DEBUG
2204 assert(__s != 0);
2205#endif
2206 return assign(__s, traits_type::length(__s));
2207}
2208
2209// append
2210
2211template <class _CharT, class _Traits, class _Allocator>
2212basic_string<_CharT, _Traits, _Allocator>&
2213basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s, size_type __n)
2214{
2215#ifdef _LIBCPP_DEBUG
2216 assert(__s != 0);
2217#endif
2218 size_type __cap = capacity();
2219 size_type __sz = size();
2220 if (__cap - __sz >= __n)
2221 {
2222 if (__n)
2223 {
2224 pointer __p = __get_pointer();
2225 traits_type::copy(__p + __sz, __s, __n);
2226 __sz += __n;
2227 __set_size(__sz);
2228 traits_type::assign(__p[__sz], value_type());
2229 }
2230 }
2231 else
2232 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2233 return *this;
2234}
2235
2236template <class _CharT, class _Traits, class _Allocator>
2237basic_string<_CharT, _Traits, _Allocator>&
2238basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2239{
2240 if (__n)
2241 {
2242 size_type __cap = capacity();
2243 size_type __sz = size();
2244 if (__cap - __sz < __n)
2245 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2246 pointer __p = __get_pointer();
2247 traits_type::assign(__p + __sz, __n, __c);
2248 __sz += __n;
2249 __set_size(__sz);
2250 traits_type::assign(__p[__sz], value_type());
2251 }
2252 return *this;
2253}
2254
2255template <class _CharT, class _Traits, class _Allocator>
2256void
2257basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2258{
2259 size_type __cap = capacity();
2260 size_type __sz = size();
2261 if (__sz == __cap)
2262 __grow_by(__cap, 1, __sz, __sz, 0);
2263 pointer __p = __get_pointer() + __sz;
2264 traits_type::assign(*__p, __c);
2265 traits_type::assign(*++__p, value_type());
2266 __set_size(__sz+1);
2267}
2268
2269template <class _CharT, class _Traits, class _Allocator>
2270template<class _InputIterator>
2271typename enable_if
2272<
2273 __is_input_iterator <_InputIterator>::value &&
2274 !__is_forward_iterator<_InputIterator>::value,
2275 basic_string<_CharT, _Traits, _Allocator>&
2276>::type
2277basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2278{
2279 for (; __first != __last; ++__first)
2280 push_back(*__first);
2281 return *this;
2282}
2283
2284template <class _CharT, class _Traits, class _Allocator>
2285template<class _ForwardIterator>
2286typename enable_if
2287<
2288 __is_forward_iterator<_ForwardIterator>::value,
2289 basic_string<_CharT, _Traits, _Allocator>&
2290>::type
2291basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2292{
2293 size_type __sz = size();
2294 size_type __cap = capacity();
2295 size_type __n = static_cast<size_type>(_STD::distance(__first, __last));
2296 if (__n)
2297 {
2298 if (__cap - __sz < __n)
2299 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2300 pointer __p = __get_pointer() + __sz;
2301 for (; __first != __last; ++__p, ++__first)
2302 traits_type::assign(*__p, *__first);
2303 traits_type::assign(*__p, value_type());
2304 __set_size(__sz + __n);
2305 }
2306 return *this;
2307}
2308
2309template <class _CharT, class _Traits, class _Allocator>
2310_LIBCPP_INLINE_VISIBILITY inline
2311basic_string<_CharT, _Traits, _Allocator>&
2312basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2313{
2314 return append(__str.data(), __str.size());
2315}
2316
2317template <class _CharT, class _Traits, class _Allocator>
2318basic_string<_CharT, _Traits, _Allocator>&
2319basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2320{
2321 size_type __sz = __str.size();
2322 if (__pos > __sz)
2323 this->__throw_out_of_range();
2324 return append(__str.data() + __pos, _STD::min(__n, __sz - __pos));
2325}
2326
2327template <class _CharT, class _Traits, class _Allocator>
2328basic_string<_CharT, _Traits, _Allocator>&
2329basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s)
2330{
2331#ifdef _LIBCPP_DEBUG
2332 assert(__s != 0);
2333#endif
2334 return append(__s, traits_type::length(__s));
2335}
2336
2337// insert
2338
2339template <class _CharT, class _Traits, class _Allocator>
2340basic_string<_CharT, _Traits, _Allocator>&
2341basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const_pointer __s, size_type __n)
2342{
2343#ifdef _LIBCPP_DEBUG
2344 assert(__s != 0);
2345#endif
2346 size_type __sz = size();
2347 if (__pos > __sz)
2348 this->__throw_out_of_range();
2349 size_type __cap = capacity();
2350 if (__cap - __sz >= __n)
2351 {
2352 if (__n)
2353 {
2354 pointer __p = __get_pointer();
2355 size_type __n_move = __sz - __pos;
2356 if (__n_move != 0)
2357 {
2358 if (__p + __pos <= __s && __s < __p + __sz)
2359 __s += __n;
2360 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2361 }
2362 traits_type::move(__p + __pos, __s, __n);
2363 __sz += __n;
2364 __set_size(__sz);
2365 traits_type::assign(__p[__sz], value_type());
2366 }
2367 }
2368 else
2369 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2370 return *this;
2371}
2372
2373template <class _CharT, class _Traits, class _Allocator>
2374basic_string<_CharT, _Traits, _Allocator>&
2375basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2376{
2377 size_type __sz = size();
2378 if (__pos > __sz)
2379 this->__throw_out_of_range();
2380 if (__n)
2381 {
2382 size_type __cap = capacity();
2383 pointer __p;
2384 if (__cap - __sz >= __n)
2385 {
2386 __p = __get_pointer();
2387 size_type __n_move = __sz - __pos;
2388 if (__n_move != 0)
2389 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2390 }
2391 else
2392 {
2393 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
2394 __p = __get_long_pointer();
2395 }
2396 traits_type::assign(__p + __pos, __n, __c);
2397 __sz += __n;
2398 __set_size(__sz);
2399 traits_type::assign(__p[__sz], value_type());
2400 }
2401 return *this;
2402}
2403
2404template <class _CharT, class _Traits, class _Allocator>
2405template<class _InputIterator>
2406typename enable_if
2407<
2408 __is_input_iterator <_InputIterator>::value &&
2409 !__is_forward_iterator<_InputIterator>::value,
2410 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2411>::type
2412basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2413{
2414 size_type __old_sz = size();
2415 difference_type __ip = __pos - begin();
2416 for (; __first != __last; ++__first)
2417 push_back(*__first);
2418 pointer __p = __get_pointer();
2419 _STD::rotate(__p + __ip, __p + __old_sz, __p + size());
2420 return iterator(__p + __ip);
2421}
2422
2423template <class _CharT, class _Traits, class _Allocator>
2424template<class _ForwardIterator>
2425typename enable_if
2426<
2427 __is_forward_iterator<_ForwardIterator>::value,
2428 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2429>::type
2430basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2431{
2432 size_type __ip = static_cast<size_type>(__pos - begin());
2433 size_type __sz = size();
2434 size_type __cap = capacity();
2435 size_type __n = static_cast<size_type>(_STD::distance(__first, __last));
2436 if (__n)
2437 {
2438 pointer __p;
2439 if (__cap - __sz >= __n)
2440 {
2441 __p = __get_pointer();
2442 size_type __n_move = __sz - __ip;
2443 if (__n_move != 0)
2444 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2445 }
2446 else
2447 {
2448 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
2449 __p = __get_long_pointer();
2450 }
2451 __sz += __n;
2452 __set_size(__sz);
2453 traits_type::assign(__p[__sz], value_type());
2454 for (__p += __ip; __first != __last; ++__p, ++__first)
2455 traits_type::assign(*__p, *__first);
2456 }
2457 return begin() + __ip;
2458}
2459
2460template <class _CharT, class _Traits, class _Allocator>
2461_LIBCPP_INLINE_VISIBILITY inline
2462basic_string<_CharT, _Traits, _Allocator>&
2463basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2464{
2465 return insert(__pos1, __str.data(), __str.size());
2466}
2467
2468template <class _CharT, class _Traits, class _Allocator>
2469basic_string<_CharT, _Traits, _Allocator>&
2470basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2471 size_type __pos2, size_type __n)
2472{
2473 size_type __str_sz = __str.size();
2474 if (__pos2 > __str_sz)
2475 this->__throw_out_of_range();
2476 return insert(__pos1, __str.data() + __pos2, _STD::min(__n, __str_sz - __pos2));
2477}
2478
2479template <class _CharT, class _Traits, class _Allocator>
2480basic_string<_CharT, _Traits, _Allocator>&
2481basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const_pointer __s)
2482{
2483#ifdef _LIBCPP_DEBUG
2484 assert(__s != 0);
2485#endif
2486 return insert(__pos, __s, traits_type::length(__s));
2487}
2488
2489template <class _CharT, class _Traits, class _Allocator>
2490typename basic_string<_CharT, _Traits, _Allocator>::iterator
2491basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2492{
2493 size_type __ip = static_cast<size_type>(__pos - begin());
2494 size_type __sz = size();
2495 size_type __cap = capacity();
2496 pointer __p;
2497 if (__cap == __sz)
2498 {
2499 __grow_by(__cap, 1, __sz, __ip, 0, 1);
2500 __p = __get_long_pointer();
2501 }
2502 else
2503 {
2504 __p = __get_pointer();
2505 size_type __n_move = __sz - __ip;
2506 if (__n_move != 0)
2507 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2508 }
2509 traits_type::assign(__p[__ip], __c);
2510 traits_type::assign(__p[++__sz], value_type());
2511 __set_size(__sz);
2512 return begin() + static_cast<difference_type>(__ip);
2513}
2514
2515template <class _CharT, class _Traits, class _Allocator>
2516_LIBCPP_INLINE_VISIBILITY inline
2517typename basic_string<_CharT, _Traits, _Allocator>::iterator
2518basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2519{
2520 difference_type __p = __pos - begin();
2521 insert(static_cast<size_type>(__p), __n, __c);
2522 return begin() + __p;
2523}
2524
2525// replace
2526
2527template <class _CharT, class _Traits, class _Allocator>
2528basic_string<_CharT, _Traits, _Allocator>&
2529basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const_pointer __s, size_type __n2)
2530{
2531#ifdef _LIBCPP_DEBUG
2532 assert(__s != 0);
2533#endif
2534 size_type __sz = size();
2535 if (__pos > __sz)
2536 this->__throw_out_of_range();
2537 __n1 = _STD::min(__n1, __sz - __pos);
2538 size_type __cap = capacity();
2539 if (__cap - __sz + __n1 >= __n2)
2540 {
2541 pointer __p = __get_pointer();
2542 if (__n1 != __n2)
2543 {
2544 size_type __n_move = __sz - __pos - __n1;
2545 if (__n_move != 0)
2546 {
2547 if (__n1 > __n2)
2548 {
2549 traits_type::move(__p + __pos, __s, __n2);
2550 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2551 goto __finish;
2552 }
2553 if (__p + __pos < __s && __s < __p + __sz)
2554 {
2555 if (__p + __pos + __n1 <= __s)
2556 __s += __n2 - __n1;
2557 else // __p + __pos < __s < __p + __pos + __n1
2558 {
2559 traits_type::move(__p + __pos, __s, __n1);
2560 __pos += __n1;
2561 __s += __n2;
2562 __n2 -= __n1;
2563 __n1 = 0;
2564 }
2565 }
2566 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2567 }
2568 }
2569 traits_type::move(__p + __pos, __s, __n2);
2570__finish:
2571 __sz += __n2 - __n1;
2572 __set_size(__sz);
2573 __invalidate_iterators_past(__sz);
2574 traits_type::assign(__p[__sz], value_type());
2575 }
2576 else
2577 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2578 return *this;
2579}
2580
2581template <class _CharT, class _Traits, class _Allocator>
2582basic_string<_CharT, _Traits, _Allocator>&
2583basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2584{
2585 size_type __sz = size();
2586 if (__pos > __sz)
2587 this->__throw_out_of_range();
2588 __n1 = _STD::min(__n1, __sz - __pos);
2589 size_type __cap = capacity();
2590 pointer __p;
2591 if (__cap - __sz + __n1 >= __n2)
2592 {
2593 __p = __get_pointer();
2594 if (__n1 != __n2)
2595 {
2596 size_type __n_move = __sz - __pos - __n1;
2597 if (__n_move != 0)
2598 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2599 }
2600 }
2601 else
2602 {
2603 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
2604 __p = __get_long_pointer();
2605 }
2606 traits_type::assign(__p + __pos, __n2, __c);
2607 __sz += __n2 - __n1;
2608 __set_size(__sz);
2609 __invalidate_iterators_past(__sz);
2610 traits_type::assign(__p[__sz], value_type());
2611 return *this;
2612}
2613
2614template <class _CharT, class _Traits, class _Allocator>
2615template<class _InputIterator>
2616typename enable_if
2617<
2618 __is_input_iterator<_InputIterator>::value,
2619 basic_string<_CharT, _Traits, _Allocator>&
2620>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002621basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002622 _InputIterator __j1, _InputIterator __j2)
2623{
2624 for (; true; ++__i1, ++__j1)
2625 {
2626 if (__i1 == __i2)
2627 {
2628 if (__j1 != __j2)
2629 insert(__i1, __j1, __j2);
2630 break;
2631 }
2632 if (__j1 == __j2)
2633 {
2634 erase(__i1, __i2);
2635 break;
2636 }
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002637 traits_type::assign(const_cast<value_type&>(*__i1), *__j1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002638 }
2639 return *this;
2640}
2641
2642template <class _CharT, class _Traits, class _Allocator>
2643_LIBCPP_INLINE_VISIBILITY inline
2644basic_string<_CharT, _Traits, _Allocator>&
2645basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2646{
2647 return replace(__pos1, __n1, __str.data(), __str.size());
2648}
2649
2650template <class _CharT, class _Traits, class _Allocator>
2651basic_string<_CharT, _Traits, _Allocator>&
2652basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2653 size_type __pos2, size_type __n2)
2654{
2655 size_type __str_sz = __str.size();
2656 if (__pos2 > __str_sz)
2657 this->__throw_out_of_range();
2658 return replace(__pos1, __n1, __str.data() + __pos2, _STD::min(__n2, __str_sz - __pos2));
2659}
2660
2661template <class _CharT, class _Traits, class _Allocator>
2662basic_string<_CharT, _Traits, _Allocator>&
2663basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const_pointer __s)
2664{
2665#ifdef _LIBCPP_DEBUG
2666 assert(__s != 0);
2667#endif
2668 return replace(__pos, __n1, __s, traits_type::length(__s));
2669}
2670
2671template <class _CharT, class _Traits, class _Allocator>
2672_LIBCPP_INLINE_VISIBILITY inline
2673basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002674basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002675{
2676 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2677 __str.data(), __str.size());
2678}
2679
2680template <class _CharT, class _Traits, class _Allocator>
2681_LIBCPP_INLINE_VISIBILITY inline
2682basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002683basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const_pointer __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002684{
2685 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2686}
2687
2688template <class _CharT, class _Traits, class _Allocator>
2689_LIBCPP_INLINE_VISIBILITY inline
2690basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002691basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const_pointer __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002692{
2693 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2694}
2695
2696template <class _CharT, class _Traits, class _Allocator>
2697_LIBCPP_INLINE_VISIBILITY inline
2698basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002699basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002700{
2701 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2702}
2703
2704// erase
2705
2706template <class _CharT, class _Traits, class _Allocator>
2707basic_string<_CharT, _Traits, _Allocator>&
2708basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2709{
2710 size_type __sz = size();
2711 if (__pos > __sz)
2712 this->__throw_out_of_range();
2713 if (__n)
2714 {
2715 pointer __p = __get_pointer();
2716 __n = _STD::min(__n, __sz - __pos);
2717 size_type __n_move = __sz - __pos - __n;
2718 if (__n_move != 0)
2719 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2720 __sz -= __n;
2721 __set_size(__sz);
2722 __invalidate_iterators_past(__sz);
2723 traits_type::assign(__p[__sz], value_type());
2724 }
2725 return *this;
2726}
2727
2728template <class _CharT, class _Traits, class _Allocator>
2729_LIBCPP_INLINE_VISIBILITY inline
2730typename basic_string<_CharT, _Traits, _Allocator>::iterator
2731basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2732{
2733 iterator __b = begin();
2734 size_type __r = static_cast<size_type>(__pos - __b);
2735 erase(__r, 1);
2736 return __b + __r;
2737}
2738
2739template <class _CharT, class _Traits, class _Allocator>
2740_LIBCPP_INLINE_VISIBILITY inline
2741typename basic_string<_CharT, _Traits, _Allocator>::iterator
2742basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2743{
2744 iterator __b = begin();
2745 size_type __r = static_cast<size_type>(__first - __b);
2746 erase(__r, static_cast<size_type>(__last - __first));
2747 return __b + __r;
2748}
2749
2750template <class _CharT, class _Traits, class _Allocator>
2751_LIBCPP_INLINE_VISIBILITY inline
2752void
2753basic_string<_CharT, _Traits, _Allocator>::pop_back()
2754{
2755#ifdef _LIBCPP_DEBUG
2756 assert(!empty());
2757#endif
2758 size_type __sz;
2759 if (__is_long())
2760 {
2761 __sz = __get_long_size() - 1;
2762 __set_long_size(__sz);
2763 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2764 }
2765 else
2766 {
2767 __sz = __get_short_size() - 1;
2768 __set_short_size(__sz);
2769 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2770 }
2771 __invalidate_iterators_past(__sz);
2772}
2773
2774template <class _CharT, class _Traits, class _Allocator>
2775_LIBCPP_INLINE_VISIBILITY inline
2776void
Howard Hinnanta6119a82011-05-29 19:57:12 +00002777basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002778{
2779 __invalidate_all_iterators();
2780 if (__is_long())
2781 {
2782 traits_type::assign(*__get_long_pointer(), value_type());
2783 __set_long_size(0);
2784 }
2785 else
2786 {
2787 traits_type::assign(*__get_short_pointer(), value_type());
2788 __set_short_size(0);
2789 }
2790}
2791
2792template <class _CharT, class _Traits, class _Allocator>
2793_LIBCPP_INLINE_VISIBILITY inline
2794void
2795basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2796{
2797 if (__is_long())
2798 {
2799 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2800 __set_long_size(__pos);
2801 }
2802 else
2803 {
2804 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2805 __set_short_size(__pos);
2806 }
2807 __invalidate_iterators_past(__pos);
2808}
2809
2810template <class _CharT, class _Traits, class _Allocator>
2811void
2812basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2813{
2814 size_type __sz = size();
2815 if (__n > __sz)
2816 append(__n - __sz, __c);
2817 else
2818 __erase_to_end(__n);
2819}
2820
2821template <class _CharT, class _Traits, class _Allocator>
2822_LIBCPP_INLINE_VISIBILITY inline
2823typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002824basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002825{
Howard Hinnante32b5e22010-11-17 17:55:08 +00002826 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002827#if _LIBCPP_BIG_ENDIAN
2828 return (__m <= ~__long_mask ? __m : __m/2) - 1;
2829#else
2830 return __m - 1;
2831#endif
2832}
2833
2834template <class _CharT, class _Traits, class _Allocator>
2835void
2836basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2837{
2838 if (__res_arg > max_size())
2839 this->__throw_length_error();
2840 size_type __cap = capacity();
2841 size_type __sz = size();
2842 __res_arg = _STD::max(__res_arg, __sz);
2843 __res_arg = __recommend(__res_arg);
2844 if (__res_arg != __cap)
2845 {
2846 pointer __new_data, __p;
2847 bool __was_long, __now_long;
2848 if (__res_arg == __min_cap - 1)
2849 {
2850 __was_long = true;
2851 __now_long = false;
2852 __new_data = __get_short_pointer();
2853 __p = __get_long_pointer();
2854 }
2855 else
2856 {
2857 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002858 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002859 else
2860 {
2861 #ifndef _LIBCPP_NO_EXCEPTIONS
2862 try
2863 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002864 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00002865 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002866 #ifndef _LIBCPP_NO_EXCEPTIONS
2867 }
2868 catch (...)
2869 {
2870 return;
2871 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002872 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002873 if (__new_data == 0)
2874 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00002875 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002876 }
2877 __now_long = true;
2878 __was_long = __is_long();
2879 __p = __get_pointer();
2880 }
2881 traits_type::copy(__new_data, __p, size()+1);
2882 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002883 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002884 if (__now_long)
2885 {
2886 __set_long_cap(__res_arg+1);
2887 __set_long_size(__sz);
2888 __set_long_pointer(__new_data);
2889 }
2890 else
2891 __set_short_size(__sz);
2892 __invalidate_all_iterators();
2893 }
2894}
2895
2896template <class _CharT, class _Traits, class _Allocator>
2897_LIBCPP_INLINE_VISIBILITY inline
2898typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2899basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
2900{
2901#ifdef __LIBCPP_DEBUG
2902 assert(__pos <= size());
2903#endif
2904 return *(data() + __pos);
2905}
2906
2907template <class _CharT, class _Traits, class _Allocator>
2908_LIBCPP_INLINE_VISIBILITY inline
2909typename basic_string<_CharT, _Traits, _Allocator>::reference
2910basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
2911{
2912#ifdef __LIBCPP_DEBUG
2913 assert(__pos < size());
2914#endif
2915 return *(__get_pointer() + __pos);
2916}
2917
2918template <class _CharT, class _Traits, class _Allocator>
2919typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2920basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
2921{
2922 if (__n >= size())
2923 this->__throw_out_of_range();
2924 return (*this)[__n];
2925}
2926
2927template <class _CharT, class _Traits, class _Allocator>
2928typename basic_string<_CharT, _Traits, _Allocator>::reference
2929basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
2930{
2931 if (__n >= size())
2932 this->__throw_out_of_range();
2933 return (*this)[__n];
2934}
2935
2936template <class _CharT, class _Traits, class _Allocator>
2937_LIBCPP_INLINE_VISIBILITY inline
2938typename basic_string<_CharT, _Traits, _Allocator>::reference
2939basic_string<_CharT, _Traits, _Allocator>::front()
2940{
2941#ifdef _LIBCPP_DEBUG
2942 assert(!empty());
2943#endif
2944 return *__get_pointer();
2945}
2946
2947template <class _CharT, class _Traits, class _Allocator>
2948_LIBCPP_INLINE_VISIBILITY inline
2949typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2950basic_string<_CharT, _Traits, _Allocator>::front() const
2951{
2952#ifdef _LIBCPP_DEBUG
2953 assert(!empty());
2954#endif
2955 return *data();
2956}
2957
2958template <class _CharT, class _Traits, class _Allocator>
2959_LIBCPP_INLINE_VISIBILITY inline
2960typename basic_string<_CharT, _Traits, _Allocator>::reference
2961basic_string<_CharT, _Traits, _Allocator>::back()
2962{
2963#ifdef _LIBCPP_DEBUG
2964 assert(!empty());
2965#endif
2966 return *(__get_pointer() + size() - 1);
2967}
2968
2969template <class _CharT, class _Traits, class _Allocator>
2970_LIBCPP_INLINE_VISIBILITY inline
2971typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2972basic_string<_CharT, _Traits, _Allocator>::back() const
2973{
2974#ifdef _LIBCPP_DEBUG
2975 assert(!empty());
2976#endif
2977 return *(data() + size() - 1);
2978}
2979
2980template <class _CharT, class _Traits, class _Allocator>
2981typename basic_string<_CharT, _Traits, _Allocator>::size_type
2982basic_string<_CharT, _Traits, _Allocator>::copy(pointer __s, size_type __n, size_type __pos) const
2983{
2984 size_type __sz = size();
2985 if (__pos > __sz)
2986 this->__throw_out_of_range();
2987 size_type __rlen = _STD::min(__n, __sz - __pos);
2988 traits_type::copy(__s, data() + __pos, __rlen);
2989 return __rlen;
2990}
2991
2992template <class _CharT, class _Traits, class _Allocator>
2993_LIBCPP_INLINE_VISIBILITY inline
2994basic_string<_CharT, _Traits, _Allocator>
2995basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
2996{
2997 return basic_string(*this, __pos, __n, __alloc());
2998}
2999
3000template <class _CharT, class _Traits, class _Allocator>
3001_LIBCPP_INLINE_VISIBILITY inline
3002void
3003basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003004 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3005 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003006{
Howard Hinnante32b5e22010-11-17 17:55:08 +00003007 _STD::swap(__r_.first(), __str.__r_.first());
3008 __swap_alloc(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003009#ifdef _LIBCPP_DEBUG
3010 __invalidate_all_iterators();
3011 __str.__invalidate_all_iterators();
Howard Hinnant324bb032010-08-22 00:02:43 +00003012#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003013}
3014
3015// find
3016
3017template <class _Traits>
3018struct _LIBCPP_HIDDEN __traits_eq
3019{
3020 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003021 _LIBCPP_INLINE_VISIBILITY
3022 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3023 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003024};
3025
3026template<class _CharT, class _Traits, class _Allocator>
3027typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003028basic_string<_CharT, _Traits, _Allocator>::find(const_pointer __s,
3029 size_type __pos,
3030 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003031{
3032#ifdef _LIBCPP_DEBUG
3033 assert(__s != 0);
3034#endif
3035 size_type __sz = size();
3036 if (__pos > __sz || __sz - __pos < __n)
3037 return npos;
3038 if (__n == 0)
3039 return __pos;
3040 const_pointer __p = data();
Howard Hinnanta6119a82011-05-29 19:57:12 +00003041 const_pointer __r = _STD::search(__p + __pos, __p + __sz, __s, __s + __n,
3042 __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003043 if (__r == __p + __sz)
3044 return npos;
3045 return static_cast<size_type>(__r - __p);
3046}
3047
3048template<class _CharT, class _Traits, class _Allocator>
3049_LIBCPP_INLINE_VISIBILITY inline
3050typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003051basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3052 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003053{
3054 return find(__str.data(), __pos, __str.size());
3055}
3056
3057template<class _CharT, class _Traits, class _Allocator>
3058_LIBCPP_INLINE_VISIBILITY inline
3059typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003060basic_string<_CharT, _Traits, _Allocator>::find(const_pointer __s,
3061 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003062{
3063#ifdef _LIBCPP_DEBUG
3064 assert(__s != 0);
3065#endif
3066 return find(__s, __pos, traits_type::length(__s));
3067}
3068
3069template<class _CharT, class _Traits, class _Allocator>
3070typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003071basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3072 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003073{
3074 size_type __sz = size();
3075 if (__pos >= __sz)
3076 return npos;
3077 const_pointer __p = data();
3078 const_pointer __r = traits_type::find(__p + __pos, __sz - __pos, __c);
3079 if (__r == 0)
3080 return npos;
3081 return static_cast<size_type>(__r - __p);
3082}
3083
3084// rfind
3085
3086template<class _CharT, class _Traits, class _Allocator>
3087typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003088basic_string<_CharT, _Traits, _Allocator>::rfind(const_pointer __s,
3089 size_type __pos,
3090 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003091{
3092#ifdef _LIBCPP_DEBUG
3093 assert(__s != 0);
3094#endif
3095 size_type __sz = size();
3096 __pos = _STD::min(__pos, __sz);
3097 if (__n < __sz - __pos)
3098 __pos += __n;
3099 else
3100 __pos = __sz;
3101 const_pointer __p = data();
Howard Hinnanta6119a82011-05-29 19:57:12 +00003102 const_pointer __r = _STD::find_end(__p, __p + __pos, __s, __s + __n,
3103 __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003104 if (__n > 0 && __r == __p + __pos)
3105 return npos;
3106 return static_cast<size_type>(__r - __p);
3107}
3108
3109template<class _CharT, class _Traits, class _Allocator>
3110_LIBCPP_INLINE_VISIBILITY inline
3111typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003112basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3113 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003114{
3115 return rfind(__str.data(), __pos, __str.size());
3116}
3117
3118template<class _CharT, class _Traits, class _Allocator>
3119_LIBCPP_INLINE_VISIBILITY inline
3120typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003121basic_string<_CharT, _Traits, _Allocator>::rfind(const_pointer __s,
3122 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003123{
3124#ifdef _LIBCPP_DEBUG
3125 assert(__s != 0);
3126#endif
3127 return rfind(__s, __pos, traits_type::length(__s));
3128}
3129
3130template<class _CharT, class _Traits, class _Allocator>
3131typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003132basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3133 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003134{
3135 size_type __sz = size();
3136 if (__sz)
3137 {
3138 if (__pos < __sz)
3139 ++__pos;
3140 else
3141 __pos = __sz;
3142 const_pointer __p = data();
3143 for (const_pointer __ps = __p + __pos; __ps != __p;)
3144 {
3145 if (traits_type::eq(*--__ps, __c))
3146 return static_cast<size_type>(__ps - __p);
3147 }
3148 }
3149 return npos;
3150}
3151
3152// find_first_of
3153
3154template<class _CharT, class _Traits, class _Allocator>
3155typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003156basic_string<_CharT, _Traits, _Allocator>::find_first_of(const_pointer __s,
3157 size_type __pos,
3158 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003159{
3160#ifdef _LIBCPP_DEBUG
3161 assert(__s != 0);
3162#endif
3163 size_type __sz = size();
3164 if (__pos >= __sz || __n == 0)
3165 return npos;
3166 const_pointer __p = data();
Howard Hinnanta6119a82011-05-29 19:57:12 +00003167 const_pointer __r = _STD::find_first_of(__p + __pos, __p + __sz, __s,
3168 __s + __n, __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003169 if (__r == __p + __sz)
3170 return npos;
3171 return static_cast<size_type>(__r - __p);
3172}
3173
3174template<class _CharT, class _Traits, class _Allocator>
3175_LIBCPP_INLINE_VISIBILITY inline
3176typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003177basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3178 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003179{
3180 return find_first_of(__str.data(), __pos, __str.size());
3181}
3182
3183template<class _CharT, class _Traits, class _Allocator>
3184_LIBCPP_INLINE_VISIBILITY inline
3185typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003186basic_string<_CharT, _Traits, _Allocator>::find_first_of(const_pointer __s,
3187 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003188{
3189#ifdef _LIBCPP_DEBUG
3190 assert(__s != 0);
3191#endif
3192 return find_first_of(__s, __pos, traits_type::length(__s));
3193}
3194
3195template<class _CharT, class _Traits, class _Allocator>
3196_LIBCPP_INLINE_VISIBILITY inline
3197typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003198basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3199 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003200{
3201 return find(__c, __pos);
3202}
3203
3204// find_last_of
3205
3206template<class _CharT, class _Traits, class _Allocator>
3207typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003208basic_string<_CharT, _Traits, _Allocator>::find_last_of(const_pointer __s,
3209 size_type __pos,
3210 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003211{
3212#ifdef _LIBCPP_DEBUG
3213 assert(__s != 0);
3214#endif
3215 if (__n != 0)
3216 {
3217 size_type __sz = size();
3218 if (__pos < __sz)
3219 ++__pos;
3220 else
3221 __pos = __sz;
3222 const_pointer __p = data();
3223 for (const_pointer __ps = __p + __pos; __ps != __p;)
3224 {
3225 const_pointer __r = traits_type::find(__s, __n, *--__ps);
3226 if (__r)
3227 return static_cast<size_type>(__ps - __p);
3228 }
3229 }
3230 return npos;
3231}
3232
3233template<class _CharT, class _Traits, class _Allocator>
3234_LIBCPP_INLINE_VISIBILITY inline
3235typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003236basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3237 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003238{
3239 return find_last_of(__str.data(), __pos, __str.size());
3240}
3241
3242template<class _CharT, class _Traits, class _Allocator>
3243_LIBCPP_INLINE_VISIBILITY inline
3244typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003245basic_string<_CharT, _Traits, _Allocator>::find_last_of(const_pointer __s,
3246 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003247{
3248#ifdef _LIBCPP_DEBUG
3249 assert(__s != 0);
3250#endif
3251 return find_last_of(__s, __pos, traits_type::length(__s));
3252}
3253
3254template<class _CharT, class _Traits, class _Allocator>
3255_LIBCPP_INLINE_VISIBILITY inline
3256typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003257basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3258 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003259{
3260 return rfind(__c, __pos);
3261}
3262
3263// find_first_not_of
3264
3265template<class _CharT, class _Traits, class _Allocator>
3266typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003267basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const_pointer __s,
3268 size_type __pos,
3269 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003270{
3271#ifdef _LIBCPP_DEBUG
3272 assert(__s != 0);
3273#endif
3274 size_type __sz = size();
3275 if (__pos < __sz)
3276 {
3277 const_pointer __p = data();
3278 const_pointer __pe = __p + __sz;
3279 for (const_pointer __ps = __p + __pos; __ps != __pe; ++__ps)
3280 if (traits_type::find(__s, __n, *__ps) == 0)
3281 return static_cast<size_type>(__ps - __p);
3282 }
3283 return npos;
3284}
3285
3286template<class _CharT, class _Traits, class _Allocator>
3287_LIBCPP_INLINE_VISIBILITY inline
3288typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003289basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3290 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003291{
3292 return find_first_not_of(__str.data(), __pos, __str.size());
3293}
3294
3295template<class _CharT, class _Traits, class _Allocator>
3296_LIBCPP_INLINE_VISIBILITY inline
3297typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003298basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const_pointer __s,
3299 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003300{
3301#ifdef _LIBCPP_DEBUG
3302 assert(__s != 0);
3303#endif
3304 return find_first_not_of(__s, __pos, traits_type::length(__s));
3305}
3306
3307template<class _CharT, class _Traits, class _Allocator>
3308_LIBCPP_INLINE_VISIBILITY inline
3309typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003310basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3311 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003312{
3313 size_type __sz = size();
3314 if (__pos < __sz)
3315 {
3316 const_pointer __p = data();
3317 const_pointer __pe = __p + __sz;
3318 for (const_pointer __ps = __p + __pos; __p != __pe; ++__ps)
3319 if (!traits_type::eq(*__ps, __c))
3320 return static_cast<size_type>(__ps - __p);
3321 }
3322 return npos;
3323}
3324
3325// find_last_not_of
3326
3327template<class _CharT, class _Traits, class _Allocator>
3328typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003329basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const_pointer __s,
3330 size_type __pos,
3331 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003332{
3333#ifdef _LIBCPP_DEBUG
3334 assert(__s != 0);
3335#endif
3336 size_type __sz = size();
3337 if (__pos < __sz)
3338 ++__pos;
3339 else
3340 __pos = __sz;
3341 const_pointer __p = data();
3342 for (const_pointer __ps = __p + __pos; __ps != __p;)
3343 if (traits_type::find(__s, __n, *--__ps) == 0)
3344 return static_cast<size_type>(__ps - __p);
3345 return npos;
3346}
3347
3348template<class _CharT, class _Traits, class _Allocator>
3349_LIBCPP_INLINE_VISIBILITY inline
3350typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003351basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3352 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003353{
3354 return find_last_not_of(__str.data(), __pos, __str.size());
3355}
3356
3357template<class _CharT, class _Traits, class _Allocator>
3358_LIBCPP_INLINE_VISIBILITY inline
3359typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003360basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const_pointer __s,
3361 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003362{
3363#ifdef _LIBCPP_DEBUG
3364 assert(__s != 0);
3365#endif
3366 return find_last_not_of(__s, __pos, traits_type::length(__s));
3367}
3368
3369template<class _CharT, class _Traits, class _Allocator>
3370_LIBCPP_INLINE_VISIBILITY inline
3371typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003372basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3373 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003374{
3375 size_type __sz = size();
3376 if (__pos < __sz)
3377 ++__pos;
3378 else
3379 __pos = __sz;
3380 const_pointer __p = data();
3381 for (const_pointer __ps = __p + __pos; __ps != __p;)
3382 if (!traits_type::eq(*--__ps, __c))
3383 return static_cast<size_type>(__ps - __p);
3384 return npos;
3385}
3386
3387// compare
3388
3389template <class _CharT, class _Traits, class _Allocator>
3390_LIBCPP_INLINE_VISIBILITY inline
3391int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003392basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003393{
3394 return compare(0, npos, __str.data(), __str.size());
3395}
3396
3397template <class _CharT, class _Traits, class _Allocator>
3398_LIBCPP_INLINE_VISIBILITY inline
3399int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003400basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3401 size_type __n1,
3402 const basic_string& __str) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003403{
3404 return compare(__pos1, __n1, __str.data(), __str.size());
3405}
3406
3407template <class _CharT, class _Traits, class _Allocator>
3408int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003409basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3410 size_type __n1,
3411 const basic_string& __str,
3412 size_type __pos2,
3413 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003414{
3415 size_type __sz = __str.size();
3416 if (__pos2 > __sz)
3417 this->__throw_out_of_range();
Howard Hinnanta6119a82011-05-29 19:57:12 +00003418 return compare(__pos1, __n1, __str.data() + __pos2, _STD::min(__n2,
3419 __sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003420}
3421
3422template <class _CharT, class _Traits, class _Allocator>
3423int
3424basic_string<_CharT, _Traits, _Allocator>::compare(const_pointer __s) const
3425{
3426#ifdef _LIBCPP_DEBUG
3427 assert(__s != 0);
3428#endif
3429 return compare(0, npos, __s, traits_type::length(__s));
3430}
3431
3432template <class _CharT, class _Traits, class _Allocator>
3433int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003434basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3435 size_type __n1,
3436 const_pointer __s) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003437{
3438#ifdef _LIBCPP_DEBUG
3439 assert(__s != 0);
3440#endif
3441 return compare(__pos1, __n1, __s, traits_type::length(__s));
3442}
3443
3444template <class _CharT, class _Traits, class _Allocator>
3445int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003446basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3447 size_type __n1,
3448 const_pointer __s,
3449 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003450{
3451#ifdef _LIBCPP_DEBUG
3452 assert(__s != 0);
3453#endif
3454 size_type __sz = size();
3455 if (__pos1 > __sz || __n2 == npos)
3456 this->__throw_out_of_range();
3457 size_type __rlen = _STD::min(__n1, __sz - __pos1);
3458 int __r = traits_type::compare(data() + __pos1, __s, _STD::min(__rlen, __n2));
3459 if (__r == 0)
3460 {
3461 if (__rlen < __n2)
3462 __r = -1;
3463 else if (__rlen > __n2)
3464 __r = 1;
3465 }
3466 return __r;
3467}
3468
3469// __invariants
3470
3471template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00003472_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003473bool
3474basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3475{
3476 if (size() > capacity())
3477 return false;
3478 if (capacity() < __min_cap - 1)
3479 return false;
3480 if (data() == 0)
3481 return false;
3482 if (data()[size()] != value_type(0))
3483 return false;
3484 return true;
3485}
3486
3487// operator==
3488
3489template<class _CharT, class _Traits, class _Allocator>
3490_LIBCPP_INLINE_VISIBILITY inline
3491bool
3492operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003493 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003494{
Howard Hinnanta6119a82011-05-29 19:57:12 +00003495 return __lhs.size() == __rhs.size() && _Traits::compare(__lhs.data(),
3496 __rhs.data(),
3497 __lhs.size()) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003498}
3499
3500template<class _CharT, class _Traits, class _Allocator>
3501_LIBCPP_INLINE_VISIBILITY inline
3502bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003503operator==(const _CharT* __lhs,
3504 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003505{
3506 return __rhs.compare(__lhs) == 0;
3507}
3508
3509template<class _Allocator>
3510_LIBCPP_INLINE_VISIBILITY inline
3511bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003512operator==(const char* __lhs,
3513 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003514{
3515 return strcmp(__lhs, __rhs.data()) == 0;
3516}
3517
3518template<class _Allocator>
3519_LIBCPP_INLINE_VISIBILITY inline
3520bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003521operator==(const wchar_t* __lhs,
3522 const basic_string<wchar_t, char_traits<wchar_t>, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003523{
3524 return wcscmp(__lhs, __rhs.data()) == 0;
3525}
3526
3527template<class _CharT, class _Traits, class _Allocator>
3528_LIBCPP_INLINE_VISIBILITY inline
3529bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003530operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3531 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003532{
3533 return __lhs.compare(__rhs) == 0;
3534}
3535
3536template<class _Allocator>
3537_LIBCPP_INLINE_VISIBILITY inline
3538bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003539operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3540 const char* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003541{
3542 return strcmp(__lhs.data(), __rhs) == 0;
3543}
3544
3545template<class _Allocator>
3546_LIBCPP_INLINE_VISIBILITY inline
3547bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003548operator==(const basic_string<wchar_t, char_traits<wchar_t>, _Allocator>& __lhs,
3549 const wchar_t* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003550{
3551 return wcscmp(__lhs.data(), __rhs) == 0;
3552}
3553
3554// operator!=
3555
Howard Hinnant324bb032010-08-22 00:02:43 +00003556template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003557_LIBCPP_INLINE_VISIBILITY inline
3558bool
3559operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003560 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003561{
3562 return !(__lhs == __rhs);
3563}
3564
3565template<class _CharT, class _Traits, class _Allocator>
3566_LIBCPP_INLINE_VISIBILITY inline
3567bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003568operator!=(const _CharT* __lhs,
3569 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003570{
3571 return !(__lhs == __rhs);
3572}
3573
3574template<class _CharT, class _Traits, class _Allocator>
3575_LIBCPP_INLINE_VISIBILITY inline
3576bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003577operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3578 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003579{
3580 return !(__lhs == __rhs);
3581}
3582
3583// operator<
3584
3585template<class _CharT, class _Traits, class _Allocator>
3586_LIBCPP_INLINE_VISIBILITY inline
3587bool
3588operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003589 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003590{
3591 return __lhs.cmpare(__rhs) < 0;
3592}
3593
3594template<class _Allocator>
3595_LIBCPP_INLINE_VISIBILITY inline
3596bool
3597operator< (const basic_string<char, char_traits<char>, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003598 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003599{
3600 return strcmp(__lhs.data(), __rhs.data()) < 0;
3601}
3602
3603template<class _Allocator>
3604_LIBCPP_INLINE_VISIBILITY inline
3605bool
3606operator< (const basic_string<wchar_t, char_traits<wchar_t>, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003607 const basic_string<wchar_t, char_traits<wchar_t>, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003608{
3609 return wcscmp(__lhs.data(), __rhs.data()) < 0;
3610}
3611
3612template<class _CharT, class _Traits, class _Allocator>
3613_LIBCPP_INLINE_VISIBILITY inline
3614bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003615operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3616 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003617{
3618 return __lhs.compare(__rhs);
3619}
3620
3621template<class _Allocator>
3622_LIBCPP_INLINE_VISIBILITY inline
3623bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003624operator< (const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3625 const char* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003626{
3627 return strcmp(__lhs.data(), __rhs) < 0;
3628}
3629
3630template<class _Allocator>
3631_LIBCPP_INLINE_VISIBILITY inline
3632bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003633operator< (const basic_string<wchar_t, char_traits<wchar_t>, _Allocator>& __lhs,
3634 const wchar_t* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003635{
3636 return wcscmp(__lhs.data(), __rhs) < 0;
3637}
3638
3639template<class _CharT, class _Traits, class _Allocator>
3640_LIBCPP_INLINE_VISIBILITY inline
3641bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003642operator< (const _CharT* __lhs,
3643 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003644{
3645 return __rhs.compare(__lhs) > 0;
3646}
3647
3648template<class _Allocator>
3649_LIBCPP_INLINE_VISIBILITY inline
3650bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003651operator< (const char* __lhs,
3652 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003653{
3654 return strcmp(__lhs, __rhs.data()) < 0;
3655}
3656
3657template<class _Allocator>
3658_LIBCPP_INLINE_VISIBILITY inline
3659bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003660operator< (const wchar_t* __lhs,
3661 const basic_string<wchar_t, char_traits<wchar_t>, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003662{
3663 return wcscmp(__lhs, __rhs.data()) < 0;
3664}
3665
3666// operator>
3667
3668template<class _CharT, class _Traits, class _Allocator>
3669_LIBCPP_INLINE_VISIBILITY inline
3670bool
3671operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003672 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003673{
3674 return __rhs < __lhs;
3675}
3676
3677template<class _CharT, class _Traits, class _Allocator>
3678_LIBCPP_INLINE_VISIBILITY inline
3679bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003680operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3681 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003682{
3683 return __rhs < __lhs;
3684}
3685
3686template<class _CharT, class _Traits, class _Allocator>
3687_LIBCPP_INLINE_VISIBILITY inline
3688bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003689operator> (const _CharT* __lhs,
3690 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003691{
3692 return __rhs < __lhs;
3693}
3694
3695// operator<=
3696
3697template<class _CharT, class _Traits, class _Allocator>
3698_LIBCPP_INLINE_VISIBILITY inline
3699bool
3700operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003701 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003702{
3703 return !(__rhs < __lhs);
3704}
3705
3706template<class _CharT, class _Traits, class _Allocator>
3707_LIBCPP_INLINE_VISIBILITY inline
3708bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003709operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3710 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003711{
3712 return !(__rhs < __lhs);
3713}
3714
3715template<class _CharT, class _Traits, class _Allocator>
3716_LIBCPP_INLINE_VISIBILITY inline
3717bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003718operator<=(const _CharT* __lhs,
3719 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003720{
3721 return !(__rhs < __lhs);
3722}
3723
3724// operator>=
3725
3726template<class _CharT, class _Traits, class _Allocator>
3727_LIBCPP_INLINE_VISIBILITY inline
3728bool
3729operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003730 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003731{
3732 return !(__lhs < __rhs);
3733}
3734
3735template<class _CharT, class _Traits, class _Allocator>
3736_LIBCPP_INLINE_VISIBILITY inline
3737bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003738operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3739 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003740{
3741 return !(__lhs < __rhs);
3742}
3743
3744template<class _CharT, class _Traits, class _Allocator>
3745_LIBCPP_INLINE_VISIBILITY inline
3746bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003747operator>=(const _CharT* __lhs,
3748 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003749{
3750 return !(__lhs < __rhs);
3751}
3752
3753// operator +
3754
3755template<class _CharT, class _Traits, class _Allocator>
3756basic_string<_CharT, _Traits, _Allocator>
3757operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3758 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3759{
3760 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3761 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3762 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3763 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3764 __r.append(__rhs.data(), __rhs_sz);
3765 return __r;
3766}
3767
3768template<class _CharT, class _Traits, class _Allocator>
3769basic_string<_CharT, _Traits, _Allocator>
3770operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3771{
3772 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3773 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3774 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3775 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3776 __r.append(__rhs.data(), __rhs_sz);
3777 return __r;
3778}
3779
3780template<class _CharT, class _Traits, class _Allocator>
3781basic_string<_CharT, _Traits, _Allocator>
3782operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3783{
3784 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3785 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3786 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3787 __r.append(__rhs.data(), __rhs_sz);
3788 return __r;
3789}
3790
3791template<class _CharT, class _Traits, class _Allocator>
3792basic_string<_CharT, _Traits, _Allocator>
3793operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3794{
3795 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3796 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3797 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3798 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3799 __r.append(__rhs, __rhs_sz);
3800 return __r;
3801}
3802
3803template<class _CharT, class _Traits, class _Allocator>
3804basic_string<_CharT, _Traits, _Allocator>
3805operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3806{
3807 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3808 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3809 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3810 __r.push_back(__rhs);
3811 return __r;
3812}
3813
Howard Hinnant73d21a42010-09-04 23:28:19 +00003814#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003815
3816template<class _CharT, class _Traits, class _Allocator>
3817_LIBCPP_INLINE_VISIBILITY inline
3818basic_string<_CharT, _Traits, _Allocator>
3819operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3820{
3821 return _STD::move(__lhs.append(__rhs));
3822}
3823
3824template<class _CharT, class _Traits, class _Allocator>
3825_LIBCPP_INLINE_VISIBILITY inline
3826basic_string<_CharT, _Traits, _Allocator>
3827operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3828{
3829 return _STD::move(__rhs.insert(0, __lhs));
3830}
3831
3832template<class _CharT, class _Traits, class _Allocator>
3833_LIBCPP_INLINE_VISIBILITY inline
3834basic_string<_CharT, _Traits, _Allocator>
3835operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3836{
3837 return _STD::move(__lhs.append(__rhs));
3838}
3839
3840template<class _CharT, class _Traits, class _Allocator>
3841_LIBCPP_INLINE_VISIBILITY inline
3842basic_string<_CharT, _Traits, _Allocator>
3843operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3844{
3845 return _STD::move(__rhs.insert(0, __lhs));
3846}
3847
3848template<class _CharT, class _Traits, class _Allocator>
3849_LIBCPP_INLINE_VISIBILITY inline
3850basic_string<_CharT, _Traits, _Allocator>
3851operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3852{
3853 __rhs.insert(__rhs.begin(), __lhs);
3854 return _STD::move(__rhs);
3855}
3856
3857template<class _CharT, class _Traits, class _Allocator>
3858_LIBCPP_INLINE_VISIBILITY inline
3859basic_string<_CharT, _Traits, _Allocator>
3860operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3861{
3862 return _STD::move(__lhs.append(__rhs));
3863}
3864
3865template<class _CharT, class _Traits, class _Allocator>
3866_LIBCPP_INLINE_VISIBILITY inline
3867basic_string<_CharT, _Traits, _Allocator>
3868operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3869{
3870 __lhs.push_back(__rhs);
3871 return _STD::move(__lhs);
3872}
3873
Howard Hinnant73d21a42010-09-04 23:28:19 +00003874#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003875
3876// swap
3877
3878template<class _CharT, class _Traits, class _Allocator>
3879_LIBCPP_INLINE_VISIBILITY inline
3880void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003881swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003882 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3883 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003884{
3885 __lhs.swap(__rhs);
3886}
3887
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003888#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3889
3890typedef basic_string<char16_t> u16string;
3891typedef basic_string<char32_t> u32string;
3892
Howard Hinnant324bb032010-08-22 00:02:43 +00003893#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003894
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003895int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3896long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3897unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3898long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
3899unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
3900
3901float stof (const string& __str, size_t* __idx = 0);
3902double stod (const string& __str, size_t* __idx = 0);
3903long double stold(const string& __str, size_t* __idx = 0);
3904
3905string to_string(int __val);
3906string to_string(unsigned __val);
3907string to_string(long __val);
3908string to_string(unsigned long __val);
3909string to_string(long long __val);
3910string to_string(unsigned long long __val);
3911string to_string(float __val);
3912string to_string(double __val);
3913string to_string(long double __val);
3914
3915int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
3916long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
3917unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
3918long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
3919unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
3920
3921float stof (const wstring& __str, size_t* __idx = 0);
3922double stod (const wstring& __str, size_t* __idx = 0);
3923long double stold(const wstring& __str, size_t* __idx = 0);
3924
3925wstring to_wstring(int __val);
3926wstring to_wstring(unsigned __val);
3927wstring to_wstring(long __val);
3928wstring to_wstring(unsigned long __val);
3929wstring to_wstring(long long __val);
3930wstring to_wstring(unsigned long long __val);
3931wstring to_wstring(float __val);
3932wstring to_wstring(double __val);
3933wstring to_wstring(long double __val);
3934
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003935template<class _CharT, class _Traits, class _Allocator>
3936 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
3937 basic_string<_CharT, _Traits, _Allocator>::npos;
3938
3939template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant8d7a9552010-09-23 17:31:07 +00003940struct _LIBCPP_VISIBLE hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003941 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
3942{
3943 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00003944 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003945};
3946
3947template<class _CharT, class _Traits, class _Allocator>
3948size_t
3949hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00003950 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003951{
3952 typedef basic_string<_CharT, _Traits, _Allocator> S;
3953 typedef typename S::const_pointer const_pointer;
3954 size_t __r = 0;
3955 const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
3956 const size_t __m = size_t(0xF) << (__sr + 4);
3957 const_pointer __p = __val.data();
3958 const_pointer __e = __p + __val.size();
3959 for (; __p != __e; ++__p)
3960 {
3961 __r = (__r << 4) + *__p;
3962 size_t __g = __r & __m;
3963 __r ^= __g | (__g >> __sr);
3964 }
3965 return __r;
3966}
3967
3968extern template class basic_string<char>;
3969extern template class basic_string<wchar_t>;
3970
3971extern template
3972 enable_if<__is_forward_iterator<char const*>::value, void>::type
3973 basic_string<char, char_traits<char>, allocator<char> >::
3974 __init<char const*>(char const*, char const*);
3975
3976extern template
3977 enable_if<__is_forward_iterator<wchar_t const*>::value, void>::type
3978 basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >::
3979 __init<wchar_t const*>(wchar_t const*, wchar_t const*);
3980
3981extern template
3982 enable_if<__is_forward_iterator<char*>::value,
3983 basic_string<char, char_traits<char>, allocator<char> >&>::type
3984 basic_string<char, char_traits<char>, allocator<char> >::
3985 append<char*>(char*, char*);
3986
3987extern template
3988 enable_if<__is_forward_iterator<wchar_t*>::value,
3989 basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&>::type
3990 basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >::
3991 append<wchar_t*>(wchar_t*, wchar_t*);
3992
3993extern template
3994 enable_if<__is_forward_iterator<char const*>::value,
3995 string::iterator>::type
3996 string::
3997 insert<char const*>(string::const_iterator, char const*, char const*);
3998
3999extern template
4000 enable_if<__is_forward_iterator<wchar_t const*>::value,
4001 wstring::iterator>::type
4002 wstring::
4003 insert<wchar_t const*>(wstring::const_iterator, wchar_t const*, wchar_t const*);
4004
4005extern template
4006 enable_if<__is_input_iterator<char const*>::value, string&>::type
4007 string::
Howard Hinnant7b2cb482010-11-17 21:11:40 +00004008 replace<char const*>(string::const_iterator, string::const_iterator, char const*, char const*);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004009
4010extern template
4011 enable_if<__is_input_iterator<wchar_t const*>::value, wstring&>::type
4012 wstring::
Howard Hinnant7b2cb482010-11-17 21:11:40 +00004013 replace<wchar_t const*>(wstring::const_iterator, wstring::const_iterator, wchar_t const*, wchar_t const*);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004014
4015extern template
4016 enable_if<__is_forward_iterator<wchar_t*>::value, wstring&>::type
4017 wstring::assign<wchar_t*>(wchar_t*, wchar_t*);
4018
4019extern template
4020 string
4021 operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
4022
4023_LIBCPP_END_NAMESPACE_STD
4024
4025#endif // _LIBCPP_STRING