blob: 283be3a35bc1f7312b1473069900ca3c031ee57b [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 Hinnant9dcdcde2013-06-28 16:59:19 +0000103 basic_string(const value_type* s, const allocator_type& a = allocator_type());
104 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000105 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 Hinnant9dcdcde2013-06-28 16:59:19 +0000120 basic_string& operator=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000121 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);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000159 basic_string& operator+=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000160 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);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000165 basic_string& append(const value_type* s, size_type n);
166 basic_string& append(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000167 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);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000182 basic_string& assign(const value_type* s, size_type n);
183 basic_string& assign(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000184 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 Hinnant9dcdcde2013-06-28 16:59:19 +0000192 basic_string& insert(size_type pos, const value_type* s, size_type n);
193 basic_string& insert(size_type pos, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000194 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 Hinnant9dcdcde2013-06-28 16:59:19 +0000208 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
209 basic_string& replace(size_type pos, size_type n1, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000210 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);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000212 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
213 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000214 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
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000219 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000220 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 Hinnant9dcdcde2013-06-28 16:59:19 +0000226 const value_type* c_str() const noexcept;
227 const value_type* 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;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000232 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
233 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000234 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;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000237 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
238 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000239 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;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000242 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
243 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000244 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;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000247 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
248 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000249 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;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000252 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
253 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000254 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;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000257 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
258 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000259 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 Hinnant9dcdcde2013-06-28 16:59:19 +0000265 int compare(const value_type* s) const noexcept;
266 int compare(size_type pos1, size_type n1, const value_type* s) const;
267 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000268
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
Marshall Clow15234322013-07-23 17:05:24 +0000425basic_string<char> operator "" s( const char *str, size_t len ); // C++14
426basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
427basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
428basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
429
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430} // std
431
432*/
433
434#include <__config>
435#include <iosfwd>
436#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000437#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000438#include <cwchar>
439#include <algorithm>
440#include <iterator>
441#include <utility>
442#include <memory>
443#include <stdexcept>
444#include <type_traits>
445#include <initializer_list>
446#include <__functional_base>
447#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
448#include <cstdint>
449#endif
450#if defined(_LIBCPP_NO_EXCEPTIONS) || defined(_LIBCPP_DEBUG)
451#include <cassert>
452#endif
453
Howard Hinnant66c6f972011-11-29 16:45:27 +0000454#include <__undef_min_max>
455
Howard Hinnant08e17472011-10-17 20:05:10 +0000456#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000457#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000458#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459
460_LIBCPP_BEGIN_NAMESPACE_STD
461
462// fpos
463
464template <class _StateT>
Howard Hinnant83eade62013-03-06 23:30:19 +0000465class _LIBCPP_TYPE_VIS fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466{
467private:
468 _StateT __st_;
469 streamoff __off_;
470public:
471 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
472
473 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
474
475 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
476 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
477
478 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
479 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
480 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
481 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
482};
483
484template <class _StateT>
485inline _LIBCPP_INLINE_VISIBILITY
486streamoff 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
494template <class _StateT>
495inline _LIBCPP_INLINE_VISIBILITY
496bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
497 {return streamoff(__x) != streamoff(__y);}
498
499// char_traits
500
501template <class _CharT>
Howard Hinnant83eade62013-03-06 23:30:19 +0000502struct _LIBCPP_TYPE_VIS char_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000503{
504 typedef _CharT char_type;
505 typedef int int_type;
506 typedef streamoff off_type;
507 typedef streampos pos_type;
508 typedef mbstate_t state_type;
509
Howard Hinnanta6119a82011-05-29 19:57:12 +0000510 _LIBCPP_INLINE_VISIBILITY
511 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
512 {__c1 = __c2;}
513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000514 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000515 {return __c1 == __c2;}
516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000517 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000518 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000519
520 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
521 static size_t length(const char_type* __s);
522 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
523 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
524 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
525 static char_type* assign(char_type* __s, size_t __n, char_type __a);
526
Howard Hinnant03d71812012-07-20 19:09:12 +0000527 _LIBCPP_INLINE_VISIBILITY
528 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000531 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000532 {return char_type(__c);}
533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000534 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000535 {return int_type(__c);}
536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000537 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000538 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000539 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000540 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000541 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000542};
543
544template <class _CharT>
545int
546char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
547{
548 for (; __n; --__n, ++__s1, ++__s2)
549 {
550 if (lt(*__s1, *__s2))
551 return -1;
552 if (lt(*__s2, *__s1))
553 return 1;
554 }
555 return 0;
556}
557
558template <class _CharT>
559inline _LIBCPP_INLINE_VISIBILITY
560size_t
561char_traits<_CharT>::length(const char_type* __s)
562{
563 size_t __len = 0;
564 for (; !eq(*__s, char_type(0)); ++__s)
565 ++__len;
566 return __len;
567}
568
569template <class _CharT>
570inline _LIBCPP_INLINE_VISIBILITY
571const _CharT*
572char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
573{
574 for (; __n; --__n)
575 {
576 if (eq(*__s, __a))
577 return __s;
578 ++__s;
579 }
580 return 0;
581}
582
583template <class _CharT>
584_CharT*
585char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
586{
587 char_type* __r = __s1;
588 if (__s1 < __s2)
589 {
590 for (; __n; --__n, ++__s1, ++__s2)
591 assign(*__s1, *__s2);
592 }
593 else if (__s2 < __s1)
594 {
595 __s1 += __n;
596 __s2 += __n;
597 for (; __n; --__n)
598 assign(*--__s1, *--__s2);
599 }
600 return __r;
601}
602
603template <class _CharT>
604inline _LIBCPP_INLINE_VISIBILITY
605_CharT*
606char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
607{
608 char_type* __r = __s1;
609 for (; __n; --__n, ++__s1, ++__s2)
610 assign(*__s1, *__s2);
611 return __r;
612}
613
614template <class _CharT>
615inline _LIBCPP_INLINE_VISIBILITY
616_CharT*
617char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
618{
619 char_type* __r = __s;
620 for (; __n; --__n, ++__s)
621 assign(*__s, __a);
622 return __r;
623}
624
625// char_traits<char>
626
627template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000628struct _LIBCPP_TYPE_VIS char_traits<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000629{
630 typedef char char_type;
631 typedef int int_type;
632 typedef streamoff off_type;
633 typedef streampos pos_type;
634 typedef mbstate_t state_type;
635
Howard Hinnanta6119a82011-05-29 19:57:12 +0000636 _LIBCPP_INLINE_VISIBILITY
637 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
638 {__c1 = __c2;}
639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000640 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000641 {return __c1 == __c2;}
642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000643 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000644 {return (unsigned char)__c1 < (unsigned char)__c2;}
645
Howard Hinnanta6119a82011-05-29 19:57:12 +0000646 _LIBCPP_INLINE_VISIBILITY
647 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000648 {return memcmp(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000649 _LIBCPP_INLINE_VISIBILITY
650 static size_t length(const char_type* __s) {return strlen(__s);}
651 _LIBCPP_INLINE_VISIBILITY
652 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000653 {return (const char_type*)memchr(__s, to_int_type(__a), __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000654 _LIBCPP_INLINE_VISIBILITY
655 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656 {return (char_type*)memmove(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000657 _LIBCPP_INLINE_VISIBILITY
658 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659 {return (char_type*)memcpy(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000660 _LIBCPP_INLINE_VISIBILITY
661 static char_type* assign(char_type* __s, size_t __n, char_type __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000662 {return (char_type*)memset(__s, to_int_type(__a), __n);}
663
Howard Hinnant03d71812012-07-20 19:09:12 +0000664 _LIBCPP_INLINE_VISIBILITY
665 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000666 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000668 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000669 {return char_type(__c);}
670 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000671 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000672 {return int_type((unsigned char)__c);}
673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000674 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000675 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000677 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000678 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679};
680
681// char_traits<wchar_t>
682
683template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000684struct _LIBCPP_TYPE_VIS char_traits<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000685{
686 typedef wchar_t char_type;
687 typedef wint_t int_type;
688 typedef streamoff off_type;
689 typedef streampos pos_type;
690 typedef mbstate_t state_type;
691
Howard Hinnanta6119a82011-05-29 19:57:12 +0000692 _LIBCPP_INLINE_VISIBILITY
693 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
694 {__c1 = __c2;}
695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000696 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000697 {return __c1 == __c2;}
698 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000699 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000700 {return __c1 < __c2;}
701
Howard Hinnanta6119a82011-05-29 19:57:12 +0000702 _LIBCPP_INLINE_VISIBILITY
703 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704 {return wmemcmp(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000705 _LIBCPP_INLINE_VISIBILITY
706 static size_t length(const char_type* __s)
707 {return wcslen(__s);}
708 _LIBCPP_INLINE_VISIBILITY
709 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000710 {return (const char_type*)wmemchr(__s, __a, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000711 _LIBCPP_INLINE_VISIBILITY
712 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713 {return (char_type*)wmemmove(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000714 _LIBCPP_INLINE_VISIBILITY
715 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000716 {return (char_type*)wmemcpy(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000717 _LIBCPP_INLINE_VISIBILITY
718 static char_type* assign(char_type* __s, size_t __n, char_type __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000719 {return (char_type*)wmemset(__s, __a, __n);}
720
Howard Hinnanta6119a82011-05-29 19:57:12 +0000721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000722 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000723 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000725 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000726 {return char_type(__c);}
727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000728 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000729 {return int_type(__c);}
730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000731 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000732 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000734 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000735 {return int_type(WEOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000736};
737
738#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
739
740template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000741struct _LIBCPP_TYPE_VIS char_traits<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000742{
743 typedef char16_t char_type;
744 typedef uint_least16_t int_type;
745 typedef streamoff off_type;
746 typedef u16streampos pos_type;
747 typedef mbstate_t state_type;
748
Howard Hinnanta6119a82011-05-29 19:57:12 +0000749 _LIBCPP_INLINE_VISIBILITY
750 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
751 {__c1 = __c2;}
752 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000753 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000754 {return __c1 == __c2;}
755 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000756 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000757 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000758
759 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
760 static size_t length(const char_type* __s);
761 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
762 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
763 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
764 static char_type* assign(char_type* __s, size_t __n, char_type __a);
765
Howard Hinnanta6119a82011-05-29 19:57:12 +0000766 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000767 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000768 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000769 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000770 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000771 {return char_type(__c);}
772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000773 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000774 {return int_type(__c);}
775 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000776 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000777 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000778 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000779 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000780 {return int_type(0xDFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000781};
782
783inline _LIBCPP_INLINE_VISIBILITY
784int
785char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
786{
787 for (; __n; --__n, ++__s1, ++__s2)
788 {
789 if (lt(*__s1, *__s2))
790 return -1;
791 if (lt(*__s2, *__s1))
792 return 1;
793 }
794 return 0;
795}
796
797inline _LIBCPP_INLINE_VISIBILITY
798size_t
799char_traits<char16_t>::length(const char_type* __s)
800{
801 size_t __len = 0;
802 for (; !eq(*__s, char_type(0)); ++__s)
803 ++__len;
804 return __len;
805}
806
807inline _LIBCPP_INLINE_VISIBILITY
808const char16_t*
809char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
810{
811 for (; __n; --__n)
812 {
813 if (eq(*__s, __a))
814 return __s;
815 ++__s;
816 }
817 return 0;
818}
819
820inline _LIBCPP_INLINE_VISIBILITY
821char16_t*
822char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
823{
824 char_type* __r = __s1;
825 if (__s1 < __s2)
826 {
827 for (; __n; --__n, ++__s1, ++__s2)
828 assign(*__s1, *__s2);
829 }
830 else if (__s2 < __s1)
831 {
832 __s1 += __n;
833 __s2 += __n;
834 for (; __n; --__n)
835 assign(*--__s1, *--__s2);
836 }
837 return __r;
838}
839
840inline _LIBCPP_INLINE_VISIBILITY
841char16_t*
842char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
843{
844 char_type* __r = __s1;
845 for (; __n; --__n, ++__s1, ++__s2)
846 assign(*__s1, *__s2);
847 return __r;
848}
849
850inline _LIBCPP_INLINE_VISIBILITY
851char16_t*
852char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
853{
854 char_type* __r = __s;
855 for (; __n; --__n, ++__s)
856 assign(*__s, __a);
857 return __r;
858}
859
860template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000861struct _LIBCPP_TYPE_VIS char_traits<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862{
863 typedef char32_t char_type;
864 typedef uint_least32_t int_type;
865 typedef streamoff off_type;
866 typedef u32streampos pos_type;
867 typedef mbstate_t state_type;
868
Howard Hinnanta6119a82011-05-29 19:57:12 +0000869 _LIBCPP_INLINE_VISIBILITY
870 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
871 {__c1 = __c2;}
872 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000873 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000874 {return __c1 == __c2;}
875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000876 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000877 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878
879 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
880 static size_t length(const char_type* __s);
881 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
882 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
883 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
884 static char_type* assign(char_type* __s, size_t __n, char_type __a);
885
Howard Hinnanta6119a82011-05-29 19:57:12 +0000886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000887 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000889 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000890 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000891 {return char_type(__c);}
892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000893 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000894 {return int_type(__c);}
895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000896 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000899 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000900 {return int_type(0xFFFFFFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901};
902
903inline _LIBCPP_INLINE_VISIBILITY
904int
905char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
906{
907 for (; __n; --__n, ++__s1, ++__s2)
908 {
909 if (lt(*__s1, *__s2))
910 return -1;
911 if (lt(*__s2, *__s1))
912 return 1;
913 }
914 return 0;
915}
916
917inline _LIBCPP_INLINE_VISIBILITY
918size_t
919char_traits<char32_t>::length(const char_type* __s)
920{
921 size_t __len = 0;
922 for (; !eq(*__s, char_type(0)); ++__s)
923 ++__len;
924 return __len;
925}
926
927inline _LIBCPP_INLINE_VISIBILITY
928const char32_t*
929char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
930{
931 for (; __n; --__n)
932 {
933 if (eq(*__s, __a))
934 return __s;
935 ++__s;
936 }
937 return 0;
938}
939
940inline _LIBCPP_INLINE_VISIBILITY
941char32_t*
942char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
943{
944 char_type* __r = __s1;
945 if (__s1 < __s2)
946 {
947 for (; __n; --__n, ++__s1, ++__s2)
948 assign(*__s1, *__s2);
949 }
950 else if (__s2 < __s1)
951 {
952 __s1 += __n;
953 __s2 += __n;
954 for (; __n; --__n)
955 assign(*--__s1, *--__s2);
956 }
957 return __r;
958}
959
960inline _LIBCPP_INLINE_VISIBILITY
961char32_t*
962char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
963{
964 char_type* __r = __s1;
965 for (; __n; --__n, ++__s1, ++__s2)
966 assign(*__s1, *__s2);
967 return __r;
968}
969
970inline _LIBCPP_INLINE_VISIBILITY
971char32_t*
972char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
973{
974 char_type* __r = __s;
975 for (; __n; --__n, ++__s)
976 assign(*__s, __a);
977 return __r;
978}
979
Howard Hinnant324bb032010-08-22 00:02:43 +0000980#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000981
982// basic_string
983
984template<class _CharT, class _Traits, class _Allocator>
985basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000986operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
987 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000988
989template<class _CharT, class _Traits, class _Allocator>
990basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000991operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000992
993template<class _CharT, class _Traits, class _Allocator>
994basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000995operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000996
997template<class _CharT, class _Traits, class _Allocator>
998basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000999operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001000
1001template<class _CharT, class _Traits, class _Allocator>
1002basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001003operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001004
1005template <bool>
1006class __basic_string_common
1007{
1008protected:
1009 void __throw_length_error() const;
1010 void __throw_out_of_range() const;
1011};
1012
1013template <bool __b>
1014void
1015__basic_string_common<__b>::__throw_length_error() const
1016{
1017#ifndef _LIBCPP_NO_EXCEPTIONS
1018 throw length_error("basic_string");
1019#else
1020 assert(!"basic_string length_error");
1021#endif
1022}
1023
1024template <bool __b>
1025void
1026__basic_string_common<__b>::__throw_out_of_range() const
1027{
1028#ifndef _LIBCPP_NO_EXCEPTIONS
1029 throw out_of_range("basic_string");
1030#else
1031 assert(!"basic_string out_of_range");
1032#endif
1033}
1034
Howard Hinnante9df0a52013-08-01 18:17:34 +00001035#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +00001036#pragma warning( push )
1037#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34 +00001038#endif // _LIBCPP_MSVC
Howard Hinnantff926772012-11-06 21:08:48 +00001039_LIBCPP_EXTERN_TEMPLATE(class __basic_string_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34 +00001040#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +00001041#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34 +00001042#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001043
Howard Hinnant15467182013-04-30 21:44:48 +00001044#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1045
1046template <class _CharT, size_t = sizeof(_CharT)>
1047struct __padding
1048{
1049 unsigned char __xx[sizeof(_CharT)-1];
1050};
1051
1052template <class _CharT>
1053struct __padding<_CharT, 1>
1054{
1055};
1056
1057#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1058
Howard Hinnant324bb032010-08-22 00:02:43 +00001059template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant83eade62013-03-06 23:30:19 +00001060class _LIBCPP_TYPE_VIS basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001061 : private __basic_string_common<true>
1062{
1063public:
1064 typedef basic_string __self;
1065 typedef _Traits traits_type;
1066 typedef typename traits_type::char_type value_type;
1067 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001068 typedef allocator_traits<allocator_type> __alloc_traits;
1069 typedef typename __alloc_traits::size_type size_type;
1070 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001071 typedef value_type& reference;
1072 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001073 typedef typename __alloc_traits::pointer pointer;
1074 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001075#ifdef _LIBCPP_DEBUG
1076 typedef __debug_iter<basic_string, pointer> iterator;
1077 typedef __debug_iter<basic_string, const_pointer> const_iterator;
1078
1079 friend class __debug_iter<basic_string, pointer>;
1080 friend class __debug_iter<basic_string, const_pointer>;
1081#elif defined(_LIBCPP_RAW_ITERATORS)
1082 typedef pointer iterator;
1083 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001084#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001085 typedef __wrap_iter<pointer> iterator;
1086 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001087#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001088 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1089 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001090
1091private:
Howard Hinnant15467182013-04-30 21:44:48 +00001092
1093#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1094
1095 struct __long
1096 {
1097 pointer __data_;
1098 size_type __size_;
1099 size_type __cap_;
1100 };
1101
1102#if _LIBCPP_BIG_ENDIAN
1103 enum {__short_mask = 0x01};
1104 enum {__long_mask = 0x1ul};
1105#else // _LIBCPP_BIG_ENDIAN
1106 enum {__short_mask = 0x80};
1107 enum {__long_mask = ~(size_type(~0) >> 1)};
1108#endif // _LIBCPP_BIG_ENDIAN
1109
1110 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1111 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1112
1113 struct __short
1114 {
1115 value_type __data_[__min_cap];
1116 struct
1117 : __padding<value_type>
1118 {
1119 unsigned char __size_;
1120 };
1121 };
1122
1123#else
1124
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001125 struct __long
1126 {
1127 size_type __cap_;
1128 size_type __size_;
1129 pointer __data_;
1130 };
1131
1132#if _LIBCPP_BIG_ENDIAN
1133 enum {__short_mask = 0x80};
1134 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43 +00001135#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001136 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04 +00001137 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43 +00001138#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001139
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001140 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1141 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1142
1143 struct __short
1144 {
1145 union
1146 {
1147 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +00001148 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149 };
1150 value_type __data_[__min_cap];
1151 };
1152
Howard Hinnant15467182013-04-30 21:44:48 +00001153#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1154
Howard Hinnant9c0df142012-10-30 19:06:59 +00001155 union __lx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001156
Howard Hinnant9c0df142012-10-30 19:06:59 +00001157 enum {__n_words = sizeof(__lx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001158
1159 struct __raw
1160 {
1161 size_type __words[__n_words];
1162 };
1163
1164 struct __rep
1165 {
1166 union
1167 {
1168 __long __l;
1169 __short __s;
1170 __raw __r;
1171 };
1172 };
1173
1174 __compressed_pair<__rep, allocator_type> __r_;
1175
1176#ifdef _LIBCPP_DEBUG
1177
1178 pair<iterator*, const_iterator*> __iterator_list_;
1179
1180 _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;}
1181 _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
1182
1183#endif // _LIBCPP_DEBUG
1184
1185public:
1186 static const size_type npos = -1;
1187
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001188 _LIBCPP_INLINE_VISIBILITY basic_string()
1189 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001190 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001191 basic_string(const basic_string& __str);
1192 basic_string(const basic_string& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001193#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59 +00001194 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001195 basic_string(basic_string&& __str)
1196 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant9f193f22011-01-26 00:06:59 +00001197 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001199#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001200 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001201 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001202 basic_string(const value_type* __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001203 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001204 basic_string(const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001205 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001206 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001207 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001208 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001209 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001210 basic_string(size_type __n, value_type __c, const allocator_type& __a);
1211 basic_string(const basic_string& __str, size_type __pos, size_type __n = npos,
1212 const allocator_type& __a = allocator_type());
1213 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001214 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001215 basic_string(_InputIterator __first, _InputIterator __last);
1216 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001217 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001219#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001220 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001221 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001222 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001223 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001224#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001225
1226 ~basic_string();
1227
Howard Hinnante32b5e22010-11-17 17:55:08 +00001228 basic_string& operator=(const basic_string& __str);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001229#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001230 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001231 basic_string& operator=(basic_string&& __str)
1232 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1233 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001234#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001235 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001236 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02 +00001237#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001239 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001240#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001241
1242#ifndef _LIBCPP_DEBUG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001243 _LIBCPP_INLINE_VISIBILITY
1244 iterator begin() _NOEXCEPT
1245 {return iterator(__get_pointer());}
1246 _LIBCPP_INLINE_VISIBILITY
1247 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001248 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001249 _LIBCPP_INLINE_VISIBILITY
1250 iterator end() _NOEXCEPT
1251 {return iterator(__get_pointer() + size());}
1252 _LIBCPP_INLINE_VISIBILITY
1253 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001254 {return const_iterator(__get_pointer() + size());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001255#else // _LIBCPP_DEBUG
1256 _LIBCPP_INLINE_VISIBILITY iterator begin() {return iterator(this, __get_pointer());}
1257 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return const_iterator(this, data());}
1258 _LIBCPP_INLINE_VISIBILITY iterator end() {return iterator(this, __get_pointer() + size());}
1259 _LIBCPP_INLINE_VISIBILITY const_iterator end() const {return const_iterator(this, data() + size());}
1260#endif // _LIBCPP_DEBUG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001261 _LIBCPP_INLINE_VISIBILITY
1262 reverse_iterator rbegin() _NOEXCEPT
1263 {return reverse_iterator(end());}
1264 _LIBCPP_INLINE_VISIBILITY
1265 const_reverse_iterator rbegin() const _NOEXCEPT
1266 {return const_reverse_iterator(end());}
1267 _LIBCPP_INLINE_VISIBILITY
1268 reverse_iterator rend() _NOEXCEPT
1269 {return reverse_iterator(begin());}
1270 _LIBCPP_INLINE_VISIBILITY
1271 const_reverse_iterator rend() const _NOEXCEPT
1272 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001273
Howard Hinnanta6119a82011-05-29 19:57:12 +00001274 _LIBCPP_INLINE_VISIBILITY
1275 const_iterator cbegin() const _NOEXCEPT
1276 {return begin();}
1277 _LIBCPP_INLINE_VISIBILITY
1278 const_iterator cend() const _NOEXCEPT
1279 {return end();}
1280 _LIBCPP_INLINE_VISIBILITY
1281 const_reverse_iterator crbegin() const _NOEXCEPT
1282 {return rbegin();}
1283 _LIBCPP_INLINE_VISIBILITY
1284 const_reverse_iterator crend() const _NOEXCEPT
1285 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001286
Howard Hinnanta6119a82011-05-29 19:57:12 +00001287 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001288 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001289 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
1290 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
1291 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001292 {return (__is_long() ? __get_long_cap() : __min_cap) - 1;}
1293
1294 void resize(size_type __n, value_type __c);
1295 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
1296
1297 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001299 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001301 void clear() _NOEXCEPT;
1302 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001303
1304 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
1305 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
1306
1307 const_reference at(size_type __n) const;
1308 reference at(size_type __n);
1309
1310 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001311 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001312 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00001313#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001314 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02 +00001315#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001316
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001317 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001318 basic_string& append(const basic_string& __str);
1319 basic_string& append(const basic_string& __str, size_type __pos, size_type __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001320 basic_string& append(const value_type* __s, size_type __n);
1321 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001322 basic_string& append(size_type __n, value_type __c);
1323 template<class _InputIterator>
1324 typename enable_if
1325 <
1326 __is_input_iterator <_InputIterator>::value &&
1327 !__is_forward_iterator<_InputIterator>::value,
1328 basic_string&
1329 >::type
1330 append(_InputIterator __first, _InputIterator __last);
1331 template<class _ForwardIterator>
1332 typename enable_if
1333 <
1334 __is_forward_iterator<_ForwardIterator>::value,
1335 basic_string&
1336 >::type
1337 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001338#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001339 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001341#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001342
1343 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001344 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001346 _LIBCPP_INLINE_VISIBILITY reference front();
1347 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1348 _LIBCPP_INLINE_VISIBILITY reference back();
1349 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001350
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001351 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001352 basic_string& assign(const basic_string& __str);
Howard Hinnanta6119a82011-05-29 19:57:12 +00001353#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1354 _LIBCPP_INLINE_VISIBILITY
1355 basic_string& assign(basic_string&& str)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001356 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001357#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001358 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001359 basic_string& assign(const value_type* __s, size_type __n);
1360 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001361 basic_string& assign(size_type __n, value_type __c);
1362 template<class _InputIterator>
1363 typename enable_if
1364 <
1365 __is_input_iterator <_InputIterator>::value &&
1366 !__is_forward_iterator<_InputIterator>::value,
1367 basic_string&
1368 >::type
1369 assign(_InputIterator __first, _InputIterator __last);
1370 template<class _ForwardIterator>
1371 typename enable_if
1372 <
1373 __is_forward_iterator<_ForwardIterator>::value,
1374 basic_string&
1375 >::type
1376 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001377#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001378 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001379 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001380#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001381
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001382 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001383 basic_string& insert(size_type __pos1, const basic_string& __str);
1384 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001385 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1386 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001387 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1388 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001389 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001390 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1391 template<class _InputIterator>
1392 typename enable_if
1393 <
1394 __is_input_iterator <_InputIterator>::value &&
1395 !__is_forward_iterator<_InputIterator>::value,
1396 iterator
1397 >::type
1398 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1399 template<class _ForwardIterator>
1400 typename enable_if
1401 <
1402 __is_forward_iterator<_ForwardIterator>::value,
1403 iterator
1404 >::type
1405 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001406#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1409 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001410#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001411
1412 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001414 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001415 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001416 iterator erase(const_iterator __first, const_iterator __last);
1417
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001418 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001419 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
1420 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001421 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1422 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001423 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001425 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001427 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001429 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001430 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001431 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001432 template<class _InputIterator>
1433 typename enable_if
1434 <
1435 __is_input_iterator<_InputIterator>::value,
1436 basic_string&
1437 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001438 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:02 +00001439#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001440 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001441 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001442 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001443#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001444
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001445 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001446 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001447 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1448
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001450 void swap(basic_string& __str)
1451 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1452 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001453
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001455 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001457 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001458
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001460 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001461
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001463 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001464 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001466 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001467 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001468
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001470 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001471 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001473 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001474 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001475
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001477 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001478 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001480 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001482 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001483
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001485 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001486 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001488 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001490 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001491
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001493 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001494 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001496 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001497 _LIBCPP_INLINE_VISIBILITY
1498 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1499
1500 _LIBCPP_INLINE_VISIBILITY
1501 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001502 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001504 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001505 _LIBCPP_INLINE_VISIBILITY
1506 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1507
1508 _LIBCPP_INLINE_VISIBILITY
1509 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001511 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
1512 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001513 int compare(const value_type* __s) const _NOEXCEPT;
1514 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1515 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001516
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001517 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001518
1519 _LIBCPP_INLINE_VISIBILITY
1520 bool __is_long() const _NOEXCEPT
1521 {return bool(__r_.first().__s.__size_ & __short_mask);}
1522
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001523private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001524 _LIBCPP_INLINE_VISIBILITY
1525 allocator_type& __alloc() _NOEXCEPT
1526 {return __r_.second();}
1527 _LIBCPP_INLINE_VISIBILITY
1528 const allocator_type& __alloc() const _NOEXCEPT
1529 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001530
Howard Hinnant15467182013-04-30 21:44:48 +00001531#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1532
Howard Hinnanta6119a82011-05-29 19:57:12 +00001533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001534 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001535# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001536 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001537# else
1538 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1539# endif
1540
Howard Hinnanta6119a82011-05-29 19:57:12 +00001541 _LIBCPP_INLINE_VISIBILITY
1542 size_type __get_short_size() const _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001543# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001544 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001545# else
1546 {return __r_.first().__s.__size_;}
1547# endif
1548
1549#else // _LIBCPP_ALTERNATE_STRING_LAYOUT
1550
1551 _LIBCPP_INLINE_VISIBILITY
1552 void __set_short_size(size_type __s) _NOEXCEPT
1553# if _LIBCPP_BIG_ENDIAN
1554 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1555# else
1556 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1557# endif
1558
1559 _LIBCPP_INLINE_VISIBILITY
1560 size_type __get_short_size() const _NOEXCEPT
1561# if _LIBCPP_BIG_ENDIAN
1562 {return __r_.first().__s.__size_;}
1563# else
1564 {return __r_.first().__s.__size_ >> 1;}
1565# endif
1566
1567#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1568
Howard Hinnanta6119a82011-05-29 19:57:12 +00001569 _LIBCPP_INLINE_VISIBILITY
1570 void __set_long_size(size_type __s) _NOEXCEPT
1571 {__r_.first().__l.__size_ = __s;}
1572 _LIBCPP_INLINE_VISIBILITY
1573 size_type __get_long_size() const _NOEXCEPT
1574 {return __r_.first().__l.__size_;}
1575 _LIBCPP_INLINE_VISIBILITY
1576 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001577 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1578
Howard Hinnanta6119a82011-05-29 19:57:12 +00001579 _LIBCPP_INLINE_VISIBILITY
1580 void __set_long_cap(size_type __s) _NOEXCEPT
1581 {__r_.first().__l.__cap_ = __long_mask | __s;}
1582 _LIBCPP_INLINE_VISIBILITY
1583 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001584 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001585
Howard Hinnanta6119a82011-05-29 19:57:12 +00001586 _LIBCPP_INLINE_VISIBILITY
1587 void __set_long_pointer(pointer __p) _NOEXCEPT
1588 {__r_.first().__l.__data_ = __p;}
1589 _LIBCPP_INLINE_VISIBILITY
1590 pointer __get_long_pointer() _NOEXCEPT
1591 {return __r_.first().__l.__data_;}
1592 _LIBCPP_INLINE_VISIBILITY
1593 const_pointer __get_long_pointer() const _NOEXCEPT
1594 {return __r_.first().__l.__data_;}
1595 _LIBCPP_INLINE_VISIBILITY
1596 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001597 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001598 _LIBCPP_INLINE_VISIBILITY
1599 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001600 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001601 _LIBCPP_INLINE_VISIBILITY
1602 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001603 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001604 _LIBCPP_INLINE_VISIBILITY
1605 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001606 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1607
Howard Hinnanta6119a82011-05-29 19:57:12 +00001608 _LIBCPP_INLINE_VISIBILITY
1609 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001610 {
1611 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1612 for (unsigned __i = 0; __i < __n_words; ++__i)
1613 __a[__i] = 0;
1614 }
1615
1616 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001617 _LIBCPP_INLINE_VISIBILITY
1618 size_type __align(size_type __s) _NOEXCEPT
1619 {return __s + (__a-1) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001620 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001621 static _LIBCPP_INLINE_VISIBILITY
1622 size_type __recommend(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001623 {return (__s < __min_cap ? __min_cap :
Howard Hinnanta6119a82011-05-29 19:57:12 +00001624 __align<sizeof(value_type) < __alignment ?
1625 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001626
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001627 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1628 void __init(const value_type* __s, size_type __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001629 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001630
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001631 template <class _InputIterator>
1632 typename enable_if
1633 <
1634 __is_input_iterator <_InputIterator>::value &&
1635 !__is_forward_iterator<_InputIterator>::value,
1636 void
1637 >::type
1638 __init(_InputIterator __first, _InputIterator __last);
1639
1640 template <class _ForwardIterator>
1641 typename enable_if
1642 <
1643 __is_forward_iterator<_ForwardIterator>::value,
1644 void
1645 >::type
1646 __init(_ForwardIterator __first, _ForwardIterator __last);
1647
1648 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001649 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001650 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1651 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001652 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001653
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001655 void __erase_to_end(size_type __pos);
1656
Howard Hinnante32b5e22010-11-17 17:55:08 +00001657 _LIBCPP_INLINE_VISIBILITY
1658 void __copy_assign_alloc(const basic_string& __str)
1659 {__copy_assign_alloc(__str, integral_constant<bool,
1660 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1661
1662 _LIBCPP_INLINE_VISIBILITY
1663 void __copy_assign_alloc(const basic_string& __str, true_type)
1664 {
1665 if (__alloc() != __str.__alloc())
1666 {
1667 clear();
1668 shrink_to_fit();
1669 }
1670 __alloc() = __str.__alloc();
1671 }
1672
1673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001674 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001675 {}
1676
1677#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00001679 void __move_assign(basic_string& __str, false_type);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001681 void __move_assign(basic_string& __str, true_type)
1682 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001683#endif
1684
1685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001686 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001687 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001688 _NOEXCEPT_(
1689 !__alloc_traits::propagate_on_container_move_assignment::value ||
1690 is_nothrow_move_assignable<allocator_type>::value)
1691 {__move_assign_alloc(__str, integral_constant<bool,
1692 __alloc_traits::propagate_on_container_move_assignment::value>());}
1693
1694 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001695 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001696 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1697 {
1698 __alloc() = _VSTD::move(__c.__alloc());
1699 }
1700
1701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001702 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001703 _NOEXCEPT
1704 {}
1705
1706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001707 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
1708 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1709 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001710 {__swap_alloc(__x, __y, integral_constant<bool,
1711 __alloc_traits::propagate_on_container_swap::value>());}
1712
1713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001714 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
1715 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001716 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001717 using _VSTD::swap;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001718 swap(__x, __y);
1719 }
1720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001721 static void __swap_alloc(allocator_type&, allocator_type&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001722 {}
1723
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001724 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1725 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001726
1727 friend basic_string operator+<>(const basic_string&, const basic_string&);
1728 friend basic_string operator+<>(const value_type*, const basic_string&);
1729 friend basic_string operator+<>(value_type, const basic_string&);
1730 friend basic_string operator+<>(const basic_string&, const value_type*);
1731 friend basic_string operator+<>(const basic_string&, value_type);
1732};
1733
1734template <class _CharT, class _Traits, class _Allocator>
1735#ifndef _LIBCPP_DEBUG
1736_LIBCPP_INLINE_VISIBILITY inline
1737#endif
1738void
1739basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1740{
1741#ifdef _LIBCPP_DEBUG
1742 iterator::__remove_all(this);
1743 const_iterator::__remove_all(this);
Howard Hinnant324bb032010-08-22 00:02:43 +00001744#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001745}
1746
1747template <class _CharT, class _Traits, class _Allocator>
1748#ifndef _LIBCPP_DEBUG
1749_LIBCPP_INLINE_VISIBILITY inline
1750#endif
1751void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001752basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
1753#ifdef _LIBCPP_DEBUG
1754 __pos
1755#endif
1756 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001757{
1758#ifdef _LIBCPP_DEBUG
1759 const_iterator __beg = begin();
1760 if (__iterator_list_.first)
1761 {
1762 for (iterator* __p = __iterator_list_.first; __p;)
1763 {
1764 if (*__p - __beg > static_cast<difference_type>(__pos))
1765 {
1766 iterator* __n = __p;
1767 __p = __p->__next;
1768 __n->__remove_owner();
1769 }
1770 else
1771 __p = __p->__next;
1772 }
1773 }
1774 if (__iterator_list_.second)
1775 {
1776 for (const_iterator* __p = __iterator_list_.second; __p;)
1777 {
1778 if (*__p - __beg > static_cast<difference_type>(__pos))
1779 {
1780 const_iterator* __n = __p;
1781 __p = __p->__next;
1782 __n->__remove_owner();
1783 }
1784 else
1785 __p = __p->__next;
1786 }
1787 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001788#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001789}
1790
1791template <class _CharT, class _Traits, class _Allocator>
1792_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001793basic_string<_CharT, _Traits, _Allocator>::basic_string()
1794 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001795{
1796 __zero();
1797}
1798
1799template <class _CharT, class _Traits, class _Allocator>
1800_LIBCPP_INLINE_VISIBILITY inline
1801basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
1802 : __r_(__a)
1803{
1804 __zero();
1805}
1806
1807template <class _CharT, class _Traits, class _Allocator>
1808void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001809basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001810{
1811 if (__reserve > max_size())
1812 this->__throw_length_error();
1813 pointer __p;
1814 if (__reserve < __min_cap)
1815 {
1816 __set_short_size(__sz);
1817 __p = __get_short_pointer();
1818 }
1819 else
1820 {
1821 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001822 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001823 __set_long_pointer(__p);
1824 __set_long_cap(__cap+1);
1825 __set_long_size(__sz);
1826 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001827 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001828 traits_type::assign(__p[__sz], value_type());
1829}
1830
1831template <class _CharT, class _Traits, class _Allocator>
1832void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001833basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001834{
1835 if (__sz > max_size())
1836 this->__throw_length_error();
1837 pointer __p;
1838 if (__sz < __min_cap)
1839 {
1840 __set_short_size(__sz);
1841 __p = __get_short_pointer();
1842 }
1843 else
1844 {
1845 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001846 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001847 __set_long_pointer(__p);
1848 __set_long_cap(__cap+1);
1849 __set_long_size(__sz);
1850 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001851 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001852 traits_type::assign(__p[__sz], value_type());
1853}
1854
1855template <class _CharT, class _Traits, class _Allocator>
1856_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001857basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001858{
1859#ifdef _LIBCPP_DEBUG
1860 assert(__s != 0);
1861#endif
1862 __init(__s, traits_type::length(__s));
1863}
1864
1865template <class _CharT, class _Traits, class _Allocator>
1866_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001867basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001868 : __r_(__a)
1869{
1870#ifdef _LIBCPP_DEBUG
1871 assert(__s != 0);
1872#endif
1873 __init(__s, traits_type::length(__s));
1874}
1875
1876template <class _CharT, class _Traits, class _Allocator>
1877_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001878basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001879{
1880#ifdef _LIBCPP_DEBUG
1881 assert(__s != 0);
1882#endif
1883 __init(__s, __n);
1884}
1885
1886template <class _CharT, class _Traits, class _Allocator>
1887_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001888basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001889 : __r_(__a)
1890{
1891#ifdef _LIBCPP_DEBUG
1892 assert(__s != 0);
1893#endif
1894 __init(__s, __n);
1895}
1896
1897template <class _CharT, class _Traits, class _Allocator>
1898basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001899 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001900{
1901 if (!__str.__is_long())
1902 __r_.first().__r = __str.__r_.first().__r;
1903 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001904 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001905}
1906
1907template <class _CharT, class _Traits, class _Allocator>
1908basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
1909 : __r_(__a)
1910{
1911 if (!__str.__is_long())
1912 __r_.first().__r = __str.__r_.first().__r;
1913 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001914 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001915}
1916
Howard Hinnant73d21a42010-09-04 23:28:19 +00001917#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001918
1919template <class _CharT, class _Traits, class _Allocator>
1920_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001921basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
1922 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001923 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001924{
1925 __str.__zero();
1926#ifdef _LIBCPP_DEBUG
1927 __str.__invalidate_all_iterators();
1928#endif
1929}
1930
1931template <class _CharT, class _Traits, class _Allocator>
1932_LIBCPP_INLINE_VISIBILITY inline
1933basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001934 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935{
Howard Hinnante32b5e22010-11-17 17:55:08 +00001936 if (__a == __str.__alloc() || !__str.__is_long())
1937 __r_.first().__r = __str.__r_.first().__r;
1938 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001939 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001940 __str.__zero();
1941#ifdef _LIBCPP_DEBUG
1942 __str.__invalidate_all_iterators();
1943#endif
1944}
1945
Howard Hinnant73d21a42010-09-04 23:28:19 +00001946#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001947
1948template <class _CharT, class _Traits, class _Allocator>
1949void
1950basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1951{
1952 if (__n > max_size())
1953 this->__throw_length_error();
1954 pointer __p;
1955 if (__n < __min_cap)
1956 {
1957 __set_short_size(__n);
1958 __p = __get_short_pointer();
1959 }
1960 else
1961 {
1962 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001963 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001964 __set_long_pointer(__p);
1965 __set_long_cap(__cap+1);
1966 __set_long_size(__n);
1967 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001968 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001969 traits_type::assign(__p[__n], value_type());
1970}
1971
1972template <class _CharT, class _Traits, class _Allocator>
1973_LIBCPP_INLINE_VISIBILITY inline
1974basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
1975{
1976 __init(__n, __c);
1977}
1978
1979template <class _CharT, class _Traits, class _Allocator>
1980_LIBCPP_INLINE_VISIBILITY inline
1981basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
1982 : __r_(__a)
1983{
1984 __init(__n, __c);
1985}
1986
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001987template <class _CharT, class _Traits, class _Allocator>
1988basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
1989 const allocator_type& __a)
1990 : __r_(__a)
1991{
1992 size_type __str_sz = __str.size();
1993 if (__pos > __str_sz)
1994 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001995 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001996}
1997
1998template <class _CharT, class _Traits, class _Allocator>
1999template <class _InputIterator>
2000typename enable_if
2001<
2002 __is_input_iterator <_InputIterator>::value &&
2003 !__is_forward_iterator<_InputIterator>::value,
2004 void
2005>::type
2006basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2007{
2008 __zero();
2009#ifndef _LIBCPP_NO_EXCEPTIONS
2010 try
2011 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002012#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002013 for (; __first != __last; ++__first)
2014 push_back(*__first);
2015#ifndef _LIBCPP_NO_EXCEPTIONS
2016 }
2017 catch (...)
2018 {
2019 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002020 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002021 throw;
2022 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002023#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002024}
2025
2026template <class _CharT, class _Traits, class _Allocator>
2027template <class _ForwardIterator>
2028typename enable_if
2029<
2030 __is_forward_iterator<_ForwardIterator>::value,
2031 void
2032>::type
2033basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2034{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002035 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002036 if (__sz > max_size())
2037 this->__throw_length_error();
2038 pointer __p;
2039 if (__sz < __min_cap)
2040 {
2041 __set_short_size(__sz);
2042 __p = __get_short_pointer();
2043 }
2044 else
2045 {
2046 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002047 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002048 __set_long_pointer(__p);
2049 __set_long_cap(__cap+1);
2050 __set_long_size(__sz);
2051 }
2052 for (; __first != __last; ++__first, ++__p)
2053 traits_type::assign(*__p, *__first);
2054 traits_type::assign(*__p, value_type());
2055}
2056
2057template <class _CharT, class _Traits, class _Allocator>
2058template<class _InputIterator>
2059_LIBCPP_INLINE_VISIBILITY inline
2060basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2061{
2062 __init(__first, __last);
2063}
2064
2065template <class _CharT, class _Traits, class _Allocator>
2066template<class _InputIterator>
2067_LIBCPP_INLINE_VISIBILITY inline
2068basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2069 const allocator_type& __a)
2070 : __r_(__a)
2071{
2072 __init(__first, __last);
2073}
2074
Howard Hinnante3e32912011-08-12 21:56:02 +00002075#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2076
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002077template <class _CharT, class _Traits, class _Allocator>
2078_LIBCPP_INLINE_VISIBILITY inline
2079basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
2080{
2081 __init(__il.begin(), __il.end());
2082}
2083
2084template <class _CharT, class _Traits, class _Allocator>
2085_LIBCPP_INLINE_VISIBILITY inline
2086basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
2087 : __r_(__a)
2088{
2089 __init(__il.begin(), __il.end());
2090}
2091
Howard Hinnante3e32912011-08-12 21:56:02 +00002092#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2093
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002094template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2096{
2097 __invalidate_all_iterators();
2098 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002099 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002100}
2101
2102template <class _CharT, class _Traits, class _Allocator>
2103void
2104basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2105 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002106 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002107{
2108 size_type __ms = max_size();
2109 if (__delta_cap > __ms - __old_cap - 1)
2110 this->__throw_length_error();
2111 pointer __old_p = __get_pointer();
2112 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002113 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002114 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002115 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002116 __invalidate_all_iterators();
2117 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002118 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2119 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002120 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002121 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002122 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2123 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002124 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2125 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002126 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002127 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002128 __set_long_pointer(__p);
2129 __set_long_cap(__cap+1);
2130 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2131 __set_long_size(__old_sz);
2132 traits_type::assign(__p[__old_sz], value_type());
2133}
2134
2135template <class _CharT, class _Traits, class _Allocator>
2136void
2137basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2138 size_type __n_copy, size_type __n_del, size_type __n_add)
2139{
2140 size_type __ms = max_size();
2141 if (__delta_cap > __ms - __old_cap - 1)
2142 this->__throw_length_error();
2143 pointer __old_p = __get_pointer();
2144 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002145 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002146 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002147 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002148 __invalidate_all_iterators();
2149 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002150 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2151 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002152 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2153 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002154 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2155 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2156 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002157 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002158 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002159 __set_long_pointer(__p);
2160 __set_long_cap(__cap+1);
2161}
2162
2163// assign
2164
2165template <class _CharT, class _Traits, class _Allocator>
2166basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002167basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002168{
2169#ifdef _LIBCPP_DEBUG
2170 assert(__s != 0);
2171#endif
2172 size_type __cap = capacity();
2173 if (__cap >= __n)
2174 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002175 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002176 traits_type::move(__p, __s, __n);
2177 traits_type::assign(__p[__n], value_type());
2178 __set_size(__n);
2179 __invalidate_iterators_past(__n);
2180 }
2181 else
2182 {
2183 size_type __sz = size();
2184 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2185 }
2186 return *this;
2187}
2188
2189template <class _CharT, class _Traits, class _Allocator>
2190basic_string<_CharT, _Traits, _Allocator>&
2191basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2192{
2193 size_type __cap = capacity();
2194 if (__cap < __n)
2195 {
2196 size_type __sz = size();
2197 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2198 }
2199 else
2200 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002201 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002202 traits_type::assign(__p, __n, __c);
2203 traits_type::assign(__p[__n], value_type());
2204 __set_size(__n);
2205 return *this;
2206}
2207
2208template <class _CharT, class _Traits, class _Allocator>
2209basic_string<_CharT, _Traits, _Allocator>&
2210basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2211{
2212 pointer __p;
2213 if (__is_long())
2214 {
2215 __p = __get_long_pointer();
2216 __set_long_size(1);
2217 }
2218 else
2219 {
2220 __p = __get_short_pointer();
2221 __set_short_size(1);
2222 }
2223 traits_type::assign(*__p, __c);
2224 traits_type::assign(*++__p, value_type());
2225 __invalidate_iterators_past(1);
2226 return *this;
2227}
2228
2229template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002230basic_string<_CharT, _Traits, _Allocator>&
2231basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2232{
2233 if (this != &__str)
2234 {
2235 __copy_assign_alloc(__str);
2236 assign(__str);
2237 }
2238 return *this;
2239}
2240
2241#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2242
2243template <class _CharT, class _Traits, class _Allocator>
2244_LIBCPP_INLINE_VISIBILITY inline
2245void
2246basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2247{
2248 if (__alloc() != __str.__alloc())
2249 assign(__str);
2250 else
2251 __move_assign(__str, true_type());
2252}
2253
2254template <class _CharT, class _Traits, class _Allocator>
2255_LIBCPP_INLINE_VISIBILITY inline
2256void
2257basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002258 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002259{
2260 clear();
2261 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002262 __r_.first() = __str.__r_.first();
2263 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002264 __str.__zero();
2265}
2266
2267template <class _CharT, class _Traits, class _Allocator>
2268_LIBCPP_INLINE_VISIBILITY inline
2269basic_string<_CharT, _Traits, _Allocator>&
2270basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002271 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
2272 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002273{
2274 __move_assign(__str, integral_constant<bool,
2275 __alloc_traits::propagate_on_container_move_assignment::value>());
2276 return *this;
2277}
2278
2279#endif
2280
2281template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002282template<class _InputIterator>
2283typename enable_if
2284<
2285 __is_input_iterator <_InputIterator>::value &&
2286 !__is_forward_iterator<_InputIterator>::value,
2287 basic_string<_CharT, _Traits, _Allocator>&
2288>::type
2289basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2290{
2291 clear();
2292 for (; __first != __last; ++__first)
2293 push_back(*__first);
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002294 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002295}
2296
2297template <class _CharT, class _Traits, class _Allocator>
2298template<class _ForwardIterator>
2299typename enable_if
2300<
2301 __is_forward_iterator<_ForwardIterator>::value,
2302 basic_string<_CharT, _Traits, _Allocator>&
2303>::type
2304basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2305{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002306 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002307 size_type __cap = capacity();
2308 if (__cap < __n)
2309 {
2310 size_type __sz = size();
2311 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2312 }
2313 else
2314 __invalidate_iterators_past(__n);
2315 pointer __p = __get_pointer();
2316 for (; __first != __last; ++__first, ++__p)
2317 traits_type::assign(*__p, *__first);
2318 traits_type::assign(*__p, value_type());
2319 __set_size(__n);
2320 return *this;
2321}
2322
2323template <class _CharT, class _Traits, class _Allocator>
2324_LIBCPP_INLINE_VISIBILITY inline
2325basic_string<_CharT, _Traits, _Allocator>&
2326basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
2327{
2328 return assign(__str.data(), __str.size());
2329}
2330
2331template <class _CharT, class _Traits, class _Allocator>
2332basic_string<_CharT, _Traits, _Allocator>&
2333basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2334{
2335 size_type __sz = __str.size();
2336 if (__pos > __sz)
2337 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002338 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002339}
2340
2341template <class _CharT, class _Traits, class _Allocator>
2342basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002343basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002344{
2345#ifdef _LIBCPP_DEBUG
2346 assert(__s != 0);
2347#endif
2348 return assign(__s, traits_type::length(__s));
2349}
2350
2351// append
2352
2353template <class _CharT, class _Traits, class _Allocator>
2354basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002355basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002356{
2357#ifdef _LIBCPP_DEBUG
2358 assert(__s != 0);
2359#endif
2360 size_type __cap = capacity();
2361 size_type __sz = size();
2362 if (__cap - __sz >= __n)
2363 {
2364 if (__n)
2365 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002366 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002367 traits_type::copy(__p + __sz, __s, __n);
2368 __sz += __n;
2369 __set_size(__sz);
2370 traits_type::assign(__p[__sz], value_type());
2371 }
2372 }
2373 else
2374 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2375 return *this;
2376}
2377
2378template <class _CharT, class _Traits, class _Allocator>
2379basic_string<_CharT, _Traits, _Allocator>&
2380basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2381{
2382 if (__n)
2383 {
2384 size_type __cap = capacity();
2385 size_type __sz = size();
2386 if (__cap - __sz < __n)
2387 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2388 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002389 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002390 __sz += __n;
2391 __set_size(__sz);
2392 traits_type::assign(__p[__sz], value_type());
2393 }
2394 return *this;
2395}
2396
2397template <class _CharT, class _Traits, class _Allocator>
2398void
2399basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2400{
Howard Hinnant15467182013-04-30 21:44:48 +00002401 bool __is_short = !__is_long();
2402 size_type __cap;
2403 size_type __sz;
2404 if (__is_short)
2405 {
2406 __cap = __min_cap - 1;
2407 __sz = __get_short_size();
2408 }
2409 else
2410 {
2411 __cap = __get_long_cap() - 1;
2412 __sz = __get_long_size();
2413 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002414 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002415 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002416 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002417 __is_short = !__is_long();
2418 }
2419 pointer __p;
2420 if (__is_short)
2421 {
2422 __p = __get_short_pointer() + __sz;
2423 __set_short_size(__sz+1);
2424 }
2425 else
2426 {
2427 __p = __get_long_pointer() + __sz;
2428 __set_long_size(__sz+1);
2429 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002430 traits_type::assign(*__p, __c);
2431 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002432}
2433
2434template <class _CharT, class _Traits, class _Allocator>
2435template<class _InputIterator>
2436typename enable_if
2437<
2438 __is_input_iterator <_InputIterator>::value &&
2439 !__is_forward_iterator<_InputIterator>::value,
2440 basic_string<_CharT, _Traits, _Allocator>&
2441>::type
2442basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2443{
2444 for (; __first != __last; ++__first)
2445 push_back(*__first);
2446 return *this;
2447}
2448
2449template <class _CharT, class _Traits, class _Allocator>
2450template<class _ForwardIterator>
2451typename enable_if
2452<
2453 __is_forward_iterator<_ForwardIterator>::value,
2454 basic_string<_CharT, _Traits, _Allocator>&
2455>::type
2456basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2457{
2458 size_type __sz = size();
2459 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002460 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002461 if (__n)
2462 {
2463 if (__cap - __sz < __n)
2464 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2465 pointer __p = __get_pointer() + __sz;
2466 for (; __first != __last; ++__p, ++__first)
2467 traits_type::assign(*__p, *__first);
2468 traits_type::assign(*__p, value_type());
2469 __set_size(__sz + __n);
2470 }
2471 return *this;
2472}
2473
2474template <class _CharT, class _Traits, class _Allocator>
2475_LIBCPP_INLINE_VISIBILITY inline
2476basic_string<_CharT, _Traits, _Allocator>&
2477basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2478{
2479 return append(__str.data(), __str.size());
2480}
2481
2482template <class _CharT, class _Traits, class _Allocator>
2483basic_string<_CharT, _Traits, _Allocator>&
2484basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2485{
2486 size_type __sz = __str.size();
2487 if (__pos > __sz)
2488 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002489 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002490}
2491
2492template <class _CharT, class _Traits, class _Allocator>
2493basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002494basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002495{
2496#ifdef _LIBCPP_DEBUG
2497 assert(__s != 0);
2498#endif
2499 return append(__s, traits_type::length(__s));
2500}
2501
2502// insert
2503
2504template <class _CharT, class _Traits, class _Allocator>
2505basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002506basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002507{
2508#ifdef _LIBCPP_DEBUG
2509 assert(__s != 0);
2510#endif
2511 size_type __sz = size();
2512 if (__pos > __sz)
2513 this->__throw_out_of_range();
2514 size_type __cap = capacity();
2515 if (__cap - __sz >= __n)
2516 {
2517 if (__n)
2518 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002519 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002520 size_type __n_move = __sz - __pos;
2521 if (__n_move != 0)
2522 {
2523 if (__p + __pos <= __s && __s < __p + __sz)
2524 __s += __n;
2525 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2526 }
2527 traits_type::move(__p + __pos, __s, __n);
2528 __sz += __n;
2529 __set_size(__sz);
2530 traits_type::assign(__p[__sz], value_type());
2531 }
2532 }
2533 else
2534 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2535 return *this;
2536}
2537
2538template <class _CharT, class _Traits, class _Allocator>
2539basic_string<_CharT, _Traits, _Allocator>&
2540basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2541{
2542 size_type __sz = size();
2543 if (__pos > __sz)
2544 this->__throw_out_of_range();
2545 if (__n)
2546 {
2547 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002548 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002549 if (__cap - __sz >= __n)
2550 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002551 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002552 size_type __n_move = __sz - __pos;
2553 if (__n_move != 0)
2554 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2555 }
2556 else
2557 {
2558 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002559 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002560 }
2561 traits_type::assign(__p + __pos, __n, __c);
2562 __sz += __n;
2563 __set_size(__sz);
2564 traits_type::assign(__p[__sz], value_type());
2565 }
2566 return *this;
2567}
2568
2569template <class _CharT, class _Traits, class _Allocator>
2570template<class _InputIterator>
2571typename enable_if
2572<
2573 __is_input_iterator <_InputIterator>::value &&
2574 !__is_forward_iterator<_InputIterator>::value,
2575 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2576>::type
2577basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2578{
2579 size_type __old_sz = size();
2580 difference_type __ip = __pos - begin();
2581 for (; __first != __last; ++__first)
2582 push_back(*__first);
2583 pointer __p = __get_pointer();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002584 _VSTD::rotate(__p + __ip, __p + __old_sz, __p + size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002585 return iterator(__p + __ip);
2586}
2587
2588template <class _CharT, class _Traits, class _Allocator>
2589template<class _ForwardIterator>
2590typename enable_if
2591<
2592 __is_forward_iterator<_ForwardIterator>::value,
2593 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2594>::type
2595basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2596{
2597 size_type __ip = static_cast<size_type>(__pos - begin());
2598 size_type __sz = size();
2599 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002600 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002601 if (__n)
2602 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002603 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002604 if (__cap - __sz >= __n)
2605 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002606 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002607 size_type __n_move = __sz - __ip;
2608 if (__n_move != 0)
2609 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2610 }
2611 else
2612 {
2613 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002614 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002615 }
2616 __sz += __n;
2617 __set_size(__sz);
2618 traits_type::assign(__p[__sz], value_type());
2619 for (__p += __ip; __first != __last; ++__p, ++__first)
2620 traits_type::assign(*__p, *__first);
2621 }
2622 return begin() + __ip;
2623}
2624
2625template <class _CharT, class _Traits, class _Allocator>
2626_LIBCPP_INLINE_VISIBILITY inline
2627basic_string<_CharT, _Traits, _Allocator>&
2628basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2629{
2630 return insert(__pos1, __str.data(), __str.size());
2631}
2632
2633template <class _CharT, class _Traits, class _Allocator>
2634basic_string<_CharT, _Traits, _Allocator>&
2635basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2636 size_type __pos2, size_type __n)
2637{
2638 size_type __str_sz = __str.size();
2639 if (__pos2 > __str_sz)
2640 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002641 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002642}
2643
2644template <class _CharT, class _Traits, class _Allocator>
2645basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002646basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002647{
2648#ifdef _LIBCPP_DEBUG
2649 assert(__s != 0);
2650#endif
2651 return insert(__pos, __s, traits_type::length(__s));
2652}
2653
2654template <class _CharT, class _Traits, class _Allocator>
2655typename basic_string<_CharT, _Traits, _Allocator>::iterator
2656basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2657{
2658 size_type __ip = static_cast<size_type>(__pos - begin());
2659 size_type __sz = size();
2660 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002661 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002662 if (__cap == __sz)
2663 {
2664 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002665 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002666 }
2667 else
2668 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002669 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002670 size_type __n_move = __sz - __ip;
2671 if (__n_move != 0)
2672 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2673 }
2674 traits_type::assign(__p[__ip], __c);
2675 traits_type::assign(__p[++__sz], value_type());
2676 __set_size(__sz);
2677 return begin() + static_cast<difference_type>(__ip);
2678}
2679
2680template <class _CharT, class _Traits, class _Allocator>
2681_LIBCPP_INLINE_VISIBILITY inline
2682typename basic_string<_CharT, _Traits, _Allocator>::iterator
2683basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2684{
2685 difference_type __p = __pos - begin();
2686 insert(static_cast<size_type>(__p), __n, __c);
2687 return begin() + __p;
2688}
2689
2690// replace
2691
2692template <class _CharT, class _Traits, class _Allocator>
2693basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002694basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002695{
2696#ifdef _LIBCPP_DEBUG
2697 assert(__s != 0);
2698#endif
2699 size_type __sz = size();
2700 if (__pos > __sz)
2701 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002702 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002703 size_type __cap = capacity();
2704 if (__cap - __sz + __n1 >= __n2)
2705 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002706 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002707 if (__n1 != __n2)
2708 {
2709 size_type __n_move = __sz - __pos - __n1;
2710 if (__n_move != 0)
2711 {
2712 if (__n1 > __n2)
2713 {
2714 traits_type::move(__p + __pos, __s, __n2);
2715 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2716 goto __finish;
2717 }
2718 if (__p + __pos < __s && __s < __p + __sz)
2719 {
2720 if (__p + __pos + __n1 <= __s)
2721 __s += __n2 - __n1;
2722 else // __p + __pos < __s < __p + __pos + __n1
2723 {
2724 traits_type::move(__p + __pos, __s, __n1);
2725 __pos += __n1;
2726 __s += __n2;
2727 __n2 -= __n1;
2728 __n1 = 0;
2729 }
2730 }
2731 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2732 }
2733 }
2734 traits_type::move(__p + __pos, __s, __n2);
2735__finish:
2736 __sz += __n2 - __n1;
2737 __set_size(__sz);
2738 __invalidate_iterators_past(__sz);
2739 traits_type::assign(__p[__sz], value_type());
2740 }
2741 else
2742 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2743 return *this;
2744}
2745
2746template <class _CharT, class _Traits, class _Allocator>
2747basic_string<_CharT, _Traits, _Allocator>&
2748basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2749{
2750 size_type __sz = size();
2751 if (__pos > __sz)
2752 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002753 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002754 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002755 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002756 if (__cap - __sz + __n1 >= __n2)
2757 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002758 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002759 if (__n1 != __n2)
2760 {
2761 size_type __n_move = __sz - __pos - __n1;
2762 if (__n_move != 0)
2763 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2764 }
2765 }
2766 else
2767 {
2768 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002769 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002770 }
2771 traits_type::assign(__p + __pos, __n2, __c);
2772 __sz += __n2 - __n1;
2773 __set_size(__sz);
2774 __invalidate_iterators_past(__sz);
2775 traits_type::assign(__p[__sz], value_type());
2776 return *this;
2777}
2778
2779template <class _CharT, class _Traits, class _Allocator>
2780template<class _InputIterator>
2781typename enable_if
2782<
2783 __is_input_iterator<_InputIterator>::value,
2784 basic_string<_CharT, _Traits, _Allocator>&
2785>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002786basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002787 _InputIterator __j1, _InputIterator __j2)
2788{
2789 for (; true; ++__i1, ++__j1)
2790 {
2791 if (__i1 == __i2)
2792 {
2793 if (__j1 != __j2)
2794 insert(__i1, __j1, __j2);
2795 break;
2796 }
2797 if (__j1 == __j2)
2798 {
2799 erase(__i1, __i2);
2800 break;
2801 }
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002802 traits_type::assign(const_cast<value_type&>(*__i1), *__j1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002803 }
2804 return *this;
2805}
2806
2807template <class _CharT, class _Traits, class _Allocator>
2808_LIBCPP_INLINE_VISIBILITY inline
2809basic_string<_CharT, _Traits, _Allocator>&
2810basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2811{
2812 return replace(__pos1, __n1, __str.data(), __str.size());
2813}
2814
2815template <class _CharT, class _Traits, class _Allocator>
2816basic_string<_CharT, _Traits, _Allocator>&
2817basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2818 size_type __pos2, size_type __n2)
2819{
2820 size_type __str_sz = __str.size();
2821 if (__pos2 > __str_sz)
2822 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002823 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002824}
2825
2826template <class _CharT, class _Traits, class _Allocator>
2827basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002828basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002829{
2830#ifdef _LIBCPP_DEBUG
2831 assert(__s != 0);
2832#endif
2833 return replace(__pos, __n1, __s, traits_type::length(__s));
2834}
2835
2836template <class _CharT, class _Traits, class _Allocator>
2837_LIBCPP_INLINE_VISIBILITY inline
2838basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002839basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002840{
2841 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2842 __str.data(), __str.size());
2843}
2844
2845template <class _CharT, class _Traits, class _Allocator>
2846_LIBCPP_INLINE_VISIBILITY inline
2847basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002848basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002849{
2850 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2851}
2852
2853template <class _CharT, class _Traits, class _Allocator>
2854_LIBCPP_INLINE_VISIBILITY inline
2855basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002856basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002857{
2858 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2859}
2860
2861template <class _CharT, class _Traits, class _Allocator>
2862_LIBCPP_INLINE_VISIBILITY inline
2863basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002864basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002865{
2866 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2867}
2868
2869// erase
2870
2871template <class _CharT, class _Traits, class _Allocator>
2872basic_string<_CharT, _Traits, _Allocator>&
2873basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2874{
2875 size_type __sz = size();
2876 if (__pos > __sz)
2877 this->__throw_out_of_range();
2878 if (__n)
2879 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002880 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002881 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002882 size_type __n_move = __sz - __pos - __n;
2883 if (__n_move != 0)
2884 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2885 __sz -= __n;
2886 __set_size(__sz);
2887 __invalidate_iterators_past(__sz);
2888 traits_type::assign(__p[__sz], value_type());
2889 }
2890 return *this;
2891}
2892
2893template <class _CharT, class _Traits, class _Allocator>
2894_LIBCPP_INLINE_VISIBILITY inline
2895typename basic_string<_CharT, _Traits, _Allocator>::iterator
2896basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2897{
2898 iterator __b = begin();
2899 size_type __r = static_cast<size_type>(__pos - __b);
2900 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002901 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002902}
2903
2904template <class _CharT, class _Traits, class _Allocator>
2905_LIBCPP_INLINE_VISIBILITY inline
2906typename basic_string<_CharT, _Traits, _Allocator>::iterator
2907basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2908{
2909 iterator __b = begin();
2910 size_type __r = static_cast<size_type>(__first - __b);
2911 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00002912 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002913}
2914
2915template <class _CharT, class _Traits, class _Allocator>
2916_LIBCPP_INLINE_VISIBILITY inline
2917void
2918basic_string<_CharT, _Traits, _Allocator>::pop_back()
2919{
2920#ifdef _LIBCPP_DEBUG
2921 assert(!empty());
2922#endif
2923 size_type __sz;
2924 if (__is_long())
2925 {
2926 __sz = __get_long_size() - 1;
2927 __set_long_size(__sz);
2928 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2929 }
2930 else
2931 {
2932 __sz = __get_short_size() - 1;
2933 __set_short_size(__sz);
2934 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2935 }
2936 __invalidate_iterators_past(__sz);
2937}
2938
2939template <class _CharT, class _Traits, class _Allocator>
2940_LIBCPP_INLINE_VISIBILITY inline
2941void
Howard Hinnanta6119a82011-05-29 19:57:12 +00002942basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002943{
2944 __invalidate_all_iterators();
2945 if (__is_long())
2946 {
2947 traits_type::assign(*__get_long_pointer(), value_type());
2948 __set_long_size(0);
2949 }
2950 else
2951 {
2952 traits_type::assign(*__get_short_pointer(), value_type());
2953 __set_short_size(0);
2954 }
2955}
2956
2957template <class _CharT, class _Traits, class _Allocator>
2958_LIBCPP_INLINE_VISIBILITY inline
2959void
2960basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2961{
2962 if (__is_long())
2963 {
2964 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2965 __set_long_size(__pos);
2966 }
2967 else
2968 {
2969 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2970 __set_short_size(__pos);
2971 }
2972 __invalidate_iterators_past(__pos);
2973}
2974
2975template <class _CharT, class _Traits, class _Allocator>
2976void
2977basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2978{
2979 size_type __sz = size();
2980 if (__n > __sz)
2981 append(__n - __sz, __c);
2982 else
2983 __erase_to_end(__n);
2984}
2985
2986template <class _CharT, class _Traits, class _Allocator>
2987_LIBCPP_INLINE_VISIBILITY inline
2988typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002989basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002990{
Howard Hinnante32b5e22010-11-17 17:55:08 +00002991 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002992#if _LIBCPP_BIG_ENDIAN
2993 return (__m <= ~__long_mask ? __m : __m/2) - 1;
2994#else
2995 return __m - 1;
2996#endif
2997}
2998
2999template <class _CharT, class _Traits, class _Allocator>
3000void
3001basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3002{
3003 if (__res_arg > max_size())
3004 this->__throw_length_error();
3005 size_type __cap = capacity();
3006 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003007 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003008 __res_arg = __recommend(__res_arg);
3009 if (__res_arg != __cap)
3010 {
3011 pointer __new_data, __p;
3012 bool __was_long, __now_long;
3013 if (__res_arg == __min_cap - 1)
3014 {
3015 __was_long = true;
3016 __now_long = false;
3017 __new_data = __get_short_pointer();
3018 __p = __get_long_pointer();
3019 }
3020 else
3021 {
3022 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003023 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003024 else
3025 {
3026 #ifndef _LIBCPP_NO_EXCEPTIONS
3027 try
3028 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003029 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00003030 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003031 #ifndef _LIBCPP_NO_EXCEPTIONS
3032 }
3033 catch (...)
3034 {
3035 return;
3036 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003037 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003038 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003039 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003040 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003041 }
3042 __now_long = true;
3043 __was_long = __is_long();
3044 __p = __get_pointer();
3045 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003046 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3047 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003048 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003049 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003050 if (__now_long)
3051 {
3052 __set_long_cap(__res_arg+1);
3053 __set_long_size(__sz);
3054 __set_long_pointer(__new_data);
3055 }
3056 else
3057 __set_short_size(__sz);
3058 __invalidate_all_iterators();
3059 }
3060}
3061
3062template <class _CharT, class _Traits, class _Allocator>
3063_LIBCPP_INLINE_VISIBILITY inline
3064typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3065basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
3066{
3067#ifdef __LIBCPP_DEBUG
3068 assert(__pos <= size());
3069#endif
3070 return *(data() + __pos);
3071}
3072
3073template <class _CharT, class _Traits, class _Allocator>
3074_LIBCPP_INLINE_VISIBILITY inline
3075typename basic_string<_CharT, _Traits, _Allocator>::reference
3076basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
3077{
3078#ifdef __LIBCPP_DEBUG
3079 assert(__pos < size());
3080#endif
3081 return *(__get_pointer() + __pos);
3082}
3083
3084template <class _CharT, class _Traits, class _Allocator>
3085typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3086basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3087{
3088 if (__n >= size())
3089 this->__throw_out_of_range();
3090 return (*this)[__n];
3091}
3092
3093template <class _CharT, class _Traits, class _Allocator>
3094typename basic_string<_CharT, _Traits, _Allocator>::reference
3095basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3096{
3097 if (__n >= size())
3098 this->__throw_out_of_range();
3099 return (*this)[__n];
3100}
3101
3102template <class _CharT, class _Traits, class _Allocator>
3103_LIBCPP_INLINE_VISIBILITY inline
3104typename basic_string<_CharT, _Traits, _Allocator>::reference
3105basic_string<_CharT, _Traits, _Allocator>::front()
3106{
3107#ifdef _LIBCPP_DEBUG
3108 assert(!empty());
3109#endif
3110 return *__get_pointer();
3111}
3112
3113template <class _CharT, class _Traits, class _Allocator>
3114_LIBCPP_INLINE_VISIBILITY inline
3115typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3116basic_string<_CharT, _Traits, _Allocator>::front() const
3117{
3118#ifdef _LIBCPP_DEBUG
3119 assert(!empty());
3120#endif
3121 return *data();
3122}
3123
3124template <class _CharT, class _Traits, class _Allocator>
3125_LIBCPP_INLINE_VISIBILITY inline
3126typename basic_string<_CharT, _Traits, _Allocator>::reference
3127basic_string<_CharT, _Traits, _Allocator>::back()
3128{
3129#ifdef _LIBCPP_DEBUG
3130 assert(!empty());
3131#endif
3132 return *(__get_pointer() + size() - 1);
3133}
3134
3135template <class _CharT, class _Traits, class _Allocator>
3136_LIBCPP_INLINE_VISIBILITY inline
3137typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3138basic_string<_CharT, _Traits, _Allocator>::back() const
3139{
3140#ifdef _LIBCPP_DEBUG
3141 assert(!empty());
3142#endif
3143 return *(data() + size() - 1);
3144}
3145
3146template <class _CharT, class _Traits, class _Allocator>
3147typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003148basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003149{
3150 size_type __sz = size();
3151 if (__pos > __sz)
3152 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003153 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003154 traits_type::copy(__s, data() + __pos, __rlen);
3155 return __rlen;
3156}
3157
3158template <class _CharT, class _Traits, class _Allocator>
3159_LIBCPP_INLINE_VISIBILITY inline
3160basic_string<_CharT, _Traits, _Allocator>
3161basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3162{
3163 return basic_string(*this, __pos, __n, __alloc());
3164}
3165
3166template <class _CharT, class _Traits, class _Allocator>
3167_LIBCPP_INLINE_VISIBILITY inline
3168void
3169basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003170 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3171 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003172{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003173 _VSTD::swap(__r_.first(), __str.__r_.first());
Howard Hinnante32b5e22010-11-17 17:55:08 +00003174 __swap_alloc(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003175#ifdef _LIBCPP_DEBUG
3176 __invalidate_all_iterators();
3177 __str.__invalidate_all_iterators();
Howard Hinnant324bb032010-08-22 00:02:43 +00003178#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003179}
3180
3181// find
3182
3183template <class _Traits>
3184struct _LIBCPP_HIDDEN __traits_eq
3185{
3186 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003187 _LIBCPP_INLINE_VISIBILITY
3188 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3189 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003190};
3191
3192template<class _CharT, class _Traits, class _Allocator>
3193typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003194basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003195 size_type __pos,
3196 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003197{
3198#ifdef _LIBCPP_DEBUG
3199 assert(__s != 0);
3200#endif
3201 size_type __sz = size();
3202 if (__pos > __sz || __sz - __pos < __n)
3203 return npos;
3204 if (__n == 0)
3205 return __pos;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003206 const value_type* __p = data();
3207 const value_type* __r = _VSTD::search(__p + __pos, __p + __sz, __s, __s + __n,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003208 __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003209 if (__r == __p + __sz)
3210 return npos;
3211 return static_cast<size_type>(__r - __p);
3212}
3213
3214template<class _CharT, class _Traits, class _Allocator>
3215_LIBCPP_INLINE_VISIBILITY inline
3216typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003217basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3218 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003219{
3220 return find(__str.data(), __pos, __str.size());
3221}
3222
3223template<class _CharT, class _Traits, class _Allocator>
3224_LIBCPP_INLINE_VISIBILITY inline
3225typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003226basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003227 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003228{
3229#ifdef _LIBCPP_DEBUG
3230 assert(__s != 0);
3231#endif
3232 return find(__s, __pos, traits_type::length(__s));
3233}
3234
3235template<class _CharT, class _Traits, class _Allocator>
3236typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003237basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3238 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003239{
3240 size_type __sz = size();
3241 if (__pos >= __sz)
3242 return npos;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003243 const value_type* __p = data();
3244 const value_type* __r = traits_type::find(__p + __pos, __sz - __pos, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003245 if (__r == 0)
3246 return npos;
3247 return static_cast<size_type>(__r - __p);
3248}
3249
3250// rfind
3251
3252template<class _CharT, class _Traits, class _Allocator>
3253typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003254basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003255 size_type __pos,
3256 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003257{
3258#ifdef _LIBCPP_DEBUG
3259 assert(__s != 0);
3260#endif
3261 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003262 __pos = _VSTD::min(__pos, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003263 if (__n < __sz - __pos)
3264 __pos += __n;
3265 else
3266 __pos = __sz;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003267 const value_type* __p = data();
3268 const value_type* __r = _VSTD::find_end(__p, __p + __pos, __s, __s + __n,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003269 __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003270 if (__n > 0 && __r == __p + __pos)
3271 return npos;
3272 return static_cast<size_type>(__r - __p);
3273}
3274
3275template<class _CharT, class _Traits, class _Allocator>
3276_LIBCPP_INLINE_VISIBILITY inline
3277typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003278basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3279 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003280{
3281 return rfind(__str.data(), __pos, __str.size());
3282}
3283
3284template<class _CharT, class _Traits, class _Allocator>
3285_LIBCPP_INLINE_VISIBILITY inline
3286typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003287basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003288 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003289{
3290#ifdef _LIBCPP_DEBUG
3291 assert(__s != 0);
3292#endif
3293 return rfind(__s, __pos, traits_type::length(__s));
3294}
3295
3296template<class _CharT, class _Traits, class _Allocator>
3297typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003298basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3299 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003300{
3301 size_type __sz = size();
3302 if (__sz)
3303 {
3304 if (__pos < __sz)
3305 ++__pos;
3306 else
3307 __pos = __sz;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003308 const value_type* __p = data();
3309 for (const value_type* __ps = __p + __pos; __ps != __p;)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003310 {
3311 if (traits_type::eq(*--__ps, __c))
3312 return static_cast<size_type>(__ps - __p);
3313 }
3314 }
3315 return npos;
3316}
3317
3318// find_first_of
3319
3320template<class _CharT, class _Traits, class _Allocator>
3321typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003322basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003323 size_type __pos,
3324 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003325{
3326#ifdef _LIBCPP_DEBUG
3327 assert(__s != 0);
3328#endif
3329 size_type __sz = size();
3330 if (__pos >= __sz || __n == 0)
3331 return npos;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003332 const value_type* __p = data();
3333 const value_type* __r = _VSTD::find_first_of(__p + __pos, __p + __sz, __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003334 __s + __n, __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003335 if (__r == __p + __sz)
3336 return npos;
3337 return static_cast<size_type>(__r - __p);
3338}
3339
3340template<class _CharT, class _Traits, class _Allocator>
3341_LIBCPP_INLINE_VISIBILITY inline
3342typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003343basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3344 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003345{
3346 return find_first_of(__str.data(), __pos, __str.size());
3347}
3348
3349template<class _CharT, class _Traits, class _Allocator>
3350_LIBCPP_INLINE_VISIBILITY inline
3351typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003352basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003353 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003354{
3355#ifdef _LIBCPP_DEBUG
3356 assert(__s != 0);
3357#endif
3358 return find_first_of(__s, __pos, traits_type::length(__s));
3359}
3360
3361template<class _CharT, class _Traits, class _Allocator>
3362_LIBCPP_INLINE_VISIBILITY inline
3363typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003364basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3365 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003366{
3367 return find(__c, __pos);
3368}
3369
3370// find_last_of
3371
3372template<class _CharT, class _Traits, class _Allocator>
3373typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003374basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003375 size_type __pos,
3376 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003377{
3378#ifdef _LIBCPP_DEBUG
3379 assert(__s != 0);
3380#endif
3381 if (__n != 0)
3382 {
3383 size_type __sz = size();
3384 if (__pos < __sz)
3385 ++__pos;
3386 else
3387 __pos = __sz;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003388 const value_type* __p = data();
3389 for (const value_type* __ps = __p + __pos; __ps != __p;)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003390 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003391 const value_type* __r = traits_type::find(__s, __n, *--__ps);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003392 if (__r)
3393 return static_cast<size_type>(__ps - __p);
3394 }
3395 }
3396 return npos;
3397}
3398
3399template<class _CharT, class _Traits, class _Allocator>
3400_LIBCPP_INLINE_VISIBILITY inline
3401typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003402basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3403 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003404{
3405 return find_last_of(__str.data(), __pos, __str.size());
3406}
3407
3408template<class _CharT, class _Traits, class _Allocator>
3409_LIBCPP_INLINE_VISIBILITY inline
3410typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003411basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003412 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003413{
3414#ifdef _LIBCPP_DEBUG
3415 assert(__s != 0);
3416#endif
3417 return find_last_of(__s, __pos, traits_type::length(__s));
3418}
3419
3420template<class _CharT, class _Traits, class _Allocator>
3421_LIBCPP_INLINE_VISIBILITY inline
3422typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003423basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3424 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003425{
3426 return rfind(__c, __pos);
3427}
3428
3429// find_first_not_of
3430
3431template<class _CharT, class _Traits, class _Allocator>
3432typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003433basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003434 size_type __pos,
3435 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003436{
3437#ifdef _LIBCPP_DEBUG
3438 assert(__s != 0);
3439#endif
3440 size_type __sz = size();
3441 if (__pos < __sz)
3442 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003443 const value_type* __p = data();
3444 const value_type* __pe = __p + __sz;
3445 for (const value_type* __ps = __p + __pos; __ps != __pe; ++__ps)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003446 if (traits_type::find(__s, __n, *__ps) == 0)
3447 return static_cast<size_type>(__ps - __p);
3448 }
3449 return npos;
3450}
3451
3452template<class _CharT, class _Traits, class _Allocator>
3453_LIBCPP_INLINE_VISIBILITY inline
3454typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003455basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3456 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003457{
3458 return find_first_not_of(__str.data(), __pos, __str.size());
3459}
3460
3461template<class _CharT, class _Traits, class _Allocator>
3462_LIBCPP_INLINE_VISIBILITY inline
3463typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003464basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003465 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003466{
3467#ifdef _LIBCPP_DEBUG
3468 assert(__s != 0);
3469#endif
3470 return find_first_not_of(__s, __pos, traits_type::length(__s));
3471}
3472
3473template<class _CharT, class _Traits, class _Allocator>
3474_LIBCPP_INLINE_VISIBILITY inline
3475typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003476basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3477 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003478{
3479 size_type __sz = size();
3480 if (__pos < __sz)
3481 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003482 const value_type* __p = data();
3483 const value_type* __pe = __p + __sz;
3484 for (const value_type* __ps = __p + __pos; __ps != __pe; ++__ps)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003485 if (!traits_type::eq(*__ps, __c))
3486 return static_cast<size_type>(__ps - __p);
3487 }
3488 return npos;
3489}
3490
3491// find_last_not_of
3492
3493template<class _CharT, class _Traits, class _Allocator>
3494typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003495basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003496 size_type __pos,
3497 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003498{
3499#ifdef _LIBCPP_DEBUG
3500 assert(__s != 0);
3501#endif
3502 size_type __sz = size();
3503 if (__pos < __sz)
3504 ++__pos;
3505 else
3506 __pos = __sz;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003507 const value_type* __p = data();
3508 for (const value_type* __ps = __p + __pos; __ps != __p;)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003509 if (traits_type::find(__s, __n, *--__ps) == 0)
3510 return static_cast<size_type>(__ps - __p);
3511 return npos;
3512}
3513
3514template<class _CharT, class _Traits, class _Allocator>
3515_LIBCPP_INLINE_VISIBILITY inline
3516typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003517basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3518 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003519{
3520 return find_last_not_of(__str.data(), __pos, __str.size());
3521}
3522
3523template<class _CharT, class _Traits, class _Allocator>
3524_LIBCPP_INLINE_VISIBILITY inline
3525typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003526basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003527 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003528{
3529#ifdef _LIBCPP_DEBUG
3530 assert(__s != 0);
3531#endif
3532 return find_last_not_of(__s, __pos, traits_type::length(__s));
3533}
3534
3535template<class _CharT, class _Traits, class _Allocator>
3536_LIBCPP_INLINE_VISIBILITY inline
3537typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003538basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3539 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003540{
3541 size_type __sz = size();
3542 if (__pos < __sz)
3543 ++__pos;
3544 else
3545 __pos = __sz;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003546 const value_type* __p = data();
3547 for (const value_type* __ps = __p + __pos; __ps != __p;)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003548 if (!traits_type::eq(*--__ps, __c))
3549 return static_cast<size_type>(__ps - __p);
3550 return npos;
3551}
3552
3553// compare
3554
3555template <class _CharT, class _Traits, class _Allocator>
3556_LIBCPP_INLINE_VISIBILITY inline
3557int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003558basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003559{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003560 size_t __lhs_sz = size();
3561 size_t __rhs_sz = __str.size();
3562 int __result = traits_type::compare(data(), __str.data(),
3563 _VSTD::min(__lhs_sz, __rhs_sz));
3564 if (__result != 0)
3565 return __result;
3566 if (__lhs_sz < __rhs_sz)
3567 return -1;
3568 if (__lhs_sz > __rhs_sz)
3569 return 1;
3570 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003571}
3572
3573template <class _CharT, class _Traits, class _Allocator>
3574_LIBCPP_INLINE_VISIBILITY inline
3575int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003576basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3577 size_type __n1,
3578 const basic_string& __str) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003579{
3580 return compare(__pos1, __n1, __str.data(), __str.size());
3581}
3582
3583template <class _CharT, class _Traits, class _Allocator>
3584int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003585basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3586 size_type __n1,
3587 const basic_string& __str,
3588 size_type __pos2,
3589 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003590{
3591 size_type __sz = __str.size();
3592 if (__pos2 > __sz)
3593 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003594 return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003595 __sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003596}
3597
3598template <class _CharT, class _Traits, class _Allocator>
3599int
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003600basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003601{
3602#ifdef _LIBCPP_DEBUG
3603 assert(__s != 0);
3604#endif
3605 return compare(0, npos, __s, traits_type::length(__s));
3606}
3607
3608template <class _CharT, class _Traits, class _Allocator>
3609int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003610basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3611 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003612 const value_type* __s) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003613{
3614#ifdef _LIBCPP_DEBUG
3615 assert(__s != 0);
3616#endif
3617 return compare(__pos1, __n1, __s, traits_type::length(__s));
3618}
3619
3620template <class _CharT, class _Traits, class _Allocator>
3621int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003622basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3623 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003624 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003625 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003626{
3627#ifdef _LIBCPP_DEBUG
3628 assert(__s != 0);
3629#endif
3630 size_type __sz = size();
3631 if (__pos1 > __sz || __n2 == npos)
3632 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003633 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3634 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003635 if (__r == 0)
3636 {
3637 if (__rlen < __n2)
3638 __r = -1;
3639 else if (__rlen > __n2)
3640 __r = 1;
3641 }
3642 return __r;
3643}
3644
3645// __invariants
3646
3647template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00003648_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003649bool
3650basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3651{
3652 if (size() > capacity())
3653 return false;
3654 if (capacity() < __min_cap - 1)
3655 return false;
3656 if (data() == 0)
3657 return false;
3658 if (data()[size()] != value_type(0))
3659 return false;
3660 return true;
3661}
3662
3663// operator==
3664
3665template<class _CharT, class _Traits, class _Allocator>
3666_LIBCPP_INLINE_VISIBILITY inline
3667bool
3668operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003669 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003670{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003671 size_t __lhs_sz = __lhs.size();
3672 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3673 __rhs.data(),
3674 __lhs_sz) == 0;
3675}
3676
3677template<class _Allocator>
3678_LIBCPP_INLINE_VISIBILITY inline
3679bool
3680operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3681 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3682{
3683 size_t __lhs_sz = __lhs.size();
3684 if (__lhs_sz != __rhs.size())
3685 return false;
3686 const char* __lp = __lhs.data();
3687 const char* __rp = __rhs.data();
3688 if (__lhs.__is_long())
3689 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3690 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3691 if (*__lp != *__rp)
3692 return false;
3693 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003694}
3695
3696template<class _CharT, class _Traits, class _Allocator>
3697_LIBCPP_INLINE_VISIBILITY inline
3698bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003699operator==(const _CharT* __lhs,
3700 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003701{
3702 return __rhs.compare(__lhs) == 0;
3703}
3704
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003705template<class _CharT, class _Traits, class _Allocator>
3706_LIBCPP_INLINE_VISIBILITY inline
3707bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003708operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3709 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003710{
3711 return __lhs.compare(__rhs) == 0;
3712}
3713
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003714// operator!=
3715
Howard Hinnant324bb032010-08-22 00:02:43 +00003716template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003717_LIBCPP_INLINE_VISIBILITY inline
3718bool
3719operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003720 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003721{
3722 return !(__lhs == __rhs);
3723}
3724
3725template<class _CharT, class _Traits, class _Allocator>
3726_LIBCPP_INLINE_VISIBILITY inline
3727bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003728operator!=(const _CharT* __lhs,
3729 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003730{
3731 return !(__lhs == __rhs);
3732}
3733
3734template<class _CharT, class _Traits, class _Allocator>
3735_LIBCPP_INLINE_VISIBILITY inline
3736bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003737operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3738 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003739{
3740 return !(__lhs == __rhs);
3741}
3742
3743// operator<
3744
3745template<class _CharT, class _Traits, class _Allocator>
3746_LIBCPP_INLINE_VISIBILITY inline
3747bool
3748operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003749 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003750{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003751 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003752}
3753
3754template<class _CharT, class _Traits, class _Allocator>
3755_LIBCPP_INLINE_VISIBILITY inline
3756bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003757operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3758 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003759{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003760 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003761}
3762
3763template<class _CharT, class _Traits, class _Allocator>
3764_LIBCPP_INLINE_VISIBILITY inline
3765bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003766operator< (const _CharT* __lhs,
3767 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003768{
3769 return __rhs.compare(__lhs) > 0;
3770}
3771
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003772// operator>
3773
3774template<class _CharT, class _Traits, class _Allocator>
3775_LIBCPP_INLINE_VISIBILITY inline
3776bool
3777operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003778 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003779{
3780 return __rhs < __lhs;
3781}
3782
3783template<class _CharT, class _Traits, class _Allocator>
3784_LIBCPP_INLINE_VISIBILITY inline
3785bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003786operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3787 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003788{
3789 return __rhs < __lhs;
3790}
3791
3792template<class _CharT, class _Traits, class _Allocator>
3793_LIBCPP_INLINE_VISIBILITY inline
3794bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003795operator> (const _CharT* __lhs,
3796 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003797{
3798 return __rhs < __lhs;
3799}
3800
3801// operator<=
3802
3803template<class _CharT, class _Traits, class _Allocator>
3804_LIBCPP_INLINE_VISIBILITY inline
3805bool
3806operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003807 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003808{
3809 return !(__rhs < __lhs);
3810}
3811
3812template<class _CharT, class _Traits, class _Allocator>
3813_LIBCPP_INLINE_VISIBILITY inline
3814bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003815operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3816 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003817{
3818 return !(__rhs < __lhs);
3819}
3820
3821template<class _CharT, class _Traits, class _Allocator>
3822_LIBCPP_INLINE_VISIBILITY inline
3823bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003824operator<=(const _CharT* __lhs,
3825 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003826{
3827 return !(__rhs < __lhs);
3828}
3829
3830// operator>=
3831
3832template<class _CharT, class _Traits, class _Allocator>
3833_LIBCPP_INLINE_VISIBILITY inline
3834bool
3835operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003836 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003837{
3838 return !(__lhs < __rhs);
3839}
3840
3841template<class _CharT, class _Traits, class _Allocator>
3842_LIBCPP_INLINE_VISIBILITY inline
3843bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003844operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3845 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003846{
3847 return !(__lhs < __rhs);
3848}
3849
3850template<class _CharT, class _Traits, class _Allocator>
3851_LIBCPP_INLINE_VISIBILITY inline
3852bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003853operator>=(const _CharT* __lhs,
3854 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003855{
3856 return !(__lhs < __rhs);
3857}
3858
3859// operator +
3860
3861template<class _CharT, class _Traits, class _Allocator>
3862basic_string<_CharT, _Traits, _Allocator>
3863operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3864 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3865{
3866 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3867 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3868 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3869 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3870 __r.append(__rhs.data(), __rhs_sz);
3871 return __r;
3872}
3873
3874template<class _CharT, class _Traits, class _Allocator>
3875basic_string<_CharT, _Traits, _Allocator>
3876operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3877{
3878 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3879 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3880 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3881 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3882 __r.append(__rhs.data(), __rhs_sz);
3883 return __r;
3884}
3885
3886template<class _CharT, class _Traits, class _Allocator>
3887basic_string<_CharT, _Traits, _Allocator>
3888operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3889{
3890 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3891 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3892 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3893 __r.append(__rhs.data(), __rhs_sz);
3894 return __r;
3895}
3896
3897template<class _CharT, class _Traits, class _Allocator>
3898basic_string<_CharT, _Traits, _Allocator>
3899operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3900{
3901 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3902 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3903 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3904 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3905 __r.append(__rhs, __rhs_sz);
3906 return __r;
3907}
3908
3909template<class _CharT, class _Traits, class _Allocator>
3910basic_string<_CharT, _Traits, _Allocator>
3911operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3912{
3913 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3914 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3915 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3916 __r.push_back(__rhs);
3917 return __r;
3918}
3919
Howard Hinnant73d21a42010-09-04 23:28:19 +00003920#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003921
3922template<class _CharT, class _Traits, class _Allocator>
3923_LIBCPP_INLINE_VISIBILITY inline
3924basic_string<_CharT, _Traits, _Allocator>
3925operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3926{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003927 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003928}
3929
3930template<class _CharT, class _Traits, class _Allocator>
3931_LIBCPP_INLINE_VISIBILITY inline
3932basic_string<_CharT, _Traits, _Allocator>
3933operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3934{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003935 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003936}
3937
3938template<class _CharT, class _Traits, class _Allocator>
3939_LIBCPP_INLINE_VISIBILITY inline
3940basic_string<_CharT, _Traits, _Allocator>
3941operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3942{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003943 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003944}
3945
3946template<class _CharT, class _Traits, class _Allocator>
3947_LIBCPP_INLINE_VISIBILITY inline
3948basic_string<_CharT, _Traits, _Allocator>
3949operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3950{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003951 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003952}
3953
3954template<class _CharT, class _Traits, class _Allocator>
3955_LIBCPP_INLINE_VISIBILITY inline
3956basic_string<_CharT, _Traits, _Allocator>
3957operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3958{
3959 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003960 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003961}
3962
3963template<class _CharT, class _Traits, class _Allocator>
3964_LIBCPP_INLINE_VISIBILITY inline
3965basic_string<_CharT, _Traits, _Allocator>
3966operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3967{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003968 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003969}
3970
3971template<class _CharT, class _Traits, class _Allocator>
3972_LIBCPP_INLINE_VISIBILITY inline
3973basic_string<_CharT, _Traits, _Allocator>
3974operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3975{
3976 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003977 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003978}
3979
Howard Hinnant73d21a42010-09-04 23:28:19 +00003980#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003981
3982// swap
3983
3984template<class _CharT, class _Traits, class _Allocator>
3985_LIBCPP_INLINE_VISIBILITY inline
3986void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003987swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003988 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3989 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003990{
3991 __lhs.swap(__rhs);
3992}
3993
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003994#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3995
3996typedef basic_string<char16_t> u16string;
3997typedef basic_string<char32_t> u32string;
3998
Howard Hinnant324bb032010-08-22 00:02:43 +00003999#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004000
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004001int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4002long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4003unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4004long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4005unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
4006
4007float stof (const string& __str, size_t* __idx = 0);
4008double stod (const string& __str, size_t* __idx = 0);
4009long double stold(const string& __str, size_t* __idx = 0);
4010
4011string to_string(int __val);
4012string to_string(unsigned __val);
4013string to_string(long __val);
4014string to_string(unsigned long __val);
4015string to_string(long long __val);
4016string to_string(unsigned long long __val);
4017string to_string(float __val);
4018string to_string(double __val);
4019string to_string(long double __val);
4020
4021int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4022long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4023unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4024long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4025unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
4026
4027float stof (const wstring& __str, size_t* __idx = 0);
4028double stod (const wstring& __str, size_t* __idx = 0);
4029long double stold(const wstring& __str, size_t* __idx = 0);
4030
4031wstring to_wstring(int __val);
4032wstring to_wstring(unsigned __val);
4033wstring to_wstring(long __val);
4034wstring to_wstring(unsigned long __val);
4035wstring to_wstring(long long __val);
4036wstring to_wstring(unsigned long long __val);
4037wstring to_wstring(float __val);
4038wstring to_wstring(double __val);
4039wstring to_wstring(long double __val);
4040
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004041template<class _CharT, class _Traits, class _Allocator>
4042 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4043 basic_string<_CharT, _Traits, _Allocator>::npos;
4044
Sean Huntaffd9e52011-07-29 23:31:56 +00004045template<class _Ptr>
4046size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
4047{
Howard Hinnant40c13d32011-12-05 00:08:45 +00004048 typedef typename iterator_traits<_Ptr>::value_type value_type;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00004049 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
Sean Huntaffd9e52011-07-29 23:31:56 +00004050}
4051
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004052template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant83eade62013-03-06 23:30:19 +00004053struct _LIBCPP_TYPE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004054 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4055{
4056 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004057 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004058};
4059
4060template<class _CharT, class _Traits, class _Allocator>
4061size_t
4062hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004063 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004064{
Sean Huntaffd9e52011-07-29 23:31:56 +00004065 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004066}
4067
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004068template<class _CharT, class _Traits, class _Allocator>
4069basic_ostream<_CharT, _Traits>&
4070operator<<(basic_ostream<_CharT, _Traits>& __os,
4071 const basic_string<_CharT, _Traits, _Allocator>& __str);
4072
4073template<class _CharT, class _Traits, class _Allocator>
4074basic_istream<_CharT, _Traits>&
4075operator>>(basic_istream<_CharT, _Traits>& __is,
4076 basic_string<_CharT, _Traits, _Allocator>& __str);
4077
4078template<class _CharT, class _Traits, class _Allocator>
4079basic_istream<_CharT, _Traits>&
4080getline(basic_istream<_CharT, _Traits>& __is,
4081 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4082
4083template<class _CharT, class _Traits, class _Allocator>
4084inline _LIBCPP_INLINE_VISIBILITY
4085basic_istream<_CharT, _Traits>&
4086getline(basic_istream<_CharT, _Traits>& __is,
4087 basic_string<_CharT, _Traits, _Allocator>& __str);
4088
4089#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4090
4091template<class _CharT, class _Traits, class _Allocator>
4092inline _LIBCPP_INLINE_VISIBILITY
4093basic_istream<_CharT, _Traits>&
4094getline(basic_istream<_CharT, _Traits>&& __is,
4095 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4096
4097template<class _CharT, class _Traits, class _Allocator>
4098inline _LIBCPP_INLINE_VISIBILITY
4099basic_istream<_CharT, _Traits>&
4100getline(basic_istream<_CharT, _Traits>&& __is,
4101 basic_string<_CharT, _Traits, _Allocator>& __str);
4102
4103#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4104
Marshall Clow15234322013-07-23 17:05:24 +00004105#if _LIBCPP_STD_VER > 11
4106// Literal suffixes for basic_string [basic.string.literals]
4107// inline // Deviation from N3690.
4108// We believe the inline to be a defect and have submitted an LWG issue.
4109// An LWG issue number has not yet been assigned.
4110namespace literals
4111{
4112 inline namespace string_literals
4113 {
4114 inline _LIBCPP_INLINE_VISIBILITY
4115 basic_string<char> operator "" s( const char *__str, size_t __len )
4116 {
4117 return basic_string<char> (__str, __len);
4118 }
4119
4120 inline _LIBCPP_INLINE_VISIBILITY
4121 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4122 {
4123 return basic_string<wchar_t> (__str, __len);
4124 }
4125
4126 inline _LIBCPP_INLINE_VISIBILITY
4127 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4128 {
4129 return basic_string<char16_t> (__str, __len);
4130 }
4131
4132 inline _LIBCPP_INLINE_VISIBILITY
4133 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4134 {
4135 return basic_string<char32_t> (__str, __len);
4136 }
4137 }
4138}
4139#endif
4140
Howard Hinnantff926772012-11-06 21:08:48 +00004141_LIBCPP_EXTERN_TEMPLATE(class basic_string<char>)
4142_LIBCPP_EXTERN_TEMPLATE(class basic_string<wchar_t>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004143
4144extern template
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004145 string
4146 operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
4147
4148_LIBCPP_END_NAMESPACE_STD
4149
4150#endif // _LIBCPP_STRING