blob: c99eaeaebe3389fdd3d75b60dc447fb0b3258aef [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- string -----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_STRING
12#define _LIBCPP_STRING
13
14/*
15 string synopsis
16
17namespace std
18{
19
20template <class stateT>
21class fpos
22{
23private:
24 stateT st;
25public:
26 fpos(streamoff = streamoff());
27
28 operator streamoff() const;
29
30 stateT state() const;
31 void state(stateT);
32
33 fpos& operator+=(streamoff);
34 fpos operator+ (streamoff) const;
35 fpos& operator-=(streamoff);
36 fpos operator- (streamoff) const;
37};
38
39template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
40
41template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
42template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
43
44template <class charT>
45struct char_traits
46{
47 typedef charT char_type;
48 typedef ... int_type;
49 typedef streamoff off_type;
50 typedef streampos pos_type;
51 typedef mbstate_t state_type;
52
Howard Hinnanta6119a82011-05-29 19:57:12 +000053 static void assign(char_type& c1, const char_type& c2) noexcept;
Howard Hinnant03d71812012-07-20 19:09:12 +000054 static constexpr bool eq(char_type c1, char_type c2) noexcept;
55 static constexpr bool lt(char_type c1, char_type c2) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056
57 static int compare(const char_type* s1, const char_type* s2, size_t n);
58 static size_t length(const char_type* s);
59 static const char_type* find(const char_type* s, size_t n, const char_type& a);
60 static char_type* move(char_type* s1, const char_type* s2, size_t n);
61 static char_type* copy(char_type* s1, const char_type* s2, size_t n);
62 static char_type* assign(char_type* s, size_t n, char_type a);
63
Howard Hinnant03d71812012-07-20 19:09:12 +000064 static constexpr int_type not_eof(int_type c) noexcept;
65 static constexpr char_type to_char_type(int_type c) noexcept;
66 static constexpr int_type to_int_type(char_type c) noexcept;
67 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
68 static constexpr int_type eof() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000069};
70
71template <> struct char_traits<char>;
72template <> struct char_traits<wchar_t>;
73
Howard Hinnant324bb032010-08-22 00:02:43 +000074template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000075class basic_string
76{
Howard Hinnant324bb032010-08-22 00:02:43 +000077public:
78// types:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000079 typedef traits traits_type;
80 typedef typename traits_type::char_type value_type;
81 typedef Allocator allocator_type;
82 typedef typename allocator_type::size_type size_type;
83 typedef typename allocator_type::difference_type difference_type;
84 typedef typename allocator_type::reference reference;
85 typedef typename allocator_type::const_reference const_reference;
86 typedef typename allocator_type::pointer pointer;
87 typedef typename allocator_type::const_pointer const_pointer;
88 typedef implementation-defined iterator;
89 typedef implementation-defined const_iterator;
90 typedef std::reverse_iterator<iterator> reverse_iterator;
91 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
92
93 static const size_type npos = -1;
94
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000095 basic_string()
96 noexcept(is_nothrow_default_constructible<allocator_type>::value);
97 explicit basic_string(const allocator_type& a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000098 basic_string(const basic_string& str);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000099 basic_string(basic_string&& str)
100 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000101 basic_string(const basic_string& str, size_type pos, size_type n = npos,
102 const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000103 basic_string(const_pointer s, const allocator_type& a = allocator_type());
104 basic_string(const_pointer s, size_type n, const allocator_type& a = allocator_type());
105 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
106 template<class InputIterator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000107 basic_string(InputIterator begin, InputIterator end,
108 const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000109 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
110 basic_string(const basic_string&, const Allocator&);
111 basic_string(basic_string&&, const Allocator&);
112
113 ~basic_string();
114
115 basic_string& operator=(const basic_string& str);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000116 basic_string& operator=(basic_string&& str)
117 noexcept(
118 allocator_type::propagate_on_container_move_assignment::value &&
119 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120 basic_string& operator=(const_pointer s);
121 basic_string& operator=(value_type c);
122 basic_string& operator=(initializer_list<value_type>);
123
Howard Hinnanta6119a82011-05-29 19:57:12 +0000124 iterator begin() noexcept;
125 const_iterator begin() const noexcept;
126 iterator end() noexcept;
127 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000128
Howard Hinnanta6119a82011-05-29 19:57:12 +0000129 reverse_iterator rbegin() noexcept;
130 const_reverse_iterator rbegin() const noexcept;
131 reverse_iterator rend() noexcept;
132 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000133
Howard Hinnanta6119a82011-05-29 19:57:12 +0000134 const_iterator cbegin() const noexcept;
135 const_iterator cend() const noexcept;
136 const_reverse_iterator crbegin() const noexcept;
137 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000138
Howard Hinnanta6119a82011-05-29 19:57:12 +0000139 size_type size() const noexcept;
140 size_type length() const noexcept;
141 size_type max_size() const noexcept;
142 size_type capacity() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000143
144 void resize(size_type n, value_type c);
145 void resize(size_type n);
146
147 void reserve(size_type res_arg = 0);
148 void shrink_to_fit();
Howard Hinnanta6119a82011-05-29 19:57:12 +0000149 void clear() noexcept;
150 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000151
152 const_reference operator[](size_type pos) const;
153 reference operator[](size_type pos);
154
155 const_reference at(size_type n) const;
156 reference at(size_type n);
157
158 basic_string& operator+=(const basic_string& str);
159 basic_string& operator+=(const_pointer s);
160 basic_string& operator+=(value_type c);
161 basic_string& operator+=(initializer_list<value_type>);
162
163 basic_string& append(const basic_string& str);
164 basic_string& append(const basic_string& str, size_type pos, size_type n);
165 basic_string& append(const_pointer s, size_type n);
166 basic_string& append(const_pointer s);
167 basic_string& append(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000168 template<class InputIterator>
169 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000170 basic_string& append(initializer_list<value_type>);
171
172 void push_back(value_type c);
173 void pop_back();
174 reference front();
175 const_reference front() const;
176 reference back();
177 const_reference back() const;
178
179 basic_string& assign(const basic_string& str);
Howard Hinnanta6119a82011-05-29 19:57:12 +0000180 basic_string& assign(basic_string&& str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000181 basic_string& assign(const basic_string& str, size_type pos, size_type n);
182 basic_string& assign(const_pointer s, size_type n);
183 basic_string& assign(const_pointer s);
184 basic_string& assign(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000185 template<class InputIterator>
186 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000187 basic_string& assign(initializer_list<value_type>);
188
189 basic_string& insert(size_type pos1, const basic_string& str);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000190 basic_string& insert(size_type pos1, const basic_string& str,
191 size_type pos2, size_type n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000192 basic_string& insert(size_type pos, const_pointer s, size_type n);
193 basic_string& insert(size_type pos, const_pointer s);
194 basic_string& insert(size_type pos, size_type n, value_type c);
195 iterator insert(const_iterator p, value_type c);
196 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000197 template<class InputIterator>
198 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000199 iterator insert(const_iterator p, initializer_list<value_type>);
200
201 basic_string& erase(size_type pos = 0, size_type n = npos);
202 iterator erase(const_iterator position);
203 iterator erase(const_iterator first, const_iterator last);
204
205 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000206 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
207 size_type pos2, size_type n2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000208 basic_string& replace(size_type pos, size_type n1, const_pointer s, size_type n2);
209 basic_string& replace(size_type pos, size_type n1, const_pointer s);
210 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000211 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
212 basic_string& replace(const_iterator i1, const_iterator i2, const_pointer s, size_type n);
213 basic_string& replace(const_iterator i1, const_iterator i2, const_pointer s);
214 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000215 template<class InputIterator>
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000216 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
217 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000218
219 size_type copy(pointer s, size_type n, size_type pos = 0) const;
220 basic_string substr(size_type pos = 0, size_type n = npos) const;
221
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000222 void swap(basic_string& str)
223 noexcept(!allocator_type::propagate_on_container_swap::value ||
224 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000225
Howard Hinnanta6119a82011-05-29 19:57:12 +0000226 const_pointer c_str() const noexcept;
227 const_pointer data() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000228
Howard Hinnanta6119a82011-05-29 19:57:12 +0000229 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000230
Howard Hinnanta6119a82011-05-29 19:57:12 +0000231 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
232 size_type find(const_pointer s, size_type pos, size_type n) const noexcept;
233 size_type find(const_pointer s, size_type pos = 0) const noexcept;
234 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000235
Howard Hinnanta6119a82011-05-29 19:57:12 +0000236 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
237 size_type rfind(const_pointer s, size_type pos, size_type n) const noexcept;
238 size_type rfind(const_pointer s, size_type pos = npos) const noexcept;
239 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000240
Howard Hinnanta6119a82011-05-29 19:57:12 +0000241 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
242 size_type find_first_of(const_pointer s, size_type pos, size_type n) const noexcept;
243 size_type find_first_of(const_pointer s, size_type pos = 0) const noexcept;
244 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000245
Howard Hinnanta6119a82011-05-29 19:57:12 +0000246 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
247 size_type find_last_of(const_pointer s, size_type pos, size_type n) const noexcept;
248 size_type find_last_of(const_pointer s, size_type pos = npos) const noexcept;
249 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000250
Howard Hinnanta6119a82011-05-29 19:57:12 +0000251 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
252 size_type find_first_not_of(const_pointer s, size_type pos, size_type n) const noexcept;
253 size_type find_first_not_of(const_pointer s, size_type pos = 0) const noexcept;
254 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000255
Howard Hinnanta6119a82011-05-29 19:57:12 +0000256 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
257 size_type find_last_not_of(const_pointer s, size_type pos, size_type n) const noexcept;
258 size_type find_last_not_of(const_pointer s, size_type pos = npos) const noexcept;
259 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000260
Howard Hinnanta6119a82011-05-29 19:57:12 +0000261 int compare(const basic_string& str) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000262 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000263 int compare(size_type pos1, size_type n1, const basic_string& str,
264 size_type pos2, size_type n2) const;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000265 int compare(const_pointer s) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000266 int compare(size_type pos1, size_type n1, const_pointer s) const;
267 int compare(size_type pos1, size_type n1, const_pointer s, size_type n2) const;
268
269 bool __invariants() const;
270};
271
272template<class charT, class traits, class Allocator>
273basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000274operator+(const basic_string<charT, traits, Allocator>& lhs,
275 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276
277template<class charT, class traits, class Allocator>
278basic_string<charT, traits, Allocator>
279operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
280
281template<class charT, class traits, class Allocator>
282basic_string<charT, traits, Allocator>
283operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
284
285template<class charT, class traits, class Allocator>
286basic_string<charT, traits, Allocator>
287operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
288
289template<class charT, class traits, class Allocator>
290basic_string<charT, traits, Allocator>
291operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
292
293template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000294bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000295 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296
297template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000298bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000299
300template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000301bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000302
Howard Hinnant324bb032010-08-22 00:02:43 +0000303template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000304bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000305 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000306
307template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000308bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000309
310template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000311bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000312
313template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000314bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000315 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000316
317template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000318bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000319
320template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000321bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000322
323template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000324bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000325 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000326
327template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000328bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000329
330template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000331bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000332
333template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000334bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000335 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000336
337template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000338bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000339
340template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000341bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000342
343template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000344bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000345 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000346
347template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000348bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000349
350template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000351bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000352
353template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000354void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000355 basic_string<charT, traits, Allocator>& rhs)
356 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000357
358template<class charT, class traits, class Allocator>
359basic_istream<charT, traits>&
360operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
361
362template<class charT, class traits, class Allocator>
363basic_ostream<charT, traits>&
364operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
365
366template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000367basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000368getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
369 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000370
371template<class charT, class traits, class Allocator>
372basic_istream<charT, traits>&
373getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
374
375typedef basic_string<char> string;
376typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000377typedef basic_string<char16_t> u16string;
378typedef basic_string<char32_t> u32string;
379
380int stoi (const string& str, size_t* idx = 0, int base = 10);
381long stol (const string& str, size_t* idx = 0, int base = 10);
382unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
383long long stoll (const string& str, size_t* idx = 0, int base = 10);
384unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
385
386float stof (const string& str, size_t* idx = 0);
387double stod (const string& str, size_t* idx = 0);
388long double stold(const string& str, size_t* idx = 0);
389
390string to_string(int val);
391string to_string(unsigned val);
392string to_string(long val);
393string to_string(unsigned long val);
394string to_string(long long val);
395string to_string(unsigned long long val);
396string to_string(float val);
397string to_string(double val);
398string to_string(long double val);
399
400int stoi (const wstring& str, size_t* idx = 0, int base = 10);
401long stol (const wstring& str, size_t* idx = 0, int base = 10);
402unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
403long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
404unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
405
406float stof (const wstring& str, size_t* idx = 0);
407double stod (const wstring& str, size_t* idx = 0);
408long double stold(const wstring& str, size_t* idx = 0);
409
410wstring to_wstring(int val);
411wstring to_wstring(unsigned val);
412wstring to_wstring(long val);
413wstring to_wstring(unsigned long val);
414wstring to_wstring(long long val);
415wstring to_wstring(unsigned long long val);
416wstring to_wstring(float val);
417wstring to_wstring(double val);
418wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419
420template <> struct hash<string>;
421template <> struct hash<u16string>;
422template <> struct hash<u32string>;
423template <> struct hash<wstring>;
424
425} // std
426
427*/
428
429#include <__config>
430#include <iosfwd>
431#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000432#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433#include <cwchar>
434#include <algorithm>
435#include <iterator>
436#include <utility>
437#include <memory>
438#include <stdexcept>
439#include <type_traits>
440#include <initializer_list>
441#include <__functional_base>
442#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
443#include <cstdint>
444#endif
445#if defined(_LIBCPP_NO_EXCEPTIONS) || defined(_LIBCPP_DEBUG)
446#include <cassert>
447#endif
448
Howard Hinnant66c6f972011-11-29 16:45:27 +0000449#include <__undef_min_max>
450
Howard Hinnant08e17472011-10-17 20:05:10 +0000451#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000452#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000453#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000454
455_LIBCPP_BEGIN_NAMESPACE_STD
456
457// fpos
458
459template <class _StateT>
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000460class _LIBCPP_VISIBLE fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000461{
462private:
463 _StateT __st_;
464 streamoff __off_;
465public:
466 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
467
468 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
469
470 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
471 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
472
473 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
474 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
475 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
476 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
477};
478
479template <class _StateT>
480inline _LIBCPP_INLINE_VISIBILITY
481streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
482 {return streamoff(__x) - streamoff(__y);}
483
484template <class _StateT>
485inline _LIBCPP_INLINE_VISIBILITY
486bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
487 {return streamoff(__x) == streamoff(__y);}
488
489template <class _StateT>
490inline _LIBCPP_INLINE_VISIBILITY
491bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
492 {return streamoff(__x) != streamoff(__y);}
493
494// char_traits
495
496template <class _CharT>
Howard Hinnant36cdf022010-09-10 16:42:26 +0000497struct _LIBCPP_VISIBLE char_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000498{
499 typedef _CharT char_type;
500 typedef int int_type;
501 typedef streamoff off_type;
502 typedef streampos pos_type;
503 typedef mbstate_t state_type;
504
Howard Hinnanta6119a82011-05-29 19:57:12 +0000505 _LIBCPP_INLINE_VISIBILITY
506 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
507 {__c1 = __c2;}
508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000509 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000510 {return __c1 == __c2;}
511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000512 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000513 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000514
515 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
516 static size_t length(const char_type* __s);
517 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
518 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
519 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
520 static char_type* assign(char_type* __s, size_t __n, char_type __a);
521
Howard Hinnant03d71812012-07-20 19:09:12 +0000522 _LIBCPP_INLINE_VISIBILITY
523 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000526 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000527 {return char_type(__c);}
528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000529 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000530 {return int_type(__c);}
531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000532 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000534 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000535 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000536 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000537};
538
539template <class _CharT>
540int
541char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
542{
543 for (; __n; --__n, ++__s1, ++__s2)
544 {
545 if (lt(*__s1, *__s2))
546 return -1;
547 if (lt(*__s2, *__s1))
548 return 1;
549 }
550 return 0;
551}
552
553template <class _CharT>
554inline _LIBCPP_INLINE_VISIBILITY
555size_t
556char_traits<_CharT>::length(const char_type* __s)
557{
558 size_t __len = 0;
559 for (; !eq(*__s, char_type(0)); ++__s)
560 ++__len;
561 return __len;
562}
563
564template <class _CharT>
565inline _LIBCPP_INLINE_VISIBILITY
566const _CharT*
567char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
568{
569 for (; __n; --__n)
570 {
571 if (eq(*__s, __a))
572 return __s;
573 ++__s;
574 }
575 return 0;
576}
577
578template <class _CharT>
579_CharT*
580char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
581{
582 char_type* __r = __s1;
583 if (__s1 < __s2)
584 {
585 for (; __n; --__n, ++__s1, ++__s2)
586 assign(*__s1, *__s2);
587 }
588 else if (__s2 < __s1)
589 {
590 __s1 += __n;
591 __s2 += __n;
592 for (; __n; --__n)
593 assign(*--__s1, *--__s2);
594 }
595 return __r;
596}
597
598template <class _CharT>
599inline _LIBCPP_INLINE_VISIBILITY
600_CharT*
601char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
602{
603 char_type* __r = __s1;
604 for (; __n; --__n, ++__s1, ++__s2)
605 assign(*__s1, *__s2);
606 return __r;
607}
608
609template <class _CharT>
610inline _LIBCPP_INLINE_VISIBILITY
611_CharT*
612char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
613{
614 char_type* __r = __s;
615 for (; __n; --__n, ++__s)
616 assign(*__s, __a);
617 return __r;
618}
619
620// char_traits<char>
621
622template <>
Howard Hinnant36cdf022010-09-10 16:42:26 +0000623struct _LIBCPP_VISIBLE char_traits<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000624{
625 typedef char char_type;
626 typedef int int_type;
627 typedef streamoff off_type;
628 typedef streampos pos_type;
629 typedef mbstate_t state_type;
630
Howard Hinnanta6119a82011-05-29 19:57:12 +0000631 _LIBCPP_INLINE_VISIBILITY
632 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
633 {__c1 = __c2;}
634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000635 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000636 {return __c1 == __c2;}
637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000638 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000639 {return (unsigned char)__c1 < (unsigned char)__c2;}
640
Howard Hinnanta6119a82011-05-29 19:57:12 +0000641 _LIBCPP_INLINE_VISIBILITY
642 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643 {return memcmp(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000644 _LIBCPP_INLINE_VISIBILITY
645 static size_t length(const char_type* __s) {return strlen(__s);}
646 _LIBCPP_INLINE_VISIBILITY
647 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000648 {return (const char_type*)memchr(__s, to_int_type(__a), __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000649 _LIBCPP_INLINE_VISIBILITY
650 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000651 {return (char_type*)memmove(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000652 _LIBCPP_INLINE_VISIBILITY
653 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000654 {return (char_type*)memcpy(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000655 _LIBCPP_INLINE_VISIBILITY
656 static char_type* assign(char_type* __s, size_t __n, char_type __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657 {return (char_type*)memset(__s, to_int_type(__a), __n);}
658
Howard Hinnant03d71812012-07-20 19:09:12 +0000659 _LIBCPP_INLINE_VISIBILITY
660 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000663 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000664 {return char_type(__c);}
665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000666 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000667 {return int_type((unsigned char)__c);}
668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000669 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000672 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000673 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000674};
675
676// char_traits<wchar_t>
677
678template <>
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000679struct _LIBCPP_VISIBLE char_traits<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680{
681 typedef wchar_t char_type;
682 typedef wint_t int_type;
683 typedef streamoff off_type;
684 typedef streampos pos_type;
685 typedef mbstate_t state_type;
686
Howard Hinnanta6119a82011-05-29 19:57:12 +0000687 _LIBCPP_INLINE_VISIBILITY
688 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
689 {__c1 = __c2;}
690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000691 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000692 {return __c1 == __c2;}
693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000694 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000695 {return __c1 < __c2;}
696
Howard Hinnanta6119a82011-05-29 19:57:12 +0000697 _LIBCPP_INLINE_VISIBILITY
698 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000699 {return wmemcmp(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000700 _LIBCPP_INLINE_VISIBILITY
701 static size_t length(const char_type* __s)
702 {return wcslen(__s);}
703 _LIBCPP_INLINE_VISIBILITY
704 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705 {return (const char_type*)wmemchr(__s, __a, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000706 _LIBCPP_INLINE_VISIBILITY
707 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708 {return (char_type*)wmemmove(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000709 _LIBCPP_INLINE_VISIBILITY
710 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711 {return (char_type*)wmemcpy(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000712 _LIBCPP_INLINE_VISIBILITY
713 static char_type* assign(char_type* __s, size_t __n, char_type __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714 {return (char_type*)wmemset(__s, __a, __n);}
715
Howard Hinnanta6119a82011-05-29 19:57:12 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000717 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000718 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000720 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000721 {return char_type(__c);}
722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000723 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000724 {return int_type(__c);}
725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000726 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000727 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000728 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000729 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000730 {return int_type(WEOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000731};
732
733#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
734
735template <>
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000736struct _LIBCPP_VISIBLE char_traits<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000737{
738 typedef char16_t char_type;
739 typedef uint_least16_t int_type;
740 typedef streamoff off_type;
741 typedef u16streampos pos_type;
742 typedef mbstate_t state_type;
743
Howard Hinnanta6119a82011-05-29 19:57:12 +0000744 _LIBCPP_INLINE_VISIBILITY
745 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
746 {__c1 = __c2;}
747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000748 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000749 {return __c1 == __c2;}
750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000751 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000752 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000753
754 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
755 static size_t length(const char_type* __s);
756 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
757 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
758 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
759 static char_type* assign(char_type* __s, size_t __n, char_type __a);
760
Howard Hinnanta6119a82011-05-29 19:57:12 +0000761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000762 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000763 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000765 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000766 {return char_type(__c);}
767 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000768 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000769 {return int_type(__c);}
770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000771 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000772 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000774 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000775 {return int_type(0xDFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000776};
777
778inline _LIBCPP_INLINE_VISIBILITY
779int
780char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
781{
782 for (; __n; --__n, ++__s1, ++__s2)
783 {
784 if (lt(*__s1, *__s2))
785 return -1;
786 if (lt(*__s2, *__s1))
787 return 1;
788 }
789 return 0;
790}
791
792inline _LIBCPP_INLINE_VISIBILITY
793size_t
794char_traits<char16_t>::length(const char_type* __s)
795{
796 size_t __len = 0;
797 for (; !eq(*__s, char_type(0)); ++__s)
798 ++__len;
799 return __len;
800}
801
802inline _LIBCPP_INLINE_VISIBILITY
803const char16_t*
804char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
805{
806 for (; __n; --__n)
807 {
808 if (eq(*__s, __a))
809 return __s;
810 ++__s;
811 }
812 return 0;
813}
814
815inline _LIBCPP_INLINE_VISIBILITY
816char16_t*
817char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
818{
819 char_type* __r = __s1;
820 if (__s1 < __s2)
821 {
822 for (; __n; --__n, ++__s1, ++__s2)
823 assign(*__s1, *__s2);
824 }
825 else if (__s2 < __s1)
826 {
827 __s1 += __n;
828 __s2 += __n;
829 for (; __n; --__n)
830 assign(*--__s1, *--__s2);
831 }
832 return __r;
833}
834
835inline _LIBCPP_INLINE_VISIBILITY
836char16_t*
837char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
838{
839 char_type* __r = __s1;
840 for (; __n; --__n, ++__s1, ++__s2)
841 assign(*__s1, *__s2);
842 return __r;
843}
844
845inline _LIBCPP_INLINE_VISIBILITY
846char16_t*
847char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
848{
849 char_type* __r = __s;
850 for (; __n; --__n, ++__s)
851 assign(*__s, __a);
852 return __r;
853}
854
855template <>
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000856struct _LIBCPP_VISIBLE char_traits<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857{
858 typedef char32_t char_type;
859 typedef uint_least32_t int_type;
860 typedef streamoff off_type;
861 typedef u32streampos pos_type;
862 typedef mbstate_t state_type;
863
Howard Hinnanta6119a82011-05-29 19:57:12 +0000864 _LIBCPP_INLINE_VISIBILITY
865 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
866 {__c1 = __c2;}
867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000868 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000869 {return __c1 == __c2;}
870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000871 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000872 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873
874 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
875 static size_t length(const char_type* __s);
876 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
877 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
878 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
879 static char_type* assign(char_type* __s, size_t __n, char_type __a);
880
Howard Hinnanta6119a82011-05-29 19:57:12 +0000881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000882 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000883 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000884 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000885 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000886 {return char_type(__c);}
887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000888 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000889 {return int_type(__c);}
890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000891 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000892 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000894 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000895 {return int_type(0xFFFFFFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896};
897
898inline _LIBCPP_INLINE_VISIBILITY
899int
900char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
901{
902 for (; __n; --__n, ++__s1, ++__s2)
903 {
904 if (lt(*__s1, *__s2))
905 return -1;
906 if (lt(*__s2, *__s1))
907 return 1;
908 }
909 return 0;
910}
911
912inline _LIBCPP_INLINE_VISIBILITY
913size_t
914char_traits<char32_t>::length(const char_type* __s)
915{
916 size_t __len = 0;
917 for (; !eq(*__s, char_type(0)); ++__s)
918 ++__len;
919 return __len;
920}
921
922inline _LIBCPP_INLINE_VISIBILITY
923const char32_t*
924char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
925{
926 for (; __n; --__n)
927 {
928 if (eq(*__s, __a))
929 return __s;
930 ++__s;
931 }
932 return 0;
933}
934
935inline _LIBCPP_INLINE_VISIBILITY
936char32_t*
937char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
938{
939 char_type* __r = __s1;
940 if (__s1 < __s2)
941 {
942 for (; __n; --__n, ++__s1, ++__s2)
943 assign(*__s1, *__s2);
944 }
945 else if (__s2 < __s1)
946 {
947 __s1 += __n;
948 __s2 += __n;
949 for (; __n; --__n)
950 assign(*--__s1, *--__s2);
951 }
952 return __r;
953}
954
955inline _LIBCPP_INLINE_VISIBILITY
956char32_t*
957char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
958{
959 char_type* __r = __s1;
960 for (; __n; --__n, ++__s1, ++__s2)
961 assign(*__s1, *__s2);
962 return __r;
963}
964
965inline _LIBCPP_INLINE_VISIBILITY
966char32_t*
967char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
968{
969 char_type* __r = __s;
970 for (; __n; --__n, ++__s)
971 assign(*__s, __a);
972 return __r;
973}
974
Howard Hinnant324bb032010-08-22 00:02:43 +0000975#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976
977// basic_string
978
979template<class _CharT, class _Traits, class _Allocator>
980basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000981operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
982 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983
984template<class _CharT, class _Traits, class _Allocator>
985basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000986operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987
988template<class _CharT, class _Traits, class _Allocator>
989basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000990operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000991
992template<class _CharT, class _Traits, class _Allocator>
993basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000994operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000995
996template<class _CharT, class _Traits, class _Allocator>
997basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000998operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000999
1000template <bool>
1001class __basic_string_common
1002{
1003protected:
1004 void __throw_length_error() const;
1005 void __throw_out_of_range() const;
1006};
1007
1008template <bool __b>
1009void
1010__basic_string_common<__b>::__throw_length_error() const
1011{
1012#ifndef _LIBCPP_NO_EXCEPTIONS
1013 throw length_error("basic_string");
1014#else
1015 assert(!"basic_string length_error");
1016#endif
1017}
1018
1019template <bool __b>
1020void
1021__basic_string_common<__b>::__throw_out_of_range() const
1022{
1023#ifndef _LIBCPP_NO_EXCEPTIONS
1024 throw out_of_range("basic_string");
1025#else
1026 assert(!"basic_string out_of_range");
1027#endif
1028}
1029
Howard Hinnant78b68282011-10-22 20:59:45 +00001030#ifdef _MSC_VER
1031#pragma warning( push )
1032#pragma warning( disable: 4231 )
1033#endif // _MSC_VER
Howard Hinnantff926772012-11-06 21:08:48 +00001034_LIBCPP_EXTERN_TEMPLATE(class __basic_string_common<true>)
Howard Hinnant78b68282011-10-22 20:59:45 +00001035#ifdef _MSC_VER
1036#pragma warning( pop )
1037#endif // _MSC_VER
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001038
Howard Hinnant324bb032010-08-22 00:02:43 +00001039template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant36cdf022010-09-10 16:42:26 +00001040class _LIBCPP_VISIBLE basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001041 : private __basic_string_common<true>
1042{
1043public:
1044 typedef basic_string __self;
1045 typedef _Traits traits_type;
1046 typedef typename traits_type::char_type value_type;
1047 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001048 typedef allocator_traits<allocator_type> __alloc_traits;
1049 typedef typename __alloc_traits::size_type size_type;
1050 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001051 typedef value_type& reference;
1052 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001053 typedef typename __alloc_traits::pointer pointer;
1054 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001055#ifdef _LIBCPP_DEBUG
1056 typedef __debug_iter<basic_string, pointer> iterator;
1057 typedef __debug_iter<basic_string, const_pointer> const_iterator;
1058
1059 friend class __debug_iter<basic_string, pointer>;
1060 friend class __debug_iter<basic_string, const_pointer>;
1061#elif defined(_LIBCPP_RAW_ITERATORS)
1062 typedef pointer iterator;
1063 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001064#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001065 typedef __wrap_iter<pointer> iterator;
1066 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001067#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001068 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1069 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070
1071private:
1072 struct __long
1073 {
1074 size_type __cap_;
1075 size_type __size_;
1076 pointer __data_;
1077 };
1078
1079#if _LIBCPP_BIG_ENDIAN
1080 enum {__short_mask = 0x80};
1081 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43 +00001082#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001083 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04 +00001084 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43 +00001085#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001086
1087 enum {__mask = size_type(~0) >> 1};
1088
1089 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1090 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1091
1092 struct __short
1093 {
1094 union
1095 {
1096 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +00001097 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001098 };
1099 value_type __data_[__min_cap];
1100 };
1101
Howard Hinnant9c0df142012-10-30 19:06:59 +00001102 union __lx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001103
Howard Hinnant9c0df142012-10-30 19:06:59 +00001104 enum {__n_words = sizeof(__lx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105
1106 struct __raw
1107 {
1108 size_type __words[__n_words];
1109 };
1110
1111 struct __rep
1112 {
1113 union
1114 {
1115 __long __l;
1116 __short __s;
1117 __raw __r;
1118 };
1119 };
1120
1121 __compressed_pair<__rep, allocator_type> __r_;
1122
1123#ifdef _LIBCPP_DEBUG
1124
1125 pair<iterator*, const_iterator*> __iterator_list_;
1126
1127 _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;}
1128 _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
1129
1130#endif // _LIBCPP_DEBUG
1131
1132public:
1133 static const size_type npos = -1;
1134
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001135 _LIBCPP_INLINE_VISIBILITY basic_string()
1136 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001137 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001138 basic_string(const basic_string& __str);
1139 basic_string(const basic_string& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001140#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59 +00001141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001142 basic_string(basic_string&& __str)
1143 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant9f193f22011-01-26 00:06:59 +00001144 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001145 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001146#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001147 _LIBCPP_INLINE_VISIBILITY basic_string(const_pointer __s);
1148 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149 basic_string(const_pointer __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001151 basic_string(const_pointer __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001153 basic_string(const_pointer __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001156 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001157 basic_string(size_type __n, value_type __c, const allocator_type& __a);
1158 basic_string(const basic_string& __str, size_type __pos, size_type __n = npos,
1159 const allocator_type& __a = allocator_type());
1160 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001161 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001162 basic_string(_InputIterator __first, _InputIterator __last);
1163 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001165 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001166#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001168 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001170 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001171#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001172
1173 ~basic_string();
1174
Howard Hinnante32b5e22010-11-17 17:55:08 +00001175 basic_string& operator=(const basic_string& __str);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001176#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001177 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001178 basic_string& operator=(basic_string&& __str)
1179 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1180 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001181#endif
Howard Hinnanta6119a82011-05-29 19:57:12 +00001182 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const_pointer __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001183 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02 +00001184#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001186 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001187#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001188
1189#ifndef _LIBCPP_DEBUG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001190 _LIBCPP_INLINE_VISIBILITY
1191 iterator begin() _NOEXCEPT
1192 {return iterator(__get_pointer());}
1193 _LIBCPP_INLINE_VISIBILITY
1194 const_iterator begin() const _NOEXCEPT
1195 {return const_iterator(data());}
1196 _LIBCPP_INLINE_VISIBILITY
1197 iterator end() _NOEXCEPT
1198 {return iterator(__get_pointer() + size());}
1199 _LIBCPP_INLINE_VISIBILITY
1200 const_iterator end() const _NOEXCEPT
1201 {return const_iterator(data() + size());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001202#else // _LIBCPP_DEBUG
1203 _LIBCPP_INLINE_VISIBILITY iterator begin() {return iterator(this, __get_pointer());}
1204 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return const_iterator(this, data());}
1205 _LIBCPP_INLINE_VISIBILITY iterator end() {return iterator(this, __get_pointer() + size());}
1206 _LIBCPP_INLINE_VISIBILITY const_iterator end() const {return const_iterator(this, data() + size());}
1207#endif // _LIBCPP_DEBUG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001208 _LIBCPP_INLINE_VISIBILITY
1209 reverse_iterator rbegin() _NOEXCEPT
1210 {return reverse_iterator(end());}
1211 _LIBCPP_INLINE_VISIBILITY
1212 const_reverse_iterator rbegin() const _NOEXCEPT
1213 {return const_reverse_iterator(end());}
1214 _LIBCPP_INLINE_VISIBILITY
1215 reverse_iterator rend() _NOEXCEPT
1216 {return reverse_iterator(begin());}
1217 _LIBCPP_INLINE_VISIBILITY
1218 const_reverse_iterator rend() const _NOEXCEPT
1219 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001220
Howard Hinnanta6119a82011-05-29 19:57:12 +00001221 _LIBCPP_INLINE_VISIBILITY
1222 const_iterator cbegin() const _NOEXCEPT
1223 {return begin();}
1224 _LIBCPP_INLINE_VISIBILITY
1225 const_iterator cend() const _NOEXCEPT
1226 {return end();}
1227 _LIBCPP_INLINE_VISIBILITY
1228 const_reverse_iterator crbegin() const _NOEXCEPT
1229 {return rbegin();}
1230 _LIBCPP_INLINE_VISIBILITY
1231 const_reverse_iterator crend() const _NOEXCEPT
1232 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001233
Howard Hinnanta6119a82011-05-29 19:57:12 +00001234 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001235 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001236 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
1237 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
1238 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001239 {return (__is_long() ? __get_long_cap() : __min_cap) - 1;}
1240
1241 void resize(size_type __n, value_type __c);
1242 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
1243
1244 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001245 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001246 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001248 void clear() _NOEXCEPT;
1249 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250
1251 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
1252 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
1253
1254 const_reference at(size_type __n) const;
1255 reference at(size_type __n);
1256
1257 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
1258 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const_pointer __s) {return append(__s);}
1259 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00001260#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001261 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02 +00001262#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001263
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001265 basic_string& append(const basic_string& __str);
1266 basic_string& append(const basic_string& __str, size_type __pos, size_type __n);
1267 basic_string& append(const_pointer __s, size_type __n);
1268 basic_string& append(const_pointer __s);
1269 basic_string& append(size_type __n, value_type __c);
1270 template<class _InputIterator>
1271 typename enable_if
1272 <
1273 __is_input_iterator <_InputIterator>::value &&
1274 !__is_forward_iterator<_InputIterator>::value,
1275 basic_string&
1276 >::type
1277 append(_InputIterator __first, _InputIterator __last);
1278 template<class _ForwardIterator>
1279 typename enable_if
1280 <
1281 __is_forward_iterator<_ForwardIterator>::value,
1282 basic_string&
1283 >::type
1284 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001285#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001287 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001288#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001289
1290 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001292 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001293 _LIBCPP_INLINE_VISIBILITY reference front();
1294 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1295 _LIBCPP_INLINE_VISIBILITY reference back();
1296 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001297
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001299 basic_string& assign(const basic_string& __str);
Howard Hinnanta6119a82011-05-29 19:57:12 +00001300#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1301 _LIBCPP_INLINE_VISIBILITY
1302 basic_string& assign(basic_string&& str)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001303 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001304#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001305 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n);
1306 basic_string& assign(const_pointer __s, size_type __n);
1307 basic_string& assign(const_pointer __s);
1308 basic_string& assign(size_type __n, value_type __c);
1309 template<class _InputIterator>
1310 typename enable_if
1311 <
1312 __is_input_iterator <_InputIterator>::value &&
1313 !__is_forward_iterator<_InputIterator>::value,
1314 basic_string&
1315 >::type
1316 assign(_InputIterator __first, _InputIterator __last);
1317 template<class _ForwardIterator>
1318 typename enable_if
1319 <
1320 __is_forward_iterator<_ForwardIterator>::value,
1321 basic_string&
1322 >::type
1323 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001324#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001325 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001326 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001327#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001328
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001330 basic_string& insert(size_type __pos1, const basic_string& __str);
1331 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n);
1332 basic_string& insert(size_type __pos, const_pointer __s, size_type __n);
1333 basic_string& insert(size_type __pos, const_pointer __s);
1334 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1335 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001336 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001337 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1338 template<class _InputIterator>
1339 typename enable_if
1340 <
1341 __is_input_iterator <_InputIterator>::value &&
1342 !__is_forward_iterator<_InputIterator>::value,
1343 iterator
1344 >::type
1345 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1346 template<class _ForwardIterator>
1347 typename enable_if
1348 <
1349 __is_forward_iterator<_ForwardIterator>::value,
1350 iterator
1351 >::type
1352 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001353#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001354 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001355 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1356 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001357#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001358
1359 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001360 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001361 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001362 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001363 iterator erase(const_iterator __first, const_iterator __last);
1364
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001365 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001366 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
1367 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2);
1368 basic_string& replace(size_type __pos, size_type __n1, const_pointer __s, size_type __n2);
1369 basic_string& replace(size_type __pos, size_type __n1, const_pointer __s);
1370 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001371 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001372 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001373 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001374 basic_string& replace(const_iterator __i1, const_iterator __i2, const_pointer __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001375 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001376 basic_string& replace(const_iterator __i1, const_iterator __i2, const_pointer __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001377 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001378 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001379 template<class _InputIterator>
1380 typename enable_if
1381 <
1382 __is_input_iterator<_InputIterator>::value,
1383 basic_string&
1384 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001385 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:02 +00001386#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001387 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001388 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001389 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001390#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001391
1392 size_type copy(pointer __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001393 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001394 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1395
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001396 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001397 void swap(basic_string& __str)
1398 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1399 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001400
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001402 const_pointer c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001403 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001404 const_pointer data() const _NOEXCEPT {return __get_pointer();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001405
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001406 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001407 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001410 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1411 size_type find(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001413 size_type find(const_pointer __s, size_type __pos = 0) const _NOEXCEPT;
1414 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001415
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001416 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001417 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1418 size_type rfind(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001420 size_type rfind(const_pointer __s, size_type __pos = npos) const _NOEXCEPT;
1421 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001422
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001423 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001424 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1425 size_type find_first_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001427 size_type find_first_of(const_pointer __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001429 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001430
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001431 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001432 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1433 size_type find_last_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001434 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001435 size_type find_last_of(const_pointer __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001436 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001437 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001438
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001439 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001440 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1441 size_type find_first_not_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
1442 _LIBCPP_INLINE_VISIBILITY
1443 size_type find_first_not_of(const_pointer __s, size_type __pos = 0) const _NOEXCEPT;
1444 _LIBCPP_INLINE_VISIBILITY
1445 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1446
1447 _LIBCPP_INLINE_VISIBILITY
1448 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1449 size_type find_last_not_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT;
1450 _LIBCPP_INLINE_VISIBILITY
1451 size_type find_last_not_of(const_pointer __s, size_type __pos = npos) const _NOEXCEPT;
1452 _LIBCPP_INLINE_VISIBILITY
1453 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1454
1455 _LIBCPP_INLINE_VISIBILITY
1456 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001458 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
1459 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 +00001460 int compare(const_pointer __s) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001461 int compare(size_type __pos1, size_type __n1, const_pointer __s) const;
1462 int compare(size_type __pos1, size_type __n1, const_pointer __s, size_type __n2) const;
1463
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001464 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001465private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001466 _LIBCPP_INLINE_VISIBILITY
1467 allocator_type& __alloc() _NOEXCEPT
1468 {return __r_.second();}
1469 _LIBCPP_INLINE_VISIBILITY
1470 const allocator_type& __alloc() const _NOEXCEPT
1471 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001472
Howard Hinnanta6119a82011-05-29 19:57:12 +00001473 _LIBCPP_INLINE_VISIBILITY
1474 bool __is_long() const _NOEXCEPT
1475 {return bool(__r_.first().__s.__size_ & __short_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001476
Howard Hinnanta6119a82011-05-29 19:57:12 +00001477 _LIBCPP_INLINE_VISIBILITY
1478 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001479#if _LIBCPP_BIG_ENDIAN
1480 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1481#else
1482 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1483#endif
Howard Hinnanta6119a82011-05-29 19:57:12 +00001484 _LIBCPP_INLINE_VISIBILITY
1485 size_type __get_short_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001486#if _LIBCPP_BIG_ENDIAN
1487 {return __r_.first().__s.__size_;}
1488#else
1489 {return __r_.first().__s.__size_ >> 1;}
1490#endif
Howard Hinnanta6119a82011-05-29 19:57:12 +00001491 _LIBCPP_INLINE_VISIBILITY
1492 void __set_long_size(size_type __s) _NOEXCEPT
1493 {__r_.first().__l.__size_ = __s;}
1494 _LIBCPP_INLINE_VISIBILITY
1495 size_type __get_long_size() const _NOEXCEPT
1496 {return __r_.first().__l.__size_;}
1497 _LIBCPP_INLINE_VISIBILITY
1498 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001499 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1500
Howard Hinnanta6119a82011-05-29 19:57:12 +00001501 _LIBCPP_INLINE_VISIBILITY
1502 void __set_long_cap(size_type __s) _NOEXCEPT
1503 {__r_.first().__l.__cap_ = __long_mask | __s;}
1504 _LIBCPP_INLINE_VISIBILITY
1505 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001506 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001507
Howard Hinnanta6119a82011-05-29 19:57:12 +00001508 _LIBCPP_INLINE_VISIBILITY
1509 void __set_long_pointer(pointer __p) _NOEXCEPT
1510 {__r_.first().__l.__data_ = __p;}
1511 _LIBCPP_INLINE_VISIBILITY
1512 pointer __get_long_pointer() _NOEXCEPT
1513 {return __r_.first().__l.__data_;}
1514 _LIBCPP_INLINE_VISIBILITY
1515 const_pointer __get_long_pointer() const _NOEXCEPT
1516 {return __r_.first().__l.__data_;}
1517 _LIBCPP_INLINE_VISIBILITY
1518 pointer __get_short_pointer() _NOEXCEPT
1519 {return __r_.first().__s.__data_;}
1520 _LIBCPP_INLINE_VISIBILITY
1521 const_pointer __get_short_pointer() const _NOEXCEPT
1522 {return __r_.first().__s.__data_;}
1523 _LIBCPP_INLINE_VISIBILITY
1524 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001526 _LIBCPP_INLINE_VISIBILITY
1527 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001528 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1529
Howard Hinnanta6119a82011-05-29 19:57:12 +00001530 _LIBCPP_INLINE_VISIBILITY
1531 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001532 {
1533 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1534 for (unsigned __i = 0; __i < __n_words; ++__i)
1535 __a[__i] = 0;
1536 }
1537
1538 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001539 _LIBCPP_INLINE_VISIBILITY
1540 size_type __align(size_type __s) _NOEXCEPT
1541 {return __s + (__a-1) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001542 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001543 static _LIBCPP_INLINE_VISIBILITY
1544 size_type __recommend(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001545 {return (__s < __min_cap ? __min_cap :
Howard Hinnanta6119a82011-05-29 19:57:12 +00001546 __align<sizeof(value_type) < __alignment ?
1547 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548
1549 void __init(const_pointer __s, size_type __sz, size_type __reserve);
1550 void __init(const_pointer __s, size_type __sz);
1551 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001552
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001553 template <class _InputIterator>
1554 typename enable_if
1555 <
1556 __is_input_iterator <_InputIterator>::value &&
1557 !__is_forward_iterator<_InputIterator>::value,
1558 void
1559 >::type
1560 __init(_InputIterator __first, _InputIterator __last);
1561
1562 template <class _ForwardIterator>
1563 typename enable_if
1564 <
1565 __is_forward_iterator<_ForwardIterator>::value,
1566 void
1567 >::type
1568 __init(_ForwardIterator __first, _ForwardIterator __last);
1569
1570 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001571 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001572 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1573 size_type __n_copy, size_type __n_del,
1574 size_type __n_add, const_pointer __p_new_stuff);
1575
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001577 void __erase_to_end(size_type __pos);
1578
Howard Hinnante32b5e22010-11-17 17:55:08 +00001579 _LIBCPP_INLINE_VISIBILITY
1580 void __copy_assign_alloc(const basic_string& __str)
1581 {__copy_assign_alloc(__str, integral_constant<bool,
1582 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1583
1584 _LIBCPP_INLINE_VISIBILITY
1585 void __copy_assign_alloc(const basic_string& __str, true_type)
1586 {
1587 if (__alloc() != __str.__alloc())
1588 {
1589 clear();
1590 shrink_to_fit();
1591 }
1592 __alloc() = __str.__alloc();
1593 }
1594
1595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001596 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001597 {}
1598
1599#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00001601 void __move_assign(basic_string& __str, false_type);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001603 void __move_assign(basic_string& __str, true_type)
1604 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001605#endif
1606
1607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001608 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001609 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001610 _NOEXCEPT_(
1611 !__alloc_traits::propagate_on_container_move_assignment::value ||
1612 is_nothrow_move_assignable<allocator_type>::value)
1613 {__move_assign_alloc(__str, integral_constant<bool,
1614 __alloc_traits::propagate_on_container_move_assignment::value>());}
1615
1616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001617 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001618 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1619 {
1620 __alloc() = _VSTD::move(__c.__alloc());
1621 }
1622
1623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001624 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001625 _NOEXCEPT
1626 {}
1627
1628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001629 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
1630 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1631 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001632 {__swap_alloc(__x, __y, integral_constant<bool,
1633 __alloc_traits::propagate_on_container_swap::value>());}
1634
1635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001636 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
1637 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001638 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001639 using _VSTD::swap;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001640 swap(__x, __y);
1641 }
1642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001643 static void __swap_alloc(allocator_type&, allocator_type&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001644 {}
1645
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001646 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1647 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001648
1649 friend basic_string operator+<>(const basic_string&, const basic_string&);
1650 friend basic_string operator+<>(const value_type*, const basic_string&);
1651 friend basic_string operator+<>(value_type, const basic_string&);
1652 friend basic_string operator+<>(const basic_string&, const value_type*);
1653 friend basic_string operator+<>(const basic_string&, value_type);
1654};
1655
1656template <class _CharT, class _Traits, class _Allocator>
1657#ifndef _LIBCPP_DEBUG
1658_LIBCPP_INLINE_VISIBILITY inline
1659#endif
1660void
1661basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1662{
1663#ifdef _LIBCPP_DEBUG
1664 iterator::__remove_all(this);
1665 const_iterator::__remove_all(this);
Howard Hinnant324bb032010-08-22 00:02:43 +00001666#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001667}
1668
1669template <class _CharT, class _Traits, class _Allocator>
1670#ifndef _LIBCPP_DEBUG
1671_LIBCPP_INLINE_VISIBILITY inline
1672#endif
1673void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001674basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
1675#ifdef _LIBCPP_DEBUG
1676 __pos
1677#endif
1678 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001679{
1680#ifdef _LIBCPP_DEBUG
1681 const_iterator __beg = begin();
1682 if (__iterator_list_.first)
1683 {
1684 for (iterator* __p = __iterator_list_.first; __p;)
1685 {
1686 if (*__p - __beg > static_cast<difference_type>(__pos))
1687 {
1688 iterator* __n = __p;
1689 __p = __p->__next;
1690 __n->__remove_owner();
1691 }
1692 else
1693 __p = __p->__next;
1694 }
1695 }
1696 if (__iterator_list_.second)
1697 {
1698 for (const_iterator* __p = __iterator_list_.second; __p;)
1699 {
1700 if (*__p - __beg > static_cast<difference_type>(__pos))
1701 {
1702 const_iterator* __n = __p;
1703 __p = __p->__next;
1704 __n->__remove_owner();
1705 }
1706 else
1707 __p = __p->__next;
1708 }
1709 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001710#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001711}
1712
1713template <class _CharT, class _Traits, class _Allocator>
1714_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001715basic_string<_CharT, _Traits, _Allocator>::basic_string()
1716 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001717{
1718 __zero();
1719}
1720
1721template <class _CharT, class _Traits, class _Allocator>
1722_LIBCPP_INLINE_VISIBILITY inline
1723basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
1724 : __r_(__a)
1725{
1726 __zero();
1727}
1728
1729template <class _CharT, class _Traits, class _Allocator>
1730void
1731basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type __sz, size_type __reserve)
1732{
1733 if (__reserve > max_size())
1734 this->__throw_length_error();
1735 pointer __p;
1736 if (__reserve < __min_cap)
1737 {
1738 __set_short_size(__sz);
1739 __p = __get_short_pointer();
1740 }
1741 else
1742 {
1743 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001744 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001745 __set_long_pointer(__p);
1746 __set_long_cap(__cap+1);
1747 __set_long_size(__sz);
1748 }
1749 traits_type::copy(__p, __s, __sz);
1750 traits_type::assign(__p[__sz], value_type());
1751}
1752
1753template <class _CharT, class _Traits, class _Allocator>
1754void
1755basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type __sz)
1756{
1757 if (__sz > max_size())
1758 this->__throw_length_error();
1759 pointer __p;
1760 if (__sz < __min_cap)
1761 {
1762 __set_short_size(__sz);
1763 __p = __get_short_pointer();
1764 }
1765 else
1766 {
1767 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001768 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001769 __set_long_pointer(__p);
1770 __set_long_cap(__cap+1);
1771 __set_long_size(__sz);
1772 }
1773 traits_type::copy(__p, __s, __sz);
1774 traits_type::assign(__p[__sz], value_type());
1775}
1776
1777template <class _CharT, class _Traits, class _Allocator>
1778_LIBCPP_INLINE_VISIBILITY inline
1779basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s)
1780{
1781#ifdef _LIBCPP_DEBUG
1782 assert(__s != 0);
1783#endif
1784 __init(__s, traits_type::length(__s));
1785}
1786
1787template <class _CharT, class _Traits, class _Allocator>
1788_LIBCPP_INLINE_VISIBILITY inline
1789basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, const allocator_type& __a)
1790 : __r_(__a)
1791{
1792#ifdef _LIBCPP_DEBUG
1793 assert(__s != 0);
1794#endif
1795 __init(__s, traits_type::length(__s));
1796}
1797
1798template <class _CharT, class _Traits, class _Allocator>
1799_LIBCPP_INLINE_VISIBILITY inline
1800basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, size_type __n)
1801{
1802#ifdef _LIBCPP_DEBUG
1803 assert(__s != 0);
1804#endif
1805 __init(__s, __n);
1806}
1807
1808template <class _CharT, class _Traits, class _Allocator>
1809_LIBCPP_INLINE_VISIBILITY inline
1810basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, size_type __n, const allocator_type& __a)
1811 : __r_(__a)
1812{
1813#ifdef _LIBCPP_DEBUG
1814 assert(__s != 0);
1815#endif
1816 __init(__s, __n);
1817}
1818
1819template <class _CharT, class _Traits, class _Allocator>
1820basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001821 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001822{
1823 if (!__str.__is_long())
1824 __r_.first().__r = __str.__r_.first().__r;
1825 else
1826 __init(__str.__get_long_pointer(), __str.__get_long_size());
1827}
1828
1829template <class _CharT, class _Traits, class _Allocator>
1830basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
1831 : __r_(__a)
1832{
1833 if (!__str.__is_long())
1834 __r_.first().__r = __str.__r_.first().__r;
1835 else
1836 __init(__str.__get_long_pointer(), __str.__get_long_size());
1837}
1838
Howard Hinnant73d21a42010-09-04 23:28:19 +00001839#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001840
1841template <class _CharT, class _Traits, class _Allocator>
1842_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001843basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
1844 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001845 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001846{
1847 __str.__zero();
1848#ifdef _LIBCPP_DEBUG
1849 __str.__invalidate_all_iterators();
1850#endif
1851}
1852
1853template <class _CharT, class _Traits, class _Allocator>
1854_LIBCPP_INLINE_VISIBILITY inline
1855basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001856 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001857{
Howard Hinnante32b5e22010-11-17 17:55:08 +00001858 if (__a == __str.__alloc() || !__str.__is_long())
1859 __r_.first().__r = __str.__r_.first().__r;
1860 else
1861 __init(__str.__get_long_pointer(), __str.__get_long_size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001862 __str.__zero();
1863#ifdef _LIBCPP_DEBUG
1864 __str.__invalidate_all_iterators();
1865#endif
1866}
1867
Howard Hinnant73d21a42010-09-04 23:28:19 +00001868#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001869
1870template <class _CharT, class _Traits, class _Allocator>
1871void
1872basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1873{
1874 if (__n > max_size())
1875 this->__throw_length_error();
1876 pointer __p;
1877 if (__n < __min_cap)
1878 {
1879 __set_short_size(__n);
1880 __p = __get_short_pointer();
1881 }
1882 else
1883 {
1884 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001885 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001886 __set_long_pointer(__p);
1887 __set_long_cap(__cap+1);
1888 __set_long_size(__n);
1889 }
1890 traits_type::assign(__p, __n, __c);
1891 traits_type::assign(__p[__n], value_type());
1892}
1893
1894template <class _CharT, class _Traits, class _Allocator>
1895_LIBCPP_INLINE_VISIBILITY inline
1896basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
1897{
1898 __init(__n, __c);
1899}
1900
1901template <class _CharT, class _Traits, class _Allocator>
1902_LIBCPP_INLINE_VISIBILITY inline
1903basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
1904 : __r_(__a)
1905{
1906 __init(__n, __c);
1907}
1908
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001909template <class _CharT, class _Traits, class _Allocator>
1910basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
1911 const allocator_type& __a)
1912 : __r_(__a)
1913{
1914 size_type __str_sz = __str.size();
1915 if (__pos > __str_sz)
1916 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001917 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001918}
1919
1920template <class _CharT, class _Traits, class _Allocator>
1921template <class _InputIterator>
1922typename enable_if
1923<
1924 __is_input_iterator <_InputIterator>::value &&
1925 !__is_forward_iterator<_InputIterator>::value,
1926 void
1927>::type
1928basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
1929{
1930 __zero();
1931#ifndef _LIBCPP_NO_EXCEPTIONS
1932 try
1933 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001934#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935 for (; __first != __last; ++__first)
1936 push_back(*__first);
1937#ifndef _LIBCPP_NO_EXCEPTIONS
1938 }
1939 catch (...)
1940 {
1941 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001942 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001943 throw;
1944 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001945#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001946}
1947
1948template <class _CharT, class _Traits, class _Allocator>
1949template <class _ForwardIterator>
1950typename enable_if
1951<
1952 __is_forward_iterator<_ForwardIterator>::value,
1953 void
1954>::type
1955basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
1956{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001957 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001958 if (__sz > max_size())
1959 this->__throw_length_error();
1960 pointer __p;
1961 if (__sz < __min_cap)
1962 {
1963 __set_short_size(__sz);
1964 __p = __get_short_pointer();
1965 }
1966 else
1967 {
1968 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001969 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001970 __set_long_pointer(__p);
1971 __set_long_cap(__cap+1);
1972 __set_long_size(__sz);
1973 }
1974 for (; __first != __last; ++__first, ++__p)
1975 traits_type::assign(*__p, *__first);
1976 traits_type::assign(*__p, value_type());
1977}
1978
1979template <class _CharT, class _Traits, class _Allocator>
1980template<class _InputIterator>
1981_LIBCPP_INLINE_VISIBILITY inline
1982basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
1983{
1984 __init(__first, __last);
1985}
1986
1987template <class _CharT, class _Traits, class _Allocator>
1988template<class _InputIterator>
1989_LIBCPP_INLINE_VISIBILITY inline
1990basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
1991 const allocator_type& __a)
1992 : __r_(__a)
1993{
1994 __init(__first, __last);
1995}
1996
Howard Hinnante3e32912011-08-12 21:56:02 +00001997#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1998
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001999template <class _CharT, class _Traits, class _Allocator>
2000_LIBCPP_INLINE_VISIBILITY inline
2001basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
2002{
2003 __init(__il.begin(), __il.end());
2004}
2005
2006template <class _CharT, class _Traits, class _Allocator>
2007_LIBCPP_INLINE_VISIBILITY inline
2008basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
2009 : __r_(__a)
2010{
2011 __init(__il.begin(), __il.end());
2012}
2013
Howard Hinnante3e32912011-08-12 21:56:02 +00002014#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2015
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002016template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002017basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2018{
2019 __invalidate_all_iterators();
2020 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002021 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002022}
2023
2024template <class _CharT, class _Traits, class _Allocator>
2025void
2026basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2027 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2028 size_type __n_copy, size_type __n_del, size_type __n_add, const_pointer __p_new_stuff)
2029{
2030 size_type __ms = max_size();
2031 if (__delta_cap > __ms - __old_cap - 1)
2032 this->__throw_length_error();
2033 pointer __old_p = __get_pointer();
2034 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002035 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002036 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002037 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002038 __invalidate_all_iterators();
2039 if (__n_copy != 0)
2040 traits_type::copy(__p, __old_p, __n_copy);
2041 if (__n_add != 0)
2042 traits_type::copy(__p + __n_copy, __p_new_stuff, __n_add);
2043 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2044 if (__sec_cp_sz != 0)
2045 traits_type::copy(__p + __n_copy + __n_add, __old_p + __n_copy + __n_del, __sec_cp_sz);
2046 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002047 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002048 __set_long_pointer(__p);
2049 __set_long_cap(__cap+1);
2050 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2051 __set_long_size(__old_sz);
2052 traits_type::assign(__p[__old_sz], value_type());
2053}
2054
2055template <class _CharT, class _Traits, class _Allocator>
2056void
2057basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2058 size_type __n_copy, size_type __n_del, size_type __n_add)
2059{
2060 size_type __ms = max_size();
2061 if (__delta_cap > __ms - __old_cap - 1)
2062 this->__throw_length_error();
2063 pointer __old_p = __get_pointer();
2064 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002065 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002066 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002067 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002068 __invalidate_all_iterators();
2069 if (__n_copy != 0)
Howard Hinnant46c49d12013-02-07 15:27:39 +00002070 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2071 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002072 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2073 if (__sec_cp_sz != 0)
Howard Hinnant46c49d12013-02-07 15:27:39 +00002074 traits_type::copy(_VSTD::__to_raw_pointer(__p + __n_copy + __n_add),
2075 _VSTD::__to_raw_pointer(__old_p + __n_copy + __n_del),
2076 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002077 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002078 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002079 __set_long_pointer(__p);
2080 __set_long_cap(__cap+1);
2081}
2082
2083// assign
2084
2085template <class _CharT, class _Traits, class _Allocator>
2086basic_string<_CharT, _Traits, _Allocator>&
2087basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s, size_type __n)
2088{
2089#ifdef _LIBCPP_DEBUG
2090 assert(__s != 0);
2091#endif
2092 size_type __cap = capacity();
2093 if (__cap >= __n)
2094 {
2095 pointer __p = __get_pointer();
2096 traits_type::move(__p, __s, __n);
2097 traits_type::assign(__p[__n], value_type());
2098 __set_size(__n);
2099 __invalidate_iterators_past(__n);
2100 }
2101 else
2102 {
2103 size_type __sz = size();
2104 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2105 }
2106 return *this;
2107}
2108
2109template <class _CharT, class _Traits, class _Allocator>
2110basic_string<_CharT, _Traits, _Allocator>&
2111basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2112{
2113 size_type __cap = capacity();
2114 if (__cap < __n)
2115 {
2116 size_type __sz = size();
2117 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2118 }
2119 else
2120 __invalidate_iterators_past(__n);
2121 pointer __p = __get_pointer();
2122 traits_type::assign(__p, __n, __c);
2123 traits_type::assign(__p[__n], value_type());
2124 __set_size(__n);
2125 return *this;
2126}
2127
2128template <class _CharT, class _Traits, class _Allocator>
2129basic_string<_CharT, _Traits, _Allocator>&
2130basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2131{
2132 pointer __p;
2133 if (__is_long())
2134 {
2135 __p = __get_long_pointer();
2136 __set_long_size(1);
2137 }
2138 else
2139 {
2140 __p = __get_short_pointer();
2141 __set_short_size(1);
2142 }
2143 traits_type::assign(*__p, __c);
2144 traits_type::assign(*++__p, value_type());
2145 __invalidate_iterators_past(1);
2146 return *this;
2147}
2148
2149template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002150basic_string<_CharT, _Traits, _Allocator>&
2151basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2152{
2153 if (this != &__str)
2154 {
2155 __copy_assign_alloc(__str);
2156 assign(__str);
2157 }
2158 return *this;
2159}
2160
2161#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2162
2163template <class _CharT, class _Traits, class _Allocator>
2164_LIBCPP_INLINE_VISIBILITY inline
2165void
2166basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2167{
2168 if (__alloc() != __str.__alloc())
2169 assign(__str);
2170 else
2171 __move_assign(__str, true_type());
2172}
2173
2174template <class _CharT, class _Traits, class _Allocator>
2175_LIBCPP_INLINE_VISIBILITY inline
2176void
2177basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002178 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002179{
2180 clear();
2181 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002182 __r_.first() = __str.__r_.first();
2183 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002184 __str.__zero();
2185}
2186
2187template <class _CharT, class _Traits, class _Allocator>
2188_LIBCPP_INLINE_VISIBILITY inline
2189basic_string<_CharT, _Traits, _Allocator>&
2190basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002191 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
2192 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002193{
2194 __move_assign(__str, integral_constant<bool,
2195 __alloc_traits::propagate_on_container_move_assignment::value>());
2196 return *this;
2197}
2198
2199#endif
2200
2201template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002202template<class _InputIterator>
2203typename enable_if
2204<
2205 __is_input_iterator <_InputIterator>::value &&
2206 !__is_forward_iterator<_InputIterator>::value,
2207 basic_string<_CharT, _Traits, _Allocator>&
2208>::type
2209basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2210{
2211 clear();
2212 for (; __first != __last; ++__first)
2213 push_back(*__first);
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002214 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002215}
2216
2217template <class _CharT, class _Traits, class _Allocator>
2218template<class _ForwardIterator>
2219typename enable_if
2220<
2221 __is_forward_iterator<_ForwardIterator>::value,
2222 basic_string<_CharT, _Traits, _Allocator>&
2223>::type
2224basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2225{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002226 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002227 size_type __cap = capacity();
2228 if (__cap < __n)
2229 {
2230 size_type __sz = size();
2231 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2232 }
2233 else
2234 __invalidate_iterators_past(__n);
2235 pointer __p = __get_pointer();
2236 for (; __first != __last; ++__first, ++__p)
2237 traits_type::assign(*__p, *__first);
2238 traits_type::assign(*__p, value_type());
2239 __set_size(__n);
2240 return *this;
2241}
2242
2243template <class _CharT, class _Traits, class _Allocator>
2244_LIBCPP_INLINE_VISIBILITY inline
2245basic_string<_CharT, _Traits, _Allocator>&
2246basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
2247{
2248 return assign(__str.data(), __str.size());
2249}
2250
2251template <class _CharT, class _Traits, class _Allocator>
2252basic_string<_CharT, _Traits, _Allocator>&
2253basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2254{
2255 size_type __sz = __str.size();
2256 if (__pos > __sz)
2257 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002258 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002259}
2260
2261template <class _CharT, class _Traits, class _Allocator>
2262basic_string<_CharT, _Traits, _Allocator>&
2263basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s)
2264{
2265#ifdef _LIBCPP_DEBUG
2266 assert(__s != 0);
2267#endif
2268 return assign(__s, traits_type::length(__s));
2269}
2270
2271// append
2272
2273template <class _CharT, class _Traits, class _Allocator>
2274basic_string<_CharT, _Traits, _Allocator>&
2275basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s, size_type __n)
2276{
2277#ifdef _LIBCPP_DEBUG
2278 assert(__s != 0);
2279#endif
2280 size_type __cap = capacity();
2281 size_type __sz = size();
2282 if (__cap - __sz >= __n)
2283 {
2284 if (__n)
2285 {
2286 pointer __p = __get_pointer();
2287 traits_type::copy(__p + __sz, __s, __n);
2288 __sz += __n;
2289 __set_size(__sz);
2290 traits_type::assign(__p[__sz], value_type());
2291 }
2292 }
2293 else
2294 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2295 return *this;
2296}
2297
2298template <class _CharT, class _Traits, class _Allocator>
2299basic_string<_CharT, _Traits, _Allocator>&
2300basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2301{
2302 if (__n)
2303 {
2304 size_type __cap = capacity();
2305 size_type __sz = size();
2306 if (__cap - __sz < __n)
2307 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2308 pointer __p = __get_pointer();
Howard Hinnant46c49d12013-02-07 15:27:39 +00002309 traits_type::assign(_VSTD::__to_raw_pointer(__p + __sz), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002310 __sz += __n;
2311 __set_size(__sz);
2312 traits_type::assign(__p[__sz], value_type());
2313 }
2314 return *this;
2315}
2316
2317template <class _CharT, class _Traits, class _Allocator>
2318void
2319basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2320{
2321 size_type __cap = capacity();
2322 size_type __sz = size();
2323 if (__sz == __cap)
2324 __grow_by(__cap, 1, __sz, __sz, 0);
2325 pointer __p = __get_pointer() + __sz;
2326 traits_type::assign(*__p, __c);
2327 traits_type::assign(*++__p, value_type());
2328 __set_size(__sz+1);
2329}
2330
2331template <class _CharT, class _Traits, class _Allocator>
2332template<class _InputIterator>
2333typename enable_if
2334<
2335 __is_input_iterator <_InputIterator>::value &&
2336 !__is_forward_iterator<_InputIterator>::value,
2337 basic_string<_CharT, _Traits, _Allocator>&
2338>::type
2339basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2340{
2341 for (; __first != __last; ++__first)
2342 push_back(*__first);
2343 return *this;
2344}
2345
2346template <class _CharT, class _Traits, class _Allocator>
2347template<class _ForwardIterator>
2348typename enable_if
2349<
2350 __is_forward_iterator<_ForwardIterator>::value,
2351 basic_string<_CharT, _Traits, _Allocator>&
2352>::type
2353basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2354{
2355 size_type __sz = size();
2356 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002357 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002358 if (__n)
2359 {
2360 if (__cap - __sz < __n)
2361 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2362 pointer __p = __get_pointer() + __sz;
2363 for (; __first != __last; ++__p, ++__first)
2364 traits_type::assign(*__p, *__first);
2365 traits_type::assign(*__p, value_type());
2366 __set_size(__sz + __n);
2367 }
2368 return *this;
2369}
2370
2371template <class _CharT, class _Traits, class _Allocator>
2372_LIBCPP_INLINE_VISIBILITY inline
2373basic_string<_CharT, _Traits, _Allocator>&
2374basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2375{
2376 return append(__str.data(), __str.size());
2377}
2378
2379template <class _CharT, class _Traits, class _Allocator>
2380basic_string<_CharT, _Traits, _Allocator>&
2381basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2382{
2383 size_type __sz = __str.size();
2384 if (__pos > __sz)
2385 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002386 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002387}
2388
2389template <class _CharT, class _Traits, class _Allocator>
2390basic_string<_CharT, _Traits, _Allocator>&
2391basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s)
2392{
2393#ifdef _LIBCPP_DEBUG
2394 assert(__s != 0);
2395#endif
2396 return append(__s, traits_type::length(__s));
2397}
2398
2399// insert
2400
2401template <class _CharT, class _Traits, class _Allocator>
2402basic_string<_CharT, _Traits, _Allocator>&
2403basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const_pointer __s, size_type __n)
2404{
2405#ifdef _LIBCPP_DEBUG
2406 assert(__s != 0);
2407#endif
2408 size_type __sz = size();
2409 if (__pos > __sz)
2410 this->__throw_out_of_range();
2411 size_type __cap = capacity();
2412 if (__cap - __sz >= __n)
2413 {
2414 if (__n)
2415 {
2416 pointer __p = __get_pointer();
2417 size_type __n_move = __sz - __pos;
2418 if (__n_move != 0)
2419 {
2420 if (__p + __pos <= __s && __s < __p + __sz)
2421 __s += __n;
2422 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2423 }
2424 traits_type::move(__p + __pos, __s, __n);
2425 __sz += __n;
2426 __set_size(__sz);
2427 traits_type::assign(__p[__sz], value_type());
2428 }
2429 }
2430 else
2431 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2432 return *this;
2433}
2434
2435template <class _CharT, class _Traits, class _Allocator>
2436basic_string<_CharT, _Traits, _Allocator>&
2437basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2438{
2439 size_type __sz = size();
2440 if (__pos > __sz)
2441 this->__throw_out_of_range();
2442 if (__n)
2443 {
2444 size_type __cap = capacity();
2445 pointer __p;
2446 if (__cap - __sz >= __n)
2447 {
2448 __p = __get_pointer();
2449 size_type __n_move = __sz - __pos;
2450 if (__n_move != 0)
2451 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2452 }
2453 else
2454 {
2455 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
2456 __p = __get_long_pointer();
2457 }
2458 traits_type::assign(__p + __pos, __n, __c);
2459 __sz += __n;
2460 __set_size(__sz);
2461 traits_type::assign(__p[__sz], value_type());
2462 }
2463 return *this;
2464}
2465
2466template <class _CharT, class _Traits, class _Allocator>
2467template<class _InputIterator>
2468typename enable_if
2469<
2470 __is_input_iterator <_InputIterator>::value &&
2471 !__is_forward_iterator<_InputIterator>::value,
2472 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2473>::type
2474basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2475{
2476 size_type __old_sz = size();
2477 difference_type __ip = __pos - begin();
2478 for (; __first != __last; ++__first)
2479 push_back(*__first);
2480 pointer __p = __get_pointer();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002481 _VSTD::rotate(__p + __ip, __p + __old_sz, __p + size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002482 return iterator(__p + __ip);
2483}
2484
2485template <class _CharT, class _Traits, class _Allocator>
2486template<class _ForwardIterator>
2487typename enable_if
2488<
2489 __is_forward_iterator<_ForwardIterator>::value,
2490 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2491>::type
2492basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2493{
2494 size_type __ip = static_cast<size_type>(__pos - begin());
2495 size_type __sz = size();
2496 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002497 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002498 if (__n)
2499 {
2500 pointer __p;
2501 if (__cap - __sz >= __n)
2502 {
2503 __p = __get_pointer();
2504 size_type __n_move = __sz - __ip;
2505 if (__n_move != 0)
2506 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2507 }
2508 else
2509 {
2510 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
2511 __p = __get_long_pointer();
2512 }
2513 __sz += __n;
2514 __set_size(__sz);
2515 traits_type::assign(__p[__sz], value_type());
2516 for (__p += __ip; __first != __last; ++__p, ++__first)
2517 traits_type::assign(*__p, *__first);
2518 }
2519 return begin() + __ip;
2520}
2521
2522template <class _CharT, class _Traits, class _Allocator>
2523_LIBCPP_INLINE_VISIBILITY inline
2524basic_string<_CharT, _Traits, _Allocator>&
2525basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2526{
2527 return insert(__pos1, __str.data(), __str.size());
2528}
2529
2530template <class _CharT, class _Traits, class _Allocator>
2531basic_string<_CharT, _Traits, _Allocator>&
2532basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2533 size_type __pos2, size_type __n)
2534{
2535 size_type __str_sz = __str.size();
2536 if (__pos2 > __str_sz)
2537 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002538 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002539}
2540
2541template <class _CharT, class _Traits, class _Allocator>
2542basic_string<_CharT, _Traits, _Allocator>&
2543basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const_pointer __s)
2544{
2545#ifdef _LIBCPP_DEBUG
2546 assert(__s != 0);
2547#endif
2548 return insert(__pos, __s, traits_type::length(__s));
2549}
2550
2551template <class _CharT, class _Traits, class _Allocator>
2552typename basic_string<_CharT, _Traits, _Allocator>::iterator
2553basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2554{
2555 size_type __ip = static_cast<size_type>(__pos - begin());
2556 size_type __sz = size();
2557 size_type __cap = capacity();
2558 pointer __p;
2559 if (__cap == __sz)
2560 {
2561 __grow_by(__cap, 1, __sz, __ip, 0, 1);
2562 __p = __get_long_pointer();
2563 }
2564 else
2565 {
2566 __p = __get_pointer();
2567 size_type __n_move = __sz - __ip;
2568 if (__n_move != 0)
2569 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2570 }
2571 traits_type::assign(__p[__ip], __c);
2572 traits_type::assign(__p[++__sz], value_type());
2573 __set_size(__sz);
2574 return begin() + static_cast<difference_type>(__ip);
2575}
2576
2577template <class _CharT, class _Traits, class _Allocator>
2578_LIBCPP_INLINE_VISIBILITY inline
2579typename basic_string<_CharT, _Traits, _Allocator>::iterator
2580basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2581{
2582 difference_type __p = __pos - begin();
2583 insert(static_cast<size_type>(__p), __n, __c);
2584 return begin() + __p;
2585}
2586
2587// replace
2588
2589template <class _CharT, class _Traits, class _Allocator>
2590basic_string<_CharT, _Traits, _Allocator>&
2591basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const_pointer __s, size_type __n2)
2592{
2593#ifdef _LIBCPP_DEBUG
2594 assert(__s != 0);
2595#endif
2596 size_type __sz = size();
2597 if (__pos > __sz)
2598 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002599 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002600 size_type __cap = capacity();
2601 if (__cap - __sz + __n1 >= __n2)
2602 {
2603 pointer __p = __get_pointer();
2604 if (__n1 != __n2)
2605 {
2606 size_type __n_move = __sz - __pos - __n1;
2607 if (__n_move != 0)
2608 {
2609 if (__n1 > __n2)
2610 {
2611 traits_type::move(__p + __pos, __s, __n2);
2612 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2613 goto __finish;
2614 }
2615 if (__p + __pos < __s && __s < __p + __sz)
2616 {
2617 if (__p + __pos + __n1 <= __s)
2618 __s += __n2 - __n1;
2619 else // __p + __pos < __s < __p + __pos + __n1
2620 {
2621 traits_type::move(__p + __pos, __s, __n1);
2622 __pos += __n1;
2623 __s += __n2;
2624 __n2 -= __n1;
2625 __n1 = 0;
2626 }
2627 }
2628 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2629 }
2630 }
2631 traits_type::move(__p + __pos, __s, __n2);
2632__finish:
2633 __sz += __n2 - __n1;
2634 __set_size(__sz);
2635 __invalidate_iterators_past(__sz);
2636 traits_type::assign(__p[__sz], value_type());
2637 }
2638 else
2639 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2640 return *this;
2641}
2642
2643template <class _CharT, class _Traits, class _Allocator>
2644basic_string<_CharT, _Traits, _Allocator>&
2645basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2646{
2647 size_type __sz = size();
2648 if (__pos > __sz)
2649 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002650 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002651 size_type __cap = capacity();
2652 pointer __p;
2653 if (__cap - __sz + __n1 >= __n2)
2654 {
2655 __p = __get_pointer();
2656 if (__n1 != __n2)
2657 {
2658 size_type __n_move = __sz - __pos - __n1;
2659 if (__n_move != 0)
2660 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2661 }
2662 }
2663 else
2664 {
2665 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
2666 __p = __get_long_pointer();
2667 }
2668 traits_type::assign(__p + __pos, __n2, __c);
2669 __sz += __n2 - __n1;
2670 __set_size(__sz);
2671 __invalidate_iterators_past(__sz);
2672 traits_type::assign(__p[__sz], value_type());
2673 return *this;
2674}
2675
2676template <class _CharT, class _Traits, class _Allocator>
2677template<class _InputIterator>
2678typename enable_if
2679<
2680 __is_input_iterator<_InputIterator>::value,
2681 basic_string<_CharT, _Traits, _Allocator>&
2682>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002683basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002684 _InputIterator __j1, _InputIterator __j2)
2685{
2686 for (; true; ++__i1, ++__j1)
2687 {
2688 if (__i1 == __i2)
2689 {
2690 if (__j1 != __j2)
2691 insert(__i1, __j1, __j2);
2692 break;
2693 }
2694 if (__j1 == __j2)
2695 {
2696 erase(__i1, __i2);
2697 break;
2698 }
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002699 traits_type::assign(const_cast<value_type&>(*__i1), *__j1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002700 }
2701 return *this;
2702}
2703
2704template <class _CharT, class _Traits, class _Allocator>
2705_LIBCPP_INLINE_VISIBILITY inline
2706basic_string<_CharT, _Traits, _Allocator>&
2707basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2708{
2709 return replace(__pos1, __n1, __str.data(), __str.size());
2710}
2711
2712template <class _CharT, class _Traits, class _Allocator>
2713basic_string<_CharT, _Traits, _Allocator>&
2714basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2715 size_type __pos2, size_type __n2)
2716{
2717 size_type __str_sz = __str.size();
2718 if (__pos2 > __str_sz)
2719 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002720 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002721}
2722
2723template <class _CharT, class _Traits, class _Allocator>
2724basic_string<_CharT, _Traits, _Allocator>&
2725basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const_pointer __s)
2726{
2727#ifdef _LIBCPP_DEBUG
2728 assert(__s != 0);
2729#endif
2730 return replace(__pos, __n1, __s, traits_type::length(__s));
2731}
2732
2733template <class _CharT, class _Traits, class _Allocator>
2734_LIBCPP_INLINE_VISIBILITY inline
2735basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002736basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002737{
2738 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2739 __str.data(), __str.size());
2740}
2741
2742template <class _CharT, class _Traits, class _Allocator>
2743_LIBCPP_INLINE_VISIBILITY inline
2744basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002745basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const_pointer __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002746{
2747 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2748}
2749
2750template <class _CharT, class _Traits, class _Allocator>
2751_LIBCPP_INLINE_VISIBILITY inline
2752basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002753basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const_pointer __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002754{
2755 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2756}
2757
2758template <class _CharT, class _Traits, class _Allocator>
2759_LIBCPP_INLINE_VISIBILITY inline
2760basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002761basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002762{
2763 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2764}
2765
2766// erase
2767
2768template <class _CharT, class _Traits, class _Allocator>
2769basic_string<_CharT, _Traits, _Allocator>&
2770basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2771{
2772 size_type __sz = size();
2773 if (__pos > __sz)
2774 this->__throw_out_of_range();
2775 if (__n)
2776 {
2777 pointer __p = __get_pointer();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002778 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002779 size_type __n_move = __sz - __pos - __n;
2780 if (__n_move != 0)
2781 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2782 __sz -= __n;
2783 __set_size(__sz);
2784 __invalidate_iterators_past(__sz);
2785 traits_type::assign(__p[__sz], value_type());
2786 }
2787 return *this;
2788}
2789
2790template <class _CharT, class _Traits, class _Allocator>
2791_LIBCPP_INLINE_VISIBILITY inline
2792typename basic_string<_CharT, _Traits, _Allocator>::iterator
2793basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2794{
2795 iterator __b = begin();
2796 size_type __r = static_cast<size_type>(__pos - __b);
2797 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002798 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002799}
2800
2801template <class _CharT, class _Traits, class _Allocator>
2802_LIBCPP_INLINE_VISIBILITY inline
2803typename basic_string<_CharT, _Traits, _Allocator>::iterator
2804basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2805{
2806 iterator __b = begin();
2807 size_type __r = static_cast<size_type>(__first - __b);
2808 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00002809 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002810}
2811
2812template <class _CharT, class _Traits, class _Allocator>
2813_LIBCPP_INLINE_VISIBILITY inline
2814void
2815basic_string<_CharT, _Traits, _Allocator>::pop_back()
2816{
2817#ifdef _LIBCPP_DEBUG
2818 assert(!empty());
2819#endif
2820 size_type __sz;
2821 if (__is_long())
2822 {
2823 __sz = __get_long_size() - 1;
2824 __set_long_size(__sz);
2825 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2826 }
2827 else
2828 {
2829 __sz = __get_short_size() - 1;
2830 __set_short_size(__sz);
2831 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2832 }
2833 __invalidate_iterators_past(__sz);
2834}
2835
2836template <class _CharT, class _Traits, class _Allocator>
2837_LIBCPP_INLINE_VISIBILITY inline
2838void
Howard Hinnanta6119a82011-05-29 19:57:12 +00002839basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002840{
2841 __invalidate_all_iterators();
2842 if (__is_long())
2843 {
2844 traits_type::assign(*__get_long_pointer(), value_type());
2845 __set_long_size(0);
2846 }
2847 else
2848 {
2849 traits_type::assign(*__get_short_pointer(), value_type());
2850 __set_short_size(0);
2851 }
2852}
2853
2854template <class _CharT, class _Traits, class _Allocator>
2855_LIBCPP_INLINE_VISIBILITY inline
2856void
2857basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2858{
2859 if (__is_long())
2860 {
2861 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2862 __set_long_size(__pos);
2863 }
2864 else
2865 {
2866 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2867 __set_short_size(__pos);
2868 }
2869 __invalidate_iterators_past(__pos);
2870}
2871
2872template <class _CharT, class _Traits, class _Allocator>
2873void
2874basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2875{
2876 size_type __sz = size();
2877 if (__n > __sz)
2878 append(__n - __sz, __c);
2879 else
2880 __erase_to_end(__n);
2881}
2882
2883template <class _CharT, class _Traits, class _Allocator>
2884_LIBCPP_INLINE_VISIBILITY inline
2885typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002886basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002887{
Howard Hinnante32b5e22010-11-17 17:55:08 +00002888 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002889#if _LIBCPP_BIG_ENDIAN
2890 return (__m <= ~__long_mask ? __m : __m/2) - 1;
2891#else
2892 return __m - 1;
2893#endif
2894}
2895
2896template <class _CharT, class _Traits, class _Allocator>
2897void
2898basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2899{
2900 if (__res_arg > max_size())
2901 this->__throw_length_error();
2902 size_type __cap = capacity();
2903 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002904 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002905 __res_arg = __recommend(__res_arg);
2906 if (__res_arg != __cap)
2907 {
2908 pointer __new_data, __p;
2909 bool __was_long, __now_long;
2910 if (__res_arg == __min_cap - 1)
2911 {
2912 __was_long = true;
2913 __now_long = false;
2914 __new_data = __get_short_pointer();
2915 __p = __get_long_pointer();
2916 }
2917 else
2918 {
2919 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002920 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002921 else
2922 {
2923 #ifndef _LIBCPP_NO_EXCEPTIONS
2924 try
2925 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002926 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00002927 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002928 #ifndef _LIBCPP_NO_EXCEPTIONS
2929 }
2930 catch (...)
2931 {
2932 return;
2933 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002934 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002935 if (__new_data == 0)
2936 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00002937 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002938 }
2939 __now_long = true;
2940 __was_long = __is_long();
2941 __p = __get_pointer();
2942 }
2943 traits_type::copy(__new_data, __p, size()+1);
2944 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002945 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002946 if (__now_long)
2947 {
2948 __set_long_cap(__res_arg+1);
2949 __set_long_size(__sz);
2950 __set_long_pointer(__new_data);
2951 }
2952 else
2953 __set_short_size(__sz);
2954 __invalidate_all_iterators();
2955 }
2956}
2957
2958template <class _CharT, class _Traits, class _Allocator>
2959_LIBCPP_INLINE_VISIBILITY inline
2960typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2961basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
2962{
2963#ifdef __LIBCPP_DEBUG
2964 assert(__pos <= size());
2965#endif
2966 return *(data() + __pos);
2967}
2968
2969template <class _CharT, class _Traits, class _Allocator>
2970_LIBCPP_INLINE_VISIBILITY inline
2971typename basic_string<_CharT, _Traits, _Allocator>::reference
2972basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
2973{
2974#ifdef __LIBCPP_DEBUG
2975 assert(__pos < size());
2976#endif
2977 return *(__get_pointer() + __pos);
2978}
2979
2980template <class _CharT, class _Traits, class _Allocator>
2981typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2982basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
2983{
2984 if (__n >= size())
2985 this->__throw_out_of_range();
2986 return (*this)[__n];
2987}
2988
2989template <class _CharT, class _Traits, class _Allocator>
2990typename basic_string<_CharT, _Traits, _Allocator>::reference
2991basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
2992{
2993 if (__n >= size())
2994 this->__throw_out_of_range();
2995 return (*this)[__n];
2996}
2997
2998template <class _CharT, class _Traits, class _Allocator>
2999_LIBCPP_INLINE_VISIBILITY inline
3000typename basic_string<_CharT, _Traits, _Allocator>::reference
3001basic_string<_CharT, _Traits, _Allocator>::front()
3002{
3003#ifdef _LIBCPP_DEBUG
3004 assert(!empty());
3005#endif
3006 return *__get_pointer();
3007}
3008
3009template <class _CharT, class _Traits, class _Allocator>
3010_LIBCPP_INLINE_VISIBILITY inline
3011typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3012basic_string<_CharT, _Traits, _Allocator>::front() const
3013{
3014#ifdef _LIBCPP_DEBUG
3015 assert(!empty());
3016#endif
3017 return *data();
3018}
3019
3020template <class _CharT, class _Traits, class _Allocator>
3021_LIBCPP_INLINE_VISIBILITY inline
3022typename basic_string<_CharT, _Traits, _Allocator>::reference
3023basic_string<_CharT, _Traits, _Allocator>::back()
3024{
3025#ifdef _LIBCPP_DEBUG
3026 assert(!empty());
3027#endif
3028 return *(__get_pointer() + size() - 1);
3029}
3030
3031template <class _CharT, class _Traits, class _Allocator>
3032_LIBCPP_INLINE_VISIBILITY inline
3033typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3034basic_string<_CharT, _Traits, _Allocator>::back() const
3035{
3036#ifdef _LIBCPP_DEBUG
3037 assert(!empty());
3038#endif
3039 return *(data() + size() - 1);
3040}
3041
3042template <class _CharT, class _Traits, class _Allocator>
3043typename basic_string<_CharT, _Traits, _Allocator>::size_type
3044basic_string<_CharT, _Traits, _Allocator>::copy(pointer __s, size_type __n, size_type __pos) const
3045{
3046 size_type __sz = size();
3047 if (__pos > __sz)
3048 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003049 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003050 traits_type::copy(__s, data() + __pos, __rlen);
3051 return __rlen;
3052}
3053
3054template <class _CharT, class _Traits, class _Allocator>
3055_LIBCPP_INLINE_VISIBILITY inline
3056basic_string<_CharT, _Traits, _Allocator>
3057basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3058{
3059 return basic_string(*this, __pos, __n, __alloc());
3060}
3061
3062template <class _CharT, class _Traits, class _Allocator>
3063_LIBCPP_INLINE_VISIBILITY inline
3064void
3065basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003066 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3067 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003068{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003069 _VSTD::swap(__r_.first(), __str.__r_.first());
Howard Hinnante32b5e22010-11-17 17:55:08 +00003070 __swap_alloc(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003071#ifdef _LIBCPP_DEBUG
3072 __invalidate_all_iterators();
3073 __str.__invalidate_all_iterators();
Howard Hinnant324bb032010-08-22 00:02:43 +00003074#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003075}
3076
3077// find
3078
3079template <class _Traits>
3080struct _LIBCPP_HIDDEN __traits_eq
3081{
3082 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003083 _LIBCPP_INLINE_VISIBILITY
3084 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3085 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003086};
3087
3088template<class _CharT, class _Traits, class _Allocator>
3089typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003090basic_string<_CharT, _Traits, _Allocator>::find(const_pointer __s,
3091 size_type __pos,
3092 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003093{
3094#ifdef _LIBCPP_DEBUG
3095 assert(__s != 0);
3096#endif
3097 size_type __sz = size();
3098 if (__pos > __sz || __sz - __pos < __n)
3099 return npos;
3100 if (__n == 0)
3101 return __pos;
3102 const_pointer __p = data();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003103 const_pointer __r = _VSTD::search(__p + __pos, __p + __sz, __s, __s + __n,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003104 __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003105 if (__r == __p + __sz)
3106 return npos;
3107 return static_cast<size_type>(__r - __p);
3108}
3109
3110template<class _CharT, class _Traits, class _Allocator>
3111_LIBCPP_INLINE_VISIBILITY inline
3112typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003113basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3114 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003115{
3116 return find(__str.data(), __pos, __str.size());
3117}
3118
3119template<class _CharT, class _Traits, class _Allocator>
3120_LIBCPP_INLINE_VISIBILITY inline
3121typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003122basic_string<_CharT, _Traits, _Allocator>::find(const_pointer __s,
3123 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003124{
3125#ifdef _LIBCPP_DEBUG
3126 assert(__s != 0);
3127#endif
3128 return find(__s, __pos, traits_type::length(__s));
3129}
3130
3131template<class _CharT, class _Traits, class _Allocator>
3132typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003133basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3134 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003135{
3136 size_type __sz = size();
3137 if (__pos >= __sz)
3138 return npos;
3139 const_pointer __p = data();
3140 const_pointer __r = traits_type::find(__p + __pos, __sz - __pos, __c);
3141 if (__r == 0)
3142 return npos;
3143 return static_cast<size_type>(__r - __p);
3144}
3145
3146// rfind
3147
3148template<class _CharT, class _Traits, class _Allocator>
3149typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003150basic_string<_CharT, _Traits, _Allocator>::rfind(const_pointer __s,
3151 size_type __pos,
3152 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003153{
3154#ifdef _LIBCPP_DEBUG
3155 assert(__s != 0);
3156#endif
3157 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003158 __pos = _VSTD::min(__pos, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003159 if (__n < __sz - __pos)
3160 __pos += __n;
3161 else
3162 __pos = __sz;
3163 const_pointer __p = data();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003164 const_pointer __r = _VSTD::find_end(__p, __p + __pos, __s, __s + __n,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003165 __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003166 if (__n > 0 && __r == __p + __pos)
3167 return npos;
3168 return static_cast<size_type>(__r - __p);
3169}
3170
3171template<class _CharT, class _Traits, class _Allocator>
3172_LIBCPP_INLINE_VISIBILITY inline
3173typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003174basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3175 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003176{
3177 return rfind(__str.data(), __pos, __str.size());
3178}
3179
3180template<class _CharT, class _Traits, class _Allocator>
3181_LIBCPP_INLINE_VISIBILITY inline
3182typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003183basic_string<_CharT, _Traits, _Allocator>::rfind(const_pointer __s,
3184 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003185{
3186#ifdef _LIBCPP_DEBUG
3187 assert(__s != 0);
3188#endif
3189 return rfind(__s, __pos, traits_type::length(__s));
3190}
3191
3192template<class _CharT, class _Traits, class _Allocator>
3193typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003194basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3195 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003196{
3197 size_type __sz = size();
3198 if (__sz)
3199 {
3200 if (__pos < __sz)
3201 ++__pos;
3202 else
3203 __pos = __sz;
3204 const_pointer __p = data();
3205 for (const_pointer __ps = __p + __pos; __ps != __p;)
3206 {
3207 if (traits_type::eq(*--__ps, __c))
3208 return static_cast<size_type>(__ps - __p);
3209 }
3210 }
3211 return npos;
3212}
3213
3214// find_first_of
3215
3216template<class _CharT, class _Traits, class _Allocator>
3217typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003218basic_string<_CharT, _Traits, _Allocator>::find_first_of(const_pointer __s,
3219 size_type __pos,
3220 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003221{
3222#ifdef _LIBCPP_DEBUG
3223 assert(__s != 0);
3224#endif
3225 size_type __sz = size();
3226 if (__pos >= __sz || __n == 0)
3227 return npos;
3228 const_pointer __p = data();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003229 const_pointer __r = _VSTD::find_first_of(__p + __pos, __p + __sz, __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003230 __s + __n, __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003231 if (__r == __p + __sz)
3232 return npos;
3233 return static_cast<size_type>(__r - __p);
3234}
3235
3236template<class _CharT, class _Traits, class _Allocator>
3237_LIBCPP_INLINE_VISIBILITY inline
3238typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003239basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3240 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003241{
3242 return find_first_of(__str.data(), __pos, __str.size());
3243}
3244
3245template<class _CharT, class _Traits, class _Allocator>
3246_LIBCPP_INLINE_VISIBILITY inline
3247typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003248basic_string<_CharT, _Traits, _Allocator>::find_first_of(const_pointer __s,
3249 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003250{
3251#ifdef _LIBCPP_DEBUG
3252 assert(__s != 0);
3253#endif
3254 return find_first_of(__s, __pos, traits_type::length(__s));
3255}
3256
3257template<class _CharT, class _Traits, class _Allocator>
3258_LIBCPP_INLINE_VISIBILITY inline
3259typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003260basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3261 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003262{
3263 return find(__c, __pos);
3264}
3265
3266// find_last_of
3267
3268template<class _CharT, class _Traits, class _Allocator>
3269typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003270basic_string<_CharT, _Traits, _Allocator>::find_last_of(const_pointer __s,
3271 size_type __pos,
3272 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003273{
3274#ifdef _LIBCPP_DEBUG
3275 assert(__s != 0);
3276#endif
3277 if (__n != 0)
3278 {
3279 size_type __sz = size();
3280 if (__pos < __sz)
3281 ++__pos;
3282 else
3283 __pos = __sz;
3284 const_pointer __p = data();
3285 for (const_pointer __ps = __p + __pos; __ps != __p;)
3286 {
3287 const_pointer __r = traits_type::find(__s, __n, *--__ps);
3288 if (__r)
3289 return static_cast<size_type>(__ps - __p);
3290 }
3291 }
3292 return npos;
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_last_of(const basic_string& __str,
3299 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003300{
3301 return find_last_of(__str.data(), __pos, __str.size());
3302}
3303
3304template<class _CharT, class _Traits, class _Allocator>
3305_LIBCPP_INLINE_VISIBILITY inline
3306typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003307basic_string<_CharT, _Traits, _Allocator>::find_last_of(const_pointer __s,
3308 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003309{
3310#ifdef _LIBCPP_DEBUG
3311 assert(__s != 0);
3312#endif
3313 return find_last_of(__s, __pos, traits_type::length(__s));
3314}
3315
3316template<class _CharT, class _Traits, class _Allocator>
3317_LIBCPP_INLINE_VISIBILITY inline
3318typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003319basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3320 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003321{
3322 return rfind(__c, __pos);
3323}
3324
3325// find_first_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_first_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 {
3339 const_pointer __p = data();
3340 const_pointer __pe = __p + __sz;
3341 for (const_pointer __ps = __p + __pos; __ps != __pe; ++__ps)
3342 if (traits_type::find(__s, __n, *__ps) == 0)
3343 return static_cast<size_type>(__ps - __p);
3344 }
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_first_not_of(const basic_string& __str,
3352 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003353{
3354 return find_first_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_first_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_first_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_first_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 {
3378 const_pointer __p = data();
3379 const_pointer __pe = __p + __sz;
Howard Hinnant352bd3a2012-12-31 20:09:48 +00003380 for (const_pointer __ps = __p + __pos; __ps != __pe; ++__ps)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003381 if (!traits_type::eq(*__ps, __c))
3382 return static_cast<size_type>(__ps - __p);
3383 }
3384 return npos;
3385}
3386
3387// find_last_not_of
3388
3389template<class _CharT, class _Traits, class _Allocator>
3390typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003391basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const_pointer __s,
3392 size_type __pos,
3393 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003394{
3395#ifdef _LIBCPP_DEBUG
3396 assert(__s != 0);
3397#endif
3398 size_type __sz = size();
3399 if (__pos < __sz)
3400 ++__pos;
3401 else
3402 __pos = __sz;
3403 const_pointer __p = data();
3404 for (const_pointer __ps = __p + __pos; __ps != __p;)
3405 if (traits_type::find(__s, __n, *--__ps) == 0)
3406 return static_cast<size_type>(__ps - __p);
3407 return npos;
3408}
3409
3410template<class _CharT, class _Traits, class _Allocator>
3411_LIBCPP_INLINE_VISIBILITY inline
3412typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003413basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3414 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003415{
3416 return find_last_not_of(__str.data(), __pos, __str.size());
3417}
3418
3419template<class _CharT, class _Traits, class _Allocator>
3420_LIBCPP_INLINE_VISIBILITY inline
3421typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003422basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const_pointer __s,
3423 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003424{
3425#ifdef _LIBCPP_DEBUG
3426 assert(__s != 0);
3427#endif
3428 return find_last_not_of(__s, __pos, traits_type::length(__s));
3429}
3430
3431template<class _CharT, class _Traits, class _Allocator>
3432_LIBCPP_INLINE_VISIBILITY inline
3433typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003434basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3435 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003436{
3437 size_type __sz = size();
3438 if (__pos < __sz)
3439 ++__pos;
3440 else
3441 __pos = __sz;
3442 const_pointer __p = data();
3443 for (const_pointer __ps = __p + __pos; __ps != __p;)
3444 if (!traits_type::eq(*--__ps, __c))
3445 return static_cast<size_type>(__ps - __p);
3446 return npos;
3447}
3448
3449// compare
3450
3451template <class _CharT, class _Traits, class _Allocator>
3452_LIBCPP_INLINE_VISIBILITY inline
3453int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003454basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003455{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003456 size_t __lhs_sz = size();
3457 size_t __rhs_sz = __str.size();
3458 int __result = traits_type::compare(data(), __str.data(),
3459 _VSTD::min(__lhs_sz, __rhs_sz));
3460 if (__result != 0)
3461 return __result;
3462 if (__lhs_sz < __rhs_sz)
3463 return -1;
3464 if (__lhs_sz > __rhs_sz)
3465 return 1;
3466 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003467}
3468
3469template <class _CharT, class _Traits, class _Allocator>
3470_LIBCPP_INLINE_VISIBILITY inline
3471int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003472basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3473 size_type __n1,
3474 const basic_string& __str) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003475{
3476 return compare(__pos1, __n1, __str.data(), __str.size());
3477}
3478
3479template <class _CharT, class _Traits, class _Allocator>
3480int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003481basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3482 size_type __n1,
3483 const basic_string& __str,
3484 size_type __pos2,
3485 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003486{
3487 size_type __sz = __str.size();
3488 if (__pos2 > __sz)
3489 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003490 return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003491 __sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003492}
3493
3494template <class _CharT, class _Traits, class _Allocator>
3495int
Howard Hinnantec3773c2011-12-01 20:21:04 +00003496basic_string<_CharT, _Traits, _Allocator>::compare(const_pointer __s) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003497{
3498#ifdef _LIBCPP_DEBUG
3499 assert(__s != 0);
3500#endif
3501 return compare(0, npos, __s, traits_type::length(__s));
3502}
3503
3504template <class _CharT, class _Traits, class _Allocator>
3505int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003506basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3507 size_type __n1,
3508 const_pointer __s) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003509{
3510#ifdef _LIBCPP_DEBUG
3511 assert(__s != 0);
3512#endif
3513 return compare(__pos1, __n1, __s, traits_type::length(__s));
3514}
3515
3516template <class _CharT, class _Traits, class _Allocator>
3517int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003518basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3519 size_type __n1,
3520 const_pointer __s,
3521 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003522{
3523#ifdef _LIBCPP_DEBUG
3524 assert(__s != 0);
3525#endif
3526 size_type __sz = size();
3527 if (__pos1 > __sz || __n2 == npos)
3528 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003529 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3530 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003531 if (__r == 0)
3532 {
3533 if (__rlen < __n2)
3534 __r = -1;
3535 else if (__rlen > __n2)
3536 __r = 1;
3537 }
3538 return __r;
3539}
3540
3541// __invariants
3542
3543template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00003544_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003545bool
3546basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3547{
3548 if (size() > capacity())
3549 return false;
3550 if (capacity() < __min_cap - 1)
3551 return false;
3552 if (data() == 0)
3553 return false;
3554 if (data()[size()] != value_type(0))
3555 return false;
3556 return true;
3557}
3558
3559// operator==
3560
3561template<class _CharT, class _Traits, class _Allocator>
3562_LIBCPP_INLINE_VISIBILITY inline
3563bool
3564operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003565 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003566{
Howard Hinnanta6119a82011-05-29 19:57:12 +00003567 return __lhs.size() == __rhs.size() && _Traits::compare(__lhs.data(),
3568 __rhs.data(),
3569 __lhs.size()) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003570}
3571
3572template<class _CharT, class _Traits, class _Allocator>
3573_LIBCPP_INLINE_VISIBILITY inline
3574bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003575operator==(const _CharT* __lhs,
3576 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003577{
3578 return __rhs.compare(__lhs) == 0;
3579}
3580
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003581template<class _CharT, class _Traits, class _Allocator>
3582_LIBCPP_INLINE_VISIBILITY inline
3583bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003584operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3585 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003586{
3587 return __lhs.compare(__rhs) == 0;
3588}
3589
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003590// operator!=
3591
Howard Hinnant324bb032010-08-22 00:02:43 +00003592template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003593_LIBCPP_INLINE_VISIBILITY inline
3594bool
3595operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003596 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003597{
3598 return !(__lhs == __rhs);
3599}
3600
3601template<class _CharT, class _Traits, class _Allocator>
3602_LIBCPP_INLINE_VISIBILITY inline
3603bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003604operator!=(const _CharT* __lhs,
3605 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003606{
3607 return !(__lhs == __rhs);
3608}
3609
3610template<class _CharT, class _Traits, class _Allocator>
3611_LIBCPP_INLINE_VISIBILITY inline
3612bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003613operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3614 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003615{
3616 return !(__lhs == __rhs);
3617}
3618
3619// operator<
3620
3621template<class _CharT, class _Traits, class _Allocator>
3622_LIBCPP_INLINE_VISIBILITY inline
3623bool
3624operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003625 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003626{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003627 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003628}
3629
3630template<class _CharT, class _Traits, class _Allocator>
3631_LIBCPP_INLINE_VISIBILITY inline
3632bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003633operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3634 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003635{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003636 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003637}
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
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003648// operator>
3649
3650template<class _CharT, class _Traits, class _Allocator>
3651_LIBCPP_INLINE_VISIBILITY inline
3652bool
3653operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003654 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003655{
3656 return __rhs < __lhs;
3657}
3658
3659template<class _CharT, class _Traits, class _Allocator>
3660_LIBCPP_INLINE_VISIBILITY inline
3661bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003662operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3663 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003664{
3665 return __rhs < __lhs;
3666}
3667
3668template<class _CharT, class _Traits, class _Allocator>
3669_LIBCPP_INLINE_VISIBILITY inline
3670bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003671operator> (const _CharT* __lhs,
3672 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003673{
3674 return __rhs < __lhs;
3675}
3676
3677// operator<=
3678
3679template<class _CharT, class _Traits, class _Allocator>
3680_LIBCPP_INLINE_VISIBILITY inline
3681bool
3682operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003683 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003684{
3685 return !(__rhs < __lhs);
3686}
3687
3688template<class _CharT, class _Traits, class _Allocator>
3689_LIBCPP_INLINE_VISIBILITY inline
3690bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003691operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3692 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003693{
3694 return !(__rhs < __lhs);
3695}
3696
3697template<class _CharT, class _Traits, class _Allocator>
3698_LIBCPP_INLINE_VISIBILITY inline
3699bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003700operator<=(const _CharT* __lhs,
3701 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003702{
3703 return !(__rhs < __lhs);
3704}
3705
3706// operator>=
3707
3708template<class _CharT, class _Traits, class _Allocator>
3709_LIBCPP_INLINE_VISIBILITY inline
3710bool
3711operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003712 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003713{
3714 return !(__lhs < __rhs);
3715}
3716
3717template<class _CharT, class _Traits, class _Allocator>
3718_LIBCPP_INLINE_VISIBILITY inline
3719bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003720operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3721 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003722{
3723 return !(__lhs < __rhs);
3724}
3725
3726template<class _CharT, class _Traits, class _Allocator>
3727_LIBCPP_INLINE_VISIBILITY inline
3728bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003729operator>=(const _CharT* __lhs,
3730 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003731{
3732 return !(__lhs < __rhs);
3733}
3734
3735// operator +
3736
3737template<class _CharT, class _Traits, class _Allocator>
3738basic_string<_CharT, _Traits, _Allocator>
3739operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3740 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3741{
3742 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3743 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3744 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3745 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3746 __r.append(__rhs.data(), __rhs_sz);
3747 return __r;
3748}
3749
3750template<class _CharT, class _Traits, class _Allocator>
3751basic_string<_CharT, _Traits, _Allocator>
3752operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3753{
3754 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3755 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3756 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3757 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3758 __r.append(__rhs.data(), __rhs_sz);
3759 return __r;
3760}
3761
3762template<class _CharT, class _Traits, class _Allocator>
3763basic_string<_CharT, _Traits, _Allocator>
3764operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3765{
3766 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3767 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3768 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3769 __r.append(__rhs.data(), __rhs_sz);
3770 return __r;
3771}
3772
3773template<class _CharT, class _Traits, class _Allocator>
3774basic_string<_CharT, _Traits, _Allocator>
3775operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3776{
3777 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3778 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3779 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3780 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3781 __r.append(__rhs, __rhs_sz);
3782 return __r;
3783}
3784
3785template<class _CharT, class _Traits, class _Allocator>
3786basic_string<_CharT, _Traits, _Allocator>
3787operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3788{
3789 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3790 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3791 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3792 __r.push_back(__rhs);
3793 return __r;
3794}
3795
Howard Hinnant73d21a42010-09-04 23:28:19 +00003796#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003797
3798template<class _CharT, class _Traits, class _Allocator>
3799_LIBCPP_INLINE_VISIBILITY inline
3800basic_string<_CharT, _Traits, _Allocator>
3801operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3802{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003803 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003804}
3805
3806template<class _CharT, class _Traits, class _Allocator>
3807_LIBCPP_INLINE_VISIBILITY inline
3808basic_string<_CharT, _Traits, _Allocator>
3809operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3810{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003811 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003812}
3813
3814template<class _CharT, class _Traits, class _Allocator>
3815_LIBCPP_INLINE_VISIBILITY inline
3816basic_string<_CharT, _Traits, _Allocator>
3817operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3818{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003819 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003820}
3821
3822template<class _CharT, class _Traits, class _Allocator>
3823_LIBCPP_INLINE_VISIBILITY inline
3824basic_string<_CharT, _Traits, _Allocator>
3825operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3826{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003827 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003828}
3829
3830template<class _CharT, class _Traits, class _Allocator>
3831_LIBCPP_INLINE_VISIBILITY inline
3832basic_string<_CharT, _Traits, _Allocator>
3833operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3834{
3835 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003836 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003837}
3838
3839template<class _CharT, class _Traits, class _Allocator>
3840_LIBCPP_INLINE_VISIBILITY inline
3841basic_string<_CharT, _Traits, _Allocator>
3842operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3843{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003844 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003845}
3846
3847template<class _CharT, class _Traits, class _Allocator>
3848_LIBCPP_INLINE_VISIBILITY inline
3849basic_string<_CharT, _Traits, _Allocator>
3850operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3851{
3852 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003853 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003854}
3855
Howard Hinnant73d21a42010-09-04 23:28:19 +00003856#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003857
3858// swap
3859
3860template<class _CharT, class _Traits, class _Allocator>
3861_LIBCPP_INLINE_VISIBILITY inline
3862void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003863swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003864 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3865 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003866{
3867 __lhs.swap(__rhs);
3868}
3869
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003870#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3871
3872typedef basic_string<char16_t> u16string;
3873typedef basic_string<char32_t> u32string;
3874
Howard Hinnant324bb032010-08-22 00:02:43 +00003875#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003876
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003877int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3878long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3879unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3880long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
3881unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
3882
3883float stof (const string& __str, size_t* __idx = 0);
3884double stod (const string& __str, size_t* __idx = 0);
3885long double stold(const string& __str, size_t* __idx = 0);
3886
3887string to_string(int __val);
3888string to_string(unsigned __val);
3889string to_string(long __val);
3890string to_string(unsigned long __val);
3891string to_string(long long __val);
3892string to_string(unsigned long long __val);
3893string to_string(float __val);
3894string to_string(double __val);
3895string to_string(long double __val);
3896
3897int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
3898long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
3899unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
3900long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
3901unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
3902
3903float stof (const wstring& __str, size_t* __idx = 0);
3904double stod (const wstring& __str, size_t* __idx = 0);
3905long double stold(const wstring& __str, size_t* __idx = 0);
3906
3907wstring to_wstring(int __val);
3908wstring to_wstring(unsigned __val);
3909wstring to_wstring(long __val);
3910wstring to_wstring(unsigned long __val);
3911wstring to_wstring(long long __val);
3912wstring to_wstring(unsigned long long __val);
3913wstring to_wstring(float __val);
3914wstring to_wstring(double __val);
3915wstring to_wstring(long double __val);
3916
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003917template<class _CharT, class _Traits, class _Allocator>
3918 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
3919 basic_string<_CharT, _Traits, _Allocator>::npos;
3920
Sean Huntaffd9e52011-07-29 23:31:56 +00003921template<class _Ptr>
3922size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
3923{
Howard Hinnant40c13d32011-12-05 00:08:45 +00003924 typedef typename iterator_traits<_Ptr>::value_type value_type;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003925 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
Sean Huntaffd9e52011-07-29 23:31:56 +00003926}
3927
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003928template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant8d7a9552010-09-23 17:31:07 +00003929struct _LIBCPP_VISIBLE hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003930 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
3931{
3932 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00003933 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003934};
3935
3936template<class _CharT, class _Traits, class _Allocator>
3937size_t
3938hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00003939 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003940{
Sean Huntaffd9e52011-07-29 23:31:56 +00003941 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003942}
3943
Howard Hinnant464aa5c2011-07-18 15:51:59 +00003944template<class _CharT, class _Traits, class _Allocator>
3945basic_ostream<_CharT, _Traits>&
3946operator<<(basic_ostream<_CharT, _Traits>& __os,
3947 const basic_string<_CharT, _Traits, _Allocator>& __str);
3948
3949template<class _CharT, class _Traits, class _Allocator>
3950basic_istream<_CharT, _Traits>&
3951operator>>(basic_istream<_CharT, _Traits>& __is,
3952 basic_string<_CharT, _Traits, _Allocator>& __str);
3953
3954template<class _CharT, class _Traits, class _Allocator>
3955basic_istream<_CharT, _Traits>&
3956getline(basic_istream<_CharT, _Traits>& __is,
3957 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3958
3959template<class _CharT, class _Traits, class _Allocator>
3960inline _LIBCPP_INLINE_VISIBILITY
3961basic_istream<_CharT, _Traits>&
3962getline(basic_istream<_CharT, _Traits>& __is,
3963 basic_string<_CharT, _Traits, _Allocator>& __str);
3964
3965#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3966
3967template<class _CharT, class _Traits, class _Allocator>
3968inline _LIBCPP_INLINE_VISIBILITY
3969basic_istream<_CharT, _Traits>&
3970getline(basic_istream<_CharT, _Traits>&& __is,
3971 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3972
3973template<class _CharT, class _Traits, class _Allocator>
3974inline _LIBCPP_INLINE_VISIBILITY
3975basic_istream<_CharT, _Traits>&
3976getline(basic_istream<_CharT, _Traits>&& __is,
3977 basic_string<_CharT, _Traits, _Allocator>& __str);
3978
3979#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3980
Howard Hinnantff926772012-11-06 21:08:48 +00003981_LIBCPP_EXTERN_TEMPLATE(class basic_string<char>)
3982_LIBCPP_EXTERN_TEMPLATE(class basic_string<wchar_t>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003983
3984extern template
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003985 string
3986 operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
3987
3988_LIBCPP_END_NAMESPACE_STD
3989
3990#endif // _LIBCPP_STRING